[MESA]
[reactos.git] / reactos / dll / opengl / mesa / 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 * Return major and minor version numbers.
81 */
82 static void
83 compute_version(struct gl_context *ctx)
84 {
85 GLuint major, minor;
86 static const int max = 100;
87
88 const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp &&
89 ctx->Extensions.ARB_texture_cube_map &&
90 ctx->Extensions.ARB_texture_env_combine &&
91 ctx->Extensions.ARB_texture_env_dot3);
92 const GLboolean ver_1_4 = (ver_1_3 &&
93 ctx->Extensions.ARB_texture_env_crossbar &&
94 ctx->Extensions.ARB_window_pos &&
95 ctx->Extensions.EXT_blend_color &&
96 ctx->Extensions.EXT_blend_func_separate &&
97 ctx->Extensions.EXT_blend_minmax &&
98 ctx->Extensions.EXT_fog_coord &&
99 ctx->Extensions.EXT_point_parameters &&
100 ctx->Extensions.EXT_secondary_color);
101 const GLboolean ver_1_5 = (ver_1_4 &&
102 ctx->Extensions.EXT_shadow_funcs);
103 const GLboolean ver_2_0 = (ver_1_5 &&
104 ctx->Extensions.ARB_point_sprite &&
105 ctx->Extensions.ARB_shader_objects &&
106 ctx->Extensions.ARB_vertex_shader &&
107 ctx->Extensions.ARB_fragment_shader &&
108 ctx->Extensions.ARB_texture_non_power_of_two &&
109 ctx->Extensions.EXT_blend_equation_separate &&
110
111 /* Technically, 2.0 requires the functionality
112 * of the EXT version. Enable 2.0 if either
113 * extension is available, and assume that a
114 * driver that only exposes the ATI extension
115 * will fallback to software when necessary.
116 */
117 (ctx->Extensions.EXT_stencil_two_side
118 || ctx->Extensions.ATI_separate_stencil));
119 const GLboolean ver_2_1 = (ver_2_0 &&
120 ctx->Const.GLSLVersion >= 120 &&
121 ctx->Extensions.EXT_pixel_buffer_object &&
122 ctx->Extensions.EXT_texture_sRGB);
123 const GLboolean ver_3_0 = (ver_2_1 &&
124 ctx->Const.GLSLVersion >= 130 &&
125 ctx->Const.MaxSamples >= 4 &&
126 ctx->Extensions.ARB_color_buffer_float &&
127 ctx->Extensions.ARB_depth_buffer_float &&
128 ctx->Extensions.ARB_half_float_pixel &&
129 ctx->Extensions.ARB_half_float_vertex &&
130 ctx->Extensions.ARB_map_buffer_range &&
131 ctx->Extensions.ARB_shader_texture_lod &&
132 ctx->Extensions.ARB_texture_float &&
133 ctx->Extensions.APPLE_vertex_array_object &&
134 ctx->Extensions.ARB_framebuffer_object &&
135 ctx->Extensions.EXT_framebuffer_sRGB &&
136 ctx->Extensions.EXT_texture_array);
137 const GLboolean ver_3_1 = (ver_3_0 &&
138 ctx->Const.GLSLVersion >= 140 &&
139 ctx->Extensions.ARB_copy_buffer &&
140 ctx->Extensions.ARB_draw_instanced &&
141 ctx->Extensions.ARB_texture_buffer_object &&
142 ctx->Extensions.ARB_uniform_buffer_object &&
143 ctx->Const.MaxVertexTextureImageUnits >= 16);
144
145
146 if (ver_3_1) {
147 major = 3;
148 minor = 1;
149 }
150 else if (ver_3_0) {
151 major = 3;
152 minor = 0;
153 }
154 else if (ver_2_1) {
155 major = 2;
156 minor = 1;
157 }
158 else if (ver_2_0) {
159 major = 2;
160 minor = 0;
161 }
162 else if (ver_1_5) {
163 major = 1;
164 minor = 5;
165 }
166 else if (ver_1_4) {
167 major = 1;
168 minor = 4;
169 }
170 else if (ver_1_3) {
171 major = 1;
172 minor = 3;
173 }
174 else {
175 major = 1;
176 minor = 2;
177 }
178
179 ctx->VersionMajor = major;
180 ctx->VersionMinor = minor;
181
182 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
183
184 ctx->VersionString = (char *) malloc(max);
185 if (ctx->VersionString) {
186 _mesa_snprintf(ctx->VersionString, max,
187 "%u.%u Mesa " MESA_VERSION_STRING
188 #ifdef MESA_GIT_SHA1
189 " (" MESA_GIT_SHA1 ")"
190 #endif
191 ,
192 ctx->VersionMajor, ctx->VersionMinor);
193 }
194 }
195
196 /**
197 * Set the context's VersionMajor, VersionMinor, VersionString fields.
198 * This should only be called once as part of context initialization
199 * or to perform version check for GLX_ARB_create_context_profile.
200 */
201 void
202 _mesa_compute_version(struct gl_context *ctx)
203 {
204 if (ctx->VersionMajor)
205 return;
206
207 compute_version(ctx);
208 }