set *t->flag = enabled in gl_extensions_add(), otherwise, extension booleans weren...
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.40 2000/10/30 16:27:21 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 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 "types.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 { ON, "GL_ARB_imaging", F(ARB_imaging) },
60 { ON, "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 { ON, "GL_ARB_texture_env_add", F(ARB_texture_env_add) },
64 { ON, "GL_ARB_tranpose_matrix", 0 },
65 { ON, "GL_EXT_abgr", 0 },
66 { OFF, "GL_EXT_bgra", 0 },
67 { ON, "GL_EXT_blend_color", F(EXT_blend_color) },
68 { ON, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
69 { ON, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
70 { ON, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
71 { ON, "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 { ON, "GL_EXT_convolution", F(EXT_convolution) },
75 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
76 { ON, "GL_EXT_fog_coord", F(EXT_fog_coord) },
77 { ON, "GL_EXT_histogram", F(EXT_histogram) },
78 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
79 { ON, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
80 { ON, "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 { ON, "GL_EXT_secondary_color", F(EXT_secondary_color) },
84 { ON, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
85 { ON, "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 { ON, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
89 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
90 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
91 { ON, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
92 { ON, "GL_EXT_vertex_array", 0 },
93 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
94 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
95 { ON, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) },
96 { ON, "GL_MESA_window_pos", F(MESA_window_pos) },
97 { ON, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
98 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
99 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
100 { ON, "GL_PGI_misc_hints", F(PGI_misc_hints) },
101 { ON, "GL_SGI_color_matrix", F(SGI_color_matrix) },
102 { ON, "GL_SGI_color_table", F(SGI_color_table) },
103 { ON, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
104 { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
105 { ON, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
106 { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) }
107 };
108
109
110
111
112
113 int gl_extensions_add( GLcontext *ctx,
114 GLboolean enabled,
115 const char *name,
116 GLboolean *flag_ptr )
117 {
118 if (ctx->Extensions.ext_string == 0) {
119 struct extension *t = MALLOC_STRUCT(extension);
120 t->enabled = enabled;
121 strncpy(t->name, name, MAX_EXT_NAMELEN);
122 t->name[MAX_EXT_NAMELEN] = 0;
123 t->flag = flag_ptr;
124 if (t->flag)
125 *t->flag = enabled;
126 insert_at_tail( ctx->Extensions.ext_list, t );
127 return 0;
128 }
129 return 1;
130 }
131
132
133 /*
134 * Either enable or disable the named extension.
135 */
136 static int set_extension( GLcontext *ctx, const char *name, GLint state )
137 {
138 struct extension *i;
139 foreach( i, ctx->Extensions.ext_list )
140 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
141 break;
142
143 if (i == ctx->Extensions.ext_list)
144 return 1;
145
146 if (i->flag)
147 *(i->flag) = state;
148 i->enabled = state;
149 return 0;
150 }
151
152
153 int gl_extensions_enable( GLcontext *ctx, const char *name )
154 {
155 if (ctx->Extensions.ext_string == 0)
156 return set_extension( ctx, name, 1 );
157 return 1;
158 }
159
160
161 int gl_extensions_disable( GLcontext *ctx, const char *name )
162 {
163 if (ctx->Extensions.ext_string == 0)
164 return set_extension( ctx, name, 0 );
165 return 1;
166 }
167
168
169 /*
170 * Test if the named extension is enabled in this context.
171 */
172 GLboolean gl_extension_is_enabled( GLcontext *ctx, const char *name)
173 {
174 struct extension *i;
175 foreach( i, ctx->Extensions.ext_list )
176 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
177 if (i->enabled)
178 return GL_TRUE;
179 else
180 return GL_FALSE;
181 }
182
183 return GL_FALSE;
184 }
185
186
187 void gl_extensions_dtr( GLcontext *ctx )
188 {
189 struct extension *i, *nexti;
190
191 if (ctx->Extensions.ext_string) {
192 FREE( ctx->Extensions.ext_string );
193 ctx->Extensions.ext_string = 0;
194 }
195
196 if (ctx->Extensions.ext_list) {
197 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
198 remove_from_list( i );
199 FREE( i );
200 }
201
202 FREE(ctx->Extensions.ext_list);
203 ctx->Extensions.ext_list = 0;
204 }
205 }
206
207
208 void gl_extensions_ctr( GLcontext *ctx )
209 {
210 GLuint i;
211 GLboolean *base = (GLboolean *)&ctx->Extensions;
212
213 ctx->Extensions.ext_string = 0;
214 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
215 make_empty_list( ctx->Extensions.ext_list );
216
217 for (i = 0 ; i < Elements(default_extensions) ; i++) {
218 GLboolean *ptr = 0;
219
220 if (default_extensions[i].flag_offset)
221 ptr = base + default_extensions[i].flag_offset;
222
223 gl_extensions_add( ctx,
224 default_extensions[i].enabled,
225 default_extensions[i].name,
226 ptr);
227 }
228 }
229
230
231 const char *gl_extensions_get_string( GLcontext *ctx )
232 {
233 if (ctx->Extensions.ext_string == 0)
234 {
235 struct extension *i;
236 char *str;
237 GLuint len = 0;
238 foreach (i, ctx->Extensions.ext_list)
239 if (i->enabled)
240 len += strlen(i->name) + 1;
241
242 if (len == 0)
243 return "";
244
245 str = (char *)MALLOC(len * sizeof(char));
246 ctx->Extensions.ext_string = str;
247
248 foreach (i, ctx->Extensions.ext_list)
249 if (i->enabled) {
250 strcpy(str, i->name);
251 str += strlen(str);
252 *str++ = ' ';
253 }
254
255 *(str-1) = 0;
256 }
257
258 return ctx->Extensions.ext_string;
259 }