9672b824843d1cf967fd0bc57db95b4e9f78a9ee
[blender.git] / source / blender / python / generic / bgl.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Willian P. Germano, Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/python/generic/bgl.c
24  *  \ingroup pygen
25  *
26  * This file is the 'bgl' module which wraps OpenGL functions and constants,
27  * allowing script writers to make OpenGL calls in their Python scripts.
28  *
29  * \note
30  * This module is very similar to 'PyOpenGL' which could replace 'bgl' one day.
31  */
32
33 #include <Python.h>
34
35 #include "BLI_utildefines.h"
36
37 #include "GPU_glew.h"
38 #include "MEM_guardedalloc.h"
39
40 #include "bgl.h"
41
42
43 /* -------------------------------------------------------------------- */
44
45 /** \name Local utility defines for wrapping OpenGL
46  * \{ */
47
48 /*@ By golly George! It looks like fancy pants macro time!!! */
49
50
51 /* TYPE_str is the string to pass to Py_ArgParse (for the format) */
52 /* TYPE_var is the name to pass to the GL function */
53 /* TYPE_ref is the pointer to pass to Py_ArgParse (to store in) */
54 /* TYPE_def is the C initialization of the variable */
55
56 #define void_str      ""
57 #define void_var(num)
58 #define void_ref(num)   &bgl_var##num
59 #define void_def(num)   char bgl_var##num
60
61 #if 0
62 #define buffer_str "O!"
63 #define buffer_var(number)  (bgl_buffer##number)->buf.asvoid
64 #define buffer_ref(number)  &BGL_bufferType, &bgl_buffer##number
65 #define buffer_def(number)  Buffer *bgl_buffer##number
66 #endif
67
68 /* GL Pointer fields, handled by buffer type */
69 /* GLdoubleP, GLfloatP, GLintP, GLuintP, GLshortP, GLsizeiP, GLcharP */
70
71 #define GLbooleanP_str      "O!"
72 #define GLbooleanP_var(number)  (bgl_buffer##number)->buf.asvoid
73 #define GLbooleanP_ref(number)  &BGL_bufferType, &bgl_buffer##number
74 #define GLbooleanP_def(number)  Buffer *bgl_buffer##number
75
76 #define GLbyteP_str     "O!"
77 #define GLbyteP_var(number) (bgl_buffer##number)->buf.asvoid
78 #define GLbyteP_ref(number) &BGL_bufferType, &bgl_buffer##number
79 #define GLbyteP_def(number) Buffer *bgl_buffer##number
80
81 #define GLubyteP_str      "O!"
82 #define GLubyteP_var(number)  (bgl_buffer##number)->buf.asvoid
83 #define GLubyteP_ref(number)  &BGL_bufferType, &bgl_buffer##number
84 #define GLubyteP_def(number)  Buffer *bgl_buffer##number
85
86 #define GLintP_str      "O!"
87 #define GLintP_var(number)  (bgl_buffer##number)->buf.asvoid
88 #define GLintP_ref(number)  &BGL_bufferType, &bgl_buffer##number
89 #define GLintP_def(number)  Buffer *bgl_buffer##number
90
91 #define GLint64P_str      "O!"
92 #define GLint64P_var(number)  (bgl_buffer##number)->buf.asvoid
93 #define GLint64P_ref(number)  &BGL_bufferType, &bgl_buffer##number
94 #define GLint64P_def(number)  Buffer *bgl_buffer##number
95
96 #define GLenumP_str      "O!"
97 #define GLenumP_var(number)  (bgl_buffer##number)->buf.asvoid
98 #define GLenumP_ref(number)  &BGL_bufferType, &bgl_buffer##number
99 #define GLenumP_def(number)  Buffer *bgl_buffer##number
100
101 #define GLuintP_str     "O!"
102 #define GLuintP_var(number) (bgl_buffer##number)->buf.asvoid
103 #define GLuintP_ref(number) &BGL_bufferType, &bgl_buffer##number
104 #define GLuintP_def(number) Buffer *bgl_buffer##number
105
106 #if 0
107 #define GLuint64P_str     "O!"
108 #define GLuint64P_var(number) (bgl_buffer##number)->buf.asvoid
109 #define GLuint64P_ref(number) &BGL_bufferType, &bgl_buffer##number
110 #define GLuint64P_def(number) Buffer *bgl_buffer##number
111 #endif
112
113 #define GLshortP_str      "O!"
114 #define GLshortP_var(number)  (bgl_buffer##number)->buf.asvoid
115 #define GLshortP_ref(number)  &BGL_bufferType, &bgl_buffer##number
116 #define GLshortP_def(number)  Buffer *bgl_buffer##number
117
118 #define GLushortP_str     "O!"
119 #define GLushortP_var(number) (bgl_buffer##number)->buf.asvoid
120 #define GLushortP_ref(number) &BGL_bufferType, &bgl_buffer##number
121 #define GLushortP_def(number) Buffer *bgl_buffer##number
122
123 #define GLfloatP_str      "O!"
124 #define GLfloatP_var(number)  (bgl_buffer##number)->buf.asvoid
125 #define GLfloatP_ref(number)  &BGL_bufferType, &bgl_buffer##number
126 #define GLfloatP_def(number)  Buffer *bgl_buffer##number
127
128 #define GLdoubleP_str     "O!"
129 #define GLdoubleP_var(number) (bgl_buffer##number)->buf.asvoid
130 #define GLdoubleP_ref(number) &BGL_bufferType, &bgl_buffer##number
131 #define GLdoubleP_def(number) Buffer *bgl_buffer##number
132
133 #if 0
134 #define GLclampfP_str     "O!"
135 #define GLclampfP_var(number) (bgl_buffer##number)->buf.asvoid
136 #define GLclampfP_ref(number) &BGL_bufferType, &bgl_buffer##number
137 #define GLclampfP_def(number) Buffer *bgl_buffer##number
138 #endif
139
140 #define GLvoidP_str     "O!"
141 #define GLvoidP_var(number) (bgl_buffer##number)->buf.asvoid
142 #define GLvoidP_ref(number) &BGL_bufferType, &bgl_buffer##number
143 #define GLvoidP_def(number) Buffer *bgl_buffer##number
144
145 #define GLsizeiP_str     "O!"
146 #define GLsizeiP_var(number) (bgl_buffer##number)->buf.asvoid
147 #define GLsizeiP_ref(number) &BGL_bufferType, &bgl_buffer##number
148 #define GLsizeiP_def(number) Buffer *bgl_buffer##number
149
150 #define GLcharP_str     "O!"
151 #define GLcharP_var(number) (bgl_buffer##number)->buf.asvoid
152 #define GLcharP_ref(number) &BGL_bufferType, &bgl_buffer##number
153 #define GLcharP_def(number) Buffer *bgl_buffer##number
154
155 #if 0
156 #define buffer_str      "O!"
157 #define buffer_var(number)  (bgl_buffer##number)->buf.asvoid
158 #define buffer_ref(number)  &BGL_bufferType, &bgl_buffer##number
159 #define buffer_def(number)  Buffer *bgl_buffer##number
160 #endif
161
162 /*@The standard GL typedefs are used as prototypes, we can't
163  * use the GL type directly because Py_ArgParse expects normal
164  * C types.
165  *
166  * Py_ArgParse doesn't grok writing into unsigned variables,
167  * so we use signed everything (even stuff that should be unsigned.
168  */
169
170 /* typedef unsigned int GLenum; */
171 #define GLenum_str      "i"
172 #define GLenum_var(num)   bgl_var##num
173 #define GLenum_ref(num)   &bgl_var##num
174 #define GLenum_def(num)   /* unsigned */ int GLenum_var(num)
175
176 /* typedef unsigned int GLboolean; */
177 #define GLboolean_str     "b"
178 #define GLboolean_var(num)    bgl_var##num
179 #define GLboolean_ref(num)    &bgl_var##num
180 #define GLboolean_def(num)    /* unsigned */ char GLboolean_var(num)
181
182 /* typedef unsigned int GLbitfield; */
183 #define GLbitfield_str      "i"
184 #define GLbitfield_var(num)   bgl_var##num
185 #define GLbitfield_ref(num)   &bgl_var##num
186 #define GLbitfield_def(num)   /* unsigned */ int GLbitfield_var(num)
187
188 #if 0
189 /* typedef signed char GLbyte; */
190 #define GLbyte_str        "b"
191 #define GLbyte_var(num)     bgl_var##num
192 #define GLbyte_ref(num)     &bgl_var##num
193 #define GLbyte_def(num)     signed char GLbyte_var(num)
194 #endif
195
196 /* typedef short GLshort; */
197 #define GLshort_str       "h"
198 #define GLshort_var(num)    bgl_var##num
199 #define GLshort_ref(num)    &bgl_var##num
200 #define GLshort_def(num)    short GLshort_var(num)
201
202 /* typedef int GLint; */
203 #define GLint_str       "i"
204 #define GLint_var(num)      bgl_var##num
205 #define GLint_ref(num)      &bgl_var##num
206 #define GLint_def(num)      int GLint_var(num)
207
208 /* typedef int GLsizei; */
209 #define GLsizei_str       "n"
210 #define GLsizei_var(num)    bgl_var##num
211 #define GLsizei_ref(num)    &bgl_var##num
212 #define GLsizei_def(num)    size_t GLsizei_var(num)
213
214 /* typedef int GLsizeiptr; */
215 #define GLsizeiptr_str       "n"
216 #define GLsizeiptr_var(num)    bgl_var##num
217 #define GLsizeiptr_ref(num)    &bgl_var##num
218 #define GLsizeiptr_def(num)    size_t GLsizeiptr_var(num)
219
220 /* typedef int GLintptr; */
221 #define GLintptr_str       "n"
222 #define GLintptr_var(num)    bgl_var##num
223 #define GLintptr_ref(num)    &bgl_var##num
224 #define GLintptr_def(num)    size_t GLintptr_var(num)
225
226 /* typedef unsigned char GLubyte; */
227 #define GLubyte_str       "B"
228 #define GLubyte_var(num)    bgl_var##num
229 #define GLubyte_ref(num)    &bgl_var##num
230 #define GLubyte_def(num)    /* unsigned */ char GLubyte_var(num)
231
232 #if 0
233 /* typedef unsigned short GLushort; */
234 #define GLushort_str      "H"
235 #define GLushort_var(num)   bgl_var##num
236 #define GLushort_ref(num)   &bgl_var##num
237 #define GLushort_def(num)   /* unsigned */ short GLushort_var(num)
238 #endif
239
240 /* typedef unsigned int GLuint; */
241 #define GLuint_str        "I"
242 #define GLuint_var(num)     bgl_var##num
243 #define GLuint_ref(num)     &bgl_var##num
244 #define GLuint_def(num)     /* unsigned */ int GLuint_var(num)
245
246 /* typedef unsigned int GLuint64; */
247 #if 0
248 #define GLuint64_str        "Q"
249 #define GLuint64_var(num)     bgl_var##num
250 #define GLuint64_ref(num)     &bgl_var##num
251 #define GLuint64_def(num)     /* unsigned */ int GLuint64_var(num)
252 #endif
253
254 /* typedef unsigned int GLsync; */
255 #if 0
256 #define GLsync_str        "I"
257 #define GLsync_var(num)     bgl_var##num
258 #define GLsync_ref(num)     &bgl_var##num
259 #define GLsync_def(num)     /* unsigned */ int GLsync_var(num)
260 #endif
261
262 /* typedef float GLfloat; */
263 #define GLfloat_str       "f"
264 #define GLfloat_var(num)    bgl_var##num
265 #define GLfloat_ref(num)    &bgl_var##num
266 #define GLfloat_def(num)    float GLfloat_var(num)
267
268 /* typedef char *GLstring; */
269 #define GLstring_str     "s"
270 #define GLstring_var(number) bgl_var##number
271 #define GLstring_ref(number) &bgl_var##number
272 #define GLstring_def(number) char *GLstring_var(number)
273
274 /* typedef float GLclampf; */
275 #if 0
276 #define GLclampf_str      "f"
277 #define GLclampf_var(num)   bgl_var##num
278 #define GLclampf_ref(num)   &bgl_var##num
279 #define GLclampf_def(num)   float GLclampf_var(num)
280 #endif
281
282 /* typedef double GLdouble; */
283 #define GLdouble_str      "d"
284 #define GLdouble_var(num)   bgl_var##num
285 #define GLdouble_ref(num)   &bgl_var##num
286 #define GLdouble_def(num)   double GLdouble_var(num)
287
288 /* typedef double GLclampd; */
289 #if 0
290 #define GLclampd_str      "d"
291 #define GLclampd_var(num)   bgl_var##num
292 #define GLclampd_ref(num)   &bgl_var##num
293 #define GLclampd_def(num)   double GLclampd_var(num)
294 #endif
295
296 #define _arg_def1(a1) \
297                    a1##_def(1)
298 #define _arg_def2(a1, a2) \
299         _arg_def1(a1); a2##_def(2)
300 #define _arg_def3(a1, a2, a3) \
301         _arg_def2(a1, a2); a3##_def(3)
302 #define _arg_def4(a1, a2, a3, a4) \
303         _arg_def3(a1, a2, a3); a4##_def(4)
304 #define _arg_def5(a1, a2, a3, a4, a5) \
305         _arg_def4(a1, a2, a3, a4); a5##_def(5)
306 #define _arg_def6(a1, a2, a3, a4, a5, a6) \
307         _arg_def5(a1, a2, a3, a4, a5); a6##_def(6)
308 #define _arg_def7(a1, a2, a3, a4, a5, a6, a7) \
309         _arg_def6(a1, a2, a3, a4, a5, a6); a7##_def(7)
310 #define _arg_def8(a1, a2, a3, a4, a5, a6, a7, a8) \
311         _arg_def7(a1, a2, a3, a4, a5, a6, a7); a8##_def(8)
312 #define _arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
313         _arg_def8(a1, a2, a3, a4, a5, a6, a7, a8); a9##_def(9)
314 #define _arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
315         _arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9); a10##_def(10)
316 #define _arg_def11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
317         _arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); a11##_def(11)
318 #define  arg_def(...) VA_NARGS_CALL_OVERLOAD(_arg_def, __VA_ARGS__)
319
320 #define _arg_var1(a1) \
321                 a1##_var(1)
322 #define _arg_var2(a1, a2) \
323         _arg_var1(a1), a2##_var(2)
324 #define _arg_var3(a1, a2, a3) \
325         _arg_var2(a1, a2), a3##_var(3)
326 #define _arg_var4(a1, a2, a3, a4) \
327         _arg_var3(a1, a2, a3), a4##_var(4)
328 #define _arg_var5(a1, a2, a3, a4, a5) \
329         _arg_var4(a1, a2, a3, a4), a5##_var(5)
330 #define _arg_var6(a1, a2, a3, a4, a5, a6) \
331         _arg_var5(a1, a2, a3, a4, a5), a6##_var(6)
332 #define _arg_var7(a1, a2, a3, a4, a5, a6, a7) \
333         _arg_var6(a1, a2, a3, a4, a5, a6), a7##_var(7)
334 #define _arg_var8(a1, a2, a3, a4, a5, a6, a7, a8) \
335         _arg_var7(a1, a2, a3, a4, a5, a6, a7), a8##_var(8)
336 #define _arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
337         _arg_var8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_var(9)
338 #define _arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
339         _arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_var(10)
340 #define _arg_var11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
341         _arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), a11##_var(11)
342 #define  arg_var(...) VA_NARGS_CALL_OVERLOAD(_arg_var, __VA_ARGS__)
343
344 #define _arg_ref1(a1) \
345                    a1##_ref(1)
346 #define _arg_ref2(a1, a2) \
347         _arg_ref1(a1), a2##_ref(2)
348 #define _arg_ref3(a1, a2, a3) \
349         _arg_ref2(a1, a2), a3##_ref(3)
350 #define _arg_ref4(a1, a2, a3, a4) \
351         _arg_ref3(a1, a2, a3), a4##_ref(4)
352 #define _arg_ref5(a1, a2, a3, a4, a5) \
353         _arg_ref4(a1, a2, a3, a4), a5##_ref(5)
354 #define _arg_ref6(a1, a2, a3, a4, a5, a6) \
355         _arg_ref5(a1, a2, a3, a4, a5), a6##_ref(6)
356 #define _arg_ref7(a1, a2, a3, a4, a5, a6, a7) \
357         _arg_ref6(a1, a2, a3, a4, a5, a6), a7##_ref(7)
358 #define _arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8) \
359         _arg_ref7(a1, a2, a3, a4, a5, a6, a7), a8##_ref(8)
360 #define _arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
361         _arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_ref(9)
362 #define _arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
363         _arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_ref(10)
364 #define _arg_ref11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
365         _arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), a11##_ref(11)
366 #define  arg_ref(...) VA_NARGS_CALL_OVERLOAD(_arg_ref, __VA_ARGS__)
367
368 #define _arg_str1(a1) \
369                   a1##_str
370 #define _arg_str2(a1, a2) \
371         _arg_str1(a1) a2##_str
372 #define _arg_str3(a1, a2, a3) \
373         _arg_str2(a1, a2) a3##_str
374 #define _arg_str4(a1, a2, a3, a4) \
375         _arg_str3(a1, a2, a3) a4##_str
376 #define _arg_str5(a1, a2, a3, a4, a5) \
377         _arg_str4(a1, a2, a3, a4) a5##_str
378 #define _arg_str6(a1, a2, a3, a4, a5, a6) \
379         _arg_str5(a1, a2, a3, a4, a5) a6##_str
380 #define _arg_str7(a1, a2, a3, a4, a5, a6, a7) \
381         _arg_str6(a1, a2, a3, a4, a5, a6) a7##_str
382 #define _arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) \
383         _arg_str7(a1, a2, a3, a4, a5, a6, a7) a8##_str
384 #define _arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
385         _arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) a9##_str
386 #define _arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
387         _arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) a10##_str
388 #define _arg_str11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
389         _arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) a11##_str
390 #define  arg_str(...) VA_NARGS_CALL_OVERLOAD(_arg_str, __VA_ARGS__)
391
392 #define ret_def_void
393 #define ret_set_void
394 #define ret_ret_void    return Py_INCREF(Py_None), Py_None
395
396 #define ret_def_GLint   int ret_int
397 #define ret_set_GLint   ret_int =
398 #define ret_ret_GLint   return PyLong_FromLong(ret_int)
399
400 #define ret_def_GLuint    unsigned int ret_uint
401 #define ret_set_GLuint    ret_uint =
402 #define ret_ret_GLuint    return PyLong_FromLong((long) ret_uint)
403
404 #if 0
405 #define ret_def_GLsizei   size_t ret_size_t
406 #define ret_set_GLsizei   ret_size_t =
407 #define ret_ret_GLsizei   return PyLong_FromSsize_t(ret_size_t)
408 #endif
409
410 #if 0
411 #define ret_def_GLsync    unsigned int ret_sync
412 #define ret_set_GLsync    ret_sync =
413 #define ret_ret_GLsync    return PyLong_FromLong((long) ret_sync)
414 #endif
415
416 #define ret_def_GLenum    unsigned int ret_uint
417 #define ret_set_GLenum    ret_uint =
418 #define ret_ret_GLenum    return PyLong_FromLong((long) ret_uint)
419
420 #define ret_def_GLboolean unsigned char ret_bool
421 #define ret_set_GLboolean ret_bool =
422 #define ret_ret_GLboolean return PyLong_FromLong((long) ret_bool)
423
424 #define ret_def_GLstring  const unsigned char *ret_str
425 #define ret_set_GLstring  ret_str =
426
427 #define ret_ret_GLstring                                                      \
428         if (ret_str) {                                                            \
429                 return PyUnicode_FromString((const char *)ret_str);                   \
430         }                                                                         \
431         else {                                                                    \
432                 PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \
433                 return NULL;                                                          \
434         }                                                                         \
435
436 /** \} */
437
438
439 /* -------------------------------------------------------------------- */
440 /* Forward Declarations */
441
442 static PyObject *Buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
443 static PyObject *Method_ShaderSource(PyObject *self, PyObject *args);
444
445 /* Buffer sequence methods */
446
447 static int Buffer_len(Buffer *self);
448 static PyObject *Buffer_item(Buffer *self, int i);
449 static PyObject *Buffer_slice(Buffer *self, int begin, int end);
450 static int Buffer_ass_item(Buffer *self, int i, PyObject *v);
451 static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq);
452 static PyObject *Buffer_subscript(Buffer *self, PyObject *item);
453 static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value);
454
455
456 /* -------------------------------------------------------------------- */
457
458 /** \name Utility Functions
459  * \{ */
460
461
462 int BGL_typeSize(int type)
463 {
464         switch (type) {
465                 case GL_BYTE:
466                         return sizeof(char);
467                 case GL_SHORT:
468                         return sizeof(short);
469                 case GL_INT:
470                         return sizeof(int);
471                 case GL_FLOAT:
472                         return sizeof(float);
473                 case GL_DOUBLE:
474                         return sizeof(double);
475         }
476         return -1;
477 }
478
479 static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer)
480 {
481         char *typestr = pybuffer->format;
482         Py_ssize_t itemsize = pybuffer->itemsize;
483
484         if (ELEM(typestr[0], '<', '>', '|')) {
485                 typestr += 1;
486         }
487
488         switch (typestr[0]) {
489                 case 't':
490                 case 'b':
491                 case 'h':
492                 case 'i':
493                 case 'l':
494                         if (itemsize == 1) return GL_BYTE;
495                         if (itemsize == 2) return GL_SHORT;
496                         if (itemsize == 4) return GL_INT;
497                         break;
498                 case 'f':
499                 case 'd':
500                         if (itemsize == 4) return GL_FLOAT;
501                         if (itemsize == 8) return GL_DOUBLE;
502                         break;
503         }
504         return -1; /* UNKNOWN */
505 }
506
507 static bool compare_dimensions(int ndim, int *dim1, Py_ssize_t *dim2)
508 {
509         for (int i = 0; i < ndim; i++) {
510                 if (dim1[i] != dim2[i]) {
511                         return false;
512                 }
513         }
514         return true;
515 }
516
517 /** \} */
518
519
520 /* -------------------------------------------------------------------- */
521
522 /** \name Buffer API
523  * \{ */
524
525 static PySequenceMethods Buffer_SeqMethods = {
526         (lenfunc) Buffer_len,                       /*sq_length */
527         (binaryfunc) NULL,                          /*sq_concat */
528         (ssizeargfunc) NULL,                        /*sq_repeat */
529         (ssizeargfunc) Buffer_item,                 /*sq_item */
530         (ssizessizeargfunc) NULL,                   /*sq_slice, deprecated, handled in Buffer_item */
531         (ssizeobjargproc) Buffer_ass_item,          /*sq_ass_item */
532         (ssizessizeobjargproc) NULL,                /*sq_ass_slice, deprecated handled in Buffer_ass_item */
533         (objobjproc) NULL,                          /* sq_contains */
534         (binaryfunc) NULL,                          /* sq_inplace_concat */
535         (ssizeargfunc) NULL,                        /* sq_inplace_repeat */
536 };
537
538
539 static PyMappingMethods Buffer_AsMapping = {
540         (lenfunc)Buffer_len,
541         (binaryfunc)Buffer_subscript,
542         (objobjargproc)Buffer_ass_subscript
543 };
544
545 static void Buffer_dealloc(Buffer *self);
546 static PyObject *Buffer_repr(Buffer *self);
547
548 static PyObject *Buffer_to_list(Buffer *self)
549 {
550         int i, len = self->dimensions[0];
551         PyObject *list = PyList_New(len);
552
553         for (i = 0; i < len; i++) {
554                 PyList_SET_ITEM(list, i, Buffer_item(self, i));
555         }
556
557         return list;
558 }
559
560 static PyObject *Buffer_to_list_recursive(Buffer *self)
561 {
562         PyObject *list;
563
564         if (self->ndimensions > 1) {
565                 int i, len = self->dimensions[0];
566                 list = PyList_New(len);
567
568                 for (i = 0; i < len; i++) {
569                         Buffer *sub = (Buffer *)Buffer_item(self, i);
570                         PyList_SET_ITEM(list, i, Buffer_to_list_recursive(sub));
571                         Py_DECREF(sub);
572                 }
573         }
574         else {
575                 list = Buffer_to_list(self);
576         }
577
578         return list;
579 }
580
581 static PyObject *Buffer_dimensions(Buffer *self, void *UNUSED(arg))
582 {
583         PyObject *list = PyList_New(self->ndimensions);
584         int i;
585
586         for (i = 0; i < self->ndimensions; i++) {
587                 PyList_SET_ITEM(list, i, PyLong_FromLong(self->dimensions[i]));
588         }
589
590         return list;
591 }
592
593 static PyMethodDef Buffer_methods[] = {
594         {"to_list", (PyCFunction)Buffer_to_list_recursive, METH_NOARGS,
595          "return the buffer as a list"},
596         {NULL, NULL, 0, NULL}
597 };
598
599 static PyGetSetDef Buffer_getseters[] = {
600         {(char *)"dimensions", (getter)Buffer_dimensions, NULL, NULL, NULL},
601         {NULL, NULL, NULL, NULL, NULL}
602 };
603
604
605 PyTypeObject BGL_bufferType = {
606         PyVarObject_HEAD_INIT(NULL, 0)
607         "bgl.Buffer",               /*tp_name */
608         sizeof(Buffer),             /*tp_basicsize */
609         0,                          /*tp_itemsize */
610         (destructor)Buffer_dealloc, /*tp_dealloc */
611         (printfunc)NULL,            /*tp_print */
612         NULL,                       /*tp_getattr */
613         NULL,                       /*tp_setattr */
614         NULL,                       /*tp_compare */
615         (reprfunc) Buffer_repr,     /*tp_repr */
616         NULL,                       /*tp_as_number */
617         &Buffer_SeqMethods,         /*tp_as_sequence */
618         &Buffer_AsMapping,          /* PyMappingMethods *tp_as_mapping; */
619
620         /* More standard operations (here for binary compatibility) */
621
622         NULL, /* hashfunc tp_hash; */
623         NULL,                       /* ternaryfunc tp_call; */
624         NULL,                       /* reprfunc tp_str; */
625         NULL,                       /* getattrofunc tp_getattro; */
626         NULL,                       /* setattrofunc tp_setattro; */
627
628         /* Functions to access object as input/output buffer */
629         NULL,                       /* PyBufferProcs *tp_as_buffer; */
630
631         /*** Flags to define presence of optional/expanded features ***/
632         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
633
634         NULL,                       /*  char *tp_doc;  Documentation string */
635         /*** Assigned meaning in release 2.0 ***/
636         /* call function for all accessible objects */
637         NULL,                       /* traverseproc tp_traverse; */
638
639         /* delete references to contained objects */
640         NULL,                       /* inquiry tp_clear; */
641
642         /***  Assigned meaning in release 2.1 ***/
643         /*** rich comparisons ***/
644         NULL,                       /* richcmpfunc tp_richcompare; */
645
646         /***  weak reference enabler ***/
647         0,                          /* long tp_weaklistoffset; */
648
649         /*** Added in release 2.2 ***/
650         /*   Iterators */
651         NULL, /* getiterfunc tp_iter; */
652         NULL,                       /* iternextfunc tp_iternext; */
653         /*** Attribute descriptor and subclassing stuff ***/
654         Buffer_methods,             /* struct PyMethodDef *tp_methods; */
655         NULL,                       /* struct PyMemberDef *tp_members; */
656         Buffer_getseters,           /* struct PyGetSetDef *tp_getset; */
657         NULL,                       /*tp_base*/
658         NULL,                       /*tp_dict*/
659         NULL,                       /*tp_descr_get*/
660         NULL,                       /*tp_descr_set*/
661         0,                          /*tp_dictoffset*/
662         NULL,                       /*tp_init*/
663         NULL,                       /*tp_alloc*/
664         Buffer_new,                 /*tp_new*/
665         NULL,                       /*tp_free*/
666         NULL,                       /*tp_is_gc*/
667         NULL,                       /*tp_bases*/
668         NULL,                       /*tp_mro*/
669         NULL,                       /*tp_cache*/
670         NULL,                       /*tp_subclasses*/
671         NULL,                       /*tp_weaklist*/
672         NULL                        /*tp_del*/
673 };
674
675
676 static Buffer *BGL_MakeBuffer_FromData(PyObject *parent, int type, int ndimensions, int *dimensions, void *buf)
677 {
678         Buffer *buffer = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType);
679
680         Py_XINCREF(parent);
681         buffer->parent = parent;
682         buffer->ndimensions = ndimensions;
683         buffer->dimensions = MEM_mallocN(ndimensions * sizeof(int), "Buffer dimensions");
684         memcpy(buffer->dimensions, dimensions, ndimensions * sizeof(int));
685         buffer->type = type;
686         buffer->buf.asvoid = buf;
687
688         return buffer;
689 }
690
691 /**
692  * Create a buffer object
693  *
694  * \param dimensions: An array of ndimensions integers representing the size of each dimension.
695  * \param initbuffer: When not NULL holds a contiguous buffer
696  * with the correct format from which the buffer will be initialized
697  */
698 Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuffer)
699 {
700         Buffer *buffer;
701         void *buf = NULL;
702         int i, size = BGL_typeSize(type);
703
704         for (i = 0; i < ndimensions; i++) {
705                 size *= dimensions[i];
706         }
707
708         buf = MEM_mallocN(size, "Buffer buffer");
709
710         buffer = BGL_MakeBuffer_FromData(NULL, type, ndimensions, dimensions, buf);
711
712         if (initbuffer) {
713                 memcpy(buffer->buf.asvoid, initbuffer, size);
714         }
715         else {
716                 memset(buffer->buf.asvoid, 0, size);
717         }
718         return buffer;
719 }
720
721
722 #define MAX_DIMENSIONS  256
723 static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
724 {
725         PyObject *length_ob = NULL, *init = NULL;
726         Buffer *buffer = NULL;
727         int dimensions[MAX_DIMENSIONS];
728
729         int type;
730         Py_ssize_t i, ndimensions = 0;
731
732         if (kwds && PyDict_Size(kwds)) {
733                 PyErr_SetString(PyExc_TypeError,
734                                 "bgl.Buffer(): takes no keyword args");
735                 return NULL;
736         }
737
738         if (!PyArg_ParseTuple(args, "iO|O: bgl.Buffer", &type, &length_ob, &init)) {
739                 return NULL;
740         }
741         if (!ELEM(type, GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE)) {
742                 PyErr_SetString(PyExc_AttributeError,
743                                 "invalid first argument type, should be one of "
744                                 "GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE");
745                 return NULL;
746         }
747
748         if (PyLong_Check(length_ob)) {
749                 ndimensions = 1;
750                 if (((dimensions[0] = PyLong_AsLong(length_ob)) < 1)) {
751                         PyErr_SetString(PyExc_AttributeError,
752                                         "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
753                         return NULL;
754                 }
755         }
756         else if (PySequence_Check(length_ob)) {
757                 ndimensions = PySequence_Size(length_ob);
758                 if (ndimensions > MAX_DIMENSIONS) {
759                         PyErr_SetString(PyExc_AttributeError,
760                                         "too many dimensions, max is "STRINGIFY(MAX_DIMENSIONS));
761                         return NULL;
762                 }
763                 else if (ndimensions < 1) {
764                         PyErr_SetString(PyExc_AttributeError,
765                                         "sequence must have at least one dimension");
766                         return NULL;
767                 }
768                 for (i = 0; i < ndimensions; i++) {
769                         PyObject *ob = PySequence_GetItem(length_ob, i);
770
771                         if (!PyLong_Check(ob))
772                                 dimensions[i] = 1;
773                         else
774                                 dimensions[i] = PyLong_AsLong(ob);
775                         Py_DECREF(ob);
776
777                         if (dimensions[i] < 1) {
778                                 PyErr_SetString(PyExc_AttributeError,
779                                                 "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
780                                 return NULL;
781                         }
782                 }
783         }
784         else {
785                 PyErr_Format(PyExc_TypeError,
786                              "invalid second argument argument expected a sequence "
787                              "or an int, not a %.200s", Py_TYPE(length_ob)->tp_name);
788                 return NULL;
789         }
790
791         if (init && PyObject_CheckBuffer(init)) {
792                 Py_buffer pybuffer;
793
794                 if (PyObject_GetBuffer(init, &pybuffer, PyBUF_ND | PyBUF_FORMAT) == -1) {
795                         /* PyObject_GetBuffer raise a PyExc_BufferError */
796                         return NULL;
797                 }
798
799                 if (type != gl_buffer_type_from_py_buffer(&pybuffer)) {
800                         PyErr_Format(PyExc_TypeError,
801                                      "`GL_TYPE` and `typestr` of object with buffer interface do not match. '%s'", pybuffer.format);
802                 }
803                 else if (ndimensions != pybuffer.ndim ||
804                          !compare_dimensions(ndimensions, dimensions, pybuffer.shape))
805                 {
806                         PyErr_Format(PyExc_TypeError, "array size does not match");
807                 }
808                 else {
809                         buffer = BGL_MakeBuffer_FromData(init, type, pybuffer.ndim, dimensions, pybuffer.buf);
810                 }
811
812                 PyBuffer_Release(&pybuffer);
813         }
814         else {
815                 buffer = BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
816                 if (init && Buffer_ass_slice(buffer, 0, dimensions[0], init)) {
817                         Py_DECREF(buffer);
818                         return NULL;
819                 }
820         }
821
822         return (PyObject *)buffer;
823 }
824
825 /* Buffer sequence methods */
826
827 static int Buffer_len(Buffer *self)
828 {
829         return self->dimensions[0];
830 }
831
832 static PyObject *Buffer_item(Buffer *self, int i)
833 {
834         if (i >= self->dimensions[0] || i < 0) {
835                 PyErr_SetString(PyExc_IndexError, "array index out of range");
836                 return NULL;
837         }
838
839         if (self->ndimensions == 1) {
840                 switch (self->type) {
841                         case GL_BYTE:   return Py_BuildValue("b", self->buf.asbyte[i]);
842                         case GL_SHORT:  return Py_BuildValue("h", self->buf.asshort[i]);
843                         case GL_INT:    return Py_BuildValue("i", self->buf.asint[i]);
844                         case GL_FLOAT:  return PyFloat_FromDouble(self->buf.asfloat[i]);
845                         case GL_DOUBLE: return Py_BuildValue("d", self->buf.asdouble[i]);
846                 }
847         }
848         else {
849                 int j, offset = i * BGL_typeSize(self->type);
850
851                 for (j = 1; j < self->ndimensions; j++) {
852                         offset *= self->dimensions[j];
853                 }
854
855                 return (PyObject *)BGL_MakeBuffer_FromData(
856                         (PyObject *)self, self->type,
857                         self->ndimensions - 1,
858                         self->dimensions + 1,
859                         self->buf.asbyte + offset);
860         }
861
862         return NULL;
863 }
864
865 static PyObject *Buffer_slice(Buffer *self, int begin, int end)
866 {
867         PyObject *list;
868         int count;
869         
870         if (begin < 0) begin = 0;
871         if (end > self->dimensions[0]) end = self->dimensions[0];
872         if (begin > end) begin = end;
873
874         list = PyList_New(end - begin);
875
876         for (count = begin; count < end; count++) {
877                 PyList_SET_ITEM(list, count - begin, Buffer_item(self, count));
878         }
879         return list;
880 }
881
882 static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
883 {
884         if (i >= self->dimensions[0] || i < 0) {
885                 PyErr_SetString(PyExc_IndexError,
886                                 "array assignment index out of range");
887                 return -1;
888         }
889
890         if (self->ndimensions != 1) {
891                 Buffer *row = (Buffer *)Buffer_item(self, i);
892
893                 if (row) {
894                         int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v);
895                         Py_DECREF(row);
896                         return ret;
897                 }
898                 else {
899                         return -1;
900                 }
901         }
902
903         switch (self->type) {
904                 case GL_BYTE:   return PyArg_Parse(v, "b:Expected ints",   &self->buf.asbyte[i])   ? 0 : -1;
905                 case GL_SHORT:  return PyArg_Parse(v, "h:Expected ints",   &self->buf.asshort[i])  ? 0 : -1;
906                 case GL_INT:    return PyArg_Parse(v, "i:Expected ints",   &self->buf.asint[i])    ? 0 : -1;
907                 case GL_FLOAT:  return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i])  ? 0 : -1;
908                 case GL_DOUBLE: return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0 : -1;
909                 default:        return 0; /* should never happen */
910         }
911 }
912
913 static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
914 {
915         PyObject *item;
916         int count, err = 0;
917         
918         if (begin < 0) begin = 0;
919         if (end > self->dimensions[0]) end = self->dimensions[0];
920         if (begin > end) begin = end;
921         
922         if (!PySequence_Check(seq)) {
923                 PyErr_Format(PyExc_TypeError,
924                              "buffer[:] = value, invalid assignment. "
925                              "Expected a sequence, not an %.200s type",
926                              Py_TYPE(seq)->tp_name);
927                 return -1;
928         }
929
930         /* re-use count var */
931         if ((count = PySequence_Size(seq)) != (end - begin)) {
932                 PyErr_Format(PyExc_TypeError,
933                              "buffer[:] = value, size mismatch in assignment. "
934                              "Expected: %d (given: %d)", count, end - begin);
935                 return -1;
936         }
937         
938         for (count = begin; count < end; count++) {
939                 item = PySequence_GetItem(seq, count - begin);
940                 if (item) {
941                         err = Buffer_ass_item(self, count, item);
942                         Py_DECREF(item);
943                 }
944                 else {
945                         err = -1;
946                 }
947                 if (err) {
948                         break;
949                 }
950         }
951         return err;
952 }
953
954 static PyObject *Buffer_subscript(Buffer *self, PyObject *item)
955 {
956         if (PyIndex_Check(item)) {
957                 Py_ssize_t i;
958                 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
959                 if (i == -1 && PyErr_Occurred())
960                         return NULL;
961                 if (i < 0)
962                         i += self->dimensions[0];
963                 return Buffer_item(self, i);
964         }
965         else if (PySlice_Check(item)) {
966                 Py_ssize_t start, stop, step, slicelength;
967
968                 if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0)
969                         return NULL;
970
971                 if (slicelength <= 0) {
972                         return PyTuple_New(0);
973                 }
974                 else if (step == 1) {
975                         return Buffer_slice(self, start, stop);
976                 }
977                 else {
978                         PyErr_SetString(PyExc_IndexError,
979                                         "slice steps not supported with vectors");
980                         return NULL;
981                 }
982         }
983         else {
984                 PyErr_Format(PyExc_TypeError,
985                              "buffer indices must be integers, not %.200s",
986                              Py_TYPE(item)->tp_name);
987                 return NULL;
988         }
989 }
990
991 static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
992 {
993         if (PyIndex_Check(item)) {
994                 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
995                 if (i == -1 && PyErr_Occurred())
996                         return -1;
997                 if (i < 0)
998                         i += self->dimensions[0];
999                 return Buffer_ass_item(self, i, value);
1000         }
1001         else if (PySlice_Check(item)) {
1002                 Py_ssize_t start, stop, step, slicelength;
1003
1004                 if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0)
1005                         return -1;
1006
1007                 if (step == 1)
1008                         return Buffer_ass_slice(self, start, stop, value);
1009                 else {
1010                         PyErr_SetString(PyExc_IndexError,
1011                                         "slice steps not supported with vectors");
1012                         return -1;
1013                 }
1014         }
1015         else {
1016                 PyErr_Format(PyExc_TypeError,
1017                              "buffer indices must be integers, not %.200s",
1018                              Py_TYPE(item)->tp_name);
1019                 return -1;
1020         }
1021 }
1022
1023
1024 static void Buffer_dealloc(Buffer *self)
1025 {
1026         if (self->parent) {
1027                 Py_DECREF(self->parent);
1028         }
1029         else {
1030                 MEM_freeN(self->buf.asvoid);
1031         }
1032
1033         MEM_freeN(self->dimensions);
1034
1035         PyObject_DEL(self);
1036 }
1037
1038
1039 static PyObject *Buffer_repr(Buffer *self)
1040 {
1041         PyObject *list = Buffer_to_list_recursive(self);
1042         PyObject *repr;
1043         const char *typestr;
1044
1045         switch (self->type) {
1046                 case GL_BYTE:   typestr = "GL_BYTE"; break;
1047                 case GL_SHORT:  typestr = "GL_SHORT"; break;
1048                 case GL_INT:    typestr = "GL_INT"; break;
1049                 case GL_FLOAT:  typestr = "GL_FLOAT"; break;
1050                 case GL_DOUBLE: typestr = "GL_DOUBLE"; break;
1051                 default:        typestr = "UNKNOWN"; break;
1052         }
1053
1054         repr = PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list);
1055         Py_DECREF(list);
1056
1057         return repr;
1058 }
1059
1060 /** \} */
1061
1062
1063 /* -------------------------------------------------------------------- */
1064
1065 /** \name OpenGL API Wrapping
1066  * \{ */
1067
1068 #define BGL_Wrap(funcname, ret, arg_list)                                     \
1069 static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args)   \
1070 {                                                                             \
1071         arg_def arg_list;                                                         \
1072         ret_def_##ret;                                                            \
1073         if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) {        \
1074                 return NULL;                                                          \
1075         }                                                                         \
1076         ret_set_##ret gl##funcname (arg_var arg_list);                            \
1077         ret_ret_##ret;                                                            \
1078 }
1079
1080 /* GL_VERSION_1_0 */
1081 BGL_Wrap(BlendFunc,                 void,      (GLenum, GLenum))
1082 BGL_Wrap(Clear,                     void,      (GLbitfield))
1083 BGL_Wrap(ClearColor,                void,      (GLfloat, GLfloat, GLfloat, GLfloat))
1084 BGL_Wrap(ClearDepth,                void,      (GLdouble))
1085 BGL_Wrap(ClearStencil,              void,      (GLint))
1086 BGL_Wrap(ColorMask,                 void,      (GLboolean, GLboolean, GLboolean, GLboolean))
1087 BGL_Wrap(CullFace,                  void,      (GLenum))
1088 BGL_Wrap(DepthFunc,                 void,      (GLenum))
1089 BGL_Wrap(DepthMask,                 void,      (GLboolean))
1090 BGL_Wrap(DepthRange,                void,      (GLdouble, GLdouble))
1091 BGL_Wrap(Disable,                   void,      (GLenum))
1092 BGL_Wrap(DrawBuffer,                void,      (GLenum))
1093 BGL_Wrap(Enable,                    void,      (GLenum))
1094 BGL_Wrap(Finish,                    void,      (void))
1095 BGL_Wrap(Flush,                     void,      (void))
1096 BGL_Wrap(FrontFace,                 void,      (GLenum))
1097 BGL_Wrap(GetBooleanv,               void,      (GLenum, GLbooleanP))
1098 BGL_Wrap(GetDoublev,                void,      (GLenum, GLdoubleP))
1099 BGL_Wrap(GetError,                  GLenum,    (void))
1100 BGL_Wrap(GetFloatv,                 void,      (GLenum, GLfloatP))
1101 BGL_Wrap(GetIntegerv,               void,      (GLenum, GLintP))
1102 BGL_Wrap(GetString,                 GLstring,  (GLenum))
1103 BGL_Wrap(GetTexImage,               void,      (GLenum, GLint, GLenum, GLenum, GLvoidP))
1104 BGL_Wrap(GetTexLevelParameterfv,    void,      (GLenum, GLint, GLenum, GLfloatP))
1105 BGL_Wrap(GetTexLevelParameteriv,    void,      (GLenum, GLint, GLenum, GLintP))
1106 BGL_Wrap(GetTexParameterfv,         void,      (GLenum, GLenum, GLfloatP))
1107 BGL_Wrap(GetTexParameteriv,         void,      (GLenum, GLenum, GLintP))
1108 BGL_Wrap(Hint,                      void,      (GLenum, GLenum))
1109 BGL_Wrap(IsEnabled,                 GLboolean, (GLenum))
1110 BGL_Wrap(LineWidth,                 void,      (GLfloat))
1111 BGL_Wrap(LogicOp,                   void,      (GLenum))
1112 BGL_Wrap(PixelStoref,               void,      (GLenum, GLfloat))
1113 BGL_Wrap(PixelStorei,               void,      (GLenum, GLint))
1114 BGL_Wrap(PointSize,                 void,      (GLfloat))
1115 BGL_Wrap(PolygonMode,               void,      (GLenum, GLenum))
1116 BGL_Wrap(ReadBuffer,                void,      (GLenum))
1117 BGL_Wrap(ReadPixels,                void,      (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP))
1118 BGL_Wrap(Scissor,                   void,      (GLint, GLint, GLsizei, GLsizei))
1119 BGL_Wrap(StencilFunc,               void,      (GLenum, GLint, GLuint))
1120 BGL_Wrap(StencilMask,               void,      (GLuint))
1121 BGL_Wrap(StencilOp,                 void,      (GLenum, GLenum, GLenum))
1122 BGL_Wrap(TexImage1D,                void,      (GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, GLvoidP))
1123 BGL_Wrap(TexImage2D,                void,      (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP))
1124 BGL_Wrap(TexParameterf,             void,      (GLenum, GLenum, GLfloat))
1125 BGL_Wrap(TexParameterfv,            void,      (GLenum, GLenum, GLfloatP))
1126 BGL_Wrap(TexParameteri,             void,      (GLenum, GLenum, GLint))
1127 BGL_Wrap(TexParameteriv,            void,      (GLenum, GLenum, GLintP))
1128 BGL_Wrap(Viewport,                  void,      (GLint, GLint, GLsizei, GLsizei))
1129
1130
1131 /* GL_VERSION_1_1 */
1132 BGL_Wrap(BindTexture,               void,      (GLenum, GLuint))
1133 BGL_Wrap(CopyTexImage1D,            void,      (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint))
1134 BGL_Wrap(CopyTexImage2D,            void,      (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint))
1135 BGL_Wrap(CopyTexSubImage1D,         void,      (GLenum, GLint, GLint, GLint, GLint, GLsizei))
1136 BGL_Wrap(CopyTexSubImage2D,         void,      (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei))
1137 BGL_Wrap(DeleteTextures,            void,      (GLsizei, GLuintP))
1138 BGL_Wrap(DrawArrays,                void,      (GLenum, GLint, GLsizei))
1139 BGL_Wrap(DrawElements,              void,      (GLenum, GLsizei, GLenum, GLvoidP))
1140 BGL_Wrap(GenTextures,               void,      (GLsizei, GLuintP))
1141 BGL_Wrap(IsTexture,                 GLboolean, (GLuint))
1142 BGL_Wrap(PolygonOffset,             void,      (GLfloat, GLfloat))
1143 BGL_Wrap(TexSubImage1D,             void,      (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, GLvoidP))
1144 BGL_Wrap(TexSubImage2D,             void,      (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP))
1145
1146
1147 /* GL_VERSION_1_2 */
1148 BGL_Wrap(CopyTexSubImage3D,         void,      (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei))
1149 BGL_Wrap(DrawRangeElements,         void,      (GLenum, GLuint, GLuint, GLsizei, GLenum, GLvoidP))
1150 BGL_Wrap(TexImage3D,                void,      (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP))
1151 BGL_Wrap(TexSubImage3D,             void,      (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, GLvoidP))
1152
1153
1154 /* GL_VERSION_1_3 */
1155 BGL_Wrap(ActiveTexture,             void,      (GLenum))
1156 BGL_Wrap(CompressedTexImage1D,      void,      (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, GLvoidP))
1157 BGL_Wrap(CompressedTexImage2D,      void,      (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, GLvoidP))
1158 BGL_Wrap(CompressedTexImage3D,      void,      (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, GLvoidP))
1159 BGL_Wrap(CompressedTexSubImage1D,   void,      (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, GLvoidP))
1160 BGL_Wrap(CompressedTexSubImage2D,   void,      (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP))
1161 BGL_Wrap(CompressedTexSubImage3D,   void,      (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP))
1162 BGL_Wrap(GetCompressedTexImage,     void,      (GLenum, GLint, GLvoidP))
1163 BGL_Wrap(SampleCoverage,            void,      (GLfloat, GLboolean))
1164
1165
1166 /* GL_VERSION_1_4 */
1167 BGL_Wrap(BlendColor,                void,      (GLfloat, GLfloat, GLfloat, GLfloat))
1168 BGL_Wrap(BlendEquation,             void,      (GLenum))
1169
1170
1171 /* GL_VERSION_1_5 */
1172 BGL_Wrap(BeginQuery,                void,      (GLenum, GLuint))
1173 BGL_Wrap(BindBuffer,                void,      (GLenum, GLuint))
1174 BGL_Wrap(BufferData,                void,      (GLenum, GLsizeiptr, GLvoidP, GLenum))
1175 BGL_Wrap(BufferSubData,             void,      (GLenum, GLintptr, GLsizeiptr, GLvoidP))
1176 BGL_Wrap(DeleteBuffers,             void,      (GLsizei, GLuintP))
1177 BGL_Wrap(DeleteQueries,             void,      (GLsizei, GLuintP))
1178 BGL_Wrap(EndQuery,                  void,      (GLenum))
1179 BGL_Wrap(GenBuffers,                void,      (GLsizei, GLuintP))
1180 BGL_Wrap(GenQueries,                void,      (GLsizei, GLuintP))
1181 BGL_Wrap(GetBufferParameteriv,      void,      (GLenum, GLenum, GLintP))
1182 BGL_Wrap(GetBufferPointerv,         void,      (GLenum, GLenum, GLvoidP))
1183 BGL_Wrap(GetBufferSubData,          void,      (GLenum, GLintptr, GLsizeiptr, GLvoidP))
1184 BGL_Wrap(GetQueryObjectiv,          void,      (GLuint, GLenum, GLintP))
1185 BGL_Wrap(GetQueryObjectuiv,         void,      (GLuint, GLenum, GLuintP))
1186 BGL_Wrap(GetQueryiv,                void,      (GLenum, GLenum, GLintP))
1187 BGL_Wrap(IsBuffer,                  GLboolean, (GLuint))
1188 BGL_Wrap(IsQuery,                   GLboolean, (GLuint))
1189 BGL_Wrap(MapBuffer,                 void,      (GLenum, GLenum))
1190 BGL_Wrap(UnmapBuffer,               GLboolean, (GLenum))
1191
1192
1193 /* GL_VERSION_2_0 */
1194 BGL_Wrap(AttachShader,              void,      (GLuint, GLuint))
1195 BGL_Wrap(BindAttribLocation,        void,      (GLuint, GLuint, GLstring))
1196 BGL_Wrap(BlendEquationSeparate,     void,      (GLenum, GLenum))
1197 BGL_Wrap(CompileShader,             void,      (GLuint))
1198 BGL_Wrap(CreateProgram,             GLuint,    (void))
1199 BGL_Wrap(CreateShader,              GLuint,    (GLenum))
1200 BGL_Wrap(DeleteProgram,             void,      (GLuint))
1201 BGL_Wrap(DeleteShader,              void,      (GLuint))
1202 BGL_Wrap(DetachShader,              void,      (GLuint, GLuint))
1203 BGL_Wrap(DisableVertexAttribArray,  void,      (GLuint))
1204 BGL_Wrap(DrawBuffers,               void,      (GLsizei, GLenumP))
1205 BGL_Wrap(EnableVertexAttribArray,   void,      (GLuint))
1206 BGL_Wrap(GetActiveAttrib,           void,      (GLuint, GLuint, GLsizei, GLsizeiP, GLintP, GLenumP, GLcharP))
1207 BGL_Wrap(GetActiveUniform,          void,      (GLuint, GLuint, GLsizei, GLsizeiP, GLintP, GLenumP, GLcharP))
1208 BGL_Wrap(GetAttachedShaders,        void,      (GLuint, GLsizei, GLsizeiP, GLuintP))
1209 BGL_Wrap(GetAttribLocation,         GLint,     (GLuint, GLstring))
1210 BGL_Wrap(GetProgramInfoLog,         void,      (GLuint, GLsizei, GLsizeiP, GLcharP))
1211 BGL_Wrap(GetProgramiv,              void,      (GLuint, GLenum, GLintP))
1212 BGL_Wrap(GetShaderInfoLog,          void,      (GLuint, GLsizei, GLsizeiP, GLcharP))
1213 BGL_Wrap(GetShaderSource,           void,      (GLuint, GLsizei, GLsizeiP, GLcharP))
1214 BGL_Wrap(GetShaderiv,               void,      (GLuint, GLenum, GLintP))
1215 BGL_Wrap(GetUniformLocation,        GLint,     (GLuint, GLstring))
1216 BGL_Wrap(GetUniformfv,              void,      (GLuint, GLint, GLfloatP))
1217 BGL_Wrap(GetUniformiv,              void,      (GLuint, GLint, GLintP))
1218 BGL_Wrap(GetVertexAttribPointerv,   void,      (GLuint, GLenum, GLvoidP))
1219 BGL_Wrap(GetVertexAttribdv,         void,      (GLuint, GLenum, GLdoubleP))
1220 BGL_Wrap(GetVertexAttribfv,         void,      (GLuint, GLenum, GLfloatP))
1221 BGL_Wrap(GetVertexAttribiv,         void,      (GLuint, GLenum, GLintP))
1222 BGL_Wrap(IsProgram,                 GLboolean, (GLuint))
1223 BGL_Wrap(IsShader,                  GLboolean, (GLuint))
1224 BGL_Wrap(LinkProgram,               void,      (GLuint))
1225 BGL_Wrap(StencilFuncSeparate,       void,      (GLenum, GLenum, GLint, GLuint))
1226 BGL_Wrap(StencilMaskSeparate,       void,      (GLenum, GLuint))
1227 BGL_Wrap(StencilOpSeparate,         void,      (GLenum, GLenum, GLenum, GLenum))
1228 BGL_Wrap(Uniform1f,                 void,      (GLint, GLfloat))
1229 BGL_Wrap(Uniform1fv,                void,      (GLint, GLsizei, GLfloatP))
1230 BGL_Wrap(Uniform1i,                 void,      (GLint, GLint))
1231 BGL_Wrap(Uniform1iv,                void,      (GLint, GLsizei, GLintP))
1232 BGL_Wrap(Uniform2f,                 void,      (GLint, GLfloat, GLfloat))
1233 BGL_Wrap(Uniform2fv,                void,      (GLint, GLsizei, GLfloatP))
1234 BGL_Wrap(Uniform2i,                 void,      (GLint, GLint, GLint))
1235 BGL_Wrap(Uniform2iv,                void,      (GLint, GLsizei, GLintP))
1236 BGL_Wrap(Uniform3f,                 void,      (GLint, GLfloat, GLfloat, GLfloat))
1237 BGL_Wrap(Uniform3fv,                void,      (GLint, GLsizei, GLfloatP))
1238 BGL_Wrap(Uniform3i,                 void,      (GLint, GLint, GLint, GLint))
1239 BGL_Wrap(Uniform3iv,                void,      (GLint, GLsizei, GLintP))
1240 BGL_Wrap(Uniform4f,                 void,      (GLint, GLfloat, GLfloat, GLfloat, GLfloat))
1241 BGL_Wrap(Uniform4fv,                void,      (GLint, GLsizei, GLfloatP))
1242 BGL_Wrap(Uniform4i,                 void,      (GLint, GLint, GLint, GLint, GLint))
1243 BGL_Wrap(Uniform4iv,                void,      (GLint, GLsizei, GLintP))
1244 BGL_Wrap(UniformMatrix2fv,          void,      (GLint, GLsizei, GLboolean, GLfloatP))
1245 BGL_Wrap(UniformMatrix3fv,          void,      (GLint, GLsizei, GLboolean, GLfloatP))
1246 BGL_Wrap(UniformMatrix4fv,          void,      (GLint, GLsizei, GLboolean, GLfloatP))
1247 BGL_Wrap(UseProgram,                void,      (GLuint))
1248 BGL_Wrap(ValidateProgram,           void,      (GLuint))
1249 BGL_Wrap(VertexAttrib1d,            void,      (GLuint, GLdouble))
1250 BGL_Wrap(VertexAttrib1dv,           void,      (GLuint, GLdoubleP))
1251 BGL_Wrap(VertexAttrib1f,            void,      (GLuint, GLfloat))
1252 BGL_Wrap(VertexAttrib1fv,           void,      (GLuint, GLfloatP))
1253 BGL_Wrap(VertexAttrib1s,            void,      (GLuint, GLshort))
1254 BGL_Wrap(VertexAttrib1sv,           void,      (GLuint, GLshortP))
1255 BGL_Wrap(VertexAttrib2d,            void,      (GLuint, GLdouble, GLdouble))
1256 BGL_Wrap(VertexAttrib2dv,           void,      (GLuint, GLdoubleP))
1257 BGL_Wrap(VertexAttrib2f,            void,      (GLuint, GLfloat, GLfloat))
1258 BGL_Wrap(VertexAttrib2fv,           void,      (GLuint, GLfloatP))
1259 BGL_Wrap(VertexAttrib2s,            void,      (GLuint, GLshort, GLshort))
1260 BGL_Wrap(VertexAttrib2sv,           void,      (GLuint, GLshortP))
1261 BGL_Wrap(VertexAttrib3d,            void,      (GLuint, GLdouble, GLdouble, GLdouble))
1262 BGL_Wrap(VertexAttrib3dv,           void,      (GLuint, GLdoubleP))
1263 BGL_Wrap(VertexAttrib3f,            void,      (GLuint, GLfloat, GLfloat, GLfloat))
1264 BGL_Wrap(VertexAttrib3fv,           void,      (GLuint, GLfloatP))
1265 BGL_Wrap(VertexAttrib3s,            void,      (GLuint, GLshort, GLshort, GLshort))
1266 BGL_Wrap(VertexAttrib3sv,           void,      (GLuint, GLshortP))
1267 BGL_Wrap(VertexAttrib4Nbv,          void,      (GLuint, GLbyteP))
1268 BGL_Wrap(VertexAttrib4Niv,          void,      (GLuint, GLintP))
1269 BGL_Wrap(VertexAttrib4Nsv,          void,      (GLuint, GLshortP))
1270 BGL_Wrap(VertexAttrib4Nub,          void,      (GLuint, GLubyte, GLubyte, GLubyte, GLubyte))
1271 BGL_Wrap(VertexAttrib4Nubv,         void,      (GLuint, GLubyteP))
1272 BGL_Wrap(VertexAttrib4Nuiv,         void,      (GLuint, GLuintP))
1273 BGL_Wrap(VertexAttrib4Nusv,         void,      (GLuint, GLushortP))
1274 BGL_Wrap(VertexAttrib4bv,           void,      (GLuint, GLbyteP))
1275 BGL_Wrap(VertexAttrib4d,            void,      (GLuint, GLdouble, GLdouble, GLdouble, GLdouble))
1276 BGL_Wrap(VertexAttrib4dv,           void,      (GLuint, GLdoubleP))
1277 BGL_Wrap(VertexAttrib4f,            void,      (GLuint, GLfloat, GLfloat, GLfloat, GLfloat))
1278 BGL_Wrap(VertexAttrib4fv,           void,      (GLuint, GLfloatP))
1279 BGL_Wrap(VertexAttrib4iv,           void,      (GLuint, GLintP))
1280 BGL_Wrap(VertexAttrib4s,            void,      (GLuint, GLshort, GLshort, GLshort, GLshort))
1281 BGL_Wrap(VertexAttrib4sv,           void,      (GLuint, GLshortP))
1282 BGL_Wrap(VertexAttrib4ubv,          void,      (GLuint, GLubyteP))
1283 BGL_Wrap(VertexAttrib4uiv,          void,      (GLuint, GLuintP))
1284 BGL_Wrap(VertexAttrib4usv,          void,      (GLuint, GLushortP))
1285 BGL_Wrap(VertexAttribPointer,       void,      (GLuint, GLint, GLenum, GLboolean, GLsizei, GLvoidP))
1286
1287
1288 /* GL_VERSION_2_1 */
1289 BGL_Wrap(UniformMatrix2x3fv,        void,      (GLint, GLsizei, GLboolean, GLfloatP))
1290 BGL_Wrap(UniformMatrix2x4fv,        void,      (GLint, GLsizei, GLboolean, GLfloatP))
1291 BGL_Wrap(UniformMatrix3x2fv,        void,      (GLint, GLsizei, GLboolean, GLfloatP))
1292 BGL_Wrap(UniformMatrix3x4fv,        void,      (GLint, GLsizei, GLboolean, GLfloatP))
1293 BGL_Wrap(UniformMatrix4x2fv,        void,      (GLint, GLsizei, GLboolean, GLfloatP))
1294 BGL_Wrap(UniformMatrix4x3fv,        void,      (GLint, GLsizei, GLboolean, GLfloatP))
1295
1296
1297 /* GL_VERSION_3_0 */
1298 BGL_Wrap(BindVertexArray,           void,      (GLuint))
1299 BGL_Wrap(DeleteVertexArrays,        void,      (GLsizei, GLuintP))
1300 BGL_Wrap(GenVertexArrays,           void,      (GLsizei, GLuintP))
1301 BGL_Wrap(IsVertexArray,             GLboolean, (GLuint))
1302
1303
1304 /* GL_VERSION_3_1 */
1305 BGL_Wrap(BindBufferBase,            void,      (GLenum, GLuint, GLuint))
1306 BGL_Wrap(BindBufferRange,           void,      (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr))
1307 BGL_Wrap(GetActiveUniformBlockName, void,      (GLuint, GLuint, GLsizei, GLsizeiP, GLcharP))
1308 BGL_Wrap(GetActiveUniformBlockiv,   void,      (GLuint, GLuint, GLenum, GLintP))
1309 BGL_Wrap(GetActiveUniformName,      void,      (GLuint, GLuint, GLsizei, GLsizeiP, GLcharP))
1310 BGL_Wrap(GetActiveUniformsiv,       void,      (GLuint, GLsizei, GLuintP, GLenum, GLintP))
1311 BGL_Wrap(GetIntegeri_v,             void,      (GLenum, GLuint, GLintP))
1312 BGL_Wrap(GetUniformBlockIndex,      GLuint,    (GLuint, GLstring))
1313 BGL_Wrap(GetUniformIndices,         void,      (GLuint, GLsizei, GLcharP, GLuintP))
1314 BGL_Wrap(UniformBlockBinding,       void,      (GLuint, GLuint, GLuint))
1315
1316
1317 /* GL_VERSION_3_2 */
1318 BGL_Wrap(FramebufferTexture,        void,      (GLenum, GLenum, GLuint, GLint))
1319 BGL_Wrap(GetBufferParameteri64v,    void,      (GLenum, GLenum, GLint64P))
1320 BGL_Wrap(GetInteger64i_v,           void,      (GLenum, GLuint, GLint64P))
1321 BGL_Wrap(GetMultisamplefv,          void,      (GLenum, GLuint, GLfloatP))
1322 BGL_Wrap(SampleMaski,               void,      (GLuint, GLbitfield))
1323 BGL_Wrap(TexImage2DMultisample,     void,      (GLenum, GLsizei, GLenum, GLsizei, GLsizei, GLboolean))
1324 BGL_Wrap(TexImage3DMultisample,     void,      (GLenum, GLsizei, GLenum, GLsizei, GLsizei, GLsizei, GLboolean))
1325
1326
1327 /* GL_VERSION_3_3 */
1328 /* no new functions besides packed immediate mode (not part of core profile) */
1329
1330 /** \} */
1331
1332
1333 /* -------------------------------------------------------------------- */
1334
1335 /** \name Module Definition
1336  * \{ */
1337
1338 static struct PyModuleDef BGL_module_def = {
1339         PyModuleDef_HEAD_INIT,
1340         "bgl",  /* m_name */
1341         NULL,  /* m_doc */
1342         0,  /* m_size */
1343         NULL,  /* m_methods */
1344         NULL,  /* m_reload */
1345         NULL,  /* m_traverse */
1346         NULL,  /* m_clear */
1347         NULL,  /* m_free */
1348 };
1349
1350 static void py_module_dict_add_int(PyObject *dict, const char *name, int value)
1351 {
1352         PyObject *item;
1353         PyDict_SetItemString(dict, name, item = PyLong_FromLong(value));
1354         Py_DECREF(item);
1355 }
1356
1357 static void py_module_dict_add_int64(PyObject *dict, const char *name, int64_t value)
1358 {
1359         PyObject *item;
1360         PyDict_SetItemString(dict, name, item = PyLong_FromLongLong(value));
1361         Py_DECREF(item);
1362 }
1363
1364 static void py_module_dict_add_method(PyObject *submodule, PyObject *dict, PyMethodDef *method_def, bool is_valid)
1365 {
1366         if (is_valid) {
1367                 PyObject *m;
1368                 m = PyCFunction_NewEx(method_def, NULL, submodule);
1369                 PyDict_SetItemString(dict, method_def->ml_name, m);
1370                 Py_DECREF(m);
1371         }
1372         else {
1373                 PyDict_SetItemString(dict, method_def->ml_name, Py_None);
1374         }
1375 }
1376
1377 PyObject *BPyInit_bgl(void)
1378 {
1379         PyObject *submodule, *dict;
1380         submodule = PyModule_Create(&BGL_module_def);
1381         dict = PyModule_GetDict(submodule);
1382
1383         if (PyType_Ready(&BGL_bufferType) < 0)
1384                 return NULL;  /* should never happen */
1385
1386         PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType);
1387         Py_INCREF((PyObject *)&BGL_bufferType);
1388
1389 /* needed since some function pointers won't be NULL */
1390 #ifdef __GNUC__
1391 #  pragma GCC diagnostic ignored "-Waddress"
1392 #endif
1393
1394 #define PY_MOD_ADD_METHOD(func) \
1395         { \
1396                 static PyMethodDef method_def = {"gl"#func, Method_##func, METH_VARARGS}; \
1397                 py_module_dict_add_method(submodule, dict, &method_def, (gl##func != NULL)); \
1398         } ((void)0)
1399
1400         /* GL_VERSION_1_0 */
1401         {
1402                 PY_MOD_ADD_METHOD(BlendFunc);
1403                 PY_MOD_ADD_METHOD(Clear);
1404                 PY_MOD_ADD_METHOD(ClearColor);
1405                 PY_MOD_ADD_METHOD(ClearDepth);
1406                 PY_MOD_ADD_METHOD(ClearStencil);
1407                 PY_MOD_ADD_METHOD(ColorMask);
1408                 PY_MOD_ADD_METHOD(CullFace);
1409                 PY_MOD_ADD_METHOD(DepthFunc);
1410                 PY_MOD_ADD_METHOD(DepthMask);
1411                 PY_MOD_ADD_METHOD(DepthRange);
1412                 PY_MOD_ADD_METHOD(Disable);
1413                 PY_MOD_ADD_METHOD(DrawBuffer);
1414                 PY_MOD_ADD_METHOD(Enable);
1415                 PY_MOD_ADD_METHOD(Finish);
1416                 PY_MOD_ADD_METHOD(Flush);
1417                 PY_MOD_ADD_METHOD(FrontFace);
1418                 PY_MOD_ADD_METHOD(GetBooleanv);
1419                 PY_MOD_ADD_METHOD(GetDoublev);
1420                 PY_MOD_ADD_METHOD(GetError);
1421                 PY_MOD_ADD_METHOD(GetFloatv);
1422                 PY_MOD_ADD_METHOD(GetIntegerv);
1423                 PY_MOD_ADD_METHOD(GetString);
1424                 PY_MOD_ADD_METHOD(GetTexImage);
1425                 PY_MOD_ADD_METHOD(GetTexLevelParameterfv);
1426                 PY_MOD_ADD_METHOD(GetTexLevelParameteriv);
1427                 PY_MOD_ADD_METHOD(GetTexParameterfv);
1428                 PY_MOD_ADD_METHOD(GetTexParameteriv);
1429                 PY_MOD_ADD_METHOD(Hint);
1430                 PY_MOD_ADD_METHOD(IsEnabled);
1431                 PY_MOD_ADD_METHOD(LineWidth);
1432                 PY_MOD_ADD_METHOD(LogicOp);
1433                 PY_MOD_ADD_METHOD(PixelStoref);
1434                 PY_MOD_ADD_METHOD(PixelStorei);
1435                 PY_MOD_ADD_METHOD(PointSize);
1436                 PY_MOD_ADD_METHOD(PolygonMode);
1437                 PY_MOD_ADD_METHOD(ReadBuffer);
1438                 PY_MOD_ADD_METHOD(ReadPixels);
1439                 PY_MOD_ADD_METHOD(Scissor);
1440                 PY_MOD_ADD_METHOD(StencilFunc);
1441                 PY_MOD_ADD_METHOD(StencilMask);
1442                 PY_MOD_ADD_METHOD(StencilOp);
1443                 PY_MOD_ADD_METHOD(TexImage1D);
1444                 PY_MOD_ADD_METHOD(TexImage2D);
1445                 PY_MOD_ADD_METHOD(TexParameterf);
1446                 PY_MOD_ADD_METHOD(TexParameterfv);
1447                 PY_MOD_ADD_METHOD(TexParameteri);
1448                 PY_MOD_ADD_METHOD(TexParameteriv);
1449                 PY_MOD_ADD_METHOD(Viewport);
1450         }
1451
1452         /* GL_VERSION_1_1 */
1453         {
1454                 PY_MOD_ADD_METHOD(BindTexture);
1455                 PY_MOD_ADD_METHOD(CopyTexImage1D);
1456                 PY_MOD_ADD_METHOD(CopyTexImage2D);
1457                 PY_MOD_ADD_METHOD(CopyTexSubImage1D);
1458                 PY_MOD_ADD_METHOD(CopyTexSubImage2D);
1459                 PY_MOD_ADD_METHOD(DeleteTextures);
1460                 PY_MOD_ADD_METHOD(DrawArrays);
1461                 PY_MOD_ADD_METHOD(DrawElements);
1462                 PY_MOD_ADD_METHOD(GenTextures);
1463                 PY_MOD_ADD_METHOD(IsTexture);
1464                 PY_MOD_ADD_METHOD(PolygonOffset);
1465                 PY_MOD_ADD_METHOD(TexSubImage1D);
1466                 PY_MOD_ADD_METHOD(TexSubImage2D);
1467         }
1468
1469         /* GL_VERSION_1_2 */
1470         {
1471                 PY_MOD_ADD_METHOD(CopyTexSubImage3D);
1472                 PY_MOD_ADD_METHOD(DrawRangeElements);
1473                 PY_MOD_ADD_METHOD(TexImage3D);
1474                 PY_MOD_ADD_METHOD(TexSubImage3D);
1475         }
1476
1477         /* GL_VERSION_1_3 */
1478         {
1479                 PY_MOD_ADD_METHOD(ActiveTexture);
1480                 PY_MOD_ADD_METHOD(CompressedTexImage1D);
1481                 PY_MOD_ADD_METHOD(CompressedTexImage2D);
1482                 PY_MOD_ADD_METHOD(CompressedTexImage3D);
1483                 PY_MOD_ADD_METHOD(CompressedTexSubImage1D);
1484                 PY_MOD_ADD_METHOD(CompressedTexSubImage2D);
1485                 PY_MOD_ADD_METHOD(CompressedTexSubImage3D);
1486                 PY_MOD_ADD_METHOD(GetCompressedTexImage);
1487                 PY_MOD_ADD_METHOD(SampleCoverage);
1488         }
1489
1490         /* GL_VERSION_1_4 */
1491         {
1492                 PY_MOD_ADD_METHOD(BlendColor);
1493                 PY_MOD_ADD_METHOD(BlendEquation);
1494         }
1495
1496         /* GL_VERSION_1_5 */
1497         {
1498                 PY_MOD_ADD_METHOD(BeginQuery);
1499                 PY_MOD_ADD_METHOD(BindBuffer);
1500                 PY_MOD_ADD_METHOD(BufferData);
1501                 PY_MOD_ADD_METHOD(BufferSubData);
1502                 PY_MOD_ADD_METHOD(DeleteBuffers);
1503                 PY_MOD_ADD_METHOD(DeleteQueries);
1504                 PY_MOD_ADD_METHOD(EndQuery);
1505                 PY_MOD_ADD_METHOD(GenBuffers);
1506                 PY_MOD_ADD_METHOD(GenQueries);
1507                 PY_MOD_ADD_METHOD(GetBufferParameteriv);
1508                 PY_MOD_ADD_METHOD(GetBufferPointerv);
1509                 PY_MOD_ADD_METHOD(GetBufferSubData);
1510                 PY_MOD_ADD_METHOD(GetQueryObjectiv);
1511                 PY_MOD_ADD_METHOD(GetQueryObjectuiv);
1512                 PY_MOD_ADD_METHOD(GetQueryiv);
1513                 PY_MOD_ADD_METHOD(IsBuffer);
1514                 PY_MOD_ADD_METHOD(IsQuery);
1515                 PY_MOD_ADD_METHOD(MapBuffer);
1516                 PY_MOD_ADD_METHOD(UnmapBuffer);
1517         }
1518
1519         /* GL_VERSION_2_0 */
1520         {
1521                 PY_MOD_ADD_METHOD(AttachShader);
1522                 PY_MOD_ADD_METHOD(BindAttribLocation);
1523                 PY_MOD_ADD_METHOD(BlendEquationSeparate);
1524                 PY_MOD_ADD_METHOD(CompileShader);
1525                 PY_MOD_ADD_METHOD(CreateProgram);
1526                 PY_MOD_ADD_METHOD(CreateShader);
1527                 PY_MOD_ADD_METHOD(DeleteProgram);
1528                 PY_MOD_ADD_METHOD(DeleteShader);
1529                 PY_MOD_ADD_METHOD(DetachShader);
1530                 PY_MOD_ADD_METHOD(DisableVertexAttribArray);
1531                 PY_MOD_ADD_METHOD(DrawBuffers);
1532                 PY_MOD_ADD_METHOD(EnableVertexAttribArray);
1533                 PY_MOD_ADD_METHOD(GetActiveAttrib);
1534                 PY_MOD_ADD_METHOD(GetActiveUniform);
1535                 PY_MOD_ADD_METHOD(GetAttachedShaders);
1536                 PY_MOD_ADD_METHOD(GetAttribLocation);
1537                 PY_MOD_ADD_METHOD(GetProgramInfoLog);
1538                 PY_MOD_ADD_METHOD(GetProgramiv);
1539                 PY_MOD_ADD_METHOD(GetShaderInfoLog);
1540                 PY_MOD_ADD_METHOD(GetShaderSource);
1541                 PY_MOD_ADD_METHOD(GetShaderiv);
1542                 PY_MOD_ADD_METHOD(GetUniformLocation);
1543                 PY_MOD_ADD_METHOD(GetUniformfv);
1544                 PY_MOD_ADD_METHOD(GetUniformiv);
1545                 PY_MOD_ADD_METHOD(GetVertexAttribPointerv);
1546                 PY_MOD_ADD_METHOD(GetVertexAttribdv);
1547                 PY_MOD_ADD_METHOD(GetVertexAttribfv);
1548                 PY_MOD_ADD_METHOD(GetVertexAttribiv);
1549                 PY_MOD_ADD_METHOD(IsProgram);
1550                 PY_MOD_ADD_METHOD(IsShader);
1551                 PY_MOD_ADD_METHOD(LinkProgram);
1552                 PY_MOD_ADD_METHOD(ShaderSource);
1553                 PY_MOD_ADD_METHOD(StencilFuncSeparate);
1554                 PY_MOD_ADD_METHOD(StencilMaskSeparate);
1555                 PY_MOD_ADD_METHOD(StencilOpSeparate);
1556                 PY_MOD_ADD_METHOD(Uniform1f);
1557                 PY_MOD_ADD_METHOD(Uniform1fv);
1558                 PY_MOD_ADD_METHOD(Uniform1i);
1559                 PY_MOD_ADD_METHOD(Uniform1iv);
1560                 PY_MOD_ADD_METHOD(Uniform2f);
1561                 PY_MOD_ADD_METHOD(Uniform2fv);
1562                 PY_MOD_ADD_METHOD(Uniform2i);
1563                 PY_MOD_ADD_METHOD(Uniform2iv);
1564                 PY_MOD_ADD_METHOD(Uniform3f);
1565                 PY_MOD_ADD_METHOD(Uniform3fv);
1566                 PY_MOD_ADD_METHOD(Uniform3i);
1567                 PY_MOD_ADD_METHOD(Uniform3iv);
1568                 PY_MOD_ADD_METHOD(Uniform4f);
1569                 PY_MOD_ADD_METHOD(Uniform4fv);
1570                 PY_MOD_ADD_METHOD(Uniform4i);
1571                 PY_MOD_ADD_METHOD(Uniform4iv);
1572                 PY_MOD_ADD_METHOD(UniformMatrix2fv);
1573                 PY_MOD_ADD_METHOD(UniformMatrix3fv);
1574                 PY_MOD_ADD_METHOD(UniformMatrix4fv);
1575                 PY_MOD_ADD_METHOD(UseProgram);
1576                 PY_MOD_ADD_METHOD(ValidateProgram);
1577                 PY_MOD_ADD_METHOD(VertexAttrib1d);
1578                 PY_MOD_ADD_METHOD(VertexAttrib1dv);
1579                 PY_MOD_ADD_METHOD(VertexAttrib1f);
1580                 PY_MOD_ADD_METHOD(VertexAttrib1fv);
1581                 PY_MOD_ADD_METHOD(VertexAttrib1s);
1582                 PY_MOD_ADD_METHOD(VertexAttrib1sv);
1583                 PY_MOD_ADD_METHOD(VertexAttrib2d);
1584                 PY_MOD_ADD_METHOD(VertexAttrib2dv);
1585                 PY_MOD_ADD_METHOD(VertexAttrib2f);
1586                 PY_MOD_ADD_METHOD(VertexAttrib2fv);
1587                 PY_MOD_ADD_METHOD(VertexAttrib2s);
1588                 PY_MOD_ADD_METHOD(VertexAttrib2sv);
1589                 PY_MOD_ADD_METHOD(VertexAttrib3d);
1590                 PY_MOD_ADD_METHOD(VertexAttrib3dv);
1591                 PY_MOD_ADD_METHOD(VertexAttrib3f);
1592                 PY_MOD_ADD_METHOD(VertexAttrib3fv);
1593                 PY_MOD_ADD_METHOD(VertexAttrib3s);
1594                 PY_MOD_ADD_METHOD(VertexAttrib3sv);
1595                 PY_MOD_ADD_METHOD(VertexAttrib4Nbv);
1596                 PY_MOD_ADD_METHOD(VertexAttrib4Niv);
1597                 PY_MOD_ADD_METHOD(VertexAttrib4Nsv);
1598                 PY_MOD_ADD_METHOD(VertexAttrib4Nub);
1599                 PY_MOD_ADD_METHOD(VertexAttrib4Nubv);
1600                 PY_MOD_ADD_METHOD(VertexAttrib4Nuiv);
1601                 PY_MOD_ADD_METHOD(VertexAttrib4Nusv);
1602                 PY_MOD_ADD_METHOD(VertexAttrib4bv);
1603                 PY_MOD_ADD_METHOD(VertexAttrib4d);
1604                 PY_MOD_ADD_METHOD(VertexAttrib4dv);
1605                 PY_MOD_ADD_METHOD(VertexAttrib4f);
1606                 PY_MOD_ADD_METHOD(VertexAttrib4fv);
1607                 PY_MOD_ADD_METHOD(VertexAttrib4iv);
1608                 PY_MOD_ADD_METHOD(VertexAttrib4s);
1609                 PY_MOD_ADD_METHOD(VertexAttrib4sv);
1610                 PY_MOD_ADD_METHOD(VertexAttrib4ubv);
1611                 PY_MOD_ADD_METHOD(VertexAttrib4uiv);
1612                 PY_MOD_ADD_METHOD(VertexAttrib4usv);
1613                 PY_MOD_ADD_METHOD(VertexAttribPointer);
1614         }
1615
1616         /* GL_VERSION_2_1 */
1617         {
1618                 PY_MOD_ADD_METHOD(UniformMatrix2x3fv);
1619                 PY_MOD_ADD_METHOD(UniformMatrix2x4fv);
1620                 PY_MOD_ADD_METHOD(UniformMatrix3x2fv);
1621                 PY_MOD_ADD_METHOD(UniformMatrix3x4fv);
1622                 PY_MOD_ADD_METHOD(UniformMatrix4x2fv);
1623                 PY_MOD_ADD_METHOD(UniformMatrix4x3fv);
1624         }
1625
1626         /* GL_VERSION_3_0 */
1627         {
1628                 PY_MOD_ADD_METHOD(BindVertexArray);
1629                 PY_MOD_ADD_METHOD(DeleteVertexArrays);
1630                 PY_MOD_ADD_METHOD(GenVertexArrays);
1631                 PY_MOD_ADD_METHOD(IsVertexArray);
1632         }
1633
1634         /* GL_VERSION_3_1 */
1635         {
1636                 PY_MOD_ADD_METHOD(BindBufferBase);
1637                 PY_MOD_ADD_METHOD(BindBufferRange);
1638                 PY_MOD_ADD_METHOD(GetActiveUniformBlockName);
1639                 PY_MOD_ADD_METHOD(GetActiveUniformBlockiv);
1640                 PY_MOD_ADD_METHOD(GetActiveUniformName);
1641                 PY_MOD_ADD_METHOD(GetActiveUniformsiv);
1642                 PY_MOD_ADD_METHOD(GetIntegeri_v);
1643                 PY_MOD_ADD_METHOD(GetUniformBlockIndex);
1644                 PY_MOD_ADD_METHOD(GetUniformIndices);
1645                 PY_MOD_ADD_METHOD(UniformBlockBinding);
1646         }
1647
1648         /* GL_VERSION_3_2 */
1649         {
1650                 PY_MOD_ADD_METHOD(FramebufferTexture);
1651                 PY_MOD_ADD_METHOD(GetBufferParameteri64v);
1652                 PY_MOD_ADD_METHOD(GetInteger64i_v);
1653                 PY_MOD_ADD_METHOD(GetMultisamplefv);
1654                 PY_MOD_ADD_METHOD(SampleMaski);
1655                 PY_MOD_ADD_METHOD(TexImage2DMultisample);
1656                 PY_MOD_ADD_METHOD(TexImage3DMultisample);
1657         }
1658
1659         /* GL_VERSION_3_3 */
1660         {
1661         }
1662
1663 #define PY_DICT_ADD_INT(x) py_module_dict_add_int(dict, #x, x)
1664 #define PY_DICT_ADD_INT64(x) py_module_dict_add_int64(dict, #x, x)
1665
1666         /* GL_VERSION_1_1 */
1667         {
1668                 PY_DICT_ADD_INT(GL_ALPHA);
1669                 PY_DICT_ADD_INT(GL_ALWAYS);
1670                 PY_DICT_ADD_INT(GL_AND);
1671                 PY_DICT_ADD_INT(GL_AND_INVERTED);
1672                 PY_DICT_ADD_INT(GL_AND_REVERSE);
1673                 PY_DICT_ADD_INT(GL_BACK);
1674                 PY_DICT_ADD_INT(GL_BACK_LEFT);
1675                 PY_DICT_ADD_INT(GL_BACK_RIGHT);
1676                 PY_DICT_ADD_INT(GL_BLEND);
1677                 PY_DICT_ADD_INT(GL_BLEND_DST);
1678                 PY_DICT_ADD_INT(GL_BLEND_SRC);
1679                 PY_DICT_ADD_INT(GL_BLUE);
1680                 PY_DICT_ADD_INT(GL_BYTE);
1681                 PY_DICT_ADD_INT(GL_CCW);
1682                 PY_DICT_ADD_INT(GL_CLEAR);
1683                 PY_DICT_ADD_INT(GL_COLOR);
1684                 PY_DICT_ADD_INT(GL_COLOR_BUFFER_BIT);
1685                 PY_DICT_ADD_INT(GL_COLOR_CLEAR_VALUE);
1686                 PY_DICT_ADD_INT(GL_COLOR_LOGIC_OP);
1687                 PY_DICT_ADD_INT(GL_COLOR_WRITEMASK);
1688                 PY_DICT_ADD_INT(GL_COPY);
1689                 PY_DICT_ADD_INT(GL_COPY_INVERTED);
1690                 PY_DICT_ADD_INT(GL_CULL_FACE);
1691                 PY_DICT_ADD_INT(GL_CULL_FACE_MODE);
1692                 PY_DICT_ADD_INT(GL_CW);
1693                 PY_DICT_ADD_INT(GL_DECR);
1694                 PY_DICT_ADD_INT(GL_DEPTH);
1695                 PY_DICT_ADD_INT(GL_DEPTH_BUFFER_BIT);
1696                 PY_DICT_ADD_INT(GL_DEPTH_CLEAR_VALUE);
1697                 PY_DICT_ADD_INT(GL_DEPTH_COMPONENT);
1698                 PY_DICT_ADD_INT(GL_DEPTH_FUNC);
1699                 PY_DICT_ADD_INT(GL_DEPTH_RANGE);
1700                 PY_DICT_ADD_INT(GL_DEPTH_TEST);
1701                 PY_DICT_ADD_INT(GL_DEPTH_WRITEMASK);
1702                 PY_DICT_ADD_INT(GL_DITHER);
1703                 PY_DICT_ADD_INT(GL_DONT_CARE);
1704                 PY_DICT_ADD_INT(GL_DOUBLE);
1705                 PY_DICT_ADD_INT(GL_DOUBLEBUFFER);
1706                 PY_DICT_ADD_INT(GL_DRAW_BUFFER);
1707                 PY_DICT_ADD_INT(GL_DST_ALPHA);
1708                 PY_DICT_ADD_INT(GL_DST_COLOR);
1709                 PY_DICT_ADD_INT(GL_EQUAL);
1710                 PY_DICT_ADD_INT(GL_EQUIV);
1711                 PY_DICT_ADD_INT(GL_EXTENSIONS);
1712                 PY_DICT_ADD_INT(GL_FALSE);
1713                 PY_DICT_ADD_INT(GL_FASTEST);
1714                 PY_DICT_ADD_INT(GL_FILL);
1715                 PY_DICT_ADD_INT(GL_FLOAT);
1716                 PY_DICT_ADD_INT(GL_FRONT);
1717                 PY_DICT_ADD_INT(GL_FRONT_AND_BACK);
1718                 PY_DICT_ADD_INT(GL_FRONT_FACE);
1719                 PY_DICT_ADD_INT(GL_FRONT_LEFT);
1720                 PY_DICT_ADD_INT(GL_FRONT_RIGHT);
1721                 PY_DICT_ADD_INT(GL_GEQUAL);
1722                 PY_DICT_ADD_INT(GL_GREATER);
1723                 PY_DICT_ADD_INT(GL_GREEN);
1724                 PY_DICT_ADD_INT(GL_INCR);
1725                 PY_DICT_ADD_INT(GL_INT);
1726                 PY_DICT_ADD_INT(GL_INVALID_ENUM);
1727                 PY_DICT_ADD_INT(GL_INVALID_OPERATION);
1728                 PY_DICT_ADD_INT(GL_INVALID_VALUE);
1729                 PY_DICT_ADD_INT(GL_INVERT);
1730                 PY_DICT_ADD_INT(GL_KEEP);
1731                 PY_DICT_ADD_INT(GL_LEFT);
1732                 PY_DICT_ADD_INT(GL_LEQUAL);
1733                 PY_DICT_ADD_INT(GL_LESS);
1734                 PY_DICT_ADD_INT(GL_LINE);
1735                 PY_DICT_ADD_INT(GL_LINEAR);
1736                 PY_DICT_ADD_INT(GL_LINEAR_MIPMAP_LINEAR);
1737                 PY_DICT_ADD_INT(GL_LINEAR_MIPMAP_NEAREST);
1738                 PY_DICT_ADD_INT(GL_LINES);
1739                 PY_DICT_ADD_INT(GL_LINE_LOOP);
1740                 PY_DICT_ADD_INT(GL_LINE_SMOOTH);
1741                 PY_DICT_ADD_INT(GL_LINE_SMOOTH_HINT);
1742                 PY_DICT_ADD_INT(GL_LINE_STRIP);
1743                 PY_DICT_ADD_INT(GL_LINE_WIDTH);
1744                 PY_DICT_ADD_INT(GL_LINE_WIDTH_GRANULARITY);
1745                 PY_DICT_ADD_INT(GL_LINE_WIDTH_RANGE);
1746                 PY_DICT_ADD_INT(GL_LOGIC_OP_MODE);
1747                 PY_DICT_ADD_INT(GL_MAX_TEXTURE_SIZE);
1748                 PY_DICT_ADD_INT(GL_MAX_VIEWPORT_DIMS);
1749                 PY_DICT_ADD_INT(GL_NAND);
1750                 PY_DICT_ADD_INT(GL_NEAREST);
1751                 PY_DICT_ADD_INT(GL_NEAREST_MIPMAP_LINEAR);
1752                 PY_DICT_ADD_INT(GL_NEAREST_MIPMAP_NEAREST);
1753                 PY_DICT_ADD_INT(GL_NEVER);
1754                 PY_DICT_ADD_INT(GL_NICEST);
1755                 PY_DICT_ADD_INT(GL_NONE);
1756                 PY_DICT_ADD_INT(GL_NOOP);
1757                 PY_DICT_ADD_INT(GL_NOR);
1758                 PY_DICT_ADD_INT(GL_NOTEQUAL);
1759                 PY_DICT_ADD_INT(GL_NO_ERROR);
1760                 PY_DICT_ADD_INT(GL_ONE);
1761                 PY_DICT_ADD_INT(GL_ONE_MINUS_DST_ALPHA);
1762                 PY_DICT_ADD_INT(GL_ONE_MINUS_DST_COLOR);
1763                 PY_DICT_ADD_INT(GL_ONE_MINUS_SRC_ALPHA);
1764                 PY_DICT_ADD_INT(GL_ONE_MINUS_SRC_COLOR);
1765                 PY_DICT_ADD_INT(GL_OR);
1766                 PY_DICT_ADD_INT(GL_OR_INVERTED);
1767                 PY_DICT_ADD_INT(GL_OR_REVERSE);
1768                 PY_DICT_ADD_INT(GL_OUT_OF_MEMORY);
1769                 PY_DICT_ADD_INT(GL_PACK_ALIGNMENT);
1770                 PY_DICT_ADD_INT(GL_PACK_LSB_FIRST);
1771                 PY_DICT_ADD_INT(GL_PACK_ROW_LENGTH);
1772                 PY_DICT_ADD_INT(GL_PACK_SKIP_PIXELS);
1773                 PY_DICT_ADD_INT(GL_PACK_SKIP_ROWS);
1774                 PY_DICT_ADD_INT(GL_PACK_SWAP_BYTES);
1775                 PY_DICT_ADD_INT(GL_POINT);
1776                 PY_DICT_ADD_INT(GL_POINTS);
1777                 PY_DICT_ADD_INT(GL_POINT_SIZE);
1778                 PY_DICT_ADD_INT(GL_POLYGON_MODE);
1779                 PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FACTOR);
1780                 PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FILL);
1781                 PY_DICT_ADD_INT(GL_POLYGON_OFFSET_LINE);
1782                 PY_DICT_ADD_INT(GL_POLYGON_OFFSET_POINT);
1783                 PY_DICT_ADD_INT(GL_POLYGON_OFFSET_UNITS);
1784                 PY_DICT_ADD_INT(GL_POLYGON_SMOOTH);
1785                 PY_DICT_ADD_INT(GL_POLYGON_SMOOTH_HINT);
1786                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_1D);
1787                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D);
1788                 PY_DICT_ADD_INT(GL_R3_G3_B2);
1789                 PY_DICT_ADD_INT(GL_READ_BUFFER);
1790                 PY_DICT_ADD_INT(GL_RED);
1791                 PY_DICT_ADD_INT(GL_RENDERER);
1792                 PY_DICT_ADD_INT(GL_REPEAT);
1793                 PY_DICT_ADD_INT(GL_REPLACE);
1794                 PY_DICT_ADD_INT(GL_RGB);
1795                 PY_DICT_ADD_INT(GL_RGB10);
1796                 PY_DICT_ADD_INT(GL_RGB10_A2);
1797                 PY_DICT_ADD_INT(GL_RGB12);
1798                 PY_DICT_ADD_INT(GL_RGB16);
1799                 PY_DICT_ADD_INT(GL_RGB4);
1800                 PY_DICT_ADD_INT(GL_RGB5);
1801                 PY_DICT_ADD_INT(GL_RGB5_A1);
1802                 PY_DICT_ADD_INT(GL_RGB8);
1803                 PY_DICT_ADD_INT(GL_RGBA);
1804                 PY_DICT_ADD_INT(GL_RGBA12);
1805                 PY_DICT_ADD_INT(GL_RGBA16);
1806                 PY_DICT_ADD_INT(GL_RGBA2);
1807                 PY_DICT_ADD_INT(GL_RGBA4);
1808                 PY_DICT_ADD_INT(GL_RGBA8);
1809                 PY_DICT_ADD_INT(GL_RIGHT);
1810                 PY_DICT_ADD_INT(GL_SCISSOR_BOX);
1811                 PY_DICT_ADD_INT(GL_SCISSOR_TEST);
1812                 PY_DICT_ADD_INT(GL_SET);
1813                 PY_DICT_ADD_INT(GL_SHORT);
1814                 PY_DICT_ADD_INT(GL_SRC_ALPHA);
1815                 PY_DICT_ADD_INT(GL_SRC_ALPHA_SATURATE);
1816                 PY_DICT_ADD_INT(GL_SRC_COLOR);
1817                 PY_DICT_ADD_INT(GL_STENCIL);
1818                 PY_DICT_ADD_INT(GL_STENCIL_BUFFER_BIT);
1819                 PY_DICT_ADD_INT(GL_STENCIL_CLEAR_VALUE);
1820                 PY_DICT_ADD_INT(GL_STENCIL_FAIL);
1821                 PY_DICT_ADD_INT(GL_STENCIL_FUNC);
1822                 PY_DICT_ADD_INT(GL_STENCIL_INDEX);
1823                 PY_DICT_ADD_INT(GL_STENCIL_PASS_DEPTH_FAIL);
1824                 PY_DICT_ADD_INT(GL_STENCIL_PASS_DEPTH_PASS);
1825                 PY_DICT_ADD_INT(GL_STENCIL_REF);
1826                 PY_DICT_ADD_INT(GL_STENCIL_TEST);
1827                 PY_DICT_ADD_INT(GL_STENCIL_VALUE_MASK);
1828                 PY_DICT_ADD_INT(GL_STENCIL_WRITEMASK);
1829                 PY_DICT_ADD_INT(GL_STEREO);
1830                 PY_DICT_ADD_INT(GL_SUBPIXEL_BITS);
1831                 PY_DICT_ADD_INT(GL_TEXTURE);
1832                 PY_DICT_ADD_INT(GL_TEXTURE_1D);
1833                 PY_DICT_ADD_INT(GL_TEXTURE_2D);
1834                 PY_DICT_ADD_INT(GL_TEXTURE_ALPHA_SIZE);
1835                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_1D);
1836                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D);
1837                 PY_DICT_ADD_INT(GL_TEXTURE_BLUE_SIZE);
1838                 PY_DICT_ADD_INT(GL_TEXTURE_BORDER_COLOR);
1839                 PY_DICT_ADD_INT(GL_TEXTURE_GREEN_SIZE);
1840                 PY_DICT_ADD_INT(GL_TEXTURE_HEIGHT);
1841                 PY_DICT_ADD_INT(GL_TEXTURE_INTERNAL_FORMAT);
1842                 PY_DICT_ADD_INT(GL_TEXTURE_MAG_FILTER);
1843                 PY_DICT_ADD_INT(GL_TEXTURE_MIN_FILTER);
1844                 PY_DICT_ADD_INT(GL_TEXTURE_RED_SIZE);
1845                 PY_DICT_ADD_INT(GL_TEXTURE_WIDTH);
1846                 PY_DICT_ADD_INT(GL_TEXTURE_WRAP_S);
1847                 PY_DICT_ADD_INT(GL_TEXTURE_WRAP_T);
1848                 PY_DICT_ADD_INT(GL_TRIANGLES);
1849                 PY_DICT_ADD_INT(GL_TRIANGLE_FAN);
1850                 PY_DICT_ADD_INT(GL_TRIANGLE_STRIP);
1851                 PY_DICT_ADD_INT(GL_TRUE);
1852                 PY_DICT_ADD_INT(GL_UNPACK_ALIGNMENT);
1853                 PY_DICT_ADD_INT(GL_UNPACK_LSB_FIRST);
1854                 PY_DICT_ADD_INT(GL_UNPACK_ROW_LENGTH);
1855                 PY_DICT_ADD_INT(GL_UNPACK_SKIP_PIXELS);
1856                 PY_DICT_ADD_INT(GL_UNPACK_SKIP_ROWS);
1857                 PY_DICT_ADD_INT(GL_UNPACK_SWAP_BYTES);
1858                 PY_DICT_ADD_INT(GL_UNSIGNED_BYTE);
1859                 PY_DICT_ADD_INT(GL_UNSIGNED_INT);
1860                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT);
1861                 PY_DICT_ADD_INT(GL_VENDOR);
1862                 PY_DICT_ADD_INT(GL_VERSION);
1863                 PY_DICT_ADD_INT(GL_VIEWPORT);
1864                 PY_DICT_ADD_INT(GL_XOR);
1865                 PY_DICT_ADD_INT(GL_ZERO);
1866         }
1867
1868         /* GL_VERSION_1_2 */
1869         {
1870                 PY_DICT_ADD_INT(GL_ALIASED_LINE_WIDTH_RANGE);
1871                 PY_DICT_ADD_INT(GL_BGR);
1872                 PY_DICT_ADD_INT(GL_BGRA);
1873                 PY_DICT_ADD_INT(GL_CLAMP_TO_EDGE);
1874                 PY_DICT_ADD_INT(GL_MAX_3D_TEXTURE_SIZE);
1875                 PY_DICT_ADD_INT(GL_MAX_ELEMENTS_INDICES);
1876                 PY_DICT_ADD_INT(GL_MAX_ELEMENTS_VERTICES);
1877                 PY_DICT_ADD_INT(GL_PACK_IMAGE_HEIGHT);
1878                 PY_DICT_ADD_INT(GL_PACK_SKIP_IMAGES);
1879                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_3D);
1880                 PY_DICT_ADD_INT(GL_SMOOTH_LINE_WIDTH_GRANULARITY);
1881                 PY_DICT_ADD_INT(GL_SMOOTH_LINE_WIDTH_RANGE);
1882                 PY_DICT_ADD_INT(GL_SMOOTH_POINT_SIZE_GRANULARITY);
1883                 PY_DICT_ADD_INT(GL_SMOOTH_POINT_SIZE_RANGE);
1884                 PY_DICT_ADD_INT(GL_TEXTURE_3D);
1885                 PY_DICT_ADD_INT(GL_TEXTURE_BASE_LEVEL);
1886                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_3D);
1887                 PY_DICT_ADD_INT(GL_TEXTURE_DEPTH);
1888                 PY_DICT_ADD_INT(GL_TEXTURE_MAX_LEVEL);
1889                 PY_DICT_ADD_INT(GL_TEXTURE_MAX_LOD);
1890                 PY_DICT_ADD_INT(GL_TEXTURE_MIN_LOD);
1891                 PY_DICT_ADD_INT(GL_TEXTURE_WRAP_R);
1892                 PY_DICT_ADD_INT(GL_UNPACK_IMAGE_HEIGHT);
1893                 PY_DICT_ADD_INT(GL_UNPACK_SKIP_IMAGES);
1894                 PY_DICT_ADD_INT(GL_UNSIGNED_BYTE_2_3_3_REV);
1895                 PY_DICT_ADD_INT(GL_UNSIGNED_BYTE_3_3_2);
1896                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_10_10_10_2);
1897                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_2_10_10_10_REV);
1898                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_8_8_8_8);
1899                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_8_8_8_8_REV);
1900                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_1_5_5_5_REV);
1901                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_4_4_4_4);
1902                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_4_4_4_4_REV);
1903                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_5_5_1);
1904                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5);
1905                 PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5_REV);
1906         }
1907
1908         /* GL_VERSION_1_3 */
1909         {
1910                 PY_DICT_ADD_INT(GL_ACTIVE_TEXTURE);
1911                 PY_DICT_ADD_INT(GL_CLAMP_TO_BORDER);
1912                 PY_DICT_ADD_INT(GL_COMPRESSED_RGB);
1913                 PY_DICT_ADD_INT(GL_COMPRESSED_RGBA);
1914                 PY_DICT_ADD_INT(GL_COMPRESSED_TEXTURE_FORMATS);
1915                 PY_DICT_ADD_INT(GL_MAX_CUBE_MAP_TEXTURE_SIZE);
1916                 PY_DICT_ADD_INT(GL_MULTISAMPLE);
1917                 PY_DICT_ADD_INT(GL_NUM_COMPRESSED_TEXTURE_FORMATS);
1918                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_CUBE_MAP);
1919                 PY_DICT_ADD_INT(GL_SAMPLES);
1920                 PY_DICT_ADD_INT(GL_SAMPLE_ALPHA_TO_COVERAGE);
1921                 PY_DICT_ADD_INT(GL_SAMPLE_ALPHA_TO_ONE);
1922                 PY_DICT_ADD_INT(GL_SAMPLE_BUFFERS);
1923                 PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE);
1924                 PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE_INVERT);
1925                 PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE_VALUE);
1926                 PY_DICT_ADD_INT(GL_TEXTURE0);
1927                 PY_DICT_ADD_INT(GL_TEXTURE1);
1928                 PY_DICT_ADD_INT(GL_TEXTURE10);
1929                 PY_DICT_ADD_INT(GL_TEXTURE11);
1930                 PY_DICT_ADD_INT(GL_TEXTURE12);
1931                 PY_DICT_ADD_INT(GL_TEXTURE13);
1932                 PY_DICT_ADD_INT(GL_TEXTURE14);
1933                 PY_DICT_ADD_INT(GL_TEXTURE15);
1934                 PY_DICT_ADD_INT(GL_TEXTURE16);
1935                 PY_DICT_ADD_INT(GL_TEXTURE17);
1936                 PY_DICT_ADD_INT(GL_TEXTURE18);
1937                 PY_DICT_ADD_INT(GL_TEXTURE19);
1938                 PY_DICT_ADD_INT(GL_TEXTURE2);
1939                 PY_DICT_ADD_INT(GL_TEXTURE20);
1940                 PY_DICT_ADD_INT(GL_TEXTURE21);
1941                 PY_DICT_ADD_INT(GL_TEXTURE22);
1942                 PY_DICT_ADD_INT(GL_TEXTURE23);
1943                 PY_DICT_ADD_INT(GL_TEXTURE24);
1944                 PY_DICT_ADD_INT(GL_TEXTURE25);
1945                 PY_DICT_ADD_INT(GL_TEXTURE26);
1946                 PY_DICT_ADD_INT(GL_TEXTURE27);
1947                 PY_DICT_ADD_INT(GL_TEXTURE28);
1948                 PY_DICT_ADD_INT(GL_TEXTURE29);
1949                 PY_DICT_ADD_INT(GL_TEXTURE3);
1950                 PY_DICT_ADD_INT(GL_TEXTURE30);
1951                 PY_DICT_ADD_INT(GL_TEXTURE31);
1952                 PY_DICT_ADD_INT(GL_TEXTURE4);
1953                 PY_DICT_ADD_INT(GL_TEXTURE5);
1954                 PY_DICT_ADD_INT(GL_TEXTURE6);
1955                 PY_DICT_ADD_INT(GL_TEXTURE7);
1956                 PY_DICT_ADD_INT(GL_TEXTURE8);
1957                 PY_DICT_ADD_INT(GL_TEXTURE9);
1958                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_CUBE_MAP);
1959                 PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSED);
1960                 PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSED_IMAGE_SIZE);
1961                 PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSION_HINT);
1962                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP);
1963                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
1964                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
1965                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
1966                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_X);
1967                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
1968                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
1969         }
1970
1971         /* GL_VERSION_1_4 */
1972         {
1973                 PY_DICT_ADD_INT(GL_BLEND_DST_ALPHA);
1974                 PY_DICT_ADD_INT(GL_BLEND_DST_RGB);
1975                 PY_DICT_ADD_INT(GL_BLEND_SRC_ALPHA);
1976                 PY_DICT_ADD_INT(GL_BLEND_SRC_RGB);
1977                 PY_DICT_ADD_INT(GL_CONSTANT_ALPHA);
1978                 PY_DICT_ADD_INT(GL_CONSTANT_COLOR);
1979                 PY_DICT_ADD_INT(GL_DECR_WRAP);
1980                 PY_DICT_ADD_INT(GL_DEPTH_COMPONENT16);
1981                 PY_DICT_ADD_INT(GL_DEPTH_COMPONENT24);
1982                 PY_DICT_ADD_INT(GL_DEPTH_COMPONENT32);
1983                 PY_DICT_ADD_INT(GL_FUNC_ADD);
1984                 PY_DICT_ADD_INT(GL_FUNC_REVERSE_SUBTRACT);
1985                 PY_DICT_ADD_INT(GL_FUNC_SUBTRACT);
1986                 PY_DICT_ADD_INT(GL_INCR_WRAP);
1987                 PY_DICT_ADD_INT(GL_MAX);
1988                 PY_DICT_ADD_INT(GL_MAX_TEXTURE_LOD_BIAS);
1989                 PY_DICT_ADD_INT(GL_MIN);
1990                 PY_DICT_ADD_INT(GL_MIRRORED_REPEAT);
1991                 PY_DICT_ADD_INT(GL_ONE_MINUS_CONSTANT_ALPHA);
1992                 PY_DICT_ADD_INT(GL_ONE_MINUS_CONSTANT_COLOR);
1993                 PY_DICT_ADD_INT(GL_POINT_FADE_THRESHOLD_SIZE);
1994                 PY_DICT_ADD_INT(GL_TEXTURE_COMPARE_FUNC);
1995                 PY_DICT_ADD_INT(GL_TEXTURE_COMPARE_MODE);
1996                 PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_SIZE);
1997                 PY_DICT_ADD_INT(GL_TEXTURE_LOD_BIAS);
1998         }
1999
2000         /* GL_VERSION_1_5 */
2001         {
2002                 PY_DICT_ADD_INT(GL_ARRAY_BUFFER);
2003                 PY_DICT_ADD_INT(GL_ARRAY_BUFFER_BINDING);
2004                 PY_DICT_ADD_INT(GL_BUFFER_ACCESS);
2005                 PY_DICT_ADD_INT(GL_BUFFER_MAPPED);
2006                 PY_DICT_ADD_INT(GL_BUFFER_MAP_POINTER);
2007                 PY_DICT_ADD_INT(GL_BUFFER_SIZE);
2008                 PY_DICT_ADD_INT(GL_BUFFER_USAGE);
2009                 PY_DICT_ADD_INT(GL_CURRENT_QUERY);
2010                 PY_DICT_ADD_INT(GL_DYNAMIC_COPY);
2011                 PY_DICT_ADD_INT(GL_DYNAMIC_DRAW);
2012                 PY_DICT_ADD_INT(GL_DYNAMIC_READ);
2013                 PY_DICT_ADD_INT(GL_ELEMENT_ARRAY_BUFFER);
2014                 PY_DICT_ADD_INT(GL_ELEMENT_ARRAY_BUFFER_BINDING);
2015                 PY_DICT_ADD_INT(GL_QUERY_COUNTER_BITS);
2016                 PY_DICT_ADD_INT(GL_QUERY_RESULT);
2017                 PY_DICT_ADD_INT(GL_QUERY_RESULT_AVAILABLE);
2018                 PY_DICT_ADD_INT(GL_READ_ONLY);
2019                 PY_DICT_ADD_INT(GL_READ_WRITE);
2020                 PY_DICT_ADD_INT(GL_SAMPLES_PASSED);
2021                 PY_DICT_ADD_INT(GL_STATIC_COPY);
2022                 PY_DICT_ADD_INT(GL_STATIC_DRAW);
2023                 PY_DICT_ADD_INT(GL_STATIC_READ);
2024                 PY_DICT_ADD_INT(GL_STREAM_COPY);
2025                 PY_DICT_ADD_INT(GL_STREAM_DRAW);
2026                 PY_DICT_ADD_INT(GL_STREAM_READ);
2027                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
2028                 PY_DICT_ADD_INT(GL_WRITE_ONLY);
2029         }
2030
2031         /* GL_VERSION_2_0 */
2032         {
2033                 PY_DICT_ADD_INT(GL_ACTIVE_ATTRIBUTES);
2034                 PY_DICT_ADD_INT(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);
2035                 PY_DICT_ADD_INT(GL_ACTIVE_UNIFORMS);
2036                 PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_MAX_LENGTH);
2037                 PY_DICT_ADD_INT(GL_ATTACHED_SHADERS);
2038                 PY_DICT_ADD_INT(GL_BLEND_EQUATION_ALPHA);
2039                 PY_DICT_ADD_INT(GL_BLEND_EQUATION_RGB);
2040                 PY_DICT_ADD_INT(GL_BOOL);
2041                 PY_DICT_ADD_INT(GL_BOOL_VEC2);
2042                 PY_DICT_ADD_INT(GL_BOOL_VEC3);
2043                 PY_DICT_ADD_INT(GL_BOOL_VEC4);
2044                 PY_DICT_ADD_INT(GL_COMPILE_STATUS);
2045                 PY_DICT_ADD_INT(GL_CURRENT_PROGRAM);
2046                 PY_DICT_ADD_INT(GL_CURRENT_VERTEX_ATTRIB);
2047                 PY_DICT_ADD_INT(GL_DELETE_STATUS);
2048                 PY_DICT_ADD_INT(GL_DRAW_BUFFER0);
2049                 PY_DICT_ADD_INT(GL_DRAW_BUFFER1);
2050                 PY_DICT_ADD_INT(GL_DRAW_BUFFER10);
2051                 PY_DICT_ADD_INT(GL_DRAW_BUFFER11);
2052                 PY_DICT_ADD_INT(GL_DRAW_BUFFER12);
2053                 PY_DICT_ADD_INT(GL_DRAW_BUFFER13);
2054                 PY_DICT_ADD_INT(GL_DRAW_BUFFER14);
2055                 PY_DICT_ADD_INT(GL_DRAW_BUFFER15);
2056                 PY_DICT_ADD_INT(GL_DRAW_BUFFER2);
2057                 PY_DICT_ADD_INT(GL_DRAW_BUFFER3);
2058                 PY_DICT_ADD_INT(GL_DRAW_BUFFER4);
2059                 PY_DICT_ADD_INT(GL_DRAW_BUFFER5);
2060                 PY_DICT_ADD_INT(GL_DRAW_BUFFER6);
2061                 PY_DICT_ADD_INT(GL_DRAW_BUFFER7);
2062                 PY_DICT_ADD_INT(GL_DRAW_BUFFER8);
2063                 PY_DICT_ADD_INT(GL_DRAW_BUFFER9);
2064                 PY_DICT_ADD_INT(GL_FLOAT_MAT2);
2065                 PY_DICT_ADD_INT(GL_FLOAT_MAT3);
2066                 PY_DICT_ADD_INT(GL_FLOAT_MAT4);
2067                 PY_DICT_ADD_INT(GL_FLOAT_VEC2);
2068                 PY_DICT_ADD_INT(GL_FLOAT_VEC3);
2069                 PY_DICT_ADD_INT(GL_FLOAT_VEC4);
2070                 PY_DICT_ADD_INT(GL_FRAGMENT_SHADER);
2071                 PY_DICT_ADD_INT(GL_FRAGMENT_SHADER_DERIVATIVE_HINT);
2072                 PY_DICT_ADD_INT(GL_INFO_LOG_LENGTH);
2073                 PY_DICT_ADD_INT(GL_INT_VEC2);
2074                 PY_DICT_ADD_INT(GL_INT_VEC3);
2075                 PY_DICT_ADD_INT(GL_INT_VEC4);
2076                 PY_DICT_ADD_INT(GL_LINK_STATUS);
2077                 PY_DICT_ADD_INT(GL_LOWER_LEFT);
2078                 PY_DICT_ADD_INT(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);
2079                 PY_DICT_ADD_INT(GL_MAX_DRAW_BUFFERS);
2080                 PY_DICT_ADD_INT(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS);
2081                 PY_DICT_ADD_INT(GL_MAX_TEXTURE_IMAGE_UNITS);
2082                 PY_DICT_ADD_INT(GL_MAX_VARYING_FLOATS);
2083                 PY_DICT_ADD_INT(GL_MAX_VERTEX_ATTRIBS);
2084                 PY_DICT_ADD_INT(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
2085                 PY_DICT_ADD_INT(GL_MAX_VERTEX_UNIFORM_COMPONENTS);
2086                 PY_DICT_ADD_INT(GL_POINT_SPRITE_COORD_ORIGIN);
2087                 PY_DICT_ADD_INT(GL_SAMPLER_1D);
2088                 PY_DICT_ADD_INT(GL_SAMPLER_1D_SHADOW);
2089                 PY_DICT_ADD_INT(GL_SAMPLER_2D);
2090                 PY_DICT_ADD_INT(GL_SAMPLER_2D_SHADOW);
2091                 PY_DICT_ADD_INT(GL_SAMPLER_3D);
2092                 PY_DICT_ADD_INT(GL_SAMPLER_CUBE);
2093                 PY_DICT_ADD_INT(GL_SHADER_SOURCE_LENGTH);
2094                 PY_DICT_ADD_INT(GL_SHADER_TYPE);
2095                 PY_DICT_ADD_INT(GL_SHADING_LANGUAGE_VERSION);
2096                 PY_DICT_ADD_INT(GL_STENCIL_BACK_FAIL);
2097                 PY_DICT_ADD_INT(GL_STENCIL_BACK_FUNC);
2098                 PY_DICT_ADD_INT(GL_STENCIL_BACK_PASS_DEPTH_FAIL);
2099                 PY_DICT_ADD_INT(GL_STENCIL_BACK_PASS_DEPTH_PASS);
2100                 PY_DICT_ADD_INT(GL_STENCIL_BACK_REF);
2101                 PY_DICT_ADD_INT(GL_STENCIL_BACK_VALUE_MASK);
2102                 PY_DICT_ADD_INT(GL_STENCIL_BACK_WRITEMASK);
2103                 PY_DICT_ADD_INT(GL_UPPER_LEFT);
2104                 PY_DICT_ADD_INT(GL_VALIDATE_STATUS);
2105                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_ENABLED);
2106                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_NORMALIZED);
2107                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_POINTER);
2108                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_SIZE);
2109                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_STRIDE);
2110                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_TYPE);
2111                 PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_POINT_SIZE);
2112                 PY_DICT_ADD_INT(GL_VERTEX_SHADER);
2113         }
2114
2115         /* GL_VERSION_2_1 */
2116         {
2117                 PY_DICT_ADD_INT(GL_COMPRESSED_SRGB);
2118                 PY_DICT_ADD_INT(GL_COMPRESSED_SRGB_ALPHA);
2119                 PY_DICT_ADD_INT(GL_FLOAT_MAT2x3);
2120                 PY_DICT_ADD_INT(GL_FLOAT_MAT2x4);
2121                 PY_DICT_ADD_INT(GL_FLOAT_MAT3x2);
2122                 PY_DICT_ADD_INT(GL_FLOAT_MAT3x4);
2123                 PY_DICT_ADD_INT(GL_FLOAT_MAT4x2);
2124                 PY_DICT_ADD_INT(GL_FLOAT_MAT4x3);
2125                 PY_DICT_ADD_INT(GL_PIXEL_PACK_BUFFER);
2126                 PY_DICT_ADD_INT(GL_PIXEL_PACK_BUFFER_BINDING);
2127                 PY_DICT_ADD_INT(GL_PIXEL_UNPACK_BUFFER);
2128                 PY_DICT_ADD_INT(GL_PIXEL_UNPACK_BUFFER_BINDING);
2129                 PY_DICT_ADD_INT(GL_SRGB);
2130                 PY_DICT_ADD_INT(GL_SRGB8);
2131                 PY_DICT_ADD_INT(GL_SRGB8_ALPHA8);
2132                 PY_DICT_ADD_INT(GL_SRGB_ALPHA);
2133         }
2134
2135         /* GL_VERSION_3_0 */
2136         {
2137                 PY_DICT_ADD_INT(GL_BGRA_INTEGER);
2138                 PY_DICT_ADD_INT(GL_BGR_INTEGER);
2139                 PY_DICT_ADD_INT(GL_BLUE_INTEGER);
2140                 PY_DICT_ADD_INT(GL_BUFFER_ACCESS_FLAGS);
2141                 PY_DICT_ADD_INT(GL_BUFFER_MAP_LENGTH);
2142                 PY_DICT_ADD_INT(GL_BUFFER_MAP_OFFSET);
2143                 PY_DICT_ADD_INT(GL_CLAMP_READ_COLOR);
2144                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE0);
2145                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE1);
2146                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE2);
2147                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE3);
2148                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE4);
2149                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE5);
2150 #if 0
2151                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE6);
2152                 PY_DICT_ADD_INT(GL_CLIP_DISTANCE7);
2153 #endif
2154                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT0);
2155                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT1);
2156                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT2);
2157                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT3);
2158                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT4);
2159                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT5);
2160                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT6);
2161                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT7);
2162                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT8);
2163                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT9);
2164                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT10);
2165                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT11);
2166                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT12);
2167                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT13);
2168                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT14);
2169                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT15);
2170 #if 0
2171                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT16);
2172                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT17);
2173                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT18);
2174                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT19);
2175                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT20);
2176                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT21);
2177                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT22);
2178                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT23);
2179                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT24);
2180                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT25);
2181                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT26);
2182                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT27);
2183                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT28);
2184                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT29);
2185                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT30);
2186                 PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT31);
2187 #endif
2188                 PY_DICT_ADD_INT(GL_COMPARE_REF_TO_TEXTURE);
2189                 PY_DICT_ADD_INT(GL_COMPRESSED_RED);
2190                 PY_DICT_ADD_INT(GL_COMPRESSED_RED_RGTC1);
2191                 PY_DICT_ADD_INT(GL_COMPRESSED_RG);
2192                 PY_DICT_ADD_INT(GL_COMPRESSED_RG_RGTC2);
2193                 PY_DICT_ADD_INT(GL_COMPRESSED_SIGNED_RED_RGTC1);
2194                 PY_DICT_ADD_INT(GL_COMPRESSED_SIGNED_RG_RGTC2);
2195                 PY_DICT_ADD_INT(GL_CONTEXT_FLAGS);
2196                 PY_DICT_ADD_INT(GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT);
2197                 PY_DICT_ADD_INT(GL_DEPTH24_STENCIL8);
2198                 PY_DICT_ADD_INT(GL_DEPTH32F_STENCIL8);
2199                 PY_DICT_ADD_INT(GL_DEPTH_ATTACHMENT);
2200                 PY_DICT_ADD_INT(GL_DEPTH_COMPONENT32F);
2201                 PY_DICT_ADD_INT(GL_DEPTH_STENCIL);
2202                 PY_DICT_ADD_INT(GL_DEPTH_STENCIL_ATTACHMENT);
2203                 PY_DICT_ADD_INT(GL_DRAW_FRAMEBUFFER);
2204                 PY_DICT_ADD_INT(GL_DRAW_FRAMEBUFFER_BINDING);
2205                 PY_DICT_ADD_INT(GL_FIXED_ONLY);
2206                 PY_DICT_ADD_INT(GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
2207                 PY_DICT_ADD_INT(GL_FRAMEBUFFER);
2208                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE);
2209                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE);
2210                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING);
2211                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE);
2212                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE);
2213                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE);
2214                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
2215                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
2216                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE);
2217                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE);
2218                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE);
2219                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER);
2220                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL);
2221                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_BINDING);
2222                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_COMPLETE);
2223                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_DEFAULT);
2224                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
2225                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER);
2226                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
2227                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
2228                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER);
2229                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_SRGB);
2230                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_UNDEFINED);
2231                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_UNSUPPORTED);
2232                 PY_DICT_ADD_INT(GL_GREEN_INTEGER);
2233                 PY_DICT_ADD_INT(GL_HALF_FLOAT);
2234                 PY_DICT_ADD_INT(GL_INDEX);
2235                 PY_DICT_ADD_INT(GL_INTERLEAVED_ATTRIBS);
2236                 PY_DICT_ADD_INT(GL_INT_SAMPLER_1D);
2237                 PY_DICT_ADD_INT(GL_INT_SAMPLER_1D_ARRAY);
2238                 PY_DICT_ADD_INT(GL_INT_SAMPLER_2D);
2239                 PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_ARRAY);
2240                 PY_DICT_ADD_INT(GL_INT_SAMPLER_3D);
2241                 PY_DICT_ADD_INT(GL_INT_SAMPLER_CUBE);
2242                 PY_DICT_ADD_INT(GL_INVALID_FRAMEBUFFER_OPERATION);
2243                 PY_DICT_ADD_INT(GL_MAJOR_VERSION);
2244                 PY_DICT_ADD_INT(GL_MAP_FLUSH_EXPLICIT_BIT);
2245                 PY_DICT_ADD_INT(GL_MAP_INVALIDATE_BUFFER_BIT);
2246                 PY_DICT_ADD_INT(GL_MAP_INVALIDATE_RANGE_BIT);
2247                 PY_DICT_ADD_INT(GL_MAP_READ_BIT);
2248                 PY_DICT_ADD_INT(GL_MAP_UNSYNCHRONIZED_BIT);
2249                 PY_DICT_ADD_INT(GL_MAP_WRITE_BIT);
2250                 PY_DICT_ADD_INT(GL_MAX_ARRAY_TEXTURE_LAYERS);
2251                 PY_DICT_ADD_INT(GL_MAX_CLIP_DISTANCES);
2252                 PY_DICT_ADD_INT(GL_MAX_COLOR_ATTACHMENTS);
2253                 PY_DICT_ADD_INT(GL_MAX_PROGRAM_TEXEL_OFFSET);
2254                 PY_DICT_ADD_INT(GL_MAX_RENDERBUFFER_SIZE);
2255                 PY_DICT_ADD_INT(GL_MAX_SAMPLES);
2256                 PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS);
2257                 PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS);
2258                 PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS);
2259                 PY_DICT_ADD_INT(GL_MAX_VARYING_COMPONENTS);
2260                 PY_DICT_ADD_INT(GL_MINOR_VERSION);
2261                 PY_DICT_ADD_INT(GL_MIN_PROGRAM_TEXEL_OFFSET);
2262                 PY_DICT_ADD_INT(GL_NUM_EXTENSIONS);
2263                 PY_DICT_ADD_INT(GL_PRIMITIVES_GENERATED);
2264                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_1D_ARRAY);
2265                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_ARRAY);
2266                 PY_DICT_ADD_INT(GL_QUERY_BY_REGION_NO_WAIT);
2267                 PY_DICT_ADD_INT(GL_QUERY_BY_REGION_WAIT);
2268                 PY_DICT_ADD_INT(GL_QUERY_NO_WAIT);
2269                 PY_DICT_ADD_INT(GL_QUERY_WAIT);
2270                 PY_DICT_ADD_INT(GL_R11F_G11F_B10F);
2271                 PY_DICT_ADD_INT(GL_R16);
2272                 PY_DICT_ADD_INT(GL_R16F);
2273                 PY_DICT_ADD_INT(GL_R16I);
2274                 PY_DICT_ADD_INT(GL_R16UI);
2275                 PY_DICT_ADD_INT(GL_R32F);
2276                 PY_DICT_ADD_INT(GL_R32I);
2277                 PY_DICT_ADD_INT(GL_R32UI);
2278                 PY_DICT_ADD_INT(GL_R8);
2279                 PY_DICT_ADD_INT(GL_R8I);
2280                 PY_DICT_ADD_INT(GL_R8UI);
2281                 PY_DICT_ADD_INT(GL_RASTERIZER_DISCARD);
2282                 PY_DICT_ADD_INT(GL_READ_FRAMEBUFFER);
2283                 PY_DICT_ADD_INT(GL_READ_FRAMEBUFFER_BINDING);
2284                 PY_DICT_ADD_INT(GL_RED_INTEGER);
2285                 PY_DICT_ADD_INT(GL_RENDERBUFFER);
2286                 PY_DICT_ADD_INT(GL_RENDERBUFFER_ALPHA_SIZE);
2287                 PY_DICT_ADD_INT(GL_RENDERBUFFER_BINDING);
2288                 PY_DICT_ADD_INT(GL_RENDERBUFFER_BLUE_SIZE);
2289                 PY_DICT_ADD_INT(GL_RENDERBUFFER_DEPTH_SIZE);
2290                 PY_DICT_ADD_INT(GL_RENDERBUFFER_GREEN_SIZE);
2291                 PY_DICT_ADD_INT(GL_RENDERBUFFER_HEIGHT);
2292                 PY_DICT_ADD_INT(GL_RENDERBUFFER_INTERNAL_FORMAT);
2293                 PY_DICT_ADD_INT(GL_RENDERBUFFER_RED_SIZE);
2294                 PY_DICT_ADD_INT(GL_RENDERBUFFER_SAMPLES);
2295                 PY_DICT_ADD_INT(GL_RENDERBUFFER_STENCIL_SIZE);
2296                 PY_DICT_ADD_INT(GL_RENDERBUFFER_WIDTH);
2297                 PY_DICT_ADD_INT(GL_RG);
2298                 PY_DICT_ADD_INT(GL_RG16);
2299                 PY_DICT_ADD_INT(GL_RG16F);
2300                 PY_DICT_ADD_INT(GL_RG16I);
2301                 PY_DICT_ADD_INT(GL_RG16UI);
2302                 PY_DICT_ADD_INT(GL_RG32F);
2303                 PY_DICT_ADD_INT(GL_RG32I);
2304                 PY_DICT_ADD_INT(GL_RG32UI);
2305                 PY_DICT_ADD_INT(GL_RG8);
2306                 PY_DICT_ADD_INT(GL_RG8I);
2307                 PY_DICT_ADD_INT(GL_RG8UI);
2308                 PY_DICT_ADD_INT(GL_RGB16F);
2309                 PY_DICT_ADD_INT(GL_RGB16I);
2310                 PY_DICT_ADD_INT(GL_RGB16UI);
2311                 PY_DICT_ADD_INT(GL_RGB32F);
2312                 PY_DICT_ADD_INT(GL_RGB32I);
2313                 PY_DICT_ADD_INT(GL_RGB32UI);
2314                 PY_DICT_ADD_INT(GL_RGB8I);
2315                 PY_DICT_ADD_INT(GL_RGB8UI);
2316                 PY_DICT_ADD_INT(GL_RGB9_E5);
2317                 PY_DICT_ADD_INT(GL_RGBA16F);
2318                 PY_DICT_ADD_INT(GL_RGBA16I);
2319                 PY_DICT_ADD_INT(GL_RGBA16UI);
2320                 PY_DICT_ADD_INT(GL_RGBA32F);
2321                 PY_DICT_ADD_INT(GL_RGBA32I);
2322                 PY_DICT_ADD_INT(GL_RGBA32UI);
2323                 PY_DICT_ADD_INT(GL_RGBA8I);
2324                 PY_DICT_ADD_INT(GL_RGBA8UI);
2325                 PY_DICT_ADD_INT(GL_RGBA_INTEGER);
2326                 PY_DICT_ADD_INT(GL_RGB_INTEGER);
2327                 PY_DICT_ADD_INT(GL_RG_INTEGER);
2328                 PY_DICT_ADD_INT(GL_SAMPLER_1D_ARRAY);
2329                 PY_DICT_ADD_INT(GL_SAMPLER_1D_ARRAY_SHADOW);
2330                 PY_DICT_ADD_INT(GL_SAMPLER_2D_ARRAY);
2331                 PY_DICT_ADD_INT(GL_SAMPLER_2D_ARRAY_SHADOW);
2332                 PY_DICT_ADD_INT(GL_SAMPLER_CUBE_SHADOW);
2333                 PY_DICT_ADD_INT(GL_SEPARATE_ATTRIBS);
2334                 PY_DICT_ADD_INT(GL_STENCIL_ATTACHMENT);
2335                 PY_DICT_ADD_INT(GL_STENCIL_INDEX1);
2336                 PY_DICT_ADD_INT(GL_STENCIL_INDEX16);
2337                 PY_DICT_ADD_INT(GL_STENCIL_INDEX4);
2338                 PY_DICT_ADD_INT(GL_STENCIL_INDEX8);
2339                 PY_DICT_ADD_INT(GL_TEXTURE_1D_ARRAY);
2340                 PY_DICT_ADD_INT(GL_TEXTURE_2D_ARRAY);
2341                 PY_DICT_ADD_INT(GL_TEXTURE_ALPHA_TYPE);
2342                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_1D_ARRAY);
2343                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_ARRAY);
2344                 PY_DICT_ADD_INT(GL_TEXTURE_BLUE_TYPE);
2345                 PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_TYPE);
2346                 PY_DICT_ADD_INT(GL_TEXTURE_GREEN_TYPE);
2347                 PY_DICT_ADD_INT(GL_TEXTURE_RED_TYPE);
2348                 PY_DICT_ADD_INT(GL_TEXTURE_SHARED_SIZE);
2349                 PY_DICT_ADD_INT(GL_TEXTURE_STENCIL_SIZE);
2350                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER);
2351                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING);
2352                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_MODE);
2353                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE);
2354                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_START);
2355                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
2356                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_VARYINGS);
2357                 PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH);
2358                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_10F_11F_11F_REV);
2359                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_24_8);
2360                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_5_9_9_9_REV);
2361                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_1D);
2362                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY);
2363                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D);
2364                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY);
2365                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_3D);
2366                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_CUBE);
2367                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC2);
2368                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC3);
2369                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC4);
2370                 PY_DICT_ADD_INT(GL_UNSIGNED_NORMALIZED);
2371                 PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BINDING);
2372                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_INTEGER);
2373         }
2374
2375         /* GL_VERSION_3_1 */
2376         {
2377                 PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_BLOCKS);
2378                 PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH);
2379                 PY_DICT_ADD_INT(GL_COPY_READ_BUFFER);
2380                 PY_DICT_ADD_INT(GL_COPY_WRITE_BUFFER);
2381                 PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_RECT);
2382                 PY_DICT_ADD_INT(GL_INT_SAMPLER_BUFFER);
2383                 PY_DICT_ADD_INT(GL_INVALID_INDEX);
2384                 PY_DICT_ADD_INT(GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS);
2385                 PY_DICT_ADD_INT(GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS);
2386                 PY_DICT_ADD_INT(GL_MAX_COMBINED_UNIFORM_BLOCKS);
2387                 PY_DICT_ADD_INT(GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS);
2388                 PY_DICT_ADD_INT(GL_MAX_FRAGMENT_UNIFORM_BLOCKS);
2389                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_UNIFORM_BLOCKS);
2390                 PY_DICT_ADD_INT(GL_MAX_RECTANGLE_TEXTURE_SIZE);
2391                 PY_DICT_ADD_INT(GL_MAX_TEXTURE_BUFFER_SIZE);
2392                 PY_DICT_ADD_INT(GL_MAX_UNIFORM_BLOCK_SIZE);
2393                 PY_DICT_ADD_INT(GL_MAX_UNIFORM_BUFFER_BINDINGS);
2394                 PY_DICT_ADD_INT(GL_MAX_VERTEX_UNIFORM_BLOCKS);
2395                 PY_DICT_ADD_INT(GL_PRIMITIVE_RESTART);
2396                 PY_DICT_ADD_INT(GL_PRIMITIVE_RESTART_INDEX);
2397                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_RECTANGLE);
2398                 PY_DICT_ADD_INT(GL_R16_SNORM);
2399                 PY_DICT_ADD_INT(GL_R8_SNORM);
2400                 PY_DICT_ADD_INT(GL_RG16_SNORM);
2401                 PY_DICT_ADD_INT(GL_RG8_SNORM);
2402                 PY_DICT_ADD_INT(GL_RGB16_SNORM);
2403                 PY_DICT_ADD_INT(GL_RGB8_SNORM);
2404                 PY_DICT_ADD_INT(GL_RGBA16_SNORM);
2405                 PY_DICT_ADD_INT(GL_RGBA8_SNORM);
2406                 PY_DICT_ADD_INT(GL_SAMPLER_2D_RECT);
2407                 PY_DICT_ADD_INT(GL_SAMPLER_2D_RECT_SHADOW);
2408                 PY_DICT_ADD_INT(GL_SAMPLER_BUFFER);
2409                 PY_DICT_ADD_INT(GL_SIGNED_NORMALIZED);
2410                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_BUFFER);
2411                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_RECTANGLE);
2412                 PY_DICT_ADD_INT(GL_TEXTURE_BUFFER);
2413                 PY_DICT_ADD_INT(GL_TEXTURE_BUFFER_DATA_STORE_BINDING);
2414                 PY_DICT_ADD_INT(GL_TEXTURE_RECTANGLE);
2415                 PY_DICT_ADD_INT(GL_UNIFORM_ARRAY_STRIDE);
2416                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS);
2417                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES);
2418                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_BINDING);
2419                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_DATA_SIZE);
2420                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_INDEX);
2421                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_NAME_LENGTH);
2422                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER);
2423                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER);
2424                 PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER);
2425                 PY_DICT_ADD_INT(GL_UNIFORM_BUFFER);
2426                 PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_BINDING);
2427                 PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
2428                 PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_SIZE);
2429                 PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_START);
2430                 PY_DICT_ADD_INT(GL_UNIFORM_IS_ROW_MAJOR);
2431                 PY_DICT_ADD_INT(GL_UNIFORM_MATRIX_STRIDE);
2432                 PY_DICT_ADD_INT(GL_UNIFORM_NAME_LENGTH);
2433                 PY_DICT_ADD_INT(GL_UNIFORM_OFFSET);
2434                 PY_DICT_ADD_INT(GL_UNIFORM_SIZE);
2435                 PY_DICT_ADD_INT(GL_UNIFORM_TYPE);
2436                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_RECT);
2437                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_BUFFER);
2438         }
2439
2440         /* GL_VERSION_3_2 */
2441         {
2442                 PY_DICT_ADD_INT(GL_ALREADY_SIGNALED);
2443                 PY_DICT_ADD_INT(GL_CONDITION_SATISFIED);
2444                 PY_DICT_ADD_INT(GL_CONTEXT_COMPATIBILITY_PROFILE_BIT);
2445                 PY_DICT_ADD_INT(GL_CONTEXT_CORE_PROFILE_BIT);
2446                 PY_DICT_ADD_INT(GL_CONTEXT_PROFILE_MASK);
2447                 PY_DICT_ADD_INT(GL_DEPTH_CLAMP);
2448                 PY_DICT_ADD_INT(GL_FIRST_VERTEX_CONVENTION);
2449                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_LAYERED);
2450                 PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS);
2451                 PY_DICT_ADD_INT(GL_GEOMETRY_INPUT_TYPE);
2452                 PY_DICT_ADD_INT(GL_GEOMETRY_OUTPUT_TYPE);
2453                 PY_DICT_ADD_INT(GL_GEOMETRY_SHADER);
2454                 PY_DICT_ADD_INT(GL_GEOMETRY_VERTICES_OUT);
2455                 PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_MULTISAMPLE);
2456                 PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY);
2457                 PY_DICT_ADD_INT(GL_LAST_VERTEX_CONVENTION);
2458                 PY_DICT_ADD_INT(GL_LINES_ADJACENCY);
2459                 PY_DICT_ADD_INT(GL_LINE_STRIP_ADJACENCY);
2460                 PY_DICT_ADD_INT(GL_MAX_COLOR_TEXTURE_SAMPLES);
2461                 PY_DICT_ADD_INT(GL_MAX_DEPTH_TEXTURE_SAMPLES);
2462                 PY_DICT_ADD_INT(GL_MAX_FRAGMENT_INPUT_COMPONENTS);
2463                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_INPUT_COMPONENTS);
2464                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_OUTPUT_COMPONENTS);
2465                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_OUTPUT_VERTICES);
2466                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS);
2467                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS);
2468                 PY_DICT_ADD_INT(GL_MAX_GEOMETRY_UNIFORM_COMPONENTS);
2469                 PY_DICT_ADD_INT(GL_MAX_INTEGER_SAMPLES);
2470                 PY_DICT_ADD_INT(GL_MAX_SAMPLE_MASK_WORDS);
2471                 PY_DICT_ADD_INT(GL_MAX_SERVER_WAIT_TIMEOUT);
2472                 PY_DICT_ADD_INT(GL_MAX_VERTEX_OUTPUT_COMPONENTS);
2473                 PY_DICT_ADD_INT(GL_OBJECT_TYPE);
2474                 PY_DICT_ADD_INT(GL_PROGRAM_POINT_SIZE);
2475                 PY_DICT_ADD_INT(GL_PROVOKING_VERTEX);
2476                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_MULTISAMPLE);
2477                 PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY);
2478                 PY_DICT_ADD_INT(GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
2479                 PY_DICT_ADD_INT(GL_SAMPLER_2D_MULTISAMPLE);
2480                 PY_DICT_ADD_INT(GL_SAMPLER_2D_MULTISAMPLE_ARRAY);
2481                 PY_DICT_ADD_INT(GL_SAMPLE_MASK);
2482                 PY_DICT_ADD_INT(GL_SAMPLE_MASK_VALUE);
2483                 PY_DICT_ADD_INT(GL_SAMPLE_POSITION);
2484                 PY_DICT_ADD_INT(GL_SIGNALED);
2485                 PY_DICT_ADD_INT(GL_SYNC_CONDITION);
2486                 PY_DICT_ADD_INT(GL_SYNC_FENCE);
2487                 PY_DICT_ADD_INT(GL_SYNC_FLAGS);
2488                 PY_DICT_ADD_INT(GL_SYNC_FLUSH_COMMANDS_BIT);
2489                 PY_DICT_ADD_INT(GL_SYNC_GPU_COMMANDS_COMPLETE);
2490                 PY_DICT_ADD_INT(GL_SYNC_STATUS);
2491                 PY_DICT_ADD_INT(GL_TEXTURE_2D_MULTISAMPLE);
2492                 PY_DICT_ADD_INT(GL_TEXTURE_2D_MULTISAMPLE_ARRAY);
2493                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_MULTISAMPLE);
2494                 PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY);
2495                 PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_SEAMLESS);
2496                 PY_DICT_ADD_INT(GL_TEXTURE_FIXED_SAMPLE_LOCATIONS);
2497                 PY_DICT_ADD_INT(GL_TEXTURE_SAMPLES);
2498                 PY_DICT_ADD_INT(GL_TIMEOUT_EXPIRED);
2499                 PY_DICT_ADD_INT64(GL_TIMEOUT_IGNORED);
2500                 PY_DICT_ADD_INT(GL_TRIANGLES_ADJACENCY);
2501                 PY_DICT_ADD_INT(GL_TRIANGLE_STRIP_ADJACENCY);
2502                 PY_DICT_ADD_INT(GL_UNSIGNALED);
2503                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE);
2504                 PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY);
2505                 PY_DICT_ADD_INT(GL_WAIT_FAILED);
2506         }
2507
2508         /* GL_VERSION_3_3 */
2509         {
2510                 PY_DICT_ADD_INT(GL_ANY_SAMPLES_PASSED);
2511                 PY_DICT_ADD_INT(GL_INT_2_10_10_10_REV);
2512                 PY_DICT_ADD_INT(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS);
2513                 PY_DICT_ADD_INT(GL_ONE_MINUS_SRC1_ALPHA);
2514                 PY_DICT_ADD_INT(GL_ONE_MINUS_SRC1_COLOR);
2515                 PY_DICT_ADD_INT(GL_RGB10_A2UI);
2516                 PY_DICT_ADD_INT(GL_SAMPLER_BINDING);
2517                 PY_DICT_ADD_INT(GL_SRC1_COLOR);
2518                 PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_A);
2519                 PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_B);
2520                 PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_G);
2521                 PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_R);
2522                 PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_RGBA);
2523                 PY_DICT_ADD_INT(GL_TIMESTAMP);
2524                 PY_DICT_ADD_INT(GL_TIME_ELAPSED);
2525                 PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR);
2526         }
2527
2528         return submodule;
2529 }
2530
2531 static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args)
2532 {
2533         unsigned int shader;
2534         const char *source;
2535
2536         if (!PyArg_ParseTuple(args, "Is", &shader, &source))
2537                 return NULL;
2538
2539         glShaderSource(shader, 1, (const char **)&source, NULL);
2540
2541         Py_RETURN_NONE;
2542 }
2543
2544
2545 /** \} */