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