695eed4623123a9a18a40a2024d1a68f6e142330
[reactos.git] / reactos / dll / opengl / mesa / src / mesa / main / version.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010 VMware, Inc. 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 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 #include "imports.h"
26 #include "mtypes.h"
27 #include "version.h"
28 #include "git_sha1.h"
29
30 /**
31 * Override the context's GL version if the environment variable
32 * MESA_GL_VERSION_OVERRIDE is set. Valid values of MESA_GL_VERSION_OVERRIDE
33 * are point-separated version numbers, such as "3.0".
34 */
35 static void
36 override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
37 {
38 const char *env_var = "MESA_GL_VERSION_OVERRIDE";
39 const char *version;
40 int n;
41
42 version = getenv(env_var);
43 if (!version) {
44 return;
45 }
46
47 n = sscanf(version, "%u.%u", major, minor);
48 if (n != 2) {
49 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
50 return;
51 }
52 }
53
54 /**
55 * Override the context's GLSL version if the environment variable
56 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
57 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
58 */
59 void
60 _mesa_override_glsl_version(struct gl_context *ctx)
61 {
62 const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
63 const char *version;
64 int n;
65
66 version = getenv(env_var);
67 if (!version) {
68 return;
69 }
70
71 n = sscanf(version, "%u", &ctx->Const.GLSLVersion);
72 if (n != 1) {
73 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
74 return;
75 }
76 }
77
78 /**
79 * Examine enabled GL extensions to determine GL version.
80 * Return major and minor version numbers.
81 */
82 static void
83 compute_version(struct gl_context *ctx)
84 {
85 GLuint major, minor;
86 static const int max = 100;
87
88 const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp &&
89 ctx->Extensions.ARB_texture_cube_map &&
90 ctx->Extensions.ARB_texture_env_combine &&
91 ctx->Extensions.ARB_texture_env_dot3);
92 const GLboolean ver_1_4 = (ver_1_3 &&
93 ctx->Extensions.ARB_depth_texture &&
94 ctx->Extensions.ARB_shadow &&
95 ctx->Extensions.ARB_texture_env_crossbar &&
96 ctx->Extensions.ARB_window_pos &&
97 ctx->Extensions.EXT_blend_color &&
98 ctx->Extensions.EXT_blend_func_separate &&
99 ctx->Extensions.EXT_blend_minmax &&
100 ctx->Extensions.EXT_fog_coord &&
101 ctx->Extensions.EXT_point_parameters &&
102 ctx->Extensions.EXT_secondary_color);
103 const GLboolean ver_1_5 = (ver_1_4 &&
104 ctx->Extensions.ARB_occlusion_query &&
105 ctx->Extensions.EXT_shadow_funcs);
106 const GLboolean ver_2_0 = (ver_1_5 &&
107 ctx->Extensions.ARB_point_sprite &&
108 ctx->Extensions.ARB_shader_objects &&
109 ctx->Extensions.ARB_vertex_shader &&
110 ctx->Extensions.ARB_fragment_shader &&
111 ctx->Extensions.ARB_texture_non_power_of_two &&
112 ctx->Extensions.EXT_blend_equation_separate &&
113
114 /* Technically, 2.0 requires the functionality
115 * of the EXT version. Enable 2.0 if either
116 * extension is available, and assume that a
117 * driver that only exposes the ATI extension
118 * will fallback to software when necessary.
119 */
120 (ctx->Extensions.EXT_stencil_two_side
121 || ctx->Extensions.ATI_separate_stencil));
122 const GLboolean ver_2_1 = (ver_2_0 &&
123 ctx->Const.GLSLVersion >= 120 &&
124 ctx->Extensions.EXT_pixel_buffer_object &&
125 ctx->Extensions.EXT_texture_sRGB);
126 const GLboolean ver_3_0 = (ver_2_1 &&
127 ctx->Const.GLSLVersion >= 130 &&
128 ctx->Const.MaxSamples >= 4 &&
129 ctx->Extensions.ARB_color_buffer_float &&
130 ctx->Extensions.ARB_depth_buffer_float &&
131 ctx->Extensions.ARB_half_float_pixel &&
132 ctx->Extensions.ARB_half_float_vertex &&
133 ctx->Extensions.ARB_map_buffer_range &&
134 ctx->Extensions.ARB_shader_texture_lod &&
135 ctx->Extensions.ARB_texture_float &&
136 ctx->Extensions.ARB_texture_rg &&
137 ctx->Extensions.ARB_texture_compression_rgtc &&
138 ctx->Extensions.APPLE_vertex_array_object &&
139 ctx->Extensions.EXT_draw_buffers2 &&
140 ctx->Extensions.ARB_framebuffer_object &&
141 ctx->Extensions.EXT_framebuffer_sRGB &&
142 ctx->Extensions.EXT_texture_array &&
143 ctx->Extensions.EXT_transform_feedback &&
144 ctx->Extensions.NV_conditional_render);
145 const GLboolean ver_3_1 = (ver_3_0 &&
146 ctx->Const.GLSLVersion >= 140 &&
147 ctx->Extensions.ARB_copy_buffer &&
148 ctx->Extensions.ARB_draw_instanced &&
149 ctx->Extensions.ARB_texture_buffer_object &&
150 ctx->Extensions.ARB_uniform_buffer_object &&
151 ctx->Extensions.EXT_texture_snorm &&
152 ctx->Extensions.NV_primitive_restart &&
153 ctx->Extensions.NV_texture_rectangle &&
154 ctx->Const.MaxVertexTextureImageUnits >= 16);
155 const GLboolean ver_3_2 = (ver_3_1 &&
156 ctx->Const.GLSLVersion >= 150 &&
157 ctx->Extensions.ARB_depth_clamp &&
158 ctx->Extensions.ARB_draw_elements_base_vertex &&
159 ctx->Extensions.ARB_fragment_coord_conventions &&
160 ctx->Extensions.ARB_geometry_shader4 &&
161 ctx->Extensions.EXT_provoking_vertex &&
162 ctx->Extensions.ARB_seamless_cube_map &&
163 ctx->Extensions.ARB_sync &&
164 ctx->Extensions.ARB_texture_multisample &&
165 ctx->Extensions.EXT_vertex_array_bgra);
166 const GLboolean ver_3_3 = (ver_3_2 &&
167 ctx->Const.GLSLVersion >= 330 &&
168 ctx->Extensions.ARB_blend_func_extended &&
169 ctx->Extensions.ARB_explicit_attrib_location &&
170 ctx->Extensions.ARB_instanced_arrays &&
171 ctx->Extensions.ARB_occlusion_query2 &&
172 ctx->Extensions.ARB_sampler_objects &&
173 ctx->Extensions.ARB_texture_rgb10_a2ui &&
174 ctx->Extensions.ARB_timer_query);
175
176 if (ver_3_3) {
177 major = 3;
178 minor = 3;
179 }
180 else if (ver_3_2) {
181 major = 3;
182 minor = 2;
183 }
184 else if (ver_3_1) {
185 major = 3;
186 minor = 1;
187 }
188 else if (ver_3_0) {
189 major = 3;
190 minor = 0;
191 }
192 else if (ver_2_1) {
193 major = 2;
194 minor = 1;
195 }
196 else if (ver_2_0) {
197 major = 2;
198 minor = 0;
199 }
200 else if (ver_1_5) {
201 major = 1;
202 minor = 5;
203 }
204 else if (ver_1_4) {
205 major = 1;
206 minor = 4;
207 }
208 else if (ver_1_3) {
209 major = 1;
210 minor = 3;
211 }
212 else {
213 major = 1;
214 minor = 2;
215 }
216
217 ctx->VersionMajor = major;
218 ctx->VersionMinor = minor;
219
220 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
221
222 ctx->VersionString = (char *) malloc(max);
223 if (ctx->VersionString) {
224 _mesa_snprintf(ctx->VersionString, max,
225 "%u.%u Mesa " MESA_VERSION_STRING
226 #ifdef MESA_GIT_SHA1
227 " (" MESA_GIT_SHA1 ")"
228 #endif
229 ,
230 ctx->VersionMajor, ctx->VersionMinor);
231 }
232 }
233
234 static void
235 compute_version_es1(struct gl_context *ctx)
236 {
237 static const int max = 100;
238
239 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
240 const GLboolean ver_1_0 = (ctx->Extensions.ARB_texture_env_combine &&
241 ctx->Extensions.ARB_texture_env_dot3);
242 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
243 const GLboolean ver_1_1 = (ver_1_0 &&
244 ctx->Extensions.EXT_point_parameters);
245
246 if (ver_1_1) {
247 ctx->VersionMajor = 1;
248 ctx->VersionMinor = 1;
249 } else if (ver_1_0) {
250 ctx->VersionMajor = 1;
251 ctx->VersionMinor = 0;
252 } else {
253 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
254 }
255
256 ctx->VersionString = (char *) malloc(max);
257 if (ctx->VersionString) {
258 _mesa_snprintf(ctx->VersionString, max,
259 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING,
260 ctx->VersionMinor);
261 }
262 }
263
264 static void
265 compute_version_es2(struct gl_context *ctx)
266 {
267 static const int max = 100;
268
269 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
270 const GLboolean ver_2_0 = (ctx->Extensions.ARB_texture_cube_map &&
271 ctx->Extensions.EXT_blend_color &&
272 ctx->Extensions.EXT_blend_func_separate &&
273 ctx->Extensions.EXT_blend_minmax &&
274 ctx->Extensions.ARB_shader_objects &&
275 ctx->Extensions.ARB_vertex_shader &&
276 ctx->Extensions.ARB_fragment_shader &&
277 ctx->Extensions.ARB_texture_non_power_of_two &&
278 ctx->Extensions.EXT_blend_equation_separate);
279 if (ver_2_0) {
280 ctx->VersionMajor = 2;
281 ctx->VersionMinor = 0;
282 } else {
283 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
284 }
285
286 ctx->VersionString = (char *) malloc(max);
287 if (ctx->VersionString) {
288 _mesa_snprintf(ctx->VersionString, max,
289 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING);
290 }
291 }
292
293 /**
294 * Set the context's VersionMajor, VersionMinor, VersionString fields.
295 * This should only be called once as part of context initialization
296 * or to perform version check for GLX_ARB_create_context_profile.
297 */
298 void
299 _mesa_compute_version(struct gl_context *ctx)
300 {
301 if (ctx->VersionMajor)
302 return;
303
304 switch (ctx->API) {
305 case API_OPENGL:
306 compute_version(ctx);
307 break;
308 case API_OPENGLES:
309 compute_version_es1(ctx);
310 break;
311 case API_OPENGLES2:
312 compute_version_es2(ctx);
313 break;
314 }
315
316 }