2 * Mesa 3-D graphics library
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
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".
34 override_version(struct gl_context
*ctx
, GLuint
*major
, GLuint
*minor
)
36 const char *env_var
= "MESA_GL_VERSION_OVERRIDE";
40 version
= getenv(env_var
);
45 n
= sscanf(version
, "%u.%u", major
, minor
);
47 fprintf(stderr
, "error: invalid value for %s: %s\n", env_var
, version
);
53 * Examine enabled GL extensions to determine GL version.
54 * Return major and minor version numbers.
57 compute_version(struct gl_context
*ctx
)
60 static const int max
= 100;
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
);
118 ctx
->VersionMajor
= major
;
119 ctx
->VersionMinor
= minor
;
121 override_version(ctx
, &ctx
->VersionMajor
, &ctx
->VersionMinor
);
123 ctx
->VersionString
= (char *) malloc(max
);
124 if (ctx
->VersionString
) {
125 _mesa_snprintf(ctx
->VersionString
, max
,
126 "%u.%u Mesa " MESA_VERSION_STRING
128 " (" MESA_GIT_SHA1
")"
131 ctx
->VersionMajor
, ctx
->VersionMinor
);
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.
141 _mesa_compute_version(struct gl_context
*ctx
)
143 if (ctx
->VersionMajor
)
146 compute_version(ctx
);