dea3019d0bc01147c478a30639a70c6f0b9e4ae6
[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 "context.h"
26 #include "version.h"
27
28
29
30 /**
31 * Examine enabled GL extensions to determine GL version.
32 * Return major and minor version numbers.
33 */
34 static void
35 compute_version(GLcontext *ctx)
36 {
37 GLuint major, minor;
38 static const int max = 100;
39
40 const GLboolean ver_1_3 = (ctx->Extensions.ARB_multisample &&
41 ctx->Extensions.ARB_multitexture &&
42 ctx->Extensions.ARB_texture_border_clamp &&
43 ctx->Extensions.ARB_texture_compression &&
44 ctx->Extensions.ARB_texture_cube_map &&
45 ctx->Extensions.EXT_texture_env_add &&
46 ctx->Extensions.ARB_texture_env_combine &&
47 ctx->Extensions.ARB_texture_env_dot3);
48 const GLboolean ver_1_4 = (ver_1_3 &&
49 ctx->Extensions.ARB_depth_texture &&
50 ctx->Extensions.ARB_shadow &&
51 ctx->Extensions.ARB_texture_env_crossbar &&
52 ctx->Extensions.ARB_texture_mirrored_repeat &&
53 ctx->Extensions.ARB_window_pos &&
54 ctx->Extensions.EXT_blend_color &&
55 ctx->Extensions.EXT_blend_func_separate &&
56 ctx->Extensions.EXT_blend_minmax &&
57 ctx->Extensions.EXT_blend_subtract &&
58 ctx->Extensions.EXT_fog_coord &&
59 ctx->Extensions.EXT_multi_draw_arrays &&
60 ctx->Extensions.EXT_point_parameters &&
61 ctx->Extensions.EXT_secondary_color &&
62 ctx->Extensions.EXT_stencil_wrap &&
63 ctx->Extensions.EXT_texture_lod_bias &&
64 ctx->Extensions.SGIS_generate_mipmap);
65 const GLboolean ver_1_5 = (ver_1_4 &&
66 ctx->Extensions.ARB_occlusion_query &&
67 ctx->Extensions.ARB_vertex_buffer_object &&
68 ctx->Extensions.EXT_shadow_funcs);
69 const GLboolean ver_2_0 = (ver_1_5 &&
70 ctx->Extensions.ARB_draw_buffers &&
71 ctx->Extensions.ARB_point_sprite &&
72 ctx->Extensions.ARB_shader_objects &&
73 ctx->Extensions.ARB_vertex_shader &&
74 ctx->Extensions.ARB_fragment_shader &&
75 ctx->Extensions.ARB_texture_non_power_of_two &&
76 ctx->Extensions.EXT_blend_equation_separate &&
77
78 /* Technically, 2.0 requires the functionality
79 * of the EXT version. Enable 2.0 if either
80 * extension is available, and assume that a
81 * driver that only exposes the ATI extension
82 * will fallback to software when necessary.
83 */
84 (ctx->Extensions.EXT_stencil_two_side
85 || ctx->Extensions.ATI_separate_stencil));
86 const GLboolean ver_2_1 = (ver_2_0 &&
87 ctx->Extensions.ARB_shading_language_120 &&
88 ctx->Extensions.EXT_pixel_buffer_object &&
89 ctx->Extensions.EXT_texture_sRGB);
90 if (ver_2_1) {
91 major = 2;
92 minor = 1;
93 }
94 else if (ver_2_0) {
95 major = 2;
96 minor = 0;
97 }
98 else if (ver_1_5) {
99 major = 1;
100 minor = 5;
101 }
102 else if (ver_1_4) {
103 major = 1;
104 minor = 4;
105 }
106 else if (ver_1_3) {
107 major = 1;
108 minor = 3;
109 }
110 else {
111 major = 1;
112 minor = 2;
113 }
114
115 ctx->VersionMajor = major;
116 ctx->VersionMinor = minor;
117 ctx->VersionString = (char *) malloc(max);
118 if (ctx->VersionString) {
119 _mesa_snprintf(ctx->VersionString, max,
120 "%u.%u Mesa " MESA_VERSION_STRING,
121 ctx->VersionMajor, ctx->VersionMinor);
122 }
123 }
124
125 static void
126 compute_version_es1(GLcontext *ctx)
127 {
128 static const int max = 100;
129
130 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
131 const GLboolean ver_1_0 = (ctx->Extensions.ARB_multisample &&
132 ctx->Extensions.ARB_multitexture &&
133 ctx->Extensions.ARB_texture_compression &&
134 ctx->Extensions.EXT_texture_env_add &&
135 ctx->Extensions.ARB_texture_env_combine &&
136 ctx->Extensions.ARB_texture_env_dot3);
137 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
138 const GLboolean ver_1_1 = (ver_1_0 &&
139 ctx->Extensions.EXT_point_parameters &&
140 ctx->Extensions.SGIS_generate_mipmap &&
141 ctx->Extensions.ARB_vertex_buffer_object);
142
143 if (ver_1_1) {
144 ctx->VersionMajor = 1;
145 ctx->VersionMinor = 1;
146 } else if (ver_1_0) {
147 ctx->VersionMajor = 1;
148 ctx->VersionMinor = 0;
149 } else {
150 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
151 }
152
153 ctx->VersionString = (char *) malloc(max);
154 if (ctx->VersionString) {
155 _mesa_snprintf(ctx->VersionString, max,
156 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING,
157 ctx->VersionMinor);
158 }
159 }
160
161 static void
162 compute_version_es2(GLcontext *ctx)
163 {
164 static const int max = 100;
165
166 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
167 const GLboolean ver_2_0 = (ctx->Extensions.ARB_multisample &&
168 ctx->Extensions.ARB_multitexture &&
169 ctx->Extensions.ARB_texture_compression &&
170 ctx->Extensions.ARB_texture_cube_map &&
171 ctx->Extensions.ARB_texture_mirrored_repeat &&
172 ctx->Extensions.EXT_blend_color &&
173 ctx->Extensions.EXT_blend_func_separate &&
174 ctx->Extensions.EXT_blend_minmax &&
175 ctx->Extensions.EXT_blend_subtract &&
176 ctx->Extensions.EXT_stencil_wrap &&
177 ctx->Extensions.ARB_vertex_buffer_object &&
178 ctx->Extensions.ARB_shader_objects &&
179 ctx->Extensions.ARB_vertex_shader &&
180 ctx->Extensions.ARB_fragment_shader &&
181 ctx->Extensions.ARB_texture_non_power_of_two &&
182 ctx->Extensions.EXT_blend_equation_separate);
183 if (ver_2_0) {
184 ctx->VersionMajor = 2;
185 ctx->VersionMinor = 0;
186 } else {
187 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
188 }
189
190 ctx->VersionString = (char *) malloc(max);
191 if (ctx->VersionString) {
192 _mesa_snprintf(ctx->VersionString, max,
193 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING);
194 }
195 }
196
197 /**
198 * Set the context's VersionMajor, VersionMinor, VersionString fields.
199 * This should only be called once as part of context initialization.
200 */
201 void
202 _mesa_compute_version(GLcontext *ctx)
203 {
204 switch (ctx->API) {
205 case API_OPENGL:
206 compute_version(ctx);
207 break;
208 case API_OPENGLES:
209 compute_version_es1(ctx);
210 break;
211 case API_OPENGLES2:
212 compute_version_es2(ctx);
213 break;
214 }
215
216 }