blob: 90afecb5d8be9c0c03e32d7caa0a10c8b7c025b3 [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.
Brian Paule0b9e332010-01-05 21:23:01 -070080 */
81static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -040082compute_version(struct gl_context *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -070083{
Kristian Høgsberg29107d42010-04-21 16:14:18 -040084 GLuint major, minor;
85 static const int max = 100;
86
Ian Romanick677743f2011-08-30 16:45:50 -070087 const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp &&
Brian Paule0b9e332010-01-05 21:23:01 -070088 ctx->Extensions.ARB_texture_cube_map &&
Brian Paule0b9e332010-01-05 21:23:01 -070089 ctx->Extensions.ARB_texture_env_combine &&
90 ctx->Extensions.ARB_texture_env_dot3);
91 const GLboolean ver_1_4 = (ver_1_3 &&
92 ctx->Extensions.ARB_depth_texture &&
93 ctx->Extensions.ARB_shadow &&
94 ctx->Extensions.ARB_texture_env_crossbar &&
Brian Paule0b9e332010-01-05 21:23:01 -070095 ctx->Extensions.ARB_window_pos &&
96 ctx->Extensions.EXT_blend_color &&
97 ctx->Extensions.EXT_blend_func_separate &&
98 ctx->Extensions.EXT_blend_minmax &&
Brian Paule0b9e332010-01-05 21:23:01 -070099 ctx->Extensions.EXT_fog_coord &&
Brian Paule0b9e332010-01-05 21:23:01 -0700100 ctx->Extensions.EXT_point_parameters &&
Ian Romanick1d5e49b2011-08-30 17:48:11 -0700101 ctx->Extensions.EXT_secondary_color);
Brian Paule0b9e332010-01-05 21:23:01 -0700102 const GLboolean ver_1_5 = (ver_1_4 &&
103 ctx->Extensions.ARB_occlusion_query &&
Brian Paule0b9e332010-01-05 21:23:01 -0700104 ctx->Extensions.EXT_shadow_funcs);
105 const GLboolean ver_2_0 = (ver_1_5 &&
Brian Paule0b9e332010-01-05 21:23:01 -0700106 ctx->Extensions.ARB_point_sprite &&
107 ctx->Extensions.ARB_shader_objects &&
108 ctx->Extensions.ARB_vertex_shader &&
109 ctx->Extensions.ARB_fragment_shader &&
110 ctx->Extensions.ARB_texture_non_power_of_two &&
111 ctx->Extensions.EXT_blend_equation_separate &&
112
113 /* Technically, 2.0 requires the functionality
114 * of the EXT version. Enable 2.0 if either
115 * extension is available, and assume that a
116 * driver that only exposes the ATI extension
117 * will fallback to software when necessary.
118 */
119 (ctx->Extensions.EXT_stencil_two_side
120 || ctx->Extensions.ATI_separate_stencil));
121 const GLboolean ver_2_1 = (ver_2_0 &&
Brian Paule7087172010-09-21 18:13:02 -0600122 ctx->Const.GLSLVersion >= 120 &&
Brian Paule0b9e332010-01-05 21:23:01 -0700123 ctx->Extensions.EXT_pixel_buffer_object &&
124 ctx->Extensions.EXT_texture_sRGB);
Brian Paul44732102010-07-01 16:30:00 -0600125 const GLboolean ver_3_0 = (ver_2_1 &&
Marek Olšák97534d92011-11-04 19:12:16 +0100126 ctx->Const.GLSLVersion >= 130 &&
Dylan Noblesmith8e909132012-04-21 19:35:48 +0000127 ctx->Const.MaxSamples >= 4 &&
Marek Olšáke5c6a922011-02-15 23:30:23 +0100128 ctx->Extensions.ARB_color_buffer_float &&
129 ctx->Extensions.ARB_depth_buffer_float &&
Brian Paul44732102010-07-01 16:30:00 -0600130 ctx->Extensions.ARB_half_float_pixel &&
Marek Olšák97534d92011-11-04 19:12:16 +0100131 ctx->Extensions.ARB_half_float_vertex &&
Brian Paul44732102010-07-01 16:30:00 -0600132 ctx->Extensions.ARB_map_buffer_range &&
Marek Olšák5596db72012-01-12 03:54:09 +0100133 ctx->Extensions.ARB_shader_texture_lod &&
Brian Paul44732102010-07-01 16:30:00 -0600134 ctx->Extensions.ARB_texture_float &&
Brian Paul6988f652010-07-07 20:26:33 -0600135 ctx->Extensions.ARB_texture_rg &&
Ian Romanicke2a054b2010-10-01 16:07:28 -0700136 ctx->Extensions.ARB_texture_compression_rgtc &&
Brian Paul44732102010-07-01 16:30:00 -0600137 ctx->Extensions.APPLE_vertex_array_object &&
138 ctx->Extensions.EXT_draw_buffers2 &&
Marek Olšák5596db72012-01-12 03:54:09 +0100139 ctx->Extensions.ARB_framebuffer_object &&
Brian Paul44732102010-07-01 16:30:00 -0600140 ctx->Extensions.EXT_framebuffer_sRGB &&
Brian Paul44732102010-07-01 16:30:00 -0600141 ctx->Extensions.EXT_packed_float &&
Brian Paul44732102010-07-01 16:30:00 -0600142 ctx->Extensions.EXT_texture_array &&
Brian Paul6988f652010-07-07 20:26:33 -0600143 ctx->Extensions.EXT_texture_shared_exponent &&
Brian Paul44732102010-07-01 16:30:00 -0600144 ctx->Extensions.EXT_transform_feedback &&
145 ctx->Extensions.NV_conditional_render);
146 const GLboolean ver_3_1 = (ver_3_0 &&
Marek Olšák97534d92011-11-04 19:12:16 +0100147 ctx->Const.GLSLVersion >= 140 &&
Brian Paul44732102010-07-01 16:30:00 -0600148 ctx->Extensions.ARB_copy_buffer &&
149 ctx->Extensions.ARB_draw_instanced &&
150 ctx->Extensions.ARB_texture_buffer_object &&
151 ctx->Extensions.ARB_uniform_buffer_object &&
Marek Olšák0be36992011-03-18 13:44:51 +0100152 ctx->Extensions.EXT_texture_snorm &&
Brian Paul44732102010-07-01 16:30:00 -0600153 ctx->Extensions.NV_primitive_restart &&
154 ctx->Extensions.NV_texture_rectangle &&
155 ctx->Const.MaxVertexTextureImageUnits >= 16);
156 const GLboolean ver_3_2 = (ver_3_1 &&
Marek Olšák97534d92011-11-04 19:12:16 +0100157 ctx->Const.GLSLVersion >= 150 &&
Brian Paul44732102010-07-01 16:30:00 -0600158 ctx->Extensions.ARB_depth_clamp &&
159 ctx->Extensions.ARB_draw_elements_base_vertex &&
160 ctx->Extensions.ARB_fragment_coord_conventions &&
161 ctx->Extensions.ARB_geometry_shader4 &&
162 ctx->Extensions.EXT_provoking_vertex &&
163 ctx->Extensions.ARB_seamless_cube_map &&
164 ctx->Extensions.ARB_sync &&
165 ctx->Extensions.ARB_texture_multisample &&
166 ctx->Extensions.EXT_vertex_array_bgra);
167 const GLboolean ver_3_3 = (ver_3_2 &&
Marek Olšák97534d92011-11-04 19:12:16 +0100168 ctx->Const.GLSLVersion >= 330 &&
Brian Paul44732102010-07-01 16:30:00 -0600169 ctx->Extensions.ARB_blend_func_extended &&
170 ctx->Extensions.ARB_explicit_attrib_location &&
171 ctx->Extensions.ARB_instanced_arrays &&
172 ctx->Extensions.ARB_occlusion_query2 &&
173 ctx->Extensions.ARB_sampler_objects &&
174 ctx->Extensions.ARB_texture_rgb10_a2ui &&
175 ctx->Extensions.ARB_timer_query &&
176 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
177 ctx->Extensions.EXT_texture_swizzle);
178
179 if (ver_3_3) {
180 major = 3;
181 minor = 3;
182 }
183 else if (ver_3_2) {
184 major = 3;
185 minor = 2;
186 }
187 else if (ver_3_1) {
188 major = 3;
189 minor = 1;
190 }
191 else if (ver_3_0) {
192 major = 3;
193 minor = 0;
194 }
195 else if (ver_2_1) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400196 major = 2;
197 minor = 1;
Brian Paule0b9e332010-01-05 21:23:01 -0700198 }
199 else if (ver_2_0) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400200 major = 2;
201 minor = 0;
Brian Paule0b9e332010-01-05 21:23:01 -0700202 }
203 else if (ver_1_5) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400204 major = 1;
205 minor = 5;
Brian Paule0b9e332010-01-05 21:23:01 -0700206 }
207 else if (ver_1_4) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400208 major = 1;
209 minor = 4;
Brian Paule0b9e332010-01-05 21:23:01 -0700210 }
211 else if (ver_1_3) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400212 major = 1;
213 minor = 3;
Brian Paule0b9e332010-01-05 21:23:01 -0700214 }
215 else {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400216 major = 1;
217 minor = 2;
218 }
219
220 ctx->VersionMajor = major;
221 ctx->VersionMinor = minor;
Chad Versace0527c112011-09-26 11:48:46 -0700222
223 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
224
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400225 ctx->VersionString = (char *) malloc(max);
226 if (ctx->VersionString) {
227 _mesa_snprintf(ctx->VersionString, max,
Ian Romanickde579a12011-03-31 11:42:01 -0700228 "%u.%u Mesa " MESA_VERSION_STRING
229#ifdef MESA_GIT_SHA1
230 " (" MESA_GIT_SHA1 ")"
231#endif
232 ,
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400233 ctx->VersionMajor, ctx->VersionMinor);
Brian Paule0b9e332010-01-05 21:23:01 -0700234 }
235}
236
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400237static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400238compute_version_es1(struct gl_context *ctx)
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400239{
240 static const int max = 100;
241
242 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
Ian Romanick5c4f9142011-08-30 16:51:57 -0700243 const GLboolean ver_1_0 = (ctx->Extensions.ARB_texture_env_combine &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400244 ctx->Extensions.ARB_texture_env_dot3);
245 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
246 const GLboolean ver_1_1 = (ver_1_0 &&
Ian Romanick34eae1c2011-08-30 16:29:52 -0700247 ctx->Extensions.EXT_point_parameters);
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400248
249 if (ver_1_1) {
250 ctx->VersionMajor = 1;
251 ctx->VersionMinor = 1;
252 } else if (ver_1_0) {
253 ctx->VersionMajor = 1;
254 ctx->VersionMinor = 0;
255 } else {
256 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
257 }
258
259 ctx->VersionString = (char *) malloc(max);
260 if (ctx->VersionString) {
261 _mesa_snprintf(ctx->VersionString, max,
Oliver McFaddenbf788062012-05-07 16:01:16 +0300262 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING
263#ifdef MESA_GIT_SHA1
264 " (" MESA_GIT_SHA1 ")"
265#endif
266 ,
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400267 ctx->VersionMinor);
268 }
269}
270
271static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400272compute_version_es2(struct gl_context *ctx)
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400273{
274 static const int max = 100;
275
276 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
Ian Romanick677743f2011-08-30 16:45:50 -0700277 const GLboolean ver_2_0 = (ctx->Extensions.ARB_texture_cube_map &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400278 ctx->Extensions.EXT_blend_color &&
279 ctx->Extensions.EXT_blend_func_separate &&
280 ctx->Extensions.EXT_blend_minmax &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400281 ctx->Extensions.ARB_shader_objects &&
282 ctx->Extensions.ARB_vertex_shader &&
283 ctx->Extensions.ARB_fragment_shader &&
284 ctx->Extensions.ARB_texture_non_power_of_two &&
285 ctx->Extensions.EXT_blend_equation_separate);
286 if (ver_2_0) {
287 ctx->VersionMajor = 2;
288 ctx->VersionMinor = 0;
289 } else {
290 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
291 }
292
293 ctx->VersionString = (char *) malloc(max);
294 if (ctx->VersionString) {
295 _mesa_snprintf(ctx->VersionString, max,
Oliver McFaddenbf788062012-05-07 16:01:16 +0300296 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING
297#ifdef MESA_GIT_SHA1
298 " (" MESA_GIT_SHA1 ")"
299#endif
300 );
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400301 }
302}
Brian Paule0b9e332010-01-05 21:23:01 -0700303
304/**
305 * Set the context's VersionMajor, VersionMinor, VersionString fields.
Chia-I Wu45313562010-09-10 10:31:06 +0800306 * This should only be called once as part of context initialization
307 * or to perform version check for GLX_ARB_create_context_profile.
Brian Paule0b9e332010-01-05 21:23:01 -0700308 */
309void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400310_mesa_compute_version(struct gl_context *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -0700311{
Chia-I Wu45313562010-09-10 10:31:06 +0800312 if (ctx->VersionMajor)
313 return;
314
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400315 switch (ctx->API) {
316 case API_OPENGL:
317 compute_version(ctx);
318 break;
319 case API_OPENGLES:
320 compute_version_es1(ctx);
321 break;
322 case API_OPENGLES2:
323 compute_version_es2(ctx);
324 break;
Brian Paule0b9e332010-01-05 21:23:01 -0700325 }
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400326
Brian Paule0b9e332010-01-05 21:23:01 -0700327}