2 * Mesa 3-D graphics library
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
33 * Scans 'string' to see if it ends with 'ending'.
36 check_for_ending(const char *string
, const char *ending
)
38 const size_t len1
= strlen(string
);
39 const size_t len2
= strlen(ending
);
44 return strcmp(string
+ (len1
- len2
), ending
) == 0;
48 * Returns the gl override data
50 * version > 0 indicates there is an override requested
51 * fwd_context is only valid if version > 0
54 get_gl_override(int *version
, bool *fwd_context
, bool *compat_context
)
56 const char *env_var
= "MESA_GL_VERSION_OVERRIDE";
57 const char *version_str
;
59 static int override_version
= -1;
60 static bool fc_suffix
= false;
61 static bool compat_suffix
= false;
63 if (override_version
< 0) {
66 version_str
= getenv(env_var
);
68 fc_suffix
= check_for_ending(version_str
, "FC");
69 compat_suffix
= check_for_ending(version_str
, "COMPAT");
71 n
= sscanf(version_str
, "%u.%u", &major
, &minor
);
73 fprintf(stderr
, "error: invalid value for %s: %s\n",
74 env_var
, version_str
);
77 override_version
= major
* 10 + minor
;
78 if (override_version
< 30 && fc_suffix
) {
79 fprintf(stderr
, "error: invalid value for %s: %s\n",
80 env_var
, version_str
);
86 *version
= override_version
;
87 *fwd_context
= fc_suffix
;
88 *compat_context
= compat_suffix
;
92 * Builds the MESA version string.
95 create_version_string(struct gl_context
*ctx
, const char *prefix
)
97 static const int max
= 100;
99 ctx
->VersionString
= malloc(max
);
100 if (ctx
->VersionString
) {
101 _mesa_snprintf(ctx
->VersionString
, max
,
102 "%s%u.%u%s Mesa " PACKAGE_VERSION
104 " (" MESA_GIT_SHA1
")"
108 ctx
->Version
/ 10, ctx
->Version
% 10,
109 (ctx
->API
== API_OPENGL_CORE
) ? " (Core Profile)" : ""
115 * Override the context's version and/or API type if the
116 * environment variable MESA_GL_VERSION_OVERRIDE is set.
118 * Example uses of MESA_GL_VERSION_OVERRIDE:
120 * 2.1: select a compatibility (non-Core) profile with GL version 2.1
121 * 3.0: select a compatibility (non-Core) profile with GL version 3.0
122 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0
123 * 3.1: select a Core profile with GL version 3.1
124 * 3.1FC: select a Core+Forward Compatible profile with GL version 3.1
127 _mesa_override_gl_version_contextless(struct gl_constants
*consts
,
128 gl_api
*apiOut
, GLuint
*versionOut
)
131 bool fwd_context
, compat_context
;
133 get_gl_override(&version
, &fwd_context
, &compat_context
);
136 *versionOut
= version
;
137 if (version
>= 30 && fwd_context
) {
138 *apiOut
= API_OPENGL_CORE
;
139 consts
->ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
140 } else if (version
>= 31 && !compat_context
) {
141 *apiOut
= API_OPENGL_CORE
;
143 *apiOut
= API_OPENGL_COMPAT
;
151 _mesa_override_gl_version(struct gl_context
*ctx
)
153 if (_mesa_override_gl_version_contextless(&ctx
->Const
, &ctx
->API
,
155 create_version_string(ctx
, "");
160 * Override the context's GLSL version if the environment variable
161 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
162 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
165 _mesa_override_glsl_version(struct gl_constants
*consts
)
167 const char *env_var
= "MESA_GLSL_VERSION_OVERRIDE";
171 version
= getenv(env_var
);
176 n
= sscanf(version
, "%u", &consts
->GLSLVersion
);
178 fprintf(stderr
, "error: invalid value for %s: %s\n", env_var
, version
);
184 * Examine enabled GL extensions to determine GL version.
187 compute_version(const struct gl_extensions
*extensions
,
188 const struct gl_constants
*consts
, gl_api api
)
190 GLuint major
, minor
, version
;
192 const bool ver_1_3
= (extensions
->ARB_texture_border_clamp
&&
193 extensions
->ARB_texture_cube_map
&&
194 extensions
->ARB_texture_env_combine
&&
195 extensions
->ARB_texture_env_dot3
);
196 const bool ver_1_4
= (ver_1_3
&&
197 extensions
->ARB_depth_texture
&&
198 extensions
->ARB_shadow
&&
199 extensions
->ARB_texture_env_crossbar
&&
200 extensions
->EXT_blend_color
&&
201 extensions
->EXT_blend_func_separate
&&
202 extensions
->EXT_blend_minmax
&&
203 extensions
->EXT_point_parameters
);
204 const bool ver_1_5
= (ver_1_4
&&
205 extensions
->ARB_occlusion_query
);
206 const bool ver_2_0
= (ver_1_5
&&
207 extensions
->ARB_point_sprite
&&
208 extensions
->ARB_vertex_shader
&&
209 extensions
->ARB_fragment_shader
&&
210 extensions
->ARB_texture_non_power_of_two
&&
211 extensions
->EXT_blend_equation_separate
&&
213 /* Technically, 2.0 requires the functionality of the
214 * EXT version. Enable 2.0 if either extension is
215 * available, and assume that a driver that only
216 * exposes the ATI extension will fallback to
217 * software when necessary.
219 (extensions
->EXT_stencil_two_side
220 || extensions
->ATI_separate_stencil
));
221 const bool ver_2_1
= (ver_2_0
&&
222 extensions
->EXT_pixel_buffer_object
&&
223 extensions
->EXT_texture_sRGB
);
224 const bool ver_3_0
= (ver_2_1
&&
225 consts
->GLSLVersion
>= 130 &&
226 (consts
->MaxSamples
>= 4 || consts
->FakeSWMSAA
) &&
227 (api
== API_OPENGL_CORE
||
228 extensions
->ARB_color_buffer_float
) &&
229 extensions
->ARB_depth_buffer_float
&&
230 extensions
->ARB_half_float_vertex
&&
231 extensions
->ARB_map_buffer_range
&&
232 extensions
->ARB_shader_texture_lod
&&
233 extensions
->ARB_texture_float
&&
234 extensions
->ARB_texture_rg
&&
235 extensions
->ARB_texture_compression_rgtc
&&
236 extensions
->EXT_draw_buffers2
&&
237 extensions
->ARB_framebuffer_object
&&
238 extensions
->EXT_framebuffer_sRGB
&&
239 extensions
->EXT_packed_float
&&
240 extensions
->EXT_texture_array
&&
241 extensions
->EXT_texture_shared_exponent
&&
242 extensions
->EXT_transform_feedback
&&
243 extensions
->NV_conditional_render
);
244 const bool ver_3_1
= (ver_3_0
&&
245 consts
->GLSLVersion
>= 140 &&
246 extensions
->ARB_draw_instanced
&&
247 extensions
->ARB_texture_buffer_object
&&
248 extensions
->ARB_uniform_buffer_object
&&
249 extensions
->EXT_texture_snorm
&&
250 extensions
->NV_primitive_restart
&&
251 extensions
->NV_texture_rectangle
&&
252 consts
->Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
>= 16);
253 const bool ver_3_2
= (ver_3_1
&&
254 consts
->GLSLVersion
>= 150 &&
255 extensions
->ARB_depth_clamp
&&
256 extensions
->ARB_draw_elements_base_vertex
&&
257 extensions
->ARB_fragment_coord_conventions
&&
258 extensions
->EXT_provoking_vertex
&&
259 extensions
->ARB_seamless_cube_map
&&
260 extensions
->ARB_sync
&&
261 extensions
->ARB_texture_multisample
&&
262 extensions
->EXT_vertex_array_bgra
);
263 const bool ver_3_3
= (ver_3_2
&&
264 consts
->GLSLVersion
>= 330 &&
265 extensions
->ARB_blend_func_extended
&&
266 extensions
->ARB_explicit_attrib_location
&&
267 extensions
->ARB_instanced_arrays
&&
268 extensions
->ARB_occlusion_query2
&&
269 extensions
->ARB_shader_bit_encoding
&&
270 extensions
->ARB_texture_rgb10_a2ui
&&
271 extensions
->ARB_timer_query
&&
272 extensions
->ARB_vertex_type_2_10_10_10_rev
&&
273 extensions
->EXT_texture_swizzle
);
274 /* ARB_sampler_objects is always enabled in mesa */
276 const bool ver_4_0
= (ver_3_3
&&
277 consts
->GLSLVersion
>= 400 &&
278 extensions
->ARB_draw_buffers_blend
&&
279 extensions
->ARB_draw_indirect
&&
280 extensions
->ARB_gpu_shader5
&&
281 extensions
->ARB_gpu_shader_fp64
&&
282 extensions
->ARB_sample_shading
&&
283 false /*extensions->ARB_shader_subroutine*/ &&
284 extensions
->ARB_tessellation_shader
&&
285 extensions
->ARB_texture_buffer_object_rgb32
&&
286 extensions
->ARB_texture_cube_map_array
&&
287 extensions
->ARB_texture_query_lod
&&
288 extensions
->ARB_transform_feedback2
&&
289 extensions
->ARB_transform_feedback3
);
290 const bool ver_4_1
= (ver_4_0
&&
291 consts
->GLSLVersion
>= 410 &&
292 extensions
->ARB_ES2_compatibility
&&
293 extensions
->ARB_shader_precision
&&
294 extensions
->ARB_vertex_attrib_64bit
&&
295 extensions
->ARB_viewport_array
);
296 const bool ver_4_2
= (ver_4_1
&&
297 consts
->GLSLVersion
>= 420 &&
298 extensions
->ARB_base_instance
&&
299 extensions
->ARB_conservative_depth
&&
300 extensions
->ARB_internalformat_query
&&
301 extensions
->ARB_shader_atomic_counters
&&
302 extensions
->ARB_shader_image_load_store
&&
303 extensions
->ARB_shading_language_420pack
&&
304 extensions
->ARB_shading_language_packing
&&
305 extensions
->ARB_texture_compression_bptc
&&
306 extensions
->ARB_transform_feedback_instanced
);
361 version
= major
* 10 + minor
;
363 if (api
== API_OPENGL_CORE
&& version
< 31)
370 compute_version_es1(const struct gl_extensions
*extensions
)
372 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
373 const bool ver_1_0
= (extensions
->ARB_texture_env_combine
&&
374 extensions
->ARB_texture_env_dot3
);
375 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
376 const bool ver_1_1
= (ver_1_0
&&
377 extensions
->EXT_point_parameters
);
381 } else if (ver_1_0
) {
389 compute_version_es2(const struct gl_extensions
*extensions
)
391 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
392 const bool ver_2_0
= (extensions
->ARB_texture_cube_map
&&
393 extensions
->EXT_blend_color
&&
394 extensions
->EXT_blend_func_separate
&&
395 extensions
->EXT_blend_minmax
&&
396 extensions
->ARB_vertex_shader
&&
397 extensions
->ARB_fragment_shader
&&
398 extensions
->ARB_texture_non_power_of_two
&&
399 extensions
->EXT_blend_equation_separate
);
400 /* FINISHME: This list isn't quite right. */
401 const bool ver_3_0
= (extensions
->ARB_half_float_vertex
&&
402 extensions
->ARB_internalformat_query
&&
403 extensions
->ARB_map_buffer_range
&&
404 extensions
->ARB_shader_texture_lod
&&
405 extensions
->ARB_texture_float
&&
406 extensions
->ARB_texture_rg
&&
407 extensions
->ARB_depth_buffer_float
&&
408 extensions
->EXT_draw_buffers2
&&
409 /* extensions->ARB_framebuffer_object && */
410 extensions
->EXT_framebuffer_sRGB
&&
411 extensions
->EXT_packed_float
&&
412 extensions
->EXT_texture_array
&&
413 extensions
->EXT_texture_shared_exponent
&&
414 extensions
->EXT_transform_feedback
&&
415 extensions
->ARB_draw_instanced
&&
416 extensions
->ARB_uniform_buffer_object
&&
417 extensions
->EXT_texture_snorm
&&
418 extensions
->NV_primitive_restart
&&
419 extensions
->OES_depth_texture_cube_map
);
420 const bool ver_3_1
= (ver_3_0
&&
421 extensions
->ARB_arrays_of_arrays
&&
422 extensions
->ARB_compute_shader
&&
423 extensions
->ARB_draw_indirect
&&
424 false /*extensions->ARB_framebuffer_no_attachments*/ &&
425 extensions
->ARB_shader_atomic_counters
&&
426 extensions
->ARB_shader_image_load_store
&&
427 false /*extensions->ARB_shader_image_size*/ &&
428 false /*extensions->ARB_shader_storage_buffer_object*/ &&
429 extensions
->ARB_shading_language_packing
&&
430 extensions
->ARB_stencil_texturing
&&
431 extensions
->ARB_gpu_shader5
&&
432 extensions
->EXT_shader_integer_mix
);
436 } else if (ver_3_0
) {
438 } else if (ver_2_0
) {
446 _mesa_get_version(const struct gl_extensions
*extensions
,
447 struct gl_constants
*consts
, gl_api api
)
450 case API_OPENGL_COMPAT
:
451 /* Disable GLSL 1.40 and later for legacy contexts.
452 * This disallows creation of the GL 3.1 compatibility context. */
453 if (consts
->GLSLVersion
> 130) {
454 consts
->GLSLVersion
= 130;
457 case API_OPENGL_CORE
:
458 return compute_version(extensions
, consts
, api
);
460 return compute_version_es1(extensions
);
462 return compute_version_es2(extensions
);
468 * Set the context's Version and VersionString fields.
469 * This should only be called once as part of context initialization
470 * or to perform version check for GLX_ARB_create_context_profile.
473 _mesa_compute_version(struct gl_context
*ctx
)
478 ctx
->Version
= _mesa_get_version(&ctx
->Extensions
, &ctx
->Const
, ctx
->API
);
480 /* Make sure that the GLSL version lines up with the GL version. In some
481 * cases it can be too high, e.g. if an extension is missing.
483 if (ctx
->API
== API_OPENGL_CORE
) {
484 switch (ctx
->Version
) {
486 ctx
->Const
.GLSLVersion
= 140;
489 ctx
->Const
.GLSLVersion
= 150;
492 ctx
->Const
.GLSLVersion
= ctx
->Version
* 10;
498 case API_OPENGL_COMPAT
:
499 case API_OPENGL_CORE
:
500 create_version_string(ctx
, "");
505 _mesa_problem(ctx
, "Incomplete OpenGL ES 1.0 support.");
508 create_version_string(ctx
, "OpenGL ES-CM ");
513 _mesa_problem(ctx
, "Incomplete OpenGL ES 2.0 support.");
516 create_version_string(ctx
, "OpenGL ES ");