This file is indexed.

/usr/share/qt5/doc/qtquick/qtquick-rendercontrol-cuberenderer-cpp.html is in qtdeclarative5-doc-html 5.5.1-2ubuntu6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>cuberenderer.cpp Example File | Qt Quick 5.5</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.5</li>
<li><a href="qtquick-index.html">Qt Quick</a></li>
<li><a href="qtquick-rendercontrol-example.html">QQuickRenderControl Example</a></li>
<li>cuberenderer.cpp Example File</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">cuberenderer.cpp Example File</h1>
<span class="subtitle">rendercontrol/cuberenderer.cpp</span>
<!-- $$$rendercontrol/cuberenderer.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp"><span class="comment">/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** &quot;Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
**
** $QT_END_LICENSE$
**
****************************************************************************/</span>

<span class="preprocessor">#include &quot;cuberenderer.h&quot;</span>
<span class="preprocessor">#include &lt;QOpenGLContext&gt;</span>
<span class="preprocessor">#include &lt;QOpenGLFunctions&gt;</span>
<span class="preprocessor">#include &lt;QOpenGLShaderProgram&gt;</span>
<span class="preprocessor">#include &lt;QOpenGLVertexArrayObject&gt;</span>
<span class="preprocessor">#include &lt;QOpenGLBuffer&gt;</span>
<span class="preprocessor">#include &lt;QOpenGLVertexArrayObject&gt;</span>
<span class="preprocessor">#include &lt;QOffscreenSurface&gt;</span>
<span class="preprocessor">#include &lt;QWindow&gt;</span>

CubeRenderer<span class="operator">::</span>CubeRenderer(<span class="type">QOffscreenSurface</span> <span class="operator">*</span>offscreenSurface)
    : m_offscreenSurface(offscreenSurface)<span class="operator">,</span>
      m_context(<span class="number">0</span>)<span class="operator">,</span>
      m_program(<span class="number">0</span>)<span class="operator">,</span>
      m_vbo(<span class="number">0</span>)<span class="operator">,</span>
      m_vao(<span class="number">0</span>)<span class="operator">,</span>
      m_matrixLoc(<span class="number">0</span>)
{
}

CubeRenderer<span class="operator">::</span><span class="operator">~</span>CubeRenderer()
{
    <span class="comment">// Use a temporary offscreen surface to do the cleanup.</span>
    <span class="comment">// There may not be a native window surface available anymore at this stage.</span>
    m_context<span class="operator">-</span><span class="operator">&gt;</span>makeCurrent(m_offscreenSurface);

    <span class="keyword">delete</span> m_program;
    <span class="keyword">delete</span> m_vbo;
    <span class="keyword">delete</span> m_vao;

    m_context<span class="operator">-</span><span class="operator">&gt;</span>doneCurrent();
    <span class="keyword">delete</span> m_context;
}

