summaryrefslogtreecommitdiffstats
path: root/demos/boxes/glextensions.h
blob: 3145f0d31ec648de5193691878e563f477e05792 (plain)
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
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the demonstration applications 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 either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** 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.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef GLEXTENSIONS_H
#define GLEXTENSIONS_H

#include <QtOpenGL>

/*
Functions resolved:

glCreateShaderObjectARB
glShaderSourceARB
glCompileShaderARB
glGetObjectParameterivARB
glDeleteObjectARB
glGetInfoLogARB
glCreateProgramObjectARB
glAttachObjectARB
glDetachObjectARB
glLinkProgramARB
glUseProgramObjectARB
glGetUniformLocationARB
glUniform1iARB
glUniform1fARB
glUniform4fARB
glUniformMatrix4fvARB

glGenFramebuffersEXT
glGenRenderbuffersEXT
glBindRenderbufferEXT
glRenderbufferStorageEXT
glDeleteFramebuffersEXT
glDeleteRenderbuffersEXT
glBindFramebufferEXT
glFramebufferTexture2DEXT
glFramebufferRenderbufferEXT
glCheckFramebufferStatusEXT

glActiveTexture
glTexImage3D

glGenBuffers
glBindBuffer
glBufferData
glDeleteBuffers
glMapBuffer
glUnmapBuffer
*/

#ifndef Q_WS_MAC
# ifndef APIENTRYP
#   ifdef APIENTRY
#     define APIENTRYP APIENTRY *
#   else
#     define APIENTRY
#     define APIENTRYP *
#   endif
# endif
#else
# define APIENTRY
# define APIENTRYP *
#endif

#ifndef GL_VERSION_1_2
#define GL_TEXTURE_3D 0x806F
#define GL_TEXTURE_WRAP_R 0x8072
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_BGRA 0x80E1
#endif

#ifndef GL_VERSION_1_3
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE_CUBE_MAP 0x8513
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
//#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
//#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
#endif

#ifndef GL_ARB_vertex_buffer_object
typedef ptrdiff_t GLsizeiptrARB;
#endif

#ifndef GL_VERSION_1_5
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_READ_WRITE 0x88BA
#define GL_STATIC_DRAW 0x88E4
#endif

#ifndef GL_EXT_framebuffer_object
#define GL_RENDERBUFFER_EXT 0x8D41
#define GL_FRAMEBUFFER_EXT 0x8D40
#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
#endif

#ifndef GL_ARB_vertex_shader
#define GL_VERTEX_SHADER_ARB 0x8B31
#endif

#ifndef GL_ARB_fragment_shader
#define GL_FRAGMENT_SHADER_ARB 0x8B30
#endif

#ifndef GL_ARB_shader_objects
typedef char GLcharARB;
typedef unsigned int GLhandleARB;
#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
#endif

typedef GLhandleARB (APIENTRY *_glCreateShaderObjectARB) (GLenum);
typedef void (APIENTRY *_glShaderSourceARB) (GLhandleARB, GLuint, const GLcharARB**, GLint *);
typedef void (APIENTRY *_glCompileShaderARB) (GLhandleARB);
typedef void (APIENTRY *_glGetObjectParameterivARB) (GLhandleARB, GLenum, int *);
typedef void (APIENTRY *_glDeleteObjectARB) (GLhandleARB);
typedef void (APIENTRY *_glGetInfoLogARB) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
typedef GLhandleARB (APIENTRY *_glCreateProgramObjectARB) ();
typedef void (APIENTRY *_glAttachObjectARB) (GLhandleARB, GLhandleARB);
typedef void (APIENTRY *_glDetachObjectARB) (GLhandleARB, GLhandleARB);
typedef void (APIENTRY *_glLinkProgramARB) (GLhandleARB);
typedef void (APIENTRY *_glUseProgramObjectARB) (GLhandleARB);
typedef GLint (APIENTRY *_glGetUniformLocationARB) (GLhandleARB, const GLcharARB *);
typedef void (APIENTRY *_glUniform1iARB) (GLint, GLint);
typedef void (APIENTRY *_glUniform1fARB) (GLint, GLfloat);
typedef void (APIENTRY *_glUniform4fARB) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
typedef void (APIENTRY *_glUniformMatrix4fvARB) (GLint, GLuint, GLboolean, const GLfloat *);

typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *);
typedef void (APIENTRY *_glGenRenderbuffersEXT) (GLsizei, GLuint *);
typedef void (APIENTRY *_glBindRenderbufferEXT) (GLenum, GLuint);
typedef void (APIENTRY *_glRenderbufferStorageEXT) (GLenum, GLenum, GLsizei, GLsizei);
typedef void (APIENTRY *_glDeleteFramebuffersEXT) (GLsizei, const GLuint*);
typedef void (APIENTRY *_glDeleteRenderbuffersEXT) (GLsizei, const GLuint*);
typedef void (APIENTRY *_glBindFramebufferEXT) (GLenum, GLuint);
typedef void (APIENTRY *_glFramebufferTexture2DEXT) (GLenum, GLenum, GLenum, GLuint, GLint);
typedef void (APIENTRY *_glFramebufferRenderbufferEXT) (GLenum, GLenum, GLenum, GLuint);
typedef GLenum (APIENTRY *_glCheckFramebufferStatusEXT) (GLenum);

typedef void (APIENTRY *_glActiveTexture) (GLenum);
typedef void (APIENTRY *_glTexImage3D) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *);

