Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | QGLExtensionFuncs QGLContextPrivate::qt_extensionFuncs; | - |
15 | | - |
16 | struct QGLThreadContext { | - |
17 | ~QGLThreadContext() { | - |
18 | if (context) | 0 |
19 | context->doneCurrent(); never executed: context->doneCurrent(); | 0 |
20 | } | 0 |
21 | QGLContext *context; | - |
22 | }; | - |
23 | | - |
24 | static QGLFormat *qgl_default_format() { static QGlobalStatic<QGLFormat > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLFormat *x = new QGLFormat; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLFormat > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
25 | | - |
26 | class QGLDefaultOverlayFormat: public QGLFormat | - |
27 | { | - |
28 | public: | - |
29 | inline QGLDefaultOverlayFormat() | - |
30 | { | - |
31 | setOption(QGL::FormatOption(0xffff << 16)); | - |
32 | setOption(QGL::DirectRendering); | - |
33 | setPlane(1); | - |
34 | } | 0 |
35 | }; | - |
36 | static QGLDefaultOverlayFormat *defaultOverlayFormatInstance() { static QGlobalStatic<QGLDefaultOverlayFormat > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLDefaultOverlayFormat *x = new QGLDefaultOverlayFormat; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLDefaultOverlayFormat > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
37 | | - |
38 | static QGLSignalProxy *theSignalProxy() { static QGlobalStatic<QGLSignalProxy > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLSignalProxy *x = new QGLSignalProxy; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLSignalProxy > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never executed: delete x; never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed never executed: return thisGlobalStatic.pointer.load(); | 0 |
39 | QGLSignalProxy *QGLSignalProxy::instance() | - |
40 | { | - |
41 | QGLSignalProxy *proxy = theSignalProxy(); | - |
42 | if (proxy && proxy->thread() != (static_cast<QApplication *>(QCoreApplication::instance()))->thread()) { never evaluated: proxy->thread() != (static_cast<QApplication *>(QCoreApplication::instance()))->thread() | 0 |
43 | if (proxy->thread() == QThread::currentThread()) never evaluated: proxy->thread() == QThread::currentThread() | 0 |
44 | proxy->moveToThread((static_cast<QApplication *>(QCoreApplication::instance()))->thread()); never executed: proxy->moveToThread((static_cast<QApplication *>(QCoreApplication::instance()))->thread()); | 0 |
45 | } | 0 |
46 | return proxy; never executed: return proxy; | 0 |
47 | } | - |
48 | static inline void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) | - |
49 | { | - |
50 | | - |
51 | out[0] = | - |
52 | m[0*4+0] * in[0] + m[1*4+0] * in[1] + m[2*4+0] * in[2] + m[3*4+0] * in[3]; | - |
53 | out[1] = | - |
54 | m[0*4+1] * in[0] + m[1*4+1] * in[1] + m[2*4+1] * in[2] + m[3*4+1] * in[3]; | - |
55 | out[2] = | - |
56 | m[0*4+2] * in[0] + m[1*4+2] * in[1] + m[2*4+2] * in[2] + m[3*4+2] * in[3]; | - |
57 | out[3] = | - |
58 | m[0*4+3] * in[0] + m[1*4+3] * in[1] + m[2*4+3] * in[2] + m[3*4+3] * in[3]; | - |
59 | | - |
60 | } | 0 |
61 | | - |
62 | static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, | - |
63 | const GLdouble model[16], const GLdouble proj[16], | - |
64 | const GLint viewport[4], | - |
65 | GLdouble * winx, GLdouble * winy, GLdouble * winz) | - |
66 | { | - |
67 | GLdouble in[4], out[4]; | - |
68 | | - |
69 | in[0] = objx; | - |
70 | in[1] = objy; | - |
71 | in[2] = objz; | - |
72 | in[3] = 1.0; | - |
73 | transform_point(out, model, in); | - |
74 | transform_point(in, proj, out); | - |
75 | | - |
76 | if (in[3] == 0.0) never evaluated: in[3] == 0.0 | 0 |
77 | return 0x0; never executed: return 0x0; | 0 |
78 | | - |
79 | in[0] /= in[3]; | - |
80 | in[1] /= in[3]; | - |
81 | in[2] /= in[3]; | - |
82 | | - |
83 | *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; | - |
84 | *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; | - |
85 | | - |
86 | *winz = (1 + in[2]) / 2; | - |
87 | return 0x1; never executed: return 0x1; | 0 |
88 | } | - |
89 | QGLFormat::QGLFormat() | - |
90 | { | - |
91 | d = new QGLFormatPrivate; | - |
92 | } | 0 |
93 | QGLFormat::QGLFormat(QGL::FormatOptions options, int plane) | - |
94 | { | - |
95 | d = new QGLFormatPrivate; | - |
96 | QGL::FormatOptions newOpts = options; | - |
97 | d->opts = defaultFormat().d->opts; | - |
98 | d->opts |= (newOpts & 0xffff); | - |
99 | d->opts &= ~(newOpts >> 16); | - |
100 | d->pln = plane; | - |
101 | } | 0 |
102 | | - |
103 | | - |
104 | | - |
105 | | - |
106 | void QGLFormat::detach() | - |
107 | { | - |
108 | if (d->ref.load() != 1) { never evaluated: d->ref.load() != 1 | 0 |
109 | QGLFormatPrivate *newd = new QGLFormatPrivate(d); | - |
110 | if (!d->ref.deref()) never evaluated: !d->ref.deref() | 0 |
111 | delete d; never executed: delete d; | 0 |
112 | d = newd; | - |
113 | } | 0 |
114 | } | 0 |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | QGLFormat::QGLFormat(const QGLFormat &other) | - |
121 | { | - |
122 | d = other.d; | - |
123 | d->ref.ref(); | - |
124 | } | 0 |
125 | | - |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | QGLFormat &QGLFormat::operator=(const QGLFormat &other) | - |
131 | { | - |
132 | if (d != other.d) { never evaluated: d != other.d | 0 |
133 | other.d->ref.ref(); | - |
134 | if (!d->ref.deref()) never evaluated: !d->ref.deref() | 0 |
135 | delete d; never executed: delete d; | 0 |
136 | d = other.d; | - |
137 | } | 0 |
138 | return *this; never executed: return *this; | 0 |
139 | } | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | QGLFormat::~QGLFormat() | - |
145 | { | - |
146 | if (!d->ref.deref()) never evaluated: !d->ref.deref() | 0 |
147 | delete d; never executed: delete d; | 0 |
148 | } | 0 |
149 | void QGLFormat::setDoubleBuffer(bool enable) | - |
150 | { | - |
151 | setOption(enable ? QGL::DoubleBuffer : QGL::SingleBuffer); | - |
152 | } | 0 |
153 | void QGLFormat::setDepth(bool enable) | - |
154 | { | - |
155 | setOption(enable ? QGL::DepthBuffer : QGL::NoDepthBuffer); | - |
156 | } | 0 |
157 | void QGLFormat::setRgba(bool enable) | - |
158 | { | - |
159 | setOption(enable ? QGL::Rgba : QGL::ColorIndex); | - |
160 | } | 0 |
161 | void QGLFormat::setAlpha(bool enable) | - |
162 | { | - |
163 | setOption(enable ? QGL::AlphaChannel : QGL::NoAlphaChannel); | - |
164 | } | 0 |
165 | void QGLFormat::setAccum(bool enable) | - |
166 | { | - |
167 | setOption(enable ? QGL::AccumBuffer : QGL::NoAccumBuffer); | - |
168 | } | 0 |
169 | void QGLFormat::setStencil(bool enable) | - |
170 | { | - |
171 | setOption(enable ? QGL::StencilBuffer: QGL::NoStencilBuffer); | - |
172 | } | 0 |
173 | void QGLFormat::setStereo(bool enable) | - |
174 | { | - |
175 | setOption(enable ? QGL::StereoBuffers : QGL::NoStereoBuffers); | - |
176 | } | 0 |
177 | void QGLFormat::setDirectRendering(bool enable) | - |
178 | { | - |
179 | setOption(enable ? QGL::DirectRendering : QGL::IndirectRendering); | - |
180 | } | 0 |
181 | void QGLFormat::setSampleBuffers(bool enable) | - |
182 | { | - |
183 | setOption(enable ? QGL::SampleBuffers : QGL::NoSampleBuffers); | - |
184 | } | 0 |
185 | int QGLFormat::samples() const | - |
186 | { | - |
187 | return d->numSamples; never executed: return d->numSamples; | 0 |
188 | } | - |
189 | void QGLFormat::setSamples(int numSamples) | - |
190 | { | - |
191 | detach(); | - |
192 | if (numSamples < 0) { never evaluated: numSamples < 0 | 0 |
193 | QMessageLogger("qgl.cpp", 654, __PRETTY_FUNCTION__).warning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); | - |
194 | return; | 0 |
195 | } | - |
196 | d->numSamples = numSamples; | - |
197 | setSampleBuffers(numSamples > 0); | - |
198 | } | 0 |
199 | void QGLFormat::setSwapInterval(int interval) | - |
200 | { | - |
201 | detach(); | - |
202 | d->swapInterval = interval; | - |
203 | } | 0 |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | | - |
211 | int QGLFormat::swapInterval() const | - |
212 | { | - |
213 | return d->swapInterval; never executed: return d->swapInterval; | 0 |
214 | } | - |
215 | void QGLFormat::setOverlay(bool enable) | - |
216 | { | - |
217 | setOption(enable ? QGL::HasOverlay : QGL::NoOverlay); | - |
218 | } | 0 |
219 | int QGLFormat::plane() const | - |
220 | { | - |
221 | return d->pln; never executed: return d->pln; | 0 |
222 | } | - |
223 | void QGLFormat::setPlane(int plane) | - |
224 | { | - |
225 | detach(); | - |
226 | d->pln = plane; | - |
227 | } | 0 |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | | - |
233 | | - |
234 | | - |
235 | void QGLFormat::setOption(QGL::FormatOptions opt) | - |
236 | { | - |
237 | detach(); | - |
238 | if (opt & 0xffff) never evaluated: opt & 0xffff | 0 |
239 | d->opts |= opt; never executed: d->opts |= opt; | 0 |
240 | else | - |
241 | d->opts &= ~(opt >> 16); never executed: d->opts &= ~(opt >> 16); | 0 |
242 | } | - |
243 | bool QGLFormat::testOption(QGL::FormatOptions opt) const | - |
244 | { | - |
245 | if (opt & 0xffff) never evaluated: opt & 0xffff | 0 |
246 | return (d->opts & opt) != 0; never executed: return (d->opts & opt) != 0; | 0 |
247 | else | - |
248 | return (d->opts & (opt >> 16)) == 0; never executed: return (d->opts & (opt >> 16)) == 0; | 0 |
249 | } | - |
250 | | - |
251 | | - |
252 | | - |
253 | | - |
254 | | - |
255 | | - |
256 | void QGLFormat::setDepthBufferSize(int size) | - |
257 | { | - |
258 | detach(); | - |
259 | if (size < 0) { never evaluated: size < 0 | 0 |
260 | QMessageLogger("qgl.cpp", 793, __PRETTY_FUNCTION__).warning("QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); | - |
261 | return; | 0 |
262 | } | - |
263 | d->depthSize = size; | - |
264 | setDepth(size > 0); | - |
265 | } | 0 |
266 | | - |
267 | | - |
268 | | - |
269 | | - |
270 | | - |
271 | | - |
272 | int QGLFormat::depthBufferSize() const | - |
273 | { | - |
274 | return d->depthSize; never executed: return d->depthSize; | 0 |
275 | } | - |
276 | void QGLFormat::setRedBufferSize(int size) | - |
277 | { | - |
278 | detach(); | - |
279 | if (size < 0) { never evaluated: size < 0 | 0 |
280 | QMessageLogger("qgl.cpp", 821, __PRETTY_FUNCTION__).warning("QGLFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); | - |
281 | return; | 0 |
282 | } | - |
283 | d->redSize = size; | - |
284 | } | 0 |
285 | int QGLFormat::redBufferSize() const | - |
286 | { | - |
287 | return d->redSize; never executed: return d->redSize; | 0 |
288 | } | - |
289 | void QGLFormat::setGreenBufferSize(int size) | - |
290 | { | - |
291 | detach(); | - |
292 | if (size < 0) { never evaluated: size < 0 | 0 |
293 | QMessageLogger("qgl.cpp", 850, __PRETTY_FUNCTION__).warning("QGLFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); | - |
294 | return; | 0 |
295 | } | - |
296 | d->greenSize = size; | - |
297 | } | 0 |
298 | int QGLFormat::greenBufferSize() const | - |
299 | { | - |
300 | return d->greenSize; never executed: return d->greenSize; | 0 |
301 | } | - |
302 | void QGLFormat::setBlueBufferSize(int size) | - |
303 | { | - |
304 | detach(); | - |
305 | if (size < 0) { never evaluated: size < 0 | 0 |
306 | QMessageLogger("qgl.cpp", 879, __PRETTY_FUNCTION__).warning("QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); | - |
307 | return; | 0 |
308 | } | - |
309 | d->blueSize = size; | - |
310 | } | 0 |
311 | int QGLFormat::blueBufferSize() const | - |
312 | { | - |
313 | return d->blueSize; never executed: return d->blueSize; | 0 |
314 | } | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | void QGLFormat::setAlphaBufferSize(int size) | - |
323 | { | - |
324 | detach(); | - |
325 | if (size < 0) { never evaluated: size < 0 | 0 |
326 | QMessageLogger("qgl.cpp", 907, __PRETTY_FUNCTION__).warning("QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); | - |
327 | return; | 0 |
328 | } | - |
329 | d->alphaSize = size; | - |
330 | setAlpha(size > 0); | - |
331 | } | 0 |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | int QGLFormat::alphaBufferSize() const | - |
339 | { | - |
340 | return d->alphaSize; never executed: return d->alphaSize; | 0 |
341 | } | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | void QGLFormat::setAccumBufferSize(int size) | - |
350 | { | - |
351 | detach(); | - |
352 | if (size < 0) { never evaluated: size < 0 | 0 |
353 | QMessageLogger("qgl.cpp", 934, __PRETTY_FUNCTION__).warning("QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); | - |
354 | return; | 0 |
355 | } | - |
356 | d->accumSize = size; | - |
357 | setAccum(size > 0); | - |
358 | } | 0 |
359 | | - |
360 | | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | int QGLFormat::accumBufferSize() const | - |
366 | { | - |
367 | return d->accumSize; never executed: return d->accumSize; | 0 |
368 | } | - |
369 | | - |
370 | | - |
371 | | - |
372 | | - |
373 | | - |
374 | | - |
375 | void QGLFormat::setStencilBufferSize(int size) | - |
376 | { | - |
377 | detach(); | - |
378 | if (size < 0) { never evaluated: size < 0 | 0 |
379 | QMessageLogger("qgl.cpp", 960, __PRETTY_FUNCTION__).warning("QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); | - |
380 | return; | 0 |
381 | } | - |
382 | d->stencilSize = size; | - |
383 | setStencil(size > 0); | - |
384 | } | 0 |
385 | | - |
386 | | - |
387 | | - |
388 | | - |
389 | | - |
390 | | - |
391 | int QGLFormat::stencilBufferSize() const | - |
392 | { | - |
393 | return d->stencilSize; never executed: return d->stencilSize; | 0 |
394 | } | - |
395 | void QGLFormat::setVersion(int major, int minor) | - |
396 | { | - |
397 | if (major < 1 || minor < 0) { never evaluated: major < 1 never evaluated: minor < 0 | 0 |
398 | QMessageLogger("qgl.cpp", 989, __PRETTY_FUNCTION__).warning("QGLFormat::setVersion: Cannot set zero or negative version number %d.%d", major, minor); | - |
399 | return; | 0 |
400 | } | - |
401 | detach(); | - |
402 | d->majorVersion = major; | - |
403 | d->minorVersion = minor; | - |
404 | } | 0 |
405 | int QGLFormat::majorVersion() const | - |
406 | { | - |
407 | return d->majorVersion; never executed: return d->majorVersion; | 0 |
408 | } | - |
409 | int QGLFormat::minorVersion() const | - |
410 | { | - |
411 | return d->minorVersion; never executed: return d->minorVersion; | 0 |
412 | } | - |
413 | void QGLFormat::setProfile(OpenGLContextProfile profile) | - |
414 | { | - |
415 | detach(); | - |
416 | d->profile = profile; | - |
417 | } | 0 |
418 | QGLFormat::OpenGLContextProfile QGLFormat::profile() const | - |
419 | { | - |
420 | return d->profile; never executed: return d->profile; | 0 |
421 | } | - |
422 | QGLFormat::OpenGLVersionFlags qOpenGLVersionFlagsFromString(const QString &versionString) | - |
423 | { | - |
424 | QGLFormat::OpenGLVersionFlags versionFlags = QGLFormat::OpenGL_Version_None; | - |
425 | | - |
426 | if (versionString.startsWith(QLatin1String("OpenGL ES"))) { never evaluated: versionString.startsWith(QLatin1String("OpenGL ES")) | 0 |
427 | QStringList parts = versionString.split(QLatin1Char(' ')); | - |
428 | if (parts.size() >= 3) { never evaluated: parts.size() >= 3 | 0 |
429 | if (parts[2].startsWith(QLatin1String("1."))) { never evaluated: parts[2].startsWith(QLatin1String("1.")) | 0 |
430 | if (parts[1].endsWith(QLatin1String("-CM"))) { never evaluated: parts[1].endsWith(QLatin1String("-CM")) | 0 |
431 | versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_0 | | - |
432 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0; | - |
433 | if (parts[2].startsWith(QLatin1String("1.1"))) never evaluated: parts[2].startsWith(QLatin1String("1.1")) | 0 |
434 | versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | | 0 |
435 | 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 |
436 | } else { | 0 |
437 | | - |
438 | versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_0; | - |
439 | if (parts[2].startsWith(QLatin1String("1.1"))) never evaluated: parts[2].startsWith(QLatin1String("1.1")) | 0 |
440 | versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; never executed: versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 |
441 | } | 0 |
442 | } else { | - |
443 | | - |
444 | versionFlags |= QGLFormat::OpenGL_ES_Version_2_0; | - |
445 | } | 0 |
446 | } else { | - |
447 | | - |
448 | QMessageLogger("qgl.cpp", 1109, __PRETTY_FUNCTION__).warning("Unrecognised OpenGL ES version"); | - |
449 | } | 0 |
450 | } else { | - |
451 | | - |
452 | if (versionString.startsWith(QLatin1String("1."))) { never evaluated: versionString.startsWith(QLatin1String("1.")) | 0 |
453 | switch (versionString[2].toLatin1()) { | - |
454 | case '5': | - |
455 | versionFlags |= QGLFormat::OpenGL_Version_1_5; | - |
456 | case '4': code before this statement never executed: case '4': | 0 |
457 | versionFlags |= QGLFormat::OpenGL_Version_1_4; | - |
458 | case '3': code before this statement never executed: case '3': | 0 |
459 | versionFlags |= QGLFormat::OpenGL_Version_1_3; | - |
460 | case '2': code before this statement never executed: case '2': | 0 |
461 | versionFlags |= QGLFormat::OpenGL_Version_1_2; | - |
462 | case '1': code before this statement never executed: case '1': | 0 |
463 | versionFlags |= QGLFormat::OpenGL_Version_1_1; | - |
464 | default: | - |
465 | break; | 0 |
466 | } | - |
467 | } else if (versionString.startsWith(QLatin1String("2."))) { never evaluated: versionString.startsWith(QLatin1String("2.")) | 0 |
468 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - |
469 | QGLFormat::OpenGL_Version_1_2 | | - |
470 | QGLFormat::OpenGL_Version_1_3 | | - |
471 | QGLFormat::OpenGL_Version_1_4 | | - |
472 | QGLFormat::OpenGL_Version_1_5 | | - |
473 | QGLFormat::OpenGL_Version_2_0; | - |
474 | if (versionString[2].toLatin1() == '1') never evaluated: versionString[2].toLatin1() == '1' | 0 |
475 | versionFlags |= QGLFormat::OpenGL_Version_2_1; never executed: versionFlags |= QGLFormat::OpenGL_Version_2_1; | 0 |
476 | } else if (versionString.startsWith(QLatin1String("3."))) { never evaluated: versionString.startsWith(QLatin1String("3.")) | 0 |
477 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - |
478 | QGLFormat::OpenGL_Version_1_2 | | - |
479 | QGLFormat::OpenGL_Version_1_3 | | - |
480 | QGLFormat::OpenGL_Version_1_4 | | - |
481 | QGLFormat::OpenGL_Version_1_5 | | - |
482 | QGLFormat::OpenGL_Version_2_0 | | - |
483 | QGLFormat::OpenGL_Version_2_1 | | - |
484 | QGLFormat::OpenGL_Version_3_0; | - |
485 | switch (versionString[2].toLatin1()) { | - |
486 | case '3': | - |
487 | versionFlags |= QGLFormat::OpenGL_Version_3_3; | - |
488 | case '2': code before this statement never executed: case '2': | 0 |
489 | versionFlags |= QGLFormat::OpenGL_Version_3_2; | - |
490 | case '1': code before this statement never executed: case '1': | 0 |
491 | versionFlags |= QGLFormat::OpenGL_Version_3_1; | - |
492 | case '0': | - |
493 | break; | 0 |
494 | default: | - |
495 | versionFlags |= QGLFormat::OpenGL_Version_3_1 | | - |
496 | QGLFormat::OpenGL_Version_3_2 | | - |
497 | QGLFormat::OpenGL_Version_3_3; | - |
498 | break; | 0 |
499 | } | - |
500 | } else if (versionString.startsWith(QLatin1String("4."))) { never evaluated: versionString.startsWith(QLatin1String("4.")) | 0 |
501 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - |
502 | QGLFormat::OpenGL_Version_1_2 | | - |
503 | QGLFormat::OpenGL_Version_1_3 | | - |
504 | QGLFormat::OpenGL_Version_1_4 | | - |
505 | QGLFormat::OpenGL_Version_1_5 | | - |
506 | QGLFormat::OpenGL_Version_2_0 | | - |
507 | QGLFormat::OpenGL_Version_2_1 | | - |
508 | QGLFormat::OpenGL_Version_3_0 | | - |
509 | QGLFormat::OpenGL_Version_3_1 | | - |
510 | QGLFormat::OpenGL_Version_3_2 | | - |
511 | QGLFormat::OpenGL_Version_3_3 | | - |
512 | QGLFormat::OpenGL_Version_4_0; | - |
513 | switch (versionString[2].toLatin1()) { | - |
514 | case '3': | - |
515 | versionFlags |= QGLFormat::OpenGL_Version_4_3; | - |
516 | case '2': code before this statement never executed: case '2': | 0 |
517 | versionFlags |= QGLFormat::OpenGL_Version_4_2; | - |
518 | case '1': code before this statement never executed: case '1': | 0 |
519 | versionFlags |= QGLFormat::OpenGL_Version_4_1; | - |
520 | case '0': | - |
521 | break; | 0 |
522 | default: | - |
523 | versionFlags |= QGLFormat::OpenGL_Version_4_1 | | - |
524 | QGLFormat::OpenGL_Version_4_2 | | - |
525 | QGLFormat::OpenGL_Version_4_3; | - |
526 | break; | 0 |
527 | } | - |
528 | } else { | 0 |
529 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - |
530 | QGLFormat::OpenGL_Version_1_2 | | - |
531 | QGLFormat::OpenGL_Version_1_3 | | - |
532 | QGLFormat::OpenGL_Version_1_4 | | - |
533 | QGLFormat::OpenGL_Version_1_5 | | - |
534 | QGLFormat::OpenGL_Version_2_0 | | - |
535 | QGLFormat::OpenGL_Version_2_1 | | - |
536 | QGLFormat::OpenGL_Version_3_0 | | - |
537 | QGLFormat::OpenGL_Version_3_1 | | - |
538 | QGLFormat::OpenGL_Version_3_2 | | - |
539 | QGLFormat::OpenGL_Version_3_3 | | - |
540 | QGLFormat::OpenGL_Version_4_0 | | - |
541 | QGLFormat::OpenGL_Version_4_1 | | - |
542 | QGLFormat::OpenGL_Version_4_2 | | - |
543 | QGLFormat::OpenGL_Version_4_3; | - |
544 | } | 0 |
545 | } | - |
546 | return versionFlags; never executed: return versionFlags; | 0 |
547 | } | - |
548 | QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags() | - |
549 | { | - |
550 | static bool cachedDefault = false; | - |
551 | static OpenGLVersionFlags defaultVersionFlags = OpenGL_Version_None; | - |
552 | QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); | - |
553 | QGLTemporaryContext *tmpContext = 0; | - |
554 | | - |
555 | if (currentCtx && currentCtx->d_func()->version_flags_cached) never evaluated: currentCtx never evaluated: currentCtx->d_func()->version_flags_cached | 0 |
556 | return currentCtx->d_func()->version_flags; never executed: return currentCtx->d_func()->version_flags; | 0 |
557 | | - |
558 | if (!currentCtx) { never evaluated: !currentCtx | 0 |
559 | if (cachedDefault) { never evaluated: cachedDefault | 0 |
560 | return defaultVersionFlags; never executed: return defaultVersionFlags; | 0 |
561 | } else { | - |
562 | if (!hasOpenGL()) never evaluated: !hasOpenGL() | 0 |
563 | return defaultVersionFlags; never executed: return defaultVersionFlags; | 0 |
564 | tmpContext = new QGLTemporaryContext; | - |
565 | cachedDefault = true; | - |
566 | } | 0 |
567 | } | - |
568 | | - |
569 | QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(0x1F02)))); | - |
570 | OpenGLVersionFlags versionFlags = qOpenGLVersionFlagsFromString(versionString); | - |
571 | if (currentCtx) { never evaluated: currentCtx | 0 |
572 | currentCtx->d_func()->version_flags_cached = true; | - |
573 | currentCtx->d_func()->version_flags = versionFlags; | - |
574 | } | 0 |
575 | if (tmpContext) { never evaluated: tmpContext | 0 |
576 | defaultVersionFlags = versionFlags; | - |
577 | delete tmpContext; | - |
578 | } | 0 |
579 | | - |
580 | return versionFlags; never executed: return versionFlags; | 0 |
581 | } | - |
582 | QGLFormat QGLFormat::defaultFormat() | - |
583 | { | - |
584 | return *qgl_default_format(); never executed: return *qgl_default_format(); | 0 |
585 | } | - |
586 | void QGLFormat::setDefaultFormat(const QGLFormat &f) | - |
587 | { | - |
588 | *qgl_default_format() = f; | - |
589 | } | 0 |
590 | QGLFormat QGLFormat::defaultOverlayFormat() | - |
591 | { | - |
592 | return *defaultOverlayFormatInstance(); never executed: return *defaultOverlayFormatInstance(); | 0 |
593 | } | - |
594 | void QGLFormat::setDefaultOverlayFormat(const QGLFormat &f) | - |
595 | { | - |
596 | QGLFormat *defaultFormat = defaultOverlayFormatInstance(); | - |
597 | *defaultFormat = f; | - |
598 | | - |
599 | | - |
600 | | - |
601 | defaultFormat->setOverlay(false); | - |
602 | } | 0 |
603 | bool operator==(const QGLFormat& a, const QGLFormat& b) | - |
604 | { | - |
605 | return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts | 0 |
606 | && a.d->pln == b.d->pln | 0 |
607 | && a.d->alphaSize == b.d->alphaSize | 0 |
608 | && a.d->accumSize == b.d->accumSize | 0 |
609 | && a.d->stencilSize == b.d->stencilSize | 0 |
610 | && a.d->depthSize == b.d->depthSize | 0 |
611 | && a.d->redSize == b.d->redSize | 0 |
612 | && a.d->greenSize == b.d->greenSize | 0 |
613 | && a.d->blueSize == b.d->blueSize | 0 |
614 | && a.d->numSamples == b.d->numSamples | 0 |
615 | && a.d->swapInterval == b.d->swapInterval | 0 |
616 | && a.d->majorVersion == b.d->majorVersion | 0 |
617 | && a.d->minorVersion == b.d->minorVersion | 0 |
618 | && 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->redSize && a.d->greenSize == 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 |
619 | } | - |
620 | | - |
621 | | - |
622 | QDebug operator<<(QDebug dbg, const QGLFormat &f) | - |
623 | { | - |
624 | const QGLFormatPrivate * const d = f.d; | - |
625 | | - |
626 | dbg.nospace() << "QGLFormat(" | - |
627 | << "options " << d->opts | - |
628 | << ", plane " << d->pln | - |
629 | << ", depthBufferSize " << d->depthSize | - |
630 | << ", accumBufferSize " << d->accumSize | - |
631 | << ", stencilBufferSize " << d->stencilSize | - |
632 | << ", redBufferSize " << d->redSize | - |
633 | << ", greenBufferSize " << d->greenSize | - |
634 | << ", blueBufferSize " << d->blueSize | - |
635 | << ", alphaBufferSize " << d->alphaSize | - |
636 | << ", samples " << d->numSamples | - |
637 | << ", swapInterval " << d->swapInterval | - |
638 | << ", majorVersion " << d->majorVersion | - |
639 | << ", minorVersion " << d->minorVersion | - |
640 | << ", profile " << d->profile | - |
641 | << ')'; | - |
642 | | - |
643 | return dbg.space(); never executed: return dbg.space(); | 0 |
644 | } | - |
645 | bool operator!=(const QGLFormat& a, const QGLFormat& b) | - |
646 | { | - |
647 | return !(a == b); never executed: return !(a == b); | 0 |
648 | } | - |
649 | | - |
650 | struct QGLContextGroupList { | - |
651 | QGLContextGroupList() | - |
652 | : m_mutex(QMutex::Recursive) | - |
653 | { | - |
654 | } | 0 |
655 | | - |
656 | void append(QGLContextGroup *group) { | - |
657 | QMutexLocker locker(&m_mutex); | - |
658 | m_list.append(group); | - |
659 | } | 0 |
660 | | - |
661 | void remove(QGLContextGroup *group) { | - |
662 | QMutexLocker locker(&m_mutex); | - |
663 | m_list.removeOne(group); | - |
664 | } | 0 |
665 | | - |
666 | QList<QGLContextGroup *> m_list; | - |
667 | QMutex m_mutex; | - |
668 | }; | - |
669 | | - |
670 | static QGLContextGroupList *qt_context_groups() { static QGlobalStatic<QGLContextGroupList > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLContextGroupList *x = new QGLContextGroupList; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLContextGroupList > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
671 | | - |
672 | | - |
673 | | - |
674 | | - |
675 | | - |
676 | QGLContextGroup::QGLContextGroup(const QGLContext *context) | - |
677 | : m_context(context), m_refs(1) | - |
678 | { | - |
679 | qt_context_groups()->append(this); | - |
680 | } | 0 |
681 | | - |
682 | QGLContextGroup::~QGLContextGroup() | - |
683 | { | - |
684 | qt_context_groups()->remove(this); | - |
685 | } | 0 |
686 | | - |
687 | const QGLContext *qt_gl_transfer_context(const QGLContext *ctx) | - |
688 | { | - |
689 | if (!ctx) | 0 |
690 | return 0; never executed: return 0; | 0 |
691 | QList<const QGLContext *> shares | - |
692 | (QGLContextPrivate::contextGroup(ctx)->shares()); | - |
693 | if (shares.size() >= 2) never evaluated: shares.size() >= 2 | 0 |
694 | 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 |
695 | else | - |
696 | return 0; never executed: return 0; | 0 |
697 | } | - |
698 | | - |
699 | QGLContextPrivate::QGLContextPrivate(QGLContext *context) | - |
700 | : internal_context(false) | - |
701 | , q_ptr(context) | - |
702 | , texture_destroyer(0) | - |
703 | , functions(0) | - |
704 | { | - |
705 | group = new QGLContextGroup(context); | - |
706 | | - |
707 | if ((static_cast<QApplication *>(QCoreApplication::instance()))) { never evaluated: (static_cast<QApplication *>(QCoreApplication::instance())) | 0 |
708 | texture_destroyer = new QGLTextureDestroyer; | - |
709 | texture_destroyer->moveToThread((static_cast<QApplication *>(QCoreApplication::instance()))->thread()); | - |
710 | } | 0 |
711 | } | 0 |
712 | | - |
713 | QGLContextPrivate::~QGLContextPrivate() | - |
714 | { | - |
715 | delete functions; | - |
716 | | - |
717 | if (!group->m_refs.deref()) { never evaluated: !group->m_refs.deref() | 0 |
718 | qt_noop(); | - |
719 | delete group; | - |
720 | } | 0 |
721 | | - |
722 | delete texture_destroyer; | - |
723 | } | 0 |
724 | | - |
725 | void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) | - |
726 | { | - |
727 | QGLContext * const q = q_func(); | - |
728 | glFormat = reqFormat = format; | - |
729 | valid = false; | - |
730 | q->setDevice(dev); | - |
731 | | - |
732 | guiGlContext = 0; | - |
733 | ownContext = false; | - |
734 | fbo = 0; | - |
735 | crWin = false; | - |
736 | initDone = false; | - |
737 | sharing = false; | - |
738 | max_texture_size = -1; | - |
739 | version_flags_cached = false; | - |
740 | version_flags = QGLFormat::OpenGL_Version_None; | - |
741 | extension_flags_cached = false; | - |
742 | extension_flags = 0; | - |
743 | current_fbo = 0; | - |
744 | default_fbo = 0; | - |
745 | active_engine = 0; | - |
746 | workaround_needsFullClearOnEveryFrame = false; | - |
747 | workaround_brokenFBOReadBack = false; | - |
748 | workaround_brokenTexSubImage = false; | - |
749 | workaroundsCached = false; | - |
750 | | - |
751 | workaround_brokenTextureFromPixmap = false; | - |
752 | workaround_brokenTextureFromPixmap_init = false; | - |
753 | | - |
754 | workaround_brokenAlphaTexSubImage = false; | - |
755 | workaround_brokenAlphaTexSubImage_init = false; | - |
756 | | - |
757 | for (int i = 0; i < 3; ++i) | 0 |
758 | vertexAttributeArraysEnabledState[i] = false; never executed: vertexAttributeArraysEnabledState[i] = false; | 0 |
759 | } | 0 |
760 | | - |
761 | QGLContext* QGLContext::currentCtx = 0; | - |
762 | | - |
763 | | - |
764 | | - |
765 | | - |
766 | | - |
767 | | - |
768 | | - |
769 | static void convertFromGLImage(QImage &img, int w, int h, bool alpha_format, bool include_alpha) | - |
770 | { | - |
771 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian | 0 |
772 | | - |
773 | uint *p = (uint*)img.bits(); | - |
774 | uint *end = p + w*h; | - |
775 | if (alpha_format && include_alpha) { never evaluated: alpha_format never evaluated: include_alpha | 0 |
776 | while (p < end) { | 0 |
777 | uint a = *p << 24; | - |
778 | *p = (*p >> 8) | a; | - |
779 | p++; | - |
780 | } | 0 |
781 | } else { | 0 |
782 | | - |
783 | | - |
784 | while (p < end) { | 0 |
785 | *p = 0xff000000 | (*p>>8); | - |
786 | ++p; | - |
787 | } | 0 |
788 | } | 0 |
789 | } else { | - |
790 | | - |
791 | for (int y = 0; y < h; y++) { | 0 |
792 | uint *q = (uint*)img.scanLine(y); | - |
793 | for (int x=0; x < w; ++x) { | 0 |
794 | const uint pixel = *q; | - |
795 | if (alpha_format && include_alpha) { never evaluated: alpha_format never evaluated: include_alpha | 0 |
796 | *q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | - |
797 | | (pixel & 0xff00ff00); | - |
798 | } else { | 0 |
799 | *q = 0xff000000 | ((pixel << 16) & 0xff0000) | - |
800 | | ((pixel >> 16) & 0xff) | (pixel & 0x00ff00); | - |
801 | } | 0 |
802 | | - |
803 | q++; | - |
804 | } | 0 |
805 | } | 0 |
806 | | - |
807 | } | 0 |
808 | img = img.mirrored(); | - |
809 | } | 0 |
810 | | - |
811 | QImage qt_gl_read_frame_buffer(const QSize &size, bool alpha_format, bool include_alpha) | - |
812 | { | - |
813 | QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32_Premultiplied | - |
814 | : QImage::Format_RGB32); | - |
815 | int w = size.width(); | - |
816 | int h = size.height(); | - |
817 | glReadPixels(0, 0, w, h, 0x1908, 0x1401, img.bits()); | - |
818 | convertFromGLImage(img, w, h, alpha_format, include_alpha); | - |
819 | return img; never executed: return img; | 0 |
820 | } | - |
821 | | - |
822 | QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha) | - |
823 | { | - |
824 | QImage img(size, alpha_format ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); | - |
825 | int w = size.width(); | - |
826 | int h = size.height(); | - |
827 | | - |
828 | | - |
829 | glGetTexImage(0x0DE1, 0, 0x1908, 0x1401, img.bits()); | - |
830 | | - |
831 | convertFromGLImage(img, w, h, alpha_format, include_alpha); | - |
832 | return img; never executed: return img; | 0 |
833 | } | - |
834 | | - |
835 | | - |
836 | | - |
837 | int qt_next_power_of_two(int v) | - |
838 | { | - |
839 | v--; | - |
840 | v |= v >> 1; | - |
841 | v |= v >> 2; | - |
842 | v |= v >> 4; | - |
843 | v |= v >> 8; | - |
844 | v |= v >> 16; | - |
845 | ++v; | - |
846 | return v; never executed: return v; | 0 |
847 | } | - |
848 | | - |
849 | static QGLTextureCache *qt_gl_texture_cache() { static QGlobalStatic<QGLTextureCache > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLTextureCache *x = new QGLTextureCache; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLTextureCache > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
850 | | - |
851 | QGLTextureCache::QGLTextureCache() | - |
852 | : m_cache(64*1024) | - |
853 | { | - |
854 | QImagePixmapCleanupHooks::instance()->addPlatformPixmapModificationHook(cleanupTexturesForPixampData); | - |
855 | QImagePixmapCleanupHooks::instance()->addPlatformPixmapDestructionHook(cleanupBeforePixmapDestruction); | - |
856 | QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey); | - |
857 | } | 0 |
858 | | - |
859 | QGLTextureCache::~QGLTextureCache() | - |
860 | { | - |
861 | QImagePixmapCleanupHooks::instance()->removePlatformPixmapModificationHook(cleanupTexturesForPixampData); | - |
862 | QImagePixmapCleanupHooks::instance()->removePlatformPixmapDestructionHook(cleanupBeforePixmapDestruction); | - |
863 | QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey); | - |
864 | } | 0 |
865 | | - |
866 | void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost) | - |
867 | { | - |
868 | QWriteLocker locker(&m_lock); | - |
869 | const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)}; | - |
870 | m_cache.insert(cacheKey, texture, cost); | - |
871 | } | 0 |
872 | | - |
873 | void QGLTextureCache::remove(qint64 key) | - |
874 | { | - |
875 | QWriteLocker locker(&m_lock); | - |
876 | QMutexLocker groupLocker(&qt_context_groups()->m_mutex); | - |
877 | QList<QGLContextGroup *>::const_iterator it = qt_context_groups()->m_list.constBegin(); | - |
878 | while (it != qt_context_groups()->m_list.constEnd()) { never evaluated: it != qt_context_groups()->m_list.constEnd() | 0 |
879 | const QGLTextureCacheKey cacheKey = {key, *it}; | - |
880 | m_cache.remove(cacheKey); | - |
881 | ++it; | - |
882 | } | 0 |
883 | } | 0 |
884 | | - |
885 | bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId) | - |
886 | { | - |
887 | QWriteLocker locker(&m_lock); | - |
888 | QList<QGLTextureCacheKey> keys = m_cache.keys(); | - |
889 | for (int i = 0; i < keys.size(); ++i) { never evaluated: i < keys.size() | 0 |
890 | QGLTexture *tex = m_cache.object(keys.at(i)); | - |
891 | if (tex->id == textureId && tex->context == ctx) { never evaluated: tex->id == textureId never evaluated: tex->context == ctx | 0 |
892 | tex->options |= QGLContext::MemoryManagedBindOption; | - |
893 | m_cache.remove(keys.at(i)); | - |
894 | return true; never executed: return true; | 0 |
895 | } | - |
896 | } | 0 |
897 | return false; never executed: return false; | 0 |
898 | } | - |
899 | | - |
900 | void QGLTextureCache::removeContextTextures(QGLContext* ctx) | - |
901 | { | - |
902 | QWriteLocker locker(&m_lock); | - |
903 | QList<QGLTextureCacheKey> keys = m_cache.keys(); | - |
904 | for (int i = 0; i < keys.size(); ++i) { never evaluated: i < keys.size() | 0 |
905 | const QGLTextureCacheKey &key = keys.at(i); | - |
906 | if (m_cache.object(key)->context == ctx) never evaluated: m_cache.object(key)->context == ctx | 0 |
907 | m_cache.remove(key); never executed: m_cache.remove(key); | 0 |
908 | } | 0 |
909 | } | 0 |
910 | | - |
911 | | - |
912 | | - |
913 | | - |
914 | | - |
915 | void QGLTextureCache::cleanupTexturesForCacheKey(qint64 cacheKey) | - |
916 | { | - |
917 | qt_gl_texture_cache()->remove(cacheKey); | - |
918 | } | 0 |
919 | | - |
920 | | - |
921 | void QGLTextureCache::cleanupTexturesForPixampData(QPlatformPixmap* pmd) | - |
922 | { | - |
923 | cleanupTexturesForCacheKey(pmd->cacheKey()); | - |
924 | } | 0 |
925 | | - |
926 | void QGLTextureCache::cleanupBeforePixmapDestruction(QPlatformPixmap* pmd) | - |
927 | { | - |
928 | | - |
929 | cleanupTexturesForPixampData(pmd); | - |
930 | } | 0 |
931 | | - |
932 | QGLTextureCache *QGLTextureCache::instance() | - |
933 | { | - |
934 | return qt_gl_texture_cache(); never executed: return qt_gl_texture_cache(); | 0 |
935 | } | - |
936 | | - |
937 | | - |
938 | struct DDSFormat { | - |
939 | quint32 dwSize; | - |
940 | quint32 dwFlags; | - |
941 | quint32 dwHeight; | - |
942 | quint32 dwWidth; | - |
943 | quint32 dwLinearSize; | - |
944 | quint32 dummy1; | - |
945 | quint32 dwMipMapCount; | - |
946 | quint32 dummy2[11]; | - |
947 | struct { | - |
948 | quint32 dummy3[2]; | - |
949 | quint32 dwFourCC; | - |
950 | quint32 dummy4[5]; | - |
951 | } ddsPixelFormat; | - |
952 | }; | - |
953 | QGLContext::QGLContext(const QGLFormat &format, QPaintDevice *device) | - |
954 | : d_ptr(new QGLContextPrivate(this)) | - |
955 | { | - |
956 | QGLContextPrivate * const d = d_func(); | - |
957 | d->init(device, format); | - |
958 | } | 0 |
959 | QGLContext::QGLContext(const QGLFormat &format) | - |
960 | : d_ptr(new QGLContextPrivate(this)) | - |
961 | { | - |
962 | QGLContextPrivate * const d = d_func(); | - |
963 | d->init(0, format); | - |
964 | } | 0 |
965 | | - |
966 | | - |
967 | | - |
968 | | - |
969 | | - |
970 | QGLContext::~QGLContext() | - |
971 | { | - |
972 | | - |
973 | QGLTextureCache::instance()->removeContextTextures(this); | - |
974 | | - |
975 | | - |
976 | d_ptr->cleanup(); | - |
977 | | - |
978 | QGLSignalProxy::instance()->emitAboutToDestroyContext(this); | - |
979 | reset(); | - |
980 | } | 0 |
981 | | - |
982 | void QGLContextPrivate::cleanup() | - |
983 | { | - |
984 | } | - |
985 | | - |
986 | | - |
987 | void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) | - |
988 | { | - |
989 | qt_noop(); | - |
990 | | - |
991 | qt_noop(); | - |
992 | | - |
993 | | - |
994 | if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled) never evaluated: vertexAttributeArraysEnabledState[arrayIndex] never evaluated: !enabled | 0 |
995 | QGLContextPrivate::extensionFuncs(q_ptr).qt_glDisableVertexAttribArray(arrayIndex); never executed: QGLContextPrivate::extensionFuncs(q_ptr).qt_glDisableVertexAttribArray(arrayIndex); | 0 |
996 | | - |
997 | if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled) never evaluated: !vertexAttributeArraysEnabledState[arrayIndex] | 0 |
998 | QGLContextPrivate::extensionFuncs(q_ptr).qt_glEnableVertexAttribArray(arrayIndex); never executed: QGLContextPrivate::extensionFuncs(q_ptr).qt_glEnableVertexAttribArray(arrayIndex); | 0 |
999 | | - |
1000 | vertexAttributeArraysEnabledState[arrayIndex] = enabled; | - |
1001 | } | 0 |
1002 | | - |
1003 | void QGLContextPrivate::syncGlState() | - |
1004 | { | - |
1005 | | - |
1006 | qt_noop(); | - |
1007 | | - |
1008 | for (int i = 0; i < 3; ++i) { | 0 |
1009 | if (vertexAttributeArraysEnabledState[i]) never evaluated: vertexAttributeArraysEnabledState[i] | 0 |
1010 | QGLContextPrivate::extensionFuncs(q_ptr).qt_glEnableVertexAttribArray(i); never executed: QGLContextPrivate::extensionFuncs(q_ptr).qt_glEnableVertexAttribArray(i); | 0 |
1011 | else | - |
1012 | QGLContextPrivate::extensionFuncs(q_ptr).qt_glDisableVertexAttribArray(i); never executed: QGLContextPrivate::extensionFuncs(q_ptr).qt_glDisableVertexAttribArray(i); | 0 |
1013 | } | - |
1014 | | - |
1015 | } | 0 |
1016 | | - |
1017 | | - |
1018 | void QGLContextPrivate::swapRegion(const QRegion &) | - |
1019 | { | - |
1020 | QGLContext * const q = q_func(); | - |
1021 | q->swapBuffers(); | - |
1022 | } | 0 |
1023 | GLuint QGLContext::bindTexture(const QString &fileName) | - |
1024 | { | - |
1025 | QGLTexture texture(this); | - |
1026 | QSize size = texture.bindCompressedTexture(fileName); | - |
1027 | if (!size.isValid()) never evaluated: !size.isValid() | 0 |
1028 | return 0; never executed: return 0; | 0 |
1029 | return texture.id; never executed: return texture.id; | 0 |
1030 | } | - |
1031 | | - |
1032 | static inline QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format) | - |
1033 | { | - |
1034 | if (texture_format == 0x80E1) { never evaluated: texture_format == 0x80E1 | 0 |
1035 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian | 0 |
1036 | return ((src_pixel << 24) & 0xff000000) | 0 |
1037 | | ((src_pixel >> 24) & 0x000000ff) | 0 |
1038 | | ((src_pixel << 8) & 0x00ff0000) | 0 |
1039 | | ((src_pixel >> 8) & 0x0000ff00); never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 |
1040 | } else { | - |
1041 | return src_pixel; never executed: return src_pixel; | 0 |
1042 | } | - |
1043 | } else { | - |
1044 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian | 0 |
1045 | return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); never executed: return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); | 0 |
1046 | } else { | - |
1047 | return ((src_pixel << 16) & 0xff0000) | 0 |
1048 | | ((src_pixel >> 16) & 0xff) | 0 |
1049 | | (src_pixel & 0xff00ff00); never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 |
1050 | } | - |
1051 | } | - |
1052 | } | - |
1053 | | - |
1054 | QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format) | - |
1055 | { | - |
1056 | return qt_gl_convertToGLFormatHelper(src_pixel, texture_format); never executed: return qt_gl_convertToGLFormatHelper(src_pixel, texture_format); | 0 |
1057 | } | - |
1058 | | - |
1059 | static void convertToGLFormatHelper(QImage &dst, const QImage &img, GLenum texture_format) | - |
1060 | { | - |
1061 | qt_noop(); | - |
1062 | qt_noop(); | - |
1063 | | - |
1064 | if (dst.size() != img.size()) { never evaluated: dst.size() != img.size() | 0 |
1065 | int target_width = dst.width(); | - |
1066 | int target_height = dst.height(); | - |
1067 | qreal sx = target_width / qreal(img.width()); | - |
1068 | qreal sy = target_height / qreal(img.height()); | - |
1069 | | - |
1070 | quint32 *dest = (quint32 *) dst.scanLine(0); | - |
1071 | uchar *srcPixels = (uchar *) img.scanLine(img.height() - 1); | - |
1072 | int sbpl = img.bytesPerLine(); | - |
1073 | int dbpl = dst.bytesPerLine(); | - |
1074 | | - |
1075 | int ix = int(0x00010000 / sx); | - |
1076 | int iy = int(0x00010000 / sy); | - |
1077 | | - |
1078 | quint32 basex = int(0.5 * ix); | - |
1079 | quint32 srcy = int(0.5 * iy); | - |
1080 | | - |
1081 | | - |
1082 | while (target_height--) { never evaluated: target_height-- | 0 |
1083 | const uint *src = (const quint32 *) (srcPixels - (srcy >> 16) * sbpl); | - |
1084 | int srcx = basex; | - |
1085 | for (int x=0; x<target_width; ++x) { never evaluated: x<target_width | 0 |
1086 | dest[x] = qt_gl_convertToGLFormatHelper(src[srcx >> 16], texture_format); | - |
1087 | srcx += ix; | - |
1088 | } | 0 |
1089 | dest = (quint32 *)(((uchar *) dest) + dbpl); | - |
1090 | srcy += iy; | - |
1091 | } | 0 |
1092 | } else { | 0 |
1093 | const int width = img.width(); | - |
1094 | const int height = img.height(); | - |
1095 | const uint *p = (const uint*) img.scanLine(img.height() - 1); | - |
1096 | uint *q = (uint*) dst.scanLine(0); | - |
1097 | | - |
1098 | if (texture_format == 0x80E1) { never evaluated: texture_format == 0x80E1 | 0 |
1099 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian | 0 |
1100 | | - |
1101 | for (int i=0; i < height; ++i) { never evaluated: i < height | 0 |
1102 | const uint *end = p + width; | - |
1103 | while (p < end) { | 0 |
1104 | *q = ((*p << 24) & 0xff000000) | - |
1105 | | ((*p >> 24) & 0x000000ff) | - |
1106 | | ((*p << 8) & 0x00ff0000) | - |
1107 | | ((*p >> 8) & 0x0000ff00); | - |
1108 | p++; | - |
1109 | q++; | - |
1110 | } | 0 |
1111 | p -= 2 * width; | - |
1112 | } | 0 |
1113 | } else { | 0 |
1114 | const uint bytesPerLine = img.bytesPerLine(); | - |
1115 | for (int i=0; i < height; ++i) { never evaluated: i < height | 0 |
1116 | memcpy(q, p, bytesPerLine); | - |
1117 | q += width; | - |
1118 | p -= width; | - |
1119 | } | 0 |
1120 | } | 0 |
1121 | } else { | - |
1122 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian | 0 |
1123 | for (int i=0; i < height; ++i) { never evaluated: i < height | 0 |
1124 | const uint *end = p + width; | - |
1125 | while (p < end) { | 0 |
1126 | *q = (*p << 8) | ((*p >> 24) & 0xff); | - |
1127 | p++; | - |
1128 | q++; | - |
1129 | } | 0 |
1130 | p -= 2 * width; | - |
1131 | } | 0 |
1132 | } else { | 0 |
1133 | for (int i=0; i < height; ++i) { never evaluated: i < height | 0 |
1134 | const uint *end = p + width; | - |
1135 | while (p < end) { | 0 |
1136 | *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00); | - |
1137 | p++; | - |
1138 | q++; | - |
1139 | } | 0 |
1140 | p -= 2 * width; | - |
1141 | } | 0 |
1142 | } | 0 |
1143 | } | - |
1144 | } | - |
1145 | } | - |
1146 | | - |
1147 | QGLExtensionFuncs& QGLContextPrivate::extensionFuncs(const QGLContext *) | - |
1148 | { | - |
1149 | return qt_extensionFuncs; never executed: return qt_extensionFuncs; | 0 |
1150 | } | - |
1151 | | - |
1152 | QImage QGLContextPrivate::convertToGLFormat(const QImage &image, bool force_premul, | - |
1153 | GLenum texture_format) | - |
1154 | { | - |
1155 | QImage::Format target_format = image.format(); | - |
1156 | if (force_premul || image.format() != QImage::Format_ARGB32) never evaluated: force_premul never evaluated: image.format() != QImage::Format_ARGB32 | 0 |
1157 | target_format = QImage::Format_ARGB32_Premultiplied; never executed: target_format = QImage::Format_ARGB32_Premultiplied; | 0 |
1158 | | - |
1159 | QImage result(image.width(), image.height(), target_format); | - |
1160 | convertToGLFormatHelper(result, image.convertToFormat(target_format), texture_format); | - |
1161 | return result; never executed: return result; | 0 |
1162 | } | - |
1163 | | - |
1164 | | - |
1165 | QGLTexture *QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint format, | - |
1166 | QGLContext::BindOptions options) | - |
1167 | { | - |
1168 | QGLContext * const q = q_func(); | - |
1169 | | - |
1170 | const qint64 key = image.cacheKey(); | - |
1171 | QGLTexture *texture = textureCacheLookup(key, target); | - |
1172 | if (texture) { | 0 |
1173 | if (image.paintingActive()) { never evaluated: image.paintingActive() | 0 |
1174 | | - |
1175 | q->deleteTexture(texture->id); | - |
1176 | texture = 0; | - |
1177 | } else { | 0 |
1178 | glBindTexture(target, texture->id); | - |
1179 | return texture; never executed: return texture; | 0 |
1180 | } | - |
1181 | } | - |
1182 | | - |
1183 | if (!texture) never evaluated: !texture | 0 |
1184 | texture = bindTexture(image, target, format, key, options); never executed: texture = bindTexture(image, target, format, key, options); | 0 |
1185 | | - |
1186 | qt_noop(); | - |
1187 | | - |
1188 | | - |
1189 | | - |
1190 | QImagePixmapCleanupHooks::enableCleanupHooks(image); | - |
1191 | | - |
1192 | return texture; never executed: return texture; | 0 |
1193 | } | - |
1194 | static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type) | - |
1195 | { | - |
1196 | const int width = img.width(); | - |
1197 | const int height = img.height(); | - |
1198 | | - |
1199 | if (pixel_type == 0x8367 never evaluated: pixel_type == 0x8367 | 0 |
1200 | || (pixel_type == 0x1401 && QSysInfo::ByteOrder == QSysInfo::LittleEndian)) never evaluated: pixel_type == 0x1401 never evaluated: QSysInfo::ByteOrder == QSysInfo::LittleEndian | 0 |
1201 | { | - |
1202 | for (int i = 0; i < height; ++i) { never evaluated: i < height | 0 |
1203 | uint *p = (uint *) img.scanLine(i); | - |
1204 | for (int x = 0; x < width; ++x) never evaluated: x < width | 0 |
1205 | 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 |
1206 | } | 0 |
1207 | } else { | 0 |
1208 | for (int i = 0; i < height; ++i) { never evaluated: i < height | 0 |
1209 | uint *p = (uint *) img.scanLine(i); | - |
1210 | for (int x = 0; x < width; ++x) never evaluated: x < width | 0 |
1211 | p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); never executed: p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); | 0 |
1212 | } | 0 |
1213 | } | 0 |
1214 | } | - |
1215 | | - |
1216 | QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint internalFormat, | - |
1217 | const qint64 key, QGLContext::BindOptions options) | - |
1218 | { | - |
1219 | QGLContext * const q = q_func(); | - |
1220 | int tx_w = qt_next_power_of_two(image.width()); | - |
1221 | int tx_h = qt_next_power_of_two(image.height()); | - |
1222 | | - |
1223 | QImage img = image; | - |
1224 | | - |
1225 | if (!(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures) never evaluated: !(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures) | 0 |
1226 | && !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0) never evaluated: !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0) | 0 |
1227 | && (target == 0x0DE1 && (tx_w != image.width() || tx_h != image.height()))) never evaluated: target == 0x0DE1 never evaluated: tx_w != image.width() never evaluated: tx_h != image.height() | 0 |
1228 | { | - |
1229 | img = img.scaled(tx_w, tx_h); | - |
1230 | | - |
1231 | | - |
1232 | | - |
1233 | | - |
1234 | } | 0 |
1235 | | - |
1236 | GLuint filtering = options & QGLContext::LinearFilteringBindOption ? 0x2601 : 0x2600; never evaluated: options & QGLContext::LinearFilteringBindOption | 0 |
1237 | | - |
1238 | GLuint tx_id; | - |
1239 | glGenTextures(1, &tx_id); | - |
1240 | glBindTexture(target, tx_id); | - |
1241 | glTexParameteri(target, 0x2800, filtering); | - |
1242 | | - |
1243 | | - |
1244 | | - |
1245 | | - |
1246 | if (glFormat.directRendering() never evaluated: glFormat.directRendering() | 0 |
1247 | && (QGLExtensions::glExtensions() & QGLExtensions::GenerateMipmap) never evaluated: (QGLExtensions::glExtensions() & QGLExtensions::GenerateMipmap) | 0 |
1248 | && target == 0x0DE1 never evaluated: target == 0x0DE1 | 0 |
1249 | && (options & QGLContext::MipmapBindOption)) never evaluated: (options & QGLContext::MipmapBindOption) | 0 |
1250 | { | - |
1251 | | - |
1252 | glHint(0x8192, 0x1102); | - |
1253 | glTexParameteri(target, 0x8191, 0x1); | - |
1254 | | - |
1255 | | - |
1256 | | - |
1257 | | - |
1258 | glTexParameteri(target, 0x2801, options & QGLContext::LinearFilteringBindOption | - |
1259 | ? 0x2703 : 0x2700); | - |
1260 | | - |
1261 | | - |
1262 | | - |
1263 | } else { | 0 |
1264 | glTexParameteri(target, 0x2801, filtering); | - |
1265 | } | 0 |
1266 | | - |
1267 | QImage::Format target_format = img.format(); | - |
1268 | bool premul = options & QGLContext::PremultipliedAlphaBindOption; | - |
1269 | GLenum externalFormat; | - |
1270 | GLuint pixel_type; | - |
1271 | if (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) { never evaluated: QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat | 0 |
1272 | externalFormat = 0x80E1; | - |
1273 | if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2) never evaluated: QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 | 0 |
1274 | pixel_type = 0x8367; never executed: pixel_type = 0x8367; | 0 |
1275 | else | - |
1276 | pixel_type = 0x1401; never executed: pixel_type = 0x1401; | 0 |
1277 | } else { | - |
1278 | externalFormat = 0x1908; | - |
1279 | pixel_type = 0x1401; | - |
1280 | } | 0 |
1281 | | - |
1282 | switch (target_format) { | - |
1283 | case QImage::Format_ARGB32: | - |
1284 | if (premul) { | 0 |
1285 | img = img.convertToFormat(target_format = QImage::Format_ARGB32_Premultiplied); | - |
1286 | | - |
1287 | | - |
1288 | | - |
1289 | } | 0 |
1290 | break; | 0 |
1291 | case QImage::Format_ARGB32_Premultiplied: | - |
1292 | if (!premul) { | 0 |
1293 | img = img.convertToFormat(target_format = QImage::Format_ARGB32); | - |
1294 | | - |
1295 | | - |
1296 | | - |
1297 | } | 0 |
1298 | break; | 0 |
1299 | case QImage::Format_RGB16: | - |
1300 | pixel_type = 0x8363; | - |
1301 | externalFormat = 0x1907; | - |
1302 | internalFormat = 0x1907; | - |
1303 | break; | 0 |
1304 | case QImage::Format_RGB32: | - |
1305 | break; | 0 |
1306 | default: | - |
1307 | if (img.hasAlphaChannel()) { never evaluated: img.hasAlphaChannel() | 0 |
1308 | img = img.convertToFormat(premul | - |
1309 | ? QImage::Format_ARGB32_Premultiplied | - |
1310 | : QImage::Format_ARGB32); | - |
1311 | | - |
1312 | | - |
1313 | | - |
1314 | } else { | 0 |
1315 | img = img.convertToFormat(QImage::Format_RGB32); | - |
1316 | | - |
1317 | | - |
1318 | | - |
1319 | } | 0 |
1320 | } | - |
1321 | | - |
1322 | if (options & QGLContext::InvertedYBindOption) { never evaluated: options & QGLContext::InvertedYBindOption | 0 |
1323 | if (img.isDetached()) { never evaluated: img.isDetached() | 0 |
1324 | int ipl = img.bytesPerLine() / 4; | - |
1325 | int h = img.height(); | - |
1326 | for (int y=0; y<h/2; ++y) { | 0 |
1327 | int *a = (int *) img.scanLine(y); | - |
1328 | int *b = (int *) img.scanLine(h - y - 1); | - |
1329 | for (int x=0; x<ipl; ++x) | 0 |
1330 | qSwap(a[x], b[x]); never executed: qSwap(a[x], b[x]); | 0 |
1331 | } | 0 |
1332 | } else { | 0 |
1333 | | - |
1334 | | - |
1335 | | - |
1336 | | - |
1337 | img = img.mirrored(); | - |
1338 | } | 0 |
1339 | | - |
1340 | | - |
1341 | | - |
1342 | } | - |
1343 | | - |
1344 | if (externalFormat == 0x1908) { never evaluated: externalFormat == 0x1908 | 0 |
1345 | | - |
1346 | | - |
1347 | | - |
1348 | qt_noop(); | - |
1349 | qgl_byteSwapImage(img, pixel_type); | - |
1350 | | - |
1351 | | - |
1352 | | - |
1353 | } | 0 |
1354 | const QImage &constRef = img; | - |
1355 | glTexImage2D(target, 0, internalFormat, img.width(), img.height(), 0, externalFormat, | - |
1356 | pixel_type, constRef.bits()); | - |
1357 | int cost = img.width()*img.height()*4/1024; | - |
1358 | QGLTexture *texture = new QGLTexture(q, tx_id, target, options); | - |
1359 | QGLTextureCache::instance()->insert(q, key, texture, cost); | - |
1360 | | - |
1361 | return texture; never executed: return texture; | 0 |
1362 | } | - |
1363 | | - |
1364 | QGLTexture *QGLContextPrivate::textureCacheLookup(const qint64 key, GLenum target) | - |
1365 | { | - |
1366 | QGLContext * const q = q_func(); | - |
1367 | QGLTexture *texture = QGLTextureCache::instance()->getTexture(q, key); | - |
1368 | if (texture && texture->target == target never evaluated: texture->target == target | 0 |
1369 | && (texture->context == q || QGLContext::areSharing(q, texture->context))) never evaluated: texture->context == q never evaluated: QGLContext::areSharing(q, texture->context) | 0 |
1370 | { | - |
1371 | return texture; never executed: return texture; | 0 |
1372 | } | - |
1373 | return 0; never executed: return 0; | 0 |
1374 | } | - |
1375 | | - |
1376 | | - |
1377 | QGLTexture *QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, QGLContext::BindOptions options) | - |
1378 | { | - |
1379 | QGLContext * const q = q_func(); | - |
1380 | QPlatformPixmap *pd = pixmap.handle(); | - |
1381 | (void)pd;; | - |
1382 | | - |
1383 | const qint64 key = pixmap.cacheKey(); | - |
1384 | QGLTexture *texture = textureCacheLookup(key, target); | - |
1385 | if (texture) { | 0 |
1386 | if (pixmap.paintingActive()) { never evaluated: pixmap.paintingActive() | 0 |
1387 | | - |
1388 | q->deleteTexture(texture->id); | - |
1389 | texture = 0; | - |
1390 | } else { | 0 |
1391 | glBindTexture(target, texture->id); | - |
1392 | return texture; never executed: return texture; | 0 |
1393 | } | - |
1394 | } | - |
1395 | | - |
1396 | if (!texture) { never evaluated: !texture | 0 |
1397 | QImage image = pixmap.toImage(); | - |
1398 | | - |
1399 | | - |
1400 | | - |
1401 | if (pixmap.depth() == 16 && !image.hasAlphaChannel() ) never evaluated: pixmap.depth() == 16 never evaluated: !image.hasAlphaChannel() | 0 |
1402 | image = image.convertToFormat(QImage::Format_RGB16); never executed: image = image.convertToFormat(QImage::Format_RGB16); | 0 |
1403 | texture = bindTexture(image, target, format, key, options); | - |
1404 | } | 0 |
1405 | | - |
1406 | qt_noop(); | - |
1407 | | - |
1408 | if (texture->id > 0) never evaluated: texture->id > 0 | 0 |
1409 | QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); never executed: QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); | 0 |
1410 | | - |
1411 | return texture; never executed: return texture; | 0 |
1412 | } | - |
1413 | | - |
1414 | | - |
1415 | int QGLContextPrivate::maxTextureSize() | - |
1416 | { | - |
1417 | if (max_texture_size != -1) never evaluated: max_texture_size != -1 | 0 |
1418 | return max_texture_size; never executed: return max_texture_size; | 0 |
1419 | | - |
1420 | glGetIntegerv(0x0D33, &max_texture_size); | - |
1421 | | - |
1422 | | - |
1423 | | - |
1424 | | - |
1425 | GLenum proxy = 0x8064; | - |
1426 | | - |
1427 | GLint size; | - |
1428 | GLint next = 64; | - |
1429 | glTexImage2D(proxy, 0, 0x1908, next, next, 0, 0x1908, 0x1401, 0); | - |
1430 | glGetTexLevelParameteriv(proxy, 0, 0x1000, &size); | - |
1431 | if (size == 0) { never evaluated: size == 0 | 0 |
1432 | return max_texture_size; never executed: return max_texture_size; | 0 |
1433 | } | - |
1434 | do { | - |
1435 | size = next; | - |
1436 | next = size * 2; | - |
1437 | | - |
1438 | if (next > max_texture_size) never evaluated: next > max_texture_size | 0 |
1439 | break; | 0 |
1440 | glTexImage2D(proxy, 0, 0x1908, next, next, 0, 0x1908, 0x1401, 0); | - |
1441 | glGetTexLevelParameteriv(proxy, 0, 0x1000, &next); | - |
1442 | } while (next > size); never evaluated: next > size | 0 |
1443 | | - |
1444 | max_texture_size = size; | - |
1445 | return max_texture_size; never executed: return max_texture_size; | 0 |
1446 | | - |
1447 | } | - |
1448 | | - |
1449 | | - |
1450 | | - |
1451 | | - |
1452 | QGLFunctions *QGLContext::functions() const | - |
1453 | { | - |
1454 | QGLContextPrivate *d = const_cast<QGLContextPrivate *>(d_func()); | - |
1455 | if (!d->functions) { never evaluated: !d->functions | 0 |
1456 | d->functions = new QGLFunctions(this); | - |
1457 | d->functions->initializeGLFunctions(this); | - |
1458 | } | 0 |
1459 | return d->functions; never executed: return d->functions; | 0 |
1460 | } | - |
1461 | GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format) | - |
1462 | { | - |
1463 | if (image.isNull()) never evaluated: image.isNull() | 0 |
1464 | return 0; never executed: return 0; | 0 |
1465 | | - |
1466 | QGLContextPrivate * const d = d_func(); | - |
1467 | QGLTexture *texture = d->bindTexture(image, target, format, DefaultBindOption); | - |
1468 | return texture->id; never executed: return texture->id; | 0 |
1469 | } | - |
1470 | GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format, BindOptions options) | - |
1471 | { | - |
1472 | if (image.isNull()) never evaluated: image.isNull() | 0 |
1473 | return 0; never executed: return 0; | 0 |
1474 | | - |
1475 | QGLContextPrivate * const d = d_func(); | - |
1476 | QGLTexture *texture = d->bindTexture(image, target, format, options); | - |
1477 | return texture->id; never executed: return texture->id; | 0 |
1478 | } | - |
1479 | | - |
1480 | | - |
1481 | | - |
1482 | | - |
1483 | | - |
1484 | GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) | - |
1485 | { | - |
1486 | if (pixmap.isNull()) never evaluated: pixmap.isNull() | 0 |
1487 | return 0; never executed: return 0; | 0 |
1488 | | - |
1489 | QGLContextPrivate * const d = d_func(); | - |
1490 | QGLTexture *texture = d->bindTexture(pixmap, target, format, DefaultBindOption); | - |
1491 | return texture->id; never executed: return texture->id; | 0 |
1492 | } | - |
1493 | GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, BindOptions options) | - |
1494 | { | - |
1495 | if (pixmap.isNull()) never evaluated: pixmap.isNull() | 0 |
1496 | return 0; never executed: return 0; | 0 |
1497 | | - |
1498 | QGLContextPrivate * const d = d_func(); | - |
1499 | QGLTexture *texture = d->bindTexture(pixmap, target, format, options); | - |
1500 | return texture->id; never executed: return texture->id; | 0 |
1501 | } | - |
1502 | void QGLContext::deleteTexture(GLuint id) | - |
1503 | { | - |
1504 | if (QGLTextureCache::instance()->remove(this, id)) never evaluated: QGLTextureCache::instance()->remove(this, id) | 0 |
1505 | return; | 0 |
1506 | glDeleteTextures(1, &id); | - |
1507 | } | 0 |
1508 | | - |
1509 | void qt_add_rect_to_array(const QRectF &r, GLfloat *array) | - |
1510 | { | - |
1511 | qreal left = r.left(); | - |
1512 | qreal right = r.right(); | - |
1513 | qreal top = r.top(); | - |
1514 | qreal bottom = r.bottom(); | - |
1515 | | - |
1516 | array[0] = left; | - |
1517 | array[1] = top; | - |
1518 | array[2] = right; | - |
1519 | array[3] = top; | - |
1520 | array[4] = right; | - |
1521 | array[5] = bottom; | - |
1522 | array[6] = left; | - |
1523 | array[7] = bottom; | - |
1524 | } | 0 |
1525 | | - |
1526 | void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array) | - |
1527 | { | - |
1528 | array[0] = x1; | - |
1529 | array[1] = y1; | - |
1530 | array[2] = x2; | - |
1531 | array[3] = y1; | - |
1532 | array[4] = x2; | - |
1533 | array[5] = y2; | - |
1534 | array[6] = x1; | - |
1535 | array[7] = y2; | - |
1536 | } | 0 |
1537 | | - |
1538 | | - |
1539 | | - |
1540 | static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget) | - |
1541 | { | - |
1542 | GLfloat tx = 1.0f; | - |
1543 | GLfloat ty = 1.0f; | - |
1544 | | - |
1545 | | - |
1546 | | - |
1547 | | - |
1548 | | - |
1549 | | - |
1550 | if (textureTarget != 0x0DE1) { never evaluated: textureTarget != 0x0DE1 | 0 |
1551 | if (textureWidth == -1 || textureHeight == -1) { never evaluated: textureWidth == -1 never evaluated: textureHeight == -1 | 0 |
1552 | glGetTexLevelParameteriv(textureTarget, 0, 0x1000, &textureWidth); | - |
1553 | glGetTexLevelParameteriv(textureTarget, 0, 0x1001, &textureHeight); | - |
1554 | } | 0 |
1555 | | - |
1556 | tx = GLfloat(textureWidth); | - |
1557 | ty = GLfloat(textureHeight); | - |
1558 | } | 0 |
1559 | | - |
1560 | | - |
1561 | GLfloat texCoordArray[4*2] = { | - |
1562 | 0, ty, tx, ty, tx, 0, 0, 0 | - |
1563 | }; | - |
1564 | | - |
1565 | GLfloat vertexArray[4*2]; | - |
1566 | qt_add_rect_to_array(target, vertexArray); | - |
1567 | | - |
1568 | glVertexPointer(2, 0x1406, 0, vertexArray); | - |
1569 | glTexCoordPointer(2, 0x1406, 0, texCoordArray); | - |
1570 | | - |
1571 | glEnableClientState(0x8074); | - |
1572 | glEnableClientState(0x8078); | - |
1573 | glDrawArrays(0x0006, 0, 4); | - |
1574 | | - |
1575 | glDisableClientState(0x8074); | - |
1576 | glDisableClientState(0x8078); | - |
1577 | } | 0 |
1578 | void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - |
1579 | { | - |
1580 | | - |
1581 | if (d_ptr->active_engine && never evaluated: d_ptr->active_engine | 0 |
1582 | d_ptr->active_engine->type() == QPaintEngine::OpenGL2) { never evaluated: d_ptr->active_engine->type() == QPaintEngine::OpenGL2 | 0 |
1583 | QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); | - |
1584 | if (!eng->isNativePaintingActive()) { never evaluated: !eng->isNativePaintingActive() | 0 |
1585 | QRectF src(0, 0, target.width(), target.height()); | - |
1586 | QSize size(target.width(), target.height()); | - |
1587 | if (eng->drawTexture(target, textureId, size, src)) never evaluated: eng->drawTexture(target, textureId, size, src) | 0 |
1588 | return; | 0 |
1589 | } | 0 |
1590 | } | 0 |
1591 | const bool wasEnabled = glIsEnabled(0x0DE1); | - |
1592 | GLint oldTexture; | - |
1593 | glGetIntegerv(0x8069, &oldTexture); | - |
1594 | | - |
1595 | | - |
1596 | glEnable(textureTarget); | - |
1597 | glBindTexture(textureTarget, textureId); | - |
1598 | | - |
1599 | qDrawTextureRect(target, -1, -1, textureTarget); | - |
1600 | | - |
1601 | | - |
1602 | | - |
1603 | | - |
1604 | if (!wasEnabled) never evaluated: !wasEnabled | 0 |
1605 | glDisable(textureTarget); never executed: glDisable(textureTarget); | 0 |
1606 | glBindTexture(textureTarget, oldTexture); | - |
1607 | | - |
1608 | | - |
1609 | | - |
1610 | | - |
1611 | | - |
1612 | | - |
1613 | | - |
1614 | } | 0 |
1615 | void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - |
1616 | { | - |
1617 | | - |
1618 | | - |
1619 | | - |
1620 | | - |
1621 | | - |
1622 | | - |
1623 | | - |
1624 | const bool wasEnabled = glIsEnabled(0x0DE1); | - |
1625 | GLint oldTexture; | - |
1626 | glGetIntegerv(0x8069, &oldTexture); | - |
1627 | | - |
1628 | glEnable(textureTarget); | - |
1629 | glBindTexture(textureTarget, textureId); | - |
1630 | | - |
1631 | GLint textureWidth; | - |
1632 | GLint textureHeight; | - |
1633 | | - |
1634 | glGetTexLevelParameteriv(textureTarget, 0, 0x1000, &textureWidth); | - |
1635 | glGetTexLevelParameteriv(textureTarget, 0, 0x1001, &textureHeight); | - |
1636 | | - |
1637 | if (d_ptr->active_engine && never evaluated: d_ptr->active_engine | 0 |
1638 | d_ptr->active_engine->type() == QPaintEngine::OpenGL2) { never evaluated: d_ptr->active_engine->type() == QPaintEngine::OpenGL2 | 0 |
1639 | QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); | - |
1640 | if (!eng->isNativePaintingActive()) { never evaluated: !eng->isNativePaintingActive() | 0 |
1641 | QRectF dest(point, QSizeF(textureWidth, textureHeight)); | - |
1642 | QRectF src(0, 0, textureWidth, textureHeight); | - |
1643 | QSize size(textureWidth, textureHeight); | - |
1644 | if (eng->drawTexture(dest, textureId, size, src)) never evaluated: eng->drawTexture(dest, textureId, size, src) | 0 |
1645 | return; | 0 |
1646 | } | 0 |
1647 | } | 0 |
1648 | | - |
1649 | qDrawTextureRect(QRectF(point, QSizeF(textureWidth, textureHeight)), textureWidth, textureHeight, textureTarget); | - |
1650 | | - |
1651 | if (!wasEnabled) never evaluated: !wasEnabled | 0 |
1652 | glDisable(textureTarget); never executed: glDisable(textureTarget); | 0 |
1653 | glBindTexture(textureTarget, oldTexture); | - |
1654 | | - |
1655 | } | 0 |
1656 | void QGLContext::setTextureCacheLimit(int size) | - |
1657 | { | - |
1658 | QGLTextureCache::instance()->setMaxCost(size); | - |
1659 | } | 0 |
1660 | | - |
1661 | | - |
1662 | | - |
1663 | | - |
1664 | | - |
1665 | | - |
1666 | int QGLContext::textureCacheLimit() | - |
1667 | { | - |
1668 | return QGLTextureCache::instance()->maxCost(); never executed: return QGLTextureCache::instance()->maxCost(); | 0 |
1669 | } | - |
1670 | void QGLContext::setFormat(const QGLFormat &format) | - |
1671 | { | - |
1672 | QGLContextPrivate * const d = d_func(); | - |
1673 | reset(); | - |
1674 | d->glFormat = d->reqFormat = format; | - |
1675 | } | 0 |
1676 | | - |
1677 | | - |
1678 | | - |
1679 | | - |
1680 | void QGLContext::setDevice(QPaintDevice *pDev) | - |
1681 | { | - |
1682 | QGLContextPrivate * const d = d_func(); | - |
1683 | if (isValid()) never evaluated: isValid() | 0 |
1684 | reset(); | 0 |
1685 | d->paintDevice = pDev; | - |
1686 | if (d->paintDevice && (d->paintDevice->devType() != QInternal::Widget never evaluated: d->paintDevice never evaluated: d->paintDevice->devType() != QInternal::Widget | 0 |
1687 | && d->paintDevice->devType() != QInternal::Pixmap never evaluated: d->paintDevice->devType() != QInternal::Pixmap | 0 |
1688 | && d->paintDevice->devType() != QInternal::Pbuffer)) { never evaluated: d->paintDevice->devType() != QInternal::Pbuffer | 0 |
1689 | QMessageLogger("qgl.cpp", 2878, __PRETTY_FUNCTION__).warning("QGLContext: Unsupported paint device type"); | - |
1690 | } | 0 |
1691 | } | 0 |
1692 | bool QGLContext::areSharing(const QGLContext *context1, const QGLContext *context2) | - |
1693 | { | - |
1694 | if (!context1 || !context2) never evaluated: !context1 never evaluated: !context2 | 0 |
1695 | return false; never executed: return false; | 0 |
1696 | return context1->d_ptr->group == context2->d_ptr->group; never executed: return context1->d_ptr->group == context2->d_ptr->group; | 0 |
1697 | } | - |
1698 | bool QGLContext::create(const QGLContext* shareContext) | - |
1699 | { | - |
1700 | QGLContextPrivate * const d = d_func(); | - |
1701 | if (!d->paintDevice && !d->guiGlContext) never evaluated: !d->paintDevice never evaluated: !d->guiGlContext | 0 |
1702 | return false; never executed: return false; | 0 |
1703 | | - |
1704 | reset(); | - |
1705 | d->valid = chooseContext(shareContext); | - |
1706 | if (d->valid && d->paintDevice && d->paintDevice->devType() == QInternal::Widget) { never evaluated: d->valid never evaluated: d->paintDevice never evaluated: d->paintDevice->devType() == QInternal::Widget | 0 |
1707 | QWidgetPrivate *wd = qt_widget_private(static_cast<QWidget *>(d->paintDevice)); | - |
1708 | wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer(); | - |
1709 | } | 0 |
1710 | return d->valid; never executed: return d->valid; | 0 |
1711 | } | - |
1712 | | - |
1713 | bool QGLContext::isValid() const | - |
1714 | { | - |
1715 | const QGLContextPrivate * const d = d_func(); | - |
1716 | return d->valid; never executed: return d->valid; | 0 |
1717 | } | - |
1718 | | - |
1719 | void QGLContext::setValid(bool valid) | - |
1720 | { | - |
1721 | QGLContextPrivate * const d = d_func(); | - |
1722 | d->valid = valid; | - |
1723 | } | 0 |
1724 | | - |
1725 | bool QGLContext::isSharing() const | - |
1726 | { | - |
1727 | const QGLContextPrivate * const d = d_func(); | - |
1728 | return d->group->isSharing(); never executed: return d->group->isSharing(); | 0 |
1729 | } | - |
1730 | | - |
1731 | QGLFormat QGLContext::format() const | - |
1732 | { | - |
1733 | const QGLContextPrivate * const d = d_func(); | - |
1734 | return d->glFormat; never executed: return d->glFormat; | 0 |
1735 | } | - |
1736 | | - |
1737 | QGLFormat QGLContext::requestedFormat() const | - |
1738 | { | - |
1739 | const QGLContextPrivate * const d = d_func(); | - |
1740 | return d->reqFormat; never executed: return d->reqFormat; | 0 |
1741 | } | - |
1742 | | - |
1743 | QPaintDevice* QGLContext::device() const | - |
1744 | { | - |
1745 | const QGLContextPrivate * const d = d_func(); | - |
1746 | return d->paintDevice; never executed: return d->paintDevice; | 0 |
1747 | } | - |
1748 | | - |
1749 | bool QGLContext::deviceIsPixmap() const | - |
1750 | { | - |
1751 | const QGLContextPrivate * const d = d_func(); | - |
1752 | return d->paintDevice->devType() == QInternal::Pixmap; never executed: return d->paintDevice->devType() == QInternal::Pixmap; | 0 |
1753 | } | - |
1754 | | - |
1755 | | - |
1756 | bool QGLContext::windowCreated() const | - |
1757 | { | - |
1758 | const QGLContextPrivate * const d = d_func(); | - |
1759 | return d->crWin; never executed: return d->crWin; | 0 |
1760 | } | - |
1761 | | - |
1762 | | - |
1763 | void QGLContext::setWindowCreated(bool on) | - |
1764 | { | - |
1765 | QGLContextPrivate * const d = d_func(); | - |
1766 | d->crWin = on; | - |
1767 | } | 0 |
1768 | | - |
1769 | bool QGLContext::initialized() const | - |
1770 | { | - |
1771 | const QGLContextPrivate * const d = d_func(); | - |
1772 | return d->initDone; never executed: return d->initDone; | 0 |
1773 | } | - |
1774 | | - |
1775 | void QGLContext::setInitialized(bool on) | - |
1776 | { | - |
1777 | QGLContextPrivate * const d = d_func(); | - |
1778 | d->initDone = on; | - |
1779 | } | 0 |
1780 | | - |
1781 | const QGLContext* QGLContext::currentContext() | - |
1782 | { | - |
1783 | if (const QOpenGLContext *threadContext = QOpenGLContext::currentContext()) { never evaluated: const QOpenGLContext *threadContext = QOpenGLContext::currentContext() | 0 |
1784 | return QGLContext::fromOpenGLContext(const_cast<QOpenGLContext *>(threadContext)); never executed: return QGLContext::fromOpenGLContext(const_cast<QOpenGLContext *>(threadContext)); | 0 |
1785 | } | - |
1786 | return 0; never executed: return 0; | 0 |
1787 | } | - |
1788 | | - |
1789 | void QGLContextPrivate::setCurrentContext(QGLContext *context) | - |
1790 | { | - |
1791 | (void)context;; | - |
1792 | } | 0 |
1793 | | - |
1794 | | - |
1795 | | - |
1796 | | - |
1797 | | - |
1798 | | - |
1799 | | - |
1800 | void QGLContext::moveToThread(QThread *thread) | - |
1801 | { | - |
1802 | QGLContextPrivate * const d = d_func(); | - |
1803 | if (d->guiGlContext) never evaluated: d->guiGlContext | 0 |
1804 | d->guiGlContext->moveToThread(thread); never executed: d->guiGlContext->moveToThread(thread); | 0 |
1805 | } | 0 |
1806 | QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFlags f) | - |
1807 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - |
1808 | { | - |
1809 | QGLWidgetPrivate * const d = d_func(); | - |
1810 | setAttribute(Qt::WA_PaintOnScreen); | - |
1811 | setAttribute(Qt::WA_NoSystemBackground); | - |
1812 | setAutoFillBackground(true); | - |
1813 | d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget); | - |
1814 | } | 0 |
1815 | | - |
1816 | | - |
1817 | | - |
1818 | | - |
1819 | QGLWidget::QGLWidget(QGLWidgetPrivate &dd, const QGLFormat &format, QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f) | - |
1820 | : QWidget(dd, parent, f | Qt::MSWindowsOwnDC) | - |
1821 | { | - |
1822 | QGLWidgetPrivate * const d = d_func(); | - |
1823 | setAttribute(Qt::WA_PaintOnScreen); | - |
1824 | setAttribute(Qt::WA_NoSystemBackground); | - |
1825 | setAutoFillBackground(true); | - |
1826 | d->init(new QGLContext(format, this), shareWidget); | - |
1827 | | - |
1828 | } | 0 |
1829 | QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget* shareWidget, | - |
1830 | Qt::WindowFlags f) | - |
1831 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - |
1832 | { | - |
1833 | QGLWidgetPrivate * const d = d_func(); | - |
1834 | setAttribute(Qt::WA_PaintOnScreen); | - |
1835 | setAttribute(Qt::WA_NoSystemBackground); | - |
1836 | setAutoFillBackground(true); | - |
1837 | d->init(new QGLContext(format, this), shareWidget); | - |
1838 | } | 0 |
1839 | QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, const QGLWidget *shareWidget, | - |
1840 | Qt::WindowFlags f) | - |
1841 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - |
1842 | { | - |
1843 | QGLWidgetPrivate * const d = d_func(); | - |
1844 | setAttribute(Qt::WA_PaintOnScreen); | - |
1845 | setAttribute(Qt::WA_NoSystemBackground); | - |
1846 | setAutoFillBackground(true); | - |
1847 | d->init(context, shareWidget); | - |
1848 | } | 0 |
1849 | | - |
1850 | | - |
1851 | | - |
1852 | | - |
1853 | | - |
1854 | QGLWidget::~QGLWidget() | - |
1855 | { | - |
1856 | QGLWidgetPrivate * const d = d_func(); | - |
1857 | delete d->glcx; | - |
1858 | d->glcx = 0; | - |
1859 | d->cleanupColormaps(); | - |
1860 | } | 0 |
1861 | bool QGLWidget::isValid() const | - |
1862 | { | - |
1863 | const QGLWidgetPrivate * const d = d_func(); | - |
1864 | return d->glcx && d->glcx->isValid(); never executed: return d->glcx && d->glcx->isValid(); | 0 |
1865 | } | - |
1866 | bool QGLWidget::isSharing() const | - |
1867 | { | - |
1868 | const QGLWidgetPrivate * const d = d_func(); | - |
1869 | return d->glcx->isSharing(); never executed: return d->glcx->isSharing(); | 0 |
1870 | } | - |
1871 | void QGLWidget::makeCurrent() | - |
1872 | { | - |
1873 | QGLWidgetPrivate * const d = d_func(); | - |
1874 | d->glcx->makeCurrent(); | - |
1875 | } | 0 |
1876 | void QGLWidget::doneCurrent() | - |
1877 | { | - |
1878 | QGLWidgetPrivate * const d = d_func(); | - |
1879 | d->glcx->doneCurrent(); | - |
1880 | } | 0 |
1881 | void QGLWidget::swapBuffers() | - |
1882 | { | - |
1883 | QGLWidgetPrivate * const d = d_func(); | - |
1884 | d->glcx->swapBuffers(); | - |
1885 | } | 0 |
1886 | void QGLWidget::setFormat(const QGLFormat &format) | - |
1887 | { | - |
1888 | setContext(new QGLContext(format,this)); | - |
1889 | } | 0 |
1890 | void QGLWidget::updateGL() | - |
1891 | { | - |
1892 | if (updatesEnabled() && testAttribute(Qt::WA_Mapped)) never evaluated: updatesEnabled() never evaluated: testAttribute(Qt::WA_Mapped) | 0 |
1893 | glDraw(); never executed: glDraw(); | 0 |
1894 | } | 0 |
1895 | void QGLWidget::initializeGL() | - |
1896 | { | - |
1897 | } | - |
1898 | void QGLWidget::paintGL() | - |
1899 | { | - |
1900 | glClear(0x00004000 | 0x00000100); | - |
1901 | } | 0 |
1902 | void QGLWidget::resizeGL(int, int) | - |
1903 | { | - |
1904 | } | - |
1905 | void QGLWidget::initializeOverlayGL() | - |
1906 | { | - |
1907 | } | - |
1908 | void QGLWidget::paintOverlayGL() | - |
1909 | { | - |
1910 | } | - |
1911 | void QGLWidget::resizeOverlayGL(int, int) | - |
1912 | { | - |
1913 | } | - |
1914 | void QGLWidget::paintEvent(QPaintEvent *) | - |
1915 | { | - |
1916 | if (updatesEnabled()) { never evaluated: updatesEnabled() | 0 |
1917 | glDraw(); | - |
1918 | updateOverlayGL(); | - |
1919 | } | 0 |
1920 | } | 0 |
1921 | QPixmap QGLWidget::renderPixmap(int w, int h, bool useContext) | - |
1922 | { | - |
1923 | QGLWidgetPrivate * const d = d_func(); | - |
1924 | QSize sz = size(); | - |
1925 | if ((w > 0) && (h > 0)) | 0 |
1926 | sz = QSize(w, h); never executed: sz = QSize(w, h); | 0 |
1927 | | - |
1928 | QPixmap pm(sz); | - |
1929 | | - |
1930 | d->glcx->doneCurrent(); | - |
1931 | | - |
1932 | bool success = true; | - |
1933 | | - |
1934 | if (useContext && isValid() && d->renderCxPm(&pm)) never evaluated: useContext never evaluated: isValid() never evaluated: d->renderCxPm(&pm) | 0 |
1935 | return pm; never executed: return pm; | 0 |
1936 | | - |
1937 | QGLFormat fmt = d->glcx->requestedFormat(); | - |
1938 | fmt.setDirectRendering(false); | - |
1939 | fmt.setDoubleBuffer(false); | - |
1940 | | - |
1941 | QGLContext* ocx = d->glcx; | - |
1942 | ocx->doneCurrent(); | - |
1943 | d->glcx = new QGLContext(fmt, &pm); | - |
1944 | d->glcx->create(); | - |
1945 | | - |
1946 | if (d->glcx->isValid()) never evaluated: d->glcx->isValid() | 0 |
1947 | updateGL(); never executed: updateGL(); | 0 |
1948 | else | - |
1949 | success = false; never executed: success = false; | 0 |
1950 | | - |
1951 | delete d->glcx; | - |
1952 | d->glcx = ocx; | - |
1953 | | - |
1954 | ocx->makeCurrent(); | - |
1955 | | - |
1956 | if (success) { | 0 |
1957 | return pm; never executed: return pm; | 0 |
1958 | } | - |
1959 | return QPixmap(); never executed: return QPixmap(); | 0 |
1960 | } | - |
1961 | QImage QGLWidget::grabFrameBuffer(bool withAlpha) | - |
1962 | { | - |
1963 | makeCurrent(); | - |
1964 | QImage res; | - |
1965 | int w = width(); | - |
1966 | int h = height(); | - |
1967 | if (format().rgba()) never evaluated: format().rgba() | 0 |
1968 | 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 |
1969 | | - |
1970 | return res; never executed: return res; | 0 |
1971 | } | - |
1972 | void QGLWidget::glInit() | - |
1973 | { | - |
1974 | QGLWidgetPrivate * const d = d_func(); | - |
1975 | if (!isValid()) never evaluated: !isValid() | 0 |
1976 | return; | 0 |
1977 | makeCurrent(); | - |
1978 | initializeGL(); | - |
1979 | d->glcx->setInitialized(true); | - |
1980 | } | 0 |
1981 | void QGLWidget::glDraw() | - |
1982 | { | - |
1983 | QGLWidgetPrivate * const d = d_func(); | - |
1984 | if (!isValid()) never evaluated: !isValid() | 0 |
1985 | return; | 0 |
1986 | makeCurrent(); | - |
1987 | | - |
1988 | if (d->glcx->deviceIsPixmap()) never evaluated: d->glcx->deviceIsPixmap() | 0 |
1989 | glDrawBuffer(0x0404); never executed: glDrawBuffer(0x0404); | 0 |
1990 | | - |
1991 | if (!d->glcx->initialized()) { never evaluated: !d->glcx->initialized() | 0 |
1992 | glInit(); | - |
1993 | const qreal scaleFactor = (window() && window()->windowHandle()) ? never evaluated: window() never evaluated: window()->windowHandle() | 0 |
1994 | window()->windowHandle()->devicePixelRatio() : 1.0; | - |
1995 | resizeGL(d->glcx->device()->width() * scaleFactor, d->glcx->device()->height() * scaleFactor); | - |
1996 | } | 0 |
1997 | paintGL(); | - |
1998 | if (doubleBuffer()) { never evaluated: doubleBuffer() | 0 |
1999 | if (d->autoSwap) never evaluated: d->autoSwap | 0 |
2000 | swapBuffers(); never executed: swapBuffers(); | 0 |
2001 | } else { | 0 |
2002 | glFlush(); | - |
2003 | } | 0 |
2004 | } | - |
2005 | void QGLWidget::qglColor(const QColor& c) const | - |
2006 | { | - |
2007 | | - |
2008 | | - |
2009 | | - |
2010 | | - |
2011 | const QGLWidgetPrivate * const d = d_func(); | - |
2012 | const QGLContext *ctx = QGLContext::currentContext(); | - |
2013 | if (ctx) { | 0 |
2014 | if (ctx->format().rgba()) never evaluated: ctx->format().rgba() | 0 |
2015 | glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); never executed: glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | 0 |
2016 | else if (!d->cmap.isEmpty()) { never evaluated: !d->cmap.isEmpty() | 0 |
2017 | int i = d->cmap.find(c.rgb()); | - |
2018 | if (i < 0) | 0 |
2019 | i = d->cmap.findNearest(c.rgb()); never executed: i = d->cmap.findNearest(c.rgb()); | 0 |
2020 | glIndexi(i); | - |
2021 | } else | 0 |
2022 | glIndexi(ctx->colorIndex(c)); never executed: glIndexi(ctx->colorIndex(c)); | 0 |
2023 | } | - |
2024 | | - |
2025 | | - |
2026 | | - |
2027 | | - |
2028 | } | 0 |
2029 | void QGLWidget::qglClearColor(const QColor& c) const | - |
2030 | { | - |
2031 | | - |
2032 | | - |
2033 | | - |
2034 | const QGLWidgetPrivate * const d = d_func(); | - |
2035 | const QGLContext *ctx = QGLContext::currentContext(); | - |
2036 | if (ctx) { | 0 |
2037 | if (ctx->format().rgba()) never evaluated: ctx->format().rgba() | 0 |
2038 | glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); never executed: glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | 0 |
2039 | else if (!d->cmap.isEmpty()) { never evaluated: !d->cmap.isEmpty() | 0 |
2040 | int i = d->cmap.find(c.rgb()); | - |
2041 | if (i < 0) | 0 |
2042 | i = d->cmap.findNearest(c.rgb()); never executed: i = d->cmap.findNearest(c.rgb()); | 0 |
2043 | glClearIndex(i); | - |
2044 | } else | 0 |
2045 | glClearIndex(ctx->colorIndex(c)); never executed: glClearIndex(ctx->colorIndex(c)); | 0 |
2046 | } | - |
2047 | | - |
2048 | } | 0 |
2049 | QImage QGLWidget::convertToGLFormat(const QImage& img) | - |
2050 | { | - |
2051 | QImage res(img.size(), QImage::Format_ARGB32); | - |
2052 | convertToGLFormatHelper(res, img.convertToFormat(QImage::Format_ARGB32), 0x1908); | - |
2053 | return res; never executed: return res; | 0 |
2054 | } | - |
2055 | static void qt_save_gl_state() | - |
2056 | { | - |
2057 | glPushClientAttrib(0xFFFFFFFF); | - |
2058 | glPushAttrib(0x000FFFFF); | - |
2059 | glMatrixMode(0x1702); | - |
2060 | glPushMatrix(); | - |
2061 | glLoadIdentity(); | - |
2062 | glMatrixMode(0x1701); | - |
2063 | glPushMatrix(); | - |
2064 | glMatrixMode(0x1700); | - |
2065 | glPushMatrix(); | - |
2066 | | - |
2067 | glShadeModel(0x1D00); | - |
2068 | glDisable(0x0B44); | - |
2069 | glDisable(0x0B50); | - |
2070 | glDisable(0x0B90); | - |
2071 | glDisable(0x0B71); | - |
2072 | glEnable(0x0BE2); | - |
2073 | glBlendFunc(0x1, 0x0303); | - |
2074 | } | 0 |
2075 | | - |
2076 | static void qt_restore_gl_state() | - |
2077 | { | - |
2078 | glMatrixMode(0x1702); | - |
2079 | glPopMatrix(); | - |
2080 | glMatrixMode(0x1701); | - |
2081 | glPopMatrix(); | - |
2082 | glMatrixMode(0x1700); | - |
2083 | glPopMatrix(); | - |
2084 | glPopAttrib(); | - |
2085 | glPopClientAttrib(); | - |
2086 | } | 0 |
2087 | | - |
2088 | static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, | - |
2089 | const QFont &font) | - |
2090 | { | - |
2091 | GLfloat color[4]; | - |
2092 | glGetFloatv(0x0B00, &color[0]); | - |
2093 | | - |
2094 | QColor col; | - |
2095 | col.setRgbF(color[0], color[1], color[2],color[3]); | - |
2096 | QPen old_pen = p->pen(); | - |
2097 | QFont old_font = p->font(); | - |
2098 | | - |
2099 | p->setPen(col); | - |
2100 | p->setFont(font); | - |
2101 | p->drawText(x, y, str); | - |
2102 | | - |
2103 | p->setPen(old_pen); | - |
2104 | p->setFont(old_font); | - |
2105 | } | 0 |
2106 | void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font) | - |
2107 | { | - |
2108 | | - |
2109 | QGLWidgetPrivate * const d = d_func(); | - |
2110 | if (str.isEmpty() || !isValid()) never evaluated: str.isEmpty() never evaluated: !isValid() | 0 |
2111 | return; | 0 |
2112 | | - |
2113 | GLint view[4]; | - |
2114 | bool use_scissor_testing = glIsEnabled(0x0C11); | - |
2115 | if (!use_scissor_testing) never evaluated: !use_scissor_testing | 0 |
2116 | glGetIntegerv(0x0BA2, &view[0]); never executed: glGetIntegerv(0x0BA2, &view[0]); | 0 |
2117 | int width = d->glcx->device()->width(); | - |
2118 | int height = d->glcx->device()->height(); | - |
2119 | bool auto_swap = autoBufferSwap(); | - |
2120 | | - |
2121 | QPaintEngine *engine = paintEngine(); | - |
2122 | | - |
2123 | qt_save_gl_state(); | - |
2124 | | - |
2125 | QPainter *p; | - |
2126 | bool reuse_painter = false; | - |
2127 | if (engine->isActive()) { never evaluated: engine->isActive() | 0 |
2128 | reuse_painter = true; | - |
2129 | p = engine->painter(); | - |
2130 | | - |
2131 | glDisable(0x0B71); | - |
2132 | glViewport(0, 0, width, height); | - |
2133 | glMatrixMode(0x1701); | - |
2134 | glLoadIdentity(); | - |
2135 | glOrtho(0, width, height, 0, 0, 1); | - |
2136 | glMatrixMode(0x1700); | - |
2137 | | - |
2138 | glLoadIdentity(); | - |
2139 | } else { | 0 |
2140 | setAutoBufferSwap(false); | - |
2141 | | - |
2142 | d->disable_clear_on_painter_begin = true; | - |
2143 | p = new QPainter(this); | - |
2144 | } | 0 |
2145 | | - |
2146 | QRect viewport(view[0], view[1], view[2], view[3]); | - |
2147 | if (!use_scissor_testing && viewport != rect()) { never evaluated: !use_scissor_testing never evaluated: viewport != rect() | 0 |
2148 | | - |
2149 | | - |
2150 | glScissor(view[0], view[1], view[2], view[3]); | - |
2151 | glEnable(0x0C11); | - |
2152 | } else if (use_scissor_testing) { never evaluated: use_scissor_testing | 0 |
2153 | | - |
2154 | glEnable(0x0C11); | - |
2155 | } | 0 |
2156 | | - |
2157 | qt_gl_draw_text(p, x, y, str, font); | - |
2158 | | - |
2159 | if (!reuse_painter) { never evaluated: !reuse_painter | 0 |
2160 | p->end(); | - |
2161 | delete p; | - |
2162 | setAutoBufferSwap(auto_swap); | - |
2163 | d->disable_clear_on_painter_begin = false; | - |
2164 | } | 0 |
2165 | | - |
2166 | qt_restore_gl_state(); | - |
2167 | } | 0 |
2168 | void QGLWidget::renderText(double x, double y, double z, const QString &str, const QFont &font) | - |
2169 | { | - |
2170 | | - |
2171 | QGLWidgetPrivate * const d = d_func(); | - |
2172 | if (str.isEmpty() || !isValid()) never evaluated: str.isEmpty() never evaluated: !isValid() | 0 |
2173 | return; | 0 |
2174 | | - |
2175 | bool auto_swap = autoBufferSwap(); | - |
2176 | | - |
2177 | int width = d->glcx->device()->width(); | - |
2178 | int height = d->glcx->device()->height(); | - |
2179 | GLdouble model[4][4], proj[4][4]; | - |
2180 | GLint view[4]; | - |
2181 | glGetDoublev(0x0BA6, &model[0][0]); | - |
2182 | glGetDoublev(0x0BA7, &proj[0][0]); | - |
2183 | glGetIntegerv(0x0BA2, &view[0]); | - |
2184 | GLdouble win_x = 0, win_y = 0, win_z = 0; | - |
2185 | qgluProject(x, y, z, &model[0][0], &proj[0][0], &view[0], | - |
2186 | &win_x, &win_y, &win_z); | - |
2187 | win_y = height - win_y; | - |
2188 | | - |
2189 | QPaintEngine *engine = paintEngine(); | - |
2190 | | - |
2191 | QPainter *p; | - |
2192 | bool reuse_painter = false; | - |
2193 | bool use_depth_testing = glIsEnabled(0x0B71); | - |
2194 | bool use_scissor_testing = glIsEnabled(0x0C11); | - |
2195 | | - |
2196 | qt_save_gl_state(); | - |
2197 | | - |
2198 | if (engine->isActive()) { never evaluated: engine->isActive() | 0 |
2199 | reuse_painter = true; | - |
2200 | p = engine->painter(); | - |
2201 | } else { | 0 |
2202 | setAutoBufferSwap(false); | - |
2203 | | - |
2204 | d->disable_clear_on_painter_begin = true; | - |
2205 | p = new QPainter(this); | - |
2206 | } | 0 |
2207 | | - |
2208 | QRect viewport(view[0], view[1], view[2], view[3]); | - |
2209 | if (!use_scissor_testing && viewport != rect()) { never evaluated: !use_scissor_testing never evaluated: viewport != rect() | 0 |
2210 | glScissor(view[0], view[1], view[2], view[3]); | - |
2211 | glEnable(0x0C11); | - |
2212 | } else if (use_scissor_testing) { never evaluated: use_scissor_testing | 0 |
2213 | glEnable(0x0C11); | - |
2214 | } | 0 |
2215 | glMatrixMode(0x1701); | - |
2216 | glLoadIdentity(); | - |
2217 | glViewport(0, 0, width, height); | - |
2218 | glOrtho(0, width, height, 0, 0, 1); | - |
2219 | glMatrixMode(0x1700); | - |
2220 | glLoadIdentity(); | - |
2221 | glAlphaFunc(0x0204, 0.0); | - |
2222 | glEnable(0x0BC0); | - |
2223 | if (use_depth_testing) never evaluated: use_depth_testing | 0 |
2224 | glEnable(0x0B71); never executed: glEnable(0x0B71); | 0 |
2225 | glTranslated(0, 0, -win_z); | - |
2226 | qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font); | - |
2227 | | - |
2228 | if (!reuse_painter) { never evaluated: !reuse_painter | 0 |
2229 | p->end(); | - |
2230 | delete p; | - |
2231 | setAutoBufferSwap(auto_swap); | - |
2232 | d->disable_clear_on_painter_begin = false; | - |
2233 | } | 0 |
2234 | | - |
2235 | qt_restore_gl_state(); | - |
2236 | } | 0 |
2237 | | - |
2238 | QGLFormat QGLWidget::format() const | - |
2239 | { | - |
2240 | const QGLWidgetPrivate * const d = d_func(); | - |
2241 | return d->glcx->format(); never executed: return d->glcx->format(); | 0 |
2242 | } | - |
2243 | | - |
2244 | QGLContext *QGLWidget::context() const | - |
2245 | { | - |
2246 | const QGLWidgetPrivate * const d = d_func(); | - |
2247 | return d->glcx; never executed: return d->glcx; | 0 |
2248 | } | - |
2249 | | - |
2250 | bool QGLWidget::doubleBuffer() const | - |
2251 | { | - |
2252 | const QGLWidgetPrivate * const d = d_func(); | - |
2253 | return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); never executed: return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); | 0 |
2254 | } | - |
2255 | | - |
2256 | void QGLWidget::setAutoBufferSwap(bool on) | - |
2257 | { | - |
2258 | QGLWidgetPrivate * const d = d_func(); | - |
2259 | d->autoSwap = on; | - |
2260 | } | 0 |
2261 | | - |
2262 | bool QGLWidget::autoBufferSwap() const | - |
2263 | { | - |
2264 | const QGLWidgetPrivate * const d = d_func(); | - |
2265 | return d->autoSwap; never executed: return d->autoSwap; | 0 |
2266 | } | - |
2267 | | - |
2268 | | - |
2269 | | - |
2270 | | - |
2271 | | - |
2272 | | - |
2273 | | - |
2274 | GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format) | - |
2275 | { | - |
2276 | if (image.isNull()) never evaluated: image.isNull() | 0 |
2277 | return 0; never executed: return 0; | 0 |
2278 | | - |
2279 | QGLWidgetPrivate * const d = d_func(); | - |
2280 | return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); never executed: return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); | 0 |
2281 | } | - |
2282 | GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options) | - |
2283 | { | - |
2284 | if (image.isNull()) never evaluated: image.isNull() | 0 |
2285 | return 0; never executed: return 0; | 0 |
2286 | | - |
2287 | QGLWidgetPrivate * const d = d_func(); | - |
2288 | return d->glcx->bindTexture(image, target, format, options); never executed: return d->glcx->bindTexture(image, target, format, options); | 0 |
2289 | } | - |
2290 | GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) | - |
2291 | { | - |
2292 | if (pixmap.isNull()) never evaluated: pixmap.isNull() | 0 |
2293 | return 0; never executed: return 0; | 0 |
2294 | | - |
2295 | QGLWidgetPrivate * const d = d_func(); | - |
2296 | return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); never executed: return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); | 0 |
2297 | } | - |
2298 | GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, | - |
2299 | QGLContext::BindOptions options) | - |
2300 | { | - |
2301 | QGLWidgetPrivate * const d = d_func(); | - |
2302 | return d->glcx->bindTexture(pixmap, target, format, options); never executed: return d->glcx->bindTexture(pixmap, target, format, options); | 0 |
2303 | } | - |
2304 | | - |
2305 | | - |
2306 | | - |
2307 | | - |
2308 | | - |
2309 | | - |
2310 | | - |
2311 | GLuint QGLWidget::bindTexture(const QString &fileName) | - |
2312 | { | - |
2313 | QGLWidgetPrivate * const d = d_func(); | - |
2314 | return d->glcx->bindTexture(fileName); never executed: return d->glcx->bindTexture(fileName); | 0 |
2315 | } | - |
2316 | | - |
2317 | | - |
2318 | | - |
2319 | | - |
2320 | | - |
2321 | | - |
2322 | | - |
2323 | void QGLWidget::deleteTexture(GLuint id) | - |
2324 | { | - |
2325 | QGLWidgetPrivate * const d = d_func(); | - |
2326 | d->glcx->deleteTexture(id); | - |
2327 | } | 0 |
2328 | void QGLWidget::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - |
2329 | { | - |
2330 | QGLWidgetPrivate * const d = d_func(); | - |
2331 | d->glcx->drawTexture(target, textureId, textureTarget); | - |
2332 | } | 0 |
2333 | void QGLWidget::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - |
2334 | { | - |
2335 | QGLWidgetPrivate * const d = d_func(); | - |
2336 | d->glcx->drawTexture(point, textureId, textureTarget); | - |
2337 | } | 0 |
2338 | | - |
2339 | static QGLEngineThreadStorage<QGL2PaintEngineEx> *qt_gl_2_engine() { static QGlobalStatic<QGLEngineThreadStorage<QGL2PaintEngineEx> > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLEngineThreadStorage<QGL2PaintEngineEx> *x = new QGLEngineThreadStorage<QGL2PaintEngineEx>; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLEngineThreadStorage<QGL2PaintEngineEx> > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
2340 | | - |
2341 | __attribute__((visibility("default"))) QPaintEngine* qt_qgl_paint_engine() | - |
2342 | { | - |
2343 | return qt_gl_2_engine()->engine(); never executed: return qt_gl_2_engine()->engine(); | 0 |
2344 | } | - |
2345 | | - |
2346 | | - |
2347 | | - |
2348 | | - |
2349 | | - |
2350 | | - |
2351 | QPaintEngine *QGLWidget::paintEngine() const | - |
2352 | { | - |
2353 | return qt_qgl_paint_engine(); never executed: return qt_qgl_paint_engine(); | 0 |
2354 | } | - |
2355 | | - |
2356 | typedef const GLubyte * ( * qt_glGetStringi)(GLenum, GLuint); | - |
2357 | | - |
2358 | | - |
2359 | | - |
2360 | | - |
2361 | | - |
2362 | QGLExtensionMatcher::QGLExtensionMatcher(const char *str) | - |
2363 | { | - |
2364 | init(str); | - |
2365 | } | 0 |
2366 | | - |
2367 | QGLExtensionMatcher::QGLExtensionMatcher() | - |
2368 | { | - |
2369 | const char *extensionStr = reinterpret_cast<const char *>(glGetString(0x1F03)); | - |
2370 | | - |
2371 | if (extensionStr) { never evaluated: extensionStr | 0 |
2372 | init(extensionStr); | - |
2373 | } else { | 0 |
2374 | | - |
2375 | while (glGetError()) {} never evaluated: glGetError() | 0 |
2376 | | - |
2377 | const QGLContext *ctx = QGLContext::currentContext(); | - |
2378 | if (ctx) { | 0 |
2379 | qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress(QLatin1String("glGetStringi")); | - |
2380 | | - |
2381 | GLint numExtensions; | - |
2382 | glGetIntegerv(0x821D, &numExtensions); | - |
2383 | | - |
2384 | for (int i = 0; i < numExtensions; ++i) { never evaluated: i < numExtensions | 0 |
2385 | const char *str = reinterpret_cast<const char *>(glGetStringi(0x1F03, i)); | - |
2386 | | - |
2387 | m_offsets << m_extensions.size(); | - |
2388 | | - |
2389 | while (*str != 0) never evaluated: *str != 0 | 0 |
2390 | m_extensions.append(*str++); never executed: m_extensions.append(*str++); | 0 |
2391 | m_extensions.append(' '); | - |
2392 | } | 0 |
2393 | } | 0 |
2394 | } | 0 |
2395 | } | - |
2396 | | - |
2397 | void QGLExtensionMatcher::init(const char *str) | - |
2398 | { | - |
2399 | m_extensions = str; | - |
2400 | | - |
2401 | | - |
2402 | if (!m_extensions.endsWith(' ')) never evaluated: !m_extensions.endsWith(' ') | 0 |
2403 | m_extensions.append(' '); never executed: m_extensions.append(' '); | 0 |
2404 | | - |
2405 | int index = 0; | - |
2406 | int next = 0; | - |
2407 | while ((next = m_extensions.indexOf(' ', index)) >= 0) { never evaluated: (next = m_extensions.indexOf(' ', index)) >= 0 | 0 |
2408 | m_offsets << index; | - |
2409 | index = next + 1; | - |
2410 | } | 0 |
2411 | } | 0 |
2412 | QGLExtensions::Extensions QGLExtensions::currentContextExtensions() | - |
2413 | { | - |
2414 | QGLExtensionMatcher extensions; | - |
2415 | Extensions glExtensions; | - |
2416 | | - |
2417 | if (extensions.match("GL_ARB_texture_rectangle")) never evaluated: extensions.match("GL_ARB_texture_rectangle") | 0 |
2418 | glExtensions |= TextureRectangle; never executed: glExtensions |= TextureRectangle; | 0 |
2419 | if (extensions.match("GL_ARB_multisample")) never evaluated: extensions.match("GL_ARB_multisample") | 0 |
2420 | glExtensions |= SampleBuffers; never executed: glExtensions |= SampleBuffers; | 0 |
2421 | if (extensions.match("GL_SGIS_generate_mipmap")) never evaluated: extensions.match("GL_SGIS_generate_mipmap") | 0 |
2422 | glExtensions |= GenerateMipmap; never executed: glExtensions |= GenerateMipmap; | 0 |
2423 | if (extensions.match("GL_ARB_texture_compression")) never evaluated: extensions.match("GL_ARB_texture_compression") | 0 |
2424 | glExtensions |= TextureCompression; never executed: glExtensions |= TextureCompression; | 0 |
2425 | if (extensions.match("GL_EXT_texture_compression_s3tc")) never evaluated: extensions.match("GL_EXT_texture_compression_s3tc") | 0 |
2426 | glExtensions |= DDSTextureCompression; never executed: glExtensions |= DDSTextureCompression; | 0 |
2427 | if (extensions.match("GL_OES_compressed_ETC1_RGB8_texture")) never evaluated: extensions.match("GL_OES_compressed_ETC1_RGB8_texture") | 0 |
2428 | glExtensions |= ETC1TextureCompression; never executed: glExtensions |= ETC1TextureCompression; | 0 |
2429 | if (extensions.match("GL_IMG_texture_compression_pvrtc")) never evaluated: extensions.match("GL_IMG_texture_compression_pvrtc") | 0 |
2430 | glExtensions |= PVRTCTextureCompression; never executed: glExtensions |= PVRTCTextureCompression; | 0 |
2431 | if (extensions.match("GL_ARB_fragment_program")) never evaluated: extensions.match("GL_ARB_fragment_program") | 0 |
2432 | glExtensions |= FragmentProgram; never executed: glExtensions |= FragmentProgram; | 0 |
2433 | if (extensions.match("GL_ARB_fragment_shader")) never evaluated: extensions.match("GL_ARB_fragment_shader") | 0 |
2434 | glExtensions |= FragmentShader; never executed: glExtensions |= FragmentShader; | 0 |
2435 | if (extensions.match("GL_ARB_shader_objects")) never evaluated: extensions.match("GL_ARB_shader_objects") | 0 |
2436 | glExtensions |= FragmentShader; never executed: glExtensions |= FragmentShader; | 0 |
2437 | if (extensions.match("GL_ARB_texture_mirrored_repeat")) never evaluated: extensions.match("GL_ARB_texture_mirrored_repeat") | 0 |
2438 | glExtensions |= MirroredRepeat; never executed: glExtensions |= MirroredRepeat; | 0 |
2439 | if (extensions.match("GL_EXT_framebuffer_object")) never evaluated: extensions.match("GL_EXT_framebuffer_object") | 0 |
2440 | glExtensions |= FramebufferObject; never executed: glExtensions |= FramebufferObject; | 0 |
2441 | if (extensions.match("GL_EXT_stencil_two_side")) never evaluated: extensions.match("GL_EXT_stencil_two_side") | 0 |
2442 | glExtensions |= StencilTwoSide; never executed: glExtensions |= StencilTwoSide; | 0 |
2443 | if (extensions.match("GL_EXT_stencil_wrap")) never evaluated: extensions.match("GL_EXT_stencil_wrap") | 0 |
2444 | glExtensions |= StencilWrap; never executed: glExtensions |= StencilWrap; | 0 |
2445 | if (extensions.match("GL_EXT_packed_depth_stencil")) never evaluated: extensions.match("GL_EXT_packed_depth_stencil") | 0 |
2446 | glExtensions |= PackedDepthStencil; never executed: glExtensions |= PackedDepthStencil; | 0 |
2447 | if (extensions.match("GL_NV_float_buffer")) never evaluated: extensions.match("GL_NV_float_buffer") | 0 |
2448 | glExtensions |= NVFloatBuffer; never executed: glExtensions |= NVFloatBuffer; | 0 |
2449 | if (extensions.match("GL_ARB_pixel_buffer_object")) never evaluated: extensions.match("GL_ARB_pixel_buffer_object") | 0 |
2450 | glExtensions |= PixelBufferObject; never executed: glExtensions |= PixelBufferObject; | 0 |
2451 | if (extensions.match("GL_IMG_texture_format_BGRA8888")) never evaluated: extensions.match("GL_IMG_texture_format_BGRA8888") | 0 |
2452 | glExtensions |= BGRATextureFormat; never executed: glExtensions |= BGRATextureFormat; | 0 |
2453 | glExtensions |= ElementIndexUint; | - |
2454 | | - |
2455 | if (extensions.match("GL_ARB_framebuffer_object")) { never evaluated: extensions.match("GL_ARB_framebuffer_object") | 0 |
2456 | | - |
2457 | glExtensions |= FramebufferObject; | - |
2458 | glExtensions |= FramebufferBlit; | - |
2459 | } | 0 |
2460 | | - |
2461 | if (extensions.match("GL_EXT_framebuffer_blit")) never evaluated: extensions.match("GL_EXT_framebuffer_blit") | 0 |
2462 | glExtensions |= FramebufferBlit; never executed: glExtensions |= FramebufferBlit; | 0 |
2463 | | - |
2464 | if (extensions.match("GL_ARB_texture_non_power_of_two")) never evaluated: extensions.match("GL_ARB_texture_non_power_of_two") | 0 |
2465 | glExtensions |= NPOTTextures; never executed: glExtensions |= NPOTTextures; | 0 |
2466 | | - |
2467 | if (extensions.match("GL_EXT_bgra")) never evaluated: extensions.match("GL_EXT_bgra") | 0 |
2468 | glExtensions |= BGRATextureFormat; never executed: glExtensions |= BGRATextureFormat; | 0 |
2469 | | - |
2470 | | - |
2471 | { | - |
2472 | GLboolean srgbCapableFramebuffers = false; | - |
2473 | glGetBooleanv(0x8DBA, &srgbCapableFramebuffers); | - |
2474 | if (srgbCapableFramebuffers) never evaluated: srgbCapableFramebuffers | 0 |
2475 | glExtensions |= SRGBFrameBuffer; never executed: glExtensions |= SRGBFrameBuffer; | 0 |
2476 | } | - |
2477 | | - |
2478 | | - |
2479 | return glExtensions; never executed: return glExtensions; | 0 |
2480 | } | - |
2481 | | - |
2482 | | - |
2483 | class QGLDefaultExtensions | - |
2484 | { | - |
2485 | public: | - |
2486 | QGLDefaultExtensions() { | - |
2487 | QGLTemporaryContext tempContext; | - |
2488 | extensions = QGLExtensions::currentContextExtensions(); | - |
2489 | } | 0 |
2490 | | - |
2491 | QGLExtensions::Extensions extensions; | - |
2492 | }; | - |
2493 | | - |
2494 | static QGLDefaultExtensions *qtDefaultExtensions() { static QGlobalStatic<QGLDefaultExtensions > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLDefaultExtensions *x = new QGLDefaultExtensions; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLDefaultExtensions > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
2495 | | - |
2496 | | - |
2497 | | - |
2498 | | - |
2499 | | - |
2500 | | - |
2501 | QGLExtensions::Extensions QGLExtensions::glExtensions() | - |
2502 | { | - |
2503 | Extensions extensionFlags = 0; | - |
2504 | QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); | - |
2505 | | - |
2506 | if (currentCtx && currentCtx->d_func()->extension_flags_cached) never evaluated: currentCtx never evaluated: currentCtx->d_func()->extension_flags_cached | 0 |
2507 | return currentCtx->d_func()->extension_flags; never executed: return currentCtx->d_func()->extension_flags; | 0 |
2508 | | - |
2509 | if (!currentCtx) { never evaluated: !currentCtx | 0 |
2510 | extensionFlags = qtDefaultExtensions()->extensions; | - |
2511 | } else { | 0 |
2512 | extensionFlags = currentContextExtensions(); | - |
2513 | currentCtx->d_func()->extension_flags_cached = true; | - |
2514 | currentCtx->d_func()->extension_flags = extensionFlags; | - |
2515 | } | 0 |
2516 | return extensionFlags; never executed: return extensionFlags; | 0 |
2517 | } | - |
2518 | | - |
2519 | | - |
2520 | | - |
2521 | | - |
2522 | void QGLWidgetPrivate::initContext(QGLContext *context, const QGLWidget* shareWidget) | - |
2523 | { | - |
2524 | QGLWidget * const q = q_func(); | - |
2525 | | - |
2526 | glDevice.setWidget(q); | - |
2527 | | - |
2528 | glcx = 0; | - |
2529 | autoSwap = true; | - |
2530 | | - |
2531 | if (context && !context->device()) never evaluated: !context->device() | 0 |
2532 | context->setDevice(q); never executed: context->setDevice(q); | 0 |
2533 | q->setContext(context, shareWidget ? shareWidget->context() : 0); | - |
2534 | | - |
2535 | if (!glcx) | 0 |
2536 | glcx = new QGLContext(QGLFormat::defaultFormat(), q); never executed: glcx = new QGLContext(QGLFormat::defaultFormat(), q); | 0 |
2537 | } | 0 |
2538 | | - |
2539 | static QString *qt_gl_lib_name() { static QGlobalStatic<QString > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QString *x = new QString; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QString > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
2540 | | - |
2541 | void qt_set_gl_library_name(const QString& name) | - |
2542 | { | - |
2543 | qt_gl_lib_name()->operator=(name); | - |
2544 | } | 0 |
2545 | | - |
2546 | const QString qt_gl_library_name() | - |
2547 | { | - |
2548 | if (qt_gl_lib_name()->isNull()) { never evaluated: qt_gl_lib_name()->isNull() | 0 |
2549 | | - |
2550 | | - |
2551 | | - |
2552 | return QLatin1String("GL"); never executed: return QLatin1String("GL"); | 0 |
2553 | | - |
2554 | } | - |
2555 | return *qt_gl_lib_name(); never executed: return *qt_gl_lib_name(); | 0 |
2556 | } | - |
2557 | | - |
2558 | void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) { | - |
2559 | qt_noop(); | - |
2560 | if (context->d_ptr->group == share->d_ptr->group) never evaluated: context->d_ptr->group == share->d_ptr->group | 0 |
2561 | return; | 0 |
2562 | | - |
2563 | | - |
2564 | qt_noop(); | - |
2565 | | - |
2566 | | - |
2567 | QGLContextGroup *group = share->d_ptr->group; | - |
2568 | delete context->d_ptr->group; | - |
2569 | context->d_ptr->group = group; | - |
2570 | group->m_refs.ref(); | - |
2571 | | - |
2572 | | - |
2573 | | - |
2574 | if (group->m_shares.isEmpty()) never evaluated: group->m_shares.isEmpty() | 0 |
2575 | group->m_shares.append(share); never executed: group->m_shares.append(share); | 0 |
2576 | group->m_shares.append(context); | - |
2577 | } | 0 |
2578 | | - |
2579 | void QGLContextGroup::removeShare(const QGLContext *context) { | - |
2580 | | - |
2581 | QGLContextGroup *group = context->d_ptr->group; | - |
2582 | if (group->m_shares.isEmpty()) never evaluated: group->m_shares.isEmpty() | 0 |
2583 | return; | 0 |
2584 | group->m_shares.removeAll(context); | - |
2585 | | - |
2586 | | - |
2587 | qt_noop(); | - |
2588 | if (group->m_context == context) never evaluated: group->m_context == context | 0 |
2589 | group->m_context = group->m_shares[0]; never executed: group->m_context = group->m_shares[0]; | 0 |
2590 | | - |
2591 | | - |
2592 | if (group->m_shares.size() == 1) never evaluated: group->m_shares.size() == 1 | 0 |
2593 | group->m_shares.clear(); never executed: group->m_shares.clear(); | 0 |
2594 | } | 0 |
2595 | | - |
2596 | QSize QGLTexture::bindCompressedTexture | - |
2597 | (const QString& fileName, const char *format) | - |
2598 | { | - |
2599 | QFile file(fileName); | - |
2600 | if (!file.open(QIODevice::ReadOnly)) never evaluated: !file.open(QIODevice::ReadOnly) | 0 |
2601 | return QSize(); never executed: return QSize(); | 0 |
2602 | QByteArray contents = file.readAll(); | - |
2603 | file.close(); | - |
2604 | return bindCompressedTexture | 0 |
2605 | (contents.constData(), contents.size(), format); never executed: return bindCompressedTexture (contents.constData(), contents.size(), format); | 0 |
2606 | } | - |
2607 | | - |
2608 | | - |
2609 | | - |
2610 | | - |
2611 | | - |
2612 | struct PvrHeader | - |
2613 | { | - |
2614 | quint32 headerSize; | - |
2615 | quint32 height; | - |
2616 | quint32 width; | - |
2617 | quint32 mipMapCount; | - |
2618 | quint32 flags; | - |
2619 | quint32 dataSize; | - |
2620 | quint32 bitsPerPixel; | - |
2621 | quint32 redMask; | - |
2622 | quint32 greenMask; | - |
2623 | quint32 blueMask; | - |
2624 | quint32 alphaMask; | - |
2625 | quint32 magic; | - |
2626 | quint32 surfaceCount; | - |
2627 | }; | - |
2628 | bool QGLTexture::canBindCompressedTexture | - |
2629 | (const char *buf, int len, const char *format, bool *hasAlpha) | - |
2630 | { | - |
2631 | if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) { never evaluated: QSysInfo::ByteOrder != QSysInfo::LittleEndian | 0 |
2632 | | - |
2633 | | - |
2634 | return false; never executed: return false; | 0 |
2635 | } | - |
2636 | if (!format) { | 0 |
2637 | | - |
2638 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) { never evaluated: len >= 4 never evaluated: !qstrncmp(buf, "DDS ", 4) | 0 |
2639 | *hasAlpha = true; | - |
2640 | return true; never executed: return true; | 0 |
2641 | } else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) { never evaluated: len >= 52 never evaluated: !qstrncmp(buf + 44, "PVR!", 4) | 0 |
2642 | const PvrHeader *pvrHeader = | - |
2643 | reinterpret_cast<const PvrHeader *>(buf); | - |
2644 | *hasAlpha = (pvrHeader->alphaMask != 0); | - |
2645 | return true; never executed: return true; | 0 |
2646 | } | - |
2647 | } else { | - |
2648 | | - |
2649 | if (!qstricmp(format, "DDS")) { never evaluated: !qstricmp(format, "DDS") | 0 |
2650 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) { never evaluated: len >= 4 never evaluated: !qstrncmp(buf, "DDS ", 4) | 0 |
2651 | *hasAlpha = true; | - |
2652 | return true; never executed: return true; | 0 |
2653 | } | - |
2654 | } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { never evaluated: !qstricmp(format, "PVR") never evaluated: !qstricmp(format, "ETC1") | 0 |
2655 | if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) { never evaluated: len >= 52 never evaluated: !qstrncmp(buf + 44, "PVR!", 4) | 0 |
2656 | const PvrHeader *pvrHeader = | - |
2657 | reinterpret_cast<const PvrHeader *>(buf); | - |
2658 | *hasAlpha = (pvrHeader->alphaMask != 0); | - |
2659 | return true; never executed: return true; | 0 |
2660 | } | - |
2661 | } | 0 |
2662 | } | - |
2663 | return false; never executed: return false; | 0 |
2664 | } | - |
2665 | | - |
2666 | | - |
2667 | | - |
2668 | QSize QGLTexture::bindCompressedTexture | - |
2669 | (const char *buf, int len, const char *format) | - |
2670 | { | - |
2671 | if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) { never evaluated: QSysInfo::ByteOrder != QSysInfo::LittleEndian | 0 |
2672 | | - |
2673 | | - |
2674 | return QSize(); never executed: return QSize(); | 0 |
2675 | } | - |
2676 | | - |
2677 | if (!QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB) { never evaluated: !QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB | 0 |
2678 | if (!(QGLExtensions::glExtensions() & QGLExtensions::TextureCompression)) { never evaluated: !(QGLExtensions::glExtensions() & QGLExtensions::TextureCompression) | 0 |
2679 | QMessageLogger("qgl.cpp", 5046, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): The GL implementation does " | - |
2680 | "not support texture compression extensions."); | - |
2681 | return QSize(); never executed: return QSize(); | 0 |
2682 | } | - |
2683 | QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB = (_glCompressedTexImage2DARB) QGLContext::currentContext()->getProcAddress(QLatin1String("glCompressedTexImage2DARB")); | - |
2684 | if (!QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB) { never evaluated: !QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB | 0 |
2685 | QMessageLogger("qgl.cpp", 5052, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): could not resolve " | - |
2686 | "glCompressedTexImage2DARB."); | - |
2687 | return QSize(); never executed: return QSize(); | 0 |
2688 | } | - |
2689 | } | 0 |
2690 | | - |
2691 | if (!format) { | 0 |
2692 | | - |
2693 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) never evaluated: len >= 4 never evaluated: !qstrncmp(buf, "DDS ", 4) | 0 |
2694 | return bindCompressedTextureDDS(buf, len); never executed: return bindCompressedTextureDDS(buf, len); | 0 |
2695 | else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) never evaluated: len >= 52 never evaluated: !qstrncmp(buf + 44, "PVR!", 4) | 0 |
2696 | return bindCompressedTexturePVR(buf, len); never executed: return bindCompressedTexturePVR(buf, len); | 0 |
2697 | } else { | - |
2698 | | - |
2699 | if (!qstricmp(format, "DDS")) { never evaluated: !qstricmp(format, "DDS") | 0 |
2700 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) never evaluated: len >= 4 never evaluated: !qstrncmp(buf, "DDS ", 4) | 0 |
2701 | return bindCompressedTextureDDS(buf, len); never executed: return bindCompressedTextureDDS(buf, len); | 0 |
2702 | } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { never evaluated: !qstricmp(format, "PVR") never evaluated: !qstricmp(format, "ETC1") | 0 |
2703 | if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) never evaluated: len >= 52 never evaluated: !qstrncmp(buf + 44, "PVR!", 4) | 0 |
2704 | return bindCompressedTexturePVR(buf, len); never executed: return bindCompressedTexturePVR(buf, len); | 0 |
2705 | } | 0 |
2706 | } | - |
2707 | return QSize(); never executed: return QSize(); | 0 |
2708 | } | - |
2709 | | - |
2710 | QSize QGLTexture::bindCompressedTextureDDS(const char *buf, int len) | - |
2711 | { | - |
2712 | | - |
2713 | if (target != 0x0DE1) never evaluated: target != 0x0DE1 | 0 |
2714 | return QSize(); never executed: return QSize(); | 0 |
2715 | | - |
2716 | | - |
2717 | if (!(QGLExtensions::glExtensions() & QGLExtensions::DDSTextureCompression)) { never evaluated: !(QGLExtensions::glExtensions() & QGLExtensions::DDSTextureCompression) | 0 |
2718 | QMessageLogger("qgl.cpp", 5085, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): DDS texture compression is not supported."); | - |
2719 | return QSize(); never executed: return QSize(); | 0 |
2720 | } | - |
2721 | | - |
2722 | const DDSFormat *ddsHeader = reinterpret_cast<const DDSFormat *>(buf + 4); | - |
2723 | if (!ddsHeader->dwLinearSize) { never evaluated: !ddsHeader->dwLinearSize | 0 |
2724 | QMessageLogger("qgl.cpp", 5091, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): DDS image size is not valid."); | - |
2725 | return QSize(); never executed: return QSize(); | 0 |
2726 | } | - |
2727 | | - |
2728 | int blockSize = 16; | - |
2729 | GLenum format; | - |
2730 | | - |
2731 | switch(ddsHeader->ddsPixelFormat.dwFourCC) { | - |
2732 | case 0x31545844: | - |
2733 | format = 0x83F1; | - |
2734 | blockSize = 8; | - |
2735 | break; | 0 |
2736 | case 0x33545844: | - |
2737 | format = 0x83F2; | - |
2738 | break; | 0 |
2739 | case 0x35545844: | - |
2740 | format = 0x83F3; | - |
2741 | break; | 0 |
2742 | default: | - |
2743 | QMessageLogger("qgl.cpp", 5110, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): DDS image format not supported."); | - |
2744 | return QSize(); never executed: return QSize(); | 0 |
2745 | } | - |
2746 | | - |
2747 | const GLubyte *pixels = | - |
2748 | reinterpret_cast<const GLubyte *>(buf + ddsHeader->dwSize + 4); | - |
2749 | | - |
2750 | glGenTextures(1, &id); | - |
2751 | glBindTexture(0x0DE1, id); | - |
2752 | glTexParameteri(0x0DE1, 0x2800, 0x2601); | - |
2753 | glTexParameteri(0x0DE1, 0x2801, 0x2601); | - |
2754 | | - |
2755 | int size; | - |
2756 | int offset = 0; | - |
2757 | int available = len - int(ddsHeader->dwSize + 4); | - |
2758 | int w = ddsHeader->dwWidth; | - |
2759 | int h = ddsHeader->dwHeight; | - |
2760 | | - |
2761 | | - |
2762 | for(int i = 0; i < (int) ddsHeader->dwMipMapCount; ++i) { never evaluated: i < (int) ddsHeader->dwMipMapCount | 0 |
2763 | if (w == 0) w = 1; | 0 |
2764 | if (h == 0) h = 1; | 0 |
2765 | | - |
2766 | size = ((w+3)/4) * ((h+3)/4) * blockSize; | - |
2767 | if (size > available) never evaluated: size > available | 0 |
2768 | break; | 0 |
2769 | QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB(0x0DE1, i, format, w, h, 0, | - |
2770 | size, pixels + offset); | - |
2771 | offset += size; | - |
2772 | available -= size; | - |
2773 | | - |
2774 | | - |
2775 | w = w/2; | - |
2776 | h = h/2; | - |
2777 | } | 0 |
2778 | | - |
2779 | | - |
2780 | options &= ~QGLContext::InvertedYBindOption; | - |
2781 | | - |
2782 | return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); never executed: return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); | 0 |
2783 | } | - |
2784 | | - |
2785 | QSize QGLTexture::bindCompressedTexturePVR(const char *buf, int len) | - |
2786 | { | - |
2787 | | - |
2788 | if (target != 0x0DE1) never evaluated: target != 0x0DE1 | 0 |
2789 | return QSize(); never executed: return QSize(); | 0 |
2790 | | - |
2791 | | - |
2792 | const PvrHeader *pvrHeader = reinterpret_cast<const PvrHeader *>(buf); | - |
2793 | GLenum textureFormat; | - |
2794 | quint32 minWidth, minHeight; | - |
2795 | switch (pvrHeader->flags & 0x000000FF) { | - |
2796 | case 0x00000018: | - |
2797 | if (pvrHeader->alphaMask) never evaluated: pvrHeader->alphaMask | 0 |
2798 | textureFormat = 0x8C03; never executed: textureFormat = 0x8C03; | 0 |
2799 | else | - |
2800 | textureFormat = 0x8C01; never executed: textureFormat = 0x8C01; | 0 |
2801 | minWidth = 16; | - |
2802 | minHeight = 8; | - |
2803 | break; | 0 |
2804 | | - |
2805 | case 0x00000019: | - |
2806 | if (pvrHeader->alphaMask) never evaluated: pvrHeader->alphaMask | 0 |
2807 | textureFormat = 0x8C02; never executed: textureFormat = 0x8C02; | 0 |
2808 | else | - |
2809 | textureFormat = 0x8C00; never executed: textureFormat = 0x8C00; | 0 |
2810 | minWidth = 8; | - |
2811 | minHeight = 8; | - |
2812 | break; | 0 |
2813 | | - |
2814 | case 0x00000036: | - |
2815 | textureFormat = 0x8D64; | - |
2816 | minWidth = 4; | - |
2817 | minHeight = 4; | - |
2818 | break; | 0 |
2819 | | - |
2820 | default: | - |
2821 | QMessageLogger("qgl.cpp", 5188, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): PVR image format 0x%x not supported.", int(pvrHeader->flags & 0x000000FF)); | - |
2822 | return QSize(); never executed: return QSize(); | 0 |
2823 | } | - |
2824 | | - |
2825 | | - |
2826 | if (textureFormat == 0x8D64) { never evaluated: textureFormat == 0x8D64 | 0 |
2827 | if (!(QGLExtensions::glExtensions() & | 0 |
2828 | QGLExtensions::ETC1TextureCompression)) { never evaluated: !(QGLExtensions::glExtensions() & QGLExtensions::ETC1TextureCompression) | 0 |
2829 | QMessageLogger("qgl.cpp", 5196, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): ETC1 texture compression is not supported."); | - |
2830 | return QSize(); never executed: return QSize(); | 0 |
2831 | } | - |
2832 | } else { | 0 |
2833 | if (!(QGLExtensions::glExtensions() & | 0 |
2834 | QGLExtensions::PVRTCTextureCompression)) { never evaluated: !(QGLExtensions::glExtensions() & QGLExtensions::PVRTCTextureCompression) | 0 |
2835 | QMessageLogger("qgl.cpp", 5202, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): PVRTC texture compression is not supported."); | - |
2836 | return QSize(); never executed: return QSize(); | 0 |
2837 | } | - |
2838 | } | 0 |
2839 | | - |
2840 | | - |
2841 | quint32 bufferSize = pvrHeader->headerSize + pvrHeader->dataSize; | - |
2842 | if (bufferSize > quint32(len)) { never evaluated: bufferSize > quint32(len) | 0 |
2843 | QMessageLogger("qgl.cpp", 5210, __PRETTY_FUNCTION__).warning("QGLContext::bindTexture(): PVR image size is not valid."); | - |
2844 | return QSize(); never executed: return QSize(); | 0 |
2845 | } | - |
2846 | | - |
2847 | | - |
2848 | glPixelStorei(0x0CF5, 1); | - |
2849 | glGenTextures(1, &id); | - |
2850 | glBindTexture(0x0DE1, id); | - |
2851 | if (pvrHeader->mipMapCount) { never evaluated: pvrHeader->mipMapCount | 0 |
2852 | if ((options & QGLContext::LinearFilteringBindOption) != 0) { never evaluated: (options & QGLContext::LinearFilteringBindOption) != 0 | 0 |
2853 | glTexParameteri(0x0DE1, 0x2800, 0x2601); | - |
2854 | glTexParameteri(0x0DE1, 0x2801, 0x2703); | - |
2855 | } else { | 0 |
2856 | glTexParameteri(0x0DE1, 0x2800, 0x2600); | - |
2857 | glTexParameteri(0x0DE1, 0x2801, 0x2700); | - |
2858 | } | 0 |
2859 | } else if ((options & QGLContext::LinearFilteringBindOption) != 0) { never evaluated: (options & QGLContext::LinearFilteringBindOption) != 0 | 0 |
2860 | glTexParameteri(0x0DE1, 0x2800, 0x2601); | - |
2861 | glTexParameteri(0x0DE1, 0x2801, 0x2601); | - |
2862 | } else { | 0 |
2863 | glTexParameteri(0x0DE1, 0x2800, 0x2600); | - |
2864 | glTexParameteri(0x0DE1, 0x2801, 0x2600); | - |
2865 | } | 0 |
2866 | | - |
2867 | | - |
2868 | const GLubyte *buffer = | - |
2869 | reinterpret_cast<const GLubyte *>(buf + pvrHeader->headerSize); | - |
2870 | bufferSize = pvrHeader->dataSize; | - |
2871 | quint32 level = 0; | - |
2872 | quint32 width = pvrHeader->width; | - |
2873 | quint32 height = pvrHeader->height; | - |
2874 | while (bufferSize > 0 && level <= pvrHeader->mipMapCount) { never evaluated: bufferSize > 0 never evaluated: level <= pvrHeader->mipMapCount | 0 |
2875 | quint32 size = | - |
2876 | (qMax(width, minWidth) * qMax(height, minHeight) * | - |
2877 | pvrHeader->bitsPerPixel) / 8; | - |
2878 | if (size > bufferSize) never evaluated: size > bufferSize | 0 |
2879 | break; | 0 |
2880 | QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glCompressedTexImage2DARB(0x0DE1, GLint(level), textureFormat, | - |
2881 | GLsizei(width), GLsizei(height), 0, | - |
2882 | GLsizei(size), buffer); | - |
2883 | width /= 2; | - |
2884 | height /= 2; | - |
2885 | buffer += size; | - |
2886 | ++level; | - |
2887 | } | 0 |
2888 | | - |
2889 | | - |
2890 | glPixelStorei(0x0CF5, 4); | - |
2891 | | - |
2892 | | - |
2893 | | - |
2894 | if ((pvrHeader->flags & 0x00010000) != 0) never evaluated: (pvrHeader->flags & 0x00010000) != 0 | 0 |
2895 | options &= ~QGLContext::InvertedYBindOption; never executed: options &= ~QGLContext::InvertedYBindOption; | 0 |
2896 | else | - |
2897 | options |= QGLContext::InvertedYBindOption; never executed: options |= QGLContext::InvertedYBindOption; | 0 |
2898 | | - |
2899 | return QSize(pvrHeader->width, pvrHeader->height); never executed: return QSize(pvrHeader->width, pvrHeader->height); | 0 |
2900 | } | - |
2901 | | - |
2902 | | - |
2903 | | - |
2904 | | - |
2905 | | - |
| | |