96984359c18a99e857b25cabf45a6e18632db49d
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.73 2002/05/02 00:59:20 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 { OFF, "GL_MESA_sprite_point", F(MESA_sprite_point) },
115 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
116 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
117 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
118 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
119 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
120 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
121 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
122 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
123 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
124 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
125 { OFF, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
126 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
127 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
128 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
129 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
130 { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) }
131 };
132
133
134
135
136 /*
137 * Enable all extensions suitable for a software-only renderer.
138 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
139 */
140 void
141 _mesa_enable_sw_extensions(GLcontext *ctx)
142 {
143 const char *extensions[] = {
144 "GL_ARB_depth_texture",
145 "GL_ARB_imaging",
146 "GL_ARB_multitexture",
147 "GL_ARB_point_parameters",
148 "GL_ARB_shadow",
149 "GL_ARB_shadow_ambient",
150 "GL_ARB_texture_border_clamp",
151 "GL_ARB_texture_cube_map",
152 "GL_ARB_texture_env_add",
153 "GL_ARB_texture_env_combine",
154 "GL_ARB_texture_env_crossbar",
155 "GL_ARB_texture_env_dot3",
156 "GL_ARB_texture_mirrored_repeat",
157 "GL_EXT_blend_color",
158 "GL_EXT_blend_func_separate",
159 "GL_EXT_blend_logic_op",
160 "GL_EXT_blend_minmax",
161 "GL_EXT_blend_subtract",
162 "GL_EXT_convolution",
163 "GL_EXT_fog_coord",
164 "GL_EXT_histogram",
165 "GL_EXT_paletted_texture",
166 "GL_EXT_point_parameters",
167 "GL_EXT_shadow_funcs",
168 "GL_EXT_secondary_color",
169 "GL_EXT_shared_texture_palette",
170 "GL_EXT_stencil_wrap",
171 "GL_EXT_texture_edge_clamp",
172 "GL_EXT_texture_env_add",
173 "GL_EXT_texture_env_combine",
174 "GL_EXT_texture_env_dot3",
175 "GL_EXT_texture_lod_bias",
176 "GL_HP_occlusion_test",
177 "GL_INGR_blend_func_separate",
178 "GL_MESA_resize_buffers",
179 "GL_NV_blend_square",
180 "GL_NV_texgen_reflection",
181 "GL_NV_vertex_program",
182 "GL_NV_vertex_program1_1",
183 "GL_SGI_color_matrix",
184 "GL_SGI_color_table",
185 "GL_SGIS_generate_mipmap",
186 "GL_SGIS_pixel_texture",
187 "GL_SGIS_texture_edge_clamp",
188 "GL_SGIS_texture_border_clamp",
189 "GL_SGIX_depth_texture",
190 "GL_SGIX_pixel_texture",
191 "GL_SGIX_shadow",
192 "GL_SGIX_shadow_ambient",
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 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
205 */
206 void
207 _mesa_enable_imaging_extensions(GLcontext *ctx)
208 {
209 const char *extensions[] = {
210 "GL_ARB_imaging",
211 "GL_EXT_blend_color",
212 "GL_EXT_blend_minmax",
213 "GL_EXT_blend_subtract",
214 "GL_EXT_convolution",
215 "GL_EXT_histogram",
216 "GL_SGI_color_matrix",
217 "GL_SGI_color_table",
218 NULL
219 };
220 GLuint i;
221
222 for (i = 0; extensions[i]; i++) {
223 _mesa_enable_extension(ctx, extensions[i]);
224 }
225 }
226
227
228
229 /*
230 * Enable all OpenGL 1.3 features and extensions.
231 */
232 void
233 _mesa_enable_1_3_extensions(GLcontext *ctx)
234 {
235 const char *extensions[] = {
236 "GL_ARB_multisample",
237 "GL_ARB_multitexture",
238 "GL_ARB_texture_border_clamp",
239 "GL_ARB_texture_compression",
240 "GL_ARB_texture_cube_map",
241 "GL_ARB_texture_env_add",
242 "GL_ARB_texture_env_combine",
243 "GL_ARB_texture_env_dot3",
244 "GL_ARB_transpose_matrix",
245 NULL
246 };
247 GLuint i;
248
249 for (i = 0; extensions[i]; i++) {
250 _mesa_enable_extension(ctx, extensions[i]);
251 }
252 }
253
254
255
256 /*
257 * Add a new extenstion. This would be called from a Mesa driver.
258 */
259 void
260 _mesa_add_extension( GLcontext *ctx,
261 GLboolean enabled,
262 const char *name,
263 GLboolean *flag_ptr )
264 {
265 /* We should never try to add an extension after
266 * _mesa_extensions_get_string() has been called!
267 */
268 assert(ctx->Extensions.ext_string == 0);
269
270 {
271 struct extension *t = MALLOC_STRUCT(extension);
272 t->enabled = enabled;
273 strncpy(t->name, name, MAX_EXT_NAMELEN);
274 t->name[MAX_EXT_NAMELEN] = 0;
275 t->flag = flag_ptr;
276 if (t->flag)
277 *t->flag = enabled;
278 insert_at_tail( ctx->Extensions.ext_list, t );
279 }
280 }
281
282
283 /*
284 * Either enable or disable the named extension.
285 */
286 static void
287 set_extension( GLcontext *ctx, const char *name, GLint state )
288 {
289 /* XXX we should assert that ext_string is null. We should never be
290 * enabling/disabling extensions after _mesa_extensions_get_string()
291 * has been called!
292 */
293 struct extension *i;
294 foreach( i, ctx->Extensions.ext_list )
295 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
296 break;
297
298 if (i == ctx->Extensions.ext_list) {
299 /* this is an error. Drivers should never try to enable/disable
300 * an extension which is unknown to Mesa or wasn't added by calling
301 * _mesa_add_extension().
302 */
303 return;
304 }
305
306 if (i->flag)
307 *(i->flag) = state;
308 i->enabled = state;
309 }
310
311
312
313 void
314 _mesa_enable_extension( GLcontext *ctx, const char *name )
315 {
316 if (ctx->Extensions.ext_string == 0)
317 set_extension( ctx, name, 1 );
318 }
319
320
321 void
322 _mesa_disable_extension( GLcontext *ctx, const char *name )
323 {
324 if (ctx->Extensions.ext_string == 0)
325 set_extension( ctx, name, 0 );
326 }
327
328
329 /*
330 * Test if the named extension is enabled in this context.
331 */
332 GLboolean
333 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
334 {
335 struct extension *i;
336 foreach( i, ctx->Extensions.ext_list )
337 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
338 if (i->enabled)
339 return GL_TRUE;
340 else
341 return GL_FALSE;
342 }
343
344 return GL_FALSE;
345 }
346
347
348 void
349 _mesa_extensions_dtr( GLcontext *ctx )
350 {
351 struct extension *i, *nexti;
352
353 if (ctx->Extensions.ext_string) {
354 FREE( ctx->Extensions.ext_string );
355 ctx->Extensions.ext_string = 0;
356 }
357
358 if (ctx->Extensions.ext_list) {
359 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
360 remove_from_list( i );
361 FREE( i );
362 }
363
364 FREE(ctx->Extensions.ext_list);
365 ctx->Extensions.ext_list = 0;
366 }
367 }
368
369
370 void
371 _mesa_extensions_ctr( GLcontext *ctx )
372 {
373 GLuint i;
374 GLboolean *base = (GLboolean *)&ctx->Extensions;
375
376 ctx->Extensions.ext_string = NULL;
377 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
378 make_empty_list( ctx->Extensions.ext_list );
379
380 for (i = 0 ; i < Elements(default_extensions) ; i++) {
381 GLboolean *ptr = NULL;
382
383 if (default_extensions[i].flag_offset)
384 ptr = base + default_extensions[i].flag_offset;
385
386 (void) _mesa_add_extension( ctx,
387 default_extensions[i].enabled,
388 default_extensions[i].name,
389 ptr);
390 }
391 }
392
393
394 const char *
395 _mesa_extensions_get_string( GLcontext *ctx )
396 {
397 if (ctx->Extensions.ext_string == 0)
398 {
399 struct extension *i;
400 char *str;
401 GLuint len = 0;
402 foreach (i, ctx->Extensions.ext_list)
403 if (i->enabled)
404 len += strlen(i->name) + 1;
405
406 if (len == 0)
407 return "";
408
409 str = (char *)MALLOC(len * sizeof(char));
410 ctx->Extensions.ext_string = str;
411
412 foreach (i, ctx->Extensions.ext_list)
413 if (i->enabled) {
414 strcpy(str, i->name);
415 str += strlen(str);
416 *str++ = ' ';
417 }
418
419 *(str-1) = 0;
420 }
421
422 return ctx->Extensions.ext_string;
423 }