opengl 0.7.0.pre1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +8 -0
  3. data/History.txt +36 -0
  4. data/MIT-LICENSE +18 -0
  5. data/Manifest.txt +140 -0
  6. data/README.rdoc +51 -0
  7. data/Rakefile +129 -0
  8. data/Rakefile.cross +104 -0
  9. data/doc/build_install.txt +119 -0
  10. data/doc/extensions.txt.in +348 -0
  11. data/doc/history.txt +66 -0
  12. data/doc/requirements_and_design.txt +117 -0
  13. data/doc/roadmap.txt +28 -0
  14. data/doc/scientific_use.txt +35 -0
  15. data/doc/supplies/page_template.html +71 -0
  16. data/doc/thanks.txt +29 -0
  17. data/doc/tutorial.txt +469 -0
  18. data/examples/NeHe/nehe_lesson02.rb +117 -0
  19. data/examples/NeHe/nehe_lesson03.rb +122 -0
  20. data/examples/NeHe/nehe_lesson04.rb +133 -0
  21. data/examples/NeHe/nehe_lesson05.rb +186 -0
  22. data/examples/NeHe/nehe_lesson36.rb +303 -0
  23. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  24. data/examples/OrangeBook/brick.frag +36 -0
  25. data/examples/OrangeBook/brick.rb +376 -0
  26. data/examples/OrangeBook/brick.vert +41 -0
  27. data/examples/OrangeBook/particle.frag +17 -0
  28. data/examples/OrangeBook/particle.rb +406 -0
  29. data/examples/OrangeBook/particle.vert +38 -0
  30. data/examples/README +16 -0
  31. data/examples/RedBook/aapoly.rb +142 -0
  32. data/examples/RedBook/aargb.rb +119 -0
  33. data/examples/RedBook/accanti.rb +162 -0
  34. data/examples/RedBook/accpersp.rb +215 -0
  35. data/examples/RedBook/alpha.rb +123 -0
  36. data/examples/RedBook/alpha3D.rb +158 -0
  37. data/examples/RedBook/bezcurve.rb +105 -0
  38. data/examples/RedBook/bezmesh.rb +137 -0
  39. data/examples/RedBook/checker.rb +124 -0
  40. data/examples/RedBook/clip.rb +95 -0
  41. data/examples/RedBook/colormat.rb +135 -0
  42. data/examples/RedBook/cube.rb +69 -0
  43. data/examples/RedBook/depthcue.rb +99 -0
  44. data/examples/RedBook/dof.rb +205 -0
  45. data/examples/RedBook/double.rb +105 -0
  46. data/examples/RedBook/drawf.rb +91 -0
  47. data/examples/RedBook/feedback.rb +145 -0
  48. data/examples/RedBook/fog.rb +167 -0
  49. data/examples/RedBook/font.rb +151 -0
  50. data/examples/RedBook/hello.rb +79 -0
  51. data/examples/RedBook/image.rb +137 -0
  52. data/examples/RedBook/jitter.rb +207 -0
  53. data/examples/RedBook/lines.rb +128 -0
  54. data/examples/RedBook/list.rb +111 -0
  55. data/examples/RedBook/material.rb +275 -0
  56. data/examples/RedBook/mipmap.rb +156 -0
  57. data/examples/RedBook/model.rb +113 -0
  58. data/examples/RedBook/movelight.rb +132 -0
  59. data/examples/RedBook/pickdepth.rb +179 -0
  60. data/examples/RedBook/planet.rb +108 -0
  61. data/examples/RedBook/quadric.rb +158 -0
  62. data/examples/RedBook/robot.rb +115 -0
  63. data/examples/RedBook/select.rb +196 -0
  64. data/examples/RedBook/smooth.rb +95 -0
  65. data/examples/RedBook/stencil.rb +163 -0
  66. data/examples/RedBook/stroke.rb +167 -0
  67. data/examples/RedBook/surface.rb +166 -0
  68. data/examples/RedBook/teaambient.rb +132 -0
  69. data/examples/RedBook/teapots.rb +182 -0
  70. data/examples/RedBook/tess.rb +183 -0
  71. data/examples/RedBook/texbind.rb +147 -0
  72. data/examples/RedBook/texgen.rb +169 -0
  73. data/examples/RedBook/texturesurf.rb +128 -0
  74. data/examples/RedBook/varray.rb +159 -0
  75. data/examples/RedBook/wrap.rb +148 -0
  76. data/examples/misc/OGLBench.rb +337 -0
  77. data/examples/misc/anisotropic.rb +194 -0
  78. data/examples/misc/fbo_test.rb +356 -0
  79. data/examples/misc/font-glut.rb +46 -0
  80. data/examples/misc/glfwtest.rb +30 -0
  81. data/examples/misc/plane.rb +161 -0
  82. data/examples/misc/readpixel.rb +65 -0
  83. data/examples/misc/sdltest.rb +34 -0
  84. data/examples/misc/trislam.rb +828 -0
  85. data/ext/common/common.h +448 -0
  86. data/ext/common/conv.h +234 -0
  87. data/ext/common/funcdef.h +280 -0
  88. data/ext/common/gl-enums.h +10031 -0
  89. data/ext/common/gl-error.h +23 -0
  90. data/ext/common/gl-types.h +67 -0
  91. data/ext/common/glu-enums.h +463 -0
  92. data/ext/gl/extconf.rb +43 -0
  93. data/ext/gl/gl-1.0-1.1.c +2811 -0
  94. data/ext/gl/gl-1.2.c +814 -0
  95. data/ext/gl/gl-1.3.c +443 -0
  96. data/ext/gl/gl-1.4.c +348 -0
  97. data/ext/gl/gl-1.5.c +225 -0
  98. data/ext/gl/gl-2.0.c +657 -0
  99. data/ext/gl/gl-2.1.c +57 -0
  100. data/ext/gl/gl-enums.c +3354 -0
  101. data/ext/gl/gl-error.c +104 -0
  102. data/ext/gl/gl-ext-3dfx.c +27 -0
  103. data/ext/gl/gl-ext-arb.c +866 -0
  104. data/ext/gl/gl-ext-ati.c +41 -0
  105. data/ext/gl/gl-ext-ext.c +889 -0
  106. data/ext/gl/gl-ext-gremedy.c +41 -0
  107. data/ext/gl/gl-ext-nv.c +679 -0
  108. data/ext/gl/gl.c +216 -0
  109. data/ext/glu/extconf.rb +51 -0
  110. data/ext/glu/glu-enums.c +164 -0
  111. data/ext/glu/glu.c +1530 -0
  112. data/ext/glut/extconf.rb +67 -0
  113. data/ext/glut/glut.c +1624 -0
  114. data/lib/opengl.rb +89 -0
  115. data/test/README +10 -0
  116. data/test/tc_common.rb +98 -0
  117. data/test/tc_ext_arb.rb +467 -0
  118. data/test/tc_ext_ati.rb +33 -0
  119. data/test/tc_ext_ext.rb +551 -0
  120. data/test/tc_ext_gremedy.rb +36 -0
  121. data/test/tc_ext_nv.rb +357 -0
  122. data/test/tc_func_10_11.rb +1281 -0
  123. data/test/tc_func_12.rb +186 -0
  124. data/test/tc_func_13.rb +229 -0
  125. data/test/tc_func_14.rb +197 -0
  126. data/test/tc_func_15.rb +270 -0
  127. data/test/tc_func_20.rb +346 -0
  128. data/test/tc_func_21.rb +541 -0
  129. data/test/tc_glu.rb +310 -0
  130. data/test/tc_include_gl.rb +35 -0
  131. data/test/tc_misc.rb +54 -0
  132. data/test/tc_require_gl.rb +34 -0
  133. data/utils/README +11 -0
  134. data/utils/enumgen.rb +112 -0
  135. data/utils/extlistgen.rb +90 -0
  136. data/utils/mkdn2html.rb +59 -0
  137. data/utils/post-mkdn2html.rb +91 -0
  138. data/website/images/ogl.jpg +0 -0
  139. data/website/images/tab_bottom.gif +0 -0
  140. data/website/style.css +198 -0
  141. metadata +274 -0