<span class="type">void</span> CubeRenderer<span class="operator">::</span>init(<span class="type">QWindow</span> <span class="operator">*</span>w<span class="operator">,</span> <span class="type">QOpenGLContext</span> <span class="operator">*</span>share)
{
    m_context <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QOpenGLContext</span>;
    m_context<span class="operator">-</span><span class="operator">&gt;</span>setShareContext(share);
    m_context<span class="operator">-</span><span class="operator">&gt;</span>setFormat(w<span class="operator">-</span><span class="operator">&gt;</span>requestedFormat());
    m_context<span class="operator">-</span><span class="operator">&gt;</span>create();
    <span class="keyword">if</span> (<span class="operator">!</span>m_context<span class="operator">-</span><span class="operator">&gt;</span>makeCurrent(w))
        <span class="keyword">return</span>;

    <span class="type">QOpenGLFunctions</span> <span class="operator">*</span>f <span class="operator">=</span> m_context<span class="operator">-</span><span class="operator">&gt;</span>functions();
    f<span class="operator">-</span><span class="operator">&gt;</span>glClearColor(<span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.1f</span><span class="operator">,</span> <span class="number">0.25f</span><span class="operator">,</span> <span class="number">1.0f</span>);
    f<span class="operator">-</span><span class="operator">&gt;</span>glViewport(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> w<span class="operator">-</span><span class="operator">&gt;</span>width() <span class="operator">*</span> w<span class="operator">-</span><span class="operator">&gt;</span>devicePixelRatio()<span class="operator">,</span> w<span class="operator">-</span><span class="operator">&gt;</span>height() <span class="operator">*</span> w<span class="operator">-</span><span class="operator">&gt;</span>devicePixelRatio());

    <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>vertexShaderSource <span class="operator">=</span>
        <span class="string">&quot;attribute highp vec4 vertex;\n&quot;</span>
        <span class="string">&quot;attribute lowp vec2 coord;\n&quot;</span>
        <span class="string">&quot;varying lowp vec2 v_coord;\n&quot;</span>
        <span class="string">&quot;uniform highp mat4 matrix;\n&quot;</span>
        <span class="string">&quot;void main() {\n&quot;</span>
        <span class="string">&quot;   v_coord = coord;\n&quot;</span>
        <span class="string">&quot;   gl_Position = matrix * vertex;\n&quot;</span>
        <span class="string">&quot;}\n&quot;</span>;
    <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>fragmentShaderSource <span class="operator">=</span>
        <span class="string">&quot;varying lowp vec2 v_coord;\n&quot;</span>
        <span class="string">&quot;uniform sampler2D sampler;\n&quot;</span>
        <span class="string">&quot;void main() {\n&quot;</span>
        <span class="string">&quot;   gl_FragColor = vec4(texture2D(sampler, v_coord).rgb, 1.0);\n&quot;</span>
        <span class="string">&quot;}\n&quot;</span>;
    m_program <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QOpenGLShaderProgram</span>;
    m_program<span class="operator">-</span><span class="operator">&gt;</span>addShaderFromSourceCode(<span class="type">QOpenGLShader</span><span class="operator">::</span>Vertex<span class="operator">,</span> vertexShaderSource);
    m_program<span class="operator">-</span><span class="operator">&gt;</span>addShaderFromSourceCode(<span class="type">QOpenGLShader</span><span class="operator">::</span>Fragment<span class="operator">,</span> fragmentShaderSource);
    m_program<span class="operator">-</span><span class="operator">&gt;</span>bindAttributeLocation(<span class="string">&quot;vertex&quot;</span><span class="operator">,</span> <span class="number">0</span>);
    m_program<span class="operator">-</span><span class="operator">&gt;</span>bindAttributeLocation(<span class="string">&quot;coord&quot;</span><span class="operator">,</span> <span class="number">1</span>);
    m_program<span class="operator">-</span><span class="operator">&gt;</span>link();
    m_matrixLoc <span class="operator">=</span> m_program<span class="operator">-</span><span class="operator">&gt;</span>uniformLocation(<span class="string">&quot;matrix&quot;</span>);

    m_vao <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QOpenGLVertexArrayObject</span>;
    m_vao<span class="operator">-</span><span class="operator">&gt;</span>create();
    <span class="type">QOpenGLVertexArrayObject</span><span class="operator">::</span>Binder vaoBinder(m_vao);

    m_vbo <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QOpenGLBuffer</span>;
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>create();
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>bind();

    GLfloat v<span class="operator">[</span><span class="operator">]</span> <span class="operator">=</span> {
        <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>

        <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span><span class="number">0.5</span><span class="operator">,</span>

        <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>
        <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>
        <span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span>  <span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span>  <span class="operator">-</span><span class="number">0.5</span><span class="operator">,</span> <span class="number">0.5</span>
    };
    GLfloat texCoords<span class="operator">[</span><span class="operator">]</span> <span class="operator">=</span> {
        <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span>
        <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span>
        <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span>
        <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span>

        <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span>
        <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span>
        <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span>
        <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span>

        <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span>
        <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span>
        <span class="number">1.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span>
        <span class="number">0.0f</span><span class="operator">,</span><span class="number">1.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span><span class="number">0.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span><span class="number">1.0f</span>
    };

    <span class="keyword">const</span> <span class="type">int</span> vertexCount <span class="operator">=</span> <span class="number">36</span>;
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>allocate(<span class="keyword">sizeof</span>(GLfloat) <span class="operator">*</span> vertexCount <span class="operator">*</span> <span class="number">5</span>);
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>write(<span class="number">0</span><span class="operator">,</span> v<span class="operator">,</span> <span class="keyword">sizeof</span>(GLfloat) <span class="operator">*</span> vertexCount <span class="operator">*</span> <span class="number">3</span>);
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>write(<span class="keyword">sizeof</span>(GLfloat) <span class="operator">*</span> vertexCount <span class="operator">*</span> <span class="number">3</span><span class="operator">,</span> texCoords<span class="operator">,</span> <span class="keyword">sizeof</span>(GLfloat) <span class="operator">*</span> vertexCount <span class="operator">*</span> <span class="number">2</span>);
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>release();

    <span class="keyword">if</span> (m_vao<span class="operator">-</span><span class="operator">&gt;</span>isCreated())
        setupVertexAttribs();
}

