Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/qgl.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qapplication.h" | - | ||||||||||||||||||
35 | #include "qplatformdefs.h" | - | ||||||||||||||||||
36 | #include "qgl.h" | - | ||||||||||||||||||
37 | #include <qdebug.h> | - | ||||||||||||||||||
38 | #include <qglfunctions.h> | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include <qdatetime.h> | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #include <stdlib.h> // malloc | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #include "qpixmap.h" | - | ||||||||||||||||||
45 | #include "qimage.h" | - | ||||||||||||||||||
46 | #include "qgl_p.h" | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | #include "gl2paintengineex/qpaintengineex_opengl2_p.h" | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | #include <qpa/qplatformopenglcontext.h> | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | #include <qglpixelbuffer.h> | - | ||||||||||||||||||
53 | #include <qglframebufferobject.h> | - | ||||||||||||||||||
54 | #include <private/qopenglextensions_p.h> | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | #include <private/qimage_p.h> | - | ||||||||||||||||||
57 | #include <qpa/qplatformpixmap.h> | - | ||||||||||||||||||
58 | #include <private/qglpixelbuffer_p.h> | - | ||||||||||||||||||
59 | #include <private/qimagepixmapcleanuphooks_p.h> | - | ||||||||||||||||||
60 | #include "qcolormap.h" | - | ||||||||||||||||||
61 | #include "qfile.h" | - | ||||||||||||||||||
62 | #include "qlibrary.h" | - | ||||||||||||||||||
63 | #include <qmutex.h> | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | #include "qsurfaceformat.h" | - | ||||||||||||||||||
66 | #include <private/qapplication_p.h> | - | ||||||||||||||||||
67 | #include <qpa/qplatformopenglcontext.h> | - | ||||||||||||||||||
68 | #include <qpa/qplatformwindow.h> | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
71 | #include <qopenglfunctions_1_1.h> | - | ||||||||||||||||||
72 | #endif | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | // #define QT_GL_CONTEXT_RESOURCE_DEBUG | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | class QGLDefaultExtensions | - | ||||||||||||||||||
79 | { | - | ||||||||||||||||||
80 | public: | - | ||||||||||||||||||
81 | QGLDefaultExtensions() : extensions(0) { | - | ||||||||||||||||||
82 | QGLTemporaryContext tempContext; | - | ||||||||||||||||||
83 | Q_ASSERT(QOpenGLContext::currentContext()); | - | ||||||||||||||||||
84 | QOpenGLExtensions *ext = qgl_extensions(); | - | ||||||||||||||||||
85 | Q_ASSERT(ext); | - | ||||||||||||||||||
86 | extensions = ext->openGLExtensions(); | - | ||||||||||||||||||
87 | features = ext->openGLFeatures(); | - | ||||||||||||||||||
88 | } never executed: end of block | 0 | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | QOpenGLFunctions::OpenGLFeatures features; | - | ||||||||||||||||||
91 | QOpenGLExtensions::OpenGLExtensions extensions; | - | ||||||||||||||||||
92 | }; | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | Q_GLOBAL_STATIC(QGLDefaultExtensions, qtDefaultExtensions) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | bool qgl_hasFeature(QOpenGLFunctions::OpenGLFeature feature) | - | ||||||||||||||||||
97 | { | - | ||||||||||||||||||
98 | if (QOpenGLContext::currentContext())
| 0 | ||||||||||||||||||
99 | return QOpenGLContext::currentContext()->functions()->hasOpenGLFeature(feature); never executed: return QOpenGLContext::currentContext()->functions()->hasOpenGLFeature(feature); | 0 | ||||||||||||||||||
100 | return qtDefaultExtensions()->features & feature; never executed: return qtDefaultExtensions()->features & feature; | 0 | ||||||||||||||||||
101 | } | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | bool qgl_hasExtension(QOpenGLExtensions::OpenGLExtension extension) | - | ||||||||||||||||||
104 | { | - | ||||||||||||||||||
105 | if (QOpenGLContext::currentContext())
| 0 | ||||||||||||||||||
106 | return qgl_extensions()->hasOpenGLExtension(extension); never executed: return qgl_extensions()->hasOpenGLExtension(extension); | 0 | ||||||||||||||||||
107 | return qtDefaultExtensions()->extensions & extension; never executed: return qtDefaultExtensions()->extensions & extension; | 0 | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | QOpenGLExtensions::OpenGLExtensions extensions; | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | /* | - | ||||||||||||||||||
113 | Returns the GL extensions for the current QOpenGLContext. If there is no | - | ||||||||||||||||||
114 | current QOpenGLContext, a default context will be created and the extensions | - | ||||||||||||||||||
115 | for that context will be returned instead. | - | ||||||||||||||||||
116 | */ | - | ||||||||||||||||||
117 | QOpenGLExtensions* qgl_extensions() | - | ||||||||||||||||||
118 | { | - | ||||||||||||||||||
119 | if (QOpenGLContext *context = QOpenGLContext::currentContext())
| 0-1 | ||||||||||||||||||
120 | return static_cast<QOpenGLExtensions *>(context->functions()); executed 1 time by 1 test: return static_cast<QOpenGLExtensions *>(context->functions()); Executed by:
| 1 | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | Q_ASSERT(false); | - | ||||||||||||||||||
123 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
124 | } | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | QOpenGLFunctions *qgl_functions() | - | ||||||||||||||||||
127 | { | - | ||||||||||||||||||
128 | return qgl_extensions(); // QOpenGLExtensions is just a subclass of QOpenGLFunctions executed 1 time by 1 test: return qgl_extensions(); Executed by:
| 1 | ||||||||||||||||||
129 | } | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
132 | QOpenGLFunctions_1_1 *qgl1_functions() | - | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | QOpenGLFunctions_1_1 *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_1_1>(); | - | ||||||||||||||||||
135 | f->initializeOpenGLFunctions(); | - | ||||||||||||||||||
136 | return f; never executed: return f; | 0 | ||||||||||||||||||
137 | } | - | ||||||||||||||||||
138 | #endif | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | struct QGLThreadContext { | - | ||||||||||||||||||
141 | ~QGLThreadContext() { | - | ||||||||||||||||||
142 | if (context)
| 0 | ||||||||||||||||||
143 | context->doneCurrent(); never executed: context->doneCurrent(); | 0 | ||||||||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||||||||
145 | QGLContext *context; | - | ||||||||||||||||||
146 | }; | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | Q_GLOBAL_STATIC(QGLFormat, qgl_default_format) executed 3 times by 3 tests: end of block Executed by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 12 times by 3 tests: return &holder.value; Executed by:
| 0-12 | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | class QGLDefaultOverlayFormat: public QGLFormat | - | ||||||||||||||||||
151 | { | - | ||||||||||||||||||
152 | public: | - | ||||||||||||||||||
153 | inline QGLDefaultOverlayFormat() | - | ||||||||||||||||||
154 | { | - | ||||||||||||||||||
155 | setOption(QGL::FormatOption(0xffff << 16)); // turn off all options | - | ||||||||||||||||||
156 | setOption(QGL::DirectRendering); | - | ||||||||||||||||||
157 | setPlane(1); | - | ||||||||||||||||||
158 | } never executed: end of block | 0 | ||||||||||||||||||
159 | }; | - | ||||||||||||||||||
160 | Q_GLOBAL_STATIC(QGLDefaultOverlayFormat, defaultOverlayFormatInstance) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | Q_GLOBAL_STATIC(QGLSignalProxy, theSignalProxy) executed 3 times by 3 tests: end of block Executed by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 12 times by 3 tests: return &holder.value; Executed by:
| 0-12 | ||||||||||||||||||
163 | QGLSignalProxy *QGLSignalProxy::instance() | - | ||||||||||||||||||
164 | { | - | ||||||||||||||||||
165 | QGLSignalProxy *proxy = theSignalProxy(); | - | ||||||||||||||||||
166 | if (proxy && qApp && proxy->thread() != qApp->thread()) {
| 0-12 | ||||||||||||||||||
167 | if (proxy->thread() == QThread::currentThread())
| 0 | ||||||||||||||||||
168 | proxy->moveToThread(qApp->thread()); never executed: proxy->moveToThread((static_cast<QApplication *>(QCoreApplication::instance()))->thread()); | 0 | ||||||||||||||||||
169 | } never executed: end of block | 0 | ||||||||||||||||||
170 | return proxy; executed 12 times by 3 tests: return proxy; Executed by:
| 12 | ||||||||||||||||||
171 | } | - | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | - | |||||||||||||||||||
174 | /*! | - | ||||||||||||||||||
175 | \namespace QGL | - | ||||||||||||||||||
176 | \inmodule QtOpenGL | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | \brief The QGL namespace specifies miscellaneous identifiers used | - | ||||||||||||||||||
179 | in the Qt OpenGL module. | - | ||||||||||||||||||
180 | */ | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | /*! | - | ||||||||||||||||||
183 | \enum QGL::FormatOption | - | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | This enum specifies the format options that can be used to configure an OpenGL | - | ||||||||||||||||||
186 | context. These are set using QGLFormat::setOption(). | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | \value DoubleBuffer Specifies the use of double buffering. | - | ||||||||||||||||||
189 | \value DepthBuffer Enables the use of a depth buffer. | - | ||||||||||||||||||
190 | \value Rgba Specifies that the context should use RGBA as its pixel format. | - | ||||||||||||||||||
191 | \value AlphaChannel Enables the use of an alpha channel. | - | ||||||||||||||||||
192 | \value AccumBuffer Enables the use of an accumulation buffer. | - | ||||||||||||||||||
193 | \value StencilBuffer Enables the use of a stencil buffer. | - | ||||||||||||||||||
194 | \value StereoBuffers Enables the use of a stereo buffers for use with visualization hardware. | - | ||||||||||||||||||
195 | \value DirectRendering Specifies that the context is used for direct rendering to a display. | - | ||||||||||||||||||
196 | \value HasOverlay Enables the use of an overlay. | - | ||||||||||||||||||
197 | \value SampleBuffers Enables the use of sample buffers. | - | ||||||||||||||||||
198 | \value DeprecatedFunctions Enables the use of deprecated functionality for OpenGL 3.x | - | ||||||||||||||||||
199 | contexts. A context with deprecated functionality enabled is | - | ||||||||||||||||||
200 | called a full context in the OpenGL specification. | - | ||||||||||||||||||
201 | \value SingleBuffer Specifies the use of a single buffer, as opposed to double buffers. | - | ||||||||||||||||||
202 | \value NoDepthBuffer Disables the use of a depth buffer. | - | ||||||||||||||||||
203 | \value ColorIndex Specifies that the context should use a color index as its pixel format. | - | ||||||||||||||||||
204 | \value NoAlphaChannel Disables the use of an alpha channel. | - | ||||||||||||||||||
205 | \value NoAccumBuffer Disables the use of an accumulation buffer. | - | ||||||||||||||||||
206 | \value NoStencilBuffer Disables the use of a stencil buffer. | - | ||||||||||||||||||
207 | \value NoStereoBuffers Disables the use of stereo buffers. | - | ||||||||||||||||||
208 | \value IndirectRendering Specifies that the context is used for indirect rendering to a buffer. | - | ||||||||||||||||||
209 | \value NoOverlay Disables the use of an overlay. | - | ||||||||||||||||||
210 | \value NoSampleBuffers Disables the use of sample buffers. | - | ||||||||||||||||||
211 | \value NoDeprecatedFunctions Disables the use of deprecated functionality for OpenGL 3.x | - | ||||||||||||||||||
212 | contexts. A context with deprecated functionality disabled is | - | ||||||||||||||||||
213 | called a forward compatible context in the OpenGL specification. | - | ||||||||||||||||||
214 | */ | - | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | /***************************************************************************** | - | ||||||||||||||||||
217 | QGLFormat implementation | - | ||||||||||||||||||
218 | *****************************************************************************/ | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | - | |||||||||||||||||||
221 | /*! | - | ||||||||||||||||||
222 | \class QGLFormat | - | ||||||||||||||||||
223 | \inmodule QtOpenGL | - | ||||||||||||||||||
224 | \obsolete | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | \brief The QGLFormat class specifies the display format of an OpenGL | - | ||||||||||||||||||
227 | rendering context. | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | A display format has several characteristics: | - | ||||||||||||||||||
230 | \list | - | ||||||||||||||||||
231 | \li \l{setDoubleBuffer()}{Double or single buffering.} | - | ||||||||||||||||||
232 | \li \l{setDepth()}{Depth buffer.} | - | ||||||||||||||||||
233 | \li \l{setRgba()}{RGBA or color index mode.} | - | ||||||||||||||||||
234 | \li \l{setAlpha()}{Alpha channel.} | - | ||||||||||||||||||
235 | \li \l{setAccum()}{Accumulation buffer.} | - | ||||||||||||||||||
236 | \li \l{setStencil()}{Stencil buffer.} | - | ||||||||||||||||||
237 | \li \l{setStereo()}{Stereo buffers.} | - | ||||||||||||||||||
238 | \li \l{setDirectRendering()}{Direct rendering.} | - | ||||||||||||||||||
239 | \li \l{setOverlay()}{Presence of an overlay.} | - | ||||||||||||||||||
240 | \li \l{setPlane()}{Plane of an overlay.} | - | ||||||||||||||||||
241 | \li \l{setSampleBuffers()}{Multisample buffers.} | - | ||||||||||||||||||
242 | \endlist | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | You can also specify preferred bit depths for the color buffer, | - | ||||||||||||||||||
245 | depth buffer, alpha buffer, accumulation buffer and the stencil | - | ||||||||||||||||||
246 | buffer with the functions: setRedBufferSize(), setGreenBufferSize(), | - | ||||||||||||||||||
247 | setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), | - | ||||||||||||||||||
248 | setAccumBufferSize() and setStencilBufferSize(). | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | Note that even if you specify that you prefer a 32 bit depth | - | ||||||||||||||||||
251 | buffer (e.g. with setDepthBufferSize(32)), the format that is | - | ||||||||||||||||||
252 | chosen may not have a 32 bit depth buffer, even if there is a | - | ||||||||||||||||||
253 | format available with a 32 bit depth buffer. The main reason for | - | ||||||||||||||||||
254 | this is how the system dependant picking algorithms work on the | - | ||||||||||||||||||
255 | different platforms, and some format options may have higher | - | ||||||||||||||||||
256 | precedence than others. | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | You create and tell a QGLFormat object what rendering options you | - | ||||||||||||||||||
259 | want from an OpenGL rendering context. | - | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | OpenGL drivers or accelerated hardware may or may not support | - | ||||||||||||||||||
262 | advanced features such as alpha channel or stereographic viewing. | - | ||||||||||||||||||
263 | If you request some features that the driver/hardware does not | - | ||||||||||||||||||
264 | provide when you create a QGLWidget, you will get a rendering | - | ||||||||||||||||||
265 | context with the nearest subset of features. | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | There are different ways to define the display characteristics of | - | ||||||||||||||||||
268 | a rendering context. One is to create a QGLFormat and make it the | - | ||||||||||||||||||
269 | default for the entire application: | - | ||||||||||||||||||
270 | \snippet code/src_opengl_qgl.cpp 0 | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | Or you can specify the desired format when creating an object of | - | ||||||||||||||||||
273 | your QGLWidget subclass: | - | ||||||||||||||||||
274 | \snippet code/src_opengl_qgl.cpp 1 | - | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | After the widget has been created, you can find out which of the | - | ||||||||||||||||||
277 | requested features the system was able to provide: | - | ||||||||||||||||||
278 | \snippet code/src_opengl_qgl.cpp 2 | - | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | \legalese | - | ||||||||||||||||||
281 | OpenGL is a trademark of Silicon Graphics, Inc. in the | - | ||||||||||||||||||
282 | United States and other countries. | - | ||||||||||||||||||
283 | \endlegalese | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | \sa QGLContext, QGLWidget | - | ||||||||||||||||||
286 | */ | - | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | static inline void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) | - | ||||||||||||||||||
291 | { | - | ||||||||||||||||||
292 | #define M(row,col) m[col*4+row] | - | ||||||||||||||||||
293 | out[0] = | - | ||||||||||||||||||
294 | M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; | - | ||||||||||||||||||
295 | out[1] = | - | ||||||||||||||||||
296 | M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3]; | - | ||||||||||||||||||
297 | out[2] = | - | ||||||||||||||||||
298 | M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3]; | - | ||||||||||||||||||
299 | out[3] = | - | ||||||||||||||||||
300 | M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3]; | - | ||||||||||||||||||
301 | #undef M | - | ||||||||||||||||||
302 | } never executed: end of block | 0 | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, | - | ||||||||||||||||||
305 | const GLdouble model[16], const GLdouble proj[16], | - | ||||||||||||||||||
306 | const GLint viewport[4], | - | ||||||||||||||||||
307 | GLdouble * winx, GLdouble * winy, GLdouble * winz) | - | ||||||||||||||||||
308 | { | - | ||||||||||||||||||
309 | GLdouble in[4], out[4]; | - | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | in[0] = objx; | - | ||||||||||||||||||
312 | in[1] = objy; | - | ||||||||||||||||||
313 | in[2] = objz; | - | ||||||||||||||||||
314 | in[3] = 1.0; | - | ||||||||||||||||||
315 | transform_point(out, model, in); | - | ||||||||||||||||||
316 | transform_point(in, proj, out); | - | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | if (in[3] == 0.0)
| 0 | ||||||||||||||||||
319 | return GL_FALSE; never executed: return 0; | 0 | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | in[0] /= in[3]; | - | ||||||||||||||||||
322 | in[1] /= in[3]; | - | ||||||||||||||||||
323 | in[2] /= in[3]; | - | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; | - | ||||||||||||||||||
326 | *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | *winz = (1 + in[2]) / 2; | - | ||||||||||||||||||
329 | return GL_TRUE; never executed: return 1; | 0 | ||||||||||||||||||
330 | } | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | #endif // !QT_OPENGL_ES | - | ||||||||||||||||||
333 | - | |||||||||||||||||||
334 | /*! | - | ||||||||||||||||||
335 | Constructs a QGLFormat object with the following default settings: | - | ||||||||||||||||||
336 | \list | - | ||||||||||||||||||
337 | \li \l{setDoubleBuffer()}{Double buffer:} Enabled. | - | ||||||||||||||||||
338 | \li \l{setDepth()}{Depth buffer:} Enabled. | - | ||||||||||||||||||
339 | \li \l{setRgba()}{RGBA:} Enabled (i.e., color index disabled). | - | ||||||||||||||||||
340 | \li \l{setAlpha()}{Alpha channel:} Disabled. | - | ||||||||||||||||||
341 | \li \l{setAccum()}{Accumulator buffer:} Disabled. | - | ||||||||||||||||||
342 | \li \l{setStencil()}{Stencil buffer:} Enabled. | - | ||||||||||||||||||
343 | \li \l{setStereo()}{Stereo:} Disabled. | - | ||||||||||||||||||
344 | \li \l{setDirectRendering()}{Direct rendering:} Enabled. | - | ||||||||||||||||||
345 | \li \l{setOverlay()}{Overlay:} Disabled. | - | ||||||||||||||||||
346 | \li \l{setPlane()}{Plane:} 0 (i.e., normal plane). | - | ||||||||||||||||||
347 | \li \l{setSampleBuffers()}{Multisample buffers:} Disabled. | - | ||||||||||||||||||
348 | \endlist | - | ||||||||||||||||||
349 | */ | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | QGLFormat::QGLFormat() | - | ||||||||||||||||||
352 | { | - | ||||||||||||||||||
353 | d = new QGLFormatPrivate; | - | ||||||||||||||||||
354 | } executed 39 times by 3 tests: end of block Executed by:
| 39 | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | - | |||||||||||||||||||
357 | /*! | - | ||||||||||||||||||
358 | Creates a QGLFormat object that is a copy of the current | - | ||||||||||||||||||
359 | defaultFormat(). | - | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | If \a options is not 0, the default format is modified by the | - | ||||||||||||||||||
362 | specified format options. The \a options parameter should be | - | ||||||||||||||||||
363 | QGL::FormatOption values OR'ed together. | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | This constructor makes it easy to specify a certain desired format | - | ||||||||||||||||||
366 | in classes derived from QGLWidget, for example: | - | ||||||||||||||||||
367 | \snippet code/src_opengl_qgl.cpp 3 | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | Note that there are QGL::FormatOption values to turn format settings | - | ||||||||||||||||||
370 | both on and off, e.g. QGL::DepthBuffer and QGL::NoDepthBuffer, | - | ||||||||||||||||||
371 | QGL::DirectRendering and QGL::IndirectRendering, etc. | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | The \a plane parameter defaults to 0 and is the plane which this | - | ||||||||||||||||||
374 | format should be associated with. Not all OpenGL implementations | - | ||||||||||||||||||
375 | supports overlay/underlay rendering planes. | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | \sa defaultFormat(), setOption(), setPlane() | - | ||||||||||||||||||
378 | */ | - | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | QGLFormat::QGLFormat(QGL::FormatOptions options, int plane) | - | ||||||||||||||||||
381 | { | - | ||||||||||||||||||
382 | d = new QGLFormatPrivate; | - | ||||||||||||||||||
383 | QGL::FormatOptions newOpts = options; | - | ||||||||||||||||||
384 | d->opts = defaultFormat().d->opts; | - | ||||||||||||||||||
385 | d->opts |= (newOpts & 0xffff); | - | ||||||||||||||||||
386 | d->opts &= ~(newOpts >> 16); | - | ||||||||||||||||||
387 | d->pln = plane; | - | ||||||||||||||||||
388 | } never executed: end of block | 0 | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | /*! | - | ||||||||||||||||||
391 | \internal | - | ||||||||||||||||||
392 | */ | - | ||||||||||||||||||
393 | void QGLFormat::detach() | - | ||||||||||||||||||
394 | { | - | ||||||||||||||||||
395 | if (d->ref.load() != 1) {
| 0-180 | ||||||||||||||||||
396 | QGLFormatPrivate *newd = new QGLFormatPrivate(d); | - | ||||||||||||||||||
397 | if (!d->ref.deref())
| 0 | ||||||||||||||||||
398 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
399 | d = newd; | - | ||||||||||||||||||
400 | } never executed: end of block | 0 | ||||||||||||||||||
401 | } executed 180 times by 3 tests: end of block Executed by:
| 180 | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | /*! | - | ||||||||||||||||||
404 | Constructs a copy of \a other. | - | ||||||||||||||||||
405 | */ | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | QGLFormat::QGLFormat(const QGLFormat &other) | - | ||||||||||||||||||
408 | { | - | ||||||||||||||||||
409 | d = other.d; | - | ||||||||||||||||||
410 | d->ref.ref(); | - | ||||||||||||||||||
411 | } executed 24 times by 3 tests: end of block Executed by:
| 24 | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | /*! | - | ||||||||||||||||||
414 | Assigns \a other to this object. | - | ||||||||||||||||||
415 | */ | - | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | QGLFormat &QGLFormat::operator=(const QGLFormat &other) | - | ||||||||||||||||||
418 | { | - | ||||||||||||||||||
419 | if (d != other.d) {
| 0-36 | ||||||||||||||||||
420 | other.d->ref.ref(); | - | ||||||||||||||||||
421 | if (!d->ref.deref())
| 12-24 | ||||||||||||||||||
422 | delete d; executed 24 times by 3 tests: delete d; Executed by:
| 24 | ||||||||||||||||||
423 | d = other.d; | - | ||||||||||||||||||
424 | } executed 36 times by 3 tests: end of block Executed by:
| 36 | ||||||||||||||||||
425 | return *this; executed 36 times by 3 tests: return *this; Executed by:
| 36 | ||||||||||||||||||
426 | } | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | /*! | - | ||||||||||||||||||
429 | Destroys the QGLFormat. | - | ||||||||||||||||||
430 | */ | - | ||||||||||||||||||
431 | QGLFormat::~QGLFormat() | - | ||||||||||||||||||
432 | { | - | ||||||||||||||||||
433 | if (!d->ref.deref())
| 15-48 | ||||||||||||||||||
434 | delete d; executed 15 times by 3 tests: delete d; Executed by:
| 15 | ||||||||||||||||||
435 | } executed 63 times by 3 tests: end of block Executed by:
| 63 | ||||||||||||||||||
436 | - | |||||||||||||||||||
437 | /*! | - | ||||||||||||||||||
438 | Returns an OpenGL format for the window format specified by \a format. | - | ||||||||||||||||||
439 | */ | - | ||||||||||||||||||
440 | QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format) | - | ||||||||||||||||||
441 | { | - | ||||||||||||||||||
442 | QGLFormat retFormat; | - | ||||||||||||||||||
443 | if (format.alphaBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
444 | retFormat.setAlphaBufferSize(format.alphaBufferSize()); executed 12 times by 3 tests: retFormat.setAlphaBufferSize(format.alphaBufferSize()); Executed by:
| 12 | ||||||||||||||||||
445 | if (format.blueBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
446 | retFormat.setBlueBufferSize(format.blueBufferSize()); executed 12 times by 3 tests: retFormat.setBlueBufferSize(format.blueBufferSize()); Executed by:
| 12 | ||||||||||||||||||
447 | if (format.greenBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
448 | retFormat.setGreenBufferSize(format.greenBufferSize()); executed 12 times by 3 tests: retFormat.setGreenBufferSize(format.greenBufferSize()); Executed by:
| 12 | ||||||||||||||||||
449 | if (format.redBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
450 | retFormat.setRedBufferSize(format.redBufferSize()); executed 12 times by 3 tests: retFormat.setRedBufferSize(format.redBufferSize()); Executed by:
| 12 | ||||||||||||||||||
451 | if (format.depthBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
452 | retFormat.setDepthBufferSize(format.depthBufferSize()); executed 12 times by 3 tests: retFormat.setDepthBufferSize(format.depthBufferSize()); Executed by:
| 12 | ||||||||||||||||||
453 | if (format.samples() > 1) {
| 0-12 | ||||||||||||||||||
454 | retFormat.setSampleBuffers(true); | - | ||||||||||||||||||
455 | retFormat.setSamples(format.samples()); | - | ||||||||||||||||||
456 | } never executed: end of block | 0 | ||||||||||||||||||
457 | if (format.stencilBufferSize() > 0) {
| 0-12 | ||||||||||||||||||
458 | retFormat.setStencil(true); | - | ||||||||||||||||||
459 | retFormat.setStencilBufferSize(format.stencilBufferSize()); | - | ||||||||||||||||||
460 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
461 | retFormat.setSwapInterval(format.swapInterval()); | - | ||||||||||||||||||
462 | retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer); | - | ||||||||||||||||||
463 | retFormat.setStereo(format.stereo()); | - | ||||||||||||||||||
464 | retFormat.setVersion(format.majorVersion(), format.minorVersion()); | - | ||||||||||||||||||
465 | retFormat.setProfile(static_cast<QGLFormat::OpenGLContextProfile>(format.profile())); | - | ||||||||||||||||||
466 | return retFormat; executed 12 times by 3 tests: return retFormat; Executed by:
| 12 | ||||||||||||||||||
467 | } | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | /*! | - | ||||||||||||||||||
470 | Returns a window format for the OpenGL format specified by \a format. | - | ||||||||||||||||||
471 | */ | - | ||||||||||||||||||
472 | QSurfaceFormat QGLFormat::toSurfaceFormat(const QGLFormat &format) | - | ||||||||||||||||||
473 | { | - | ||||||||||||||||||
474 | QSurfaceFormat retFormat; | - | ||||||||||||||||||
475 | if (format.alpha())
| 0-12 | ||||||||||||||||||
476 | retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); never executed: retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); | 0 | ||||||||||||||||||
477 | if (format.blueBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
478 | retFormat.setBlueBufferSize(format.blueBufferSize()); never executed: retFormat.setBlueBufferSize(format.blueBufferSize()); | 0 | ||||||||||||||||||
479 | if (format.greenBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
480 | retFormat.setGreenBufferSize(format.greenBufferSize()); never executed: retFormat.setGreenBufferSize(format.greenBufferSize()); | 0 | ||||||||||||||||||
481 | if (format.redBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
482 | retFormat.setRedBufferSize(format.redBufferSize()); never executed: retFormat.setRedBufferSize(format.redBufferSize()); | 0 | ||||||||||||||||||
483 | if (format.depth())
| 0-12 | ||||||||||||||||||
484 | retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); executed 12 times by 3 tests: retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); Executed by:
| 12 | ||||||||||||||||||
485 | retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::SingleBuffer); | - | ||||||||||||||||||
486 | if (format.sampleBuffers())
| 0-12 | ||||||||||||||||||
487 | retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); never executed: retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); | 0 | ||||||||||||||||||
488 | if (format.stencil())
| 0-12 | ||||||||||||||||||
489 | retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize()); executed 12 times by 3 tests: retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize()); Executed by:
| 12 | ||||||||||||||||||
490 | retFormat.setSwapInterval(format.swapInterval()); | - | ||||||||||||||||||
491 | retFormat.setStereo(format.stereo()); | - | ||||||||||||||||||
492 | retFormat.setMajorVersion(format.majorVersion()); | - | ||||||||||||||||||
493 | retFormat.setMinorVersion(format.minorVersion()); | - | ||||||||||||||||||
494 | retFormat.setProfile(static_cast<QSurfaceFormat::OpenGLContextProfile>(format.profile())); | - | ||||||||||||||||||
495 | // QGLFormat has no way to set DeprecatedFunctions, that is, to tell that forward | - | ||||||||||||||||||
496 | // compatibility should not be requested. Some drivers fail to ignore the fwdcompat | - | ||||||||||||||||||
497 | // bit with compatibility profiles so make sure it is not set. | - | ||||||||||||||||||
498 | if (format.profile() == QGLFormat::CompatibilityProfile)
| 0-12 | ||||||||||||||||||
499 | retFormat.setOption(QSurfaceFormat::DeprecatedFunctions); never executed: retFormat.setOption(QSurfaceFormat::DeprecatedFunctions); | 0 | ||||||||||||||||||
500 | return retFormat; executed 12 times by 3 tests: return retFormat; Executed by:
| 12 | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | void QGLContextPrivate::setupSharing() { | - | ||||||||||||||||||
504 | Q_Q(QGLContext); | - | ||||||||||||||||||
505 | QOpenGLContext *sharedContext = guiGlContext->shareContext(); | - | ||||||||||||||||||
506 | if (sharedContext) {
| 1-11 | ||||||||||||||||||
507 | QGLContext *actualSharedContext = QGLContext::fromOpenGLContext(sharedContext); | - | ||||||||||||||||||
508 | sharing = true; | - | ||||||||||||||||||
509 | QGLContextGroup::addShare(q, actualSharedContext); | - | ||||||||||||||||||
510 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
511 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | void QGLContextPrivate::refreshCurrentFbo() | - | ||||||||||||||||||
514 | { | - | ||||||||||||||||||
515 | QOpenGLContextPrivate *guiGlContextPrivate = | - | ||||||||||||||||||
516 | guiGlContext ? QOpenGLContextPrivate::get(guiGlContext) : 0;
| 0-32 | ||||||||||||||||||
517 | - | |||||||||||||||||||
518 | // if QOpenGLFramebufferObjects have been used in the mean-time, we've lost our cached value | - | ||||||||||||||||||
519 | if (guiGlContextPrivate && guiGlContextPrivate->qgl_current_fbo_invalid) {
| 0-32 | ||||||||||||||||||
520 | GLint current; | - | ||||||||||||||||||
521 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
522 | funcs->glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤t); | - | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | current_fbo = current; | - | ||||||||||||||||||
525 | - | |||||||||||||||||||
526 | guiGlContextPrivate->qgl_current_fbo_invalid = false; | - | ||||||||||||||||||
527 | } never executed: end of block | 0 | ||||||||||||||||||
528 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | void QGLContextPrivate::setCurrentFbo(GLuint fbo) | - | ||||||||||||||||||
531 | { | - | ||||||||||||||||||
532 | current_fbo = fbo; | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | QOpenGLContextPrivate *guiGlContextPrivate = | - | ||||||||||||||||||
535 | guiGlContext ? QOpenGLContextPrivate::get(guiGlContext) : 0;
| 0 | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | if (guiGlContextPrivate)
| 0 | ||||||||||||||||||
538 | guiGlContextPrivate->qgl_current_fbo_invalid = false; never executed: guiGlContextPrivate->qgl_current_fbo_invalid = false; | 0 | ||||||||||||||||||
539 | } never executed: end of block | 0 | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | - | |||||||||||||||||||
542 | /*! | - | ||||||||||||||||||
543 | \fn bool QGLFormat::doubleBuffer() const | - | ||||||||||||||||||
544 | - | |||||||||||||||||||
545 | Returns \c true if double buffering is enabled; otherwise returns | - | ||||||||||||||||||
546 | false. Double buffering is enabled by default. | - | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | \sa setDoubleBuffer() | - | ||||||||||||||||||
549 | */ | - | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | /*! | - | ||||||||||||||||||
552 | If \a enable is true sets double buffering; otherwise sets single | - | ||||||||||||||||||
553 | buffering. | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | Double buffering is enabled by default. | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | Double buffering is a technique where graphics are rendered on an | - | ||||||||||||||||||
558 | off-screen buffer and not directly to the screen. When the drawing | - | ||||||||||||||||||
559 | has been completed, the program calls a swapBuffers() function to | - | ||||||||||||||||||
560 | exchange the screen contents with the buffer. The result is | - | ||||||||||||||||||
561 | flicker-free drawing and often better performance. | - | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | Note that single buffered contexts are currently not supported | - | ||||||||||||||||||
564 | with EGL. | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | \sa doubleBuffer(), QGLContext::swapBuffers(), | - | ||||||||||||||||||
567 | QGLWidget::swapBuffers() | - | ||||||||||||||||||
568 | */ | - | ||||||||||||||||||
569 | - | |||||||||||||||||||
570 | void QGLFormat::setDoubleBuffer(bool enable) | - | ||||||||||||||||||
571 | { | - | ||||||||||||||||||
572 | setOption(enable ? QGL::DoubleBuffer : QGL::SingleBuffer); | - | ||||||||||||||||||
573 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
574 | - | |||||||||||||||||||
575 | - | |||||||||||||||||||
576 | /*! | - | ||||||||||||||||||
577 | \fn bool QGLFormat::depth() const | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | Returns \c true if the depth buffer is enabled; otherwise returns | - | ||||||||||||||||||
580 | false. The depth buffer is enabled by default. | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | \sa setDepth(), setDepthBufferSize() | - | ||||||||||||||||||
583 | */ | - | ||||||||||||||||||
584 | - | |||||||||||||||||||
585 | /*! | - | ||||||||||||||||||
586 | If \a enable is true enables the depth buffer; otherwise disables | - | ||||||||||||||||||
587 | the depth buffer. | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | The depth buffer is enabled by default. | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | The purpose of a depth buffer (or Z-buffering) is to remove hidden | - | ||||||||||||||||||
592 | surfaces. Pixels are assigned Z values based on the distance to | - | ||||||||||||||||||
593 | the viewer. A pixel with a high Z value is closer to the viewer | - | ||||||||||||||||||
594 | than a pixel with a low Z value. This information is used to | - | ||||||||||||||||||
595 | decide whether to draw a pixel or not. | - | ||||||||||||||||||
596 | - | |||||||||||||||||||
597 | \sa depth(), setDepthBufferSize() | - | ||||||||||||||||||
598 | */ | - | ||||||||||||||||||
599 | - | |||||||||||||||||||
600 | void QGLFormat::setDepth(bool enable) | - | ||||||||||||||||||
601 | { | - | ||||||||||||||||||
602 | setOption(enable ? QGL::DepthBuffer : QGL::NoDepthBuffer); | - | ||||||||||||||||||
603 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | - | |||||||||||||||||||
606 | /*! | - | ||||||||||||||||||
607 | \fn bool QGLFormat::rgba() const | - | ||||||||||||||||||
608 | - | |||||||||||||||||||
609 | Returns \c true if RGBA color mode is set. Returns \c false if color | - | ||||||||||||||||||
610 | index mode is set. The default color mode is RGBA. | - | ||||||||||||||||||
611 | - | |||||||||||||||||||
612 | \sa setRgba() | - | ||||||||||||||||||
613 | */ | - | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | /*! | - | ||||||||||||||||||
616 | If \a enable is true sets RGBA mode. If \a enable is false sets | - | ||||||||||||||||||
617 | color index mode. | - | ||||||||||||||||||
618 | - | |||||||||||||||||||
619 | The default color mode is RGBA. | - | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | RGBA is the preferred mode for most OpenGL applications. In RGBA | - | ||||||||||||||||||
622 | color mode you specify colors as red + green + blue + alpha | - | ||||||||||||||||||
623 | quadruplets. | - | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | In color index mode you specify an index into a color lookup | - | ||||||||||||||||||
626 | table. | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | \sa rgba() | - | ||||||||||||||||||
629 | */ | - | ||||||||||||||||||
630 | - | |||||||||||||||||||
631 | void QGLFormat::setRgba(bool enable) | - | ||||||||||||||||||
632 | { | - | ||||||||||||||||||
633 | setOption(enable ? QGL::Rgba : QGL::ColorIndex); | - | ||||||||||||||||||
634 | } never executed: end of block | 0 | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | - | |||||||||||||||||||
637 | /*! | - | ||||||||||||||||||
638 | \fn bool QGLFormat::alpha() const | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | Returns \c true if the alpha buffer in the framebuffer is enabled; | - | ||||||||||||||||||
641 | otherwise returns \c false. The alpha buffer is disabled by default. | - | ||||||||||||||||||
642 | - | |||||||||||||||||||
643 | \sa setAlpha(), setAlphaBufferSize() | - | ||||||||||||||||||
644 | */ | - | ||||||||||||||||||
645 | - | |||||||||||||||||||
646 | /*! | - | ||||||||||||||||||
647 | If \a enable is true enables the alpha buffer; otherwise disables | - | ||||||||||||||||||
648 | the alpha buffer. | - | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | The alpha buffer is disabled by default. | - | ||||||||||||||||||
651 | - | |||||||||||||||||||
652 | The alpha buffer is typically used for implementing transparency | - | ||||||||||||||||||
653 | or translucency. The A in RGBA specifies the transparency of a | - | ||||||||||||||||||
654 | pixel. | - | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | \sa alpha(), setAlphaBufferSize() | - | ||||||||||||||||||
657 | */ | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | void QGLFormat::setAlpha(bool enable) | - | ||||||||||||||||||
660 | { | - | ||||||||||||||||||
661 | setOption(enable ? QGL::AlphaChannel : QGL::NoAlphaChannel); | - | ||||||||||||||||||
662 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | - | |||||||||||||||||||
665 | /*! | - | ||||||||||||||||||
666 | \fn bool QGLFormat::accum() const | - | ||||||||||||||||||
667 | - | |||||||||||||||||||
668 | Returns \c true if the accumulation buffer is enabled; otherwise | - | ||||||||||||||||||
669 | returns \c false. The accumulation buffer is disabled by default. | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | \sa setAccum(), setAccumBufferSize() | - | ||||||||||||||||||
672 | */ | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | /*! | - | ||||||||||||||||||
675 | If \a enable is true enables the accumulation buffer; otherwise | - | ||||||||||||||||||
676 | disables the accumulation buffer. | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | The accumulation buffer is disabled by default. | - | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | The accumulation buffer is used to create blur effects and | - | ||||||||||||||||||
681 | multiple exposures. | - | ||||||||||||||||||
682 | - | |||||||||||||||||||
683 | \sa accum(), setAccumBufferSize() | - | ||||||||||||||||||
684 | */ | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | void QGLFormat::setAccum(bool enable) | - | ||||||||||||||||||
687 | { | - | ||||||||||||||||||
688 | setOption(enable ? QGL::AccumBuffer : QGL::NoAccumBuffer); | - | ||||||||||||||||||
689 | } never executed: end of block | 0 | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | - | |||||||||||||||||||
692 | /*! | - | ||||||||||||||||||
693 | \fn bool QGLFormat::stencil() const | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | Returns \c true if the stencil buffer is enabled; otherwise returns | - | ||||||||||||||||||
696 | false. The stencil buffer is enabled by default. | - | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | \sa setStencil(), setStencilBufferSize() | - | ||||||||||||||||||
699 | */ | - | ||||||||||||||||||
700 | - | |||||||||||||||||||
701 | /*! | - | ||||||||||||||||||
702 | If \a enable is true enables the stencil buffer; otherwise | - | ||||||||||||||||||
703 | disables the stencil buffer. | - | ||||||||||||||||||
704 | - | |||||||||||||||||||
705 | The stencil buffer is enabled by default. | - | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | The stencil buffer masks certain parts of the drawing area so that | - | ||||||||||||||||||
708 | masked parts are not drawn on. | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | \sa stencil(), setStencilBufferSize() | - | ||||||||||||||||||
711 | */ | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | void QGLFormat::setStencil(bool enable) | - | ||||||||||||||||||
714 | { | - | ||||||||||||||||||
715 | setOption(enable ? QGL::StencilBuffer: QGL::NoStencilBuffer); | - | ||||||||||||||||||
716 | } executed 24 times by 3 tests: end of block Executed by:
| 24 | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | - | |||||||||||||||||||
719 | /*! | - | ||||||||||||||||||
720 | \fn bool QGLFormat::stereo() const | - | ||||||||||||||||||
721 | - | |||||||||||||||||||
722 | Returns \c true if stereo buffering is enabled; otherwise returns | - | ||||||||||||||||||
723 | false. Stereo buffering is disabled by default. | - | ||||||||||||||||||
724 | - | |||||||||||||||||||
725 | \sa setStereo() | - | ||||||||||||||||||
726 | */ | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | /*! | - | ||||||||||||||||||
729 | If \a enable is true enables stereo buffering; otherwise disables | - | ||||||||||||||||||
730 | stereo buffering. | - | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | Stereo buffering is disabled by default. | - | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | Stereo buffering provides extra color buffers to generate left-eye | - | ||||||||||||||||||
735 | and right-eye images. | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | \sa stereo() | - | ||||||||||||||||||
738 | */ | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | void QGLFormat::setStereo(bool enable) | - | ||||||||||||||||||
741 | { | - | ||||||||||||||||||
742 | setOption(enable ? QGL::StereoBuffers : QGL::NoStereoBuffers); | - | ||||||||||||||||||
743 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | - | |||||||||||||||||||
746 | /*! | - | ||||||||||||||||||
747 | \fn bool QGLFormat::directRendering() const | - | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | Returns \c true if direct rendering is enabled; otherwise returns | - | ||||||||||||||||||
750 | false. | - | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | Direct rendering is enabled by default. | - | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | \sa setDirectRendering() | - | ||||||||||||||||||
755 | */ | - | ||||||||||||||||||
756 | - | |||||||||||||||||||
757 | /*! | - | ||||||||||||||||||
758 | If \a enable is true enables direct rendering; otherwise disables | - | ||||||||||||||||||
759 | direct rendering. | - | ||||||||||||||||||
760 | - | |||||||||||||||||||
761 | Direct rendering is enabled by default. | - | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | Enabling this option will make OpenGL bypass the underlying window | - | ||||||||||||||||||
764 | system and render directly from hardware to the screen, if this is | - | ||||||||||||||||||
765 | supported by the system. | - | ||||||||||||||||||
766 | - | |||||||||||||||||||
767 | \sa directRendering() | - | ||||||||||||||||||
768 | */ | - | ||||||||||||||||||
769 | - | |||||||||||||||||||
770 | void QGLFormat::setDirectRendering(bool enable) | - | ||||||||||||||||||
771 | { | - | ||||||||||||||||||
772 | setOption(enable ? QGL::DirectRendering : QGL::IndirectRendering); | - | ||||||||||||||||||
773 | } never executed: end of block | 0 | ||||||||||||||||||
774 | - | |||||||||||||||||||
775 | /*! | - | ||||||||||||||||||
776 | \fn bool QGLFormat::sampleBuffers() const | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | Returns \c true if multisample buffer support is enabled; otherwise | - | ||||||||||||||||||
779 | returns \c false. | - | ||||||||||||||||||
780 | - | |||||||||||||||||||
781 | The multisample buffer is disabled by default. | - | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | \sa setSampleBuffers() | - | ||||||||||||||||||
784 | */ | - | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | /*! | - | ||||||||||||||||||
787 | If \a enable is true, a GL context with multisample buffer support | - | ||||||||||||||||||
788 | is picked; otherwise ignored. | - | ||||||||||||||||||
789 | - | |||||||||||||||||||
790 | \sa sampleBuffers(), setSamples(), samples() | - | ||||||||||||||||||
791 | */ | - | ||||||||||||||||||
792 | void QGLFormat::setSampleBuffers(bool enable) | - | ||||||||||||||||||
793 | { | - | ||||||||||||||||||
794 | setOption(enable ? QGL::SampleBuffers : QGL::NoSampleBuffers); | - | ||||||||||||||||||
795 | } never executed: end of block | 0 | ||||||||||||||||||
796 | - | |||||||||||||||||||
797 | /*! | - | ||||||||||||||||||
798 | Returns the number of samples per pixel when multisampling is | - | ||||||||||||||||||
799 | enabled. By default, the highest number of samples that is | - | ||||||||||||||||||
800 | available is used. | - | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | \sa setSampleBuffers(), sampleBuffers(), setSamples() | - | ||||||||||||||||||
803 | */ | - | ||||||||||||||||||
804 | int QGLFormat::samples() const | - | ||||||||||||||||||
805 | { | - | ||||||||||||||||||
806 | return d->numSamples; never executed: return d->numSamples; | 0 | ||||||||||||||||||
807 | } | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | /*! | - | ||||||||||||||||||
810 | Set the preferred number of samples per pixel when multisampling | - | ||||||||||||||||||
811 | is enabled to \a numSamples. By default, the highest number of | - | ||||||||||||||||||
812 | samples available is used. | - | ||||||||||||||||||
813 | - | |||||||||||||||||||
814 | \sa setSampleBuffers(), sampleBuffers(), samples() | - | ||||||||||||||||||
815 | */ | - | ||||||||||||||||||
816 | void QGLFormat::setSamples(int numSamples) | - | ||||||||||||||||||
817 | { | - | ||||||||||||||||||
818 | detach(); | - | ||||||||||||||||||
819 | if (numSamples < 0) {
| 0 | ||||||||||||||||||
820 | qWarning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); | - | ||||||||||||||||||
821 | return; never executed: return; | 0 | ||||||||||||||||||
822 | } | - | ||||||||||||||||||
823 | d->numSamples = numSamples; | - | ||||||||||||||||||
824 | setSampleBuffers(numSamples > 0); | - | ||||||||||||||||||
825 | } never executed: end of block | 0 | ||||||||||||||||||
826 | - | |||||||||||||||||||
827 | /*! | - | ||||||||||||||||||
828 | \since 4.2 | - | ||||||||||||||||||
829 | - | |||||||||||||||||||
830 | Set the preferred swap interval. This can be used to sync the GL | - | ||||||||||||||||||
831 | drawing into a system window to the vertical refresh of the screen. | - | ||||||||||||||||||
832 | Setting an \a interval value of 0 will turn the vertical refresh syncing | - | ||||||||||||||||||
833 | off, any value higher than 0 will turn the vertical syncing on. | - | ||||||||||||||||||
834 | - | |||||||||||||||||||
835 | Under Windows and under X11, where the \c{WGL_EXT_swap_control} | - | ||||||||||||||||||
836 | and \c{GLX_SGI_video_sync} extensions are used, the \a interval | - | ||||||||||||||||||
837 | parameter can be used to set the minimum number of video frames | - | ||||||||||||||||||
838 | that are displayed before a buffer swap will occur. In effect, | - | ||||||||||||||||||
839 | setting the \a interval to 10, means there will be 10 vertical | - | ||||||||||||||||||
840 | retraces between every buffer swap. | - | ||||||||||||||||||
841 | - | |||||||||||||||||||
842 | Under Windows the \c{WGL_EXT_swap_control} extension has to be present, | - | ||||||||||||||||||
843 | and under X11 the \c{GLX_SGI_video_sync} extension has to be present. | - | ||||||||||||||||||
844 | */ | - | ||||||||||||||||||
845 | void QGLFormat::setSwapInterval(int interval) | - | ||||||||||||||||||
846 | { | - | ||||||||||||||||||
847 | detach(); | - | ||||||||||||||||||
848 | d->swapInterval = interval; | - | ||||||||||||||||||
849 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | /*! | - | ||||||||||||||||||
852 | \since 4.2 | - | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | Returns the currently set swap interval. -1 is returned if setting | - | ||||||||||||||||||
855 | the swap interval isn't supported in the system GL implementation. | - | ||||||||||||||||||
856 | */ | - | ||||||||||||||||||
857 | int QGLFormat::swapInterval() const | - | ||||||||||||||||||
858 | { | - | ||||||||||||||||||
859 | return d->swapInterval; executed 12 times by 3 tests: return d->swapInterval; Executed by:
| 12 | ||||||||||||||||||
860 | } | - | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | /*! | - | ||||||||||||||||||
863 | \fn bool QGLFormat::hasOverlay() const | - | ||||||||||||||||||
864 | - | |||||||||||||||||||
865 | Returns \c true if overlay plane is enabled; otherwise returns \c false. | - | ||||||||||||||||||
866 | - | |||||||||||||||||||
867 | Overlay is disabled by default. | - | ||||||||||||||||||
868 | - | |||||||||||||||||||
869 | \sa setOverlay() | - | ||||||||||||||||||
870 | */ | - | ||||||||||||||||||
871 | - | |||||||||||||||||||
872 | /*! | - | ||||||||||||||||||
873 | If \a enable is true enables an overlay plane; otherwise disables | - | ||||||||||||||||||
874 | the overlay plane. | - | ||||||||||||||||||
875 | - | |||||||||||||||||||
876 | Enabling the overlay plane will cause QGLWidget to create an | - | ||||||||||||||||||
877 | additional context in an overlay plane. See the QGLWidget | - | ||||||||||||||||||
878 | documentation for further information. | - | ||||||||||||||||||
879 | - | |||||||||||||||||||
880 | \sa hasOverlay() | - | ||||||||||||||||||
881 | */ | - | ||||||||||||||||||
882 | - | |||||||||||||||||||
883 | void QGLFormat::setOverlay(bool enable) | - | ||||||||||||||||||
884 | { | - | ||||||||||||||||||
885 | setOption(enable ? QGL::HasOverlay : QGL::NoOverlay); | - | ||||||||||||||||||
886 | } never executed: end of block | 0 | ||||||||||||||||||
887 | - | |||||||||||||||||||
888 | /*! | - | ||||||||||||||||||
889 | Returns the plane of this format. The default for normal formats | - | ||||||||||||||||||
890 | is 0, which means the normal plane. The default for overlay | - | ||||||||||||||||||
891 | formats is 1, which is the first overlay plane. | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | \sa setPlane(), defaultOverlayFormat() | - | ||||||||||||||||||
894 | */ | - | ||||||||||||||||||
895 | int QGLFormat::plane() const | - | ||||||||||||||||||
896 | { | - | ||||||||||||||||||
897 | return d->pln; never executed: return d->pln; | 0 | ||||||||||||||||||
898 | } | - | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | /*! | - | ||||||||||||||||||
901 | Sets the requested plane to \a plane. 0 is the normal plane, 1 is | - | ||||||||||||||||||
902 | the first overlay plane, 2 is the second overlay plane, etc.; -1, | - | ||||||||||||||||||
903 | -2, etc. are underlay planes. | - | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | Note that in contrast to other format specifications, the plane | - | ||||||||||||||||||
906 | specifications will be matched exactly. This means that if you | - | ||||||||||||||||||
907 | specify a plane that the underlying OpenGL system cannot provide, | - | ||||||||||||||||||
908 | an \l{QGLWidget::isValid()}{invalid} QGLWidget will be | - | ||||||||||||||||||
909 | created. | - | ||||||||||||||||||
910 | - | |||||||||||||||||||
911 | \sa plane() | - | ||||||||||||||||||
912 | */ | - | ||||||||||||||||||
913 | void QGLFormat::setPlane(int plane) | - | ||||||||||||||||||
914 | { | - | ||||||||||||||||||
915 | detach(); | - | ||||||||||||||||||
916 | d->pln = plane; | - | ||||||||||||||||||
917 | } never executed: end of block | 0 | ||||||||||||||||||
918 | - | |||||||||||||||||||
919 | /*! | - | ||||||||||||||||||
920 | Sets the format option to \a opt. | - | ||||||||||||||||||
921 | - | |||||||||||||||||||
922 | \sa testOption() | - | ||||||||||||||||||
923 | */ | - | ||||||||||||||||||
924 | - | |||||||||||||||||||
925 | void QGLFormat::setOption(QGL::FormatOptions opt) | - | ||||||||||||||||||
926 | { | - | ||||||||||||||||||
927 | detach(); | - | ||||||||||||||||||
928 | if (opt & 0xffff)
| 24-48 | ||||||||||||||||||
929 | d->opts |= opt; executed 48 times by 3 tests: d->opts |= opt; Executed by:
| 48 | ||||||||||||||||||
930 | else | - | ||||||||||||||||||
931 | d->opts &= ~(opt >> 16); executed 24 times by 3 tests: d->opts &= ~(opt >> 16); Executed by:
| 24 | ||||||||||||||||||
932 | } | - | ||||||||||||||||||
933 | - | |||||||||||||||||||
934 | - | |||||||||||||||||||
935 | - | |||||||||||||||||||
936 | /*! | - | ||||||||||||||||||
937 | Returns \c true if format option \a opt is set; otherwise returns \c false. | - | ||||||||||||||||||
938 | - | |||||||||||||||||||
939 | \sa setOption() | - | ||||||||||||||||||
940 | */ | - | ||||||||||||||||||
941 | - | |||||||||||||||||||
942 | bool QGLFormat::testOption(QGL::FormatOptions opt) const | - | ||||||||||||||||||
943 | { | - | ||||||||||||||||||
944 | if (opt & 0xffff)
| 0-84 | ||||||||||||||||||
945 | return (d->opts & opt) != 0; executed 84 times by 3 tests: return (d->opts & opt) != 0; Executed by:
| 84 | ||||||||||||||||||
946 | else | - | ||||||||||||||||||
947 | return (d->opts & (opt >> 16)) == 0; never executed: return (d->opts & (opt >> 16)) == 0; | 0 | ||||||||||||||||||
948 | } | - | ||||||||||||||||||
949 | - | |||||||||||||||||||
950 | /*! | - | ||||||||||||||||||
951 | Set the minimum depth buffer size to \a size. | - | ||||||||||||||||||
952 | - | |||||||||||||||||||
953 | \sa depthBufferSize(), setDepth(), depth() | - | ||||||||||||||||||
954 | */ | - | ||||||||||||||||||
955 | void QGLFormat::setDepthBufferSize(int size) | - | ||||||||||||||||||
956 | { | - | ||||||||||||||||||
957 | detach(); | - | ||||||||||||||||||
958 | if (size < 0) {
| 0-12 | ||||||||||||||||||
959 | qWarning("QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); | - | ||||||||||||||||||
960 | return; never executed: return; | 0 | ||||||||||||||||||
961 | } | - | ||||||||||||||||||
962 | d->depthSize = size; | - | ||||||||||||||||||
963 | setDepth(size > 0); | - | ||||||||||||||||||
964 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
965 | - | |||||||||||||||||||
966 | /*! | - | ||||||||||||||||||
967 | Returns the depth buffer size. | - | ||||||||||||||||||
968 | - | |||||||||||||||||||
969 | \sa depth(), setDepth(), setDepthBufferSize() | - | ||||||||||||||||||
970 | */ | - | ||||||||||||||||||
971 | int QGLFormat::depthBufferSize() const | - | ||||||||||||||||||
972 | { | - | ||||||||||||||||||
973 | return d->depthSize; executed 12 times by 3 tests: return d->depthSize; Executed by:
| 12 | ||||||||||||||||||
974 | } | - | ||||||||||||||||||
975 | - | |||||||||||||||||||
976 | /*! | - | ||||||||||||||||||
977 | \since 4.2 | - | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | Set the preferred red buffer size to \a size. | - | ||||||||||||||||||
980 | - | |||||||||||||||||||
981 | \sa setGreenBufferSize(), setBlueBufferSize(), setAlphaBufferSize() | - | ||||||||||||||||||
982 | */ | - | ||||||||||||||||||
983 | void QGLFormat::setRedBufferSize(int size) | - | ||||||||||||||||||
984 | { | - | ||||||||||||||||||
985 | detach(); | - | ||||||||||||||||||
986 | if (size < 0) {
| 0-12 | ||||||||||||||||||
987 | qWarning("QGLFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); | - | ||||||||||||||||||
988 | return; never executed: return; | 0 | ||||||||||||||||||
989 | } | - | ||||||||||||||||||
990 | d->redSize = size; | - | ||||||||||||||||||
991 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
992 | - | |||||||||||||||||||
993 | /*! | - | ||||||||||||||||||
994 | \since 4.2 | - | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | Returns the red buffer size. | - | ||||||||||||||||||
997 | - | |||||||||||||||||||
998 | \sa setRedBufferSize() | - | ||||||||||||||||||
999 | */ | - | ||||||||||||||||||
1000 | int QGLFormat::redBufferSize() const | - | ||||||||||||||||||
1001 | { | - | ||||||||||||||||||
1002 | return d->redSize; executed 12 times by 3 tests: return d->redSize; Executed by:
| 12 | ||||||||||||||||||
1003 | } | - | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | /*! | - | ||||||||||||||||||
1006 | \since 4.2 | - | ||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | Set the preferred green buffer size to \a size. | - | ||||||||||||||||||
1009 | - | |||||||||||||||||||
1010 | \sa setRedBufferSize(), setBlueBufferSize(), setAlphaBufferSize() | - | ||||||||||||||||||
1011 | */ | - | ||||||||||||||||||
1012 | void QGLFormat::setGreenBufferSize(int size) | - | ||||||||||||||||||
1013 | { | - | ||||||||||||||||||
1014 | detach(); | - | ||||||||||||||||||
1015 | if (size < 0) {
| 0-12 | ||||||||||||||||||
1016 | qWarning("QGLFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); | - | ||||||||||||||||||
1017 | return; never executed: return; | 0 | ||||||||||||||||||
1018 | } | - | ||||||||||||||||||
1019 | d->greenSize = size; | - | ||||||||||||||||||
1020 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1021 | - | |||||||||||||||||||
1022 | /*! | - | ||||||||||||||||||
1023 | \since 4.2 | - | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | Returns the green buffer size. | - | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | \sa setGreenBufferSize() | - | ||||||||||||||||||
1028 | */ | - | ||||||||||||||||||
1029 | int QGLFormat::greenBufferSize() const | - | ||||||||||||||||||
1030 | { | - | ||||||||||||||||||
1031 | return d->greenSize; executed 12 times by 3 tests: return d->greenSize; Executed by:
| 12 | ||||||||||||||||||
1032 | } | - | ||||||||||||||||||
1033 | - | |||||||||||||||||||
1034 | /*! | - | ||||||||||||||||||
1035 | \since 4.2 | - | ||||||||||||||||||
1036 | - | |||||||||||||||||||
1037 | Set the preferred blue buffer size to \a size. | - | ||||||||||||||||||
1038 | - | |||||||||||||||||||
1039 | \sa setRedBufferSize(), setGreenBufferSize(), setAlphaBufferSize() | - | ||||||||||||||||||
1040 | */ | - | ||||||||||||||||||
1041 | void QGLFormat::setBlueBufferSize(int size) | - | ||||||||||||||||||
1042 | { | - | ||||||||||||||||||
1043 | detach(); | - | ||||||||||||||||||
1044 | if (size < 0) {
| 0-12 | ||||||||||||||||||
1045 | qWarning("QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); | - | ||||||||||||||||||
1046 | return; never executed: return; | 0 | ||||||||||||||||||
1047 | } | - | ||||||||||||||||||
1048 | d->blueSize = size; | - | ||||||||||||||||||
1049 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | /*! | - | ||||||||||||||||||
1052 | \since 4.2 | - | ||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | Returns the blue buffer size. | - | ||||||||||||||||||
1055 | - | |||||||||||||||||||
1056 | \sa setBlueBufferSize() | - | ||||||||||||||||||
1057 | */ | - | ||||||||||||||||||
1058 | int QGLFormat::blueBufferSize() const | - | ||||||||||||||||||
1059 | { | - | ||||||||||||||||||
1060 | return d->blueSize; executed 12 times by 3 tests: return d->blueSize; Executed by:
| 12 | ||||||||||||||||||
1061 | } | - | ||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | /*! | - | ||||||||||||||||||
1064 | Set the preferred alpha buffer size to \a size. | - | ||||||||||||||||||
1065 | This function implicitly enables the alpha channel. | - | ||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | \sa setRedBufferSize(), setGreenBufferSize(), alphaBufferSize() | - | ||||||||||||||||||
1068 | */ | - | ||||||||||||||||||
1069 | void QGLFormat::setAlphaBufferSize(int size) | - | ||||||||||||||||||
1070 | { | - | ||||||||||||||||||
1071 | detach(); | - | ||||||||||||||||||
1072 | if (size < 0) {
| 0-12 | ||||||||||||||||||
1073 | qWarning("QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); | - | ||||||||||||||||||
1074 | return; never executed: return; | 0 | ||||||||||||||||||
1075 | } | - | ||||||||||||||||||
1076 | d->alphaSize = size; | - | ||||||||||||||||||
1077 | setAlpha(size > 0); | - | ||||||||||||||||||
1078 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1079 | - | |||||||||||||||||||
1080 | /*! | - | ||||||||||||||||||
1081 | Returns the alpha buffer size. | - | ||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | \sa alpha(), setAlpha(), setAlphaBufferSize() | - | ||||||||||||||||||
1084 | */ | - | ||||||||||||||||||
1085 | int QGLFormat::alphaBufferSize() const | - | ||||||||||||||||||
1086 | { | - | ||||||||||||||||||
1087 | return d->alphaSize; never executed: return d->alphaSize; | 0 | ||||||||||||||||||
1088 | } | - | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | /*! | - | ||||||||||||||||||
1091 | Set the preferred accumulation buffer size, where \a size is the | - | ||||||||||||||||||
1092 | bit depth for each RGBA component. | - | ||||||||||||||||||
1093 | - | |||||||||||||||||||
1094 | \sa accum(), setAccum(), accumBufferSize() | - | ||||||||||||||||||
1095 | */ | - | ||||||||||||||||||
1096 | void QGLFormat::setAccumBufferSize(int size) | - | ||||||||||||||||||
1097 | { | - | ||||||||||||||||||
1098 | detach(); | - | ||||||||||||||||||
1099 | if (size < 0) {
| 0 | ||||||||||||||||||
1100 | qWarning("QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); | - | ||||||||||||||||||
1101 | return; never executed: return; | 0 | ||||||||||||||||||
1102 | } | - | ||||||||||||||||||
1103 | d->accumSize = size; | - | ||||||||||||||||||
1104 | setAccum(size > 0); | - | ||||||||||||||||||
1105 | } never executed: end of block | 0 | ||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | /*! | - | ||||||||||||||||||
1108 | Returns the accumulation buffer size. | - | ||||||||||||||||||
1109 | - | |||||||||||||||||||
1110 | \sa setAccumBufferSize(), accum(), setAccum() | - | ||||||||||||||||||
1111 | */ | - | ||||||||||||||||||
1112 | int QGLFormat::accumBufferSize() const | - | ||||||||||||||||||
1113 | { | - | ||||||||||||||||||
1114 | return d->accumSize; never executed: return d->accumSize; | 0 | ||||||||||||||||||
1115 | } | - | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | /*! | - | ||||||||||||||||||
1118 | Set the preferred stencil buffer size to \a size. | - | ||||||||||||||||||
1119 | - | |||||||||||||||||||
1120 | \sa stencilBufferSize(), setStencil(), stencil() | - | ||||||||||||||||||
1121 | */ | - | ||||||||||||||||||
1122 | void QGLFormat::setStencilBufferSize(int size) | - | ||||||||||||||||||
1123 | { | - | ||||||||||||||||||
1124 | detach(); | - | ||||||||||||||||||
1125 | if (size < 0) {
| 0-12 | ||||||||||||||||||
1126 | qWarning("QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); | - | ||||||||||||||||||
1127 | return; never executed: return; | 0 | ||||||||||||||||||
1128 | } | - | ||||||||||||||||||
1129 | d->stencilSize = size; | - | ||||||||||||||||||
1130 | setStencil(size > 0); | - | ||||||||||||||||||
1131 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | /*! | - | ||||||||||||||||||
1134 | Returns the stencil buffer size. | - | ||||||||||||||||||
1135 | - | |||||||||||||||||||
1136 | \sa stencil(), setStencil(), setStencilBufferSize() | - | ||||||||||||||||||
1137 | */ | - | ||||||||||||||||||
1138 | int QGLFormat::stencilBufferSize() const | - | ||||||||||||||||||
1139 | { | - | ||||||||||||||||||
1140 | return d->stencilSize; executed 12 times by 3 tests: return d->stencilSize; Executed by:
| 12 | ||||||||||||||||||
1141 | } | - | ||||||||||||||||||
1142 | - | |||||||||||||||||||
1143 | /*! | - | ||||||||||||||||||
1144 | \since 4.7 | - | ||||||||||||||||||
1145 | - | |||||||||||||||||||
1146 | Set the OpenGL version to the \a major and \a minor numbers. If a | - | ||||||||||||||||||
1147 | context compatible with the requested OpenGL version cannot be | - | ||||||||||||||||||
1148 | created, a context compatible with version 1.x is created instead. | - | ||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | \sa majorVersion(), minorVersion() | - | ||||||||||||||||||
1151 | */ | - | ||||||||||||||||||
1152 | void QGLFormat::setVersion(int major, int minor) | - | ||||||||||||||||||
1153 | { | - | ||||||||||||||||||
1154 | if (major < 1 || minor < 0) {
| 0-12 | ||||||||||||||||||
1155 | qWarning("QGLFormat::setVersion: Cannot set zero or negative version number %d.%d", major, minor); | - | ||||||||||||||||||
1156 | return; never executed: return; | 0 | ||||||||||||||||||
1157 | } | - | ||||||||||||||||||
1158 | detach(); | - | ||||||||||||||||||
1159 | d->majorVersion = major; | - | ||||||||||||||||||
1160 | d->minorVersion = minor; | - | ||||||||||||||||||
1161 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1162 | - | |||||||||||||||||||
1163 | /*! | - | ||||||||||||||||||
1164 | \since 4.7 | - | ||||||||||||||||||
1165 | - | |||||||||||||||||||
1166 | Returns the OpenGL major version. | - | ||||||||||||||||||
1167 | - | |||||||||||||||||||
1168 | \sa setVersion(), minorVersion() | - | ||||||||||||||||||
1169 | */ | - | ||||||||||||||||||
1170 | int QGLFormat::majorVersion() const | - | ||||||||||||||||||
1171 | { | - | ||||||||||||||||||
1172 | return d->majorVersion; executed 12 times by 3 tests: return d->majorVersion; Executed by:
| 12 | ||||||||||||||||||
1173 | } | - | ||||||||||||||||||
1174 | - | |||||||||||||||||||
1175 | /*! | - | ||||||||||||||||||
1176 | \since 4.7 | - | ||||||||||||||||||
1177 | - | |||||||||||||||||||
1178 | Returns the OpenGL minor version. | - | ||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | \sa setVersion(), majorVersion() | - | ||||||||||||||||||
1181 | */ | - | ||||||||||||||||||
1182 | int QGLFormat::minorVersion() const | - | ||||||||||||||||||
1183 | { | - | ||||||||||||||||||
1184 | return d->minorVersion; executed 12 times by 3 tests: return d->minorVersion; Executed by:
| 12 | ||||||||||||||||||
1185 | } | - | ||||||||||||||||||
1186 | - | |||||||||||||||||||
1187 | /*! | - | ||||||||||||||||||
1188 | \enum QGLFormat::OpenGLContextProfile | - | ||||||||||||||||||
1189 | \since 4.7 | - | ||||||||||||||||||
1190 | - | |||||||||||||||||||
1191 | This enum describes the OpenGL context profiles that can be | - | ||||||||||||||||||
1192 | specified for contexts implementing OpenGL version 3.2 or | - | ||||||||||||||||||
1193 | higher. These profiles are different from OpenGL ES profiles. | - | ||||||||||||||||||
1194 | - | |||||||||||||||||||
1195 | \value NoProfile OpenGL version is lower than 3.2. | - | ||||||||||||||||||
1196 | \value CoreProfile Functionality deprecated in OpenGL version 3.0 is not available. | - | ||||||||||||||||||
1197 | \value CompatibilityProfile Functionality from earlier OpenGL versions is available. | - | ||||||||||||||||||
1198 | */ | - | ||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | /*! | - | ||||||||||||||||||
1201 | \since 4.7 | - | ||||||||||||||||||
1202 | - | |||||||||||||||||||
1203 | Set the OpenGL context profile to \a profile. The \a profile is | - | ||||||||||||||||||
1204 | ignored if the requested OpenGL version is less than 3.2. | - | ||||||||||||||||||
1205 | - | |||||||||||||||||||
1206 | \sa profile() | - | ||||||||||||||||||
1207 | */ | - | ||||||||||||||||||
1208 | void QGLFormat::setProfile(OpenGLContextProfile profile) | - | ||||||||||||||||||
1209 | { | - | ||||||||||||||||||
1210 | detach(); | - | ||||||||||||||||||
1211 | d->profile = profile; | - | ||||||||||||||||||
1212 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1213 | - | |||||||||||||||||||
1214 | /*! | - | ||||||||||||||||||
1215 | \since 4.7 | - | ||||||||||||||||||
1216 | - | |||||||||||||||||||
1217 | Returns the OpenGL context profile. | - | ||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | \sa setProfile() | - | ||||||||||||||||||
1220 | */ | - | ||||||||||||||||||
1221 | QGLFormat::OpenGLContextProfile QGLFormat::profile() const | - | ||||||||||||||||||
1222 | { | - | ||||||||||||||||||
1223 | return d->profile; executed 24 times by 3 tests: return d->profile; Executed by:
| 24 | ||||||||||||||||||
1224 | } | - | ||||||||||||||||||
1225 | - | |||||||||||||||||||
1226 | - | |||||||||||||||||||
1227 | /*! | - | ||||||||||||||||||
1228 | \fn bool QGLFormat::hasOpenGL() | - | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | Returns \c true if the window system has any OpenGL support; | - | ||||||||||||||||||
1231 | otherwise returns \c false. | - | ||||||||||||||||||
1232 | - | |||||||||||||||||||
1233 | \warning This function must not be called until the QApplication | - | ||||||||||||||||||
1234 | object has been created. | - | ||||||||||||||||||
1235 | */ | - | ||||||||||||||||||
1236 | bool QGLFormat::hasOpenGL() | - | ||||||||||||||||||
1237 | { | - | ||||||||||||||||||
1238 | return QApplicationPrivate::platformIntegration() executed 1 time by 1 test: return QApplicationPrivate::platformIntegration() ->hasCapability(QPlatformIntegration::OpenGL); Executed by:
| 1 | ||||||||||||||||||
1239 | ->hasCapability(QPlatformIntegration::OpenGL); executed 1 time by 1 test: return QApplicationPrivate::platformIntegration() ->hasCapability(QPlatformIntegration::OpenGL); Executed by:
| 1 | ||||||||||||||||||
1240 | } | - | ||||||||||||||||||
1241 | - | |||||||||||||||||||
1242 | /*! | - | ||||||||||||||||||
1243 | \fn bool QGLFormat::hasOpenGLOverlays() | - | ||||||||||||||||||
1244 | - | |||||||||||||||||||
1245 | Returns \c true if the window system supports OpenGL overlays; | - | ||||||||||||||||||
1246 | otherwise returns \c false. | - | ||||||||||||||||||
1247 | - | |||||||||||||||||||
1248 | \warning This function must not be called until the QApplication | - | ||||||||||||||||||
1249 | object has been created. | - | ||||||||||||||||||
1250 | */ | - | ||||||||||||||||||
1251 | bool QGLFormat::hasOpenGLOverlays() | - | ||||||||||||||||||
1252 | { | - | ||||||||||||||||||
1253 | return false; never executed: return false; | 0 | ||||||||||||||||||
1254 | } | - | ||||||||||||||||||
1255 | - | |||||||||||||||||||
1256 | QGLFormat::OpenGLVersionFlags Q_AUTOTEST_EXPORT qOpenGLVersionFlagsFromString(const QString &versionString) | - | ||||||||||||||||||
1257 | { | - | ||||||||||||||||||
1258 | QGLFormat::OpenGLVersionFlags versionFlags = QGLFormat::OpenGL_Version_None; | - | ||||||||||||||||||
1259 | - | |||||||||||||||||||
1260 | if (versionString.startsWith(QLatin1String("OpenGL ES"))) {
| 0-1 | ||||||||||||||||||
1261 | QStringList parts = versionString.split(QLatin1Char(' ')); | - | ||||||||||||||||||
1262 | if (parts.size() >= 3) {
| 0 | ||||||||||||||||||
1263 | if (parts[2].startsWith(QLatin1String("1."))) {
| 0 | ||||||||||||||||||
1264 | if (parts[1].endsWith(QLatin1String("-CM"))) {
| 0 | ||||||||||||||||||
1265 | versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_0 | | - | ||||||||||||||||||
1266 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0; | - | ||||||||||||||||||
1267 | if (parts[2].startsWith(QLatin1String("1.1")))
| 0 | ||||||||||||||||||
1268 | versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | never executed: versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 | ||||||||||||||||||
1269 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1; never executed: versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 | ||||||||||||||||||
1270 | } else { never executed: end of block | 0 | ||||||||||||||||||
1271 | // Not -CM, must be CL, CommonLite | - | ||||||||||||||||||
1272 | versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_0; | - | ||||||||||||||||||
1273 | if (parts[2].startsWith(QLatin1String("1.1")))
| 0 | ||||||||||||||||||
1274 | versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; never executed: versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 | ||||||||||||||||||
1275 | } never executed: end of block | 0 | ||||||||||||||||||
1276 | } else { | - | ||||||||||||||||||
1277 | // OpenGL ES version 2.0 or higher | - | ||||||||||||||||||
1278 | versionFlags |= QGLFormat::OpenGL_ES_Version_2_0; | - | ||||||||||||||||||
1279 | } never executed: end of block | 0 | ||||||||||||||||||
1280 | } else { | - | ||||||||||||||||||
1281 | // if < 3 parts to the name, it is an unrecognised OpenGL ES | - | ||||||||||||||||||
1282 | qWarning("Unrecognised OpenGL ES version"); | - | ||||||||||||||||||
1283 | } never executed: end of block | 0 | ||||||||||||||||||
1284 | } else { | - | ||||||||||||||||||
1285 | // not ES, regular OpenGL, the version numbers are first in the string | - | ||||||||||||||||||
1286 | if (versionString.startsWith(QLatin1String("1."))) {
| 0-1 | ||||||||||||||||||
1287 | switch (versionString[2].toLatin1()) { | - | ||||||||||||||||||
1288 | case '5': never executed: case '5': | 0 | ||||||||||||||||||
1289 | versionFlags |= QGLFormat::OpenGL_Version_1_5; | - | ||||||||||||||||||
1290 | // fall through | - | ||||||||||||||||||
1291 | case '4': code before this statement never executed: case '4': never executed: case '4': | 0 | ||||||||||||||||||
1292 | versionFlags |= QGLFormat::OpenGL_Version_1_4; | - | ||||||||||||||||||
1293 | // fall through | - | ||||||||||||||||||
1294 | case '3': code before this statement never executed: case '3': never executed: case '3': | 0 | ||||||||||||||||||
1295 | versionFlags |= QGLFormat::OpenGL_Version_1_3; | - | ||||||||||||||||||
1296 | // fall through | - | ||||||||||||||||||
1297 | case '2': code before this statement never executed: case '2': never executed: case '2': | 0 | ||||||||||||||||||
1298 | versionFlags |= QGLFormat::OpenGL_Version_1_2; | - | ||||||||||||||||||
1299 | // fall through | - | ||||||||||||||||||
1300 | case '1': code before this statement never executed: case '1': never executed: case '1': | 0 | ||||||||||||||||||
1301 | versionFlags |= QGLFormat::OpenGL_Version_1_1; | - | ||||||||||||||||||
1302 | // fall through | - | ||||||||||||||||||
1303 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||
1304 | break; never executed: break; | 0 | ||||||||||||||||||
1305 | } | - | ||||||||||||||||||
1306 | } else if (versionString.startsWith(QLatin1String("2."))) {
| 0-1 | ||||||||||||||||||
1307 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
1308 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
1309 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
1310 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
1311 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
1312 | QGLFormat::OpenGL_Version_2_0; | - | ||||||||||||||||||
1313 | if (versionString[2].toLatin1() == '1')
| 0 | ||||||||||||||||||
1314 | versionFlags |= QGLFormat::OpenGL_Version_2_1; never executed: versionFlags |= QGLFormat::OpenGL_Version_2_1; | 0 | ||||||||||||||||||
1315 | } else if (versionString.startsWith(QLatin1String("3."))) { never executed: end of block
| 0-1 | ||||||||||||||||||
1316 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
1317 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
1318 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
1319 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
1320 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
1321 | QGLFormat::OpenGL_Version_2_0 | | - | ||||||||||||||||||
1322 | QGLFormat::OpenGL_Version_2_1 | | - | ||||||||||||||||||
1323 | QGLFormat::OpenGL_Version_3_0; | - | ||||||||||||||||||
1324 | switch (versionString[2].toLatin1()) { | - | ||||||||||||||||||
1325 | case '3': never executed: case '3': | 0 | ||||||||||||||||||
1326 | versionFlags |= QGLFormat::OpenGL_Version_3_3; | - | ||||||||||||||||||
1327 | // fall through | - | ||||||||||||||||||
1328 | case '2': code before this statement never executed: case '2': never executed: case '2': | 0 | ||||||||||||||||||
1329 | versionFlags |= QGLFormat::OpenGL_Version_3_2; | - | ||||||||||||||||||
1330 | // fall through | - | ||||||||||||||||||
1331 | case '1': code before this statement never executed: case '1': never executed: case '1': | 0 | ||||||||||||||||||
1332 | versionFlags |= QGLFormat::OpenGL_Version_3_1; | - | ||||||||||||||||||
1333 | // fall through | - | ||||||||||||||||||
1334 | case '0': code before this statement never executed: case '0': executed 1 time by 1 test: case '0': Executed by:
| 0-1 | ||||||||||||||||||
1335 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
1336 | default: never executed: default: | 0 | ||||||||||||||||||
1337 | versionFlags |= QGLFormat::OpenGL_Version_3_1 | | - | ||||||||||||||||||
1338 | QGLFormat::OpenGL_Version_3_2 | | - | ||||||||||||||||||
1339 | QGLFormat::OpenGL_Version_3_3; | - | ||||||||||||||||||
1340 | break; never executed: break; | 0 | ||||||||||||||||||
1341 | } | - | ||||||||||||||||||
1342 | } else if (versionString.startsWith(QLatin1String("4."))) {
| 0 | ||||||||||||||||||
1343 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
1344 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
1345 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
1346 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
1347 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
1348 | QGLFormat::OpenGL_Version_2_0 | | - | ||||||||||||||||||
1349 | QGLFormat::OpenGL_Version_2_1 | | - | ||||||||||||||||||
1350 | QGLFormat::OpenGL_Version_3_0 | | - | ||||||||||||||||||
1351 | QGLFormat::OpenGL_Version_3_1 | | - | ||||||||||||||||||
1352 | QGLFormat::OpenGL_Version_3_2 | | - | ||||||||||||||||||
1353 | QGLFormat::OpenGL_Version_3_3 | | - | ||||||||||||||||||
1354 | QGLFormat::OpenGL_Version_4_0; | - | ||||||||||||||||||
1355 | switch (versionString[2].toLatin1()) { | - | ||||||||||||||||||
1356 | case '3': never executed: case '3': | 0 | ||||||||||||||||||
1357 | versionFlags |= QGLFormat::OpenGL_Version_4_3; | - | ||||||||||||||||||
1358 | // fall through | - | ||||||||||||||||||
1359 | case '2': code before this statement never executed: case '2': never executed: case '2': | 0 | ||||||||||||||||||
1360 | versionFlags |= QGLFormat::OpenGL_Version_4_2; | - | ||||||||||||||||||
1361 | // fall through | - | ||||||||||||||||||
1362 | case '1': code before this statement never executed: case '1': never executed: case '1': | 0 | ||||||||||||||||||
1363 | versionFlags |= QGLFormat::OpenGL_Version_4_1; | - | ||||||||||||||||||
1364 | // fall through | - | ||||||||||||||||||
1365 | case '0': code before this statement never executed: case '0': never executed: case '0': | 0 | ||||||||||||||||||
1366 | break; never executed: break; | 0 | ||||||||||||||||||
1367 | default: never executed: default: | 0 | ||||||||||||||||||
1368 | versionFlags |= QGLFormat::OpenGL_Version_4_1 | | - | ||||||||||||||||||
1369 | QGLFormat::OpenGL_Version_4_2 | | - | ||||||||||||||||||
1370 | QGLFormat::OpenGL_Version_4_3; | - | ||||||||||||||||||
1371 | break; never executed: break; | 0 | ||||||||||||||||||
1372 | } | - | ||||||||||||||||||
1373 | } else { | - | ||||||||||||||||||
1374 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
1375 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
1376 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
1377 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
1378 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
1379 | QGLFormat::OpenGL_Version_2_0 | | - | ||||||||||||||||||
1380 | QGLFormat::OpenGL_Version_2_1 | | - | ||||||||||||||||||
1381 | QGLFormat::OpenGL_Version_3_0 | | - | ||||||||||||||||||
1382 | QGLFormat::OpenGL_Version_3_1 | | - | ||||||||||||||||||
1383 | QGLFormat::OpenGL_Version_3_2 | | - | ||||||||||||||||||
1384 | QGLFormat::OpenGL_Version_3_3 | | - | ||||||||||||||||||
1385 | QGLFormat::OpenGL_Version_4_0 | | - | ||||||||||||||||||
1386 | QGLFormat::OpenGL_Version_4_1 | | - | ||||||||||||||||||
1387 | QGLFormat::OpenGL_Version_4_2 | | - | ||||||||||||||||||
1388 | QGLFormat::OpenGL_Version_4_3; | - | ||||||||||||||||||
1389 | } never executed: end of block | 0 | ||||||||||||||||||
1390 | } | - | ||||||||||||||||||
1391 | return versionFlags; executed 1 time by 1 test: return versionFlags; Executed by:
| 1 | ||||||||||||||||||
1392 | } | - | ||||||||||||||||||
1393 | - | |||||||||||||||||||
1394 | /*! | - | ||||||||||||||||||
1395 | \enum QGLFormat::OpenGLVersionFlag | - | ||||||||||||||||||
1396 | \since 4.2 | - | ||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | This enum describes the various OpenGL versions that are | - | ||||||||||||||||||
1399 | recognized by Qt. Use the QGLFormat::openGLVersionFlags() function | - | ||||||||||||||||||
1400 | to identify which versions that are supported at runtime. | - | ||||||||||||||||||
1401 | - | |||||||||||||||||||
1402 | \value OpenGL_Version_None If no OpenGL is present or if no OpenGL context is current. | - | ||||||||||||||||||
1403 | - | |||||||||||||||||||
1404 | \value OpenGL_Version_1_1 OpenGL version 1.1 or higher is present. | - | ||||||||||||||||||
1405 | - | |||||||||||||||||||
1406 | \value OpenGL_Version_1_2 OpenGL version 1.2 or higher is present. | - | ||||||||||||||||||
1407 | - | |||||||||||||||||||
1408 | \value OpenGL_Version_1_3 OpenGL version 1.3 or higher is present. | - | ||||||||||||||||||
1409 | - | |||||||||||||||||||
1410 | \value OpenGL_Version_1_4 OpenGL version 1.4 or higher is present. | - | ||||||||||||||||||
1411 | - | |||||||||||||||||||
1412 | \value OpenGL_Version_1_5 OpenGL version 1.5 or higher is present. | - | ||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | \value OpenGL_Version_2_0 OpenGL version 2.0 or higher is present. | - | ||||||||||||||||||
1415 | Note that version 2.0 supports all the functionality of version 1.5. | - | ||||||||||||||||||
1416 | - | |||||||||||||||||||
1417 | \value OpenGL_Version_2_1 OpenGL version 2.1 or higher is present. | - | ||||||||||||||||||
1418 | - | |||||||||||||||||||
1419 | \value OpenGL_Version_3_0 OpenGL version 3.0 or higher is present. | - | ||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | \value OpenGL_Version_3_1 OpenGL version 3.1 or higher is present. | - | ||||||||||||||||||
1422 | Note that OpenGL version 3.1 or higher does not necessarily support all the features of | - | ||||||||||||||||||
1423 | version 3.0 and lower. | - | ||||||||||||||||||
1424 | - | |||||||||||||||||||
1425 | \value OpenGL_Version_3_2 OpenGL version 3.2 or higher is present. | - | ||||||||||||||||||
1426 | - | |||||||||||||||||||
1427 | \value OpenGL_Version_3_3 OpenGL version 3.3 or higher is present. | - | ||||||||||||||||||
1428 | - | |||||||||||||||||||
1429 | \value OpenGL_Version_4_0 OpenGL version 4.0 or higher is present. | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | \value OpenGL_Version_4_1 OpenGL version 4.1 or higher is present. | - | ||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | \value OpenGL_Version_4_2 OpenGL version 4.2 or higher is present. | - | ||||||||||||||||||
1434 | - | |||||||||||||||||||
1435 | \value OpenGL_Version_4_3 OpenGL version 4.3 or higher is present. | - | ||||||||||||||||||
1436 | - | |||||||||||||||||||
1437 | \value OpenGL_ES_CommonLite_Version_1_0 OpenGL ES version 1.0 Common Lite or higher is present. | - | ||||||||||||||||||
1438 | - | |||||||||||||||||||
1439 | \value OpenGL_ES_Common_Version_1_0 OpenGL ES version 1.0 Common or higher is present. | - | ||||||||||||||||||
1440 | The Common profile supports all the features of Common Lite. | - | ||||||||||||||||||
1441 | - | |||||||||||||||||||
1442 | \value OpenGL_ES_CommonLite_Version_1_1 OpenGL ES version 1.1 Common Lite or higher is present. | - | ||||||||||||||||||
1443 | - | |||||||||||||||||||
1444 | \value OpenGL_ES_Common_Version_1_1 OpenGL ES version 1.1 Common or higher is present. | - | ||||||||||||||||||
1445 | The Common profile supports all the features of Common Lite. | - | ||||||||||||||||||
1446 | - | |||||||||||||||||||
1447 | \value OpenGL_ES_Version_2_0 OpenGL ES version 2.0 or higher is present. | - | ||||||||||||||||||
1448 | Note that OpenGL ES version 2.0 does not support all the features of OpenGL ES 1.x. | - | ||||||||||||||||||
1449 | So if OpenGL_ES_Version_2_0 is returned, none of the ES 1.x flags are returned. | - | ||||||||||||||||||
1450 | - | |||||||||||||||||||
1451 | See also \l{http://www.opengl.org} for more information about the different | - | ||||||||||||||||||
1452 | revisions of OpenGL. | - | ||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | \sa openGLVersionFlags() | - | ||||||||||||||||||
1455 | */ | - | ||||||||||||||||||
1456 | - | |||||||||||||||||||
1457 | /*! | - | ||||||||||||||||||
1458 | \since 4.2 | - | ||||||||||||||||||
1459 | - | |||||||||||||||||||
1460 | Identifies, at runtime, which OpenGL versions that are supported | - | ||||||||||||||||||
1461 | by the current platform. | - | ||||||||||||||||||
1462 | - | |||||||||||||||||||
1463 | Note that if OpenGL version 1.5 is supported, its predecessors | - | ||||||||||||||||||
1464 | (i.e., version 1.4 and lower) are also supported. To identify the | - | ||||||||||||||||||
1465 | support of a particular feature, like multi texturing, test for | - | ||||||||||||||||||
1466 | the version in which the feature was first introduced (i.e., | - | ||||||||||||||||||
1467 | version 1.3 in the case of multi texturing) to adapt to the largest | - | ||||||||||||||||||
1468 | possible group of runtime platforms. | - | ||||||||||||||||||
1469 | - | |||||||||||||||||||
1470 | This function needs a valid current OpenGL context to work; | - | ||||||||||||||||||
1471 | otherwise it will return OpenGL_Version_None. | - | ||||||||||||||||||
1472 | - | |||||||||||||||||||
1473 | \sa hasOpenGL(), hasOpenGLOverlays() | - | ||||||||||||||||||
1474 | */ | - | ||||||||||||||||||
1475 | QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags() | - | ||||||||||||||||||
1476 | { | - | ||||||||||||||||||
1477 | static bool cachedDefault = false; | - | ||||||||||||||||||
1478 | static OpenGLVersionFlags defaultVersionFlags = OpenGL_Version_None; | - | ||||||||||||||||||
1479 | QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
1480 | QGLTemporaryContext *tmpContext = 0; | - | ||||||||||||||||||
1481 | - | |||||||||||||||||||
1482 | if (currentCtx && currentCtx->d_func()->version_flags_cached)
| 0-2 | ||||||||||||||||||
1483 | return currentCtx->d_func()->version_flags; executed 1 time by 1 test: return currentCtx->d_func()->version_flags; Executed by:
| 1 | ||||||||||||||||||
1484 | - | |||||||||||||||||||
1485 | if (!currentCtx) {
| 0-1 | ||||||||||||||||||
1486 | if (cachedDefault) {
| 0 | ||||||||||||||||||
1487 | return defaultVersionFlags; never executed: return defaultVersionFlags; | 0 | ||||||||||||||||||
1488 | } else { | - | ||||||||||||||||||
1489 | if (!hasOpenGL())
| 0 | ||||||||||||||||||
1490 | return defaultVersionFlags; never executed: return defaultVersionFlags; | 0 | ||||||||||||||||||
1491 | tmpContext = new QGLTemporaryContext; | - | ||||||||||||||||||
1492 | cachedDefault = true; | - | ||||||||||||||||||
1493 | } never executed: end of block | 0 | ||||||||||||||||||
1494 | } | - | ||||||||||||||||||
1495 | - | |||||||||||||||||||
1496 | QString versionString(QLatin1String(reinterpret_cast<const char*>(qgl_functions()->glGetString(GL_VERSION)))); | - | ||||||||||||||||||
1497 | OpenGLVersionFlags versionFlags = qOpenGLVersionFlagsFromString(versionString); | - | ||||||||||||||||||
1498 | if (currentCtx) {
| 0-1 | ||||||||||||||||||
1499 | currentCtx->d_func()->version_flags_cached = true; | - | ||||||||||||||||||
1500 | currentCtx->d_func()->version_flags = versionFlags; | - | ||||||||||||||||||
1501 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
1502 | if (tmpContext) {
| 0-1 | ||||||||||||||||||
1503 | defaultVersionFlags = versionFlags; | - | ||||||||||||||||||
1504 | delete tmpContext; | - | ||||||||||||||||||
1505 | } never executed: end of block | 0 | ||||||||||||||||||
1506 | - | |||||||||||||||||||
1507 | return versionFlags; executed 1 time by 1 test: return versionFlags; Executed by:
| 1 | ||||||||||||||||||
1508 | } | - | ||||||||||||||||||
1509 | - | |||||||||||||||||||
1510 | - | |||||||||||||||||||
1511 | /*! | - | ||||||||||||||||||
1512 | Returns the default QGLFormat for the application. All QGLWidget | - | ||||||||||||||||||
1513 | objects that are created use this format unless another format is | - | ||||||||||||||||||
1514 | specified, e.g. when they are constructed. | - | ||||||||||||||||||
1515 | - | |||||||||||||||||||
1516 | If no special default format has been set using | - | ||||||||||||||||||
1517 | setDefaultFormat(), the default format is the same as that created | - | ||||||||||||||||||
1518 | with QGLFormat(). | - | ||||||||||||||||||
1519 | - | |||||||||||||||||||
1520 | \sa setDefaultFormat() | - | ||||||||||||||||||
1521 | */ | - | ||||||||||||||||||
1522 | - | |||||||||||||||||||
1523 | QGLFormat QGLFormat::defaultFormat() | - | ||||||||||||||||||
1524 | { | - | ||||||||||||||||||
1525 | return *qgl_default_format(); executed 12 times by 3 tests: return *qgl_default_format(); Executed by:
| 12 | ||||||||||||||||||
1526 | } | - | ||||||||||||||||||
1527 | - | |||||||||||||||||||
1528 | /*! | - | ||||||||||||||||||
1529 | Sets a new default QGLFormat for the application to \a f. For | - | ||||||||||||||||||
1530 | example, to set single buffering as the default instead of double | - | ||||||||||||||||||
1531 | buffering, your main() might contain code like this: | - | ||||||||||||||||||
1532 | \snippet code/src_opengl_qgl.cpp 4 | - | ||||||||||||||||||
1533 | - | |||||||||||||||||||
1534 | \sa defaultFormat() | - | ||||||||||||||||||
1535 | */ | - | ||||||||||||||||||
1536 | - | |||||||||||||||||||
1537 | void QGLFormat::setDefaultFormat(const QGLFormat &f) | - | ||||||||||||||||||
1538 | { | - | ||||||||||||||||||
1539 | *qgl_default_format() = f; | - | ||||||||||||||||||
1540 | } never executed: end of block | 0 | ||||||||||||||||||
1541 | - | |||||||||||||||||||
1542 | - | |||||||||||||||||||
1543 | /*! | - | ||||||||||||||||||
1544 | Returns the default QGLFormat for overlay contexts. | - | ||||||||||||||||||
1545 | - | |||||||||||||||||||
1546 | The default overlay format is: | - | ||||||||||||||||||
1547 | \list | - | ||||||||||||||||||
1548 | \li \l{setDoubleBuffer()}{Double buffer:} Disabled. | - | ||||||||||||||||||
1549 | \li \l{setDepth()}{Depth buffer:} Disabled. | - | ||||||||||||||||||
1550 | \li \l{setRgba()}{RGBA:} Disabled (i.e., color index enabled). | - | ||||||||||||||||||
1551 | \li \l{setAlpha()}{Alpha channel:} Disabled. | - | ||||||||||||||||||
1552 | \li \l{setAccum()}{Accumulator buffer:} Disabled. | - | ||||||||||||||||||
1553 | \li \l{setStencil()}{Stencil buffer:} Disabled. | - | ||||||||||||||||||
1554 | \li \l{setStereo()}{Stereo:} Disabled. | - | ||||||||||||||||||
1555 | \li \l{setDirectRendering()}{Direct rendering:} Enabled. | - | ||||||||||||||||||
1556 | \li \l{setOverlay()}{Overlay:} Disabled. | - | ||||||||||||||||||
1557 | \li \l{setSampleBuffers()}{Multisample buffers:} Disabled. | - | ||||||||||||||||||
1558 | \li \l{setPlane()}{Plane:} 1 (i.e., first overlay plane). | - | ||||||||||||||||||
1559 | \endlist | - | ||||||||||||||||||
1560 | - | |||||||||||||||||||
1561 | \sa setDefaultFormat() | - | ||||||||||||||||||
1562 | */ | - | ||||||||||||||||||
1563 | - | |||||||||||||||||||
1564 | QGLFormat QGLFormat::defaultOverlayFormat() | - | ||||||||||||||||||
1565 | { | - | ||||||||||||||||||
1566 | return *defaultOverlayFormatInstance(); never executed: return *defaultOverlayFormatInstance(); | 0 | ||||||||||||||||||
1567 | } | - | ||||||||||||||||||
1568 | - | |||||||||||||||||||
1569 | /*! | - | ||||||||||||||||||
1570 | Sets a new default QGLFormat for overlay contexts to \a f. This | - | ||||||||||||||||||
1571 | format is used whenever a QGLWidget is created with a format that | - | ||||||||||||||||||
1572 | hasOverlay() enabled. | - | ||||||||||||||||||
1573 | - | |||||||||||||||||||
1574 | For example, to get a double buffered overlay context (if | - | ||||||||||||||||||
1575 | available), use code like this: | - | ||||||||||||||||||
1576 | - | |||||||||||||||||||
1577 | \snippet code/src_opengl_qgl.cpp 5 | - | ||||||||||||||||||
1578 | - | |||||||||||||||||||
1579 | As usual, you can find out after widget creation whether the | - | ||||||||||||||||||
1580 | underlying OpenGL system was able to provide the requested | - | ||||||||||||||||||
1581 | specification: | - | ||||||||||||||||||
1582 | - | |||||||||||||||||||
1583 | \snippet code/src_opengl_qgl.cpp 6 | - | ||||||||||||||||||
1584 | - | |||||||||||||||||||
1585 | \sa defaultOverlayFormat() | - | ||||||||||||||||||
1586 | */ | - | ||||||||||||||||||
1587 | - | |||||||||||||||||||
1588 | void QGLFormat::setDefaultOverlayFormat(const QGLFormat &f) | - | ||||||||||||||||||
1589 | { | - | ||||||||||||||||||
1590 | QGLFormat *defaultFormat = defaultOverlayFormatInstance(); | - | ||||||||||||||||||
1591 | *defaultFormat = f; | - | ||||||||||||||||||
1592 | // Make sure the user doesn't request that the overlays themselves | - | ||||||||||||||||||
1593 | // have overlays, since it is unlikely that the system supports | - | ||||||||||||||||||
1594 | // infinitely many planes... | - | ||||||||||||||||||
1595 | defaultFormat->setOverlay(false); | - | ||||||||||||||||||
1596 | } never executed: end of block | 0 | ||||||||||||||||||
1597 | - | |||||||||||||||||||
1598 | - | |||||||||||||||||||
1599 | /*! | - | ||||||||||||||||||
1600 | Returns \c true if all the options of the two QGLFormat objects | - | ||||||||||||||||||
1601 | \a a and \a b are equal; otherwise returns \c false. | - | ||||||||||||||||||
1602 | - | |||||||||||||||||||
1603 | \relates QGLFormat | - | ||||||||||||||||||
1604 | */ | - | ||||||||||||||||||
1605 | - | |||||||||||||||||||
1606 | bool operator==(const QGLFormat& a, const QGLFormat& b) | - | ||||||||||||||||||
1607 | { | - | ||||||||||||||||||
1608 | return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1609 | && a.d->pln == b.d->pln never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1610 | && a.d->alphaSize == b.d->alphaSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1611 | && a.d->accumSize == b.d->accumSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1612 | && a.d->stencilSize == b.d->stencilSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1613 | && a.d->depthSize == b.d->depthSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1614 | && a.d->redSize == b.d->redSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1615 | && a.d->greenSize == b.d->greenSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1616 | && a.d->blueSize == b.d->blueSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1617 | && a.d->numSamples == b.d->numSamples never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1618 | && a.d->swapInterval == b.d->swapInterval never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1619 | && a.d->majorVersion == b.d->majorVersion never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1620 | && a.d->minorVersion == b.d->minorVersion never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1621 | && a.d->profile == b.d->profile); never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile);
| 0 | ||||||||||||||||||
1622 | } | - | ||||||||||||||||||
1623 | - | |||||||||||||||||||
1624 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||
1625 | QDebug operator<<(QDebug dbg, const QGLFormat &f) | - | ||||||||||||||||||
1626 | { | - | ||||||||||||||||||
1627 | const QGLFormatPrivate * const d = f.d; | - | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
1630 | dbg.nospace() << "QGLFormat(" | - | ||||||||||||||||||
1631 | << "options " << d->opts | - | ||||||||||||||||||
1632 | << ", plane " << d->pln | - | ||||||||||||||||||
1633 | << ", depthBufferSize " << d->depthSize | - | ||||||||||||||||||
1634 | << ", accumBufferSize " << d->accumSize | - | ||||||||||||||||||
1635 | << ", stencilBufferSize " << d->stencilSize | - | ||||||||||||||||||
1636 | << ", redBufferSize " << d->redSize | - | ||||||||||||||||||
1637 | << ", greenBufferSize " << d->greenSize | - | ||||||||||||||||||
1638 | << ", blueBufferSize " << d->blueSize | - | ||||||||||||||||||
1639 | << ", alphaBufferSize " << d->alphaSize | - | ||||||||||||||||||
1640 | << ", samples " << d->numSamples | - | ||||||||||||||||||
1641 | << ", swapInterval " << d->swapInterval | - | ||||||||||||||||||
1642 | << ", majorVersion " << d->majorVersion | - | ||||||||||||||||||
1643 | << ", minorVersion " << d->minorVersion | - | ||||||||||||||||||
1644 | << ", profile " << d->profile | - | ||||||||||||||||||
1645 | << ')'; | - | ||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | return dbg; never executed: return dbg; | 0 | ||||||||||||||||||
1648 | } | - | ||||||||||||||||||
1649 | #endif | - | ||||||||||||||||||
1650 | - | |||||||||||||||||||
1651 | - | |||||||||||||||||||
1652 | /*! | - | ||||||||||||||||||
1653 | Returns \c false if all the options of the two QGLFormat objects | - | ||||||||||||||||||
1654 | \a a and \a b are equal; otherwise returns \c true. | - | ||||||||||||||||||
1655 | - | |||||||||||||||||||
1656 | \relates QGLFormat | - | ||||||||||||||||||
1657 | */ | - | ||||||||||||||||||
1658 | - | |||||||||||||||||||
1659 | bool operator!=(const QGLFormat& a, const QGLFormat& b) | - | ||||||||||||||||||
1660 | { | - | ||||||||||||||||||
1661 | return !(a == b); never executed: return !(a == b); | 0 | ||||||||||||||||||
1662 | } | - | ||||||||||||||||||
1663 | - | |||||||||||||||||||
1664 | struct QGLContextGroupList { | - | ||||||||||||||||||
1665 | QGLContextGroupList() | - | ||||||||||||||||||
1666 | : m_mutex(QMutex::Recursive) | - | ||||||||||||||||||
1667 | { | - | ||||||||||||||||||
1668 | } executed 3 times by 3 tests: end of block Executed by:
| 3 | ||||||||||||||||||
1669 | - | |||||||||||||||||||
1670 | void append(QGLContextGroup *group) { | - | ||||||||||||||||||
1671 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
1672 | m_list.append(group); | - | ||||||||||||||||||
1673 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1674 | - | |||||||||||||||||||
1675 | void remove(QGLContextGroup *group) { | - | ||||||||||||||||||
1676 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
1677 | m_list.removeOne(group); | - | ||||||||||||||||||
1678 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1679 | - | |||||||||||||||||||
1680 | QList<QGLContextGroup *> m_list; | - | ||||||||||||||||||
1681 | QMutex m_mutex; | - | ||||||||||||||||||
1682 | }; | - | ||||||||||||||||||
1683 | - | |||||||||||||||||||
1684 | Q_GLOBAL_STATIC(QGLContextGroupList, qt_context_groups) executed 3 times by 3 tests: end of block Executed by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 24 times by 3 tests: return &holder.value; Executed by:
| 0-24 | ||||||||||||||||||
1685 | - | |||||||||||||||||||
1686 | /***************************************************************************** | - | ||||||||||||||||||
1687 | QGLContext implementation | - | ||||||||||||||||||
1688 | *****************************************************************************/ | - | ||||||||||||||||||
1689 | - | |||||||||||||||||||
1690 | QGLContextGroup::QGLContextGroup(const QGLContext *context) | - | ||||||||||||||||||
1691 | : m_context(context), m_refs(1) | - | ||||||||||||||||||
1692 | { | - | ||||||||||||||||||
1693 | qt_context_groups()->append(this); | - | ||||||||||||||||||
1694 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1695 | - | |||||||||||||||||||
1696 | QGLContextGroup::~QGLContextGroup() | - | ||||||||||||||||||
1697 | { | - | ||||||||||||||||||
1698 | qt_context_groups()->remove(this); | - | ||||||||||||||||||
1699 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1700 | - | |||||||||||||||||||
1701 | const QGLContext *qt_gl_transfer_context(const QGLContext *ctx) | - | ||||||||||||||||||
1702 | { | - | ||||||||||||||||||
1703 | if (!ctx)
| 0 | ||||||||||||||||||
1704 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1705 | QList<const QGLContext *> shares | - | ||||||||||||||||||
1706 | (QGLContextPrivate::contextGroup(ctx)->shares()); | - | ||||||||||||||||||
1707 | if (shares.size() >= 2)
| 0 | ||||||||||||||||||
1708 | return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0); never executed: return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0);
| 0 | ||||||||||||||||||
1709 | else | - | ||||||||||||||||||
1710 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1711 | } | - | ||||||||||||||||||
1712 | - | |||||||||||||||||||
1713 | QGLContextPrivate::QGLContextPrivate(QGLContext *context) | - | ||||||||||||||||||
1714 | : internal_context(false) | - | ||||||||||||||||||
1715 | , q_ptr(context) | - | ||||||||||||||||||
1716 | , texture_destroyer(0) | - | ||||||||||||||||||
1717 | , functions(0) | - | ||||||||||||||||||
1718 | { | - | ||||||||||||||||||
1719 | group = new QGLContextGroup(context); | - | ||||||||||||||||||
1720 | - | |||||||||||||||||||
1721 | texture_destroyer = new QGLTextureDestroyer; | - | ||||||||||||||||||
1722 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1723 | - | |||||||||||||||||||
1724 | QGLContextPrivate::~QGLContextPrivate() | - | ||||||||||||||||||
1725 | { | - | ||||||||||||||||||
1726 | delete functions; | - | ||||||||||||||||||
1727 | - | |||||||||||||||||||
1728 | if (!group->m_refs.deref()) {
| 1-11 | ||||||||||||||||||
1729 | Q_ASSERT(group->context() == q_ptr); | - | ||||||||||||||||||
1730 | delete group; | - | ||||||||||||||||||
1731 | } executed 11 times by 3 tests: end of block Executed by:
| 11 | ||||||||||||||||||
1732 | - | |||||||||||||||||||
1733 | delete texture_destroyer; | - | ||||||||||||||||||
1734 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1735 | - | |||||||||||||||||||
1736 | void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) | - | ||||||||||||||||||
1737 | { | - | ||||||||||||||||||
1738 | Q_Q(QGLContext); | - | ||||||||||||||||||
1739 | glFormat = reqFormat = format; | - | ||||||||||||||||||
1740 | valid = false; | - | ||||||||||||||||||
1741 | q->setDevice(dev); | - | ||||||||||||||||||
1742 | - | |||||||||||||||||||
1743 | guiGlContext = 0; | - | ||||||||||||||||||
1744 | ownContext = false; | - | ||||||||||||||||||
1745 | fbo = 0; | - | ||||||||||||||||||
1746 | crWin = false; | - | ||||||||||||||||||
1747 | initDone = false; | - | ||||||||||||||||||
1748 | sharing = false; | - | ||||||||||||||||||
1749 | max_texture_size = -1; | - | ||||||||||||||||||
1750 | version_flags_cached = false; | - | ||||||||||||||||||
1751 | version_flags = QGLFormat::OpenGL_Version_None; | - | ||||||||||||||||||
1752 | current_fbo = 0; | - | ||||||||||||||||||
1753 | default_fbo = 0; | - | ||||||||||||||||||
1754 | active_engine = 0; | - | ||||||||||||||||||
1755 | workaround_needsFullClearOnEveryFrame = false; | - | ||||||||||||||||||
1756 | workaround_brokenFBOReadBack = false; | - | ||||||||||||||||||
1757 | workaround_brokenTexSubImage = false; | - | ||||||||||||||||||
1758 | workaroundsCached = false; | - | ||||||||||||||||||
1759 | - | |||||||||||||||||||
1760 | workaround_brokenTextureFromPixmap = false; | - | ||||||||||||||||||
1761 | workaround_brokenTextureFromPixmap_init = false; | - | ||||||||||||||||||
1762 | - | |||||||||||||||||||
1763 | workaround_brokenAlphaTexSubImage = false; | - | ||||||||||||||||||
1764 | workaround_brokenAlphaTexSubImage_init = false; | - | ||||||||||||||||||
1765 | - | |||||||||||||||||||
1766 | for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
| 12-36 | ||||||||||||||||||
1767 | vertexAttributeArraysEnabledState[i] = false; executed 36 times by 3 tests: vertexAttributeArraysEnabledState[i] = false; Executed by:
| 36 | ||||||||||||||||||
1768 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1769 | - | |||||||||||||||||||
1770 | QGLContext* QGLContext::currentCtx = 0; | - | ||||||||||||||||||
1771 | - | |||||||||||||||||||
1772 | /* | - | ||||||||||||||||||
1773 | QGLTemporaryContext implementation | - | ||||||||||||||||||
1774 | */ | - | ||||||||||||||||||
1775 | class QGLTemporaryContextPrivate | - | ||||||||||||||||||
1776 | { | - | ||||||||||||||||||
1777 | public: | - | ||||||||||||||||||
1778 | QWindow *window; | - | ||||||||||||||||||
1779 | QOpenGLContext *context; | - | ||||||||||||||||||
1780 | - | |||||||||||||||||||
1781 | QGLContext *oldContext; | - | ||||||||||||||||||
1782 | }; | - | ||||||||||||||||||
1783 | - | |||||||||||||||||||
1784 | QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) | - | ||||||||||||||||||
1785 | : d(new QGLTemporaryContextPrivate) | - | ||||||||||||||||||
1786 | { | - | ||||||||||||||||||
1787 | d->oldContext = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
1788 | - | |||||||||||||||||||
1789 | d->window = new QWindow; | - | ||||||||||||||||||
1790 | d->window->setSurfaceType(QWindow::OpenGLSurface); | - | ||||||||||||||||||
1791 | d->window->setGeometry(QRect(0, 0, 3, 3)); | - | ||||||||||||||||||
1792 | d->window->create(); | - | ||||||||||||||||||
1793 | - | |||||||||||||||||||
1794 | d->context = new QOpenGLContext; | - | ||||||||||||||||||
1795 | #if !defined(QT_OPENGL_ES) | - | ||||||||||||||||||
1796 | if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
| 0 | ||||||||||||||||||
1797 | // On desktop, request latest released version | - | ||||||||||||||||||
1798 | QSurfaceFormat format; | - | ||||||||||||||||||
1799 | #if defined(Q_OS_MAC) | - | ||||||||||||||||||
1800 | // OS X is limited to OpenGL 3.2 Core Profile at present | - | ||||||||||||||||||
1801 | // so set that here. If we use compatibility profile it | - | ||||||||||||||||||
1802 | // only reports 2.x contexts. | - | ||||||||||||||||||
1803 | format.setMajorVersion(3); | - | ||||||||||||||||||
1804 | format.setMinorVersion(2); | - | ||||||||||||||||||
1805 | format.setProfile(QSurfaceFormat::CoreProfile); | - | ||||||||||||||||||
1806 | #else | - | ||||||||||||||||||
1807 | format.setMajorVersion(4); | - | ||||||||||||||||||
1808 | format.setMinorVersion(3); | - | ||||||||||||||||||
1809 | #endif | - | ||||||||||||||||||
1810 | d->context->setFormat(format); | - | ||||||||||||||||||
1811 | } never executed: end of block | 0 | ||||||||||||||||||
1812 | #endif // QT_OPENGL_ES | - | ||||||||||||||||||
1813 | d->context->create(); | - | ||||||||||||||||||
1814 | d->context->makeCurrent(d->window); | - | ||||||||||||||||||
1815 | } never executed: end of block | 0 | ||||||||||||||||||
1816 | - | |||||||||||||||||||
1817 | QGLTemporaryContext::~QGLTemporaryContext() | - | ||||||||||||||||||
1818 | { | - | ||||||||||||||||||
1819 | if (d->oldContext)
| 0 | ||||||||||||||||||
1820 | d->oldContext->makeCurrent(); never executed: d->oldContext->makeCurrent(); | 0 | ||||||||||||||||||
1821 | - | |||||||||||||||||||
1822 | delete d->context; | - | ||||||||||||||||||
1823 | delete d->window; | - | ||||||||||||||||||
1824 | } never executed: end of block | 0 | ||||||||||||||||||
1825 | - | |||||||||||||||||||
1826 | /* | - | ||||||||||||||||||
1827 | Read back the contents of the currently bound framebuffer, used in | - | ||||||||||||||||||
1828 | QGLWidget::grabFrameBuffer(), QGLPixelbuffer::toImage() and | - | ||||||||||||||||||
1829 | QGLFramebufferObject::toImage() | - | ||||||||||||||||||
1830 | */ | - | ||||||||||||||||||
1831 | - | |||||||||||||||||||
1832 | static void convertFromGLImage(QImage &img, int w, int h, bool alpha_format, bool include_alpha) | - | ||||||||||||||||||
1833 | { | - | ||||||||||||||||||
1834 | Q_ASSERT(!img.isNull()); | - | ||||||||||||||||||
1835 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
1836 | // OpenGL gives RGBA; Qt wants ARGB | - | ||||||||||||||||||
1837 | uint *p = (uint*)img.bits(); | - | ||||||||||||||||||
1838 | uint *end = p + w*h; | - | ||||||||||||||||||
1839 | if (alpha_format && include_alpha) {
| 0 | ||||||||||||||||||
1840 | while (p < end) {
| 0 | ||||||||||||||||||
1841 | uint a = *p << 24; | - | ||||||||||||||||||
1842 | *p = (*p >> 8) | a; | - | ||||||||||||||||||
1843 | p++; | - | ||||||||||||||||||
1844 | } never executed: end of block | 0 | ||||||||||||||||||
1845 | } else { never executed: end of block | 0 | ||||||||||||||||||
1846 | // This is an old legacy fix for PowerPC based Macs, which | - | ||||||||||||||||||
1847 | // we shouldn't remove | - | ||||||||||||||||||
1848 | while (p < end) {
| 0 | ||||||||||||||||||
1849 | *p = 0xff000000 | (*p>>8); | - | ||||||||||||||||||
1850 | ++p; | - | ||||||||||||||||||
1851 | } never executed: end of block | 0 | ||||||||||||||||||
1852 | } never executed: end of block | 0 | ||||||||||||||||||
1853 | } else { | - | ||||||||||||||||||
1854 | // OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB | - | ||||||||||||||||||
1855 | for (int y = 0; y < h; y++) {
| 0 | ||||||||||||||||||
1856 | uint *q = (uint*)img.scanLine(y); | - | ||||||||||||||||||
1857 | for (int x=0; x < w; ++x) {
| 0 | ||||||||||||||||||
1858 | const uint pixel = *q; | - | ||||||||||||||||||
1859 | if (alpha_format && include_alpha) {
| 0 | ||||||||||||||||||
1860 | *q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | - | ||||||||||||||||||
1861 | | (pixel & 0xff00ff00); | - | ||||||||||||||||||
1862 | } else { never executed: end of block | 0 | ||||||||||||||||||
1863 | *q = 0xff000000 | ((pixel << 16) & 0xff0000) | - | ||||||||||||||||||
1864 | | ((pixel >> 16) & 0xff) | (pixel & 0x00ff00); | - | ||||||||||||||||||
1865 | } never executed: end of block | 0 | ||||||||||||||||||
1866 | - | |||||||||||||||||||
1867 | q++; | - | ||||||||||||||||||
1868 | } never executed: end of block | 0 | ||||||||||||||||||
1869 | } never executed: end of block | 0 | ||||||||||||||||||
1870 | - | |||||||||||||||||||
1871 | } never executed: end of block | 0 | ||||||||||||||||||
1872 | img = img.mirrored(); | - | ||||||||||||||||||
1873 | } never executed: end of block | 0 | ||||||||||||||||||
1874 | - | |||||||||||||||||||
1875 | QImage qt_gl_read_frame_buffer(const QSize &size, bool alpha_format, bool include_alpha) | - | ||||||||||||||||||
1876 | { | - | ||||||||||||||||||
1877 | QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32_Premultiplied | - | ||||||||||||||||||
1878 | : QImage::Format_RGB32); | - | ||||||||||||||||||
1879 | if (img.isNull())
| 0 | ||||||||||||||||||
1880 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||
1881 | int w = size.width(); | - | ||||||||||||||||||
1882 | int h = size.height(); | - | ||||||||||||||||||
1883 | qgl_functions()->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); | - | ||||||||||||||||||
1884 | convertFromGLImage(img, w, h, alpha_format, include_alpha); | - | ||||||||||||||||||
1885 | return img; never executed: return img; | 0 | ||||||||||||||||||
1886 | } | - | ||||||||||||||||||
1887 | - | |||||||||||||||||||
1888 | QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha) | - | ||||||||||||||||||
1889 | { | - | ||||||||||||||||||
1890 | QImage img(size, alpha_format ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); | - | ||||||||||||||||||
1891 | if (img.isNull())
| 0 | ||||||||||||||||||
1892 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||
1893 | int w = size.width(); | - | ||||||||||||||||||
1894 | int h = size.height(); | - | ||||||||||||||||||
1895 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
1896 | if (!QOpenGLContext::currentContext()->isOpenGLES()) {
| 0 | ||||||||||||||||||
1897 | - | |||||||||||||||||||
1898 | qgl1_functions()->glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); | - | ||||||||||||||||||
1899 | } never executed: end of block | 0 | ||||||||||||||||||
1900 | #endif // QT_OPENGL_ES | - | ||||||||||||||||||
1901 | convertFromGLImage(img, w, h, alpha_format, include_alpha); | - | ||||||||||||||||||
1902 | return img; never executed: return img; | 0 | ||||||||||||||||||
1903 | } | - | ||||||||||||||||||
1904 | - | |||||||||||||||||||
1905 | Q_GLOBAL_STATIC(QGLTextureCache, qt_gl_texture_cache) executed 3 times by 3 tests: end of block Executed by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 12 times by 3 tests: return &holder.value; Executed by:
| 0-12 | ||||||||||||||||||
1906 | - | |||||||||||||||||||
1907 | QGLTextureCache::QGLTextureCache() | - | ||||||||||||||||||
1908 | : m_cache(64*1024) // cache ~64 MB worth of textures - this is not accurate though | - | ||||||||||||||||||
1909 | { | - | ||||||||||||||||||
1910 | QImagePixmapCleanupHooks::instance()->addPlatformPixmapModificationHook(cleanupTexturesForPixampData); | - | ||||||||||||||||||
1911 | QImagePixmapCleanupHooks::instance()->addPlatformPixmapDestructionHook(cleanupBeforePixmapDestruction); | - | ||||||||||||||||||
1912 | QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey); | - | ||||||||||||||||||
1913 | } executed 3 times by 3 tests: end of block Executed by:
| 3 | ||||||||||||||||||
1914 | - | |||||||||||||||||||
1915 | QGLTextureCache::~QGLTextureCache() | - | ||||||||||||||||||
1916 | { | - | ||||||||||||||||||
1917 | QImagePixmapCleanupHooks::instance()->removePlatformPixmapModificationHook(cleanupTexturesForPixampData); | - | ||||||||||||||||||
1918 | QImagePixmapCleanupHooks::instance()->removePlatformPixmapDestructionHook(cleanupBeforePixmapDestruction); | - | ||||||||||||||||||
1919 | QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey); | - | ||||||||||||||||||
1920 | } executed 3 times by 3 tests: end of block Executed by:
| 3 | ||||||||||||||||||
1921 | - | |||||||||||||||||||
1922 | void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost) | - | ||||||||||||||||||
1923 | { | - | ||||||||||||||||||
1924 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
1925 | const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)}; | - | ||||||||||||||||||
1926 | m_cache.insert(cacheKey, texture, cost); | - | ||||||||||||||||||
1927 | } never executed: end of block | 0 | ||||||||||||||||||
1928 | - | |||||||||||||||||||
1929 | void QGLTextureCache::remove(qint64 key) | - | ||||||||||||||||||
1930 | { | - | ||||||||||||||||||
1931 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
1932 | QMutexLocker groupLocker(&qt_context_groups()->m_mutex); | - | ||||||||||||||||||
1933 | QList<QGLContextGroup *>::const_iterator it = qt_context_groups()->m_list.constBegin(); | - | ||||||||||||||||||
1934 | while (it != qt_context_groups()->m_list.constEnd()) {
| 0 | ||||||||||||||||||
1935 | const QGLTextureCacheKey cacheKey = {key, *it}; | - | ||||||||||||||||||
1936 | m_cache.remove(cacheKey); | - | ||||||||||||||||||
1937 | ++it; | - | ||||||||||||||||||
1938 | } never executed: end of block | 0 | ||||||||||||||||||
1939 | } never executed: end of block | 0 | ||||||||||||||||||
1940 | - | |||||||||||||||||||
1941 | bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId) | - | ||||||||||||||||||
1942 | { | - | ||||||||||||||||||
1943 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
1944 | QList<QGLTextureCacheKey> keys = m_cache.keys(); | - | ||||||||||||||||||
1945 | for (int i = 0; i < keys.size(); ++i) {
| 0 | ||||||||||||||||||
1946 | QGLTexture *tex = m_cache.object(keys.at(i)); | - | ||||||||||||||||||
1947 | if (tex->id == textureId && tex->context == ctx) {
| 0 | ||||||||||||||||||
1948 | tex->options |= QGLContext::MemoryManagedBindOption; // forces a glDeleteTextures() call | - | ||||||||||||||||||
1949 | m_cache.remove(keys.at(i)); | - | ||||||||||||||||||
1950 | return true; never executed: return true; | 0 | ||||||||||||||||||
1951 | } | - | ||||||||||||||||||
1952 | } never executed: end of block | 0 | ||||||||||||||||||
1953 | return false; never executed: return false; | 0 | ||||||||||||||||||
1954 | } | - | ||||||||||||||||||
1955 | - | |||||||||||||||||||
1956 | void QGLTextureCache::removeContextTextures(QGLContext* ctx) | - | ||||||||||||||||||
1957 | { | - | ||||||||||||||||||
1958 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
1959 | QList<QGLTextureCacheKey> keys = m_cache.keys(); | - | ||||||||||||||||||
1960 | for (int i = 0; i < keys.size(); ++i) {
| 0-12 | ||||||||||||||||||
1961 | const QGLTextureCacheKey &key = keys.at(i); | - | ||||||||||||||||||
1962 | if (m_cache.object(key)->context == ctx)
| 0 | ||||||||||||||||||
1963 | m_cache.remove(key); never executed: m_cache.remove(key); | 0 | ||||||||||||||||||
1964 | } never executed: end of block | 0 | ||||||||||||||||||
1965 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1966 | - | |||||||||||||||||||
1967 | /* | - | ||||||||||||||||||
1968 | a hook that removes textures from the cache when a pixmap/image | - | ||||||||||||||||||
1969 | is deref'ed | - | ||||||||||||||||||
1970 | */ | - | ||||||||||||||||||
1971 | void QGLTextureCache::cleanupTexturesForCacheKey(qint64 cacheKey) | - | ||||||||||||||||||
1972 | { | - | ||||||||||||||||||
1973 | qt_gl_texture_cache()->remove(cacheKey); | - | ||||||||||||||||||
1974 | } never executed: end of block | 0 | ||||||||||||||||||
1975 | - | |||||||||||||||||||
1976 | - | |||||||||||||||||||
1977 | void QGLTextureCache::cleanupTexturesForPixampData(QPlatformPixmap* pmd) | - | ||||||||||||||||||
1978 | { | - | ||||||||||||||||||
1979 | cleanupTexturesForCacheKey(pmd->cacheKey()); | - | ||||||||||||||||||
1980 | } never executed: end of block | 0 | ||||||||||||||||||
1981 | - | |||||||||||||||||||
1982 | void QGLTextureCache::cleanupBeforePixmapDestruction(QPlatformPixmap* pmd) | - | ||||||||||||||||||
1983 | { | - | ||||||||||||||||||
1984 | // Remove any bound textures first: | - | ||||||||||||||||||
1985 | cleanupTexturesForPixampData(pmd); | - | ||||||||||||||||||
1986 | } never executed: end of block | 0 | ||||||||||||||||||
1987 | - | |||||||||||||||||||
1988 | QGLTextureCache *QGLTextureCache::instance() | - | ||||||||||||||||||
1989 | { | - | ||||||||||||||||||
1990 | return qt_gl_texture_cache(); executed 12 times by 3 tests: return qt_gl_texture_cache(); Executed by:
| 12 | ||||||||||||||||||
1991 | } | - | ||||||||||||||||||
1992 | - | |||||||||||||||||||
1993 | // DDS format structure | - | ||||||||||||||||||
1994 | struct DDSFormat { | - | ||||||||||||||||||
1995 | quint32 dwSize; | - | ||||||||||||||||||
1996 | quint32 dwFlags; | - | ||||||||||||||||||
1997 | quint32 dwHeight; | - | ||||||||||||||||||
1998 | quint32 dwWidth; | - | ||||||||||||||||||
1999 | quint32 dwLinearSize; | - | ||||||||||||||||||
2000 | quint32 dummy1; | - | ||||||||||||||||||
2001 | quint32 dwMipMapCount; | - | ||||||||||||||||||
2002 | quint32 dummy2[11]; | - | ||||||||||||||||||
2003 | struct { | - | ||||||||||||||||||
2004 | quint32 dummy3[2]; | - | ||||||||||||||||||
2005 | quint32 dwFourCC; | - | ||||||||||||||||||
2006 | quint32 dummy4[5]; | - | ||||||||||||||||||
2007 | } ddsPixelFormat; | - | ||||||||||||||||||
2008 | }; | - | ||||||||||||||||||
2009 | - | |||||||||||||||||||
2010 | // compressed texture pixel formats | - | ||||||||||||||||||
2011 | #define FOURCC_DXT1 0x31545844 | - | ||||||||||||||||||
2012 | #define FOURCC_DXT2 0x32545844 | - | ||||||||||||||||||
2013 | #define FOURCC_DXT3 0x33545844 | - | ||||||||||||||||||
2014 | #define FOURCC_DXT4 0x34545844 | - | ||||||||||||||||||
2015 | #define FOURCC_DXT5 0x35545844 | - | ||||||||||||||||||
2016 | - | |||||||||||||||||||
2017 | // ####TODO Properly #ifdef this class to use #define symbols actually defined | - | ||||||||||||||||||
2018 | // by system GL includes | - | ||||||||||||||||||
2019 | #ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT | - | ||||||||||||||||||
2020 | #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 | - | ||||||||||||||||||
2021 | #endif | - | ||||||||||||||||||
2022 | - | |||||||||||||||||||
2023 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT | - | ||||||||||||||||||
2024 | #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 | - | ||||||||||||||||||
2025 | #endif | - | ||||||||||||||||||
2026 | - | |||||||||||||||||||
2027 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT | - | ||||||||||||||||||
2028 | #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 | - | ||||||||||||||||||
2029 | #endif | - | ||||||||||||||||||
2030 | - | |||||||||||||||||||
2031 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT | - | ||||||||||||||||||
2032 | #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 | - | ||||||||||||||||||
2033 | #endif | - | ||||||||||||||||||
2034 | - | |||||||||||||||||||
2035 | #ifndef GL_GENERATE_MIPMAP_SGIS | - | ||||||||||||||||||
2036 | #define GL_GENERATE_MIPMAP_SGIS 0x8191 | - | ||||||||||||||||||
2037 | #define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 | - | ||||||||||||||||||
2038 | #endif | - | ||||||||||||||||||
2039 | - | |||||||||||||||||||
2040 | /*! | - | ||||||||||||||||||
2041 | \class QGLContext | - | ||||||||||||||||||
2042 | \inmodule QtOpenGL | - | ||||||||||||||||||
2043 | \obsolete | - | ||||||||||||||||||
2044 | - | |||||||||||||||||||
2045 | \brief The QGLContext class encapsulates an OpenGL rendering context. | - | ||||||||||||||||||
2046 | - | |||||||||||||||||||
2047 | An OpenGL rendering context is a complete set of OpenGL state | - | ||||||||||||||||||
2048 | variables. The rendering context's \l {QGL::FormatOption} {format} | - | ||||||||||||||||||
2049 | is set in the constructor, but it can also be set later with | - | ||||||||||||||||||
2050 | setFormat(). The format options that are actually set are returned | - | ||||||||||||||||||
2051 | by format(); the options you asked for are returned by | - | ||||||||||||||||||
2052 | requestedFormat(). Note that after a QGLContext object has been | - | ||||||||||||||||||
2053 | constructed, the actual OpenGL context must be created by | - | ||||||||||||||||||
2054 | explicitly calling the \l{create()} | - | ||||||||||||||||||
2055 | function. The makeCurrent() function makes this context the | - | ||||||||||||||||||
2056 | current rendering context. You can make \e no context current | - | ||||||||||||||||||
2057 | using doneCurrent(). The reset() function will reset the context | - | ||||||||||||||||||
2058 | and make it invalid. | - | ||||||||||||||||||
2059 | - | |||||||||||||||||||
2060 | You can examine properties of the context with, e.g. isValid(), | - | ||||||||||||||||||
2061 | isSharing(), initialized(), windowCreated() and | - | ||||||||||||||||||
2062 | overlayTransparentColor(). | - | ||||||||||||||||||
2063 | - | |||||||||||||||||||
2064 | If you're using double buffering you can swap the screen contents | - | ||||||||||||||||||
2065 | with the off-screen buffer using swapBuffers(). | - | ||||||||||||||||||
2066 | - | |||||||||||||||||||
2067 | Please note that QGLContext is not thread safe. | - | ||||||||||||||||||
2068 | */ | - | ||||||||||||||||||
2069 | - | |||||||||||||||||||
2070 | /*! | - | ||||||||||||||||||
2071 | \enum QGLContext::BindOption | - | ||||||||||||||||||
2072 | \since 4.6 | - | ||||||||||||||||||
2073 | - | |||||||||||||||||||
2074 | A set of options to decide how to bind a texture using bindTexture(). | - | ||||||||||||||||||
2075 | - | |||||||||||||||||||
2076 | \value NoBindOption Don't do anything, pass the texture straight | - | ||||||||||||||||||
2077 | through. | - | ||||||||||||||||||
2078 | - | |||||||||||||||||||
2079 | \value InvertedYBindOption Specifies that the texture should be flipped | - | ||||||||||||||||||
2080 | over the X axis so that the texture coordinate 0,0 corresponds to | - | ||||||||||||||||||
2081 | the top left corner. Inverting the texture implies a deep copy | - | ||||||||||||||||||
2082 | prior to upload. | - | ||||||||||||||||||
2083 | - | |||||||||||||||||||
2084 | \value MipmapBindOption Specifies that bindTexture() should try | - | ||||||||||||||||||
2085 | to generate mipmaps. If the GL implementation supports the \c | - | ||||||||||||||||||
2086 | GL_SGIS_generate_mipmap extension, mipmaps will be automatically | - | ||||||||||||||||||
2087 | generated for the texture. Mipmap generation is only supported for | - | ||||||||||||||||||
2088 | the \c GL_TEXTURE_2D target. | - | ||||||||||||||||||
2089 | - | |||||||||||||||||||
2090 | \value PremultipliedAlphaBindOption Specifies that the image should be | - | ||||||||||||||||||
2091 | uploaded with premultiplied alpha and does a conversion accordingly. | - | ||||||||||||||||||
2092 | - | |||||||||||||||||||
2093 | \value LinearFilteringBindOption Specifies that the texture filtering | - | ||||||||||||||||||
2094 | should be set to GL_LINEAR. Default is GL_NEAREST. If mipmap is | - | ||||||||||||||||||
2095 | also enabled, filtering will be set to GL_LINEAR_MIPMAP_LINEAR. | - | ||||||||||||||||||
2096 | - | |||||||||||||||||||
2097 | \value DefaultBindOption In Qt 4.5 and earlier, bindTexture() | - | ||||||||||||||||||
2098 | would mirror the image and automatically generate mipmaps. This | - | ||||||||||||||||||
2099 | option helps preserve this default behavior. | - | ||||||||||||||||||
2100 | - | |||||||||||||||||||
2101 | \omitvalue CanFlipNativePixmapBindOption Used by x11 from pixmap to choose | - | ||||||||||||||||||
2102 | whether or not it can bind the pixmap upside down or not. | - | ||||||||||||||||||
2103 | - | |||||||||||||||||||
2104 | \omitvalue MemoryManagedBindOption Used by paint engines to | - | ||||||||||||||||||
2105 | indicate that the pixmap should be memory managed along side with | - | ||||||||||||||||||
2106 | the pixmap/image that it stems from, e.g. installing destruction | - | ||||||||||||||||||
2107 | hooks in them. | - | ||||||||||||||||||
2108 | - | |||||||||||||||||||
2109 | \omitvalue TemporarilyCachedBindOption Used by paint engines on some | - | ||||||||||||||||||
2110 | platforms to indicate that the pixmap or image texture is possibly | - | ||||||||||||||||||
2111 | cached only temporarily and must be destroyed immediately after the use. | - | ||||||||||||||||||
2112 | - | |||||||||||||||||||
2113 | \omitvalue InternalBindOption | - | ||||||||||||||||||
2114 | */ | - | ||||||||||||||||||
2115 | - | |||||||||||||||||||
2116 | /*! | - | ||||||||||||||||||
2117 | \obsolete | - | ||||||||||||||||||
2118 | - | |||||||||||||||||||
2119 | Constructs an OpenGL context for the given paint \a device, which | - | ||||||||||||||||||
2120 | can be a widget or a pixmap. The \a format specifies several | - | ||||||||||||||||||
2121 | display options for the context. | - | ||||||||||||||||||
2122 | - | |||||||||||||||||||
2123 | If the underlying OpenGL/Window system cannot satisfy all the | - | ||||||||||||||||||
2124 | features requested in \a format, the nearest subset of features | - | ||||||||||||||||||
2125 | will be used. After creation, the format() method will return the | - | ||||||||||||||||||
2126 | actual format obtained. | - | ||||||||||||||||||
2127 | - | |||||||||||||||||||
2128 | Note that after a QGLContext object has been constructed, \l | - | ||||||||||||||||||
2129 | create() must be called explicitly to create the actual OpenGL | - | ||||||||||||||||||
2130 | context. The context will be \l {isValid()}{invalid} if it was not | - | ||||||||||||||||||
2131 | possible to obtain a GL context at all. | - | ||||||||||||||||||
2132 | */ | - | ||||||||||||||||||
2133 | - | |||||||||||||||||||
2134 | QGLContext::QGLContext(const QGLFormat &format, QPaintDevice *device) | - | ||||||||||||||||||
2135 | : d_ptr(new QGLContextPrivate(this)) | - | ||||||||||||||||||
2136 | { | - | ||||||||||||||||||
2137 | Q_D(QGLContext); | - | ||||||||||||||||||
2138 | d->init(device, format); | - | ||||||||||||||||||
2139 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2140 | - | |||||||||||||||||||
2141 | /*! | - | ||||||||||||||||||
2142 | Constructs an OpenGL context with the given \a format which | - | ||||||||||||||||||
2143 | specifies several display options for the context. | - | ||||||||||||||||||
2144 | - | |||||||||||||||||||
2145 | If the underlying OpenGL/Window system cannot satisfy all the | - | ||||||||||||||||||
2146 | features requested in \a format, the nearest subset of features | - | ||||||||||||||||||
2147 | will be used. After creation, the format() method will return the | - | ||||||||||||||||||
2148 | actual format obtained. | - | ||||||||||||||||||
2149 | - | |||||||||||||||||||
2150 | Note that after a QGLContext object has been constructed, \l | - | ||||||||||||||||||
2151 | create() must be called explicitly to create the actual OpenGL | - | ||||||||||||||||||
2152 | context. The context will be \l {isValid()}{invalid} if it was not | - | ||||||||||||||||||
2153 | possible to obtain a GL context at all. | - | ||||||||||||||||||
2154 | - | |||||||||||||||||||
2155 | \sa format(), isValid() | - | ||||||||||||||||||
2156 | */ | - | ||||||||||||||||||
2157 | QGLContext::QGLContext(const QGLFormat &format) | - | ||||||||||||||||||
2158 | : d_ptr(new QGLContextPrivate(this)) | - | ||||||||||||||||||
2159 | { | - | ||||||||||||||||||
2160 | Q_D(QGLContext); | - | ||||||||||||||||||
2161 | d->init(0, format); | - | ||||||||||||||||||
2162 | } never executed: end of block | 0 | ||||||||||||||||||
2163 | - | |||||||||||||||||||
2164 | static void qDeleteQGLContext(void *handle) | - | ||||||||||||||||||
2165 | { | - | ||||||||||||||||||
2166 | QGLContext *context = static_cast<QGLContext *>(handle); | - | ||||||||||||||||||
2167 | delete context; | - | ||||||||||||||||||
2168 | } never executed: end of block | 0 | ||||||||||||||||||
2169 | - | |||||||||||||||||||
2170 | QGLContext::QGLContext(QOpenGLContext *context) | - | ||||||||||||||||||
2171 | : d_ptr(new QGLContextPrivate(this)) | - | ||||||||||||||||||
2172 | { | - | ||||||||||||||||||
2173 | Q_D(QGLContext); | - | ||||||||||||||||||
2174 | d->init(0, QGLFormat::fromSurfaceFormat(context->format())); | - | ||||||||||||||||||
2175 | d->guiGlContext = context; | - | ||||||||||||||||||
2176 | d->guiGlContext->setQGLContextHandle(this, qDeleteQGLContext); | - | ||||||||||||||||||
2177 | d->ownContext = false; | - | ||||||||||||||||||
2178 | d->valid = context->isValid(); | - | ||||||||||||||||||
2179 | d->setupSharing(); | - | ||||||||||||||||||
2180 | } never executed: end of block | 0 | ||||||||||||||||||
2181 | - | |||||||||||||||||||
2182 | /*! | - | ||||||||||||||||||
2183 | Returns the OpenGL context handle. | - | ||||||||||||||||||
2184 | */ | - | ||||||||||||||||||
2185 | QOpenGLContext *QGLContext::contextHandle() const | - | ||||||||||||||||||
2186 | { | - | ||||||||||||||||||
2187 | Q_D(const QGLContext); | - | ||||||||||||||||||
2188 | return d->guiGlContext; executed 81 times by 3 tests: return d->guiGlContext; Executed by:
| 81 | ||||||||||||||||||
2189 | } | - | ||||||||||||||||||
2190 | - | |||||||||||||||||||
2191 | /*! | - | ||||||||||||||||||
2192 | Returns an OpenGL context for the window context specified by the \a context | - | ||||||||||||||||||
2193 | parameter. | - | ||||||||||||||||||
2194 | */ | - | ||||||||||||||||||
2195 | QGLContext *QGLContext::fromOpenGLContext(QOpenGLContext *context) | - | ||||||||||||||||||
2196 | { | - | ||||||||||||||||||
2197 | if (!context)
| 0-66 | ||||||||||||||||||
2198 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2199 | if (context->qGLContextHandle()) {
| 0-66 | ||||||||||||||||||
2200 | return reinterpret_cast<QGLContext *>(context->qGLContextHandle()); executed 66 times by 3 tests: return reinterpret_cast<QGLContext *>(context->qGLContextHandle()); Executed by:
| 66 | ||||||||||||||||||
2201 | } | - | ||||||||||||||||||
2202 | QGLContext *glContext = new QGLContext(context); | - | ||||||||||||||||||
2203 | //Don't call create on context. This can cause the platformFormat to be set on the widget, which | - | ||||||||||||||||||
2204 | //will cause the platformWindow to be recreated. | - | ||||||||||||||||||
2205 | return glContext; never executed: return glContext; | 0 | ||||||||||||||||||
2206 | } | - | ||||||||||||||||||
2207 | - | |||||||||||||||||||
2208 | /*! | - | ||||||||||||||||||
2209 | Destroys the OpenGL context and frees its resources. | - | ||||||||||||||||||
2210 | */ | - | ||||||||||||||||||
2211 | - | |||||||||||||||||||
2212 | QGLContext::~QGLContext() | - | ||||||||||||||||||
2213 | { | - | ||||||||||||||||||
2214 | // remove any textures cached in this context | - | ||||||||||||||||||
2215 | QGLTextureCache::instance()->removeContextTextures(this); | - | ||||||||||||||||||
2216 | - | |||||||||||||||||||
2217 | // clean up resources specific to this context | - | ||||||||||||||||||
2218 | d_ptr->cleanup(); | - | ||||||||||||||||||
2219 | - | |||||||||||||||||||
2220 | QGLSignalProxy::instance()->emitAboutToDestroyContext(this); | - | ||||||||||||||||||
2221 | reset(); | - | ||||||||||||||||||
2222 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2223 | - | |||||||||||||||||||
2224 | void QGLContextPrivate::cleanup() | - | ||||||||||||||||||
2225 | { | - | ||||||||||||||||||
2226 | } | - | ||||||||||||||||||
2227 | - | |||||||||||||||||||
2228 | #define ctx q_ptr | - | ||||||||||||||||||
2229 | void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) | - | ||||||||||||||||||
2230 | { | - | ||||||||||||||||||
2231 | Q_Q(QGLContext); | - | ||||||||||||||||||
2232 | Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT); | - | ||||||||||||||||||
2233 | #ifdef glEnableVertexAttribArray | - | ||||||||||||||||||
2234 | Q_ASSERT(glEnableVertexAttribArray); | - | ||||||||||||||||||
2235 | #endif | - | ||||||||||||||||||
2236 | - | |||||||||||||||||||
2237 | if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
| 2-18 | ||||||||||||||||||
2238 | q->functions()->glDisableVertexAttribArray(arrayIndex); executed 2 times by 1 test: q->functions()->glDisableVertexAttribArray(arrayIndex); Executed by:
| 2 | ||||||||||||||||||
2239 | - | |||||||||||||||||||
2240 | if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled)
| 2-18 | ||||||||||||||||||
2241 | q->functions()->glEnableVertexAttribArray(arrayIndex); executed 2 times by 1 test: q->functions()->glEnableVertexAttribArray(arrayIndex); Executed by:
| 2 | ||||||||||||||||||
2242 | - | |||||||||||||||||||
2243 | vertexAttributeArraysEnabledState[arrayIndex] = enabled; | - | ||||||||||||||||||
2244 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
2245 | - | |||||||||||||||||||
2246 | void QGLContextPrivate::syncGlState() | - | ||||||||||||||||||
2247 | { | - | ||||||||||||||||||
2248 | Q_Q(QGLContext); | - | ||||||||||||||||||
2249 | #ifdef glEnableVertexAttribArray | - | ||||||||||||||||||
2250 | Q_ASSERT(glEnableVertexAttribArray); | - | ||||||||||||||||||
2251 | #endif | - | ||||||||||||||||||
2252 | for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) {
| 2-6 | ||||||||||||||||||
2253 | if (vertexAttributeArraysEnabledState[i])
| 0-6 | ||||||||||||||||||
2254 | q->functions()->glEnableVertexAttribArray(i); never executed: q->functions()->glEnableVertexAttribArray(i); | 0 | ||||||||||||||||||
2255 | else | - | ||||||||||||||||||
2256 | q->functions()->glDisableVertexAttribArray(i); executed 6 times by 1 test: q->functions()->glDisableVertexAttribArray(i); Executed by:
| 6 | ||||||||||||||||||
2257 | } | - | ||||||||||||||||||
2258 | - | |||||||||||||||||||
2259 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
2260 | #undef ctx | - | ||||||||||||||||||
2261 | - | |||||||||||||||||||
2262 | void QGLContextPrivate::swapRegion(const QRegion &) | - | ||||||||||||||||||
2263 | { | - | ||||||||||||||||||
2264 | Q_Q(QGLContext); | - | ||||||||||||||||||
2265 | q->swapBuffers(); | - | ||||||||||||||||||
2266 | } never executed: end of block | 0 | ||||||||||||||||||
2267 | - | |||||||||||||||||||
2268 | /*! | - | ||||||||||||||||||
2269 | \overload | - | ||||||||||||||||||
2270 | - | |||||||||||||||||||
2271 | Reads the compressed texture file \a fileName and generates a 2D GL | - | ||||||||||||||||||
2272 | texture from it. | - | ||||||||||||||||||
2273 | - | |||||||||||||||||||
2274 | This function can load DirectDrawSurface (DDS) textures in the | - | ||||||||||||||||||
2275 | DXT1, DXT3 and DXT5 DDS formats if the \c GL_ARB_texture_compression | - | ||||||||||||||||||
2276 | and \c GL_EXT_texture_compression_s3tc extensions are supported. | - | ||||||||||||||||||
2277 | - | |||||||||||||||||||
2278 | Since 4.6.1, textures in the ETC1 format can be loaded if the | - | ||||||||||||||||||
2279 | \c GL_OES_compressed_ETC1_RGB8_texture extension is supported | - | ||||||||||||||||||
2280 | and the ETC1 texture has been encapsulated in the PVR container format. | - | ||||||||||||||||||
2281 | Also, textures in the PVRTC2 and PVRTC4 formats can be loaded | - | ||||||||||||||||||
2282 | if the \c GL_IMG_texture_compression_pvrtc extension is supported. | - | ||||||||||||||||||
2283 | - | |||||||||||||||||||
2284 | \sa deleteTexture() | - | ||||||||||||||||||
2285 | */ | - | ||||||||||||||||||
2286 | - | |||||||||||||||||||
2287 | GLuint QGLContext::bindTexture(const QString &fileName) | - | ||||||||||||||||||
2288 | { | - | ||||||||||||||||||
2289 | QGLTexture texture(this); | - | ||||||||||||||||||
2290 | QSize size = texture.bindCompressedTexture(fileName); | - | ||||||||||||||||||
2291 | if (!size.isValid())
| 0 | ||||||||||||||||||
2292 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2293 | return texture.id; never executed: return texture.id; | 0 | ||||||||||||||||||
2294 | } | - | ||||||||||||||||||
2295 | - | |||||||||||||||||||
2296 | static inline QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format) | - | ||||||||||||||||||
2297 | { | - | ||||||||||||||||||
2298 | if (texture_format == GL_BGRA) {
| 0 | ||||||||||||||||||
2299 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
2300 | return ((src_pixel << 24) & 0xff000000) never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
2301 | | ((src_pixel >> 24) & 0x000000ff) never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
2302 | | ((src_pixel << 8) & 0x00ff0000) never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
2303 | | ((src_pixel >> 8) & 0x0000ff00); never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
2304 | } else { | - | ||||||||||||||||||
2305 | return src_pixel; never executed: return src_pixel; | 0 | ||||||||||||||||||
2306 | } | - | ||||||||||||||||||
2307 | } else { // GL_RGBA | - | ||||||||||||||||||
2308 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
2309 | return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); never executed: return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); | 0 | ||||||||||||||||||
2310 | } else { | - | ||||||||||||||||||
2311 | return ((src_pixel << 16) & 0xff0000) never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 | ||||||||||||||||||
2312 | | ((src_pixel >> 16) & 0xff) never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 | ||||||||||||||||||
2313 | | (src_pixel & 0xff00ff00); never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 | ||||||||||||||||||
2314 | } | - | ||||||||||||||||||
2315 | } | - | ||||||||||||||||||
2316 | } | - | ||||||||||||||||||
2317 | - | |||||||||||||||||||
2318 | static void convertToGLFormatHelper(QImage &dst, const QImage &img, GLenum texture_format) | - | ||||||||||||||||||
2319 | { | - | ||||||||||||||||||
2320 | Q_ASSERT(dst.depth() == 32); | - | ||||||||||||||||||
2321 | Q_ASSERT(img.depth() == 32); | - | ||||||||||||||||||
2322 | - | |||||||||||||||||||
2323 | if (dst.size() != img.size()) {
| 0 | ||||||||||||||||||
2324 | int target_width = dst.width(); | - | ||||||||||||||||||
2325 | int target_height = dst.height(); | - | ||||||||||||||||||
2326 | qreal sx = target_width / qreal(img.width()); | - | ||||||||||||||||||
2327 | qreal sy = target_height / qreal(img.height()); | - | ||||||||||||||||||
2328 | - | |||||||||||||||||||
2329 | quint32 *dest = (quint32 *) dst.scanLine(0); // NB! avoid detach here | - | ||||||||||||||||||
2330 | const uchar *srcPixels = img.constScanLine(img.height() - 1); | - | ||||||||||||||||||
2331 | int sbpl = img.bytesPerLine(); | - | ||||||||||||||||||
2332 | int dbpl = dst.bytesPerLine(); | - | ||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | int ix = int(0x00010000 / sx); | - | ||||||||||||||||||
2335 | int iy = int(0x00010000 / sy); | - | ||||||||||||||||||
2336 | - | |||||||||||||||||||
2337 | quint32 basex = int(0.5 * ix); | - | ||||||||||||||||||
2338 | quint32 srcy = int(0.5 * iy); | - | ||||||||||||||||||
2339 | - | |||||||||||||||||||
2340 | // scale, swizzle and mirror in one loop | - | ||||||||||||||||||
2341 | while (target_height--) {
| 0 | ||||||||||||||||||
2342 | const uint *src = (const quint32 *) (srcPixels - (srcy >> 16) * sbpl); | - | ||||||||||||||||||
2343 | int srcx = basex; | - | ||||||||||||||||||
2344 | for (int x=0; x<target_width; ++x) {
| 0 | ||||||||||||||||||
2345 | dest[x] = qt_gl_convertToGLFormatHelper(src[srcx >> 16], texture_format); | - | ||||||||||||||||||
2346 | srcx += ix; | - | ||||||||||||||||||
2347 | } never executed: end of block | 0 | ||||||||||||||||||
2348 | dest = (quint32 *)(((uchar *) dest) + dbpl); | - | ||||||||||||||||||
2349 | srcy += iy; | - | ||||||||||||||||||
2350 | } never executed: end of block | 0 | ||||||||||||||||||
2351 | } else { never executed: end of block | 0 | ||||||||||||||||||
2352 | const int width = img.width(); | - | ||||||||||||||||||
2353 | const int height = img.height(); | - | ||||||||||||||||||
2354 | const uint *p = (const uint*) img.scanLine(img.height() - 1); | - | ||||||||||||||||||
2355 | uint *q = (uint*) dst.scanLine(0); | - | ||||||||||||||||||
2356 | - | |||||||||||||||||||
2357 | if (texture_format == GL_BGRA) {
| 0 | ||||||||||||||||||
2358 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
2359 | // mirror + swizzle | - | ||||||||||||||||||
2360 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
2361 | const uint *end = p + width; | - | ||||||||||||||||||
2362 | while (p < end) {
| 0 | ||||||||||||||||||
2363 | *q = ((*p << 24) & 0xff000000) | - | ||||||||||||||||||
2364 | | ((*p >> 24) & 0x000000ff) | - | ||||||||||||||||||
2365 | | ((*p << 8) & 0x00ff0000) | - | ||||||||||||||||||
2366 | | ((*p >> 8) & 0x0000ff00); | - | ||||||||||||||||||
2367 | p++; | - | ||||||||||||||||||
2368 | q++; | - | ||||||||||||||||||
2369 | } never executed: end of block | 0 | ||||||||||||||||||
2370 | p -= 2 * width; | - | ||||||||||||||||||
2371 | } never executed: end of block | 0 | ||||||||||||||||||
2372 | } else { never executed: end of block | 0 | ||||||||||||||||||
2373 | const uint bytesPerLine = img.bytesPerLine(); | - | ||||||||||||||||||
2374 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
2375 | memcpy(q, p, bytesPerLine); | - | ||||||||||||||||||
2376 | q += width; | - | ||||||||||||||||||
2377 | p -= width; | - | ||||||||||||||||||
2378 | } never executed: end of block | 0 | ||||||||||||||||||
2379 | } never executed: end of block | 0 | ||||||||||||||||||
2380 | } else { | - | ||||||||||||||||||
2381 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
2382 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
2383 | const uint *end = p + width; | - | ||||||||||||||||||
2384 | while (p < end) {
| 0 | ||||||||||||||||||
2385 | *q = (*p << 8) | ((*p >> 24) & 0xff); | - | ||||||||||||||||||
2386 | p++; | - | ||||||||||||||||||
2387 | q++; | - | ||||||||||||||||||
2388 | } never executed: end of block | 0 | ||||||||||||||||||
2389 | p -= 2 * width; | - | ||||||||||||||||||
2390 | } never executed: end of block | 0 | ||||||||||||||||||
2391 | } else { never executed: end of block | 0 | ||||||||||||||||||
2392 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
2393 | const uint *end = p + width; | - | ||||||||||||||||||
2394 | while (p < end) {
| 0 | ||||||||||||||||||
2395 | *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00); | - | ||||||||||||||||||
2396 | p++; | - | ||||||||||||||||||
2397 | q++; | - | ||||||||||||||||||
2398 | } never executed: end of block | 0 | ||||||||||||||||||
2399 | p -= 2 * width; | - | ||||||||||||||||||
2400 | } never executed: end of block | 0 | ||||||||||||||||||
2401 | } never executed: end of block | 0 | ||||||||||||||||||
2402 | } | - | ||||||||||||||||||
2403 | } | - | ||||||||||||||||||
2404 | } | - | ||||||||||||||||||
2405 | - | |||||||||||||||||||
2406 | /*! \internal */ | - | ||||||||||||||||||
2407 | QGLTexture *QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint format, | - | ||||||||||||||||||
2408 | QGLContext::BindOptions options) | - | ||||||||||||||||||
2409 | { | - | ||||||||||||||||||
2410 | Q_Q(QGLContext); | - | ||||||||||||||||||
2411 | - | |||||||||||||||||||
2412 | const qint64 key = image.cacheKey(); | - | ||||||||||||||||||
2413 | QGLTexture *texture = textureCacheLookup(key, target); | - | ||||||||||||||||||
2414 | if (texture) {
| 0 | ||||||||||||||||||
2415 | if (image.paintingActive()) {
| 0 | ||||||||||||||||||
2416 | // A QPainter is active on the image - take the safe route and replace the texture. | - | ||||||||||||||||||
2417 | q->deleteTexture(texture->id); | - | ||||||||||||||||||
2418 | texture = 0; | - | ||||||||||||||||||
2419 | } else { never executed: end of block | 0 | ||||||||||||||||||
2420 | qgl_functions()->glBindTexture(target, texture->id); | - | ||||||||||||||||||
2421 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
2422 | } | - | ||||||||||||||||||
2423 | } | - | ||||||||||||||||||
2424 | - | |||||||||||||||||||
2425 | if (!texture)
| 0 | ||||||||||||||||||
2426 | texture = bindTexture(image, target, format, key, options); never executed: texture = bindTexture(image, target, format, key, options); | 0 | ||||||||||||||||||
2427 | // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null | - | ||||||||||||||||||
2428 | Q_ASSERT(texture); | - | ||||||||||||||||||
2429 | - | |||||||||||||||||||
2430 | // Enable the cleanup hooks for this image so that the texture cache entry is removed when the | - | ||||||||||||||||||
2431 | // image gets deleted: | - | ||||||||||||||||||
2432 | QImagePixmapCleanupHooks::enableCleanupHooks(image); | - | ||||||||||||||||||
2433 | - | |||||||||||||||||||
2434 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
2435 | } | - | ||||||||||||||||||
2436 | - | |||||||||||||||||||
2437 | // #define QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2438 | - | |||||||||||||||||||
2439 | // ####TODO Properly #ifdef this file to use #define symbols actually defined | - | ||||||||||||||||||
2440 | // by OpenGL/ES includes | - | ||||||||||||||||||
2441 | #ifndef GL_UNSIGNED_INT_8_8_8_8_REV | - | ||||||||||||||||||
2442 | #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 | - | ||||||||||||||||||
2443 | #endif | - | ||||||||||||||||||
2444 | - | |||||||||||||||||||
2445 | // map from Qt's ARGB endianness-dependent format to GL's big-endian RGBA layout | - | ||||||||||||||||||
2446 | static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type) | - | ||||||||||||||||||
2447 | { | - | ||||||||||||||||||
2448 | const int width = img.width(); | - | ||||||||||||||||||
2449 | const int height = img.height(); | - | ||||||||||||||||||
2450 | - | |||||||||||||||||||
2451 | if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV
| 0 | ||||||||||||||||||
2452 | || (pixel_type == GL_UNSIGNED_BYTE && QSysInfo::ByteOrder == QSysInfo::LittleEndian))
| 0 | ||||||||||||||||||
2453 | { | - | ||||||||||||||||||
2454 | for (int i = 0; i < height; ++i) {
| 0 | ||||||||||||||||||
2455 | uint *p = (uint *) img.scanLine(i); | - | ||||||||||||||||||
2456 | for (int x = 0; x < width; ++x)
| 0 | ||||||||||||||||||
2457 | p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); never executed: p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); | 0 | ||||||||||||||||||
2458 | } never executed: end of block | 0 | ||||||||||||||||||
2459 | } else { never executed: end of block | 0 | ||||||||||||||||||
2460 | for (int i = 0; i < height; ++i) {
| 0 | ||||||||||||||||||
2461 | uint *p = (uint *) img.scanLine(i); | - | ||||||||||||||||||
2462 | for (int x = 0; x < width; ++x)
| 0 | ||||||||||||||||||
2463 | p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); never executed: p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); | 0 | ||||||||||||||||||
2464 | } never executed: end of block | 0 | ||||||||||||||||||
2465 | } never executed: end of block | 0 | ||||||||||||||||||
2466 | } | - | ||||||||||||||||||
2467 | - | |||||||||||||||||||
2468 | QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint internalFormat, | - | ||||||||||||||||||
2469 | const qint64 key, QGLContext::BindOptions options) | - | ||||||||||||||||||
2470 | { | - | ||||||||||||||||||
2471 | Q_Q(QGLContext); | - | ||||||||||||||||||
2472 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
2473 | - | |||||||||||||||||||
2474 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2475 | printf("QGLContextPrivate::bindTexture(), imageSize=(%d,%d), internalFormat =0x%x, options=%x, key=%llx\n", | - | ||||||||||||||||||
2476 | image.width(), image.height(), internalFormat, int(options), key); | - | ||||||||||||||||||
2477 | QTime time; | - | ||||||||||||||||||
2478 | time.start(); | - | ||||||||||||||||||
2479 | #endif | - | ||||||||||||||||||
2480 | - | |||||||||||||||||||
2481 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
2482 | // Reset the gl error stack...git | - | ||||||||||||||||||
2483 | while (funcs->glGetError() != GL_NO_ERROR) ; never executed: ;
| 0 | ||||||||||||||||||
2484 | #endif | - | ||||||||||||||||||
2485 | - | |||||||||||||||||||
2486 | // Scale the pixmap if needed. GL textures needs to have the | - | ||||||||||||||||||
2487 | // dimensions 2^n+2(border) x 2^m+2(border), unless we're using GL | - | ||||||||||||||||||
2488 | // 2.0 or use the GL_TEXTURE_RECTANGLE texture target | - | ||||||||||||||||||
2489 | int tx_w = qNextPowerOfTwo(image.width() - 1); | - | ||||||||||||||||||
2490 | int tx_h = qNextPowerOfTwo(image.height() - 1); | - | ||||||||||||||||||
2491 | - | |||||||||||||||||||
2492 | QImage img = image; | - | ||||||||||||||||||
2493 | - | |||||||||||||||||||
2494 | if (!qgl_extensions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)
| 0 | ||||||||||||||||||
2495 | && !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0)
| 0 | ||||||||||||||||||
2496 | && (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height())))
| 0 | ||||||||||||||||||
2497 | { | - | ||||||||||||||||||
2498 | img = img.scaled(tx_w, tx_h); | - | ||||||||||||||||||
2499 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2500 | printf(" - upscaled to %dx%d (%d ms)\n", tx_w, tx_h, time.elapsed()); | - | ||||||||||||||||||
2501 | - | |||||||||||||||||||
2502 | #endif | - | ||||||||||||||||||
2503 | } never executed: end of block | 0 | ||||||||||||||||||
2504 | - | |||||||||||||||||||
2505 | GLuint filtering = options & QGLContext::LinearFilteringBindOption ? GL_LINEAR : GL_NEAREST;
| 0 | ||||||||||||||||||
2506 | - | |||||||||||||||||||
2507 | GLuint tx_id; | - | ||||||||||||||||||
2508 | funcs->glGenTextures(1, &tx_id); | - | ||||||||||||||||||
2509 | funcs->glBindTexture(target, tx_id); | - | ||||||||||||||||||
2510 | funcs->glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filtering); | - | ||||||||||||||||||
2511 | - | |||||||||||||||||||
2512 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
2513 | bool genMipmap = !ctx->isOpenGLES(); | - | ||||||||||||||||||
2514 | if (glFormat.directRendering()
| 0 | ||||||||||||||||||
2515 | && (qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::GenerateMipmap))
| 0 | ||||||||||||||||||
2516 | && target == GL_TEXTURE_2D
| 0 | ||||||||||||||||||
2517 | && (options & QGLContext::MipmapBindOption))
| 0 | ||||||||||||||||||
2518 | { | - | ||||||||||||||||||
2519 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
2520 | if (genMipmap) {
| 0 | ||||||||||||||||||
2521 | funcs->glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); | - | ||||||||||||||||||
2522 | funcs->glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); | - | ||||||||||||||||||
2523 | } else { never executed: end of block | 0 | ||||||||||||||||||
2524 | funcs->glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); | - | ||||||||||||||||||
2525 | genMipmap = true; | - | ||||||||||||||||||
2526 | } never executed: end of block | 0 | ||||||||||||||||||
2527 | #else | - | ||||||||||||||||||
2528 | funcs->glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); | - | ||||||||||||||||||
2529 | genMipmap = true; | - | ||||||||||||||||||
2530 | #endif | - | ||||||||||||||||||
2531 | funcs->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, options & QGLContext::LinearFilteringBindOption | - | ||||||||||||||||||
2532 | ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST); | - | ||||||||||||||||||
2533 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2534 | printf(" - generating mipmaps (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
2535 | #endif | - | ||||||||||||||||||
2536 | } else { never executed: end of block | 0 | ||||||||||||||||||
2537 | funcs->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filtering); | - | ||||||||||||||||||
2538 | } never executed: end of block | 0 | ||||||||||||||||||
2539 | - | |||||||||||||||||||
2540 | QImage::Format target_format = img.format(); | - | ||||||||||||||||||
2541 | bool premul = options & QGLContext::PremultipliedAlphaBindOption; | - | ||||||||||||||||||
2542 | bool needsbyteswap = true; | - | ||||||||||||||||||
2543 | GLenum externalFormat; | - | ||||||||||||||||||
2544 | GLuint pixel_type; | - | ||||||||||||||||||
2545 | if (target_format == QImage::Format_RGBA8888
| 0 | ||||||||||||||||||
2546 | || target_format == QImage::Format_RGBA8888_Premultiplied
| 0 | ||||||||||||||||||
2547 | || target_format == QImage::Format_RGBX8888) {
| 0 | ||||||||||||||||||
2548 | externalFormat = GL_RGBA; | - | ||||||||||||||||||
2549 | pixel_type = GL_UNSIGNED_BYTE; | - | ||||||||||||||||||
2550 | needsbyteswap = false; | - | ||||||||||||||||||
2551 | } else if (qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::BGRATextureFormat)) { never executed: end of block
| 0 | ||||||||||||||||||
2552 | externalFormat = GL_BGRA; | - | ||||||||||||||||||
2553 | needsbyteswap = false; | - | ||||||||||||||||||
2554 | if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2)
| 0 | ||||||||||||||||||
2555 | pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV; never executed: pixel_type = 0x8367; | 0 | ||||||||||||||||||
2556 | else | - | ||||||||||||||||||
2557 | pixel_type = GL_UNSIGNED_BYTE; never executed: pixel_type = 0x1401; | 0 | ||||||||||||||||||
2558 | } else { | - | ||||||||||||||||||
2559 | externalFormat = GL_RGBA; | - | ||||||||||||||||||
2560 | pixel_type = GL_UNSIGNED_BYTE; | - | ||||||||||||||||||
2561 | } never executed: end of block | 0 | ||||||||||||||||||
2562 | - | |||||||||||||||||||
2563 | switch (target_format) { | - | ||||||||||||||||||
2564 | case QImage::Format_ARGB32: never executed: case QImage::Format_ARGB32: | 0 | ||||||||||||||||||
2565 | if (premul) {
| 0 | ||||||||||||||||||
2566 | img = img.convertToFormat(target_format = QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||
2567 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2568 | printf(" - converted ARGB32 -> ARGB32_Premultiplied (%d ms) \n", time.elapsed()); | - | ||||||||||||||||||
2569 | #endif | - | ||||||||||||||||||
2570 | } never executed: end of block | 0 | ||||||||||||||||||
2571 | break; never executed: break; | 0 | ||||||||||||||||||
2572 | case QImage::Format_ARGB32_Premultiplied: never executed: case QImage::Format_ARGB32_Premultiplied: | 0 | ||||||||||||||||||
2573 | if (!premul) {
| 0 | ||||||||||||||||||
2574 | img = img.convertToFormat(target_format = QImage::Format_ARGB32); | - | ||||||||||||||||||
2575 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2576 | printf(" - converted ARGB32_Premultiplied -> ARGB32 (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
2577 | #endif | - | ||||||||||||||||||
2578 | } never executed: end of block | 0 | ||||||||||||||||||
2579 | break; never executed: break; | 0 | ||||||||||||||||||
2580 | case QImage::Format_RGBA8888: never executed: case QImage::Format_RGBA8888: | 0 | ||||||||||||||||||
2581 | if (premul) {
| 0 | ||||||||||||||||||
2582 | img = img.convertToFormat(target_format = QImage::Format_RGBA8888_Premultiplied); | - | ||||||||||||||||||
2583 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2584 | printf(" - converted RGBA8888 -> RGBA8888_Premultiplied (%d ms) \n", time.elapsed()); | - | ||||||||||||||||||
2585 | #endif | - | ||||||||||||||||||
2586 | } never executed: end of block | 0 | ||||||||||||||||||
2587 | break; never executed: break; | 0 | ||||||||||||||||||
2588 | case QImage::Format_RGBA8888_Premultiplied: never executed: case QImage::Format_RGBA8888_Premultiplied: | 0 | ||||||||||||||||||
2589 | if (!premul) {
| 0 | ||||||||||||||||||
2590 | img = img.convertToFormat(target_format = QImage::Format_RGBA8888); | - | ||||||||||||||||||
2591 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2592 | printf(" - converted RGBA8888_Premultiplied -> RGBA8888 (%d ms) \n", time.elapsed()); | - | ||||||||||||||||||
2593 | #endif | - | ||||||||||||||||||
2594 | } never executed: end of block | 0 | ||||||||||||||||||
2595 | break; never executed: break; | 0 | ||||||||||||||||||
2596 | case QImage::Format_RGB16: never executed: case QImage::Format_RGB16: | 0 | ||||||||||||||||||
2597 | pixel_type = GL_UNSIGNED_SHORT_5_6_5; | - | ||||||||||||||||||
2598 | externalFormat = GL_RGB; | - | ||||||||||||||||||
2599 | internalFormat = GL_RGB; | - | ||||||||||||||||||
2600 | needsbyteswap = false; | - | ||||||||||||||||||
2601 | break; never executed: break; | 0 | ||||||||||||||||||
2602 | case QImage::Format_RGB32: never executed: case QImage::Format_RGB32: | 0 | ||||||||||||||||||
2603 | case QImage::Format_RGBX8888: never executed: case QImage::Format_RGBX8888: | 0 | ||||||||||||||||||
2604 | break; never executed: break; | 0 | ||||||||||||||||||
2605 | default: never executed: default: | 0 | ||||||||||||||||||
2606 | // Ideally more formats would be converted directly to an RGBA8888 format, | - | ||||||||||||||||||
2607 | // but we are only guaranteed to have a fast conversion to an ARGB format. | - | ||||||||||||||||||
2608 | if (img.hasAlphaChannel()) {
| 0 | ||||||||||||||||||
2609 | img = img.convertToFormat(premul | - | ||||||||||||||||||
2610 | ? QImage::Format_ARGB32_Premultiplied | - | ||||||||||||||||||
2611 | : QImage::Format_ARGB32); | - | ||||||||||||||||||
2612 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2613 | printf(" - converted to 32-bit alpha format (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
2614 | #endif | - | ||||||||||||||||||
2615 | } else { never executed: end of block | 0 | ||||||||||||||||||
2616 | img = img.convertToFormat(QImage::Format_RGB32); | - | ||||||||||||||||||
2617 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2618 | printf(" - converted to 32-bit (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
2619 | #endif | - | ||||||||||||||||||
2620 | } never executed: end of block | 0 | ||||||||||||||||||
2621 | } | - | ||||||||||||||||||
2622 | - | |||||||||||||||||||
2623 | if (options & QGLContext::InvertedYBindOption) {
| 0 | ||||||||||||||||||
2624 | if (img.isDetached()) {
| 0 | ||||||||||||||||||
2625 | int ipl = img.bytesPerLine() / 4; | - | ||||||||||||||||||
2626 | int h = img.height(); | - | ||||||||||||||||||
2627 | for (int y=0; y<h/2; ++y) {
| 0 | ||||||||||||||||||
2628 | int *a = (int *) img.scanLine(y); | - | ||||||||||||||||||
2629 | int *b = (int *) img.scanLine(h - y - 1); | - | ||||||||||||||||||
2630 | for (int x=0; x<ipl; ++x)
| 0 | ||||||||||||||||||
2631 | qSwap(a[x], b[x]); never executed: qSwap(a[x], b[x]); | 0 | ||||||||||||||||||
2632 | } never executed: end of block | 0 | ||||||||||||||||||
2633 | } else { never executed: end of block | 0 | ||||||||||||||||||
2634 | // Create a new image and copy across. If we use the | - | ||||||||||||||||||
2635 | // above in-place code then a full copy of the image is | - | ||||||||||||||||||
2636 | // made before the lines are swapped, which processes the | - | ||||||||||||||||||
2637 | // data twice. This version should only do it once. | - | ||||||||||||||||||
2638 | img = img.mirrored(); | - | ||||||||||||||||||
2639 | } never executed: end of block | 0 | ||||||||||||||||||
2640 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2641 | printf(" - flipped bits over y (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
2642 | #endif | - | ||||||||||||||||||
2643 | } | - | ||||||||||||||||||
2644 | - | |||||||||||||||||||
2645 | if (needsbyteswap) {
| 0 | ||||||||||||||||||
2646 | // The only case where we end up with a depth different from | - | ||||||||||||||||||
2647 | // 32 in the switch above is for the RGB16 case, where we do | - | ||||||||||||||||||
2648 | // not need a byteswap. | - | ||||||||||||||||||
2649 | Q_ASSERT(img.depth() == 32); | - | ||||||||||||||||||
2650 | qgl_byteSwapImage(img, pixel_type); | - | ||||||||||||||||||
2651 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2652 | printf(" - did byte swapping (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
2653 | #endif | - | ||||||||||||||||||
2654 | } never executed: end of block | 0 | ||||||||||||||||||
2655 | if (ctx->isOpenGLES()) {
| 0 | ||||||||||||||||||
2656 | // OpenGL/ES requires that the internal and external formats be | - | ||||||||||||||||||
2657 | // identical. | - | ||||||||||||||||||
2658 | internalFormat = externalFormat; | - | ||||||||||||||||||
2659 | } never executed: end of block | 0 | ||||||||||||||||||
2660 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2661 | printf(" - uploading, image.format=%d, externalFormat=0x%x, internalFormat=0x%x, pixel_type=0x%x\n", | - | ||||||||||||||||||
2662 | img.format(), externalFormat, internalFormat, pixel_type); | - | ||||||||||||||||||
2663 | #endif | - | ||||||||||||||||||
2664 | - | |||||||||||||||||||
2665 | const QImage &constRef = img; // to avoid detach in bits()... | - | ||||||||||||||||||
2666 | funcs->glTexImage2D(target, 0, internalFormat, img.width(), img.height(), 0, externalFormat, | - | ||||||||||||||||||
2667 | pixel_type, constRef.bits()); | - | ||||||||||||||||||
2668 | if (genMipmap && ctx->isOpenGLES())
| 0 | ||||||||||||||||||
2669 | q->functions()->glGenerateMipmap(target); never executed: q->functions()->glGenerateMipmap(target); | 0 | ||||||||||||||||||
2670 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
2671 | GLenum error = funcs->glGetError(); | - | ||||||||||||||||||
2672 | if (error != GL_NO_ERROR) {
| 0 | ||||||||||||||||||
2673 | qWarning(" - texture upload failed, error code 0x%x, enum: %d (%x)\n", error, target, target); | - | ||||||||||||||||||
2674 | } never executed: end of block | 0 | ||||||||||||||||||
2675 | #endif | - | ||||||||||||||||||
2676 | - | |||||||||||||||||||
2677 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
2678 | static int totalUploadTime = 0; | - | ||||||||||||||||||
2679 | totalUploadTime += time.elapsed(); | - | ||||||||||||||||||
2680 | printf(" - upload done in %d ms, (accumulated: %d ms)\n", time.elapsed(), totalUploadTime); | - | ||||||||||||||||||
2681 | #endif | - | ||||||||||||||||||
2682 | - | |||||||||||||||||||
2683 | - | |||||||||||||||||||
2684 | // this assumes the size of a texture is always smaller than the max cache size | - | ||||||||||||||||||
2685 | int cost = img.width()*img.height()*4/1024; | - | ||||||||||||||||||
2686 | QGLTexture *texture = new QGLTexture(q, tx_id, target, options); | - | ||||||||||||||||||
2687 | QGLTextureCache::instance()->insert(q, key, texture, cost); | - | ||||||||||||||||||
2688 | - | |||||||||||||||||||
2689 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
2690 | } | - | ||||||||||||||||||
2691 | - | |||||||||||||||||||
2692 | QGLTexture *QGLContextPrivate::textureCacheLookup(const qint64 key, GLenum target) | - | ||||||||||||||||||
2693 | { | - | ||||||||||||||||||
2694 | Q_Q(QGLContext); | - | ||||||||||||||||||
2695 | QGLTexture *texture = QGLTextureCache::instance()->getTexture(q, key); | - | ||||||||||||||||||
2696 | if (texture && texture->target == target
| 0 | ||||||||||||||||||
2697 | && (texture->context == q || QGLContext::areSharing(q, texture->context)))
| 0 | ||||||||||||||||||
2698 | { | - | ||||||||||||||||||
2699 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
2700 | } | - | ||||||||||||||||||
2701 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2702 | } | - | ||||||||||||||||||
2703 | - | |||||||||||||||||||
2704 | /*! \internal */ | - | ||||||||||||||||||
2705 | QGLTexture *QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, QGLContext::BindOptions options) | - | ||||||||||||||||||
2706 | { | - | ||||||||||||||||||
2707 | Q_Q(QGLContext); | - | ||||||||||||||||||
2708 | QPlatformPixmap *pd = pixmap.handle(); | - | ||||||||||||||||||
2709 | Q_UNUSED(pd); | - | ||||||||||||||||||
2710 | - | |||||||||||||||||||
2711 | const qint64 key = pixmap.cacheKey(); | - | ||||||||||||||||||
2712 | QGLTexture *texture = textureCacheLookup(key, target); | - | ||||||||||||||||||
2713 | if (texture) {
| 0 | ||||||||||||||||||
2714 | if (pixmap.paintingActive()) {
| 0 | ||||||||||||||||||
2715 | // A QPainter is active on the pixmap - take the safe route and replace the texture. | - | ||||||||||||||||||
2716 | q->deleteTexture(texture->id); | - | ||||||||||||||||||
2717 | texture = 0; | - | ||||||||||||||||||
2718 | } else { never executed: end of block | 0 | ||||||||||||||||||
2719 | qgl_functions()->glBindTexture(target, texture->id); | - | ||||||||||||||||||
2720 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
2721 | } | - | ||||||||||||||||||
2722 | } | - | ||||||||||||||||||
2723 | - | |||||||||||||||||||
2724 | if (!texture) {
| 0 | ||||||||||||||||||
2725 | QImage image; | - | ||||||||||||||||||
2726 | QPaintEngine* paintEngine = pixmap.paintEngine(); | - | ||||||||||||||||||
2727 | if (!paintEngine || paintEngine->type() != QPaintEngine::Raster)
| 0 | ||||||||||||||||||
2728 | image = pixmap.toImage(); never executed: image = pixmap.toImage(); | 0 | ||||||||||||||||||
2729 | else { | - | ||||||||||||||||||
2730 | // QRasterPixmapData::toImage() will deep-copy the backing QImage if there's an active QPainter on it. | - | ||||||||||||||||||
2731 | // For performance reasons, we don't want that here, so we temporarily redirect the paint engine. | - | ||||||||||||||||||
2732 | QPaintDevice* currentPaintDevice = paintEngine->paintDevice(); | - | ||||||||||||||||||
2733 | paintEngine->setPaintDevice(0); | - | ||||||||||||||||||
2734 | image = pixmap.toImage(); | - | ||||||||||||||||||
2735 | paintEngine->setPaintDevice(currentPaintDevice); | - | ||||||||||||||||||
2736 | } never executed: end of block | 0 | ||||||||||||||||||
2737 | - | |||||||||||||||||||
2738 | // If the system depth is 16 and the pixmap doesn't have an alpha channel | - | ||||||||||||||||||
2739 | // then we convert it to RGB16 in the hope that it gets uploaded as a 16 | - | ||||||||||||||||||
2740 | // bit texture which is much faster to access than a 32-bit one. | - | ||||||||||||||||||
2741 | if (pixmap.depth() == 16 && !image.hasAlphaChannel() )
| 0 | ||||||||||||||||||
2742 | image = image.convertToFormat(QImage::Format_RGB16); never executed: image = image.convertToFormat(QImage::Format_RGB16); | 0 | ||||||||||||||||||
2743 | texture = bindTexture(image, target, format, key, options); | - | ||||||||||||||||||
2744 | } never executed: end of block | 0 | ||||||||||||||||||
2745 | // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null | - | ||||||||||||||||||
2746 | Q_ASSERT(texture); | - | ||||||||||||||||||
2747 | - | |||||||||||||||||||
2748 | if (texture->id > 0)
| 0 | ||||||||||||||||||
2749 | QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); never executed: QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); | 0 | ||||||||||||||||||
2750 | - | |||||||||||||||||||
2751 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
2752 | } | - | ||||||||||||||||||
2753 | - | |||||||||||||||||||
2754 | /*! \internal */ | - | ||||||||||||||||||
2755 | int QGLContextPrivate::maxTextureSize() | - | ||||||||||||||||||
2756 | { | - | ||||||||||||||||||
2757 | if (max_texture_size != -1)
| 0 | ||||||||||||||||||
2758 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
2759 | - | |||||||||||||||||||
2760 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
2761 | funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | - | ||||||||||||||||||
2762 | - | |||||||||||||||||||
2763 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
2764 | Q_Q(QGLContext); | - | ||||||||||||||||||
2765 | if (!q->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
2766 | GLenum proxy = GL_PROXY_TEXTURE_2D; | - | ||||||||||||||||||
2767 | - | |||||||||||||||||||
2768 | GLint size; | - | ||||||||||||||||||
2769 | GLint next = 64; | - | ||||||||||||||||||
2770 | funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | - | ||||||||||||||||||
2771 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
2772 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); | - | ||||||||||||||||||
2773 | if (size == 0) {
| 0 | ||||||||||||||||||
2774 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
2775 | } | - | ||||||||||||||||||
2776 | do { | - | ||||||||||||||||||
2777 | size = next; | - | ||||||||||||||||||
2778 | next = size * 2; | - | ||||||||||||||||||
2779 | - | |||||||||||||||||||
2780 | if (next > max_texture_size)
| 0 | ||||||||||||||||||
2781 | break; never executed: break; | 0 | ||||||||||||||||||
2782 | funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | - | ||||||||||||||||||
2783 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); | - | ||||||||||||||||||
2784 | } while (next > size); never executed: end of block
| 0 | ||||||||||||||||||
2785 | - | |||||||||||||||||||
2786 | max_texture_size = size; | - | ||||||||||||||||||
2787 | } never executed: end of block | 0 | ||||||||||||||||||
2788 | #endif | - | ||||||||||||||||||
2789 | - | |||||||||||||||||||
2790 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
2791 | } | - | ||||||||||||||||||
2792 | - | |||||||||||||||||||
2793 | /*! | - | ||||||||||||||||||
2794 | Returns a QGLFunctions object that is initialized for this context. | - | ||||||||||||||||||
2795 | */ | - | ||||||||||||||||||
2796 | QGLFunctions *QGLContext::functions() const | - | ||||||||||||||||||
2797 | { | - | ||||||||||||||||||
2798 | QGLContextPrivate *d = const_cast<QGLContextPrivate *>(d_func()); | - | ||||||||||||||||||
2799 | if (!d->functions) {
| 1-9 | ||||||||||||||||||
2800 | d->functions = new QGLFunctions(this); | - | ||||||||||||||||||
2801 | d->functions->initializeGLFunctions(this); | - | ||||||||||||||||||
2802 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
2803 | return d->functions; executed 10 times by 1 test: return d->functions; Executed by:
| 10 | ||||||||||||||||||
2804 | } | - | ||||||||||||||||||
2805 | - | |||||||||||||||||||
2806 | /*! | - | ||||||||||||||||||
2807 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
2808 | on \a image. The generated texture id is returned and can be used in | - | ||||||||||||||||||
2809 | later \c glBindTexture() calls. | - | ||||||||||||||||||
2810 | - | |||||||||||||||||||
2811 | \overload | - | ||||||||||||||||||
2812 | */ | - | ||||||||||||||||||
2813 | GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format) | - | ||||||||||||||||||
2814 | { | - | ||||||||||||||||||
2815 | if (image.isNull())
| 0 | ||||||||||||||||||
2816 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2817 | - | |||||||||||||||||||
2818 | Q_D(QGLContext); | - | ||||||||||||||||||
2819 | QGLTexture *texture = d->bindTexture(image, target, format, DefaultBindOption); | - | ||||||||||||||||||
2820 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
2821 | } | - | ||||||||||||||||||
2822 | - | |||||||||||||||||||
2823 | /*! | - | ||||||||||||||||||
2824 | \since 4.6 | - | ||||||||||||||||||
2825 | - | |||||||||||||||||||
2826 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
2827 | on \a image. The generated texture id is returned and can be used | - | ||||||||||||||||||
2828 | in later \c glBindTexture() calls. | - | ||||||||||||||||||
2829 | - | |||||||||||||||||||
2830 | The \a target parameter specifies the texture target. The default | - | ||||||||||||||||||
2831 | target is \c GL_TEXTURE_2D. | - | ||||||||||||||||||
2832 | - | |||||||||||||||||||
2833 | The \a format parameter sets the internal format for the | - | ||||||||||||||||||
2834 | texture. The default format is \c GL_RGBA. | - | ||||||||||||||||||
2835 | - | |||||||||||||||||||
2836 | The binding \a options are a set of options used to decide how to | - | ||||||||||||||||||
2837 | bind the texture to the context. | - | ||||||||||||||||||
2838 | - | |||||||||||||||||||
2839 | The texture that is generated is cached, so multiple calls to | - | ||||||||||||||||||
2840 | bindTexture() with the same QImage will return the same texture | - | ||||||||||||||||||
2841 | id. | - | ||||||||||||||||||
2842 | - | |||||||||||||||||||
2843 | Note that we assume default values for the glPixelStore() and | - | ||||||||||||||||||
2844 | glPixelTransfer() parameters. | - | ||||||||||||||||||
2845 | - | |||||||||||||||||||
2846 | \sa deleteTexture() | - | ||||||||||||||||||
2847 | */ | - | ||||||||||||||||||
2848 | GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format, BindOptions options) | - | ||||||||||||||||||
2849 | { | - | ||||||||||||||||||
2850 | if (image.isNull())
| 0 | ||||||||||||||||||
2851 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2852 | - | |||||||||||||||||||
2853 | Q_D(QGLContext); | - | ||||||||||||||||||
2854 | QGLTexture *texture = d->bindTexture(image, target, format, options); | - | ||||||||||||||||||
2855 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
2856 | } | - | ||||||||||||||||||
2857 | - | |||||||||||||||||||
2858 | /*! \overload | - | ||||||||||||||||||
2859 | - | |||||||||||||||||||
2860 | Generates and binds a 2D GL texture based on \a pixmap. | - | ||||||||||||||||||
2861 | */ | - | ||||||||||||||||||
2862 | GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) | - | ||||||||||||||||||
2863 | { | - | ||||||||||||||||||
2864 | if (pixmap.isNull())
| 0 | ||||||||||||||||||
2865 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2866 | - | |||||||||||||||||||
2867 | Q_D(QGLContext); | - | ||||||||||||||||||
2868 | QGLTexture *texture = d->bindTexture(pixmap, target, format, DefaultBindOption); | - | ||||||||||||||||||
2869 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
2870 | } | - | ||||||||||||||||||
2871 | - | |||||||||||||||||||
2872 | /*! | - | ||||||||||||||||||
2873 | \overload | - | ||||||||||||||||||
2874 | \since 4.6 | - | ||||||||||||||||||
2875 | - | |||||||||||||||||||
2876 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
2877 | on \a pixmap. | - | ||||||||||||||||||
2878 | */ | - | ||||||||||||||||||
2879 | GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, BindOptions options) | - | ||||||||||||||||||
2880 | { | - | ||||||||||||||||||
2881 | if (pixmap.isNull())
| 0 | ||||||||||||||||||
2882 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2883 | - | |||||||||||||||||||
2884 | Q_D(QGLContext); | - | ||||||||||||||||||
2885 | QGLTexture *texture = d->bindTexture(pixmap, target, format, options); | - | ||||||||||||||||||
2886 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
2887 | } | - | ||||||||||||||||||
2888 | - | |||||||||||||||||||
2889 | /*! | - | ||||||||||||||||||
2890 | Removes the texture identified by \a id from the texture cache, | - | ||||||||||||||||||
2891 | and calls glDeleteTextures() to delete the texture from the | - | ||||||||||||||||||
2892 | context. | - | ||||||||||||||||||
2893 | - | |||||||||||||||||||
2894 | \sa bindTexture() | - | ||||||||||||||||||
2895 | */ | - | ||||||||||||||||||
2896 | void QGLContext::deleteTexture(GLuint id) | - | ||||||||||||||||||
2897 | { | - | ||||||||||||||||||
2898 | if (QGLTextureCache::instance()->remove(this, id))
| 0 | ||||||||||||||||||
2899 | return; never executed: return; | 0 | ||||||||||||||||||
2900 | qgl_functions()->glDeleteTextures(1, &id); | - | ||||||||||||||||||
2901 | } never executed: end of block | 0 | ||||||||||||||||||
2902 | - | |||||||||||||||||||
2903 | void qt_add_rect_to_array(const QRectF &r, GLfloat *array) | - | ||||||||||||||||||
2904 | { | - | ||||||||||||||||||
2905 | qreal left = r.left(); | - | ||||||||||||||||||
2906 | qreal right = r.right(); | - | ||||||||||||||||||
2907 | qreal top = r.top(); | - | ||||||||||||||||||
2908 | qreal bottom = r.bottom(); | - | ||||||||||||||||||
2909 | - | |||||||||||||||||||
2910 | array[0] = left; | - | ||||||||||||||||||
2911 | array[1] = top; | - | ||||||||||||||||||
2912 | array[2] = right; | - | ||||||||||||||||||
2913 | array[3] = top; | - | ||||||||||||||||||
2914 | array[4] = right; | - | ||||||||||||||||||
2915 | array[5] = bottom; | - | ||||||||||||||||||
2916 | array[6] = left; | - | ||||||||||||||||||
2917 | array[7] = bottom; | - | ||||||||||||||||||
2918 | } never executed: end of block | 0 | ||||||||||||||||||
2919 | - | |||||||||||||||||||
2920 | void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array) | - | ||||||||||||||||||
2921 | { | - | ||||||||||||||||||
2922 | array[0] = x1; | - | ||||||||||||||||||
2923 | array[1] = y1; | - | ||||||||||||||||||
2924 | array[2] = x2; | - | ||||||||||||||||||
2925 | array[3] = y1; | - | ||||||||||||||||||
2926 | array[4] = x2; | - | ||||||||||||||||||
2927 | array[5] = y2; | - | ||||||||||||||||||
2928 | array[6] = x1; | - | ||||||||||||||||||
2929 | array[7] = y2; | - | ||||||||||||||||||
2930 | } never executed: end of block | 0 | ||||||||||||||||||
2931 | - | |||||||||||||||||||
2932 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
2933 | - | |||||||||||||||||||
2934 | static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget) | - | ||||||||||||||||||
2935 | { | - | ||||||||||||||||||
2936 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
2937 | GLfloat tx = 1.0f; | - | ||||||||||||||||||
2938 | GLfloat ty = 1.0f; | - | ||||||||||||||||||
2939 | - | |||||||||||||||||||
2940 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
2941 | Q_UNUSED(textureWidth); | - | ||||||||||||||||||
2942 | Q_UNUSED(textureHeight); | - | ||||||||||||||||||
2943 | Q_UNUSED(textureTarget); | - | ||||||||||||||||||
2944 | #else | - | ||||||||||||||||||
2945 | if (textureTarget != GL_TEXTURE_2D && !QOpenGLContext::currentContext()->isOpenGLES()) {
| 0 | ||||||||||||||||||
2946 | if (textureWidth == -1 || textureHeight == -1) {
| 0 | ||||||||||||||||||
2947 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
2948 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); | - | ||||||||||||||||||
2949 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); | - | ||||||||||||||||||
2950 | } never executed: end of block | 0 | ||||||||||||||||||
2951 | - | |||||||||||||||||||
2952 | tx = GLfloat(textureWidth); | - | ||||||||||||||||||
2953 | ty = GLfloat(textureHeight); | - | ||||||||||||||||||
2954 | } never executed: end of block | 0 | ||||||||||||||||||
2955 | #endif | - | ||||||||||||||||||
2956 | - | |||||||||||||||||||
2957 | GLfloat texCoordArray[4*2] = { | - | ||||||||||||||||||
2958 | 0, ty, tx, ty, tx, 0, 0, 0 | - | ||||||||||||||||||
2959 | }; | - | ||||||||||||||||||
2960 | - | |||||||||||||||||||
2961 | GLfloat vertexArray[4*2]; | - | ||||||||||||||||||
2962 | qt_add_rect_to_array(target, vertexArray); | - | ||||||||||||||||||
2963 | - | |||||||||||||||||||
2964 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
2965 | gl1funcs->glVertexPointer(2, GL_FLOAT, 0, vertexArray); | - | ||||||||||||||||||
2966 | gl1funcs->glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); | - | ||||||||||||||||||
2967 | - | |||||||||||||||||||
2968 | gl1funcs->glEnableClientState(GL_VERTEX_ARRAY); | - | ||||||||||||||||||
2969 | gl1funcs->glEnableClientState(GL_TEXTURE_COORD_ARRAY); | - | ||||||||||||||||||
2970 | funcs->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | - | ||||||||||||||||||
2971 | - | |||||||||||||||||||
2972 | gl1funcs->glDisableClientState(GL_VERTEX_ARRAY); | - | ||||||||||||||||||
2973 | gl1funcs->glDisableClientState(GL_TEXTURE_COORD_ARRAY); | - | ||||||||||||||||||
2974 | } never executed: end of block | 0 | ||||||||||||||||||
2975 | - | |||||||||||||||||||
2976 | #endif // !QT_OPENGL_ES_2 | - | ||||||||||||||||||
2977 | - | |||||||||||||||||||
2978 | /*! | - | ||||||||||||||||||
2979 | \since 4.4 | - | ||||||||||||||||||
2980 | - | |||||||||||||||||||
2981 | This function supports the following use cases: | - | ||||||||||||||||||
2982 | - | |||||||||||||||||||
2983 | \list | - | ||||||||||||||||||
2984 | \li On OpenGL and OpenGL ES 1.x it draws the given texture, \a textureId, | - | ||||||||||||||||||
2985 | to the given target rectangle, \a target, in OpenGL model space. The | - | ||||||||||||||||||
2986 | \a textureTarget should be a 2D texture target. | - | ||||||||||||||||||
2987 | \li On OpenGL and OpenGL ES 2.x, if a painter is active, not inside a | - | ||||||||||||||||||
2988 | beginNativePainting / endNativePainting block, and uses the | - | ||||||||||||||||||
2989 | engine with type QPaintEngine::OpenGL2, the function will draw the given | - | ||||||||||||||||||
2990 | texture, \a textureId, to the given target rectangle, \a target, | - | ||||||||||||||||||
2991 | respecting the current painter state. This will let you draw a texture | - | ||||||||||||||||||
2992 | with the clip, transform, render hints, and composition mode set by the | - | ||||||||||||||||||
2993 | painter. Note that the texture target needs to be GL_TEXTURE_2D for this | - | ||||||||||||||||||
2994 | use case, and that this is the only supported use case under OpenGL ES 2.x. | - | ||||||||||||||||||
2995 | \endlist | - | ||||||||||||||||||
2996 | - | |||||||||||||||||||
2997 | */ | - | ||||||||||||||||||
2998 | void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
2999 | { | - | ||||||||||||||||||
3000 | #if !defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
3001 | if (d_ptr->active_engine &&
| 0 | ||||||||||||||||||
3002 | d_ptr->active_engine->type() == QPaintEngine::OpenGL2) {
| 0 | ||||||||||||||||||
3003 | QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); | - | ||||||||||||||||||
3004 | if (!eng->isNativePaintingActive()) {
| 0 | ||||||||||||||||||
3005 | QRectF src(0, 0, target.width(), target.height()); | - | ||||||||||||||||||
3006 | QSize size(target.width(), target.height()); | - | ||||||||||||||||||
3007 | if (eng->drawTexture(target, textureId, size, src))
| 0 | ||||||||||||||||||
3008 | return; never executed: return; | 0 | ||||||||||||||||||
3009 | } never executed: end of block | 0 | ||||||||||||||||||
3010 | } never executed: end of block | 0 | ||||||||||||||||||
3011 | #endif | - | ||||||||||||||||||
3012 | - | |||||||||||||||||||
3013 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
3014 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
3015 | if (!contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
3016 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
3017 | if (textureTarget != GL_TEXTURE_2D) { | - | ||||||||||||||||||
3018 | qWarning("QGLContext::drawTexture(): texture target must be GL_TEXTURE_2D on OpenGL ES"); | - | ||||||||||||||||||
3019 | return; | - | ||||||||||||||||||
3020 | } | - | ||||||||||||||||||
3021 | #else | - | ||||||||||||||||||
3022 | const bool wasEnabled = funcs->glIsEnabled(GL_TEXTURE_2D); | - | ||||||||||||||||||
3023 | GLint oldTexture; | - | ||||||||||||||||||
3024 | funcs->glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); | - | ||||||||||||||||||
3025 | #endif | - | ||||||||||||||||||
3026 | - | |||||||||||||||||||
3027 | funcs->glEnable(textureTarget); | - | ||||||||||||||||||
3028 | funcs->glBindTexture(textureTarget, textureId); | - | ||||||||||||||||||
3029 | - | |||||||||||||||||||
3030 | qDrawTextureRect(target, -1, -1, textureTarget); | - | ||||||||||||||||||
3031 | - | |||||||||||||||||||
3032 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
3033 | funcs->glDisable(textureTarget); | - | ||||||||||||||||||
3034 | #else | - | ||||||||||||||||||
3035 | if (!wasEnabled)
| 0 | ||||||||||||||||||
3036 | funcs->glDisable(textureTarget); never executed: funcs->glDisable(textureTarget); | 0 | ||||||||||||||||||
3037 | funcs->glBindTexture(textureTarget, oldTexture); | - | ||||||||||||||||||
3038 | #endif | - | ||||||||||||||||||
3039 | return; never executed: return; | 0 | ||||||||||||||||||
3040 | } | - | ||||||||||||||||||
3041 | #else | - | ||||||||||||||||||
3042 | Q_UNUSED(target); | - | ||||||||||||||||||
3043 | Q_UNUSED(textureId); | - | ||||||||||||||||||
3044 | Q_UNUSED(textureTarget); | - | ||||||||||||||||||
3045 | #endif | - | ||||||||||||||||||
3046 | qWarning("drawTexture() with OpenGL ES 2.0 requires an active OpenGL2 paint engine"); | - | ||||||||||||||||||
3047 | } never executed: end of block | 0 | ||||||||||||||||||
3048 | - | |||||||||||||||||||
3049 | /*! | - | ||||||||||||||||||
3050 | \since 4.4 | - | ||||||||||||||||||
3051 | - | |||||||||||||||||||
3052 | This function supports the following use cases: | - | ||||||||||||||||||
3053 | - | |||||||||||||||||||
3054 | \list | - | ||||||||||||||||||
3055 | \li By default it draws the given texture, \a textureId, | - | ||||||||||||||||||
3056 | at the given \a point in OpenGL model space. The | - | ||||||||||||||||||
3057 | \a textureTarget should be a 2D texture target. | - | ||||||||||||||||||
3058 | \li If a painter is active, not inside a | - | ||||||||||||||||||
3059 | beginNativePainting / endNativePainting block, and uses the | - | ||||||||||||||||||
3060 | engine with type QPaintEngine::OpenGL2, the function will draw the given | - | ||||||||||||||||||
3061 | texture, \a textureId, at the given \a point, | - | ||||||||||||||||||
3062 | respecting the current painter state. This will let you draw a texture | - | ||||||||||||||||||
3063 | with the clip, transform, render hints, and composition mode set by the | - | ||||||||||||||||||
3064 | painter. Note that the texture target needs to be GL_TEXTURE_2D for this | - | ||||||||||||||||||
3065 | use case. | - | ||||||||||||||||||
3066 | \endlist | - | ||||||||||||||||||
3067 | - | |||||||||||||||||||
3068 | \note This function is not supported under any version of OpenGL ES. | - | ||||||||||||||||||
3069 | */ | - | ||||||||||||||||||
3070 | void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
3071 | { | - | ||||||||||||||||||
3072 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
3073 | Q_UNUSED(point); | - | ||||||||||||||||||
3074 | Q_UNUSED(textureId); | - | ||||||||||||||||||
3075 | Q_UNUSED(textureTarget); | - | ||||||||||||||||||
3076 | #else | - | ||||||||||||||||||
3077 | if (!contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
3078 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
3079 | const bool wasEnabled = funcs->glIsEnabled(GL_TEXTURE_2D); | - | ||||||||||||||||||
3080 | GLint oldTexture; | - | ||||||||||||||||||
3081 | funcs->glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); | - | ||||||||||||||||||
3082 | - | |||||||||||||||||||
3083 | funcs->glEnable(textureTarget); | - | ||||||||||||||||||
3084 | funcs->glBindTexture(textureTarget, textureId); | - | ||||||||||||||||||
3085 | - | |||||||||||||||||||
3086 | GLint textureWidth; | - | ||||||||||||||||||
3087 | GLint textureHeight; | - | ||||||||||||||||||
3088 | - | |||||||||||||||||||
3089 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
3090 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); | - | ||||||||||||||||||
3091 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); | - | ||||||||||||||||||
3092 | - | |||||||||||||||||||
3093 | if (d_ptr->active_engine &&
| 0 | ||||||||||||||||||
3094 | d_ptr->active_engine->type() == QPaintEngine::OpenGL2) {
| 0 | ||||||||||||||||||
3095 | QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); | - | ||||||||||||||||||
3096 | if (!eng->isNativePaintingActive()) {
| 0 | ||||||||||||||||||
3097 | QRectF dest(point, QSizeF(textureWidth, textureHeight)); | - | ||||||||||||||||||
3098 | QRectF src(0, 0, textureWidth, textureHeight); | - | ||||||||||||||||||
3099 | QSize size(textureWidth, textureHeight); | - | ||||||||||||||||||
3100 | if (eng->drawTexture(dest, textureId, size, src))
| 0 | ||||||||||||||||||
3101 | return; never executed: return; | 0 | ||||||||||||||||||
3102 | } never executed: end of block | 0 | ||||||||||||||||||
3103 | } never executed: end of block | 0 | ||||||||||||||||||
3104 | - | |||||||||||||||||||
3105 | qDrawTextureRect(QRectF(point, QSizeF(textureWidth, textureHeight)), textureWidth, textureHeight, textureTarget); | - | ||||||||||||||||||
3106 | - | |||||||||||||||||||
3107 | if (!wasEnabled)
| 0 | ||||||||||||||||||
3108 | funcs->glDisable(textureTarget); never executed: funcs->glDisable(textureTarget); | 0 | ||||||||||||||||||
3109 | funcs->glBindTexture(textureTarget, oldTexture); | - | ||||||||||||||||||
3110 | return; never executed: return; | 0 | ||||||||||||||||||
3111 | } | - | ||||||||||||||||||
3112 | #endif | - | ||||||||||||||||||
3113 | qWarning("drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) not supported with OpenGL ES, use rect version instead"); | - | ||||||||||||||||||
3114 | } never executed: end of block | 0 | ||||||||||||||||||
3115 | - | |||||||||||||||||||
3116 | /*! | - | ||||||||||||||||||
3117 | This function sets the limit for the texture cache to \a size, | - | ||||||||||||||||||
3118 | expressed in kilobytes. | - | ||||||||||||||||||
3119 | - | |||||||||||||||||||
3120 | By default, the cache limit is approximately 64 MB. | - | ||||||||||||||||||
3121 | - | |||||||||||||||||||
3122 | \sa textureCacheLimit() | - | ||||||||||||||||||
3123 | */ | - | ||||||||||||||||||
3124 | void QGLContext::setTextureCacheLimit(int size) | - | ||||||||||||||||||
3125 | { | - | ||||||||||||||||||
3126 | QGLTextureCache::instance()->setMaxCost(size); | - | ||||||||||||||||||
3127 | } never executed: end of block | 0 | ||||||||||||||||||
3128 | - | |||||||||||||||||||
3129 | /*! | - | ||||||||||||||||||
3130 | Returns the current texture cache limit in kilobytes. | - | ||||||||||||||||||
3131 | - | |||||||||||||||||||
3132 | \sa setTextureCacheLimit() | - | ||||||||||||||||||
3133 | */ | - | ||||||||||||||||||
3134 | int QGLContext::textureCacheLimit() | - | ||||||||||||||||||
3135 | { | - | ||||||||||||||||||
3136 | return QGLTextureCache::instance()->maxCost(); never executed: return QGLTextureCache::instance()->maxCost(); | 0 | ||||||||||||||||||
3137 | } | - | ||||||||||||||||||
3138 | - | |||||||||||||||||||
3139 | - | |||||||||||||||||||
3140 | /*! | - | ||||||||||||||||||
3141 | \fn QGLFormat QGLContext::format() const | - | ||||||||||||||||||
3142 | - | |||||||||||||||||||
3143 | Returns the frame buffer format that was obtained (this may be a | - | ||||||||||||||||||
3144 | subset of what was requested). | - | ||||||||||||||||||
3145 | - | |||||||||||||||||||
3146 | \sa requestedFormat() | - | ||||||||||||||||||
3147 | */ | - | ||||||||||||||||||
3148 | - | |||||||||||||||||||
3149 | /*! | - | ||||||||||||||||||
3150 | \fn QGLFormat QGLContext::requestedFormat() const | - | ||||||||||||||||||
3151 | - | |||||||||||||||||||
3152 | Returns the frame buffer format that was originally requested in | - | ||||||||||||||||||
3153 | the constructor or setFormat(). | - | ||||||||||||||||||
3154 | - | |||||||||||||||||||
3155 | \sa format() | - | ||||||||||||||||||
3156 | */ | - | ||||||||||||||||||
3157 | - | |||||||||||||||||||
3158 | /*! | - | ||||||||||||||||||
3159 | Sets a \a format for this context. The context is \l{reset()}{reset}. | - | ||||||||||||||||||
3160 | - | |||||||||||||||||||
3161 | Call create() to create a new GL context that tries to match the | - | ||||||||||||||||||
3162 | new format. | - | ||||||||||||||||||
3163 | - | |||||||||||||||||||
3164 | \snippet code/src_opengl_qgl.cpp 7 | - | ||||||||||||||||||
3165 | - | |||||||||||||||||||
3166 | \sa format(), reset(), create() | - | ||||||||||||||||||
3167 | */ | - | ||||||||||||||||||
3168 | - | |||||||||||||||||||
3169 | void QGLContext::setFormat(const QGLFormat &format) | - | ||||||||||||||||||
3170 | { | - | ||||||||||||||||||
3171 | Q_D(QGLContext); | - | ||||||||||||||||||
3172 | reset(); | - | ||||||||||||||||||
3173 | d->glFormat = d->reqFormat = format; | - | ||||||||||||||||||
3174 | } never executed: end of block | 0 | ||||||||||||||||||
3175 | - | |||||||||||||||||||
3176 | /*! | - | ||||||||||||||||||
3177 | \internal | - | ||||||||||||||||||
3178 | */ | - | ||||||||||||||||||
3179 | void QGLContext::setDevice(QPaintDevice *pDev) | - | ||||||||||||||||||
3180 | { | - | ||||||||||||||||||
3181 | Q_D(QGLContext); | - | ||||||||||||||||||
3182 | // Do not touch the valid flag here. The context is either a new one and | - | ||||||||||||||||||
3183 | // valid is not yet set or it is adapted from a valid QOpenGLContext in which | - | ||||||||||||||||||
3184 | // case it must remain valid. | - | ||||||||||||||||||
3185 | d->paintDevice = pDev; | - | ||||||||||||||||||
3186 | if (d->paintDevice && (d->paintDevice->devType() != QInternal::Widget
| 0-12 | ||||||||||||||||||
3187 | && d->paintDevice->devType() != QInternal::Pixmap
| 0 | ||||||||||||||||||
3188 | && d->paintDevice->devType() != QInternal::Pbuffer)) {
| 0 | ||||||||||||||||||
3189 | qWarning("QGLContext: Unsupported paint device type"); | - | ||||||||||||||||||
3190 | } never executed: end of block | 0 | ||||||||||||||||||
3191 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3192 | - | |||||||||||||||||||
3193 | /*! | - | ||||||||||||||||||
3194 | \fn bool QGLContext::isValid() const | - | ||||||||||||||||||
3195 | - | |||||||||||||||||||
3196 | Returns \c true if a GL rendering context has been successfully | - | ||||||||||||||||||
3197 | created; otherwise returns \c false. | - | ||||||||||||||||||
3198 | */ | - | ||||||||||||||||||
3199 | - | |||||||||||||||||||
3200 | /*! | - | ||||||||||||||||||
3201 | \fn void QGLContext::setValid(bool valid) | - | ||||||||||||||||||
3202 | \internal | - | ||||||||||||||||||
3203 | - | |||||||||||||||||||
3204 | Forces the GL rendering context to be valid. | - | ||||||||||||||||||
3205 | */ | - | ||||||||||||||||||
3206 | - | |||||||||||||||||||
3207 | /*! | - | ||||||||||||||||||
3208 | \fn bool QGLContext::isSharing() const | - | ||||||||||||||||||
3209 | - | |||||||||||||||||||
3210 | Returns \c true if this context is sharing its GL context with | - | ||||||||||||||||||
3211 | another QGLContext, otherwise false is returned. Note that context | - | ||||||||||||||||||
3212 | sharing might not be supported between contexts with different | - | ||||||||||||||||||
3213 | formats. | - | ||||||||||||||||||
3214 | */ | - | ||||||||||||||||||
3215 | - | |||||||||||||||||||
3216 | /*! | - | ||||||||||||||||||
3217 | Returns \c true if \a context1 and \a context2 are sharing their | - | ||||||||||||||||||
3218 | GL resources such as textures, shader programs, etc; | - | ||||||||||||||||||
3219 | otherwise returns \c false. | - | ||||||||||||||||||
3220 | - | |||||||||||||||||||
3221 | \since 4.6 | - | ||||||||||||||||||
3222 | */ | - | ||||||||||||||||||
3223 | bool QGLContext::areSharing(const QGLContext *context1, const QGLContext *context2) | - | ||||||||||||||||||
3224 | { | - | ||||||||||||||||||
3225 | if (!context1 || !context2)
| 0-4 | ||||||||||||||||||
3226 | return false; never executed: return false; | 0 | ||||||||||||||||||
3227 | return context1->d_ptr->group == context2->d_ptr->group; executed 4 times by 1 test: return context1->d_ptr->group == context2->d_ptr->group; Executed by:
| 4 | ||||||||||||||||||
3228 | } | - | ||||||||||||||||||
3229 | - | |||||||||||||||||||
3230 | /*! | - | ||||||||||||||||||
3231 | \fn bool QGLContext::deviceIsPixmap() const | - | ||||||||||||||||||
3232 | - | |||||||||||||||||||
3233 | Returns \c true if the paint device of this context is a pixmap; | - | ||||||||||||||||||
3234 | otherwise returns \c false. | - | ||||||||||||||||||
3235 | - | |||||||||||||||||||
3236 | Since Qt 5 the paint device is never actually a pixmap. renderPixmap() is | - | ||||||||||||||||||
3237 | however still simulated using framebuffer objects and readbacks, and this | - | ||||||||||||||||||
3238 | function will return \c true in this case. | - | ||||||||||||||||||
3239 | */ | - | ||||||||||||||||||
3240 | - | |||||||||||||||||||
3241 | /*! | - | ||||||||||||||||||
3242 | \fn bool QGLContext::windowCreated() const | - | ||||||||||||||||||
3243 | - | |||||||||||||||||||
3244 | Returns \c true if a window has been created for this context; | - | ||||||||||||||||||
3245 | otherwise returns \c false. | - | ||||||||||||||||||
3246 | - | |||||||||||||||||||
3247 | \sa setWindowCreated() | - | ||||||||||||||||||
3248 | */ | - | ||||||||||||||||||
3249 | - | |||||||||||||||||||
3250 | /*! | - | ||||||||||||||||||
3251 | \fn void QGLContext::setWindowCreated(bool on) | - | ||||||||||||||||||
3252 | - | |||||||||||||||||||
3253 | If \a on is true the context has had a window created for it. If | - | ||||||||||||||||||
3254 | \a on is false no window has been created for the context. | - | ||||||||||||||||||
3255 | - | |||||||||||||||||||
3256 | \sa windowCreated() | - | ||||||||||||||||||
3257 | */ | - | ||||||||||||||||||
3258 | - | |||||||||||||||||||
3259 | /*! | - | ||||||||||||||||||
3260 | \fn uint QGLContext::colorIndex(const QColor& c) const | - | ||||||||||||||||||
3261 | - | |||||||||||||||||||
3262 | \internal | - | ||||||||||||||||||
3263 | - | |||||||||||||||||||
3264 | Returns a colormap index for the color c, in ColorIndex mode. Used | - | ||||||||||||||||||
3265 | by qglColor() and qglClearColor(). | - | ||||||||||||||||||
3266 | */ | - | ||||||||||||||||||
3267 | uint QGLContext::colorIndex(const QColor&) const | - | ||||||||||||||||||
3268 | { | - | ||||||||||||||||||
3269 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
3270 | } | - | ||||||||||||||||||
3271 | - | |||||||||||||||||||
3272 | /*! | - | ||||||||||||||||||
3273 | \fn bool QGLContext::initialized() const | - | ||||||||||||||||||
3274 | - | |||||||||||||||||||
3275 | Returns \c true if this context has been initialized, i.e. if | - | ||||||||||||||||||
3276 | QGLWidget::initializeGL() has been performed on it; otherwise | - | ||||||||||||||||||
3277 | returns \c false. | - | ||||||||||||||||||
3278 | - | |||||||||||||||||||
3279 | \sa setInitialized() | - | ||||||||||||||||||
3280 | */ | - | ||||||||||||||||||
3281 | - | |||||||||||||||||||
3282 | /*! | - | ||||||||||||||||||
3283 | \fn void QGLContext::setInitialized(bool on) | - | ||||||||||||||||||
3284 | - | |||||||||||||||||||
3285 | If \a on is true the context has been initialized, i.e. | - | ||||||||||||||||||
3286 | QGLContext::setInitialized() has been called on it. If \a on is | - | ||||||||||||||||||
3287 | false the context has not been initialized. | - | ||||||||||||||||||
3288 | - | |||||||||||||||||||
3289 | \sa initialized() | - | ||||||||||||||||||
3290 | */ | - | ||||||||||||||||||
3291 | - | |||||||||||||||||||
3292 | /*! | - | ||||||||||||||||||
3293 | \fn const QGLContext* QGLContext::currentContext() | - | ||||||||||||||||||
3294 | - | |||||||||||||||||||
3295 | Returns the current context, i.e. the context to which any OpenGL | - | ||||||||||||||||||
3296 | commands will currently be directed. Returns 0 if no context is | - | ||||||||||||||||||
3297 | current. | - | ||||||||||||||||||
3298 | - | |||||||||||||||||||
3299 | \sa makeCurrent() | - | ||||||||||||||||||
3300 | */ | - | ||||||||||||||||||
3301 | - | |||||||||||||||||||
3302 | /*! | - | ||||||||||||||||||
3303 | \fn QColor QGLContext::overlayTransparentColor() const | - | ||||||||||||||||||
3304 | - | |||||||||||||||||||
3305 | If this context is a valid context in an overlay plane, returns | - | ||||||||||||||||||
3306 | the plane's transparent color. Otherwise returns an \l{QColor::isValid()}{invalid} color. | - | ||||||||||||||||||
3307 | - | |||||||||||||||||||
3308 | The returned color's \l{QColormap::pixel()}{pixel} value is | - | ||||||||||||||||||
3309 | the index of the transparent color in the colormap of the overlay | - | ||||||||||||||||||
3310 | plane. (Naturally, the color's RGB values are meaningless.) | - | ||||||||||||||||||
3311 | - | |||||||||||||||||||
3312 | The returned QColor object will generally work as expected only | - | ||||||||||||||||||
3313 | when passed as the argument to QGLWidget::qglColor() or | - | ||||||||||||||||||
3314 | QGLWidget::qglClearColor(). Under certain circumstances it can | - | ||||||||||||||||||
3315 | also be used to draw transparent graphics with a QPainter. | - | ||||||||||||||||||
3316 | */ | - | ||||||||||||||||||
3317 | QColor QGLContext::overlayTransparentColor() const | - | ||||||||||||||||||
3318 | { | - | ||||||||||||||||||
3319 | return QColor(); // Invalid color never executed: return QColor(); | 0 | ||||||||||||||||||
3320 | } | - | ||||||||||||||||||
3321 | - | |||||||||||||||||||
3322 | /*! | - | ||||||||||||||||||
3323 | Creates the GL context. Returns \c true if it was successful in | - | ||||||||||||||||||
3324 | creating a valid GL rendering context on the paint device | - | ||||||||||||||||||
3325 | specified in the constructor; otherwise returns \c false (i.e. the | - | ||||||||||||||||||
3326 | context is invalid). | - | ||||||||||||||||||
3327 | - | |||||||||||||||||||
3328 | If the OpenGL implementation on your system does not support the requested | - | ||||||||||||||||||
3329 | version of OpenGL context, then QGLContext will try to create the closest | - | ||||||||||||||||||
3330 | matching version. The actual created context properties can be queried | - | ||||||||||||||||||
3331 | using the QGLFormat returned by the format() function. For example, if | - | ||||||||||||||||||
3332 | you request a context that supports OpenGL 4.3 Core profile but the driver | - | ||||||||||||||||||
3333 | and/or hardware only supports version 3.2 Core profile contexts then you will | - | ||||||||||||||||||
3334 | get a 3.2 Core profile context. | - | ||||||||||||||||||
3335 | - | |||||||||||||||||||
3336 | After successful creation, format() returns the set of features of | - | ||||||||||||||||||
3337 | the created GL rendering context. | - | ||||||||||||||||||
3338 | - | |||||||||||||||||||
3339 | If \a shareContext points to a valid QGLContext, this method will | - | ||||||||||||||||||
3340 | try to establish OpenGL display list and texture object sharing | - | ||||||||||||||||||
3341 | between this context and the \a shareContext. Note that this may | - | ||||||||||||||||||
3342 | fail if the two contexts have different \l {format()} {formats}. | - | ||||||||||||||||||
3343 | Use isSharing() to see if sharing is in effect. | - | ||||||||||||||||||
3344 | - | |||||||||||||||||||
3345 | \warning Implementation note: initialization of C++ class | - | ||||||||||||||||||
3346 | members usually takes place in the class constructor. QGLContext | - | ||||||||||||||||||
3347 | is an exception because it must be simple to customize. The | - | ||||||||||||||||||
3348 | virtual functions chooseContext() (and chooseVisual() for X11) can | - | ||||||||||||||||||
3349 | be reimplemented in a subclass to select a particular context. The | - | ||||||||||||||||||
3350 | problem is that virtual functions are not properly called during | - | ||||||||||||||||||
3351 | construction (even though this is correct C++) because C++ | - | ||||||||||||||||||
3352 | constructs class hierarchies from the bottom up. For this reason | - | ||||||||||||||||||
3353 | we need a create() function. | - | ||||||||||||||||||
3354 | - | |||||||||||||||||||
3355 | \sa chooseContext(), format(), isValid() | - | ||||||||||||||||||
3356 | */ | - | ||||||||||||||||||
3357 | - | |||||||||||||||||||
3358 | bool QGLContext::create(const QGLContext* shareContext) | - | ||||||||||||||||||
3359 | { | - | ||||||||||||||||||
3360 | Q_D(QGLContext); | - | ||||||||||||||||||
3361 | if (!d->paintDevice && !d->guiGlContext)
| 0-12 | ||||||||||||||||||
3362 | return false; never executed: return false; | 0 | ||||||||||||||||||
3363 | - | |||||||||||||||||||
3364 | reset(); | - | ||||||||||||||||||
3365 | d->valid = chooseContext(shareContext); | - | ||||||||||||||||||
3366 | if (d->valid && d->paintDevice && d->paintDevice->devType() == QInternal::Widget) {
| 0-12 | ||||||||||||||||||
3367 | QWidgetPrivate *wd = qt_widget_private(static_cast<QWidget *>(d->paintDevice)); | - | ||||||||||||||||||
3368 | wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer(); | - | ||||||||||||||||||
3369 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3370 | return d->valid; executed 12 times by 3 tests: return d->valid; Executed by:
| 12 | ||||||||||||||||||
3371 | } | - | ||||||||||||||||||
3372 | - | |||||||||||||||||||
3373 | bool QGLContext::isValid() const | - | ||||||||||||||||||
3374 | { | - | ||||||||||||||||||
3375 | Q_D(const QGLContext); | - | ||||||||||||||||||
3376 | return d->valid; executed 16 times by 3 tests: return d->valid; Executed by:
| 16 | ||||||||||||||||||
3377 | } | - | ||||||||||||||||||
3378 | - | |||||||||||||||||||
3379 | void QGLContext::setValid(bool valid) | - | ||||||||||||||||||
3380 | { | - | ||||||||||||||||||
3381 | Q_D(QGLContext); | - | ||||||||||||||||||
3382 | d->valid = valid; | - | ||||||||||||||||||
3383 | } never executed: end of block | 0 | ||||||||||||||||||
3384 | - | |||||||||||||||||||
3385 | bool QGLContext::isSharing() const | - | ||||||||||||||||||
3386 | { | - | ||||||||||||||||||
3387 | Q_D(const QGLContext); | - | ||||||||||||||||||
3388 | return d->group->isSharing(); executed 1 time by 1 test: return d->group->isSharing(); Executed by:
| 1 | ||||||||||||||||||
3389 | } | - | ||||||||||||||||||
3390 | - | |||||||||||||||||||
3391 | QGLFormat QGLContext::format() const | - | ||||||||||||||||||
3392 | { | - | ||||||||||||||||||
3393 | Q_D(const QGLContext); | - | ||||||||||||||||||
3394 | return d->glFormat; executed 12 times by 3 tests: return d->glFormat; Executed by:
| 12 | ||||||||||||||||||
3395 | } | - | ||||||||||||||||||
3396 | - | |||||||||||||||||||
3397 | QGLFormat QGLContext::requestedFormat() const | - | ||||||||||||||||||
3398 | { | - | ||||||||||||||||||
3399 | Q_D(const QGLContext); | - | ||||||||||||||||||
3400 | return d->reqFormat; never executed: return d->reqFormat; | 0 | ||||||||||||||||||
3401 | } | - | ||||||||||||||||||
3402 | - | |||||||||||||||||||
3403 | QPaintDevice* QGLContext::device() const | - | ||||||||||||||||||
3404 | { | - | ||||||||||||||||||
3405 | Q_D(const QGLContext); | - | ||||||||||||||||||
3406 | return d->paintDevice; executed 24 times by 3 tests: return d->paintDevice; Executed by:
| 24 | ||||||||||||||||||
3407 | } | - | ||||||||||||||||||
3408 | - | |||||||||||||||||||
3409 | bool QGLContext::deviceIsPixmap() const | - | ||||||||||||||||||
3410 | { | - | ||||||||||||||||||
3411 | Q_D(const QGLContext); | - | ||||||||||||||||||
3412 | return !d->readback_target_size.isEmpty(); never executed: return !d->readback_target_size.isEmpty(); | 0 | ||||||||||||||||||
3413 | } | - | ||||||||||||||||||
3414 | - | |||||||||||||||||||
3415 | - | |||||||||||||||||||
3416 | bool QGLContext::windowCreated() const | - | ||||||||||||||||||
3417 | { | - | ||||||||||||||||||
3418 | Q_D(const QGLContext); | - | ||||||||||||||||||
3419 | return d->crWin; never executed: return d->crWin; | 0 | ||||||||||||||||||
3420 | } | - | ||||||||||||||||||
3421 | - | |||||||||||||||||||
3422 | - | |||||||||||||||||||
3423 | void QGLContext::setWindowCreated(bool on) | - | ||||||||||||||||||
3424 | { | - | ||||||||||||||||||
3425 | Q_D(QGLContext); | - | ||||||||||||||||||
3426 | d->crWin = on; | - | ||||||||||||||||||
3427 | } never executed: end of block | 0 | ||||||||||||||||||
3428 | - | |||||||||||||||||||
3429 | bool QGLContext::initialized() const | - | ||||||||||||||||||
3430 | { | - | ||||||||||||||||||
3431 | Q_D(const QGLContext); | - | ||||||||||||||||||
3432 | return d->initDone; never executed: return d->initDone; | 0 | ||||||||||||||||||
3433 | } | - | ||||||||||||||||||
3434 | - | |||||||||||||||||||
3435 | void QGLContext::setInitialized(bool on) | - | ||||||||||||||||||
3436 | { | - | ||||||||||||||||||
3437 | Q_D(QGLContext); | - | ||||||||||||||||||
3438 | d->initDone = on; | - | ||||||||||||||||||
3439 | } never executed: end of block | 0 | ||||||||||||||||||
3440 | - | |||||||||||||||||||
3441 | const QGLContext* QGLContext::currentContext() | - | ||||||||||||||||||
3442 | { | - | ||||||||||||||||||
3443 | if (const QOpenGLContext *threadContext = QOpenGLContext::currentContext()) {
| 0-56 | ||||||||||||||||||
3444 | return QGLContext::fromOpenGLContext(const_cast<QOpenGLContext *>(threadContext)); executed 56 times by 3 tests: return QGLContext::fromOpenGLContext(const_cast<QOpenGLContext *>(threadContext)); Executed by:
| 56 | ||||||||||||||||||
3445 | } | - | ||||||||||||||||||
3446 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
3447 | } | - | ||||||||||||||||||
3448 | - | |||||||||||||||||||
3449 | void QGLContextPrivate::setCurrentContext(QGLContext *context) | - | ||||||||||||||||||
3450 | { | - | ||||||||||||||||||
3451 | Q_UNUSED(context); | - | ||||||||||||||||||
3452 | } never executed: end of block | 0 | ||||||||||||||||||
3453 | - | |||||||||||||||||||
3454 | /*! | - | ||||||||||||||||||
3455 | Moves the QGLContext to the given \a thread. | - | ||||||||||||||||||
3456 | - | |||||||||||||||||||
3457 | Enables calling swapBuffers() and makeCurrent() on the context in | - | ||||||||||||||||||
3458 | the given thread. | - | ||||||||||||||||||
3459 | */ | - | ||||||||||||||||||
3460 | void QGLContext::moveToThread(QThread *thread) | - | ||||||||||||||||||
3461 | { | - | ||||||||||||||||||
3462 | Q_D(QGLContext); | - | ||||||||||||||||||
3463 | if (d->guiGlContext)
| 0 | ||||||||||||||||||
3464 | d->guiGlContext->moveToThread(thread); never executed: d->guiGlContext->moveToThread(thread); | 0 | ||||||||||||||||||
3465 | } never executed: end of block | 0 | ||||||||||||||||||
3466 | - | |||||||||||||||||||
3467 | /*! | - | ||||||||||||||||||
3468 | \fn bool QGLContext::chooseContext(const QGLContext* shareContext = 0) | - | ||||||||||||||||||
3469 | - | |||||||||||||||||||
3470 | This semi-internal function is called by create(). It creates a | - | ||||||||||||||||||
3471 | system-dependent OpenGL handle that matches the format() of \a | - | ||||||||||||||||||
3472 | shareContext as closely as possible, returning true if successful | - | ||||||||||||||||||
3473 | or false if a suitable handle could not be found. | - | ||||||||||||||||||
3474 | - | |||||||||||||||||||
3475 | On Windows, it calls the virtual function choosePixelFormat(), | - | ||||||||||||||||||
3476 | which finds a matching pixel format identifier. On X11, it calls | - | ||||||||||||||||||
3477 | the virtual function chooseVisual() which finds an appropriate X | - | ||||||||||||||||||
3478 | visual. On other platforms it may work differently. | - | ||||||||||||||||||
3479 | */ | - | ||||||||||||||||||
3480 | bool QGLContext::chooseContext(const QGLContext* shareContext) | - | ||||||||||||||||||
3481 | { | - | ||||||||||||||||||
3482 | Q_D(QGLContext); | - | ||||||||||||||||||
3483 | if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) {
| 0-12 | ||||||||||||||||||
3484 | // Unlike in Qt 4, the only possible target is a widget backed by an OpenGL-based | - | ||||||||||||||||||
3485 | // QWindow. Pixmaps in particular are not supported anymore as paint devices since | - | ||||||||||||||||||
3486 | // starting from Qt 5 QPixmap is raster-backed on almost all platforms. | - | ||||||||||||||||||
3487 | d->valid = false; | - | ||||||||||||||||||
3488 | }else { never executed: end of block | 0 | ||||||||||||||||||
3489 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); | - | ||||||||||||||||||
3490 | QGLFormat glformat = format(); | - | ||||||||||||||||||
3491 | QSurfaceFormat winFormat = QGLFormat::toSurfaceFormat(glformat); | - | ||||||||||||||||||
3492 | if (widget->testAttribute(Qt::WA_TranslucentBackground))
| 0-12 | ||||||||||||||||||
3493 | winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8)); never executed: winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8)); | 0 | ||||||||||||||||||
3494 | - | |||||||||||||||||||
3495 | QWindow *window = widget->windowHandle(); | - | ||||||||||||||||||
3496 | if (!window->handle()
| 0-12 | ||||||||||||||||||
3497 | || window->surfaceType() != QWindow::OpenGLSurface
| 0 | ||||||||||||||||||
3498 | || window->requestedFormat() != winFormat)
| 0 | ||||||||||||||||||
3499 | { | - | ||||||||||||||||||
3500 | window->setSurfaceType(QWindow::OpenGLSurface); | - | ||||||||||||||||||
3501 | window->setFormat(winFormat); | - | ||||||||||||||||||
3502 | window->destroy(); | - | ||||||||||||||||||
3503 | window->create(); | - | ||||||||||||||||||
3504 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3505 | - | |||||||||||||||||||
3506 | if (d->ownContext)
| 0-12 | ||||||||||||||||||
3507 | delete d->guiGlContext; never executed: delete d->guiGlContext; | 0 | ||||||||||||||||||
3508 | d->ownContext = true; | - | ||||||||||||||||||
3509 | QOpenGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0;
| 1-11 | ||||||||||||||||||
3510 | d->guiGlContext = new QOpenGLContext; | - | ||||||||||||||||||
3511 | d->guiGlContext->setFormat(winFormat); | - | ||||||||||||||||||
3512 | d->guiGlContext->setShareContext(shareGlContext); | - | ||||||||||||||||||
3513 | d->valid = d->guiGlContext->create(); | - | ||||||||||||||||||
3514 | - | |||||||||||||||||||
3515 | if (d->valid)
| 0-12 | ||||||||||||||||||
3516 | d->guiGlContext->setQGLContextHandle(this, 0); executed 12 times by 3 tests: d->guiGlContext->setQGLContextHandle(this, 0); Executed by:
| 12 | ||||||||||||||||||
3517 | - | |||||||||||||||||||
3518 | d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format()); | - | ||||||||||||||||||
3519 | d->setupSharing(); | - | ||||||||||||||||||
3520 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3521 | - | |||||||||||||||||||
3522 | - | |||||||||||||||||||
3523 | return d->valid; executed 12 times by 3 tests: return d->valid; Executed by:
| 12 | ||||||||||||||||||
3524 | } | - | ||||||||||||||||||
3525 | - | |||||||||||||||||||
3526 | /*! | - | ||||||||||||||||||
3527 | \fn void QGLContext::reset() | - | ||||||||||||||||||
3528 | - | |||||||||||||||||||
3529 | Resets the context and makes it invalid. | - | ||||||||||||||||||
3530 | - | |||||||||||||||||||
3531 | \sa create(), isValid() | - | ||||||||||||||||||
3532 | */ | - | ||||||||||||||||||
3533 | void QGLContext::reset() | - | ||||||||||||||||||
3534 | { | - | ||||||||||||||||||
3535 | Q_D(QGLContext); | - | ||||||||||||||||||
3536 | if (!d->valid)
| 12 | ||||||||||||||||||
3537 | return; executed 12 times by 3 tests: return; Executed by:
| 12 | ||||||||||||||||||
3538 | d->cleanup(); | - | ||||||||||||||||||
3539 | - | |||||||||||||||||||
3540 | d->crWin = false; | - | ||||||||||||||||||
3541 | d->sharing = false; | - | ||||||||||||||||||
3542 | d->valid = false; | - | ||||||||||||||||||
3543 | d->transpColor = QColor(); | - | ||||||||||||||||||
3544 | d->initDone = false; | - | ||||||||||||||||||
3545 | QGLContextGroup::removeShare(this); | - | ||||||||||||||||||
3546 | if (d->guiGlContext) {
| 0-12 | ||||||||||||||||||
3547 | if (QOpenGLContext::currentContext() == d->guiGlContext)
| 1-11 | ||||||||||||||||||
3548 | doneCurrent(); executed 11 times by 3 tests: doneCurrent(); Executed by:
| 11 | ||||||||||||||||||
3549 | if (d->ownContext) {
| 0-12 | ||||||||||||||||||
3550 | if (d->guiGlContext->thread() == QThread::currentThread())
| 0-12 | ||||||||||||||||||
3551 | delete d->guiGlContext; executed 12 times by 3 tests: delete d->guiGlContext; Executed by:
| 12 | ||||||||||||||||||
3552 | else | - | ||||||||||||||||||
3553 | d->guiGlContext->deleteLater(); never executed: d->guiGlContext->deleteLater(); | 0 | ||||||||||||||||||
3554 | } else | - | ||||||||||||||||||
3555 | d->guiGlContext->setQGLContextHandle(0,0); never executed: d->guiGlContext->setQGLContextHandle(0,0); | 0 | ||||||||||||||||||
3556 | d->guiGlContext = 0; | - | ||||||||||||||||||
3557 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3558 | d->ownContext = false; | - | ||||||||||||||||||
3559 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3560 | - | |||||||||||||||||||
3561 | /*! | - | ||||||||||||||||||
3562 | \fn void QGLContext::makeCurrent() | - | ||||||||||||||||||
3563 | - | |||||||||||||||||||
3564 | Makes this context the current OpenGL rendering context. All GL | - | ||||||||||||||||||
3565 | functions you call operate on this context until another context | - | ||||||||||||||||||
3566 | is made current. | - | ||||||||||||||||||
3567 | - | |||||||||||||||||||
3568 | In some very rare cases the underlying call may fail. If this | - | ||||||||||||||||||
3569 | occurs an error message is output to stderr. | - | ||||||||||||||||||
3570 | - | |||||||||||||||||||
3571 | If you call this from a thread other than the main UI thread, | - | ||||||||||||||||||
3572 | make sure you've first pushed the context to the relevant thread | - | ||||||||||||||||||
3573 | from the UI thread using moveToThread(). | - | ||||||||||||||||||
3574 | */ | - | ||||||||||||||||||
3575 | void QGLContext::makeCurrent() | - | ||||||||||||||||||
3576 | { | - | ||||||||||||||||||
3577 | Q_D(QGLContext); | - | ||||||||||||||||||
3578 | if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget)
| 0-14 | ||||||||||||||||||
3579 | return; never executed: return; | 0 | ||||||||||||||||||
3580 | - | |||||||||||||||||||
3581 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); | - | ||||||||||||||||||
3582 | if (!widget->windowHandle())
| 0-14 | ||||||||||||||||||
3583 | return; never executed: return; | 0 | ||||||||||||||||||
3584 | - | |||||||||||||||||||
3585 | if (d->guiGlContext->makeCurrent(widget->windowHandle())) {
| 0-14 | ||||||||||||||||||
3586 | if (!d->workaroundsCached) {
| 2-12 | ||||||||||||||||||
3587 | d->workaroundsCached = true; | - | ||||||||||||||||||
3588 | const char *renderer = reinterpret_cast<const char *>(d->guiGlContext->functions()->glGetString(GL_RENDERER)); | - | ||||||||||||||||||
3589 | if (renderer && strstr(renderer, "Mali")) {
| 0-12 | ||||||||||||||||||
3590 | d->workaround_brokenFBOReadBack = true; | - | ||||||||||||||||||
3591 | } never executed: end of block | 0 | ||||||||||||||||||
3592 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3593 | } executed 14 times by 3 tests: end of block Executed by:
| 14 | ||||||||||||||||||
3594 | } executed 14 times by 3 tests: end of block Executed by:
| 14 | ||||||||||||||||||
3595 | - | |||||||||||||||||||
3596 | /*! | - | ||||||||||||||||||
3597 | \fn void QGLContext::swapBuffers() const | - | ||||||||||||||||||
3598 | - | |||||||||||||||||||
3599 | Call this to finish a frame of OpenGL rendering, and make sure to | - | ||||||||||||||||||
3600 | call makeCurrent() again before you begin a new frame. | - | ||||||||||||||||||
3601 | */ | - | ||||||||||||||||||
3602 | void QGLContext::swapBuffers() const | - | ||||||||||||||||||
3603 | { | - | ||||||||||||||||||
3604 | Q_D(const QGLContext); | - | ||||||||||||||||||
3605 | if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget)
| 0-2 | ||||||||||||||||||
3606 | return; never executed: return; | 0 | ||||||||||||||||||
3607 | - | |||||||||||||||||||
3608 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); | - | ||||||||||||||||||
3609 | if (!widget->windowHandle())
| 0-2 | ||||||||||||||||||
3610 | return; never executed: return; | 0 | ||||||||||||||||||
3611 | - | |||||||||||||||||||
3612 | d->guiGlContext->swapBuffers(widget->windowHandle()); | - | ||||||||||||||||||
3613 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
3614 | - | |||||||||||||||||||
3615 | /*! | - | ||||||||||||||||||
3616 | \fn void QGLContext::doneCurrent() | - | ||||||||||||||||||
3617 | - | |||||||||||||||||||
3618 | Makes no GL context the current context. Normally, you do not need | - | ||||||||||||||||||
3619 | to call this function; QGLContext calls it as necessary. | - | ||||||||||||||||||
3620 | */ | - | ||||||||||||||||||
3621 | void QGLContext::doneCurrent() | - | ||||||||||||||||||
3622 | { | - | ||||||||||||||||||
3623 | Q_D(QGLContext); | - | ||||||||||||||||||
3624 | d->guiGlContext->doneCurrent(); | - | ||||||||||||||||||
3625 | } executed 11 times by 3 tests: end of block Executed by:
| 11 | ||||||||||||||||||
3626 | - | |||||||||||||||||||
3627 | /*! | - | ||||||||||||||||||
3628 | \fn QPaintDevice* QGLContext::device() const | - | ||||||||||||||||||
3629 | - | |||||||||||||||||||
3630 | Returns the paint device set for this context. | - | ||||||||||||||||||
3631 | - | |||||||||||||||||||
3632 | \sa QGLContext::QGLContext() | - | ||||||||||||||||||
3633 | */ | - | ||||||||||||||||||
3634 | - | |||||||||||||||||||
3635 | /***************************************************************************** | - | ||||||||||||||||||
3636 | QGLWidget implementation | - | ||||||||||||||||||
3637 | *****************************************************************************/ | - | ||||||||||||||||||
3638 | - | |||||||||||||||||||
3639 | - | |||||||||||||||||||
3640 | /*! | - | ||||||||||||||||||
3641 | \class QGLWidget | - | ||||||||||||||||||
3642 | \inmodule QtOpenGL | - | ||||||||||||||||||
3643 | \obsolete | - | ||||||||||||||||||
3644 | - | |||||||||||||||||||
3645 | \brief The QGLWidget class is a widget for rendering OpenGL graphics. | - | ||||||||||||||||||
3646 | - | |||||||||||||||||||
3647 | QGLWidget provides functionality for displaying OpenGL graphics | - | ||||||||||||||||||
3648 | integrated into a Qt application. It is very simple to use. You | - | ||||||||||||||||||
3649 | inherit from it and use the subclass like any other QWidget, | - | ||||||||||||||||||
3650 | except that you have the choice between using QPainter and | - | ||||||||||||||||||
3651 | standard OpenGL rendering commands. | - | ||||||||||||||||||
3652 | - | |||||||||||||||||||
3653 | \note This class is part of the legacy \l {Qt OpenGL} module and, | - | ||||||||||||||||||
3654 | like the other \c QGL classes, should be avoided in the new | - | ||||||||||||||||||
3655 | applications. Instead, starting from Qt 5.4, prefer using | - | ||||||||||||||||||
3656 | QOpenGLWidget and the \c QOpenGL classes. | - | ||||||||||||||||||
3657 | - | |||||||||||||||||||
3658 | QGLWidget provides three convenient virtual functions that you can | - | ||||||||||||||||||
3659 | reimplement in your subclass to perform the typical OpenGL tasks: | - | ||||||||||||||||||
3660 | - | |||||||||||||||||||
3661 | \list | - | ||||||||||||||||||
3662 | \li paintGL() - Renders the OpenGL scene. Gets called whenever the widget | - | ||||||||||||||||||
3663 | needs to be updated. | - | ||||||||||||||||||
3664 | \li resizeGL() - Sets up the OpenGL viewport, projection, etc. Gets | - | ||||||||||||||||||
3665 | called whenever the widget has been resized (and also when it | - | ||||||||||||||||||
3666 | is shown for the first time because all newly created widgets get a | - | ||||||||||||||||||
3667 | resize event automatically). | - | ||||||||||||||||||
3668 | \li initializeGL() - Sets up the OpenGL rendering context, defines display | - | ||||||||||||||||||
3669 | lists, etc. Gets called once before the first time resizeGL() or | - | ||||||||||||||||||
3670 | paintGL() is called. | - | ||||||||||||||||||
3671 | \endlist | - | ||||||||||||||||||
3672 | - | |||||||||||||||||||
3673 | Here is a rough outline of how a QGLWidget subclass might look: | - | ||||||||||||||||||
3674 | - | |||||||||||||||||||
3675 | \snippet code/src_opengl_qgl.cpp 8 | - | ||||||||||||||||||
3676 | - | |||||||||||||||||||
3677 | If you need to trigger a repaint from places other than paintGL() | - | ||||||||||||||||||
3678 | (a typical example is when using \l{QTimer}{timers} to | - | ||||||||||||||||||
3679 | animate scenes), you should call the widget's updateGL() function. | - | ||||||||||||||||||
3680 | - | |||||||||||||||||||
3681 | Your widget's OpenGL rendering context is made current when | - | ||||||||||||||||||
3682 | paintGL(), resizeGL(), or initializeGL() is called. If you need to | - | ||||||||||||||||||
3683 | call the standard OpenGL API functions from other places (e.g. in | - | ||||||||||||||||||
3684 | your widget's constructor or in your own paint functions), you | - | ||||||||||||||||||
3685 | must call makeCurrent() first. | - | ||||||||||||||||||
3686 | - | |||||||||||||||||||
3687 | QGLWidget provides functions for requesting a new display | - | ||||||||||||||||||
3688 | \l{QGLFormat}{format} and you can also create widgets with | - | ||||||||||||||||||
3689 | customized rendering \l{QGLContext}{contexts}. | - | ||||||||||||||||||
3690 | - | |||||||||||||||||||
3691 | You can also share OpenGL display lists between QGLWidget objects (see | - | ||||||||||||||||||
3692 | the documentation of the QGLWidget constructors for details). | - | ||||||||||||||||||
3693 | - | |||||||||||||||||||
3694 | Note that under Windows, the QGLContext belonging to a QGLWidget | - | ||||||||||||||||||
3695 | has to be recreated when the QGLWidget is reparented. This is | - | ||||||||||||||||||
3696 | necessary due to limitations on the Windows platform. This will | - | ||||||||||||||||||
3697 | most likely cause problems for users that have subclassed and | - | ||||||||||||||||||
3698 | installed their own QGLContext on a QGLWidget. It is possible to | - | ||||||||||||||||||
3699 | work around this issue by putting the QGLWidget inside a dummy | - | ||||||||||||||||||
3700 | widget and then reparenting the dummy widget, instead of the | - | ||||||||||||||||||
3701 | QGLWidget. This will side-step the issue altogether, and is what | - | ||||||||||||||||||
3702 | we recommend for users that need this kind of functionality. | - | ||||||||||||||||||
3703 | - | |||||||||||||||||||
3704 | On \macos, when Qt is built with Cocoa support, a QGLWidget | - | ||||||||||||||||||
3705 | can't have any sibling widgets placed ontop of itself. This is due | - | ||||||||||||||||||
3706 | to limitations in the Cocoa API and is not supported by Apple. | - | ||||||||||||||||||
3707 | - | |||||||||||||||||||
3708 | \section1 Overlays | - | ||||||||||||||||||
3709 | - | |||||||||||||||||||
3710 | The QGLWidget creates a GL overlay context in addition to the | - | ||||||||||||||||||
3711 | normal context if overlays are supported by the underlying system. | - | ||||||||||||||||||
3712 | - | |||||||||||||||||||
3713 | If you want to use overlays, you specify it in the | - | ||||||||||||||||||
3714 | \l{QGLFormat}{format}. (Note: Overlay must be requested in the format | - | ||||||||||||||||||
3715 | passed to the QGLWidget constructor.) Your GL widget should also | - | ||||||||||||||||||
3716 | implement some or all of these virtual methods: | - | ||||||||||||||||||
3717 | - | |||||||||||||||||||
3718 | \list | - | ||||||||||||||||||
3719 | \li paintOverlayGL() | - | ||||||||||||||||||
3720 | \li resizeOverlayGL() | - | ||||||||||||||||||
3721 | \li initializeOverlayGL() | - | ||||||||||||||||||
3722 | \endlist | - | ||||||||||||||||||
3723 | - | |||||||||||||||||||
3724 | These methods work in the same way as the normal paintGL() etc. | - | ||||||||||||||||||
3725 | functions, except that they will be called when the overlay | - | ||||||||||||||||||
3726 | context is made current. You can explicitly make the overlay | - | ||||||||||||||||||
3727 | context current by using makeOverlayCurrent(), and you can access | - | ||||||||||||||||||
3728 | the overlay context directly (e.g. to ask for its transparent | - | ||||||||||||||||||
3729 | color) by calling overlayContext(). | - | ||||||||||||||||||
3730 | - | |||||||||||||||||||
3731 | On X servers in which the default visual is in an overlay plane, | - | ||||||||||||||||||
3732 | non-GL Qt windows can also be used for overlays. | - | ||||||||||||||||||
3733 | - | |||||||||||||||||||
3734 | \section1 Painting Techniques | - | ||||||||||||||||||
3735 | - | |||||||||||||||||||
3736 | As described above, subclass QGLWidget to render pure 3D content in the | - | ||||||||||||||||||
3737 | following way: | - | ||||||||||||||||||
3738 | - | |||||||||||||||||||
3739 | \list | - | ||||||||||||||||||
3740 | \li Reimplement the QGLWidget::initializeGL() and QGLWidget::resizeGL() to | - | ||||||||||||||||||
3741 | set up the OpenGL state and provide a perspective transformation. | - | ||||||||||||||||||
3742 | \li Reimplement QGLWidget::paintGL() to paint the 3D scene, calling only | - | ||||||||||||||||||
3743 | OpenGL functions to draw on the widget. | - | ||||||||||||||||||
3744 | \endlist | - | ||||||||||||||||||
3745 | - | |||||||||||||||||||
3746 | It is also possible to draw 2D graphics onto a QGLWidget subclass, it is necessary | - | ||||||||||||||||||
3747 | to reimplement QGLWidget::paintEvent() and do the following: | - | ||||||||||||||||||
3748 | - | |||||||||||||||||||
3749 | \list | - | ||||||||||||||||||
3750 | \li Construct a QPainter object. | - | ||||||||||||||||||
3751 | \li Initialize it for use on the widget with the QPainter::begin() function. | - | ||||||||||||||||||
3752 | \li Draw primitives using QPainter's member functions. | - | ||||||||||||||||||
3753 | \li Call QPainter::end() to finish painting. | - | ||||||||||||||||||
3754 | \endlist | - | ||||||||||||||||||
3755 | - | |||||||||||||||||||
3756 | \section1 Threading | - | ||||||||||||||||||
3757 | - | |||||||||||||||||||
3758 | As of Qt version 4.8, support for doing threaded GL rendering has | - | ||||||||||||||||||
3759 | been improved. There are three scenarios that we currently support: | - | ||||||||||||||||||
3760 | \list | - | ||||||||||||||||||
3761 | \li 1. Buffer swapping in a thread. | - | ||||||||||||||||||
3762 | - | |||||||||||||||||||
3763 | Swapping buffers in a double buffered context may be a | - | ||||||||||||||||||
3764 | synchronous, locking call that may be a costly operation in some | - | ||||||||||||||||||
3765 | GL implementations. Especially so on embedded devices. It's not | - | ||||||||||||||||||
3766 | optimal to have the CPU idling while the GPU is doing a buffer | - | ||||||||||||||||||
3767 | swap. In those cases it is possible to do the rendering in the | - | ||||||||||||||||||
3768 | main thread and do the actual buffer swap in a separate | - | ||||||||||||||||||
3769 | thread. This can be done with the following steps: | - | ||||||||||||||||||
3770 | - | |||||||||||||||||||
3771 | 1. Call doneCurrent() in the main thread when the rendering is | - | ||||||||||||||||||
3772 | finished. | - | ||||||||||||||||||
3773 | - | |||||||||||||||||||
3774 | 2. Call QGLContext::moveToThread(swapThread) to transfer ownership | - | ||||||||||||||||||
3775 | of the context to the swapping thread. | - | ||||||||||||||||||
3776 | - | |||||||||||||||||||
3777 | 3. Notify the swapping thread that it can grab the context. | - | ||||||||||||||||||
3778 | - | |||||||||||||||||||
3779 | 4. Make the rendering context current in the swapping thread with | - | ||||||||||||||||||
3780 | makeCurrent() and then call swapBuffers(). | - | ||||||||||||||||||
3781 | - | |||||||||||||||||||
3782 | 5. Call doneCurrent() in the swapping thread. | - | ||||||||||||||||||
3783 | - | |||||||||||||||||||
3784 | 6. Call QGLContext::moveToThread(qApp->thread()) and notify the | - | ||||||||||||||||||
3785 | main thread that swapping is done. | - | ||||||||||||||||||
3786 | - | |||||||||||||||||||
3787 | Doing this will free up the main thread so that it can continue | - | ||||||||||||||||||
3788 | with, for example, handling UI events or network requests. Even if | - | ||||||||||||||||||
3789 | there is a context swap involved, it may be preferable compared to | - | ||||||||||||||||||
3790 | having the main thread wait while the GPU finishes the swap | - | ||||||||||||||||||
3791 | operation. Note that this is highly implementation dependent. | - | ||||||||||||||||||
3792 | - | |||||||||||||||||||
3793 | \li 2. Texture uploading in a thread. | - | ||||||||||||||||||
3794 | - | |||||||||||||||||||
3795 | Doing texture uploads in a thread may be very useful for | - | ||||||||||||||||||
3796 | applications handling large amounts of images that needs to be | - | ||||||||||||||||||
3797 | displayed, like for instance a photo gallery application. This is | - | ||||||||||||||||||
3798 | supported in Qt through the existing bindTexture() API. A simple | - | ||||||||||||||||||
3799 | way of doing this is to create two sharing QGLWidgets. One is made | - | ||||||||||||||||||
3800 | current in the main GUI thread, while the other is made current in | - | ||||||||||||||||||
3801 | the texture upload thread. The widget in the uploading thread is | - | ||||||||||||||||||
3802 | never shown, it is only used for sharing textures with the main | - | ||||||||||||||||||
3803 | thread. For each texture that is bound via bindTexture(), notify | - | ||||||||||||||||||
3804 | the main thread so that it can start using the texture. | - | ||||||||||||||||||
3805 | - | |||||||||||||||||||
3806 | \li 3. Using QPainter to draw into a QGLWidget in a thread. | - | ||||||||||||||||||
3807 | - | |||||||||||||||||||
3808 | In Qt 4.8, it is possible to draw into a QGLWidget using a | - | ||||||||||||||||||
3809 | QPainter in a separate thread. Note that this is also possible for | - | ||||||||||||||||||
3810 | QGLPixelBuffers and QGLFramebufferObjects. Since this is only | - | ||||||||||||||||||
3811 | supported in the GL 2 paint engine, OpenGL 2.0 or OpenGL ES 2.0 is | - | ||||||||||||||||||
3812 | required. | - | ||||||||||||||||||
3813 | - | |||||||||||||||||||
3814 | QGLWidgets can only be created in the main GUI thread. This means | - | ||||||||||||||||||
3815 | a call to doneCurrent() is necessary to release the GL context | - | ||||||||||||||||||
3816 | from the main thread, before the widget can be drawn into by | - | ||||||||||||||||||
3817 | another thread. You then need to call QGLContext::moveToThread() | - | ||||||||||||||||||
3818 | to transfer ownership of the context to the thread in which you | - | ||||||||||||||||||
3819 | want to make it current. | - | ||||||||||||||||||
3820 | Also, the main GUI thread will dispatch resize and | - | ||||||||||||||||||
3821 | paint events to a QGLWidget when the widget is resized, or parts | - | ||||||||||||||||||
3822 | of it becomes exposed or needs redrawing. It is therefore | - | ||||||||||||||||||
3823 | necessary to handle those events because the default | - | ||||||||||||||||||
3824 | implementations inside QGLWidget will try to make the QGLWidget's | - | ||||||||||||||||||
3825 | context current, which again will interfere with any threads | - | ||||||||||||||||||
3826 | rendering into the widget. Reimplement QGLWidget::paintEvent() and | - | ||||||||||||||||||
3827 | QGLWidget::resizeEvent() to notify the rendering thread that a | - | ||||||||||||||||||
3828 | resize or update is necessary, and be careful not to call the base | - | ||||||||||||||||||
3829 | class implementation. If you are rendering an animation, it might | - | ||||||||||||||||||
3830 | not be necessary to handle the paint event at all since the | - | ||||||||||||||||||
3831 | rendering thread is doing regular updates. Then it would be enough | - | ||||||||||||||||||
3832 | to reimplement QGLWidget::paintEvent() to do nothing. | - | ||||||||||||||||||
3833 | - | |||||||||||||||||||
3834 | \endlist | - | ||||||||||||||||||
3835 | - | |||||||||||||||||||
3836 | As a general rule when doing threaded rendering: be aware that | - | ||||||||||||||||||
3837 | binding and releasing contexts in different threads have to be | - | ||||||||||||||||||
3838 | synchronized by the user. A GL rendering context can only be | - | ||||||||||||||||||
3839 | current in one thread at any time. If you try to open a QPainter | - | ||||||||||||||||||
3840 | on a QGLWidget and the widget's rendering context is current in | - | ||||||||||||||||||
3841 | another thread, it will fail. | - | ||||||||||||||||||
3842 | - | |||||||||||||||||||
3843 | In addition to this, rendering using raw GL calls in a separate | - | ||||||||||||||||||
3844 | thread is supported. | - | ||||||||||||||||||
3845 | - | |||||||||||||||||||
3846 | \e{OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other | - | ||||||||||||||||||
3847 | countries.} | - | ||||||||||||||||||
3848 | - | |||||||||||||||||||
3849 | \sa QOpenGLWidget, QGLPixelBuffer | - | ||||||||||||||||||
3850 | */ | - | ||||||||||||||||||
3851 | - | |||||||||||||||||||
3852 | /*! | - | ||||||||||||||||||
3853 | Constructs an OpenGL widget with a \a parent widget. | - | ||||||||||||||||||
3854 | - | |||||||||||||||||||
3855 | The \l{QGLFormat::defaultFormat()}{default format} is | - | ||||||||||||||||||
3856 | used. The widget will be \l{isValid()}{invalid} if the | - | ||||||||||||||||||
3857 | system has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
3858 | - | |||||||||||||||||||
3859 | The \a parent and widget flag, \a f, arguments are passed | - | ||||||||||||||||||
3860 | to the QWidget constructor. | - | ||||||||||||||||||
3861 | - | |||||||||||||||||||
3862 | If \a shareWidget is a valid QGLWidget, this widget will share | - | ||||||||||||||||||
3863 | OpenGL display lists and texture objects with \a shareWidget. But | - | ||||||||||||||||||
3864 | if \a shareWidget and this widget have different \l {format()} | - | ||||||||||||||||||
3865 | {formats}, sharing might not be possible. You can check whether | - | ||||||||||||||||||
3866 | sharing is in effect by calling isSharing(). | - | ||||||||||||||||||
3867 | - | |||||||||||||||||||
3868 | The initialization of OpenGL rendering state, etc. should be done | - | ||||||||||||||||||
3869 | by overriding the initializeGL() function, rather than in the | - | ||||||||||||||||||
3870 | constructor of your QGLWidget subclass. | - | ||||||||||||||||||
3871 | - | |||||||||||||||||||
3872 | \sa QGLFormat::defaultFormat(), {Textures Example} | - | ||||||||||||||||||
3873 | */ | - | ||||||||||||||||||
3874 | - | |||||||||||||||||||
3875 | QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFlags f) | - | ||||||||||||||||||
3876 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
3877 | { | - | ||||||||||||||||||
3878 | Q_D(QGLWidget); | - | ||||||||||||||||||
3879 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
3880 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
3881 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
3882 | d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget); | - | ||||||||||||||||||
3883 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3884 | - | |||||||||||||||||||
3885 | /*! | - | ||||||||||||||||||
3886 | \internal | - | ||||||||||||||||||
3887 | */ | - | ||||||||||||||||||
3888 | QGLWidget::QGLWidget(QGLWidgetPrivate &dd, const QGLFormat &format, QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f) | - | ||||||||||||||||||
3889 | : QWidget(dd, parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
3890 | { | - | ||||||||||||||||||
3891 | Q_D(QGLWidget); | - | ||||||||||||||||||
3892 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
3893 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
3894 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
3895 | d->init(new QGLContext(format, this), shareWidget); | - | ||||||||||||||||||
3896 | - | |||||||||||||||||||
3897 | } never executed: end of block | 0 | ||||||||||||||||||
3898 | - | |||||||||||||||||||
3899 | - | |||||||||||||||||||
3900 | /*! | - | ||||||||||||||||||
3901 | Constructs an OpenGL widget with parent \a parent. | - | ||||||||||||||||||
3902 | - | |||||||||||||||||||
3903 | The \a format argument specifies the desired | - | ||||||||||||||||||
3904 | \l{QGLFormat}{rendering options}. | - | ||||||||||||||||||
3905 | If the underlying OpenGL/Window system | - | ||||||||||||||||||
3906 | cannot satisfy all the features requested in \a format, the | - | ||||||||||||||||||
3907 | nearest subset of features will be used. After creation, the | - | ||||||||||||||||||
3908 | format() method will return the actual format obtained. | - | ||||||||||||||||||
3909 | - | |||||||||||||||||||
3910 | The widget will be \l{isValid()}{invalid} if the system | - | ||||||||||||||||||
3911 | has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
3912 | - | |||||||||||||||||||
3913 | The \a parent and widget flag, \a f, arguments are passed | - | ||||||||||||||||||
3914 | to the QWidget constructor. | - | ||||||||||||||||||
3915 | - | |||||||||||||||||||
3916 | If \a shareWidget is a valid QGLWidget, this widget will share | - | ||||||||||||||||||
3917 | OpenGL display lists and texture objects with \a shareWidget. But | - | ||||||||||||||||||
3918 | if \a shareWidget and this widget have different \l {format()} | - | ||||||||||||||||||
3919 | {formats}, sharing might not be possible. You can check whether | - | ||||||||||||||||||
3920 | sharing is in effect by calling isSharing(). | - | ||||||||||||||||||
3921 | - | |||||||||||||||||||
3922 | The initialization of OpenGL rendering state, etc. should be done | - | ||||||||||||||||||
3923 | by overriding the initializeGL() function, rather than in the | - | ||||||||||||||||||
3924 | constructor of your QGLWidget subclass. | - | ||||||||||||||||||
3925 | - | |||||||||||||||||||
3926 | \sa QGLFormat::defaultFormat(), isValid() | - | ||||||||||||||||||
3927 | */ | - | ||||||||||||||||||
3928 | - | |||||||||||||||||||
3929 | QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget* shareWidget, | - | ||||||||||||||||||
3930 | Qt::WindowFlags f) | - | ||||||||||||||||||
3931 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
3932 | { | - | ||||||||||||||||||
3933 | Q_D(QGLWidget); | - | ||||||||||||||||||
3934 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
3935 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
3936 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
3937 | d->init(new QGLContext(format, this), shareWidget); | - | ||||||||||||||||||
3938 | } never executed: end of block | 0 | ||||||||||||||||||
3939 | - | |||||||||||||||||||
3940 | /*! | - | ||||||||||||||||||
3941 | Constructs an OpenGL widget with parent \a parent. | - | ||||||||||||||||||
3942 | - | |||||||||||||||||||
3943 | The \a context argument is a pointer to the QGLContext that | - | ||||||||||||||||||
3944 | you wish to be bound to this widget. This allows you to pass in | - | ||||||||||||||||||
3945 | your own QGLContext sub-classes. | - | ||||||||||||||||||
3946 | - | |||||||||||||||||||
3947 | The widget will be \l{isValid()}{invalid} if the system | - | ||||||||||||||||||
3948 | has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
3949 | - | |||||||||||||||||||
3950 | The \a parent and widget flag, \a f, arguments are passed | - | ||||||||||||||||||
3951 | to the QWidget constructor. | - | ||||||||||||||||||
3952 | - | |||||||||||||||||||
3953 | If \a shareWidget is a valid QGLWidget, this widget will share | - | ||||||||||||||||||
3954 | OpenGL display lists and texture objects with \a shareWidget. But | - | ||||||||||||||||||
3955 | if \a shareWidget and this widget have different \l {format()} | - | ||||||||||||||||||
3956 | {formats}, sharing might not be possible. You can check whether | - | ||||||||||||||||||
3957 | sharing is in effect by calling isSharing(). | - | ||||||||||||||||||
3958 | - | |||||||||||||||||||
3959 | The initialization of OpenGL rendering state, etc. should be done | - | ||||||||||||||||||
3960 | by overriding the initializeGL() function, rather than in the | - | ||||||||||||||||||
3961 | constructor of your QGLWidget subclass. | - | ||||||||||||||||||
3962 | - | |||||||||||||||||||
3963 | \sa QGLFormat::defaultFormat(), isValid() | - | ||||||||||||||||||
3964 | */ | - | ||||||||||||||||||
3965 | QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, const QGLWidget *shareWidget, | - | ||||||||||||||||||
3966 | Qt::WindowFlags f) | - | ||||||||||||||||||
3967 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
3968 | { | - | ||||||||||||||||||
3969 | Q_D(QGLWidget); | - | ||||||||||||||||||
3970 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
3971 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
3972 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
3973 | d->init(context, shareWidget); | - | ||||||||||||||||||
3974 | } never executed: end of block | 0 | ||||||||||||||||||
3975 | - | |||||||||||||||||||
3976 | /*! | - | ||||||||||||||||||
3977 | Destroys the widget. | - | ||||||||||||||||||
3978 | */ | - | ||||||||||||||||||
3979 | - | |||||||||||||||||||
3980 | QGLWidget::~QGLWidget() | - | ||||||||||||||||||
3981 | { | - | ||||||||||||||||||
3982 | Q_D(QGLWidget); | - | ||||||||||||||||||
3983 | delete d->glcx; | - | ||||||||||||||||||
3984 | d->glcx = 0; | - | ||||||||||||||||||
3985 | d->cleanupColormaps(); | - | ||||||||||||||||||
3986 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
3987 | - | |||||||||||||||||||
3988 | /*! | - | ||||||||||||||||||
3989 | \fn QGLFormat QGLWidget::format() const | - | ||||||||||||||||||
3990 | - | |||||||||||||||||||
3991 | Returns the format of the contained GL rendering context. | - | ||||||||||||||||||
3992 | */ | - | ||||||||||||||||||
3993 | - | |||||||||||||||||||
3994 | /*! | - | ||||||||||||||||||
3995 | \fn bool QGLWidget::doubleBuffer() const | - | ||||||||||||||||||
3996 | - | |||||||||||||||||||
3997 | Returns \c true if the contained GL rendering context has double | - | ||||||||||||||||||
3998 | buffering; otherwise returns \c false. | - | ||||||||||||||||||
3999 | - | |||||||||||||||||||
4000 | \sa QGLFormat::doubleBuffer() | - | ||||||||||||||||||
4001 | */ | - | ||||||||||||||||||
4002 | - | |||||||||||||||||||
4003 | /*! | - | ||||||||||||||||||
4004 | \fn void QGLWidget::setAutoBufferSwap(bool on) | - | ||||||||||||||||||
4005 | - | |||||||||||||||||||
4006 | If \a on is true automatic GL buffer swapping is switched on; | - | ||||||||||||||||||
4007 | otherwise it is switched off. | - | ||||||||||||||||||
4008 | - | |||||||||||||||||||
4009 | If \a on is true and the widget is using a double-buffered format, | - | ||||||||||||||||||
4010 | the background and foreground GL buffers will automatically be | - | ||||||||||||||||||
4011 | swapped after each paintGL() call. | - | ||||||||||||||||||
4012 | - | |||||||||||||||||||
4013 | The buffer auto-swapping is on by default. | - | ||||||||||||||||||
4014 | - | |||||||||||||||||||
4015 | \sa autoBufferSwap(), doubleBuffer(), swapBuffers() | - | ||||||||||||||||||
4016 | */ | - | ||||||||||||||||||
4017 | - | |||||||||||||||||||
4018 | /*! | - | ||||||||||||||||||
4019 | \fn bool QGLWidget::autoBufferSwap() const | - | ||||||||||||||||||
4020 | - | |||||||||||||||||||
4021 | Returns \c true if the widget is doing automatic GL buffer swapping; | - | ||||||||||||||||||
4022 | otherwise returns \c false. | - | ||||||||||||||||||
4023 | - | |||||||||||||||||||
4024 | \sa setAutoBufferSwap() | - | ||||||||||||||||||
4025 | */ | - | ||||||||||||||||||
4026 | - | |||||||||||||||||||
4027 | /*! | - | ||||||||||||||||||
4028 | \fn QFunctionPointer QGLContext::getProcAddress(const QString &proc) const | - | ||||||||||||||||||
4029 | - | |||||||||||||||||||
4030 | Returns a function pointer to the GL extension function passed in | - | ||||||||||||||||||
4031 | \a proc. 0 is returned if a pointer to the function could not be | - | ||||||||||||||||||
4032 | obtained. | - | ||||||||||||||||||
4033 | */ | - | ||||||||||||||||||
4034 | QFunctionPointer QGLContext::getProcAddress(const QString &procName) const | - | ||||||||||||||||||
4035 | { | - | ||||||||||||||||||
4036 | Q_D(const QGLContext); | - | ||||||||||||||||||
4037 | return d->guiGlContext->getProcAddress(procName.toLatin1()); never executed: return d->guiGlContext->getProcAddress(procName.toLatin1()); | 0 | ||||||||||||||||||
4038 | } | - | ||||||||||||||||||
4039 | - | |||||||||||||||||||
4040 | /*! | - | ||||||||||||||||||
4041 | \fn bool QGLWidget::isValid() const | - | ||||||||||||||||||
4042 | - | |||||||||||||||||||
4043 | Returns \c true if the widget has a valid GL rendering context; | - | ||||||||||||||||||
4044 | otherwise returns \c false. A widget will be invalid if the system | - | ||||||||||||||||||
4045 | has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
4046 | */ | - | ||||||||||||||||||
4047 | - | |||||||||||||||||||
4048 | bool QGLWidget::isValid() const | - | ||||||||||||||||||
4049 | { | - | ||||||||||||||||||
4050 | Q_D(const QGLWidget); | - | ||||||||||||||||||
4051 | return d->glcx && d->glcx->isValid(); executed 3 times by 1 test: return d->glcx && d->glcx->isValid(); Executed by:
| 0-3 | ||||||||||||||||||
4052 | } | - | ||||||||||||||||||
4053 | - | |||||||||||||||||||
4054 | /*! | - | ||||||||||||||||||
4055 | \fn bool QGLWidget::isSharing() const | - | ||||||||||||||||||
4056 | - | |||||||||||||||||||
4057 | Returns \c true if this widget's GL context is shared with another GL | - | ||||||||||||||||||
4058 | context, otherwise false is returned. Context sharing might not be | - | ||||||||||||||||||
4059 | possible if the widgets use different formats. | - | ||||||||||||||||||
4060 | - | |||||||||||||||||||
4061 | \sa format() | - | ||||||||||||||||||
4062 | */ | - | ||||||||||||||||||
4063 | - | |||||||||||||||||||
4064 | bool QGLWidget::isSharing() const | - | ||||||||||||||||||
4065 | { | - | ||||||||||||||||||
4066 | Q_D(const QGLWidget); | - | ||||||||||||||||||
4067 | return d->glcx->isSharing(); executed 1 time by 1 test: return d->glcx->isSharing(); Executed by:
| 1 | ||||||||||||||||||
4068 | } | - | ||||||||||||||||||
4069 | - | |||||||||||||||||||
4070 | /*! | - | ||||||||||||||||||
4071 | \fn void QGLWidget::makeCurrent() | - | ||||||||||||||||||
4072 | - | |||||||||||||||||||
4073 | Makes this widget the current widget for OpenGL operations, i.e. | - | ||||||||||||||||||
4074 | makes the widget's rendering context the current OpenGL rendering | - | ||||||||||||||||||
4075 | context. | - | ||||||||||||||||||
4076 | */ | - | ||||||||||||||||||
4077 | - | |||||||||||||||||||
4078 | void QGLWidget::makeCurrent() | - | ||||||||||||||||||
4079 | { | - | ||||||||||||||||||
4080 | Q_D(QGLWidget); | - | ||||||||||||||||||
4081 | d->glcx->makeCurrent(); | - | ||||||||||||||||||
4082 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
4083 | - | |||||||||||||||||||
4084 | /*! | - | ||||||||||||||||||
4085 | \fn void QGLWidget::doneCurrent() | - | ||||||||||||||||||
4086 | - | |||||||||||||||||||
4087 | Makes no GL context the current context. Normally, you do not need | - | ||||||||||||||||||
4088 | to call this function; QGLContext calls it as necessary. However, | - | ||||||||||||||||||
4089 | it may be useful in multithreaded environments. | - | ||||||||||||||||||
4090 | */ | - | ||||||||||||||||||
4091 | - | |||||||||||||||||||
4092 | void QGLWidget::doneCurrent() | - | ||||||||||||||||||
4093 | { | - | ||||||||||||||||||
4094 | Q_D(QGLWidget); | - | ||||||||||||||||||
4095 | d->glcx->doneCurrent(); | - | ||||||||||||||||||
4096 | } never executed: end of block | 0 | ||||||||||||||||||
4097 | - | |||||||||||||||||||
4098 | /*! | - | ||||||||||||||||||
4099 | \fn void QGLWidget::swapBuffers() | - | ||||||||||||||||||
4100 | - | |||||||||||||||||||
4101 | Swaps the screen contents with an off-screen buffer. This only | - | ||||||||||||||||||
4102 | works if the widget's format specifies double buffer mode. | - | ||||||||||||||||||
4103 | - | |||||||||||||||||||
4104 | Normally, there is no need to explicitly call this function | - | ||||||||||||||||||
4105 | because it is done automatically after each widget repaint, i.e. | - | ||||||||||||||||||
4106 | each time after paintGL() has been executed. | - | ||||||||||||||||||
4107 | - | |||||||||||||||||||
4108 | \sa doubleBuffer(), setAutoBufferSwap(), QGLFormat::setDoubleBuffer() | - | ||||||||||||||||||
4109 | */ | - | ||||||||||||||||||
4110 | - | |||||||||||||||||||
4111 | void QGLWidget::swapBuffers() | - | ||||||||||||||||||
4112 | { | - | ||||||||||||||||||
4113 | Q_D(QGLWidget); | - | ||||||||||||||||||
4114 | d->glcx->swapBuffers(); | - | ||||||||||||||||||
4115 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
4116 | - | |||||||||||||||||||
4117 | - | |||||||||||||||||||
4118 | /*! | - | ||||||||||||||||||
4119 | \fn const QGLContext* QGLWidget::overlayContext() const | - | ||||||||||||||||||
4120 | - | |||||||||||||||||||
4121 | Returns the overlay context of this widget, or 0 if this widget | - | ||||||||||||||||||
4122 | has no overlay. | - | ||||||||||||||||||
4123 | - | |||||||||||||||||||
4124 | \sa context() | - | ||||||||||||||||||
4125 | */ | - | ||||||||||||||||||
4126 | const QGLContext* QGLWidget::overlayContext() const | - | ||||||||||||||||||
4127 | { | - | ||||||||||||||||||
4128 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
4129 | } | - | ||||||||||||||||||
4130 | - | |||||||||||||||||||
4131 | /*! | - | ||||||||||||||||||
4132 | \fn void QGLWidget::makeOverlayCurrent() | - | ||||||||||||||||||
4133 | - | |||||||||||||||||||
4134 | Makes the overlay context of this widget current. Use this if you | - | ||||||||||||||||||
4135 | need to issue OpenGL commands to the overlay context outside of | - | ||||||||||||||||||
4136 | initializeOverlayGL(), resizeOverlayGL(), and paintOverlayGL(). | - | ||||||||||||||||||
4137 | - | |||||||||||||||||||
4138 | Does nothing if this widget has no overlay. | - | ||||||||||||||||||
4139 | - | |||||||||||||||||||
4140 | \sa makeCurrent() | - | ||||||||||||||||||
4141 | */ | - | ||||||||||||||||||
4142 | void QGLWidget::makeOverlayCurrent() | - | ||||||||||||||||||
4143 | { | - | ||||||||||||||||||
4144 | } | - | ||||||||||||||||||
4145 | - | |||||||||||||||||||
4146 | /*! | - | ||||||||||||||||||
4147 | \obsolete | - | ||||||||||||||||||
4148 | - | |||||||||||||||||||
4149 | Sets a new format for this widget. | - | ||||||||||||||||||
4150 | - | |||||||||||||||||||
4151 | If the underlying OpenGL/Window system cannot satisfy all the | - | ||||||||||||||||||
4152 | features requested in \a format, the nearest subset of features will | - | ||||||||||||||||||
4153 | be used. After creation, the format() method will return the actual | - | ||||||||||||||||||
4154 | rendering context format obtained. | - | ||||||||||||||||||
4155 | - | |||||||||||||||||||
4156 | The widget will be assigned a new QGLContext, and the initializeGL() | - | ||||||||||||||||||
4157 | function will be executed for this new context before the first | - | ||||||||||||||||||
4158 | resizeGL() or paintGL(). | - | ||||||||||||||||||
4159 | - | |||||||||||||||||||
4160 | This method will try to keep display list and texture object sharing | - | ||||||||||||||||||
4161 | in effect with other QGLWidget objects, but changing the format might make | - | ||||||||||||||||||
4162 | sharing impossible. Use isSharing() to see if sharing is still in | - | ||||||||||||||||||
4163 | effect. | - | ||||||||||||||||||
4164 | - | |||||||||||||||||||
4165 | \sa format(), isSharing(), isValid() | - | ||||||||||||||||||
4166 | */ | - | ||||||||||||||||||
4167 | - | |||||||||||||||||||
4168 | void QGLWidget::setFormat(const QGLFormat &format) | - | ||||||||||||||||||
4169 | { | - | ||||||||||||||||||
4170 | setContext(new QGLContext(format,this)); | - | ||||||||||||||||||
4171 | } never executed: end of block | 0 | ||||||||||||||||||
4172 | - | |||||||||||||||||||
4173 | - | |||||||||||||||||||
4174 | - | |||||||||||||||||||
4175 | - | |||||||||||||||||||
4176 | /*! | - | ||||||||||||||||||
4177 | \fn QGLContext *QGLWidget::context() const | - | ||||||||||||||||||
4178 | - | |||||||||||||||||||
4179 | Returns the context of this widget. | - | ||||||||||||||||||
4180 | - | |||||||||||||||||||
4181 | It is possible that the context is not valid (see isValid()), for | - | ||||||||||||||||||
4182 | example, if the underlying hardware does not support the format | - | ||||||||||||||||||
4183 | attributes that were requested. | - | ||||||||||||||||||
4184 | */ | - | ||||||||||||||||||
4185 | - | |||||||||||||||||||
4186 | /*! | - | ||||||||||||||||||
4187 | \fn void QGLWidget::setContext(QGLContext *context, | - | ||||||||||||||||||
4188 | const QGLContext* shareContext, | - | ||||||||||||||||||
4189 | bool deleteOldContext) | - | ||||||||||||||||||
4190 | \obsolete | - | ||||||||||||||||||
4191 | - | |||||||||||||||||||
4192 | Sets a new context for this widget. The QGLContext \a context must | - | ||||||||||||||||||
4193 | be created using \e new. QGLWidget will delete \a context when | - | ||||||||||||||||||
4194 | another context is set or when the widget is destroyed. | - | ||||||||||||||||||
4195 | - | |||||||||||||||||||
4196 | If \a context is invalid, QGLContext::create() is performed on | - | ||||||||||||||||||
4197 | it. The initializeGL() function will then be executed for the new | - | ||||||||||||||||||
4198 | context before the first resizeGL() or paintGL(). | - | ||||||||||||||||||
4199 | - | |||||||||||||||||||
4200 | If \a context is invalid, this method will try to keep display list | - | ||||||||||||||||||
4201 | and texture object sharing in effect, or (if \a shareContext points | - | ||||||||||||||||||
4202 | to a valid context) start display list and texture object sharing | - | ||||||||||||||||||
4203 | with that context, but sharing might be impossible if the two | - | ||||||||||||||||||
4204 | contexts have different \l {format()} {formats}. Use isSharing() to | - | ||||||||||||||||||
4205 | see whether sharing is in effect. | - | ||||||||||||||||||
4206 | - | |||||||||||||||||||
4207 | If \a deleteOldContext is true (the default), the existing context | - | ||||||||||||||||||
4208 | will be deleted. You may use false here if you have kept a pointer | - | ||||||||||||||||||
4209 | to the old context (as returned by context()), and want to restore | - | ||||||||||||||||||
4210 | that context later. | - | ||||||||||||||||||
4211 | - | |||||||||||||||||||
4212 | \note This function is obsolete and should no longer be used. If you were | - | ||||||||||||||||||
4213 | using it to recreate the context for a QGLWidget, you should instead create a | - | ||||||||||||||||||
4214 | new QGLWidget or use the QOpenGLContext API in conjunction with QWindow. | - | ||||||||||||||||||
4215 | There is currently no officially supported way to substitute QGLWidget's | - | ||||||||||||||||||
4216 | context with your own implementation of QGLContext. | - | ||||||||||||||||||
4217 | - | |||||||||||||||||||
4218 | \sa context(), isSharing() | - | ||||||||||||||||||
4219 | */ | - | ||||||||||||||||||
4220 | void QGLWidget::setContext(QGLContext *context, | - | ||||||||||||||||||
4221 | const QGLContext* shareContext, | - | ||||||||||||||||||
4222 | bool deleteOldContext) | - | ||||||||||||||||||
4223 | { | - | ||||||||||||||||||
4224 | Q_D(QGLWidget); | - | ||||||||||||||||||
4225 | if (context == 0) {
| 0-12 | ||||||||||||||||||
4226 | qWarning("QGLWidget::setContext: Cannot set null context"); | - | ||||||||||||||||||
4227 | return; never executed: return; | 0 | ||||||||||||||||||
4228 | } | - | ||||||||||||||||||
4229 | - | |||||||||||||||||||
4230 | if (context->device() == 0) // a context may refere to more than 1 window.
| 0-12 | ||||||||||||||||||
4231 | context->setDevice(this); //but its better to point to 1 of them than none of them. never executed: context->setDevice(this); | 0 | ||||||||||||||||||
4232 | - | |||||||||||||||||||
4233 | QGLContext* oldcx = d->glcx; | - | ||||||||||||||||||
4234 | d->glcx = context; | - | ||||||||||||||||||
4235 | - | |||||||||||||||||||
4236 | if (!d->glcx->isValid())
| 0-12 | ||||||||||||||||||
4237 | d->glcx->create(shareContext ? shareContext : oldcx); executed 12 times by 3 tests: d->glcx->create(shareContext ? shareContext : oldcx); Executed by:
| 12 | ||||||||||||||||||
4238 | - | |||||||||||||||||||
4239 | if (deleteOldContext)
| 0-12 | ||||||||||||||||||
4240 | delete oldcx; executed 12 times by 3 tests: delete oldcx; Executed by:
| 12 | ||||||||||||||||||
4241 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
4242 | - | |||||||||||||||||||
4243 | /*! | - | ||||||||||||||||||
4244 | \fn void QGLWidget::updateGL() | - | ||||||||||||||||||
4245 | - | |||||||||||||||||||
4246 | Updates the widget by calling glDraw(). | - | ||||||||||||||||||
4247 | */ | - | ||||||||||||||||||
4248 | - | |||||||||||||||||||
4249 | void QGLWidget::updateGL() | - | ||||||||||||||||||
4250 | { | - | ||||||||||||||||||
4251 | Q_D(QGLWidget); | - | ||||||||||||||||||
4252 | const bool targetIsOffscreen = !d->glcx->d_ptr->readback_target_size.isEmpty(); | - | ||||||||||||||||||
4253 | if (updatesEnabled() && (testAttribute(Qt::WA_Mapped) || targetIsOffscreen))
| 0 | ||||||||||||||||||
4254 | glDraw(); never executed: glDraw(); | 0 | ||||||||||||||||||
4255 | } never executed: end of block | 0 | ||||||||||||||||||
4256 | - | |||||||||||||||||||
4257 | - | |||||||||||||||||||
4258 | /*! | - | ||||||||||||||||||
4259 | \fn void QGLWidget::updateOverlayGL() | - | ||||||||||||||||||
4260 | - | |||||||||||||||||||
4261 | Updates the widget's overlay (if any). Will cause the virtual | - | ||||||||||||||||||
4262 | function paintOverlayGL() to be executed. | - | ||||||||||||||||||
4263 | - | |||||||||||||||||||
4264 | The widget's rendering context will become the current context and | - | ||||||||||||||||||
4265 | initializeGL() will be called if it hasn't already been called. | - | ||||||||||||||||||
4266 | */ | - | ||||||||||||||||||
4267 | void QGLWidget::updateOverlayGL() | - | ||||||||||||||||||
4268 | { | - | ||||||||||||||||||
4269 | } | - | ||||||||||||||||||
4270 | - | |||||||||||||||||||
4271 | /*! | - | ||||||||||||||||||
4272 | This virtual function is called once before the first call to | - | ||||||||||||||||||
4273 | paintGL() or resizeGL(), and then once whenever the widget has | - | ||||||||||||||||||
4274 | been assigned a new QGLContext. Reimplement it in a subclass. | - | ||||||||||||||||||
4275 | - | |||||||||||||||||||
4276 | This function should set up any required OpenGL context rendering | - | ||||||||||||||||||
4277 | flags, defining display lists, etc. | - | ||||||||||||||||||
4278 | - | |||||||||||||||||||
4279 | There is no need to call makeCurrent() because this has already | - | ||||||||||||||||||
4280 | been done when this function is called. | - | ||||||||||||||||||
4281 | */ | - | ||||||||||||||||||
4282 | - | |||||||||||||||||||
4283 | void QGLWidget::initializeGL() | - | ||||||||||||||||||
4284 | { | - | ||||||||||||||||||
4285 | } | - | ||||||||||||||||||
4286 | - | |||||||||||||||||||
4287 | - | |||||||||||||||||||
4288 | /*! | - | ||||||||||||||||||
4289 | This virtual function is called whenever the widget needs to be | - | ||||||||||||||||||
4290 | painted. Reimplement it in a subclass. | - | ||||||||||||||||||
4291 | - | |||||||||||||||||||
4292 | There is no need to call makeCurrent() because this has already | - | ||||||||||||||||||
4293 | been done when this function is called. | - | ||||||||||||||||||
4294 | */ | - | ||||||||||||||||||
4295 | - | |||||||||||||||||||
4296 | void QGLWidget::paintGL() | - | ||||||||||||||||||
4297 | { | - | ||||||||||||||||||
4298 | qgl_functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | - | ||||||||||||||||||
4299 | } never executed: end of block | 0 | ||||||||||||||||||
4300 | - | |||||||||||||||||||
4301 | - | |||||||||||||||||||
4302 | /*! | - | ||||||||||||||||||
4303 | \fn void QGLWidget::resizeGL(int width , int height) | - | ||||||||||||||||||
4304 | - | |||||||||||||||||||
4305 | This virtual function is called whenever the widget has been | - | ||||||||||||||||||
4306 | resized. The new size is passed in \a width and \a height. | - | ||||||||||||||||||
4307 | Reimplement it in a subclass. | - | ||||||||||||||||||
4308 | - | |||||||||||||||||||
4309 | There is no need to call makeCurrent() because this has already | - | ||||||||||||||||||
4310 | been done when this function is called. | - | ||||||||||||||||||
4311 | */ | - | ||||||||||||||||||
4312 | - | |||||||||||||||||||
4313 | void QGLWidget::resizeGL(int, int) | - | ||||||||||||||||||
4314 | { | - | ||||||||||||||||||
4315 | } | - | ||||||||||||||||||
4316 | - | |||||||||||||||||||
4317 | - | |||||||||||||||||||
4318 | - | |||||||||||||||||||
4319 | /*! | - | ||||||||||||||||||
4320 | This virtual function is used in the same manner as initializeGL() | - | ||||||||||||||||||
4321 | except that it operates on the widget's overlay context instead of | - | ||||||||||||||||||
4322 | the widget's main context. This means that initializeOverlayGL() | - | ||||||||||||||||||
4323 | is called once before the first call to paintOverlayGL() or | - | ||||||||||||||||||
4324 | resizeOverlayGL(). Reimplement it in a subclass. | - | ||||||||||||||||||
4325 | - | |||||||||||||||||||
4326 | This function should set up any required OpenGL context rendering | - | ||||||||||||||||||
4327 | flags, defining display lists, etc. for the overlay context. | - | ||||||||||||||||||
4328 | - | |||||||||||||||||||
4329 | There is no need to call makeOverlayCurrent() because this has | - | ||||||||||||||||||
4330 | already been done when this function is called. | - | ||||||||||||||||||
4331 | */ | - | ||||||||||||||||||
4332 | - | |||||||||||||||||||
4333 | void QGLWidget::initializeOverlayGL() | - | ||||||||||||||||||
4334 | { | - | ||||||||||||||||||
4335 | } | - | ||||||||||||||||||
4336 | - | |||||||||||||||||||
4337 | - | |||||||||||||||||||
4338 | /*! | - | ||||||||||||||||||
4339 | This virtual function is used in the same manner as paintGL() | - | ||||||||||||||||||
4340 | except that it operates on the widget's overlay context instead of | - | ||||||||||||||||||
4341 | the widget's main context. This means that paintOverlayGL() is | - | ||||||||||||||||||
4342 | called whenever the widget's overlay needs to be painted. | - | ||||||||||||||||||
4343 | Reimplement it in a subclass. | - | ||||||||||||||||||
4344 | - | |||||||||||||||||||
4345 | There is no need to call makeOverlayCurrent() because this has | - | ||||||||||||||||||
4346 | already been done when this function is called. | - | ||||||||||||||||||
4347 | */ | - | ||||||||||||||||||
4348 | - | |||||||||||||||||||
4349 | void QGLWidget::paintOverlayGL() | - | ||||||||||||||||||
4350 | { | - | ||||||||||||||||||
4351 | } | - | ||||||||||||||||||
4352 | - | |||||||||||||||||||
4353 | - | |||||||||||||||||||
4354 | /*! | - | ||||||||||||||||||
4355 | \fn void QGLWidget::resizeOverlayGL(int width , int height) | - | ||||||||||||||||||
4356 | - | |||||||||||||||||||
4357 | This virtual function is used in the same manner as paintGL() | - | ||||||||||||||||||
4358 | except that it operates on the widget's overlay context instead of | - | ||||||||||||||||||
4359 | the widget's main context. This means that resizeOverlayGL() is | - | ||||||||||||||||||
4360 | called whenever the widget has been resized. The new size is | - | ||||||||||||||||||
4361 | passed in \a width and \a height. Reimplement it in a subclass. | - | ||||||||||||||||||
4362 | - | |||||||||||||||||||
4363 | There is no need to call makeOverlayCurrent() because this has | - | ||||||||||||||||||
4364 | already been done when this function is called. | - | ||||||||||||||||||
4365 | */ | - | ||||||||||||||||||
4366 | - | |||||||||||||||||||
4367 | void QGLWidget::resizeOverlayGL(int, int) | - | ||||||||||||||||||
4368 | { | - | ||||||||||||||||||
4369 | } | - | ||||||||||||||||||
4370 | - | |||||||||||||||||||
4371 | /*!\reimp | - | ||||||||||||||||||
4372 | */ | - | ||||||||||||||||||
4373 | bool QGLWidget::event(QEvent *e) | - | ||||||||||||||||||
4374 | { | - | ||||||||||||||||||
4375 | Q_D(QGLWidget); | - | ||||||||||||||||||
4376 | - | |||||||||||||||||||
4377 | // A re-parent will destroy the window and re-create it. We should not reset the context while it happens. | - | ||||||||||||||||||
4378 | if (e->type() == QEvent::ParentAboutToChange)
| 0-29 | ||||||||||||||||||
4379 | d->parent_changing = true; never executed: d->parent_changing = true; | 0 | ||||||||||||||||||
4380 | - | |||||||||||||||||||
4381 | if (e->type() == QEvent::ParentChange)
| 1-28 | ||||||||||||||||||
4382 | d->parent_changing = false; executed 1 time by 1 test: d->parent_changing = false; Executed by:
| 1 | ||||||||||||||||||
4383 | - | |||||||||||||||||||
4384 | return QWidget::event(e); executed 29 times by 3 tests: return QWidget::event(e); Executed by:
| 29 | ||||||||||||||||||
4385 | } | - | ||||||||||||||||||
4386 | - | |||||||||||||||||||
4387 | /*! | - | ||||||||||||||||||
4388 | \fn void QGLWidget::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||
4389 | - | |||||||||||||||||||
4390 | Handles paint events passed in the \a event parameter. Will cause | - | ||||||||||||||||||
4391 | the virtual paintGL() function to be called. | - | ||||||||||||||||||
4392 | - | |||||||||||||||||||
4393 | The widget's rendering context will become the current context and | - | ||||||||||||||||||
4394 | initializeGL() will be called if it hasn't already been called. | - | ||||||||||||||||||
4395 | */ | - | ||||||||||||||||||
4396 | - | |||||||||||||||||||
4397 | void QGLWidget::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
4398 | { | - | ||||||||||||||||||
4399 | if (updatesEnabled()) {
| 0 | ||||||||||||||||||
4400 | glDraw(); | - | ||||||||||||||||||
4401 | updateOverlayGL(); | - | ||||||||||||||||||
4402 | } never executed: end of block | 0 | ||||||||||||||||||
4403 | } never executed: end of block | 0 | ||||||||||||||||||
4404 | - | |||||||||||||||||||
4405 | - | |||||||||||||||||||
4406 | /*! | - | ||||||||||||||||||
4407 | \fn void QGLWidget::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||
4408 | - | |||||||||||||||||||
4409 | Handles resize events that are passed in the \a event parameter. | - | ||||||||||||||||||
4410 | Calls the virtual function resizeGL(). | - | ||||||||||||||||||
4411 | */ | - | ||||||||||||||||||
4412 | void QGLWidget::resizeEvent(QResizeEvent *e) | - | ||||||||||||||||||
4413 | { | - | ||||||||||||||||||
4414 | Q_D(QGLWidget); | - | ||||||||||||||||||
4415 | - | |||||||||||||||||||
4416 | QWidget::resizeEvent(e); | - | ||||||||||||||||||
4417 | if (!isValid())
| 0 | ||||||||||||||||||
4418 | return; never executed: return; | 0 | ||||||||||||||||||
4419 | makeCurrent(); | - | ||||||||||||||||||
4420 | if (!d->glcx->initialized())
| 0 | ||||||||||||||||||
4421 | glInit(); never executed: glInit(); | 0 | ||||||||||||||||||
4422 | const qreal scaleFactor = (window() && window()->windowHandle()) ?
| 0 | ||||||||||||||||||
4423 | window()->windowHandle()->devicePixelRatio() : 1.0; | - | ||||||||||||||||||
4424 | - | |||||||||||||||||||
4425 | resizeGL(width() * scaleFactor, height() * scaleFactor); | - | ||||||||||||||||||
4426 | } never executed: end of block | 0 | ||||||||||||||||||
4427 | - | |||||||||||||||||||
4428 | /*! | - | ||||||||||||||||||
4429 | Renders the current scene on a pixmap and returns the pixmap. | - | ||||||||||||||||||
4430 | - | |||||||||||||||||||
4431 | You can use this method on both visible and invisible QGLWidget objects. | - | ||||||||||||||||||
4432 | - | |||||||||||||||||||
4433 | Internally the function renders into a framebuffer object and performs pixel | - | ||||||||||||||||||
4434 | readback. This has a performance penalty, meaning that this function is not | - | ||||||||||||||||||
4435 | suitable to be called at a high frequency. | - | ||||||||||||||||||
4436 | - | |||||||||||||||||||
4437 | After creating and binding the framebuffer object, the function will call | - | ||||||||||||||||||
4438 | initializeGL(), resizeGL(), and paintGL(). On the next normal update | - | ||||||||||||||||||
4439 | initializeGL() and resizeGL() will be triggered again since the size of the | - | ||||||||||||||||||
4440 | destination pixmap and the QGLWidget's size may differ. | - | ||||||||||||||||||
4441 | - | |||||||||||||||||||
4442 | The size of the pixmap will be \a w pixels wide and \a h pixels high unless | - | ||||||||||||||||||
4443 | one of these parameters is 0 (the default), in which case the pixmap will | - | ||||||||||||||||||
4444 | have the same size as the widget. | - | ||||||||||||||||||
4445 | - | |||||||||||||||||||
4446 | Care must be taken when using framebuffer objects in paintGL() in | - | ||||||||||||||||||
4447 | combination with this function. To switch back to the default framebuffer, | - | ||||||||||||||||||
4448 | use QGLFramebufferObject::bindDefault(). Binding FBO 0 is wrong since | - | ||||||||||||||||||
4449 | renderPixmap() uses a custom framebuffer instead of the one provided by the | - | ||||||||||||||||||
4450 | windowing system. | - | ||||||||||||||||||
4451 | - | |||||||||||||||||||
4452 | \a useContext is ignored. Historically this parameter enabled the usage of | - | ||||||||||||||||||
4453 | the existing GL context. This is not supported anymore since additional | - | ||||||||||||||||||
4454 | contexts are never created. | - | ||||||||||||||||||
4455 | - | |||||||||||||||||||
4456 | Overlays are not rendered onto the pixmap. | - | ||||||||||||||||||
4457 | - | |||||||||||||||||||
4458 | If the GL rendering context and the desktop have different bit | - | ||||||||||||||||||
4459 | depths, the result will most likely look surprising. | - | ||||||||||||||||||
4460 | - | |||||||||||||||||||
4461 | Note that the creation of display lists, modifications of the view | - | ||||||||||||||||||
4462 | frustum etc. should be done from within initializeGL(). If this is | - | ||||||||||||||||||
4463 | not done, the temporary QGLContext will not be initialized | - | ||||||||||||||||||
4464 | properly, and the rendered pixmap may be incomplete/corrupted. | - | ||||||||||||||||||
4465 | */ | - | ||||||||||||||||||
4466 | - | |||||||||||||||||||
4467 | QPixmap QGLWidget::renderPixmap(int w, int h, bool useContext) | - | ||||||||||||||||||
4468 | { | - | ||||||||||||||||||
4469 | Q_UNUSED(useContext); | - | ||||||||||||||||||
4470 | Q_D(QGLWidget); | - | ||||||||||||||||||
4471 | - | |||||||||||||||||||
4472 | QSize sz = size(); | - | ||||||||||||||||||
4473 | if ((w > 0) && (h > 0))
| 0 | ||||||||||||||||||
4474 | sz = QSize(w, h); never executed: sz = QSize(w, h); | 0 | ||||||||||||||||||
4475 | - | |||||||||||||||||||
4476 | QPixmap pm; | - | ||||||||||||||||||
4477 | if (d->glcx->isValid()) {
| 0 | ||||||||||||||||||
4478 | d->glcx->makeCurrent(); | - | ||||||||||||||||||
4479 | QGLFramebufferObject fbo(sz, QGLFramebufferObject::CombinedDepthStencil); | - | ||||||||||||||||||
4480 | fbo.bind(); | - | ||||||||||||||||||
4481 | d->glcx->setInitialized(false); | - | ||||||||||||||||||
4482 | uint prevDefaultFbo = d->glcx->d_ptr->default_fbo; | - | ||||||||||||||||||
4483 | d->glcx->d_ptr->default_fbo = fbo.handle(); | - | ||||||||||||||||||
4484 | d->glcx->d_ptr->readback_target_size = sz; | - | ||||||||||||||||||
4485 | updateGL(); | - | ||||||||||||||||||
4486 | fbo.release(); | - | ||||||||||||||||||
4487 | pm = QPixmap::fromImage(fbo.toImage()); | - | ||||||||||||||||||
4488 | d->glcx->d_ptr->default_fbo = prevDefaultFbo; | - | ||||||||||||||||||
4489 | d->glcx->setInitialized(false); | - | ||||||||||||||||||
4490 | d->glcx->d_ptr->readback_target_size = QSize(); | - | ||||||||||||||||||
4491 | } never executed: end of block | 0 | ||||||||||||||||||
4492 | - | |||||||||||||||||||
4493 | return pm; never executed: return pm; | 0 | ||||||||||||||||||
4494 | } | - | ||||||||||||||||||
4495 | - | |||||||||||||||||||
4496 | /*! | - | ||||||||||||||||||
4497 | Returns an image of the frame buffer. If \a withAlpha is true the | - | ||||||||||||||||||
4498 | alpha channel is included. | - | ||||||||||||||||||
4499 | - | |||||||||||||||||||
4500 | Depending on your hardware, you can explicitly select which color | - | ||||||||||||||||||
4501 | buffer to grab with a glReadBuffer() call before calling this | - | ||||||||||||||||||
4502 | function. | - | ||||||||||||||||||
4503 | - | |||||||||||||||||||
4504 | On QNX the back buffer is not preserved when swapBuffers() is called. The back buffer | - | ||||||||||||||||||
4505 | where this function reads from, might thus not contain the same content as the front buffer. | - | ||||||||||||||||||
4506 | In order to retrieve what is currently visible on the screen, swapBuffers() | - | ||||||||||||||||||
4507 | has to be executed prior to this function call. | - | ||||||||||||||||||
4508 | */ | - | ||||||||||||||||||
4509 | QImage QGLWidget::grabFrameBuffer(bool withAlpha) | - | ||||||||||||||||||
4510 | { | - | ||||||||||||||||||
4511 | makeCurrent(); | - | ||||||||||||||||||
4512 | QImage res; | - | ||||||||||||||||||
4513 | qreal pixelRatio = devicePixelRatioF(); | - | ||||||||||||||||||
4514 | int w = pixelRatio * width(); | - | ||||||||||||||||||
4515 | int h = pixelRatio * height(); | - | ||||||||||||||||||
4516 | if (format().rgba())
| 0 | ||||||||||||||||||
4517 | res = qt_gl_read_frame_buffer(QSize(w, h), format().alpha(), withAlpha); never executed: res = qt_gl_read_frame_buffer(QSize(w, h), format().alpha(), withAlpha); | 0 | ||||||||||||||||||
4518 | res.setDevicePixelRatio(pixelRatio); | - | ||||||||||||||||||
4519 | return res; never executed: return res; | 0 | ||||||||||||||||||
4520 | } | - | ||||||||||||||||||
4521 | - | |||||||||||||||||||
4522 | - | |||||||||||||||||||
4523 | - | |||||||||||||||||||
4524 | /*! | - | ||||||||||||||||||
4525 | Initializes OpenGL for this widget's context. Calls the virtual | - | ||||||||||||||||||
4526 | function initializeGL(). | - | ||||||||||||||||||
4527 | */ | - | ||||||||||||||||||
4528 | - | |||||||||||||||||||
4529 | void QGLWidget::glInit() | - | ||||||||||||||||||
4530 | { | - | ||||||||||||||||||
4531 | Q_D(QGLWidget); | - | ||||||||||||||||||
4532 | if (!isValid())
| 0 | ||||||||||||||||||
4533 | return; never executed: return; | 0 | ||||||||||||||||||
4534 | makeCurrent(); | - | ||||||||||||||||||
4535 | initializeGL(); | - | ||||||||||||||||||
4536 | d->glcx->setInitialized(true); | - | ||||||||||||||||||
4537 | } never executed: end of block | 0 | ||||||||||||||||||
4538 | - | |||||||||||||||||||
4539 | - | |||||||||||||||||||
4540 | /*! | - | ||||||||||||||||||
4541 | Executes the virtual function paintGL(). | - | ||||||||||||||||||
4542 | - | |||||||||||||||||||
4543 | The widget's rendering context will become the current context and | - | ||||||||||||||||||
4544 | initializeGL() will be called if it hasn't already been called. | - | ||||||||||||||||||
4545 | */ | - | ||||||||||||||||||
4546 | - | |||||||||||||||||||
4547 | void QGLWidget::glDraw() | - | ||||||||||||||||||
4548 | { | - | ||||||||||||||||||
4549 | Q_D(QGLWidget); | - | ||||||||||||||||||
4550 | if (!isValid())
| 0 | ||||||||||||||||||
4551 | return; never executed: return; | 0 | ||||||||||||||||||
4552 | makeCurrent(); | - | ||||||||||||||||||
4553 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
4554 | if (d->glcx->deviceIsPixmap() && !d->glcx->contextHandle()->isOpenGLES())
| 0 | ||||||||||||||||||
4555 | qgl1_functions()->glDrawBuffer(GL_FRONT); never executed: qgl1_functions()->glDrawBuffer(0x0404); | 0 | ||||||||||||||||||
4556 | #endif | - | ||||||||||||||||||
4557 | QSize readback_target_size = d->glcx->d_ptr->readback_target_size; | - | ||||||||||||||||||
4558 | if (!d->glcx->initialized()) {
| 0 | ||||||||||||||||||
4559 | glInit(); | - | ||||||||||||||||||
4560 | const qreal scaleFactor = (window() && window()->windowHandle()) ?
| 0 | ||||||||||||||||||
4561 | window()->windowHandle()->devicePixelRatio() : 1.0; | - | ||||||||||||||||||
4562 | int w, h; | - | ||||||||||||||||||
4563 | if (readback_target_size.isEmpty()) {
| 0 | ||||||||||||||||||
4564 | w = d->glcx->device()->width() * scaleFactor; | - | ||||||||||||||||||
4565 | h = d->glcx->device()->height() * scaleFactor; | - | ||||||||||||||||||
4566 | } else { never executed: end of block | 0 | ||||||||||||||||||
4567 | w = readback_target_size.width(); | - | ||||||||||||||||||
4568 | h = readback_target_size.height(); | - | ||||||||||||||||||
4569 | } never executed: end of block | 0 | ||||||||||||||||||
4570 | resizeGL(w, h); // New context needs this "resize" | - | ||||||||||||||||||
4571 | } never executed: end of block | 0 | ||||||||||||||||||
4572 | paintGL(); | - | ||||||||||||||||||
4573 | if (doubleBuffer() && readback_target_size.isEmpty()) {
| 0 | ||||||||||||||||||
4574 | if (d->autoSwap)
| 0 | ||||||||||||||||||
4575 | swapBuffers(); never executed: swapBuffers(); | 0 | ||||||||||||||||||
4576 | } else { never executed: end of block | 0 | ||||||||||||||||||
4577 | qgl_functions()->glFlush(); | - | ||||||||||||||||||
4578 | } never executed: end of block | 0 | ||||||||||||||||||
4579 | } | - | ||||||||||||||||||
4580 | - | |||||||||||||||||||
4581 | /*! | - | ||||||||||||||||||
4582 | Convenience function for specifying a drawing color to OpenGL. | - | ||||||||||||||||||
4583 | Calls glColor4 (in RGBA mode) or glIndex (in color-index mode) | - | ||||||||||||||||||
4584 | with the color \a c. Applies to this widgets GL context. | - | ||||||||||||||||||
4585 | - | |||||||||||||||||||
4586 | \note This function is not supported on OpenGL/ES 2.0 systems. | - | ||||||||||||||||||
4587 | - | |||||||||||||||||||
4588 | \sa qglClearColor(), QGLContext::currentContext(), QColor | - | ||||||||||||||||||
4589 | */ | - | ||||||||||||||||||
4590 | - | |||||||||||||||||||
4591 | void QGLWidget::qglColor(const QColor& c) const | - | ||||||||||||||||||
4592 | { | - | ||||||||||||||||||
4593 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
4594 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
4595 | qgl_functions()->glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||
4596 | #else | - | ||||||||||||||||||
4597 | Q_D(const QGLWidget); | - | ||||||||||||||||||
4598 | const QGLContext *ctx = QGLContext::currentContext(); | - | ||||||||||||||||||
4599 | if (ctx && !ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
4600 | if (ctx->format().rgba())
| 0 | ||||||||||||||||||
4601 | qgl1_functions()->glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); never executed: qgl1_functions()->glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | 0 | ||||||||||||||||||
4602 | else if (!d->cmap.isEmpty()) { // QGLColormap in use?
| 0 | ||||||||||||||||||
4603 | int i = d->cmap.find(c.rgb()); | - | ||||||||||||||||||
4604 | if (i < 0)
| 0 | ||||||||||||||||||
4605 | i = d->cmap.findNearest(c.rgb()); never executed: i = d->cmap.findNearest(c.rgb()); | 0 | ||||||||||||||||||
4606 | qgl1_functions()->glIndexi(i); | - | ||||||||||||||||||
4607 | } else never executed: end of block | 0 | ||||||||||||||||||
4608 | qgl1_functions()->glIndexi(ctx->colorIndex(c)); never executed: qgl1_functions()->glIndexi(ctx->colorIndex(c)); | 0 | ||||||||||||||||||
4609 | } | - | ||||||||||||||||||
4610 | #endif //QT_OPENGL_ES | - | ||||||||||||||||||
4611 | #else | - | ||||||||||||||||||
4612 | Q_UNUSED(c); | - | ||||||||||||||||||
4613 | #endif //QT_OPENGL_ES_2 | - | ||||||||||||||||||
4614 | } never executed: end of block | 0 | ||||||||||||||||||
4615 | - | |||||||||||||||||||
4616 | /*! | - | ||||||||||||||||||
4617 | Convenience function for specifying the clearing color to OpenGL. | - | ||||||||||||||||||
4618 | Calls glClearColor (in RGBA mode) or glClearIndex (in color-index | - | ||||||||||||||||||
4619 | mode) with the color \a c. Applies to this widgets GL context. | - | ||||||||||||||||||
4620 | - | |||||||||||||||||||
4621 | \sa qglColor(), QGLContext::currentContext(), QColor | - | ||||||||||||||||||
4622 | */ | - | ||||||||||||||||||
4623 | - | |||||||||||||||||||
4624 | void QGLWidget::qglClearColor(const QColor& c) const | - | ||||||||||||||||||
4625 | { | - | ||||||||||||||||||
4626 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
4627 | qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||
4628 | #else | - | ||||||||||||||||||
4629 | Q_D(const QGLWidget); | - | ||||||||||||||||||
4630 | const QGLContext *ctx = QGLContext::currentContext(); | - | ||||||||||||||||||
4631 | if (ctx && !ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
4632 | if (ctx->format().rgba())
| 0 | ||||||||||||||||||
4633 | qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); never executed: qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | 0 | ||||||||||||||||||
4634 | else if (!d->cmap.isEmpty()) { // QGLColormap in use?
| 0 | ||||||||||||||||||
4635 | int i = d->cmap.find(c.rgb()); | - | ||||||||||||||||||
4636 | if (i < 0)
| 0 | ||||||||||||||||||
4637 | i = d->cmap.findNearest(c.rgb()); never executed: i = d->cmap.findNearest(c.rgb()); | 0 | ||||||||||||||||||
4638 | qgl1_functions()->glClearIndex(i); | - | ||||||||||||||||||
4639 | } else { never executed: end of block | 0 | ||||||||||||||||||
4640 | qgl1_functions()->glClearIndex(ctx->colorIndex(c)); | - | ||||||||||||||||||
4641 | } never executed: end of block | 0 | ||||||||||||||||||
4642 | } else { | - | ||||||||||||||||||
4643 | qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||
4644 | } never executed: end of block | 0 | ||||||||||||||||||
4645 | #endif | - | ||||||||||||||||||
4646 | } | - | ||||||||||||||||||
4647 | - | |||||||||||||||||||
4648 | - | |||||||||||||||||||
4649 | /*! | - | ||||||||||||||||||
4650 | Converts the image \a img into the unnamed format expected by | - | ||||||||||||||||||
4651 | OpenGL functions such as glTexImage2D(). The returned image is not | - | ||||||||||||||||||
4652 | usable as a QImage, but QImage::width(), QImage::height() and | - | ||||||||||||||||||
4653 | QImage::bits() may be used with OpenGL. The GL format used is | - | ||||||||||||||||||
4654 | \c GL_RGBA. | - | ||||||||||||||||||
4655 | - | |||||||||||||||||||
4656 | \omit ### | - | ||||||||||||||||||
4657 | - | |||||||||||||||||||
4658 | \l opengl/texture example | - | ||||||||||||||||||
4659 | The following few lines are from the texture example. Most of the | - | ||||||||||||||||||
4660 | code is irrelevant, so we just quote the relevant bits: | - | ||||||||||||||||||
4661 | - | |||||||||||||||||||
4662 | \quotefromfile opengl/texture/gltexobj.cpp | - | ||||||||||||||||||
4663 | \skipto tex1 | - | ||||||||||||||||||
4664 | \printline tex1 | - | ||||||||||||||||||
4665 | \printline gllogo.bmp | - | ||||||||||||||||||
4666 | - | |||||||||||||||||||
4667 | We create \e tex1 (and another variable) for OpenGL, and load a real | - | ||||||||||||||||||
4668 | image into \e buf. | - | ||||||||||||||||||
4669 | - | |||||||||||||||||||
4670 | \skipto convertToGLFormat | - | ||||||||||||||||||
4671 | \printline convertToGLFormat | - | ||||||||||||||||||
4672 | - | |||||||||||||||||||
4673 | A few lines later, we convert \e buf into OpenGL format and store it | - | ||||||||||||||||||
4674 | in \e tex1. | - | ||||||||||||||||||
4675 | - | |||||||||||||||||||
4676 | \skipto glTexImage2D | - | ||||||||||||||||||
4677 | \printline glTexImage2D | - | ||||||||||||||||||
4678 | \printline tex1.bits | - | ||||||||||||||||||
4679 | - | |||||||||||||||||||
4680 | Note the dimension restrictions for texture images as described in | - | ||||||||||||||||||
4681 | the glTexImage2D() documentation. The width must be 2^m + 2*border | - | ||||||||||||||||||
4682 | and the height 2^n + 2*border where m and n are integers and | - | ||||||||||||||||||
4683 | border is either 0 or 1. | - | ||||||||||||||||||
4684 | - | |||||||||||||||||||
4685 | Another function in the same example uses \e tex1 with OpenGL. | - | ||||||||||||||||||
4686 | - | |||||||||||||||||||
4687 | \endomit | - | ||||||||||||||||||
4688 | */ | - | ||||||||||||||||||
4689 | - | |||||||||||||||||||
4690 | QImage QGLWidget::convertToGLFormat(const QImage& img) | - | ||||||||||||||||||
4691 | { | - | ||||||||||||||||||
4692 | QImage res(img.size(), QImage::Format_ARGB32); | - | ||||||||||||||||||
4693 | convertToGLFormatHelper(res, img.convertToFormat(QImage::Format_ARGB32), GL_RGBA); | - | ||||||||||||||||||
4694 | return res; never executed: return res; | 0 | ||||||||||||||||||
4695 | } | - | ||||||||||||||||||
4696 | - | |||||||||||||||||||
4697 | - | |||||||||||||||||||
4698 | /*! | - | ||||||||||||||||||
4699 | \fn QGLColormap & QGLWidget::colormap() const | - | ||||||||||||||||||
4700 | - | |||||||||||||||||||
4701 | Returns the colormap for this widget. | - | ||||||||||||||||||
4702 | - | |||||||||||||||||||
4703 | Usually it is only top-level widgets that can have different | - | ||||||||||||||||||
4704 | colormaps installed. Asking for the colormap of a child widget | - | ||||||||||||||||||
4705 | will return the colormap for the child's top-level widget. | - | ||||||||||||||||||
4706 | - | |||||||||||||||||||
4707 | If no colormap has been set for this widget, the QGLColormap | - | ||||||||||||||||||
4708 | returned will be empty. | - | ||||||||||||||||||
4709 | - | |||||||||||||||||||
4710 | \sa setColormap(), QGLColormap::isEmpty() | - | ||||||||||||||||||
4711 | */ | - | ||||||||||||||||||
4712 | const QGLColormap & QGLWidget::colormap() const | - | ||||||||||||||||||
4713 | { | - | ||||||||||||||||||
4714 | Q_D(const QGLWidget); | - | ||||||||||||||||||
4715 | return d->cmap; never executed: return d->cmap; | 0 | ||||||||||||||||||
4716 | } | - | ||||||||||||||||||
4717 | - | |||||||||||||||||||
4718 | /*! | - | ||||||||||||||||||
4719 | \fn void QGLWidget::setColormap(const QGLColormap & cmap) | - | ||||||||||||||||||
4720 | - | |||||||||||||||||||
4721 | Set the colormap for this widget to \a cmap. Usually it is only | - | ||||||||||||||||||
4722 | top-level widgets that can have colormaps installed. | - | ||||||||||||||||||
4723 | - | |||||||||||||||||||
4724 | \sa colormap() | - | ||||||||||||||||||
4725 | */ | - | ||||||||||||||||||
4726 | void QGLWidget::setColormap(const QGLColormap & c) | - | ||||||||||||||||||
4727 | { | - | ||||||||||||||||||
4728 | Q_UNUSED(c); | - | ||||||||||||||||||
4729 | } never executed: end of block | 0 | ||||||||||||||||||
4730 | - | |||||||||||||||||||
4731 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
4732 | - | |||||||||||||||||||
4733 | static void qt_save_gl_state() | - | ||||||||||||||||||
4734 | { | - | ||||||||||||||||||
4735 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
4736 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
4737 | - | |||||||||||||||||||
4738 | gl1funcs->glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); | - | ||||||||||||||||||
4739 | gl1funcs->glPushAttrib(GL_ALL_ATTRIB_BITS); | - | ||||||||||||||||||
4740 | gl1funcs->glMatrixMode(GL_TEXTURE); | - | ||||||||||||||||||
4741 | gl1funcs->glPushMatrix(); | - | ||||||||||||||||||
4742 | gl1funcs->glLoadIdentity(); | - | ||||||||||||||||||
4743 | gl1funcs->glMatrixMode(GL_PROJECTION); | - | ||||||||||||||||||
4744 | gl1funcs->glPushMatrix(); | - | ||||||||||||||||||
4745 | gl1funcs->glMatrixMode(GL_MODELVIEW); | - | ||||||||||||||||||
4746 | gl1funcs->glPushMatrix(); | - | ||||||||||||||||||
4747 | - | |||||||||||||||||||
4748 | gl1funcs->glShadeModel(GL_FLAT); | - | ||||||||||||||||||
4749 | funcs->glDisable(GL_CULL_FACE); | - | ||||||||||||||||||
4750 | funcs->glDisable(GL_LIGHTING); | - | ||||||||||||||||||
4751 | funcs->glDisable(GL_STENCIL_TEST); | - | ||||||||||||||||||
4752 | funcs->glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||
4753 | funcs->glEnable(GL_BLEND); | - | ||||||||||||||||||
4754 | funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||
4755 | } never executed: end of block | 0 | ||||||||||||||||||
4756 | - | |||||||||||||||||||
4757 | static void qt_restore_gl_state() | - | ||||||||||||||||||
4758 | { | - | ||||||||||||||||||
4759 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
4760 | - | |||||||||||||||||||
4761 | gl1funcs->glMatrixMode(GL_TEXTURE); | - | ||||||||||||||||||
4762 | gl1funcs->glPopMatrix(); | - | ||||||||||||||||||
4763 | gl1funcs->glMatrixMode(GL_PROJECTION); | - | ||||||||||||||||||
4764 | gl1funcs->glPopMatrix(); | - | ||||||||||||||||||
4765 | gl1funcs->glMatrixMode(GL_MODELVIEW); | - | ||||||||||||||||||
4766 | gl1funcs->glPopMatrix(); | - | ||||||||||||||||||
4767 | gl1funcs->glPopAttrib(); | - | ||||||||||||||||||
4768 | gl1funcs->glPopClientAttrib(); | - | ||||||||||||||||||
4769 | } never executed: end of block | 0 | ||||||||||||||||||
4770 | - | |||||||||||||||||||
4771 | static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, | - | ||||||||||||||||||
4772 | const QFont &font) | - | ||||||||||||||||||
4773 | { | - | ||||||||||||||||||
4774 | GLfloat color[4]; | - | ||||||||||||||||||
4775 | qgl_functions()->glGetFloatv(GL_CURRENT_COLOR, &color[0]); | - | ||||||||||||||||||
4776 | - | |||||||||||||||||||
4777 | QColor col; | - | ||||||||||||||||||
4778 | col.setRgbF(color[0], color[1], color[2],color[3]); | - | ||||||||||||||||||
4779 | QPen old_pen = p->pen(); | - | ||||||||||||||||||
4780 | QFont old_font = p->font(); | - | ||||||||||||||||||
4781 | - | |||||||||||||||||||
4782 | p->setPen(col); | - | ||||||||||||||||||
4783 | p->setFont(font); | - | ||||||||||||||||||
4784 | p->drawText(x, y, str); | - | ||||||||||||||||||
4785 | - | |||||||||||||||||||
4786 | p->setPen(old_pen); | - | ||||||||||||||||||
4787 | p->setFont(old_font); | - | ||||||||||||||||||
4788 | } never executed: end of block | 0 | ||||||||||||||||||
4789 | - | |||||||||||||||||||
4790 | #endif // !QT_OPENGL_ES | - | ||||||||||||||||||
4791 | - | |||||||||||||||||||
4792 | /*! | - | ||||||||||||||||||
4793 | Renders the string \a str into the GL context of this widget. | - | ||||||||||||||||||
4794 | - | |||||||||||||||||||
4795 | \a x and \a y are specified in window coordinates, with the origin | - | ||||||||||||||||||
4796 | in the upper left-hand corner of the window. If \a font is not | - | ||||||||||||||||||
4797 | specified, the currently set application font will be used to | - | ||||||||||||||||||
4798 | render the string. To change the color of the rendered text you can | - | ||||||||||||||||||
4799 | use the glColor() call (or the qglColor() convenience function), | - | ||||||||||||||||||
4800 | just before the renderText() call. | - | ||||||||||||||||||
4801 | - | |||||||||||||||||||
4802 | \note This function clears the stencil buffer. | - | ||||||||||||||||||
4803 | - | |||||||||||||||||||
4804 | \note This function is not supported on OpenGL/ES systems. | - | ||||||||||||||||||
4805 | - | |||||||||||||||||||
4806 | \note This function temporarily disables depth-testing when the | - | ||||||||||||||||||
4807 | text is drawn. | - | ||||||||||||||||||
4808 | - | |||||||||||||||||||
4809 | \note This function can only be used inside a | - | ||||||||||||||||||
4810 | QPainter::beginNativePainting()/QPainter::endNativePainting() block | - | ||||||||||||||||||
4811 | if a painter is active on the QGLWidget. | - | ||||||||||||||||||
4812 | */ | - | ||||||||||||||||||
4813 | - | |||||||||||||||||||
4814 | void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font) | - | ||||||||||||||||||
4815 | { | - | ||||||||||||||||||
4816 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
4817 | Q_D(QGLWidget); | - | ||||||||||||||||||
4818 | if (!d->glcx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
4819 | Q_D(QGLWidget); | - | ||||||||||||||||||
4820 | if (str.isEmpty() || !isValid())
| 0 | ||||||||||||||||||
4821 | return; never executed: return; | 0 | ||||||||||||||||||
4822 | - | |||||||||||||||||||
4823 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
4824 | GLint view[4]; | - | ||||||||||||||||||
4825 | bool use_scissor_testing = funcs->glIsEnabled(GL_SCISSOR_TEST); | - | ||||||||||||||||||
4826 | if (!use_scissor_testing)
| 0 | ||||||||||||||||||
4827 | funcs->glGetIntegerv(GL_VIEWPORT, &view[0]); never executed: funcs->glGetIntegerv(0x0BA2, &view[0]); | 0 | ||||||||||||||||||
4828 | int width = d->glcx->device()->width(); | - | ||||||||||||||||||
4829 | int height = d->glcx->device()->height(); | - | ||||||||||||||||||
4830 | bool auto_swap = autoBufferSwap(); | - | ||||||||||||||||||
4831 | - | |||||||||||||||||||
4832 | QPaintEngine *engine = paintEngine(); | - | ||||||||||||||||||
4833 | - | |||||||||||||||||||
4834 | qt_save_gl_state(); | - | ||||||||||||||||||
4835 | - | |||||||||||||||||||
4836 | QPainter *p; | - | ||||||||||||||||||
4837 | bool reuse_painter = false; | - | ||||||||||||||||||
4838 | if (engine->isActive()) {
| 0 | ||||||||||||||||||
4839 | reuse_painter = true; | - | ||||||||||||||||||
4840 | p = engine->painter(); | - | ||||||||||||||||||
4841 | - | |||||||||||||||||||
4842 | funcs->glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||
4843 | funcs->glViewport(0, 0, width, height); | - | ||||||||||||||||||
4844 | } else { never executed: end of block | 0 | ||||||||||||||||||
4845 | setAutoBufferSwap(false); | - | ||||||||||||||||||
4846 | // disable glClear() as a result of QPainter::begin() | - | ||||||||||||||||||
4847 | d->disable_clear_on_painter_begin = true; | - | ||||||||||||||||||
4848 | p = new QPainter(this); | - | ||||||||||||||||||
4849 | } never executed: end of block | 0 | ||||||||||||||||||
4850 | - | |||||||||||||||||||
4851 | QRect viewport(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
4852 | if (!use_scissor_testing && viewport != rect()) {
| 0 | ||||||||||||||||||
4853 | // if the user hasn't set a scissor box, we set one that | - | ||||||||||||||||||
4854 | // covers the current viewport | - | ||||||||||||||||||
4855 | funcs->glScissor(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
4856 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
4857 | } else if (use_scissor_testing) { never executed: end of block
| 0 | ||||||||||||||||||
4858 | // use the scissor box set by the user | - | ||||||||||||||||||
4859 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
4860 | } never executed: end of block | 0 | ||||||||||||||||||
4861 | - | |||||||||||||||||||
4862 | qt_gl_draw_text(p, x, y, str, font); | - | ||||||||||||||||||
4863 | - | |||||||||||||||||||
4864 | if (!reuse_painter) {
| 0 | ||||||||||||||||||
4865 | p->end(); | - | ||||||||||||||||||
4866 | delete p; | - | ||||||||||||||||||
4867 | setAutoBufferSwap(auto_swap); | - | ||||||||||||||||||
4868 | d->disable_clear_on_painter_begin = false; | - | ||||||||||||||||||
4869 | } never executed: end of block | 0 | ||||||||||||||||||
4870 | - | |||||||||||||||||||
4871 | qt_restore_gl_state(); | - | ||||||||||||||||||
4872 | - | |||||||||||||||||||
4873 | return; never executed: return; | 0 | ||||||||||||||||||
4874 | } | - | ||||||||||||||||||
4875 | #else // QT_OPENGL_ES | - | ||||||||||||||||||
4876 | Q_UNUSED(x); | - | ||||||||||||||||||
4877 | Q_UNUSED(y); | - | ||||||||||||||||||
4878 | Q_UNUSED(str); | - | ||||||||||||||||||
4879 | Q_UNUSED(font); | - | ||||||||||||||||||
4880 | #endif | - | ||||||||||||||||||
4881 | qWarning("QGLWidget::renderText is not supported under OpenGL/ES"); | - | ||||||||||||||||||
4882 | } never executed: end of block | 0 | ||||||||||||||||||
4883 | - | |||||||||||||||||||
4884 | /*! \overload | - | ||||||||||||||||||
4885 | - | |||||||||||||||||||
4886 | \a x, \a y and \a z are specified in scene or object coordinates | - | ||||||||||||||||||
4887 | relative to the currently set projection and model matrices. This | - | ||||||||||||||||||
4888 | can be useful if you want to annotate models with text labels and | - | ||||||||||||||||||
4889 | have the labels move with the model as it is rotated etc. | - | ||||||||||||||||||
4890 | - | |||||||||||||||||||
4891 | \note This function is not supported on OpenGL/ES systems. | - | ||||||||||||||||||
4892 | - | |||||||||||||||||||
4893 | \note If depth testing is enabled before this function is called, | - | ||||||||||||||||||
4894 | then the drawn text will be depth-tested against the models that | - | ||||||||||||||||||
4895 | have already been drawn in the scene. Use \c{glDisable(GL_DEPTH_TEST)} | - | ||||||||||||||||||
4896 | before calling this function to annotate the models without | - | ||||||||||||||||||
4897 | depth-testing the text. | - | ||||||||||||||||||
4898 | - | |||||||||||||||||||
4899 | \note This function can only be used inside a | - | ||||||||||||||||||
4900 | QPainter::beginNativePainting()/QPainter::endNativePainting() block | - | ||||||||||||||||||
4901 | if a painter is active on the QGLWidget. | - | ||||||||||||||||||
4902 | */ | - | ||||||||||||||||||
4903 | void QGLWidget::renderText(double x, double y, double z, const QString &str, const QFont &font) | - | ||||||||||||||||||
4904 | { | - | ||||||||||||||||||
4905 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
4906 | Q_D(QGLWidget); | - | ||||||||||||||||||
4907 | if (!d->glcx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
4908 | Q_D(QGLWidget); | - | ||||||||||||||||||
4909 | if (str.isEmpty() || !isValid())
| 0 | ||||||||||||||||||
4910 | return; never executed: return; | 0 | ||||||||||||||||||
4911 | - | |||||||||||||||||||
4912 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
4913 | bool auto_swap = autoBufferSwap(); | - | ||||||||||||||||||
4914 | - | |||||||||||||||||||
4915 | int width = d->glcx->device()->width(); | - | ||||||||||||||||||
4916 | int height = d->glcx->device()->height(); | - | ||||||||||||||||||
4917 | GLdouble model[4 * 4], proj[4 * 4]; | - | ||||||||||||||||||
4918 | GLint view[4]; | - | ||||||||||||||||||
4919 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
4920 | gl1funcs->glGetDoublev(GL_MODELVIEW_MATRIX, &model[0]); | - | ||||||||||||||||||
4921 | gl1funcs->glGetDoublev(GL_PROJECTION_MATRIX, &proj[0]); | - | ||||||||||||||||||
4922 | funcs->glGetIntegerv(GL_VIEWPORT, &view[0]); | - | ||||||||||||||||||
4923 | GLdouble win_x = 0, win_y = 0, win_z = 0; | - | ||||||||||||||||||
4924 | qgluProject(x, y, z, &model[0], &proj[0], &view[0], | - | ||||||||||||||||||
4925 | &win_x, &win_y, &win_z); | - | ||||||||||||||||||
4926 | const int dpr = d->glcx->device()->devicePixelRatioF(); | - | ||||||||||||||||||
4927 | win_x /= dpr; | - | ||||||||||||||||||
4928 | win_y /= dpr; | - | ||||||||||||||||||
4929 | win_y = height - win_y; // y is inverted | - | ||||||||||||||||||
4930 | - | |||||||||||||||||||
4931 | QPaintEngine *engine = paintEngine(); | - | ||||||||||||||||||
4932 | - | |||||||||||||||||||
4933 | QPainter *p; | - | ||||||||||||||||||
4934 | bool reuse_painter = false; | - | ||||||||||||||||||
4935 | bool use_depth_testing = funcs->glIsEnabled(GL_DEPTH_TEST); | - | ||||||||||||||||||
4936 | bool use_scissor_testing = funcs->glIsEnabled(GL_SCISSOR_TEST); | - | ||||||||||||||||||
4937 | - | |||||||||||||||||||
4938 | qt_save_gl_state(); | - | ||||||||||||||||||
4939 | - | |||||||||||||||||||
4940 | if (engine->isActive()) {
| 0 | ||||||||||||||||||
4941 | reuse_painter = true; | - | ||||||||||||||||||
4942 | p = engine->painter(); | - | ||||||||||||||||||
4943 | } else { never executed: end of block | 0 | ||||||||||||||||||
4944 | setAutoBufferSwap(false); | - | ||||||||||||||||||
4945 | // disable glClear() as a result of QPainter::begin() | - | ||||||||||||||||||
4946 | d->disable_clear_on_painter_begin = true; | - | ||||||||||||||||||
4947 | p = new QPainter(this); | - | ||||||||||||||||||
4948 | } never executed: end of block | 0 | ||||||||||||||||||
4949 | - | |||||||||||||||||||
4950 | QRect viewport(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
4951 | if (!use_scissor_testing && viewport != rect()) {
| 0 | ||||||||||||||||||
4952 | funcs->glScissor(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
4953 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
4954 | } else if (use_scissor_testing) { never executed: end of block
| 0 | ||||||||||||||||||
4955 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
4956 | } never executed: end of block | 0 | ||||||||||||||||||
4957 | funcs->glViewport(0, 0, width * dpr, height * dpr); | - | ||||||||||||||||||
4958 | gl1funcs->glAlphaFunc(GL_GREATER, 0.0); | - | ||||||||||||||||||
4959 | funcs->glEnable(GL_ALPHA_TEST); | - | ||||||||||||||||||
4960 | if (use_depth_testing)
| 0 | ||||||||||||||||||
4961 | funcs->glEnable(GL_DEPTH_TEST); never executed: funcs->glEnable(0x0B71); | 0 | ||||||||||||||||||
4962 | - | |||||||||||||||||||
4963 | // The only option in Qt 5 is the shader-based OpenGL 2 paint engine. | - | ||||||||||||||||||
4964 | // Setting fixed pipeline transformations is futile. Instead, pass the | - | ||||||||||||||||||
4965 | // extra values directly and let the engine figure the matrices out. | - | ||||||||||||||||||
4966 | static_cast<QGL2PaintEngineEx *>(p->paintEngine())->setTranslateZ(-win_z); | - | ||||||||||||||||||
4967 | - | |||||||||||||||||||
4968 | qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font); | - | ||||||||||||||||||
4969 | - | |||||||||||||||||||
4970 | static_cast<QGL2PaintEngineEx *>(p->paintEngine())->setTranslateZ(0); | - | ||||||||||||||||||
4971 | - | |||||||||||||||||||
4972 | if (!reuse_painter) {
| 0 | ||||||||||||||||||
4973 | p->end(); | - | ||||||||||||||||||
4974 | delete p; | - | ||||||||||||||||||
4975 | setAutoBufferSwap(auto_swap); | - | ||||||||||||||||||
4976 | d->disable_clear_on_painter_begin = false; | - | ||||||||||||||||||
4977 | } never executed: end of block | 0 | ||||||||||||||||||
4978 | - | |||||||||||||||||||
4979 | qt_restore_gl_state(); | - | ||||||||||||||||||
4980 | - | |||||||||||||||||||
4981 | return; never executed: return; | 0 | ||||||||||||||||||
4982 | } | - | ||||||||||||||||||
4983 | #else // QT_OPENGL_ES | - | ||||||||||||||||||
4984 | Q_UNUSED(x); | - | ||||||||||||||||||
4985 | Q_UNUSED(y); | - | ||||||||||||||||||
4986 | Q_UNUSED(z); | - | ||||||||||||||||||
4987 | Q_UNUSED(str); | - | ||||||||||||||||||
4988 | Q_UNUSED(font); | - | ||||||||||||||||||
4989 | #endif | - | ||||||||||||||||||
4990 | qWarning("QGLWidget::renderText is not supported under OpenGL/ES"); | - | ||||||||||||||||||
4991 | } never executed: end of block | 0 | ||||||||||||||||||
4992 | - | |||||||||||||||||||
4993 | QGLFormat QGLWidget::format() const | - | ||||||||||||||||||
4994 | { | - | ||||||||||||||||||
4995 | Q_D(const QGLWidget); | - | ||||||||||||||||||
4996 | return d->glcx->format(); never executed: return d->glcx->format(); | 0 | ||||||||||||||||||
4997 | } | - | ||||||||||||||||||
4998 | - | |||||||||||||||||||
4999 | QGLContext *QGLWidget::context() const | - | ||||||||||||||||||
5000 | { | - | ||||||||||||||||||
5001 | Q_D(const QGLWidget); | - | ||||||||||||||||||
5002 | return d->glcx; executed 38 times by 2 tests: return d->glcx; Executed by:
| 38 | ||||||||||||||||||
5003 | } | - | ||||||||||||||||||
5004 | - | |||||||||||||||||||
5005 | bool QGLWidget::doubleBuffer() const | - | ||||||||||||||||||
5006 | { | - | ||||||||||||||||||
5007 | Q_D(const QGLWidget); | - | ||||||||||||||||||
5008 | return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); never executed: return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); | 0 | ||||||||||||||||||
5009 | } | - | ||||||||||||||||||
5010 | - | |||||||||||||||||||
5011 | void QGLWidget::setAutoBufferSwap(bool on) | - | ||||||||||||||||||
5012 | { | - | ||||||||||||||||||
5013 | Q_D(QGLWidget); | - | ||||||||||||||||||
5014 | d->autoSwap = on; | - | ||||||||||||||||||
5015 | } never executed: end of block | 0 | ||||||||||||||||||
5016 | - | |||||||||||||||||||
5017 | bool QGLWidget::autoBufferSwap() const | - | ||||||||||||||||||
5018 | { | - | ||||||||||||||||||
5019 | Q_D(const QGLWidget); | - | ||||||||||||||||||
5020 | return d->autoSwap; executed 2 times by 1 test: return d->autoSwap; Executed by:
| 2 | ||||||||||||||||||
5021 | } | - | ||||||||||||||||||
5022 | - | |||||||||||||||||||
5023 | /*! | - | ||||||||||||||||||
5024 | Calls QGLContext:::bindTexture(\a image, \a target, \a format) on the currently | - | ||||||||||||||||||
5025 | set context. | - | ||||||||||||||||||
5026 | - | |||||||||||||||||||
5027 | \sa deleteTexture() | - | ||||||||||||||||||
5028 | */ | - | ||||||||||||||||||
5029 | GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format) | - | ||||||||||||||||||
5030 | { | - | ||||||||||||||||||
5031 | if (image.isNull())
| 0 | ||||||||||||||||||
5032 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
5033 | - | |||||||||||||||||||
5034 | Q_D(QGLWidget); | - | ||||||||||||||||||
5035 | return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); never executed: return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); | 0 | ||||||||||||||||||
5036 | } | - | ||||||||||||||||||
5037 | - | |||||||||||||||||||
5038 | /*! | - | ||||||||||||||||||
5039 | \overload | - | ||||||||||||||||||
5040 | \since 4.6 | - | ||||||||||||||||||
5041 | - | |||||||||||||||||||
5042 | The binding \a options are a set of options used to decide how to | - | ||||||||||||||||||
5043 | bind the texture to the context. | - | ||||||||||||||||||
5044 | */ | - | ||||||||||||||||||
5045 | GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options) | - | ||||||||||||||||||
5046 | { | - | ||||||||||||||||||
5047 | if (image.isNull())
| 0 | ||||||||||||||||||
5048 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
5049 | - | |||||||||||||||||||
5050 | Q_D(QGLWidget); | - | ||||||||||||||||||
5051 | return d->glcx->bindTexture(image, target, format, options); never executed: return d->glcx->bindTexture(image, target, format, options); | 0 | ||||||||||||||||||
5052 | } | - | ||||||||||||||||||
5053 | - | |||||||||||||||||||
5054 | - | |||||||||||||||||||
5055 | /*! | - | ||||||||||||||||||
5056 | Calls QGLContext:::bindTexture(\a pixmap, \a target, \a format) on the currently | - | ||||||||||||||||||
5057 | set context. | - | ||||||||||||||||||
5058 | - | |||||||||||||||||||
5059 | \sa deleteTexture() | - | ||||||||||||||||||
5060 | */ | - | ||||||||||||||||||
5061 | GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) | - | ||||||||||||||||||
5062 | { | - | ||||||||||||||||||
5063 | if (pixmap.isNull())
| 0 | ||||||||||||||||||
5064 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
5065 | - | |||||||||||||||||||
5066 | Q_D(QGLWidget); | - | ||||||||||||||||||
5067 | return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); never executed: return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); | 0 | ||||||||||||||||||
5068 | } | - | ||||||||||||||||||
5069 | - | |||||||||||||||||||
5070 | /*! | - | ||||||||||||||||||
5071 | \overload | - | ||||||||||||||||||
5072 | \since 4.6 | - | ||||||||||||||||||
5073 | - | |||||||||||||||||||
5074 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
5075 | on \a pixmap. The generated texture id is returned and can be used in | - | ||||||||||||||||||
5076 | - | |||||||||||||||||||
5077 | The binding \a options are a set of options used to decide how to | - | ||||||||||||||||||
5078 | bind the texture to the context. | - | ||||||||||||||||||
5079 | */ | - | ||||||||||||||||||
5080 | GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, | - | ||||||||||||||||||
5081 | QGLContext::BindOptions options) | - | ||||||||||||||||||
5082 | { | - | ||||||||||||||||||
5083 | Q_D(QGLWidget); | - | ||||||||||||||||||
5084 | return d->glcx->bindTexture(pixmap, target, format, options); never executed: return d->glcx->bindTexture(pixmap, target, format, options); | 0 | ||||||||||||||||||
5085 | } | - | ||||||||||||||||||
5086 | - | |||||||||||||||||||
5087 | /*! \overload | - | ||||||||||||||||||
5088 | - | |||||||||||||||||||
5089 | Calls QGLContext::bindTexture(\a fileName) on the currently set context. | - | ||||||||||||||||||
5090 | - | |||||||||||||||||||
5091 | \sa deleteTexture() | - | ||||||||||||||||||
5092 | */ | - | ||||||||||||||||||
5093 | GLuint QGLWidget::bindTexture(const QString &fileName) | - | ||||||||||||||||||
5094 | { | - | ||||||||||||||||||
5095 | Q_D(QGLWidget); | - | ||||||||||||||||||
5096 | return d->glcx->bindTexture(fileName); never executed: return d->glcx->bindTexture(fileName); | 0 | ||||||||||||||||||
5097 | } | - | ||||||||||||||||||
5098 | - | |||||||||||||||||||
5099 | /*! | - | ||||||||||||||||||
5100 | Calls QGLContext::deleteTexture(\a id) on the currently set | - | ||||||||||||||||||
5101 | context. | - | ||||||||||||||||||
5102 | - | |||||||||||||||||||
5103 | \sa bindTexture() | - | ||||||||||||||||||
5104 | */ | - | ||||||||||||||||||
5105 | void QGLWidget::deleteTexture(GLuint id) | - | ||||||||||||||||||
5106 | { | - | ||||||||||||||||||
5107 | Q_D(QGLWidget); | - | ||||||||||||||||||
5108 | d->glcx->deleteTexture(id); | - | ||||||||||||||||||
5109 | } never executed: end of block | 0 | ||||||||||||||||||
5110 | - | |||||||||||||||||||
5111 | /*! | - | ||||||||||||||||||
5112 | \since 4.4 | - | ||||||||||||||||||
5113 | - | |||||||||||||||||||
5114 | Calls the corresponding QGLContext::drawTexture() with | - | ||||||||||||||||||
5115 | \a target, \a textureId, and \a textureTarget for this | - | ||||||||||||||||||
5116 | widget's context. | - | ||||||||||||||||||
5117 | */ | - | ||||||||||||||||||
5118 | void QGLWidget::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
5119 | { | - | ||||||||||||||||||
5120 | Q_D(QGLWidget); | - | ||||||||||||||||||
5121 | d->glcx->drawTexture(target, textureId, textureTarget); | - | ||||||||||||||||||
5122 | } never executed: end of block | 0 | ||||||||||||||||||
5123 | - | |||||||||||||||||||
5124 | /*! | - | ||||||||||||||||||
5125 | \since 4.4 | - | ||||||||||||||||||
5126 | - | |||||||||||||||||||
5127 | Calls the corresponding QGLContext::drawTexture() with | - | ||||||||||||||||||
5128 | \a point, \a textureId, and \a textureTarget for this | - | ||||||||||||||||||
5129 | widget's context. | - | ||||||||||||||||||
5130 | */ | - | ||||||||||||||||||
5131 | void QGLWidget::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
5132 | { | - | ||||||||||||||||||
5133 | Q_D(QGLWidget); | - | ||||||||||||||||||
5134 | d->glcx->drawTexture(point, textureId, textureTarget); | - | ||||||||||||||||||
5135 | } never executed: end of block | 0 | ||||||||||||||||||
5136 | - | |||||||||||||||||||
5137 | Q_GLOBAL_STATIC(QGLEngineThreadStorage<QGL2PaintEngineEx>, qt_gl_2_engine) executed 1 time by 1 test: end of block Executed by:
executed 1 time by 1 test: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 10 times by 1 test: return &holder.value; Executed by:
| 0-10 | ||||||||||||||||||
5138 | - | |||||||||||||||||||
5139 | Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine() | - | ||||||||||||||||||
5140 | { | - | ||||||||||||||||||
5141 | return qt_gl_2_engine()->engine(); executed 10 times by 1 test: return qt_gl_2_engine()->engine(); Executed by:
| 10 | ||||||||||||||||||
5142 | } | - | ||||||||||||||||||
5143 | - | |||||||||||||||||||
5144 | /*! | - | ||||||||||||||||||
5145 | \internal | - | ||||||||||||||||||
5146 | - | |||||||||||||||||||
5147 | Returns the GL widget's paint engine. | - | ||||||||||||||||||
5148 | */ | - | ||||||||||||||||||
5149 | QPaintEngine *QGLWidget::paintEngine() const | - | ||||||||||||||||||
5150 | { | - | ||||||||||||||||||
5151 | return qt_qgl_paint_engine(); executed 10 times by 1 test: return qt_qgl_paint_engine(); Executed by:
| 10 | ||||||||||||||||||
5152 | } | - | ||||||||||||||||||
5153 | - | |||||||||||||||||||
5154 | void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget *shareWidget) | - | ||||||||||||||||||
5155 | { | - | ||||||||||||||||||
5156 | initContext(context, shareWidget); | - | ||||||||||||||||||
5157 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
5158 | - | |||||||||||||||||||
5159 | /* | - | ||||||||||||||||||
5160 | This is the shared initialization for all platforms. Called from QGLWidgetPrivate::init() | - | ||||||||||||||||||
5161 | */ | - | ||||||||||||||||||
5162 | void QGLWidgetPrivate::initContext(QGLContext *context, const QGLWidget* shareWidget) | - | ||||||||||||||||||
5163 | { | - | ||||||||||||||||||
5164 | Q_Q(QGLWidget); | - | ||||||||||||||||||
5165 | - | |||||||||||||||||||
5166 | glDevice.setWidget(q); | - | ||||||||||||||||||
5167 | - | |||||||||||||||||||
5168 | glcx = 0; | - | ||||||||||||||||||
5169 | autoSwap = true; | - | ||||||||||||||||||
5170 | - | |||||||||||||||||||
5171 | if (context && !context->device())
| 0-12 | ||||||||||||||||||
5172 | context->setDevice(q); never executed: context->setDevice(q); | 0 | ||||||||||||||||||
5173 | q->setContext(context, shareWidget ? shareWidget->context() : 0); | - | ||||||||||||||||||
5174 | - | |||||||||||||||||||
5175 | if (!glcx)
| 0-12 | ||||||||||||||||||
5176 | glcx = new QGLContext(QGLFormat::defaultFormat(), q); never executed: glcx = new QGLContext(QGLFormat::defaultFormat(), q); | 0 | ||||||||||||||||||
5177 | } executed 12 times by 3 tests: end of block Executed by:
| 12 | ||||||||||||||||||
5178 | - | |||||||||||||||||||
5179 | bool QGLWidgetPrivate::renderCxPm(QPixmap*) | - | ||||||||||||||||||
5180 | { | - | ||||||||||||||||||
5181 | return false; never executed: return false; | 0 | ||||||||||||||||||
5182 | } | - | ||||||||||||||||||
5183 | - | |||||||||||||||||||
5184 | /*! \internal | - | ||||||||||||||||||
5185 | Free up any allocated colormaps. This fn is only called for | - | ||||||||||||||||||
5186 | top-level widgets. | - | ||||||||||||||||||
5187 | */ | - | ||||||||||||||||||
5188 | void QGLWidgetPrivate::cleanupColormaps() | - | ||||||||||||||||||
5189 | { | - | ||||||||||||||||||
5190 | } | - | ||||||||||||||||||
5191 | - | |||||||||||||||||||
5192 | Q_GLOBAL_STATIC(QString, qt_gl_lib_name) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
5193 | - | |||||||||||||||||||
5194 | void qt_set_gl_library_name(const QString& name) | - | ||||||||||||||||||
5195 | { | - | ||||||||||||||||||
5196 | qt_gl_lib_name()->operator=(name); | - | ||||||||||||||||||
5197 | } never executed: end of block | 0 | ||||||||||||||||||
5198 | - | |||||||||||||||||||
5199 | const QString qt_gl_library_name() | - | ||||||||||||||||||
5200 | { | - | ||||||||||||||||||
5201 | if (qt_gl_lib_name()->isNull()) {
| 0 | ||||||||||||||||||
5202 | # if defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
5203 | return QLatin1String("GLESv2"); | - | ||||||||||||||||||
5204 | # else | - | ||||||||||||||||||
5205 | return QLatin1String("GL"); never executed: return QLatin1String("GL"); | 0 | ||||||||||||||||||
5206 | # endif | - | ||||||||||||||||||
5207 | } | - | ||||||||||||||||||
5208 | return *qt_gl_lib_name(); never executed: return *qt_gl_lib_name(); | 0 | ||||||||||||||||||
5209 | } | - | ||||||||||||||||||
5210 | - | |||||||||||||||||||
5211 | void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) { | - | ||||||||||||||||||
5212 | Q_ASSERT(context && share); | - | ||||||||||||||||||
5213 | if (context->d_ptr->group == share->d_ptr->group)
| 0-1 | ||||||||||||||||||
5214 | return; never executed: return; | 0 | ||||||||||||||||||
5215 | - | |||||||||||||||||||
5216 | // Make sure 'context' is not already shared with another group of contexts. | - | ||||||||||||||||||
5217 | Q_ASSERT(context->d_ptr->group->m_refs.load() == 1); | - | ||||||||||||||||||
5218 | - | |||||||||||||||||||
5219 | // Free 'context' group resources and make it use the same resources as 'share'. | - | ||||||||||||||||||
5220 | QGLContextGroup *group = share->d_ptr->group; | - | ||||||||||||||||||
5221 | delete context->d_ptr->group; | - | ||||||||||||||||||
5222 | context->d_ptr->group = group; | - | ||||||||||||||||||
5223 | group->m_refs.ref(); | - | ||||||||||||||||||
5224 | - | |||||||||||||||||||
5225 | // Maintain a list of all the contexts in each group of sharing contexts. | - | ||||||||||||||||||
5226 | // The list is empty if the "share" context wasn't sharing already. | - | ||||||||||||||||||
5227 | if (group->m_shares.isEmpty())
| 0-1 | ||||||||||||||||||
5228 | group->m_shares.append(share); executed 1 time by 1 test: group->m_shares.append(share); Executed by:
| 1 | ||||||||||||||||||
5229 | group->m_shares.append(context); | - | ||||||||||||||||||
5230 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
5231 | - | |||||||||||||||||||
5232 | void QGLContextGroup::removeShare(const QGLContext *context) { | - | ||||||||||||||||||
5233 | // Remove the context from the group. | - | ||||||||||||||||||
5234 | QGLContextGroup *group = context->d_ptr->group; | - | ||||||||||||||||||
5235 | if (group->m_shares.isEmpty())
| 1-11 | ||||||||||||||||||
5236 | return; executed 11 times by 3 tests: return; Executed by:
| 11 | ||||||||||||||||||
5237 | group->m_shares.removeAll(context); | - | ||||||||||||||||||
5238 | - | |||||||||||||||||||
5239 | // Update context group representative. | - | ||||||||||||||||||
5240 | Q_ASSERT(group->m_shares.size() != 0); | - | ||||||||||||||||||
5241 | if (group->m_context == context)
| 0-1 | ||||||||||||||||||
5242 | group->m_context = group->m_shares[0]; executed 1 time by 1 test: group->m_context = group->m_shares[0]; Executed by:
| 1 | ||||||||||||||||||
5243 | - | |||||||||||||||||||
5244 | // If there is only one context left, then make the list empty. | - | ||||||||||||||||||
5245 | if (group->m_shares.size() == 1)
| 0-1 | ||||||||||||||||||
5246 | group->m_shares.clear(); executed 1 time by 1 test: group->m_shares.clear(); Executed by:
| 1 | ||||||||||||||||||
5247 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
5248 | - | |||||||||||||||||||
5249 | QSize QGLTexture::bindCompressedTexture | - | ||||||||||||||||||
5250 | (const QString& fileName, const char *format) | - | ||||||||||||||||||
5251 | { | - | ||||||||||||||||||
5252 | QFile file(fileName); | - | ||||||||||||||||||
5253 | if (!file.open(QIODevice::ReadOnly))
| 0 | ||||||||||||||||||
5254 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5255 | QByteArray contents = file.readAll(); | - | ||||||||||||||||||
5256 | file.close(); | - | ||||||||||||||||||
5257 | return bindCompressedTexture never executed: return bindCompressedTexture (contents.constData(), contents.size(), format); | 0 | ||||||||||||||||||
5258 | (contents.constData(), contents.size(), format); never executed: return bindCompressedTexture (contents.constData(), contents.size(), format); | 0 | ||||||||||||||||||
5259 | } | - | ||||||||||||||||||
5260 | - | |||||||||||||||||||
5261 | // PVR header format for container files that store textures compressed | - | ||||||||||||||||||
5262 | // with the ETC1, PVRTC2, and PVRTC4 encodings. Format information from the | - | ||||||||||||||||||
5263 | // PowerVR SDK at http://www.imgtec.com/powervr/insider/powervr-sdk.asp | - | ||||||||||||||||||
5264 | // "PVRTexTool Reference Manual, version 1.11f". | - | ||||||||||||||||||
5265 | struct PvrHeader | - | ||||||||||||||||||
5266 | { | - | ||||||||||||||||||
5267 | quint32 headerSize; | - | ||||||||||||||||||
5268 | quint32 height; | - | ||||||||||||||||||
5269 | quint32 width; | - | ||||||||||||||||||
5270 | quint32 mipMapCount; | - | ||||||||||||||||||
5271 | quint32 flags; | - | ||||||||||||||||||
5272 | quint32 dataSize; | - | ||||||||||||||||||
5273 | quint32 bitsPerPixel; | - | ||||||||||||||||||
5274 | quint32 redMask; | - | ||||||||||||||||||
5275 | quint32 greenMask; | - | ||||||||||||||||||
5276 | quint32 blueMask; | - | ||||||||||||||||||
5277 | quint32 alphaMask; | - | ||||||||||||||||||
5278 | quint32 magic; | - | ||||||||||||||||||
5279 | quint32 surfaceCount; | - | ||||||||||||||||||
5280 | }; | - | ||||||||||||||||||
5281 | - | |||||||||||||||||||
5282 | #define PVR_MAGIC 0x21525650 // "PVR!" in little-endian | - | ||||||||||||||||||
5283 | - | |||||||||||||||||||
5284 | #define PVR_FORMAT_MASK 0x000000FF | - | ||||||||||||||||||
5285 | #define PVR_FORMAT_PVRTC2 0x00000018 | - | ||||||||||||||||||
5286 | #define PVR_FORMAT_PVRTC4 0x00000019 | - | ||||||||||||||||||
5287 | #define PVR_FORMAT_ETC1 0x00000036 | - | ||||||||||||||||||
5288 | - | |||||||||||||||||||
5289 | #define PVR_HAS_MIPMAPS 0x00000100 | - | ||||||||||||||||||
5290 | #define PVR_TWIDDLED 0x00000200 | - | ||||||||||||||||||
5291 | #define PVR_NORMAL_MAP 0x00000400 | - | ||||||||||||||||||
5292 | #define PVR_BORDER_ADDED 0x00000800 | - | ||||||||||||||||||
5293 | #define PVR_CUBE_MAP 0x00001000 | - | ||||||||||||||||||
5294 | #define PVR_FALSE_COLOR_MIPMAPS 0x00002000 | - | ||||||||||||||||||
5295 | #define PVR_VOLUME_TEXTURE 0x00004000 | - | ||||||||||||||||||
5296 | #define PVR_ALPHA_IN_TEXTURE 0x00008000 | - | ||||||||||||||||||
5297 | #define PVR_VERTICAL_FLIP 0x00010000 | - | ||||||||||||||||||
5298 | - | |||||||||||||||||||
5299 | #ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG | - | ||||||||||||||||||
5300 | #define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 | - | ||||||||||||||||||
5301 | #define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 | - | ||||||||||||||||||
5302 | #define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 | - | ||||||||||||||||||
5303 | #define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 | - | ||||||||||||||||||
5304 | #endif | - | ||||||||||||||||||
5305 | - | |||||||||||||||||||
5306 | #ifndef GL_ETC1_RGB8_OES | - | ||||||||||||||||||
5307 | #define GL_ETC1_RGB8_OES 0x8D64 | - | ||||||||||||||||||
5308 | #endif | - | ||||||||||||||||||
5309 | - | |||||||||||||||||||
5310 | bool QGLTexture::canBindCompressedTexture | - | ||||||||||||||||||
5311 | (const char *buf, int len, const char *format, bool *hasAlpha) | - | ||||||||||||||||||
5312 | { | - | ||||||||||||||||||
5313 | if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) {
| 0 | ||||||||||||||||||
5314 | // Compressed texture loading only supported on little-endian | - | ||||||||||||||||||
5315 | // systems such as x86 and ARM at the moment. | - | ||||||||||||||||||
5316 | return false; never executed: return false; | 0 | ||||||||||||||||||
5317 | } | - | ||||||||||||||||||
5318 | if (!format) {
| 0 | ||||||||||||||||||
5319 | // Auto-detect the format from the header. | - | ||||||||||||||||||
5320 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) {
| 0 | ||||||||||||||||||
5321 | *hasAlpha = true; | - | ||||||||||||||||||
5322 | return true; never executed: return true; | 0 | ||||||||||||||||||
5323 | } else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) {
| 0 | ||||||||||||||||||
5324 | const PvrHeader *pvrHeader = | - | ||||||||||||||||||
5325 | reinterpret_cast<const PvrHeader *>(buf); | - | ||||||||||||||||||
5326 | *hasAlpha = (pvrHeader->alphaMask != 0); | - | ||||||||||||||||||
5327 | return true; never executed: return true; | 0 | ||||||||||||||||||
5328 | } | - | ||||||||||||||||||
5329 | } else { never executed: end of block | 0 | ||||||||||||||||||
5330 | // Validate the format against the header. | - | ||||||||||||||||||
5331 | if (!qstricmp(format, "DDS")) {
| 0 | ||||||||||||||||||
5332 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) {
| 0 | ||||||||||||||||||
5333 | *hasAlpha = true; | - | ||||||||||||||||||
5334 | return true; never executed: return true; | 0 | ||||||||||||||||||
5335 | } | - | ||||||||||||||||||
5336 | } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { never executed: end of block
| 0 | ||||||||||||||||||
5337 | if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) {
| 0 | ||||||||||||||||||
5338 | const PvrHeader *pvrHeader = | - | ||||||||||||||||||
5339 | reinterpret_cast<const PvrHeader *>(buf); | - | ||||||||||||||||||
5340 | *hasAlpha = (pvrHeader->alphaMask != 0); | - | ||||||||||||||||||
5341 | return true; never executed: return true; | 0 | ||||||||||||||||||
5342 | } | - | ||||||||||||||||||
5343 | } never executed: end of block | 0 | ||||||||||||||||||
5344 | } never executed: end of block | 0 | ||||||||||||||||||
5345 | return false; never executed: return false; | 0 | ||||||||||||||||||
5346 | } | - | ||||||||||||||||||
5347 | - | |||||||||||||||||||
5348 | #define ctx QGLContext::currentContext() | - | ||||||||||||||||||
5349 | - | |||||||||||||||||||
5350 | QSize QGLTexture::bindCompressedTexture | - | ||||||||||||||||||
5351 | (const char *buf, int len, const char *format) | - | ||||||||||||||||||
5352 | { | - | ||||||||||||||||||
5353 | if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) {
| 0 | ||||||||||||||||||
5354 | // Compressed texture loading only supported on little-endian | - | ||||||||||||||||||
5355 | // systems such as x86 and ARM at the moment. | - | ||||||||||||||||||
5356 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5357 | } | - | ||||||||||||||||||
5358 | if (!format) {
| 0 | ||||||||||||||||||
5359 | // Auto-detect the format from the header. | - | ||||||||||||||||||
5360 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4))
| 0 | ||||||||||||||||||
5361 | return bindCompressedTextureDDS(buf, len); never executed: return bindCompressedTextureDDS(buf, len); | 0 | ||||||||||||||||||
5362 | else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4))
| 0 | ||||||||||||||||||
5363 | return bindCompressedTexturePVR(buf, len); never executed: return bindCompressedTexturePVR(buf, len); | 0 | ||||||||||||||||||
5364 | } else { never executed: end of block | 0 | ||||||||||||||||||
5365 | // Validate the format against the header. | - | ||||||||||||||||||
5366 | if (!qstricmp(format, "DDS")) {
| 0 | ||||||||||||||||||
5367 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4))
| 0 | ||||||||||||||||||
5368 | return bindCompressedTextureDDS(buf, len); never executed: return bindCompressedTextureDDS(buf, len); | 0 | ||||||||||||||||||
5369 | } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { never executed: end of block
| 0 | ||||||||||||||||||
5370 | if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4))
| 0 | ||||||||||||||||||
5371 | return bindCompressedTexturePVR(buf, len); never executed: return bindCompressedTexturePVR(buf, len); | 0 | ||||||||||||||||||
5372 | } never executed: end of block | 0 | ||||||||||||||||||
5373 | } never executed: end of block | 0 | ||||||||||||||||||
5374 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5375 | } | - | ||||||||||||||||||
5376 | - | |||||||||||||||||||
5377 | QSize QGLTexture::bindCompressedTextureDDS(const char *buf, int len) | - | ||||||||||||||||||
5378 | { | - | ||||||||||||||||||
5379 | // We only support 2D texture loading at present. | - | ||||||||||||||||||
5380 | if (target != GL_TEXTURE_2D)
| 0 | ||||||||||||||||||
5381 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5382 | - | |||||||||||||||||||
5383 | // Bail out if the necessary extension is not present. | - | ||||||||||||||||||
5384 | if (!qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::DDSTextureCompression)) {
| 0 | ||||||||||||||||||
5385 | qWarning("QGLContext::bindTexture(): DDS texture compression is not supported."); | - | ||||||||||||||||||
5386 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5387 | } | - | ||||||||||||||||||
5388 | - | |||||||||||||||||||
5389 | const DDSFormat *ddsHeader = reinterpret_cast<const DDSFormat *>(buf + 4); | - | ||||||||||||||||||
5390 | if (!ddsHeader->dwLinearSize) {
| 0 | ||||||||||||||||||
5391 | qWarning("QGLContext::bindTexture(): DDS image size is not valid."); | - | ||||||||||||||||||
5392 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5393 | } | - | ||||||||||||||||||
5394 | - | |||||||||||||||||||
5395 | int blockSize = 16; | - | ||||||||||||||||||
5396 | GLenum format; | - | ||||||||||||||||||
5397 | - | |||||||||||||||||||
5398 | switch(ddsHeader->ddsPixelFormat.dwFourCC) { | - | ||||||||||||||||||
5399 | case FOURCC_DXT1: never executed: case 0x31545844: | 0 | ||||||||||||||||||
5400 | format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; | - | ||||||||||||||||||
5401 | blockSize = 8; | - | ||||||||||||||||||
5402 | break; never executed: break; | 0 | ||||||||||||||||||
5403 | case FOURCC_DXT3: never executed: case 0x33545844: | 0 | ||||||||||||||||||
5404 | format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; | - | ||||||||||||||||||
5405 | break; never executed: break; | 0 | ||||||||||||||||||
5406 | case FOURCC_DXT5: never executed: case 0x35545844: | 0 | ||||||||||||||||||
5407 | format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | - | ||||||||||||||||||
5408 | break; never executed: break; | 0 | ||||||||||||||||||
5409 | default: never executed: default: | 0 | ||||||||||||||||||
5410 | qWarning("QGLContext::bindTexture(): DDS image format not supported."); | - | ||||||||||||||||||
5411 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5412 | } | - | ||||||||||||||||||
5413 | - | |||||||||||||||||||
5414 | const GLubyte *pixels = | - | ||||||||||||||||||
5415 | reinterpret_cast<const GLubyte *>(buf + ddsHeader->dwSize + 4); | - | ||||||||||||||||||
5416 | - | |||||||||||||||||||
5417 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
5418 | funcs->glGenTextures(1, &id); | - | ||||||||||||||||||
5419 | funcs->glBindTexture(GL_TEXTURE_2D, id); | - | ||||||||||||||||||
5420 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||
5421 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | - | ||||||||||||||||||
5422 | - | |||||||||||||||||||
5423 | int size; | - | ||||||||||||||||||
5424 | int offset = 0; | - | ||||||||||||||||||
5425 | int available = len - int(ddsHeader->dwSize + 4); | - | ||||||||||||||||||
5426 | int w = ddsHeader->dwWidth; | - | ||||||||||||||||||
5427 | int h = ddsHeader->dwHeight; | - | ||||||||||||||||||
5428 | - | |||||||||||||||||||
5429 | // load mip-maps | - | ||||||||||||||||||
5430 | for(int i = 0; i < (int) ddsHeader->dwMipMapCount; ++i) {
| 0 | ||||||||||||||||||
5431 | if (w == 0) w = 1; never executed: w = 1;
| 0 | ||||||||||||||||||
5432 | if (h == 0) h = 1; never executed: h = 1;
| 0 | ||||||||||||||||||
5433 | - | |||||||||||||||||||
5434 | size = ((w+3)/4) * ((h+3)/4) * blockSize; | - | ||||||||||||||||||
5435 | if (size > available)
| 0 | ||||||||||||||||||
5436 | break; never executed: break; | 0 | ||||||||||||||||||
5437 | qgl_extensions()->glCompressedTexImage2D(GL_TEXTURE_2D, i, format, w, h, 0, | - | ||||||||||||||||||
5438 | size, pixels + offset); | - | ||||||||||||||||||
5439 | offset += size; | - | ||||||||||||||||||
5440 | available -= size; | - | ||||||||||||||||||
5441 | - | |||||||||||||||||||
5442 | // half size for each mip-map level | - | ||||||||||||||||||
5443 | w = w/2; | - | ||||||||||||||||||
5444 | h = h/2; | - | ||||||||||||||||||
5445 | } never executed: end of block | 0 | ||||||||||||||||||
5446 | - | |||||||||||||||||||
5447 | // DDS images are not inverted. | - | ||||||||||||||||||
5448 | options &= ~QGLContext::InvertedYBindOption; | - | ||||||||||||||||||
5449 | - | |||||||||||||||||||
5450 | return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); never executed: return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); | 0 | ||||||||||||||||||
5451 | } | - | ||||||||||||||||||
5452 | - | |||||||||||||||||||
5453 | QSize QGLTexture::bindCompressedTexturePVR(const char *buf, int len) | - | ||||||||||||||||||
5454 | { | - | ||||||||||||||||||
5455 | // We only support 2D texture loading at present. Cube maps later. | - | ||||||||||||||||||
5456 | if (target != GL_TEXTURE_2D)
| 0 | ||||||||||||||||||
5457 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5458 | - | |||||||||||||||||||
5459 | // Determine which texture format we will be loading. | - | ||||||||||||||||||
5460 | const PvrHeader *pvrHeader = reinterpret_cast<const PvrHeader *>(buf); | - | ||||||||||||||||||
5461 | GLenum textureFormat; | - | ||||||||||||||||||
5462 | quint32 minWidth, minHeight; | - | ||||||||||||||||||
5463 | switch (pvrHeader->flags & PVR_FORMAT_MASK) { | - | ||||||||||||||||||
5464 | case PVR_FORMAT_PVRTC2: never executed: case 0x00000018: | 0 | ||||||||||||||||||
5465 | if (pvrHeader->alphaMask)
| 0 | ||||||||||||||||||
5466 | textureFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; never executed: textureFormat = 0x8C03; | 0 | ||||||||||||||||||
5467 | else | - | ||||||||||||||||||
5468 | textureFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; never executed: textureFormat = 0x8C01; | 0 | ||||||||||||||||||
5469 | minWidth = 16; | - | ||||||||||||||||||
5470 | minHeight = 8; | - | ||||||||||||||||||
5471 | break; never executed: break; | 0 | ||||||||||||||||||
5472 | - | |||||||||||||||||||
5473 | case PVR_FORMAT_PVRTC4: never executed: case 0x00000019: | 0 | ||||||||||||||||||
5474 | if (pvrHeader->alphaMask)
| 0 | ||||||||||||||||||
5475 | textureFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; never executed: textureFormat = 0x8C02; | 0 | ||||||||||||||||||
5476 | else | - | ||||||||||||||||||
5477 | textureFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; never executed: textureFormat = 0x8C00; | 0 | ||||||||||||||||||
5478 | minWidth = 8; | - | ||||||||||||||||||
5479 | minHeight = 8; | - | ||||||||||||||||||
5480 | break; never executed: break; | 0 | ||||||||||||||||||
5481 | - | |||||||||||||||||||
5482 | case PVR_FORMAT_ETC1: never executed: case 0x00000036: | 0 | ||||||||||||||||||
5483 | textureFormat = GL_ETC1_RGB8_OES; | - | ||||||||||||||||||
5484 | minWidth = 4; | - | ||||||||||||||||||
5485 | minHeight = 4; | - | ||||||||||||||||||
5486 | break; never executed: break; | 0 | ||||||||||||||||||
5487 | - | |||||||||||||||||||
5488 | default: never executed: default: | 0 | ||||||||||||||||||
5489 | qWarning("QGLContext::bindTexture(): PVR image format 0x%x not supported.", int(pvrHeader->flags & PVR_FORMAT_MASK)); | - | ||||||||||||||||||
5490 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5491 | } | - | ||||||||||||||||||
5492 | - | |||||||||||||||||||
5493 | // Bail out if the necessary extension is not present. | - | ||||||||||||||||||
5494 | if (textureFormat == GL_ETC1_RGB8_OES) {
| 0 | ||||||||||||||||||
5495 | if (!qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::ETC1TextureCompression)) {
| 0 | ||||||||||||||||||
5496 | qWarning("QGLContext::bindTexture(): ETC1 texture compression is not supported."); | - | ||||||||||||||||||
5497 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5498 | } | - | ||||||||||||||||||
5499 | } else { never executed: end of block | 0 | ||||||||||||||||||
5500 | if (!qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::PVRTCTextureCompression)) {
| 0 | ||||||||||||||||||
5501 | qWarning("QGLContext::bindTexture(): PVRTC texture compression is not supported."); | - | ||||||||||||||||||
5502 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5503 | } | - | ||||||||||||||||||
5504 | } never executed: end of block | 0 | ||||||||||||||||||
5505 | - | |||||||||||||||||||
5506 | // Boundary check on the buffer size. | - | ||||||||||||||||||
5507 | quint32 bufferSize = pvrHeader->headerSize + pvrHeader->dataSize; | - | ||||||||||||||||||
5508 | if (bufferSize > quint32(len)) {
| 0 | ||||||||||||||||||
5509 | qWarning("QGLContext::bindTexture(): PVR image size is not valid."); | - | ||||||||||||||||||
5510 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
5511 | } | - | ||||||||||||||||||
5512 | - | |||||||||||||||||||
5513 | // Create the texture. | - | ||||||||||||||||||
5514 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
5515 | funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | - | ||||||||||||||||||
5516 | funcs->glGenTextures(1, &id); | - | ||||||||||||||||||
5517 | funcs->glBindTexture(GL_TEXTURE_2D, id); | - | ||||||||||||||||||
5518 | if (pvrHeader->mipMapCount) {
| 0 | ||||||||||||||||||
5519 | if ((options & QGLContext::LinearFilteringBindOption) != 0) {
| 0 | ||||||||||||||||||
5520 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||
5521 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); | - | ||||||||||||||||||
5522 | } else { never executed: end of block | 0 | ||||||||||||||||||
5523 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
5524 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); | - | ||||||||||||||||||
5525 | } never executed: end of block | 0 | ||||||||||||||||||
5526 | } else if ((options & QGLContext::LinearFilteringBindOption) != 0) {
| 0 | ||||||||||||||||||
5527 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||
5528 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | - | ||||||||||||||||||
5529 | } else { never executed: end of block | 0 | ||||||||||||||||||
5530 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
5531 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||
5532 | } never executed: end of block | 0 | ||||||||||||||||||
5533 | - | |||||||||||||||||||
5534 | // Load the compressed mipmap levels. | - | ||||||||||||||||||
5535 | const GLubyte *buffer = | - | ||||||||||||||||||
5536 | reinterpret_cast<const GLubyte *>(buf + pvrHeader->headerSize); | - | ||||||||||||||||||
5537 | bufferSize = pvrHeader->dataSize; | - | ||||||||||||||||||
5538 | quint32 level = 0; | - | ||||||||||||||||||
5539 | quint32 width = pvrHeader->width; | - | ||||||||||||||||||
5540 | quint32 height = pvrHeader->height; | - | ||||||||||||||||||
5541 | while (bufferSize > 0 && level <= pvrHeader->mipMapCount) {
| 0 | ||||||||||||||||||
5542 | quint32 size = | - | ||||||||||||||||||
5543 | (qMax(width, minWidth) * qMax(height, minHeight) * | - | ||||||||||||||||||
5544 | pvrHeader->bitsPerPixel) / 8; | - | ||||||||||||||||||
5545 | if (size > bufferSize)
| 0 | ||||||||||||||||||
5546 | break; never executed: break; | 0 | ||||||||||||||||||
5547 | qgl_extensions()->glCompressedTexImage2D(GL_TEXTURE_2D, GLint(level), textureFormat, | - | ||||||||||||||||||
5548 | GLsizei(width), GLsizei(height), 0, | - | ||||||||||||||||||
5549 | GLsizei(size), buffer); | - | ||||||||||||||||||
5550 | width /= 2; | - | ||||||||||||||||||
5551 | height /= 2; | - | ||||||||||||||||||
5552 | buffer += size; | - | ||||||||||||||||||
5553 | ++level; | - | ||||||||||||||||||
5554 | } never executed: end of block | 0 | ||||||||||||||||||
5555 | - | |||||||||||||||||||
5556 | // Restore the default pixel alignment for later texture uploads. | - | ||||||||||||||||||
5557 | funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 4); | - | ||||||||||||||||||
5558 | - | |||||||||||||||||||
5559 | // Set the invert flag for the texture. The "vertical flip" | - | ||||||||||||||||||
5560 | // flag in PVR is the opposite sense to our sense of inversion. | - | ||||||||||||||||||
5561 | if ((pvrHeader->flags & PVR_VERTICAL_FLIP) != 0)
| 0 | ||||||||||||||||||
5562 | options &= ~QGLContext::InvertedYBindOption; never executed: options &= ~QGLContext::InvertedYBindOption; | 0 | ||||||||||||||||||
5563 | else | - | ||||||||||||||||||
5564 | options |= QGLContext::InvertedYBindOption; never executed: options |= QGLContext::InvertedYBindOption; | 0 | ||||||||||||||||||
5565 | - | |||||||||||||||||||
5566 | return QSize(pvrHeader->width, pvrHeader->height); never executed: return QSize(pvrHeader->width, pvrHeader->height); | 0 | ||||||||||||||||||
5567 | } | - | ||||||||||||||||||
5568 | - | |||||||||||||||||||
5569 | #undef ctx | - | ||||||||||||||||||
5570 | - | |||||||||||||||||||
5571 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |