ruby-opengl 0.50.0 → 0.60.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +15 -11
- data/doc/build_install.txt +10 -6
- data/doc/extensions.txt.in +348 -0
- data/doc/history.txt +4 -0
- data/doc/roadmap.txt +4 -6
- data/doc/scientific_use.txt +7 -0
- data/doc/supplies/page_template.html +2 -1
- data/doc/thanks.txt +5 -0
- data/doc/tutorial.txt +431 -121
- data/examples/NeHe/nehe_lesson02.rb +1 -1
- data/examples/NeHe/nehe_lesson03.rb +1 -1
- data/examples/NeHe/nehe_lesson04.rb +1 -1
- data/examples/NeHe/nehe_lesson05.rb +1 -1
- data/examples/NeHe/nehe_lesson36.rb +1 -1
- data/examples/OrangeBook/brick.rb +3 -15
- data/examples/OrangeBook/particle.rb +2 -20
- data/examples/RedBook/aapoly.rb +1 -1
- data/examples/RedBook/aargb.rb +2 -2
- data/examples/RedBook/accanti.rb +1 -1
- data/examples/RedBook/accpersp.rb +1 -1
- data/examples/RedBook/alpha.rb +2 -2
- data/examples/RedBook/alpha3D.rb +1 -1
- data/examples/RedBook/bezcurve.rb +1 -1
- data/examples/RedBook/bezmesh.rb +1 -1
- data/examples/RedBook/checker.rb +1 -1
- data/examples/RedBook/clip.rb +1 -1
- data/examples/RedBook/colormat.rb +1 -1
- data/examples/RedBook/cube.rb +1 -1
- data/examples/RedBook/depthcue.rb +1 -1
- data/examples/RedBook/dof.rb +1 -1
- data/examples/RedBook/double.rb +1 -1
- data/examples/RedBook/drawf.rb +1 -1
- data/examples/RedBook/feedback.rb +1 -1
- data/examples/RedBook/fog.rb +1 -1
- data/examples/RedBook/font.rb +2 -2
- data/examples/RedBook/hello.rb +1 -1
- data/examples/RedBook/image.rb +4 -4
- data/examples/RedBook/lines.rb +1 -1
- data/examples/RedBook/list.rb +1 -1
- data/examples/RedBook/material.rb +1 -1
- data/examples/RedBook/mipmap.rb +1 -1
- data/examples/RedBook/model.rb +1 -1
- data/examples/RedBook/movelight.rb +1 -1
- data/examples/RedBook/pickdepth.rb +1 -1
- data/examples/RedBook/planet.rb +5 -5
- data/examples/RedBook/quadric.rb +1 -1
- data/examples/RedBook/robot.rb +5 -5
- data/examples/RedBook/select.rb +1 -1
- data/examples/RedBook/smooth.rb +1 -1
- data/examples/RedBook/stencil.rb +1 -1
- data/examples/RedBook/stroke.rb +2 -2
- data/examples/RedBook/surface.rb +1 -1
- data/examples/RedBook/teaambient.rb +1 -1
- data/examples/RedBook/teapots.rb +1 -1
- data/examples/RedBook/tess.rb +1 -1
- data/examples/RedBook/texbind.rb +1 -1
- data/examples/RedBook/texgen.rb +5 -5
- data/examples/RedBook/texturesurf.rb +1 -1
- data/examples/RedBook/varray.rb +1 -1
- data/examples/RedBook/wrap.rb +5 -5
- data/examples/misc/OGLBench.rb +337 -0
- data/examples/misc/anisotropic.rb +1 -1
- data/examples/misc/fbo_test.rb +356 -0
- data/examples/misc/font-glut.rb +1 -1
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/md2model.rb +15 -0
- data/examples/misc/plane.rb +1 -1
- data/examples/misc/readpixel.rb +1 -1
- data/examples/misc/sdltest.rb +34 -0
- data/examples/misc/trislam.rb +828 -0
- data/ext/common/common.h +126 -218
- data/ext/common/conv.h +244 -0
- data/ext/common/funcdef.h +280 -0
- data/ext/common/gl-error.h +23 -0
- data/ext/common/gl-types.h +14 -0
- data/ext/gl/gl-1.0-1.1.c +497 -1255
- data/ext/gl/gl-1.2.c +121 -304
- data/ext/gl/gl-1.3.c +78 -339
- data/ext/gl/gl-1.4.c +102 -164
- data/ext/gl/gl-1.5.c +42 -173
- data/ext/gl/gl-2.0.c +273 -1039
- data/ext/gl/gl-2.1.c +15 -19
- data/ext/gl/gl-enums.c +3 -2
- data/ext/gl/gl-error.c +104 -0
- data/ext/gl/gl-ext-3dfx.c +27 -0
- data/ext/gl/gl-ext-arb.c +812 -12
- data/ext/gl/gl-ext-ati.c +41 -0
- data/ext/gl/gl-ext-ext.c +791 -119
- data/ext/gl/gl-ext-gremedy.c +41 -0
- data/ext/gl/gl-ext-nv.c +679 -0
- data/ext/gl/gl.c +48 -28
- data/ext/gl/mkrf_conf.rb +13 -10
- data/ext/glu/glu-enums.c +3 -2
- data/ext/glu/glu.c +136 -41
- data/ext/glu/mkrf_conf.rb +15 -12
- data/ext/glut/glut.c +37 -80
- data/ext/glut/mkrf_conf.rb +17 -13
- data/lib/opengl.rb +29 -53
- data/test/tc_common.rb +9 -3
- data/test/tc_ext_arb.rb +397 -3
- data/test/tc_ext_ati.rb +33 -0
- data/test/tc_ext_ext.rb +479 -2
- data/test/tc_ext_gremedy.rb +36 -0
- data/test/tc_ext_nv.rb +357 -0
- data/test/tc_func_10_11.rb +93 -67
- data/test/tc_func_12.rb +11 -11
- data/test/tc_func_13.rb +38 -18
- data/test/tc_func_14.rb +2 -2
- data/test/tc_func_15.rb +10 -10
- data/test/tc_func_20.rb +20 -20
- data/test/tc_func_21.rb +53 -22
- data/test/tc_glu.rb +9 -4
- data/test/tc_misc.rb +15 -2
- metadata +22 -8
- data/doc/extensions.txt +0 -361
- data/examples/RedBook/aaindex.rb +0 -97
- data/examples/misc/smooth.rb +0 -42
- data/examples/misc/test.rb +0 -65
data/ext/common/common.h
CHANGED
@@ -24,6 +24,8 @@
|
|
24
24
|
|
25
25
|
#include <ruby.h>
|
26
26
|
|
27
|
+
#include <ctype.h>
|
28
|
+
|
27
29
|
#ifdef __APPLE__
|
28
30
|
#include <OpenGL/gl.h>
|
29
31
|
#include <OpenGL/glu.h>
|
@@ -46,6 +48,10 @@
|
|
46
48
|
#include "gl-types.h"
|
47
49
|
#include "gl-enums.h"
|
48
50
|
#include "glu-enums.h"
|
51
|
+
#include "gl-error.h"
|
52
|
+
|
53
|
+
#include "funcdef.h"
|
54
|
+
#include "conv.h"
|
49
55
|
|
50
56
|
#ifndef APIENTRY
|
51
57
|
#define APIENTRY
|
@@ -67,21 +73,16 @@
|
|
67
73
|
|
68
74
|
/* */
|
69
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
|
+
|
70
79
|
typedef struct RArray RArray;
|
71
80
|
|
72
81
|
extern VALUE cProc;
|
73
82
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#define LOAD_GL_EXT_FUNC(_NAME_,_EXTNAME_) \
|
79
|
-
if (fptr_##_NAME_==NULL) {\
|
80
|
-
if (CheckExtension(_EXTNAME_)==GL_FALSE) \
|
81
|
-
rb_raise(rb_eNotImpError,"Extension %s is not available on this system",_EXTNAME_); \
|
82
|
-
fptr_##_NAME_ = load_gl_function(#_NAME_, 1); \
|
83
|
-
}
|
84
|
-
|
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 */
|
85
86
|
#define FORCE_PIXEL_STORE_MODE \
|
86
87
|
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); \
|
87
88
|
glPixelStorei(GL_PACK_ALIGNMENT, 1); \
|
@@ -90,7 +91,7 @@ if (fptr_##_NAME_==NULL) {\
|
|
90
91
|
glPixelStorei(GL_PACK_ROW_LENGTH, 0); \
|
91
92
|
glPixelStorei(GL_PACK_SKIP_IMAGES, 0); \
|
92
93
|
glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0); \
|
93
|
-
if (
|
94
|
+
if (CheckVersionExtension("GL_SGIS_texture4D")) { \
|
94
95
|
glPixelStorei(GL_PACK_SKIP_VOLUMES_SGIS, 0); \
|
95
96
|
glPixelStorei(GL_PACK_IMAGE_DEPTH_SGIS, 0); \
|
96
97
|
}
|
@@ -98,151 +99,9 @@ if (fptr_##_NAME_==NULL) {\
|
|
98
99
|
#define RESTORE_PIXEL_STORE_MODE \
|
99
100
|
glPopClientAttrib();
|
100
101
|
|
101
|
-
GLboolean
|
102
|
+
GLboolean CheckVersionExtension(const char *name);
|
102
103
|
GLint CheckBufferBinding(GLint buffer);
|
103
104
|
|
104
|
-
/* -------------------------------------------------------------------- */
|
105
|
-
#ifndef NUM2DBL
|
106
|
-
#define NUM2DBL(_val) num2double(_val)
|
107
|
-
|
108
|
-
static inline double num2double( VALUE val )
|
109
|
-
{
|
110
|
-
struct RFloat* flt;
|
111
|
-
if (NIL_P(val)) return 0;
|
112
|
-
flt = RFLOAT(f_float(0, val));
|
113
|
-
return flt->value;
|
114
|
-
}
|
115
|
-
#endif
|
116
|
-
|
117
|
-
/* -------------------------------------------------------------------- */
|
118
|
-
#define ARY2INTEGRAL(_type_,_convert_) \
|
119
|
-
static inline int ary2c##_type_( arg, cary, maxlen ) \
|
120
|
-
VALUE arg; \
|
121
|
-
GL##_type_ cary[]; \
|
122
|
-
int maxlen; \
|
123
|
-
{ \
|
124
|
-
int i; \
|
125
|
-
struct RArray* ary; \
|
126
|
-
VALUE entry; \
|
127
|
-
ary = RARRAY(rb_Array(arg)); \
|
128
|
-
if (maxlen < 1) \
|
129
|
-
maxlen = ary->len; \
|
130
|
-
else \
|
131
|
-
maxlen = maxlen < ary->len ? maxlen : ary->len; \
|
132
|
-
for (i=0; i < maxlen; i++) \
|
133
|
-
{ \
|
134
|
-
entry = rb_ary_entry((VALUE)ary,i); \
|
135
|
-
cary[i] = (GL##_type_)_convert_(entry); \
|
136
|
-
} \
|
137
|
-
return i; \
|
138
|
-
}
|
139
|
-
|
140
|
-
ARY2INTEGRAL(int,NUM2INT)
|
141
|
-
ARY2INTEGRAL(uint,NUM2UINT)
|
142
|
-
ARY2INTEGRAL(byte,NUM2INT)
|
143
|
-
ARY2INTEGRAL(ubyte,NUM2INT)
|
144
|
-
ARY2INTEGRAL(short,NUM2INT)
|
145
|
-
ARY2INTEGRAL(ushort,NUM2INT)
|
146
|
-
ARY2INTEGRAL(boolean,NUM2INT)
|
147
|
-
#undef ARY2INTEGRAL
|
148
|
-
|
149
|
-
/* -------------------------------------------------------------------- */
|
150
|
-
static inline int ary2cflt(arg, cary, maxlen)
|
151
|
-
VALUE arg;
|
152
|
-
float cary[];
|
153
|
-
int maxlen;
|
154
|
-
{
|
155
|
-
int i;
|
156
|
-
struct RArray* ary;
|
157
|
-
ary = RARRAY(rb_Array(arg));
|
158
|
-
if (maxlen < 1)
|
159
|
-
maxlen = ary->len;
|
160
|
-
else
|
161
|
-
maxlen = maxlen < ary->len ? maxlen : ary->len;
|
162
|
-
for (i=0; i < maxlen; i++)
|
163
|
-
cary[i] = (float)NUM2DBL(rb_ary_entry((VALUE)ary,i));
|
164
|
-
return i;
|
165
|
-
}
|
166
|
-
|
167
|
-
/* -------------------------------------------------------------------- */
|
168
|
-
static inline int ary2cdbl(arg, cary, maxlen)
|
169
|
-
VALUE arg;
|
170
|
-
double cary[];
|
171
|
-
int maxlen;
|
172
|
-
{
|
173
|
-
int i;
|
174
|
-
struct RArray* ary;
|
175
|
-
ary = RARRAY(rb_Array(arg));
|
176
|
-
if (maxlen < 1)
|
177
|
-
maxlen = ary->len;
|
178
|
-
else
|
179
|
-
maxlen = maxlen < ary->len ? maxlen : ary->len;
|
180
|
-
for (i=0; i < maxlen; i++)
|
181
|
-
cary[i] = NUM2DBL(rb_ary_entry((VALUE)ary,i));
|
182
|
-
return i;
|
183
|
-
}
|
184
|
-
|
185
|
-
/* -------------------------------------------------------------------- */
|
186
|
-
/* Array.flatten */
|
187
|
-
static inline void mary2ary(src, ary)
|
188
|
-
VALUE src;
|
189
|
-
VALUE ary;
|
190
|
-
{
|
191
|
-
struct RArray* tmp_ary;
|
192
|
-
int i;
|
193
|
-
tmp_ary = RARRAY(rb_Array(src));
|
194
|
-
for (i = 0; i < tmp_ary->len; i++)
|
195
|
-
{
|
196
|
-
if (TYPE(tmp_ary->ptr[i]) == T_ARRAY)
|
197
|
-
mary2ary((VALUE)tmp_ary->ptr[i], ary);
|
198
|
-
else
|
199
|
-
rb_ary_push(ary, tmp_ary->ptr[i]);
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
/* -------------------------------------------------------------------- */
|
204
|
-
static inline void ary2cmat4x4dbl(ary, cary)
|
205
|
-
VALUE ary;
|
206
|
-
double cary[];
|
207
|
-
{
|
208
|
-
int i,j;
|
209
|
-
RArray *ary_r,*ary_c;
|
210
|
-
memset(cary, 0x0, sizeof(double[4*4]));
|
211
|
-
ary_c = RARRAY(rb_Array(ary));
|
212
|
-
if (TYPE(ary_c->ptr[0]) != T_ARRAY)
|
213
|
-
ary2cdbl((VALUE)ary_c, cary, 16);
|
214
|
-
else
|
215
|
-
{
|
216
|
-
for (i = 0; i < ary_c->len && i < 4; i++)
|
217
|
-
{
|
218
|
-
ary_r = RARRAY(rb_Array(ary_c->ptr[i]));
|
219
|
-
for(j = 0; j < ary_r->len && j < 4; j++)
|
220
|
-
cary[i*4+j] = (GLdouble)NUM2DBL(ary_r->ptr[j]);
|
221
|
-
}
|
222
|
-
}
|
223
|
-
}
|
224
|
-
|
225
|
-
static inline void ary2cmat4x4flt(ary, cary)
|
226
|
-
VALUE ary;
|
227
|
-
float cary[];
|
228
|
-
{
|
229
|
-
int i,j;
|
230
|
-
RArray *ary_r,*ary_c;
|
231
|
-
memset(cary, 0x0, sizeof(float[4*4]));
|
232
|
-
ary_c = RARRAY(rb_Array(ary));
|
233
|
-
if (TYPE(ary_c->ptr[0]) != T_ARRAY)
|
234
|
-
ary2cflt((VALUE)ary_c, cary, 16);
|
235
|
-
else
|
236
|
-
{
|
237
|
-
for (i = 0; i < ary_c->len && i < 4; i++)
|
238
|
-
{
|
239
|
-
ary_r = RARRAY(rb_Array(ary_c->ptr[i]));
|
240
|
-
for(j = 0; j < ary_r->len && j < 4; j++)
|
241
|
-
cary[i*4+j] = (GLfloat)NUM2DBL(ary_r->ptr[j]);
|
242
|
-
}
|
243
|
-
}
|
244
|
-
}
|
245
|
-
|
246
105
|
/* -------------------------------------------------------------------- */
|
247
106
|
|
248
107
|
/* gets number of components for given format */
|
@@ -374,6 +233,91 @@ static inline int gltype_glformat_unit_size(GLenum type,GLenum format)
|
|
374
233
|
}
|
375
234
|
}
|
376
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
|
+
|
377
321
|
static inline int GetDataSize(GLenum type,GLenum format,int num)
|
378
322
|
{
|
379
323
|
int size;
|
@@ -397,7 +341,7 @@ static inline void CheckDataSize(GLenum type,GLenum format,int num,VALUE data)
|
|
397
341
|
|
398
342
|
size = GetDataSize(type,format,num);
|
399
343
|
|
400
|
-
if (
|
344
|
+
if (RSTRING_LEN(data) < size)
|
401
345
|
rb_raise(rb_eArgError, "Length of specified data doesn't correspond to format and type parameters passed. Calculated length: %i",size);
|
402
346
|
}
|
403
347
|
|
@@ -448,68 +392,32 @@ static inline void *load_gl_function(const char *name,int raise)
|
|
448
392
|
return func_ptr;
|
449
393
|
}
|
450
394
|
|
451
|
-
|
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
|
+
}
|
452
417
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
user is really passing type that can be converted to INT, otherwire raises. */
|
458
|
-
|
459
|
-
#define ARGLIST0 obj
|
460
|
-
#define ARGLIST1 obj,arg1
|
461
|
-
#define ARGLIST2 obj,arg1,arg2
|
462
|
-
#define ARGLIST3 obj,arg1,arg2,arg3
|
463
|
-
#define ARGLIST4 obj,arg1,arg2,arg3,arg4
|
464
|
-
#define ARGLIST5 obj,arg1,arg2,arg3,arg4,arg5
|
465
|
-
#define ARGLIST6 obj,arg1,arg2,arg3,arg4,arg5,arg6
|
466
|
-
|
467
|
-
#define TYPELIST0(_ctype_) void
|
468
|
-
#define TYPELIST1(_ctype_) _ctype_
|
469
|
-
#define TYPELIST2(_ctype_) _ctype_,_ctype_
|
470
|
-
#define TYPELIST3(_ctype_) _ctype_,_ctype_,_ctype_
|
471
|
-
#define TYPELIST4(_ctype_) _ctype_,_ctype_,_ctype_,_ctype_
|
472
|
-
#define TYPELIST5(_ctype_) _ctype_,_ctype_,_ctype_,_ctype_,_ctype_
|
473
|
-
#define TYPELIST6(_ctype_) _ctype_,_ctype_,_ctype_,_ctype_,_ctype_,_ctype_
|
474
|
-
|
475
|
-
#define FUNCPARAMS0(_ctype_,_conversion_)
|
476
|
-
#define FUNCPARAMS1(_ctype_,_conversion_) (_ctype_)_conversion_(arg1)
|
477
|
-
#define FUNCPARAMS2(_ctype_,_conversion_) (_ctype_)_conversion_(arg1),(_ctype_)_conversion_(arg2)
|
478
|
-
#define FUNCPARAMS3(_ctype_,_conversion_) (_ctype_)_conversion_(arg1),(_ctype_)_conversion_(arg2),(_ctype_)_conversion_(arg3)
|
479
|
-
#define FUNCPARAMS4(_ctype_,_conversion_) (_ctype_)_conversion_(arg1),(_ctype_)_conversion_(arg2),(_ctype_)_conversion_(arg3),(_ctype_)_conversion_(arg4)
|
480
|
-
#define FUNCPARAMS5(_ctype_,_conversion_) (_ctype_)_conversion_(arg1),(_ctype_)_conversion_(arg2),(_ctype_)_conversion_(arg3),(_ctype_)_conversion_(arg4),(_ctype_)_conversion_(arg5)
|
481
|
-
#define FUNCPARAMS6(_ctype_,_conversion_) (_ctype_)_conversion_(arg1),(_ctype_)_conversion_(arg2),(_ctype_)_conversion_(arg3),(_ctype_)_conversion_(arg4),(_ctype_)_conversion_(arg5),(_ctype_)_conversion_(arg6)
|
482
|
-
|
483
|
-
#define GL_SIMPLE_FUNC(_name_,_numparams_,_ctype_,_conversion_) \
|
484
|
-
static VALUE \
|
485
|
-
gl_##_name_(ARGLIST##_numparams_) \
|
486
|
-
VALUE ARGLIST##_numparams_; \
|
487
|
-
{ \
|
488
|
-
gl##_name_(FUNCPARAMS##_numparams_(_ctype_,_conversion_)); \
|
489
|
-
return Qnil; \
|
490
|
-
}
|
491
|
-
|
492
|
-
#define GL_SIMPLE_FUNC_LOAD(_name_,_numparams_,_ctype_,_conversion_) \
|
493
|
-
static void (APIENTRY * fptr_gl##_name_)( TYPELIST##_numparams_(_ctype_) ); \
|
494
|
-
static VALUE \
|
495
|
-
gl_##_name_(ARGLIST##_numparams_) \
|
496
|
-
VALUE ARGLIST##_numparams_; \
|
497
|
-
{ \
|
498
|
-
LOAD_GL_FUNC(gl##_name_) \
|
499
|
-
fptr_gl##_name_(FUNCPARAMS##_numparams_(_ctype_,_conversion_)); \
|
500
|
-
return Qnil; \
|
501
|
-
}
|
502
|
-
|
503
|
-
|
504
|
-
#define GL_EXT_SIMPLE_FUNC_LOAD(_name_,_numparams_,_ctype_,_conversion_,_extensionname_) \
|
505
|
-
static void (APIENTRY * fptr_gl##_name_)( TYPELIST##_numparams_(_ctype_) ); \
|
506
|
-
static VALUE \
|
507
|
-
gl_##_name_(ARGLIST##_numparams_) \
|
508
|
-
VALUE ARGLIST##_numparams_; \
|
509
|
-
{ \
|
510
|
-
LOAD_GL_EXT_FUNC(gl##_name_,_extensionname_) \
|
511
|
-
fptr_gl##_name_(FUNCPARAMS##_numparams_(_ctype_,_conversion_)); \
|
512
|
-
return Qnil; \
|
513
|
-
}
|
418
|
+
return rb_funcall(ary,rb_intern("pack"),1,rb_str_new2(type_str));
|
419
|
+
}
|
420
|
+
|
421
|
+
/* -------------------------------------------------------------------- */
|
514
422
|
|
515
423
|
#endif /* _COMMON_H_ */
|
data/ext/common/conv.h
ADDED
@@ -0,0 +1,244 @@
|
|
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 = ary->len; \
|
135
|
+
else \
|
136
|
+
maxlen = maxlen < ary->len ? maxlen : ary->len; \
|
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(rary)->len != 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
|
+
}
|