work on GL_SGI_color_table
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.24 2000/04/17 15:13:53 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
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 char name[MAX_EXT_NAMELEN+1];
46 void (*notify)( GLcontext *, GLboolean );
47 };
48
49
50
51 static struct { int enabled; const char *name; } default_extensions[] = {
52 { DEFAULT_OFF, "GL_ARB_imaging" },
53 { DEFAULT_ON, "GL_ARB_multitexture" },
54 { ALWAYS_ENABLED, "GL_ARB_tranpose_matrix" },
55 { ALWAYS_ENABLED, "GL_EXT_abgr" },
56 { DEFAULT_ON, "GL_EXT_blend_color" },
57 { DEFAULT_ON, "GL_EXT_blend_logic_op" },
58 { DEFAULT_ON, "GL_EXT_blend_minmax" },
59 { DEFAULT_ON, "GL_EXT_blend_subtract" },
60 { DEFAULT_ON, "GL_EXT_clip_volume_hint" },
61 { DEFAULT_ON, "GL_EXT_compiled_vertex_array" },
62 { DEFAULT_ON, "GL_EXT_paletted_texture" },
63 { DEFAULT_ON, "GL_EXT_point_parameters" },
64 { ALWAYS_ENABLED, "GL_EXT_polygon_offset" },
65 { ALWAYS_ENABLED, "GL_EXT_rescale_normal" },
66 { DEFAULT_ON, "GL_EXT_shared_texture_palette" },
67 { ALWAYS_ENABLED, "GL_EXT_stencil_wrap" },
68 { DEFAULT_ON, "GL_EXT_texture3D" },
69 { DEFAULT_OFF, "GL_EXT_texture_env" },
70 { DEFAULT_ON, "GL_EXT_texture_env_add" },
71 { ALWAYS_ENABLED, "GL_EXT_texture_object" },
72 { DEFAULT_ON, "GL_EXT_texture_lod_bias" },
73 { ALWAYS_ENABLED, "GL_EXT_vertex_array" },
74 { DEFAULT_OFF, "GL_EXT_vertex_array_set" },
75 { DEFAULT_OFF, "GL_HP_occlusion_test" },
76 { DEFAULT_ON, "GL_INGR_blend_func_separate" },
77 { ALWAYS_ENABLED, "GL_MESA_window_pos" },
78 { ALWAYS_ENABLED, "GL_MESA_resize_buffers" },
79 { ALWAYS_ENABLED, "GL_NV_texgen_reflection" },
80 { DEFAULT_ON, "GL_PGI_misc_hints" },
81 { DEFAULT_ON, "GL_SGI_color_matrix" },
82 { DEFAULT_ON, "GL_SGI_color_table" },
83 { DEFAULT_ON, "GL_SGIS_pixel_texture" },
84 { DEFAULT_ON, "GL_SGIS_texture_edge_clamp" },
85 { DEFAULT_ON, "GL_SGIX_pixel_texture" }
86 };
87
88
89 /*
90 * Update the boolean convenience flags in the Extensions struct.
91 */
92 static void
93 update_extension_flags( GLcontext *ctx )
94 {
95 /* Update flags */
96 ctx->Extensions.HaveTextureEnvAdd = gl_extension_is_enabled(ctx, "GL_EXT_texture_env_add");
97 ctx->Extensions.HaveTextureLodBias = gl_extension_is_enabled(ctx, "GL_EXT_texture_lod_bias");
98 ctx->Extensions.HaveHpOcclusionTest = gl_extension_is_enabled(ctx, "GL_HP_occlusion_test");
99 }
100
101
102
103 int gl_extensions_add( GLcontext *ctx,
104 int state,
105 const char *name,
106 void (*notify)(void) )
107 {
108 (void) notify;
109
110 if (ctx->Extensions.ext_string == 0)
111 {
112 struct extension *t = MALLOC_STRUCT(extension);
113 t->enabled = state;
114 strncpy(t->name, name, MAX_EXT_NAMELEN);
115 t->name[MAX_EXT_NAMELEN] = 0;
116 t->notify = (void (*)(GLcontext *, GLboolean)) notify;
117 insert_at_tail( ctx->Extensions.ext_list, t );
118 return 0;
119 }
120 return 1;
121 }
122
123
124 /*
125 * Either enable or disable the named extension.
126 */
127 static int set_extension( GLcontext *ctx, const char *name, GLint state )
128 {
129 struct extension *i;
130 foreach( i, ctx->Extensions.ext_list )
131 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
132 break;
133
134 if (i == ctx->Extensions.ext_list)
135 return 1;
136
137 if (!(i->enabled & ALWAYS_ENABLED)) {
138 if (i->notify) i->notify( ctx, state );
139 i->enabled = state;
140 }
141
142 update_extension_flags(ctx);
143
144 return 0;
145 }
146
147
148 int gl_extensions_enable( GLcontext *ctx, const char *name )
149 {
150 if (ctx->Extensions.ext_string == 0)
151 return set_extension( ctx, name, 1 );
152 return 1;
153 }
154
155
156 int gl_extensions_disable( GLcontext *ctx, const char *name )
157 {
158 if (ctx->Extensions.ext_string == 0)
159 return set_extension( ctx, name, 0 );
160 return 1;
161 }
162
163
164 /*
165 * Test if the named extension is enabled in this context.
166 */
167 GLboolean gl_extension_is_enabled( GLcontext *ctx, const char *name)
168 {
169 struct extension *i;
170 foreach( i, ctx->Extensions.ext_list )
171 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
172 if (i->enabled)
173 return GL_TRUE;
174 else
175 return GL_FALSE;
176 }
177
178 return GL_FALSE;
179 }
180
181
182 void gl_extensions_dtr( GLcontext *ctx )
183 {
184 struct extension *i, *nexti;
185
186 if (ctx->Extensions.ext_string) {
187 FREE( ctx->Extensions.ext_string );
188 ctx->Extensions.ext_string = 0;
189 }
190
191 if (ctx->Extensions.ext_list) {
192 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
193 remove_from_list( i );
194 FREE( i );
195 }
196
197 FREE(ctx->Extensions.ext_list);
198 ctx->Extensions.ext_list = 0;
199 }
200 }
201
202
203 void gl_extensions_ctr( GLcontext *ctx )
204 {
205 GLuint i;
206
207 ctx->Extensions.ext_string = 0;
208 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
209 make_empty_list( ctx->Extensions.ext_list );
210
211 for (i = 0 ; i < Elements(default_extensions) ; i++) {
212 gl_extensions_add( ctx,
213 default_extensions[i].enabled,
214 default_extensions[i].name,
215 0 );
216 }
217 update_extension_flags(ctx);
218 }
219
220
221 const char *gl_extensions_get_string( GLcontext *ctx )
222 {
223 if (ctx->Extensions.ext_string == 0)
224 {
225 struct extension *i;
226 char *str;
227 GLuint len = 0;
228 foreach (i, ctx->Extensions.ext_list)
229 if (i->enabled)
230 len += strlen(i->name) + 1;
231
232 if (len == 0)
233 return "";
234
235 str = (char *)MALLOC(len * sizeof(char));
236 ctx->Extensions.ext_string = str;
237
238 foreach (i, ctx->Extensions.ext_list)
239 if (i->enabled) {
240 strcpy(str, i->name);
241 str += strlen(str);
242 *str++ = ' ';
243 }
244
245 *(str-1) = 0;
246 }
247
248 return ctx->Extensions.ext_string;
249 }