Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / es / main / specials_es2.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 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_2_0[] = "OpenGL ES 2.0";
40 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
41 const GLboolean ver_2_0 = (ctx->Extensions.ARB_multisample &&
42 ctx->Extensions.ARB_multitexture &&
43 ctx->Extensions.ARB_texture_compression &&
44 ctx->Extensions.ARB_texture_cube_map &&
45 ctx->Extensions.ARB_texture_mirrored_repeat &&
46 ctx->Extensions.EXT_blend_color &&
47 ctx->Extensions.EXT_blend_func_separate &&
48 ctx->Extensions.EXT_blend_minmax &&
49 ctx->Extensions.EXT_blend_subtract &&
50 ctx->Extensions.EXT_stencil_wrap &&
51 ctx->Extensions.ARB_vertex_buffer_object &&
52 ctx->Extensions.ARB_shader_objects &&
53 ctx->Extensions.ARB_vertex_shader &&
54 ctx->Extensions.ARB_fragment_shader &&
55 ctx->Extensions.ARB_texture_non_power_of_two &&
56 ctx->Extensions.EXT_blend_equation_separate);
57 if (!ver_2_0)
58 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
59 return (const GLubyte *) es_2_0;
60 }
61
62
63 static size_t
64 append_extension(char **str, const char *ext)
65 {
66 char *s = *str;
67 size_t len = strlen(ext);
68
69 if (s) {
70 memcpy(s, ext, len);
71 s[len++] = ' ';
72 s[len] = '\0';
73
74 *str += len;
75 }
76 else {
77 len++;
78 }
79
80 return len;
81 }
82
83
84 static size_t
85 make_extension_string(const GLcontext *ctx, char *str)
86 {
87 size_t len = 0;
88
89 len += append_extension(&str, "GL_OES_compressed_paletted_texture");
90
91 if (ctx->Extensions.ARB_framebuffer_object) {
92 len += append_extension(&str, "GL_OES_depth24");
93 len += append_extension(&str, "GL_OES_depth32");
94 len += append_extension(&str, "GL_OES_fbo_render_mipmap");
95 len += append_extension(&str, "GL_OES_rgb8_rgba8");
96 len += append_extension(&str, "GL_OES_stencil1");
97 len += append_extension(&str, "GL_OES_stencil4");
98 }
99
100 if (ctx->Extensions.EXT_vertex_array)
101 len += append_extension(&str, "GL_OES_element_index_uint");
102 if (ctx->Extensions.ARB_vertex_buffer_object)
103 len += append_extension(&str, "GL_OES_mapbuffer");
104
105 if (ctx->Extensions.EXT_texture3D)
106 len += append_extension(&str, "GL_OES_texture_3D");
107 if (ctx->Extensions.ARB_texture_non_power_of_two)
108 len += append_extension(&str, "GL_OES_texture_npot");
109 if (ctx->Extensions.EXT_texture_filter_anisotropic)
110 len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
111
112 len += append_extension(&str, "GL_EXT_texture_type_2_10_10_10_REV");
113 if (ctx->Extensions.ARB_depth_texture)
114 len += append_extension(&str, "GL_OES_depth_texture");
115 if (ctx->Extensions.EXT_packed_depth_stencil)
116 len += append_extension(&str, "GL_OES_packed_depth_stencil");
117 if (ctx->Extensions.ARB_fragment_shader)
118 len += append_extension(&str, "GL_OES_standard_derivatives");
119
120 if (ctx->Extensions.EXT_texture_compression_s3tc)
121 len += append_extension(&str, "GL_EXT_texture_compression_dxt1");
122 if (ctx->Extensions.EXT_blend_minmax)
123 len += append_extension(&str, "GL_EXT_blend_minmax");
124 if (ctx->Extensions.EXT_multi_draw_arrays)
125 len += append_extension(&str, "GL_EXT_multi_draw_arrays");
126
127 return len;
128 }
129
130
131 static const GLubyte *
132 compute_es_extensions(void)
133 {
134 GET_CURRENT_CONTEXT(ctx);
135
136 if (!ctx->Extensions.String) {
137 char *s;
138 unsigned int len;
139
140 len = make_extension_string(ctx, NULL);
141 s = (char *) _mesa_malloc(len + 1);
142 if (!s)
143 return NULL;
144 make_extension_string(ctx, s);
145 ctx->Extensions.String = (const GLubyte *) s;
146 }
147
148 return ctx->Extensions.String;
149 }
150
151 const GLubyte * GLAPIENTRY
152 _es_GetString(GLenum name)
153 {
154 switch (name) {
155 case GL_VERSION:
156 return compute_es_version();
157 case GL_SHADING_LANGUAGE_VERSION:
158 return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16";
159 case GL_EXTENSIONS:
160 return compute_es_extensions();
161 default:
162 return _mesa_GetString(name);
163 }
164 }
165
166
167 void
168 _mesa_initialize_context_extra(GLcontext *ctx)
169 {
170 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
171 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
172
173 ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */
174 }