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