GL_MESA_pack_invert
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.80 2002/09/21 17:34:56 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_convolution", F(EXT_convolution) },
85 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
86 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
87 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
88 { OFF, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
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 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
99 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
100 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
101 { OFF, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
102 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
103 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
104 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
105 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
106 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
107 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
108 { ON, "GL_EXT_vertex_array", 0 },
109 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
110 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
111 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
112 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
113 { OFF, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
114 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
115 { OFF, "GL_MESA_packed_depth_stencil", 0 },
116 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
117 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
118 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
119 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
120 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
121 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
122 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
123 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
124 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
125 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
126 { OFF, "GL_SGI_color_table", F(SGI_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(_3DFX_texture_compression_FXT1) },
136 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) }
137
138 };
139
140
141
142
143 /*
144 * Enable all extensions suitable for a software-only renderer.
145 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
146 */
147 void
148 _mesa_enable_sw_extensions(GLcontext *ctx)
149 {
150 const char *extensions[] = {
151 "GL_ARB_depth_texture",
152 "GL_ARB_imaging",
153 "GL_ARB_multitexture",
154 "GL_ARB_point_parameters",
155 "GL_ARB_shadow",
156 "GL_ARB_shadow_ambient",
157 "GL_ARB_texture_border_clamp",
158 "GL_ARB_texture_cube_map",
159 "GL_ARB_texture_env_add",
160 "GL_ARB_texture_env_combine",
161 "GL_ARB_texture_env_crossbar",
162 "GL_ARB_texture_env_dot3",
163 "GL_ARB_texture_mirrored_repeat",
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 "GL_NV_vertex_program",
195 "GL_NV_vertex_program1_1",
196 "GL_SGI_color_matrix",
197 "GL_SGI_color_table",
198 "GL_SGIS_generate_mipmap",
199 "GL_SGIS_pixel_texture",
200 "GL_SGIS_texture_edge_clamp",
201 "GL_SGIS_texture_border_clamp",
202 "GL_SGIX_depth_texture",
203 "GL_SGIX_pixel_texture",
204 "GL_SGIX_shadow",
205 "GL_SGIX_shadow_ambient",
206 NULL
207 };
208 GLuint i;
209
210 for (i = 0; extensions[i]; i++) {
211 _mesa_enable_extension(ctx, extensions[i]);
212 }
213 }
214
215
216 /*
217 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
218 */
219 void
220 _mesa_enable_imaging_extensions(GLcontext *ctx)
221 {
222 const char *extensions[] = {
223 "GL_ARB_imaging",
224 "GL_EXT_blend_color",
225 "GL_EXT_blend_minmax",
226 "GL_EXT_blend_subtract",
227 "GL_EXT_convolution",
228 "GL_EXT_histogram",
229 "GL_SGI_color_matrix",
230 "GL_SGI_color_table",
231 NULL
232 };
233 GLuint i;
234
235 for (i = 0; extensions[i]; i++) {
236 _mesa_enable_extension(ctx, extensions[i]);
237 }
238 }
239
240
241
242 /*
243 * Enable all OpenGL 1.3 features and extensions.
244 */
245 void
246 _mesa_enable_1_3_extensions(GLcontext *ctx)
247 {
248 const char *extensions[] = {
249 "GL_ARB_multisample",
250 "GL_ARB_multitexture",
251 "GL_ARB_texture_border_clamp",
252 "GL_ARB_texture_compression",
253 "GL_ARB_texture_cube_map",
254 "GL_ARB_texture_env_add",
255 "GL_ARB_texture_env_combine",
256 "GL_ARB_texture_env_dot3",
257 "GL_ARB_transpose_matrix",
258 NULL
259 };
260 GLuint i;
261
262 for (i = 0; extensions[i]; i++) {
263 _mesa_enable_extension(ctx, extensions[i]);
264 }
265 }
266
267
268
269 /*
270 * Enable all OpenGL 1.4 features and extensions.
271 */
272 void
273 _mesa_enable_1_4_extensions(GLcontext *ctx)
274 {
275 const char *extensions[] = {
276 "GL_ARB_depth_texture",
277 "GL_ARB_point_parameters",
278 "GL_ARB_shadow",
279 "GL_ARB_texture_env_crossbar",
280 "GL_ARB_texture_mirrored_repeat",
281 "GL_ARB_window_pos",
282 "GL_EXT_blend_color",
283 "GL_EXT_blend_func_separate",
284 "GL_EXT_blend_logic_op",
285 "GL_EXT_blend_minmax",
286 "GL_EXT_blend_subtract",
287 "GL_EXT_fog_coord",
288 "GL_EXT_multi_draw_arrays",
289 "GL_EXT_secondary_color",
290 "GL_EXT_stencil_wrap",
291 "GL_SGIS_generate_mipmap",
292 NULL
293 };
294 GLuint i;
295
296 for (i = 0; extensions[i]; i++) {
297 _mesa_enable_extension(ctx, extensions[i]);
298 }
299 }
300
301
302
303 /*
304 * Add a new extenstion. This would be called from a Mesa driver.
305 */
306 void
307 _mesa_add_extension( GLcontext *ctx,
308 GLboolean enabled,
309 const char *name,
310 GLboolean *flag_ptr )
311 {
312 /* We should never try to add an extension after
313 * _mesa_extensions_get_string() has been called!
314 */
315 assert(ctx->Extensions.ext_string == 0);
316
317 {
318 struct extension *t = MALLOC_STRUCT(extension);
319 t->enabled = enabled;
320 strncpy(t->name, name, MAX_EXT_NAMELEN);
321 t->name[MAX_EXT_NAMELEN] = 0;
322 t->flag = flag_ptr;
323 if (t->flag)
324 *t->flag = enabled;
325 insert_at_tail( ctx->Extensions.ext_list, t );
326 }
327 }
328
329
330 /*
331 * Either enable or disable the named extension.
332 */
333 static void
334 set_extension( GLcontext *ctx, const char *name, GLint state )
335 {
336 /* XXX we should assert that ext_string is null. We should never be
337 * enabling/disabling extensions after _mesa_extensions_get_string()
338 * has been called!
339 */
340 struct extension *i;
341 foreach( i, ctx->Extensions.ext_list )
342 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
343 break;
344
345 if (i == ctx->Extensions.ext_list) {
346 /* this is an error. Drivers should never try to enable/disable
347 * an extension which is unknown to Mesa or wasn't added by calling
348 * _mesa_add_extension().
349 */
350 return;
351 }
352
353 if (i->flag)
354 *(i->flag) = state;
355 i->enabled = state;
356 }
357
358
359
360 void
361 _mesa_enable_extension( GLcontext *ctx, const char *name )
362 {
363 if (ctx->Extensions.ext_string == 0)
364 set_extension( ctx, name, 1 );
365 }
366
367
368 void
369 _mesa_disable_extension( GLcontext *ctx, const char *name )
370 {
371 if (ctx->Extensions.ext_string == 0)
372 set_extension( ctx, name, 0 );
373 }
374
375
376 /*
377 * Test if the named extension is enabled in this context.
378 */
379 GLboolean
380 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
381 {
382 struct extension *i;
383 foreach( i, ctx->Extensions.ext_list )
384 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
385 if (i->enabled)
386 return GL_TRUE;
387 else
388 return GL_FALSE;
389 }
390
391 return GL_FALSE;
392 }
393
394
395 void
396 _mesa_extensions_dtr( GLcontext *ctx )
397 {
398 struct extension *i, *nexti;
399
400 if (ctx->Extensions.ext_string) {
401 FREE( ctx->Extensions.ext_string );
402 ctx->Extensions.ext_string = 0;
403 }
404
405 if (ctx->Extensions.ext_list) {
406 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
407 remove_from_list( i );
408 FREE( i );
409 }
410
411 FREE(ctx->Extensions.ext_list);
412 ctx->Extensions.ext_list = 0;
413 }
414 }
415
416
417 void
418 _mesa_extensions_ctr( GLcontext *ctx )
419 {
420 GLuint i;
421 GLboolean *base = (GLboolean *)&ctx->Extensions;
422
423 ctx->Extensions.ext_string = NULL;
424 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
425 make_empty_list( ctx->Extensions.ext_list );
426
427 for (i = 0 ; i < Elements(default_extensions) ; i++) {
428 GLboolean *ptr = NULL;
429
430 if (default_extensions[i].flag_offset)
431 ptr = base + default_extensions[i].flag_offset;
432
433 (void) _mesa_add_extension( ctx,
434 default_extensions[i].enabled,
435 default_extensions[i].name,
436 ptr);
437 }
438 }
439
440
441 const char *
442 _mesa_extensions_get_string( GLcontext *ctx )
443 {
444 if (ctx->Extensions.ext_string == 0)
445 {
446 struct extension *i;
447 char *str;
448 GLuint len = 0;
449 foreach (i, ctx->Extensions.ext_list)
450 if (i->enabled)
451 len += strlen(i->name) + 1;
452
453 if (len == 0)
454 return "";
455
456 str = (char *)MALLOC(len * sizeof(char));
457 ctx->Extensions.ext_string = str;
458
459 foreach (i, ctx->Extensions.ext_list)
460 if (i->enabled) {
461 strcpy(str, i->name);
462 str += strlen(str);
463 *str++ = ' ';
464 }
465
466 *(str-1) = 0;
467 }
468
469 return ctx->Extensions.ext_string;
470 }