ef8c5816187fd472750aee69318d17d3b76b9bf0
[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 /* Core additions */
90 len += append_extension(&str, "GL_OES_single_precision");
91
92 /* Required extensions */
93 len += append_extension(&str, "GL_OES_compressed_paletted_texture");
94
95 if (ctx->Extensions.ARB_framebuffer_object) {
96 len += append_extension(&str, "GL_OES_framebuffer_object");
97 len += append_extension(&str, "GL_OES_depth24");
98 len += append_extension(&str, "GL_OES_depth32");
99 len += append_extension(&str, "GL_OES_fbo_render_mipmap");
100 len += append_extension(&str, "GL_OES_rgb8_rgba8");
101 len += append_extension(&str, "GL_OES_stencil1");
102 len += append_extension(&str, "GL_OES_stencil4");
103 len += append_extension(&str, "GL_OES_stencil8");
104 }
105
106 if (ctx->Extensions.EXT_vertex_array)
107 len += append_extension(&str, "GL_OES_element_index_uint");
108 if (ctx->Extensions.ARB_vertex_buffer_object)
109 len += append_extension(&str, "GL_OES_mapbuffer");
110
111 if (ctx->Extensions.EXT_texture3D)
112 len += append_extension(&str, "GL_OES_texture_3D");
113 if (ctx->Extensions.ARB_texture_non_power_of_two)
114 len += append_extension(&str, "GL_OES_texture_npot");
115 if (ctx->Extensions.EXT_texture_filter_anisotropic)
116 len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
117
118 len += append_extension(&str, "GL_EXT_texture_type_2_10_10_10_REV");
119 if (ctx->Extensions.ARB_depth_texture)
120 len += append_extension(&str, "GL_OES_depth_texture");
121 if (ctx->Extensions.EXT_packed_depth_stencil)
122 len += append_extension(&str, "GL_OES_packed_depth_stencil");
123 if (ctx->Extensions.ARB_fragment_shader)
124 len += append_extension(&str, "GL_OES_standard_derivatives");
125
126 if (ctx->Extensions.EXT_multi_draw_arrays)
127 len += append_extension(&str, "GL_EXT_multi_draw_arrays");
128
129 return len;
130 }
131
132
133 static const GLubyte *
134 compute_es_extensions(void)
135 {
136 GET_CURRENT_CONTEXT(ctx);
137
138 if (!ctx->Extensions.String) {
139 char *s;
140 unsigned int len;
141
142 len = make_extension_string(ctx, NULL);
143 s = (char *) _mesa_malloc(len + 1);
144 if (!s)
145 return NULL;
146 make_extension_string(ctx, s);
147 ctx->Extensions.String = (const GLubyte *) s;
148 }
149
150 return ctx->Extensions.String;
151 }
152
153 const GLubyte * GLAPIENTRY
154 _es_GetString(GLenum name)
155 {
156 switch (name) {
157 case GL_VERSION:
158 return compute_es_version();
159 case GL_SHADING_LANGUAGE_VERSION:
160 return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16";
161 case GL_EXTENSIONS:
162 return compute_es_extensions();
163 default:
164 return _mesa_GetString(name);
165 }
166 }
167
168
169 void
170 _mesa_initialize_context_extra(GLcontext *ctx)
171 {
172 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
173 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
174
175 ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */
176 }