fix for GL_COMPILE_AND_EXECUTE bug
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.1
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 <stdlib.h>
29 #include "extensions.h"
30 #include "simple_list.h"
31 #include "types.h"
32
33 #define MAX_EXT_NAMELEN 80
34 #define MALLOC_STRUCT(T) (struct T *) malloc( sizeof(struct T) )
35
36 struct extension {
37 struct extension *next, *prev;
38 int enabled;
39 char name[MAX_EXT_NAMELEN+1];
40 void (*notify)( GLcontext *, GLboolean );
41 };
42
43
44
45 static struct { int enabled; const char *name; } default_extensions[] = {
46 { ALWAYS_ENABLED, "GL_EXT_blend_color" },
47 { ALWAYS_ENABLED, "GL_EXT_blend_minmax" },
48 { ALWAYS_ENABLED, "GL_EXT_blend_logic_op" },
49 { ALWAYS_ENABLED, "GL_EXT_blend_subtract" },
50 { ALWAYS_ENABLED, "GL_EXT_paletted_texture" },
51 { DEFAULT_ON, "GL_EXT_point_parameters" },
52 { ALWAYS_ENABLED, "GL_EXT_polygon_offset" },
53 { ALWAYS_ENABLED, "GL_EXT_vertex_array" },
54 { ALWAYS_ENABLED, "GL_EXT_texture_object" },
55 { DEFAULT_ON, "GL_EXT_texture3D" },
56 { ALWAYS_ENABLED, "GL_MESA_window_pos" },
57 { ALWAYS_ENABLED, "GL_MESA_resize_buffers" },
58 { ALWAYS_ENABLED, "GL_EXT_shared_texture_palette" },
59 { ALWAYS_ENABLED, "GL_EXT_rescale_normal" },
60 { ALWAYS_ENABLED, "GL_EXT_abgr" },
61 { ALWAYS_ENABLED, "GL_SGIS_texture_edge_clamp" },
62 { ALWAYS_ENABLED, "GL_EXT_stencil_wrap" },
63 { ALWAYS_ENABLED, "GL_INGR_blend_func_separate" },
64 { DEFAULT_ON, "GL_ARB_multitexture" },
65 { ALWAYS_ENABLED, "GL_NV_texgen_reflection" },
66 { DEFAULT_ON, "GL_PGI_misc_hints" },
67 { DEFAULT_ON, "GL_EXT_compiled_vertex_array" },
68 { DEFAULT_OFF, "GL_EXT_vertex_array_set" },
69 { DEFAULT_ON, "GL_EXT_clip_volume_hint" },
70 };
71
72
73 int gl_extensions_add( GLcontext *ctx,
74 int state,
75 const char *name,
76 void (*notify)() )
77 {
78 (void) notify;
79
80 if (ctx->Extensions.ext_string == 0)
81 {
82 struct extension *t = MALLOC_STRUCT(extension);
83 t->enabled = state;
84 strncpy(t->name, name, MAX_EXT_NAMELEN);
85 t->name[MAX_EXT_NAMELEN] = 0;
86 t->notify = (void (*)(GLcontext *, GLboolean)) notify;
87 insert_at_tail( ctx->Extensions.ext_list, t );
88 return 0;
89 }
90 return 1;
91 }
92
93
94 static int set_extension( GLcontext *ctx, const char *name, GLuint state )
95 {
96 struct extension *i;
97 foreach( i, ctx->Extensions.ext_list )
98 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
99 break;
100
101 if (i == ctx->Extensions.ext_list) return 1;
102
103 if (i->enabled && !(i->enabled & ALWAYS_ENABLED))
104 {
105 if (i->notify) i->notify( ctx, state );
106 i->enabled = state;
107 }
108
109 return 0;
110 }
111
112
113 int gl_extensions_enable( GLcontext *ctx, const char *name )
114 {
115 if (ctx->Extensions.ext_string == 0)
116 return set_extension( ctx, name, 1 );
117 return 1;
118 }
119
120
121 int gl_extensions_disable( GLcontext *ctx, const char *name )
122 {
123 if (ctx->Extensions.ext_string == 0)
124 return set_extension( ctx, name, 0 );
125 return 1;
126 }
127
128
129 void gl_extensions_dtr( GLcontext *ctx )
130 {
131 struct extension *i, *nexti;
132
133 if (ctx->Extensions.ext_string) {
134 free( ctx->Extensions.ext_string );
135 ctx->Extensions.ext_string = 0;
136 }
137
138 if (ctx->Extensions.ext_list) {
139 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
140 free( i );
141 }
142
143 free(ctx->Extensions.ext_list);
144 ctx->Extensions.ext_list = 0;
145 }
146 }
147
148
149 void gl_extensions_ctr( GLcontext *ctx )
150 {
151 GLuint i;
152
153 ctx->Extensions.ext_string = 0;
154 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
155 make_empty_list( ctx->Extensions.ext_list );
156
157 for (i = 0 ; i < Elements(default_extensions) ; i++) {
158 gl_extensions_add( ctx,
159 default_extensions[i].enabled,
160 default_extensions[i].name,
161 0 );
162 }
163 }
164
165
166 const char *gl_extensions_get_string( GLcontext *ctx )
167 {
168 if (ctx->Extensions.ext_string == 0)
169 {
170 struct extension *i;
171 char *str;
172 GLuint len = 0;
173 foreach (i, ctx->Extensions.ext_list)
174 if (i->enabled)
175 len += strlen(i->name) + 1;
176
177 if (len == 0)
178 return "";
179
180 str = (char *)malloc(len * sizeof(char));
181 ctx->Extensions.ext_string = str;
182
183 foreach (i, ctx->Extensions.ext_list)
184 if (i->enabled) {
185 strcpy(str, i->name);
186 str += strlen(str);
187 *str++ = ' ';
188 }
189
190 *(str-1) = 0;
191 }
192
193 return ctx->Extensions.ext_string;
194 }
195
196