source: trunk/src/opengl/qgl.h@ 257

Last change on this file since 257 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 17.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtOpenGL module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGL_H
43#define QGL_H
44
45#include <QtGui/qwidget.h>
46#include <QtOpenGL/qglcolormap.h>
47#include <QtCore/qmap.h>
48
49QT_BEGIN_HEADER
50
51#if defined(Q_WS_WIN)
52# include <QtCore/qt_windows.h>
53#endif
54
55#if defined(Q_WS_MAC)
56# include <OpenGL/gl.h>
57# include <OpenGL/glu.h>
58#elif defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
59# include <GLES/gl.h>
60#ifndef GL_DOUBLE
61# define GL_DOUBLE GL_FLOAT
62#endif
63#ifndef GLdouble
64typedef GLfloat GLdouble;
65#endif
66#elif defined(QT_OPENGL_ES_2)
67# include <GLES2/gl2.h>
68#ifndef GL_DOUBLE
69# define GL_DOUBLE GL_FLOAT
70#endif
71#ifndef GLdouble
72typedef GLfloat GLdouble;
73#endif
74#else
75# include <GL/gl.h>
76# ifndef QT_LINUXBASE
77# include <GL/glu.h>
78# endif
79#endif
80
81QT_BEGIN_NAMESPACE
82
83QT_MODULE(OpenGL)
84
85#if defined(Q_WS_MAC) && defined (QT_BUILD_OPENGL_LIB) && !defined(QT_MAC_USE_COCOA) && !defined(QDOC)
86#define Q_MAC_COMPAT_GL_FUNCTIONS
87
88template <typename T>
89struct QMacGLCompatTypes
90{
91 typedef long CompatGLint;
92 typedef unsigned long CompatGLuint;
93 typedef unsigned long CompatGLenum;
94};
95
96template <>
97struct QMacGLCompatTypes<long>
98{
99 typedef int CompatGLint;
100 typedef unsigned int CompatGLuint;
101 typedef unsigned int CompatGLenum;
102};
103
104typedef QMacGLCompatTypes<GLint>::CompatGLint QMacCompatGLint;
105typedef QMacGLCompatTypes<GLint>::CompatGLuint QMacCompatGLuint;
106typedef QMacGLCompatTypes<GLint>::CompatGLenum QMacCompatGLenum;
107
108#endif
109
110#ifdef QT3_SUPPORT
111#define QGL_VERSION 460
112#define QGL_VERSION_STR "4.6"
113inline QT3_SUPPORT const char *qGLVersion() {
114 return QGL_VERSION_STR;
115}
116#endif
117
118#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
119class QGLCmap;
120#endif
121
122class QPixmap;
123#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES)
124class QGLOverlayWidget;
125#endif
126class QGLWidgetPrivate;
127class QGLContextPrivate;
128
129// Namespace class:
130namespace QGL
131{
132 enum FormatOption {
133 DoubleBuffer = 0x0001,
134 DepthBuffer = 0x0002,
135 Rgba = 0x0004,
136 AlphaChannel = 0x0008,
137 AccumBuffer = 0x0010,
138 StencilBuffer = 0x0020,
139 StereoBuffers = 0x0040,
140 DirectRendering = 0x0080,
141 HasOverlay = 0x0100,
142 SampleBuffers = 0x0200,
143 SingleBuffer = DoubleBuffer << 16,
144 NoDepthBuffer = DepthBuffer << 16,
145 ColorIndex = Rgba << 16,
146 NoAlphaChannel = AlphaChannel << 16,
147 NoAccumBuffer = AccumBuffer << 16,
148 NoStencilBuffer = StencilBuffer << 16,
149 NoStereoBuffers = StereoBuffers << 16,
150 IndirectRendering = DirectRendering << 16,
151 NoOverlay = HasOverlay << 16,
152 NoSampleBuffers = SampleBuffers << 16
153 };
154 Q_DECLARE_FLAGS(FormatOptions, FormatOption)
155}
156
157Q_DECLARE_OPERATORS_FOR_FLAGS(QGL::FormatOptions)
158
159class QGLFormatPrivate;
160
161class Q_OPENGL_EXPORT QGLFormat
162{
163public:
164 QGLFormat();
165 QGLFormat(QGL::FormatOptions options, int plane = 0);
166 QGLFormat(const QGLFormat &other);
167 QGLFormat &operator=(const QGLFormat &other);
168 ~QGLFormat();
169
170 void setDepthBufferSize(int size);
171 int depthBufferSize() const;
172
173 void setAccumBufferSize(int size);
174 int accumBufferSize() const;
175
176 void setRedBufferSize(int size);
177 int redBufferSize() const;
178
179 void setGreenBufferSize(int size);
180 int greenBufferSize() const;
181
182 void setBlueBufferSize(int size);
183 int blueBufferSize() const;
184
185 void setAlphaBufferSize(int size);
186 int alphaBufferSize() const;
187
188 void setStencilBufferSize(int size);
189 int stencilBufferSize() const;
190
191 void setSampleBuffers(bool enable);
192 bool sampleBuffers() const;
193
194 void setSamples(int numSamples);
195 int samples() const;
196
197 void setSwapInterval(int interval);
198 int swapInterval() const;
199
200 bool doubleBuffer() const;
201 void setDoubleBuffer(bool enable);
202 bool depth() const;
203 void setDepth(bool enable);
204 bool rgba() const;
205 void setRgba(bool enable);
206 bool alpha() const;
207 void setAlpha(bool enable);
208 bool accum() const;
209 void setAccum(bool enable);
210 bool stencil() const;
211 void setStencil(bool enable);
212 bool stereo() const;
213 void setStereo(bool enable);
214 bool directRendering() const;
215 void setDirectRendering(bool enable);
216 bool hasOverlay() const;
217 void setOverlay(bool enable);
218
219 int plane() const;
220 void setPlane(int plane);
221
222 void setOption(QGL::FormatOptions opt);
223 bool testOption(QGL::FormatOptions opt) const;
224
225 static QGLFormat defaultFormat();
226 static void setDefaultFormat(const QGLFormat& f);
227
228 static QGLFormat defaultOverlayFormat();
229 static void setDefaultOverlayFormat(const QGLFormat& f);
230
231 static bool hasOpenGL();
232 static bool hasOpenGLOverlays();
233
234 enum OpenGLVersionFlag {
235 OpenGL_Version_None = 0x00000000,
236 OpenGL_Version_1_1 = 0x00000001,
237 OpenGL_Version_1_2 = 0x00000002,
238 OpenGL_Version_1_3 = 0x00000004,
239 OpenGL_Version_1_4 = 0x00000008,
240 OpenGL_Version_1_5 = 0x00000010,
241 OpenGL_Version_2_0 = 0x00000020,