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