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 <stdio.h>
27 #include "context.h"
28
29 #include "mtypes.h"
30 #include "version.h"
31 #include "git_sha1.h"
32
33 /**
34 * Scans 'string' to see if it ends with 'ending'.
35 */
36 static bool
check_for_ending(const char * string,const char * ending)37 check_for_ending(const char *string, const char *ending)
38 {
39 const size_t len1 = strlen(string);
40 const size_t len2 = strlen(ending);
41
42 if (len2 > len1)
43 return false;
44
45 return strcmp(string + (len1 - len2), ending) == 0;
46 }
47
48 /**
49 * Returns the gl override data
50 *
51 * version > 0 indicates there is an override requested
52 * fwd_context is only valid if version > 0
53 */
54 static void
get_gl_override(gl_api api,int * version,bool * fwd_context,bool * compat_context)55 get_gl_override(gl_api api, int *version, bool *fwd_context,
56 bool *compat_context)
57 {
58 const char *env_var = (api == API_OPENGL_CORE || api == API_OPENGL_COMPAT)
59 ? "MESA_GL_VERSION_OVERRIDE" : "MESA_GLES_VERSION_OVERRIDE";
60 const char *version_str;
61 int major, minor, n;
62 static struct override_info {
63 int version;
64 bool fc_suffix;
65 bool compat_suffix;
66 } override[] = {
67 [API_OPENGL_COMPAT] = { -1, false, false},
68 [API_OPENGLES] = { -1, false, false},
69 [API_OPENGLES2] = { -1, false, false},
70 [API_OPENGL_CORE] = { -1, false, false},
71 };
72
73 STATIC_ASSERT(ARRAY_SIZE(override) == API_OPENGL_LAST + 1);
74
75 if (api == API_OPENGLES)
76 goto exit;
77
78 if (override[api].version < 0) {
79 override[api].version = 0;
80
81 version_str = getenv(env_var);
82 if (version_str) {
83 override[api].fc_suffix = check_for_ending(version_str, "FC");
84 override[api].compat_suffix = check_for_ending(version_str, "COMPAT");
85
86 n = sscanf(version_str, "%u.%u", &major, &minor);
87 if (n != 2) {
88 fprintf(stderr, "error: invalid value for %s: %s\n",
89 env_var, version_str);
90 override[api].version = 0;
91 } else {
92 override[api].version = major * 10 + minor;
93
94 /* There is no such thing as compatibility or forward-compatible for
95 * OpenGL ES 2.0 or 3.x APIs.
96 */
97 if ((override[api].version < 30 && override[api].fc_suffix) ||
98 (api == API_OPENGLES2 && (override[api].fc_suffix ||
99 override[api].compat_suffix))) {
100 fprintf(stderr, "error: invalid value for %s: %s\n",
101 env_var, version_str);
102 }
103 }
104 }
105 }
106
107 exit:
108 *version = override[api].version;
109 *fwd_context = override[api].fc_suffix;
110 *compat_context = override[api].compat_suffix;
111 }
112
113 /**
114 * Builds the Mesa version string.
115 */
116 static void
create_version_string(struct gl_context * ctx,const char * prefix)117 create_version_string(struct gl_context *ctx, const char *prefix)
118 {
119 static const int max = 100;
120
121 ctx->VersionString = malloc(max);
122 if (ctx->VersionString) {
123 snprintf(ctx->VersionString, max,
124 "%s%u.%u%s Mesa " PACKAGE_VERSION MESA_GIT_SHA1,
125 prefix,
126 ctx->Version / 10, ctx->Version % 10,
127 (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" :
128 (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 32) ?
129 " (Compatibility Profile)" : ""
130 );
131 }
132 }
133
134 /**
135 * Override the context's version and/or API type if the environment variables
136 * MESA_GL_VERSION_OVERRIDE or MESA_GLES_VERSION_OVERRIDE are set.
137 *
138 * Example uses of MESA_GL_VERSION_OVERRIDE:
139 *
140 * 2.1: select a compatibility (non-Core) profile with GL version 2.1.
141 * 3.0: select a compatibility (non-Core) profile with GL version 3.0.
142 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0.
143 * 3.1: select GL version 3.1 with GL_ARB_compatibility enabled per the driver default.
144 * 3.1FC: select GL version 3.1 with forward compatibility and GL_ARB_compatibility disabled.
145 * 3.1COMPAT: select GL version 3.1 with GL_ARB_compatibility enabled.
146 * X.Y: override GL version to X.Y without changing the profile.
147 * X.YFC: select a Core+Forward Compatible profile with GL version X.Y.
148 * X.YCOMPAT: select a Compatibility profile with GL version X.Y.
149 *
150 * Example uses of MESA_GLES_VERSION_OVERRIDE:
151 *
152 * 2.0: select GLES version 2.0.
153 * 3.0: select GLES version 3.0.
154 * 3.1: select GLES version 3.1.
155 */
156 bool
_mesa_override_gl_version_contextless(struct gl_constants * consts,gl_api * apiOut,GLuint * versionOut)157 _mesa_override_gl_version_contextless(struct gl_constants *consts,
158 gl_api *apiOut, GLuint *versionOut)
159 {
160 int version;
161 bool fwd_context, compat_context;
162
163 get_gl_override(*apiOut, &version, &fwd_context, &compat_context);
164
165 if (version > 0) {
166 *versionOut = version;
167
168 /* Modify the API and context flags as needed. */
169 if (*apiOut == API_OPENGL_CORE || *apiOut == API_OPENGL_COMPAT) {
170 if (version >= 30 && fwd_context) {
171 *apiOut = API_OPENGL_CORE;
172 consts->ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
173 } else if (compat_context) {
174 *apiOut = API_OPENGL_COMPAT;
175 }
176 }
177
178 return true;
179 }
180 return false;
181 }
182
183 void
_mesa_override_gl_version(struct gl_context * ctx)184 _mesa_override_gl_version(struct gl_context *ctx)
185 {
186 if (_mesa_override_gl_version_contextless(&ctx->Const, &ctx->API,
187 &ctx->Version)) {
188 /* We need to include API in version string for OpenGL ES, otherwise
189 * application can not detect GLES via glGetString(GL_VERSION) query.
190 *
191 * From OpenGL ES 3.2 spec, Page 436:
192 *
193 * "The VERSION string is laid out as follows:
194 *
195 * OpenGL ES N.M vendor-specific information"
196 *
197 * From OpenGL 4.5 spec, Page 538:
198 *
199 * "The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as
200 * follows:
201 *
202 * <version number><space><vendor-specific information>"
203 */
204 create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : "");
205 ctx->Extensions.Version = ctx->Version;
206 }
207 }
208
209 /**
210 * Override the context's GLSL version if the environment variable
211 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
212 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
213 */
214 void
_mesa_override_glsl_version(struct gl_constants * consts)215 _mesa_override_glsl_version(struct gl_constants *consts)
216 {
217 const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
218 const char *version;
219 int n;
220
221 version = getenv(env_var);
222 if (!version) {
223 return;
224 }
225
226 n = sscanf(version, "%u", &consts->GLSLVersion);
227 if (n != 1) {
228 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
229 return;
230 }
231 }
232
233 /**
234 * Examine enabled GL extensions to determine GL version.
235 */
236 static GLuint
compute_version(const struct gl_extensions * extensions,const struct gl_constants * consts,gl_api api)237 compute_version(const struct gl_extensions *extensions,
238 const struct gl_constants *consts, gl_api api)
239 {
240 GLuint major, minor, version;
241
242 const bool ver_1_3 = (extensions->ARB_texture_border_clamp &&
243 extensions->ARB_texture_cube_map &&
244 extensions->ARB_texture_env_combine &&
245 extensions->ARB_texture_env_dot3);
246 const bool ver_1_4 = (ver_1_3 &&
247 extensions->ARB_depth_texture &&
248 extensions->ARB_shadow &&
249 extensions->ARB_texture_env_crossbar &&
250 extensions->EXT_blend_color &&
251 extensions->EXT_blend_func_separate &&
252 extensions->EXT_blend_minmax &&
253 extensions->EXT_point_parameters);
254 const bool ver_1_5 = (ver_1_4 &&
255 extensions->ARB_occlusion_query);
256 const bool ver_2_0 = (ver_1_5 &&
257 extensions->ARB_point_sprite &&
258 extensions->ARB_vertex_shader &&
259 extensions->ARB_fragment_shader &&
260 extensions->ARB_texture_non_power_of_two &&
261 extensions->EXT_blend_equation_separate &&
262 extensions->EXT_stencil_two_side);
263 const bool ver_2_1 = (ver_2_0 &&
264 extensions->EXT_pixel_buffer_object &&
265 extensions->EXT_texture_sRGB);
266 const bool ver_3_0 = (ver_2_1 &&
267 consts->GLSLVersion >= 130 &&
268 (consts->MaxSamples >= 4 || consts->FakeSWMSAA) &&
269 (api == API_OPENGL_CORE ||
270 extensions->ARB_color_buffer_float) &&
271 extensions->ARB_depth_buffer_float &&
272 extensions->ARB_half_float_vertex &&
273 extensions->ARB_map_buffer_range &&
274 extensions->ARB_shader_texture_lod &&
275 extensions->ARB_texture_float &&
276 extensions->ARB_texture_rg &&
277 extensions->ARB_texture_compression_rgtc &&
278 extensions->EXT_draw_buffers2 &&
279 extensions->ARB_framebuffer_object &&
280 extensions->EXT_framebuffer_sRGB &&
281 extensions->EXT_packed_float &&
282 extensions->EXT_texture_array &&
283 extensions->EXT_texture_shared_exponent &&
284 extensions->EXT_transform_feedback &&
285 extensions->NV_conditional_render);
286 const bool ver_3_1 = (ver_3_0 &&
287 consts->GLSLVersion >= 140 &&
288 extensions->ARB_draw_instanced &&
289 extensions->ARB_texture_buffer_object &&
290 extensions->ARB_uniform_buffer_object &&
291 extensions->EXT_texture_snorm &&
292 extensions->NV_primitive_restart &&
293 extensions->NV_texture_rectangle &&
294 consts->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits >= 16);
295 const bool ver_3_2 = (ver_3_1 &&
296 consts->GLSLVersion >= 150 &&
297 extensions->ARB_depth_clamp &&
298 extensions->ARB_draw_elements_base_vertex &&
299 extensions->ARB_fragment_coord_conventions &&
300 extensions->EXT_provoking_vertex &&
301 extensions->ARB_seamless_cube_map &&
302 extensions->ARB_sync &&
303 extensions->ARB_texture_multisample &&
304 extensions->EXT_vertex_array_bgra);
305 const bool ver_3_3 = (ver_3_2 &&
306 consts->GLSLVersion >= 330 &&
307 extensions->ARB_blend_func_extended &&
308 extensions->ARB_explicit_attrib_location &&
309 extensions->ARB_instanced_arrays &&
310 extensions->ARB_occlusion_query2 &&
311 extensions->ARB_shader_bit_encoding &&
312 extensions->ARB_texture_rgb10_a2ui &&
313 extensions->ARB_timer_query &&
314 extensions->ARB_vertex_type_2_10_10_10_rev &&
315 extensions->EXT_texture_swizzle);
316 /* ARB_sampler_objects is always enabled in mesa */
317
318 const bool ver_4_0 = (ver_3_3 &&
319 consts->GLSLVersion >= 400 &&
320 extensions->ARB_draw_buffers_blend &&
321 extensions->ARB_draw_indirect &&
322 extensions->ARB_gpu_shader5 &&
323 extensions->ARB_gpu_shader_fp64 &&
324 extensions->ARB_sample_shading &&
325 extensions->ARB_tessellation_shader &&
326 extensions->ARB_texture_buffer_object_rgb32 &&
327 extensions->ARB_texture_cube_map_array &&
328 extensions->ARB_texture_query_lod &&
329 extensions->ARB_transform_feedback2 &&
330 extensions->ARB_transform_feedback3);
331 const bool ver_4_1 = (ver_4_0 &&
332 consts->GLSLVersion >= 410 &&
333 consts->MaxTextureSize >= 16384 &&
334 consts->MaxRenderbufferSize >= 16384 &&
335 extensions->ARB_ES2_compatibility &&
336 extensions->ARB_shader_precision &&
337 extensions->ARB_vertex_attrib_64bit &&
338 extensions->ARB_viewport_array);
339 const bool ver_4_2 = (ver_4_1 &&
340 consts->GLSLVersion >= 420 &&
341 extensions->ARB_base_instance &&
342 extensions->ARB_conservative_depth &&
343 extensions->ARB_internalformat_query &&
344 extensions->ARB_shader_atomic_counters &&
345 extensions->ARB_shader_image_load_store &&
346 extensions->ARB_shading_language_420pack &&
347 extensions->ARB_shading_language_packing &&
348 extensions->ARB_texture_compression_bptc &&
349 extensions->ARB_transform_feedback_instanced);
350 const bool ver_4_3 = (ver_4_2 &&
351 consts->GLSLVersion >= 430 &&
352 consts->Program[MESA_SHADER_VERTEX].MaxUniformBlocks >= 14 &&
353 extensions->ARB_ES3_compatibility &&
354 extensions->ARB_arrays_of_arrays &&
355 extensions->ARB_compute_shader &&
356 extensions->ARB_copy_image &&
357 extensions->ARB_explicit_uniform_location &&
358 extensions->ARB_fragment_layer_viewport &&
359 extensions->ARB_framebuffer_no_attachments &&
360 extensions->ARB_internalformat_query2 &&
361 extensions->ARB_robust_buffer_access_behavior &&
362 extensions->ARB_shader_image_size &&
363 extensions->ARB_shader_storage_buffer_object &&
364 extensions->ARB_stencil_texturing &&
365 extensions->ARB_texture_buffer_range &&
366 extensions->ARB_texture_query_levels &&
367 extensions->ARB_texture_view);
368 const bool ver_4_4 = (ver_4_3 &&
369 consts->GLSLVersion >= 440 &&
370 consts->MaxVertexAttribStride >= 2048 &&
371 extensions->ARB_buffer_storage &&
372 extensions->ARB_clear_texture &&
373 extensions->ARB_enhanced_layouts &&
374 extensions->ARB_query_buffer_object &&
375 extensions->ARB_texture_mirror_clamp_to_edge &&
376 extensions->ARB_texture_stencil8 &&
377 extensions->ARB_vertex_type_10f_11f_11f_rev);
378 const bool ver_4_5 = (ver_4_4 &&
379 consts->GLSLVersion >= 450 &&
380 extensions->ARB_ES3_1_compatibility &&
381 extensions->ARB_clip_control &&
382 extensions->ARB_conditional_render_inverted &&
383 extensions->ARB_cull_distance &&
384 extensions->ARB_derivative_control &&
385 extensions->ARB_shader_texture_image_samples &&
386 extensions->NV_texture_barrier);
387 const bool ver_4_6 = (ver_4_5 &&
388 consts->GLSLVersion >= 460 &&
389 extensions->ARB_gl_spirv &&
390 extensions->ARB_spirv_extensions &&
391 extensions->ARB_indirect_parameters &&
392 extensions->ARB_pipeline_statistics_query &&
393 extensions->ARB_polygon_offset_clamp &&
394 extensions->ARB_shader_atomic_counter_ops &&
395 extensions->ARB_shader_draw_parameters &&
396 extensions->ARB_shader_group_vote &&
397 extensions->ARB_texture_filter_anisotropic &&
398 extensions->ARB_transform_feedback_overflow_query);
399
400 if (ver_4_6) {
401 major = 4;
402 minor = 6;
403 }
404 else if (ver_4_5) {
405 major = 4;
406 minor = 5;
407 }
408 else if (ver_4_4) {
409 major = 4;
410 minor = 4;
411 }
412 else if (ver_4_3) {
413 major = 4;
414 minor = 3;
415 }
416 else if (ver_4_2) {
417 major = 4;
418 minor = 2;
419 }
420 else if (ver_4_1) {
421 major = 4;
422 minor = 1;
423 }
424 else if (ver_4_0) {
425 major = 4;
426 minor = 0;
427 }
428 else if (ver_3_3) {
429 major = 3;
430 minor = 3;
431 }
432 else if (ver_3_2) {
433 major = 3;
434 minor = 2;
435 }
436 else if (ver_3_1) {
437 major = 3;
438 minor = 1;
439 }
440 else if (ver_3_0) {
441 major = 3;
442 minor = 0;
443 }
444 else if (ver_2_1) {
445 major = 2;
446 minor = 1;
447 }
448 else if (ver_2_0) {
449 major = 2;
450 minor = 0;
451 }
452 else if (ver_1_5) {
453 major = 1;
454 minor = 5;
455 }
456 else if (ver_1_4) {
457 major = 1;
458 minor = 4;
459 }
460 else if (ver_1_3) {
461 major = 1;
462 minor = 3;
463 }
464 else {
465 major = 1;
466 minor = 2;
467 }
468
469 version = major * 10 + minor;
470
471 if (api == API_OPENGL_CORE && version < 31)
472 return 0;
473
474 return version;
475 }
476
477 static GLuint
compute_version_es1(const struct gl_extensions * extensions)478 compute_version_es1(const struct gl_extensions *extensions)
479 {
480 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
481 const bool ver_1_0 = (extensions->ARB_texture_env_combine &&
482 extensions->ARB_texture_env_dot3);
483 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
484 const bool ver_1_1 = (ver_1_0 &&
485 extensions->EXT_point_parameters);
486
487 if (ver_1_1) {
488 return 11;
489 } else if (ver_1_0) {
490 return 10;
491 } else {
492 return 0;
493 }
494 }
495
496 static GLuint
compute_version_es2(const struct gl_extensions * extensions,const struct gl_constants * consts)497 compute_version_es2(const struct gl_extensions *extensions,
498 const struct gl_constants *consts)
499 {
500 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
501 const bool ver_2_0 = (extensions->ARB_texture_cube_map &&
502 extensions->EXT_blend_color &&
503 extensions->EXT_blend_func_separate &&
504 extensions->EXT_blend_minmax &&
505 extensions->ARB_vertex_shader &&
506 extensions->ARB_fragment_shader &&
507 extensions->ARB_texture_non_power_of_two &&
508 extensions->EXT_blend_equation_separate);
509 /* FINISHME: This list isn't quite right. */
510 const bool ver_3_0 = (extensions->ARB_half_float_vertex &&
511 extensions->ARB_internalformat_query &&
512 extensions->ARB_map_buffer_range &&
513 extensions->ARB_shader_texture_lod &&
514 extensions->OES_texture_float &&
515 extensions->OES_texture_half_float &&
516 extensions->OES_texture_half_float_linear &&
517 extensions->ARB_texture_rg &&
518 extensions->ARB_depth_buffer_float &&
519 extensions->ARB_framebuffer_object &&
520 extensions->EXT_sRGB &&
521 extensions->EXT_packed_float &&
522 extensions->EXT_texture_array &&
523 extensions->EXT_texture_shared_exponent &&
524 extensions->EXT_texture_sRGB &&
525 extensions->EXT_transform_feedback &&
526 extensions->ARB_draw_instanced &&
527 extensions->ARB_uniform_buffer_object &&
528 extensions->EXT_texture_snorm &&
529 (extensions->NV_primitive_restart ||
530 consts->PrimitiveRestartFixedIndex) &&
531 extensions->OES_depth_texture_cube_map &&
532 extensions->EXT_texture_type_2_10_10_10_REV);
533 const bool es31_compute_shader =
534 consts->MaxComputeWorkGroupInvocations >= 128;
535 const bool ver_3_1 = (ver_3_0 &&
536 consts->MaxVertexAttribStride >= 2048 &&
537 extensions->ARB_arrays_of_arrays &&
538 es31_compute_shader &&
539 extensions->ARB_draw_indirect &&
540 extensions->ARB_explicit_uniform_location &&
541 extensions->ARB_framebuffer_no_attachments &&
542 extensions->ARB_shader_atomic_counters &&
543 extensions->ARB_shader_image_load_store &&
544 extensions->ARB_shader_image_size &&
545 extensions->ARB_shader_storage_buffer_object &&
546 extensions->ARB_shading_language_packing &&
547 extensions->ARB_stencil_texturing &&
548 extensions->ARB_texture_multisample &&
549 extensions->ARB_texture_gather &&
550 extensions->MESA_shader_integer_functions &&
551 extensions->EXT_shader_integer_mix);
552 const bool ver_3_2 = (ver_3_1 &&
553 extensions->EXT_draw_buffers2 &&
554 extensions->KHR_blend_equation_advanced &&
555 extensions->KHR_robustness &&
556 extensions->KHR_texture_compression_astc_ldr &&
557 extensions->OES_copy_image &&
558 extensions->ARB_draw_buffers_blend &&
559 extensions->ARB_draw_elements_base_vertex &&
560 extensions->OES_geometry_shader &&
561 extensions->OES_primitive_bounding_box &&
562 extensions->OES_sample_variables &&
563 extensions->ARB_tessellation_shader &&
564 extensions->ARB_texture_border_clamp &&
565 extensions->OES_texture_buffer &&
566 extensions->OES_texture_cube_map_array &&
567 extensions->ARB_texture_stencil8);
568
569 if (ver_3_2) {
570 return 32;
571 } else if (ver_3_1) {
572 return 31;
573 } else if (ver_3_0) {
574 return 30;
575 } else if (ver_2_0) {
576 return 20;
577 } else {
578 return 0;
579 }
580 }
581
582 GLuint
_mesa_get_version(const struct gl_extensions * extensions,struct gl_constants * consts,gl_api api)583 _mesa_get_version(const struct gl_extensions *extensions,
584 struct gl_constants *consts, gl_api api)
585 {
586 switch (api) {
587 case API_OPENGL_COMPAT:
588 /* Disable higher GLSL versions for legacy contexts.
589 * This disallows creation of higher compatibility contexts. */
590 if (!consts->AllowHigherCompatVersion) {
591 consts->GLSLVersion = consts->GLSLVersionCompat;
592 }
593 /* fall through */
594 case API_OPENGL_CORE:
595 return compute_version(extensions, consts, api);
596 case API_OPENGLES:
597 return compute_version_es1(extensions);
598 case API_OPENGLES2:
599 return compute_version_es2(extensions, consts);
600 }
601 return 0;
602 }
603
604 /**
605 * Set the context's Version and VersionString fields.
606 * This should only be called once as part of context initialization
607 * or to perform version check for GLX_ARB_create_context_profile.
608 */
609 void
_mesa_compute_version(struct gl_context * ctx)610 _mesa_compute_version(struct gl_context *ctx)
611 {
612 if (ctx->Version)
613 goto done;
614
615 ctx->Version = _mesa_get_version(&ctx->Extensions, &ctx->Const, ctx->API);
616 ctx->Extensions.Version = ctx->Version;
617
618 /* Make sure that the GLSL version lines up with the GL version. In some
619 * cases it can be too high, e.g. if an extension is missing.
620 */
621 if (_mesa_is_desktop_gl(ctx)) {
622 switch (ctx->Version) {
623 case 20:
624 /* fall-through, GLSL 1.20 is the minimum we support */
625 case 21:
626 ctx->Const.GLSLVersion = 120;
627 break;
628 case 30:
629 ctx->Const.GLSLVersion = 130;
630 break;
631 case 31:
632 ctx->Const.GLSLVersion = 140;
633 break;
634 case 32:
635 ctx->Const.GLSLVersion = 150;
636 break;
637 default:
638 if (ctx->Version >= 33)
639 ctx->Const.GLSLVersion = ctx->Version * 10;
640 break;
641 }
642 }
643
644 switch (ctx->API) {
645 case API_OPENGL_COMPAT:
646 case API_OPENGL_CORE:
647 create_version_string(ctx, "");
648 break;
649
650 case API_OPENGLES:
651 if (!ctx->Version) {
652 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
653 return;
654 }
655 create_version_string(ctx, "OpenGL ES-CM ");
656 break;
657
658 case API_OPENGLES2:
659 if (!ctx->Version) {
660 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
661 return;
662 }
663 create_version_string(ctx, "OpenGL ES ");
664 break;
665 }
666
667 done:
668 if (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 31)
669 ctx->Extensions.ARB_compatibility = GL_TRUE;
670 }
671
672
673 void
_mesa_get_driver_uuid(struct gl_context * ctx,GLint * uuid)674 _mesa_get_driver_uuid(struct gl_context *ctx, GLint *uuid)
675 {
676 ctx->Driver.GetDriverUuid(ctx, (char*) uuid);
677 }
678
679 void
_mesa_get_device_uuid(struct gl_context * ctx,GLint * uuid)680 _mesa_get_device_uuid(struct gl_context *ctx, GLint *uuid)
681 {
682 ctx->Driver.GetDeviceUuid(ctx, (char*) uuid);
683 }
684
685 /**
686 * Get the i-th GLSL version string. If index=0, return the most recent
687 * supported version.
688 * \param ctx context to query
689 * \param index which version string to return, or -1 if none
690 * \param versionOut returns the vesrion string
691 * \return total number of shading language versions.
692 */
693 int
_mesa_get_shading_language_version(const struct gl_context * ctx,int index,char ** versionOut)694 _mesa_get_shading_language_version(const struct gl_context *ctx,
695 int index,
696 char **versionOut)
697 {
698 int n = 0;
699
700 #define GLSL_VERSION(S) \
701 if (n++ == index) \
702 *versionOut = S
703
704 /* GLSL core */
705 if (ctx->Const.GLSLVersion >= 460)
706 GLSL_VERSION("460");
707 if (ctx->Const.GLSLVersion >= 450)
708 GLSL_VERSION("450");
709 if (ctx->Const.GLSLVersion >= 440)
710 GLSL_VERSION("440");
711 if (ctx->Const.GLSLVersion >= 430)
712 GLSL_VERSION("430");
713 if (ctx->Const.GLSLVersion >= 420)
714 GLSL_VERSION("420");
715 if (ctx->Const.GLSLVersion >= 410)
716 GLSL_VERSION("410");
717 if (ctx->Const.GLSLVersion >= 400)
718 GLSL_VERSION("400");
719 if (ctx->Const.GLSLVersion >= 330)
720 GLSL_VERSION("330");
721 if (ctx->Const.GLSLVersion >= 150)
722 GLSL_VERSION("150");
723 if (ctx->Const.GLSLVersion >= 140)
724 GLSL_VERSION("140");
725 if (ctx->Const.GLSLVersion >= 130)
726 GLSL_VERSION("130");
727 if (ctx->Const.GLSLVersion >= 120)
728 GLSL_VERSION("120");
729 /* The GL spec says to return the empty string for GLSL 1.10 */
730 if (ctx->Const.GLSLVersion >= 110)
731 GLSL_VERSION("");
732
733 /* GLSL es */
734 if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
735 ctx->Extensions.ARB_ES3_2_compatibility)
736 GLSL_VERSION("320 es");
737 if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
738 GLSL_VERSION("310 es");
739 if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
740 GLSL_VERSION("300 es");
741 if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
742 GLSL_VERSION("100");
743
744 #undef GLSL_VERSION
745
746 return n;
747 }
748