1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL LICENSE BLOCK *****
*/
/* This is the Blender.BGL part of opy_draw.c, from the old bpython/intern
* dir, with minor changes to adapt it to the new Python implementation.
* The BGL submodule "wraps" OpenGL functions and constants, allowing script
* writers to make OpenGL calls in their Python scripts for Blender. The
* more important original comments are marked with an @ symbol. */
#ifndef EXPP_BGL_H
#define EXPP_BGL_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <Python.h>
#include "BIF_gl.h"
/*@ Buffer Object */
/*@ For Python access to OpenGL functions requiring a pointer. */
typedef struct _Buffer {
PyObject_VAR_HEAD
PyObject * parent;
int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */
int ndimensions;
int *dimensions;
union {
char *asbyte;
short *asshort;
int *asint;
float *asfloat;
double *asdouble;
void *asvoid;
} buf;
} Buffer;
/*@ By golly George! It looks like fancy pants macro time!!! */
/*
#define int_str "i"
#define int_var(number) bgl_int##number
#define int_ref(number) &bgl_int##number
#define int_def(number) int int_var(number)
#define float_str "f"
#define float_var(number) bgl_float##number
#define float_ref(number) &bgl_float##number
#define float_def(number) float float_var(number)
*/
/* TYPE_str is the string to pass to Py_ArgParse (for the format) */
/* TYPE_var is the name to pass to the GL function */
/* TYPE_ref is the pointer to pass to Py_ArgParse (to store in) */
/* TYPE_def is the C initialization of the variable */
#define void_str ""
#define void_var(num)
#define void_ref(num) &bgl_var##num
#define void_def(num) char bgl_var##num
#define buffer_str "O!"
#define buffer_var(number) (bgl_buffer##number)->buf.asvoid
#define buffer_ref(number) &buffer_Type, &bgl_buffer##number
#define buffer_def(number) Buffer *bgl_buffer##number
/* GL Pointer fields, handled by buffer type */
/* GLdoubleP, GLfloatP, GLintP, GLuintP, GLshortP */
#define GLbooleanP_str "O!"
#define GLbooleanP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLbooleanP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLbooleanP_def(number) Buffer *bgl_buffer##number
#define GLbyteP_str "O!"
#define GLbyteP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLbyteP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLbyteP_def(number) Buffer *bgl_buffer##number
#define GLubyteP_str "O!"
#define GLubyteP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLubyteP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLubyteP_def(number) Buffer *bgl_buffer##number
#define GLintP_str "O!"
#define GLintP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLintP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLintP_def(number) Buffer *bgl_buffer##number
#define GLuintP_str "O!"
#define GLuintP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLuintP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLuintP_def(number) Buffer *bgl_buffer##number
#define GLshortP_str "O!"
#define GLshortP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLshortP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLshortP_def(number) Buffer *bgl_buffer##number
#define GLushortP_str "O!"
#define GLushortP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLushortP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLushortP_def(number) Buffer *bgl_buffer##number
#define GLfloatP_str "O!"
#define GLfloatP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLfloatP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLfloatP_def(number) Buffer *bgl_buffer##number
#define GLdoubleP_str "O!"
#define GLdoubleP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLdoubleP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLdoubleP_def(number) Buffer *bgl_buffer##number
#define GLclampfP_str "O!"
#define GLclampfP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLclampfP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLclampfP_def(number) Buffer *bgl_buffer##number
#define GLvoidP_str "O!"
#define GLvoidP_var(number) (bgl_buffer##number)->buf.asvoid
#define GLvoidP_ref(number) &buffer_Type, &bgl_buffer##number
#define GLvoidP_def(number) Buffer *bgl_buffer##number
#define buffer_str "O!"
#define buffer_var(number) (bgl_buffer##number)->buf.asvoid
#define buffer_ref(number) &buffer_Type, &bgl_buffer##number
#define buffer_def(number) Buffer *bgl_buffer##number
/*@The standard GL typedefs are used as prototypes, we can't
* use the GL type directly because Py_ArgParse expects normal
* C types.
*
* Py_ArgParse doesn't grok writing into unsigned variables,
* so we use signed everything (even stuff that should be unsigned.
*/
/* typedef unsigned int GLenum; */
#define GLenum_str "i"
#define GLenum_var(num) bgl_var##num
#define GLenum_ref(num) &bgl_var##num
#define GLenum_def(num) /* unsigned */ int GLenum_var(num)
/* typedef unsigned int GLboolean; */
#define GLboolean_str "b"
#define GLboolean_var(num) bgl_var##num
#define GLboolean_ref(num) &bgl_var##num
#define GLboolean_def(num) /* unsigned */ char GLboolean_var(num)
/* typedef unsigned int GLbitfield; */
#define GLbitfield_str "i"
#define GLbitfield_var(num) bgl_var##num
#define GLbitfield_ref(num) &bgl_var##num
#define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num)
/* typedef signed char GLbyte; */
#define GLbyte_str "b"
#define GLbyte_var(num) bgl_var##num
#define GLbyte_ref(num) &bgl_var##num
#define GLbyte_def(num) signed char GLbyte_var(num)
/* typedef short GLshort; */
#define GLshort_str "h"
#define GLshort_var(num) bgl_var##num
#define GLshort_ref(num) &bgl_var##num
#define GLshort_def(num) short GLshort_var(num)
/* typedef int GLint; */
#define GLint_str "i"
#define GLint_var(num) bgl_var##num
#define GLint_ref(num) &bgl_var##num
#define GLint_def(num) int GLint_var(num)
/* typedef int GLsizei; */
#define GLsizei_str "i"
#define GLsizei_var(num) bgl_var##num
#define GLsizei_ref(num) &bgl_var##num
#define GLsizei_def(num) int GLsizei_var(num)
/* typedef unsigned char GLubyte; */
#define GLubyte_str "b"
#define GLubyte_var(num) bgl_var##num
#define GLubyte_ref(num) &bgl_var##num
#define GLubyte_def(num) /* unsigned */ char GLubyte_var(num)
/* typedef unsigned short GLushort; */
#define GLushort_str "h"
#define GLushort_var(num) bgl_var##num
#define GLushort_ref(num) &bgl_var##num
#define GLushort_def(num) /* unsigned */ short GLushort_var(num)
/* typedef unsigned int GLuint; */
#define GLuint_str "i"
#define GLuint_var(num) bgl_var##num
#define GLuint_ref(num) &bgl_var##num
#define GLuint_def(num) /* unsigned */ int GLuint_var(num)
/* typedef float GLfloat; */
#define GLfloat_str "f"
#define GLfloat_var(num) bgl_var##num
#define GLfloat_ref(num) &bgl_var##num
#define GLfloat_def(num) float GLfloat_var(num)
/* typedef float GLclampf; */
#define GLclampf_str "f"
#define GLclampf_var(num) bgl_var##num
#define GLclampf_ref(num) &bgl_var##num
#define GLclampf_def(num) float GLclampf_var(num)
/* typedef double GLdouble; */
#define GLdouble_str "d"
#define GLdouble_var(num) bgl_var##num
#define GLdouble_ref(num) &bgl_var##num
#define GLdouble_def(num) double GLdouble_var(num)
/* typedef double GLclampd; */
#define GLclampd_str "d"
#define GLclampd_var(num) bgl_var##num
#define GLclampd_ref(num) &bgl_var##num
#define GLclampd_def(num) double GLclampd_var(num)
/* typedef void GLvoid; */
/* #define GLvoid_str "" */
/* #define GLvoid_var(num) bgl_var##num */
/* #define GLvoid_ref(num) &bgl_var##num */
/* #define GLvoid_def(num) char bgl_var##num */
#define arg_def1(a1) a1##_def(1)
#define arg_def2(a1, a2) arg_def1(a1); a2##_def(2)
#define arg_def3(a1, a2, a3) arg_def2(a1, a2); a3##_def(3)
#define arg_def4(a1, a2, a3, a4) arg_def3(a1, a2, a3); a4##_def(4)
#define arg_def5(a1, a2, a3, a4, a5) arg_def4(a1, a2, a3, a4); a5##_def(5)
#define arg_def6(a1, a2, a3, a4, a5, a6)arg_def5(a1, a2, a3, a4, a5); a6##_def(6)
#define arg_def7(a1, a2, a3, a4, a5, a6, a7)arg_def6(a1, a2, a3, a4, a5, a6); a7##_def(7)
#define arg_def8(a1, a2, a3, a4, a5, a6, a7, a8)arg_def7(a1, a2, a3, a4, a5, a6, a7); a8##_def(8)
#define arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_def8(a1, a2, a3, a4, a5, a6, a7, a8); a9##_def(9)
#define arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9); a10##_def(10)
#define arg_var1(a1) a1##_var(1)
#define arg_var2(a1, a2) arg_var1(a1), a2##_var(2)
#define arg_var3(a1, a2, a3) arg_var2(a1, a2), a3##_var(3)
#define arg_var4(a1, a2, a3, a4) arg_var3(a1, a2, a3), a4##_var(4)
#define arg_var5(a1, a2, a3, a4, a5) arg_var4(a1, a2, a3, a4), a5##_var(5)
#define arg_var6(a1, a2, a3, a4, a5, a6)arg_var5(a1, a2, a3, a4, a5), a6##_var(6)
#define arg_var7(a1, a2, a3, a4, a5, a6, a7)arg_var6(a1, a2, a3, a4, a5, a6), a7##_var(7)
#define arg_var8(a1, a2, a3, a4, a5, a6, a7, a8)arg_var7(a1, a2, a3, a4, a5, a6, a7), a8##_var(8)
#define arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_var8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_var(9)
#define arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_var(10)
#define arg_ref1(a1) a1##_ref(1)
#define arg_ref2(a1, a2) arg_ref1(a1), a2##_ref(2)
#define arg_ref3(a1, a2, a3) arg_ref2(a1, a2), a3##_ref(3)
#define arg_ref4(a1, a2, a3, a4) arg_ref3(a1, a2, a3), a4##_ref(4)
#define arg_ref5(a1, a2, a3, a4, a5) arg_ref4(a1, a2, a3, a4), a5##_ref(5)
#define arg_ref6(a1, a2, a3, a4, a5, a6)arg_ref5(a1, a2, a3, a4, a5), a6##_ref(6)
#define arg_ref7(a1, a2, a3, a4, a5, a6, a7)arg_ref6(a1, a2, a3, a4, a5, a6), a7##_ref(7)
#define arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8)arg_ref7(a1, a2, a3, a4, a5, a6, a7), a8##_ref(8)
#define arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_ref(9)
#define arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_ref(10)
#define arg_str1(a1) a1##_str
#define arg_str2(a1, a2) arg_str1(a1) a2##_str
#define arg_str3(a1, a2, a3) arg_str2(a1, a2) a3##_str
#define arg_str4(a1, a2, a3, a4) arg_str3(a1, a2, a3) a4##_str
#define arg_str5(a1, a2, a3, a4, a5) arg_str4(a1, a2, a3, a4) a5##_str
#define arg_str6(a1, a2, a3, a4, a5, a6)arg_str5(a1, a2, a3, a4, a5) a6##_str
#define arg_str7(a1, a2, a3, a4, a5, a6, a7)arg_str6(a1, a2, a3, a4, a5, a6) a7##_str
#define arg_str8(a1, a2, a3, a4, a5, a6, a7, a8)arg_str7(a1, a2, a3, a4, a5, a6, a7) a8##_str
#define arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) a9##_str
#define arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) a10##_str
#define ret_def_void
#define ret_set_void
#define ret_ret_void return EXPP_incr_ret(Py_None)
#define ret_def_GLint int ret_int
#define ret_set_GLint ret_int=
#define ret_ret_GLint return PyInt_FromLong(ret_int);
#define ret_def_GLuint unsigned int ret_uint
#define ret_set_GLuint ret_uint=
#define ret_ret_GLuint return PyInt_FromLong((long) ret_uint);
#define ret_def_GLenum unsigned int ret_uint
#define ret_set_GLenum ret_uint=
#define ret_ret_GLenum return PyInt_FromLong((long) ret_uint);
#define ret_def_GLboolean unsigned char ret_bool
#define ret_set_GLboolean ret_bool=
#define ret_ret_GLboolean return PyInt_FromLong((long) ret_bool);
#define ret_def_GLstring const unsigned char *ret_str;
#define ret_set_GLstring ret_str=
#define ret_ret_GLstring \
if (ret_str) {\
return PyString_FromString(ret_str);\
} else {\
PyErr_SetString(PyExc_AttributeError, "could not get opengl string");\
return NULL;\
}
#endif /* EXPP_BGL_H */
|