added memory macros
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.5 1999/10/08 09:27:10 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #include <stdlib.h>
29 #include "context.h"
30 #include "extensions.h"
31 #include "simple_list.h"
32 #include "types.h"
33
34
35 #define MAX_EXT_NAMELEN 80
36 #define MALLOC_STRUCT(T) (struct T *) malloc( sizeof(struct T) )
37
38 struct extension {
39 struct extension *next, *prev;
40 int enabled;
41 char name[MAX_EXT_NAMELEN+1];
42 void (*notify)( GLcontext *, GLboolean );
43 };
44
45
46
47 static struct { int enabled; const char *name; } default_extensions[] = {
48 { ALWAYS_ENABLED, "GL_EXT_blend_color" },
49 { DEFAULT_OFF, "ARB_imaging" },
50 { DEFAULT_ON, "GL_EXT_blend_minmax" },
51 { DEFAULT_ON, "GL_EXT_blend_logic_op" },
52 { DEFAULT_ON, "GL_EXT_blend_subtract" },
53 { DEFAULT_ON, "GL_EXT_paletted_texture" },
54 { DEFAULT_ON, "GL_EXT_point_parameters" },
55 { ALWAYS_ENABLED, "GL_EXT_polygon_offset" },
56 { ALWAYS_ENABLED, "GL_EXT_vertex_array" },
57 { ALWAYS_ENABLED, "GL_EXT_texture_object" },
58 { DEFAULT_ON, "GL_EXT_texture3D" },
59 { ALWAYS_ENABLED, "GL_MESA_window_pos" },
60 { ALWAYS_ENABLED, "GL_MESA_resize_buffers" },
61 { ALWAYS_ENABLED, "GL_EXT_shared_texture_palette" },
62 { ALWAYS_ENABLED, "GL_EXT_rescale_normal" },
63 { ALWAYS_ENABLED, "GL_EXT_abgr" },
64 { ALWAYS_ENABLED, "GL_SGIS_texture_edge_clamp" },
65 { ALWAYS_ENABLED, "GL_EXT_stencil_wrap" },
66 { DEFAULT_ON, "GL_INGR_blend_func_separate" },
67 { DEFAULT_ON, "GL_ARB_multitexture" },
68 { ALWAYS_ENABLED, "GL_NV_texgen_reflection" },
69 { DEFAULT_ON, "GL_PGI_misc_hints" },
70 { DEFAULT_ON, "GL_EXT_compiled_vertex_array" },
71 { DEFAULT_OFF, "GL_EXT_vertex_array_set" },
72 { DEFAULT_ON, "GL_EXT_clip_volume_hint" },
73 { ALWAYS_ENABLED, "GL_EXT_get_proc_address" }
74 };
75
76
77 int gl_extensions_add( GLcontext *ctx,
78 int state,
79 const char *name,
80 void (*notify)() )
81 {
82 (void) notify;
83
84 if (ctx->Extensions.ext_string == 0)
85 {
86 struct extension *t = MALLOC_STRUCT(extension);
87 t->enabled = state;
88 strncpy(t->name, name, MAX_EXT_NAMELEN);
89 t->name[MAX_EXT_NAMELEN] = 0;
90 t->notify = (void (*)(GLcontext *, GLboolean)) notify;
91 insert_at_tail( ctx->Extensions.ext_list, t );
92 return 0;
93 }
94 return 1;
95 }
96
97
98 static int set_extension( GLcontext *ctx, const char *name, GLuint state )
99 {
100 struct extension *i;
101 foreach( i, ctx->Extensions.ext_list )
102 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
103 break;
104
105 if (i == ctx->Extensions.ext_list) return 1;
106
107 if (i->enabled && !(i->enabled & ALWAYS_ENABLED))
108 {
109 if (i->notify) i->notify( ctx, state );
110 i->enabled = state;
111 }
112
113 return 0;
114 }
115
116
117 int gl_extensions_enable( GLcontext *ctx, const char *name )
118 {
119 if (ctx->Extensions.ext_string == 0)
120 return set_extension( ctx, name, 1 );
121 return 1;
122 }
123
124
125 int gl_extensions_disable( GLcontext *ctx, const char *name )
126 {
127 if (ctx->Extensions.ext_string == 0)
128 return set_extension( ctx, name, 0 );
129 return 1;
130 }
131
132
133 void gl_extensions_dtr( GLcontext *ctx )
134 {
135 struct extension *i, *nexti;
136
137 if (ctx->Extensions.ext_string) {
138 free( ctx->Extensions.ext_string );
139 ctx->Extensions.ext_string = 0;
140 }
141
142 if (ctx->Extensions.ext_list) {
143 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
144 remove_from_list( i );
145 free( i );
146 }
147
148 free(ctx->Extensions.ext_list);
149 ctx->Extensions.ext_list = 0;
150 }
151 }
152
153
154 void gl_extensions_ctr( GLcontext *ctx )
155 {
156 GLuint i;
157
158 ctx->Extensions.ext_string = 0;
159 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
160 make_empty_list( ctx->Extensions.ext_list );
161
162 for (i = 0 ; i < Elements(default_extensions) ; i++) {
163 gl_extensions_add( ctx,
164 default_extensions[i].enabled,
165 default_extensions[i].name,
166 0 );
167 }
168 }
169
170
171 const char *gl_extensions_get_string( GLcontext *ctx )
172 {
173 if (ctx->Extensions.ext_string == 0)
174 {
175 struct extension *i;
176 char *str;
177 GLuint len = 0;
178 foreach (i, ctx->Extensions.ext_list)
179 if (i->enabled)
180 len += strlen(i->name) + 1;
181
182 if (len == 0)
183 return "";
184
185 str = (char *)malloc(len * sizeof(char));
186 ctx->Extensions.ext_string = str;
187
188 foreach (i, ctx->Extensions.ext_list)
189 if (i->enabled) {
190 strcpy(str, i->name);
191 str += strlen(str);
192 *str++ = ' ';
193 }
194
195 *(str-1) = 0;
196 }
197
198 return ctx->Extensions.ext_string;
199 }
200
201
202
203 /*
204 * Return the address of an extension function.
205 * NOTE: this function could be optimized to binary search a sorted
206 * list of function names.
207 * Also, this function does not yet do per-context function searches.
208 * Not applicable to Mesa at this time.
209 */
210 void (* gl_GetProcAddress( GLcontext *ctx, const GLubyte *procName ))()
211 {
212 struct proc {
213 const char *name;
214 GLfunction address;
215 };
216 static struct proc procTable[] = {
217 #ifdef GL_EXT_get_proc_address
218 { "glGetProcAddressEXT", (GLfunction) glGetProcAddressEXT }, /* me! */
219 #endif
220 /* OpenGL 1.1 functions */
221 { "glEnableClientState", (GLfunction) glEnableClientState },
222 { "glDisableClientState", (GLfunction) glDisableClientState },
223 { "glPushClientAttrib", (GLfunction) glPushClientAttrib },
224 { "glPopClientAttrib", (GLfunction) glPopClientAttrib },
225 { "glIndexub", (GLfunction) glIndexub },
226 { "glIndexubv", (GLfunction) glIndexubv },
227 { "glVertexPointer", (GLfunction) glVertexPointer },
228 { "glNormalPointer", (GLfunction) glNormalPointer },
229 { "glColorPointer", (GLfunction) glColorPointer },
230 { "glIndexPointer", (GLfunction) glIndexPointer },
231 { "glTexCoordPointer", (GLfunction) glTexCoordPointer },
232 { "glEdgeFlagPointer", (GLfunction) glEdgeFlagPointer },
233 { "glGetPointerv", (GLfunction) glGetPointerv },
234 { "glArrayElement", (GLfunction) glArrayElement },
235 { "glDrawArrays", (GLfunction) glDrawArrays },
236 { "glDrawElements", (GLfunction) glDrawElements },
237 { "glInterleavedArrays", (GLfunction) glInterleavedArrays },
238 { "glGenTextures", (GLfunction) glGenTextures },
239 { "glDeleteTextures", (GLfunction) glDeleteTextures },
240 { "glBindTexture", (GLfunction) glBindTexture },
241 { "glPrioritizeTextures", (GLfunction) glPrioritizeTextures },
242 { "glAreTexturesResident", (GLfunction) glAreTexturesResident },
243 { "glIsTexture", (GLfunction) glIsTexture },
244 { "glTexSubImage1D", (GLfunction) glTexSubImage1D },
245 { "glTexSubImage2D", (GLfunction) glTexSubImage2D },
246 { "glCopyTexImage1D", (GLfunction) glCopyTexImage1D },
247 { "glCopyTexImage2D", (GLfunction) glCopyTexImage2D },
248 { "glCopyTexSubImage1D", (GLfunction) glCopyTexSubImage1D },
249 { "glCopyTexSubImage2D", (GLfunction) glCopyTexSubImage2D },
250
251 /* OpenGL 1.2 functions */
252 { "glDrawRangeElements", (GLfunction) glDrawRangeElements },
253 { "glTexImage3D", (GLfunction) glTexImage3D },
254 { "glTexSubImage3D", (GLfunction) glTexSubImage3D },
255 { "glCopyTexSubImage3D", (GLfunction) glCopyTexSubImage3D },
256 /* NOTE: 1.2 imaging subset functions not implemented in Mesa */
257
258 /* GL_EXT_blend_minmax */
259 { "glBlendEquationEXT", (GLfunction) glBlendEquationEXT },
260
261 /* GL_EXT_blend_color */
262 { "glBlendColorEXT", (GLfunction) glBlendColorEXT },
263
264 /* GL_EXT_polygon_offset */
265 { "glPolygonOffsetEXT", (GLfunction) glPolygonOffsetEXT },
266
267 /* GL_EXT_vertex_arrays */
268 { "glVertexPointerEXT", (GLfunction) glVertexPointerEXT },
269 { "glNormalPointerEXT", (GLfunction) glNormalPointerEXT },
270 { "glColorPointerEXT", (GLfunction) glColorPointerEXT },
271 { "glIndexPointerEXT", (GLfunction) glIndexPointerEXT },
272 { "glTexCoordPointerEXT", (GLfunction) glTexCoordPointerEXT },
273 { "glEdgeFlagPointerEXT", (GLfunction) glEdgeFlagPointerEXT },
274 { "glGetPointervEXT", (GLfunction) glGetPointervEXT },
275 { "glArrayElementEXT", (GLfunction) glArrayElementEXT },
276 { "glDrawArraysEXT", (GLfunction) glDrawArraysEXT },
277
278 /* GL_EXT_texture_object */
279 { "glGenTexturesEXT", (GLfunction) glGenTexturesEXT },
280 { "glDeleteTexturesEXT", (GLfunction) glDeleteTexturesEXT },
281 { "glBindTextureEXT", (GLfunction) glBindTextureEXT },
282 { "glPrioritizeTexturesEXT", (GLfunction) glPrioritizeTexturesEXT },
283 { "glAreTexturesResidentEXT", (GLfunction) glAreTexturesResidentEXT },
284 { "glIsTextureEXT", (GLfunction) glIsTextureEXT },
285
286 /* GL_EXT_texture3D */
287 { "glTexImage3DEXT", (GLfunction) glTexImage3DEXT },
288 { "glTexSubImage3DEXT", (GLfunction) glTexSubImage3DEXT },
289 { "glCopyTexSubImage3DEXT", (GLfunction) glCopyTexSubImage3DEXT },
290
291 /* GL_EXT_color_table */
292 { "glColorTableEXT", (GLfunction) glColorTableEXT },
293 { "glColorSubTableEXT", (GLfunction) glColorSubTableEXT },
294 { "glGetColorTableEXT", (GLfunction) glGetColorTableEXT },
295 { "glGetColorTableParameterfvEXT", (GLfunction) glGetColorTableParameterfvEXT },
296 { "glGetColorTableParameterivEXT", (GLfunction) glGetColorTableParameterivEXT },
297
298 /* GL_ARB_multitexture */
299 { "glActiveTextureARB", (GLfunction) glActiveTextureARB },
300 { "glClientActiveTextureARB", (GLfunction) glClientActiveTextureARB },
301 { "glMultiTexCoord1dARB", (GLfunction) glMultiTexCoord1dARB },
302 { "glMultiTexCoord1dvARB", (GLfunction) glMultiTexCoord1dvARB },
303 { "glMultiTexCoord1fARB", (GLfunction) glMultiTexCoord1fARB },
304 { "glMultiTexCoord1fvARB", (GLfunction) glMultiTexCoord1fvARB },
305 { "glMultiTexCoord1iARB", (GLfunction) glMultiTexCoord1iARB },
306 { "glMultiTexCoord1ivARB", (GLfunction) glMultiTexCoord1ivARB },
307 { "glMultiTexCoord1sARB", (GLfunction) glMultiTexCoord1sARB },
308 { "glMultiTexCoord1svARB", (GLfunction) glMultiTexCoord1svARB },
309 { "glMultiTexCoord2dARB", (GLfunction) glMultiTexCoord2dARB },
310 { "glMultiTexCoord2dvARB", (GLfunction) glMultiTexCoord2dvARB },
311 { "glMultiTexCoord2fARB", (GLfunction) glMultiTexCoord2fARB },
312 { "glMultiTexCoord2fvARB", (GLfunction) glMultiTexCoord2fvARB },
313 { "glMultiTexCoord2iARB", (GLfunction) glMultiTexCoord2iARB },
314 { "glMultiTexCoord2ivARB", (GLfunction) glMultiTexCoord2ivARB },
315 { "glMultiTexCoord2sARB", (GLfunction) glMultiTexCoord2sARB },
316 { "glMultiTexCoord2svARB", (GLfunction) glMultiTexCoord2svARB },
317 { "glMultiTexCoord3dARB", (GLfunction) glMultiTexCoord3dARB },
318 { "glMultiTexCoord3dvARB", (GLfunction) glMultiTexCoord3dvARB },
319 { "glMultiTexCoord3fARB", (GLfunction) glMultiTexCoord3fARB },
320 { "glMultiTexCoord3fvARB", (GLfunction) glMultiTexCoord3fvARB },
321 { "glMultiTexCoord3iARB", (GLfunction) glMultiTexCoord3iARB },
322 { "glMultiTexCoord3ivARB", (GLfunction) glMultiTexCoord3ivARB },
323 { "glMultiTexCoord3sARB", (GLfunction) glMultiTexCoord3sARB },
324 { "glMultiTexCoord3svARB", (GLfunction) glMultiTexCoord3svARB },
325 { "glMultiTexCoord4dARB", (GLfunction) glMultiTexCoord4dARB },
326 { "glMultiTexCoord4dvARB", (GLfunction) glMultiTexCoord4dvARB },
327 { "glMultiTexCoord4fARB", (GLfunction) glMultiTexCoord4fARB },
328 { "glMultiTexCoord4fvARB", (GLfunction) glMultiTexCoord4fvARB },
329 { "glMultiTexCoord4iARB", (GLfunction) glMultiTexCoord4iARB },
330 { "glMultiTexCoord4ivARB", (GLfunction) glMultiTexCoord4ivARB },
331 { "glMultiTexCoord4sARB", (GLfunction) glMultiTexCoord4sARB },
332 { "glMultiTexCoord4svARB", (GLfunction) glMultiTexCoord4svARB },
333
334 /* GL_EXT_point_parameters */
335 { "glPointParameterfEXT", (GLfunction) glPointParameterfEXT },
336 { "glPointParameterfvEXT", (GLfunction) glPointParameterfvEXT },
337
338 /* GL_INGR_blend_func_separate */
339 { "glBlendFuncSeparateINGR", (GLfunction) glBlendFuncSeparateINGR },
340
341 /* GL_MESA_window_pos */
342 { "glWindowPos2iMESA", (GLfunction) glWindowPos2iMESA },
343 { "glWindowPos2sMESA", (GLfunction) glWindowPos2sMESA },
344 { "glWindowPos2fMESA", (GLfunction) glWindowPos2fMESA },
345 { "glWindowPos2dMESA", (GLfunction) glWindowPos2dMESA },
346 { "glWindowPos2ivMESA", (GLfunction) glWindowPos2ivMESA },
347 { "glWindowPos2svMESA", (GLfunction) glWindowPos2svMESA },
348 { "glWindowPos2fvMESA", (GLfunction) glWindowPos2fvMESA },
349 { "glWindowPos2dvMESA", (GLfunction) glWindowPos2dvMESA },
350 { "glWindowPos3iMESA", (GLfunction) glWindowPos3iMESA },
351 { "glWindowPos3sMESA", (GLfunction) glWindowPos3sMESA },
352 { "glWindowPos3fMESA", (GLfunction) glWindowPos3fMESA },
353 { "glWindowPos3dMESA", (GLfunction) glWindowPos3dMESA },
354 { "glWindowPos3ivMESA", (GLfunction) glWindowPos3ivMESA },
355 { "glWindowPos3svMESA", (GLfunction) glWindowPos3svMESA },
356 { "glWindowPos3fvMESA", (GLfunction) glWindowPos3fvMESA },
357 { "glWindowPos3dvMESA", (GLfunction) glWindowPos3dvMESA },
358 { "glWindowPos4iMESA", (GLfunction) glWindowPos4iMESA },
359 { "glWindowPos4sMESA", (GLfunction) glWindowPos4sMESA },
360 { "glWindowPos4fMESA", (GLfunction) glWindowPos4fMESA },
361 { "glWindowPos4dMESA", (GLfunction) glWindowPos4dMESA },
362 { "glWindowPos4ivMESA", (GLfunction) glWindowPos4ivMESA },
363 { "glWindowPos4svMESA", (GLfunction) glWindowPos4svMESA },
364 { "glWindowPos4fvMESA", (GLfunction) glWindowPos4fvMESA },
365 { "glWindowPos4dvMESA", (GLfunction) glWindowPos4dvMESA },
366
367 /* GL_MESA_resize_buffers */
368 { "glResizeBuffersMESA", (GLfunction) glResizeBuffersMESA },
369
370 /* GL_EXT_compiled_vertex_array */
371 { "glLockArraysEXT", (GLfunction) glLockArraysEXT },
372 { "glUnlockArraysEXT", (GLfunction) glUnlockArraysEXT },
373
374 { NULL, NULL } /* end of list token */
375 };
376 GLuint i;
377
378 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glGetProcAddressEXT", NULL);
379
380 for (i = 0; procTable[i].address; i++) {
381 if (strcmp((const char *) procName, procTable[i].name) == 0)
382 return procTable[i].address;
383 }
384
385 return NULL;
386 }