author | William Roberts <williamr@symbian.org> |
Thu, 22 Jul 2010 16:41:55 +0100 | |
branch | GCC_SURGE |
changeset 31 | 5daf16870df6 |
parent 30 | 5dc02b23752f |
child 33 | 3e2da88830cd |
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 |
#ifndef QGL_P_H |
|
43 |
#define QGL_P_H |
|
44 |
||
45 |
// |
|
46 |
// W A R N I N G |
|
47 |
// ------------- |
|
48 |
// |
|
49 |
// This file is not part of the Qt API. It exists for the convenience |
|
50 |
// of the QGLWidget class. This header file may change from |
|
51 |
// version to version without notice, or even be removed. |
|
52 |
// |
|
53 |
// We mean it. |
|
54 |
// |
|
55 |
||
56 |
#include "QtOpenGL/qgl.h" |
|
57 |
#include "QtOpenGL/qglcolormap.h" |
|
58 |
#include "QtCore/qmap.h" |
|
59 |
#include "QtCore/qthread.h" |
|
60 |
#include "QtCore/qthreadstorage.h" |
|
61 |
#include "QtCore/qhash.h" |
|
62 |
#include "QtCore/qatomic.h" |
|
63 |
#include "private/qwidget_p.h" |
|
64 |
#include "qcache.h" |
|
65 |
#include "qglpaintdevice_p.h" |
|
66 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
67 |
#ifndef QT_NO_EGL |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
68 |
#include <QtGui/private/qegl_p.h> |
0 | 69 |
#endif |
70 |
||
71 |
QT_BEGIN_NAMESPACE |
|
72 |
||
73 |
class QGLContext; |
|
74 |
class QGLOverlayWidget; |
|
75 |
class QPixmap; |
|
76 |
class QPixmapFilter; |
|
77 |
#ifdef Q_WS_MAC |
|
78 |
# ifdef qDebug |
|
79 |
# define old_qDebug qDebug |
|
80 |
# undef qDebug |
|
81 |
# endif |
|
82 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
83 |
#ifndef QT_MAC_USE_COCOA |
|
84 |
# include <AGL/agl.h> |
|
85 |
#endif |
|
86 |
QT_END_INCLUDE_NAMESPACE |
|
87 |
# ifdef old_qDebug |
|
88 |
# undef qDebug |
|
89 |
# define qDebug QT_QDEBUG_MACRO |
|
90 |
# undef old_qDebug |
|
91 |
# endif |
|
92 |
class QMacWindowChangeEvent; |
|
93 |
#endif |
|
94 |
||
95 |
#ifdef Q_WS_QWS |
|
96 |
class QWSGLWindowSurface; |
|
97 |
#endif |
|
98 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
99 |
#ifndef QT_NO_EGL |
0 | 100 |
class QEglContext; |
101 |
#endif |
|
102 |
||
103 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
104 |
#include <QtOpenGL/private/qglextensions_p.h> |
|
105 |
QT_END_INCLUDE_NAMESPACE |
|
106 |
||
107 |
class QGLFormatPrivate |
|
108 |
{ |
|
109 |
public: |
|
110 |
QGLFormatPrivate() |
|
111 |
: ref(1) |
|
112 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
113 |
opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
114 |
| QGL::StencilBuffer | QGL::DeprecatedFunctions; |
0 | 115 |
pln = 0; |
116 |
depthSize = accumSize = stencilSize = redSize = greenSize = blueSize = alphaSize = -1; |
|
117 |
numSamples = -1; |
|
118 |
swapInterval = -1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
119 |
majorVersion = 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
120 |
minorVersion = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
121 |
profile = QGLFormat::NoProfile; |
0 | 122 |
} |
123 |
QGLFormatPrivate(const QGLFormatPrivate *other) |
|
124 |
: ref(1), |
|
125 |
opts(other->opts), |
|
126 |
pln(other->pln), |
|
127 |
depthSize(other->depthSize), |
|
128 |
accumSize(other->accumSize), |
|
129 |
stencilSize(other->stencilSize), |
|
130 |
redSize(other->redSize), |
|
131 |
greenSize(other->greenSize), |
|
132 |
blueSize(other->blueSize), |
|
133 |
alphaSize(other->alphaSize), |
|
134 |
numSamples(other->numSamples), |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
135 |
swapInterval(other->swapInterval), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
136 |
majorVersion(other->majorVersion), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
137 |
minorVersion(other->minorVersion), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
138 |
profile(other->profile) |
0 | 139 |
{ |
140 |
} |
|
141 |
QAtomicInt ref; |
|
142 |
QGL::FormatOptions opts; |
|
143 |
int pln; |
|
144 |
int depthSize; |
|
145 |
int accumSize; |
|
146 |
int stencilSize; |
|
147 |
int redSize; |
|
148 |
int greenSize; |
|
149 |
int blueSize; |
|
150 |
int alphaSize; |
|
151 |
int numSamples; |
|
152 |
int swapInterval; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
153 |
int majorVersion; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
154 |
int minorVersion; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
155 |
QGLFormat::OpenGLContextProfile profile; |
0 | 156 |
}; |
157 |
||
158 |
class QGLWidgetPrivate : public QWidgetPrivate |
|
159 |
{ |
|
160 |
Q_DECLARE_PUBLIC(QGLWidget) |
|
161 |
public: |
|
162 |
QGLWidgetPrivate() : QWidgetPrivate() |
|
163 |
, disable_clear_on_painter_begin(false) |
|
164 |
#ifdef Q_WS_QWS |
|
165 |
, wsurf(0) |
|
166 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
167 |
#if defined(Q_WS_X11) && !defined(QT_NO_EGL) |
0 | 168 |
, eglSurfaceWindowId(0) |
169 |
#endif |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
170 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
171 |
isGLWidget = 1; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
172 |
} |
0 | 173 |
|
174 |
~QGLWidgetPrivate() {} |
|
175 |
||
176 |
void init(QGLContext *context, const QGLWidget* shareWidget); |
|
177 |
void initContext(QGLContext *context, const QGLWidget* shareWidget); |
|
178 |
bool renderCxPm(QPixmap *pixmap); |
|
179 |
void cleanupColormaps(); |
|
180 |
||
181 |
QGLContext *glcx; |
|
182 |
QGLWidgetGLPaintDevice glDevice; |
|
183 |
bool autoSwap; |
|
184 |
||
185 |
QGLColormap cmap; |
|
186 |
#ifndef QT_OPENGL_ES |
|
187 |
QMap<QString, int> displayListCache; |
|
188 |
#endif |
|
189 |
||
190 |
bool disable_clear_on_painter_begin; |
|
191 |
||
192 |
#if defined(Q_WS_WIN) |
|
193 |
void updateColormap(); |
|
194 |
QGLContext *olcx; |
|
195 |
#elif defined(Q_WS_X11) |
|
196 |
QGLOverlayWidget *olw; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
197 |
#ifndef QT_NO_EGL |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
198 |
void recreateEglSurface(); |
0 | 199 |
WId eglSurfaceWindowId; |
200 |
#endif |
|
201 |
#elif defined(Q_WS_MAC) |
|
202 |
QGLContext *olcx; |
|
203 |
void updatePaintDevice(); |
|
204 |
#elif defined(Q_WS_QWS) |
|
205 |
QWSGLWindowSurface *wsurf; |
|
206 |
#endif |
|
207 |
}; |
|
208 |
||
209 |
class QGLContextResource; |
|
210 |
class QGLSharedResourceGuard; |
|
211 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
typedef QHash<QString, GLuint> QGLDDSCache; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
|
0 | 214 |
// QGLContextPrivate has the responsibility of creating context groups. |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
215 |
// QGLContextPrivate maintains the reference counter and destroys |
0 | 216 |
// context groups when needed. |
217 |
class QGLContextGroup |
|
218 |
{ |
|
219 |
public: |
|
220 |
~QGLContextGroup(); |
|
221 |
||
222 |
QGLExtensionFuncs &extensionFuncs() {return m_extensionFuncs;} |
|
223 |
const QGLContext *context() const {return m_context;} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
bool isSharing() const { return m_shares.size() >= 2; } |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
225 |
QList<const QGLContext *> shares() const { return m_shares; } |
0 | 226 |
|
227 |
void addGuard(QGLSharedResourceGuard *guard); |
|
228 |
void removeGuard(QGLSharedResourceGuard *guard); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
229 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
230 |
static void addShare(const QGLContext *context, const QGLContext *share); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
231 |
static void removeShare(const QGLContext *context); |
0 | 232 |
private: |
233 |
QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { } |
|
234 |
||
235 |
QGLExtensionFuncs m_extensionFuncs; |
|
236 |
const QGLContext *m_context; // context group's representative |
|
237 |
QList<const QGLContext *> m_shares; |
|
238 |
QHash<QGLContextResource *, void *> m_resources; |
|
239 |
QGLSharedResourceGuard *m_guards; // double-linked list of active guards. |
|
240 |
QAtomicInt m_refs; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
QGLDDSCache m_dds_cache; |
0 | 242 |
|
243 |
void cleanupResources(const QGLContext *ctx); |
|
244 |
||
245 |
friend class QGLContext; |
|
246 |
friend class QGLContextPrivate; |
|
247 |
friend class QGLContextResource; |
|
248 |
}; |
|
249 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
250 |
// Get the context that resources for "ctx" will transfer to once |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
251 |
// "ctx" is destroyed. Returns null if nothing is sharing with ctx. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
252 |
Q_OPENGL_EXPORT const QGLContext *qt_gl_transfer_context(const QGLContext *); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
253 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
254 |
// GL extension definitions |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
255 |
class QGLExtensions { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
256 |
public: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
257 |
enum Extension { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
258 |
TextureRectangle = 0x00000001, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
259 |
SampleBuffers = 0x00000002, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
260 |
GenerateMipmap = 0x00000004, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
261 |
TextureCompression = 0x00000008, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
262 |
FragmentProgram = 0x00000010, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
263 |
MirroredRepeat = 0x00000020, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
264 |
FramebufferObject = 0x00000040, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
265 |
StencilTwoSide = 0x00000080, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
266 |
StencilWrap = 0x00000100, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
267 |
PackedDepthStencil = 0x00000200, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
268 |
NVFloatBuffer = 0x00000400, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
269 |
PixelBufferObject = 0x00000800, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
270 |
FramebufferBlit = 0x00001000, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
271 |
NPOTTextures = 0x00002000, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
272 |
BGRATextureFormat = 0x00004000, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
273 |
DDSTextureCompression = 0x00008000, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
274 |
ETC1TextureCompression = 0x00010000, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
275 |
PVRTCTextureCompression = 0x00020000, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
276 |
FragmentShader = 0x00040000 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
277 |
}; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
278 |
Q_DECLARE_FLAGS(Extensions, Extension) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
279 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
280 |
static Extensions glExtensions(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
281 |
static Extensions currentContextExtensions(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
282 |
}; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
283 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
284 |
/* |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
285 |
QGLTemporaryContext - the main objective of this class is to have a way of |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
286 |
creating a GL context and making it current, without going via QGLWidget |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
287 |
and friends. At certain points during GL initialization we need a current |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
288 |
context in order decide what GL features are available, and to resolve GL |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
289 |
extensions. Having a light-weight way of creating such a context saves |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
290 |
initial application startup time, and it doesn't wind up creating recursive |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
291 |
conflicts. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
292 |
The class currently uses a private d pointer to hide the platform specific |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
293 |
types. This could possibly been done inline with #ifdef'ery, but it causes |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
294 |
major headaches on e.g. X11 due to namespace pollution. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
295 |
*/ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
296 |
class QGLTemporaryContextPrivate; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
297 |
class QGLTemporaryContext { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
298 |
public: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
299 |
QGLTemporaryContext(bool directRendering = true, QWidget *parent = 0); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
300 |
~QGLTemporaryContext(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
301 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
302 |
private: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
303 |
QScopedPointer<QGLTemporaryContextPrivate> d; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
304 |
}; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
305 |
|
0 | 306 |
class QGLTexture; |
307 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
308 |
// This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
309 |
// all the GL2 engine uses: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
310 |
#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT 3 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
311 |
|
0 | 312 |
class QGLContextPrivate |
313 |
{ |
|
314 |
Q_DECLARE_PUBLIC(QGLContext) |
|
315 |
public: |
|
316 |
explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);} |
|
317 |
~QGLContextPrivate(); |
|
318 |
QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, |
|
319 |
QGLContext::BindOptions options); |
|
320 |
QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, const qint64 key, |
|
321 |
QGLContext::BindOptions options); |
|
322 |
QGLTexture *bindTexture(const QPixmap &pixmap, GLenum target, GLint format, |
|
323 |
QGLContext::BindOptions options); |
|
324 |
QGLTexture *textureCacheLookup(const qint64 key, GLenum target); |
|
325 |
void init(QPaintDevice *dev, const QGLFormat &format); |
|
326 |
QImage convertToGLFormat(const QImage &image, bool force_premul, GLenum texture_format); |
|
327 |
int maxTextureSize(); |
|
328 |
||
329 |
void cleanup(); |
|
330 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
331 |
void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
332 |
void syncGlState(); // Makes sure the GL context's state is what we think it is |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
333 |
|
0 | 334 |
#if defined(Q_WS_WIN) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
335 |
void updateFormatVersion(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
336 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
337 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
338 |
#if defined(Q_WS_WIN) |
0 | 339 |
HGLRC rc; |
340 |
HDC dc; |
|
341 |
WId win; |
|
342 |
int pixelFormatId; |
|
343 |
QGLCmap* cmap; |
|
344 |
HBITMAP hbitmap; |
|
345 |
HDC hbitmap_hdc; |
|
346 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
347 |
#ifndef QT_NO_EGL |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
348 |
uint ownsEglContext : 1; |
0 | 349 |
QEglContext *eglContext; |
350 |
EGLSurface eglSurface; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
void destroyEglSurfaceForDevice(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
352 |
EGLSurface eglSurfaceForDevice() const; |
0 | 353 |
#elif defined(Q_WS_X11) || defined(Q_WS_MAC) |
354 |
void* cx; |
|
355 |
#endif |
|
356 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC) |
|
357 |
void* vi; |
|
358 |
#endif |
|
359 |
#if defined(Q_WS_X11) |
|
360 |
void* pbuf; |
|
361 |
quint32 gpm; |
|
362 |
int screen; |
|
363 |
QHash<QPixmapData*, QPixmap> boundPixmaps; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
364 |
QGLTexture *bindTextureFromNativePixmap(QPixmap*, const qint64 key, |
0 | 365 |
QGLContext::BindOptions options); |
366 |
static void destroyGlSurfaceForPixmap(QPixmapData*); |
|
367 |
static void unbindPixmapFromTexture(QPixmapData*); |
|
368 |
#endif |
|
369 |
#if defined(Q_WS_MAC) |
|
370 |
bool update; |
|
371 |
void *tryFormat(const QGLFormat &format); |
|
372 |
void clearDrawable(); |
|
373 |
#endif |
|
374 |
QGLFormat glFormat; |
|
375 |
QGLFormat reqFormat; |
|
376 |
GLuint fbo; |
|
377 |
||
378 |
uint valid : 1; |
|
379 |
uint sharing : 1; |
|
380 |
uint initDone : 1; |
|
381 |
uint crWin : 1; |
|
382 |
uint internal_context : 1; |
|
383 |
uint version_flags_cached : 1; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
384 |
uint extension_flags_cached : 1; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
385 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
386 |
// workarounds for driver/hw bugs on different platforms |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
387 |
uint workaround_needsFullClearOnEveryFrame : 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
388 |
uint workaround_brokenFBOReadBack : 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
389 |
uint workaroundsCached : 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
390 |
|
0 | 391 |
QPaintDevice *paintDevice; |
392 |
QColor transpColor; |
|
393 |
QGLContext *q_ptr; |
|
394 |
QGLFormat::OpenGLVersionFlags version_flags; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
395 |
QGLExtensions::Extensions extension_flags; |
0 | 396 |
|
397 |
QGLContextGroup *group; |
|
398 |
GLint max_texture_size; |
|
399 |
||
400 |
GLuint current_fbo; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
GLuint default_fbo; |
0 | 402 |
QPaintEngine *active_engine; |
403 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
404 |
bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
405 |
|
0 | 406 |
static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; } |
407 |
||
408 |
#ifdef Q_WS_WIN |
|
409 |
static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); } |
|
410 |
#endif |
|
411 |
||
412 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) |
|
413 |
static QGLExtensionFuncs qt_extensionFuncs; |
|
414 |
static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; } |
|
415 |
#endif |
|
416 |
||
417 |
static void setCurrentContext(QGLContext *context); |
|
418 |
}; |
|
419 |
||
420 |
// ### make QGLContext a QObject in 5.0 and remove the proxy stuff |
|
421 |
class Q_OPENGL_EXPORT QGLSignalProxy : public QObject |
|
422 |
{ |
|
423 |
Q_OBJECT |
|
424 |
public: |
|
425 |
QGLSignalProxy() : QObject() {} |
|
426 |
void emitAboutToDestroyContext(const QGLContext *context) { |
|
427 |
emit aboutToDestroyContext(context); |
|
428 |
} |
|
429 |
static QGLSignalProxy *instance(); |
|
430 |
Q_SIGNALS: |
|
431 |
void aboutToDestroyContext(const QGLContext *context); |
|
432 |
}; |
|
433 |
||
434 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions) |
|
435 |
||
436 |
// Temporarily make a context current if not already current or |
|
437 |
// shared with the current contex. The previous context is made |
|
438 |
// current when the object goes out of scope. |
|
439 |
class Q_OPENGL_EXPORT QGLShareContextScope |
|
440 |
{ |
|
441 |
public: |
|
442 |
QGLShareContextScope(const QGLContext *ctx) |
|
443 |
: m_oldContext(0) |
|
444 |
{ |
|
445 |
QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext()); |
|
446 |
if (currentContext != ctx && !QGLContext::areSharing(ctx, currentContext)) { |
|
447 |
m_oldContext = currentContext; |
|
448 |
m_ctx = const_cast<QGLContext *>(ctx); |
|
449 |
m_ctx->makeCurrent(); |
|
450 |
} else { |
|
451 |
m_ctx = currentContext; |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
operator QGLContext *() |
|
456 |
{ |
|
457 |
return m_ctx; |
|
458 |
} |
|
459 |
||
460 |
QGLContext *operator->() |
|
461 |
{ |
|
462 |
return m_ctx; |
|
463 |
} |
|
464 |
||
465 |
~QGLShareContextScope() |
|
466 |
{ |
|
467 |
if (m_oldContext) |
|
468 |
m_oldContext->makeCurrent(); |
|
469 |
} |
|
470 |
||
471 |
private: |
|
472 |
QGLContext *m_oldContext; |
|
473 |
QGLContext *m_ctx; |
|
474 |
}; |
|
475 |
||
476 |
class QGLTexture { |
|
477 |
public: |
|
478 |
QGLTexture(QGLContext *ctx = 0, GLuint tx_id = 0, GLenum tx_target = GL_TEXTURE_2D, |
|
479 |
QGLContext::BindOptions opt = QGLContext::DefaultBindOption) |
|
480 |
: context(ctx), |
|
481 |
id(tx_id), |
|
482 |
target(tx_target), |
|
483 |
options(opt) |
|
484 |
#if defined(Q_WS_X11) |
|
485 |
, boundPixmap(0) |
|
486 |
#endif |
|
487 |
{} |
|
488 |
||
489 |
~QGLTexture() { |
|
490 |
if (options & QGLContext::MemoryManagedBindOption) { |
|
491 |
Q_ASSERT(context); |
|
492 |
QGLShareContextScope scope(context); |
|
493 |
#if defined(Q_WS_X11) |
|
494 |
// Although glXReleaseTexImage is a glX call, it must be called while there |
|
495 |
// is a current context - the context the pixmap was bound to a texture in. |
|
496 |
// Otherwise the release doesn't do anything and you get BadDrawable errors |
|
497 |
// when you come to delete the context. |
|
498 |
if (boundPixmap) |
|
499 |
QGLContextPrivate::unbindPixmapFromTexture(boundPixmap); |
|
500 |
#endif |
|
501 |
glDeleteTextures(1, &id); |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
QGLContext *context; |
|
506 |
GLuint id; |
|
507 |
GLenum target; |
|
508 |
||
509 |
QGLContext::BindOptions options; |
|
510 |
||
511 |
#if defined(Q_WS_X11) |
|
512 |
QPixmapData* boundPixmap; |
|
513 |
#endif |
|
514 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
515 |
bool canBindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
(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
|
517 |
QSize bindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
(const QString& fileName, const char *format = 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
QSize bindCompressedTexture |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
(const char *buf, int len, const char *format = 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
521 |
QSize bindCompressedTextureDDS(const char *buf, int len); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
QSize bindCompressedTexturePVR(const char *buf, int len); |
0 | 523 |
}; |
524 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
525 |
class Q_AUTOTEST_EXPORT QGLTextureCache { |
0 | 526 |
public: |
527 |
QGLTextureCache(); |
|
528 |
~QGLTextureCache(); |
|
529 |
||
530 |
void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
531 |
inline void remove(quint64 key); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
532 |
inline int size(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
533 |
inline void setMaxCost(int newMax); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
534 |
inline int maxCost(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
535 |
inline QGLTexture* getTexture(quint64 key); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
536 |
|
0 | 537 |
bool remove(QGLContext *ctx, GLuint textureId); |
538 |
void removeContextTextures(QGLContext *ctx); |
|
539 |
static QGLTextureCache *instance(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
540 |
static void cleanupTexturesForCacheKey(qint64 cacheKey); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
541 |
static void cleanupTexturesForPixampData(QPixmapData* pixmap); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
542 |
static void cleanupBeforePixmapDestruction(QPixmapData* pixmap); |
0 | 543 |
|
544 |
private: |
|
545 |
QCache<qint64, QGLTexture> m_cache; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
546 |
QReadWriteLock m_lock; |
0 | 547 |
}; |
548 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
549 |
int QGLTextureCache::size() { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
550 |
QReadLocker locker(&m_lock); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
551 |
return m_cache.size(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
552 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
553 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
554 |
void QGLTextureCache::setMaxCost(int newMax) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
555 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
556 |
QWriteLocker locker(&m_lock); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
557 |
m_cache.setMaxCost(newMax); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
558 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
559 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
560 |
int QGLTextureCache::maxCost() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
561 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
562 |
QReadLocker locker(&m_lock); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
563 |
return m_cache.maxCost(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
564 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
565 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
566 |
QGLTexture* QGLTextureCache::getTexture(quint64 key) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
567 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
568 |
QReadLocker locker(&m_lock); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
569 |
return m_cache.object(key); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
570 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
571 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
572 |
void QGLTextureCache::remove(quint64 key) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
573 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
574 |
QWriteLocker locker(&m_lock); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
575 |
m_cache.remove(key); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
576 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
577 |
|
0 | 578 |
|
579 |
extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine(); |
|
580 |
||
581 |
bool qt_gl_preferGL2Engine(); |
|
582 |
||
583 |
inline GLenum qt_gl_preferredTextureFormat() |
|
584 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
585 |
return (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
? GL_BGRA : GL_RGBA; |
0 | 587 |
} |
588 |
||
589 |
inline GLenum qt_gl_preferredTextureTarget() |
|
590 |
{ |
|
591 |
#if defined(QT_OPENGL_ES_2) |
|
592 |
return GL_TEXTURE_2D; |
|
593 |
#else |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
594 |
return (QGLExtensions::glExtensions() & QGLExtensions::TextureRectangle) |
0 | 595 |
&& !qt_gl_preferGL2Engine() |
596 |
? GL_TEXTURE_RECTANGLE_NV |
|
597 |
: GL_TEXTURE_2D; |
|
598 |
#endif |
|
599 |
} |
|
600 |
||
601 |
// One resource per group of shared contexts. |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
602 |
class Q_OPENGL_EXPORT QGLContextResource |
0 | 603 |
{ |
604 |
public: |
|
605 |
typedef void (*FreeFunc)(void *); |
|
606 |
QGLContextResource(FreeFunc f); |
|
607 |
~QGLContextResource(); |
|
608 |
// Set resource 'value' for 'key' and all its shared contexts. |
|
609 |
void insert(const QGLContext *key, void *value); |
|
610 |
// Return resource for 'key' or a shared context. |
|
611 |
void *value(const QGLContext *key); |
|
612 |
// Cleanup 'value' in response to a context group being destroyed. |
|
613 |
void cleanup(const QGLContext *ctx, void *value); |
|
614 |
private: |
|
615 |
FreeFunc free; |
|
616 |
QAtomicInt active; |
|
617 |
}; |
|
618 |
||
619 |
// Put a guard around a GL object identifier and its context. |
|
620 |
// When the context goes away, a shared context will be used |
|
621 |
// in its place. If there are no more shared contexts, then |
|
622 |
// the identifier is returned as zero - it is assumed that the |
|
623 |
// context destruction cleaned up the identifier in this case. |
|
624 |
class Q_OPENGL_EXPORT QGLSharedResourceGuard |
|
625 |
{ |
|
626 |
public: |
|
627 |
QGLSharedResourceGuard(const QGLContext *context) |
|
628 |
: m_group(0), m_id(0), m_next(0), m_prev(0) |
|
629 |
{ |
|
630 |
setContext(context); |
|
631 |
} |
|
632 |
QGLSharedResourceGuard(const QGLContext *context, GLuint id) |
|
633 |
: m_group(0), m_id(id), m_next(0), m_prev(0) |
|
634 |
{ |
|
635 |
setContext(context); |
|
636 |
} |
|
637 |
~QGLSharedResourceGuard(); |
|
638 |
||
639 |
const QGLContext *context() const |
|
640 |
{ |
|
641 |
return m_group ? m_group->context() : 0; |
|
642 |
} |
|
643 |
||
644 |
void setContext(const QGLContext *context); |
|
645 |
||
646 |
GLuint id() const |
|
647 |
{ |
|
648 |
return m_id; |
|
649 |
} |
|
650 |
||
651 |
void setId(GLuint id) |
|
652 |
{ |
|
653 |
m_id = id; |
|
654 |
} |
|
655 |
||
656 |
private: |
|
657 |
QGLContextGroup *m_group; |
|
658 |
GLuint m_id; |
|
659 |
QGLSharedResourceGuard *m_next; |
|
660 |
QGLSharedResourceGuard *m_prev; |
|
661 |
||
662 |
friend class QGLContextGroup; |
|
663 |
}; |
|
664 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
665 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
666 |
// This class can be used to match GL extensions without doing any mallocs. The |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
667 |
// class assumes that the GL extension string ends with a space character, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
668 |
// which it should do on all conformant platforms. Create the object and pass |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
669 |
// in a pointer to the extension string, then call match() on each extension |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
670 |
// that should be matched. The match() function takes the extension name |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
671 |
// *without* the terminating space character as input. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
672 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
673 |
class QGLExtensionMatcher |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
674 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
675 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
676 |
QGLExtensionMatcher(const char *str) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
677 |
: gl_extensions(str), gl_extensions_length(qstrlen(str)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
678 |
{} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
679 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
680 |
bool match(const char *str) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
681 |
int str_length = qstrlen(str); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
682 |
const char *extensions = gl_extensions; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
int extensions_length = gl_extensions_length; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
684 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
685 |
while (1) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
// the total length that needs to be matched is the str_length + |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
// the space character that terminates the extension name |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
if (extensions_length < str_length + 1) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
690 |
if (qstrncmp(extensions, str, str_length) == 0 && extensions[str_length] == ' ') |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
692 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
693 |
int split_pos = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
694 |
while (split_pos < extensions_length && extensions[split_pos] != ' ') |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
695 |
++split_pos; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
++split_pos; // added for the terminating space character |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
697 |
extensions += split_pos; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
698 |
extensions_length -= split_pos; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
699 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
700 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
701 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
702 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
703 |
private: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
const char *gl_extensions; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
int gl_extensions_length; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
|
0 | 708 |
QT_END_NAMESPACE |
709 |
||
710 |
#endif // QGL_P_H |