version.c 27.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Mesa 3-D graphics library
 *
 * Copyright (C) 2010  VMware, Inc.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 20 21 22
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * 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
37
check_for_ending(const char *string, const char *ending)
38
{
39 40
   const size_t len1 = strlen(string);
   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 50 51 52 53 54
/**
 * Returns the gl override data
 *
 * version > 0 indicates there is an override requested
 * fwd_context is only valid if version > 0
 */
static void
55 56
get_gl_override(gl_api api, int *version, bool *fwd_context,
                bool *compat_context)
57
{
58 59
   const char *env_var = (api == API_OPENGL_CORE || api == API_OPENGL_COMPAT)
      ? "MESA_GL_VERSION_OVERRIDE" : "MESA_GLES_VERSION_OVERRIDE";
60 61
   const char *version_str;
   int major, minor, n;
62 63 64 65 66
   static struct override_info {
      int version;
      bool fc_suffix;
      bool compat_suffix;
   } override[] = {
67 68 69 70
      [API_OPENGL_COMPAT] = { -1, false, false},
      [API_OPENGLES]      = { -1, false, false},
      [API_OPENGLES2]     = { -1, false, false},
      [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 79
   if (override[api].version < 0) {
      override[api].version = 0;
80 81 82

      version_str = getenv(env_var);
      if (version_str) {
83 84
         override[api].fc_suffix = check_for_ending(version_str, "FC");
         override[api].compat_suffix = check_for_ending(version_str, "COMPAT");
85 86 87

         n = sscanf(version_str, "%u.%u", &major, &minor);
         if (n != 2) {
88 89
            fprintf(stderr, "error: invalid value for %s: %s\n",
                    env_var, version_str);
90
            override[api].version = 0;
91
         } else {
92
            override[api].version = major * 10 + minor;
93 94 95 96

            /* There is no such thing as compatibility or forward-compatible for
             * OpenGL ES 2.0 or 3.x APIs.
             */
97 98 99
            if ((override[api].version < 30 && override[api].fc_suffix) ||
                (api == API_OPENGLES2 && (override[api].fc_suffix ||
                                          override[api].compat_suffix))) {
100 101
               fprintf(stderr, "error: invalid value for %s: %s\n",
                       env_var, version_str);
102 103 104 105 106
            }
         }
      }
   }

107
exit:
108 109 110
   *version = override[api].version;
   *fwd_context = override[api].fc_suffix;
   *compat_context = override[api].compat_suffix;
111 112
}

113
/**
114
 * Builds the Mesa version string.
115
 */
116
static void
117 118 119 120 121 122
create_version_string(struct gl_context *ctx, const char *prefix)
{
   static const int max = 100;

   ctx->VersionString = malloc(max);
   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 128 129
		     (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" :
                     (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 32) ?
                        " (Compatibility Profile)" : ""
130
		     );
131 132 133
   }
}

134
/**
135 136
 * Override the context's version and/or API type if the environment variables
 * MESA_GL_VERSION_OVERRIDE or MESA_GLES_VERSION_OVERRIDE are set.
137 138 139
 *
 * Example uses of MESA_GL_VERSION_OVERRIDE:
 *
140 141 142 143 144 145 146 147 148
 * 2.1: select a compatibility (non-Core) profile with GL version 2.1.
 * 3.0: select a compatibility (non-Core) profile with GL version 3.0.
 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0.
 * 3.1: select GL version 3.1 with GL_ARB_compatibility enabled per the driver default.
 * 3.1FC: select GL version 3.1 with forward compatibility and GL_ARB_compatibility disabled.
 * 3.1COMPAT: select GL version 3.1 with GL_ARB_compatibility enabled.
 * X.Y: override GL version to X.Y without changing the profile.
 * X.YFC: select a Core+Forward Compatible profile with GL version X.Y.
 * X.YCOMPAT: select a Compatibility profile with GL version X.Y.
149 150 151 152 153 154
 *
 * Example uses of MESA_GLES_VERSION_OVERRIDE:
 *
 * 2.0: select GLES version 2.0.
 * 3.0: select GLES version 3.0.
 * 3.1: select GLES version 3.1.
155
 */
156 157 158
bool
_mesa_override_gl_version_contextless(struct gl_constants *consts,
                                      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 170 171 172
      if (*apiOut == API_OPENGL_CORE || *apiOut == API_OPENGL_COMPAT) {
         if (version >= 30 && fwd_context) {
            *apiOut = API_OPENGL_CORE;
            consts->ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
173
         } else if (compat_context) {
174 175
            *apiOut = API_OPENGL_COMPAT;
         }
176
      }
177

178
      return true;
179
   }
180
   return false;
181 182 183 184 185 186 187
}

void
_mesa_override_gl_version(struct gl_context *ctx)
{
   if (_mesa_override_gl_version_contextless(&ctx->Const, &ctx->API,
                                             &ctx->Version)) {
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
      /* We need to include API in version string for OpenGL ES, otherwise
       * application can not detect GLES via glGetString(GL_VERSION) query.
       *
       * From OpenGL ES 3.2 spec, Page 436:
       *
       *     "The VERSION string is laid out as follows:
       *
       *     OpenGL ES N.M vendor-specific information"
       *
       * From OpenGL 4.5 spec, Page 538:
       *
       *     "The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as
       *     follows:
       *
       *     <version number><space><vendor-specific information>"
       */
      create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : "");
205
      ctx->Extensions.Version = ctx->Version;
206 207 208
   }
}

