Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
||
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
||
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
22 | * OTHER DEALINGS IN THE SOFTWARE. |
||
23 | */ |
||
24 | |||
25 | |||
26 | #include "imports.h" |
||
27 | #include "mtypes.h" |
||
28 | #include "version.h" |
||
29 | #include "git_sha1.h" |
||
30 | |||
31 | /** |
||
32 | * Scans 'string' to see if it ends with 'ending'. |
||
33 | */ |
||
34 | static GLboolean |
||
35 | check_for_ending(const char *string, const char *ending) |
||
36 | { |
||
37 | int len1, len2; |
||
38 | |||
39 | len1 = strlen(string); |
||
40 | len2 = strlen(ending); |
||
41 | |||
42 | if (len2 > len1) { |
||
43 | return GL_FALSE; |
||
44 | } |
||
45 | |||
46 | if (strcmp(string + (len1 - len2), ending) == 0) { |
||
47 | return GL_TRUE; |
||
48 | } else { |
||
49 | return GL_FALSE; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Returns the gl override data |
||
55 | * |
||
56 | * version > 0 indicates there is an override requested |
||
57 | * fwd_context is only valid if version > 0 |
||
58 | */ |
||
59 | static void |
||
60 | get_gl_override(int *version, GLboolean *fwd_context) |
||
61 | { |
||
62 | const char *env_var = "MESA_GL_VERSION_OVERRIDE"; |
||
63 | const char *version_str; |
||
64 | int major, minor, n; |
||
65 | static int override_version = -1; |
||
66 | static GLboolean fc_suffix = GL_FALSE; |
||
67 | |||
68 | if (override_version < 0) { |
||
69 | override_version = 0; |
||
70 | |||
71 | version_str = getenv(env_var); |
||
72 | if (version_str) { |
||
73 | fc_suffix = check_for_ending(version_str, "FC"); |
||
74 | |||
75 | n = sscanf(version_str, "%u.%u", &major, &minor); |
||
76 | if (n != 2) { |
||
77 | fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version_str); |
||
78 | override_version = 0; |
||
79 | } else { |
||
80 | override_version = major * 10 + minor; |
||
81 | if (override_version < 30 && fc_suffix) { |
||
82 | fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version_str); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | *version = override_version; |
||
89 | *fwd_context = fc_suffix; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Builds the MESA version string. |
||
94 | */ |
||
95 | static void |
||
96 | create_version_string(struct gl_context *ctx, const char *prefix) |
||
97 | { |
||
98 | static const int max = 100; |
||
99 | |||
100 | ctx->VersionString = malloc(max); |
||
101 | if (ctx->VersionString) { |
||
102 | _mesa_snprintf(ctx->VersionString, max, |
||
103 | "%s%u.%u%s Mesa " PACKAGE_VERSION |
||
104 | #ifdef MESA_GIT_SHA1 |
||
105 | " (" MESA_GIT_SHA1 ")" |
||
106 | #endif |
||
107 | , |
||
108 | prefix, |
||
109 | ctx->Version / 10, ctx->Version % 10, |
||
110 | (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" : "" |
||
111 | ); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Override the context's version and/or API type if the |
||
117 | * environment variable MESA_GL_VERSION_OVERRIDE is set. |
||
118 | * |
||
119 | * Example uses of MESA_GL_VERSION_OVERRIDE: |
||
120 | * |
||
121 | * 2.1: select a compatibility (non-Core) profile with GL version 2.1 |
||
122 | * 3.0: select a compatibility (non-Core) profile with GL version 3.0 |
||
123 | * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0 |
||
124 | * 3.1: select a Core profile with GL version 3.1 |
||
125 | * 3.1FC: select a Core+Forward Compatible profile with GL version 3.1 |
||
126 | */ |
||
127 | void |
||
128 | _mesa_override_gl_version(struct gl_context *ctx) |
||
129 | { |
||
130 | int version; |
||
131 | GLboolean fwd_context; |
||
132 | |||
133 | get_gl_override(&version, &fwd_context); |
||
134 | |||
135 | if (version > 0) { |
||
136 | ctx->Version = version; |
||
137 | if (version >= 30 && fwd_context) { |
||
138 | ctx->API = API_OPENGL_CORE; |
||
139 | ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT; |
||
140 | } else if (version >= 31) { |
||
141 | ctx->API = API_OPENGL_CORE; |
||
142 | } else { |
||
143 | ctx->API = API_OPENGL_COMPAT; |
||
144 | } |
||
145 | create_version_string(ctx, ""); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Returns the gl override value |
||
151 | * |
||
152 | * version > 0 indicates there is an override requested |
||
153 | */ |
||
154 | int |
||
155 | _mesa_get_gl_version_override(void) |
||
156 | { |
||
157 | int version; |
||
158 | GLboolean fwd_context; |
||
159 | |||
160 | get_gl_override(&version, &fwd_context); |
||
161 | |||
162 | return version; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Override the context's GLSL version if the environment variable |
||
167 | * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for |
||
168 | * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130". |
||
169 | */ |
||
170 | void |
||
171 | _mesa_override_glsl_version(struct gl_context *ctx) |
||
172 | { |
||
173 | const char *env_var = "MESA_GLSL_VERSION_OVERRIDE"; |
||
174 | const char *version; |
||
175 | int n; |
||
176 | |||
177 | version = getenv(env_var); |
||
178 | if (!version) { |
||
179 | return; |
||
180 | } |
||
181 | |||
182 | n = sscanf(version, "%u", &ctx->Const.GLSLVersion); |
||
183 | if (n != 1) { |
||
184 | fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version); |
||
185 | return; |
||
186 | } |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Examine enabled GL extensions to determine GL version. |
||
191 | */ |
||
192 | static void |
||
193 | compute_version(struct gl_context *ctx) |
||
194 | { |
||
195 | GLuint major, minor; |
||
196 | |||
197 | const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp && |
||
198 | ctx->Extensions.ARB_texture_cube_map && |
||
199 | ctx->Extensions.ARB_texture_env_combine && |
||
200 | ctx->Extensions.ARB_texture_env_dot3); |
||
201 | const GLboolean ver_1_4 = (ver_1_3 && |
||
202 | ctx->Extensions.ARB_depth_texture && |
||
203 | ctx->Extensions.ARB_shadow && |
||
204 | ctx->Extensions.ARB_texture_env_crossbar && |
||
205 | ctx->Extensions.EXT_blend_color && |
||
206 | ctx->Extensions.EXT_blend_func_separate && |
||
207 | ctx->Extensions.EXT_blend_minmax && |
||
208 | ctx->Extensions.EXT_point_parameters); |
||
209 | const GLboolean ver_1_5 = (ver_1_4 && |
||
210 | ctx->Extensions.ARB_occlusion_query); |
||
211 | const GLboolean ver_2_0 = (ver_1_5 && |
||
212 | ctx->Extensions.ARB_point_sprite && |
||
213 | ctx->Extensions.ARB_vertex_shader && |
||
214 | ctx->Extensions.ARB_fragment_shader && |
||
215 | ctx->Extensions.ARB_texture_non_power_of_two && |
||
216 | ctx->Extensions.EXT_blend_equation_separate && |
||
217 | |||
218 | /* Technically, 2.0 requires the functionality |
||
219 | * of the EXT version. Enable 2.0 if either |
||
220 | * extension is available, and assume that a |
||
221 | * driver that only exposes the ATI extension |
||
222 | * will fallback to software when necessary. |
||
223 | */ |
||
224 | (ctx->Extensions.EXT_stencil_two_side |
||
225 | || ctx->Extensions.ATI_separate_stencil)); |
||
226 | const GLboolean ver_2_1 = (ver_2_0 && |
||
227 | ctx->Const.GLSLVersion >= 120 && |
||
228 | ctx->Extensions.EXT_pixel_buffer_object && |
||
229 | ctx->Extensions.EXT_texture_sRGB); |
||
230 | const GLboolean ver_3_0 = (ver_2_1 && |
||
231 | ctx->Const.GLSLVersion >= 130 && |
||
232 | ctx->Const.MaxSamples >= 4 && |
||
233 | (ctx->API == API_OPENGL_CORE || |
||
234 | ctx->Extensions.ARB_color_buffer_float) && |
||
235 | ctx->Extensions.ARB_depth_buffer_float && |
||
236 | ctx->Extensions.ARB_half_float_pixel && |
||
237 | ctx->Extensions.ARB_half_float_vertex && |
||
238 | ctx->Extensions.ARB_map_buffer_range && |
||
239 | ctx->Extensions.ARB_shader_texture_lod && |
||
240 | ctx->Extensions.ARB_texture_float && |
||
241 | ctx->Extensions.ARB_texture_rg && |
||
242 | ctx->Extensions.ARB_texture_compression_rgtc && |
||
243 | ctx->Extensions.EXT_draw_buffers2 && |
||
244 | ctx->Extensions.ARB_framebuffer_object && |
||
245 | ctx->Extensions.EXT_framebuffer_sRGB && |
||
246 | ctx->Extensions.EXT_packed_float && |
||
247 | ctx->Extensions.EXT_texture_array && |
||
248 | ctx->Extensions.EXT_texture_shared_exponent && |
||
249 | ctx->Extensions.EXT_transform_feedback && |
||
250 | ctx->Extensions.NV_conditional_render); |
||
251 | const GLboolean ver_3_1 = (ver_3_0 && |
||
252 | ctx->Const.GLSLVersion >= 140 && |
||
253 | ctx->Extensions.ARB_draw_instanced && |
||
254 | ctx->Extensions.ARB_texture_buffer_object && |
||
255 | ctx->Extensions.ARB_uniform_buffer_object && |
||
256 | ctx->Extensions.EXT_texture_snorm && |
||
257 | ctx->Extensions.NV_primitive_restart && |
||
258 | ctx->Extensions.NV_texture_rectangle && |
||
259 | ctx->Const.VertexProgram.MaxTextureImageUnits >= 16); |
||
260 | const GLboolean ver_3_2 = (ver_3_1 && |
||
261 | ctx->Const.GLSLVersion >= 150 && |
||
262 | ctx->Extensions.ARB_depth_clamp && |
||
263 | ctx->Extensions.ARB_draw_elements_base_vertex && |
||
264 | ctx->Extensions.ARB_fragment_coord_conventions && |
||
265 | ctx->Extensions.ARB_geometry_shader4 && |
||
266 | ctx->Extensions.EXT_provoking_vertex && |
||
267 | ctx->Extensions.ARB_seamless_cube_map && |
||
268 | ctx->Extensions.ARB_sync && |
||
269 | ctx->Extensions.ARB_texture_multisample && |
||
270 | ctx->Extensions.EXT_vertex_array_bgra); |
||
271 | const GLboolean ver_3_3 = (ver_3_2 && |
||
272 | ctx->Const.GLSLVersion >= 330 && |
||
273 | ctx->Extensions.ARB_blend_func_extended && |
||
274 | ctx->Extensions.ARB_explicit_attrib_location && |
||
275 | ctx->Extensions.ARB_instanced_arrays && |
||
276 | ctx->Extensions.ARB_occlusion_query2 && |
||
277 | ctx->Extensions.ARB_shader_bit_encoding && |
||
278 | ctx->Extensions.ARB_texture_rgb10_a2ui && |
||
279 | ctx->Extensions.ARB_timer_query && |
||
280 | ctx->Extensions.ARB_vertex_type_2_10_10_10_rev && |
||
281 | ctx->Extensions.EXT_texture_swizzle); |
||
282 | /* ARB_sampler_objects is always enabled in mesa */ |
||
283 | |||
284 | if (ver_3_3) { |
||
285 | major = 3; |
||
286 | minor = 3; |
||
287 | } |
||
288 | else if (ver_3_2) { |
||
289 | major = 3; |
||
290 | minor = 2; |
||
291 | } |
||
292 | else if (ver_3_1) { |
||
293 | major = 3; |
||
294 | minor = 1; |
||
295 | } |
||
296 | else if (ver_3_0) { |
||
297 | major = 3; |
||
298 | minor = 0; |
||
299 | } |
||
300 | else if (ver_2_1) { |
||
301 | major = 2; |
||
302 | minor = 1; |
||
303 | } |
||
304 | else if (ver_2_0) { |
||
305 | major = 2; |
||
306 | minor = 0; |
||
307 | } |
||
308 | else if (ver_1_5) { |
||
309 | major = 1; |
||
310 | minor = 5; |
||
311 | } |
||
312 | else if (ver_1_4) { |
||
313 | major = 1; |
||
314 | minor = 4; |
||
315 | } |
||
316 | else if (ver_1_3) { |
||
317 | major = 1; |
||
318 | minor = 3; |
||
319 | } |
||
320 | else { |
||
321 | major = 1; |
||
322 | minor = 2; |
||
323 | } |
||
324 | |||
325 | ctx->Version = major * 10 + minor; |
||
326 | |||
327 | create_version_string(ctx, ""); |
||
328 | } |
||
329 | |||
330 | static void |
||
331 | compute_version_es1(struct gl_context *ctx) |
||
332 | { |
||
333 | /* OpenGL ES 1.0 is derived from OpenGL 1.3 */ |
||
334 | const GLboolean ver_1_0 = (ctx->Extensions.ARB_texture_env_combine && |
||
335 | ctx->Extensions.ARB_texture_env_dot3); |
||
336 | /* OpenGL ES 1.1 is derived from OpenGL 1.5 */ |
||
337 | const GLboolean ver_1_1 = (ver_1_0 && |
||
338 | ctx->Extensions.EXT_point_parameters); |
||
339 | |||
340 | if (ver_1_1) { |
||
341 | ctx->Version = 11; |
||
342 | } else if (ver_1_0) { |
||
343 | ctx->Version = 10; |
||
344 | } else { |
||
345 | _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support."); |
||
346 | } |
||
347 | |||
348 | create_version_string(ctx, "OpenGL ES-CM "); |
||
349 | } |
||
350 | |||
351 | static void |
||
352 | compute_version_es2(struct gl_context *ctx) |
||
353 | { |
||
354 | /* OpenGL ES 2.0 is derived from OpenGL 2.0 */ |
||
355 | const GLboolean ver_2_0 = (ctx->Extensions.ARB_texture_cube_map && |
||
356 | ctx->Extensions.EXT_blend_color && |
||
357 | ctx->Extensions.EXT_blend_func_separate && |
||
358 | ctx->Extensions.EXT_blend_minmax && |
||
359 | ctx->Extensions.ARB_vertex_shader && |
||
360 | ctx->Extensions.ARB_fragment_shader && |
||
361 | ctx->Extensions.ARB_texture_non_power_of_two && |
||
362 | ctx->Extensions.EXT_blend_equation_separate); |
||
363 | /* FINISHME: This list isn't quite right. */ |
||
364 | const GLboolean ver_3_0 = (ctx->Extensions.ARB_half_float_vertex && |
||
365 | ctx->Extensions.ARB_internalformat_query && |
||
366 | ctx->Extensions.ARB_map_buffer_range && |
||
367 | ctx->Extensions.ARB_shader_texture_lod && |
||
368 | ctx->Extensions.ARB_texture_float && |
||
369 | ctx->Extensions.ARB_texture_rg && |
||
370 | ctx->Extensions.ARB_texture_compression_rgtc && |
||
371 | ctx->Extensions.EXT_draw_buffers2 && |
||
372 | /* ctx->Extensions.ARB_framebuffer_object && */ |
||
373 | ctx->Extensions.EXT_framebuffer_sRGB && |
||
374 | ctx->Extensions.EXT_packed_float && |
||
375 | ctx->Extensions.EXT_texture_array && |
||
376 | ctx->Extensions.EXT_texture_shared_exponent && |
||
377 | ctx->Extensions.EXT_transform_feedback && |
||
378 | ctx->Extensions.NV_conditional_render && |
||
379 | ctx->Extensions.ARB_draw_instanced && |
||
380 | ctx->Extensions.ARB_uniform_buffer_object && |
||
381 | ctx->Extensions.EXT_texture_snorm && |
||
382 | ctx->Extensions.NV_primitive_restart && |
||
383 | ctx->Extensions.OES_depth_texture_cube_map); |
||
384 | if (ver_3_0) { |
||
385 | ctx->Version = 30; |
||
386 | } else if (ver_2_0) { |
||
387 | ctx->Version = 20; |
||
388 | } else { |
||
389 | _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support."); |
||
390 | } |
||
391 | |||
392 | create_version_string(ctx, "OpenGL ES "); |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * Set the context's Version and VersionString fields. |
||
397 | * This should only be called once as part of context initialization |
||
398 | * or to perform version check for GLX_ARB_create_context_profile. |
||
399 | */ |
||
400 | void |
||
401 | _mesa_compute_version(struct gl_context *ctx) |
||
402 | { |
||
403 | if (ctx->Version) |
||
404 | return; |
||
405 | |||
406 | switch (ctx->API) { |
||
407 | case API_OPENGL_COMPAT: |
||
408 | /* Disable GLSL 1.40 and later for legacy contexts. |
||
409 | * This disallows creation of the GL 3.1 compatibility context. */ |
||
410 | if (ctx->Const.GLSLVersion > 130) { |
||
411 | ctx->Const.GLSLVersion = 130; |
||
412 | } |
||
413 | /* fall through */ |
||
414 | case API_OPENGL_CORE: |
||
415 | compute_version(ctx); |
||
416 | break; |
||
417 | case API_OPENGLES: |
||
418 | compute_version_es1(ctx); |
||
419 | break; |
||
420 | case API_OPENGLES2: |
||
421 | compute_version_es2(ctx); |
||
422 | break; |
||
423 | } |
||
424 | |||
425 | }>> |