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