209 210 211 212 213 214
/**
 * Override the context's GLSL version if the environment variable
 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
 */
void
215
_mesa_override_glsl_version(struct gl_constants *consts)
216 217 218 219 220 221 222 223 224 225
{
   const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
   const char *version;
   int n;

   version = getenv(env_var);
   if (!version) {
      return;
   }

226
   n = sscanf(version, "%u", &consts->GLSLVersion);
227 228 229 230 231 232
   if (n != 1) {
      fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
      return;
   }
}

233 234 235
/**
 * Examine enabled GL extensions to determine GL version.
 */
236 237 238
static GLuint
compute_version(const struct gl_extensions *extensions,
                const struct gl_constants *consts, gl_api api)
239
{
240
   GLuint major, minor, version;
241

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
   const bool ver_1_3 = (extensions->ARB_texture_border_clamp &&
                         extensions->ARB_texture_cube_map &&
                         extensions->ARB_texture_env_combine &&
                         extensions->ARB_texture_env_dot3);
   const bool ver_1_4 = (ver_1_3 &&
                         extensions->ARB_depth_texture &&
                         extensions->ARB_shadow &&
                         extensions->ARB_texture_env_crossbar &&
                         extensions->EXT_blend_color &&
                         extensions->EXT_blend_func_separate &&
                         extensions->EXT_blend_minmax &&
                         extensions->EXT_point_parameters);
   const bool ver_1_5 = (ver_1_4 &&
                         extensions->ARB_occlusion_query);
   const bool ver_2_0 = (ver_1_5 &&
                         extensions->ARB_point_sprite &&
                         extensions->ARB_vertex_shader &&
                         extensions->ARB_fragment_shader &&
                         extensions->ARB_texture_non_power_of_two &&
                         extensions->EXT_blend_equation_separate &&
262
                         extensions->EXT_stencil_two_side);
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
   const bool ver_2_1 = (ver_2_0 &&
                         extensions->EXT_pixel_buffer_object &&
                         extensions->EXT_texture_sRGB);
   const bool ver_3_0 = (ver_2_1 &&
                         consts->GLSLVersion >= 130 &&
                         (consts->MaxSamples >= 4 || consts->FakeSWMSAA) &&
                         (api == API_OPENGL_CORE ||
                          extensions->ARB_color_buffer_float) &&
                         extensions->ARB_depth_buffer_float &&
                         extensions->ARB_half_float_vertex &&
                         extensions->ARB_map_buffer_range &&
                         extensions->ARB_shader_texture_lod &&
                         extensions->ARB_texture_float &&
                         extensions->ARB_texture_rg &&
                         extensions->ARB_texture_compression_rgtc &&
                         extensions->EXT_draw_buffers2 &&
                         extensions->ARB_framebuffer_object &&
                         extensions->EXT_framebuffer_sRGB &&
                         extensions->EXT_packed_float &&
                         extensions->EXT_texture_array &&
                         extensions->EXT_texture_shared_exponent &&
                         extensions->EXT_transform_feedback &&
                         extensions->NV_conditional_render);
   const bool ver_3_1 = (ver_3_0 &&
                         consts->GLSLVersion >= 140 &&
                         extensions->ARB_draw_instanced &&
                         extensions->ARB_texture_buffer_object &&
                         extensions->ARB_uniform_buffer_object &&
                         extensions->EXT_texture_snorm &&
                         extensions->NV_primitive_restart &&
                         extensions->NV_texture_rectangle &&
                         consts->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits >= 16);
   const bool ver_3_2 = (ver_3_1 &&
                         consts->GLSLVersion >= 150 &&
                         extensions->ARB_depth_clamp &&
                         extensions->ARB_draw_elements_base_vertex &&
                         extensions->ARB_fragment_coord_conventions &&
                         extensions->EXT_provoking_vertex &&
                         extensions->ARB_seamless_cube_map &&
                         extensions->ARB_sync &&
                         extensions->ARB_texture_multisample &&
                         extensions->EXT_vertex_array_bgra);
   const bool ver_3_3 = (ver_3_2 &&
                         consts->GLSLVersion >= 330 &&
                         extensions->ARB_blend_func_extended &&
                         extensions->ARB_explicit_attrib_location &&
                         extensions->ARB_instanced_arrays &&
                         extensions->ARB_occlusion_query2 &&
                         extensions->ARB_shader_bit_encoding &&
                         extensions->ARB_texture_rgb10_a2ui &&
                         extensions->ARB_timer_query &&
                         extensions->ARB_vertex_type_2_10_10_10_rev &&
                         extensions->EXT_texture_swizzle);
   /* ARB_sampler_objects is always enabled in mesa */

   const bool ver_4_0 = (ver_3_3 &&
                         consts->GLSLVersion >= 400 &&
                         extensions->ARB_draw_buffers_blend &&
                         extensions->ARB_draw_indirect &&
                         extensions->ARB_gpu_shader5 &&
                         extensions->ARB_gpu_shader_fp64 &&
                         extensions->ARB_sample_shading &&
                         extensions->ARB_tessellation_shader &&
                         extensions->ARB_texture_buffer_object_rgb32 &&
                         extensions->ARB_texture_cube_map_array &&
                         extensions->ARB_texture_query_lod &&
                         extensions->ARB_transform_feedback2 &&
                         extensions->ARB_transform_feedback3);
   const bool ver_4_1 = (ver_4_0 &&
                         consts->GLSLVersion >= 410 &&
333 334
                         consts->MaxTextureSize >= 16384 &&
                         consts->MaxRenderbufferSize >= 16384 &&
335 336
                         extensions->ARB_ES2_compatibility &&
                         extensions->ARB_shader_precision &&
337
                         extensions->ARB_vertex_attrib_64bit &&
338 339 340 341 342 343 344 345 346 347 348 349
                         extensions->ARB_viewport_array);
   const bool ver_4_2 = (ver_4_1 &&
                         consts->GLSLVersion >= 420 &&
                         extensions->ARB_base_instance &&
                         extensions->ARB_conservative_depth &&
                         extensions->ARB_internalformat_query &&
                         extensions->ARB_shader_atomic_counters &&
                         extensions->ARB_shader_image_load_store &&
                         extensions->ARB_shading_language_420pack &&
                         extensions->ARB_shading_language_packing &&
                         extensions->ARB_texture_compression_bptc &&
                         extensions->ARB_transform_feedback_instanced);
350 351
   const bool ver_4_3 = (ver_4_2 &&
                         consts->GLSLVersion >= 430 &&
352
                         consts->Program[MESA_SHADER_VERTEX].MaxUniformBlocks >= 14 &&
353 354 355 356 357 358 359 360
                         extensions->ARB_ES3_compatibility &&
                         extensions->ARB_arrays_of_arrays &&
                         extensions->ARB_compute_shader &&
                         extensions->ARB_copy_image &&
                         extensions->ARB_explicit_uniform_location &&
                         extensions->ARB_fragment_layer_viewport &&
                         extensions->ARB_framebuffer_no_attachments &&
                         extensions->ARB_internalformat_query2 &&
361
                         extensions->ARB_robust_buffer_access_behavior &&
362 363 364 365 366 367 368 369
                         extensions->ARB_shader_image_size &&
                         extensions->ARB_shader_storage_buffer_object &&
                         extensions->ARB_stencil_texturing &&
                         extensions->ARB_texture_buffer_range &&
                         extensions->ARB_texture_query_levels &&
                         extensions->ARB_texture_view);
   const bool ver_4_4 = (ver_4_3 &&
                         consts->GLSLVersion >= 440 &&
370
                         consts->MaxVertexAttribStride >= 2048 &&
371 372 373 374 375 376 377 378 379 380 381 382
                         extensions->ARB_buffer_storage &&
                         extensions->ARB_clear_texture &&
                         extensions->ARB_enhanced_layouts &&
                         extensions->ARB_query_buffer_object &&
                         extensions->ARB_texture_mirror_clamp_to_edge &&
                         extensions->ARB_texture_stencil8 &&
                         extensions->ARB_vertex_type_10f_11f_11f_rev);
   const bool ver_4_5 = (ver_4_4 &&
                         consts->GLSLVersion >= 450 &&
                         extensions->ARB_ES3_1_compatibility &&
                         extensions->ARB_clip_control &&
                         extensions->ARB_conditional_render_inverted &&
383
                         extensions->ARB_cull_distance &&
384 385 386
                         extensions->ARB_derivative_control &&
                         extensions->ARB_shader_texture_image_samples &&
                         extensions->NV_texture_barrier);
387 388
   const bool ver_4_6 = (ver_4_5 &&
                         consts->GLSLVersion >= 460 &&
389 390
                         extensions->ARB_gl_spirv &&
                         extensions->ARB_spirv_extensions &&
391 392
                         extensions->ARB_indirect_parameters &&
                         extensions->ARB_pipeline_statistics_query &&
393
                         extensions->ARB_polygon_offset_clamp &&
394 395 396
                         extensions->ARB_shader_atomic_counter_ops &&
                         extensions->ARB_shader_draw_parameters &&
                         extensions->ARB_shader_group_vote &&
397
                         extensions->ARB_texture_filter_anisotropic &&
398
                         extensions->ARB_transform_feedback_overflow_query);
399

400 401 402 403 404
   if (ver_4_6) {
      major = 4;
      minor = 6;
   }
   else if (ver_4_5) {
405 406 407 408 409 410 411 412 413 414 415 416
      major = 4;
      minor = 5;
   }
   else if (ver_4_4) {
      major = 4;
      minor = 4;
   }
   else if (ver_4_3) {
      major = 4;
      minor = 3;
   }
   else if (ver_4_2) {
417 418 419 420 421 422 423 424 425 426 427 428
      major = 4;
      minor = 2;
   }
   else if (ver_4_1) {
      major = 4;
      minor = 1;
   }
   else if (ver_4_0) {
      major = 4;
      minor = 0;
   }
   else if (ver_3_3) {
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
      major = 3;
      minor = 3;
   }
   else if (ver_3_2) {
      major = 3;
      minor = 2;
   }
   else if (ver_3_1) {
      major = 3;
      minor = 1;
   }
   else if (ver_3_0) {
      major = 3;
      minor = 0;
   }
   else if (ver_2_1) {
445 446
      major = 2;
      minor = 1;
447 448
   }
   else if (ver_2_0) {
449 450
      major = 2;
      minor = 0;
451 452
   }
   else if (ver_1_5) {
453 454
      major = 1;
      minor = 5;
455 456
   }
   else if (ver_1_4) {
457 458
      major = 1;
      minor = 4;
459 460
   }
   else if (ver_1_3) {
461 462
      major = 1;
      minor = 3;
463 464
   }
   else {
465 466 467 468
      major = 1;
      minor = 2;
   }

469 470 471 472 473 474
   version = major * 10 + minor;

   if (api == API_OPENGL_CORE && version < 31)
      return 0;

   return version;
475 476
}

