Sync with trunk r63647.
[reactos.git] / 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 /* report openGL 1.1 */
60 ctx->VersionMajor = 1;
61 ctx->VersionMinor = 1;
62
63 override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
64
65 ctx->VersionString = (char *) malloc(20);
66 if (ctx->VersionString) {
67 _mesa_snprintf(ctx->VersionString, 20,
68 "%u.%u Mesa " MESA_VERSION_STRING
69 #ifdef MESA_GIT_SHA1
70 " (" MESA_GIT_SHA1 ")"
71 #endif
72 ,
73 ctx->VersionMajor, ctx->VersionMinor);
74 }
75 }
76
77 /**
78 * Set the context's VersionMajor, VersionMinor, VersionString fields.
79 * This should only be called once as part of context initialization
80 * or to perform version check for GLX_ARB_create_context_profile.
81 */
82 void
83 _mesa_compute_version(struct gl_context *ctx)
84 {
85 if (ctx->VersionMajor)
86 return;
87
88 compute_version(ctx);
89 }