version.c revision 3464ebd5
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 "imports.h" 26#include "mtypes.h" 27#include "version.h" 28#include "git_sha1.h" 29 30 31 32/** 33 * Examine enabled GL extensions to determine GL version. 34 * Return major and minor version numbers. 35 */ 36static void 37compute_version(struct gl_context *ctx) 38{ 39 GLuint major, minor; 40 static const int max = 100; 41 42 const GLboolean ver_1_3 = (ctx->Extensions.ARB_multisample && 43 ctx->Extensions.ARB_multitexture && 44 ctx->Extensions.ARB_texture_border_clamp && 45 ctx->Extensions.ARB_texture_compression && 46 ctx->Extensions.ARB_texture_cube_map && 47 ctx->Extensions.EXT_texture_env_add && 48 ctx->Extensions.ARB_texture_env_combine && 49 ctx->Extensions.ARB_texture_env_dot3); 50 const GLboolean ver_1_4 = (ver_1_3 && 51 ctx->Extensions.ARB_depth_texture && 52 ctx->Extensions.ARB_shadow && 53 ctx->Extensions.ARB_texture_env_crossbar && 54 ctx->Extensions.ARB_texture_mirrored_repeat && 55 ctx->Extensions.ARB_window_pos && 56 ctx->Extensions.EXT_blend_color && 57 ctx->Extensions.EXT_blend_func_separate && 58 ctx->Extensions.EXT_blend_minmax && 59 ctx->Extensions.EXT_blend_subtract && 60 ctx->Extensions.EXT_fog_coord && 61 ctx->Extensions.EXT_multi_draw_arrays && 62 ctx->Extensions.EXT_point_parameters && 63 ctx->Extensions.EXT_secondary_color && 64 ctx->Extensions.EXT_stencil_wrap && 65 ctx->Extensions.EXT_texture_lod_bias && 66 ctx->Extensions.SGIS_generate_mipmap); 67 const GLboolean ver_1_5 = (ver_1_4 && 68 ctx->Extensions.ARB_occlusion_query && 69 ctx->Extensions.ARB_vertex_buffer_object && 70 ctx->Extensions.EXT_shadow_funcs); 71 const GLboolean ver_2_0 = (ver_1_5 && 72 ctx->Extensions.ARB_draw_buffers && 73 ctx->Extensions.ARB_point_sprite && 74 ctx->Extensions.ARB_shader_objects && 75 ctx->Extensions.ARB_vertex_shader && 76 ctx->Extensions.ARB_fragment_shader && 77 ctx->Extensions.ARB_texture_non_power_of_two && 78 ctx->Extensions.EXT_blend_equation_separate && 79 80 /* Technically, 2.0 requires the functionality 81 * of the EXT version. Enable 2.0 if either 82 * extension is available, and assume that a 83 * driver that only exposes the ATI extension 84 * will fallback to software when necessary. 85 */ 86 (ctx->Extensions.EXT_stencil_two_side 87 || ctx->Extensions.ATI_separate_stencil)); 88 const GLboolean ver_2_1 = (ver_2_0 && 89 ctx->Const.GLSLVersion >= 120 && 90 ctx->Extensions.EXT_pixel_buffer_object && 91 ctx->Extensions.EXT_texture_sRGB); 92 const GLboolean ver_3_0 = (ver_2_1 && 93 ctx->Extensions.ARB_color_buffer_float && 94 ctx->Extensions.ARB_depth_buffer_float && 95 ctx->Extensions.ARB_half_float_pixel && 96 ctx->Extensions.ARB_map_buffer_range && 97 ctx->Extensions.ARB_texture_float && 98 ctx->Extensions.ARB_texture_rg && 99 ctx->Extensions.ARB_texture_compression_rgtc && 100 ctx->Extensions.APPLE_vertex_array_object && 101 ctx->Extensions.EXT_draw_buffers2 && 102 ctx->Extensions.EXT_framebuffer_blit && 103 ctx->Extensions.EXT_framebuffer_multisample && 104 ctx->Extensions.EXT_framebuffer_object && 105 ctx->Extensions.EXT_framebuffer_sRGB && 106 ctx->Extensions.EXT_packed_depth_stencil && 107 ctx->Extensions.EXT_packed_float && 108 ctx->Extensions.EXT_texture_array && 109 ctx->Extensions.EXT_texture_integer && 110 ctx->Extensions.EXT_texture_shared_exponent && 111 ctx->Extensions.EXT_transform_feedback && 112 ctx->Extensions.NV_conditional_render); 113 const GLboolean ver_3_1 = (ver_3_0 && 114 ctx->Extensions.ARB_copy_buffer && 115 ctx->Extensions.ARB_draw_instanced && 116 ctx->Extensions.ARB_texture_buffer_object && 117 ctx->Extensions.ARB_uniform_buffer_object && 118 ctx->Extensions.EXT_texture_snorm && 119 ctx->Extensions.NV_primitive_restart && 120 ctx->Extensions.NV_texture_rectangle && 121 ctx->Const.MaxVertexTextureImageUnits >= 16); 122 const GLboolean ver_3_2 = (ver_3_1 && 123 ctx->Extensions.ARB_depth_clamp && 124 ctx->Extensions.ARB_draw_elements_base_vertex && 125 ctx->Extensions.ARB_fragment_coord_conventions && 126 ctx->Extensions.ARB_geometry_shader4 && 127 ctx->Extensions.EXT_provoking_vertex && 128 ctx->Extensions.ARB_seamless_cube_map && 129 ctx->Extensions.ARB_sync && 130 ctx->Extensions.ARB_texture_multisample && 131 ctx->Extensions.EXT_vertex_array_bgra); 132 const GLboolean ver_3_3 = (ver_3_2 && 133 ctx->Extensions.ARB_blend_func_extended && 134 ctx->Extensions.ARB_explicit_attrib_location && 135 ctx->Extensions.ARB_instanced_arrays && 136 ctx->Extensions.ARB_occlusion_query2 && 137 ctx->Extensions.ARB_sampler_objects && 138 ctx->Extensions.ARB_texture_rgb10_a2ui && 139 ctx->Extensions.ARB_timer_query && 140 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev && 141 ctx->Extensions.EXT_texture_swizzle); 142 143 if (ver_3_3) { 144 major = 3; 145 minor = 3; 146 } 147 else if (ver_3_2) { 148 major = 3; 149 minor = 2; 150 } 151 else if (ver_3_1) { 152 major = 3; 153 minor = 1; 154 } 155 else if (ver_3_0) { 156 major = 3; 157 minor = 0; 158 } 159 else if (ver_2_1) { 160 major = 2; 161 minor = 1; 162 } 163 else if (ver_2_0) { 164 major = 2; 165 minor = 0; 166 } 167 else if (ver_1_5) { 168 major = 1; 169 minor = 5; 170 } 171 else if (ver_1_4) { 172 major = 1; 173 minor = 4; 174 } 175 else if (ver_1_3) { 176 major = 1; 177 minor = 3; 178 } 179 else { 180 major = 1; 181 minor = 2; 182 } 183 184 ctx->VersionMajor = major; 185 ctx->VersionMinor = minor; 186 ctx->VersionString = (char *) malloc(max); 187 if (ctx->VersionString) { 188 _mesa_snprintf(ctx->VersionString, max, 189 "%u.%u Mesa " MESA_VERSION_STRING 190#ifdef MESA_GIT_SHA1 191 " (" MESA_GIT_SHA1 ")" 192#endif 193 , 194 ctx->VersionMajor, ctx->VersionMinor); 195 } 196} 197 198static void 199compute_version_es1(struct gl_context *ctx) 200{ 201 static const int max = 100; 202 203 /* OpenGL ES 1.0 is derived from OpenGL 1.3 */ 204 const GLboolean ver_1_0 = (ctx->Extensions.ARB_multisample && 205 ctx->Extensions.ARB_multitexture && 206 ctx->Extensions.ARB_texture_compression && 207 ctx->Extensions.EXT_texture_env_add && 208 ctx->Extensions.ARB_texture_env_combine && 209 ctx->Extensions.ARB_texture_env_dot3); 210 /* OpenGL ES 1.1 is derived from OpenGL 1.5 */ 211 const GLboolean ver_1_1 = (ver_1_0 && 212 ctx->Extensions.EXT_point_parameters && 213 ctx->Extensions.SGIS_generate_mipmap && 214 ctx->Extensions.ARB_vertex_buffer_object); 215 216 if (ver_1_1) { 217 ctx->VersionMajor = 1; 218 ctx->VersionMinor = 1; 219 } else if (ver_1_0) { 220 ctx->VersionMajor = 1; 221 ctx->VersionMinor = 0; 222 } else { 223 _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support."); 224 } 225 226 ctx->VersionString = (char *) malloc(max); 227 if (ctx->VersionString) { 228 _mesa_snprintf(ctx->VersionString, max, 229 "OpenGL ES-CM 1.%d Mesa " MESA_VERSION_STRING, 230 ctx->VersionMinor); 231 } 232} 233 234static void 235compute_version_es2(struct gl_context *ctx) 236{ 237 static const int max = 100; 238 239 /* OpenGL ES 2.0 is derived from OpenGL 2.0 */ 240 const GLboolean ver_2_0 = (ctx->Extensions.ARB_multisample && 241 ctx->Extensions.ARB_multitexture && 242 ctx->Extensions.ARB_texture_compression && 243 ctx->Extensions.ARB_texture_cube_map && 244 ctx->Extensions.ARB_texture_mirrored_repeat && 245 ctx->Extensions.EXT_blend_color && 246 ctx->Extensions.EXT_blend_func_separate && 247 ctx->Extensions.EXT_blend_minmax && 248 ctx->Extensions.EXT_blend_subtract && 249 ctx->Extensions.EXT_stencil_wrap && 250 ctx->Extensions.ARB_vertex_buffer_object && 251 ctx->Extensions.ARB_shader_objects && 252 ctx->Extensions.ARB_vertex_shader && 253 ctx->Extensions.ARB_fragment_shader && 254 ctx->Extensions.ARB_texture_non_power_of_two && 255 ctx->Extensions.EXT_blend_equation_separate); 256 if (ver_2_0) { 257 ctx->VersionMajor = 2; 258 ctx->VersionMinor = 0; 259 } else { 260 _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support."); 261 } 262 263 ctx->VersionString = (char *) malloc(max); 264 if (ctx->VersionString) { 265 _mesa_snprintf(ctx->VersionString, max, 266 "OpenGL ES 2.0 Mesa " MESA_VERSION_STRING); 267 } 268} 269 270/** 271 * Set the context's VersionMajor, VersionMinor, VersionString fields. 272 * This should only be called once as part of context initialization 273 * or to perform version check for GLX_ARB_create_context_profile. 274 */ 275void 276_mesa_compute_version(struct gl_context *ctx) 277{ 278 if (ctx->VersionMajor) 279 return; 280 281 switch (ctx->API) { 282 case API_OPENGL: 283 compute_version(ctx); 284 break; 285 case API_OPENGLES: 286 compute_version_es1(ctx); 287 break; 288 case API_OPENGLES2: 289 compute_version_es2(ctx); 290 break; 291 } 292 293} 294