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