ruby-opengl 0.60.1 → 0.61.0

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