blob: 525d179621b4829cee168b7a734a2b28539b12a7 [file] [log] [blame]
Brian Paule0b9e332010-01-05 21:23:01 -07001/*
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 */
34static void
Kristian Høgsberg29107d42010-04-21 16:14:18 -040035compute_version(GLcontext *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -070036{
Kristian Høgsberg29107d42010-04-21 16:14:18 -040037 GLuint major, minor;
38 static const int max = 100;
39
Brian Paule0b9e332010-01-05 21:23:01 -070040 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);
Brian Paul44732102010-07-01 16:30:00 -060090 const GLboolean ver_3_0 = (ver_2_1 &&
91 ctx->Extensions.ARB_half_float_pixel &&
92 ctx->Extensions.ARB_map_buffer_range &&
93 ctx->Extensions.ARB_texture_float &&
94 ctx->Extensions.APPLE_vertex_array_object &&
95 ctx->Extensions.EXT_draw_buffers2 &&
96 ctx->Extensions.EXT_framebuffer_blit &&
97 ctx->Extensions.EXT_framebuffer_multisample &&
98 ctx->Extensions.EXT_framebuffer_object &&
99 ctx->Extensions.EXT_framebuffer_sRGB &&
100 ctx->Extensions.EXT_packed_depth_stencil &&
101 ctx->Extensions.EXT_packed_float &&
102 ctx->Extensions.EXT_shared_exponent &&
103 ctx->Extensions.EXT_texture_array &&
104 ctx->Extensions.EXT_texture_compression_rgtc &&
105 ctx->Extensions.EXT_texture_integer &&
106 ctx->Extensions.EXT_transform_feedback &&
107 ctx->Extensions.NV_conditional_render);
108 const GLboolean ver_3_1 = (ver_3_0 &&
109 ctx->Extensions.ARB_copy_buffer &&
110 ctx->Extensions.ARB_draw_instanced &&
111 ctx->Extensions.ARB_texture_buffer_object &&
112 ctx->Extensions.ARB_uniform_buffer_object &&
113 ctx->Extensions.NV_primitive_restart &&
114 ctx->Extensions.NV_texture_rectangle &&
115 ctx->Const.MaxVertexTextureImageUnits >= 16);
116 const GLboolean ver_3_2 = (ver_3_1 &&
117 ctx->Extensions.ARB_depth_clamp &&
118 ctx->Extensions.ARB_draw_elements_base_vertex &&
119 ctx->Extensions.ARB_fragment_coord_conventions &&
120 ctx->Extensions.ARB_geometry_shader4 &&
121 ctx->Extensions.EXT_provoking_vertex &&
122 ctx->Extensions.ARB_seamless_cube_map &&
123 ctx->Extensions.ARB_sync &&
124 ctx->Extensions.ARB_texture_multisample &&
125 ctx->Extensions.EXT_vertex_array_bgra);
126 const GLboolean ver_3_3 = (ver_3_2 &&
127 ctx->Extensions.ARB_blend_func_extended &&
128 ctx->Extensions.ARB_explicit_attrib_location &&
129 ctx->Extensions.ARB_instanced_arrays &&
130 ctx->Extensions.ARB_occlusion_query2 &&
131 ctx->Extensions.ARB_sampler_objects &&
132 ctx->Extensions.ARB_texture_rgb10_a2ui &&
133 ctx->Extensions.ARB_timer_query &&
134 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
135 ctx->Extensions.EXT_texture_swizzle);
136
137 if (ver_3_3) {
138 major = 3;
139 minor = 3;
140 }
141 else if (ver_3_2) {
142 major = 3;
143 minor = 2;
144 }
145 else if (ver_3_1) {
146 major = 3;
147 minor = 1;
148 }
149 else if (ver_3_0) {
150 major = 3;
151 minor = 0;
152 }
153 else if (ver_2_1) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400154 major = 2;
155 minor = 1;
Brian Paule0b9e332010-01-05 21:23:01 -0700156 }
157 else if (ver_2_0) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400158 major = 2;
159 minor = 0;
Brian Paule0b9e332010-01-05 21:23:01 -0700160 }
161 else if (ver_1_5) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400162 major = 1;
163 minor = 5;
Brian Paule0b9e332010-01-05 21:23:01 -0700164 }
165 else if (ver_1_4) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400166 major = 1;
167 minor = 4;
Brian Paule0b9e332010-01-05 21:23:01 -0700168 }
169 else if (ver_1_3) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400170 major = 1;
171 minor = 3;
Brian Paule0b9e332010-01-05 21:23:01 -0700172 }
173 else {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400174 major = 1;
175 minor = 2;
176 }
177
178 ctx->VersionMajor = major;
179 ctx->VersionMinor = minor;
180 ctx->VersionString = (char *) malloc(max);
181 if (ctx->VersionString) {
182 _mesa_snprintf(ctx->VersionString, max,
183 "%u.%u Mesa " MESA_VERSION_STRING,
184 ctx->VersionMajor, ctx->VersionMinor);
Brian Paule0b9e332010-01-05 21:23:01 -0700185 }
186}
187
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400188static void
189compute_version_es1(GLcontext *ctx)
190{
191 static const int max = 100;
192
193 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
194 const GLboolean ver_1_0 = (ctx->Extensions.ARB_multisample &&
195 ctx->Extensions.ARB_multitexture &&
196 ctx->Extensions.ARB_texture_compression &&
197 ctx->Extensions.EXT_texture_env_add &&
198 ctx->Extensions.ARB_texture_env_combine &&
199 ctx->Extensions.ARB_texture_env_dot3);
200 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
201 const GLboolean ver_1_1 = (ver_1_0 &&
202 ctx->Extensions.EXT_point_parameters &&
203 ctx->Extensions.SGIS_generate_mipmap &&
204 ctx->Extensions.ARB_vertex_buffer_object);
205
206 if (ver_1_1) {
207 ctx->VersionMajor = 1;
208 ctx->VersionMinor = 1;
209 } else if (ver_1_0) {
210 ctx->VersionMajor = 1;
211 ctx->VersionMinor = 0;
212 } else {
213 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
214 }
215
216 ctx->VersionString = (char *) malloc(max);
217 if (ctx->VersionString) {
218 _mesa_snprintf(ctx->VersionString, max,
219 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING,
220 ctx->VersionMinor);
221 }
222}
223
224static void
225compute_version_es2(GLcontext *ctx)
226{
227 static const int max = 100;
228
229 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
230 const GLboolean ver_2_0 = (ctx->Extensions.ARB_multisample &&
231 ctx->Extensions.ARB_multitexture &&
232 ctx->Extensions.ARB_texture_compression &&
233 ctx->Extensions.ARB_texture_cube_map &&
234 ctx->Extensions.ARB_texture_mirrored_repeat &&
235 ctx->Extensions.EXT_blend_color &&
236 ctx->Extensions.EXT_blend_func_separate &&
237 ctx->Extensions.EXT_blend_minmax &&
238 ctx->Extensions.EXT_blend_subtract &&
239 ctx->Extensions.EXT_stencil_wrap &&
240 ctx->Extensions.ARB_vertex_buffer_object &&
241 ctx->Extensions.ARB_shader_objects &&
242 ctx->Extensions.ARB_vertex_shader &&
243 ctx->Extensions.ARB_fragment_shader &&
244 ctx->Extensions.ARB_texture_non_power_of_two &&
245 ctx->Extensions.EXT_blend_equation_separate);
246 if (ver_2_0) {
247 ctx->VersionMajor = 2;
248 ctx->VersionMinor = 0;
249 } else {
250 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
251 }
252
253 ctx->VersionString = (char *) malloc(max);
254 if (ctx->VersionString) {
255 _mesa_snprintf(ctx->VersionString, max,
256 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING);
257 }
258}
Brian Paule0b9e332010-01-05 21:23:01 -0700259
260/**
261 * Set the context's VersionMajor, VersionMinor, VersionString fields.
262 * This should only be called once as part of context initialization.
263 */
264void
265_mesa_compute_version(GLcontext *ctx)
266{
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400267 switch (ctx->API) {
268 case API_OPENGL:
269 compute_version(ctx);
270 break;
271 case API_OPENGLES:
272 compute_version_es1(ctx);
273 break;
274 case API_OPENGLES2:
275 compute_version_es2(ctx);
276 break;
Brian Paule0b9e332010-01-05 21:23:01 -0700277 }
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400278
Brian Paule0b9e332010-01-05 21:23:01 -0700279}