24fecb837fd4fbe78493a4f7346bd57245c35e51
[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 size_t
36 append_extension(char **str, const char *ext)
37 {
38 char *s = *str;
39 size_t len = strlen(ext);
40
41 if (s) {
42 memcpy(s, ext, len);
43 s[len++] = ' ';
44 s[len] = '\0';
45
46 *str += len;
47 }
48 else {
49 len++;
50 }
51
52 return len;
53 }
54
55
56 static size_t
57 make_extension_string(const GLcontext *ctx, char *str)
58 {
59 size_t len = 0;
60
61 len += append_extension(&str, "GL_OES_compressed_paletted_texture");
62
63 if (ctx->Extensions.ARB_framebuffer_object) {
64 len += append_extension(&str, "GL_OES_depth24");
65 len += append_extension(&str, "GL_OES_depth32");
66 len += append_extension(&str, "GL_OES_fbo_render_mipmap");
67 len += append_extension(&str, "GL_OES_rgb8_rgba8");
68 len += append_extension(&str, "GL_OES_stencil1");
69 len += append_extension(&str, "GL_OES_stencil4");
70 }
71
72 if (ctx->Extensions.EXT_vertex_array)
73 len += append_extension(&str, "GL_OES_element_index_uint");
74 if (ctx->Extensions.ARB_vertex_buffer_object)
75 len += append_extension(&str, "GL_OES_mapbuffer");
76
77 if (ctx->Extensions.EXT_texture3D)
78 len += append_extension(&str, "GL_OES_texture_3D");
79 if (ctx->Extensions.ARB_texture_non_power_of_two)
80 len += append_extension(&str, "GL_OES_texture_npot");
81 if (ctx->Extensions.EXT_texture_filter_anisotropic)
82 len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
83
84 len += append_extension(&str, "GL_EXT_texture_type_2_10_10_10_REV");
85 if (ctx->Extensions.ARB_depth_texture)
86 len += append_extension(&str, "GL_OES_depth_texture");
87 if (ctx->Extensions.EXT_packed_depth_stencil)
88 len += append_extension(&str, "GL_OES_packed_depth_stencil");
89 if (ctx->Extensions.ARB_fragment_shader)
90 len += append_extension(&str, "GL_OES_standard_derivatives");
91
92 if (ctx->Extensions.EXT_texture_compression_s3tc)
93 len += append_extension(&str, "GL_EXT_texture_compression_dxt1");
94 if (ctx->Extensions.EXT_blend_minmax)
95 len += append_extension(&str, "GL_EXT_blend_minmax");
96 if (ctx->Extensions.EXT_multi_draw_arrays)
97 len += append_extension(&str, "GL_EXT_multi_draw_arrays");
98
99 #if FEATURE_OES_EGL_image
100 if (ctx->Extensions.OES_EGL_image)
101 len += append_extension(&str, "GL_OES_EGL_image");
102 #endif
103
104 return len;
105 }
106
107
108 static const GLubyte *
109 compute_es_extensions(void)
110 {
111 GET_CURRENT_CONTEXT(ctx);
112
113 if (!ctx->Extensions.String) {
114 char *s;
115 unsigned int len;
116
117 len = make_extension_string(ctx, NULL);
118 s = (char *) malloc(len + 1);
119 if (!s)
120 return NULL;
121 make_extension_string(ctx, s);
122 ctx->Extensions.String = (const GLubyte *) s;
123 }
124
125 return ctx->Extensions.String;
126 }
127
128 const GLubyte * GLAPIENTRY
129 _es_GetString(GLenum name)
130 {
131 switch (name) {
132 case GL_SHADING_LANGUAGE_VERSION:
133 return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16";
134 case GL_EXTENSIONS:
135 return compute_es_extensions();
136 default:
137 return _mesa_GetString(name);
138 }
139 }