88616b63093dab174e07f0e7347c98cb09bbe5f1
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.89 2003/03/29 17:01:01 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 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 #include "glheader.h"
28 #include "imports.h"
29 #include "context.h"
30 #include "extensions.h"
31 #include "simple_list.h"
32 #include "mtypes.h"
33
34
35 #define MAX_EXT_NAMELEN 80
36
37 struct extension {
38 struct extension *next, *prev;
39 GLint enabled;
40 GLboolean *flag; /* optional flag stored elsewhere */
41 char name[MAX_EXT_NAMELEN+1];
42 void (*notify)( GLcontext *, GLboolean );
43 };
44
45 #define F(x) (int)&(((struct gl_extensions *)0)->x)
46 #define ON GL_TRUE
47 #define OFF GL_FALSE
48
49 static struct {
50 GLboolean enabled;
51 const char *name;
52 int flag_offset;
53 } default_extensions[] = {
54 { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) },
55 { OFF, "GL_ARB_imaging", F(ARB_imaging) },
56 { OFF, "GL_ARB_multisample", F(ARB_multisample) },
57 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
58 { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) },
59 { OFF, "GL_ARB_shadow", F(ARB_shadow) },
60 { OFF, "GL_ARB_shadow_ambient", F(SGIX_shadow_ambient) },
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_crossbar", F(ARB_texture_env_crossbar) },
67 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
68 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
69 { ON, "GL_ARB_transpose_matrix", 0 },
70 { OFF, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) },
71 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
72 { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)},
73 { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)},
74 { ON, "GL_EXT_abgr", 0 },
75 { ON, "GL_EXT_bgra", 0 },
76 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
77 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
78 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
79 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
80 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
81 { ON, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
82 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
83 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
84 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
85 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
86 { OFF, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
87 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
88 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
89 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
90 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
91 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
92 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
93 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
94 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
95 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
96 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
97 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
98 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
99 { OFF, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
100 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
101 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
102 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
103 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
104 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
105 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
106 { ON, "GL_EXT_vertex_array", 0 },
107 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
108 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
109 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
110 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
111 { OFF, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
112 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
113 { OFF, "GL_MESA_packed_depth_stencil", 0 },
114 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
115 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
116 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
117 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
118 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
119 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
120 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
121 { OFF, "GL_NV_fragment_program", F(NV_fragment_program) },
122 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
123 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
124 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
125 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
126 { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) },
127 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
128 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
129 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
130 { OFF, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
131 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
132 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
133 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
134 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
135 { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) },
136 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) }
137 };
138
139
140
141
142 /*
143 * Enable all extensions suitable for a software-only renderer.
144 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
145 */
146 void
147 _mesa_enable_sw_extensions(GLcontext *ctx)
148 {
149 const char *extensions[] = {
150 "GL_ARB_depth_texture",
151 "GL_ARB_imaging",
152 "GL_ARB_multitexture",
153 "GL_ARB_point_parameters",
154 "GL_ARB_shadow",
155 "GL_ARB_shadow_ambient",
156 "GL_ARB_texture_border_clamp",
157 "GL_ARB_texture_cube_map",
158 "GL_ARB_texture_env_add",
159 "GL_ARB_texture_env_combine",
160 "GL_ARB_texture_env_crossbar",
161 "GL_ARB_texture_env_dot3",
162 "GL_ARB_texture_mirrored_repeat",
163 "GL_ATI_texture_env_combine3",
164 "GL_ATI_texture_mirror_once",
165 "GL_EXT_blend_color",
166 "GL_EXT_blend_func_separate",
167 "GL_EXT_blend_logic_op",
168 "GL_EXT_blend_minmax",
169 "GL_EXT_blend_subtract",
170 "GL_EXT_convolution",
171 "GL_EXT_fog_coord",
172 "GL_EXT_histogram",
173 "GL_EXT_paletted_texture",
174 "GL_EXT_point_parameters",
175 "GL_EXT_shadow_funcs",
176 "GL_EXT_secondary_color",
177 "GL_EXT_shared_texture_palette",
178 "GL_EXT_stencil_wrap",
179 "GL_EXT_stencil_two_side",
180 "GL_EXT_texture_edge_clamp",
181 "GL_EXT_texture_env_add",
182 "GL_EXT_texture_env_combine",
183 "GL_EXT_texture_env_dot3",
184 "GL_EXT_texture_lod_bias",
185 "GL_HP_occlusion_test",
186 "GL_IBM_texture_mirrored_repeat",
187 "GL_INGR_blend_func_separate",
188 "GL_MESA_pack_invert",
189 "GL_MESA_resize_buffers",
190 "GL_MESA_ycbcr_texture",
191 "GL_NV_blend_square",
192 "GL_NV_point_sprite",
193 "GL_NV_texture_rectangle",
194 "GL_NV_texgen_reflection",
195 #if FEATURE_NV_vertex_program
196 "GL_NV_vertex_program",
197 "GL_NV_vertex_program1_1",
198 #endif
199 #if FEATURE_NV_fragment_program
200 "GL_NV_fragment_program",
201 #endif
202 "GL_SGI_color_matrix",
203 "GL_SGI_color_table",
204 "GL_SGI_texture_color_table",
205 "GL_SGIS_generate_mipmap",
206 "GL_SGIS_pixel_texture",
207 "GL_SGIS_texture_edge_clamp",
208 "GL_SGIS_texture_border_clamp",
209 "GL_SGIX_depth_texture",
210 "GL_SGIX_pixel_texture",
211 "GL_SGIX_shadow",
212 "GL_SGIX_shadow_ambient",
213 NULL
214 };
215 GLuint i;
216
217 for (i = 0; extensions[i]; i++) {
218 _mesa_enable_extension(ctx, extensions[i]);
219 }
220 }
221
222
223 /*
224 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
225 */
226 void
227 _mesa_enable_imaging_extensions(GLcontext *ctx)
228 {
229 const char *extensions[] = {
230 "GL_ARB_imaging",
231 "GL_EXT_blend_color",
232 "GL_EXT_blend_minmax",
233 "GL_EXT_blend_subtract",
234 "GL_EXT_convolution",
235 "GL_EXT_histogram",
236 "GL_SGI_color_matrix",
237 "GL_SGI_color_table",
238 NULL
239 };
240 GLuint i;
241
242 for (i = 0; extensions[i]; i++) {
243 _mesa_enable_extension(ctx, extensions[i]);
244 }
245 }
246
247
248
249 /*
250 * Enable all OpenGL 1.3 features and extensions.
251 */
252 void
253 _mesa_enable_1_3_extensions(GLcontext *ctx)
254 {
255 const char *extensions[] = {
256 "GL_ARB_multisample",
257 "GL_ARB_multitexture",
258 "GL_ARB_texture_border_clamp",
259 "GL_ARB_texture_compression",
260 "GL_ARB_texture_cube_map",
261 "GL_ARB_texture_env_add",
262 "GL_ARB_texture_env_combine",
263 "GL_ARB_texture_env_dot3",
264 "GL_ARB_transpose_matrix",
265 NULL
266 };
267 GLuint i;
268
269 for (i = 0; extensions[i]; i++) {
270 _mesa_enable_extension(ctx, extensions[i]);
271 }
272 }
273
274
275
276 /*
277 * Enable all OpenGL 1.4 features and extensions.
278 */
279 void
280 _mesa_enable_1_4_extensions(GLcontext *ctx)
281 {
282 const char *extensions[] = {
283 "GL_ARB_depth_texture",
284 "GL_ARB_point_parameters",
285 "GL_ARB_shadow",
286 "GL_ARB_texture_env_crossbar",
287 "GL_ARB_texture_mirrored_repeat",
288 "GL_ARB_window_pos",
289 "GL_EXT_blend_color",
290 "GL_EXT_blend_func_separate",
291 "GL_EXT_blend_logic_op",
292 "GL_EXT_blend_minmax",
293 "GL_EXT_blend_subtract",
294 "GL_EXT_fog_coord",
295 "GL_EXT_multi_draw_arrays",
296 "GL_EXT_secondary_color",
297 "GL_EXT_stencil_wrap",
298 "GL_SGIS_generate_mipmap",
299 NULL
300 };
301 GLuint i;
302
303 for (i = 0; extensions[i]; i++) {
304 _mesa_enable_extension(ctx, extensions[i]);
305 }
306 }
307
308
309
310 /*
311 * Add a new extenstion. This would be called from a Mesa driver.
312 */
313 void
314 _mesa_add_extension( GLcontext *ctx,
315 GLboolean enabled,
316 const char *name,
317 GLboolean *flag_ptr )
318 {
319 /* We should never try to add an extension after
320 * _mesa_extensions_get_string() has been called!
321 */
322 assert(ctx->Extensions.ext_string == 0);
323
324 {
325 struct extension *t = MALLOC_STRUCT(extension);
326 t->enabled = enabled;
327 _mesa_strncpy(t->name, name, MAX_EXT_NAMELEN);
328 t->name[MAX_EXT_NAMELEN] = 0;
329 t->flag = flag_ptr;
330 if (t->flag)
331 *t->flag = enabled;
332 insert_at_tail( ctx->Extensions.ext_list, t );
333 }
334 }
335
336
337 /*
338 * Either enable or disable the named extension.
339 */
340 static void
341 set_extension( GLcontext *ctx, const char *name, GLint state )
342 {
343 /* XXX we should assert that ext_string is null. We should never be
344 * enabling/disabling extensions after _mesa_extensions_get_string()
345 * has been called!
346 */
347 struct extension *i;
348 foreach( i, ctx->Extensions.ext_list )
349 if (_mesa_strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
350 break;
351
352 if (i == ctx->Extensions.ext_list) {
353 /* this is an error. Drivers should never try to enable/disable
354 * an extension which is unknown to Mesa or wasn't added by calling
355 * _mesa_add_extension().
356 */
357 return;
358 }
359
360 if (i->flag)
361 *(i->flag) = state;
362 i->enabled = state;
363 }
364
365
366
367 void
368 _mesa_enable_extension( GLcontext *ctx, const char *name )
369 {
370 if (ctx->Extensions.ext_string == 0)
371 set_extension( ctx, name, 1 );
372 }
373
374
375 void
376 _mesa_disable_extension( GLcontext *ctx, const char *name )
377 {
378 if (ctx->Extensions.ext_string == 0)
379 set_extension( ctx, name, 0 );
380 }
381
382
383 /*
384 * Test if the named extension is enabled in this context.
385 */
386 GLboolean
387 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
388 {
389 struct extension *i;
390 foreach( i, ctx->Extensions.ext_list )
391 if (_mesa_strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
392 if (i->enabled)
393 return GL_TRUE;
394 else
395 return GL_FALSE;
396 }
397
398 return GL_FALSE;
399 }
400
401
402 void
403 _mesa_extensions_dtr( GLcontext *ctx )
404 {
405 struct extension *i, *nexti;
406
407 if (ctx->Extensions.ext_string) {
408 FREE( ctx->Extensions.ext_string );
409 ctx->Extensions.ext_string = 0;
410 }
411
412 if (ctx->Extensions.ext_list) {
413 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
414 remove_from_list( i );
415 FREE( i );
416 }
417
418 FREE(ctx->Extensions.ext_list);
419 ctx->Extensions.ext_list = 0;
420 }
421 }
422
423
424 void
425 _mesa_extensions_ctr( GLcontext *ctx )
426 {
427 GLuint i;
428 GLboolean *base = (GLboolean *)&ctx->Extensions;
429
430 ctx->Extensions.ext_string = NULL;
431 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
432 make_empty_list( ctx->Extensions.ext_list );
433
434 for (i = 0 ; i < Elements(default_extensions) ; i++) {
435 GLboolean *ptr = NULL;
436
437 if (default_extensions[i].flag_offset)
438 ptr = base + default_extensions[i].flag_offset;
439
440 (void) _mesa_add_extension( ctx,
441 default_extensions[i].enabled,
442 default_extensions[i].name,
443 ptr);
444 }
445 }
446
447
448 const char *
449 _mesa_extensions_get_string( GLcontext *ctx )
450 {
451 if (ctx->Extensions.ext_string == 0)
452 {
453 struct extension *i;
454 char *str;
455 GLuint len = 0;
456 foreach (i, ctx->Extensions.ext_list)
457 if (i->enabled)
458 len += _mesa_strlen(i->name) + 1;
459
460 if (len == 0)
461 return "";
462
463 str = (char *) _mesa_malloc(len * sizeof(char));
464 ctx->Extensions.ext_string = str;
465
466 foreach (i, ctx->Extensions.ext_list)
467 if (i->enabled) {
468 _mesa_strcpy(str, i->name);
469 str += _mesa_strlen(str);
470 *str++ = ' ';
471 }
472
473 *(str-1) = 0;
474 }
475
476 return ctx->Extensions.ext_string;
477 }