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