fix for gl_ztrick bug (Ove Kaaven)
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.53 2001/03/18 08:53:49 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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_imaging", F(ARB_imaging) },
60 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
61 { OFF, "GL_ARB_texture_compression", F(ARB_texture_compression) },
62 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
63 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
64 { ON, "GL_ARB_tranpose_matrix", 0 },
65 { ON, "GL_EXT_abgr", 0 },
66 { ON, "GL_EXT_bgra", 0 },
67 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
68 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
69 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
70 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
71 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
72 { ON, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
73 { OFF, "GL_EXT_cull_vertex", 0 },
74 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
75 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
76 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
77 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
78 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
79 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
80 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
81 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
82 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
83 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
84 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
85 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
86 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
87 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
88 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
89 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
90 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
91 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
92 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
93 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
94 { ON, "GL_EXT_vertex_array", 0 },
95 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
96 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
97 { OFF, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
98 { OFF, "GL_MESA_packed_depth_stencil", 0 },
99 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
100 { OFF, "GL_MESA_sprite_point", F(MESA_sprite_point) },
101 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
102 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
103 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
104 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
105 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
106 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
107 { OFF, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
108 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
109 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
110 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
111 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
112 { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) }
113 };
114
115
116
117
118 /*
119 * Enable all extensions suitable for a software-only renderer.
120 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
121 */
122 void
123 _mesa_enable_sw_extensions(GLcontext *ctx)
124 {
125 const char *extensions[] = {
126 "GL_ARB_imaging",
127 "GL_ARB_multitexture",
128 "GL_ARB_texture_cube_map",
129 "GL_ARB_texture_env_add",
130 "GL_EXT_blend_color",
131 "GL_EXT_blend_func_separate",
132 "GL_EXT_blend_logic_op",
133 "GL_EXT_blend_minmax",
134 "GL_EXT_blend_subtract",
135 "GL_EXT_convolution",
136 "GL_EXT_fog_coord",
137 "GL_EXT_histogram",
138 "GL_EXT_paletted_texture",
139 "GL_EXT_point_parameters",
140 "GL_EXT_secondary_color",
141 "GL_EXT_shared_texture_palette",
142 "GL_EXT_stencil_wrap",
143 "GL_EXT_texture_env_add",
144 "GL_EXT_texture_env_combine",
145 "GL_EXT_texture_env_dot3",
146 "GL_EXT_texture_lod_bias",
147 "GL_HP_occlusion_test",
148 "GL_INGR_blend_func_separate",
149 "GL_MESA_resize_buffers",
150 "GL_NV_blend_square",
151 "GL_NV_texgen_reflection",
152 "GL_SGI_color_matrix",
153 "GL_SGI_color_table",
154 "GL_SGIS_pixel_texture",
155 "GL_SGIS_texture_edge_clamp",
156 "GL_SGIX_depth_texture",
157 "GL_SGIX_pixel_texture",
158 "GL_SGIX_shadow",
159 "GL_SGIX_shadow_ambient",
160 NULL
161 };
162 GLuint i;
163
164 for (i = 0; extensions[i]; i++) {
165 _mesa_enable_extension(ctx, extensions[i]);
166 }
167 }
168
169
170 /*
171 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
172 */
173 void
174 _mesa_enable_imaging_extensions(GLcontext *ctx)
175 {
176 const char *extensions[] = {
177 "GL_ARB_imaging",
178 "GL_EXT_blend_color",
179 "GL_EXT_blend_minmax",
180 "GL_EXT_blend_subtract",
181 "GL_EXT_convolution",
182 "GL_EXT_histogram",
183 "GL_SGI_color_matrix",
184 "GL_SGI_color_table",
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 * Add a new extenstion. This would be called from a Mesa driver.
197 */
198 void
199 _mesa_add_extension( GLcontext *ctx,
200 GLboolean enabled,
201 const char *name,
202 GLboolean *flag_ptr )
203 {
204 /* We should never try to add an extension after
205 * _mesa_extensions_get_string() has been called!
206 */
207 assert(ctx->Extensions.ext_string == 0);
208
209 {
210 struct extension *t = MALLOC_STRUCT(extension);
211 t->enabled = enabled;
212 strncpy(t->name, name, MAX_EXT_NAMELEN);
213 t->name[MAX_EXT_NAMELEN] = 0;
214 t->flag = flag_ptr;
215 if (t->flag)
216 *t->flag = enabled;
217 insert_at_tail( ctx->Extensions.ext_list, t );
218 }
219 }
220
221
222 /*
223 * Either enable or disable the named extension.
224 */
225 static void
226 set_extension( GLcontext *ctx, const char *name, GLint state )
227 {
228 /* XXX we should assert that ext_string is null. We should never be
229 * enabling/disabling extensions after _mesa_extensions_get_string()
230 * has been called!
231 */
232 struct extension *i;
233 foreach( i, ctx->Extensions.ext_list )
234 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
235 break;
236
237 if (i == ctx->Extensions.ext_list) {
238 /* this is an error. Drivers should never try to enable/disable
239 * an extension which is unknown to Mesa or wasn't added by calling
240 * _mesa_add_extension().
241 */
242 return;
243 }
244
245 if (i->flag)
246 *(i->flag) = state;
247 i->enabled = state;
248 }
249
250
251
252 void
253 _mesa_enable_extension( GLcontext *ctx, const char *name )
254 {
255 if (ctx->Extensions.ext_string == 0)
256 set_extension( ctx, name, 1 );
257 }
258
259
260 void
261 _mesa_disable_extension( GLcontext *ctx, const char *name )
262 {
263 if (ctx->Extensions.ext_string == 0)
264 set_extension( ctx, name, 0 );
265 }
266
267
268 /*
269 * Test if the named extension is enabled in this context.
270 */
271 GLboolean
272 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
273 {
274 struct extension *i;
275 foreach( i, ctx->Extensions.ext_list )
276 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
277 if (i->enabled)
278 return GL_TRUE;
279 else
280 return GL_FALSE;
281 }
282
283 return GL_FALSE;
284 }
285
286
287 void
288 _mesa_extensions_dtr( GLcontext *ctx )
289 {
290 struct extension *i, *nexti;
291
292 if (ctx->Extensions.ext_string) {
293 FREE( ctx->Extensions.ext_string );
294 ctx->Extensions.ext_string = 0;
295 }
296
297 if (ctx->Extensions.ext_list) {
298 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
299 remove_from_list( i );
300 FREE( i );
301 }
302
303 FREE(ctx->Extensions.ext_list);
304 ctx->Extensions.ext_list = 0;
305 }
306 }
307
308
309 void
310 _mesa_extensions_ctr( GLcontext *ctx )
311 {
312 GLuint i;
313 GLboolean *base = (GLboolean *)&ctx->Extensions;
314
315 ctx->Extensions.ext_string = NULL;
316 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
317 make_empty_list( ctx->Extensions.ext_list );
318
319 for (i = 0 ; i < Elements(default_extensions) ; i++) {
320 GLboolean *ptr = NULL;
321
322 if (default_extensions[i].flag_offset)
323 ptr = base + default_extensions[i].flag_offset;
324
325 (void) _mesa_add_extension( ctx,
326 default_extensions[i].enabled,
327 default_extensions[i].name,
328 ptr);
329 }
330 }
331
332
333 const char *
334 _mesa_extensions_get_string( GLcontext *ctx )
335 {
336 if (ctx->Extensions.ext_string == 0)
337 {
338 struct extension *i;
339 char *str;
340 GLuint len = 0;
341 foreach (i, ctx->Extensions.ext_list)
342 if (i->enabled)
343 len += strlen(i->name) + 1;
344
345 if (len == 0)
346 return "";
347
348 str = (char *)MALLOC(len * sizeof(char));
349 ctx->Extensions.ext_string = str;
350
351 foreach (i, ctx->Extensions.ext_list)
352 if (i->enabled) {
353 strcpy(str, i->name);
354 str += strlen(str);
355 *str++ = ' ';
356 }
357
358 *(str-1) = 0;
359 }
360
361 return ctx->Extensions.ext_string;
362 }