| 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 | |
| 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(const GLcontext *ctx, GLuint *major, GLuint *minor) |
| 36 | { |
| 37 | const GLboolean ver_1_3 = (ctx->Extensions.ARB_multisample && |
| 38 | ctx->Extensions.ARB_multitexture && |
| 39 | ctx->Extensions.ARB_texture_border_clamp && |
| 40 | ctx->Extensions.ARB_texture_compression && |
| 41 | ctx->Extensions.ARB_texture_cube_map && |
| 42 | ctx->Extensions.EXT_texture_env_add && |
| 43 | ctx->Extensions.ARB_texture_env_combine && |
| 44 | ctx->Extensions.ARB_texture_env_dot3); |
| 45 | const GLboolean ver_1_4 = (ver_1_3 && |
| 46 | ctx->Extensions.ARB_depth_texture && |
| 47 | ctx->Extensions.ARB_shadow && |
| 48 | ctx->Extensions.ARB_texture_env_crossbar && |
| 49 | ctx->Extensions.ARB_texture_mirrored_repeat && |
| 50 | ctx->Extensions.ARB_window_pos && |
| 51 | ctx->Extensions.EXT_blend_color && |
| 52 | ctx->Extensions.EXT_blend_func_separate && |
| 53 | ctx->Extensions.EXT_blend_minmax && |
| 54 | ctx->Extensions.EXT_blend_subtract && |
| 55 | ctx->Extensions.EXT_fog_coord && |
| 56 | ctx->Extensions.EXT_multi_draw_arrays && |
| 57 | ctx->Extensions.EXT_point_parameters && |
| 58 | ctx->Extensions.EXT_secondary_color && |
| 59 | ctx->Extensions.EXT_stencil_wrap && |
| 60 | ctx->Extensions.EXT_texture_lod_bias && |
| 61 | ctx->Extensions.SGIS_generate_mipmap); |
| 62 | const GLboolean ver_1_5 = (ver_1_4 && |
| 63 | ctx->Extensions.ARB_occlusion_query && |
| 64 | ctx->Extensions.ARB_vertex_buffer_object && |
| 65 | 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 && |
| 84 | ctx->Extensions.ARB_shading_language_120 && |
| 85 | ctx->Extensions.EXT_pixel_buffer_object && |
| 86 | ctx->Extensions.EXT_texture_sRGB); |
| 87 | if (ver_2_1) { |
| 88 | *major = 2; |
| 89 | *minor = 1; |
| 90 | } |
| 91 | else if (ver_2_0) { |
| 92 | *major = 2; |
| 93 | *minor = 0; |
| 94 | } |
| 95 | else if (ver_1_5) { |
| 96 | *major = 1; |
| 97 | *minor = 5; |
| 98 | } |
| 99 | else if (ver_1_4) { |
| 100 | *major = 1; |
| 101 | *minor = 4; |
| 102 | } |
| 103 | else if (ver_1_3) { |
| 104 | *major = 1; |
| 105 | *minor = 3; |
| 106 | } |
| 107 | else { |
| 108 | *major = 1; |
| 109 | *minor = 2; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * Set the context's VersionMajor, VersionMinor, VersionString fields. |
| 116 | * This should only be called once as part of context initialization. |
| 117 | */ |
| 118 | void |
| 119 | _mesa_compute_version(GLcontext *ctx) |
| 120 | { |
| 121 | static const int max = 100; |
| 122 | |
| 123 | compute_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor); |
| 124 | |
| 125 | ctx->VersionString = (char *) _mesa_malloc(max); |
| 126 | if (ctx->VersionString) { |
| 127 | _mesa_snprintf(ctx->VersionString, max, "%u.%u Mesa " MESA_VERSION_STRING, |
| 128 | ctx->VersionMajor, ctx->VersionMinor); |
| 129 | } |
| 130 | } |