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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 * Scans 'string' to see if it ends with 'ending'.
34 check_for_ending(const char *string
, const char *ending
)
38 len1
= strlen(string
);
39 len2
= strlen(ending
);
45 if (strcmp(string
+ (len1
- len2
), ending
) == 0) {
53 * Builds the MESA version string.
56 create_version_string(struct gl_context
*ctx
, const char *prefix
)
58 static const int max
= 100;
60 ctx
->VersionString
= malloc(max
);
61 if (ctx
->VersionString
) {
62 _mesa_snprintf(ctx
->VersionString
, max
,
63 "%s%u.%u%s Mesa " MESA_VERSION_STRING
65 " (" MESA_GIT_SHA1
")"
69 ctx
->Version
/ 10, ctx
->Version
% 10,
70 (ctx
->API
== API_OPENGL_CORE
) ? " (Core Profile)" : ""
76 * Override the context's version and/or API type if the
77 * environment variable MESA_GL_VERSION_OVERRIDE is set.
79 * Example uses of MESA_GL_VERSION_OVERRIDE:
81 * 2.1: select a compatibility (non-Core) profile with GL version 2.1
82 * 3.0: select a compatibility (non-Core) profile with GL version 3.0
83 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0
84 * 3.1: select a Core profile with GL version 3.1
85 * 3.1FC: select a Core+Forward Compatible profile with GL version 3.1
88 _mesa_override_gl_version(struct gl_context
*ctx
)
90 const char *env_var
= "MESA_GL_VERSION_OVERRIDE";
96 version
= getenv(env_var
);
101 fc_suffix
= check_for_ending(version
, "FC");
103 n
= sscanf(version
, "%u.%u", &major
, &minor
);
105 fprintf(stderr
, "error: invalid value for %s: %s\n", env_var
, version
);
107 ctx
->Version
= major
* 10 + minor
;
108 if (ctx
->Version
< 30 && fc_suffix
) {
109 fprintf(stderr
, "error: invalid value for %s: %s\n", env_var
, version
);
111 if (ctx
->Version
>= 30 && fc_suffix
) {
112 ctx
->API
= API_OPENGL_CORE
;
113 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
114 } else if (ctx
->Version
>= 31) {
115 ctx
->API
= API_OPENGL_CORE
;
117 ctx
->API
= API_OPENGL_COMPAT
;
119 create_version_string(ctx
, "");
125 * Override the context's GLSL version if the environment variable
126 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
127 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
130 _mesa_override_glsl_version(struct gl_context
*ctx
)
132 const char *env_var
= "MESA_GLSL_VERSION_OVERRIDE";
136 version
= getenv(env_var
);
141 n
= sscanf(version
, "%u", &ctx
->Const
.GLSLVersion
);
143 fprintf(stderr
, "error: invalid value for %s: %s\n", env_var
, version
);
149 * Examine enabled GL extensions to determine GL version.
152 compute_version(struct gl_context
*ctx
)
156 const GLboolean ver_1_3
= (ctx
->Extensions
.ARB_texture_border_clamp
&&
157 ctx
->Extensions
.ARB_texture_cube_map
&&
158 ctx
->Extensions
.ARB_texture_env_combine
&&
159 ctx
->Extensions
.ARB_texture_env_dot3
);
160 const GLboolean ver_1_4
= (ver_1_3
&&
161 ctx
->Extensions
.ARB_depth_texture
&&
162 ctx
->Extensions
.ARB_shadow
&&
163 ctx
->Extensions
.ARB_texture_env_crossbar
&&
164 ctx
->Extensions
.EXT_blend_color
&&
165 ctx
->Extensions
.EXT_blend_func_separate
&&
166 ctx
->Extensions
.EXT_blend_minmax
&&
167 ctx
->Extensions
.EXT_fog_coord
&&
168 ctx
->Extensions
.EXT_point_parameters
&&
169 ctx
->Extensions
.EXT_secondary_color
);
170 const GLboolean ver_1_5
= (ver_1_4
&&
171 ctx
->Extensions
.ARB_occlusion_query
&&
172 ctx
->Extensions
.EXT_shadow_funcs
);
173 const GLboolean ver_2_0
= (ver_1_5
&&
174 ctx
->Extensions
.ARB_point_sprite
&&
175 ctx
->Extensions
.ARB_shader_objects
&&
176 ctx
->Extensions
.ARB_vertex_shader
&&
177 ctx
->Extensions
.ARB_fragment_shader
&&
178 ctx
->Extensions
.ARB_texture_non_power_of_two
&&
179 ctx
->Extensions
.EXT_blend_equation_separate
&&
181 /* Technically, 2.0 requires the functionality
182 * of the EXT version. Enable 2.0 if either
183 * extension is available, and assume that a
184 * driver that only exposes the ATI extension
185 * will fallback to software when necessary.
187 (ctx
->Extensions
.EXT_stencil_two_side
188 || ctx
->Extensions
.ATI_separate_stencil
));
189 const GLboolean ver_2_1
= (ver_2_0
&&
190 ctx
->Const
.GLSLVersion
>= 120 &&
191 ctx
->Extensions
.EXT_pixel_buffer_object
&&
192 ctx
->Extensions
.EXT_texture_sRGB
);
193 const GLboolean ver_3_0
= (ver_2_1
&&
194 ctx
->Const
.GLSLVersion
>= 130 &&
195 ctx
->Const
.MaxSamples
>= 4 &&
196 ctx
->Extensions
.ARB_color_buffer_float
&&
197 ctx
->Extensions
.ARB_depth_buffer_float
&&
198 ctx
->Extensions
.ARB_half_float_pixel
&&
199 ctx
->Extensions
.ARB_half_float_vertex
&&
200 ctx
->Extensions
.ARB_map_buffer_range
&&
201 ctx
->Extensions
.ARB_shader_texture_lod
&&
202 ctx
->Extensions
.ARB_texture_float
&&
203 ctx
->Extensions
.ARB_texture_rg
&&
204 ctx
->Extensions
.ARB_texture_compression_rgtc
&&
205 ctx
->Extensions
.EXT_draw_buffers2
&&
206 ctx
->Extensions
.ARB_framebuffer_object
&&
207 ctx
->Extensions
.EXT_framebuffer_sRGB
&&
208 ctx
->Extensions
.EXT_packed_float
&&
209 ctx
->Extensions
.EXT_texture_array
&&
210 ctx
->Extensions
.EXT_texture_shared_exponent
&&
211 ctx
->Extensions
.EXT_transform_feedback
&&
212 ctx
->Extensions
.NV_conditional_render
);
213 const GLboolean ver_3_1
= (ver_3_0
&&
214 ctx
->Const
.GLSLVersion
>= 140 &&
215 ctx
->Extensions
.ARB_draw_instanced
&&
216 ctx
->Extensions
.ARB_texture_buffer_object
&&
217 ctx
->Extensions
.ARB_uniform_buffer_object
&&
218 ctx
->Extensions
.EXT_texture_snorm
&&
219 ctx
->Extensions
.NV_primitive_restart
&&
220 ctx
->Extensions
.NV_texture_rectangle
&&
221 ctx
->Const
.MaxVertexTextureImageUnits
>= 16);
222 const GLboolean ver_3_2
= (ver_3_1
&&
223 ctx
->Const
.GLSLVersion
>= 150 &&
224 ctx
->Extensions
.ARB_depth_clamp
&&
225 ctx
->Extensions
.ARB_draw_elements_base_vertex
&&
226 ctx
->Extensions
.ARB_fragment_coord_conventions
&&
227 ctx
->Extensions
.ARB_geometry_shader4
&&
228 ctx
->Extensions
.EXT_provoking_vertex
&&
229 ctx
->Extensions
.ARB_seamless_cube_map
&&
230 ctx
->Extensions
.ARB_sync
&&
231 ctx
->Extensions
.ARB_texture_multisample
&&
232 ctx
->Extensions
.EXT_vertex_array_bgra
);
233 const GLboolean ver_3_3
= (ver_3_2
&&
234 ctx
->Const
.GLSLVersion
>= 330 &&
235 ctx
->Extensions
.ARB_blend_func_extended
&&
236 ctx
->Extensions
.ARB_explicit_attrib_location
&&
237 ctx
->Extensions
.ARB_instanced_arrays
&&
238 ctx
->Extensions
.ARB_occlusion_query2
&&
239 ctx
->Extensions
.ARB_shader_bit_encoding
&&
240 ctx
->Extensions
.ARB_texture_rgb10_a2ui
&&
241 ctx
->Extensions
.ARB_timer_query
&&
242 ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
243 ctx
->Extensions
.EXT_texture_swizzle
);
244 /* ARB_sampler_objects is always enabled in mesa */
287 ctx
->Version
= major
* 10 + minor
;
289 create_version_string(ctx
, "");
293 compute_version_es1(struct gl_context
*ctx
)
295 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
296 const GLboolean ver_1_0
= (ctx
->Extensions
.ARB_texture_env_combine
&&
297 ctx
->Extensions
.ARB_texture_env_dot3
);
298 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
299 const GLboolean ver_1_1
= (ver_1_0
&&
300 ctx
->Extensions
.EXT_point_parameters
);
304 } else if (ver_1_0
) {
307 _mesa_problem(ctx
, "Incomplete OpenGL ES 1.0 support.");
310 create_version_string(ctx
, "OpenGL ES-CM ");
314 compute_version_es2(struct gl_context
*ctx
)
316 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
317 const GLboolean ver_2_0
= (ctx
->Extensions
.ARB_texture_cube_map
&&
318 ctx
->Extensions
.EXT_blend_color
&&
319 ctx
->Extensions
.EXT_blend_func_separate
&&
320 ctx
->Extensions
.EXT_blend_minmax
&&
321 ctx
->Extensions
.ARB_shader_objects
&&
322 ctx
->Extensions
.ARB_vertex_shader
&&
323 ctx
->Extensions
.ARB_fragment_shader
&&
324 ctx
->Extensions
.ARB_texture_non_power_of_two
&&
325 ctx
->Extensions
.EXT_blend_equation_separate
);
326 /* FINISHME: This list isn't quite right. */
327 const GLboolean ver_3_0
= (ctx
->Extensions
.ARB_half_float_vertex
&&
328 ctx
->Extensions
.ARB_internalformat_query
&&
329 ctx
->Extensions
.ARB_map_buffer_range
&&
330 ctx
->Extensions
.ARB_shader_texture_lod
&&
331 ctx
->Extensions
.ARB_texture_float
&&
332 ctx
->Extensions
.ARB_texture_rg
&&
333 ctx
->Extensions
.ARB_texture_compression_rgtc
&&
334 ctx
->Extensions
.EXT_draw_buffers2
&&
335 /* ctx->Extensions.ARB_framebuffer_object && */
336 ctx
->Extensions
.EXT_framebuffer_sRGB
&&
337 ctx
->Extensions
.EXT_packed_float
&&
338 ctx
->Extensions
.EXT_texture_array
&&
339 ctx
->Extensions
.EXT_texture_shared_exponent
&&
340 ctx
->Extensions
.EXT_transform_feedback
&&
341 ctx
->Extensions
.NV_conditional_render
&&
342 ctx
->Extensions
.ARB_draw_instanced
&&
343 ctx
->Extensions
.ARB_uniform_buffer_object
&&
344 ctx
->Extensions
.EXT_texture_snorm
&&
345 ctx
->Extensions
.NV_primitive_restart
&&
346 ctx
->Extensions
.OES_depth_texture_cube_map
);
349 } else if (ver_2_0
) {
352 _mesa_problem(ctx
, "Incomplete OpenGL ES 2.0 support.");
355 create_version_string(ctx
, "OpenGL ES ");
359 * Set the context's Version and VersionString fields.
360 * This should only be called once as part of context initialization
361 * or to perform version check for GLX_ARB_create_context_profile.
364 _mesa_compute_version(struct gl_context
*ctx
)
370 case API_OPENGL_COMPAT
:
371 /* Disable GLSL 1.40 and later for legacy contexts.
372 * This disallows creation of the GL 3.1 compatibility context. */
373 if (ctx
->Const
.GLSLVersion
> 130) {
374 ctx
->Const
.GLSLVersion
= 130;
377 case API_OPENGL_CORE
:
378 compute_version(ctx
);
381 compute_version_es1(ctx
);
384 compute_version_es2(ctx
);