Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1901 serge 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(struct gl_context *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->Const.GLSLVersion >= 120 &&
88
                              ctx->Extensions.EXT_pixel_buffer_object &&
89
                              ctx->Extensions.EXT_texture_sRGB);
90
   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.ARB_texture_rg &&
95
                              ctx->Extensions.ARB_texture_compression_rgtc &&
96
                              ctx->Extensions.APPLE_vertex_array_object &&
97
                              ctx->Extensions.EXT_draw_buffers2 &&
98
                              ctx->Extensions.EXT_framebuffer_blit &&
99
                              ctx->Extensions.EXT_framebuffer_multisample &&
100
                              ctx->Extensions.EXT_framebuffer_object &&
101
                              ctx->Extensions.EXT_framebuffer_sRGB &&
102
                              ctx->Extensions.EXT_packed_depth_stencil &&
103
                              ctx->Extensions.EXT_packed_float &&
104
                              ctx->Extensions.EXT_texture_array &&
105
                              ctx->Extensions.EXT_texture_integer &&
106
                              ctx->Extensions.EXT_texture_shared_exponent &&
107
                              ctx->Extensions.EXT_transform_feedback &&
108
                              ctx->Extensions.NV_conditional_render);
109
   const GLboolean ver_3_1 = (ver_3_0 &&
110
                              ctx->Extensions.ARB_copy_buffer &&
111
                              ctx->Extensions.ARB_draw_instanced &&
112
                              ctx->Extensions.ARB_texture_buffer_object &&
113
                              ctx->Extensions.ARB_uniform_buffer_object &&
114
                              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) {
155
      major = 2;
156
      minor = 1;
157
   }
158
   else if (ver_2_0) {
159
      major = 2;
160
      minor = 0;
161
   }
162
   else if (ver_1_5) {
163
      major = 1;
164
      minor = 5;
165
   }
166
   else if (ver_1_4) {
167
      major = 1;
168
      minor = 4;
169
   }
170
   else if (ver_1_3) {
171
      major = 1;
172
      minor = 3;
173
   }
174
   else {
175
      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,
184
		     "%u.%u Mesa " MESA_VERSION_STRING,
185
		     ctx->VersionMajor, ctx->VersionMinor);
186
   }
187
}
188
 
189
static void
190
compute_version_es1(struct gl_context *ctx)
191
{
192
   static const int max = 100;
193
 
194
   /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
195
   const GLboolean ver_1_0 = (ctx->Extensions.ARB_multisample &&
196
                              ctx->Extensions.ARB_multitexture &&
197
                              ctx->Extensions.ARB_texture_compression &&
198
                              ctx->Extensions.EXT_texture_env_add &&
199
                              ctx->Extensions.ARB_texture_env_combine &&
200
                              ctx->Extensions.ARB_texture_env_dot3);
201
   /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
202
   const GLboolean ver_1_1 = (ver_1_0 &&
203
                              ctx->Extensions.EXT_point_parameters &&
204
                              ctx->Extensions.SGIS_generate_mipmap &&
205
                              ctx->Extensions.ARB_vertex_buffer_object);
206
 
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
 
225
static void
226
compute_version_es2(struct gl_context *ctx)
227
{
228
   static const int max = 100;
229
 
230
   /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
231
   const GLboolean ver_2_0 = (ctx->Extensions.ARB_multisample &&
232
                              ctx->Extensions.ARB_multitexture &&
233
                              ctx->Extensions.ARB_texture_compression &&
234
                              ctx->Extensions.ARB_texture_cube_map &&
235
                              ctx->Extensions.ARB_texture_mirrored_repeat &&
236
                              ctx->Extensions.EXT_blend_color &&
237
                              ctx->Extensions.EXT_blend_func_separate &&
238
                              ctx->Extensions.EXT_blend_minmax &&
239
                              ctx->Extensions.EXT_blend_subtract &&
240
                              ctx->Extensions.EXT_stencil_wrap &&
241
                              ctx->Extensions.ARB_vertex_buffer_object &&
242
                              ctx->Extensions.ARB_shader_objects &&
243
                              ctx->Extensions.ARB_vertex_shader &&
244
                              ctx->Extensions.ARB_fragment_shader &&
245
                              ctx->Extensions.ARB_texture_non_power_of_two &&
246
                              ctx->Extensions.EXT_blend_equation_separate);
247
   if (ver_2_0) {
248
      ctx->VersionMajor = 2;
249
      ctx->VersionMinor = 0;
250
   } else {
251
      _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
252
   }
253
 
254
   ctx->VersionString = (char *) malloc(max);
255
   if (ctx->VersionString) {
256
      _mesa_snprintf(ctx->VersionString, max,
257
		     "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING);
258
   }
259
}
260
 
261
/**
262
 * Set the context's VersionMajor, VersionMinor, VersionString fields.
263
 * This should only be called once as part of context initialization
264
 * or to perform version check for GLX_ARB_create_context_profile.
265
 */
266
void
267
_mesa_compute_version(struct gl_context *ctx)
268
{
269
   if (ctx->VersionMajor)
270
      return;
271
 
272
   switch (ctx->API) {
273
   case API_OPENGL:
274
      compute_version(ctx);
275
      break;
276
   case API_OPENGLES:
277
      compute_version_es1(ctx);
278
      break;
279
   case API_OPENGLES2:
280
      compute_version_es2(ctx);
281
      break;
282
   }
283
 
284
}