0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
|
|
67 |
#ifndef QT_OPENGL_ES_1_CL
|
|
68 |
#define q_vertexType float
|
|
69 |
#define q_vertexTypeEnum GL_FLOAT
|
|
70 |
#define f2vt(f) (f)
|
|
71 |
#define vt2f(x) (x)
|
|
72 |
#define i2vt(i) (float(i))
|
|
73 |
#else
|
|
74 |
#define FLOAT2X(f) (int( (f) * (65536)))
|
|
75 |
#define X2FLOAT(x) (float(x) / 65536.0f)
|
|
76 |
#define f2vt(f) FLOAT2X(f)
|
|
77 |
#define i2vt(i) ((i)*65536)
|
|
78 |
#define vt2f(x) X2FLOAT(x)
|
|
79 |
#define q_vertexType GLfixed
|
|
80 |
#define q_vertexTypeEnum GL_FIXED
|
|
81 |
#endif //QT_OPENGL_ES_1_CL
|
|
82 |
|
|
83 |
#ifdef QT_OPENGL_ES
|
|
84 |
QT_BEGIN_INCLUDE_NAMESPACE
|
|
85 |
#if defined(QT_OPENGL_ES_2)
|
|
86 |
#include <EGL/egl.h>
|
|
87 |
#else
|
|
88 |
#include <GLES/egl.h>
|
|
89 |
#endif
|
|
90 |
QT_END_INCLUDE_NAMESPACE
|
|
91 |
#endif
|
|
92 |
|
|
93 |
QT_BEGIN_NAMESPACE
|
|
94 |
|
|
95 |
class QGLContext;
|
|
96 |
class QGLOverlayWidget;
|
|
97 |
class QPixmap;
|
|
98 |
class QPixmapFilter;
|
|
99 |
#ifdef Q_WS_MAC
|
|
100 |
# ifdef qDebug
|
|
101 |
# define old_qDebug qDebug
|
|
102 |
# undef qDebug
|
|
103 |
# endif
|
|
104 |
QT_BEGIN_INCLUDE_NAMESPACE
|
|
105 |
#ifndef QT_MAC_USE_COCOA
|
|
106 |
# include <AGL/agl.h>
|
|
107 |
#endif
|
|
108 |
QT_END_INCLUDE_NAMESPACE
|
|
109 |
# ifdef old_qDebug
|
|
110 |
# undef qDebug
|
|
111 |
# define qDebug QT_QDEBUG_MACRO
|
|
112 |
# undef old_qDebug
|
|
113 |
# endif
|
|
114 |
class QMacWindowChangeEvent;
|
|
115 |
#endif
|
|
116 |
|
|
117 |
#ifdef Q_WS_QWS
|
|
118 |
class QWSGLWindowSurface;
|
|
119 |
#endif
|
|
120 |
|
|
121 |
#if defined(QT_OPENGL_ES)
|
|
122 |
class QEglContext;
|
|
123 |
#endif
|
|
124 |
|
|
125 |
QT_BEGIN_INCLUDE_NAMESPACE
|
|
126 |
#include <QtOpenGL/private/qglextensions_p.h>
|
|
127 |
QT_END_INCLUDE_NAMESPACE
|
|
128 |
|
|
129 |
class QGLFormatPrivate
|
|
130 |
{
|
|
131 |
public:
|
|
132 |
QGLFormatPrivate()
|
|
133 |
: ref(1)
|
|
134 |
{
|
|
135 |
opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering | QGL::StencilBuffer;
|
|
136 |
#if defined(QT_OPENGL_ES_2)
|
|
137 |
opts |= QGL::SampleBuffers;
|
|
138 |
#endif
|
|
139 |
pln = 0;
|
|
140 |
depthSize = accumSize = stencilSize = redSize = greenSize = blueSize = alphaSize = -1;
|
|
141 |
numSamples = -1;
|
|
142 |
swapInterval = -1;
|
|
143 |
}
|
|
144 |
QGLFormatPrivate(const QGLFormatPrivate *other)
|
|
145 |
: ref(1),
|
|
146 |
opts(other->opts),
|
|
147 |
pln(other->pln),
|
|
148 |
depthSize(other->depthSize),
|
|
149 |
accumSize(other->accumSize),
|
|
150 |
stencilSize(other->stencilSize),
|
|
151 |
redSize(other->redSize),
|
|
152 |
greenSize(other->greenSize),
|
|
153 |
blueSize(other->blueSize),
|
|
154 |
alphaSize(other->alphaSize),
|
|
155 |
numSamples(other->numSamples),
|
|
156 |
swapInterval(other->swapInterval)
|
|
157 |
{
|
|
158 |
}
|
|
159 |
QAtomicInt ref;
|
|
160 |
QGL::FormatOptions opts;
|
|
161 |
int pln;
|
|
162 |
int depthSize;
|
|
163 |
int accumSize;
|
|
164 |
int stencilSize;
|
|
165 |
int redSize;
|
|
166 |
int greenSize;
|
|
167 |
int blueSize;
|
|
168 |
int alphaSize;
|
|
169 |
int numSamples;
|
|
170 |
int swapInterval;
|
|
171 |
};
|
|
172 |
|
|
173 |
class QGLWidgetPrivate : public QWidgetPrivate
|
|
174 |
{
|
|
175 |
Q_DECLARE_PUBLIC(QGLWidget)
|
|
176 |
public:
|
|
177 |
QGLWidgetPrivate() : QWidgetPrivate()
|
|
178 |
, disable_clear_on_painter_begin(false)
|
|
179 |
#ifdef Q_WS_QWS
|
|
180 |
, wsurf(0)
|
|
181 |
#endif
|
|
182 |
#if defined(Q_WS_X11) && defined(QT_OPENGL_ES)
|
|
183 |
, eglSurfaceWindowId(0)
|
|
184 |
#endif
|
|
185 |
{}
|
|
186 |
|
|
187 |
~QGLWidgetPrivate() {}
|
|
188 |
|
|
189 |
void init(QGLContext *context, const QGLWidget* shareWidget);
|
|
190 |
void initContext(QGLContext *context, const QGLWidget* shareWidget);
|
|
191 |
bool renderCxPm(QPixmap *pixmap);
|
|
192 |
void cleanupColormaps();
|
|
193 |
|
|
194 |
QGLContext *glcx;
|
|
195 |
QGLWidgetGLPaintDevice glDevice;
|
|
196 |
bool autoSwap;
|
|
197 |
|
|
198 |
QGLColormap cmap;
|
|
199 |
#ifndef QT_OPENGL_ES
|
|
200 |
QMap<QString, int> displayListCache;
|
|
201 |
#endif
|
|
202 |
|
|
203 |
bool disable_clear_on_painter_begin;
|
|
204 |
|
|
205 |
#if defined(Q_WS_WIN)
|
|
206 |
void updateColormap();
|
|
207 |
QGLContext *olcx;
|
|
208 |
#elif defined(Q_WS_X11)
|
|
209 |
QGLOverlayWidget *olw;
|
|
210 |
#if defined(QT_OPENGL_ES)
|
|
211 |
void recreateEglSurface(bool force);
|
|
212 |
WId eglSurfaceWindowId;
|
|
213 |
#endif
|
|
214 |
#elif defined(Q_WS_MAC)
|
|
215 |
QGLContext *olcx;
|
|
216 |
void updatePaintDevice();
|
|
217 |
#elif defined(Q_WS_QWS)
|
|
218 |
QWSGLWindowSurface *wsurf;
|
|
219 |
#endif
|
|
220 |
};
|
|
221 |
|
|
222 |
class QGLContextResource;
|
|
223 |
class QGLSharedResourceGuard;
|
|
224 |
|
|
225 |
// QGLContextPrivate has the responsibility of creating context groups.
|
|
226 |
// QGLContextPrivate and QGLShareRegister will both maintain the reference counter and destroy
|
|
227 |
// context groups when needed.
|
|
228 |
// QGLShareRegister has the responsibility of keeping the context pointer up to date.
|
|
229 |
class QGLContextGroup
|
|
230 |
{
|
|
231 |
public:
|
|
232 |
~QGLContextGroup();
|
|
233 |
|
|
234 |
QGLExtensionFuncs &extensionFuncs() {return m_extensionFuncs;}
|
|
235 |
const QGLContext *context() const {return m_context;}
|
|
236 |
|
|
237 |
void addGuard(QGLSharedResourceGuard *guard);
|
|
238 |
void removeGuard(QGLSharedResourceGuard *guard);
|
|
239 |
private:
|
|
240 |
QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }
|
|
241 |
|
|
242 |
QGLExtensionFuncs m_extensionFuncs;
|
|
243 |
const QGLContext *m_context; // context group's representative
|
|
244 |
QList<const QGLContext *> m_shares;
|
|
245 |
QHash<QGLContextResource *, void *> m_resources;
|
|
246 |
QGLSharedResourceGuard *m_guards; // double-linked list of active guards.
|
|
247 |
QAtomicInt m_refs;
|
|
248 |
|
|
249 |
void cleanupResources(const QGLContext *ctx);
|
|
250 |
|
|
251 |
friend class QGLShareRegister;
|
|
252 |
friend class QGLContext;
|
|
253 |
friend class QGLContextPrivate;
|
|
254 |
friend class QGLContextResource;
|
|
255 |
};
|
|
256 |
|
|
257 |
class QGLTexture;
|
|
258 |
|
|
259 |
class QGLContextPrivate
|
|
260 |
{
|
|
261 |
Q_DECLARE_PUBLIC(QGLContext)
|
|
262 |
public:
|
|
263 |
explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
|
|
264 |
~QGLContextPrivate();
|
|
265 |
QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
|
|
266 |
QGLContext::BindOptions options);
|
|
267 |
QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, const qint64 key,
|
|
268 |
QGLContext::BindOptions options);
|
|
269 |
QGLTexture *bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
|
|
270 |
QGLContext::BindOptions options);
|
|
271 |
QGLTexture *textureCacheLookup(const qint64 key, GLenum target);
|
|
272 |
void init(QPaintDevice *dev, const QGLFormat &format);
|
|
273 |
QImage convertToGLFormat(const QImage &image, bool force_premul, GLenum texture_format);
|
|
274 |
int maxTextureSize();
|
|
275 |
|
|
276 |
void cleanup();
|
|
277 |
|
|
278 |
#if defined(Q_WS_WIN)
|
|
279 |
HGLRC rc;
|
|
280 |
HDC dc;
|
|
281 |
WId win;
|
|
282 |
int pixelFormatId;
|
|
283 |
QGLCmap* cmap;
|
|
284 |
HBITMAP hbitmap;
|
|
285 |
HDC hbitmap_hdc;
|
|
286 |
#endif
|
|
287 |
#if defined(QT_OPENGL_ES)
|
|
288 |
QEglContext *eglContext;
|
|
289 |
EGLSurface eglSurface;
|
|
290 |
#elif defined(Q_WS_X11) || defined(Q_WS_MAC)
|
|
291 |
void* cx;
|
|
292 |
#endif
|
|
293 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
|
|
294 |
void* vi;
|
|
295 |
#endif
|
|
296 |
#if defined(Q_WS_X11)
|
|
297 |
void* pbuf;
|
|
298 |
quint32 gpm;
|
|
299 |
int screen;
|
|
300 |
QHash<QPixmapData*, QPixmap> boundPixmaps;
|
|
301 |
QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
|
|
302 |
QGLContext::BindOptions options);
|
|
303 |
static void destroyGlSurfaceForPixmap(QPixmapData*);
|
|
304 |
static void unbindPixmapFromTexture(QPixmapData*);
|
|
305 |
#endif
|
|
306 |
#if defined(Q_WS_MAC)
|
|
307 |
bool update;
|
|
308 |
void *tryFormat(const QGLFormat &format);
|
|
309 |
void clearDrawable();
|
|
310 |
#endif
|
|
311 |
QGLFormat glFormat;
|
|
312 |
QGLFormat reqFormat;
|
|
313 |
GLuint fbo;
|
|
314 |
|
|
315 |
uint valid : 1;
|
|
316 |
uint sharing : 1;
|
|
317 |
uint initDone : 1;
|
|
318 |
uint crWin : 1;
|
|
319 |
uint internal_context : 1;
|
|
320 |
uint version_flags_cached : 1;
|
|
321 |
QPaintDevice *paintDevice;
|
|
322 |
QColor transpColor;
|
|
323 |
QGLContext *q_ptr;
|
|
324 |
QGLFormat::OpenGLVersionFlags version_flags;
|
|
325 |
|
|
326 |
QGLContextGroup *group;
|
|
327 |
GLint max_texture_size;
|
|
328 |
|
|
329 |
GLuint current_fbo;
|
|
330 |
QPaintEngine *active_engine;
|
|
331 |
|
|
332 |
static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; }
|
|
333 |
|
|
334 |
#ifdef Q_WS_WIN
|
|
335 |
static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); }
|
|
336 |
#endif
|
|
337 |
|
|
338 |
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
|
339 |
static QGLExtensionFuncs qt_extensionFuncs;
|
|
340 |
static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }
|
|
341 |
#endif
|
|
342 |
|
|
343 |
static void setCurrentContext(QGLContext *context);
|
|
344 |
};
|
|
345 |
|
|
346 |
// ### make QGLContext a QObject in 5.0 and remove the proxy stuff
|
|
347 |
class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
|
|
348 |
{
|
|
349 |
Q_OBJECT
|
|
350 |
public:
|
|
351 |
QGLSignalProxy() : QObject() {}
|
|
352 |
void emitAboutToDestroyContext(const QGLContext *context) {
|
|
353 |
emit aboutToDestroyContext(context);
|
|
354 |
}
|
|
355 |
static QGLSignalProxy *instance();
|
|
356 |
Q_SIGNALS:
|
|
357 |
void aboutToDestroyContext(const QGLContext *context);
|
|
358 |
};
|
|
359 |
|
|
360 |
// GL extension definitions
|
|
361 |
class QGLExtensions {
|
|
362 |
public:
|
|
363 |
enum Extension {
|
|
364 |
TextureRectangle = 0x00000001,
|
|
365 |
SampleBuffers = 0x00000002,
|
|
366 |
GenerateMipmap = 0x00000004,
|
|
367 |
TextureCompression = 0x00000008,
|
|
368 |
FragmentProgram = 0x00000010,
|
|
369 |
MirroredRepeat = 0x00000020,
|
|
370 |
FramebufferObject = 0x00000040,
|
|
371 |
StencilTwoSide = 0x00000080,
|
|
372 |
StencilWrap = 0x00000100,
|
|
373 |
PackedDepthStencil = 0x00000200,
|
|
374 |
NVFloatBuffer = 0x00000400,
|
|
375 |
PixelBufferObject = 0x00000800,
|
|
376 |
FramebufferBlit = 0x00001000,
|
|
377 |
NPOTTextures = 0x00002000
|
|
378 |
};
|
|
379 |
Q_DECLARE_FLAGS(Extensions, Extension)
|
|
380 |
|
|
381 |
static Extensions glExtensions;
|
|
382 |
static bool nvidiaFboNeedsFinish;
|
|
383 |
static void init(); // sys dependent
|
|
384 |
static void init_extensions(); // general: called by init()
|
|
385 |
};
|
|
386 |
|
|
387 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions)
|
|
388 |
|
|
389 |
|
|
390 |
class Q_AUTOTEST_EXPORT QGLShareRegister
|
|
391 |
{
|
|
392 |
public:
|
|
393 |
QGLShareRegister() {}
|
|
394 |
~QGLShareRegister() {}
|
|
395 |
|
|
396 |
void addShare(const QGLContext *context, const QGLContext *share);
|
|
397 |
QList<const QGLContext *> shares(const QGLContext *context);
|
|
398 |
void removeShare(const QGLContext *context);
|
|
399 |
};
|
|
400 |
|
|
401 |
extern Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg();
|
|
402 |
|
|
403 |
// Temporarily make a context current if not already current or
|
|
404 |
// shared with the current contex. The previous context is made
|
|
405 |
// current when the object goes out of scope.
|
|
406 |
class Q_OPENGL_EXPORT QGLShareContextScope
|
|
407 |
{
|
|
408 |
public:
|
|
409 |
QGLShareContextScope(const QGLContext *ctx)
|
|
410 |
: m_oldContext(0)
|
|
411 |
{
|
|
412 |
QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext());
|
|
413 |
if (currentContext != ctx && !QGLContext::areSharing(ctx, currentContext)) {
|
|
414 |
m_oldContext = currentContext;
|
|
415 |
m_ctx = const_cast<QGLContext *>(ctx);
|
|
416 |
m_ctx->makeCurrent();
|
|
417 |
} else {
|
|
418 |
m_ctx = currentContext;
|
|
419 |
}
|
|
420 |
}
|
|
421 |
|
|
422 |
operator QGLContext *()
|
|
423 |
{
|
|
424 |
return m_ctx;
|
|
425 |
}
|
|
426 |
|
|
427 |
QGLContext *operator->()
|
|
428 |
{
|
|
429 |
return m_ctx;
|
|
430 |
}
|
|
431 |
|
|
432 |
~QGLShareContextScope()
|
|
433 |
{
|
|
434 |
if (m_oldContext)
|
|
435 |
m_oldContext->makeCurrent();
|
|
436 |
}
|
|
437 |
|
|
438 |
private:
|
|
439 |
QGLContext *m_oldContext;
|
|
440 |
QGLContext *m_ctx;
|
|
441 |
};
|
|
442 |
|
|
443 |
class QGLTexture {
|
|
444 |
public:
|
|
445 |
QGLTexture(QGLContext *ctx = 0, GLuint tx_id = 0, GLenum tx_target = GL_TEXTURE_2D,
|
|
446 |
QGLContext::BindOptions opt = QGLContext::DefaultBindOption)
|
|
447 |
: context(ctx),
|
|
448 |
id(tx_id),
|
|
449 |
target(tx_target),
|
|
450 |
options(opt)
|
|
451 |
#if defined(Q_WS_X11)
|
|
452 |
, boundPixmap(0)
|
|
453 |
#endif
|
|
454 |
{}
|
|
455 |
|
|
456 |
~QGLTexture() {
|
|
457 |
if (options & QGLContext::MemoryManagedBindOption) {
|
|
458 |
Q_ASSERT(context);
|
|
459 |
QGLShareContextScope scope(context);
|
|
460 |
#if defined(Q_WS_X11)
|
|
461 |
// Although glXReleaseTexImage is a glX call, it must be called while there
|
|
462 |
// is a current context - the context the pixmap was bound to a texture in.
|
|
463 |
// Otherwise the release doesn't do anything and you get BadDrawable errors
|
|
464 |
// when you come to delete the context.
|
|
465 |
if (boundPixmap)
|
|
466 |
QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
|
|
467 |
#endif
|
|
468 |
glDeleteTextures(1, &id);
|
|
469 |
}
|
|
470 |
}
|
|
471 |
|
|
472 |
QGLContext *context;
|
|
473 |
GLuint id;
|
|
474 |
GLenum target;
|
|
475 |
|
|
476 |
QGLContext::BindOptions options;
|
|
477 |
|
|
478 |
#if defined(Q_WS_X11)
|
|
479 |
QPixmapData* boundPixmap;
|
|
480 |
#endif
|
|
481 |
|
|
482 |
};
|
|
483 |
|
|
484 |
class QGLTextureCache {
|
|
485 |
public:
|
|
486 |
QGLTextureCache();
|
|
487 |
~QGLTextureCache();
|
|
488 |
|
|
489 |
void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost);
|
|
490 |
void remove(quint64 key) { m_cache.remove(key); }
|
|
491 |
bool remove(QGLContext *ctx, GLuint textureId);
|
|
492 |
void removeContextTextures(QGLContext *ctx);
|
|
493 |
int size() { return m_cache.size(); }
|
|
494 |
void setMaxCost(int newMax) { m_cache.setMaxCost(newMax); }
|
|
495 |
int maxCost() {return m_cache.maxCost(); }
|
|
496 |
QGLTexture* getTexture(quint64 key) { return m_cache.object(key); }
|
|
497 |
|
|
498 |
static QGLTextureCache *instance();
|
|
499 |
static void deleteIfEmpty();
|
|
500 |
static void imageCleanupHook(qint64 cacheKey);
|
|
501 |
static void cleanupTextures(QPixmap* pixmap);
|
|
502 |
#ifdef Q_WS_X11
|
|
503 |
// X11 needs to catch pixmap data destruction to delete EGL/GLX pixmap surfaces
|
|
504 |
static void cleanupPixmapSurfaces(QPixmap* pixmap);
|
|
505 |
#endif
|
|
506 |
|
|
507 |
private:
|
|
508 |
QCache<qint64, QGLTexture> m_cache;
|
|
509 |
};
|
|
510 |
|
|
511 |
|
|
512 |
extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine();
|
|
513 |
|
|
514 |
bool qt_gl_preferGL2Engine();
|
|
515 |
|
|
516 |
inline GLenum qt_gl_preferredTextureFormat()
|
|
517 |
{
|
|
518 |
return QSysInfo::ByteOrder == QSysInfo::BigEndian ? GL_RGBA : GL_BGRA;
|
|
519 |
}
|
|
520 |
|
|
521 |
inline GLenum qt_gl_preferredTextureTarget()
|
|
522 |
{
|
|
523 |
#if defined(QT_OPENGL_ES_2)
|
|
524 |
return GL_TEXTURE_2D;
|
|
525 |
#else
|
|
526 |
return (QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
|
|
527 |
&& !qt_gl_preferGL2Engine()
|
|
528 |
? GL_TEXTURE_RECTANGLE_NV
|
|
529 |
: GL_TEXTURE_2D;
|
|
530 |
#endif
|
|
531 |
}
|
|
532 |
|
|
533 |
// One resource per group of shared contexts.
|
|
534 |
class Q_AUTOTEST_EXPORT QGLContextResource
|
|
535 |
{
|
|
536 |
public:
|
|
537 |
typedef void (*FreeFunc)(void *);
|
|
538 |
QGLContextResource(FreeFunc f);
|
|
539 |
~QGLContextResource();
|
|
540 |
// Set resource 'value' for 'key' and all its shared contexts.
|
|
541 |
void insert(const QGLContext *key, void *value);
|
|
542 |
// Return resource for 'key' or a shared context.
|
|
543 |
void *value(const QGLContext *key);
|
|
544 |
// Cleanup 'value' in response to a context group being destroyed.
|
|
545 |
void cleanup(const QGLContext *ctx, void *value);
|
|
546 |
private:
|
|
547 |
FreeFunc free;
|
|
548 |
QAtomicInt active;
|
|
549 |
};
|
|
550 |
|
|
551 |
// Put a guard around a GL object identifier and its context.
|
|
552 |
// When the context goes away, a shared context will be used
|
|
553 |
// in its place. If there are no more shared contexts, then
|
|
554 |
// the identifier is returned as zero - it is assumed that the
|
|
555 |
// context destruction cleaned up the identifier in this case.
|
|
556 |
class Q_OPENGL_EXPORT QGLSharedResourceGuard
|
|
557 |
{
|
|
558 |
public:
|
|
559 |
QGLSharedResourceGuard(const QGLContext *context)
|
|
560 |
: m_group(0), m_id(0), m_next(0), m_prev(0)
|
|
561 |
{
|
|
562 |
setContext(context);
|
|
563 |
}
|
|
564 |
QGLSharedResourceGuard(const QGLContext *context, GLuint id)
|
|
565 |
: m_group(0), m_id(id), m_next(0), m_prev(0)
|
|
566 |
{
|
|
567 |
setContext(context);
|
|
568 |
}
|
|
569 |
~QGLSharedResourceGuard();
|
|
570 |
|
|
571 |
const QGLContext *context() const
|
|
572 |
{
|
|
573 |
return m_group ? m_group->context() : 0;
|
|
574 |
}
|
|
575 |
|
|
576 |
void setContext(const QGLContext *context);
|
|
577 |
|
|
578 |
GLuint id() const
|
|
579 |
{
|
|
580 |
return m_id;
|
|
581 |
}
|
|
582 |
|
|
583 |
void setId(GLuint id)
|
|
584 |
{
|
|
585 |
m_id = id;
|
|
586 |
}
|
|
587 |
|
|
588 |
private:
|
|
589 |
QGLContextGroup *m_group;
|
|
590 |
GLuint m_id;
|
|
591 |
QGLSharedResourceGuard *m_next;
|
|
592 |
QGLSharedResourceGuard *m_prev;
|
|
593 |
|
|
594 |
friend class QGLContextGroup;
|
|
595 |
};
|
|
596 |
|
|
597 |
QT_END_NAMESPACE
|
|
598 |
|
|
599 |
#endif // QGL_P_H
|