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