-
Notifications
You must be signed in to change notification settings - Fork 1
/
gl_util.h
353 lines (292 loc) · 10.4 KB
/
gl_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#include "pgopogl.h"
#ifndef CALLBACK
#define CALLBACK
#endif
/* Include prototype flag */
#if (defined(_WIN32) || defined(HAVE_W32API))
#define GL_GLEXT_PROCS
#else
#define GL_GLEXT_PROTOTYPES
#endif
/* Provide GL header files for Windows and Apple */
#define INCLUDE_LOCAL_HEADER defined(HAVE_W32API)
#if INCLUDE_LOCAL_HEADER
#include "./include/GL/gl.h"
#else
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
/* Use version-detection if available */
#if defined(HAVE_VER)
#include "glext_types.h"
#include "gl_exclude.h"
#include "glext_procs.h"
#else
#endif
/* Get a Perl parameter, cast to C type */
#define SvItems(type,offset,count,dst) \
{ \
GLuint i; \
switch (type) \
{ \
case GL_UNSIGNED_BYTE: \
case GL_BITMAP: \
for (i=0;i<(count);i++) \
{ \
((GLubyte*)(dst))[i] = (GLubyte)SvIV(ST(i+(offset))); \
} \
break; \
case GL_BYTE: \
for (i=0;i<(count);i++) \
{ \
((GLbyte*)(dst))[i] = (GLbyte)SvIV(ST(i+(offset))); \
} \
break; \
case GL_UNSIGNED_SHORT: \
for (i=0;i<(count);i++) \
{ \
((GLushort*)(dst))[i] = (GLushort)SvIV(ST(i+(offset))); \
} \
break; \
case GL_SHORT: \
for (i=0;i<(count);i++) \
{ \
((GLshort*)(dst))[i] = (GLshort)SvIV(ST(i+(offset))); \
} \
break; \
case GL_UNSIGNED_INT: \
for (i=0;i<(count);i++) \
{ \
((GLuint*)(dst))[i] = (GLuint)SvIV(ST(i+(offset))); \
} \
break; \
case GL_INT: \
for (i=0;i<(count);i++) \
{ \
((GLint*)(dst))[i] = (GLint)SvIV(ST(i+(offset))); \
} \
break; \
case GL_FLOAT: \
for (i=0;i<(count);i++) \
{ \
((GLfloat*)(dst))[i] = (GLfloat)SvNV(ST(i+(offset))); \
} \
break; \
case GL_DOUBLE: \
for (i=0;i<(count);i++) \
{ \
((GLdouble*)(dst))[i] = (GLdouble)SvNV(ST(i+(offset))); \
} \
break; \
default: \
croak("unknown type"); \
} \
}
#ifndef GL_ADD
#define GL_ADD 0x0104
#endif
#ifndef GL_ADD_SIGNED_ARB
#define GL_ADD_SIGNED_ARB GL_ADD_SIGNED_EXT
#endif
#ifndef GL_SUBTRACT_ARB
#define GL_SUBTRACT_ARB GL_SUBTRACT_EXT
#endif
#ifndef GL_INTERPOLATE_ARB
#define GL_INTERPOLATE_ARB GL_INTERPOLATE_EXT
#endif
#ifndef GL_VERSION_1_0
#define GL_VERSION_1_0 1
#endif
#ifndef GL_TEXTURE_BINDING_3D
#define GL_TEXTURE_BINDING_3D 0x806A
#endif
/* Remap 1.1 extensions */
#ifdef GL_VERSION_1_1
#ifndef GL_VERSION_1_2
#ifndef GL_EXT_polygon_offset
#define GL_EXT_polygon_offset 1
#define GL_EXT_polygon_offset_is_faked 1
#define GL_POLYGON_OFFSET_EXT 0x8037
#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038
#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039
#define glPolygonOffsetEXT(factor,units) glPolygonOffset((factor),(units)*(float)0x10000)
#endif
#ifndef GL_EXT_texture_object
#define GL_EXT_texture_object 1
#define GL_EXT_texture_object_is_faked 1
#define GL_TEXTURE_PRIORITY_EXT GL_TEXTURE_PRIORITY
#define GL_TEXTURE_RESIDENT_EXT GL_TEXTURE_RESIDENT
#define GL_TEXTURE_1D_BINDING_EXT GL_TEXTURE_BINDING_1D
#define GL_TEXTURE_2D_BINDING_EXT GL_TEXTURE_BINDING_2D
#define GL_TEXTURE_3D_BINDING_EXT GL_TEXTURE_BINDING_3D
#define glAreTexturesResidentEXT(n,textures,residences) glAreTexturesResident(n,textures,residences)
#define glBindTextureEXT(target,texture) glBindTexture((target),(texture))
#define glDeleteTexturesEXT(n,textures) glDeleteTextures((n),(textures))
#define glGenTexturesEXT(n,textures) glGenTextures((n),(textures))
#define glIsTextureEXT(list) glIsTexture(list)
#define glPrioritizeTexturesEXT(n,textures,priorities) glPrioritizeTextures((n),(textures),(priorities))
#endif
#ifndef GL_EXT_copy_texture
#define GL_EXT_copy_texture 1
#define GL_EXT_copy_texture_is_faked 1
#define glCopyTexImage1DEXT(target,level,internalFormat,x,y,width,border) \
glCopyTexImage1D((target),(level),(internalFormat),(x),(y),(width),(border))
#define glCopyTexImage2DEXT(target,level,internalFormat,x,y,width,height,border) \
glCopyTexImage2D((target),(level),(internalFormat),(x),(y),(width),(height),(border))
#define glCopyTexSubImage1DEXT(target,level,xoffset,x,y,width) \
glCopyTexSubImage1D((target),(level),(xoffset),(x),(y),(width))
#define glCopyTexSubImage2DEXT(target,level,xoffset,yoffset,x,y,width,height) \
glCopyTexSubImage2D((target),(level),(xoffset),(yoffset),(x),(y),(width),(height))
#if defined(HAVE_VER) || defined(_WIN32)
#define glCopyTexSubImage3DEXT(target,level,xoffset,yoffset,zoffset,x,y,width,height) \
glCopyTexSubImage3D((target),(level),(xoffset),(yoffset),(zoffset),(x),(y),(width),(height))
#else
#define glCopyTexSubImage3DEXT(target,level,xoffset,yoffset,zoffset,x,y,width,height)
#endif
#endif
#ifndef GL_EXT_vertex_array
#define GL_EXT_vertex_array 1
#define GL_EXT_vertex_array_is_faked 1
#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D
#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080
#define GL_COLOR_ARRAY_COUNT_EXT 0x8084
#define GL_INDEX_ARRAY_COUNT_EXT 0x8087
#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B
#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D
#define GL_VERTEX_ARRAY_EXT GL_VERTEX_ARRAY
#define GL_NORMAL_ARRAY_EXT GL_NORMAL_ARRAY
#define GL_COLOR_ARRAY_EXT GL_COLOR_ARRAY
#define GL_INDEX_ARRAY_EXT GL_INDEX_ARRAY
#define GL_TEXCOORD_ARRAY_EXT GL_TEXCOORD_ARRAY
#define GL_EDGEFLAG_ARRAY_EXT GL_EDGEFLAG_ARRAY
#define GL_TEXTURE_COORD_ARRAY_EXT GL_TEXTURE_COORD_ARRAY
#define GL_EDGE_FLAG_ARRAY_EXT GL_EDGE_FLAG_ARRAY
#define GL_VERTEX_ARRAY_SIZE_EXT GL_VERTEX_ARRAY_SIZE
#define GL_VERTEX_ARRAY_TYPE_EXT GL_VERTEX_ARRAY_TYPE
#define GL_VERTEX_ARRAY_STRIDE_EXT GL_VERTEX_ARRAY_STRIDE
#define GL_NORMAL_ARRAY_TYPE_EXT GL_NORMAL_ARRAY_TYPE
#define GL_NORMAL_ARRAY_STRIDE_EXT GL_NORMAL_ARRAY_STRIDE
#define GL_COLOR_ARRAY_SIZE_EXT GL_COLOR_ARRAY_SIZE
#define GL_COLOR_ARRAY_TYPE_EXT GL_COLOR_ARRAY_TYPE
#define GL_COLOR_ARRAY_STRIDE_EXT GL_COLOR_ARRAY_STRIDE
#define GL_INDEX_ARRAY_TYPE_EXT GL_INDEX_ARRAY_TYPE
#define GL_INDEX_ARRAY_STRIDE_EXT GL_INDEX_ARRAY_STRIDE
#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT GL_TEXTURE_COORD_ARRAY_SIZE
#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT GL_TEXTURE_COORD_ARRAY_TYPE
#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT GL_TEXTURE_COORD_ARRAY_STRIDE
#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT GL_EDGE_FLAG_ARRAY_STRIDE
#define GL_VERTEX_ARRAY_POINTER_EXT GL_VERTEX_ARRAY_POINTER
#define GL_NORMAL_ARRAY_POINTER_EXT GL_NORMAL_ARRAY_POINTER
#define GL_COLOR_ARRAY_POINTER_EXT GL_COLOR_ARRAY_POINTER
#define GL_INDEX_ARRAY_POINTER_EXT GL_INDEX_ARRAY_POINTER
#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT GL_TEXTURE_COORD_ARRAY_POINTER
#define GL_EDGE_FLAG_ARRAY_POINTER_EXT GL_EDGE_FLAG_ARRAY_POINTER
#define glArrayElementEXT(i) glArrayElement(i)
#define glDrawArraysEXT(mode,first,count) glDrawArrays((mode),(first),(count))
#define glVertexPointerEXT(size,type,stride,count,pointer) \
glVertexPointer((size),(type),(stride),(pointer))
#define glNormalPointerEXT(type,stride,count,pointer) \
glNormalPointer((type),(stride),(pointer))
#define glColorPointerEXT(size,type,stride,count,pointer) \
glColorPointer((size),(type),(stride),(pointer))
#define glIndexPointerEXT(type,stride,count,pointer) \
glIndexPointer((type),(stride),(pointer))
#define glTexCoordPointerEXT(size,type,stride,count,pointer) \
glTexCoordPointer((size),(type),(stride),(pointer))
#define glEdgeFlagPointerEXT(stride,count,pointer) \
glEdgeFlagPointer((stride),(pointer))
#endif
#endif
#endif /* Remap 1.1 extensions */
#ifndef GL_EXT_Cg_shader
#define GL_EXT_Cg_shader 1
#define GL_CG_VERTEX_SHADER_EXT 0x890E
#define GL_CG_FRAGMENT_SHADER_EXT 0x890F
#endif
/* missing defs */
#ifndef GL_CMYK
#define GL_CMYK GL_CMYK_EXT
#endif
#ifndef GL_CMYKA
#define GL_CMYKA GL_CMYKA_EXT
#endif
#ifndef GL_PACK_CMYK_HINT
#define GL_PACK_CMYK_HINT GL_PACK_CMYK_HINT_EXT
#endif
#ifndef GL_UNPACK_CMYK_HINT
#define GL_UNPACK_CMYK_HINT GL_UNPACK_CMYK_HINT_EXT
#endif
#ifndef GL_BLEND_EQUATION_EXT
#define GL_BLEND_EQUATION_EXT 0x8009
#endif
#ifndef GL_BLEND_COLOR_EXT
#define GL_BLEND_COLOR_EXT 0x8005
#endif
// fake bgr constants so OpenGL::Image::Targa will work on GL1.1
#if !defined(GL_VERSION_1_2) && defined(GL_EXT_bgra)
#define GL_BGR GL_BGR_EXT
#define GL_BGRA GL_BGRA_EXT
#endif
#define MAX_GL_TEXPARAMETER_COUNT 4
extern int gl_texparameter_count(GLenum pname);
#define MAX_GL_TEXENV_COUNT 4
extern int gl_texenv_count(GLenum pname);
#define MAX_GL_TEXGEN_COUNT 4
extern int gl_texgen_count(GLenum pname);
#define MAX_GL_MATERIAL_COUNT 4
extern int gl_material_count(GLenum pname);
#define MAX_GL_MAP_COUNT 4
extern int gl_map_count(GLenum target, GLenum query);
#define MAX_GL_LIGHT_COUNT 4
extern int gl_light_count(GLenum pname);
#define MAX_GL_LIGHTMODEL_COUNT 4
extern int gl_lightmodel_count(GLenum pname);
#define MAX_GL_FOG_COUNT 4
extern int gl_fog_count(GLenum pname);
#define MAX_GL_GET_COUNT 16
extern int gl_get_count(GLenum param);
extern int gl_pixelmap_size(GLenum map);
extern int gl_state_count(GLenum state);
enum {
gl_pixelbuffer_pack = 1,
gl_pixelbuffer_unpack = 2,
};
extern unsigned long gl_pixelbuffer_size(
GLenum format,
GLsizei width,
GLsizei height,
GLenum type,
int mode);
extern GLvoid * pack_image_ST(SV ** stack, int count, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int mode);
extern GLvoid * allocate_image_ST(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int mode);
extern SV ** unpack_image_ST(SV ** SP, void * data,
GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int mode);
extern GLvoid * ELI(SV * sv, GLsizei width, GLsizei height, GLenum format, GLenum type, int mode);
extern GLvoid * EL(SV * sv, int needlen);
extern int gl_type_size(GLenum type);
extern int gl_component_count(GLenum format, GLenum type);
// Only support 2 for now
#define MAX_ARRAY_DIMENSIONS 2
struct oga_struct {
int type_count, item_count;
GLint bind;
GLenum * types;
GLint * type_offset;
int total_types_width;
void * data;
int data_length;
int dimension_count;
int dimensions[MAX_ARRAY_DIMENSIONS];
GLuint target, pixel_type, pixel_format, element_size;
GLuint affine_handle;
GLuint tex_handle[2];
GLuint fbo_handle;
int fbo_w, fbo_h;
int free_data;
};
typedef struct oga_struct oga_struct;
typedef oga_struct * OpenGL__Array;
typedef oga_struct * OpenGL__Matrix;