1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtOpenGL module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QGL_H
#define QGL_H
#include <QtGui/qwidget.h>
#include <QtGui/qpaintengine.h>
#include <QtOpenGL/qglcolormap.h>
#include <QtCore/qmap.h>
#include <QtCore/qscopedpointer.h>
QT_BEGIN_HEADER
#if defined(Q_WS_WIN)
# include <QtCore/qt_windows.h>
#endif
#if defined(Q_WS_MAC)
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
#elif defined(QT_OPENGL_ES_1)
# include <GLES/gl.h>
#ifndef GL_DOUBLE
# define GL_DOUBLE GL_FLOAT
#endif
#ifndef GLdouble
typedef GLfloat GLdouble;
#endif
#elif defined(QT_OPENGL_ES_2)
# include <GLES2/gl2.h>
#ifndef GL_DOUBLE
# define GL_DOUBLE GL_FLOAT
#endif
#ifndef GLdouble
typedef GLfloat GLdouble;
#endif
#else
# include <GL/gl.h>
# ifndef QT_LINUXBASE
# include <GL/glu.h>
# endif
#endif
QT_BEGIN_NAMESPACE
QT_MODULE(OpenGL)
#if defined(Q_WS_MAC) && defined (QT_BUILD_OPENGL_LIB) && !defined(QT_MAC_USE_COCOA) && !defined(QDOC)
#define Q_MAC_COMPAT_GL_FUNCTIONS
template <typename T>
struct QMacGLCompatTypes
{
typedef long CompatGLint;
typedef unsigned long CompatGLuint;
typedef unsigned long CompatGLenum;
};
template <>
struct QMacGLCompatTypes<long>
{
typedef int CompatGLint;
typedef unsigned int CompatGLuint;
typedef unsigned int CompatGLenum;
};
typedef QMacGLCompatTypes<GLint>::CompatGLint QMacCompatGLint;
typedef QMacGLCompatTypes<GLint>::CompatGLuint QMacCompatGLuint;
typedef QMacGLCompatTypes<GLint>::CompatGLenum QMacCompatGLenum;
#endif
#ifdef QT3_SUPPORT
#define QGL_VERSION 460
#define QGL_VERSION_STR "4.6"
inline QT3_SUPPORT const char *qGLVersion() {
return QGL_VERSION_STR;
}
#endif
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
class QGLCmap;
#endif
class QPixmap;
#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES)
class QGLOverlayWidget;
#endif
class QGLWidgetPrivate;
class QGLContextPrivate;
// Namespace class:
namespace QGL
{
Q_OPENGL_EXPORT void setPreferredPaintEngine(QPaintEngine::Type engineType);
enum FormatOption {
DoubleBuffer = 0x0001,
DepthBuffer = 0x0002,
Rgba = 0x0004,
AlphaChannel = 0x0008,
AccumBuffer = 0x0010,
StencilBuffer = 0x0020,
StereoBuffers = 0x0040,
DirectRendering = 0x0080,
HasOverlay = 0x0100,
SampleBuffers = 0x0200,
DeprecatedFunctions = 0x0400,
SingleBuffer = DoubleBuffer << 16,
NoDepthBuffer = DepthBuffer << 16,
ColorIndex = Rgba << 16,
NoAlphaChannel = AlphaChannel << 16,
NoAccumBuffer = AccumBuffer << 16,
NoStencilBuffer = StencilBuffer << 16,
NoStereoBuffers = StereoBuffers << 16,
IndirectRendering = DirectRendering << 16,
NoOverlay = HasOverlay << 16,
NoSampleBuffers = SampleBuffers << 16,
NoDeprecatedFunctions = DeprecatedFunctions << 16
};
Q_DECLARE_FLAGS(FormatOptions, FormatOption)
}
Q_DECLARE_OPERATORS_FOR_FLAGS(QGL::FormatOptions)
class QGLFormatPrivate;
class Q_OPENGL_EXPORT QGLFormat
{
public:
QGLFormat();
QGLFormat(QGL::FormatOptions options, int plane = 0);
QGLFormat(const QGLFormat &other);
QGLFormat &operator=(const QGLFormat &other);
~QGLFormat();
void setDepthBufferSize(int size);
int depthBufferSize() const;
void setAccumBufferSize(int size);
int accumBufferSize() const;
void setRedBufferSize(int size);
int redBufferSize() const;
void setGreenBufferSize(int size);
int greenBufferSize() const;
void setBlueBufferSize(int size);
int blueBufferSize() const;
void setAlphaBufferSize(int size);
int alphaBufferSize() const;
void setStencilBufferSize(int size);
int stencilBufferSize() const;
void setSampleBuffers(bool enable);
bool sampleBuffers() const;
void setSamples(int numSamples);
int samples() const;
void setSwapInterval(int interval);
int swapInterval() const;
bool doubleBuffer() const;
void setDoubleBuffer(bool enable);
bool depth() const;
void setDepth(bool enable);
bool rgba() const;
void setRgba(bool enable);
bool alpha() const;
void setAlpha(bool enable);
bool accum() const;
void setAccum(bool enable);
bool stencil() const;
void setStencil(bool enable);
bool stereo() const;
void setStereo(bool enable);
bool directRendering() const;
void setDirectRendering(bool enable);
bool hasOverlay() const;
void setOverlay(bool enable);
int plane() const;
void setPlane(int plane);
void setOption(QGL::FormatOptions opt);
bool testOption(QGL::FormatOptions opt) const;
static QGLFormat defaultFormat();
static void setDefaultFormat(const QGLFormat& f);
static QGLFormat defaultOverlayFormat();
static void setDefaultOverlayFormat(const QGLFormat& f);
static bool hasOpenGL();
static bool hasOpenGLOverlays();
void setVersion(int major, int minor);
int majorVersion() const;
int minorVersion() const;
enum OpenGLContextProfile {
NoProfile,
CoreProfile,
CompatibilityProfile
};
void setProfile(OpenGLContextProfile profile);
OpenGLContextProfile profile() const;
enum OpenGLVersionFlag {
OpenGL_Version_None = 0x00000000,
OpenGL_Version_1_1 = 0x00000001,
OpenGL_Version_1_2 = 0x00000002,
OpenGL_Version_1_3 = 0x00000004,
OpenGL_Version_1_4 = 0x00000008,
OpenGL_Version_1_5 = 0x00000010,
OpenGL_Version_2_0 = 0x00000020,
OpenGL_Version_2_1 = 0x00000040,
OpenGL_ES_Common_Version_1_0 = 0x00000080,
OpenGL_ES_CommonLite_Version_1_0 = 0x00000100,
OpenGL_ES_Common_Version_1_1 = 0x00000200,
OpenGL_ES_CommonLite_Version_1_1 = 0x00000400,
OpenGL_ES_Version_2_0 = 0x00000800,
OpenGL_Version_3_0 = 0x00001000,
OpenGL_Version_3_1 = 0x00002000,
OpenGL_Version_3_2 = 0x00004000
};
Q_DECLARE_FLAGS(OpenGLVersionFlags, OpenGLVersionFlag)
static OpenGLVersionFlags openGLVersionFlags();
private:
QGLFormatPrivate *d;
void detach();
friend Q_OPENGL_EXPORT bool operator==(const QGLFormat&, const QGLFormat&);
friend Q_OPENGL_EXPORT bool operator!=(const QGLFormat&, const QGLFormat&);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLFormat::OpenGLVersionFlags)
Q_OPENGL_EXPORT bool operator==(const QGLFormat&, const QGLFormat&);
Q_OPENGL_EXPORT bool operator!=(const QGLFormat&, const QGLFormat&);
class Q_OPENGL_EXPORT QGLContext
{
Q_DECLARE_PRIVATE(QGLContext)
public:
QGLContext(const QGLFormat& format, QPaintDevice* device);
QGLContext(const QGLFormat& format);
virtual ~QGLContext();
virtual bool create(const QGLContext* shareContext = 0);
bool isValid() const;
bool isSharing() const;
void reset();
static bool areSharing(const QGLContext *context1, const QGLContext *context2);
QGLFormat format() const;
QGLFormat requestedFormat() const;
void setFormat(const QGLFormat& format);
// ### Qt 5: return bools + maybe remove virtuals
virtual void makeCurrent();
virtual void doneCurrent();
virtual void swapBuffers() const;
enum BindOption {
NoBindOption = 0x0000,
InvertedYBindOption = 0x0001,
MipmapBindOption = 0x0002,
PremultipliedAlphaBindOption = 0x0004,
LinearFilteringBindOption = 0x0008,
MemoryManagedBindOption = 0x0010, // internal flag
CanFlipNativePixmapBindOption = 0x0020, // internal flag
DefaultBindOption = LinearFilteringBindOption
| InvertedYBindOption
| MipmapBindOption,
InternalBindOption = MemoryManagedBindOption
| PremultipliedAlphaBindOption
};
Q_DECLARE_FLAGS(BindOptions, BindOption)
GLuint bindTexture(const QImage &image, GLenum target, GLint format,
BindOptions options);
GLuint bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
BindOptions options);
GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D,
GLint format = GL_RGBA);
GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D,
GLint format = GL_RGBA);
GLuint bindTexture(const QString &fileName);
void deleteTexture(GLuint tx_id);
void drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
void drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS
GLuint bindTexture(const QImage &image, QMacCompatGLenum = GL_TEXTURE_2D,
QMacCompatGLint format = GL_RGBA);
GLuint bindTexture(const QPixmap &pixmap, QMacCompatGLenum = GL_TEXTURE_2D,
QMacCompatGLint format = GL_RGBA);
GLuint bindTexture(const QImage &image, QMacCompatGLenum, QMacCompatGLint format,
BindOptions);
GLuint bindTexture(const QPixmap &pixmap, QMacCompatGLenum, QMacCompatGLint format,
BindOptions);
void deleteTexture(QMacCompatGLuint tx_id);
void drawTexture(const QRectF &target, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
void drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
#endif
static void setTextureCacheLimit(int size);
static int textureCacheLimit();
void *getProcAddress(const QString &proc) const;
QPaintDevice* device() const;
QColor overlayTransparentColor() const;
static const QGLContext* currentContext();
protected:
virtual bool chooseContext(const QGLContext* shareContext = 0);
#if defined(Q_WS_WIN)
virtual int choosePixelFormat(void* pfd, HDC pdc);
#endif
#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES)
virtual void* tryVisual(const QGLFormat& f, int bufDepth = 1);
virtual void* chooseVisual();
#endif
#if defined(Q_WS_MAC)
virtual void* chooseMacVisual(GDHandle);
#endif
bool deviceIsPixmap() const;
bool windowCreated() const;
void setWindowCreated(bool on);
bool initialized() const;
void setInitialized(bool on);
void generateFontDisplayLists(const QFont & fnt, int listBase); // ### Qt 5: remove
uint colorIndex(const QColor& c) const;
void setValid(bool valid);
void setDevice(QPaintDevice *pDev);
protected:
static QGLContext* currentCtx;
private:
QScopedPointer<QGLContextPrivate> d_ptr;
friend class QGLPixelBuffer;
friend class QGLPixelBufferPrivate;
friend class QGLWidget;
friend class QGLWidgetPrivate;
friend class QGLGlyphCache;
friend class QOpenGLPaintEngine;
friend class QOpenGLPaintEnginePrivate;
friend class QGL2PaintEngineEx;
friend class QGL2PaintEngineExPrivate;
friend class QGLEngineShaderManager;
friend class QGLWindowSurface;
friend class QGLPixmapData;
friend class QGLPixmapFilterBase;
friend class QGLTextureGlyphCache;
friend class QGLContextGroup;
friend class QGLSharedResourceGuard;
friend class QGLPixmapBlurFilter;
friend class QGLExtensions;
friend QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags();
#ifdef Q_WS_MAC
public:
void updatePaintDevice();
private:
friend class QMacGLWindowChangeEvent;
friend QGLContextPrivate *qt_phonon_get_dptr(const QGLContext *);
#endif
friend class QGLFramebufferObject;
friend class QGLFramebufferObjectPrivate;
friend class QGLFBOGLPaintDevice;
friend class QGLPaintDevice;
friend class QX11GLPixmapData;
private:
Q_DISABLE_COPY(QGLContext)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLContext::BindOptions)
class Q_OPENGL_EXPORT QGLWidget : public QWidget
{
Q_OBJECT
Q_DECLARE_PRIVATE(QGLWidget)
public:
explicit QGLWidget(QWidget* parent=0,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f=0);
explicit QGLWidget(QGLContext *context, QWidget* parent=0,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f=0);
explicit QGLWidget(const QGLFormat& format, QWidget* parent=0,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f=0);
#ifdef QT3_SUPPORT
QT3_SUPPORT_CONSTRUCTOR QGLWidget(QWidget* parent, const char* name,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f=0);
QT3_SUPPORT_CONSTRUCTOR QGLWidget(QGLContext *context, QWidget* parent, const char* name,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f=0);
QT3_SUPPORT_CONSTRUCTOR QGLWidget(const QGLFormat& format, QWidget* parent, const char* name,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f=0);
#endif
~QGLWidget();
void qglColor(const QColor& c) const;
void qglClearColor(const QColor& c) const;
bool isValid() const;
bool isSharing() const;
// ### Qt 5: return bools
void makeCurrent();
void doneCurrent();
bool doubleBuffer() const;
void swapBuffers();
QGLFormat format() const;
void setFormat(const QGLFormat& format);
const QGLContext* context() const;
void setContext(QGLContext* context, const QGLContext* shareContext = 0,
bool deleteOldContext = true);
QPixmap renderPixmap(int w = 0, int h = 0, bool useContext = false);
QImage grabFrameBuffer(bool withAlpha = false);
void makeOverlayCurrent();
const QGLContext* overlayContext() const;
static QImage convertToGLFormat(const QImage& img);
void setMouseTracking(bool enable);
const QGLColormap & colormap() const;
void setColormap(const QGLColormap & map);
void renderText(int x, int y, const QString & str,
const QFont & fnt = QFont(), int listBase = 2000);
void renderText(double x, double y, double z, const QString & str,
const QFont & fnt = QFont(), int listBase = 2000);
QPaintEngine *paintEngine() const;
GLuint bindTexture(const QImage &image, GLenum target, GLint format,
QGLContext::BindOptions options);
GLuint bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
QGLContext::BindOptions options);
GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D,
GLint format = GL_RGBA);
GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D,
GLint format = GL_RGBA);
GLuint bindTexture(const QString &fileName);
void deleteTexture(GLuint tx_id);
void drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
void drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS
GLuint bindTexture(const QImage &image, QMacCompatGLenum = GL_TEXTURE_2D,
QMacCompatGLint format = GL_RGBA);
GLuint bindTexture(const QPixmap &pixmap, QMacCompatGLenum = GL_TEXTURE_2D,
QMacCompatGLint format = GL_RGBA);
GLuint bindTexture(const QImage &image, QMacCompatGLenum, QMacCompatGLint format,
QGLContext::BindOptions);
GLuint bindTexture(const QPixmap &pixmap, QMacCompatGLenum, QMacCompatGLint format,
QGLContext::BindOptions);
void deleteTexture(QMacCompatGLuint tx_id);
void drawTexture(const QRectF &target, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
void drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
#endif
public Q_SLOTS:
virtual void updateGL();
virtual void updateOverlayGL();
protected:
bool event(QEvent *);
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
virtual void initializeOverlayGL();
virtual void resizeOverlayGL(int w, int h);
virtual void paintOverlayGL();
void setAutoBufferSwap(bool on);
bool autoBufferSwap() const;
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
virtual void glInit();
virtual void glDraw();
int fontDisplayListBase(const QFont & fnt, int listBase = 2000); // ### Qt 5: remove
private:
Q_DISABLE_COPY(QGLWidget)
#ifdef Q_WS_MAC
friend class QMacGLWindowChangeEvent;
#endif
friend class QGLDrawable;
friend class QGLPixelBuffer;
friend class QGLPixelBufferPrivate;
friend class QGLContext;
friend class QGLContextPrivate;
friend class QGLOverlayWidget;
friend class QOpenGLPaintEngine;
friend class QGLPaintDevice;
friend class QGLWidgetGLPaintDevice;
};
//
// QGLFormat inline functions
//
inline bool QGLFormat::doubleBuffer() const
{
return testOption(QGL::DoubleBuffer);
}
inline bool QGLFormat::depth() const
{
return testOption(QGL::DepthBuffer);
}
inline bool QGLFormat::rgba() const
{
return testOption(QGL::Rgba);
}
inline bool QGLFormat::alpha() const
{
return testOption(QGL::AlphaChannel);
}
inline bool QGLFormat::accum() const
{
return testOption(QGL::AccumBuffer);
}
inline bool QGLFormat::stencil() const
{
return testOption(QGL::StencilBuffer);
}
inline bool QGLFormat::stereo() const
{
return testOption(QGL::StereoBuffers);
}
inline bool QGLFormat::directRendering() const
{
return testOption(QGL::DirectRendering);
}
inline bool QGLFormat::hasOverlay() const
{
return testOption(QGL::HasOverlay);
}
inline bool QGLFormat::sampleBuffers() const
{
return testOption(QGL::SampleBuffers);
}
QT_END_NAMESPACE
QT_END_HEADER
#endif // QGL_H
|