477 478
static GLuint
compute_version_es1(const struct gl_extensions *extensions)
479 480
{
   /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
481 482
   const bool ver_1_0 = (extensions->ARB_texture_env_combine &&
                         extensions->ARB_texture_env_dot3);
483
   /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
484 485
   const bool ver_1_1 = (ver_1_0 &&
                         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
497 498
compute_version_es2(const struct gl_extensions *extensions,
                    const struct gl_constants *consts)
499 500
{
   /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
501 502 503 504 505 506 507 508
   const bool ver_2_0 = (extensions->ARB_texture_cube_map &&
                         extensions->EXT_blend_color &&
                         extensions->EXT_blend_func_separate &&
                         extensions->EXT_blend_minmax &&
                         extensions->ARB_vertex_shader &&
                         extensions->ARB_fragment_shader &&
                         extensions->ARB_texture_non_power_of_two &&
                         extensions->EXT_blend_equation_separate);
509
   /* FINISHME: This list isn't quite right. */
510 511 512 513
   const bool ver_3_0 = (extensions->ARB_half_float_vertex &&
                         extensions->ARB_internalformat_query &&
                         extensions->ARB_map_buffer_range &&
                         extensions->ARB_shader_texture_lod &&
514 515 516
                         extensions->OES_texture_float &&
                         extensions->OES_texture_half_float &&
                         extensions->OES_texture_half_float_linear &&
517 518
                         extensions->ARB_texture_rg &&
                         extensions->ARB_depth_buffer_float &&
519 520
                         extensions->ARB_framebuffer_object &&
                         extensions->EXT_sRGB &&
521 522 523
                         extensions->EXT_packed_float &&
                         extensions->EXT_texture_array &&
                         extensions->EXT_texture_shared_exponent &&
524
                         extensions->EXT_texture_sRGB &&
525 526 527 528
                         extensions->EXT_transform_feedback &&
                         extensions->ARB_draw_instanced &&
                         extensions->ARB_uniform_buffer_object &&
                         extensions->EXT_texture_snorm &&
529 530
                         (extensions->NV_primitive_restart ||
                          consts->PrimitiveRestartFixedIndex) &&
531 532
                         extensions->OES_depth_texture_cube_map &&
                         extensions->EXT_texture_type_2_10_10_10_REV);
533 534
   const bool es31_compute_shader =
      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 543
                         extensions->ARB_shader_atomic_counters &&
                         extensions->ARB_shader_image_load_store &&
544 545
                         extensions->ARB_shader_image_size &&
                         extensions->ARB_shader_storage_buffer_object &&
546 547
                         extensions->ARB_shading_language_packing &&
                         extensions->ARB_stencil_texturing &&
548
                         extensions->ARB_texture_multisample &&
549 550
                         extensions->ARB_texture_gather &&
                         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 557 558 559 560
                         extensions->KHR_texture_compression_astc_ldr &&
                         extensions->OES_copy_image &&
                         extensions->ARB_draw_buffers_blend &&
                         extensions->ARB_draw_elements_base_vertex &&
                         extensions->OES_geometry_shader &&
561
                         extensions->OES_primitive_bounding_box &&
562 563 564 565
                         extensions->OES_sample_variables &&
                         extensions->ARB_tessellation_shader &&
                         extensions->ARB_texture_border_clamp &&
                         extensions->OES_texture_buffer &&
566
                         extensions->OES_texture_cube_map_array &&
567
                         extensions->ARB_texture_stencil8);
568

569 570 571
   if (ver_3_2) {
      return 32;
   } else if (ver_3_1) {
572 573
      return 31;
   } 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 583 584 585 586 587
GLuint
_mesa_get_version(const struct gl_extensions *extensions,
                  struct gl_constants *consts, gl_api api)
{
   switch (api) {
   case API_OPENGL_COMPAT:
588 589
      /* Disable higher GLSL versions for legacy contexts.
       * This disallows creation of higher compatibility contexts. */
590
      if (!consts->AllowHigherCompatVersion) {
591
         consts->GLSLVersion = consts->GLSLVersionCompat;
592 593 594 595 596 597 598
      }
      /* fall through */
   case API_OPENGL_CORE:
      return compute_version(extensions, consts, api);
   case API_OPENGLES:
      return compute_version_es1(extensions);
   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 607
 * This should only be called once as part of context initialization
 * or to perform version check for GLX_ARB_create_context_profile.
608 609
 */
void
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 619 620
   /* Make sure that the GLSL version lines up with the GL version. In some
    * cases it can be too high, e.g. if an extension is missing.
    */
621
   if (_mesa_is_desktop_gl(ctx)) {
622
      switch (ctx->Version) {
623 624
      case 20:
         /* fall-through, GLSL 1.20 is the minimum we support */
625 626 627
      case 21:
         ctx->Const.GLSLVersion = 120;
         break;
628 629 630
      case 30:
         ctx->Const.GLSLVersion = 130;
         break;
631 632 633 634 635 636 637
      case 31:
         ctx->Const.GLSLVersion = 140;
         break;
      case 32:
         ctx->Const.GLSLVersion = 150;
         break;
      default:
638 639
         if (ctx->Version >= 33)
            ctx->Const.GLSLVersion = ctx->Version * 10;
640 641 642 643
         break;
      }
   }

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 652 653 654 655
      if (!ctx->Version) {
         _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
         return;
      }
      create_version_string(ctx, "OpenGL ES-CM ");
656
      break;
657

658
   case API_OPENGLES2:
659 660 661 662 663
      if (!ctx->Version) {
         _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
         return;
      }
      create_version_string(ctx, "OpenGL ES ");
664
      break;
665
   }
666 667 668 669

done:
   if (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 31)
      ctx->Extensions.ARB_compatibility = GL_TRUE;
670
}
671 672 673 674 675 676 677 678 679 680 681 682 683


void
_mesa_get_driver_uuid(struct gl_context *ctx, GLint *uuid)
{
   ctx->Driver.GetDriverUuid(ctx, (char*) uuid);
}

void
_mesa_get_device_uuid(struct gl_context *ctx, GLint *uuid)
{
   ctx->Driver.GetDeviceUuid(ctx, (char*) uuid);
}
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747

/**
 * Get the i-th GLSL version string.  If index=0, return the most recent
 * supported version.
 * \param ctx context to query
 * \param index  which version string to return, or -1 if none
 * \param versionOut returns the vesrion string
 * \return total number of shading language versions.
 */
int
_mesa_get_shading_language_version(const struct gl_context *ctx,
                                   int index,
                                   char **versionOut)
{
   int n = 0;

#define GLSL_VERSION(S) \
   if (n++ == index) \
      *versionOut = S

   /* GLSL core */
   if (ctx->Const.GLSLVersion >= 460)
      GLSL_VERSION("460");
   if (ctx->Const.GLSLVersion >= 450)
      GLSL_VERSION("450");
   if (ctx->Const.GLSLVersion >= 440)
      GLSL_VERSION("440");
   if (ctx->Const.GLSLVersion >= 430)
      GLSL_VERSION("430");
   if (ctx->Const.GLSLVersion >= 420)
      GLSL_VERSION("420");
   if (ctx->Const.GLSLVersion >= 410)
      GLSL_VERSION("410");
   if (ctx->Const.GLSLVersion >= 400)
      GLSL_VERSION("400");
   if (ctx->Const.GLSLVersion >= 330)
      GLSL_VERSION("330");
   if (ctx->Const.GLSLVersion >= 150)
      GLSL_VERSION("150");
   if (ctx->Const.GLSLVersion >= 140)
      GLSL_VERSION("140");
   if (ctx->Const.GLSLVersion >= 130)
      GLSL_VERSION("130");
   if (ctx->Const.GLSLVersion >= 120)
      GLSL_VERSION("120");
   /* The GL spec says to return the empty string for GLSL 1.10 */
   if (ctx->Const.GLSLVersion >= 110)
      GLSL_VERSION("");

   /* GLSL es */
   if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
        ctx->Extensions.ARB_ES3_2_compatibility)
      GLSL_VERSION("320 es");
   if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
      GLSL_VERSION("310 es");
   if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
      GLSL_VERSION("300 es");
   if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
      GLSL_VERSION("100");

#undef GLSL_VERSION

   return n;
}