Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / es / main / specials_es1.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * TUNGSTEN GRAPHICS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 **************************************************************************/
24
25
26 #include "main/mtypes.h"
27 #include "main/context.h"
28 #include "main/imports.h"
29 #include "main/get.h"
30
31
32 extern const GLubyte * GLAPIENTRY _es_GetString(GLenum name);
33
34
35 static const GLubyte *
36 compute_es_version(void)
37 {
38 GET_CURRENT_CONTEXT(ctx);
39 static const char es_1_0[] = "OpenGL ES-CM 1.0";
40 static const char es_1_1[] = "OpenGL ES-CM 1.1";
41 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
42 const GLboolean ver_1_0 = (ctx->Extensions.ARB_multisample &&
43 ctx->Extensions.ARB_multitexture &&
44 ctx->Extensions.ARB_texture_compression &&
45 ctx->Extensions.EXT_texture_env_add &&
46 ctx->Extensions.ARB_texture_env_combine &&
47 ctx->Extensions.ARB_texture_env_dot3);
48 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
49 const GLboolean ver_1_1 = (ver_1_0 &&
50 ctx->Extensions.EXT_point_parameters &&
51 ctx->Extensions.SGIS_generate_mipmap &&
52 ctx->Extensions.ARB_vertex_buffer_object);
53 if (ver_1_1)
54 return (const GLubyte *) es_1_1;
55
56 if (!ver_1_0)
57 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
58 return (const GLubyte *) es_1_0;
59 }
60
61
62 static size_t
63 append_extension(char **str, const char *ext)
64 {
65 char *s = *str;
66 size_t len = strlen(ext);
67
68 if (s) {
69 memcpy(s, ext, len);
70 s[len++] = ' ';
71 s[len] = '\0';
72
73 *str += len;
74 }
75 else {
76 len++;
77 }
78
79 return len;
80 }
81
82
83 static size_t
84 make_extension_string(const GLcontext *ctx, char *str)
85 {
86 size_t len = 0;
87
88 /* Core additions */
89 len += append_extension(&str, "GL_OES_byte_coordinates");
90 len += append_extension(&str, "GL_OES_fixed_point");
91 len += append_extension(&str, "GL_OES_single_precision");
92 len += append_extension(&str, "GL_OES_matrix_get");
93
94 /* 1.1 required extensions */
95 len += append_extension(&str, "GL_OES_read_format");
96 len += append_extension(&str, "GL_OES_compressed_paletted_texture");
97 len += append_extension(&str, "GL_OES_point_size_array");
98 len += append_extension(&str, "GL_OES_point_sprite");
99
100 /* 1.1 deprecated extensions */
101 len += append_extension(&str, "GL_OES_query_matrix");
102
103 #if FEATURE_OES_draw_texture
104 if (ctx->Extensions.OES_draw_texture)
105 len += append_extension(&str, "GL_OES_draw_texture");
106 #endif
107
108 if (ctx->Extensions.EXT_blend_equation_separate)
109 len += append_extension(&str, "GL_OES_blend_equation_separate");
110 if (ctx->Extensions.EXT_blend_func_separate)
111 len += append_extension(&str, "GL_OES_blend_func_separate");
112 if (ctx->Extensions.EXT_blend_subtract)
113 len += append_extension(&str, "GL_OES_blend_subtract");
114
115 if (ctx->Extensions.EXT_stencil_wrap)
116 len += append_extension(&str, "GL_OES_stencil_wrap");
117
118 if (ctx->Extensions.ARB_texture_cube_map)
119 len += append_extension(&str, "GL_OES_texture_cube_map");
120 if (ctx->Extensions.ARB_texture_env_crossbar)
121 len += append_extension(&str, "GL_OES_texture_env_crossbar");
122 if (ctx->Extensions.ARB_texture_mirrored_repeat)
123 len += append_extension(&str, "GL_OES_texture_mirrored_repeat");
124
125 if (ctx->Extensions.ARB_framebuffer_object) {
126 len += append_extension(&str, "GL_OES_framebuffer_object");
127 len += append_extension(&str, "GL_OES_depth24");
128 len += append_extension(&str, "GL_OES_depth32");
129 len += append_extension(&str, "GL_OES_fbo_render_mipmap");
130 len += append_extension(&str, "GL_OES_rgb8_rgba8");
131 len += append_extension(&str, "GL_OES_stencil1");
132 len += append_extension(&str, "GL_OES_stencil4");
133 len += append_extension(&str, "GL_OES_stencil8");
134 }
135
136 if (ctx->Extensions.EXT_vertex_array)
137 len += append_extension(&str, "GL_OES_element_index_uint");
138 if (ctx->Extensions.ARB_vertex_buffer_object)
139 len += append_extension(&str, "GL_OES_mapbuffer");
140 if (ctx->Extensions.EXT_texture_filter_anisotropic)
141 len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
142
143 /* some applications check this for NPOT support */
144 if (ctx->Extensions.ARB_texture_non_power_of_two)
145 len += append_extension(&str, "GL_ARB_texture_non_power_of_two");
146
147 if (ctx->Extensions.EXT_texture_compression_s3tc)
148 len += append_extension(&str, "GL_EXT_texture_compression_dxt1");
149 if (ctx->Extensions.EXT_texture_lod_bias)
150 len += append_extension(&str, "GL_EXT_texture_lod_bias");
151 if (ctx->Extensions.EXT_blend_minmax)
152 len += append_extension(&str, "GL_EXT_blend_minmax");
153 if (ctx->Extensions.EXT_multi_draw_arrays)
154 len += append_extension(&str, "GL_EXT_multi_draw_arrays");
155
156 return len;
157 }
158
159
160 static const GLubyte *
161 compute_es_extensions(void)
162 {
163 GET_CURRENT_CONTEXT(ctx);
164
165 if (!ctx->Extensions.String) {
166 char *s;
167 unsigned int len;
168
169 len = make_extension_string(ctx, NULL);
170 s = (char *) _mesa_malloc(len + 1);
171 if (!s)
172 return NULL;
173 make_extension_string(ctx, s);
174 ctx->Extensions.String = (const GLubyte *) s;
175 }
176
177 return ctx->Extensions.String;
178 }
179
180
181 const GLubyte * GLAPIENTRY
182 _es_GetString(GLenum name)
183 {
184 switch (name) {
185 case GL_VERSION:
186 return compute_es_version();
187 case GL_EXTENSIONS:
188 return compute_es_extensions();
189 default:
190 return _mesa_GetString(name);
191 }
192 }
193
194
195 void
196 _mesa_initialize_context_extra(GLcontext *ctx)
197 {
198 GLuint i;
199
200 /**
201 * GL_OES_texture_cube_map says
202 * "Initially all texture generation modes are set to REFLECTION_MAP_OES"
203 */
204 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
205 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
206 texUnit->GenS.Mode = GL_REFLECTION_MAP_NV;
207 texUnit->GenT.Mode = GL_REFLECTION_MAP_NV;
208 texUnit->GenR.Mode = GL_REFLECTION_MAP_NV;
209 texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV;
210 texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV;
211 texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV;
212 }
213 }