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