Comment out __FUNCTION__ usage.
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.58 2001/04/24 21:52:36 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "extensions.h"
34 #include "mem.h"
35 #include "simple_list.h"
36 #include "mtypes.h"
37 #endif
38
39
40 #define MAX_EXT_NAMELEN 80
41
42 struct extension {
43 struct extension *next, *prev;
44 GLint enabled;
45 GLboolean *flag; /* optional flag stored elsewhere */
46 char name[MAX_EXT_NAMELEN+1];
47 void (*notify)( GLcontext *, GLboolean );
48 };
49
50 #define F(x) (int)&(((struct gl_extensions *)0)->x)
51 #define ON GL_TRUE
52 #define OFF GL_FALSE
53
54 static struct {
55 GLboolean enabled;
56 const char *name;
57 int flag_offset;
58 } default_extensions[] = {
59 { OFF, "GL_ARB_imaging", F(ARB_imaging) },
60 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
61 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
62 { OFF, "GL_ARB_texture_compression", F(ARB_texture_compression) },
63 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
64 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
65 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
66 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
67 { ON, "GL_ARB_transpose_matrix", 0 },
68 { ON, "GL_EXT_abgr", 0 },
69 { ON, "GL_EXT_bgra", 0 },
70 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
71 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
72 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
73 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
74 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
75 { ON, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
76 { OFF, "GL_EXT_cull_vertex", 0 },
77 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
78 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
79 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
80 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
81 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
82 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
83 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
84 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
85 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
86 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
87 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
88 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
89 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
90 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
91 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
92 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
93 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
94 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
95 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
96 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
97 { ON, "GL_EXT_vertex_array", 0 },
98 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
99 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
100 { OFF, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
101 { OFF, "GL_MESA_packed_depth_stencil", 0 },
102 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
103 { OFF, "GL_MESA_sprite_point", F(MESA_sprite_point) },
104 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
105 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
106 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
107 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
108 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
109 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
110 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
111 { OFF, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
112 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
113 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
114 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
115 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
116 { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) }
117 };
118
119
120
121
122 /*
123 * Enable all extensions suitable for a software-only renderer.
124 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
125 */
126 void
127 _mesa_enable_sw_extensions(GLcontext *ctx)
128 {
129 const char *extensions[] = {
130 "GL_ARB_imaging",
131 "GL_ARB_multitexture",
132 "GL_ARB_texture_border_clamp",
133 "GL_ARB_texture_cube_map",
134 "GL_ARB_texture_env_add",
135 "GL_ARB_texture_env_combine",
136 "GL_ARB_texture_env_dot3",
137 "GL_EXT_blend_color",
138 "GL_EXT_blend_func_separate",
139 "GL_EXT_blend_logic_op",
140 "GL_EXT_blend_minmax",
141 "GL_EXT_blend_subtract",
142 "GL_EXT_convolution",
143 "GL_EXT_fog_coord",
144 "GL_EXT_histogram",
145 "GL_EXT_paletted_texture",
146 "GL_EXT_point_parameters",
147 "GL_EXT_secondary_color",
148 "GL_EXT_shared_texture_palette",
149 "GL_EXT_stencil_wrap",
150 "GL_EXT_texture_env_add",
151 "GL_EXT_texture_env_combine",
152 "GL_EXT_texture_env_dot3",
153 "GL_EXT_texture_lod_bias",
154 "GL_HP_occlusion_test",
155 "GL_INGR_blend_func_separate",
156 "GL_MESA_resize_buffers",
157 "GL_NV_blend_square",
158 "GL_NV_texgen_reflection",
159 "GL_SGI_color_matrix",
160 "GL_SGI_color_table",
161 "GL_SGIS_pixel_texture",
162 "GL_SGIS_texture_edge_clamp",
163 "GL_SGIS_texture_border_clamp",
164 "GL_SGIX_depth_texture",
165 "GL_SGIX_pixel_texture",
166 "GL_SGIX_shadow",
167 "GL_SGIX_shadow_ambient",
168 NULL
169 };
170 GLuint i;
171
172 for (i = 0; extensions[i]; i++) {
173 _mesa_enable_extension(ctx, extensions[i]);
174 }
175 }
176
177
178 /*
179 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
180 */
181 void
182 _mesa_enable_imaging_extensions(GLcontext *ctx)
183 {
184 const char *extensions[] = {
185 "GL_ARB_imaging",
186 "GL_EXT_blend_color",
187 "GL_EXT_blend_minmax",
188 "GL_EXT_blend_subtract",
189 "GL_EXT_convolution",
190 "GL_EXT_histogram",
191 "GL_SGI_color_matrix",
192 "GL_SGI_color_table",
193 NULL
194 };
195 GLuint i;
196
197 for (i = 0; extensions[i]; i++) {
198 _mesa_enable_extension(ctx, extensions[i]);
199 }
200 }
201
202
203 /*
204 * Add a new extenstion. This would be called from a Mesa driver.
205 */
206 void
207 _mesa_add_extension( GLcontext *ctx,
208 GLboolean enabled,
209 const char *name,
210 GLboolean *flag_ptr )
211 {
212 /* We should never try to add an extension after
213 * _mesa_extensions_get_string() has been called!
214 */
215 assert(ctx->Extensions.ext_string == 0);
216
217 {
218 struct extension *t = MALLOC_STRUCT(extension);
219 t->enabled = enabled;
220 strncpy(t->name, name, MAX_EXT_NAMELEN);
221 t->name[MAX_EXT_NAMELEN] = 0;
222 t->flag = flag_ptr;
223 if (t->flag)
224 *t->flag = enabled;
225 insert_at_tail( ctx->Extensions.ext_list, t );
226 }
227 }
228
229
230 /*
231 * Either enable or disable the named extension.
232 */
233 static void
234 set_extension( GLcontext *ctx, const char *name, GLint state )
235 {
236 /* XXX we should assert that ext_string is null. We should never be
237 * enabling/disabling extensions after _mesa_extensions_get_string()
238 * has been called!
239 */
240 struct extension *i;
241 foreach( i, ctx->Extensions.ext_list )
242 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
243 break;
244
245 if (i == ctx->Extensions.ext_list) {
246 /* this is an error. Drivers should never try to enable/disable
247 * an extension which is unknown to Mesa or wasn't added by calling
248 * _mesa_add_extension().
249 */
250 return;
251 }
252
253 if (i->flag)
254 *(i->flag) = state;
255 i->enabled = state;
256 }
257
258
259
260 void
261 _mesa_enable_extension( GLcontext *ctx, const char *name )
262 {
263 if (ctx->Extensions.ext_string == 0)
264 set_extension( ctx, name, 1 );
265 }
266
267
268 void
269 _mesa_disable_extension( GLcontext *ctx, const char *name )
270 {
271 if (ctx->Extensions.ext_string == 0)
272 set_extension( ctx, name, 0 );
273 }
274
275
276 /*
277 * Test if the named extension is enabled in this context.
278 */
279 GLboolean
280 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
281 {
282 struct extension *i;
283 foreach( i, ctx->Extensions.ext_list )
284 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
285 if (i->enabled)
286 return GL_TRUE;
287 else
288 return GL_FALSE;
289 }
290
291 return GL_FALSE;
292 }
293
294
295 void
296 _mesa_extensions_dtr( GLcontext *ctx )
297 {
298 struct extension *i, *nexti;
299
300 if (ctx->Extensions.ext_string) {
301 FREE( ctx->Extensions.ext_string );
302 ctx->Extensions.ext_string = 0;
303 }
304
305 if (ctx->Extensions.ext_list) {
306 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
307 remove_from_list( i );
308 FREE( i );
309 }
310
311 FREE(ctx->Extensions.ext_list);
312 ctx->Extensions.ext_list = 0;
313 }
314 }
315
316
317 void
318 _mesa_extensions_ctr( GLcontext *ctx )
319 {
320 GLuint i;
321 GLboolean *base = (GLboolean *)&ctx->Extensions;
322
323 ctx->Extensions.ext_string = NULL;
324 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
325 make_empty_list( ctx->Extensions.ext_list );
326
327 for (i = 0 ; i < Elements(default_extensions) ; i++) {
328 GLboolean *ptr = NULL;
329
330 if (default_extensions[i].flag_offset)
331 ptr = base + default_extensions[i].flag_offset;
332
333 (void) _mesa_add_extension( ctx,
334 default_extensions[i].enabled,
335 default_extensions[i].name,
336 ptr);
337 }
338 }
339
340
341 const char *
342 _mesa_extensions_get_string( GLcontext *ctx )
343 {
344 if (ctx->Extensions.ext_string == 0)
345 {
346 struct extension *i;
347 char *str;
348 GLuint len = 0;
349 foreach (i, ctx->Extensions.ext_list)
350 if (i->enabled)
351 len += strlen(i->name) + 1;
352
353 if (len == 0)
354 return "";
355
356 str = (char *)MALLOC(len * sizeof(char));
357 ctx->Extensions.ext_string = str;
358
359 foreach (i, ctx->Extensions.ext_list)
360 if (i->enabled) {
361 strcpy(str, i->name);
362 str += strlen(str);
363 *str++ = ' ';
364 }
365
366 *(str-1) = 0;
367 }
368
369 return ctx->Extensions.ext_string;
370 }