mesa: Make ARB_sampler_objects mandatory
[mesa.git] / src / mesa / main / version.c
1 /*
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
25 #include "imports.h"
26 #include "mtypes.h"
27 #include "version.h"
28 #include "git_sha1.h"
29
30 /**
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 */
35 static void
36 override_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;
41
42 version = getenv(env_var);
43 if (!version) {
44 return;
45 }
46
47 n = sscanf(version, "%u.%u", major, minor);
48 if (n != 2) {
49 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
50 return;
51 }
52 }
53
54 /**
55 * 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 */
59 void
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
71 n = sscanf(version, "%u", &ctx->Const.GLSLVersion);
72 if (n != 1) {
73 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
74 return;
75 }
76 }
77
78 /**
79 * Examine enabled GL extensions to determine GL version.
80 */
81 static void
82 compute_version(struct gl_context *ctx)
83 {
84 GLuint major, minor;
85 static const int max = 100;
86
87 const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp &&
88 ctx->Extensions.ARB_texture_cube_map &&
89 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 &&
95 ctx->Extensions.ARB_window_pos &&
96 ctx->Extensions.EXT_blend_color &&
97 ctx->Extensions.EXT_blend_func_separate &&
98 ctx->Extensions.EXT_blend_minmax &&
99 ctx->Extensions.EXT_fog_coord &&
100 ctx->Extensions.EXT_point_parameters &&
101 ctx->Extensions.EXT_secondary_color);
102 const GLboolean ver_1_5 = (ver_1_4 &&
103 ctx->Extensions.ARB_occlusion_query &&
104 ctx->Extensions.EXT_shadow_funcs);
105 const GLboolean ver_2_0 = (ver_1_5 &&
106 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 &&
122 ctx->Const.GLSLVersion >= 120 &&
123 ctx->Extensions.EXT_pixel_buffer_object &&
124 ctx->Extensions.EXT_texture_sRGB);
125 const GLboolean ver_3_0 = (ver_2_1 &&
126 ctx->Const.GLSLVersion >= 130 &&
127 ctx->Const.MaxSamples >= 4 &&
128 ctx->Extensions.ARB_color_buffer_float &&
129 ctx->Extensions.ARB_depth_buffer_float &&
130 ctx->Extensions.ARB_half_float_pixel &&
131 ctx->Extensions.ARB_half_float_vertex &&
132 ctx->Extensions.ARB_map_buffer_range &&
133 ctx->Extensions.ARB_shader_texture_lod &&
134 ctx->Extensions.ARB_texture_float &&
135 ctx->Extensions.ARB_texture_rg &&
136 ctx->Extensions.ARB_texture_compression_rgtc &&
137 ctx->Extensions.APPLE_vertex_array_object &&
138 ctx->Extensions.EXT_draw_buffers2 &&
139 ctx->Extensions.ARB_framebuffer_object &&
140 ctx->Extensions.EXT_framebuffer_sRGB &&
141 ctx->Extensions.EXT_packed_float &&
142 ctx->Extensions.EXT_texture_array &&
143 ctx->Extensions.EXT_texture_shared_exponent &&
144 ctx->Extensions.EXT_transform_feedback &&
145 ctx->Extensions.NV_conditional_render);
146 const GLboolean ver_3_1 = (ver_3_0 &&
147 ctx->Const.GLSLVersion >= 140 &&
148 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 &&
152 ctx->Extensions.EXT_texture_snorm &&
153 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 &&
157 ctx->Const.GLSLVersion >= 150 &&
158 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 &&
168 ctx->Const.GLSLVersion >= 330 &&
169 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_shader_bit_encoding &&
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 /* ARB_sampler_objects is always enabled in mesa */
179
180 if (ver_3_3) {
181 major = 3;
182 minor = 3;
183 }
184 else if (ver_3_2) {
185 major = 3;
186 minor = 2;
187 }
188 else if (ver_3_1) {
189 major = 3;
190 minor = 1;
191 }
192 else if (ver_3_0) {
193 major = 3;
194 minor = 0;
195 }
196 else if (ver_2_1) {
197 major = 2;
198 minor = 1;
199 }
200 else if (ver_2_0) {
201 major = 2;
202 minor = 0;
203 }
204 else if (ver_1_5) {
205 major = 1;
206 minor = 5;
207 }
208 else if (ver_1_4) {
209 major = 1;
210 minor = 4;
211 }
212 else if (ver_1_3) {
213 major = 1;
214 minor = 3;
215 }
216 else {
217 major = 1;
218 minor = 2;
219 }
220
221 ctx->VersionMajor = major;
222 ctx->VersionMinor = minor;
223
224 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
225
226 ctx->VersionString = (char *) malloc(max);
227 if (ctx->VersionString) {
228 _mesa_snprintf(ctx->VersionString, max,
229 "%u.%u Mesa " MESA_VERSION_STRING
230 #ifdef MESA_GIT_SHA1
231 " (" MESA_GIT_SHA1 ")"
232 #endif
233 ,
234 ctx->VersionMajor, ctx->VersionMinor);
235 }
236 }
237
238 static void
239 compute_version_es1(struct gl_context *ctx)
240 {
241 static const int max = 100;
242
243 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
244 const GLboolean ver_1_0 = (ctx->Extensions.ARB_texture_env_combine &&
245 ctx->Extensions.ARB_texture_env_dot3);
246 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
247 const GLboolean ver_1_1 = (ver_1_0 &&
248 ctx->Extensions.EXT_point_parameters);
249
250 if (ver_1_1) {
251 ctx->VersionMajor = 1;
252 ctx->VersionMinor = 1;
253 } else if (ver_1_0) {
254 ctx->VersionMajor = 1;
255 ctx->VersionMinor = 0;
256 } else {
257 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
258 }
259
260 ctx->VersionString = (char *) malloc(max);
261 if (ctx->VersionString) {
262 _mesa_snprintf(ctx->VersionString, max,
263 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING
264 #ifdef MESA_GIT_SHA1
265 " (" MESA_GIT_SHA1 ")"
266 #endif
267 ,
268 ctx->VersionMinor);
269 }
270 }
271
272 static void
273 compute_version_es2(struct gl_context *ctx)
274 {
275 static const int max = 100;
276
277 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
278 const GLboolean ver_2_0 = (ctx->Extensions.ARB_texture_cube_map &&
279 ctx->Extensions.EXT_blend_color &&
280 ctx->Extensions.EXT_blend_func_separate &&
281 ctx->Extensions.EXT_blend_minmax &&
282 ctx->Extensions.ARB_shader_objects &&
283 ctx->Extensions.ARB_vertex_shader &&
284 ctx->Extensions.ARB_fragment_shader &&
285 ctx->Extensions.ARB_texture_non_power_of_two &&
286 ctx->Extensions.EXT_blend_equation_separate);
287 if (ver_2_0) {
288 ctx->VersionMajor = 2;
289 ctx->VersionMinor = 0;
290 } else {
291 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
292 }
293
294 ctx->VersionString = (char *) malloc(max);
295 if (ctx->VersionString) {
296 _mesa_snprintf(ctx->VersionString, max,
297 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING
298 #ifdef MESA_GIT_SHA1
299 " (" MESA_GIT_SHA1 ")"
300 #endif
301 );
302 }
303 }
304
305 /**
306 * Set the context's VersionMajor, VersionMinor, VersionString fields.
307 * This should only be called once as part of context initialization
308 * or to perform version check for GLX_ARB_create_context_profile.
309 */
310 void
311 _mesa_compute_version(struct gl_context *ctx)
312 {
313 if (ctx->VersionMajor)
314 return;
315
316 switch (ctx->API) {
317 case API_OPENGL:
318 case API_OPENGL_CORE:
319 compute_version(ctx);
320 break;
321 case API_OPENGLES:
322 compute_version_es1(ctx);
323 break;
324 case API_OPENGLES2:
325 compute_version_es2(ctx);
326 break;
327 }
328
329 }