@@ -0,0 +1,448 @@
1
+ /*
2
+ * Last edit by previous maintainer:
3
+ * 2000/01/06 16:37:43, kusano
4
+ *
5
+ * Copyright (C) 1999 - 2005 Yoshi <yoshi@giganet.net>
6
+ * Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
7
+ * Copyright (C) 2007 James Adam <james@lazyatom.com>
8
+ * Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
9
+ *
10
+ * This program is distributed under the terms of the MIT license.
11
+ * See the included MIT-LICENSE file for the terms of this license.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
17
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ */
21
+
22
+ #ifndef _COMMON_H_
23
+ #define _COMMON_H_
24
+
25
+ #include <ruby.h>
26
+ #include "extconf.h"
27
+
28
+ #include <ctype.h>
29
+
30
+ #ifdef HAVE_OPENGL_GL_H
31
+ #include <OpenGL/gl.h>
32
+ #endif
33
+
34
+ #ifdef HAVE_OPENGL_GLU_H
35
+ #include <OpenGL/glu.h>
36
+ #endif
37
+
38
+ #ifdef HAVE_GLUT_GLUT_H
39
+ #include <GLUT/glut.h>
40
+ #endif
41
+
42
+ #ifdef HAVE_DLFCN_H
43
+ #include <dlfcn.h>
44
+ #endif
45
+ #if false
46
+ #include <stdlib.h>
47
+ #include <string.h>
48
+ #endif
49
+
50
+ #ifdef HAVE_WINDOWS_H
51
+ #include <windows.h>
52
+ #endif
53
+
54
+ #ifdef HAVE_GL_GL_H
55
+ #include <GL/gl.h>
56
+ #endif
57
+
58
+ #ifdef HAVE_GL_GLU_H
59
+ #include <GL/glu.h>
60
+ #endif
61
+
62
+ #ifdef HAVE_GL_GLUT_H
63
+ #include <GL/glut.h>
64
+ #endif
65
+
66
+ #ifdef HAVE_GL_GLX_H
67
+ #include <GL/glx.h>
68
+ #endif
69
+
70
+ #include "gl-types.h"
71
+ #include "gl-enums.h"
72
+ #include "glu-enums.h"
73
+ #include "gl-error.h"
74
+
75
+ #include "funcdef.h"
76
+ #include "conv.h"
77
+
78
+ #ifndef APIENTRY
79
+ #define APIENTRY
80
+ #endif
81
+
82
+ #ifndef CALLBACK
83
+ #define CALLBACK
84
+ #endif
85
+
86
+ #ifndef GLUTCALLBACK
87
+ #define GLUTCALLBACK
88
+ #endif
89
+
90
+ #ifdef HAVE_WINDOWS_H
91
+ #define DLLEXPORT __declspec(dllexport)
92
+ #else
93
+ #define DLLEXPORT
94
+ #endif
95
+
96
+ /* these two macros are cast to a 32 bit type in the places they are used */
97
+ #ifndef RARRAY_LENINT
98
+ #define RARRAY_LENINT RARRAY_LEN
99
+ #endif
100
+
101
+ #ifndef RSTRING_LENINT
102
+ #define RSTRING_LENINT RSTRING_LEN
103
+ #endif
104
+
105
+ /* */
106
+
107
+ /* at least GL_MAX_VERTEX_ATTRIBS - usually 16 or 32 on today's high-end cards */
108
+ #define _MAX_VERTEX_ATTRIBS 64
109
+
110
+ typedef struct RArray RArray;
111
+
112
+ extern VALUE cProc;
113
+
114
+ /* For now we do not honor pixel store modes, so we need to
115
+ force them to defaults on each affected function call for
116
+ correct size requirement calculations */
117
+ #define FORCE_PIXEL_STORE_MODE \
118
+ glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); \
119
+ glPixelStorei(GL_PACK_ALIGNMENT, 1); \
120
+ glPixelStorei(GL_PACK_SKIP_PIXELS, 0); \
121
+ glPixelStorei(GL_PACK_SKIP_ROWS, 0); \
122
+ glPixelStorei(GL_PACK_ROW_LENGTH, 0); \
123
+ glPixelStorei(GL_PACK_SKIP_IMAGES, 0); \
124
+ glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0); \
125
+ if (CheckVersionExtension("GL_SGIS_texture4D")) { \
126
+ glPixelStorei(GL_PACK_SKIP_VOLUMES_SGIS, 0); \
127
+ glPixelStorei(GL_PACK_IMAGE_DEPTH_SGIS, 0); \
128
+ }
129
+
130
+ #define RESTORE_PIXEL_STORE_MODE \
131
+ glPopClientAttrib();
132
+
133
+ GLboolean CheckVersionExtension(const char *name);
134
+ GLint CheckBufferBinding(GLint buffer);
135
+
136
+ /* -------------------------------------------------------------------- */
137
+
138
+ /* gets number of components for given format */
139
+ static inline int glformat_size(GLenum format)
140
+ {
141
+ switch(format)
142
+ {
143
+ case GL_COLOR_INDEX:
144
+ case GL_RED:
145
+ case GL_GREEN:
146
+ case GL_BLUE:
147
+ case GL_ALPHA:
148
+ case GL_RED_INTEGER_EXT:
149
+ case GL_GREEN_INTEGER_EXT:
150
+ case GL_BLUE_INTEGER_EXT:
151
+ case GL_ALPHA_INTEGER_EXT:
152
+ case GL_STENCIL_INDEX:
153
+ case GL_DEPTH_COMPONENT:
154
+ case GL_LUMINANCE:
155
+ case GL_LUMINANCE_INTEGER_EXT:
156
+ return 1;
157
+
158
+ case GL_LUMINANCE_ALPHA:
159
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
160
+ case GL_422_EXT:
161
+ case GL_422_REV_EXT:
162
+ case GL_422_AVERAGE_EXT:
163
+ case GL_422_REV_AVERAGE_EXT:
164
+ case GL_YCRCB_422_SGIX:
165
+ case GL_YCBCR_422_APPLE:
166
+ case GL_YCBCR_MESA:
167
+ case GL_DEPTH_STENCIL_NV:
168
+ case GL_HILO_NV:
169
+ case GL_DSDT_NV:
170
+ case GL_DUDV_ATI:
171
+ case GL_DU8DV8_ATI:
172
+ case GL_FORMAT_SUBSAMPLE_24_24_OML:
173
+ return 2;
174
+
175
+ case GL_RGB:
176
+ case GL_RGB_INTEGER_EXT:
177
+ case GL_BGR_EXT:
178
+ case GL_BGR_INTEGER_EXT:
179
+ case GL_YCRCB_444_SGIX:
180
+ case GL_DSDT_MAG_NV:
181
+ case GL_FORMAT_SUBSAMPLE_244_244_OML:
182
+ return 3;
183
+
184
+ case GL_RGBA:
185
+ case GL_RGBA_INTEGER_EXT:
186
+ case GL_BGRA_EXT:
187
+ case GL_BGRA_INTEGER_EXT:
188
+ case GL_ABGR_EXT:
189
+ case GL_CMYK_EXT:
190
+ case GL_DSDT_MAG_VIB_NV:
191
+ return 4;
192
+
193
+ case GL_CMYKA_EXT:
194
+ return 5;
195
+
196
+ /* GL spec permits passing direct format size instead of enum (now obsolete) */
197
+ case 1:
198
+ case 2:
199
+ case 3:
200
+ case 4:
201
+ return format;
202
+
203
+ default:
204
+ rb_raise(rb_eArgError, "Unknown GL format enum %i",format);
205
+ return -1; /* not reached */
206
+ }
207
+ }
208
+
209
+ /* computes unit (pixel) size for given type and format */
210
+ static inline int gltype_glformat_unit_size(GLenum type,GLenum format)
211
+ {
212
+ unsigned int format_size;
213
+
214
+ format_size = glformat_size(format);
215
+
216
+ switch(type)
217
+ {
218
+ case GL_BYTE:
219
+ case GL_UNSIGNED_BYTE:
220
+ case GL_BITMAP:
221
+ return 1*format_size;
222
+
223
+ case GL_SHORT:
224
+ case GL_UNSIGNED_SHORT:
225
+ case GL_HALF_FLOAT_ARB:
226
+ return 2*format_size;
227
+
228
+ case GL_INT:
229
+ case GL_UNSIGNED_INT:
230
+ case GL_FLOAT:
231
+ return 4*format_size;
232
+
233
+ /* in packed formats all components are packed into/unpacked from single datatype,
234
+ so number of components(format_size) doesn't matter for total size calculation */
235
+ case GL_UNSIGNED_BYTE_3_3_2:
236
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
237
+ return 1;
238
+
239
+ case GL_UNSIGNED_SHORT_5_6_5:
240
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
241
+ case GL_UNSIGNED_SHORT_4_4_4_4:
242
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
243
+ case GL_UNSIGNED_SHORT_5_5_5_1:
244
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
245
+ case GL_UNSIGNED_SHORT_8_8_APPLE:
246
+ case GL_UNSIGNED_SHORT_8_8_REV_APPLE:
247
+ return 2;
248
+
249
+ case GL_UNSIGNED_INT_8_8_8_8:
250
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
251
+ case GL_UNSIGNED_INT_10_10_10_2:
252
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
253
+ case GL_UNSIGNED_INT_24_8_NV:
254
+ case GL_UNSIGNED_INT_S8_S8_8_8_NV:
255
+ case GL_UNSIGNED_INT_8_8_S8_S8_REV_NV:
256
+ case GL_UNSIGNED_INT_10F_11F_11F_REV_EXT:
257
+ case GL_UNSIGNED_INT_5_9_9_9_REV_EXT:
258
+ case GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV:
259
+ return 4;
260
+
261
+ default:
262
+ rb_raise(rb_eArgError, "Unknown GL type enum %i",type);
263
+ return -1; /* not reached */
264
+ }
265
+ }
266
+
267
+ /* returns size(units) for given type of shader uniform var */
268
+ static inline int get_uniform_size(GLenum uniform_type)
269
+ {
270
+ int uniform_size = 0;
271
+
272
+ switch (uniform_type) {
273
+ case GL_FLOAT:
274
+ case GL_INT:
275
+ case GL_UNSIGNED_INT:
276
+ case GL_BOOL:
277
+ case GL_SAMPLER_1D:
278
+ case GL_SAMPLER_2D:
279
+ case GL_SAMPLER_3D:
280
+ case GL_SAMPLER_CUBE:
281
+ case GL_SAMPLER_1D_SHADOW:
282
+ case GL_SAMPLER_2D_SHADOW:
283
+ case GL_SAMPLER_2D_RECT_ARB:
284
+ case GL_SAMPLER_2D_RECT_SHADOW_ARB:
285
+ case GL_SAMPLER_1D_ARRAY_EXT:
286
+ case GL_SAMPLER_2D_ARRAY_EXT:
287
+ case GL_SAMPLER_BUFFER_EXT:
288
+ case GL_SAMPLER_1D_ARRAY_SHADOW_EXT:
289
+ case GL_SAMPLER_2D_ARRAY_SHADOW_EXT:
290
+ case GL_SAMPLER_CUBE_SHADOW_EXT:
291
+ case GL_INT_SAMPLER_1D_EXT:
292
+ case GL_INT_SAMPLER_2D_EXT:
293
+ case GL_INT_SAMPLER_3D_EXT:
294
+ case GL_INT_SAMPLER_CUBE_EXT:
295
+ case GL_INT_SAMPLER_2D_RECT_EXT:
296
+ case GL_INT_SAMPLER_1D_ARRAY_EXT:
297
+ case GL_INT_SAMPLER_2D_ARRAY_EXT:
298
+ case GL_INT_SAMPLER_BUFFER_EXT:
299
+ case GL_UNSIGNED_INT_SAMPLER_1D_EXT:
300
+ case GL_UNSIGNED_INT_SAMPLER_2D_EXT:
301
+ case GL_UNSIGNED_INT_SAMPLER_3D_EXT:
302
+ case GL_UNSIGNED_INT_SAMPLER_CUBE_EXT:
303
+ case GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT:
304
+ case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT:
305
+ case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT:
306
+ case GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT:
307
+ uniform_size = 1;
308
+ break;
309
+ case GL_FLOAT_VEC2:
310
+ case GL_INT_VEC2:
311
+ case GL_UNSIGNED_INT_VEC2_EXT:
312
+ case GL_BOOL_VEC2:
313
+ uniform_size = 2;
314
+ break;
315
+ case GL_FLOAT_VEC3:
316
+ case GL_INT_VEC3:
317
+ case GL_UNSIGNED_INT_VEC3_EXT:
318
+ case GL_BOOL_VEC3:
319
+ uniform_size = 3;
320
+ break;
321
+ case GL_FLOAT_VEC4:
322
+ case GL_INT_VEC4:
323
+ case GL_UNSIGNED_INT_VEC4_EXT:
324
+ case GL_BOOL_VEC4:
325
+ case GL_FLOAT_MAT2:
326
+ uniform_size = 4;
327
+ break;
328
+ case GL_FLOAT_MAT2x3:
329
+ case GL_FLOAT_MAT3x2:
330
+ uniform_size = 6;
331
+ break;
332
+ case GL_FLOAT_MAT2x4:
333
+ case GL_FLOAT_MAT4x2:
334
+ uniform_size = 8;
335
+ break;
336
+ case GL_FLOAT_MAT3:
337
+ uniform_size = 9;
338
+ break;
339
+ case GL_FLOAT_MAT4x3:
340
+ case GL_FLOAT_MAT3x4:
341
+ uniform_size = 12;
342
+ break;
343
+ case GL_FLOAT_MAT4:
344
+ uniform_size = 16;
345
+ break;
346
+ default:
347
+ rb_raise(rb_eTypeError, "Unsupported uniform type '%i'",uniform_type);
348
+ }
349
+ return uniform_size;
350
+ }
351
+
352
+ static inline int GetDataSize(GLenum type,GLenum format,int num)
353
+ {
354
+ int size;
355
+ int unit_size;
356
+
357
+ unit_size = gltype_glformat_unit_size(type,format);
358
+
359
+ if (type==GL_BITMAP)
360
+ size = unit_size*(num/8); /* FIXME account for alignment */
361
+ else
362
+ size = unit_size*num;
363
+
364
+ return size;
365
+ }
366
+
367
+ /* Checks if data size of 'data' string confirms to passed format values */
368
+ /* 'num' is number of elements, each of size 'format' * 'type' */
369
+ static inline void CheckDataSize(GLenum type,GLenum format,int num,VALUE data)
370
+ {
371
+ int size;
372
+
373
+ size = GetDataSize(type,format,num);
374
+
375
+ if (RSTRING_LEN(data) < size)
376
+ rb_raise(rb_eArgError, "Length of specified data doesn't correspond to format and type parameters passed. Calculated length: %i",size);
377
+ }
378
+
379
+ /* -------------------------------------------------------------------- */
380
+ static inline VALUE allocate_buffer_with_string( long size )
381
+ {
382
+ return rb_str_new(NULL, size);
383
+ }
384
+
385
+ /* -------------------------------------------------------------------- */
386
+ static inline void *load_gl_function(const char *name,int raise)
387
+ {
388
+ void *func_ptr = NULL;
389
+
390
+ #if defined(__APPLE__)
391
+ void *library = NULL;
392
+ char* symbolName;
393
+ library = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
394
+
395
+ if (library == NULL)
396
+ rb_raise(rb_eRuntimeError,"Can't load OpenGL library for dynamic loading");
397
+
398
+ /* prepend a '_' for the Unix C symbol mangling convention */
399
+ symbolName = ALLOC_N(char,strlen(name) + 2);
400
+ symbolName[0] = '_';
401
+ strcpy(symbolName+1, name);
402
+
403
+ func_ptr = dlsym(library, symbolName);
404
+ xfree(symbolName);
405
+ dlclose(library);
406
+ #elif HAVE_WGLGETPROCADDRESS
407
+ func_ptr = wglGetProcAddress((LPCSTR)name);
408
+ #elif defined(GLX_VERSION_1_4)
409
+ func_ptr = glXGetProcAddress((const GLubyte *)name);
410
+ #else
411
+ func_ptr = glXGetProcAddressARB((const GLubyte *)name);
412
+ #endif
413
+
414
+ if (func_ptr == NULL && raise == 1)
415
+ rb_raise(rb_eNotImpError,"Function %s is not available on this system",name);
416
+
417
+ return func_ptr;
418
+ }
419
+
420
+ static inline VALUE pack_array_or_pass_string(GLenum type,VALUE ary)
421
+ {
422
+ const char *type_str;
423
+
424
+ if (TYPE(ary)==T_STRING)
425
+ return ary;
426
+
427
+ Check_Type(ary,T_ARRAY);
428
+
429
+ switch(type) {
430
+ case GL_FLOAT: type_str = "f*"; break;
431
+ case GL_DOUBLE: type_str = "d*"; break;
432
+ case GL_BYTE: type_str = "c*"; break;
433
+ case GL_SHORT: type_str = "s*"; break;
434
+ case GL_INT: type_str = "i*"; break;
435
+ case GL_UNSIGNED_BYTE: type_str = "C*"; break;
436
+ case GL_UNSIGNED_SHORT: type_str = "S*"; break;
437
+ case GL_UNSIGNED_INT: type_str = "I*"; break;
438
+ default:
439
+ rb_raise(rb_eTypeError,"Unknown type %i",type);
440
+ return Qnil; /* not reached */
441
+ }
442
+
443
+ return rb_funcall(ary,rb_intern("pack"),1,rb_str_new2(type_str));
444
+ }
445
+
446
+ /* -------------------------------------------------------------------- */
447
+
448
+ #endif /* _COMMON_H_ */
data/ext/common/conv.h ADDED
@@ -0,0 +1,234 @@
1
+ /*
2
+ * Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
3
+ *
4
+ * This program is distributed under the terms of the MIT license.
5
+ * See the included MIT-LICENSE file for the terms of this license.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
8
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
10
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
11
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
12
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
13
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ */
15
+
16
+ /* Functions and macros for datatype conversion between Ruby and C */
17
+
18
+ /*
19
+ Fast inline conversion functions as a replacement for the ones in libruby.
20
+ FIXNUM_P is simple logical AND check so it comes first, TYPE() is simple function,
21
+ and specified in header file so it can be inlined. For conversion, FIX2LONG is
22
+ simple right shift, and RFLOAT()-> just pointer dereference. For converting
23
+ Fixnum and Float types (which accounts for 99.9% of things you would want to pass
24
+ to OpenGL), there is large performance boost as result.
25
+
26
+ Also ruby 'true' and 'false' are converted to GL_TRUE/GL_FALSE for compatibility, and
27
+ finally, we fallback to library functions for any other data types (and error handling).
28
+ */
29
+
30
+ #if HAVE_STRUCT_RFLOAT_FLOAT_VALUE
31
+ #define FLOAT_VAL_ACCESS(val) RFLOAT(val)->float_value
32
+ #else
33
+ #define FLOAT_VAL_ACCESS(val) RFLOAT(val)->value
34
+ #endif
35
+
36
+ #define FASTCONV(_name_,_type_,_convfix_,_convfallback_) \
37
+ static inline _type_ _name_(val) \
38
+ VALUE val; \
39
+ { \
40
+ if (FIXNUM_P(val)) \
41
+ return (_type_) _convfix_(val); \
42
+ \
43
+ if (TYPE(val) == T_FLOAT) \
44
+ return (_type_)FLOAT_VAL_ACCESS(val); \
45
+ \
46
+ if ((val) == Qtrue) \
47
+ return (_type_)(GL_TRUE); \
48
+ \
49
+ if ((val) == Qfalse || (val) == Qnil) \
50
+ return (_type_)(GL_FALSE); \
51
+ \
52
+ return (_convfallback_(val)); \
53
+ }
54
+
55
+ FASTCONV(num2double,double,FIX2LONG,rb_num2dbl)
56
+ #if SIZEOF_INT < SIZEOF_LONG
57
+ /* For 64bit platforms with LP64 mode */
58
+ FASTCONV(num2int,long,FIX2LONG,rb_num2int)
59
+ FASTCONV(num2uint,unsigned long,FIX2ULONG,rb_num2uint)
60
+ #else
61
+ /* All other platforms */
62
+ FASTCONV(num2int,long,FIX2LONG,(int)NUM2LONG)
63
+ FASTCONV(num2uint,unsigned long,FIX2ULONG,(unsigned int)NUM2ULONG)
64
+ #endif
65
+
66
+ #undef FASTCONV
67
+
68
+ /* For conversion between ruby and GL boolean values */
69
+ #define GLBOOL2RUBY(x) (x)==GL_TRUE? Qtrue :( (x)==GL_FALSE? Qfalse : INT2NUM((x)))
70
+ #define RUBYBOOL2GL(x) (x)==Qtrue? GL_TRUE : GL_FALSE
71
+
72
+ #define cond_GLBOOL2RUBY_FUNC(_name_,_type_,_conv_) \
73
+ static inline VALUE _name_(GLenum pname,_type_ value) \
74
+ { \
75
+ switch (pname) { \
76
+ case GL_DELETE_STATUS: \
77
+ case GL_LINK_STATUS: \
78
+ case GL_VALIDATE_STATUS: \
79
+ case GL_COMPILE_STATUS: \
80
+ case GL_MINMAX_SINK: \
81
+ case GL_HISTOGRAM_SINK: \
82
+ case GL_COORD_REPLACE: \
83
+ case GL_TEXTURE_COMPRESSED: \
84
+ case GL_GENERATE_MIPMAP: \
85
+ case GL_TEXTURE_RESIDENT: \
86
+ case GL_BUFFER_MAPPED: \
87
+ case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: \
88
+ case GL_VERTEX_ATTRIB_ARRAY_ENABLED: \
89
+ case GL_QUERY_RESULT_AVAILABLE: \
90
+ case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB: \
91
+ case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: \
92
+ case GL_FENCE_STATUS_NV: \
93
+ case GL_TEXTURE_FLOAT_COMPONENTS_NV: \
94
+ case GL_SHADER_CONSISTENT_NV: \
95
+ case GL_TEXTURE_COMPARE_SGIX: \
96
+ case GLU_TESS_BOUNDARY_ONLY: \
97
+ case GLU_CULLING: \
98
+ case GLU_AUTO_LOAD_MATRIX: \
99
+ return GLBOOL2RUBY(value); \
100
+ default: \
101
+ return _conv_(value); \
102
+ } \
103
+ }
104
+
105
+ cond_GLBOOL2RUBY_FUNC(cond_GLBOOL2RUBY,GLint,INT2NUM)
106
+ cond_GLBOOL2RUBY_FUNC(cond_GLBOOL2RUBY_U,GLuint,UINT2NUM)
107
+ cond_GLBOOL2RUBY_FUNC(cond_GLBOOL2RUBY_LL,GLint64EXT,LL2NUM)
108
+ cond_GLBOOL2RUBY_FUNC(cond_GLBOOL2RUBY_ULL,GLuint64EXT,ULL2NUM)
109
+ cond_GLBOOL2RUBY_FUNC(cond_GLBOOL2RUBY_F,GLfloat,rb_float_new)
110
+ cond_GLBOOL2RUBY_FUNC(cond_GLBOOL2RUBY_D,GLdouble,rb_float_new)
111
+
112
+
113
+ /* For conversion between ruby array (or object that can be converted to array) and C array.
114
+ The C array has to be preallocated by calling function. */
115
+ #define ARY2CTYPE(_type_,_convert_) \
116
+ static inline long ary2c##_type_( arg, cary, maxlen ) \
117
+ VALUE arg; \
118
+ GL##_type_ cary[]; \
119
+ long maxlen; \
120
+ { \
121
+ long i; \
122
+ VALUE ary = rb_Array(arg); \
123
+ if (maxlen < 1) \
124
+ maxlen = RARRAY_LEN(ary); \
125
+ else \
126
+ maxlen = maxlen < RARRAY_LEN(ary) ? maxlen : RARRAY_LEN(ary); \
127
+ for (i=0; i < maxlen; i++) \
128
+ cary[i] = (GL##_type_)_convert_(rb_ary_entry(ary,i)); \
129
+ return i; \
130
+ }
131
+
132
+ ARY2CTYPE(int,NUM2INT)
133
+ ARY2CTYPE(uint,NUM2UINT)
134
+ ARY2CTYPE(byte,NUM2INT)
135
+ ARY2CTYPE(ubyte,NUM2INT)
136
+ ARY2CTYPE(short,NUM2INT)
137
+ ARY2CTYPE(ushort,NUM2INT)
138
+ ARY2CTYPE(boolean,NUM2INT)
139
+ ARY2CTYPE(float,NUM2DBL)
140
+ ARY2CTYPE(double,NUM2DBL)
141
+
142
+ #define ary2cflt ary2cfloat
143
+ #define ary2cdbl ary2cdouble
144
+
145
+ #undef ARY2CTYPE
146
+
147
+ /* Converts either array or object responding to #to_a to C-style array */
148
+ #define ARY2CMAT(_type_) \
149
+ static inline void ary2cmat##_type_(rary, cary, cols, rows) \
150
+ VALUE rary; \
151
+ _type_ cary[]; \
152
+ int cols,rows; \
153
+ { \
154
+ int i; \
155
+ \
156
+ rary = rb_Array(rary); \
157
+ rary = rb_funcall(rary,rb_intern("flatten"),0); \
158
+ \
159
+ if (RARRAY_LEN(rary) != cols*rows) \
160
+ rb_raise(rb_eArgError, "passed array/matrix must have %i*%i elements",cols,rows); \
161
+ \
162
+ for (i=0; i < cols*rows; i++) \
163
+ cary[i] = (_type_) NUM2DBL(rb_ary_entry(rary,i)); \
164
+ }
165
+
166
+ ARY2CMAT(double)
167
+ ARY2CMAT(float)
168
+ #undef ARY2CMAT
169
+
170
+ #define ARY2CMATCNT(_type_) \
171
+ static inline void ary2cmat##_type_##count(rary, cary, cols, rows) \
172
+ VALUE rary; \
173
+ _type_ cary[]; \
174
+ int cols,rows; \
175
+ { \
176
+ int i; \
177
+ \
178
+ rary = rb_Array(rary); \
179
+ rary = rb_funcall(rary,rb_intern("flatten"),0); \
180
+ \
181
+ if (RARRAY_LEN(rary)<1 || (RARRAY_LEN(rary) % (cols*rows) != 0)) {\
182
+ xfree(cary); \
183
+ rb_raise(rb_eArgError, "passed array/matrix must conatain n x (%i*%i) elements",cols,rows); \
184
+ } \
185
+ \
186
+ for (i=0; i < RARRAY_LEN(rary); i++) \
187
+ cary[i] = (_type_) NUM2DBL(rb_ary_entry(rary,i)); \
188
+ }
189
+
190
+ ARY2CMATCNT(double)
191
+ ARY2CMATCNT(float)
192
+ #undef ARY2CMATCNT
193
+
194
+
195
+ #define EMPTY
196
+ #define FREE(_x_) xfree(_x_);
197
+
198
+ #define RET_ARRAY_OR_SINGLE(_size_,_conv_,_params_) RET_ARRAY_OR_SINGLE_FUNC(_size_,_conv_,_params_,EMPTY)
199
+ #define RET_ARRAY_OR_SINGLE_FREE(_size_,_conv_,_params_) RET_ARRAY_OR_SINGLE_FUNC(_size_,_conv_,_params_,FREE(_params_))
200
+
201
+ #define RET_ARRAY_OR_SINGLE_FUNC(_size_,_conv_,_params_,_extra_) \
202
+ { \
203
+ int iter; \
204
+ VALUE return_array; \
205
+ if (_size_ == 1) { \
206
+ return_array = _conv_(_params_[0]); \
207
+ } else { \
208
+ return_array = rb_ary_new2(_size_); \
209
+ for(iter=0;iter<_size_;iter++) \
210
+ rb_ary_push(return_array, _conv_(_params_[iter])); \
211
+ } \
212
+ _extra_ \
213
+ CHECK_GLERROR \
214
+ return return_array; \
215
+ }
216
+
217
+ #define RET_ARRAY_OR_SINGLE_BOOL(_size_,_conv_,_enum_,_params_) RET_ARRAY_OR_SINGLE_BOOL_FUNC(_size_,_conv_,_enum_,_params_,EMPTY)
218
+ #define RET_ARRAY_OR_SINGLE_BOOL_FREE(_size_,_conv_,_enum_,_params_) RET_ARRAY_OR_SINGLE_BOOL_FUNC(_size_,_conv_,_enum_,_params_,FREE(_params_))
219
+
220
+ #define RET_ARRAY_OR_SINGLE_BOOL_FUNC(_size_,_conv_,_enum_,_params_,_extra_) \
221
+ { \
222
+ int iter; \
223
+ VALUE return_array; \
224
+ if (_size_ == 1) { \
225
+ return_array = _conv_(_enum_,_params_[0]); \
226
+ } else { \
227
+ return_array = rb_ary_new2(_size_); \
228
+ for(iter=0;iter<_size_;iter++) \
229
+ rb_ary_push(return_array, _conv_(_enum_,_params_[iter])); \
230
+ } \
231
+ _extra_ \
232
+ CHECK_GLERROR \
233
+ return return_array; \
234
+ }