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(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
;
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
.ARB_window_pos
&&
165 ctx
->Extensions
.EXT_blend_color
&&
166 ctx
->Extensions
.EXT_blend_func_separate
&&
167 ctx
->Extensions
.EXT_blend_minmax
&&
168 ctx
->Extensions
.EXT_fog_coord
&&
169 ctx
->Extensions
.EXT_point_parameters
&&
170 ctx
->Extensions
.EXT_secondary_color
);
171 const GLboolean ver_1_5
= (ver_1_4
&&
172 ctx
->Extensions
.ARB_occlusion_query
&&
173 ctx
->Extensions
.EXT_shadow_funcs
);
174 const GLboolean ver_2_0
= (ver_1_5
&&
175 ctx
->Extensions
.ARB_point_sprite
&&
176 ctx
->Extensions
.ARB_shader_objects
&&
177 ctx
->Extensions
.ARB_vertex_shader
&&
178 ctx
->Extensions
.ARB_fragment_shader
&&
179 ctx
->Extensions
.ARB_texture_non_power_of_two
&&
180 ctx
->Extensions
.EXT_blend_equation_separate
&&
182 /* Technically, 2.0 requires the functionality
183 * of the EXT version. Enable 2.0 if either
184 * extension is available, and assume that a
185 * driver that only exposes the ATI extension
186 * will fallback to software when necessary.
188 (ctx
->Extensions
.EXT_stencil_two_side
189 || ctx
->Extensions
.ATI_separate_stencil
));
190 const GLboolean ver_2_1
= (ver_2_0
&&
191 ctx
->Const
.GLSLVersion
>= 120 &&
192 ctx
->Extensions
.EXT_pixel_buffer_object
&&
193 ctx
->Extensions
.EXT_texture_sRGB
);
194 const GLboolean ver_3_0
= (ver_2_1
&&
195 ctx
->Const
.GLSLVersion
>= 130 &&
196 ctx
->Const
.MaxSamples
>= 4 &&
197 ctx
->Extensions
.ARB_color_buffer_float
&&
198 ctx
->Extensions
.ARB_depth_buffer_float
&&
199 ctx
->Extensions
.ARB_half_float_pixel
&&
200 ctx
->Extensions
.ARB_half_float_vertex
&&
201 ctx
->Extensions
.ARB_map_buffer_range
&&
202 ctx
->Extensions
.ARB_shader_texture_lod
&&
203 ctx
->Extensions
.ARB_texture_float
&&
204 ctx
->Extensions
.ARB_texture_rg
&&
205 ctx
->Extensions
.ARB_texture_compression_rgtc
&&
206 ctx
->Extensions
.EXT_draw_buffers2
&&
207 ctx
->Extensions
.ARB_framebuffer_object
&&
208 ctx
->Extensions
.EXT_framebuffer_sRGB
&&
209 ctx
->Extensions
.EXT_packed_float
&&
210 ctx
->Extensions
.EXT_texture_array
&&
211 ctx
->Extensions
.EXT_texture_shared_exponent
&&
212 ctx
->Extensions
.EXT_transform_feedback
&&
213 ctx
->Extensions
.NV_conditional_render
);
214 const GLboolean ver_3_1
= (ver_3_0
&&
215 ctx
->Const
.GLSLVersion
>= 140 &&
216 ctx
->Extensions
.ARB_copy_buffer
&&
217 ctx
->Extensions
.ARB_draw_instanced
&&
218 ctx
->Extensions
.ARB_texture_buffer_object
&&
219 ctx
->Extensions
.ARB_uniform_buffer_object
&&
220 ctx
->Extensions
.EXT_texture_snorm
&&
221 ctx
->Extensions
.NV_primitive_restart
&&
222 ctx
->Extensions
.NV_texture_rectangle
&&
223 ctx
->Const
.MaxVertexTextureImageUnits
>= 16);
224 const GLboolean ver_3_2
= (ver_3_1
&&
225 ctx
->Const
.GLSLVersion
>= 150 &&
226 ctx
->Extensions
.ARB_depth_clamp
&&
227 ctx
->Extensions
.ARB_draw_elements_base_vertex
&&
228 ctx
->Extensions
.ARB_fragment_coord_conventions
&&
229 ctx
->Extensions
.ARB_geometry_shader4
&&
230 ctx
->Extensions
.EXT_provoking_vertex
&&
231 ctx
->Extensions
.ARB_seamless_cube_map
&&
232 ctx
->Extensions
.ARB_sync
&&
233 ctx
->Extensions
.ARB_texture_multisample
&&
234 ctx
->Extensions
.EXT_vertex_array_bgra
);
235 const GLboolean ver_3_3
= (ver_3_2
&&
236 ctx
->Const
.GLSLVersion
>= 330 &&
237 ctx
->Extensions
.ARB_blend_func_extended
&&
238 ctx
->Extensions
.ARB_explicit_attrib_location
&&
239 ctx
->Extensions
.ARB_instanced_arrays
&&
240 ctx
->Extensions
.ARB_occlusion_query2
&&
241 ctx
->Extensions
.ARB_shader_bit_encoding
&&
242 ctx
->Extensions
.ARB_texture_rgb10_a2ui
&&
243 ctx
->Extensions
.ARB_timer_query
&&
244 ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
245 ctx
->Extensions
.EXT_texture_swizzle
);
246 /* ARB_sampler_objects is always enabled in mesa */
289 ctx
->Version
= major
* 10 + minor
;
291 create_version_string(ctx
, "");
295 compute_version_es1(struct gl_context
*ctx
)
297 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
298 const GLboolean ver_1_0
= (ctx
->Extensions
.ARB_texture_env_combine
&&
299 ctx
->Extensions
.ARB_texture_env_dot3
);
300 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
301 const GLboolean ver_1_1
= (ver_1_0
&&
302 ctx
->Extensions
.EXT_point_parameters
);
306 } else if (ver_1_0
) {
309 _mesa_problem(ctx
, "Incomplete OpenGL ES 1.0 support.");
312 create_version_string(ctx
, "OpenGL ES-CM ");
316 compute_version_es2(struct gl_context
*ctx
)
318 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
319 const GLboolean ver_2_0
= (ctx
->Extensions
.ARB_texture_cube_map
&&
320 ctx
->Extensions
.EXT_blend_color
&&
321 ctx
->Extensions
.EXT_blend_func_separate
&&
322 ctx
->Extensions
.EXT_blend_minmax
&&
323 ctx
->Extensions
.ARB_shader_objects
&&
324 ctx
->Extensions
.ARB_vertex_shader
&&
325 ctx
->Extensions
.ARB_fragment_shader
&&
326 ctx
->Extensions
.ARB_texture_non_power_of_two
&&
327 ctx
->Extensions
.EXT_blend_equation_separate
);
331 _mesa_problem(ctx
, "Incomplete OpenGL ES 2.0 support.");
334 create_version_string(ctx
, "OpenGL ES ");
338 * Set the context's Version and VersionString fields.
339 * This should only be called once as part of context initialization
340 * or to perform version check for GLX_ARB_create_context_profile.
343 _mesa_compute_version(struct gl_context
*ctx
)
350 case API_OPENGL_CORE
:
351 compute_version(ctx
);
354 compute_version_es1(ctx
);
357 compute_version_es2(ctx
);