blob: c497317473dec732b8766dfa9ceb558a676cdaed [file] [log] [blame]
Brian Paule0b9e332010-01-05 21:23:01 -07001/*
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 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.
22 */
23
24
Vinson Leeab564b52011-01-06 00:45:08 -080025#include "imports.h"
Vinson Lee0117da42011-01-05 23:11:54 -080026#include "mtypes.h"
Brian Paule0b9e332010-01-05 21:23:01 -070027#include "version.h"
Ian Romanickde579a12011-03-31 11:42:01 -070028#include "git_sha1.h"
Brian Paule0b9e332010-01-05 21:23:01 -070029
Chad Versace0527c112011-09-26 11:48:46 -070030/**
31 * Override the context's GL version if the environment variable
32 * MESA_GL_VERSION_OVERRIDE is set. Valid values of MESA_GL_VERSION_OVERRIDE
33 * are point-separated version numbers, such as "3.0".
34 */
35static void
36override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
37{
38 const char *env_var = "MESA_GL_VERSION_OVERRIDE";
39 const char *version;
40 int n;
Brian Paule0b9e332010-01-05 21:23:01 -070041
Chad Versace0527c112011-09-26 11:48:46 -070042 version = getenv(env_var);
43 if (!version) {
44 return;
45 }
46
Brian Pauld1e567f2011-09-28 10:09:56 -060047 n = sscanf(version, "%u.%u", major, minor);
Chad Versace0527c112011-09-26 11:48:46 -070048 if (n != 2) {
49 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
50 return;
51 }
52}
Brian Paule0b9e332010-01-05 21:23:01 -070053
54/**
Chad Versacea1eff552011-09-27 13:53:11 -070055 * Override the context's GLSL version if the environment variable
56 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
57 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
58 */
59void
60_mesa_override_glsl_version(struct gl_context *ctx)
61{
62 const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
63 const char *version;
64 int n;
65
66 version = getenv(env_var);
67 if (!version) {
68 return;
69 }
70
Brian Paulb79782c2011-09-28 13:16:45 -060071 n = sscanf(version, "%u", &ctx->Const.GLSLVersion);
Chad Versacea1eff552011-09-27 13:53:11 -070072 if (n != 1) {
73 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
74 return;
75 }
76}
77
78/**
Brian Paule0b9e332010-01-05 21:23:01 -070079 * Examine enabled GL extensions to determine GL version.
80 * Return major and minor version numbers.
81 */
82static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -040083compute_version(struct gl_context *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -070084{
Kristian Høgsberg29107d42010-04-21 16:14:18 -040085 GLuint major, minor;
86 static const int max = 100;
87
Ian Romanick34eae1c2011-08-30 16:29:52 -070088 const GLboolean ver_1_3 = (ctx->Extensions.ARB_multitexture &&
Brian Paule0b9e332010-01-05 21:23:01 -070089 ctx->Extensions.ARB_texture_border_clamp &&
Brian Paule0b9e332010-01-05 21:23:01 -070090 ctx->Extensions.ARB_texture_cube_map &&
91 ctx->Extensions.EXT_texture_env_add &&
92 ctx->Extensions.ARB_texture_env_combine &&
93 ctx->Extensions.ARB_texture_env_dot3);
94 const GLboolean ver_1_4 = (ver_1_3 &&
95 ctx->Extensions.ARB_depth_texture &&
96 ctx->Extensions.ARB_shadow &&
97 ctx->Extensions.ARB_texture_env_crossbar &&
98 ctx->Extensions.ARB_texture_mirrored_repeat &&
99 ctx->Extensions.ARB_window_pos &&
100 ctx->Extensions.EXT_blend_color &&
101 ctx->Extensions.EXT_blend_func_separate &&
102 ctx->Extensions.EXT_blend_minmax &&
103 ctx->Extensions.EXT_blend_subtract &&
104 ctx->Extensions.EXT_fog_coord &&
Brian Paule0b9e332010-01-05 21:23:01 -0700105 ctx->Extensions.EXT_point_parameters &&
106 ctx->Extensions.EXT_secondary_color &&
107 ctx->Extensions.EXT_stencil_wrap &&
Ian Romanick34eae1c2011-08-30 16:29:52 -0700108 ctx->Extensions.EXT_texture_lod_bias);
Brian Paule0b9e332010-01-05 21:23:01 -0700109 const GLboolean ver_1_5 = (ver_1_4 &&
110 ctx->Extensions.ARB_occlusion_query &&
Brian Paule0b9e332010-01-05 21:23:01 -0700111 ctx->Extensions.EXT_shadow_funcs);
112 const GLboolean ver_2_0 = (ver_1_5 &&
113 ctx->Extensions.ARB_draw_buffers &&
114 ctx->Extensions.ARB_point_sprite &&
115 ctx->Extensions.ARB_shader_objects &&
116 ctx->Extensions.ARB_vertex_shader &&
117 ctx->Extensions.ARB_fragment_shader &&
118 ctx->Extensions.ARB_texture_non_power_of_two &&
119 ctx->Extensions.EXT_blend_equation_separate &&
120
121 /* Technically, 2.0 requires the functionality
122 * of the EXT version. Enable 2.0 if either
123 * extension is available, and assume that a
124 * driver that only exposes the ATI extension
125 * will fallback to software when necessary.
126 */
127 (ctx->Extensions.EXT_stencil_two_side
128 || ctx->Extensions.ATI_separate_stencil));
129 const GLboolean ver_2_1 = (ver_2_0 &&
Brian Paule7087172010-09-21 18:13:02 -0600130 ctx->Const.GLSLVersion >= 120 &&
Brian Paule0b9e332010-01-05 21:23:01 -0700131 ctx->Extensions.EXT_pixel_buffer_object &&
132 ctx->Extensions.EXT_texture_sRGB);
Brian Paul44732102010-07-01 16:30:00 -0600133 const GLboolean ver_3_0 = (ver_2_1 &&
Marek Olšáke5c6a922011-02-15 23:30:23 +0100134 ctx->Extensions.ARB_color_buffer_float &&
135 ctx->Extensions.ARB_depth_buffer_float &&
Brian Paul44732102010-07-01 16:30:00 -0600136 ctx->Extensions.ARB_half_float_pixel &&
137 ctx->Extensions.ARB_map_buffer_range &&
138 ctx->Extensions.ARB_texture_float &&
Brian Paul6988f652010-07-07 20:26:33 -0600139 ctx->Extensions.ARB_texture_rg &&
Ian Romanicke2a054b2010-10-01 16:07:28 -0700140 ctx->Extensions.ARB_texture_compression_rgtc &&
Brian Paul44732102010-07-01 16:30:00 -0600141 ctx->Extensions.APPLE_vertex_array_object &&
142 ctx->Extensions.EXT_draw_buffers2 &&
143 ctx->Extensions.EXT_framebuffer_blit &&
144 ctx->Extensions.EXT_framebuffer_multisample &&
145 ctx->Extensions.EXT_framebuffer_object &&
146 ctx->Extensions.EXT_framebuffer_sRGB &&
147 ctx->Extensions.EXT_packed_depth_stencil &&
148 ctx->Extensions.EXT_packed_float &&
Brian Paul44732102010-07-01 16:30:00 -0600149 ctx->Extensions.EXT_texture_array &&
Brian Paul44732102010-07-01 16:30:00 -0600150 ctx->Extensions.EXT_texture_integer &&
Brian Paul6988f652010-07-07 20:26:33 -0600151 ctx->Extensions.EXT_texture_shared_exponent &&
Brian Paul44732102010-07-01 16:30:00 -0600152 ctx->Extensions.EXT_transform_feedback &&
153 ctx->Extensions.NV_conditional_render);
154 const GLboolean ver_3_1 = (ver_3_0 &&
155 ctx->Extensions.ARB_copy_buffer &&
156 ctx->Extensions.ARB_draw_instanced &&
157 ctx->Extensions.ARB_texture_buffer_object &&
158 ctx->Extensions.ARB_uniform_buffer_object &&
Marek Olšák0be36992011-03-18 13:44:51 +0100159 ctx->Extensions.EXT_texture_snorm &&
Brian Paul44732102010-07-01 16:30:00 -0600160 ctx->Extensions.NV_primitive_restart &&
161 ctx->Extensions.NV_texture_rectangle &&
162 ctx->Const.MaxVertexTextureImageUnits >= 16);
163 const GLboolean ver_3_2 = (ver_3_1 &&
164 ctx->Extensions.ARB_depth_clamp &&
165 ctx->Extensions.ARB_draw_elements_base_vertex &&
166 ctx->Extensions.ARB_fragment_coord_conventions &&
167 ctx->Extensions.ARB_geometry_shader4 &&
168 ctx->Extensions.EXT_provoking_vertex &&
169 ctx->Extensions.ARB_seamless_cube_map &&
170 ctx->Extensions.ARB_sync &&
171 ctx->Extensions.ARB_texture_multisample &&
172 ctx->Extensions.EXT_vertex_array_bgra);
173 const GLboolean ver_3_3 = (ver_3_2 &&
174 ctx->Extensions.ARB_blend_func_extended &&
175 ctx->Extensions.ARB_explicit_attrib_location &&
176 ctx->Extensions.ARB_instanced_arrays &&
177 ctx->Extensions.ARB_occlusion_query2 &&
178 ctx->Extensions.ARB_sampler_objects &&
179 ctx->Extensions.ARB_texture_rgb10_a2ui &&
180 ctx->Extensions.ARB_timer_query &&
181 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
182 ctx->Extensions.EXT_texture_swizzle);
183
184 if (ver_3_3) {
185 major = 3;
186 minor = 3;
187 }
188 else if (ver_3_2) {
189 major = 3;
190 minor = 2;
191 }
192 else if (ver_3_1) {
193 major = 3;
194 minor = 1;
195 }
196 else if (ver_3_0) {
197 major = 3;
198 minor = 0;
199 }
200 else if (ver_2_1) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400201 major = 2;
202 minor = 1;
Brian Paule0b9e332010-01-05 21:23:01 -0700203 }
204 else if (ver_2_0) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400205 major = 2;
206 minor = 0;
Brian Paule0b9e332010-01-05 21:23:01 -0700207 }
208 else if (ver_1_5) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400209 major = 1;
210 minor = 5;
Brian Paule0b9e332010-01-05 21:23:01 -0700211 }
212 else if (ver_1_4) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400213 major = 1;
214 minor = 4;
Brian Paule0b9e332010-01-05 21:23:01 -0700215 }
216 else if (ver_1_3) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400217 major = 1;
218 minor = 3;
Brian Paule0b9e332010-01-05 21:23:01 -0700219 }
220 else {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400221 major = 1;
222 minor = 2;
223 }
224
225 ctx->VersionMajor = major;
226 ctx->VersionMinor = minor;
Chad Versace0527c112011-09-26 11:48:46 -0700227
228 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
229
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400230 ctx->VersionString = (char *) malloc(max);
231 if (ctx->VersionString) {
232 _mesa_snprintf(ctx->VersionString, max,
Ian Romanickde579a12011-03-31 11:42:01 -0700233 "%u.%u Mesa " MESA_VERSION_STRING
234#ifdef MESA_GIT_SHA1
235 " (" MESA_GIT_SHA1 ")"
236#endif
237 ,
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400238 ctx->VersionMajor, ctx->VersionMinor);
Brian Paule0b9e332010-01-05 21:23:01 -0700239 }
240}
241
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400242static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400243compute_version_es1(struct gl_context *ctx)
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400244{
245 static const int max = 100;
246
247 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
Ian Romanick34eae1c2011-08-30 16:29:52 -0700248 const GLboolean ver_1_0 = (ctx->Extensions.ARB_multitexture &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400249 ctx->Extensions.EXT_texture_env_add &&
250 ctx->Extensions.ARB_texture_env_combine &&
251 ctx->Extensions.ARB_texture_env_dot3);
252 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
253 const GLboolean ver_1_1 = (ver_1_0 &&
Ian Romanick34eae1c2011-08-30 16:29:52 -0700254 ctx->Extensions.EXT_point_parameters);
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400255
256 if (ver_1_1) {
257 ctx->VersionMajor = 1;
258 ctx->VersionMinor = 1;
259 } else if (ver_1_0) {
260 ctx->VersionMajor = 1;
261 ctx->VersionMinor = 0;
262 } else {
263 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
264 }
265
266 ctx->VersionString = (char *) malloc(max);
267 if (ctx->VersionString) {
268 _mesa_snprintf(ctx->VersionString, max,
269 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING,
270 ctx->VersionMinor);
271 }
272}
273
274static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400275compute_version_es2(struct gl_context *ctx)
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400276{
277 static const int max = 100;
278
279 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
Ian Romanick34eae1c2011-08-30 16:29:52 -0700280 const GLboolean ver_2_0 = (ctx->Extensions.ARB_multitexture &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400281 ctx->Extensions.ARB_texture_cube_map &&
282 ctx->Extensions.ARB_texture_mirrored_repeat &&
283 ctx->Extensions.EXT_blend_color &&
284 ctx->Extensions.EXT_blend_func_separate &&
285 ctx->Extensions.EXT_blend_minmax &&
286 ctx->Extensions.EXT_blend_subtract &&
287 ctx->Extensions.EXT_stencil_wrap &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400288 ctx->Extensions.ARB_shader_objects &&
289 ctx->Extensions.ARB_vertex_shader &&
290 ctx->Extensions.ARB_fragment_shader &&
291 ctx->Extensions.ARB_texture_non_power_of_two &&
292 ctx->Extensions.EXT_blend_equation_separate);
293 if (ver_2_0) {
294 ctx->VersionMajor = 2;
295 ctx->VersionMinor = 0;
296 } else {
297 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
298 }
299
300 ctx->VersionString = (char *) malloc(max);
301 if (ctx->VersionString) {
302 _mesa_snprintf(ctx->VersionString, max,
303 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING);
304 }
305}
Brian Paule0b9e332010-01-05 21:23:01 -0700306
307/**
308 * Set the context's VersionMajor, VersionMinor, VersionString fields.
Chia-I Wu45313562010-09-10 10:31:06 +0800309 * This should only be called once as part of context initialization
310 * or to perform version check for GLX_ARB_create_context_profile.
Brian Paule0b9e332010-01-05 21:23:01 -0700311 */
312void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400313_mesa_compute_version(struct gl_context *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -0700314{
Chia-I Wu45313562010-09-10 10:31:06 +0800315 if (ctx->VersionMajor)
316 return;
317
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400318 switch (ctx->API) {
319 case API_OPENGL:
320 compute_version(ctx);
321 break;
322 case API_OPENGLES:
323 compute_version_es1(ctx);
324 break;
325 case API_OPENGLES2:
326 compute_version_es2(ctx);
327 break;
Brian Paule0b9e332010-01-05 21:23:01 -0700328 }
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400329
Brian Paule0b9e332010-01-05 21:23:01 -0700330}