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