<span class="type">void</span> CubeRenderer<span class="operator">::</span>resize(<span class="type">int</span> w<span class="operator">,</span> <span class="type">int</span> h)
{
    m_proj<span class="operator">.</span>setToIdentity();
    m_proj<span class="operator">.</span>perspective(<span class="number">45</span><span class="operator">,</span> w <span class="operator">/</span> <span class="type">float</span>(h)<span class="operator">,</span> <span class="number">0.01f</span><span class="operator">,</span> <span class="number">100.0f</span>);
}

<span class="type">void</span> CubeRenderer<span class="operator">::</span>setupVertexAttribs()
{
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>bind();
    m_program<span class="operator">-</span><span class="operator">&gt;</span>enableAttributeArray(<span class="number">0</span>);
    m_program<span class="operator">-</span><span class="operator">&gt;</span>enableAttributeArray(<span class="number">1</span>);
    m_context<span class="operator">-</span><span class="operator">&gt;</span>functions()<span class="operator">-</span><span class="operator">&gt;</span>glVertexAttribPointer(<span class="number">0</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> GL_FLOAT<span class="operator">,</span> GL_FALSE<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
    m_context<span class="operator">-</span><span class="operator">&gt;</span>functions()<span class="operator">-</span><span class="operator">&gt;</span>glVertexAttribPointer(<span class="number">1</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> GL_FLOAT<span class="operator">,</span> GL_FALSE<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span>
                                                  (<span class="keyword">const</span> <span class="type">void</span> <span class="operator">*</span>)(<span class="number">36</span> <span class="operator">*</span> <span class="number">3</span> <span class="operator">*</span> <span class="keyword">sizeof</span>(GLfloat)));
    m_vbo<span class="operator">-</span><span class="operator">&gt;</span>release();
}

<span class="type">void</span> CubeRenderer<span class="operator">::</span>render(<span class="type">QWindow</span> <span class="operator">*</span>w<span class="operator">,</span> <span class="type">QOpenGLContext</span> <span class="operator">*</span>share<span class="operator">,</span> <span class="type">uint</span> texture)
{
    <span class="keyword">if</span> (<span class="operator">!</span>m_context)
        init(w<span class="operator">,</span> share);

    <span class="keyword">if</span> (<span class="operator">!</span>m_context<span class="operator">-</span><span class="operator">&gt;</span>makeCurrent(w))
        <span class="keyword">return</span>;

    <span class="type">QOpenGLFunctions</span> <span class="operator">*</span>f <span class="operator">=</span> m_context<span class="operator">-</span><span class="operator">&gt;</span>functions();
    f<span class="operator">-</span><span class="operator">&gt;</span>glClear(GL_COLOR_BUFFER_BIT <span class="operator">|</span> GL_DEPTH_BUFFER_BIT);

    <span class="keyword">if</span> (texture) {
        f<span class="operator">-</span><span class="operator">&gt;</span>glBindTexture(GL_TEXTURE_2D<span class="operator">,</span> texture);
        f<span class="operator">-</span><span class="operator">&gt;</span>glFrontFace(GL_CW); <span class="comment">// because our cube's vertex data is such</span>
        f<span class="operator">-</span><span class="operator">&gt;</span>glEnable(GL_CULL_FACE);
        f<span class="operator">-</span><span class="operator">&gt;</span>glEnable(GL_DEPTH_TEST);

        m_program<span class="operator">-</span><span class="operator">&gt;</span>bind();
        <span class="type">QOpenGLVertexArrayObject</span><span class="operator">::</span>Binder vaoBinder(m_vao);
        <span class="comment">// If VAOs are not supported, set the vertex attributes every time.</span>
        <span class="keyword">if</span> (<span class="operator">!</span>m_vao<span class="operator">-</span><span class="operator">&gt;</span>isCreated())
            setupVertexAttribs();

        <span class="keyword">static</span> GLfloat angle <span class="operator">=</span> <span class="number">0</span>;
        QMatrix4x4 m;
        m<span class="operator">.</span>translate(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="operator">-</span><span class="number">2</span>);
        m<span class="operator">.</span>rotate(<span class="number">90</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
        m<span class="operator">.</span>rotate(angle<span class="operator">,</span> <span class="number">0.5</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
        angle <span class="operator">+</span><span class="operator">=</span> <span class="number">0.5f</span>;

        m_program<span class="operator">-</span><span class="operator">&gt;</span>setUniformValue(m_matrixLoc<span class="operator">,</span> m_proj <span class="operator">*</span> m);

        <span class="comment">// Draw the cube.</span>
        f<span class="operator">-</span><span class="operator">&gt;</span>glDrawArrays(GL_TRIANGLES<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">36</span>);
    }

    m_context<span class="operator">-</span><span class="operator">&gt;</span>swapBuffers(w);
}</pre>
</div>
<!-- @@@rendercontrol/cuberenderer.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>