author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qapplication.h" |
|
43 |
#include "qplatformdefs.h" |
|
44 |
#include "qgl.h" |
|
45 |
#include <qdebug.h> |
|
46 |
||
47 |
#if defined(Q_WS_X11) |
|
48 |
#include "private/qt_x11_p.h" |
|
49 |
#include "private/qpixmap_x11_p.h" |
|
50 |
#define INT32 dummy_INT32 |
|
51 |
#define INT8 dummy_INT8 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
52 |
#ifdef QT_NO_EGL |
0 | 53 |
# include <GL/glx.h> |
54 |
#endif |
|
55 |
#undef INT32 |
|
56 |
#undef INT8 |
|
57 |
#include "qx11info_x11.h" |
|
58 |
#elif defined(Q_WS_MAC) |
|
59 |
# include <private/qt_mac_p.h> |
|
60 |
#endif |
|
61 |
||
62 |
#include <qdatetime.h> |
|
63 |
||
64 |
#include <stdlib.h> // malloc |
|
65 |
||
66 |
#include "qpixmap.h" |
|
67 |
#include "qimage.h" |
|
68 |
#include "qgl_p.h" |
|
69 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
70 |
#if !defined(QT_OPENGL_ES_1) |
0 | 71 |
#include "gl2paintengineex/qpaintengineex_opengl2_p.h" |
72 |
#endif |
|
73 |
||
74 |
#ifndef QT_OPENGL_ES_2 |
|
75 |
#include <private/qpaintengine_opengl_p.h> |
|
76 |
#endif |
|
77 |
||
78 |
#ifdef Q_WS_QWS |
|
79 |
#include <private/qglwindowsurface_qws_p.h> |
|
80 |
#endif |
|
81 |
||
82 |
#include <qglpixelbuffer.h> |
|
83 |
#include <qglframebufferobject.h> |
|
84 |
||
85 |
#include <private/qimage_p.h> |
|
86 |
#include <private/qpixmapdata_p.h> |
|
87 |
#include <private/qpixmapdata_gl_p.h> |
|
88 |
#include <private/qglpixelbuffer_p.h> |
|
89 |
#include <private/qwindowsurface_gl_p.h> |
|
90 |
#include <private/qimagepixmapcleanuphooks_p.h> |
|
91 |
#include "qcolormap.h" |
|
92 |
#include "qfile.h" |
|
93 |
#include "qlibrary.h" |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
94 |
#include <qmutex.h> |
0 | 95 |
|
96 |
||
97 |
QT_BEGIN_NAMESPACE |
|
98 |
||
99 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) |
|
100 |
QGLExtensionFuncs QGLContextPrivate::qt_extensionFuncs; |
|
101 |
#endif |
|
102 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
103 |
#ifdef Q_WS_X11 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
104 |
extern const QX11Info *qt_x11Info(const QPaintDevice *pd); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
105 |
#endif |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
106 |
|
0 | 107 |
struct QGLThreadContext { |
108 |
QGLContext *context; |
|
109 |
}; |
|
110 |
||
111 |
static QThreadStorage<QGLThreadContext *> qgl_context_storage; |
|
112 |
||
113 |
Q_GLOBAL_STATIC(QGLFormat, qgl_default_format) |
|
114 |
||
115 |
class QGLDefaultOverlayFormat: public QGLFormat |
|
116 |
{ |
|
117 |
public: |
|
118 |
inline QGLDefaultOverlayFormat() |
|
119 |
{ |
|
120 |
setOption(QGL::FormatOption(0xffff << 16)); // turn off all options |
|
121 |
setOption(QGL::DirectRendering); |
|
122 |
setPlane(1); |
|
123 |
} |
|
124 |
}; |
|
125 |
Q_GLOBAL_STATIC(QGLDefaultOverlayFormat, defaultOverlayFormatInstance) |
|
126 |
||
127 |
Q_GLOBAL_STATIC(QGLSignalProxy, theSignalProxy) |
|
128 |
QGLSignalProxy *QGLSignalProxy::instance() |
|
129 |
{ |
|
130 |
return theSignalProxy(); |
|
131 |
} |
|
132 |
||
133 |
||
134 |
class QGLEngineSelector |
|
135 |
{ |
|
136 |
public: |
|
137 |
QGLEngineSelector() : engineType(QPaintEngine::MaxUser) |
|
138 |
{ |
|
139 |
} |
|
140 |
||
141 |
void setPreferredPaintEngine(QPaintEngine::Type type) { |
|
142 |
if (type == QPaintEngine::OpenGL || type == QPaintEngine::OpenGL2) |
|
143 |
engineType = type; |
|
144 |
} |
|
145 |
||
146 |
QPaintEngine::Type preferredPaintEngine() { |
|
147 |
#ifdef Q_WS_MAC |
|
148 |
// The ATI X1600 driver for Mac OS X does not support return |
|
149 |
// values from functions in GLSL. Since working around this in |
|
150 |
// the GL2 engine would require a big, ugly rewrite, we're |
|
151 |
// falling back to the GL 1 engine.. |
|
152 |
static bool mac_x1600_check_done = false; |
|
153 |
if (!mac_x1600_check_done) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
154 |
QGLTemporaryContext *tmp = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
155 |
if (!QGLContext::currentContext()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
156 |
tmp = new QGLTemporaryContext(); |
0 | 157 |
if (strstr((char *) glGetString(GL_RENDERER), "X1600")) |
158 |
engineType = QPaintEngine::OpenGL; |
|
159 |
if (tmp) |
|
160 |
delete tmp; |
|
161 |
mac_x1600_check_done = true; |
|
162 |
} |
|
163 |
#endif |
|
164 |
if (engineType == QPaintEngine::MaxUser) { |
|
165 |
// No user-set engine - use the defaults |
|
166 |
#if defined(QT_OPENGL_ES_2) |
|
167 |
engineType = QPaintEngine::OpenGL2; |
|
168 |
#else |
|
169 |
// We can't do this in the constructor for this object because it |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
// needs to be called *before* the QApplication constructor. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
// Also check for the FragmentShader extension in conjunction with |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
// the 2.0 version flag, to cover the case where we export the display |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
// from an old GL 1.1 server to a GL 2.x client. In that case we can't |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
// use GL 2.0. |
0 | 175 |
if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
176 |
&& (QGLExtensions::glExtensions() & QGLExtensions::FragmentShader) |
0 | 177 |
&& qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty()) |
178 |
engineType = QPaintEngine::OpenGL2; |
|
179 |
else |
|
180 |
engineType = QPaintEngine::OpenGL; |
|
181 |
#endif |
|
182 |
} |
|
183 |
return engineType; |
|
184 |
} |
|
185 |
||
186 |
private: |
|
187 |
QPaintEngine::Type engineType; |
|
188 |
}; |
|
189 |
||
190 |
Q_GLOBAL_STATIC(QGLEngineSelector, qgl_engine_selector) |
|
191 |
||
192 |
||
193 |
bool qt_gl_preferGL2Engine() |
|
194 |
{ |
|
195 |
return qgl_engine_selector()->preferredPaintEngine() == QPaintEngine::OpenGL2; |
|
196 |
} |
|
197 |
||
198 |
||
199 |
/*! |
|
200 |
\namespace QGL |
|
201 |
\inmodule QtOpenGL |
|
202 |
||
203 |
\brief The QGL namespace specifies miscellaneous identifiers used |
|
204 |
in the Qt OpenGL module. |
|
205 |
||
206 |
\ingroup painting-3D |
|
207 |
*/ |
|
208 |
||
209 |
/*! |
|
210 |
\enum QGL::FormatOption |
|
211 |
||
212 |
This enum specifies the format options that can be used to configure an OpenGL |
|
213 |
context. These are set using QGLFormat::setOption(). |
|
214 |
||
215 |
\value DoubleBuffer Specifies the use of double buffering. |
|
216 |
\value DepthBuffer Enables the use of a depth buffer. |
|
217 |
\value Rgba Specifies that the context should use RGBA as its pixel format. |
|
218 |
\value AlphaChannel Enables the use of an alpha channel. |
|
219 |
\value AccumBuffer Enables the use of an accumulation buffer. |
|
220 |
\value StencilBuffer Enables the use of a stencil buffer. |
|
221 |
\value StereoBuffers Enables the use of a stereo buffers for use with visualization hardware. |
|
222 |
\value DirectRendering Specifies that the context is used for direct rendering to a display. |
|
223 |
\value HasOverlay Enables the use of an overlay. |
|
224 |
\value SampleBuffers Enables the use of sample buffers. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
225 |
\value DeprecatedFunctions Enables the use of deprecated functionality for OpenGL 3.x |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
226 |
contexts. A context with deprecated functionality enabled is |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
227 |
called a full context in the OpenGL specification. |
0 | 228 |
\value SingleBuffer Specifies the use of a single buffer, as opposed to double buffers. |
229 |
\value NoDepthBuffer Disables the use of a depth buffer. |
|
230 |
\value ColorIndex Specifies that the context should use a color index as its pixel format. |
|
231 |
\value NoAlphaChannel Disables the use of an alpha channel. |
|
232 |
\value NoAccumBuffer Disables the use of an accumulation buffer. |
|
233 |
\value NoStencilBuffer Disables the use of a stencil buffer. |
|
234 |
\value NoStereoBuffers Disables the use of stereo buffers. |
|
235 |
\value IndirectRendering Specifies that the context is used for indirect rendering to a buffer. |
|
236 |
\value NoOverlay Disables the use of an overlay. |
|
237 |
\value NoSampleBuffers Disables the use of sample buffers. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
238 |
\value NoDeprecatedFunctions Disables the use of deprecated functionality for OpenGL 3.x |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
239 |
contexts. A context with deprecated functionality disabled is |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
240 |
called a forward compatible context in the OpenGL specification. |
0 | 241 |
|
242 |
\sa {Sample Buffers Example} |
|
243 |
*/ |
|
244 |
||
245 |
/*! |
|
246 |
\fn void QGL::setPreferredPaintEngine(QPaintEngine::Type engineType) |
|
247 |
||
248 |
\since 4.6 |
|
249 |
||
250 |
Sets the preferred OpenGL paint engine that is used to draw onto |
|
251 |
QGLWidget, QGLPixelBuffer and QGLFramebufferObject targets with QPainter |
|
252 |
in Qt. |
|
253 |
||
254 |
The \a engineType parameter specifies which of the GL engines to |
|
255 |
use. Only \c QPaintEngine::OpenGL and \c QPaintEngine::OpenGL2 are |
|
256 |
valid parameters to this function. All other values are ignored. |
|
257 |
||
258 |
By default, the \c QPaintEngine::OpenGL2 engine is used if GL/GLES |
|
259 |
version 2.0 is available, otherwise \c QPaintEngine::OpenGL is |
|
260 |
used. |
|
261 |
||
262 |
\warning This function must be called before the QApplication |
|
263 |
constructor is called. |
|
264 |
*/ |
|
265 |
void QGL::setPreferredPaintEngine(QPaintEngine::Type engineType) |
|
266 |
{ |
|
267 |
qgl_engine_selector()->setPreferredPaintEngine(engineType); |
|
268 |
} |
|
269 |
||
270 |
||
271 |
/***************************************************************************** |
|
272 |
QGLFormat implementation |
|
273 |
*****************************************************************************/ |
|
274 |
||
275 |
||
276 |
/*! |
|
277 |
\class QGLFormat |
|
278 |
\brief The QGLFormat class specifies the display format of an OpenGL |
|
279 |
rendering context. |
|
280 |
||
281 |
\ingroup painting-3D |
|
282 |
||
283 |
A display format has several characteristics: |
|
284 |
\list |
|
285 |
\i \link setDoubleBuffer() Double or single buffering.\endlink |
|
286 |
\i \link setDepth() Depth buffer.\endlink |
|
287 |
\i \link setRgba() RGBA or color index mode.\endlink |
|
288 |
\i \link setAlpha() Alpha channel.\endlink |
|
289 |
\i \link setAccum() Accumulation buffer.\endlink |
|
290 |
\i \link setStencil() Stencil buffer.\endlink |
|
291 |
\i \link setStereo() Stereo buffers.\endlink |
|
292 |
\i \link setDirectRendering() Direct rendering.\endlink |
|
293 |
\i \link setOverlay() Presence of an overlay.\endlink |
|
294 |
\i \link setPlane() Plane of an overlay.\endlink |
|
295 |
\i \link setSampleBuffers() Multisample buffers.\endlink |
|
296 |
\endlist |
|
297 |
||
298 |
You can also specify preferred bit depths for the color buffer, |
|
299 |
depth buffer, alpha buffer, accumulation buffer and the stencil |
|
300 |
buffer with the functions: setRedBufferSize(), setGreenBufferSize(), |
|
301 |
setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), |
|
302 |
setAccumBufferSize() and setStencilBufferSize(). |
|
303 |
||
304 |
Note that even if you specify that you prefer a 32 bit depth |
|
305 |
buffer (e.g. with setDepthBufferSize(32)), the format that is |
|
306 |
chosen may not have a 32 bit depth buffer, even if there is a |
|
307 |
format available with a 32 bit depth buffer. The main reason for |
|
308 |
this is how the system dependant picking algorithms work on the |
|
309 |
different platforms, and some format options may have higher |
|
310 |
precedence than others. |
|
311 |
||
312 |
You create and tell a QGLFormat object what rendering options you |
|
313 |
want from an OpenGL rendering context. |
|
314 |
||
315 |
OpenGL drivers or accelerated hardware may or may not support |
|
316 |
advanced features such as alpha channel or stereographic viewing. |
|
317 |
If you request some features that the driver/hardware does not |
|
318 |
provide when you create a QGLWidget, you will get a rendering |
|
319 |
context with the nearest subset of features. |
|
320 |
||
321 |
There are different ways to define the display characteristics of |
|
322 |
a rendering context. One is to create a QGLFormat and make it the |
|
323 |
default for the entire application: |
|
324 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 0 |
|
325 |
||
326 |
Or you can specify the desired format when creating an object of |
|
327 |
your QGLWidget subclass: |
|
328 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 1 |
|
329 |
||
330 |
After the widget has been created, you can find out which of the |
|
331 |
requested features the system was able to provide: |
|
332 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 2 |
|
333 |
||
334 |
\legalese |
|
335 |
OpenGL is a trademark of Silicon Graphics, Inc. in the |
|
336 |
United States and other countries. |
|
337 |
\endlegalese |
|
338 |
||
339 |
\sa QGLContext, QGLWidget |
|
340 |
*/ |
|
341 |
||
342 |
#ifndef QT_OPENGL_ES |
|
343 |
||
344 |
static inline void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) |
|
345 |
{ |
|
346 |
#define M(row,col) m[col*4+row] |
|
347 |
out[0] = |
|
348 |
M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; |
|
349 |
out[1] = |
|
350 |
M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3]; |
|
351 |
out[2] = |
|
352 |
M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3]; |
|
353 |
out[3] = |
|
354 |
M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3]; |
|
355 |
#undef M |
|
356 |
} |
|
357 |
||
358 |
static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, |
|
359 |
const GLdouble model[16], const GLdouble proj[16], |
|
360 |
const GLint viewport[4], |
|
361 |
GLdouble * winx, GLdouble * winy, GLdouble * winz) |
|
362 |
{ |
|
363 |
GLdouble in[4], out[4]; |
|
364 |
||
365 |
in[0] = objx; |
|
366 |
in[1] = objy; |
|
367 |
in[2] = objz; |
|
368 |
in[3] = 1.0; |
|
369 |
transform_point(out, model, in); |
|
370 |
transform_point(in, proj, out); |
|
371 |
||
372 |
if (in[3] == 0.0) |
|
373 |
return GL_FALSE; |
|
374 |
||
375 |
in[0] /= in[3]; |
|
376 |
in[1] /= in[3]; |
|
377 |
in[2] /= in[3]; |
|
378 |
||
379 |
*winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; |
|
380 |
*winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; |
|
381 |
||
382 |
*winz = (1 + in[2]) / 2; |
|
383 |
return GL_TRUE; |
|
384 |
} |
|
385 |
||
386 |
#endif // !QT_OPENGL_ES |
|
387 |
||
388 |
/*! |
|
389 |
Constructs a QGLFormat object with the following default settings: |
|
390 |
\list |
|
391 |
\i \link setDoubleBuffer() Double buffer:\endlink Enabled. |
|
392 |
\i \link setDepth() Depth buffer:\endlink Enabled. |
|
393 |
\i \link setRgba() RGBA:\endlink Enabled (i.e., color index disabled). |
|
394 |
\i \link setAlpha() Alpha channel:\endlink Disabled. |
|
395 |
\i \link setAccum() Accumulator buffer:\endlink Disabled. |
|
396 |
\i \link setStencil() Stencil buffer:\endlink Enabled. |
|
397 |
\i \link setStereo() Stereo:\endlink Disabled. |
|
398 |
\i \link setDirectRendering() Direct rendering:\endlink Enabled. |
|
399 |
\i \link setOverlay() Overlay:\endlink Disabled. |
|
400 |
\i \link setPlane() Plane:\endlink 0 (i.e., normal plane). |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
\i \link setSampleBuffers() Multisample buffers:\endlink Disabled. |
0 | 402 |
\endlist |
403 |
*/ |
|
404 |
||
405 |
QGLFormat::QGLFormat() |
|
406 |
{ |
|
407 |
d = new QGLFormatPrivate; |
|
408 |
} |
|
409 |
||
410 |
||
411 |
/*! |
|
412 |
Creates a QGLFormat object that is a copy of the current |
|
413 |
defaultFormat(). |
|
414 |
||
415 |
If \a options is not 0, the default format is modified by the |
|
416 |
specified format options. The \a options parameter should be |
|
417 |
QGL::FormatOption values OR'ed together. |
|
418 |
||
419 |
This constructor makes it easy to specify a certain desired format |
|
420 |
in classes derived from QGLWidget, for example: |
|
421 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 3 |
|
422 |
||
423 |
Note that there are QGL::FormatOption values to turn format settings |
|
424 |
both on and off, e.g. QGL::DepthBuffer and QGL::NoDepthBuffer, |
|
425 |
QGL::DirectRendering and QGL::IndirectRendering, etc. |
|
426 |
||
427 |
The \a plane parameter defaults to 0 and is the plane which this |
|
428 |
format should be associated with. Not all OpenGL implementations |
|
429 |
supports overlay/underlay rendering planes. |
|
430 |
||
431 |
\sa defaultFormat(), setOption(), setPlane() |
|
432 |
*/ |
|
433 |
||
434 |
QGLFormat::QGLFormat(QGL::FormatOptions options, int plane) |
|
435 |
{ |
|
436 |
d = new QGLFormatPrivate; |
|
437 |
QGL::FormatOptions newOpts = options; |
|
438 |
d->opts = defaultFormat().d->opts; |
|
439 |
d->opts |= (newOpts & 0xffff); |
|
440 |
d->opts &= ~(newOpts >> 16); |
|
441 |
d->pln = plane; |
|
442 |
} |
|
443 |
||
444 |
/*! |
|
445 |
\internal |
|
446 |
*/ |
|
447 |
void QGLFormat::detach() |
|
448 |
{ |
|
449 |
if (d->ref != 1) { |
|
450 |
QGLFormatPrivate *newd = new QGLFormatPrivate(d); |
|
451 |
if (!d->ref.deref()) |
|
452 |
delete d; |
|
453 |
d = newd; |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
/*! |
|
458 |
Constructs a copy of \a other. |
|
459 |
*/ |
|
460 |
||
461 |
QGLFormat::QGLFormat(const QGLFormat &other) |
|
462 |
{ |
|
463 |
d = other.d; |
|
464 |
d->ref.ref(); |
|
465 |
} |
|
466 |
||
467 |
/*! |
|
468 |
Assigns \a other to this object. |
|
469 |
*/ |
|
470 |
||
471 |
QGLFormat &QGLFormat::operator=(const QGLFormat &other) |
|
472 |
{ |
|
473 |
if (d != other.d) { |
|
474 |
other.d->ref.ref(); |
|
475 |
if (!d->ref.deref()) |
|
476 |
delete d; |
|
477 |
d = other.d; |
|
478 |
} |
|
479 |
return *this; |
|
480 |
} |
|
481 |
||
482 |
/*! |
|
483 |
Destroys the QGLFormat. |
|
484 |
*/ |
|
485 |
QGLFormat::~QGLFormat() |
|
486 |
{ |
|
487 |
if (!d->ref.deref()) |
|
488 |
delete d; |
|
489 |
} |
|
490 |
||
491 |
/*! |
|
492 |
\fn bool QGLFormat::doubleBuffer() const |
|
493 |
||
494 |
Returns true if double buffering is enabled; otherwise returns |
|
495 |
false. Double buffering is enabled by default. |
|
496 |
||
497 |
\sa setDoubleBuffer() |
|
498 |
*/ |
|
499 |
||
500 |
/*! |
|
501 |
If \a enable is true sets double buffering; otherwise sets single |
|
502 |
buffering. |
|
503 |
||
504 |
Double buffering is enabled by default. |
|
505 |
||
506 |
Double buffering is a technique where graphics are rendered on an |
|
507 |
off-screen buffer and not directly to the screen. When the drawing |
|
508 |
has been completed, the program calls a swapBuffers() function to |
|
509 |
exchange the screen contents with the buffer. The result is |
|
510 |
flicker-free drawing and often better performance. |
|
511 |
||
512 |
\sa doubleBuffer(), QGLContext::swapBuffers(), |
|
513 |
QGLWidget::swapBuffers() |
|
514 |
*/ |
|
515 |
||
516 |
void QGLFormat::setDoubleBuffer(bool enable) |
|
517 |
{ |
|
518 |
setOption(enable ? QGL::DoubleBuffer : QGL::SingleBuffer); |
|
519 |
} |
|
520 |
||
521 |
||
522 |
/*! |
|
523 |
\fn bool QGLFormat::depth() const |
|
524 |
||
525 |
Returns true if the depth buffer is enabled; otherwise returns |
|
526 |
false. The depth buffer is enabled by default. |
|
527 |
||
528 |
\sa setDepth(), setDepthBufferSize() |
|
529 |
*/ |
|
530 |
||
531 |
/*! |
|
532 |
If \a enable is true enables the depth buffer; otherwise disables |
|
533 |
the depth buffer. |
|
534 |
||
535 |
The depth buffer is enabled by default. |
|
536 |
||
537 |
The purpose of a depth buffer (or Z-buffering) is to remove hidden |
|
538 |
surfaces. Pixels are assigned Z values based on the distance to |
|
539 |
the viewer. A pixel with a high Z value is closer to the viewer |
|
540 |
than a pixel with a low Z value. This information is used to |
|
541 |
decide whether to draw a pixel or not. |
|
542 |
||
543 |
\sa depth(), setDepthBufferSize() |
|
544 |
*/ |
|
545 |
||
546 |
void QGLFormat::setDepth(bool enable) |
|
547 |
{ |
|
548 |
setOption(enable ? QGL::DepthBuffer : QGL::NoDepthBuffer); |
|
549 |
} |
|
550 |
||
551 |
||
552 |
/*! |
|
553 |
\fn bool QGLFormat::rgba() const |
|
554 |
||
555 |
Returns true if RGBA color mode is set. Returns false if color |
|
556 |
index mode is set. The default color mode is RGBA. |
|
557 |
||
558 |
\sa setRgba() |
|
559 |
*/ |
|
560 |
||
561 |
/*! |
|
562 |
If \a enable is true sets RGBA mode. If \a enable is false sets |
|
563 |
color index mode. |
|
564 |
||
565 |
The default color mode is RGBA. |
|
566 |
||
567 |
RGBA is the preferred mode for most OpenGL applications. In RGBA |
|
568 |
color mode you specify colors as red + green + blue + alpha |
|
569 |
quadruplets. |
|
570 |
||
571 |
In color index mode you specify an index into a color lookup |
|
572 |
table. |
|
573 |
||
574 |
\sa rgba() |
|
575 |
*/ |
|
576 |
||
577 |
void QGLFormat::setRgba(bool enable) |
|
578 |
{ |
|
579 |
setOption(enable ? QGL::Rgba : QGL::ColorIndex); |
|
580 |
} |
|
581 |
||
582 |
||
583 |
/*! |
|
584 |
\fn bool QGLFormat::alpha() const |
|
585 |
||
586 |
Returns true if the alpha buffer in the framebuffer is enabled; |
|
587 |
otherwise returns false. The alpha buffer is disabled by default. |
|
588 |
||
589 |
\sa setAlpha(), setAlphaBufferSize() |
|
590 |
*/ |
|
591 |
||
592 |
/*! |
|
593 |
If \a enable is true enables the alpha buffer; otherwise disables |
|
594 |
the alpha buffer. |
|
595 |
||
596 |
The alpha buffer is disabled by default. |
|
597 |
||
598 |
The alpha buffer is typically used for implementing transparency |
|
599 |
or translucency. The A in RGBA specifies the transparency of a |
|
600 |
pixel. |
|
601 |
||
602 |
\sa alpha(), setAlphaBufferSize() |
|
603 |
*/ |
|
604 |
||
605 |
void QGLFormat::setAlpha(bool enable) |
|
606 |
{ |
|
607 |
setOption(enable ? QGL::AlphaChannel : QGL::NoAlphaChannel); |
|
608 |
} |
|
609 |
||
610 |
||
611 |
/*! |
|
612 |
\fn bool QGLFormat::accum() const |
|
613 |
||
614 |
Returns true if the accumulation buffer is enabled; otherwise |
|
615 |
returns false. The accumulation buffer is disabled by default. |
|
616 |
||
617 |
\sa setAccum(), setAccumBufferSize() |
|
618 |
*/ |
|
619 |
||
620 |
/*! |
|
621 |
If \a enable is true enables the accumulation buffer; otherwise |
|
622 |
disables the accumulation buffer. |
|
623 |
||
624 |
The accumulation buffer is disabled by default. |
|
625 |
||
626 |
The accumulation buffer is used to create blur effects and |
|
627 |
multiple exposures. |
|
628 |
||
629 |
\sa accum(), setAccumBufferSize() |
|
630 |
*/ |
|
631 |
||
632 |
void QGLFormat::setAccum(bool enable) |
|
633 |
{ |
|
634 |
setOption(enable ? QGL::AccumBuffer : QGL::NoAccumBuffer); |
|
635 |
} |
|
636 |
||
637 |
||
638 |
/*! |
|
639 |
\fn bool QGLFormat::stencil() const |
|
640 |
||
641 |
Returns true if the stencil buffer is enabled; otherwise returns |
|
642 |
false. The stencil buffer is enabled by default. |
|
643 |
||
644 |
\sa setStencil(), setStencilBufferSize() |
|
645 |
*/ |
|
646 |
||
647 |
/*! |
|
648 |
If \a enable is true enables the stencil buffer; otherwise |
|
649 |
disables the stencil buffer. |
|
650 |
||
651 |
The stencil buffer is enabled by default. |
|
652 |
||
653 |
The stencil buffer masks certain parts of the drawing area so that |
|
654 |
masked parts are not drawn on. |
|
655 |
||
656 |
\sa stencil(), setStencilBufferSize() |
|
657 |
*/ |
|
658 |
||
659 |
void QGLFormat::setStencil(bool enable) |
|
660 |
{ |
|
661 |
setOption(enable ? QGL::StencilBuffer: QGL::NoStencilBuffer); |
|
662 |
} |
|
663 |
||
664 |
||
665 |
/*! |
|
666 |
\fn bool QGLFormat::stereo() const |
|
667 |
||
668 |
Returns true if stereo buffering is enabled; otherwise returns |
|
669 |
false. Stereo buffering is disabled by default. |
|
670 |
||
671 |
\sa setStereo() |
|
672 |
*/ |
|
673 |
||
674 |
/*! |
|
675 |
If \a enable is true enables stereo buffering; otherwise disables |
|
676 |
stereo buffering. |
|
677 |
||
678 |
Stereo buffering is disabled by default. |
|
679 |
||
680 |
Stereo buffering provides extra color buffers to generate left-eye |
|
681 |
and right-eye images. |
|
682 |
||
683 |
\sa stereo() |
|
684 |
*/ |
|
685 |
||
686 |
void QGLFormat::setStereo(bool enable) |
|
687 |
{ |
|
688 |
setOption(enable ? QGL::StereoBuffers : QGL::NoStereoBuffers); |
|
689 |
} |
|
690 |
||
691 |
||
692 |
/*! |
|
693 |
\fn bool QGLFormat::directRendering() const |
|
694 |
||
695 |
Returns true if direct rendering is enabled; otherwise returns |
|
696 |
false. |
|
697 |
||
698 |
Direct rendering is enabled by default. |
|
699 |
||
700 |
\sa setDirectRendering() |
|
701 |
*/ |
|
702 |
||
703 |
/*! |
|
704 |
If \a enable is true enables direct rendering; otherwise disables |
|
705 |
direct rendering. |
|
706 |
||
707 |
Direct rendering is enabled by default. |
|
708 |
||
709 |
Enabling this option will make OpenGL bypass the underlying window |
|
710 |
system and render directly from hardware to the screen, if this is |
|
711 |
supported by the system. |
|
712 |
||
713 |
\sa directRendering() |
|
714 |
*/ |
|
715 |
||
716 |
void QGLFormat::setDirectRendering(bool enable) |
|
717 |
{ |
|
718 |
setOption(enable ? QGL::DirectRendering : QGL::IndirectRendering); |
|
719 |
} |
|
720 |
||
721 |
/*! |
|
722 |
\fn bool QGLFormat::sampleBuffers() const |
|
723 |
||
724 |
Returns true if multisample buffer support is enabled; otherwise |
|
725 |
returns false. |
|
726 |
||
727 |
The multisample buffer is disabled by default. |
|
728 |
||
729 |
\sa setSampleBuffers() |
|
730 |
*/ |
|
731 |
||
732 |
/*! |
|
733 |
If \a enable is true, a GL context with multisample buffer support |
|
734 |
is picked; otherwise ignored. |
|
735 |
||
736 |
\sa sampleBuffers(), setSamples(), samples() |
|
737 |
*/ |
|
738 |
void QGLFormat::setSampleBuffers(bool enable) |
|
739 |
{ |
|
740 |
setOption(enable ? QGL::SampleBuffers : QGL::NoSampleBuffers); |
|
741 |
} |
|
742 |
||
743 |
/*! |
|
744 |
Returns the number of samples per pixel when multisampling is |
|
745 |
enabled. By default, the highest number of samples that is |
|
746 |
available is used. |
|
747 |
||
748 |
\sa setSampleBuffers(), sampleBuffers(), setSamples() |
|
749 |
*/ |
|
750 |
int QGLFormat::samples() const |
|
751 |
{ |
|
752 |
return d->numSamples; |
|
753 |
} |
|
754 |
||
755 |
/*! |
|
756 |
Set the preferred number of samples per pixel when multisampling |
|
757 |
is enabled to \a numSamples. By default, the highest number of |
|
758 |
samples available is used. |
|
759 |
||
760 |
\sa setSampleBuffers(), sampleBuffers(), samples() |
|
761 |
*/ |
|
762 |
void QGLFormat::setSamples(int numSamples) |
|
763 |
{ |
|
764 |
detach(); |
|
765 |
if (numSamples < 0) { |
|
766 |
qWarning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); |
|
767 |
return; |
|
768 |
} |
|
769 |
d->numSamples = numSamples; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
770 |
setSampleBuffers(numSamples > 0); |
0 | 771 |
} |
772 |
||
773 |
/*! |
|
774 |
\since 4.2 |
|
775 |
||
776 |
Set the preferred swap interval. This can be used to sync the GL |
|
777 |
drawing into a system window to the vertical refresh of the screen. |
|
778 |
Setting an \a interval value of 0 will turn the vertical refresh syncing |
|
779 |
off, any value higher than 0 will turn the vertical syncing on. |
|
780 |
||
781 |
Under Windows and under X11, where the \c{WGL_EXT_swap_control} |
|
782 |
and \c{GLX_SGI_video_sync} extensions are used, the \a interval |
|
783 |
parameter can be used to set the minimum number of video frames |
|
784 |
that are displayed before a buffer swap will occur. In effect, |
|
785 |
setting the \a interval to 10, means there will be 10 vertical |
|
786 |
retraces between every buffer swap. |
|
787 |
||
788 |
Under Windows the \c{WGL_EXT_swap_control} extension has to be present, |
|
789 |
and under X11 the \c{GLX_SGI_video_sync} extension has to be present. |
|
790 |
*/ |
|
791 |
void QGLFormat::setSwapInterval(int interval) |
|
792 |
{ |
|
793 |
detach(); |
|
794 |
d->swapInterval = interval; |
|
795 |
} |
|
796 |
||
797 |
/*! |
|
798 |
\since 4.2 |
|
799 |
||
800 |
Returns the currently set swap interval. -1 is returned if setting |
|
801 |
the swap interval isn't supported in the system GL implementation. |
|
802 |
*/ |
|
803 |
int QGLFormat::swapInterval() const |
|
804 |
{ |
|
805 |
return d->swapInterval; |
|
806 |
} |
|
807 |
||
808 |
/*! |
|
809 |
\fn bool QGLFormat::hasOverlay() const |
|
810 |
||
811 |
Returns true if overlay plane is enabled; otherwise returns false. |
|
812 |
||
813 |
Overlay is disabled by default. |
|
814 |
||
815 |
\sa setOverlay() |
|
816 |
*/ |
|
817 |
||
818 |
/*! |
|
819 |
If \a enable is true enables an overlay plane; otherwise disables |
|
820 |
the overlay plane. |
|
821 |
||
822 |
Enabling the overlay plane will cause QGLWidget to create an |
|
823 |
additional context in an overlay plane. See the QGLWidget |
|
824 |
documentation for further information. |
|
825 |
||
826 |
\sa hasOverlay() |
|
827 |
*/ |
|
828 |
||
829 |
void QGLFormat::setOverlay(bool enable) |
|
830 |
{ |
|
831 |
setOption(enable ? QGL::HasOverlay : QGL::NoOverlay); |
|
832 |
} |
|
833 |
||
834 |
/*! |
|
835 |
Returns the plane of this format. The default for normal formats |
|
836 |
is 0, which means the normal plane. The default for overlay |
|
837 |
formats is 1, which is the first overlay plane. |
|
838 |
||
839 |
\sa setPlane(), defaultOverlayFormat() |
|
840 |
*/ |
|
841 |
int QGLFormat::plane() const |
|
842 |
{ |
|
843 |
return d->pln; |
|
844 |
} |
|
845 |
||
846 |
/*! |
|
847 |
Sets the requested plane to \a plane. 0 is the normal plane, 1 is |
|
848 |
the first overlay plane, 2 is the second overlay plane, etc.; -1, |
|
849 |
-2, etc. are underlay planes. |
|
850 |
||
851 |
Note that in contrast to other format specifications, the plane |
|
852 |
specifications will be matched exactly. This means that if you |
|
853 |
specify a plane that the underlying OpenGL system cannot provide, |
|
854 |
an \link QGLWidget::isValid() invalid\endlink QGLWidget will be |
|
855 |
created. |
|
856 |
||
857 |
\sa plane() |
|
858 |
*/ |
|
859 |
void QGLFormat::setPlane(int plane) |
|
860 |
{ |
|
861 |
detach(); |
|
862 |
d->pln = plane; |
|
863 |
} |
|
864 |
||
865 |
/*! |
|
866 |
Sets the format option to \a opt. |
|
867 |
||
868 |
\sa testOption() |
|
869 |
*/ |
|
870 |
||
871 |
void QGLFormat::setOption(QGL::FormatOptions opt) |
|
872 |
{ |
|
873 |
detach(); |
|
874 |
if (opt & 0xffff) |
|
875 |
d->opts |= opt; |
|
876 |
else |
|
877 |
d->opts &= ~(opt >> 16); |
|
878 |
} |
|
879 |
||
880 |
||
881 |
||
882 |
/*! |
|
883 |
Returns true if format option \a opt is set; otherwise returns false. |
|
884 |
||
885 |
\sa setOption() |
|
886 |
*/ |
|
887 |
||
888 |
bool QGLFormat::testOption(QGL::FormatOptions opt) const |
|
889 |
{ |
|
890 |
if (opt & 0xffff) |
|
891 |
return (d->opts & opt) != 0; |
|
892 |
else |
|
893 |
return (d->opts & (opt >> 16)) == 0; |
|
894 |
} |
|
895 |
||
896 |
/*! |
|
897 |
Set the minimum depth buffer size to \a size. |
|
898 |
||
899 |
\sa depthBufferSize(), setDepth(), depth() |
|
900 |
*/ |
|
901 |
void QGLFormat::setDepthBufferSize(int size) |
|
902 |
{ |
|
903 |
detach(); |
|
904 |
if (size < 0) { |
|
905 |
qWarning("QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); |
|
906 |
return; |
|
907 |
} |
|
908 |
d->depthSize = size; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
909 |
setDepth(size > 0); |
0 | 910 |
} |
911 |
||
912 |
/*! |
|
913 |
Returns the depth buffer size. |
|
914 |
||
915 |
\sa depth(), setDepth(), setDepthBufferSize() |
|
916 |
*/ |
|
917 |
int QGLFormat::depthBufferSize() const |
|
918 |
{ |
|
919 |
return d->depthSize; |
|
920 |
} |
|
921 |
||
922 |
/*! |
|
923 |
\since 4.2 |
|
924 |
||
925 |
Set the preferred red buffer size to \a size. |
|
926 |
||
927 |
\sa setGreenBufferSize(), setBlueBufferSize(), setAlphaBufferSize() |
|
928 |
*/ |
|
929 |
void QGLFormat::setRedBufferSize(int size) |
|
930 |
{ |
|
931 |
detach(); |
|
932 |
if (size < 0) { |
|
933 |
qWarning("QGLFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); |
|
934 |
return; |
|
935 |
} |
|
936 |
d->redSize = size; |
|
937 |
} |
|
938 |
||
939 |
/*! |
|
940 |
\since 4.2 |
|
941 |
||
942 |
Returns the red buffer size. |
|
943 |
||
944 |
\sa setRedBufferSize() |
|
945 |
*/ |
|
946 |
int QGLFormat::redBufferSize() const |
|
947 |
{ |
|
948 |
return d->redSize; |
|
949 |
} |
|
950 |
||
951 |
/*! |
|
952 |
\since 4.2 |
|
953 |
||
954 |
Set the preferred green buffer size to \a size. |
|
955 |
||
956 |
\sa setRedBufferSize(), setBlueBufferSize(), setAlphaBufferSize() |
|
957 |
*/ |
|
958 |
void QGLFormat::setGreenBufferSize(int size) |
|
959 |
{ |
|
960 |
detach(); |
|
961 |
if (size < 0) { |
|
962 |
qWarning("QGLFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); |
|
963 |
return; |
|
964 |
} |
|
965 |
d->greenSize = size; |
|
966 |
} |
|
967 |
||
968 |
/*! |
|
969 |
\since 4.2 |
|
970 |
||
971 |
Returns the green buffer size. |
|
972 |
||
973 |
\sa setGreenBufferSize() |
|
974 |
*/ |
|
975 |
int QGLFormat::greenBufferSize() const |
|
976 |
{ |
|
977 |
return d->greenSize; |
|
978 |
} |
|
979 |
||
980 |
/*! |
|
981 |
\since 4.2 |
|
982 |
||
983 |
Set the preferred blue buffer size to \a size. |
|
984 |
||
985 |
\sa setRedBufferSize(), setGreenBufferSize(), setAlphaBufferSize() |
|
986 |
*/ |
|
987 |
void QGLFormat::setBlueBufferSize(int size) |
|
988 |
{ |
|
989 |
detach(); |
|
990 |
if (size < 0) { |
|
991 |
qWarning("QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); |
|
992 |
return; |
|
993 |
} |
|
994 |
d->blueSize = size; |
|
995 |
} |
|
996 |
||
997 |
/*! |
|
998 |
\since 4.2 |
|
999 |
||
1000 |
Returns the blue buffer size. |
|
1001 |
||
1002 |
\sa setBlueBufferSize() |
|
1003 |
*/ |
|
1004 |
int QGLFormat::blueBufferSize() const |
|
1005 |
{ |
|
1006 |
return d->blueSize; |
|
1007 |
} |
|
1008 |
||
1009 |
/*! |
|
1010 |
Set the preferred alpha buffer size to \a size. |
|
1011 |
This function implicitly enables the alpha channel. |
|
1012 |
||
1013 |
\sa setRedBufferSize(), setGreenBufferSize(), alphaBufferSize() |
|
1014 |
*/ |
|
1015 |
void QGLFormat::setAlphaBufferSize(int size) |
|
1016 |
{ |
|
1017 |
detach(); |
|
1018 |
if (size < 0) { |
|
1019 |
qWarning("QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); |
|
1020 |
return; |
|
1021 |
} |
|
1022 |
d->alphaSize = size; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1023 |
setAlpha(size > 0); |
0 | 1024 |
} |
1025 |
||
1026 |
/*! |
|
1027 |
Returns the alpha buffer size. |
|
1028 |
||
1029 |
\sa alpha(), setAlpha(), setAlphaBufferSize() |
|
1030 |
*/ |
|
1031 |
int QGLFormat::alphaBufferSize() const |
|
1032 |
{ |
|
1033 |
return d->alphaSize; |
|
1034 |
} |
|
1035 |
||
1036 |
/*! |
|
1037 |
Set the preferred accumulation buffer size, where \a size is the |
|
1038 |
bit depth for each RGBA component. |
|
1039 |
||
1040 |
\sa accum(), setAccum(), accumBufferSize() |
|
1041 |
*/ |
|
1042 |
void QGLFormat::setAccumBufferSize(int size) |
|
1043 |
{ |
|
1044 |
detach(); |
|
1045 |
if (size < 0) { |
|
1046 |
qWarning("QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); |
|
1047 |
return; |
|
1048 |
} |
|
1049 |
d->accumSize = size; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1050 |
setAccum(size > 0); |
0 | 1051 |
} |
1052 |
||
1053 |
/*! |
|
1054 |
Returns the accumulation buffer size. |
|
1055 |
||
1056 |
\sa setAccumBufferSize(), accum(), setAccum() |
|
1057 |
*/ |
|
1058 |
int QGLFormat::accumBufferSize() const |
|
1059 |
{ |
|
1060 |
return d->accumSize; |
|
1061 |
} |
|
1062 |
||
1063 |
/*! |
|
1064 |
Set the preferred stencil buffer size to \a size. |
|
1065 |
||
1066 |
\sa stencilBufferSize(), setStencil(), stencil() |
|
1067 |
*/ |
|
1068 |
void QGLFormat::setStencilBufferSize(int size) |
|
1069 |
{ |
|
1070 |
detach(); |
|
1071 |
if (size < 0) { |
|
1072 |
qWarning("QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); |
|
1073 |
return; |
|
1074 |
} |
|
1075 |
d->stencilSize = size; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1076 |
setStencil(size > 0); |
0 | 1077 |
} |
1078 |
||
1079 |
/*! |
|
1080 |
Returns the stencil buffer size. |
|
1081 |
||
1082 |
\sa stencil(), setStencil(), setStencilBufferSize() |
|
1083 |
*/ |
|
1084 |
int QGLFormat::stencilBufferSize() const |
|
1085 |
{ |
|
1086 |
return d->stencilSize; |
|
1087 |
} |
|
1088 |
||
1089 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1090 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1091 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1092 |
Set the OpenGL version to the \a major and \a minor numbers. If a |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1093 |
context compatible with the requested OpenGL version cannot be |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1094 |
created, a context compatible with version 1.x is created instead. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1095 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1096 |
\sa majorVersion(), minorVersion() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1097 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1098 |
void QGLFormat::setVersion(int major, int minor) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1099 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1100 |
if (major < 1 || minor < 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1101 |
qWarning("QGLFormat::setVersion: Cannot set zero or negative version number %d.%d", major, minor); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1102 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1103 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1104 |
detach(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1105 |
d->majorVersion = major; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1106 |
d->minorVersion = minor; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1107 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1108 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1109 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1110 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1111 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1112 |
Returns the OpenGL major version. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1113 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1114 |
\sa setVersion(), minorVersion() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1115 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1116 |
int QGLFormat::majorVersion() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1117 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1118 |
return d->majorVersion; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1119 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1120 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1121 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1122 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1123 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1124 |
Returns the OpenGL minor version. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1125 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1126 |
\sa setVersion(), majorVersion() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1127 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1128 |
int QGLFormat::minorVersion() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1129 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1130 |
return d->minorVersion; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1131 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1132 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1133 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1134 |
\enum QGLFormat::OpenGLContextProfile |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1135 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1136 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1137 |
This enum describes the OpenGL context profiles that can be |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1138 |
specified for contexts implementing OpenGL version 3.2 or |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1139 |
higher. These profiles are different from OpenGL ES profiles. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1140 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1141 |
\value NoProfile OpenGL version is lower than 3.2. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1142 |
\value CoreProfile Functionality deprecated in OpenGL version 3.0 is not available. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1143 |
\value CompatibilityProfile Functionality from earlier OpenGL versions is available. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1144 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1145 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1146 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1147 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1148 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1149 |
Set the OpenGL context profile to \a profile. The \a profile is |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1150 |
ignored if the requested OpenGL version is less than 3.2. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1151 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1152 |
\sa profile() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1153 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1154 |
void QGLFormat::setProfile(OpenGLContextProfile profile) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1155 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1156 |
detach(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1157 |
d->profile = profile; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1158 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1159 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1160 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1161 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1162 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1163 |
Returns the OpenGL context profile. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1164 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1165 |
\sa setProfile() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1166 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1167 |
QGLFormat::OpenGLContextProfile QGLFormat::profile() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1168 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1169 |
return d->profile; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1170 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1171 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1172 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1173 |
/*! |
0 | 1174 |
\fn bool QGLFormat::hasOpenGL() |
1175 |
||
1176 |
Returns true if the window system has any OpenGL support; |
|
1177 |
otherwise returns false. |
|
1178 |
||
1179 |
\warning This function must not be called until the QApplication |
|
1180 |
object has been created. |
|
1181 |
*/ |
|
1182 |
||
1183 |
||
1184 |
||
1185 |
/*! |
|
1186 |
\fn bool QGLFormat::hasOpenGLOverlays() |
|
1187 |
||
1188 |
Returns true if the window system supports OpenGL overlays; |
|
1189 |
otherwise returns false. |
|
1190 |
||
1191 |
\warning This function must not be called until the QApplication |
|
1192 |
object has been created. |
|
1193 |
*/ |
|
1194 |
||
1195 |
QGLFormat::OpenGLVersionFlags Q_AUTOTEST_EXPORT qOpenGLVersionFlagsFromString(const QString &versionString) |
|
1196 |
{ |
|
1197 |
QGLFormat::OpenGLVersionFlags versionFlags = QGLFormat::OpenGL_Version_None; |
|
1198 |
||
1199 |
if (versionString.startsWith(QLatin1String("OpenGL ES"))) { |
|
1200 |
QStringList parts = versionString.split(QLatin1Char(' ')); |
|
1201 |
if (parts.size() >= 3) { |
|
1202 |
if (parts[2].startsWith(QLatin1String("1."))) { |
|
1203 |
if (parts[1].endsWith(QLatin1String("-CM"))) { |
|
1204 |
versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_0 | |
|
1205 |
QGLFormat::OpenGL_ES_CommonLite_Version_1_0; |
|
1206 |
if (parts[2].startsWith(QLatin1String("1.1"))) |
|
1207 |
versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | |
|
1208 |
QGLFormat::OpenGL_ES_CommonLite_Version_1_1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1209 |
} else { |
0 | 1210 |
// Not -CM, must be CL, CommonLite |
1211 |
versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_0; |
|
1212 |
if (parts[2].startsWith(QLatin1String("1.1"))) |
|
1213 |
versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; |
|
1214 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1215 |
} else { |
0 | 1216 |
// OpenGL ES version 2.0 or higher |
1217 |
versionFlags |= QGLFormat::OpenGL_ES_Version_2_0; |
|
1218 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1219 |
} else { |
0 | 1220 |
// if < 3 parts to the name, it is an unrecognised OpenGL ES |
1221 |
qWarning("Unrecognised OpenGL ES version"); |
|
1222 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1223 |
} else { |
0 | 1224 |
// not ES, regular OpenGL, the version numbers are first in the string |
1225 |
if (versionString.startsWith(QLatin1String("1."))) { |
|
1226 |
switch (versionString[2].toAscii()) { |
|
1227 |
case '5': |
|
1228 |
versionFlags |= QGLFormat::OpenGL_Version_1_5; |
|
1229 |
case '4': |
|
1230 |
versionFlags |= QGLFormat::OpenGL_Version_1_4; |
|
1231 |
case '3': |
|
1232 |
versionFlags |= QGLFormat::OpenGL_Version_1_3; |
|
1233 |
case '2': |
|
1234 |
versionFlags |= QGLFormat::OpenGL_Version_1_2; |
|
1235 |
case '1': |
|
1236 |
versionFlags |= QGLFormat::OpenGL_Version_1_1; |
|
1237 |
default: |
|
1238 |
break; |
|
1239 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1240 |
} else if (versionString.startsWith(QLatin1String("2."))) { |
0 | 1241 |
versionFlags |= QGLFormat::OpenGL_Version_1_1 | |
1242 |
QGLFormat::OpenGL_Version_1_2 | |
|
1243 |
QGLFormat::OpenGL_Version_1_3 | |
|
1244 |
QGLFormat::OpenGL_Version_1_4 | |
|
1245 |
QGLFormat::OpenGL_Version_1_5 | |
|
1246 |
QGLFormat::OpenGL_Version_2_0; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1247 |
if (versionString[2].toAscii() == '1') |
0 | 1248 |
versionFlags |= QGLFormat::OpenGL_Version_2_1; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1249 |
} else if (versionString.startsWith(QLatin1String("3."))) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1250 |
versionFlags |= QGLFormat::OpenGL_Version_1_1 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1251 |
QGLFormat::OpenGL_Version_1_2 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1252 |
QGLFormat::OpenGL_Version_1_3 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1253 |
QGLFormat::OpenGL_Version_1_4 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1254 |
QGLFormat::OpenGL_Version_1_5 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1255 |
QGLFormat::OpenGL_Version_2_0 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1256 |
QGLFormat::OpenGL_Version_2_1 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1257 |
QGLFormat::OpenGL_Version_3_0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1258 |
switch (versionString[2].toAscii()) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1259 |
case '3': |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1260 |
versionFlags |= QGLFormat::OpenGL_Version_3_3; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1261 |
case '2': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1262 |
versionFlags |= QGLFormat::OpenGL_Version_3_2; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1263 |
case '1': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1264 |
versionFlags |= QGLFormat::OpenGL_Version_3_1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1265 |
case '0': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1266 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1267 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1268 |
versionFlags |= QGLFormat::OpenGL_Version_3_1 | |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1269 |
QGLFormat::OpenGL_Version_3_2 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1270 |
QGLFormat::OpenGL_Version_3_3; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1271 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1272 |
} |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1273 |
} else if (versionString.startsWith(QLatin1String("4."))) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1274 |
versionFlags |= QGLFormat::OpenGL_Version_1_1 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1275 |
QGLFormat::OpenGL_Version_1_2 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1276 |
QGLFormat::OpenGL_Version_1_3 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1277 |
QGLFormat::OpenGL_Version_1_4 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1278 |
QGLFormat::OpenGL_Version_1_5 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1279 |
QGLFormat::OpenGL_Version_2_0 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1280 |
QGLFormat::OpenGL_Version_2_1 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1281 |
QGLFormat::OpenGL_Version_3_0 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1282 |
QGLFormat::OpenGL_Version_3_1 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1283 |
QGLFormat::OpenGL_Version_3_2 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1284 |
QGLFormat::OpenGL_Version_3_3 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1285 |
QGLFormat::OpenGL_Version_4_0; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1286 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1287 |
versionFlags |= QGLFormat::OpenGL_Version_1_1 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1288 |
QGLFormat::OpenGL_Version_1_2 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1289 |
QGLFormat::OpenGL_Version_1_3 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1290 |
QGLFormat::OpenGL_Version_1_4 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1291 |
QGLFormat::OpenGL_Version_1_5 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1292 |
QGLFormat::OpenGL_Version_2_0 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1293 |
QGLFormat::OpenGL_Version_2_1 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1294 |
QGLFormat::OpenGL_Version_3_0 | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1295 |
QGLFormat::OpenGL_Version_3_1 | |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1296 |
QGLFormat::OpenGL_Version_3_2 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1297 |
QGLFormat::OpenGL_Version_3_3 | |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1298 |
QGLFormat::OpenGL_Version_4_0; |
0 | 1299 |
} |
1300 |
} |
|
1301 |
return versionFlags; |
|
1302 |
} |
|
1303 |
||
1304 |
/*! |
|
1305 |
\enum QGLFormat::OpenGLVersionFlag |
|
1306 |
\since 4.2 |
|
1307 |
||
1308 |
This enum describes the various OpenGL versions that are |
|
1309 |
recognized by Qt. Use the QGLFormat::openGLVersionFlags() function |
|
1310 |
to identify which versions that are supported at runtime. |
|
1311 |
||
1312 |
\value OpenGL_Version_None If no OpenGL is present or if no OpenGL context is current. |
|
1313 |
||
1314 |
\value OpenGL_Version_1_1 OpenGL version 1.1 or higher is present. |
|
1315 |
||
1316 |
\value OpenGL_Version_1_2 OpenGL version 1.2 or higher is present. |
|
1317 |
||
1318 |
\value OpenGL_Version_1_3 OpenGL version 1.3 or higher is present. |
|
1319 |
||
1320 |
\value OpenGL_Version_1_4 OpenGL version 1.4 or higher is present. |
|
1321 |
||
1322 |
\value OpenGL_Version_1_5 OpenGL version 1.5 or higher is present. |
|
1323 |
||
1324 |
\value OpenGL_Version_2_0 OpenGL version 2.0 or higher is present. |
|
1325 |
Note that version 2.0 supports all the functionality of version 1.5. |
|
1326 |
||
1327 |
\value OpenGL_Version_2_1 OpenGL version 2.1 or higher is present. |
|
1328 |
||
1329 |
\value OpenGL_Version_3_0 OpenGL version 3.0 or higher is present. |
|
1330 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1331 |
\value OpenGL_Version_3_1 OpenGL version 3.1 or higher is present. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1332 |
Note that OpenGL version 3.1 or higher does not necessarily support all the features of |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1333 |
version 3.0 and lower. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1334 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1335 |
\value OpenGL_Version_3_2 OpenGL version 3.2 or higher is present. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1336 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1337 |
\value OpenGL_Version_3_3 OpenGL version 3.3 or higher is present. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1338 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1339 |
\value OpenGL_Version_4_0 OpenGL version 4.0 or higher is present. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1340 |
|
0 | 1341 |
\value OpenGL_ES_CommonLite_Version_1_0 OpenGL ES version 1.0 Common Lite or higher is present. |
1342 |
||
1343 |
\value OpenGL_ES_Common_Version_1_0 OpenGL ES version 1.0 Common or higher is present. |
|
1344 |
The Common profile supports all the features of Common Lite. |
|
1345 |
||
1346 |
\value OpenGL_ES_CommonLite_Version_1_1 OpenGL ES version 1.1 Common Lite or higher is present. |
|
1347 |
||
1348 |
\value OpenGL_ES_Common_Version_1_1 OpenGL ES version 1.1 Common or higher is present. |
|
1349 |
The Common profile supports all the features of Common Lite. |
|
1350 |
||
1351 |
\value OpenGL_ES_Version_2_0 OpenGL ES version 2.0 or higher is present. |
|
1352 |
Note that OpenGL ES version 2.0 does not support all the features of OpenGL ES 1.x. |
|
1353 |
So if OpenGL_ES_Version_2_0 is returned, none of the ES 1.x flags are returned. |
|
1354 |
||
1355 |
See also \l{http://www.opengl.org} for more information about the different |
|
1356 |
revisions of OpenGL. |
|
1357 |
||
1358 |
\sa openGLVersionFlags() |
|
1359 |
*/ |
|
1360 |
||
1361 |
/*! |
|
1362 |
\since 4.2 |
|
1363 |
||
1364 |
Identifies, at runtime, which OpenGL versions that are supported |
|
1365 |
by the current platform. |
|
1366 |
||
1367 |
Note that if OpenGL version 1.5 is supported, its predecessors |
|
1368 |
(i.e., version 1.4 and lower) are also supported. To identify the |
|
1369 |
support of a particular feature, like multi texturing, test for |
|
1370 |
the version in which the feature was first introduced (i.e., |
|
1371 |
version 1.3 in the case of multi texturing) to adapt to the largest |
|
1372 |
possible group of runtime platforms. |
|
1373 |
||
1374 |
This function needs a valid current OpenGL context to work; |
|
1375 |
otherwise it will return OpenGL_Version_None. |
|
1376 |
||
1377 |
\sa hasOpenGL(), hasOpenGLOverlays() |
|
1378 |
*/ |
|
1379 |
QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags() |
|
1380 |
{ |
|
1381 |
static bool cachedDefault = false; |
|
1382 |
static OpenGLVersionFlags defaultVersionFlags = OpenGL_Version_None; |
|
1383 |
QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1384 |
QGLTemporaryContext *tmpContext = 0; |
0 | 1385 |
|
1386 |
if (currentCtx && currentCtx->d_func()->version_flags_cached) |
|
1387 |
return currentCtx->d_func()->version_flags; |
|
1388 |
||
1389 |
if (!currentCtx) { |
|
1390 |
if (cachedDefault) { |
|
1391 |
return defaultVersionFlags; |
|
1392 |
} else { |
|
1393 |
if (!hasOpenGL()) |
|
1394 |
return defaultVersionFlags; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1395 |
tmpContext = new QGLTemporaryContext; |
0 | 1396 |
cachedDefault = true; |
1397 |
} |
|
1398 |
} |
|
1399 |
||
1400 |
QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION)))); |
|
1401 |
OpenGLVersionFlags versionFlags = qOpenGLVersionFlagsFromString(versionString); |
|
1402 |
if (currentCtx) { |
|
1403 |
currentCtx->d_func()->version_flags_cached = true; |
|
1404 |
currentCtx->d_func()->version_flags = versionFlags; |
|
1405 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1406 |
if (tmpContext) { |
0 | 1407 |
defaultVersionFlags = versionFlags; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1408 |
delete tmpContext; |
0 | 1409 |
} |
1410 |
||
1411 |
return versionFlags; |
|
1412 |
} |
|
1413 |
||
1414 |
||
1415 |
/*! |
|
1416 |
Returns the default QGLFormat for the application. All QGLWidget |
|
1417 |
objects that are created use this format unless another format is |
|
1418 |
specified, e.g. when they are constructed. |
|
1419 |
||
1420 |
If no special default format has been set using |
|
1421 |
setDefaultFormat(), the default format is the same as that created |
|
1422 |
with QGLFormat(). |
|
1423 |
||
1424 |
\sa setDefaultFormat() |
|
1425 |
*/ |
|
1426 |
||
1427 |
QGLFormat QGLFormat::defaultFormat() |
|
1428 |
{ |
|
1429 |
return *qgl_default_format(); |
|
1430 |
} |
|
1431 |
||
1432 |
/*! |
|
1433 |
Sets a new default QGLFormat for the application to \a f. For |
|
1434 |
example, to set single buffering as the default instead of double |
|
1435 |
buffering, your main() might contain code like this: |
|
1436 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 4 |
|
1437 |
||
1438 |
\sa defaultFormat() |
|
1439 |
*/ |
|
1440 |
||
1441 |
void QGLFormat::setDefaultFormat(const QGLFormat &f) |
|
1442 |
{ |
|
1443 |
*qgl_default_format() = f; |
|
1444 |
} |
|
1445 |
||
1446 |
||
1447 |
/*! |
|
1448 |
Returns the default QGLFormat for overlay contexts. |
|
1449 |
||
1450 |
The default overlay format is: |
|
1451 |
\list |
|
1452 |
\i \link setDoubleBuffer() Double buffer:\endlink Disabled. |
|
1453 |
\i \link setDepth() Depth buffer:\endlink Disabled. |
|
1454 |
\i \link setRgba() RGBA:\endlink Disabled (i.e., color index enabled). |
|
1455 |
\i \link setAlpha() Alpha channel:\endlink Disabled. |
|
1456 |
\i \link setAccum() Accumulator buffer:\endlink Disabled. |
|
1457 |
\i \link setStencil() Stencil buffer:\endlink Disabled. |
|
1458 |
\i \link setStereo() Stereo:\endlink Disabled. |
|
1459 |
\i \link setDirectRendering() Direct rendering:\endlink Enabled. |
|
1460 |
\i \link setOverlay() Overlay:\endlink Disabled. |
|
1461 |
\i \link setSampleBuffers() Multisample buffers:\endlink Disabled. |
|
1462 |
\i \link setPlane() Plane:\endlink 1 (i.e., first overlay plane). |
|
1463 |
\endlist |
|
1464 |
||
1465 |
\sa setDefaultFormat() |
|
1466 |
*/ |
|
1467 |
||
1468 |
QGLFormat QGLFormat::defaultOverlayFormat() |
|
1469 |
{ |
|
1470 |
return *defaultOverlayFormatInstance(); |
|
1471 |
} |
|
1472 |
||
1473 |
/*! |
|
1474 |
Sets a new default QGLFormat for overlay contexts to \a f. This |
|
1475 |
format is used whenever a QGLWidget is created with a format that |
|
1476 |
hasOverlay() enabled. |
|
1477 |
||
1478 |
For example, to get a double buffered overlay context (if |
|
1479 |
available), use code like this: |
|
1480 |
||
1481 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 5 |
|
1482 |
||
1483 |
As usual, you can find out after widget creation whether the |
|
1484 |
underlying OpenGL system was able to provide the requested |
|
1485 |
specification: |
|
1486 |
||
1487 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 6 |
|
1488 |
||
1489 |
\sa defaultOverlayFormat() |
|
1490 |
*/ |
|
1491 |
||
1492 |
void QGLFormat::setDefaultOverlayFormat(const QGLFormat &f) |
|
1493 |
{ |
|
1494 |
QGLFormat *defaultFormat = defaultOverlayFormatInstance(); |
|
1495 |
*defaultFormat = f; |
|
1496 |
// Make sure the user doesn't request that the overlays themselves |
|
1497 |
// have overlays, since it is unlikely that the system supports |
|
1498 |
// infinitely many planes... |
|
1499 |
defaultFormat->setOverlay(false); |
|
1500 |
} |
|
1501 |
||
1502 |
||
1503 |
/*! |
|
1504 |
Returns true if all the options of the two QGLFormat objects |
|
1505 |
\a a and \a b are equal; otherwise returns false. |
|
1506 |
||
1507 |
\relates QGLFormat |
|
1508 |
*/ |
|
1509 |
||
1510 |
bool operator==(const QGLFormat& a, const QGLFormat& b) |
|
1511 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1512 |
return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1513 |
&& a.d->pln == b.d->pln |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1514 |
&& a.d->alphaSize == b.d->alphaSize |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1515 |
&& a.d->accumSize == b.d->accumSize |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1516 |
&& a.d->stencilSize == b.d->stencilSize |
0 | 1517 |
&& a.d->depthSize == b.d->depthSize |
1518 |
&& a.d->redSize == b.d->redSize |
|
1519 |
&& a.d->greenSize == b.d->greenSize |
|
1520 |
&& a.d->blueSize == b.d->blueSize |
|
1521 |
&& a.d->numSamples == b.d->numSamples |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1522 |
&& a.d->swapInterval == b.d->swapInterval |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1523 |
&& a.d->majorVersion == b.d->majorVersion |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1524 |
&& a.d->minorVersion == b.d->minorVersion |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1525 |
&& a.d->profile == b.d->profile); |
0 | 1526 |
} |
1527 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1528 |
#ifndef QT_NO_DEBUG_STREAM |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1529 |
QDebug operator<<(QDebug dbg, const QGLFormat &f) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1530 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1531 |
const QGLFormatPrivate * const d = f.d; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1532 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1533 |
dbg.nospace() << "QGLFormat(" |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1534 |
<< "options " << d->opts |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1535 |
<< ", plane " << d->pln |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1536 |
<< ", depthBufferSize " << d->depthSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1537 |
<< ", accumBufferSize " << d->accumSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1538 |
<< ", stencilBufferSize " << d->stencilSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1539 |
<< ", redBufferSize " << d->redSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1540 |
<< ", greenBufferSize " << d->greenSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1541 |
<< ", blueBufferSize " << d->blueSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1542 |
<< ", alphaBufferSize " << d->alphaSize |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1543 |
<< ", samples " << d->numSamples |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1544 |
<< ", swapInterval " << d->swapInterval |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1545 |
<< ", majorVersion " << d->majorVersion |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1546 |
<< ", minorVersion " << d->minorVersion |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1547 |
<< ", profile " << d->profile |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1548 |
<< ')'; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1549 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1550 |
return dbg.space(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1551 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1552 |
#endif |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1553 |
|
0 | 1554 |
|
1555 |
/*! |
|
1556 |
Returns false if all the options of the two QGLFormat objects |
|
1557 |
\a a and \a b are equal; otherwise returns true. |
|
1558 |
||
1559 |
\relates QGLFormat |
|
1560 |
*/ |
|
1561 |
||
1562 |
bool operator!=(const QGLFormat& a, const QGLFormat& b) |
|
1563 |
{ |
|
1564 |
return !(a == b); |
|
1565 |
} |
|
1566 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1567 |
struct QGLContextGroupList { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1568 |
void append(QGLContextGroup *group) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1569 |
QMutexLocker locker(&m_mutex); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1570 |
m_list.append(group); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1571 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1572 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1573 |
void remove(QGLContextGroup *group) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1574 |
QMutexLocker locker(&m_mutex); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1575 |
m_list.removeOne(group); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1576 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1577 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1578 |
QList<QGLContextGroup *> m_list; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1579 |
QMutex m_mutex; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1580 |
}; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1581 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1582 |
Q_GLOBAL_STATIC(QGLContextGroupList, qt_context_groups) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1583 |
|
0 | 1584 |
/***************************************************************************** |
1585 |
QGLContext implementation |
|
1586 |
*****************************************************************************/ |
|
1587 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1588 |
QGLContextGroup::QGLContextGroup(const QGLContext *context) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1589 |
: m_context(context), m_guards(0), m_refs(1) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1590 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1591 |
qt_context_groups()->append(this); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1592 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1593 |
|
0 | 1594 |
QGLContextGroup::~QGLContextGroup() |
1595 |
{ |
|
1596 |
// Clear any remaining QGLSharedResourceGuard objects on the group. |
|
1597 |
QGLSharedResourceGuard *guard = m_guards; |
|
1598 |
while (guard != 0) { |
|
1599 |
guard->m_group = 0; |
|
1600 |
guard->m_id = 0; |
|
1601 |
guard = guard->m_next; |
|
1602 |
} |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1603 |
qt_context_groups()->remove(this); |
0 | 1604 |
} |
1605 |
||
1606 |
void QGLContextGroup::addGuard(QGLSharedResourceGuard *guard) |
|
1607 |
{ |
|
1608 |
if (m_guards) |
|
1609 |
m_guards->m_prev = guard; |
|
1610 |
guard->m_next = m_guards; |
|
1611 |
guard->m_prev = 0; |
|
1612 |
m_guards = guard; |
|
1613 |
} |
|
1614 |
||
1615 |
void QGLContextGroup::removeGuard(QGLSharedResourceGuard *guard) |
|
1616 |
{ |
|
1617 |
if (guard->m_next) |
|
1618 |
guard->m_next->m_prev = guard->m_prev; |
|
1619 |
if (guard->m_prev) |
|
1620 |
guard->m_prev->m_next = guard->m_next; |
|
1621 |
else |
|
1622 |
m_guards = guard->m_next; |
|
1623 |
} |
|
1624 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1625 |
const QGLContext *qt_gl_transfer_context(const QGLContext *ctx) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1626 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1627 |
if (!ctx) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1628 |
return 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1629 |
QList<const QGLContext *> shares |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1630 |
(QGLContextPrivate::contextGroup(ctx)->shares()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1631 |
if (shares.size() >= 2) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1632 |
return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1633 |
else |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1634 |
return 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1635 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1636 |
|
0 | 1637 |
QGLContextPrivate::~QGLContextPrivate() |
1638 |
{ |
|
1639 |
if (!group->m_refs.deref()) { |
|
1640 |
Q_ASSERT(group->context() == q_ptr); |
|
1641 |
delete group; |
|
1642 |
} |
|
1643 |
} |
|
1644 |
||
1645 |
void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) |
|
1646 |
{ |
|
1647 |
Q_Q(QGLContext); |
|
1648 |
glFormat = reqFormat = format; |
|
1649 |
valid = false; |
|
1650 |
q->setDevice(dev); |
|
1651 |
#if defined(Q_WS_X11) |
|
1652 |
pbuf = 0; |
|
1653 |
gpm = 0; |
|
1654 |
vi = 0; |
|
1655 |
screen = QX11Info::appScreen(); |
|
1656 |
#endif |
|
1657 |
#if defined(Q_WS_WIN) |
|
1658 |
dc = 0; |
|
1659 |
win = 0; |
|
1660 |
pixelFormatId = 0; |
|
1661 |
cmap = 0; |
|
1662 |
hbitmap = 0; |
|
1663 |
hbitmap_hdc = 0; |
|
1664 |
#endif |
|
1665 |
#if defined(Q_WS_MAC) |
|
1666 |
# ifndef QT_MAC_USE_COCOA |
|
1667 |
update = false; |
|
1668 |
# endif |
|
1669 |
vi = 0; |
|
1670 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1671 |
#ifndef QT_NO_EGL |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1672 |
ownsEglContext = false; |
0 | 1673 |
eglContext = 0; |
1674 |
eglSurface = EGL_NO_SURFACE; |
|
1675 |
#endif |
|
1676 |
fbo = 0; |
|
1677 |
crWin = false; |
|
1678 |
initDone = false; |
|
1679 |
sharing = false; |
|
1680 |
max_texture_size = -1; |
|
1681 |
version_flags_cached = false; |
|
1682 |
version_flags = QGLFormat::OpenGL_Version_None; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1683 |
extension_flags_cached = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1684 |
extension_flags = 0; |
0 | 1685 |
current_fbo = 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1686 |
default_fbo = 0; |
0 | 1687 |
active_engine = 0; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1688 |
workaround_needsFullClearOnEveryFrame = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1689 |
workaround_brokenFBOReadBack = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1690 |
workaroundsCached = false; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1691 |
for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1692 |
vertexAttributeArraysEnabledState[i] = false; |
0 | 1693 |
} |
1694 |
||
1695 |
QGLContext* QGLContext::currentCtx = 0; |
|
1696 |
||
1697 |
/* |
|
1698 |
Read back the contents of the currently bound framebuffer, used in |
|
1699 |
QGLWidget::grabFrameBuffer(), QGLPixelbuffer::toImage() and |
|
1700 |
QGLFramebufferObject::toImage() |
|
1701 |
*/ |
|
1702 |
||
1703 |
static void convertFromGLImage(QImage &img, int w, int h, bool alpha_format, bool include_alpha) |
|
1704 |
{ |
|
1705 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
1706 |
// OpenGL gives RGBA; Qt wants ARGB |
|
1707 |
uint *p = (uint*)img.bits(); |
|
1708 |
uint *end = p + w*h; |
|
1709 |
if (alpha_format && include_alpha) { |
|
1710 |
while (p < end) { |
|
1711 |
uint a = *p << 24; |
|
1712 |
*p = (*p >> 8) | a; |
|
1713 |
p++; |
|
1714 |
} |
|
1715 |
} else { |
|
1716 |
// This is an old legacy fix for PowerPC based Macs, which |
|
1717 |
// we shouldn't remove |
|
1718 |
while (p < end) { |
|
1719 |
*p = 0xff000000 | (*p>>8); |
|
1720 |
++p; |
|
1721 |
} |
|
1722 |
} |
|
1723 |
} else { |
|
1724 |
// OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB |
|
1725 |
for (int y = 0; y < h; y++) { |
|
1726 |
uint *q = (uint*)img.scanLine(y); |
|
1727 |
for (int x=0; x < w; ++x) { |
|
1728 |
const uint pixel = *q; |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1729 |
if (alpha_format && include_alpha) { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1730 |
*q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1731 |
| (pixel & 0xff00ff00); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1732 |
} else { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1733 |
*q = 0xff000000 | ((pixel << 16) & 0xff0000) |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1734 |
| ((pixel >> 16) & 0xff) | (pixel & 0x00ff00); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1735 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1736 |
|
0 | 1737 |
q++; |
1738 |
} |
|
1739 |
} |
|
1740 |
||
1741 |
} |
|
1742 |
img = img.mirrored(); |
|
1743 |
} |
|
1744 |
||
1745 |
QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha) |
|
1746 |
{ |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1747 |
QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32 |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1748 |
: QImage::Format_RGB32); |
0 | 1749 |
int w = size.width(); |
1750 |
int h = size.height(); |
|
1751 |
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); |
|
1752 |
convertFromGLImage(img, w, h, alpha_format, include_alpha); |
|
1753 |
return img; |
|
1754 |
} |
|
1755 |
||
1756 |
QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha) |
|
1757 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1758 |
QImage img(size, alpha_format ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); |
0 | 1759 |
int w = size.width(); |
1760 |
int h = size.height(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1761 |
#if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_ES_1) |
0 | 1762 |
//### glGetTexImage not in GL ES 2.0, need to do something else here! |
1763 |
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); |
|
1764 |
#endif |
|
1765 |
convertFromGLImage(img, w, h, alpha_format, include_alpha); |
|
1766 |
return img; |
|
1767 |
} |
|
1768 |
||
1769 |
// returns the highest number closest to v, which is a power of 2 |
|
1770 |
// NB! assumes 32 bit ints |
|
1771 |
int qt_next_power_of_two(int v) |
|
1772 |
{ |
|
1773 |
v--; |
|
1774 |
v |= v >> 1; |
|
1775 |
v |= v >> 2; |
|
1776 |
v |= v >> 4; |
|
1777 |
v |= v >> 8; |
|
1778 |
v |= v >> 16; |
|
1779 |
++v; |
|
1780 |
return v; |
|
1781 |
} |
|
1782 |
||
1783 |
typedef void (*_qt_pixmap_cleanup_hook_64)(qint64); |
|
1784 |
typedef void (*_qt_image_cleanup_hook_64)(qint64); |
|
1785 |
||
1786 |
extern Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64; |
|
1787 |
extern Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64; |
|
1788 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1789 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1790 |
Q_GLOBAL_STATIC(QGLTextureCache, qt_gl_texture_cache) |
0 | 1791 |
|
1792 |
QGLTextureCache::QGLTextureCache() |
|
1793 |
: m_cache(64*1024) // cache ~64 MB worth of textures - this is not accurate though |
|
1794 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1795 |
QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTexturesForPixampData); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1796 |
QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1797 |
QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey); |
0 | 1798 |
} |
1799 |
||
1800 |
QGLTextureCache::~QGLTextureCache() |
|
1801 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1802 |
QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTexturesForPixampData); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1803 |
QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1804 |
QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey); |
0 | 1805 |
} |
1806 |
||
1807 |
void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost) |
|
1808 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1809 |
QWriteLocker locker(&m_lock); |
0 | 1810 |
if (m_cache.totalCost() + cost > m_cache.maxCost()) { |
1811 |
// the cache is full - make an attempt to remove something |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1812 |
const QList<QGLTextureCacheKey> keys = m_cache.keys(); |
0 | 1813 |
int i = 0; |
1814 |
while (i < m_cache.count() |
|
1815 |
&& (m_cache.totalCost() + cost > m_cache.maxCost())) { |
|
1816 |
QGLTexture *tex = m_cache.object(keys.at(i)); |
|
1817 |
if (tex->context == ctx) |
|
1818 |
m_cache.remove(keys.at(i)); |
|
1819 |
++i; |
|
1820 |
} |
|
1821 |
} |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1822 |
const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)}; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1823 |
m_cache.insert(cacheKey, texture, cost); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1824 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1825 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1826 |
void QGLTextureCache::remove(qint64 key) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1827 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1828 |
QWriteLocker locker(&m_lock); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1829 |
QMutexLocker groupLocker(&qt_context_groups()->m_mutex); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1830 |
QList<QGLContextGroup *>::const_iterator it = qt_context_groups()->m_list.constBegin(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1831 |
while (it != qt_context_groups()->m_list.constEnd()) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1832 |
const QGLTextureCacheKey cacheKey = {key, *it}; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1833 |
m_cache.remove(cacheKey); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1834 |
++it; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1835 |
} |
0 | 1836 |
} |
1837 |
||
1838 |
bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId) |
|
1839 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1840 |
QWriteLocker locker(&m_lock); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1841 |
QList<QGLTextureCacheKey> keys = m_cache.keys(); |
0 | 1842 |
for (int i = 0; i < keys.size(); ++i) { |
1843 |
QGLTexture *tex = m_cache.object(keys.at(i)); |
|
1844 |
if (tex->id == textureId && tex->context == ctx) { |
|
1845 |
tex->options |= QGLContext::MemoryManagedBindOption; // forces a glDeleteTextures() call |
|
1846 |
m_cache.remove(keys.at(i)); |
|
1847 |
return true; |
|
1848 |
} |
|
1849 |
} |
|
1850 |
return false; |
|
1851 |
} |
|
1852 |
||
1853 |
void QGLTextureCache::removeContextTextures(QGLContext* ctx) |
|
1854 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1855 |
QWriteLocker locker(&m_lock); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1856 |
QList<QGLTextureCacheKey> keys = m_cache.keys(); |
0 | 1857 |
for (int i = 0; i < keys.size(); ++i) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1858 |
const QGLTextureCacheKey &key = keys.at(i); |
0 | 1859 |
if (m_cache.object(key)->context == ctx) |
1860 |
m_cache.remove(key); |
|
1861 |
} |
|
1862 |
} |
|
1863 |
||
1864 |
/* |
|
1865 |
a hook that removes textures from the cache when a pixmap/image |
|
1866 |
is deref'ed |
|
1867 |
*/ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1868 |
void QGLTextureCache::cleanupTexturesForCacheKey(qint64 cacheKey) |
0 | 1869 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1870 |
qt_gl_texture_cache()->remove(cacheKey); |
0 | 1871 |
} |
1872 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1873 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1874 |
void QGLTextureCache::cleanupTexturesForPixampData(QPixmapData* pmd) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1875 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1876 |
cleanupTexturesForCacheKey(pmd->cacheKey()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1877 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1878 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1879 |
void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1880 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1881 |
// Remove any bound textures first: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1882 |
cleanupTexturesForPixampData(pmd); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1883 |
|
0 | 1884 |
#if defined(Q_WS_X11) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1885 |
if (pmd->classId() == QPixmapData::X11Class) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1886 |
Q_ASSERT(pmd->ref == 0); // Make sure reference counting isn't broken |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1887 |
QGLContextPrivate::destroyGlSurfaceForPixmap(pmd); |
0 | 1888 |
} |
1889 |
#endif |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1890 |
} |
0 | 1891 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1892 |
QGLTextureCache *QGLTextureCache::instance() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1893 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1894 |
return qt_gl_texture_cache(); |
0 | 1895 |
} |
1896 |
||
1897 |
// DDS format structure |
|
1898 |
struct DDSFormat { |
|
1899 |
quint32 dwSize; |
|
1900 |
quint32 dwFlags; |
|
1901 |
quint32 dwHeight; |
|
1902 |
quint32 dwWidth; |
|
1903 |
quint32 dwLinearSize; |
|
1904 |
quint32 dummy1; |
|
1905 |
quint32 dwMipMapCount; |
|
1906 |
quint32 dummy2[11]; |
|
1907 |
struct { |
|
1908 |
quint32 dummy3[2]; |
|
1909 |
quint32 dwFourCC; |
|
1910 |
quint32 dummy4[5]; |
|
1911 |
} ddsPixelFormat; |
|
1912 |
}; |
|
1913 |
||
1914 |
// compressed texture pixel formats |
|
1915 |
#define FOURCC_DXT1 0x31545844 |
|
1916 |
#define FOURCC_DXT2 0x32545844 |
|
1917 |
#define FOURCC_DXT3 0x33545844 |
|
1918 |
#define FOURCC_DXT4 0x34545844 |
|
1919 |
#define FOURCC_DXT5 0x35545844 |
|
1920 |
||
1921 |
#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT |
|
1922 |
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 |
|
1923 |
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 |
|
1924 |
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 |
|
1925 |
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 |
|
1926 |
#endif |
|
1927 |
||
1928 |
#ifndef GL_GENERATE_MIPMAP_SGIS |
|
1929 |
#define GL_GENERATE_MIPMAP_SGIS 0x8191 |
|
1930 |
#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 |
|
1931 |
#endif |
|
1932 |
||
1933 |
/*! |
|
1934 |
\class QGLContext |
|
1935 |
\brief The QGLContext class encapsulates an OpenGL rendering context. |
|
1936 |
||
1937 |
\ingroup painting-3D |
|
1938 |
||
1939 |
An OpenGL rendering context is a complete set of OpenGL state |
|
1940 |
variables. The rendering context's \l {QGL::FormatOption} {format} |
|
1941 |
is set in the constructor, but it can also be set later with |
|
1942 |
setFormat(). The format options that are actually set are returned |
|
1943 |
by format(); the options you asked for are returned by |
|
1944 |
requestedFormat(). Note that after a QGLContext object has been |
|
1945 |
constructed, the actual OpenGL context must be created by |
|
1946 |
explicitly calling the \link create() create()\endlink |
|
1947 |
function. The makeCurrent() function makes this context the |
|
1948 |
current rendering context. You can make \e no context current |
|
1949 |
using doneCurrent(). The reset() function will reset the context |
|
1950 |
and make it invalid. |
|
1951 |
||
1952 |
You can examine properties of the context with, e.g. isValid(), |
|
1953 |
isSharing(), initialized(), windowCreated() and |
|
1954 |
overlayTransparentColor(). |
|
1955 |
||
1956 |
If you're using double buffering you can swap the screen contents |
|
1957 |
with the off-screen buffer using swapBuffers(). |
|
1958 |
||
1959 |
Please note that QGLContext is not thread safe. |
|
1960 |
*/ |
|
1961 |
||
1962 |
/*! |
|
1963 |
\enum QGLContext::BindOption |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1964 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1965 |
|
0 | 1966 |
A set of options to decide how to bind a texture using bindTexture(). |
1967 |
||
1968 |
\value NoBindOption Don't do anything, pass the texture straight |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1969 |
through. |
0 | 1970 |
|
1971 |
\value InvertedYBindOption Specifies that the texture should be flipped |
|
1972 |
over the X axis so that the texture coordinate 0,0 corresponds to |
|
1973 |
the top left corner. Inverting the texture implies a deep copy |
|
1974 |
prior to upload. |
|
1975 |
||
1976 |
\value MipmapBindOption Specifies that bindTexture() should try |
|
1977 |
to generate mipmaps. If the GL implementation supports the \c |
|
1978 |
GL_SGIS_generate_mipmap extension, mipmaps will be automatically |
|
1979 |
generated for the texture. Mipmap generation is only supported for |
|
1980 |
the \c GL_TEXTURE_2D target. |
|
1981 |
||
1982 |
\value PremultipliedAlphaBindOption Specifies that the image should be |
|
1983 |
uploaded with premultiplied alpha and does a conversion accordingly. |
|
1984 |
||
1985 |
\value LinearFilteringBindOption Specifies that the texture filtering |
|
1986 |
should be set to GL_LINEAR. Default is GL_NEAREST. If mipmap is |
|
1987 |
also enabled, filtering will be set to GL_LINEAR_MIPMAP_LINEAR. |
|
1988 |
||
1989 |
\value DefaultBindOption In Qt 4.5 and earlier, bindTexture() |
|
1990 |
would mirror the image and automatically generate mipmaps. This |
|
1991 |
option helps preserve this default behavior. |
|
1992 |
||
1993 |
\omitvalue CanFlipNativePixmapBindOption Used by x11 from pixmap to choose |
|
1994 |
wether or not it can bind the pixmap upside down or not. |
|
1995 |
||
1996 |
\omitvalue MemoryManagedBindOption Used by paint engines to |
|
1997 |
indicate that the pixmap should be memory managed along side with |
|
1998 |
the pixmap/image that it stems from, e.g. installing destruction |
|
1999 |
hooks in them. |
|
2000 |
||
2001 |
\omitvalue InternalBindOption |
|
2002 |
*/ |
|
2003 |
||
2004 |
/*! |
|
2005 |
\obsolete |
|
2006 |
||
2007 |
Constructs an OpenGL context for the given paint \a device, which |
|
2008 |
can be a widget or a pixmap. The \a format specifies several |
|
2009 |
display options for the context. |
|
2010 |
||
2011 |
If the underlying OpenGL/Window system cannot satisfy all the |
|
2012 |
features requested in \a format, the nearest subset of features |
|
2013 |
will be used. After creation, the format() method will return the |
|
2014 |
actual format obtained. |
|
2015 |
||
2016 |
Note that after a QGLContext object has been constructed, \l |
|
2017 |
create() must be called explicitly to create the actual OpenGL |
|
2018 |
context. The context will be \l {isValid()}{invalid} if it was not |
|
2019 |
possible to obtain a GL context at all. |
|
2020 |
*/ |
|
2021 |
||
2022 |
QGLContext::QGLContext(const QGLFormat &format, QPaintDevice *device) |
|
2023 |
: d_ptr(new QGLContextPrivate(this)) |
|
2024 |
{ |
|
2025 |
Q_D(QGLContext); |
|
2026 |
d->init(device, format); |
|
2027 |
} |
|
2028 |
||
2029 |
/*! |
|
2030 |
Constructs an OpenGL context with the given \a format which |
|
2031 |
specifies several display options for the context. |
|
2032 |
||
2033 |
If the underlying OpenGL/Window system cannot satisfy all the |
|
2034 |
features requested in \a format, the nearest subset of features |
|
2035 |
will be used. After creation, the format() method will return the |
|
2036 |
actual format obtained. |
|
2037 |
||
2038 |
Note that after a QGLContext object has been constructed, \l |
|
2039 |
create() must be called explicitly to create the actual OpenGL |
|
2040 |
context. The context will be \l {isValid()}{invalid} if it was not |
|
2041 |
possible to obtain a GL context at all. |
|
2042 |
||
2043 |
\sa format(), isValid() |
|
2044 |
*/ |
|
2045 |
QGLContext::QGLContext(const QGLFormat &format) |
|
2046 |
: d_ptr(new QGLContextPrivate(this)) |
|
2047 |
{ |
|
2048 |
Q_D(QGLContext); |
|
2049 |
d->init(0, format); |
|
2050 |
} |
|
2051 |
||
2052 |
/*! |
|
2053 |
Destroys the OpenGL context and frees its resources. |
|
2054 |
*/ |
|
2055 |
||
2056 |
QGLContext::~QGLContext() |
|
2057 |
{ |
|
2058 |
// remove any textures cached in this context |
|
2059 |
QGLTextureCache::instance()->removeContextTextures(this); |
|
2060 |
||
2061 |
d_ptr->group->cleanupResources(this); |
|
2062 |
||
2063 |
QGLSignalProxy::instance()->emitAboutToDestroyContext(this); |
|
2064 |
reset(); |
|
2065 |
} |
|
2066 |
||
2067 |
void QGLContextPrivate::cleanup() |
|
2068 |
{ |
|
2069 |
} |
|
2070 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2071 |
#define ctx q_ptr |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2072 |
void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2073 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2074 |
Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2075 |
Q_ASSERT(glEnableVertexAttribArray); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2076 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2077 |
if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2078 |
glDisableVertexAttribArray(arrayIndex); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2079 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2080 |
if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2081 |
glEnableVertexAttribArray(arrayIndex); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2082 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2083 |
vertexAttributeArraysEnabledState[arrayIndex] = enabled; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2084 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2085 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2086 |
void QGLContextPrivate::syncGlState() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2087 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2088 |
Q_ASSERT(glEnableVertexAttribArray); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2089 |
for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2090 |
if (vertexAttributeArraysEnabledState[i]) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2091 |
glEnableVertexAttribArray(i); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2092 |
else |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2093 |
glDisableVertexAttribArray(i); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2094 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2095 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2096 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2097 |
#undef ctx |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2098 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2099 |
#ifdef QT_NO_EGL |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2100 |
void QGLContextPrivate::swapRegion(const QRegion *) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2101 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2102 |
static bool firstWarning = true; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2103 |
if (firstWarning) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2104 |
qWarning() << "::swapRegion called but not supported!"; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2105 |
firstWarning = false; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2106 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2107 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2108 |
#endif |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2109 |
|
0 | 2110 |
/*! |
2111 |
\overload |
|
2112 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2113 |
Reads the compressed texture file \a fileName and generates a 2D GL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2114 |
texture from it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2115 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2116 |
This function can load DirectDrawSurface (DDS) textures in the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2117 |
DXT1, DXT3 and DXT5 DDS formats if the \c GL_ARB_texture_compression |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2118 |
and \c GL_EXT_texture_compression_s3tc extensions are supported. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2119 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2120 |
Since 4.6.1, textures in the ETC1 format can be loaded if the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2121 |
\c GL_OES_compressed_ETC1_RGB8_texture extension is supported |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2122 |
and the ETC1 texture has been encapsulated in the PVR container format. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2123 |
Also, textures in the PVRTC2 and PVRTC4 formats can be loaded |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2124 |
if the \c GL_IMG_texture_compression_pvrtc extension is supported. |
0 | 2125 |
|
2126 |
\sa deleteTexture() |
|
2127 |
*/ |
|
2128 |
||
2129 |
GLuint QGLContext::bindTexture(const QString &fileName) |
|
2130 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2131 |
Q_D(QGLContext); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2132 |
QGLDDSCache *dds_cache = &(d->group->m_dds_cache); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2133 |
QGLDDSCache::const_iterator it = dds_cache->constFind(fileName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2134 |
if (it != dds_cache->constEnd()) { |
0 | 2135 |
glBindTexture(GL_TEXTURE_2D, it.value()); |
2136 |
return it.value(); |
|
2137 |
} |
|
2138 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2139 |
QGLTexture texture(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2140 |
QSize size = texture.bindCompressedTexture(fileName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2141 |
if (!size.isValid()) |
0 | 2142 |
return 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2143 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2144 |
dds_cache->insert(fileName, texture.id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2145 |
return texture.id; |
0 | 2146 |
} |
2147 |
||
2148 |
static inline QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format) |
|
2149 |
{ |
|
2150 |
if (texture_format == GL_BGRA) { |
|
2151 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
2152 |
return ((src_pixel << 24) & 0xff000000) |
|
2153 |
| ((src_pixel >> 24) & 0x000000ff) |
|
2154 |
| ((src_pixel << 8) & 0x00ff0000) |
|
2155 |
| ((src_pixel >> 8) & 0x0000ff00); |
|
2156 |
} else { |
|
2157 |
return src_pixel; |
|
2158 |
} |
|
2159 |
} else { // GL_RGBA |
|
2160 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
2161 |
return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); |
|
2162 |
} else { |
|
2163 |
return ((src_pixel << 16) & 0xff0000) |
|
2164 |
| ((src_pixel >> 16) & 0xff) |
|
2165 |
| (src_pixel & 0xff00ff00); |
|
2166 |
} |
|
2167 |
} |
|
2168 |
} |
|
2169 |
||
2170 |
QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format) |
|
2171 |
{ |
|
2172 |
return qt_gl_convertToGLFormatHelper(src_pixel, texture_format); |
|
2173 |
} |
|
2174 |
||
2175 |
static void convertToGLFormatHelper(QImage &dst, const QImage &img, GLenum texture_format) |
|
2176 |
{ |
|
2177 |
Q_ASSERT(dst.depth() == 32); |
|
2178 |
Q_ASSERT(img.depth() == 32); |
|
2179 |
||
2180 |
if (dst.size() != img.size()) { |
|
2181 |
int target_width = dst.width(); |
|
2182 |
int target_height = dst.height(); |
|
2183 |
qreal sx = target_width / qreal(img.width()); |
|
2184 |
qreal sy = target_height / qreal(img.height()); |
|
2185 |
||
2186 |
quint32 *dest = (quint32 *) dst.scanLine(0); // NB! avoid detach here |
|
2187 |
uchar *srcPixels = (uchar *) img.scanLine(img.height() - 1); |
|
2188 |
int sbpl = img.bytesPerLine(); |
|
2189 |
int dbpl = dst.bytesPerLine(); |
|
2190 |
||
2191 |
int ix = int(0x00010000 / sx); |
|
2192 |
int iy = int(0x00010000 / sy); |
|
2193 |
||
2194 |
quint32 basex = int(0.5 * ix); |
|
2195 |
quint32 srcy = int(0.5 * iy); |
|
2196 |
||
2197 |
// scale, swizzle and mirror in one loop |
|
2198 |
while (target_height--) { |
|
2199 |
const uint *src = (const quint32 *) (srcPixels - (srcy >> 16) * sbpl); |
|
2200 |
int srcx = basex; |
|
2201 |
for (int x=0; x<target_width; ++x) { |
|
2202 |
dest[x] = qt_gl_convertToGLFormatHelper(src[srcx >> 16], texture_format); |
|
2203 |
srcx += ix; |
|
2204 |
} |
|
2205 |
dest = (quint32 *)(((uchar *) dest) + dbpl); |
|
2206 |
srcy += iy; |
|
2207 |
} |
|
2208 |
} else { |
|
2209 |
const int width = img.width(); |
|
2210 |
const int height = img.height(); |
|
2211 |
const uint *p = (const uint*) img.scanLine(img.height() - 1); |
|
2212 |
uint *q = (uint*) dst.scanLine(0); |
|
2213 |
||
2214 |
if (texture_format == GL_BGRA) { |
|
2215 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
2216 |
// mirror + swizzle |
|
2217 |
for (int i=0; i < height; ++i) { |
|
2218 |
const uint *end = p + width; |
|
2219 |
while (p < end) { |
|
2220 |
*q = ((*p << 24) & 0xff000000) |
|
2221 |
| ((*p >> 24) & 0x000000ff) |
|
2222 |
| ((*p << 8) & 0x00ff0000) |
|
2223 |
| ((*p >> 8) & 0x0000ff00); |
|
2224 |
p++; |
|
2225 |
q++; |
|
2226 |
} |
|
2227 |
p -= 2 * width; |
|
2228 |
} |
|
2229 |
} else { |
|
2230 |
const uint bytesPerLine = img.bytesPerLine(); |
|
2231 |
for (int i=0; i < height; ++i) { |
|
2232 |
memcpy(q, p, bytesPerLine); |
|
2233 |
q += width; |
|
2234 |
p -= width; |
|
2235 |
} |
|
2236 |
} |
|
2237 |
} else { |
|
2238 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
2239 |
for (int i=0; i < height; ++i) { |
|
2240 |
const uint *end = p + width; |
|
2241 |
while (p < end) { |
|
2242 |
*q = (*p << 8) | ((*p >> 24) & 0xff); |
|
2243 |
p++; |
|
2244 |
q++; |
|
2245 |
} |
|
2246 |
p -= 2 * width; |
|
2247 |
} |
|
2248 |
} else { |
|
2249 |
for (int i=0; i < height; ++i) { |
|
2250 |
const uint *end = p + width; |
|
2251 |
while (p < end) { |
|
2252 |
*q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00); |
|
2253 |
p++; |
|
2254 |
q++; |
|
2255 |
} |
|
2256 |
p -= 2 * width; |
|
2257 |
} |
|
2258 |
} |
|
2259 |
} |
|
2260 |
} |
|
2261 |
} |
|
2262 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2263 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2264 |
QGLExtensionFuncs& QGLContextPrivate::extensionFuncs(const QGLContext *) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2265 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2266 |
return qt_extensionFuncs; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2267 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2268 |
#endif |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2269 |
|
0 | 2270 |
QImage QGLContextPrivate::convertToGLFormat(const QImage &image, bool force_premul, |
2271 |
GLenum texture_format) |
|
2272 |
{ |
|
2273 |
QImage::Format target_format = image.format(); |
|
2274 |
if (force_premul || image.format() != QImage::Format_ARGB32) |
|
2275 |
target_format = QImage::Format_ARGB32_Premultiplied; |
|
2276 |
||
2277 |
QImage result(image.width(), image.height(), target_format); |
|
2278 |
convertToGLFormatHelper(result, image.convertToFormat(target_format), texture_format); |
|
2279 |
return result; |
|
2280 |
} |
|
2281 |
||
2282 |
/*! \internal */ |
|
2283 |
QGLTexture *QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint format, |
|
2284 |
QGLContext::BindOptions options) |
|
2285 |
{ |
|
2286 |
const qint64 key = image.cacheKey(); |
|
2287 |
QGLTexture *texture = textureCacheLookup(key, target); |
|
2288 |
if (texture) { |
|
2289 |
glBindTexture(target, texture->id); |
|
2290 |
return texture; |
|
2291 |
} |
|
2292 |
||
2293 |
if (!texture) |
|
2294 |
texture = bindTexture(image, target, format, key, options); |
|
2295 |
// NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null |
|
2296 |
Q_ASSERT(texture); |
|
2297 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2298 |
// Enable the cleanup hooks for this image so that the texture cache entry is removed when the |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2299 |
// image gets deleted: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2300 |
QImagePixmapCleanupHooks::enableCleanupHooks(image); |
0 | 2301 |
|
2302 |
return texture; |
|
2303 |
} |
|
2304 |
||
2305 |
// #define QGL_BIND_TEXTURE_DEBUG |
|
2306 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2307 |
// map from Qt's ARGB endianness-dependent format to GL's big-endian RGBA layout |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2308 |
static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2309 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2310 |
const int width = img.width(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2311 |
const int height = img.height(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2312 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2313 |
if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2314 |
|| (pixel_type == GL_UNSIGNED_BYTE && QSysInfo::ByteOrder == QSysInfo::LittleEndian)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2315 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2316 |
for (int i = 0; i < height; ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2317 |
uint *p = (uint *) img.scanLine(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2318 |
for (int x = 0; x < width; ++x) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2319 |
p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2320 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2321 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2322 |
for (int i = 0; i < height; ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2323 |
uint *p = (uint *) img.scanLine(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2324 |
for (int x = 0; x < width; ++x) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2325 |
p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2326 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2327 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2328 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2329 |
|
0 | 2330 |
QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint internalFormat, |
2331 |
const qint64 key, QGLContext::BindOptions options) |
|
2332 |
{ |
|
2333 |
Q_Q(QGLContext); |
|
2334 |
||
2335 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2336 |
printf("QGLContextPrivate::bindTexture(), imageSize=(%d,%d), internalFormat =0x%x, options=%x, key=%llx\n", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2337 |
image.width(), image.height(), internalFormat, int(options), key); |
0 | 2338 |
QTime time; |
2339 |
time.start(); |
|
2340 |
#endif |
|
2341 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2342 |
#ifndef QT_NO_DEBUG |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2343 |
// Reset the gl error stack...git |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2344 |
while (glGetError() != GL_NO_ERROR) ; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2345 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2346 |
|
0 | 2347 |
// Scale the pixmap if needed. GL textures needs to have the |
2348 |
// dimensions 2^n+2(border) x 2^m+2(border), unless we're using GL |
|
2349 |
// 2.0 or use the GL_TEXTURE_RECTANGLE texture target |
|
2350 |
int tx_w = qt_next_power_of_two(image.width()); |
|
2351 |
int tx_h = qt_next_power_of_two(image.height()); |
|
2352 |
||
2353 |
QImage img = image; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2354 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2355 |
if (!(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2356 |
&& !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0) |
0 | 2357 |
&& (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height()))) |
2358 |
{ |
|
2359 |
img = img.scaled(tx_w, tx_h); |
|
2360 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
2361 |
printf(" - upscaled to %dx%d (%d ms)\n", tx_w, tx_h, time.elapsed()); |
|
2362 |
||
2363 |
#endif |
|
2364 |
} |
|
2365 |
||
2366 |
GLuint filtering = options & QGLContext::LinearFilteringBindOption ? GL_LINEAR : GL_NEAREST; |
|
2367 |
||
2368 |
GLuint tx_id; |
|
2369 |
glGenTextures(1, &tx_id); |
|
2370 |
glBindTexture(target, tx_id); |
|
2371 |
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, filtering); |
|
2372 |
||
2373 |
#if defined(QT_OPENGL_ES_2) |
|
2374 |
bool genMipmap = false; |
|
2375 |
#endif |
|
2376 |
if (glFormat.directRendering() |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2377 |
&& (QGLExtensions::glExtensions() & QGLExtensions::GenerateMipmap) |
0 | 2378 |
&& target == GL_TEXTURE_2D |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2379 |
&& (options & QGLContext::MipmapBindOption)) |
0 | 2380 |
{ |
2381 |
#if !defined(QT_OPENGL_ES_2) |
|
2382 |
glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); |
|
2383 |
#ifndef QT_OPENGL_ES |
|
2384 |
glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); |
|
2385 |
#else |
|
2386 |
glTexParameterf(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); |
|
2387 |
#endif |
|
2388 |
#else |
|
2389 |
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); |
|
2390 |
genMipmap = true; |
|
2391 |
#endif |
|
2392 |
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, options & QGLContext::LinearFilteringBindOption |
|
2393 |
? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2394 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2395 |
printf(" - generating mipmaps (%d ms)\n", time.elapsed()); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2396 |
#endif |
0 | 2397 |
} else { |
2398 |
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, filtering); |
|
2399 |
} |
|
2400 |
||
2401 |
QImage::Format target_format = img.format(); |
|
2402 |
bool premul = options & QGLContext::PremultipliedAlphaBindOption; |
|
2403 |
GLenum externalFormat; |
|
2404 |
GLuint pixel_type; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2405 |
if (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) { |
0 | 2406 |
externalFormat = GL_BGRA; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2407 |
if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2408 |
pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2409 |
else |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2410 |
pixel_type = GL_UNSIGNED_BYTE; |
0 | 2411 |
} else { |
2412 |
externalFormat = GL_RGBA; |
|
2413 |
pixel_type = GL_UNSIGNED_BYTE; |
|
2414 |
} |
|
2415 |
||
2416 |
switch (target_format) { |
|
2417 |
case QImage::Format_ARGB32: |
|
2418 |
if (premul) { |
|
2419 |
img = img.convertToFormat(target_format = QImage::Format_ARGB32_Premultiplied); |
|
2420 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2421 |
printf(" - converted ARGB32 -> ARGB32_Premultiplied (%d ms) \n", time.elapsed()); |
0 | 2422 |
#endif |
2423 |
} |
|
2424 |
break; |
|
2425 |
case QImage::Format_ARGB32_Premultiplied: |
|
2426 |
if (!premul) { |
|
2427 |
img = img.convertToFormat(target_format = QImage::Format_ARGB32); |
|
2428 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2429 |
printf(" - converted ARGB32_Premultiplied -> ARGB32 (%d ms)\n", time.elapsed()); |
0 | 2430 |
#endif |
2431 |
} |
|
2432 |
break; |
|
2433 |
case QImage::Format_RGB16: |
|
2434 |
pixel_type = GL_UNSIGNED_SHORT_5_6_5; |
|
2435 |
externalFormat = GL_RGB; |
|
2436 |
internalFormat = GL_RGB; |
|
2437 |
break; |
|
2438 |
case QImage::Format_RGB32: |
|
2439 |
break; |
|
2440 |
default: |
|
2441 |
if (img.hasAlphaChannel()) { |
|
2442 |
img = img.convertToFormat(premul |
|
2443 |
? QImage::Format_ARGB32_Premultiplied |
|
2444 |
: QImage::Format_ARGB32); |
|
2445 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2446 |
printf(" - converted to 32-bit alpha format (%d ms)\n", time.elapsed()); |
0 | 2447 |
#endif |
2448 |
} else { |
|
2449 |
img = img.convertToFormat(QImage::Format_RGB32); |
|
2450 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2451 |
printf(" - converted to 32-bit (%d ms)\n", time.elapsed()); |
0 | 2452 |
#endif |
2453 |
} |
|
2454 |
} |
|
2455 |
||
2456 |
if (options & QGLContext::InvertedYBindOption) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2457 |
if (img.isDetached()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2458 |
int ipl = img.bytesPerLine() / 4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2459 |
int h = img.height(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2460 |
for (int y=0; y<h/2; ++y) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2461 |
int *a = (int *) img.scanLine(y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2462 |
int *b = (int *) img.scanLine(h - y - 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2463 |
for (int x=0; x<ipl; ++x) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2464 |
qSwap(a[x], b[x]); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2465 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2466 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2467 |
// Create a new image and copy across. If we use the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2468 |
// above in-place code then a full copy of the image is |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2469 |
// made before the lines are swapped, which processes the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2470 |
// data twice. This version should only do it once. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2471 |
img = img.mirrored(); |
0 | 2472 |
} |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2473 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2474 |
printf(" - flipped bits over y (%d ms)\n", time.elapsed()); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2475 |
#endif |
0 | 2476 |
} |
2477 |
||
2478 |
if (externalFormat == GL_RGBA) { |
|
2479 |
// The only case where we end up with a depth different from |
|
2480 |
// 32 in the switch above is for the RGB16 case, where we set |
|
2481 |
// the format to GL_RGB |
|
2482 |
Q_ASSERT(img.depth() == 32); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2483 |
qgl_byteSwapImage(img, pixel_type); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2484 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2485 |
printf(" - did byte swapping (%d ms)\n", time.elapsed()); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2486 |
#endif |
0 | 2487 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2488 |
#ifdef QT_OPENGL_ES |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2489 |
// OpenGL/ES requires that the internal and external formats be |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2490 |
// identical. |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2491 |
internalFormat = externalFormat; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2492 |
#endif |
0 | 2493 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
2494 |
printf(" - uploading, image.format=%d, externalFormat=0x%x, internalFormat=0x%x, pixel_type=0x%x\n", |
|
2495 |
img.format(), externalFormat, internalFormat, pixel_type); |
|
2496 |
#endif |
|
2497 |
||
2498 |
const QImage &constRef = img; // to avoid detach in bits()... |
|
2499 |
glTexImage2D(target, 0, internalFormat, img.width(), img.height(), 0, externalFormat, |
|
2500 |
pixel_type, constRef.bits()); |
|
2501 |
#if defined(QT_OPENGL_ES_2) |
|
2502 |
if (genMipmap) |
|
2503 |
glGenerateMipmap(target); |
|
2504 |
#endif |
|
2505 |
#ifndef QT_NO_DEBUG |
|
2506 |
GLenum error = glGetError(); |
|
2507 |
if (error != GL_NO_ERROR) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2508 |
qWarning(" - texture upload failed, error code 0x%x, enum: %d (%x)\n", error, target, target); |
0 | 2509 |
} |
2510 |
#endif |
|
2511 |
||
2512 |
#ifdef QGL_BIND_TEXTURE_DEBUG |
|
2513 |
static int totalUploadTime = 0; |
|
2514 |
totalUploadTime += time.elapsed(); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2515 |
printf(" - upload done in %d ms, (accumulated: %d ms)\n", time.elapsed(), totalUploadTime); |
0 | 2516 |
#endif |
2517 |
||
2518 |
||
2519 |
// this assumes the size of a texture is always smaller than the max cache size |
|
2520 |
int cost = img.width()*img.height()*4/1024; |
|
2521 |
QGLTexture *texture = new QGLTexture(q, tx_id, target, options); |
|
2522 |
QGLTextureCache::instance()->insert(q, key, texture, cost); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2523 |
|
0 | 2524 |
return texture; |
2525 |
} |
|
2526 |
||
2527 |
QGLTexture *QGLContextPrivate::textureCacheLookup(const qint64 key, GLenum target) |
|
2528 |
{ |
|
2529 |
Q_Q(QGLContext); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2530 |
QGLTexture *texture = QGLTextureCache::instance()->getTexture(q, key); |
0 | 2531 |
if (texture && texture->target == target |
2532 |
&& (texture->context == q || QGLContext::areSharing(q, texture->context))) |
|
2533 |
{ |
|
2534 |
return texture; |
|
2535 |
} |
|
2536 |
return 0; |
|
2537 |
} |
|
2538 |
||
2539 |
||
2540 |
/*! \internal */ |
|
2541 |
QGLTexture *QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, QGLContext::BindOptions options) |
|
2542 |
{ |
|
2543 |
Q_Q(QGLContext); |
|
2544 |
QPixmapData *pd = pixmap.pixmapData(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2545 |
#if !defined(QT_OPENGL_ES_1) |
0 | 2546 |
if (target == GL_TEXTURE_2D && pd->classId() == QPixmapData::OpenGLClass) { |
2547 |
const QGLPixmapData *data = static_cast<const QGLPixmapData *>(pd); |
|
2548 |
||
2549 |
if (data->isValidContext(q)) { |
|
2550 |
data->bind(); |
|
2551 |
return data->texture(); |
|
2552 |
} |
|
2553 |
} |
|
2554 |
#else |
|
2555 |
Q_UNUSED(pd); |
|
2556 |
Q_UNUSED(q); |
|
2557 |
#endif |
|
2558 |
||
2559 |
const qint64 key = pixmap.cacheKey(); |
|
2560 |
QGLTexture *texture = textureCacheLookup(key, target); |
|
2561 |
if (texture) { |
|
2562 |
glBindTexture(target, texture->id); |
|
2563 |
return texture; |
|
2564 |
} |
|
2565 |
||
2566 |
#if defined(Q_WS_X11) |
|
2567 |
// Try to use texture_from_pixmap |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2568 |
const QX11Info *xinfo = qt_x11Info(paintDevice); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2569 |
if (pd->classId() == QPixmapData::X11Class && pd->pixelType() == QPixmapData::PixmapType |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2570 |
&& xinfo && xinfo->screen() == pixmap.x11Info().screen() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2571 |
&& target == GL_TEXTURE_2D) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2572 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2573 |
texture = bindTextureFromNativePixmap(const_cast<QPixmap*>(&pixmap), key, options); |
0 | 2574 |
if (texture) { |
2575 |
texture->options |= QGLContext::MemoryManagedBindOption; |
|
2576 |
texture->boundPixmap = pd; |
|
2577 |
boundPixmaps.insert(pd, QPixmap(pixmap)); |
|
2578 |
} |
|
2579 |
} |
|
2580 |
#endif |
|
2581 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2582 |
if (!texture) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2583 |
QImage image = pixmap.toImage(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2584 |
// If the system depth is 16 and the pixmap doesn't have an alpha channel |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2585 |
// then we convert it to RGB16 in the hope that it gets uploaded as a 16 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2586 |
// bit texture which is much faster to access than a 32-bit one. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2587 |
if (pixmap.depth() == 16 && !image.hasAlphaChannel() ) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2588 |
image = image.convertToFormat(QImage::Format_RGB16); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2589 |
texture = bindTexture(image, target, format, key, options); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2590 |
} |
0 | 2591 |
// NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null |
2592 |
Q_ASSERT(texture); |
|
2593 |
||
2594 |
if (texture->id > 0) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2595 |
QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); |
0 | 2596 |
|
2597 |
return texture; |
|
2598 |
} |
|
2599 |
||
2600 |
/*! \internal */ |
|
2601 |
int QGLContextPrivate::maxTextureSize() |
|
2602 |
{ |
|
2603 |
if (max_texture_size != -1) |
|
2604 |
return max_texture_size; |
|
2605 |
||
2606 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
|
2607 |
||
2608 |
#if defined(QT_OPENGL_ES) |
|
2609 |
return max_texture_size; |
|
2610 |
#else |
|
2611 |
GLenum proxy = GL_PROXY_TEXTURE_2D; |
|
2612 |
||
2613 |
GLint size; |
|
2614 |
GLint next = 64; |
|
2615 |
glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
|
2616 |
glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); |
|
2617 |
if (size == 0) { |
|
2618 |
return max_texture_size; |
|
2619 |
} |
|
2620 |
do { |
|
2621 |
size = next; |
|
2622 |
next = size * 2; |
|
2623 |
||
2624 |
if (next > max_texture_size) |
|
2625 |
break; |
|
2626 |
glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
|
2627 |
glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); |
|
2628 |
} while (next > size); |
|
2629 |
||
2630 |
max_texture_size = size; |
|
2631 |
return max_texture_size; |
|
2632 |
#endif |
|
2633 |
} |
|
2634 |
||
2635 |
/*! |
|
2636 |
Generates and binds a 2D GL texture to the current context, based |
|
2637 |
on \a image. The generated texture id is returned and can be used in |
|
2638 |
later \c glBindTexture() calls. |
|
2639 |
||
2640 |
\overload |
|
2641 |
*/ |
|
2642 |
GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format) |
|
2643 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2644 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2645 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2646 |
|
0 | 2647 |
Q_D(QGLContext); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2648 |
QGLTexture *texture = d->bindTexture(image, target, format, DefaultBindOption); |
0 | 2649 |
return texture->id; |
2650 |
} |
|
2651 |
||
2652 |
/*! |
|
2653 |
\since 4.6 |
|
2654 |
||
2655 |
Generates and binds a 2D GL texture to the current context, based |
|
2656 |
on \a image. The generated texture id is returned and can be used |
|
2657 |
in later \c glBindTexture() calls. |
|
2658 |
||
2659 |
The \a target parameter specifies the texture target. The default |
|
2660 |
target is \c GL_TEXTURE_2D. |
|
2661 |
||
2662 |
The \a format parameter sets the internal format for the |
|
2663 |
texture. The default format is \c GL_RGBA. |
|
2664 |
||
2665 |
The binding \a options are a set of options used to decide how to |
|
2666 |
bind the texture to the context. |
|
2667 |
||
2668 |
The texture that is generated is cached, so multiple calls to |
|
2669 |
bindTexture() with the same QImage will return the same texture |
|
2670 |
id. |
|
2671 |
||
2672 |
Note that we assume default values for the glPixelStore() and |
|
2673 |
glPixelTransfer() parameters. |
|
2674 |
||
2675 |
\sa deleteTexture() |
|
2676 |
*/ |
|
2677 |
GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format, BindOptions options) |
|
2678 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2679 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2680 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2681 |
|
0 | 2682 |
Q_D(QGLContext); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2683 |
QGLTexture *texture = d->bindTexture(image, target, format, options); |
0 | 2684 |
return texture->id; |
2685 |
} |
|
2686 |
||
2687 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
2688 |
/*! \internal */ |
|
2689 |
GLuint QGLContext::bindTexture(const QImage &image, QMacCompatGLenum target, QMacCompatGLint format) |
|
2690 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2691 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2692 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2693 |
|
0 | 2694 |
Q_D(QGLContext); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2695 |
QGLTexture *texture = d->bindTexture(image, GLenum(target), GLint(format), DefaultBindOption); |
0 | 2696 |
return texture->id; |
2697 |
} |
|
2698 |
||
2699 |
/*! \internal */ |
|
2700 |
GLuint QGLContext::bindTexture(const QImage &image, QMacCompatGLenum target, QMacCompatGLint format, |
|
2701 |
BindOptions options) |
|
2702 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2703 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2704 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2705 |
|
0 | 2706 |
Q_D(QGLContext); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2707 |
QGLTexture *texture = d->bindTexture(image, GLenum(target), GLint(format), options); |
0 | 2708 |
return texture->id; |
2709 |
} |
|
2710 |
#endif |
|
2711 |
||
2712 |
/*! \overload |
|
2713 |
||
2714 |
Generates and binds a 2D GL texture based on \a pixmap. |
|
2715 |
*/ |
|
2716 |
GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) |
|
2717 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2718 |
if (pixmap.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2719 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2720 |
|
0 | 2721 |
Q_D(QGLContext); |
2722 |
QGLTexture *texture = d->bindTexture(pixmap, target, format, DefaultBindOption); |
|
2723 |
return texture->id; |
|
2724 |
} |
|
2725 |
||
2726 |
/*! |
|
2727 |
\overload |
|
2728 |
\since 4.6 |
|
2729 |
||
2730 |
Generates and binds a 2D GL texture to the current context, based |
|
2731 |
on \a pixmap. |
|
2732 |
*/ |
|
2733 |
GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, BindOptions options) |
|
2734 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2735 |
if (pixmap.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2736 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2737 |
|
0 | 2738 |
Q_D(QGLContext); |
2739 |
QGLTexture *texture = d->bindTexture(pixmap, target, format, options); |
|
2740 |
return texture->id; |
|
2741 |
} |
|
2742 |
||
2743 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
2744 |
/*! \internal */ |
|
2745 |
GLuint QGLContext::bindTexture(const QPixmap &pixmap, QMacCompatGLenum target, QMacCompatGLint format) |
|
2746 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2747 |
if (pixmap.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2748 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2749 |
|
0 | 2750 |
Q_D(QGLContext); |
2751 |
QGLTexture *texture = d->bindTexture(pixmap, GLenum(target), GLint(format), DefaultBindOption); |
|
2752 |
return texture->id; |
|
2753 |
} |
|
2754 |
/*! \internal */ |
|
2755 |
GLuint QGLContext::bindTexture(const QPixmap &pixmap, QMacCompatGLenum target, QMacCompatGLint format, |
|
2756 |
BindOptions options) |
|
2757 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2758 |
if (pixmap.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2759 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2760 |
|
0 | 2761 |
Q_D(QGLContext); |
2762 |
QGLTexture *texture = d->bindTexture(pixmap, GLenum(target), GLint(format), options); |
|
2763 |
return texture->id; |
|
2764 |
} |
|
2765 |
#endif |
|
2766 |
||
2767 |
/*! |
|
2768 |
Removes the texture identified by \a id from the texture cache, |
|
2769 |
and calls glDeleteTextures() to delete the texture from the |
|
2770 |
context. |
|
2771 |
||
2772 |
\sa bindTexture() |
|
2773 |
*/ |
|
2774 |
void QGLContext::deleteTexture(GLuint id) |
|
2775 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2776 |
Q_D(QGLContext); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2777 |
|
0 | 2778 |
if (QGLTextureCache::instance()->remove(this, id)) |
2779 |
return; |
|
2780 |
||
2781 |
// check the DDS cache if the texture wasn't found in the pixmap/image |
|
2782 |
// cache |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2783 |
QGLDDSCache *dds_cache = &(d->group->m_dds_cache); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2784 |
QList<QString> ddsKeys = dds_cache->keys(); |
0 | 2785 |
for (int i = 0; i < ddsKeys.size(); ++i) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2786 |
GLuint texture = dds_cache->value(ddsKeys.at(i)); |
0 | 2787 |
if (id == texture) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2788 |
dds_cache->remove(ddsKeys.at(i)); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2789 |
break; |
0 | 2790 |
} |
2791 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2792 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2793 |
// Finally, actually delete the texture ID |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2794 |
glDeleteTextures(1, &id); |
0 | 2795 |
} |
2796 |
||
2797 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
2798 |
/*! \internal */ |
|
2799 |
void QGLContext::deleteTexture(QMacCompatGLuint id) |
|
2800 |
{ |
|
2801 |
return deleteTexture(GLuint(id)); |
|
2802 |
} |
|
2803 |
#endif |
|
2804 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2805 |
void qt_add_rect_to_array(const QRectF &r, GLfloat *array) |
0 | 2806 |
{ |
2807 |
qreal left = r.left(); |
|
2808 |
qreal right = r.right(); |
|
2809 |
qreal top = r.top(); |
|
2810 |
qreal bottom = r.bottom(); |
|
2811 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2812 |
array[0] = left; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2813 |
array[1] = top; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2814 |
array[2] = right; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2815 |
array[3] = top; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2816 |
array[4] = right; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2817 |
array[5] = bottom; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2818 |
array[6] = left; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2819 |
array[7] = bottom; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2820 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2821 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2822 |
void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2823 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2824 |
array[0] = x1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2825 |
array[1] = y1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2826 |
array[2] = x2; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2827 |
array[3] = y1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2828 |
array[4] = x2; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2829 |
array[5] = y2; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2830 |
array[6] = x1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2831 |
array[7] = y2; |
0 | 2832 |
} |
2833 |
||
2834 |
#if !defined(QT_OPENGL_ES_2) |
|
2835 |
||
2836 |
static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget) |
|
2837 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2838 |
GLfloat tx = 1.0f; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2839 |
GLfloat ty = 1.0f; |
0 | 2840 |
|
2841 |
#ifdef QT_OPENGL_ES |
|
2842 |
Q_UNUSED(textureWidth); |
|
2843 |
Q_UNUSED(textureHeight); |
|
2844 |
Q_UNUSED(textureTarget); |
|
2845 |
#else |
|
2846 |
if (textureTarget != GL_TEXTURE_2D) { |
|
2847 |
if (textureWidth == -1 || textureHeight == -1) { |
|
2848 |
glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); |
|
2849 |
glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); |
|
2850 |
} |
|
2851 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2852 |
tx = GLfloat(textureWidth); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2853 |
ty = GLfloat(textureHeight); |
0 | 2854 |
} |
2855 |
#endif |
|
2856 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2857 |
GLfloat texCoordArray[4*2] = { |
0 | 2858 |
0, ty, tx, ty, tx, 0, 0, 0 |
2859 |
}; |
|
2860 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2861 |
GLfloat vertexArray[4*2]; |
0 | 2862 |
qt_add_rect_to_array(target, vertexArray); |
2863 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2864 |
glVertexPointer(2, GL_FLOAT, 0, vertexArray); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2865 |
glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); |
0 | 2866 |
|
2867 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
2868 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
2869 |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
|
2870 |
||
2871 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
2872 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
2873 |
} |
|
2874 |
||
2875 |
#endif // !QT_OPENGL_ES_2 |
|
2876 |
||
2877 |
/*! |
|
2878 |
\since 4.4 |
|
2879 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2880 |
This function supports the following use cases: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2881 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2882 |
\list |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2883 |
\i On OpenGL and OpenGL ES 1.x it draws the given texture, \a textureId, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2884 |
to the given target rectangle, \a target, in OpenGL model space. The |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2885 |
\a textureTarget should be a 2D texture target. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2886 |
\i On OpenGL and OpenGL ES 2.x, if a painter is active, not inside a |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2887 |
beginNativePainting / endNativePainting block, and uses the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2888 |
engine with type QPaintEngine::OpenGL2, the function will draw the given |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2889 |
texture, \a textureId, to the given target rectangle, \a target, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2890 |
respecting the current painter state. This will let you draw a texture |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2891 |
with the clip, transform, render hints, and composition mode set by the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2892 |
painter. Note that the texture target needs to be GL_TEXTURE_2D for this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2893 |
use case, and that this is the only supported use case under OpenGL ES 2.x. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2894 |
\endlist |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2895 |
|
0 | 2896 |
*/ |
2897 |
void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) |
|
2898 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2899 |
#if !defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2900 |
if (d_ptr->active_engine && |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2901 |
d_ptr->active_engine->type() == QPaintEngine::OpenGL2) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2902 |
QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2903 |
if (!eng->isNativePaintingActive()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2904 |
QRectF src(0, 0, target.width(), target.height()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2905 |
QSize size(target.width(), target.height()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2906 |
if (eng->drawTexture(target, textureId, size, src)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2907 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2908 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2909 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2910 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2911 |
|
0 | 2912 |
#ifndef QT_OPENGL_ES_2 |
2913 |
#ifdef QT_OPENGL_ES |
|
2914 |
if (textureTarget != GL_TEXTURE_2D) { |
|
2915 |
qWarning("QGLContext::drawTexture(): texture target must be GL_TEXTURE_2D on OpenGL ES"); |
|
2916 |
return; |
|
2917 |
} |
|
2918 |
#else |
|
2919 |
const bool wasEnabled = glIsEnabled(GL_TEXTURE_2D); |
|
2920 |
GLint oldTexture; |
|
2921 |
glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); |
|
2922 |
#endif |
|
2923 |
||
2924 |
glEnable(textureTarget); |
|
2925 |
glBindTexture(textureTarget, textureId); |
|
2926 |
||
2927 |
qDrawTextureRect(target, -1, -1, textureTarget); |
|
2928 |
||
2929 |
#ifdef QT_OPENGL_ES |
|
2930 |
glDisable(textureTarget); |
|
2931 |
#else |
|
2932 |
if (!wasEnabled) |
|
2933 |
glDisable(textureTarget); |
|
2934 |
glBindTexture(textureTarget, oldTexture); |
|
2935 |
#endif |
|
2936 |
#else |
|
2937 |
Q_UNUSED(target); |
|
2938 |
Q_UNUSED(textureId); |
|
2939 |
Q_UNUSED(textureTarget); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2940 |
qWarning("drawTexture() with OpenGL ES 2.0 requires an active OpenGL2 paint engine"); |
0 | 2941 |
#endif |
2942 |
} |
|
2943 |
||
2944 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
2945 |
/*! \internal */ |
|
2946 |
void QGLContext::drawTexture(const QRectF &target, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget) |
|
2947 |
{ |
|
2948 |
drawTexture(target, GLuint(textureId), GLenum(textureTarget)); |
|
2949 |
} |
|
2950 |
#endif |
|
2951 |
||
2952 |
/*! |
|
2953 |
\since 4.4 |
|
2954 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2955 |
This function supports the following use cases: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2956 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2957 |
\list |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2958 |
\i By default it draws the given texture, \a textureId, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2959 |
at the given \a point in OpenGL model space. The |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2960 |
\a textureTarget should be a 2D texture target. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2961 |
\i If a painter is active, not inside a |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2962 |
beginNativePainting / endNativePainting block, and uses the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2963 |
engine with type QPaintEngine::OpenGL2, the function will draw the given |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2964 |
texture, \a textureId, at the given \a point, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2965 |
respecting the current painter state. This will let you draw a texture |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2966 |
with the clip, transform, render hints, and composition mode set by the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2967 |
painter. Note that the texture target needs to be GL_TEXTURE_2D for this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2968 |
use case. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2969 |
\endlist |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2970 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2971 |
\note This function is not supported under any version of OpenGL ES. |
0 | 2972 |
*/ |
2973 |
void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) |
|
2974 |
{ |
|
2975 |
#ifdef QT_OPENGL_ES |
|
2976 |
Q_UNUSED(point); |
|
2977 |
Q_UNUSED(textureId); |
|
2978 |
Q_UNUSED(textureTarget); |
|
2979 |
qWarning("drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) not supported with OpenGL ES, use rect version instead"); |
|
2980 |
#else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2981 |
|
0 | 2982 |
const bool wasEnabled = glIsEnabled(GL_TEXTURE_2D); |
2983 |
GLint oldTexture; |
|
2984 |
glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); |
|
2985 |
||
2986 |
glEnable(textureTarget); |
|
2987 |
glBindTexture(textureTarget, textureId); |
|
2988 |
||
2989 |
GLint textureWidth; |
|
2990 |
GLint textureHeight; |
|
2991 |
||
2992 |
glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); |
|
2993 |
glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); |
|
2994 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2995 |
if (d_ptr->active_engine && |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2996 |
d_ptr->active_engine->type() == QPaintEngine::OpenGL2) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2997 |
QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2998 |
if (!eng->isNativePaintingActive()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2999 |
QRectF dest(point, QSizeF(textureWidth, textureHeight)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3000 |
QRectF src(0, 0, textureWidth, textureHeight); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3001 |
QSize size(textureWidth, textureHeight); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3002 |
if (eng->drawTexture(dest, textureId, size, src)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3003 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3004 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3005 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3006 |
|
0 | 3007 |
qDrawTextureRect(QRectF(point, QSizeF(textureWidth, textureHeight)), textureWidth, textureHeight, textureTarget); |
3008 |
||
3009 |
if (!wasEnabled) |
|
3010 |
glDisable(textureTarget); |
|
3011 |
glBindTexture(textureTarget, oldTexture); |
|
3012 |
#endif |
|
3013 |
} |
|
3014 |
||
3015 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
3016 |
/*! \internal */ |
|
3017 |
void QGLContext::drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget) |
|
3018 |
{ |
|
3019 |
drawTexture(point, GLuint(textureId), GLenum(textureTarget)); |
|
3020 |
} |
|
3021 |
#endif |
|
3022 |
||
3023 |
||
3024 |
/*! |
|
3025 |
This function sets the limit for the texture cache to \a size, |
|
3026 |
expressed in kilobytes. |
|
3027 |
||
3028 |
By default, the cache limit is approximately 64 MB. |
|
3029 |
||
3030 |
\sa textureCacheLimit() |
|
3031 |
*/ |
|
3032 |
void QGLContext::setTextureCacheLimit(int size) |
|
3033 |
{ |
|
3034 |
QGLTextureCache::instance()->setMaxCost(size); |
|
3035 |
} |
|
3036 |
||
3037 |
/*! |
|
3038 |
Returns the current texture cache limit in kilobytes. |
|
3039 |
||
3040 |
\sa setTextureCacheLimit() |
|
3041 |
*/ |
|
3042 |
int QGLContext::textureCacheLimit() |
|
3043 |
{ |
|
3044 |
return QGLTextureCache::instance()->maxCost(); |
|
3045 |
} |
|
3046 |
||
3047 |
||
3048 |
/*! |
|
3049 |
\fn QGLFormat QGLContext::format() const |
|
3050 |
||
3051 |
Returns the frame buffer format that was obtained (this may be a |
|
3052 |
subset of what was requested). |
|
3053 |
||
3054 |
\sa requestedFormat() |
|
3055 |
*/ |
|
3056 |
||
3057 |
/*! |
|
3058 |
\fn QGLFormat QGLContext::requestedFormat() const |
|
3059 |
||
3060 |
Returns the frame buffer format that was originally requested in |
|
3061 |
the constructor or setFormat(). |
|
3062 |
||
3063 |
\sa format() |
|
3064 |
*/ |
|
3065 |
||
3066 |
/*! |
|
3067 |
Sets a \a format for this context. The context is \link reset() |
|
3068 |
reset\endlink. |
|
3069 |
||
3070 |
Call create() to create a new GL context that tries to match the |
|
3071 |
new format. |
|
3072 |
||
3073 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 7 |
|
3074 |
||
3075 |
\sa format(), reset(), create() |
|
3076 |
*/ |
|
3077 |
||
3078 |
void QGLContext::setFormat(const QGLFormat &format) |
|
3079 |
{ |
|
3080 |
Q_D(QGLContext); |
|
3081 |
reset(); |
|
3082 |
d->glFormat = d->reqFormat = format; |
|
3083 |
} |
|
3084 |
||
3085 |
/*! |
|
3086 |
\internal |
|
3087 |
*/ |
|
3088 |
void QGLContext::setDevice(QPaintDevice *pDev) |
|
3089 |
{ |
|
3090 |
Q_D(QGLContext); |
|
3091 |
if (isValid()) |
|
3092 |
reset(); |
|
3093 |
d->paintDevice = pDev; |
|
3094 |
if (d->paintDevice && (d->paintDevice->devType() != QInternal::Widget |
|
3095 |
&& d->paintDevice->devType() != QInternal::Pixmap |
|
3096 |
&& d->paintDevice->devType() != QInternal::Pbuffer)) { |
|
3097 |
qWarning("QGLContext: Unsupported paint device type"); |
|
3098 |
} |
|
3099 |
} |
|
3100 |
||
3101 |
/*! |
|
3102 |
\fn bool QGLContext::isValid() const |
|
3103 |
||
3104 |
Returns true if a GL rendering context has been successfully |
|
3105 |
created; otherwise returns false. |
|
3106 |
*/ |
|
3107 |
||
3108 |
/*! |
|
3109 |
\fn void QGLContext::setValid(bool valid) |
|
3110 |
\internal |
|
3111 |
||
3112 |
Forces the GL rendering context to be valid. |
|
3113 |
*/ |
|
3114 |
||
3115 |
/*! |
|
3116 |
\fn bool QGLContext::isSharing() const |
|
3117 |
||
3118 |
Returns true if this context is sharing its GL context with |
|
3119 |
another QGLContext, otherwise false is returned. Note that context |
|
3120 |
sharing might not be supported between contexts with different |
|
3121 |
formats. |
|
3122 |
*/ |
|
3123 |
||
3124 |
/*! |
|
3125 |
Returns true if \a context1 and \a context2 are sharing their |
|
3126 |
GL resources such as textures, shader programs, etc; |
|
3127 |
otherwise returns false. |
|
3128 |
||
3129 |
\since 4.6 |
|
3130 |
*/ |
|
3131 |
bool QGLContext::areSharing(const QGLContext *context1, const QGLContext *context2) |
|
3132 |
{ |
|
3133 |
if (!context1 || !context2) |
|
3134 |
return false; |
|
3135 |
return context1->d_ptr->group == context2->d_ptr->group; |
|
3136 |
} |
|
3137 |
||
3138 |
/*! |
|
3139 |
\fn bool QGLContext::deviceIsPixmap() const |
|
3140 |
||
3141 |
Returns true if the paint device of this context is a pixmap; |
|
3142 |
otherwise returns false. |
|
3143 |
*/ |
|
3144 |
||
3145 |
/*! |
|
3146 |
\fn bool QGLContext::windowCreated() const |
|
3147 |
||
3148 |
Returns true if a window has been created for this context; |
|
3149 |
otherwise returns false. |
|
3150 |
||
3151 |
\sa setWindowCreated() |
|
3152 |
*/ |
|
3153 |
||
3154 |
/*! |
|
3155 |
\fn void QGLContext::setWindowCreated(bool on) |
|
3156 |
||
3157 |
If \a on is true the context has had a window created for it. If |
|
3158 |
\a on is false no window has been created for the context. |
|
3159 |
||
3160 |
\sa windowCreated() |
|
3161 |
*/ |
|
3162 |
||
3163 |
/*! |
|
3164 |
\fn uint QGLContext::colorIndex(const QColor& c) const |
|
3165 |
||
3166 |
\internal |
|
3167 |
||
3168 |
Returns a colormap index for the color c, in ColorIndex mode. Used |
|
3169 |
by qglColor() and qglClearColor(). |
|
3170 |
*/ |
|
3171 |
||
3172 |
||
3173 |
/*! |
|
3174 |
\fn bool QGLContext::initialized() const |
|
3175 |
||
3176 |
Returns true if this context has been initialized, i.e. if |
|
3177 |
QGLWidget::initializeGL() has been performed on it; otherwise |
|
3178 |
returns false. |
|
3179 |
||
3180 |
\sa setInitialized() |
|
3181 |
*/ |
|
3182 |
||
3183 |
/*! |
|
3184 |
\fn void QGLContext::setInitialized(bool on) |
|
3185 |
||
3186 |
If \a on is true the context has been initialized, i.e. |
|
3187 |
QGLContext::setInitialized() has been called on it. If \a on is |
|
3188 |
false the context has not been initialized. |
|
3189 |
||
3190 |
\sa initialized() |
|
3191 |
*/ |
|
3192 |
||
3193 |
/*! |
|
3194 |
\fn const QGLContext* QGLContext::currentContext() |
|
3195 |
||
3196 |
Returns the current context, i.e. the context to which any OpenGL |
|
3197 |
commands will currently be directed. Returns 0 if no context is |
|
3198 |
current. |
|
3199 |
||
3200 |
\sa makeCurrent() |
|
3201 |
*/ |
|
3202 |
||
3203 |
/*! |
|
3204 |
\fn QColor QGLContext::overlayTransparentColor() const |
|
3205 |
||
3206 |
If this context is a valid context in an overlay plane, returns |
|
3207 |
the plane's transparent color. Otherwise returns an \link |
|
3208 |
QColor::isValid() invalid \endlink color. |
|
3209 |
||
3210 |
The returned color's \link QColor::pixel() pixel \endlink value is |
|
3211 |
the index of the transparent color in the colormap of the overlay |
|
3212 |
plane. (Naturally, the color's RGB values are meaningless.) |
|
3213 |
||
3214 |
The returned QColor object will generally work as expected only |
|
3215 |
when passed as the argument to QGLWidget::qglColor() or |
|
3216 |
QGLWidget::qglClearColor(). Under certain circumstances it can |
|
3217 |
also be used to draw transparent graphics with a QPainter. See the |
|
3218 |
examples/opengl/overlay_x11 example for details. |
|
3219 |
*/ |
|
3220 |
||
3221 |
||
3222 |
/*! |
|
3223 |
Creates the GL context. Returns true if it was successful in |
|
3224 |
creating a valid GL rendering context on the paint device |
|
3225 |
specified in the constructor; otherwise returns false (i.e. the |
|
3226 |
context is invalid). |
|
3227 |
||
3228 |
After successful creation, format() returns the set of features of |
|
3229 |
the created GL rendering context. |
|
3230 |
||
3231 |
If \a shareContext points to a valid QGLContext, this method will |
|
3232 |
try to establish OpenGL display list and texture object sharing |
|
3233 |
between this context and the \a shareContext. Note that this may |
|
3234 |
fail if the two contexts have different \l {format()} {formats}. |
|
3235 |
Use isSharing() to see if sharing is in effect. |
|
3236 |
||
3237 |
\warning Implementation note: initialization of C++ class |
|
3238 |
members usually takes place in the class constructor. QGLContext |
|
3239 |
is an exception because it must be simple to customize. The |
|
3240 |
virtual functions chooseContext() (and chooseVisual() for X11) can |
|
3241 |
be reimplemented in a subclass to select a particular context. The |
|
3242 |
problem is that virtual functions are not properly called during |
|
3243 |
construction (even though this is correct C++) because C++ |
|
3244 |
constructs class hierarchies from the bottom up. For this reason |
|
3245 |
we need a create() function. |
|
3246 |
||
3247 |
\sa chooseContext(), format(), isValid() |
|
3248 |
*/ |
|
3249 |
||
3250 |
bool QGLContext::create(const QGLContext* shareContext) |
|
3251 |
{ |
|
3252 |
Q_D(QGLContext); |
|
3253 |
if (!d->paintDevice) |
|
3254 |
return false; |
|
3255 |
reset(); |
|
3256 |
d->valid = chooseContext(shareContext); |
|
3257 |
if (d->valid && d->paintDevice->devType() == QInternal::Widget) { |
|
3258 |
QWidgetPrivate *wd = qt_widget_private(static_cast<QWidget *>(d->paintDevice)); |
|
3259 |
wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer(); |
|
3260 |
} |
|
3261 |
if (d->sharing) // ok, we managed to share |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3262 |
QGLContextGroup::addShare(this, shareContext); |
0 | 3263 |
return d->valid; |
3264 |
} |
|
3265 |
||
3266 |
bool QGLContext::isValid() const |
|
3267 |
{ |
|
3268 |
Q_D(const QGLContext); |
|
3269 |
return d->valid; |
|
3270 |
} |
|
3271 |
||
3272 |
void QGLContext::setValid(bool valid) |
|
3273 |
{ |
|
3274 |
Q_D(QGLContext); |
|
3275 |
d->valid = valid; |
|
3276 |
} |
|
3277 |
||
3278 |
bool QGLContext::isSharing() const |
|
3279 |
{ |
|
3280 |
Q_D(const QGLContext); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3281 |
return d->group->isSharing(); |
0 | 3282 |
} |
3283 |
||
3284 |
QGLFormat QGLContext::format() const |
|
3285 |
{ |
|
3286 |
Q_D(const QGLContext); |
|
3287 |
return d->glFormat; |
|
3288 |
} |
|
3289 |
||
3290 |
QGLFormat QGLContext::requestedFormat() const |
|
3291 |
{ |
|
3292 |
Q_D(const QGLContext); |
|
3293 |
return d->reqFormat; |
|
3294 |
} |
|
3295 |
||
3296 |
QPaintDevice* QGLContext::device() const |
|
3297 |
{ |
|
3298 |
Q_D(const QGLContext); |
|
3299 |
return d->paintDevice; |
|
3300 |
} |
|
3301 |
||
3302 |
bool QGLContext::deviceIsPixmap() const |
|
3303 |
{ |
|
3304 |
Q_D(const QGLContext); |
|
3305 |
return d->paintDevice->devType() == QInternal::Pixmap; |
|
3306 |
} |
|
3307 |
||
3308 |
||
3309 |
bool QGLContext::windowCreated() const |
|
3310 |
{ |
|
3311 |
Q_D(const QGLContext); |
|
3312 |
return d->crWin; |
|
3313 |
} |
|
3314 |
||
3315 |
||
3316 |
void QGLContext::setWindowCreated(bool on) |
|
3317 |
{ |
|
3318 |
Q_D(QGLContext); |
|
3319 |
d->crWin = on; |
|
3320 |
} |
|
3321 |
||
3322 |
bool QGLContext::initialized() const |
|
3323 |
{ |
|
3324 |
Q_D(const QGLContext); |
|
3325 |
return d->initDone; |
|
3326 |
} |
|
3327 |
||
3328 |
void QGLContext::setInitialized(bool on) |
|
3329 |
{ |
|
3330 |
Q_D(QGLContext); |
|
3331 |
d->initDone = on; |
|
3332 |
} |
|
3333 |
||
3334 |
const QGLContext* QGLContext::currentContext() |
|
3335 |
{ |
|
3336 |
QGLThreadContext *threadContext = qgl_context_storage.localData(); |
|
3337 |
if (threadContext) |
|
3338 |
return threadContext->context; |
|
3339 |
return 0; |
|
3340 |
} |
|
3341 |
||
3342 |
void QGLContextPrivate::setCurrentContext(QGLContext *context) |
|
3343 |
{ |
|
3344 |
QGLThreadContext *threadContext = qgl_context_storage.localData(); |
|
3345 |
if (!threadContext) { |
|
3346 |
if (!QThread::currentThread()) { |
|
3347 |
// We don't have a current QThread, so just set the static. |
|
3348 |
QGLContext::currentCtx = context; |
|
3349 |
return; |
|
3350 |
} |
|
3351 |
threadContext = new QGLThreadContext; |
|
3352 |
qgl_context_storage.setLocalData(threadContext); |
|
3353 |
} |
|
3354 |
threadContext->context = context; |
|
3355 |
QGLContext::currentCtx = context; // XXX: backwards-compat, not thread-safe |
|
3356 |
} |
|
3357 |
||
3358 |
/*! |
|
3359 |
\fn bool QGLContext::chooseContext(const QGLContext* shareContext = 0) |
|
3360 |
||
3361 |
This semi-internal function is called by create(). It creates a |
|
3362 |
system-dependent OpenGL handle that matches the format() of \a |
|
3363 |
shareContext as closely as possible, returning true if successful |
|
3364 |
or false if a suitable handle could not be found. |
|
3365 |
||
3366 |
On Windows, it calls the virtual function choosePixelFormat(), |
|
3367 |
which finds a matching pixel format identifier. On X11, it calls |
|
3368 |
the virtual function chooseVisual() which finds an appropriate X |
|
3369 |
visual. On other platforms it may work differently. |
|
3370 |
*/ |
|
3371 |
||
3372 |
/*! \fn int QGLContext::choosePixelFormat(void* dummyPfd, HDC pdc) |
|
3373 |
||
3374 |
\bold{Win32 only:} This virtual function chooses a pixel format |
|
3375 |
that matches the OpenGL \link setFormat() format\endlink. |
|
3376 |
Reimplement this function in a subclass if you need a custom |
|
3377 |
context. |
|
3378 |
||
3379 |
\warning The \a dummyPfd pointer and \a pdc are used as a \c |
|
3380 |
PIXELFORMATDESCRIPTOR*. We use \c void to avoid using |
|
3381 |
Windows-specific types in our header files. |
|
3382 |
||
3383 |
\sa chooseContext() |
|
3384 |
*/ |
|
3385 |
||
3386 |
/*! \fn void *QGLContext::chooseVisual() |
|
3387 |
||
3388 |
\bold{X11 only:} This virtual function tries to find a visual that |
|
3389 |
matches the format, reducing the demands if the original request |
|
3390 |
cannot be met. |
|
3391 |
||
3392 |
The algorithm for reducing the demands of the format is quite |
|
3393 |
simple-minded, so override this method in your subclass if your |
|
3394 |
application has spcific requirements on visual selection. |
|
3395 |
||
3396 |
\sa chooseContext() |
|
3397 |
*/ |
|
3398 |
||
3399 |
/*! \fn void *QGLContext::tryVisual(const QGLFormat& f, int bufDepth) |
|
3400 |
\internal |
|
3401 |
||
3402 |
\bold{X11 only:} This virtual function chooses a visual that matches |
|
3403 |
the OpenGL \link format() format\endlink. Reimplement this function |
|
3404 |
in a subclass if you need a custom visual. |
|
3405 |
||
3406 |
\sa chooseContext() |
|
3407 |
*/ |
|
3408 |
||
3409 |
/*! |
|
3410 |
\fn void QGLContext::reset() |
|
3411 |
||
3412 |
Resets the context and makes it invalid. |
|
3413 |
||
3414 |
\sa create(), isValid() |
|
3415 |
*/ |
|
3416 |
||
3417 |
||
3418 |
/*! |
|
3419 |
\fn void QGLContext::makeCurrent() |
|
3420 |
||
3421 |
Makes this context the current OpenGL rendering context. All GL |
|
3422 |
functions you call operate on this context until another context |
|
3423 |
is made current. |
|
3424 |
||
3425 |
In some very rare cases the underlying call may fail. If this |
|
3426 |
occurs an error message is output to stderr. |
|
3427 |
*/ |
|
3428 |
||
3429 |
||
3430 |
/*! |
|
3431 |
\fn void QGLContext::swapBuffers() const |
|
3432 |
||
3433 |
Swaps the screen contents with an off-screen buffer. Only works if |
|
3434 |
the context is in double buffer mode. |
|
3435 |
||
3436 |
\sa QGLFormat::setDoubleBuffer() |
|
3437 |
*/ |
|
3438 |
||
3439 |
||
3440 |
/*! |
|
3441 |
\fn void QGLContext::doneCurrent() |
|
3442 |
||
3443 |
Makes no GL context the current context. Normally, you do not need |
|
3444 |
to call this function; QGLContext calls it as necessary. |
|
3445 |
*/ |
|
3446 |
||
3447 |
||
3448 |
/*! |
|
3449 |
\fn QPaintDevice* QGLContext::device() const |
|
3450 |
||
3451 |
Returns the paint device set for this context. |
|
3452 |
||
3453 |
\sa QGLContext::QGLContext() |
|
3454 |
*/ |
|
3455 |
||
3456 |
/*! |
|
3457 |
\obsolete |
|
3458 |
\fn void QGLContext::generateFontDisplayLists(const QFont& font, int listBase) |
|
3459 |
||
3460 |
Generates a set of 256 display lists for the 256 first characters |
|
3461 |
in the font \a font. The first list will start at index \a listBase. |
|
3462 |
||
3463 |
\sa QGLWidget::renderText() |
|
3464 |
*/ |
|
3465 |
||
3466 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3467 |
|
0 | 3468 |
/***************************************************************************** |
3469 |
QGLWidget implementation |
|
3470 |
*****************************************************************************/ |
|
3471 |
||
3472 |
||
3473 |
/*! |
|
3474 |
\class QGLWidget |
|
3475 |
\brief The QGLWidget class is a widget for rendering OpenGL graphics. |
|
3476 |
||
3477 |
\ingroup painting-3D |
|
3478 |
||
3479 |
||
3480 |
QGLWidget provides functionality for displaying OpenGL graphics |
|
3481 |
integrated into a Qt application. It is very simple to use. You |
|
3482 |
inherit from it and use the subclass like any other QWidget, |
|
3483 |
except that you have the choice between using QPainter and |
|
3484 |
standard OpenGL rendering commands. |
|
3485 |
||
3486 |
QGLWidget provides three convenient virtual functions that you can |
|
3487 |
reimplement in your subclass to perform the typical OpenGL tasks: |
|
3488 |
||
3489 |
\list |
|
3490 |
\i paintGL() - Renders the OpenGL scene. Gets called whenever the widget |
|
3491 |
needs to be updated. |
|
3492 |
\i resizeGL() - Sets up the OpenGL viewport, projection, etc. Gets |
|
3493 |
called whenever the widget has been resized (and also when it |
|
3494 |
is shown for the first time because all newly created widgets get a |
|
3495 |
resize event automatically). |
|
3496 |
\i initializeGL() - Sets up the OpenGL rendering context, defines display |
|
3497 |
lists, etc. Gets called once before the first time resizeGL() or |
|
3498 |
paintGL() is called. |
|
3499 |
\endlist |
|
3500 |
||
3501 |
Here is a rough outline of how a QGLWidget subclass might look: |
|
3502 |
||
3503 |
\snippet doc/src/snippets/code/src_opengl_qgl.cpp 8 |
|
3504 |
||
3505 |
If you need to trigger a repaint from places other than paintGL() |
|
3506 |
(a typical example is when using \link QTimer timers\endlink to |
|
3507 |
animate scenes), you should call the widget's updateGL() function. |
|
3508 |
||
3509 |
Your widget's OpenGL rendering context is made current when |
|
3510 |
paintGL(), resizeGL(), or initializeGL() is called. If you need to |
|
3511 |
call the standard OpenGL API functions from other places (e.g. in |
|
3512 |
your widget's constructor or in your own paint functions), you |
|
3513 |
must call makeCurrent() first. |
|
3514 |
||
3515 |
QGLWidget provides functions for requesting a new display \link |
|
3516 |
QGLFormat format\endlink and you can also create widgets with |
|
3517 |
customized rendering \link QGLContext contexts\endlink. |
|
3518 |
||
3519 |
You can also share OpenGL display lists between QGLWidget objects (see |
|
3520 |
the documentation of the QGLWidget constructors for details). |
|
3521 |
||
3522 |
Note that under Windows, the QGLContext belonging to a QGLWidget |
|
3523 |
has to be recreated when the QGLWidget is reparented. This is |
|
3524 |
necessary due to limitations on the Windows platform. This will |
|
3525 |
most likely cause problems for users that have subclassed and |
|
3526 |
installed their own QGLContext on a QGLWidget. It is possible to |
|
3527 |
work around this issue by putting the QGLWidget inside a dummy |
|
3528 |
widget and then reparenting the dummy widget, instead of the |
|
3529 |
QGLWidget. This will side-step the issue altogether, and is what |
|
3530 |
we recommend for users that need this kind of functionality. |
|
3531 |
||
3532 |
On Mac OS X, when Qt is built with Cocoa support, a QGLWidget |
|
3533 |
can't have any sibling widgets placed ontop of itself. This is due |
|
3534 |
to limitations in the Cocoa API and is not supported by Apple. |
|
3535 |
||
3536 |
\section1 Overlays |
|
3537 |
||
3538 |
The QGLWidget creates a GL overlay context in addition to the |
|
3539 |
normal context if overlays are supported by the underlying system. |
|
3540 |
||
3541 |
If you want to use overlays, you specify it in the \link QGLFormat |
|
3542 |
format\endlink. (Note: Overlay must be requested in the format |
|
3543 |
passed to the QGLWidget constructor.) Your GL widget should also |
|
3544 |
implement some or all of these virtual methods: |
|
3545 |
||
3546 |
\list |
|
3547 |
\i paintOverlayGL() |
|
3548 |
\i resizeOverlayGL() |
|
3549 |
\i initializeOverlayGL() |
|
3550 |
\endlist |
|
3551 |
||
3552 |
These methods work in the same way as the normal paintGL() etc. |
|
3553 |
functions, except that they will be called when the overlay |
|
3554 |
context is made current. You can explicitly make the overlay |
|
3555 |
context current by using makeOverlayCurrent(), and you can access |
|
3556 |
the overlay context directly (e.g. to ask for its transparent |
|
3557 |
color) by calling overlayContext(). |
|
3558 |
||
3559 |
On X servers in which the default visual is in an overlay plane, |
|
3560 |
non-GL Qt windows can also be used for overlays. |
|
3561 |
||
3562 |
\section1 Painting Techniques |
|
3563 |
||
3564 |
As described above, subclass QGLWidget to render pure 3D content in the |
|
3565 |
following way: |
|
3566 |
||
3567 |
\list |
|
3568 |
\o Reimplement the QGLWidget::initializeGL() and QGLWidget::resizeGL() to |
|
3569 |
set up the OpenGL state and provide a perspective transformation. |
|
3570 |
\o Reimplement QGLWidget::paintGL() to paint the 3D scene, calling only |
|
3571 |
OpenGL functions to draw on the widget. |
|
3572 |
\endlist |
|
3573 |
||
3574 |
It is also possible to draw 2D graphics onto a QGLWidget subclass, it is necessary |
|
3575 |
to reimplement QGLWidget::paintEvent() and do the following: |
|
3576 |
||
3577 |
\list |
|
3578 |
\o Construct a QPainter object. |
|
3579 |
\o Initialize it for use on the widget with the QPainter::begin() function. |
|
3580 |
\o Draw primitives using QPainter's member functions. |
|
3581 |
\o Call QPainter::end() to finish painting. |
|
3582 |
\endlist |
|
3583 |
||
3584 |
Overpainting 2D content on top of 3D content takes a little more effort. |
|
3585 |
One approach to doing this is shown in the |
|
3586 |
\l{Overpainting Example}{Overpainting} example. |
|
3587 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3588 |
\section1 Threading |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3589 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3590 |
It is possible to render into a QGLWidget from another thread, but it |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3591 |
requires that all access to the GL context is safe guarded. The Qt GUI |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3592 |
thread will try to use the context in resizeEvent and paintEvent, so in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3593 |
order for threaded rendering using a GL widget to work, these functions |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3594 |
need to be intercepted in the GUI thread and handled accordingly in the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3595 |
application. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
3596 |
|
0 | 3597 |
\e{OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other |
3598 |
countries.} |
|
3599 |
||
3600 |
\sa QGLPixelBuffer, {Hello GL Example}, {2D Painting Example}, {Overpainting Example}, |
|
3601 |
{Grabber Example} |
|
3602 |
*/ |
|
3603 |
||
3604 |
/*! |
|
3605 |
Constructs an OpenGL widget with a \a parent widget. |
|
3606 |
||
3607 |
The \link QGLFormat::defaultFormat() default format\endlink is |
|
3608 |
used. The widget will be \link isValid() invalid\endlink if the |
|
3609 |
system has no \link QGLFormat::hasOpenGL() OpenGL support\endlink. |
|
3610 |
||
3611 |
The \a parent and widget flag, \a f, arguments are passed |
|
3612 |
to the QWidget constructor. |
|
3613 |
||
3614 |
If \a shareWidget is a valid QGLWidget, this widget will share |
|
3615 |
OpenGL display lists and texture objects with \a shareWidget. But |
|
3616 |
if \a shareWidget and this widget have different \l {format()} |
|
3617 |
{formats}, sharing might not be possible. You can check whether |
|
3618 |
sharing is in effect by calling isSharing(). |
|
3619 |
||
3620 |
The initialization of OpenGL rendering state, etc. should be done |
|
3621 |
by overriding the initializeGL() function, rather than in the |
|
3622 |
constructor of your QGLWidget subclass. |
|
3623 |
||
3624 |
\sa QGLFormat::defaultFormat(), {Textures Example} |
|
3625 |
*/ |
|
3626 |
||
3627 |
QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFlags f) |
|
3628 |
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) |
|
3629 |
{ |
|
3630 |
Q_D(QGLWidget); |
|
3631 |
setAttribute(Qt::WA_PaintOnScreen); |
|
3632 |
setAttribute(Qt::WA_NoSystemBackground); |
|
3633 |
setAutoFillBackground(true); // for compatibility |
|
3634 |
d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget); |
|
3635 |
} |
|
3636 |
||
3637 |
||
3638 |
/*! |
|
3639 |
Constructs an OpenGL widget with parent \a parent. |
|
3640 |
||
3641 |
The \a format argument specifies the desired \link QGLFormat |
|
3642 |
rendering options \endlink. If the underlying OpenGL/Window system |
|
3643 |
cannot satisfy all the features requested in \a format, the |
|
3644 |
nearest subset of features will be used. After creation, the |
|
3645 |
format() method will return the actual format obtained. |
|
3646 |
||
3647 |
The widget will be \link isValid() invalid\endlink if the system |
|
3648 |
has no \link QGLFormat::hasOpenGL() OpenGL support\endlink. |
|
3649 |
||
3650 |
The \a parent and widget flag, \a f, arguments are passed |
|
3651 |
to the QWidget constructor. |
|
3652 |
||
3653 |
If \a shareWidget is a valid QGLWidget, this widget will share |
|
3654 |
OpenGL display lists and texture objects with \a shareWidget. But |
|
3655 |
if \a shareWidget and this widget have different \l {format()} |
|
3656 |
{formats}, sharing might not be possible. You can check whether |
|
3657 |
sharing is in effect by calling isSharing(). |
|
3658 |
||
3659 |
The initialization of OpenGL rendering state, etc. should be done |
|
3660 |
by overriding the initializeGL() function, rather than in the |
|
3661 |
constructor of your QGLWidget subclass. |
|
3662 |
||
3663 |
\sa QGLFormat::defaultFormat(), isValid() |
|
3664 |
*/ |
|
3665 |
||
3666 |
QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget* shareWidget, |
|
3667 |
Qt::WindowFlags f) |
|
3668 |
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) |
|
3669 |
{ |
|
3670 |
Q_D(QGLWidget); |
|
3671 |
setAttribute(Qt::WA_PaintOnScreen); |
|
3672 |
setAttribute(Qt::WA_NoSystemBackground); |
|
3673 |
setAutoFillBackground(true); // for compatibility |
|
3674 |
d->init(new QGLContext(format, this), shareWidget); |
|
3675 |
} |
|
3676 |
||
3677 |
/*! |
|
3678 |
Constructs an OpenGL widget with parent \a parent. |
|
3679 |
||
3680 |
The \a context argument is a pointer to the QGLContext that |
|
3681 |
you wish to be bound to this widget. This allows you to pass in |
|
3682 |
your own QGLContext sub-classes. |
|
3683 |
||
3684 |
The widget will be \link isValid() invalid\endlink if the system |
|
3685 |
has no \link QGLFormat::hasOpenGL() OpenGL support\endlink. |
|
3686 |
||
3687 |
The \a parent and widget flag, \a f, arguments are passed |
|
3688 |
to the QWidget constructor. |
|
3689 |
||
3690 |
If \a shareWidget is a valid QGLWidget, this widget will share |
|
3691 |
OpenGL display lists and texture objects with \a shareWidget. But |
|
3692 |
if \a shareWidget and this widget have different \l {format()} |
|
3693 |
{formats}, sharing might not be possible. You can check whether |
|
3694 |
sharing is in effect by calling isSharing(). |
|
3695 |
||
3696 |
The initialization of OpenGL rendering state, etc. should be done |
|
3697 |
by overriding the initializeGL() function, rather than in the |
|
3698 |
constructor of your QGLWidget subclass. |
|
3699 |
||
3700 |
\sa QGLFormat::defaultFormat(), isValid() |
|
3701 |
*/ |
|
3702 |
QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, const QGLWidget *shareWidget, |
|
3703 |
Qt::WindowFlags f) |
|
3704 |
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) |
|
3705 |
{ |
|
3706 |
Q_D(QGLWidget); |
|
3707 |
setAttribute(Qt::WA_PaintOnScreen); |
|
3708 |
setAttribute(Qt::WA_NoSystemBackground); |
|
3709 |
setAutoFillBackground(true); // for compatibility |
|
3710 |
d->init(context, shareWidget); |
|
3711 |
} |
|
3712 |
||
3713 |
/*! |
|
3714 |
Destroys the widget. |
|
3715 |
*/ |
|
3716 |
||
3717 |
QGLWidget::~QGLWidget() |
|
3718 |
{ |
|
3719 |
Q_D(QGLWidget); |
|
3720 |
#if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT) |
|
3721 |
bool doRelease = (glcx && glcx->windowCreated()); |
|
3722 |
#endif |
|
3723 |
delete d->glcx; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3724 |
d->glcx = 0; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3725 |
#if defined(Q_WS_WIN) |
0 | 3726 |
delete d->olcx; |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3727 |
d->olcx = 0; |
0 | 3728 |
#endif |
3729 |
#if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT) |
|
3730 |
if (doRelease) |
|
3731 |
glXReleaseBuffersMESA(x11Display(), winId()); |
|
3732 |
#endif |
|
3733 |
d->cleanupColormaps(); |
|
3734 |
||
3735 |
#ifdef Q_WS_MAC |
|
3736 |
QWidget *current = parentWidget(); |
|
3737 |
while (current) { |
|
3738 |
qt_widget_private(current)->glWidgets.removeAll(QWidgetPrivate::GlWidgetInfo(this)); |
|
3739 |
if (current->isWindow()) |
|
3740 |
break; |
|
3741 |
current = current->parentWidget(); |
|
3742 |
}; |
|
3743 |
#endif |
|
3744 |
} |
|
3745 |
||
3746 |
/*! |
|
3747 |
\fn QGLFormat QGLWidget::format() const |
|
3748 |
||
3749 |
Returns the format of the contained GL rendering context. |
|
3750 |
*/ |
|
3751 |
||
3752 |
/*! |
|
3753 |
\fn bool QGLWidget::doubleBuffer() const |
|
3754 |
||
3755 |
Returns true if the contained GL rendering context has double |
|
3756 |
buffering; otherwise returns false. |
|
3757 |
||
3758 |
\sa QGLFormat::doubleBuffer() |
|
3759 |
*/ |
|
3760 |
||
3761 |
/*! |
|
3762 |
\fn void QGLWidget::setAutoBufferSwap(bool on) |
|
3763 |
||
3764 |
If \a on is true automatic GL buffer swapping is switched on; |
|
3765 |
otherwise it is switched off. |
|
3766 |
||
3767 |
If \a on is true and the widget is using a double-buffered format, |
|
3768 |
the background and foreground GL buffers will automatically be |
|
3769 |
swapped after each paintGL() call. |
|
3770 |
||
3771 |
The buffer auto-swapping is on by default. |
|
3772 |
||
3773 |
\sa autoBufferSwap(), doubleBuffer(), swapBuffers() |
|
3774 |
*/ |
|
3775 |
||
3776 |
/*! |
|
3777 |
\fn bool QGLWidget::autoBufferSwap() const |
|
3778 |
||
3779 |
Returns true if the widget is doing automatic GL buffer swapping; |
|
3780 |
otherwise returns false. |
|
3781 |
||
3782 |
\sa setAutoBufferSwap() |
|
3783 |
*/ |
|
3784 |
||
3785 |
/*! |
|
3786 |
\fn void *QGLContext::getProcAddress(const QString &proc) const |
|
3787 |
||
3788 |
Returns a function pointer to the GL extension function passed in |
|
3789 |
\a proc. 0 is returned if a pointer to the function could not be |
|
3790 |
obtained. |
|
3791 |
*/ |
|
3792 |
||
3793 |
/*! |
|
3794 |
\fn bool QGLWidget::isValid() const |
|
3795 |
||
3796 |
Returns true if the widget has a valid GL rendering context; |
|
3797 |
otherwise returns false. A widget will be invalid if the system |
|
3798 |
has no \link QGLFormat::hasOpenGL() OpenGL support\endlink. |
|
3799 |
*/ |
|
3800 |
||
3801 |
bool QGLWidget::isValid() const |
|
3802 |
{ |
|
3803 |
Q_D(const QGLWidget); |
|
3804 |
return d->glcx && d->glcx->isValid(); |
|
3805 |
} |
|
3806 |
||
3807 |
/*! |
|
3808 |
\fn bool QGLWidget::isSharing() const |
|
3809 |
||
3810 |
Returns true if this widget's GL context is shared with another GL |
|
3811 |
context, otherwise false is returned. Context sharing might not be |
|
3812 |
possible if the widgets use different formats. |
|
3813 |
||
3814 |
\sa format() |
|
3815 |
*/ |
|
3816 |
||
3817 |
bool QGLWidget::isSharing() const |
|
3818 |
{ |
|
3819 |
Q_D(const QGLWidget); |
|
3820 |
return d->glcx->isSharing(); |
|
3821 |
} |
|
3822 |
||
3823 |
/*! |
|
3824 |
\fn void QGLWidget::makeCurrent() |
|
3825 |
||
3826 |
Makes this widget the current widget for OpenGL operations, i.e. |
|
3827 |
makes the widget's rendering context the current OpenGL rendering |
|
3828 |
context. |
|
3829 |
*/ |
|
3830 |
||
3831 |
void QGLWidget::makeCurrent() |
|
3832 |
{ |
|
3833 |
Q_D(QGLWidget); |
|
3834 |
d->glcx->makeCurrent(); |
|
3835 |
} |
|
3836 |
||
3837 |
/*! |
|
3838 |
\fn void QGLWidget::doneCurrent() |
|
3839 |
||
3840 |
Makes no GL context the current context. Normally, you do not need |
|
3841 |
to call this function; QGLContext calls it as necessary. However, |
|
3842 |
it may be useful in multithreaded environments. |
|
3843 |
*/ |
|
3844 |
||
3845 |
void QGLWidget::doneCurrent() |
|
3846 |
{ |
|
3847 |
Q_D(QGLWidget); |
|
3848 |
d->glcx->doneCurrent(); |
|
3849 |
} |
|
3850 |
||
3851 |
/*! |
|
3852 |
\fn void QGLWidget::swapBuffers() |
|
3853 |
||
3854 |
Swaps the screen contents with an off-screen buffer. This only |
|
3855 |
works if the widget's format specifies double buffer mode. |
|
3856 |
||
3857 |
Normally, there is no need to explicitly call this function |
|
3858 |
because it is done automatically after each widget repaint, i.e. |
|
3859 |
each time after paintGL() has been executed. |
|
3860 |
||
3861 |
\sa doubleBuffer(), setAutoBufferSwap(), QGLFormat::setDoubleBuffer() |
|
3862 |
*/ |
|
3863 |
||
3864 |
void QGLWidget::swapBuffers() |
|
3865 |
{ |
|
3866 |
Q_D(QGLWidget); |
|
3867 |
d->glcx->swapBuffers(); |
|
3868 |
} |
|
3869 |
||
3870 |
||
3871 |
/*! |
|
3872 |
\fn const QGLContext* QGLWidget::overlayContext() const |
|
3873 |
||
3874 |
Returns the overlay context of this widget, or 0 if this widget |
|
3875 |
has no overlay. |
|
3876 |
||
3877 |
\sa context() |
|
3878 |
*/ |
|
3879 |
||
3880 |
||
3881 |
||
3882 |
/*! |
|
3883 |
\fn void QGLWidget::makeOverlayCurrent() |
|
3884 |
||
3885 |
Makes the overlay context of this widget current. Use this if you |
|
3886 |
need to issue OpenGL commands to the overlay context outside of |
|
3887 |
initializeOverlayGL(), resizeOverlayGL(), and paintOverlayGL(). |
|
3888 |
||
3889 |
Does nothing if this widget has no overlay. |
|
3890 |
||
3891 |
\sa makeCurrent() |
|
3892 |
*/ |
|
3893 |
||
3894 |
||
3895 |
/*! |
|
3896 |
\obsolete |
|
3897 |
||
3898 |
Sets a new format for this widget. |
|
3899 |
||
3900 |
If the underlying OpenGL/Window system cannot satisfy all the |
|
3901 |
features requested in \a format, the nearest subset of features will |
|
3902 |
be used. After creation, the format() method will return the actual |
|
3903 |
rendering context format obtained. |
|
3904 |
||
3905 |
The widget will be assigned a new QGLContext, and the initializeGL() |
|
3906 |
function will be executed for this new context before the first |
|
3907 |
resizeGL() or paintGL(). |
|
3908 |
||
3909 |
This method will try to keep display list and texture object sharing |
|
3910 |
in effect with other QGLWidget objects, but changing the format might make |
|
3911 |
sharing impossible. Use isSharing() to see if sharing is still in |
|
3912 |
effect. |
|
3913 |
||
3914 |
\sa format(), isSharing(), isValid() |
|
3915 |
*/ |
|
3916 |
||
3917 |
void QGLWidget::setFormat(const QGLFormat &format) |
|
3918 |
{ |
|
3919 |
setContext(new QGLContext(format,this)); |
|
3920 |
} |
|
3921 |
||
3922 |
||
3923 |
||
3924 |
||
3925 |
/*! |
|
3926 |
\fn const QGLContext *QGLWidget::context() const |
|
3927 |
||
3928 |
Returns the context of this widget. |
|
3929 |
||
3930 |
It is possible that the context is not valid (see isValid()), for |
|
3931 |
example, if the underlying hardware does not support the format |
|
3932 |
attributes that were requested. |
|
3933 |
*/ |
|
3934 |
||
3935 |
/* |
|
3936 |
\fn void QGLWidget::setContext(QGLContext *context, |
|
3937 |
const QGLContext* shareContext, |
|
3938 |
bool deleteOldContext) |
|
3939 |
\obsolete |
|
3940 |
||
3941 |
Sets a new context for this widget. The QGLContext \a context must |
|
3942 |
be created using \e new. QGLWidget will delete \a context when |
|
3943 |
another context is set or when the widget is destroyed. |
|
3944 |
||
3945 |
If \a context is invalid, QGLContext::create() is performed on |
|
3946 |
it. The initializeGL() function will then be executed for the new |
|
3947 |
context before the first resizeGL() or paintGL(). |
|
3948 |
||
3949 |
If \a context is invalid, this method will try to keep display list |
|
3950 |
and texture object sharing in effect, or (if \a shareContext points |
|
3951 |
to a valid context) start display list and texture object sharing |
|
3952 |
with that context, but sharing might be impossible if the two |
|
3953 |
contexts have different \l {format()} {formats}. Use isSharing() to |
|
3954 |
see whether sharing is in effect. |
|
3955 |
||
3956 |
If \a deleteOldContext is true (the default), the existing context |
|
3957 |
will be deleted. You may use false here if you have kept a pointer |
|
3958 |
to the old context (as returned by context()), and want to restore |
|
3959 |
that context later. |
|
3960 |
||
3961 |
\sa context(), isSharing() |
|
3962 |
*/ |
|
3963 |
||
3964 |
||
3965 |
||
3966 |
/*! |
|
3967 |
\fn void QGLWidget::updateGL() |
|
3968 |
||
3969 |
Updates the widget by calling glDraw(). |
|
3970 |
*/ |
|
3971 |
||
3972 |
void QGLWidget::updateGL() |
|
3973 |
{ |
|
3974 |
if (updatesEnabled()) |
|
3975 |
glDraw(); |
|
3976 |
} |
|
3977 |
||
3978 |
||
3979 |
/*! |
|
3980 |
\fn void QGLWidget::updateOverlayGL() |
|
3981 |
||
3982 |
Updates the widget's overlay (if any). Will cause the virtual |
|
3983 |
function paintOverlayGL() to be executed. |
|
3984 |
||
3985 |
The widget's rendering context will become the current context and |
|
3986 |
initializeGL() will be called if it hasn't already been called. |
|
3987 |
*/ |
|
3988 |
||
3989 |
||
3990 |
/*! |
|
3991 |
This virtual function is called once before the first call to |
|
3992 |
paintGL() or resizeGL(), and then once whenever the widget has |
|
3993 |
been assigned a new QGLContext. Reimplement it in a subclass. |
|
3994 |
||
3995 |
This function should set up any required OpenGL context rendering |
|
3996 |
flags, defining display lists, etc. |
|
3997 |
||
3998 |
There is no need to call makeCurrent() because this has already |
|
3999 |
been done when this function is called. |
|
4000 |
*/ |
|
4001 |
||
4002 |
void QGLWidget::initializeGL() |
|
4003 |
{ |
|
4004 |
} |
|
4005 |
||
4006 |
||
4007 |
/*! |
|
4008 |
This virtual function is called whenever the widget needs to be |
|
4009 |
painted. Reimplement it in a subclass. |
|
4010 |
||
4011 |
There is no need to call makeCurrent() because this has already |
|
4012 |
been done when this function is called. |
|
4013 |
*/ |
|
4014 |
||
4015 |
void QGLWidget::paintGL() |
|
4016 |
{ |
|
4017 |
} |
|
4018 |
||
4019 |
||
4020 |
/*! |
|
4021 |
\fn void QGLWidget::resizeGL(int width , int height) |
|
4022 |
||
4023 |
This virtual function is called whenever the widget has been |
|
4024 |
resized. The new size is passed in \a width and \a height. |
|
4025 |
Reimplement it in a subclass. |
|
4026 |
||
4027 |
There is no need to call makeCurrent() because this has already |
|
4028 |
been done when this function is called. |
|
4029 |
*/ |
|
4030 |
||
4031 |
void QGLWidget::resizeGL(int, int) |
|
4032 |
{ |
|
4033 |
} |
|
4034 |
||
4035 |
||
4036 |
||
4037 |
/*! |
|
4038 |
This virtual function is used in the same manner as initializeGL() |
|
4039 |
except that it operates on the widget's overlay context instead of |
|
4040 |
the widget's main context. This means that initializeOverlayGL() |
|
4041 |
is called once before the first call to paintOverlayGL() or |
|
4042 |
resizeOverlayGL(). Reimplement it in a subclass. |
|
4043 |
||
4044 |
This function should set up any required OpenGL context rendering |
|
4045 |
flags, defining display lists, etc. for the overlay context. |
|
4046 |
||
4047 |
There is no need to call makeOverlayCurrent() because this has |
|
4048 |
already been done when this function is called. |
|
4049 |
*/ |
|
4050 |
||
4051 |
void QGLWidget::initializeOverlayGL() |
|
4052 |
{ |
|
4053 |
} |
|
4054 |
||
4055 |
||
4056 |
/*! |
|
4057 |
This virtual function is used in the same manner as paintGL() |
|
4058 |
except that it operates on the widget's overlay context instead of |
|
4059 |
the widget's main context. This means that paintOverlayGL() is |
|
4060 |
called whenever the widget's overlay needs to be painted. |
|
4061 |
Reimplement it in a subclass. |
|
4062 |
||
4063 |
There is no need to call makeOverlayCurrent() because this has |
|
4064 |
already been done when this function is called. |
|
4065 |
*/ |
|
4066 |
||
4067 |
void QGLWidget::paintOverlayGL() |
|
4068 |
{ |
|
4069 |
} |
|
4070 |
||
4071 |
||
4072 |
/*! |
|
4073 |
\fn void QGLWidget::resizeOverlayGL(int width , int height) |
|
4074 |
||
4075 |
This virtual function is used in the same manner as paintGL() |
|
4076 |
except that it operates on the widget's overlay context instead of |
|
4077 |
the widget's main context. This means that resizeOverlayGL() is |
|
4078 |
called whenever the widget has been resized. The new size is |
|
4079 |
passed in \a width and \a height. Reimplement it in a subclass. |
|
4080 |
||
4081 |
There is no need to call makeOverlayCurrent() because this has |
|
4082 |
already been done when this function is called. |
|
4083 |
*/ |
|
4084 |
||
4085 |
void QGLWidget::resizeOverlayGL(int, int) |
|
4086 |
{ |
|
4087 |
} |
|
4088 |
||
4089 |
/*! \fn bool QGLWidget::event(QEvent *e) |
|
4090 |
\reimp |
|
4091 |
*/ |
|
4092 |
#if !defined(Q_OS_WINCE) && !defined(Q_WS_QWS) |
|
4093 |
bool QGLWidget::event(QEvent *e) |
|
4094 |
{ |
|
4095 |
Q_D(QGLWidget); |
|
4096 |
||
4097 |
if (e->type() == QEvent::Paint) { |
|
4098 |
QPoint offset; |
|
4099 |
QPaintDevice *redirectedDevice = d->redirected(&offset); |
|
4100 |
if (redirectedDevice && redirectedDevice->devType() == QInternal::Pixmap) { |
|
4101 |
d->restoreRedirected(); |
|
4102 |
QPixmap pixmap = renderPixmap(); |
|
4103 |
d->setRedirected(redirectedDevice, offset); |
|
4104 |
QPainter p(redirectedDevice); |
|
4105 |
p.drawPixmap(-offset, pixmap); |
|
4106 |
return true; |
|
4107 |
} |
|
4108 |
} |
|
4109 |
||
4110 |
#if defined(Q_WS_X11) |
|
4111 |
// prevents X errors on some systems, where we get a flush to a |
|
4112 |
// hidden widget |
|
4113 |
if (e->type() == QEvent::Hide) { |
|
4114 |
makeCurrent(); |
|
4115 |
glFinish(); |
|
4116 |
doneCurrent(); |
|
4117 |
} else if (e->type() == QEvent::ParentChange) { |
|
4118 |
// if we've reparented a window that has the current context |
|
4119 |
// bound, we need to rebind that context to the new window id |
|
4120 |
if (d->glcx == QGLContext::currentContext()) |
|
4121 |
makeCurrent(); |
|
4122 |
||
4123 |
if (d->glcx->d_func()->screen != d->xinfo.screen() || testAttribute(Qt::WA_TranslucentBackground)) { |
|
4124 |
setContext(new QGLContext(d->glcx->requestedFormat(), this)); |
|
4125 |
// ### recreating the overlay isn't supported atm |
|
4126 |
} |
|
4127 |
} |
|
4128 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
4129 |
#ifndef QT_NO_EGL |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4130 |
// A re-parent is likely to destroy the X11 window and re-create it. It is important |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4131 |
// that we free the EGL surface _before_ the winID changes - otherwise we can leak. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4132 |
if (e->type() == QEvent::ParentAboutToChange) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4133 |
d->glcx->d_func()->destroyEglSurfaceForDevice(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4134 |
|
0 | 4135 |
if ((e->type() == QEvent::ParentChange) || (e->type() == QEvent::WindowStateChange)) { |
4136 |
// The window may have been re-created during re-parent or state change - if so, the EGL |
|
4137 |
// surface will need to be re-created. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
4138 |
d->recreateEglSurface(); |
0 | 4139 |
} |
4140 |
#endif |
|
4141 |
#elif defined(Q_WS_WIN) |
|
4142 |
if (e->type() == QEvent::ParentChange) { |
|
4143 |
QGLContext *newContext = new QGLContext(d->glcx->requestedFormat(), this); |
|
4144 |
setContext(newContext, d->glcx); |
|
4145 |
||
4146 |
// the overlay needs to be recreated as well |
|
4147 |
delete d->olcx; |
|
4148 |
if (isValid() && context()->format().hasOverlay()) { |
|
4149 |
d->olcx = new QGLContext(QGLFormat::defaultOverlayFormat(), this); |
|
4150 |
if (!d->olcx->create(isSharing() ? d->glcx : 0)) { |
|
4151 |
delete d->olcx; |
|
4152 |
d->olcx = 0; |
|
4153 |
d->glcx->d_func()->glFormat.setOverlay(false); |
|
4154 |
} |
|
4155 |
} else { |
|
4156 |
d->olcx = 0; |
|
4157 |
} |
|
4158 |
} else if (e->type() == QEvent::Show) { |
|
4159 |
if (!format().rgba()) |
|
4160 |
d->updateColormap(); |
|
4161 |
} |
|
4162 |
#elif defined(Q_WS_MAC) |
|
4163 |
if (e->type() == QEvent::MacGLWindowChange |
|
4164 |
#if 0 //(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) |
|
4165 |
&& ((QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && isWindow()) |
|
4166 |
|| QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4) |
|
4167 |
#endif |
|
4168 |
) { |
|
4169 |
if (d->needWindowChange) { |
|
4170 |
d->needWindowChange = false; |
|
4171 |
d->glcx->updatePaintDevice(); |
|
4172 |
update(); |
|
4173 |
} |
|
4174 |
return true; |
|
4175 |
# if defined(QT_MAC_USE_COCOA) |
|
4176 |
} else if (e->type() == QEvent::MacGLClearDrawable) { |
|
4177 |
d->glcx->d_ptr->clearDrawable(); |
|
4178 |
# endif |
|
4179 |
} |
|
4180 |
#endif |
|
4181 |
||
4182 |
return QWidget::event(e); |
|
4183 |
} |
|
4184 |
#endif |
|
4185 |
||
4186 |
/*! |
|
4187 |
\fn void QGLWidget::paintEvent(QPaintEvent *event) |
|
4188 |
||
4189 |
Handles paint events passed in the \a event parameter. Will cause |
|
4190 |
the virtual paintGL() function to be called. |
|
4191 |
||
4192 |
The widget's rendering context will become the current context and |
|
4193 |
initializeGL() will be called if it hasn't already been called. |
|
4194 |
*/ |
|
4195 |
||
4196 |
void QGLWidget::paintEvent(QPaintEvent *) |
|
4197 |
{ |
|
4198 |
if (updatesEnabled()) { |
|
4199 |
glDraw(); |
|
4200 |
updateOverlayGL(); |
|
4201 |
} |
|
4202 |
} |
|
4203 |
||
4204 |
||
4205 |
/*! |
|
4206 |
\fn void QGLWidget::resizeEvent(QResizeEvent *event) |
|
4207 |
||
4208 |
Handles resize events that are passed in the \a event parameter. |
|
4209 |
Calls the virtual function resizeGL(). |
|
4210 |
*/ |
|
4211 |
||
4212 |
||
4213 |
/*! |
|
4214 |
\fn void QGLWidget::setMouseTracking(bool enable) |
|
4215 |
||
4216 |
If \a enable is true then mouse tracking is enabled; otherwise it |
|
4217 |
is disabled. |
|
4218 |
*/ |
|
4219 |
||
4220 |
||
4221 |
/*! |
|
4222 |
Renders the current scene on a pixmap and returns the pixmap. |
|
4223 |
||
4224 |
You can use this method on both visible and invisible QGLWidget objects. |
|
4225 |
||
4226 |
This method will create a pixmap and a temporary QGLContext to |
|
4227 |
render on the pixmap. It will then call initializeGL(), |
|
4228 |
resizeGL(), and paintGL() on this context. Finally, the widget's |
|
4229 |
original GL context is restored. |
|
4230 |
||
4231 |
The size of the pixmap will be \a w pixels wide and \a h pixels |
|
4232 |
high unless one of these parameters is 0 (the default), in which |
|
4233 |
case the pixmap will have the same size as the widget. |
|
4234 |
||
4235 |
If \a useContext is true, this method will try to be more |
|
4236 |
efficient by using the existing GL context to render the pixmap. |
|
4237 |
The default is false. Only use true if you understand the risks. |
|
4238 |
Note that under Windows a temporary context has to be created |
|
4239 |
and usage of the \e useContext parameter is not supported. |
|
4240 |
||
4241 |
Overlays are not rendered onto the pixmap. |
|
4242 |
||
4243 |
If the GL rendering context and the desktop have different bit |
|
4244 |
depths, the result will most likely look surprising. |
|
4245 |
||
4246 |
Note that the creation of display lists, modifications of the view |
|
4247 |
frustum etc. should be done from within initializeGL(). If this is |
|
4248 |
not done, the temporary QGLContext will not be initialized |
|
4249 |
properly, and the rendered pixmap may be incomplete/corrupted. |
|
4250 |
*/ |
|
4251 |
||
4252 |
QPixmap QGLWidget::renderPixmap(int w, int h, bool useContext) |
|
4253 |
{ |
|
4254 |
Q_D(QGLWidget); |
|
4255 |
QSize sz = size(); |
|
4256 |
if ((w > 0) && (h > 0)) |
|
4257 |
sz = QSize(w, h); |
|
4258 |
||
4259 |
#if defined(Q_WS_X11) |
|
4260 |
extern int qt_x11_preferred_pixmap_depth; |
|
4261 |
int old_depth = qt_x11_preferred_pixmap_depth; |
|
4262 |
qt_x11_preferred_pixmap_depth = x11Info().depth(); |
|
4263 |
||
4264 |
QPixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); |
|
4265 |
data->resize(sz.width(), sz.height()); |
|
4266 |
QPixmap pm(data); |
|
4267 |
qt_x11_preferred_pixmap_depth = old_depth; |
|
4268 |
QX11Info xinfo = x11Info(); |
|
4269 |
||
4270 |
// make sure we use a pixmap with the same depth/visual as the widget |
|
4271 |
if (xinfo.visual() != QX11Info::appVisual()) { |
|
4272 |
QX11InfoData* xd = pm.x11Info().getX11Data(true); |
|
4273 |
xd->depth = xinfo.depth(); |
|
4274 |
xd->visual = static_cast<Visual *>(xinfo.visual()); |
|
4275 |
const_cast<QX11Info &>(pm.x11Info()).setX11Data(xd); |
|
4276 |
} |
|
4277 |
||
4278 |
#else |
|
4279 |
QPixmap pm(sz); |
|
4280 |
#endif |
|
4281 |
||
4282 |
d->glcx->doneCurrent(); |
|
4283 |
||
4284 |
bool success = true; |
|
4285 |
||
4286 |
if (useContext && isValid() && d->renderCxPm(&pm)) |
|
4287 |
return pm; |
|
4288 |
||
4289 |
QGLFormat fmt = d->glcx->requestedFormat(); |
|
4290 |
fmt.setDirectRendering(false); // Direct is unlikely to work |
|
4291 |
fmt.setDoubleBuffer(false); // We don't need dbl buf |
|
4292 |
#ifdef Q_WS_MAC // crash prevention on the Mac - it's unlikely to work anyway |
|
4293 |
fmt.setSampleBuffers(false); |
|
4294 |
#endif |
|
4295 |
||
4296 |
QGLContext* ocx = d->glcx; |
|
4297 |
ocx->doneCurrent(); |
|
4298 |
d->glcx = new QGLContext(fmt, &pm); |
|
4299 |
d->glcx->create(); |
|
4300 |
||
4301 |
if (d->glcx->isValid()) |
|
4302 |
updateGL(); |
|
4303 |
else |
|
4304 |
success = false; |
|
4305 |
||
4306 |
delete d->glcx; |
|
4307 |
d->glcx = ocx; |
|
4308 |
||
4309 |
ocx->makeCurrent(); |
|
4310 |
||
4311 |
if (success) { |
|
4312 |
#if defined(Q_WS_X11) |
|
4313 |
if (xinfo.visual() != QX11Info::appVisual()) { |
|
4314 |
QImage image = pm.toImage(); |
|
4315 |
QPixmap p = QPixmap::fromImage(image); |
|
4316 |
return p; |
|
4317 |
} |
|
4318 |
#endif |
|
4319 |
return pm; |
|
4320 |
} |
|
4321 |
return QPixmap(); |
|
4322 |
} |
|
4323 |
||
4324 |
/*! |
|
4325 |
Returns an image of the frame buffer. If \a withAlpha is true the |
|
4326 |
alpha channel is included. |
|
4327 |
||
4328 |
Depending on your hardware, you can explicitly select which color |
|
4329 |
buffer to grab with a glReadBuffer() call before calling this |
|
4330 |
function. |
|
4331 |
*/ |
|
4332 |
QImage QGLWidget::grabFrameBuffer(bool withAlpha) |
|
4333 |
{ |
|
4334 |
makeCurrent(); |
|
4335 |
QImage res; |
|
4336 |
int w = width(); |
|
4337 |
int h = height(); |
|
4338 |
if (format().rgba()) { |
|
4339 |
res = qt_gl_read_framebuffer(QSize(w, h), format().alpha(), withAlpha); |
|
4340 |
} else { |
|
4341 |
#if defined (Q_WS_WIN) && !defined(QT_OPENGL_ES) |
|
4342 |
res = QImage(w, h, QImage::Format_Indexed8); |
|
4343 |
glReadPixels(0, 0, w, h, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, res.bits()); |
|
4344 |
const QVector<QColor> pal = QColormap::instance().colormap(); |
|
4345 |
if (pal.size()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4346 |
res.setColorCount(pal.size()); |
0 | 4347 |
for (int i = 0; i < pal.size(); i++) |
4348 |
res.setColor(i, pal.at(i).rgb()); |
|
4349 |
} |
|
4350 |
res = res.mirrored(); |
|
4351 |
#endif |
|
4352 |
} |
|
4353 |
||
4354 |
return res; |
|
4355 |
} |
|
4356 |
||
4357 |
||
4358 |
||
4359 |
/*! |
|
4360 |
Initializes OpenGL for this widget's context. Calls the virtual |
|
4361 |
function initializeGL(). |
|
4362 |
*/ |
|
4363 |
||
4364 |
void QGLWidget::glInit() |
|
4365 |
{ |
|
4366 |
Q_D(QGLWidget); |
|
4367 |
if (!isValid()) |
|
4368 |
return; |
|
4369 |
makeCurrent(); |
|
4370 |
initializeGL(); |
|
4371 |
d->glcx->setInitialized(true); |
|
4372 |
} |
|
4373 |
||
4374 |
||
4375 |
/*! |
|
4376 |
Executes the virtual function paintGL(). |
|
4377 |
||
4378 |
The widget's rendering context will become the current context and |
|
4379 |
initializeGL() will be called if it hasn't already been called. |
|
4380 |
*/ |
|
4381 |
||
4382 |
void QGLWidget::glDraw() |
|
4383 |
{ |
|
4384 |
Q_D(QGLWidget); |
|
4385 |
if (!isValid()) |
|
4386 |
return; |
|
4387 |
makeCurrent(); |
|
4388 |
#ifndef QT_OPENGL_ES |
|
4389 |
if (d->glcx->deviceIsPixmap()) |
|
4390 |
glDrawBuffer(GL_FRONT); |
|
4391 |
#endif |
|
4392 |
if (!d->glcx->initialized()) { |
|
4393 |
glInit(); |
|
4394 |
resizeGL(d->glcx->device()->width(), d->glcx->device()->height()); // New context needs this "resize" |
|
4395 |
} |
|
4396 |
paintGL(); |
|
4397 |
if (doubleBuffer()) { |
|
4398 |
if (d->autoSwap) |
|
4399 |
swapBuffers(); |
|
4400 |
} else { |
|
4401 |
glFlush(); |
|
4402 |
} |
|
4403 |
} |
|
4404 |
||
4405 |
/*! |
|
4406 |
Convenience function for specifying a drawing color to OpenGL. |
|
4407 |
Calls glColor4 (in RGBA mode) or glIndex (in color-index mode) |
|
4408 |
with the color \a c. Applies to this widgets GL context. |
|
4409 |
||
4410 |
\note This function is not supported on OpenGL/ES 2.0 systems. |
|
4411 |
||
4412 |
\sa qglClearColor(), QGLContext::currentContext(), QColor |
|
4413 |
*/ |
|
4414 |
||
4415 |
void QGLWidget::qglColor(const QColor& c) const |
|
4416 |
{ |
|
4417 |
#if !defined(QT_OPENGL_ES_2) |
|
4418 |
#ifdef QT_OPENGL_ES |
|
4419 |
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); |
|
4420 |
#else |
|
4421 |
Q_D(const QGLWidget); |
|
4422 |
const QGLContext *ctx = QGLContext::currentContext(); |
|
4423 |
if (ctx) { |
|
4424 |
if (ctx->format().rgba()) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4425 |
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); |
0 | 4426 |
else if (!d->cmap.isEmpty()) { // QGLColormap in use? |
4427 |
int i = d->cmap.find(c.rgb()); |
|
4428 |
if (i < 0) |
|
4429 |
i = d->cmap.findNearest(c.rgb()); |
|
4430 |
glIndexi(i); |
|
4431 |
} else |
|
4432 |
glIndexi(ctx->colorIndex(c)); |
|
4433 |
} |
|
4434 |
#endif //QT_OPENGL_ES |
|
4435 |
#else |
|
4436 |
Q_UNUSED(c); |
|
4437 |
#endif //QT_OPENGL_ES_2 |
|
4438 |
} |
|
4439 |
||
4440 |
/*! |
|
4441 |
Convenience function for specifying the clearing color to OpenGL. |
|
4442 |
Calls glClearColor (in RGBA mode) or glClearIndex (in color-index |
|
4443 |
mode) with the color \a c. Applies to this widgets GL context. |
|
4444 |
||
4445 |
\sa qglColor(), QGLContext::currentContext(), QColor |
|
4446 |
*/ |
|
4447 |
||
4448 |
void QGLWidget::qglClearColor(const QColor& c) const |
|
4449 |
{ |
|
4450 |
#ifdef QT_OPENGL_ES |
|
4451 |
glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); |
|
4452 |
#else |
|
4453 |
Q_D(const QGLWidget); |
|
4454 |
const QGLContext *ctx = QGLContext::currentContext(); |
|
4455 |
if (ctx) { |
|
4456 |
if (ctx->format().rgba()) |
|
4457 |
glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); |
|
4458 |
else if (!d->cmap.isEmpty()) { // QGLColormap in use? |
|
4459 |
int i = d->cmap.find(c.rgb()); |
|
4460 |
if (i < 0) |
|
4461 |
i = d->cmap.findNearest(c.rgb()); |
|
4462 |
glClearIndex(i); |
|
4463 |
} else |
|
4464 |
glClearIndex(ctx->colorIndex(c)); |
|
4465 |
} |
|
4466 |
#endif |
|
4467 |
} |
|
4468 |
||
4469 |
||
4470 |
/*! |
|
4471 |
Converts the image \a img into the unnamed format expected by |
|
4472 |
OpenGL functions such as glTexImage2D(). The returned image is not |
|
4473 |
usable as a QImage, but QImage::width(), QImage::height() and |
|
4474 |
QImage::bits() may be used with OpenGL. The GL format used is |
|
4475 |
\c GL_RGBA. |
|
4476 |
||
4477 |
\omit ### |
|
4478 |
||
4479 |
\l opengl/texture example |
|
4480 |
The following few lines are from the texture example. Most of the |
|
4481 |
code is irrelevant, so we just quote the relevant bits: |
|
4482 |
||
4483 |
\quotefromfile opengl/texture/gltexobj.cpp |
|
4484 |
\skipto tex1 |
|
4485 |
\printline tex1 |
|
4486 |
\printline gllogo.bmp |
|
4487 |
||
4488 |
We create \e tex1 (and another variable) for OpenGL, and load a real |
|
4489 |
image into \e buf. |
|
4490 |
||
4491 |
\skipto convertToGLFormat |
|
4492 |
\printline convertToGLFormat |
|
4493 |
||
4494 |
A few lines later, we convert \e buf into OpenGL format and store it |
|
4495 |
in \e tex1. |
|
4496 |
||
4497 |
\skipto glTexImage2D |
|
4498 |
\printline glTexImage2D |
|
4499 |
\printline tex1.bits |
|
4500 |
||
4501 |
Note the dimension restrictions for texture images as described in |
|
4502 |
the glTexImage2D() documentation. The width must be 2^m + 2*border |
|
4503 |
and the height 2^n + 2*border where m and n are integers and |
|
4504 |
border is either 0 or 1. |
|
4505 |
||
4506 |
Another function in the same example uses \e tex1 with OpenGL. |
|
4507 |
||
4508 |
\endomit |
|
4509 |
*/ |
|
4510 |
||
4511 |
QImage QGLWidget::convertToGLFormat(const QImage& img) |
|
4512 |
{ |
|
4513 |
QImage res(img.size(), QImage::Format_ARGB32); |
|
4514 |
convertToGLFormatHelper(res, img.convertToFormat(QImage::Format_ARGB32), GL_RGBA); |
|
4515 |
return res; |
|
4516 |
} |
|
4517 |
||
4518 |
||
4519 |
/*! |
|
4520 |
\fn QGLColormap & QGLWidget::colormap() const |
|
4521 |
||
4522 |
Returns the colormap for this widget. |
|
4523 |
||
4524 |
Usually it is only top-level widgets that can have different |
|
4525 |
colormaps installed. Asking for the colormap of a child widget |
|
4526 |
will return the colormap for the child's top-level widget. |
|
4527 |
||
4528 |
If no colormap has been set for this widget, the QGLColormap |
|
4529 |
returned will be empty. |
|
4530 |
||
4531 |
\sa setColormap(), QGLColormap::isEmpty() |
|
4532 |
*/ |
|
4533 |
||
4534 |
/*! |
|
4535 |
\fn void QGLWidget::setColormap(const QGLColormap & cmap) |
|
4536 |
||
4537 |
Set the colormap for this widget to \a cmap. Usually it is only |
|
4538 |
top-level widgets that can have colormaps installed. |
|
4539 |
||
4540 |
\sa colormap() |
|
4541 |
*/ |
|
4542 |
||
4543 |
||
4544 |
/*! |
|
4545 |
\obsolete |
|
4546 |
||
4547 |
Returns the value of the first display list that is generated for |
|
4548 |
the characters in the given \a font. \a listBase indicates the base |
|
4549 |
value used when generating the display lists for the font. The |
|
4550 |
default value is 2000. |
|
4551 |
||
4552 |
\note This function is not supported on OpenGL/ES systems. |
|
4553 |
*/ |
|
4554 |
int QGLWidget::fontDisplayListBase(const QFont & font, int listBase) |
|
4555 |
{ |
|
4556 |
#ifndef QT_OPENGL_ES |
|
4557 |
Q_D(QGLWidget); |
|
4558 |
int base; |
|
4559 |
||
4560 |
if (!d->glcx) { // this can't happen unless we run out of mem |
|
4561 |
return 0; |
|
4562 |
} |
|
4563 |
||
4564 |
// always regenerate font disp. lists for pixmaps - hw accelerated |
|
4565 |
// contexts can't handle this otherwise |
|
4566 |
bool regenerate = d->glcx->deviceIsPixmap(); |
|
4567 |
#ifndef QT_NO_FONTCONFIG |
|
4568 |
// font color needs to be part of the font cache key when using |
|
4569 |
// antialiased fonts since one set of glyphs needs to be generated |
|
4570 |
// for each font color |
|
4571 |
QString color_key; |
|
4572 |
if (font.styleStrategy() != QFont::NoAntialias) { |
|
4573 |
GLfloat color[4]; |
|
4574 |
glGetFloatv(GL_CURRENT_COLOR, color); |
|
4575 |
color_key.sprintf("%f_%f_%f",color[0], color[1], color[2]); |
|
4576 |
} |
|
4577 |
QString key = font.key() + color_key + QString::number((int) regenerate); |
|
4578 |
#else |
|
4579 |
QString key = font.key() + QString::number((int) regenerate); |
|
4580 |
#endif |
|
4581 |
if (!regenerate && (d->displayListCache.find(key) != d->displayListCache.end())) { |
|
4582 |
base = d->displayListCache[key]; |
|
4583 |
} else { |
|
4584 |
int maxBase = listBase - 256; |
|
4585 |
QMap<QString,int>::ConstIterator it; |
|
4586 |
for (it = d->displayListCache.constBegin(); it != d->displayListCache.constEnd(); ++it) { |
|
4587 |
if (maxBase < it.value()) { |
|
4588 |
maxBase = it.value(); |
|
4589 |
} |
|
4590 |
} |
|
4591 |
maxBase += 256; |
|
4592 |
d->glcx->generateFontDisplayLists(font, maxBase); |
|
4593 |
d->displayListCache[key] = maxBase; |
|
4594 |
base = maxBase; |
|
4595 |
} |
|
4596 |
return base; |
|
4597 |
#else // QT_OPENGL_ES |
|
4598 |
Q_UNUSED(font); |
|
4599 |
Q_UNUSED(listBase); |
|
4600 |
return 0; |
|
4601 |
#endif |
|
4602 |
} |
|
4603 |
||
4604 |
#ifndef QT_OPENGL_ES |
|
4605 |
||
4606 |
static void qt_save_gl_state() |
|
4607 |
{ |
|
4608 |
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); |
|
4609 |
glPushAttrib(GL_ALL_ATTRIB_BITS); |
|
4610 |
glMatrixMode(GL_TEXTURE); |
|
4611 |
glPushMatrix(); |
|
4612 |
glLoadIdentity(); |
|
4613 |
glMatrixMode(GL_PROJECTION); |
|
4614 |
glPushMatrix(); |
|
4615 |
glMatrixMode(GL_MODELVIEW); |
|
4616 |
glPushMatrix(); |
|
4617 |
||
4618 |
glShadeModel(GL_FLAT); |
|
4619 |
glDisable(GL_CULL_FACE); |
|
4620 |
glDisable(GL_LIGHTING); |
|
4621 |
glDisable(GL_STENCIL_TEST); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4622 |
glDisable(GL_DEPTH_TEST); |
0 | 4623 |
glEnable(GL_BLEND); |
4624 |
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
4625 |
} |
|
4626 |
||
4627 |
static void qt_restore_gl_state() |
|
4628 |
{ |
|
4629 |
glMatrixMode(GL_TEXTURE); |
|
4630 |
glPopMatrix(); |
|
4631 |
glMatrixMode(GL_PROJECTION); |
|
4632 |
glPopMatrix(); |
|
4633 |
glMatrixMode(GL_MODELVIEW); |
|
4634 |
glPopMatrix(); |
|
4635 |
glPopAttrib(); |
|
4636 |
glPopClientAttrib(); |
|
4637 |
} |
|
4638 |
||
4639 |
static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, |
|
4640 |
const QFont &font) |
|
4641 |
{ |
|
4642 |
GLfloat color[4]; |
|
4643 |
glGetFloatv(GL_CURRENT_COLOR, &color[0]); |
|
4644 |
||
4645 |
QColor col; |
|
4646 |
col.setRgbF(color[0], color[1], color[2],color[3]); |
|
4647 |
QPen old_pen = p->pen(); |
|
4648 |
QFont old_font = p->font(); |
|
4649 |
||
4650 |
p->setPen(col); |
|
4651 |
p->setFont(font); |
|
4652 |
p->drawText(x, y, str); |
|
4653 |
||
4654 |
p->setPen(old_pen); |
|
4655 |
p->setFont(old_font); |
|
4656 |
} |
|
4657 |
||
4658 |
#endif // !QT_OPENGL_ES |
|
4659 |
||
4660 |
/*! |
|
4661 |
Renders the string \a str into the GL context of this widget. |
|
4662 |
||
4663 |
\a x and \a y are specified in window coordinates, with the origin |
|
4664 |
in the upper left-hand corner of the window. If \a font is not |
|
4665 |
specified, the currently set application font will be used to |
|
4666 |
render the string. To change the color of the rendered text you can |
|
4667 |
use the glColor() call (or the qglColor() convenience function), |
|
4668 |
just before the renderText() call. |
|
4669 |
||
4670 |
The \a listBase parameter is obsolete and will be removed in a |
|
4671 |
future version of Qt. |
|
4672 |
||
4673 |
\note This function clears the stencil buffer. |
|
4674 |
||
4675 |
\note This function is not supported on OpenGL/ES systems. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4676 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4677 |
\note This function temporarily disables depth-testing when the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4678 |
text is drawn. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4679 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4680 |
\note This function can only be used inside a |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4681 |
QPainter::beginNativePainting()/QPainter::endNativePainting() block |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4682 |
if the default OpenGL paint engine is QPaintEngine::OpenGL. To make |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4683 |
QPaintEngine::OpenGL the default GL engine, call |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4684 |
QGL::setPreferredPaintEngine(QPaintEngine::OpenGL) before the |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4685 |
QApplication constructor. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4686 |
|
0 | 4687 |
\l{Overpainting Example}{Overpaint} with QPainter::drawText() instead. |
4688 |
*/ |
|
4689 |
||
4690 |
void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, int) |
|
4691 |
{ |
|
4692 |
#ifndef QT_OPENGL_ES |
|
4693 |
Q_D(QGLWidget); |
|
4694 |
if (str.isEmpty() || !isValid()) |
|
4695 |
return; |
|
4696 |
||
4697 |
GLint view[4]; |
|
4698 |
bool use_scissor_testing = glIsEnabled(GL_SCISSOR_TEST); |
|
4699 |
if (!use_scissor_testing) |
|
4700 |
glGetIntegerv(GL_VIEWPORT, &view[0]); |
|
4701 |
int width = d->glcx->device()->width(); |
|
4702 |
int height = d->glcx->device()->height(); |
|
4703 |
bool auto_swap = autoBufferSwap(); |
|
4704 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4705 |
QPaintEngine::Type oldEngineType = qgl_engine_selector()->preferredPaintEngine(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4706 |
|
0 | 4707 |
QPaintEngine *engine = paintEngine(); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4708 |
if (engine && (oldEngineType == QPaintEngine::OpenGL2) && engine->isActive()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4709 |
qWarning("QGLWidget::renderText(): Calling renderText() while a GL 2 paint engine is" |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4710 |
" active on the same device is not allowed."); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4711 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4712 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4713 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4714 |
// this changes what paintEngine() returns |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4715 |
qgl_engine_selector()->setPreferredPaintEngine(QPaintEngine::OpenGL); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4716 |
engine = paintEngine(); |
0 | 4717 |
QPainter *p; |
4718 |
bool reuse_painter = false; |
|
4719 |
if (engine->isActive()) { |
|
4720 |
reuse_painter = true; |
|
4721 |
p = engine->painter(); |
|
4722 |
qt_save_gl_state(); |
|
4723 |
||
4724 |
glDisable(GL_DEPTH_TEST); |
|
4725 |
glViewport(0, 0, width, height); |
|
4726 |
glMatrixMode(GL_PROJECTION); |
|
4727 |
glLoadIdentity(); |
|
4728 |
glOrtho(0, width, height, 0, 0, 1); |
|
4729 |
glMatrixMode(GL_MODELVIEW); |
|
4730 |
||
4731 |
glLoadIdentity(); |
|
4732 |
} else { |
|
4733 |
setAutoBufferSwap(false); |
|
4734 |
// disable glClear() as a result of QPainter::begin() |
|
4735 |
d->disable_clear_on_painter_begin = true; |
|
4736 |
p = new QPainter(this); |
|
4737 |
} |
|
4738 |
||
4739 |
QRect viewport(view[0], view[1], view[2], view[3]); |
|
4740 |
if (!use_scissor_testing && viewport != rect()) { |
|
4741 |
// if the user hasn't set a scissor box, we set one that |
|
4742 |
// covers the current viewport |
|
4743 |
glScissor(view[0], view[1], view[2], view[3]); |
|
4744 |
glEnable(GL_SCISSOR_TEST); |
|
4745 |
} else if (use_scissor_testing) { |
|
4746 |
// use the scissor box set by the user |
|
4747 |
glEnable(GL_SCISSOR_TEST); |
|
4748 |
} |
|
4749 |
||
4750 |
qt_gl_draw_text(p, x, y, str, font); |
|
4751 |
||
4752 |
if (reuse_painter) { |
|
4753 |
qt_restore_gl_state(); |
|
4754 |
} else { |
|
4755 |
p->end(); |
|
4756 |
delete p; |
|
4757 |
setAutoBufferSwap(auto_swap); |
|
4758 |
d->disable_clear_on_painter_begin = false; |
|
4759 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4760 |
qgl_engine_selector()->setPreferredPaintEngine(oldEngineType); |
0 | 4761 |
#else // QT_OPENGL_ES |
4762 |
Q_UNUSED(x); |
|
4763 |
Q_UNUSED(y); |
|
4764 |
Q_UNUSED(str); |
|
4765 |
Q_UNUSED(font); |
|
4766 |
qWarning("QGLWidget::renderText is not supported under OpenGL/ES"); |
|
4767 |
#endif |
|
4768 |
} |
|
4769 |
||
4770 |
/*! \overload |
|
4771 |
||
4772 |
\a x, \a y and \a z are specified in scene or object coordinates |
|
4773 |
relative to the currently set projection and model matrices. This |
|
4774 |
can be useful if you want to annotate models with text labels and |
|
4775 |
have the labels move with the model as it is rotated etc. |
|
4776 |
||
4777 |
\note This function is not supported on OpenGL/ES systems. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4778 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4779 |
\note If depth testing is enabled before this function is called, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4780 |
then the drawn text will be depth-tested against the models that |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4781 |
have already been drawn in the scene. Use \c{glDisable(GL_DEPTH_TEST)} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4782 |
before calling this function to annotate the models without |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4783 |
depth-testing the text. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4784 |
|
0 | 4785 |
\l{Overpainting Example}{Overpaint} with QPainter::drawText() instead. |
4786 |
*/ |
|
4787 |
void QGLWidget::renderText(double x, double y, double z, const QString &str, const QFont &font, int) |
|
4788 |
{ |
|
4789 |
#ifndef QT_OPENGL_ES |
|
4790 |
Q_D(QGLWidget); |
|
4791 |
if (str.isEmpty() || !isValid()) |
|
4792 |
return; |
|
4793 |
||
4794 |
bool auto_swap = autoBufferSwap(); |
|
4795 |
||
4796 |
int width = d->glcx->device()->width(); |
|
4797 |
int height = d->glcx->device()->height(); |
|
4798 |
GLdouble model[4][4], proj[4][4]; |
|
4799 |
GLint view[4]; |
|
4800 |
glGetDoublev(GL_MODELVIEW_MATRIX, &model[0][0]); |
|
4801 |
glGetDoublev(GL_PROJECTION_MATRIX, &proj[0][0]); |
|
4802 |
glGetIntegerv(GL_VIEWPORT, &view[0]); |
|
4803 |
GLdouble win_x = 0, win_y = 0, win_z = 0; |
|
4804 |
qgluProject(x, y, z, &model[0][0], &proj[0][0], &view[0], |
|
4805 |
&win_x, &win_y, &win_z); |
|
4806 |
win_y = height - win_y; // y is inverted |
|
4807 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4808 |
QPaintEngine::Type oldEngineType = qgl_engine_selector()->preferredPaintEngine(); |
0 | 4809 |
QPaintEngine *engine = paintEngine(); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4810 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4811 |
if (engine && (oldEngineType == QPaintEngine::OpenGL2) && engine->isActive()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4812 |
qWarning("QGLWidget::renderText(): Calling renderText() while a GL 2 paint engine is" |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4813 |
" active on the same device is not allowed."); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4814 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4815 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4816 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4817 |
// this changes what paintEngine() returns |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4818 |
qgl_engine_selector()->setPreferredPaintEngine(QPaintEngine::OpenGL); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4819 |
engine = paintEngine(); |
0 | 4820 |
QPainter *p; |
4821 |
bool reuse_painter = false; |
|
4822 |
bool use_depth_testing = glIsEnabled(GL_DEPTH_TEST); |
|
4823 |
bool use_scissor_testing = glIsEnabled(GL_SCISSOR_TEST); |
|
4824 |
||
4825 |
if (engine->isActive()) { |
|
4826 |
reuse_painter = true; |
|
4827 |
p = engine->painter(); |
|
4828 |
qt_save_gl_state(); |
|
4829 |
} else { |
|
4830 |
setAutoBufferSwap(false); |
|
4831 |
// disable glClear() as a result of QPainter::begin() |
|
4832 |
d->disable_clear_on_painter_begin = true; |
|
4833 |
p = new QPainter(this); |
|
4834 |
} |
|
4835 |
||
4836 |
QRect viewport(view[0], view[1], view[2], view[3]); |
|
4837 |
if (!use_scissor_testing && viewport != rect()) { |
|
4838 |
glScissor(view[0], view[1], view[2], view[3]); |
|
4839 |
glEnable(GL_SCISSOR_TEST); |
|
4840 |
} else if (use_scissor_testing) { |
|
4841 |
glEnable(GL_SCISSOR_TEST); |
|
4842 |
} |
|
4843 |
glMatrixMode(GL_PROJECTION); |
|
4844 |
glLoadIdentity(); |
|
4845 |
glViewport(0, 0, width, height); |
|
4846 |
glOrtho(0, width, height, 0, 0, 1); |
|
4847 |
glMatrixMode(GL_MODELVIEW); |
|
4848 |
glLoadIdentity(); |
|
4849 |
glAlphaFunc(GL_GREATER, 0.0); |
|
4850 |
glEnable(GL_ALPHA_TEST); |
|
4851 |
if (use_depth_testing) |
|
4852 |
glEnable(GL_DEPTH_TEST); |
|
4853 |
glTranslated(0, 0, -win_z); |
|
4854 |
qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font); |
|
4855 |
||
4856 |
if (reuse_painter) { |
|
4857 |
qt_restore_gl_state(); |
|
4858 |
} else { |
|
4859 |
p->end(); |
|
4860 |
delete p; |
|
4861 |
setAutoBufferSwap(auto_swap); |
|
4862 |
d->disable_clear_on_painter_begin = false; |
|
4863 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4864 |
qgl_engine_selector()->setPreferredPaintEngine(oldEngineType); |
0 | 4865 |
#else // QT_OPENGL_ES |
4866 |
Q_UNUSED(x); |
|
4867 |
Q_UNUSED(y); |
|
4868 |
Q_UNUSED(z); |
|
4869 |
Q_UNUSED(str); |
|
4870 |
Q_UNUSED(font); |
|
4871 |
qWarning("QGLWidget::renderText is not supported under OpenGL/ES"); |
|
4872 |
#endif |
|
4873 |
} |
|
4874 |
||
4875 |
QGLFormat QGLWidget::format() const |
|
4876 |
{ |
|
4877 |
Q_D(const QGLWidget); |
|
4878 |
return d->glcx->format(); |
|
4879 |
} |
|
4880 |
||
4881 |
const QGLContext *QGLWidget::context() const |
|
4882 |
{ |
|
4883 |
Q_D(const QGLWidget); |
|
4884 |
return d->glcx; |
|
4885 |
} |
|
4886 |
||
4887 |
bool QGLWidget::doubleBuffer() const |
|
4888 |
{ |
|
4889 |
Q_D(const QGLWidget); |
|
4890 |
return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); |
|
4891 |
} |
|
4892 |
||
4893 |
void QGLWidget::setAutoBufferSwap(bool on) |
|
4894 |
{ |
|
4895 |
Q_D(QGLWidget); |
|
4896 |
d->autoSwap = on; |
|
4897 |
} |
|
4898 |
||
4899 |
bool QGLWidget::autoBufferSwap() const |
|
4900 |
{ |
|
4901 |
Q_D(const QGLWidget); |
|
4902 |
return d->autoSwap; |
|
4903 |
} |
|
4904 |
||
4905 |
/*! |
|
4906 |
Calls QGLContext:::bindTexture(\a image, \a target, \a format) on the currently |
|
4907 |
set context. |
|
4908 |
||
4909 |
\sa deleteTexture() |
|
4910 |
*/ |
|
4911 |
GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format) |
|
4912 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4913 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4914 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4915 |
|
0 | 4916 |
Q_D(QGLWidget); |
4917 |
return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); |
|
4918 |
} |
|
4919 |
||
4920 |
/*! |
|
4921 |
\overload |
|
4922 |
\since 4.6 |
|
4923 |
||
4924 |
The binding \a options are a set of options used to decide how to |
|
4925 |
bind the texture to the context. |
|
4926 |
*/ |
|
4927 |
GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options) |
|
4928 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4929 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4930 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4931 |
|
0 | 4932 |
Q_D(QGLWidget); |
4933 |
return d->glcx->bindTexture(image, target, format, options); |
|
4934 |
} |
|
4935 |
||
4936 |
||
4937 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
4938 |
/*! \internal */ |
|
4939 |
GLuint QGLWidget::bindTexture(const QImage &image, QMacCompatGLenum target, QMacCompatGLint format) |
|
4940 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4941 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4942 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4943 |
|
0 | 4944 |
Q_D(QGLWidget); |
4945 |
return d->glcx->bindTexture(image, GLenum(target), GLint(format), QGLContext::DefaultBindOption); |
|
4946 |
} |
|
4947 |
||
4948 |
GLuint QGLWidget::bindTexture(const QImage &image, QMacCompatGLenum target, QMacCompatGLint format, |
|
4949 |
QGLContext::BindOptions options) |
|
4950 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4951 |
if (image.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4952 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4953 |
|
0 | 4954 |
Q_D(QGLWidget); |
4955 |
return d->glcx->bindTexture(image, GLenum(target), GLint(format), options); |
|
4956 |
} |
|
4957 |
#endif |
|
4958 |
||
4959 |
/*! |
|
4960 |
Calls QGLContext:::bindTexture(\a pixmap, \a target, \a format) on the currently |
|
4961 |
set context. |
|
4962 |
||
4963 |
\sa deleteTexture() |
|
4964 |
*/ |
|
4965 |
GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) |
|
4966 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4967 |
if (pixmap.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4968 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4969 |
|
0 | 4970 |
Q_D(QGLWidget); |
4971 |
return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); |
|
4972 |
} |
|
4973 |
||
4974 |
/*! |
|
4975 |
\overload |
|
4976 |
\since 4.6 |
|
4977 |
||
4978 |
Generates and binds a 2D GL texture to the current context, based |
|
4979 |
on \a pixmap. The generated texture id is returned and can be used in |
|
4980 |
||
4981 |
The binding \a options are a set of options used to decide how to |
|
4982 |
bind the texture to the context. |
|
4983 |
*/ |
|
4984 |
GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, |
|
4985 |
QGLContext::BindOptions options) |
|
4986 |
{ |
|
4987 |
Q_D(QGLWidget); |
|
4988 |
return d->glcx->bindTexture(pixmap, target, format, options); |
|
4989 |
} |
|
4990 |
||
4991 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
4992 |
/*! \internal */ |
|
4993 |
GLuint QGLWidget::bindTexture(const QPixmap &pixmap, QMacCompatGLenum target, QMacCompatGLint format) |
|
4994 |
{ |
|
4995 |
Q_D(QGLWidget); |
|
4996 |
return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); |
|
4997 |
} |
|
4998 |
||
4999 |
GLuint QGLWidget::bindTexture(const QPixmap &pixmap, QMacCompatGLenum target, QMacCompatGLint format, |
|
5000 |
QGLContext::BindOptions options) |
|
5001 |
{ |
|
5002 |
Q_D(QGLWidget); |
|
5003 |
return d->glcx->bindTexture(pixmap, target, format, options); |
|
5004 |
} |
|
5005 |
#endif |
|
5006 |
||
5007 |
||
5008 |
/*! \overload |
|
5009 |
||
5010 |
Calls QGLContext::bindTexture(\a fileName) on the currently set context. |
|
5011 |
||
5012 |
\sa deleteTexture() |
|
5013 |
*/ |
|
5014 |
GLuint QGLWidget::bindTexture(const QString &fileName) |
|
5015 |
{ |
|
5016 |
Q_D(QGLWidget); |
|
5017 |
return d->glcx->bindTexture(fileName); |
|
5018 |
} |
|
5019 |
||
5020 |
/*! |
|
5021 |
Calls QGLContext::deleteTexture(\a id) on the currently set |
|
5022 |
context. |
|
5023 |
||
5024 |
\sa bindTexture() |
|
5025 |
*/ |
|
5026 |
void QGLWidget::deleteTexture(GLuint id) |
|
5027 |
{ |
|
5028 |
Q_D(QGLWidget); |
|
5029 |
d->glcx->deleteTexture(id); |
|
5030 |
} |
|
5031 |
||
5032 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
5033 |
/*! \internal */ |
|
5034 |
void QGLWidget::deleteTexture(QMacCompatGLuint id) |
|
5035 |
{ |
|
5036 |
Q_D(QGLWidget); |
|
5037 |
d->glcx->deleteTexture(GLuint(id)); |
|
5038 |
} |
|
5039 |
#endif |
|
5040 |
||
5041 |
/*! |
|
5042 |
\since 4.4 |
|
5043 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5044 |
Calls the corresponding QGLContext::drawTexture() with |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5045 |
\a target, \a textureId, and \a textureTarget for this |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5046 |
widget's context. |
0 | 5047 |
*/ |
5048 |
void QGLWidget::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) |
|
5049 |
{ |
|
5050 |
Q_D(QGLWidget); |
|
5051 |
d->glcx->drawTexture(target, textureId, textureTarget); |
|
5052 |
} |
|
5053 |
||
5054 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
5055 |
/*! \internal */ |
|
5056 |
void QGLWidget::drawTexture(const QRectF &target, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget) |
|
5057 |
{ |
|
5058 |
Q_D(QGLWidget); |
|
5059 |
d->glcx->drawTexture(target, GLint(textureId), GLenum(textureTarget)); |
|
5060 |
} |
|
5061 |
#endif |
|
5062 |
||
5063 |
/*! |
|
5064 |
\since 4.4 |
|
5065 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5066 |
Calls the corresponding QGLContext::drawTexture() with |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5067 |
\a point, \a textureId, and \a textureTarget for this |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5068 |
widget's context. |
0 | 5069 |
*/ |
5070 |
void QGLWidget::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) |
|
5071 |
{ |
|
5072 |
Q_D(QGLWidget); |
|
5073 |
d->glcx->drawTexture(point, textureId, textureTarget); |
|
5074 |
} |
|
5075 |
||
5076 |
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
5077 |
/*! \internal */ |
|
5078 |
void QGLWidget::drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget) |
|
5079 |
{ |
|
5080 |
Q_D(QGLWidget); |
|
5081 |
d->glcx->drawTexture(point, GLuint(textureId), GLenum(textureTarget)); |
|
5082 |
} |
|
5083 |
#endif |
|
5084 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5085 |
#ifndef QT_OPENGL_ES_1 |
0 | 5086 |
Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_2_engine) |
5087 |
#endif |
|
5088 |
||
5089 |
#ifndef QT_OPENGL_ES_2 |
|
5090 |
Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_gl_engine) |
|
5091 |
#endif |
|
5092 |
||
5093 |
Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine() |
|
5094 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5095 |
#if defined(QT_OPENGL_ES_1) |
0 | 5096 |
return qt_gl_engine(); |
5097 |
#elif defined(QT_OPENGL_ES_2) |
|
5098 |
return qt_gl_2_engine(); |
|
5099 |
#else |
|
5100 |
if (qt_gl_preferGL2Engine()) |
|
5101 |
return qt_gl_2_engine(); |
|
5102 |
else |
|
5103 |
return qt_gl_engine(); |
|
5104 |
#endif |
|
5105 |
} |
|
5106 |
||
5107 |
/*! |
|
5108 |
\internal |
|
5109 |
||
5110 |
Returns the GL widget's paint engine. This is normally a |
|
5111 |
QOpenGLPaintEngine. |
|
5112 |
*/ |
|
5113 |
QPaintEngine *QGLWidget::paintEngine() const |
|
5114 |
{ |
|
5115 |
return qt_qgl_paint_engine(); |
|
5116 |
} |
|
5117 |
||
5118 |
#ifdef QT3_SUPPORT |
|
5119 |
/*! |
|
5120 |
\overload |
|
5121 |
\obsolete |
|
5122 |
*/ |
|
5123 |
QGLWidget::QGLWidget(QWidget *parent, const char *name, |
|
5124 |
const QGLWidget* shareWidget, Qt::WindowFlags f) |
|
5125 |
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) |
|
5126 |
{ |
|
5127 |
Q_D(QGLWidget); |
|
5128 |
if (name) |
|
5129 |
setObjectName(QString::fromAscii(name)); |
|
5130 |
setAttribute(Qt::WA_PaintOnScreen); |
|
5131 |
setAttribute(Qt::WA_NoSystemBackground); |
|
5132 |
setAutoFillBackground(true); // for compatibility |
|
5133 |
d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget); |
|
5134 |
} |
|
5135 |
||
5136 |
/*! |
|
5137 |
\overload |
|
5138 |
\obsolete |
|
5139 |
*/ |
|
5140 |
QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, |
|
5141 |
const char *name, const QGLWidget* shareWidget, |
|
5142 |
Qt::WindowFlags f) |
|
5143 |
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) |
|
5144 |
{ |
|
5145 |
Q_D(QGLWidget); |
|
5146 |
if (name) |
|
5147 |
setObjectName(QString::fromAscii(name)); |
|
5148 |
setAttribute(Qt::WA_PaintOnScreen); |
|
5149 |
setAttribute(Qt::WA_NoSystemBackground); |
|
5150 |
setAutoFillBackground(true); // for compatibility |
|
5151 |
d->init(new QGLContext(format, this), shareWidget); |
|
5152 |
} |
|
5153 |
||
5154 |
/*! |
|
5155 |
\overload |
|
5156 |
\obsolete |
|
5157 |
*/ |
|
5158 |
QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, |
|
5159 |
const char *name, const QGLWidget *shareWidget, Qt::WindowFlags f) |
|
5160 |
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) |
|
5161 |
{ |
|
5162 |
Q_D(QGLWidget); |
|
5163 |
if (name) |
|
5164 |
setObjectName(QString::fromAscii(name)); |
|
5165 |
setAttribute(Qt::WA_PaintOnScreen); |
|
5166 |
setAttribute(Qt::WA_NoSystemBackground); |
|
5167 |
setAutoFillBackground(true); // for compatibility |
|
5168 |
d->init(context, shareWidget); |
|
5169 |
} |
|
5170 |
||
5171 |
#endif // QT3_SUPPORT |
|
5172 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5173 |
/* |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5174 |
Returns the GL extensions for the current context. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5175 |
*/ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5176 |
QGLExtensions::Extensions QGLExtensions::currentContextExtensions() |
0 | 5177 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5178 |
QGLExtensionMatcher extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5179 |
Extensions glExtensions; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5180 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5181 |
if (extensions.match("GL_ARB_texture_rectangle")) |
0 | 5182 |
glExtensions |= TextureRectangle; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5183 |
if (extensions.match("GL_ARB_multisample")) |
0 | 5184 |
glExtensions |= SampleBuffers; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5185 |
if (extensions.match("GL_SGIS_generate_mipmap")) |
0 | 5186 |
glExtensions |= GenerateMipmap; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5187 |
if (extensions.match("GL_ARB_texture_compression")) |
0 | 5188 |
glExtensions |= TextureCompression; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5189 |
if (extensions.match("GL_EXT_texture_compression_s3tc")) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5190 |
glExtensions |= DDSTextureCompression; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5191 |
if (extensions.match("GL_OES_compressed_ETC1_RGB8_texture")) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5192 |
glExtensions |= ETC1TextureCompression; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5193 |
if (extensions.match("GL_IMG_texture_compression_pvrtc")) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5194 |
glExtensions |= PVRTCTextureCompression; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5195 |
if (extensions.match("GL_ARB_fragment_program")) |
0 | 5196 |
glExtensions |= FragmentProgram; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5197 |
if (extensions.match("GL_ARB_fragment_shader")) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5198 |
glExtensions |= FragmentShader; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5199 |
if (extensions.match("GL_ARB_texture_mirrored_repeat")) |
0 | 5200 |
glExtensions |= MirroredRepeat; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5201 |
if (extensions.match("GL_EXT_framebuffer_object")) |
0 | 5202 |
glExtensions |= FramebufferObject; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5203 |
if (extensions.match("GL_EXT_stencil_two_side")) |
0 | 5204 |
glExtensions |= StencilTwoSide; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5205 |
if (extensions.match("GL_EXT_stencil_wrap")) |
0 | 5206 |
glExtensions |= StencilWrap; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5207 |
if (extensions.match("GL_EXT_packed_depth_stencil")) |
0 | 5208 |
glExtensions |= PackedDepthStencil; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5209 |
if (extensions.match("GL_NV_float_buffer")) |
0 | 5210 |
glExtensions |= NVFloatBuffer; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5211 |
if (extensions.match("GL_ARB_pixel_buffer_object")) |
0 | 5212 |
glExtensions |= PixelBufferObject; |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5213 |
if (extensions.match("GL_IMG_texture_format_BGRA8888")) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5214 |
glExtensions |= BGRATextureFormat; |
0 | 5215 |
#if defined(QT_OPENGL_ES_2) |
5216 |
glExtensions |= FramebufferObject; |
|
5217 |
glExtensions |= GenerateMipmap; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5218 |
glExtensions |= FragmentShader; |
0 | 5219 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5220 |
#if defined(QT_OPENGL_ES_1) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5221 |
if (extensions.match("GL_OES_framebuffer_object")) |
0 | 5222 |
glExtensions |= FramebufferObject; |
5223 |
#endif |
|
5224 |
#if defined(QT_OPENGL_ES) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5225 |
if (extensions.match("GL_OES_packed_depth_stencil")) |
0 | 5226 |
glExtensions |= PackedDepthStencil; |
5227 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5228 |
if (extensions.match("GL_ARB_framebuffer_object")) { |
0 | 5229 |
// ARB_framebuffer_object also includes EXT_framebuffer_blit. |
5230 |
glExtensions |= FramebufferObject; |
|
5231 |
glExtensions |= FramebufferBlit; |
|
5232 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5233 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5234 |
if (extensions.match("GL_EXT_framebuffer_blit")) |
0 | 5235 |
glExtensions |= FramebufferBlit; |
5236 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5237 |
if (extensions.match("GL_ARB_texture_non_power_of_two")) |
0 | 5238 |
glExtensions |= NPOTTextures; |
5239 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5240 |
if (extensions.match("GL_EXT_bgra")) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5241 |
glExtensions |= BGRATextureFormat; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5242 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5243 |
return glExtensions; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5244 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5245 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5246 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5247 |
class QGLDefaultExtensions |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5248 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5249 |
public: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5250 |
QGLDefaultExtensions() { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5251 |
QGLTemporaryContext tempContext; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5252 |
extensions = QGLExtensions::currentContextExtensions(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5253 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5254 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5255 |
QGLExtensions::Extensions extensions; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5256 |
}; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5257 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5258 |
Q_GLOBAL_STATIC(QGLDefaultExtensions, qtDefaultExtensions) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5259 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5260 |
/* |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5261 |
Returns the GL extensions for the current QGLContext. If there is no |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5262 |
current QGLContext, a default context will be created and the extensions |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5263 |
for that context will be returned instead. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5264 |
*/ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5265 |
QGLExtensions::Extensions QGLExtensions::glExtensions() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5266 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5267 |
Extensions extensionFlags = 0; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5268 |
QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5269 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5270 |
if (currentCtx && currentCtx->d_func()->extension_flags_cached) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5271 |
return currentCtx->d_func()->extension_flags; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5272 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5273 |
if (!currentCtx) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5274 |
extensionFlags = qtDefaultExtensions()->extensions; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5275 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5276 |
extensionFlags = currentContextExtensions(); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5277 |
currentCtx->d_func()->extension_flags_cached = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5278 |
currentCtx->d_func()->extension_flags = extensionFlags; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5279 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5280 |
return extensionFlags; |
0 | 5281 |
} |
5282 |
||
5283 |
/* |
|
5284 |
This is the shared initialization for all platforms. Called from QGLWidgetPrivate::init() |
|
5285 |
*/ |
|
5286 |
void QGLWidgetPrivate::initContext(QGLContext *context, const QGLWidget* shareWidget) |
|
5287 |
{ |
|
5288 |
Q_Q(QGLWidget); |
|
5289 |
||
5290 |
glDevice.setWidget(q); |
|
5291 |
||
5292 |
glcx = 0; |
|
5293 |
autoSwap = true; |
|
5294 |
||
5295 |
if (context && !context->device()) |
|
5296 |
context->setDevice(q); |
|
5297 |
q->setContext(context, shareWidget ? shareWidget->context() : 0); |
|
5298 |
||
5299 |
if (!glcx) |
|
5300 |
glcx = new QGLContext(QGLFormat::defaultFormat(), q); |
|
5301 |
} |
|
5302 |
||
5303 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) |
|
5304 |
Q_GLOBAL_STATIC(QString, qt_gl_lib_name) |
|
5305 |
||
5306 |
Q_OPENGL_EXPORT void qt_set_gl_library_name(const QString& name) |
|
5307 |
{ |
|
5308 |
qt_gl_lib_name()->operator=(name); |
|
5309 |
} |
|
5310 |
||
5311 |
Q_OPENGL_EXPORT const QString qt_gl_library_name() |
|
5312 |
{ |
|
5313 |
if (qt_gl_lib_name()->isNull()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5314 |
#ifdef Q_WS_MAC |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5315 |
return QLatin1String("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5316 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5317 |
# if defined(QT_OPENGL_ES_1) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5318 |
return QLatin1String("GLES_CM"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5319 |
# elif defined(QT_OPENGL_ES_2) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5320 |
return QLatin1String("GLESv2"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5321 |
# else |
0 | 5322 |
return QLatin1String("GL"); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5323 |
# endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
5324 |
#endif // defined Q_WS_MAC |
0 | 5325 |
} |
5326 |
return *qt_gl_lib_name(); |
|
5327 |
} |
|
5328 |
#endif |
|
5329 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5330 |
void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) { |
0 | 5331 |
Q_ASSERT(context && share); |
5332 |
if (context->d_ptr->group == share->d_ptr->group) |
|
5333 |
return; |
|
5334 |
||
5335 |
// Make sure 'context' is not already shared with another group of contexts. |
|
5336 |
Q_ASSERT(context->d_ptr->group->m_refs == 1); |
|
5337 |
||
5338 |
// Free 'context' group resources and make it use the same resources as 'share'. |
|
5339 |
QGLContextGroup *group = share->d_ptr->group; |
|
5340 |
delete context->d_ptr->group; |
|
5341 |
context->d_ptr->group = group; |
|
5342 |
group->m_refs.ref(); |
|
5343 |
||
5344 |
// Maintain a list of all the contexts in each group of sharing contexts. |
|
5345 |
// The list is empty if the "share" context wasn't sharing already. |
|
5346 |
if (group->m_shares.isEmpty()) |
|
5347 |
group->m_shares.append(share); |
|
5348 |
group->m_shares.append(context); |
|
5349 |
} |
|
5350 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5351 |
void QGLContextGroup::removeShare(const QGLContext *context) { |
0 | 5352 |
// Remove the context from the group. |
5353 |
QGLContextGroup *group = context->d_ptr->group; |
|
5354 |
if (group->m_shares.isEmpty()) |
|
5355 |
return; |
|
5356 |
group->m_shares.removeAll(context); |
|
5357 |
||
5358 |
// Update context group representative. |
|
5359 |
Q_ASSERT(group->m_shares.size() != 0); |
|
5360 |
if (group->m_context == context) |
|
5361 |
group->m_context = group->m_shares[0]; |
|
5362 |
||
5363 |
// If there is only one context left, then make the list empty. |
|
5364 |
if (group->m_shares.size() == 1) |
|
5365 |
group->m_shares.clear(); |
|
5366 |
} |
|
5367 |
||
5368 |
QGLContextResource::QGLContextResource(FreeFunc f) |
|
5369 |
: free(f), active(0) |
|
5370 |
{ |
|
5371 |
} |
|
5372 |
||
5373 |
QGLContextResource::~QGLContextResource() |
|
5374 |
{ |
|
5375 |
#ifndef QT_NO_DEBUG |
|
5376 |
if (active != 0) { |
|
5377 |
qWarning("QtOpenGL: Resources are still available at program shutdown.\n" |
|
5378 |
" This is possibly caused by a leaked QGLWidget, \n" |
|
5379 |
" QGLFramebufferObject or QGLPixelBuffer."); |
|
5380 |
} |
|
5381 |
#endif |
|
5382 |
} |
|
5383 |
||
5384 |
void QGLContextResource::insert(const QGLContext *key, void *value) |
|
5385 |
{ |
|
5386 |
QGLContextGroup *group = QGLContextPrivate::contextGroup(key); |
|
5387 |
Q_ASSERT(!group->m_resources.contains(this)); |
|
5388 |
group->m_resources.insert(this, value); |
|
5389 |
active.ref(); |
|
5390 |
} |
|
5391 |
||
5392 |
void *QGLContextResource::value(const QGLContext *key) |
|
5393 |
{ |
|
5394 |
QGLContextGroup *group = QGLContextPrivate::contextGroup(key); |
|
5395 |
return group->m_resources.value(this, 0); |
|
5396 |
} |
|
5397 |
||
5398 |
void QGLContextResource::cleanup(const QGLContext *ctx, void *value) |
|
5399 |
{ |
|
5400 |
QGLShareContextScope scope(ctx); |
|
5401 |
free(value); |
|
5402 |
active.deref(); |
|
5403 |
} |
|
5404 |
||
5405 |
void QGLContextGroup::cleanupResources(const QGLContext *ctx) |
|
5406 |
{ |
|
5407 |
// If there are still shares, then no cleanup to be done yet. |
|
5408 |
if (m_shares.size() > 1) |
|
5409 |
return; |
|
5410 |
||
5411 |
// Iterate over all resources and free each in turn. |
|
5412 |
QHash<QGLContextResource *, void *>::ConstIterator it; |
|
5413 |
for (it = m_resources.begin(); it != m_resources.end(); ++it) |
|
5414 |
it.key()->cleanup(ctx, it.value()); |
|
5415 |
} |
|
5416 |
||
5417 |
QGLSharedResourceGuard::~QGLSharedResourceGuard() |
|
5418 |
{ |
|
5419 |
if (m_group) |
|
5420 |
m_group->removeGuard(this); |
|
5421 |
} |
|
5422 |
||
5423 |
void QGLSharedResourceGuard::setContext(const QGLContext *context) |
|
5424 |
{ |
|
5425 |
if (m_group) |
|
5426 |
m_group->removeGuard(this); |
|
5427 |
if (context) { |
|
5428 |
m_group = QGLContextPrivate::contextGroup(context); |
|
5429 |
m_group->addGuard(this); |
|
5430 |
} else { |
|
5431 |
m_group = 0; |
|
5432 |
} |
|
5433 |
} |
|
5434 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5435 |
QSize QGLTexture::bindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5436 |
(const QString& fileName, const char *format) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5437 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5438 |
QFile file(fileName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5439 |
if (!file.open(QIODevice::ReadOnly)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5440 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5441 |
QByteArray contents = file.readAll(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5442 |
file.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5443 |
return bindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5444 |
(contents.constData(), contents.size(), format); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5445 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5446 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5447 |
// PVR header format for container files that store textures compressed |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5448 |
// with the ETC1, PVRTC2, and PVRTC4 encodings. Format information from the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5449 |
// PowerVR SDK at http://www.imgtec.com/powervr/insider/powervr-sdk.asp |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5450 |
// "PVRTexTool Reference Manual, version 1.11f". |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5451 |
struct PvrHeader |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5452 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5453 |
quint32 headerSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5454 |
quint32 height; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5455 |
quint32 width; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5456 |
quint32 mipMapCount; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5457 |
quint32 flags; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5458 |
quint32 dataSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5459 |
quint32 bitsPerPixel; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5460 |
quint32 redMask; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5461 |
quint32 greenMask; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5462 |
quint32 blueMask; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5463 |
quint32 alphaMask; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5464 |
quint32 magic; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5465 |
quint32 surfaceCount; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5466 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5467 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5468 |
#define PVR_MAGIC 0x21525650 // "PVR!" in little-endian |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5469 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5470 |
#define PVR_FORMAT_MASK 0x000000FF |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5471 |
#define PVR_FORMAT_PVRTC2 0x00000018 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5472 |
#define PVR_FORMAT_PVRTC4 0x00000019 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5473 |
#define PVR_FORMAT_ETC1 0x00000036 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5474 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5475 |
#define PVR_HAS_MIPMAPS 0x00000100 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5476 |
#define PVR_TWIDDLED 0x00000200 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5477 |
#define PVR_NORMAL_MAP 0x00000400 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5478 |
#define PVR_BORDER_ADDED 0x00000800 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5479 |
#define PVR_CUBE_MAP 0x00001000 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5480 |
#define PVR_FALSE_COLOR_MIPMAPS 0x00002000 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5481 |
#define PVR_VOLUME_TEXTURE 0x00004000 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5482 |
#define PVR_ALPHA_IN_TEXTURE 0x00008000 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5483 |
#define PVR_VERTICAL_FLIP 0x00010000 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5484 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5485 |
#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5486 |
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5487 |
#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5488 |
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5489 |
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5490 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5491 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5492 |
#ifndef GL_ETC1_RGB8_OES |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5493 |
#define GL_ETC1_RGB8_OES 0x8D64 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5494 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5495 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5496 |
bool QGLTexture::canBindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5497 |
(const char *buf, int len, const char *format, bool *hasAlpha) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5498 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5499 |
if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5500 |
// Compressed texture loading only supported on little-endian |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5501 |
// systems such as x86 and ARM at the moment. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5502 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5503 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5504 |
if (!format) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5505 |
// Auto-detect the format from the header. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5506 |
if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5507 |
*hasAlpha = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5508 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5509 |
} else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5510 |
const PvrHeader *pvrHeader = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5511 |
reinterpret_cast<const PvrHeader *>(buf); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5512 |
*hasAlpha = (pvrHeader->alphaMask != 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5513 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5514 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5515 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5516 |
// Validate the format against the header. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5517 |
if (!qstricmp(format, "DDS")) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5518 |
if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5519 |
*hasAlpha = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5520 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5521 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5522 |
} else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5523 |
if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5524 |
const PvrHeader *pvrHeader = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5525 |
reinterpret_cast<const PvrHeader *>(buf); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5526 |
*hasAlpha = (pvrHeader->alphaMask != 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5527 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5528 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5529 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5530 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5531 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5532 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5533 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5534 |
#define ctx QGLContext::currentContext() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5535 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5536 |
QSize QGLTexture::bindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5537 |
(const char *buf, int len, const char *format) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5538 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5539 |
if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5540 |
// Compressed texture loading only supported on little-endian |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5541 |
// systems such as x86 and ARM at the moment. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5542 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5543 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5544 |
#if !defined(QT_OPENGL_ES) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5545 |
if (!glCompressedTexImage2D) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5546 |
if (!(QGLExtensions::glExtensions() & QGLExtensions::TextureCompression)) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5547 |
qWarning("QGLContext::bindTexture(): The GL implementation does " |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5548 |
"not support texture compression extensions."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5549 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5550 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5551 |
glCompressedTexImage2D = (_glCompressedTexImage2DARB) ctx->getProcAddress(QLatin1String("glCompressedTexImage2DARB")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5552 |
if (!glCompressedTexImage2D) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5553 |
qWarning("QGLContext::bindTexture(): could not resolve " |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5554 |
"glCompressedTexImage2DARB."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5555 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5556 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5557 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5558 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5559 |
if (!format) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5560 |
// Auto-detect the format from the header. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5561 |
if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5562 |
return bindCompressedTextureDDS(buf, len); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5563 |
else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5564 |
return bindCompressedTexturePVR(buf, len); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5565 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5566 |
// Validate the format against the header. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5567 |
if (!qstricmp(format, "DDS")) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5568 |
if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5569 |
return bindCompressedTextureDDS(buf, len); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5570 |
} else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5571 |
if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5572 |
return bindCompressedTexturePVR(buf, len); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5573 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5574 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5575 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5576 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5577 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5578 |
QSize QGLTexture::bindCompressedTextureDDS(const char *buf, int len) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5579 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5580 |
// We only support 2D texture loading at present. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5581 |
if (target != GL_TEXTURE_2D) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5582 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5583 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5584 |
// Bail out if the necessary extension is not present. |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5585 |
if (!(QGLExtensions::glExtensions() & QGLExtensions::DDSTextureCompression)) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5586 |
qWarning("QGLContext::bindTexture(): DDS texture compression is not supported."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5587 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5588 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5589 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5590 |
const DDSFormat *ddsHeader = reinterpret_cast<const DDSFormat *>(buf + 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5591 |
if (!ddsHeader->dwLinearSize) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5592 |
qWarning("QGLContext::bindTexture(): DDS image size is not valid."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5593 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5594 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5595 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5596 |
int blockSize = 16; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5597 |
GLenum format; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5598 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5599 |
switch(ddsHeader->ddsPixelFormat.dwFourCC) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5600 |
case FOURCC_DXT1: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5601 |
format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5602 |
blockSize = 8; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5603 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5604 |
case FOURCC_DXT3: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5605 |
format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5606 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5607 |
case FOURCC_DXT5: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5608 |
format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5609 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5610 |
default: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5611 |
qWarning("QGLContext::bindTexture(): DDS image format not supported."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5612 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5613 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5614 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5615 |
const GLubyte *pixels = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5616 |
reinterpret_cast<const GLubyte *>(buf + ddsHeader->dwSize + 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5617 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5618 |
glGenTextures(1, &id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5619 |
glBindTexture(GL_TEXTURE_2D, id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5620 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5621 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5622 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5623 |
int size; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5624 |
int offset = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5625 |
int available = len - int(ddsHeader->dwSize + 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5626 |
int w = ddsHeader->dwWidth; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5627 |
int h = ddsHeader->dwHeight; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5628 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5629 |
// load mip-maps |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5630 |
for(int i = 0; i < (int) ddsHeader->dwMipMapCount; ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5631 |
if (w == 0) w = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5632 |
if (h == 0) h = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5633 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5634 |
size = ((w+3)/4) * ((h+3)/4) * blockSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5635 |
if (size > available) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5636 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5637 |
glCompressedTexImage2D(GL_TEXTURE_2D, i, format, w, h, 0, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5638 |
size, pixels + offset); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5639 |
offset += size; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5640 |
available -= size; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5641 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5642 |
// half size for each mip-map level |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5643 |
w = w/2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5644 |
h = h/2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5645 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5646 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5647 |
// DDS images are not inverted. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5648 |
options &= ~QGLContext::InvertedYBindOption; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5649 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5650 |
return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5651 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5652 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5653 |
QSize QGLTexture::bindCompressedTexturePVR(const char *buf, int len) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5654 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5655 |
// We only support 2D texture loading at present. Cube maps later. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5656 |
if (target != GL_TEXTURE_2D) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5657 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5658 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5659 |
// Determine which texture format we will be loading. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5660 |
const PvrHeader *pvrHeader = reinterpret_cast<const PvrHeader *>(buf); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5661 |
GLenum textureFormat; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5662 |
quint32 minWidth, minHeight; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5663 |
switch (pvrHeader->flags & PVR_FORMAT_MASK) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5664 |
case PVR_FORMAT_PVRTC2: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5665 |
if (pvrHeader->alphaMask) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5666 |
textureFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5667 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5668 |
textureFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5669 |
minWidth = 16; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5670 |
minHeight = 8; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5671 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5672 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5673 |
case PVR_FORMAT_PVRTC4: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5674 |
if (pvrHeader->alphaMask) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5675 |
textureFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5676 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5677 |
textureFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5678 |
minWidth = 8; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5679 |
minHeight = 8; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5680 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5681 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5682 |
case PVR_FORMAT_ETC1: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5683 |
textureFormat = GL_ETC1_RGB8_OES; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5684 |
minWidth = 4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5685 |
minHeight = 4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5686 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5687 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5688 |
default: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5689 |
qWarning("QGLContext::bindTexture(): PVR image format 0x%x not supported.", int(pvrHeader->flags & PVR_FORMAT_MASK)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5690 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5691 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5692 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5693 |
// Bail out if the necessary extension is not present. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5694 |
if (textureFormat == GL_ETC1_RGB8_OES) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5695 |
if (!(QGLExtensions::glExtensions() & |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5696 |
QGLExtensions::ETC1TextureCompression)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5697 |
qWarning("QGLContext::bindTexture(): ETC1 texture compression is not supported."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5698 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5699 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5700 |
} else { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5701 |
if (!(QGLExtensions::glExtensions() & |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5702 |
QGLExtensions::PVRTCTextureCompression)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5703 |
qWarning("QGLContext::bindTexture(): PVRTC texture compression is not supported."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5704 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5705 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5706 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5707 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5708 |
// Boundary check on the buffer size. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5709 |
quint32 bufferSize = pvrHeader->headerSize + pvrHeader->dataSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5710 |
if (bufferSize > quint32(len)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5711 |
qWarning("QGLContext::bindTexture(): PVR image size is not valid."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5712 |
return QSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5713 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5714 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5715 |
// Create the texture. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5716 |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5717 |
glGenTextures(1, &id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5718 |
glBindTexture(GL_TEXTURE_2D, id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5719 |
if (pvrHeader->mipMapCount) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5720 |
if ((options & QGLContext::LinearFilteringBindOption) != 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5721 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5722 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5723 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5724 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5725 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5726 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5727 |
} else if ((options & QGLContext::LinearFilteringBindOption) != 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5728 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5729 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5730 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5731 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5732 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5733 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5734 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5735 |
// Load the compressed mipmap levels. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5736 |
const GLubyte *buffer = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5737 |
reinterpret_cast<const GLubyte *>(buf + pvrHeader->headerSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5738 |
bufferSize = pvrHeader->dataSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5739 |
quint32 level = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5740 |
quint32 width = pvrHeader->width; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5741 |
quint32 height = pvrHeader->height; |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5742 |
while (bufferSize > 0 && level <= pvrHeader->mipMapCount) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5743 |
quint32 size = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5744 |
(qMax(width, minWidth) * qMax(height, minHeight) * |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5745 |
pvrHeader->bitsPerPixel) / 8; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5746 |
if (size > bufferSize) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5747 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5748 |
glCompressedTexImage2D(GL_TEXTURE_2D, GLint(level), textureFormat, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5749 |
GLsizei(width), GLsizei(height), 0, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5750 |
GLsizei(size), buffer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5751 |
width /= 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5752 |
height /= 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5753 |
buffer += size; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5754 |
++level; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5755 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5756 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5757 |
// Restore the default pixel alignment for later texture uploads. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5758 |
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5759 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5760 |
// Set the invert flag for the texture. The "vertical flip" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5761 |
// flag in PVR is the opposite sense to our sense of inversion. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5762 |
if ((pvrHeader->flags & PVR_VERTICAL_FLIP) != 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5763 |
options &= ~QGLContext::InvertedYBindOption; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5764 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5765 |
options |= QGLContext::InvertedYBindOption; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5766 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5767 |
return QSize(pvrHeader->width, pvrHeader->height); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5768 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5769 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5770 |
#undef ctx |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5771 |
|
0 | 5772 |
QT_END_NAMESPACE |