1 /*
2  * Copyright (C) 2003-2011 Neverball authors
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14 
15 #ifndef GLEXT_H
16 #define GLEXT_H
17 
18 /*---------------------------------------------------------------------------*/
19 /* Include the system OpenGL headers.                                        */
20 
21 #ifdef _WIN32
22 #define WIN32_LEAN_AND_MEAN
23 #include <windows.h>
24 #endif
25 
26 #ifdef __APPLE__
27 #include <OpenGL/gl.h>
28 #else
29 #include <GL/gl.h>
30 #endif
31 
32 #ifdef _WIN32
33 #include <GL/glext.h>
34 #endif
35 
36 /* Windows calling convention cruft. */
37 
38 #ifndef APIENTRY
39 #define APIENTRY
40 #endif
41 
42 #ifndef APIENTRYP
43 #define APIENTRYP APIENTRY *
44 #endif
45 
46 /*---------------------------------------------------------------------------*/
47 
48 #ifndef GL_MULTISAMPLE
49 #define GL_MULTISAMPLE                0x809D
50 #endif
51 
52 #ifndef GL_TEXTURE0
53 #define GL_TEXTURE0                   0x84C0
54 #endif
55 #ifndef GL_TEXTURE1
56 #define GL_TEXTURE1                   0x84C1
57 #endif
58 #ifndef GL_TEXTURE2
59 #define GL_TEXTURE2                   0x84C2
60 #endif
61 
62 #ifndef GL_ARRAY_BUFFER
63 #define GL_ARRAY_BUFFER               0x8892
64 #endif
65 #ifndef GL_ELEMENT_ARRAY_BUFFER
66 #define GL_ELEMENT_ARRAY_BUFFER       0x8893
67 #endif
68 
69 #ifndef GL_STATIC_DRAW
70 #define GL_STATIC_DRAW                0x88E4
71 #endif
72 #ifndef GL_DYNAMIC_DRAW
73 #define GL_DYNAMIC_DRAW               0x88E8
74 #endif
75 
76 #ifndef GL_POINT_SPRITE
77 #define GL_POINT_SPRITE               0x8861
78 #endif
79 #ifndef GL_COORD_REPLACE
80 #define GL_COORD_REPLACE              0x8862
81 #endif
82 #ifndef GL_POINT_SIZE_MIN
83 #define GL_POINT_SIZE_MIN             0x8126
84 #endif
85 #ifndef GL_POINT_SIZE_MAX
86 #define GL_POINT_SIZE_MAX             0x8127
87 #endif
88 #ifndef GL_POINT_DISTANCE_ATTENUATION
89 #define GL_POINT_DISTANCE_ATTENUATION 0x8129
90 #endif
91 
92 #ifndef GL_SRC0_RGB
93 #define GL_SRC0_RGB                   0x8580
94 #endif
95 #ifndef GL_SRC1_RGB
96 #define GL_SRC1_RGB                   0x8581
97 #endif
98 #ifndef GL_SRC2_RGB
99 #define GL_SRC2_RGB                   0x8582
100 #endif
101 #ifndef GL_SRC0_ALPHA
102 #define GL_SRC0_ALPHA                 0x8588
103 #endif
104 
105 #ifndef GL_DEPTH_STENCIL
106 #define GL_DEPTH_STENCIL              0x84F9
107 #endif
108 #ifndef GL_DEPTH24_STENCIL8
109 #define GL_DEPTH24_STENCIL8           0x88F0
110 #endif
111 #ifndef GL_UNSIGNED_INT_24_8
112 #define GL_UNSIGNED_INT_24_8          0x84FA
113 #endif
114 #ifndef GL_FRAMEBUFFER
115 #define GL_FRAMEBUFFER                0x8D40
116 #endif
117 #ifndef GL_COLOR_ATTACHMENT0
118 #define GL_COLOR_ATTACHMENT0          0x8CE0
119 #endif
120 #ifndef GL_DEPTH_ATTACHMENT
121 #define GL_DEPTH_ATTACHMENT           0x8D00
122 #endif
123 #ifndef GL_STENCIL_ATTACHMENT
124 #define GL_STENCIL_ATTACHMENT         0x8D20
125 #endif
126 #ifndef GL_FRAMEBUFFER_COMPLETE
127 #define GL_FRAMEBUFFER_COMPLETE       0x8CD5
128 #endif
129 
130 #ifndef GL_VERTEX_SHADER
131 #define GL_VERTEX_SHADER              0x8B31
132 #endif
133 #ifndef GL_FRAGMENT_SHADER
134 #define GL_FRAGMENT_SHADER            0x8B30
135 #endif
136 #ifndef GL_LINK_STATUS
137 #define GL_LINK_STATUS                0x8B82
138 #endif
139 #ifndef GL_COMPILE_STATUS
140 #define GL_COMPILE_STATUS             0x8B81
141 #endif
142 #ifndef GL_INFO_LOG_LENGTH
143 #define GL_INFO_LOG_LENGTH            0x8B84
144 #endif
145 
146 /*---------------------------------------------------------------------------*/
147 
148 int glext_check(const char *);
149 int glext_init(void);
150 
151 /*---------------------------------------------------------------------------*/
152 
153 /* Exercise extreme paranoia in defining a cross-platform OpenGL interface.  */
154 /* If we're compiling against OpenGL ES then we must assume native linkage   */
155 /* of the extensions we use. Otherwise, GetProc them regardless of whether   */
156 /* they need it or not.                                                      */
157 
158 #if defined(GL_VERSION_ES_CM_1_0) || \
159     defined(GL_VERSION_ES_CM_1_1) || \
160     defined(GL_OES_VERSION_1_0)
161 
162 #define ENABLE_OPENGLES 1
163 
164 #define glClientActiveTexture_ glClientActiveTexture
165 #define glActiveTexture_       glActiveTexture
166 #define glGenBuffers_          glGenBuffers
167 #define glBindBuffer_          glBindBuffer
168 #define glBufferData_          glBufferData
169 #define glBufferSubData_       glBufferSubData
170 #define glDeleteBuffers_       glDeleteBuffers
171 #define glIsBuffer_            glIsBuffer
172 #define glPointParameterfv_    glPointParameterfv
173 
174 #define glOrtho_               glOrthof
175 
176 #define glStringMarker_(s) ((void) (s))
177 
178 #else /* No native linkage?  Define the extension API. */
179 
180 #define glOrtho_               glOrtho
181 
182 /*---------------------------------------------------------------------------*/
183 /* ARB_multitexture                                                          */
184 
185 typedef void (APIENTRYP PFNGLACTIVETEXTURE_PROC)(GLenum);
186 typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTURE_PROC)(GLenum);
187 
188 extern PFNGLCLIENTACTIVETEXTURE_PROC glClientActiveTexture_;
189 extern PFNGLACTIVETEXTURE_PROC       glActiveTexture_;
190 
191 /*---------------------------------------------------------------------------*/
192 /* ARB_vertex_buffer_object                                                  */
193 
194 typedef void      (APIENTRYP PFNGLGENBUFFERS_PROC)(GLsizei, GLuint *);
195 typedef void      (APIENTRYP PFNGLBINDBUFFER_PROC)(GLenum, GLuint);
196 typedef void      (APIENTRYP PFNGLBUFFERDATA_PROC)(GLenum, long, const GLvoid *, GLenum);
197 typedef void      (APIENTRYP PFNGLBUFFERSUBDATA_PROC)(GLenum, long, long, const GLvoid *);
198 typedef void      (APIENTRYP PFNGLDELETEBUFFERS_PROC)(GLsizei, const GLuint *);
199 typedef GLboolean (APIENTRYP PFNGLISBUFFER_PROC)(GLuint);
200 
201 extern PFNGLGENBUFFERS_PROC    glGenBuffers_;
202 extern PFNGLBINDBUFFER_PROC    glBindBuffer_;
203 extern PFNGLBUFFERDATA_PROC    glBufferData_;
204 extern PFNGLBUFFERSUBDATA_PROC glBufferSubData_;
205 extern PFNGLDELETEBUFFERS_PROC glDeleteBuffers_;
206 extern PFNGLISBUFFER_PROC      glIsBuffer_;
207 
208 /*---------------------------------------------------------------------------*/
209 /* ARB_point_parameters                                                      */
210 
211 typedef void (APIENTRYP PFNGLPOINTPARAMETERFV_PROC)(GLenum, const GLfloat *);
212 typedef void (APIENTRYP PFNGLPOINTPARAMETERF_PROC) (GLenum, const GLfloat);
213 
214 extern PFNGLPOINTPARAMETERFV_PROC glPointParameterfv_;
215 extern PFNGLPOINTPARAMETERF_PROC  glPointParameterf_;
216 
217 /*---------------------------------------------------------------------------*/
218 /* OpenGL Shading Language                                                   */
219 
220 typedef void   (APIENTRYP PFNGLGETSHADERIV_PROC)(GLuint, GLenum, GLint *);
221 typedef void   (APIENTRYP PFNGLGETSHADERINFOLOG_PROC)(GLuint, GLsizei, GLsizei *, char *);
222 typedef void   (APIENTRYP PFNGLGETPROGRAMIV_PROC)(GLuint, GLenum, GLint *);
223 typedef void   (APIENTRYP PFNGLGETPROGRAMINFOLOG_PROC)(GLuint, GLsizei, GLsizei *, char *);
224 typedef GLuint (APIENTRYP PFNGLCREATESHADER_PROC)(GLenum);
225 typedef GLuint (APIENTRYP PFNGLCREATEPROGRAM_PROC)(void);
226 typedef void   (APIENTRYP PFNGLSHADERSOURCE_PROC)(GLuint, GLsizei, const char * const *, const GLint *);
227 typedef void   (APIENTRYP PFNGLCOMPILESHADER_PROC)(GLuint);
228 typedef void   (APIENTRYP PFNGLDELETESHADER_PROC)(GLuint);
229 typedef void   (APIENTRYP PFNGLDELETEPROGRAM_PROC)(GLuint);
230 typedef void   (APIENTRYP PFNGLATTACHSHADER_PROC)(GLuint, GLuint);
231 typedef void   (APIENTRYP PFNGLLINKPROGRAM_PROC)(GLuint);
232 typedef void   (APIENTRYP PFNGLUSEPROGRAM_PROC)(GLuint);
233 typedef GLint  (APIENTRYP PFNGLGETUNIFORMLOCATION_PROC)(GLuint, const char *);
234 typedef void   (APIENTRYP PFNGLUNIFORM1F_PROC)(GLint, GLfloat);
235 typedef void   (APIENTRYP PFNGLUNIFORM2F_PROC)(GLint, GLfloat, GLfloat);
236 typedef void   (APIENTRYP PFNGLUNIFORM3F_PROC)(GLint, GLfloat, GLfloat, GLfloat);
237 typedef void   (APIENTRYP PFNGLUNIFORM4F_PROC)(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
238 
239 extern PFNGLGETSHADERIV_PROC         glGetShaderiv_;
240 extern PFNGLGETSHADERINFOLOG_PROC    glGetShaderInfoLog_;
241 extern PFNGLGETPROGRAMIV_PROC        glGetProgramiv_;
242 extern PFNGLGETPROGRAMINFOLOG_PROC   glGetProgramInfoLog_;
243 extern PFNGLCREATESHADER_PROC        glCreateShader_;
244 extern PFNGLCREATEPROGRAM_PROC       glCreateProgram_;
245 extern PFNGLSHADERSOURCE_PROC        glShaderSource_;
246 extern PFNGLCOMPILESHADER_PROC       glCompileShader_;
247 extern PFNGLDELETESHADER_PROC        glDeleteShader_;
248 extern PFNGLDELETEPROGRAM_PROC       glDeleteProgram_;
249 extern PFNGLATTACHSHADER_PROC        glAttachShader_;
250 extern PFNGLLINKPROGRAM_PROC         glLinkProgram_;
251 extern PFNGLUSEPROGRAM_PROC          glUseProgram_;
252 extern PFNGLGETUNIFORMLOCATION_PROC  glGetUniformLocation_;
253 extern PFNGLUNIFORM1F_PROC           glUniform1f_;
254 extern PFNGLUNIFORM2F_PROC           glUniform2f_;
255 extern PFNGLUNIFORM3F_PROC           glUniform3f_;
256 extern PFNGLUNIFORM4F_PROC           glUniform4f_;
257 
258 /*---------------------------------------------------------------------------*/
259 /* ARB_framebuffer_object                                                    */
260 
261 typedef void (APIENTRYP PFNGLBINDFRAMEBUFFER_PROC)(GLenum, GLuint);
262 typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERS_PROC)(GLsizei, const GLuint *);
263 typedef void (APIENTRYP PFNGLGENFRAMEBUFFERS_PROC)(GLsizei, GLuint *);
264 typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2D_PROC)(GLenum, GLenum, GLenum, GLuint, GLint);
265 typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUS_PROC)(GLenum);
266 
267 extern PFNGLBINDFRAMEBUFFER_PROC        glBindFramebuffer_;
268 extern PFNGLDELETEFRAMEBUFFERS_PROC     glDeleteFramebuffers_;
269 extern PFNGLGENFRAMEBUFFERS_PROC        glGenFramebuffers_;
270 extern PFNGLFRAMEBUFFERTEXTURE2D_PROC   glFramebufferTexture2D_;
271 extern PFNGLCHECKFRAMEBUFFERSTATUS_PROC glCheckFramebufferStatus_;
272 
273 /*---------------------------------------------------------------------------*/
274 /* GREMEDY_string_marker                                                     */
275 
276 typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDY_PROC)(GLsizei, const void *);
277 
278 extern PFNGLSTRINGMARKERGREMEDY_PROC glStringMarkerGREMEDY_;
279 
280 #define glStringMarker_(s)      \
281     if (glStringMarkerGREMEDY_) \
282         glStringMarkerGREMEDY_(0, (s))
283 
284 /*---------------------------------------------------------------------------*/
285 #endif /* !ENABLE_OPENGLES */
286 
287 void glClipPlane4f_(GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
288 
289 /*---------------------------------------------------------------------------*/
290 
291 struct gl_info
292 {
293     GLint max_texture_units;
294     GLint max_texture_size;
295 
296     unsigned int shader_objects     : 1;
297     unsigned int framebuffer_object : 1;
298 };
299 
300 extern struct gl_info gli;
301 
302 /*---------------------------------------------------------------------------*/
303 #endif
304