1 /* $Id: extensions.c,v 1.14 1999/11/12 23:38:42 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "extensions.h"
35 #include "simple_list.h"
40 #define MAX_EXT_NAMELEN 80
43 struct extension
*next
, *prev
;
45 char name
[MAX_EXT_NAMELEN
+1];
46 void (*notify
)( GLcontext
*, GLboolean
);
51 static struct { int enabled
; const char *name
; } default_extensions
[] = {
52 { ALWAYS_ENABLED
, "GL_EXT_blend_color" },
53 { DEFAULT_OFF
, "ARB_imaging" },
54 { DEFAULT_ON
, "GL_EXT_blend_minmax" },
55 { DEFAULT_ON
, "GL_EXT_blend_logic_op" },
56 { DEFAULT_ON
, "GL_EXT_blend_subtract" },
57 { DEFAULT_ON
, "GL_EXT_paletted_texture" },
58 { DEFAULT_ON
, "GL_EXT_point_parameters" },
59 { ALWAYS_ENABLED
, "GL_EXT_polygon_offset" },
60 { ALWAYS_ENABLED
, "GL_EXT_vertex_array" },
61 { ALWAYS_ENABLED
, "GL_EXT_texture_object" },
62 { DEFAULT_ON
, "GL_EXT_texture3D" },
63 { ALWAYS_ENABLED
, "GL_MESA_window_pos" },
64 { ALWAYS_ENABLED
, "GL_MESA_resize_buffers" },
65 { ALWAYS_ENABLED
, "GL_EXT_shared_texture_palette" },
66 { ALWAYS_ENABLED
, "GL_EXT_rescale_normal" },
67 { ALWAYS_ENABLED
, "GL_EXT_abgr" },
68 { ALWAYS_ENABLED
, "GL_SGIS_texture_edge_clamp" },
69 { ALWAYS_ENABLED
, "GL_EXT_stencil_wrap" },
70 { DEFAULT_ON
, "GL_INGR_blend_func_separate" },
71 { DEFAULT_ON
, "GL_ARB_multitexture" },
72 { ALWAYS_ENABLED
, "GL_NV_texgen_reflection" },
73 { DEFAULT_ON
, "GL_PGI_misc_hints" },
74 { DEFAULT_ON
, "GL_EXT_compiled_vertex_array" },
75 { DEFAULT_OFF
, "GL_EXT_vertex_array_set" },
76 { DEFAULT_ON
, "GL_EXT_clip_volume_hint" },
77 { DEFAULT_ON
, "GL_EXT_texture_env_add" },
81 int gl_extensions_add( GLcontext
*ctx
,
84 void (*notify
)(void) )
88 if (ctx
->Extensions
.ext_string
== 0)
90 struct extension
*t
= MALLOC_STRUCT(extension
);
92 strncpy(t
->name
, name
, MAX_EXT_NAMELEN
);
93 t
->name
[MAX_EXT_NAMELEN
] = 0;
94 t
->notify
= (void (*)(GLcontext
*, GLboolean
)) notify
;
95 insert_at_tail( ctx
->Extensions
.ext_list
, t
);
102 static int set_extension( GLcontext
*ctx
, const char *name
, GLuint state
)
105 foreach( i
, ctx
->Extensions
.ext_list
)
106 if (strncmp(i
->name
, name
, MAX_EXT_NAMELEN
) == 0)
109 if (i
== ctx
->Extensions
.ext_list
) return 1;
111 if (i
->enabled
&& !(i
->enabled
& ALWAYS_ENABLED
))
113 if (i
->notify
) i
->notify( ctx
, state
);
121 int gl_extensions_enable( GLcontext
*ctx
, const char *name
)
123 if (ctx
->Extensions
.ext_string
== 0)
124 return set_extension( ctx
, name
, 1 );
129 int gl_extensions_disable( GLcontext
*ctx
, const char *name
)
131 if (ctx
->Extensions
.ext_string
== 0)
132 return set_extension( ctx
, name
, 0 );
138 * Test if the named extension is enabled in this context.
140 GLboolean
gl_extension_is_enabled( GLcontext
*ctx
, const char *name
)
143 foreach( i
, ctx
->Extensions
.ext_list
)
144 if (strncmp(i
->name
, name
, MAX_EXT_NAMELEN
) == 0) {
155 void gl_extensions_dtr( GLcontext
*ctx
)
157 struct extension
*i
, *nexti
;
159 if (ctx
->Extensions
.ext_string
) {
160 FREE( ctx
->Extensions
.ext_string
);
161 ctx
->Extensions
.ext_string
= 0;
164 if (ctx
->Extensions
.ext_list
) {
165 foreach_s( i
, nexti
, ctx
->Extensions
.ext_list
) {
166 remove_from_list( i
);
170 FREE(ctx
->Extensions
.ext_list
);
171 ctx
->Extensions
.ext_list
= 0;
176 void gl_extensions_ctr( GLcontext
*ctx
)
180 ctx
->Extensions
.ext_string
= 0;
181 ctx
->Extensions
.ext_list
= MALLOC_STRUCT(extension
);
182 make_empty_list( ctx
->Extensions
.ext_list
);
184 for (i
= 0 ; i
< Elements(default_extensions
) ; i
++) {
185 gl_extensions_add( ctx
,
186 default_extensions
[i
].enabled
,
187 default_extensions
[i
].name
,
193 const char *gl_extensions_get_string( GLcontext
*ctx
)
195 if (ctx
->Extensions
.ext_string
== 0)
200 foreach (i
, ctx
->Extensions
.ext_list
)
202 len
+= strlen(i
->name
) + 1;
207 str
= (char *)MALLOC(len
* sizeof(char));
208 ctx
->Extensions
.ext_string
= str
;
210 foreach (i
, ctx
->Extensions
.ext_list
)
212 strcpy(str
, i
->name
);
220 return ctx
->Extensions
.ext_string
;
226 * Return the address of an extension function.
227 * This is meant to be called by glXGetProcAddress(), wglGetProcAddress(),
228 * or similar function.
229 * NOTE: this function could be optimized to binary search a sorted
230 * list of function names.
232 void (*gl_get_proc_address( const GLubyte
*procName
))()
234 typedef void (*gl_function
)();
239 static struct proc procTable
[] = {
240 /* OpenGL 1.1 functions */
241 { "glEnableClientState", (gl_function
) glEnableClientState
},
242 { "glDisableClientState", (gl_function
) glDisableClientState
},
243 { "glPushClientAttrib", (gl_function
) glPushClientAttrib
},
244 { "glPopClientAttrib", (gl_function
) glPopClientAttrib
},
245 { "glIndexub", (gl_function
) glIndexub
},
246 { "glIndexubv", (gl_function
) glIndexubv
},
247 { "glVertexPointer", (gl_function
) glVertexPointer
},
248 { "glNormalPointer", (gl_function
) glNormalPointer
},
249 { "glColorPointer", (gl_function
) glColorPointer
},
250 { "glIndexPointer", (gl_function
) glIndexPointer
},
251 { "glTexCoordPointer", (gl_function
) glTexCoordPointer
},
252 { "glEdgeFlagPointer", (gl_function
) glEdgeFlagPointer
},
253 { "glGetPointerv", (gl_function
) glGetPointerv
},
254 { "glArrayElement", (gl_function
) glArrayElement
},
255 { "glDrawArrays", (gl_function
) glDrawArrays
},
256 { "glDrawElements", (gl_function
) glDrawElements
},
257 { "glInterleavedArrays", (gl_function
) glInterleavedArrays
},
258 { "glGenTextures", (gl_function
) glGenTextures
},
259 { "glDeleteTextures", (gl_function
) glDeleteTextures
},
260 { "glBindTexture", (gl_function
) glBindTexture
},
261 { "glPrioritizeTextures", (gl_function
) glPrioritizeTextures
},
262 { "glAreTexturesResident", (gl_function
) glAreTexturesResident
},
263 { "glIsTexture", (gl_function
) glIsTexture
},
264 { "glTexSubImage1D", (gl_function
) glTexSubImage1D
},
265 { "glTexSubImage2D", (gl_function
) glTexSubImage2D
},
266 { "glCopyTexImage1D", (gl_function
) glCopyTexImage1D
},
267 { "glCopyTexImage2D", (gl_function
) glCopyTexImage2D
},
268 { "glCopyTexSubImage1D", (gl_function
) glCopyTexSubImage1D
},
269 { "glCopyTexSubImage2D", (gl_function
) glCopyTexSubImage2D
},
271 /* OpenGL 1.2 functions */
272 { "glDrawRangeElements", (gl_function
) glDrawRangeElements
},
273 { "glTexImage3D", (gl_function
) glTexImage3D
},
274 { "glTexSubImage3D", (gl_function
) glTexSubImage3D
},
275 { "glCopyTexSubImage3D", (gl_function
) glCopyTexSubImage3D
},
276 /* NOTE: 1.2 imaging subset functions not implemented in Mesa */
278 /* GL_EXT_blend_minmax */
279 { "glBlendEquationEXT", (gl_function
) glBlendEquationEXT
},
281 /* GL_EXT_blend_color */
282 { "glBlendColorEXT", (gl_function
) glBlendColorEXT
},
284 /* GL_EXT_polygon_offset */
285 { "glPolygonOffsetEXT", (gl_function
) glPolygonOffsetEXT
},
287 /* GL_EXT_vertex_arrays */
288 { "glVertexPointerEXT", (gl_function
) glVertexPointerEXT
},
289 { "glNormalPointerEXT", (gl_function
) glNormalPointerEXT
},
290 { "glColorPointerEXT", (gl_function
) glColorPointerEXT
},
291 { "glIndexPointerEXT", (gl_function
) glIndexPointerEXT
},
292 { "glTexCoordPointerEXT", (gl_function
) glTexCoordPointerEXT
},
293 { "glEdgeFlagPointerEXT", (gl_function
) glEdgeFlagPointerEXT
},
294 { "glGetPointervEXT", (gl_function
) glGetPointervEXT
},
295 { "glArrayElementEXT", (gl_function
) glArrayElementEXT
},
296 { "glDrawArraysEXT", (gl_function
) glDrawArraysEXT
},
298 /* GL_EXT_texture_object */
299 { "glGenTexturesEXT", (gl_function
) glGenTexturesEXT
},
300 { "glDeleteTexturesEXT", (gl_function
) glDeleteTexturesEXT
},
301 { "glBindTextureEXT", (gl_function
) glBindTextureEXT
},
302 { "glPrioritizeTexturesEXT", (gl_function
) glPrioritizeTexturesEXT
},
303 { "glAreTexturesResidentEXT", (gl_function
) glAreTexturesResidentEXT
},
304 { "glIsTextureEXT", (gl_function
) glIsTextureEXT
},
306 /* GL_EXT_texture3D */
307 { "glTexImage3DEXT", (gl_function
) glTexImage3DEXT
},
308 { "glTexSubImage3DEXT", (gl_function
) glTexSubImage3DEXT
},
309 { "glCopyTexSubImage3DEXT", (gl_function
) glCopyTexSubImage3DEXT
},
311 /* GL_EXT_paletted_texture */
312 { "glColorTableEXT", (gl_function
) glColorTableEXT
},
313 { "glColorSubTableEXT", (gl_function
) glColorSubTableEXT
},
314 { "glGetColorTableEXT", (gl_function
) glGetColorTableEXT
},
315 { "glGetColorTableParameterfvEXT", (gl_function
) glGetColorTableParameterfvEXT
},
316 { "glGetColorTableParameterivEXT", (gl_function
) glGetColorTableParameterivEXT
},
318 /* GL_ARB_multitexture */
319 { "glActiveTextureARB", (gl_function
) glActiveTextureARB
},
320 { "glClientActiveTextureARB", (gl_function
) glClientActiveTextureARB
},
321 { "glMultiTexCoord1dARB", (gl_function
) glMultiTexCoord1dARB
},
322 { "glMultiTexCoord1dvARB", (gl_function
) glMultiTexCoord1dvARB
},
323 { "glMultiTexCoord1fARB", (gl_function
) glMultiTexCoord1fARB
},
324 { "glMultiTexCoord1fvARB", (gl_function
) glMultiTexCoord1fvARB
},
325 { "glMultiTexCoord1iARB", (gl_function
) glMultiTexCoord1iARB
},
326 { "glMultiTexCoord1ivARB", (gl_function
) glMultiTexCoord1ivARB
},
327 { "glMultiTexCoord1sARB", (gl_function
) glMultiTexCoord1sARB
},
328 { "glMultiTexCoord1svARB", (gl_function
) glMultiTexCoord1svARB
},
329 { "glMultiTexCoord2dARB", (gl_function
) glMultiTexCoord2dARB
},
330 { "glMultiTexCoord2dvARB", (gl_function
) glMultiTexCoord2dvARB
},
331 { "glMultiTexCoord2fARB", (gl_function
) glMultiTexCoord2fARB
},
332 { "glMultiTexCoord2fvARB", (gl_function
) glMultiTexCoord2fvARB
},
333 { "glMultiTexCoord2iARB", (gl_function
) glMultiTexCoord2iARB
},
334 { "glMultiTexCoord2ivARB", (gl_function
) glMultiTexCoord2ivARB
},
335 { "glMultiTexCoord2sARB", (gl_function
) glMultiTexCoord2sARB
},
336 { "glMultiTexCoord2svARB", (gl_function
) glMultiTexCoord2svARB
},
337 { "glMultiTexCoord3dARB", (gl_function
) glMultiTexCoord3dARB
},
338 { "glMultiTexCoord3dvARB", (gl_function
) glMultiTexCoord3dvARB
},
339 { "glMultiTexCoord3fARB", (gl_function
) glMultiTexCoord3fARB
},
340 { "glMultiTexCoord3fvARB", (gl_function
) glMultiTexCoord3fvARB
},
341 { "glMultiTexCoord3iARB", (gl_function
) glMultiTexCoord3iARB
},
342 { "glMultiTexCoord3ivARB", (gl_function
) glMultiTexCoord3ivARB
},
343 { "glMultiTexCoord3sARB", (gl_function
) glMultiTexCoord3sARB
},
344 { "glMultiTexCoord3svARB", (gl_function
) glMultiTexCoord3svARB
},
345 { "glMultiTexCoord4dARB", (gl_function
) glMultiTexCoord4dARB
},
346 { "glMultiTexCoord4dvARB", (gl_function
) glMultiTexCoord4dvARB
},
347 { "glMultiTexCoord4fARB", (gl_function
) glMultiTexCoord4fARB
},
348 { "glMultiTexCoord4fvARB", (gl_function
) glMultiTexCoord4fvARB
},
349 { "glMultiTexCoord4iARB", (gl_function
) glMultiTexCoord4iARB
},
350 { "glMultiTexCoord4ivARB", (gl_function
) glMultiTexCoord4ivARB
},
351 { "glMultiTexCoord4sARB", (gl_function
) glMultiTexCoord4sARB
},
352 { "glMultiTexCoord4svARB", (gl_function
) glMultiTexCoord4svARB
},
354 /* GL_EXT_point_parameters */
355 { "glPointParameterfEXT", (gl_function
) glPointParameterfEXT
},
356 { "glPointParameterfvEXT", (gl_function
) glPointParameterfvEXT
},
358 /* GL_INGR_blend_func_separate */
359 { "glBlendFuncSeparateINGR", (gl_function
) glBlendFuncSeparateINGR
},
361 /* GL_MESA_window_pos */
362 { "glWindowPos2iMESA", (gl_function
) glWindowPos2iMESA
},
363 { "glWindowPos2sMESA", (gl_function
) glWindowPos2sMESA
},
364 { "glWindowPos2fMESA", (gl_function
) glWindowPos2fMESA
},
365 { "glWindowPos2dMESA", (gl_function
) glWindowPos2dMESA
},
366 { "glWindowPos2ivMESA", (gl_function
) glWindowPos2ivMESA
},
367 { "glWindowPos2svMESA", (gl_function
) glWindowPos2svMESA
},
368 { "glWindowPos2fvMESA", (gl_function
) glWindowPos2fvMESA
},
369 { "glWindowPos2dvMESA", (gl_function
) glWindowPos2dvMESA
},
370 { "glWindowPos3iMESA", (gl_function
) glWindowPos3iMESA
},
371 { "glWindowPos3sMESA", (gl_function
) glWindowPos3sMESA
},
372 { "glWindowPos3fMESA", (gl_function
) glWindowPos3fMESA
},
373 { "glWindowPos3dMESA", (gl_function
) glWindowPos3dMESA
},
374 { "glWindowPos3ivMESA", (gl_function
) glWindowPos3ivMESA
},
375 { "glWindowPos3svMESA", (gl_function
) glWindowPos3svMESA
},
376 { "glWindowPos3fvMESA", (gl_function
) glWindowPos3fvMESA
},
377 { "glWindowPos3dvMESA", (gl_function
) glWindowPos3dvMESA
},
378 { "glWindowPos4iMESA", (gl_function
) glWindowPos4iMESA
},
379 { "glWindowPos4sMESA", (gl_function
) glWindowPos4sMESA
},
380 { "glWindowPos4fMESA", (gl_function
) glWindowPos4fMESA
},
381 { "glWindowPos4dMESA", (gl_function
) glWindowPos4dMESA
},
382 { "glWindowPos4ivMESA", (gl_function
) glWindowPos4ivMESA
},
383 { "glWindowPos4svMESA", (gl_function
) glWindowPos4svMESA
},
384 { "glWindowPos4fvMESA", (gl_function
) glWindowPos4fvMESA
},
385 { "glWindowPos4dvMESA", (gl_function
) glWindowPos4dvMESA
},
387 /* GL_MESA_resize_buffers */
388 { "glResizeBuffersMESA", (gl_function
) glResizeBuffersMESA
},
390 /* GL_EXT_compiled_vertex_array */
391 { "glLockArraysEXT", (gl_function
) glLockArraysEXT
},
392 { "glUnlockArraysEXT", (gl_function
) glUnlockArraysEXT
},
394 { NULL
, NULL
} /* end of list token */
398 for (i
= 0; procTable
[i
].address
; i
++) {
399 if (strcmp((const char *) procName
, procTable
[i
].name
) == 0)
400 return procTable
[i
].address
;