blob: 384281479a315cd5292daadecefd29adb997372d [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
Vinson Leeab564b52011-01-06 00:45:08 -080025#include "imports.h"
Vinson Lee0117da42011-01-05 23:11:54 -080026#include "mtypes.h"
Brian Paule0b9e332010-01-05 21:23:01 -070027#include "version.h"
Ian Romanickde579a12011-03-31 11:42:01 -070028#include "git_sha1.h"
Brian Paule0b9e332010-01-05 21:23:01 -070029
30
31
32/**
33 * Examine enabled GL extensions to determine GL version.
34 * Return major and minor version numbers.
35 */
36static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -040037compute_version(struct gl_context *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -070038{
Kristian Høgsberg29107d42010-04-21 16:14:18 -040039 GLuint major, minor;
40 static const int max = 100;
41
Ian Romanick34eae1c2011-08-30 16:29:52 -070042 const GLboolean ver_1_3 = (ctx->Extensions.ARB_multitexture &&
Brian Paule0b9e332010-01-05 21:23:01 -070043 ctx->Extensions.ARB_texture_border_clamp &&
Brian Paule0b9e332010-01-05 21:23:01 -070044 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 &&
Brian Paule0b9e332010-01-05 21:23:01 -070059 ctx->Extensions.EXT_point_parameters &&
60 ctx->Extensions.EXT_secondary_color &&
61 ctx->Extensions.EXT_stencil_wrap &&
Ian Romanick34eae1c2011-08-30 16:29:52 -070062 ctx->Extensions.EXT_texture_lod_bias);
Brian Paule0b9e332010-01-05 21:23:01 -070063 const GLboolean ver_1_5 = (ver_1_4 &&
64 ctx->Extensions.ARB_occlusion_query &&
Brian Paule0b9e332010-01-05 21:23:01 -070065 ctx->Extensions.EXT_shadow_funcs);
66 const GLboolean ver_2_0 = (ver_1_5 &&
67 ctx->Extensions.ARB_draw_buffers &&
68 ctx->Extensions.ARB_point_sprite &&
69 ctx->Extensions.ARB_shader_objects &&
70 ctx->Extensions.ARB_vertex_shader &&
71 ctx->Extensions.ARB_fragment_shader &&
72 ctx->Extensions.ARB_texture_non_power_of_two &&
73 ctx->Extensions.EXT_blend_equation_separate &&
74
75 /* Technically, 2.0 requires the functionality
76 * of the EXT version. Enable 2.0 if either
77 * extension is available, and assume that a
78 * driver that only exposes the ATI extension
79 * will fallback to software when necessary.
80 */
81 (ctx->Extensions.EXT_stencil_two_side
82 || ctx->Extensions.ATI_separate_stencil));
83 const GLboolean ver_2_1 = (ver_2_0 &&
Brian Paule7087172010-09-21 18:13:02 -060084 ctx->Const.GLSLVersion >= 120 &&
Brian Paule0b9e332010-01-05 21:23:01 -070085 ctx->Extensions.EXT_pixel_buffer_object &&
86 ctx->Extensions.EXT_texture_sRGB);
Brian Paul44732102010-07-01 16:30:00 -060087 const GLboolean ver_3_0 = (ver_2_1 &&
Marek Olšáke5c6a922011-02-15 23:30:23 +010088 ctx->Extensions.ARB_color_buffer_float &&
89 ctx->Extensions.ARB_depth_buffer_float &&
Brian Paul44732102010-07-01 16:30:00 -060090 ctx->Extensions.ARB_half_float_pixel &&
91 ctx->Extensions.ARB_map_buffer_range &&
92 ctx->Extensions.ARB_texture_float &&
Brian Paul6988f652010-07-07 20:26:33 -060093 ctx->Extensions.ARB_texture_rg &&
Ian Romanicke2a054b2010-10-01 16:07:28 -070094 ctx->Extensions.ARB_texture_compression_rgtc &&
Brian Paul44732102010-07-01 16:30:00 -060095 ctx->Extensions.APPLE_vertex_array_object &&
96 ctx->Extensions.EXT_draw_buffers2 &&
97 ctx->Extensions.EXT_framebuffer_blit &&
98 ctx->Extensions.EXT_framebuffer_multisample &&
99 ctx->Extensions.EXT_framebuffer_object &&
100 ctx->Extensions.EXT_framebuffer_sRGB &&
101 ctx->Extensions.EXT_packed_depth_stencil &&
102 ctx->Extensions.EXT_packed_float &&
Brian Paul44732102010-07-01 16:30:00 -0600103 ctx->Extensions.EXT_texture_array &&
Brian Paul44732102010-07-01 16:30:00 -0600104 ctx->Extensions.EXT_texture_integer &&
Brian Paul6988f652010-07-07 20:26:33 -0600105 ctx->Extensions.EXT_texture_shared_exponent &&
Brian Paul44732102010-07-01 16:30:00 -0600106 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 &&
Marek Olšák0be36992011-03-18 13:44:51 +0100113 ctx->Extensions.EXT_texture_snorm &&
Brian Paul44732102010-07-01 16:30:00 -0600114 ctx->Extensions.NV_primitive_restart &&
115 ctx->Extensions.NV_texture_rectangle &&
116 ctx->Const.MaxVertexTextureImageUnits >= 16);
117 const GLboolean ver_3_2 = (ver_3_1 &&
118 ctx->Extensions.ARB_depth_clamp &&
119 ctx->Extensions.ARB_draw_elements_base_vertex &&
120 ctx->Extensions.ARB_fragment_coord_conventions &&
121 ctx->Extensions.ARB_geometry_shader4 &&
122 ctx->Extensions.EXT_provoking_vertex &&
123 ctx->Extensions.ARB_seamless_cube_map &&
124 ctx->Extensions.ARB_sync &&
125 ctx->Extensions.ARB_texture_multisample &&
126 ctx->Extensions.EXT_vertex_array_bgra);
127 const GLboolean ver_3_3 = (ver_3_2 &&
128 ctx->Extensions.ARB_blend_func_extended &&
129 ctx->Extensions.ARB_explicit_attrib_location &&
130 ctx->Extensions.ARB_instanced_arrays &&
131 ctx->Extensions.ARB_occlusion_query2 &&
132 ctx->Extensions.ARB_sampler_objects &&
133 ctx->Extensions.ARB_texture_rgb10_a2ui &&
134 ctx->Extensions.ARB_timer_query &&
135 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
136 ctx->Extensions.EXT_texture_swizzle);
137
138 if (ver_3_3) {
139 major = 3;
140 minor = 3;
141 }
142 else if (ver_3_2) {
143 major = 3;
144 minor = 2;
145 }
146 else if (ver_3_1) {
147 major = 3;
148 minor = 1;
149 }
150 else if (ver_3_0) {
151 major = 3;
152 minor = 0;
153 }
154 else if (ver_2_1) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400155 major = 2;
156 minor = 1;
Brian Paule0b9e332010-01-05 21:23:01 -0700157 }
158 else if (ver_2_0) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400159 major = 2;
160 minor = 0;
Brian Paule0b9e332010-01-05 21:23:01 -0700161 }
162 else if (ver_1_5) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400163 major = 1;
164 minor = 5;
Brian Paule0b9e332010-01-05 21:23:01 -0700165 }
166 else if (ver_1_4) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400167 major = 1;
168 minor = 4;
Brian Paule0b9e332010-01-05 21:23:01 -0700169 }
170 else if (ver_1_3) {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400171 major = 1;
172 minor = 3;
Brian Paule0b9e332010-01-05 21:23:01 -0700173 }
174 else {
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400175 major = 1;
176 minor = 2;
177 }
178
179 ctx->VersionMajor = major;
180 ctx->VersionMinor = minor;
181 ctx->VersionString = (char *) malloc(max);
182 if (ctx->VersionString) {
183 _mesa_snprintf(ctx->VersionString, max,
Ian Romanickde579a12011-03-31 11:42:01 -0700184 "%u.%u Mesa " MESA_VERSION_STRING
185#ifdef MESA_GIT_SHA1
186 " (" MESA_GIT_SHA1 ")"
187#endif
188 ,
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400189 ctx->VersionMajor, ctx->VersionMinor);
Brian Paule0b9e332010-01-05 21:23:01 -0700190 }
191}
192
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400193static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400194compute_version_es1(struct gl_context *ctx)
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400195{
196 static const int max = 100;
197
198 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
Ian Romanick34eae1c2011-08-30 16:29:52 -0700199 const GLboolean ver_1_0 = (ctx->Extensions.ARB_multitexture &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400200 ctx->Extensions.EXT_texture_env_add &&
201 ctx->Extensions.ARB_texture_env_combine &&
202 ctx->Extensions.ARB_texture_env_dot3);
203 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
204 const GLboolean ver_1_1 = (ver_1_0 &&
Ian Romanick34eae1c2011-08-30 16:29:52 -0700205 ctx->Extensions.EXT_point_parameters);
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400206
207 if (ver_1_1) {
208 ctx->VersionMajor = 1;
209 ctx->VersionMinor = 1;
210 } else if (ver_1_0) {
211 ctx->VersionMajor = 1;
212 ctx->VersionMinor = 0;
213 } else {
214 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
215 }
216
217 ctx->VersionString = (char *) malloc(max);
218 if (ctx->VersionString) {
219 _mesa_snprintf(ctx->VersionString, max,
220 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING,
221 ctx->VersionMinor);
222 }
223}
224
225static void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400226compute_version_es2(struct gl_context *ctx)
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400227{
228 static const int max = 100;
229
230 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
Ian Romanick34eae1c2011-08-30 16:29:52 -0700231 const GLboolean ver_2_0 = (ctx->Extensions.ARB_multitexture &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400232 ctx->Extensions.ARB_texture_cube_map &&
233 ctx->Extensions.ARB_texture_mirrored_repeat &&
234 ctx->Extensions.EXT_blend_color &&
235 ctx->Extensions.EXT_blend_func_separate &&
236 ctx->Extensions.EXT_blend_minmax &&
237 ctx->Extensions.EXT_blend_subtract &&
238 ctx->Extensions.EXT_stencil_wrap &&
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400239 ctx->Extensions.ARB_shader_objects &&
240 ctx->Extensions.ARB_vertex_shader &&
241 ctx->Extensions.ARB_fragment_shader &&
242 ctx->Extensions.ARB_texture_non_power_of_two &&
243 ctx->Extensions.EXT_blend_equation_separate);
244 if (ver_2_0) {
245 ctx->VersionMajor = 2;
246 ctx->VersionMinor = 0;
247 } else {
248 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
249 }
250
251 ctx->VersionString = (char *) malloc(max);
252 if (ctx->VersionString) {
253 _mesa_snprintf(ctx->VersionString, max,
254 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING);
255 }
256}
Brian Paule0b9e332010-01-05 21:23:01 -0700257
258/**
259 * Set the context's VersionMajor, VersionMinor, VersionString fields.
Chia-I Wu45313562010-09-10 10:31:06 +0800260 * This should only be called once as part of context initialization
261 * or to perform version check for GLX_ARB_create_context_profile.
Brian Paule0b9e332010-01-05 21:23:01 -0700262 */
263void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400264_mesa_compute_version(struct gl_context *ctx)
Brian Paule0b9e332010-01-05 21:23:01 -0700265{
Chia-I Wu45313562010-09-10 10:31:06 +0800266 if (ctx->VersionMajor)
267 return;
268
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400269 switch (ctx->API) {
270 case API_OPENGL:
271 compute_version(ctx);
272 break;
273 case API_OPENGLES:
274 compute_version_es1(ctx);
275 break;
276 case API_OPENGLES2:
277 compute_version_es2(ctx);
278 break;
Brian Paule0b9e332010-01-05 21:23:01 -0700279 }
Kristian Høgsberg29107d42010-04-21 16:14:18 -0400280
Brian Paule0b9e332010-01-05 21:23:01 -0700281}