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