[PROPSYS]
[reactos.git] / reactos / dll / opengl / 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 #include <precomp.h>
25
26 #include "git_sha1.h"
27
28 /**
29 * Override the context's GL version if the environment variable
30 * MESA_GL_VERSION_OVERRIDE is set. Valid values of MESA_GL_VERSION_OVERRIDE
31 * are point-separated version numbers, such as "3.0".
32 */
33 static void
34 override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
35 {
36 const char *env_var = "MESA_GL_VERSION_OVERRIDE";
37 const char *version;
38 int n;
39
40 version = getenv(env_var);
41 if (!version) {
42 return;
43 }
44
45 n = sscanf(version, "%u.%u", major, minor);
46 if (n != 2) {
47 fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
48 return;
49 }
50 }
51
52 /**
53 * Examine enabled GL extensions to determine GL version.
54 * Return major and minor version numbers.
55 */
56 static void
57 compute_version(struct gl_context *ctx)
58 {
59 GLuint major, minor;
60 static const int max = 100;
61
62 const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_cube_map &&
63 ctx->Extensions.ARB_texture_env_combine &&
64 ctx->Extensions.ARB_texture_env_dot3);
65 const GLboolean ver_1_4 = (ver_1_3 &&
66 ctx->Extensions.ARB_texture_env_crossbar &&
67 ctx->Extensions.ARB_window_pos &&
68 ctx->Extensions.EXT_blend_color &&
69 ctx->Extensions.EXT_blend_func_separate &&
70 ctx->Extensions.EXT_blend_minmax &&
71 ctx->Extensions.EXT_fog_coord &&
72 ctx->Extensions.EXT_point_parameters &&
73 ctx->Extensions.EXT_secondary_color);
74 const GLboolean ver_1_5 = (ver_1_4 &&
75 ctx->Extensions.EXT_shadow_funcs);
76 const GLboolean ver_2_0 = (ver_1_5 &&
77 ctx->Extensions.ARB_point_sprite &&
78 ctx->Extensions.ARB_texture_non_power_of_two &&
79 ctx->Extensions.EXT_blend_equation_separate);
80 const GLboolean ver_2_1 = (ver_2_0);
81 const GLboolean ver_3_0 = (ver_2_1 &&
82 ctx->Extensions.ARB_half_float_pixel &&
83 ctx->Extensions.ARB_half_float_vertex &&
84 ctx->Extensions.ARB_map_buffer_range &&
85 ctx->Extensions.ARB_texture_float &&
86 ctx->Extensions.APPLE_vertex_array_object);
87
88
89 if (ver_3_0) {
90 major = 3;
91 minor = 0;
92 }
93 else if (ver_2_1) {
94 major = 2;
95 minor = 1;
96 }
97 else if (ver_2_0) {
98 major = 2;
99 minor = 0;
100 }
101 else if (ver_1_5) {
102 major = 1;
103 minor = 5;
104 }
105 else if (ver_1_4) {
106 major = 1;
107 minor = 4;
108 }
109 else if (ver_1_3) {
110 major = 1;
111 minor = 3;
112 }
113 else {
114 major = 1;
115 minor = 2;
116 }
117
118 ctx->VersionMajor = major;
119 ctx->VersionMinor = minor;
120
121 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
122
123 ctx->VersionString = (char *) malloc(max);
124 if (ctx->VersionString) {
125 _mesa_snprintf(ctx->VersionString, max,
126 "%u.%u Mesa " MESA_VERSION_STRING
127 #ifdef MESA_GIT_SHA1
128 " (" MESA_GIT_SHA1 ")"
129 #endif
130 ,
131 ctx->VersionMajor, ctx->VersionMinor);
132 }
133 }
134
135 /**
136 * Set the context's VersionMajor, VersionMinor, VersionString fields.
137 * This should only be called once as part of context initialization
138 * or to perform version check for GLX_ARB_create_context_profile.
139 */
140 void
141 _mesa_compute_version(struct gl_context *ctx)
142 {
143 if (ctx->VersionMajor)
144 return;
145
146 compute_version(ctx);
147 }