Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * This is a new part of Blender. 00022 * 00023 * Contributor(s): Willian P. Germano 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 /* This is the Blender.BGL part of opy_draw.c, from the old bpython/intern 00034 * dir, with minor changes to adapt it to the new Python implementation. 00035 * The BGL submodule "wraps" OpenGL functions and constants, allowing script 00036 * writers to make OpenGL calls in their Python scripts for Blender. The 00037 * more important original comments are marked with an @ symbol. */ 00038 00039 #ifndef BGL_H 00040 #define BGL_H 00041 00042 PyObject *BPyInit_bgl(void); 00043 00044 /*@ Create a buffer object */ 00045 /*@ dimensions is an array of ndimensions integers representing the size of each dimension */ 00046 /*@ initbuffer if not NULL holds a contiguous buffer with the correct format from which the buffer will be initialized */ 00047 struct _Buffer *BGL_MakeBuffer( int type, int ndimensions, int *dimensions, void *initbuffer ); 00048 /*@ Return the size of buffer element, type must be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE */ 00049 /*@ returns -1 otherwise */ 00050 int BGL_typeSize( int type ); 00051 00052 /*@ Buffer Object */ 00053 /*@ For Python access to OpenGL functions requiring a pointer. */ 00054 typedef struct _Buffer { 00055 PyObject_VAR_HEAD 00056 PyObject *parent; 00057 00058 int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */ 00059 int ndimensions; 00060 int *dimensions; 00061 00062 union { 00063 char *asbyte; 00064 short *asshort; 00065 int *asint; 00066 float *asfloat; 00067 double *asdouble; 00068 00069 void *asvoid; 00070 } buf; 00071 } Buffer; 00072 00073 /*@ The type object */ 00074 extern PyTypeObject BGL_bufferType; 00075 00076 /*@ By golly George! It looks like fancy pants macro time!!! */ 00077 00078 /* 00079 #define int_str "i" 00080 #define int_var(number) bgl_int##number 00081 #define int_ref(number) &bgl_int##number 00082 #define int_def(number) int int_var(number) 00083 00084 #define float_str "f" 00085 #define float_var(number) bgl_float##number 00086 #define float_ref(number) &bgl_float##number 00087 #define float_def(number) float float_var(number) 00088 */ 00089 00090 /* TYPE_str is the string to pass to Py_ArgParse (for the format) */ 00091 /* TYPE_var is the name to pass to the GL function */ 00092 /* TYPE_ref is the pointer to pass to Py_ArgParse (to store in) */ 00093 /* TYPE_def is the C initialization of the variable */ 00094 00095 #define void_str "" 00096 #define void_var(num) 00097 #define void_ref(num) &bgl_var##num 00098 #define void_def(num) char bgl_var##num 00099 00100 #define buffer_str "O!" 00101 #define buffer_var(number) (bgl_buffer##number)->buf.asvoid 00102 #define buffer_ref(number) &BGL_bufferType, &bgl_buffer##number 00103 #define buffer_def(number) Buffer *bgl_buffer##number 00104 00105 /* GL Pointer fields, handled by buffer type */ 00106 /* GLdoubleP, GLfloatP, GLintP, GLuintP, GLshortP */ 00107 00108 #define GLbooleanP_str "O!" 00109 #define GLbooleanP_var(number) (bgl_buffer##number)->buf.asvoid 00110 #define GLbooleanP_ref(number) &BGL_bufferType, &bgl_buffer##number 00111 #define GLbooleanP_def(number) Buffer *bgl_buffer##number 00112 00113 #define GLbyteP_str "O!" 00114 #define GLbyteP_var(number) (bgl_buffer##number)->buf.asvoid 00115 #define GLbyteP_ref(number) &BGL_bufferType, &bgl_buffer##number 00116 #define GLbyteP_def(number) Buffer *bgl_buffer##number 00117 00118 #define GLubyteP_str "O!" 00119 #define GLubyteP_var(number) (bgl_buffer##number)->buf.asvoid 00120 #define GLubyteP_ref(number) &BGL_bufferType, &bgl_buffer##number 00121 #define GLubyteP_def(number) Buffer *bgl_buffer##number 00122 00123 #define GLintP_str "O!" 00124 #define GLintP_var(number) (bgl_buffer##number)->buf.asvoid 00125 #define GLintP_ref(number) &BGL_bufferType, &bgl_buffer##number 00126 #define GLintP_def(number) Buffer *bgl_buffer##number 00127 00128 #define GLuintP_str "O!" 00129 #define GLuintP_var(number) (bgl_buffer##number)->buf.asvoid 00130 #define GLuintP_ref(number) &BGL_bufferType, &bgl_buffer##number 00131 #define GLuintP_def(number) Buffer *bgl_buffer##number 00132 00133 #define GLshortP_str "O!" 00134 #define GLshortP_var(number) (bgl_buffer##number)->buf.asvoid 00135 #define GLshortP_ref(number) &BGL_bufferType, &bgl_buffer##number 00136 #define GLshortP_def(number) Buffer *bgl_buffer##number 00137 00138 #define GLushortP_str "O!" 00139 #define GLushortP_var(number) (bgl_buffer##number)->buf.asvoid 00140 #define GLushortP_ref(number) &BGL_bufferType, &bgl_buffer##number 00141 #define GLushortP_def(number) Buffer *bgl_buffer##number 00142 00143 #define GLfloatP_str "O!" 00144 #define GLfloatP_var(number) (bgl_buffer##number)->buf.asvoid 00145 #define GLfloatP_ref(number) &BGL_bufferType, &bgl_buffer##number 00146 #define GLfloatP_def(number) Buffer *bgl_buffer##number 00147 00148 #define GLdoubleP_str "O!" 00149 #define GLdoubleP_var(number) (bgl_buffer##number)->buf.asvoid 00150 #define GLdoubleP_ref(number) &BGL_bufferType, &bgl_buffer##number 00151 #define GLdoubleP_def(number) Buffer *bgl_buffer##number 00152 00153 #define GLclampfP_str "O!" 00154 #define GLclampfP_var(number) (bgl_buffer##number)->buf.asvoid 00155 #define GLclampfP_ref(number) &BGL_bufferType, &bgl_buffer##number 00156 #define GLclampfP_def(number) Buffer *bgl_buffer##number 00157 00158 #define GLvoidP_str "O!" 00159 #define GLvoidP_var(number) (bgl_buffer##number)->buf.asvoid 00160 #define GLvoidP_ref(number) &BGL_bufferType, &bgl_buffer##number 00161 #define GLvoidP_def(number) Buffer *bgl_buffer##number 00162 00163 #define buffer_str "O!" 00164 #define buffer_var(number) (bgl_buffer##number)->buf.asvoid 00165 #define buffer_ref(number) &BGL_bufferType, &bgl_buffer##number 00166 #define buffer_def(number) Buffer *bgl_buffer##number 00167 00168 /*@The standard GL typedefs are used as prototypes, we can't 00169 * use the GL type directly because Py_ArgParse expects normal 00170 * C types. 00171 * 00172 * Py_ArgParse doesn't grok writing into unsigned variables, 00173 * so we use signed everything (even stuff that should be unsigned. 00174 */ 00175 00176 /* typedef unsigned int GLenum; */ 00177 #define GLenum_str "i" 00178 #define GLenum_var(num) bgl_var##num 00179 #define GLenum_ref(num) &bgl_var##num 00180 #define GLenum_def(num) /* unsigned */ int GLenum_var(num) 00181 00182 /* typedef unsigned int GLboolean; */ 00183 #define GLboolean_str "b" 00184 #define GLboolean_var(num) bgl_var##num 00185 #define GLboolean_ref(num) &bgl_var##num 00186 #define GLboolean_def(num) /* unsigned */ char GLboolean_var(num) 00187 00188 /* typedef unsigned int GLbitfield; */ 00189 #define GLbitfield_str "i" 00190 #define GLbitfield_var(num) bgl_var##num 00191 #define GLbitfield_ref(num) &bgl_var##num 00192 #define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num) 00193 00194 /* typedef signed char GLbyte; */ 00195 #define GLbyte_str "b" 00196 #define GLbyte_var(num) bgl_var##num 00197 #define GLbyte_ref(num) &bgl_var##num 00198 #define GLbyte_def(num) signed char GLbyte_var(num) 00199 00200 /* typedef short GLshort; */ 00201 #define GLshort_str "h" 00202 #define GLshort_var(num) bgl_var##num 00203 #define GLshort_ref(num) &bgl_var##num 00204 #define GLshort_def(num) short GLshort_var(num) 00205 00206 /* typedef int GLint; */ 00207 #define GLint_str "i" 00208 #define GLint_var(num) bgl_var##num 00209 #define GLint_ref(num) &bgl_var##num 00210 #define GLint_def(num) int GLint_var(num) 00211 00212 /* typedef int GLsizei; */ 00213 #define GLsizei_str "i" 00214 #define GLsizei_var(num) bgl_var##num 00215 #define GLsizei_ref(num) &bgl_var##num 00216 #define GLsizei_def(num) int GLsizei_var(num) 00217 00218 /* typedef unsigned char GLubyte; */ 00219 #define GLubyte_str "B" 00220 #define GLubyte_var(num) bgl_var##num 00221 #define GLubyte_ref(num) &bgl_var##num 00222 #define GLubyte_def(num) /* unsigned */ char GLubyte_var(num) 00223 00224 /* typedef unsigned short GLushort; */ 00225 #define GLushort_str "H" 00226 #define GLushort_var(num) bgl_var##num 00227 #define GLushort_ref(num) &bgl_var##num 00228 #define GLushort_def(num) /* unsigned */ short GLushort_var(num) 00229 00230 /* typedef unsigned int GLuint; */ 00231 #define GLuint_str "I" 00232 #define GLuint_var(num) bgl_var##num 00233 #define GLuint_ref(num) &bgl_var##num 00234 #define GLuint_def(num) /* unsigned */ int GLuint_var(num) 00235 00236 /* typedef float GLfloat; */ 00237 #define GLfloat_str "f" 00238 #define GLfloat_var(num) bgl_var##num 00239 #define GLfloat_ref(num) &bgl_var##num 00240 #define GLfloat_def(num) float GLfloat_var(num) 00241 00242 /* typedef float GLclampf; */ 00243 #define GLclampf_str "f" 00244 #define GLclampf_var(num) bgl_var##num 00245 #define GLclampf_ref(num) &bgl_var##num 00246 #define GLclampf_def(num) float GLclampf_var(num) 00247 00248 /* typedef double GLdouble; */ 00249 #define GLdouble_str "d" 00250 #define GLdouble_var(num) bgl_var##num 00251 #define GLdouble_ref(num) &bgl_var##num 00252 #define GLdouble_def(num) double GLdouble_var(num) 00253 00254 /* typedef double GLclampd; */ 00255 #define GLclampd_str "d" 00256 #define GLclampd_var(num) bgl_var##num 00257 #define GLclampd_ref(num) &bgl_var##num 00258 #define GLclampd_def(num) double GLclampd_var(num) 00259 00260 /* typedef void GLvoid; */ 00261 /* #define GLvoid_str "" */ 00262 /* #define GLvoid_var(num) bgl_var##num */ 00263 /* #define GLvoid_ref(num) &bgl_var##num */ 00264 /* #define GLvoid_def(num) char bgl_var##num */ 00265 00266 #define arg_def1(a1) a1##_def(1) 00267 #define arg_def2(a1, a2) arg_def1(a1); a2##_def(2) 00268 #define arg_def3(a1, a2, a3) arg_def2(a1, a2); a3##_def(3) 00269 #define arg_def4(a1, a2, a3, a4) arg_def3(a1, a2, a3); a4##_def(4) 00270 #define arg_def5(a1, a2, a3, a4, a5) arg_def4(a1, a2, a3, a4); a5##_def(5) 00271 #define arg_def6(a1, a2, a3, a4, a5, a6)arg_def5(a1, a2, a3, a4, a5); a6##_def(6) 00272 #define arg_def7(a1, a2, a3, a4, a5, a6, a7)arg_def6(a1, a2, a3, a4, a5, a6); a7##_def(7) 00273 #define arg_def8(a1, a2, a3, a4, a5, a6, a7, a8)arg_def7(a1, a2, a3, a4, a5, a6, a7); a8##_def(8) 00274 #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) 00275 #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) 00276 00277 #define arg_var1(a1) a1##_var(1) 00278 #define arg_var2(a1, a2) arg_var1(a1), a2##_var(2) 00279 #define arg_var3(a1, a2, a3) arg_var2(a1, a2), a3##_var(3) 00280 #define arg_var4(a1, a2, a3, a4) arg_var3(a1, a2, a3), a4##_var(4) 00281 #define arg_var5(a1, a2, a3, a4, a5) arg_var4(a1, a2, a3, a4), a5##_var(5) 00282 #define arg_var6(a1, a2, a3, a4, a5, a6)arg_var5(a1, a2, a3, a4, a5), a6##_var(6) 00283 #define arg_var7(a1, a2, a3, a4, a5, a6, a7)arg_var6(a1, a2, a3, a4, a5, a6), a7##_var(7) 00284 #define arg_var8(a1, a2, a3, a4, a5, a6, a7, a8)arg_var7(a1, a2, a3, a4, a5, a6, a7), a8##_var(8) 00285 #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) 00286 #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) 00287 00288 #define arg_ref1(a1) a1##_ref(1) 00289 #define arg_ref2(a1, a2) arg_ref1(a1), a2##_ref(2) 00290 #define arg_ref3(a1, a2, a3) arg_ref2(a1, a2), a3##_ref(3) 00291 #define arg_ref4(a1, a2, a3, a4) arg_ref3(a1, a2, a3), a4##_ref(4) 00292 #define arg_ref5(a1, a2, a3, a4, a5) arg_ref4(a1, a2, a3, a4), a5##_ref(5) 00293 #define arg_ref6(a1, a2, a3, a4, a5, a6)arg_ref5(a1, a2, a3, a4, a5), a6##_ref(6) 00294 #define arg_ref7(a1, a2, a3, a4, a5, a6, a7)arg_ref6(a1, a2, a3, a4, a5, a6), a7##_ref(7) 00295 #define arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8)arg_ref7(a1, a2, a3, a4, a5, a6, a7), a8##_ref(8) 00296 #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) 00297 #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) 00298 00299 #define arg_str1(a1) a1##_str 00300 #define arg_str2(a1, a2) arg_str1(a1) a2##_str 00301 #define arg_str3(a1, a2, a3) arg_str2(a1, a2) a3##_str 00302 #define arg_str4(a1, a2, a3, a4) arg_str3(a1, a2, a3) a4##_str 00303 #define arg_str5(a1, a2, a3, a4, a5) arg_str4(a1, a2, a3, a4) a5##_str 00304 #define arg_str6(a1, a2, a3, a4, a5, a6)arg_str5(a1, a2, a3, a4, a5) a6##_str 00305 #define arg_str7(a1, a2, a3, a4, a5, a6, a7)arg_str6(a1, a2, a3, a4, a5, a6) a7##_str 00306 #define arg_str8(a1, a2, a3, a4, a5, a6, a7, a8)arg_str7(a1, a2, a3, a4, a5, a6, a7) a8##_str 00307 #define arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) a9##_str 00308 #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 00309 00310 #define ret_def_void 00311 #define ret_set_void 00312 #define ret_ret_void return Py_INCREF(Py_None), Py_None 00313 00314 #define ret_def_GLint int ret_int 00315 #define ret_set_GLint ret_int= 00316 #define ret_ret_GLint return PyLong_FromLong(ret_int) 00317 00318 #define ret_def_GLuint unsigned int ret_uint 00319 #define ret_set_GLuint ret_uint= 00320 #define ret_ret_GLuint return PyLong_FromLong((long) ret_uint) 00321 00322 #define ret_def_GLenum unsigned int ret_uint 00323 #define ret_set_GLenum ret_uint= 00324 #define ret_ret_GLenum return PyLong_FromLong((long) ret_uint) 00325 00326 #define ret_def_GLboolean unsigned char ret_bool 00327 #define ret_set_GLboolean ret_bool= 00328 #define ret_ret_GLboolean return PyLong_FromLong((long) ret_bool) 00329 00330 #define ret_def_GLstring const unsigned char *ret_str; 00331 #define ret_set_GLstring ret_str= 00332 00333 #define ret_ret_GLstring \ 00334 if (ret_str) { \ 00335 return PyUnicode_FromString((const char *)ret_str); \ 00336 } \ 00337 else { \ 00338 PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \ 00339 return NULL; \ 00340 } \ 00341 00342 #endif /* BGL_H */