signal _NEW_TEXTURE in all teximage functions
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.51 2001/02/27 00:13:25 brianp 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(ARB_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 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
92 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
93 { ON, "GL_EXT_vertex_array", 0 },
94 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
95 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
96 { OFF, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
97 { OFF, "GL_MESA_packed_depth_stencil", 0 },
98 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
99 { OFF, "GL_MESA_sprite_point", F(MESA_sprite_point) },
100 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
101 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
102 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
103 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
104 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
105 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
106 { OFF, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
107 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
108 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
109 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
110 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
111 { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) }
112 };
113
114
115
116
117 /*
118 * Enable all extensions suitable for a software-only renderer.
119 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
120 */
121 void
122 _mesa_enable_sw_extensions(GLcontext *ctx)
123 {
124 const char *extensions[] = {
125 "GL_ARB_imaging",
126 "GL_ARB_multitexture",
127 "GL_ARB_texture_cube_map",
128 "GL_ARB_texture_env_add",
129 "GL_EXT_blend_color",
130 "GL_EXT_blend_func_separate",
131 "GL_EXT_blend_logic_op",
132 "GL_EXT_blend_minmax",
133 "GL_EXT_blend_subtract",
134 "GL_EXT_convolution",
135 "GL_EXT_fog_coord",
136 "GL_EXT_histogram",
137 "GL_EXT_paletted_texture",
138 "GL_EXT_point_parameters",
139 "GL_EXT_secondary_color",
140 "GL_EXT_shared_texture_palette",
141 "GL_EXT_stencil_wrap",
142 "GL_EXT_texture_env_add",
143 "GL_EXT_texture_env_combine",
144 "GL_EXT_texture_env_dot3",
145 "GL_EXT_texture_lod_bias",
146 "GL_HP_occlusion_test",
147 "GL_INGR_blend_func_separate",
148 "GL_MESA_resize_buffers",
149 "GL_NV_blend_square",
150 "GL_NV_texgen_reflection",
151 "GL_SGI_color_matrix",
152 "GL_SGI_color_table",
153 "GL_SGIS_pixel_texture",
154 "GL_SGIS_texture_edge_clamp",
155 "GL_SGIX_depth_texture",
156 "GL_SGIX_pixel_texture",
157 "GL_SGIX_shadow",
158 "GL_SGIX_shadow_ambient",
159 NULL
160 };
161 GLuint i;
162
163 for (i = 0; extensions[i]; i++) {
164 _mesa_enable_extension(ctx, extensions[i]);
165 }
166 }
167
168
169 /*
170 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
171 */
172 void
173 _mesa_enable_imaging_extensions(GLcontext *ctx)
174 {
175 const char *extensions[] = {
176 "GL_ARB_imaging",
177 "GL_EXT_blend_color",
178 "GL_EXT_blend_minmax",
179 "GL_EXT_blend_subtract",
180 "GL_EXT_convolution",
181 "GL_EXT_histogram",
182 "GL_SGI_color_matrix",
183 "GL_SGI_color_table",
184 NULL
185 };
186 GLuint i;
187
188 for (i = 0; extensions[i]; i++) {
189 _mesa_enable_extension(ctx, extensions[i]);
190 }
191 }
192
193
194 /*
195 * Add a new extenstion. This would be called from a Mesa driver.
196 */
197 void
198 _mesa_add_extension( GLcontext *ctx,
199 GLboolean enabled,
200 const char *name,
201 GLboolean *flag_ptr )
202 {
203 /* We should never try to add an extension after
204 * _mesa_extensions_get_string() has been called!
205 */
206 assert(ctx->Extensions.ext_string == 0);
207
208 {
209 struct extension *t = MALLOC_STRUCT(extension);
210 t->enabled = enabled;
211 strncpy(t->name, name, MAX_EXT_NAMELEN);
212 t->name[MAX_EXT_NAMELEN] = 0;
213 t->flag = flag_ptr;
214 if (t->flag)
215 *t->flag = enabled;
216 insert_at_tail( ctx->Extensions.ext_list, t );
217 }
218 }
219
220
221 /*
222 * Either enable or disable the named extension.
223 */
224 static void
225 set_extension( GLcontext *ctx, const char *name, GLint state )
226 {
227 /* XXX we should assert that ext_string is null. We should never be
228 * enabling/disabling extensions after _mesa_extensions_get_string()
229 * has been called!
230 */
231 struct extension *i;
232 foreach( i, ctx->Extensions.ext_list )
233 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
234 break;
235
236 if (i == ctx->Extensions.ext_list) {
237 /* this is an error. Drivers should never try to enable/disable
238 * an extension which is unknown to Mesa or wasn't added by calling
239 * _mesa_add_extension().
240 */
241 return;
242 }
243
244 if (i->flag)
245 *(i->flag) = state;
246 i->enabled = state;
247 }
248
249
250
251 void
252 _mesa_enable_extension( GLcontext *ctx, const char *name )
253 {
254 if (ctx->Extensions.ext_string == 0)
255 set_extension( ctx, name, 1 );
256 }
257
258
259 void
260 _mesa_disable_extension( GLcontext *ctx, const char *name )
261 {
262 if (ctx->Extensions.ext_string == 0)
263 set_extension( ctx, name, 0 );
264 }
265
266
267 /*
268 * Test if the named extension is enabled in this context.
269 */
270 GLboolean
271 _mesa_extension_is_enabled( GLcontext *ctx, const char *name)
272 {
273 struct extension *i;
274 foreach( i, ctx->Extensions.ext_list )
275 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
276 if (i->enabled)
277 return GL_TRUE;
278 else
279 return GL_FALSE;
280 }
281
282 return GL_FALSE;
283 }
284
285
286 void
287 _mesa_extensions_dtr( GLcontext *ctx )
288 {
289 struct extension *i, *nexti;
290
291 if (ctx->Extensions.ext_string) {
292 FREE( ctx->Extensions.ext_string );
293 ctx->Extensions.ext_string = 0;
294 }
295
296 if (ctx->Extensions.ext_list) {
297 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
298 remove_from_list( i );
299 FREE( i );
300 }
301
302 FREE(ctx->Extensions.ext_list);
303 ctx->Extensions.ext_list = 0;
304 }
305 }
306
307
308 void
309 _mesa_extensions_ctr( GLcontext *ctx )
310 {
311 GLuint i;
312 GLboolean *base = (GLboolean *)&ctx->Extensions;
313
314 ctx->Extensions.ext_string = NULL;
315 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
316 make_empty_list( ctx->Extensions.ext_list );
317
318 for (i = 0 ; i < Elements(default_extensions) ; i++) {
319 GLboolean *ptr = NULL;
320
321 if (default_extensions[i].flag_offset)
322 ptr = base + default_extensions[i].flag_offset;
323
324 (void) _mesa_add_extension( ctx,
325 default_extensions[i].enabled,
326 default_extensions[i].name,
327 ptr);
328 }
329 }
330
331
332 const char *
333 _mesa_extensions_get_string( GLcontext *ctx )
334 {
335 if (ctx->Extensions.ext_string == 0)
336 {
337 struct extension *i;
338 char *str;
339 GLuint len = 0;
340 foreach (i, ctx->Extensions.ext_list)
341 if (i->enabled)
342 len += strlen(i->name) + 1;
343
344 if (len == 0)
345 return "";
346
347 str = (char *)MALLOC(len * sizeof(char));
348 ctx->Extensions.ext_string = str;
349
350 foreach (i, ctx->Extensions.ext_list)
351 if (i->enabled) {
352 strcpy(str, i->name);
353 str += strlen(str);
354 *str++ = ' ';
355 }
356
357 *(str-1) = 0;
358 }
359
360 return ctx->Extensions.ext_string;
361 }