added a comment
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.75 2002/06/15 03:03:08 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
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_depth_texture", F(ARB_depth_texture) },
60 { OFF, "GL_ARB_imaging", F(ARB_imaging) },
61 { OFF, "GL_ARB_multisample", F(ARB_multisample) },
62 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
63 { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) },
64 { OFF, "GL_ARB_shadow", F(ARB_shadow) },
65 { OFF, "GL_ARB_shadow_ambient", F(SGIX_shadow_ambient) },
66 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
67 { OFF, "GL_ARB_texture_compression", F(ARB_texture_compression) },
68 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
69 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
70 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
71 { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) },
72 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
73 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
74 { ON, "GL_ARB_transpose_matrix", 0 },
75 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
76 { ON, "GL_EXT_abgr", 0 },
77 { ON, "GL_EXT_bgra", 0 },
78 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
79 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
80 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
81 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
82 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
83 { ON, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
84 { OFF, "GL_EXT_cull_vertex", 0 },
85 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
86 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
87 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
88 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
89 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
90 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
91 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
92 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
93 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
94 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
95 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
96 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
97 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
98 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
99 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
100 { OFF, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
101 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
102 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
103 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
104 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
105 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
106 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
107 { ON, "GL_EXT_vertex_array", 0 },
108 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
109 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
110 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
111 { OFF, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
112 { OFF, "GL_MESA_packed_depth_stencil", 0 },
113 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
114 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
115 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
116 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
117 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
118 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
119 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
120 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
121 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
122 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
123 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
124 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
125 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
126 { OFF, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
127 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
128 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
129 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
130 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
131 { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) }
132 };
133
134
135
136
137 /*
138 * Enable all extensions suitable for a software-only renderer.
139 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
140 */
141 void
142 _mesa_enable_sw_extensions(GLcontext *ctx)
143 {
144 const char *extensions[] = {
145 "GL_ARB_depth_texture",
146 "GL_ARB_imaging",
147 "GL_ARB_multitexture",
148 "GL_ARB_point_parameters",
149 "GL_ARB_shadow",
150 "GL_ARB_shadow_ambient",
151 "GL_ARB_texture_border_clamp",
152 "GL_ARB_texture_cube_map",
153 "GL_ARB_texture_env_add",
154 "GL_ARB_texture_env_combine",
155 "GL_ARB_texture_env_crossbar",
156 "GL_ARB_texture_env_dot3",
157 "GL_ARB_texture_mirrored_repeat",
158 "GL_EXT_blend_color",
159 "GL_EXT_blend_func_separate",
160 "GL_EXT_blend_logic_op",
161 "GL_EXT_blend_minmax",
162 "GL_EXT_blend_subtract",
163 "GL_EXT_convolution",
164 "GL_EXT_fog_coord",
165 "GL_EXT_histogram",
166 "GL_EXT_paletted_texture",
167 "GL_EXT_point_parameters",
168 "GL_EXT_shadow_funcs",
169 "GL_EXT_secondary_color",
170 "GL_EXT_shared_texture_palette",
171 "GL_EXT_stencil_wrap",
172 "GL_EXT_texture_edge_clamp",
173 "GL_EXT_texture_env_add",
174 "GL_EXT_texture_env_combine",
175 "GL_EXT_texture_env_dot3",
176 "GL_EXT_texture_lod_bias",
177 "GL_HP_occlusion_test",
178 "GL_INGR_blend_func_separate",
179 "GL_MESA_resize_buffers",
180 "GL_NV_blend_square",
181 "GL_NV_point_sprite",
182 "GL_NV_texture_rectangle",
183 "GL_NV_texgen_reflection",
184 "GL_NV_vertex_program",
185 "GL_NV_vertex_program1_1",
186 "GL_SGI_color_matrix",
187 "GL_SGI_color_table",
188 "GL_SGIS_generate_mipmap",
189 "GL_SGIS_pixel_texture",
190 "GL_SGIS_texture_edge_clamp",
191 "GL_SGIS_texture_border_clamp",
192 "GL_SGIX_depth_texture",
193 "GL_SGIX_pixel_texture",
194 "GL_SGIX_shadow",
195 "GL_SGIX_shadow_ambient",
196 NULL
197 };
198 GLuint i;
199
200 for (i = 0; extensions[i]; i++) {
201 _mesa_enable_extension(ctx, extensions[i]);
202 }
203 }
204
205
206 /*
207 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
208 */
209 void
210 _mesa_enable_imaging_extensions(GLcontext *ctx)
211 {
212 const char *extensions[] = {
213 "GL_ARB_imaging",
214 "GL_EXT_blend_color",
215 "GL_EXT_blend_minmax",
216 "GL_EXT_blend_subtract",
217 "GL_EXT_convolution",
218 "GL_EXT_histogram",
219 "GL_SGI_color_matrix",
220 "GL_SGI_color_table",
221 NULL
222 };
223 GLuint i;
224
225 for (i = 0; extensions[i]; i++) {
226 _mesa_enable_extension(ctx, extensions[i]);
227 }
228 }
229
230
231
232 /*
233 * Enable all OpenGL 1.3 features and extensions.
234 */
235 void
236 _mesa_enable_1_3_extensions(GLcontext *ctx)
237 {
238 const char *extensions[] = {
239 "GL_ARB_multisample",
240 "GL_ARB_multitexture",
241 "GL_ARB_texture_border_clamp",
242 "GL_ARB_texture_compression",
243 "GL_ARB_texture_cube_map",
244 "GL_ARB_texture_env_add",
245 "GL_ARB_texture_env_combine",
246 "GL_ARB_texture_env_dot3",
247 "GL_ARB_transpose_matrix",
248 NULL
249 };
250 GLuint i;
251
252 for (i = 0; extensions[i]; i++) {
253 _mesa_enable_extension(ctx, extensions[i]);
254 }
255 }
256
257
258
259 /*
260 * Add a new extenstion. This would be called from a Mesa driver.
261 */
262 void
263 _mesa_add_extension( GLcontext *ctx,
264 GLboolean enabled,
265 const char *name,
266 GLboolean *flag_ptr )
267 {
268 /* We should never try to add an extension after
269 * _mesa_extensions_get_string() has been called!
270 */
271 assert(ctx->Extensions.ext_string == 0);
272
273 {
274 struct extension *t = MALLOC_STRUCT(extension);
275 t->enabled = enabled;
276 strncpy(t->name, name, MAX_EXT_NAMELEN);
277 t->name[MAX_EXT_NAMELEN] = 0;
278 t->flag = flag_ptr;
279 if (t->flag)
280 *t->flag = enabled;
281 insert_at_tail( ctx->Extensions.ext_list, t );
282 }
283 }
284
285
286 /*
287 * Either enable or disable the named extension.
288 */
289 static void
290 set_extension( GLcontext *ctx, const char *name, GLint state )
291 {
292 /* XXX we should assert that ext_string is null. We should never be
293 * enabling/disabling extensions after _mesa_extensions_get_string()
294 * has been called!
295 */
296 struct extension *i;
297 foreach( i, ctx->Extensions.ext_list )
298 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
299 break;
300
301 if (i == ctx->Extensions.ext_list) {
302 /* this is an error. Drivers should never try to enable/disable
303 * an extension which is unknown to Mesa or wasn't added by calling
304 * _mesa_add_extension().
305 */
306 return;
307 }
308
309 if (i->flag)
310 *(i->flag) = state;
311 i->enabled = state;
312 }
313
314
315
316 void
317 _mesa_enable_extension( GLcontext *ctx, const char *name )
318 {
319 if (ctx->Extensions.ext_string == 0)
320 set_extension( ctx, name, 1 );
321 }
322
323
324 void
325 _mesa_disable_extension( GLcontext *ctx, const char *name )
326 {
327 if (ctx->Extensions.ext_string == 0)
328 set_extension( ctx, name, 0 );
329 }
330
331
332 /*
333 * Test if the named extension is enabled in this context.
334 */
335 GLboolean
336 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
337 {
338 struct extension *i;
339 foreach( i, ctx->Extensions.ext_list )
340 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
341 if (i->enabled)
342 return GL_TRUE;
343 else
344 return GL_FALSE;
345 }
346
347 return GL_FALSE;
348 }
349
350
351 void
352 _mesa_extensions_dtr( GLcontext *ctx )
353 {
354 struct extension *i, *nexti;
355
356 if (ctx->Extensions.ext_string) {
357 FREE( ctx->Extensions.ext_string );
358 ctx->Extensions.ext_string = 0;
359 }
360
361 if (ctx->Extensions.ext_list) {
362 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
363 remove_from_list( i );
364 FREE( i );
365 }
366
367 FREE(ctx->Extensions.ext_list);
368 ctx->Extensions.ext_list = 0;
369 }
370 }
371
372
373 void
374 _mesa_extensions_ctr( GLcontext *ctx )
375 {
376 GLuint i;
377 GLboolean *base = (GLboolean *)&ctx->Extensions;
378
379 ctx->Extensions.ext_string = NULL;
380 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
381 make_empty_list( ctx->Extensions.ext_list );
382
383 for (i = 0 ; i < Elements(default_extensions) ; i++) {
384 GLboolean *ptr = NULL;
385
386 if (default_extensions[i].flag_offset)
387 ptr = base + default_extensions[i].flag_offset;
388
389 (void) _mesa_add_extension( ctx,
390 default_extensions[i].enabled,
391 default_extensions[i].name,
392 ptr);
393 }
394 }
395
396
397 const char *
398 _mesa_extensions_get_string( GLcontext *ctx )
399 {
400 if (ctx->Extensions.ext_string == 0)
401 {
402 struct extension *i;
403 char *str;
404 GLuint len = 0;
405 foreach (i, ctx->Extensions.ext_list)
406 if (i->enabled)
407 len += strlen(i->name) + 1;
408
409 if (len == 0)
410 return "";
411
412 str = (char *)MALLOC(len * sizeof(char));
413 ctx->Extensions.ext_string = str;
414
415 foreach (i, ctx->Extensions.ext_list)
416 if (i->enabled) {
417 strcpy(str, i->name);
418 str += strlen(str);
419 *str++ = ' ';
420 }
421
422 *(str-1) = 0;
423 }
424
425 return ctx->Extensions.ext_string;
426 }