typedef void (APIENTRY *_glGenBuffers) (GLsizei, GLuint *);
typedef void (APIENTRY *_glBindBuffer) (GLenum, GLuint);
typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum);
typedef void (APIENTRY *_glDeleteBuffers) (GLsizei, const GLuint *);
typedef void *(APIENTRY *_glMapBuffer) (GLenum, GLenum);
typedef GLboolean (APIENTRY *_glUnmapBuffer) (GLenum);

struct GLExtensionFunctions
{
	bool resolve(const QGLContext *context);

    bool glslSupported();
    bool fboSupported();
    bool openGL15Supported(); // the rest: multi-texture, 3D-texture, vertex buffer objects

	_glCreateShaderObjectARB CreateShaderObjectARB;
	_glShaderSourceARB ShaderSourceARB;
	_glCompileShaderARB CompileShaderARB;
	_glGetObjectParameterivARB GetObjectParameterivARB;
	_glDeleteObjectARB DeleteObjectARB;
	_glGetInfoLogARB GetInfoLogARB;
	_glCreateProgramObjectARB CreateProgramObjectARB;
	_glAttachObjectARB AttachObjectARB;
	_glDetachObjectARB DetachObjectARB;
	_glLinkProgramARB LinkProgramARB;
	_glUseProgramObjectARB UseProgramObjectARB;
	_glGetUniformLocationARB GetUniformLocationARB;
	_glUniform1iARB Uniform1iARB;
	_glUniform1fARB Uniform1fARB;
	_glUniform4fARB Uniform4fARB;
	_glUniformMatrix4fvARB UniformMatrix4fvARB;

	_glGenFramebuffersEXT GenFramebuffersEXT;
	_glGenRenderbuffersEXT GenRenderbuffersEXT;
	_glBindRenderbufferEXT BindRenderbufferEXT;
	_glRenderbufferStorageEXT RenderbufferStorageEXT;
	_glDeleteFramebuffersEXT DeleteFramebuffersEXT;
	_glDeleteRenderbuffersEXT DeleteRenderbuffersEXT;
	_glBindFramebufferEXT BindFramebufferEXT;
	_glFramebufferTexture2DEXT FramebufferTexture2DEXT;
	_glFramebufferRenderbufferEXT FramebufferRenderbufferEXT;
	_glCheckFramebufferStatusEXT CheckFramebufferStatusEXT;

	_glActiveTexture ActiveTexture;
	_glTexImage3D TexImage3D;

	_glGenBuffers GenBuffers;
	_glBindBuffer BindBuffer;
	_glBufferData BufferData;
	_glDeleteBuffers DeleteBuffers;
	_glMapBuffer MapBuffer;
	_glUnmapBuffer UnmapBuffer;
};

inline GLExtensionFunctions &getGLExtensionFunctions()
{
	static GLExtensionFunctions funcs;
	return funcs;
}

#define glCreateShaderObjectARB getGLExtensionFunctions().CreateShaderObjectARB
#define glShaderSourceARB getGLExtensionFunctions().ShaderSourceARB
#define glCompileShaderARB getGLExtensionFunctions().CompileShaderARB
#define glGetObjectParameterivARB getGLExtensionFunctions().GetObjectParameterivARB
#define glDeleteObjectARB getGLExtensionFunctions().DeleteObjectARB
#define glGetInfoLogARB getGLExtensionFunctions().GetInfoLogARB
#define glCreateProgramObjectARB getGLExtensionFunctions().CreateProgramObjectARB
#define glAttachObjectARB getGLExtensionFunctions().AttachObjectARB
#define glDetachObjectARB getGLExtensionFunctions().DetachObjectARB
#define glLinkProgramARB getGLExtensionFunctions().LinkProgramARB
#define glUseProgramObjectARB getGLExtensionFunctions().UseProgramObjectARB
#define glGetUniformLocationARB getGLExtensionFunctions().GetUniformLocationARB
#define glUniform1iARB getGLExtensionFunctions().Uniform1iARB
#define glUniform1fARB getGLExtensionFunctions().Uniform1fARB
#define glUniform4fARB getGLExtensionFunctions().Uniform4fARB
#define glUniformMatrix4fvARB getGLExtensionFunctions().UniformMatrix4fvARB

#define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT
#define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT
#define glBindRenderbufferEXT getGLExtensionFunctions().BindRenderbufferEXT
#define glRenderbufferStorageEXT getGLExtensionFunctions().RenderbufferStorageEXT
#define glDeleteFramebuffersEXT getGLExtensionFunctions().DeleteFramebuffersEXT
#define glDeleteRenderbuffersEXT getGLExtensionFunctions().DeleteRenderbuffersEXT
#define glBindFramebufferEXT getGLExtensionFunctions().BindFramebufferEXT
#define glFramebufferTexture2DEXT getGLExtensionFunctions().FramebufferTexture2DEXT
#define glFramebufferRenderbufferEXT getGLExtensionFunctions().FramebufferRenderbufferEXT
#define glCheckFramebufferStatusEXT getGLExtensionFunctions().CheckFramebufferStatusEXT

#define glActiveTexture getGLExtensionFunctions().ActiveTexture
#define glTexImage3D getGLExtensionFunctions().TexImage3D

#define glGenBuffers getGLExtensionFunctions().GenBuffers
#define glBindBuffer getGLExtensionFunctions().BindBuffer
#define glBufferData getGLExtensionFunctions().BufferData
#define glDeleteBuffers getGLExtensionFunctions().DeleteBuffers
#define glMapBuffer getGLExtensionFunctions().MapBuffer
#define glUnmapBuffer getGLExtensionFunctions().UnmapBuffer

#endif