OSDN Git Service

mesa: remove support for GL_APPLE_client_storage extension
[android-x86/external-mesa.git] / src / mesa / main / extensions.c
1 /*
2  * Mesa 3-D graphics library
3  * Version:  7.6
4  *
5  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26
27 /**
28  * \file
29  * \brief Extension handling
30  */
31
32
33 #include "glheader.h"
34 #include "imports.h"
35 #include "context.h"
36 #include "extensions.h"
37 #include "mfeatures.h"
38 #include "mtypes.h"
39
40 #define ALIGN(value, alignment)  (((value) + alignment - 1) & ~(alignment - 1))
41
42 enum {
43    DISABLE = 0,
44    GL  = 1 << API_OPENGL,
45    ES1 = 1 << API_OPENGLES,
46    ES2 = 1 << API_OPENGLES2,
47 };
48
49 /**
50  * \brief An element of the \c extension_table.
51  */
52 struct extension {
53    /** Name of extension, such as "GL_ARB_depth_clamp". */
54    const char *name;
55
56    /** Offset (in bytes) of the corresponding member in struct gl_extensions. */
57    size_t offset;
58
59    /** Set of API's in which the extension exists, as a bitset. */
60    uint8_t api_set;
61
62    /** Year the extension was proposed or approved.  Used to sort the 
63     * extension string chronologically. */
64    uint16_t year;
65 };
66
67
68 /**
69  * Given a member \c x of struct gl_extensions, return offset of
70  * \c x in bytes.
71  */
72 #define o(x) offsetof(struct gl_extensions, x)
73
74
75 /**
76  * \brief Table of supported OpenGL extensions for all API's.
77  */
78 static const struct extension extension_table[] = {
79    /* ARB Extensions */
80    { "GL_ARB_ES2_compatibility",                   o(ARB_ES2_compatibility),                   GL,             2009 },
81    { "GL_ARB_blend_func_extended",                 o(ARB_blend_func_extended),                 GL,             2009 },
82    { "GL_ARB_color_buffer_float",                  o(ARB_color_buffer_float),                  GL,             2004 },
83    { "GL_ARB_copy_buffer",                         o(ARB_copy_buffer),                         GL,             2008 },
84    { "GL_ARB_conservative_depth",                  o(AMD_conservative_depth),                  GL,             2011 },
85    { "GL_ARB_depth_buffer_float",                  o(ARB_depth_buffer_float),                  GL,             2008 },
86    { "GL_ARB_depth_clamp",                         o(ARB_depth_clamp),                         GL,             2003 },
87    { "GL_ARB_depth_texture",                       o(ARB_depth_texture),                       GL,             2001 },
88    { "GL_ARB_draw_buffers",                        o(ARB_draw_buffers),                        GL,             2002 },
89    { "GL_ARB_draw_buffers_blend",                  o(ARB_draw_buffers_blend),                  GL,             2009 },
90    { "GL_ARB_draw_elements_base_vertex",           o(ARB_draw_elements_base_vertex),           GL,             2009 },
91    { "GL_ARB_draw_instanced",                      o(ARB_draw_instanced),                      GL,             2008 },
92    { "GL_ARB_explicit_attrib_location",            o(ARB_explicit_attrib_location),            GL,             2009 },
93    { "GL_ARB_fragment_coord_conventions",          o(ARB_fragment_coord_conventions),          GL,             2009 },
94    { "GL_ARB_fragment_program",                    o(ARB_fragment_program),                    GL,             2002 },
95    { "GL_ARB_fragment_program_shadow",             o(ARB_fragment_program_shadow),             GL,             2003 },
96    { "GL_ARB_fragment_shader",                     o(ARB_fragment_shader),                     GL,             2002 },
97    { "GL_ARB_framebuffer_object",                  o(ARB_framebuffer_object),                  GL,             2005 },
98    { "GL_ARB_framebuffer_sRGB",                    o(EXT_framebuffer_sRGB),                    GL,             1998 },
99    { "GL_ARB_half_float_pixel",                    o(ARB_half_float_pixel),                    GL,             2003 },
100    { "GL_ARB_half_float_vertex",                   o(ARB_half_float_vertex),                   GL,             2008 },
101    { "GL_ARB_instanced_arrays",                    o(ARB_instanced_arrays),                    GL,             2008 },
102    { "GL_ARB_map_buffer_range",                    o(ARB_map_buffer_range),                    GL,             2008 },
103    { "GL_ARB_multisample",                         o(ARB_multisample),                         GL,             1994 },
104    { "GL_ARB_multitexture",                        o(ARB_multitexture),                        GL,             1998 },
105    { "GL_ARB_occlusion_query2",                    o(ARB_occlusion_query2),                    GL,             2003 },
106    { "GL_ARB_occlusion_query",                     o(ARB_occlusion_query),                     GL,             2001 },
107    { "GL_ARB_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL,             2004 },
108    { "GL_ARB_point_parameters",                    o(EXT_point_parameters),                    GL,             1997 },
109    { "GL_ARB_point_sprite",                        o(ARB_point_sprite),                        GL,             2003 },
110    { "GL_ARB_provoking_vertex",                    o(EXT_provoking_vertex),                    GL,             2009 },
111    { "GL_ARB_robustness",                          o(dummy_true),                              GL,             2010 },
112    { "GL_ARB_sampler_objects",                     o(ARB_sampler_objects),                     GL,             2009 },
113    { "GL_ARB_seamless_cube_map",                   o(ARB_seamless_cube_map),                   GL,             2009 },
114    { "GL_ARB_shader_objects",                      o(ARB_shader_objects),                      GL,             2002 },
115    { "GL_ARB_shader_stencil_export",               o(ARB_shader_stencil_export),               GL,             2009 },
116    { "GL_ARB_shader_texture_lod",                  o(ARB_shader_texture_lod),                  GL,             2009 },
117    { "GL_ARB_shading_language_100",                o(ARB_shading_language_100),                GL,             2003 },
118    { "GL_ARB_shadow_ambient",                      o(ARB_shadow_ambient),                      GL,             2001 },
119    { "GL_ARB_shadow",                              o(ARB_shadow),                              GL,             2001 },
120    { "GL_ARB_sync",                                o(ARB_sync),                                GL,             2003 },
121    { "GL_ARB_texture_border_clamp",                o(ARB_texture_border_clamp),                GL,             2000 },
122    { "GL_ARB_texture_buffer_object",               o(ARB_texture_buffer_object),               GL,             2008 },
123    { "GL_ARB_texture_compression",                 o(ARB_texture_compression),                 GL,             2000 },
124    { "GL_ARB_texture_compression_rgtc",            o(ARB_texture_compression_rgtc),            GL,             2004 },
125    { "GL_ARB_texture_cube_map",                    o(ARB_texture_cube_map),                    GL,             1999 },
126    { "GL_ARB_texture_env_add",                     o(EXT_texture_env_add),                     GL,             1999 },
127    { "GL_ARB_texture_env_combine",                 o(ARB_texture_env_combine),                 GL,             2001 },
128    { "GL_ARB_texture_env_crossbar",                o(ARB_texture_env_crossbar),                GL,             2001 },
129    { "GL_ARB_texture_env_dot3",                    o(ARB_texture_env_dot3),                    GL,             2001 },
130    { "GL_ARB_texture_float",                       o(ARB_texture_float),                       GL,             2004 },
131    { "GL_ARB_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),             GL,             2001 },
132    { "GL_ARB_texture_multisample",                 o(ARB_texture_multisample),                 GL,             2009 },
133    { "GL_ARB_texture_non_power_of_two",            o(ARB_texture_non_power_of_two),            GL,             2003 },
134    { "GL_ARB_texture_rectangle",                   o(NV_texture_rectangle),                    GL,             2004 },
135    { "GL_ARB_texture_rgb10_a2ui",                  o(ARB_texture_rgb10_a2ui),                  GL,             2009 },
136    { "GL_ARB_texture_rg",                          o(ARB_texture_rg),                          GL,             2008 },
137    { "GL_ARB_texture_swizzle",                     o(EXT_texture_swizzle),                     GL,             2008 },
138    { "GL_ARB_transform_feedback2",                 o(ARB_transform_feedback2),                 GL,             2010 },
139    { "GL_ARB_transpose_matrix",                    o(ARB_transpose_matrix),                    GL,             1999 },
140    { "GL_ARB_uniform_buffer_object",               o(ARB_uniform_buffer_object),               GL,             2002 },
141    { "GL_ARB_vertex_array_bgra",                   o(EXT_vertex_array_bgra),                   GL,             2008 },
142    { "GL_ARB_vertex_array_object",                 o(ARB_vertex_array_object),                 GL,             2006 },
143    { "GL_ARB_vertex_buffer_object",                o(ARB_vertex_buffer_object),                GL,             2003 },
144    { "GL_ARB_vertex_program",                      o(ARB_vertex_program),                      GL,             2002 },
145    { "GL_ARB_vertex_shader",                       o(ARB_vertex_shader),                       GL,             2002 },
146    { "GL_ARB_vertex_type_2_10_10_10_rev",          o(ARB_vertex_type_2_10_10_10_rev),          GL,             2009 },
147    { "GL_ARB_window_pos",                          o(ARB_window_pos),                          GL,             2001 },
148    /* EXT extensions */
149    { "GL_EXT_abgr",                                o(EXT_abgr),                                GL,             1995 },
150    { "GL_EXT_bgra",                                o(EXT_bgra),                                GL,             1995 },
151    { "GL_EXT_blend_color",                         o(EXT_blend_color),                         GL,             1995 },
152    { "GL_EXT_blend_equation_separate",             o(EXT_blend_equation_separate),             GL,             2003 },
153    { "GL_EXT_blend_func_separate",                 o(EXT_blend_func_separate),                 GL,             1999 },
154    { "GL_EXT_blend_minmax",                        o(EXT_blend_minmax),                        GL | ES1 | ES2, 1995 },
155    { "GL_EXT_blend_subtract",                      o(EXT_blend_subtract),                      GL,             1995 },
156    { "GL_EXT_clip_volume_hint",                    o(EXT_clip_volume_hint),                    GL,             1996 },
157    { "GL_EXT_compiled_vertex_array",               o(EXT_compiled_vertex_array),               GL,             1996 },
158    { "GL_EXT_copy_texture",                        o(EXT_copy_texture),                        GL,             1995 },
159    { "GL_EXT_depth_bounds_test",                   o(EXT_depth_bounds_test),                   GL,             2002 },
160    { "GL_EXT_draw_buffers2",                       o(EXT_draw_buffers2),                       GL,             2006 },
161    { "GL_EXT_draw_instanced",                      o(ARB_draw_instanced),                      GL,             2006 },
162    { "GL_EXT_draw_range_elements",                 o(EXT_draw_range_elements),                 GL,             1997 },
163    { "GL_EXT_fog_coord",                           o(EXT_fog_coord),                           GL,             1999 },
164    { "GL_EXT_framebuffer_blit",                    o(EXT_framebuffer_blit),                    GL,             2005 },
165    { "GL_EXT_framebuffer_multisample",             o(EXT_framebuffer_multisample),             GL,             2005 },
166    { "GL_EXT_framebuffer_object",                  o(EXT_framebuffer_object),                  GL,             2000 },
167    { "GL_EXT_framebuffer_sRGB",                    o(EXT_framebuffer_sRGB),                    GL,             1998 },
168    { "GL_EXT_gpu_program_parameters",              o(EXT_gpu_program_parameters),              GL,             2006 },
169    { "GL_EXT_gpu_shader4",                         o(EXT_gpu_shader4),                         GL,             2006 },
170    { "GL_EXT_multi_draw_arrays",                   o(EXT_multi_draw_arrays),                   GL | ES1 | ES2, 1999 },
171    { "GL_EXT_packed_depth_stencil",                o(EXT_packed_depth_stencil),                GL,             2005 },
172    { "GL_EXT_packed_float",                        o(EXT_packed_float),                        GL,             2004 },
173    { "GL_EXT_packed_pixels",                       o(EXT_packed_pixels),                       GL,             1997 },
174    { "GL_EXT_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL,             2004 },
175    { "GL_EXT_point_parameters",                    o(EXT_point_parameters),                    GL,             1997 },
176    { "GL_EXT_polygon_offset",                      o(EXT_polygon_offset),                      GL,             1995 },
177    { "GL_EXT_provoking_vertex",                    o(EXT_provoking_vertex),                    GL,             2009 },
178    { "GL_EXT_rescale_normal",                      o(EXT_rescale_normal),                      GL,             1997 },
179    { "GL_EXT_secondary_color",                     o(EXT_secondary_color),                     GL,             1999 },
180    { "GL_EXT_separate_shader_objects",             o(EXT_separate_shader_objects),             GL,             2008 },
181    { "GL_EXT_separate_specular_color",             o(EXT_separate_specular_color),             GL,             1997 },
182    { "GL_EXT_shadow_funcs",                        o(EXT_shadow_funcs),                        GL,             2002 },
183    { "GL_EXT_stencil_two_side",                    o(EXT_stencil_two_side),                    GL,             2001 },
184    { "GL_EXT_stencil_wrap",                        o(EXT_stencil_wrap),                        GL,             2002 },
185    { "GL_EXT_subtexture",                          o(EXT_subtexture),                          GL,             1995 },
186    { "GL_EXT_texture3D",                           o(EXT_texture3D),                           GL,             1996 },
187    { "GL_EXT_texture_array",                       o(EXT_texture_array),                       GL,             2006 },
188    { "GL_EXT_texture_compression_dxt1",            o(EXT_texture_compression_s3tc),            GL | ES1 | ES2, 2004 },
189    { "GL_EXT_texture_compression_latc",            o(EXT_texture_compression_latc),            GL,             2006 },
190    { "GL_EXT_texture_compression_rgtc",            o(ARB_texture_compression_rgtc),            GL,             2004 },
191    { "GL_EXT_texture_compression_s3tc",            o(EXT_texture_compression_s3tc),            GL,             2000 },
192    { "GL_EXT_texture_cube_map",                    o(ARB_texture_cube_map),                    GL,             2001 },
193    { "GL_EXT_texture_edge_clamp",                  o(SGIS_texture_edge_clamp),                 GL,             1997 },
194    { "GL_EXT_texture_env_add",                     o(EXT_texture_env_add),                     GL,             1999 },
195    { "GL_EXT_texture_env_combine",                 o(EXT_texture_env_combine),                 GL,             2006 },
196    { "GL_EXT_texture_env_dot3",                    o(EXT_texture_env_dot3),                    GL,             2000 },
197    { "GL_EXT_texture_filter_anisotropic",          o(EXT_texture_filter_anisotropic),          GL | ES1 | ES2, 1999 },
198    { "GL_EXT_texture_format_BGRA8888",             o(EXT_texture_format_BGRA8888),                  ES1 | ES2, 2009 },
199    { "GL_EXT_texture_integer",                     o(EXT_texture_integer),                     GL,             2006 },
200    { "GL_EXT_texture_lod_bias",                    o(EXT_texture_lod_bias),                    GL | ES1,       1999 },
201    { "GL_EXT_texture_mirror_clamp",                o(EXT_texture_mirror_clamp),                GL,             2004 },
202    { "GL_EXT_texture_object",                      o(EXT_texture_object),                      GL,             1995 },
203    { "GL_EXT_texture",                             o(EXT_texture),                             GL,             1996 },
204    { "GL_EXT_texture_rectangle",                   o(NV_texture_rectangle),                    GL,             2004 },
205    { "GL_EXT_texture_shared_exponent",             o(EXT_texture_shared_exponent),             GL,             2004 },
206    { "GL_EXT_texture_snorm",                       o(EXT_texture_snorm),                       GL,             2009 },
207    { "GL_EXT_texture_sRGB",                        o(EXT_texture_sRGB),                        GL,             2004 },
208    { "GL_EXT_texture_sRGB_decode",                 o(EXT_texture_sRGB_decode),                        GL,      2006 },
209    { "GL_EXT_texture_swizzle",                     o(EXT_texture_swizzle),                     GL,             2008 },
210    { "GL_EXT_texture_type_2_10_10_10_REV",         o(dummy_true),                                         ES2, 2008 },
211    { "GL_EXT_timer_query",                         o(EXT_timer_query),                         GL,             2006 },
212    { "GL_EXT_transform_feedback",                  o(EXT_transform_feedback),                  GL,             2011 },
213    { "GL_EXT_vertex_array_bgra",                   o(EXT_vertex_array_bgra),                   GL,             2008 },
214    { "GL_EXT_vertex_array",                        o(EXT_vertex_array),                        GL,             1995 },
215    { "GL_EXT_vertex_array_set",                    o(EXT_vertex_array_set),                    GL,             1997 },
216
217    /* OES extensions */
218    { "GL_OES_blend_equation_separate",             o(EXT_blend_equation_separate),                  ES1,       2009 },
219    { "GL_OES_blend_func_separate",                 o(EXT_blend_func_separate),                      ES1,       2009 },
220    { "GL_OES_blend_subtract",                      o(EXT_blend_subtract),                           ES1,       2009 },
221    { "GL_OES_byte_coordinates",                    o(dummy_true),                                   ES1,       2002 },
222    { "GL_OES_compressed_paletted_texture",         o(dummy_true),                                   ES1,       2003 },
223    { "GL_OES_depth24",                             o(EXT_framebuffer_object),                       ES1 | ES2, 2005 },
224    { "GL_OES_depth32",                             o(dummy_false),                     DISABLE,                2005 },
225    { "GL_OES_depth_texture",                       o(ARB_depth_texture),                                  ES2, 2006 },
226 #if FEATURE_OES_draw_texture
227    { "GL_OES_draw_texture",                        o(OES_draw_texture),                             ES1 | ES2, 2004 },
228 #endif
229 #if FEATURE_OES_EGL_image
230    /*  FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */
231    { "GL_OES_EGL_image",                           o(OES_EGL_image),                           GL | ES1 | ES2, 2006 },
232 #endif
233    { "GL_OES_element_index_uint",                  o(EXT_vertex_array),                             ES1 | ES2, 2005 },
234    { "GL_OES_fbo_render_mipmap",                   o(EXT_framebuffer_object),                       ES1 | ES2, 2005 },
235    { "GL_OES_fixed_point",                         o(dummy_true),                                   ES1,       2002 },
236    { "GL_OES_framebuffer_object",                  o(EXT_framebuffer_object),                       ES1,       2005 },
237    { "GL_OES_mapbuffer",                           o(ARB_vertex_buffer_object),                     ES1 | ES2, 2005 },
238    { "GL_OES_matrix_get",                          o(dummy_true),                                   ES1,       2004 },
239    { "GL_OES_packed_depth_stencil",                o(EXT_packed_depth_stencil),                     ES1 | ES2, 2007 },
240    { "GL_OES_point_size_array",                    o(dummy_true),                                   ES1,       2004 },
241    { "GL_OES_point_sprite",                        o(ARB_point_sprite),                             ES1,       2004 },
242    { "GL_OES_query_matrix",                        o(dummy_true),                                   ES1,       2003 },
243    { "GL_OES_read_format",                         o(OES_read_format),                         GL | ES1,       2003 },
244    { "GL_OES_rgb8_rgba8",                          o(EXT_framebuffer_object),                       ES1 | ES2, 2005 },
245    { "GL_OES_single_precision",                    o(dummy_true),                                   ES1,       2003 },
246    { "GL_OES_standard_derivatives",                o(OES_standard_derivatives),                           ES2, 2005 },
247    { "GL_OES_stencil1",                            o(dummy_false),                     DISABLE,                2005 },
248    { "GL_OES_stencil4",                            o(dummy_false),                     DISABLE,                2005 },
249    { "GL_OES_stencil8",                            o(EXT_framebuffer_object),                       ES1 | ES2, 2005 },
250    { "GL_OES_stencil_wrap",                        o(EXT_stencil_wrap),                             ES1,       2002 },
251    { "GL_OES_texture_3D",                          o(EXT_texture3D),                                      ES2, 2005 },
252    { "GL_OES_texture_cube_map",                    o(ARB_texture_cube_map),                         ES1,       2007 },
253    { "GL_OES_texture_env_crossbar",                o(ARB_texture_env_crossbar),                     ES1,       2005 },
254    { "GL_OES_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),                  ES1,       2005 },
255    { "GL_OES_texture_npot",                        o(ARB_texture_non_power_of_two),                       ES2, 2005 },
256
257    /* Vendor extensions */
258    { "GL_3DFX_texture_compression_FXT1",           o(TDFX_texture_compression_FXT1),           GL,             1999 },
259    { "GL_AMD_conservative_depth",                  o(AMD_conservative_depth),                  GL,             2009 },
260    { "GL_AMD_draw_buffers_blend",                  o(ARB_draw_buffers_blend),                  GL,             2009 },
261    { "GL_AMD_seamless_cubemap_per_texture",        o(AMD_seamless_cubemap_per_texture),        GL,             2009 },
262    { "GL_AMD_shader_stencil_export",               o(ARB_shader_stencil_export),               GL,             2009 },
263    { "GL_APPLE_object_purgeable",                  o(APPLE_object_purgeable),                  GL,             2006 },
264    { "GL_APPLE_packed_pixels",                     o(APPLE_packed_pixels),                     GL,             2002 },
265    { "GL_APPLE_vertex_array_object",               o(APPLE_vertex_array_object),               GL,             2002 },
266    { "GL_ATI_blend_equation_separate",             o(EXT_blend_equation_separate),             GL,             2003 },
267    { "GL_ATI_draw_buffers",                        o(ARB_draw_buffers),                        GL,             2002 },
268    { "GL_ATI_envmap_bumpmap",                      o(ATI_envmap_bumpmap),                      GL,             2001 },
269    { "GL_ATI_fragment_shader",                     o(ATI_fragment_shader),                     GL,             2001 },
270    { "GL_ATI_separate_stencil",                    o(ATI_separate_stencil),                    GL,             2006 },
271    { "GL_ATI_texture_compression_3dc",             o(ATI_texture_compression_3dc),             GL,             2004 },
272    { "GL_ATI_texture_env_combine3",                o(ATI_texture_env_combine3),                GL,             2002 },
273    { "GL_ATI_texture_float",                       o(ARB_texture_float),                       GL,             2002 },
274    { "GL_ATI_texture_mirror_once",                 o(ATI_texture_mirror_once),                 GL,             2006 },
275    { "GL_IBM_multimode_draw_arrays",               o(IBM_multimode_draw_arrays),               GL,             1998 },
276    { "GL_IBM_rasterpos_clip",                      o(IBM_rasterpos_clip),                      GL,             1996 },
277    { "GL_IBM_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),             GL,             1998 },
278    { "GL_INGR_blend_func_separate",                o(EXT_blend_func_separate),                 GL,             1999 },
279    { "GL_MESA_pack_invert",                        o(MESA_pack_invert),                        GL,             2002 },
280    { "GL_MESA_resize_buffers",                     o(MESA_resize_buffers),                     GL,             1999 },
281    { "GL_MESA_texture_array",                      o(MESA_texture_array),                      GL,             2007 },
282    { "GL_MESA_texture_signed_rgba",                o(EXT_texture_snorm),                       GL,             2009 },
283    { "GL_MESA_window_pos",                         o(ARB_window_pos),                          GL,             2000 },
284    { "GL_MESA_ycbcr_texture",                      o(MESA_ycbcr_texture),                      GL,             2002 },
285    { "GL_NV_blend_square",                         o(NV_blend_square),                         GL,             1999 },
286    { "GL_NV_conditional_render",                   o(NV_conditional_render),                   GL,             2008 },
287    { "GL_NV_depth_clamp",                          o(ARB_depth_clamp),                         GL,             2001 },
288    { "GL_NV_fragment_program",                     o(NV_fragment_program),                     GL,             2001 },
289    { "GL_NV_fragment_program_option",              o(NV_fragment_program_option),              GL,             2005 },
290    { "GL_NV_light_max_exponent",                   o(NV_light_max_exponent),                   GL,             1999 },
291    { "GL_NV_packed_depth_stencil",                 o(EXT_packed_depth_stencil),                GL,             2000 },
292    { "GL_NV_point_sprite",                         o(NV_point_sprite),                         GL,             2001 },
293    { "GL_NV_primitive_restart",                    o(NV_primitive_restart),                    GL,             2002 },
294    { "GL_NV_texgen_reflection",                    o(NV_texgen_reflection),                    GL,             1999 },
295    { "GL_NV_texture_barrier",                      o(NV_texture_barrier),                      GL,             2009 },
296    { "GL_NV_texture_env_combine4",                 o(NV_texture_env_combine4),                 GL,             1999 },
297    { "GL_NV_texture_rectangle",                    o(NV_texture_rectangle),                    GL,             2000 },
298    { "GL_NV_vertex_program1_1",                    o(NV_vertex_program1_1),                    GL,             2001 },
299    { "GL_NV_vertex_program",                       o(NV_vertex_program),                       GL,             2000 },
300    { "GL_S3_s3tc",                                 o(S3_s3tc),                                 GL,             1999 },
301    { "GL_SGIS_generate_mipmap",                    o(SGIS_generate_mipmap),                    GL,             1997 },
302    { "GL_SGIS_texture_border_clamp",               o(ARB_texture_border_clamp),                GL,             1997 },
303    { "GL_SGIS_texture_edge_clamp",                 o(SGIS_texture_edge_clamp),                 GL,             1997 },
304    { "GL_SGIS_texture_lod",                        o(SGIS_texture_lod),                        GL,             1997 },
305    { "GL_SUN_multi_draw_arrays",                   o(EXT_multi_draw_arrays),                   GL,             1999 },
306
307    { 0, 0, 0, 0 },
308 };
309
310
311 /**
312  * Given an extension name, lookup up the corresponding member of struct
313  * gl_extensions and return that member's offset (in bytes).  If the name is
314  * not found in the \c extension_table, return 0.
315  *
316  * \param name Name of extension.
317  * \return Offset of member in struct gl_extensions.
318  */
319 static size_t
320 name_to_offset(const char* name)
321 {
322    const struct extension *i;
323
324    if (name == 0)
325       return 0;
326
327    for (i = extension_table; i->name != 0; ++i) {
328       if (strcmp(name, i->name) == 0)
329          return i->offset;
330    }
331
332    return 0;
333 }
334
335
336 /**
337  * \brief Extensions enabled by default.
338  *
339  * These extensions are enabled by _mesa_init_extensions().
340  *
341  * XXX: Should these defaults also apply to GLES?
342  */
343 static const size_t default_extensions[] = {
344    o(ARB_copy_buffer),
345    o(ARB_draw_buffers),
346    o(ARB_multisample),
347    o(ARB_texture_compression),
348    o(ARB_transpose_matrix),
349    o(ARB_vertex_buffer_object),
350    o(ARB_window_pos),
351
352    o(EXT_abgr),
353    o(EXT_bgra),
354    o(EXT_compiled_vertex_array),
355    o(EXT_copy_texture),
356    o(EXT_draw_range_elements),
357    o(EXT_multi_draw_arrays),
358    o(EXT_packed_pixels),
359    o(EXT_polygon_offset),
360    o(EXT_rescale_normal),
361    o(EXT_separate_specular_color),
362    o(EXT_subtexture),
363    o(EXT_texture),
364    o(EXT_texture3D),
365    o(EXT_texture_object),
366    o(EXT_vertex_array),
367
368    o(OES_read_format),
369    o(OES_standard_derivatives),
370
371    /* Vendor Extensions */
372    o(APPLE_packed_pixels),
373    o(IBM_multimode_draw_arrays),
374    o(IBM_rasterpos_clip),
375    o(NV_light_max_exponent),
376    o(NV_texgen_reflection),
377    o(SGIS_generate_mipmap),
378    o(SGIS_texture_edge_clamp),
379    o(SGIS_texture_lod),
380
381    0,
382 };
383
384
385 /**
386  * Enable all extensions suitable for a software-only renderer.
387  * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
388  */
389 void
390 _mesa_enable_sw_extensions(struct gl_context *ctx)
391 {
392    /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
393    ctx->Extensions.ARB_depth_clamp = GL_TRUE;
394    ctx->Extensions.ARB_depth_texture = GL_TRUE;
395    /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
396    ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
397    ctx->Extensions.ARB_draw_instanced = GL_TRUE;
398    ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
399    ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
400 #if FEATURE_ARB_fragment_program
401    ctx->Extensions.ARB_fragment_program = GL_TRUE;
402    ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
403 #endif
404 #if FEATURE_ARB_fragment_shader
405    ctx->Extensions.ARB_fragment_shader = GL_TRUE;
406 #endif
407 #if FEATURE_ARB_framebuffer_object
408    ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
409 #endif
410 #if FEATURE_ARB_geometry_shader4 && 0
411    /* XXX re-enable when GLSL compiler again supports geometry shaders */
412    ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
413 #endif
414    ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
415    ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
416    ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
417    ctx->Extensions.ARB_multitexture = GL_TRUE;
418 #if FEATURE_queryobj
419    ctx->Extensions.ARB_occlusion_query = GL_TRUE;
420    ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
421 #endif
422    ctx->Extensions.ARB_point_sprite = GL_TRUE;
423 #if FEATURE_ARB_shader_objects
424    ctx->Extensions.ARB_shader_objects = GL_TRUE;
425    ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
426 #endif
427 #if FEATURE_ARB_shading_language_100
428    ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
429 #endif
430    ctx->Extensions.ARB_shadow = GL_TRUE;
431    ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
432    ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
433    ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
434    ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
435    ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
436    ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
437    /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
438    ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
439    ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
440    ctx->Extensions.ARB_texture_rg = GL_TRUE;
441    ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
442    ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
443 #if FEATURE_ARB_vertex_program
444    ctx->Extensions.ARB_vertex_program = GL_TRUE;
445 #endif
446 #if FEATURE_ARB_vertex_shader
447    ctx->Extensions.ARB_vertex_shader = GL_TRUE;
448 #endif
449 #if FEATURE_ARB_vertex_buffer_object
450    /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
451 #endif
452 #if FEATURE_ARB_sync
453    ctx->Extensions.ARB_sync = GL_TRUE;
454 #endif
455    ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
456 #if FEATURE_APPLE_object_purgeable
457    ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
458 #endif
459    ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
460 #if FEATURE_ATI_fragment_shader
461    ctx->Extensions.ATI_fragment_shader = GL_TRUE;
462 #endif
463    ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
464    ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
465    ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
466    ctx->Extensions.ATI_separate_stencil = GL_TRUE;
467    ctx->Extensions.EXT_blend_color = GL_TRUE;
468    ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
469    ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
470    ctx->Extensions.EXT_blend_minmax = GL_TRUE;
471    ctx->Extensions.EXT_blend_subtract = GL_TRUE;
472    ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
473    ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
474    ctx->Extensions.EXT_fog_coord = GL_TRUE;
475 #if FEATURE_EXT_framebuffer_object
476    ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
477 #endif
478 #if FEATURE_EXT_framebuffer_blit
479    ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
480 #endif
481 #if FEATURE_ARB_framebuffer_object
482    ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
483 #endif
484    /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
485    ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
486 #if FEATURE_EXT_pixel_buffer_object
487    ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
488 #endif
489    ctx->Extensions.EXT_point_parameters = GL_TRUE;
490    ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
491    ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
492    ctx->Extensions.EXT_secondary_color = GL_TRUE;
493    ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
494    ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
495    ctx->Extensions.EXT_texture_array = GL_TRUE;
496    ctx->Extensions.EXT_texture_compression_latc = GL_TRUE;
497    ctx->Extensions.EXT_texture_env_add = GL_TRUE;
498    ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
499    ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
500    ctx->Extensions.EXT_texture_filter_anisotropic = GL_TRUE;
501    ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
502    ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
503    ctx->Extensions.EXT_texture_shared_exponent = GL_TRUE;
504 #if FEATURE_EXT_texture_sRGB
505    ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
506    ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
507 #endif
508    ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
509 #if FEATURE_EXT_transform_feedback
510    /*ctx->Extensions.EXT_transform_feedback = GL_TRUE;*/
511 #endif
512    ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
513    /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
514    ctx->Extensions.MESA_pack_invert = GL_TRUE;
515    ctx->Extensions.MESA_resize_buffers = GL_TRUE;
516    ctx->Extensions.MESA_texture_array = GL_TRUE;
517    ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
518    ctx->Extensions.NV_blend_square = GL_TRUE;
519    ctx->Extensions.NV_conditional_render = GL_TRUE;
520    /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
521    ctx->Extensions.NV_point_sprite = GL_TRUE;
522    ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
523    ctx->Extensions.NV_texture_rectangle = GL_TRUE;
524    /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
525 #if FEATURE_NV_vertex_program
526    ctx->Extensions.NV_vertex_program = GL_TRUE;
527    ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
528 #endif
529 #if FEATURE_NV_fragment_program
530    ctx->Extensions.NV_fragment_program = GL_TRUE;
531 #endif
532 #if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
533    ctx->Extensions.NV_fragment_program_option = GL_TRUE;
534 #endif
535    /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
536    ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
537 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
538    ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
539 #endif
540 #if FEATURE_texture_fxt1
541    _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
542 #endif
543 #if FEATURE_texture_s3tc
544    if (ctx->Mesa_DXTn) {
545       _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
546       _mesa_enable_extension(ctx, "GL_S3_s3tc");
547    }
548 #endif
549 }
550
551
552 /**
553  * Enable all OpenGL 1.3 features and extensions.
554  * A convenience function to be called by drivers.
555  */
556 void
557 _mesa_enable_1_3_extensions(struct gl_context *ctx)
558 {
559    /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
560    ctx->Extensions.ARB_multitexture = GL_TRUE;
561    ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
562    /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
563    ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
564    ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
565    ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
566    ctx->Extensions.EXT_texture_env_add = GL_TRUE;
567    /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
568 }
569
570
571
572 /**
573  * Enable all OpenGL 1.4 features and extensions.
574  * A convenience function to be called by drivers.
575  */
576 void
577 _mesa_enable_1_4_extensions(struct gl_context *ctx)
578 {
579    ctx->Extensions.ARB_depth_texture = GL_TRUE;
580    ctx->Extensions.ARB_shadow = GL_TRUE;
581    ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
582    ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
583    ctx->Extensions.ARB_window_pos = GL_TRUE;
584    ctx->Extensions.EXT_blend_color = GL_TRUE;
585    ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
586    ctx->Extensions.EXT_blend_minmax = GL_TRUE;
587    ctx->Extensions.EXT_blend_subtract = GL_TRUE;
588    ctx->Extensions.EXT_fog_coord = GL_TRUE;
589    /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
590    ctx->Extensions.EXT_point_parameters = GL_TRUE;
591    ctx->Extensions.EXT_secondary_color = GL_TRUE;
592    ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
593    ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
594    /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
595 }
596
597
598 /**
599  * Enable all OpenGL 1.5 features and extensions.
600  * A convenience function to be called by drivers.
601  */
602 void
603 _mesa_enable_1_5_extensions(struct gl_context *ctx)
604 {
605    ctx->Extensions.ARB_occlusion_query = GL_TRUE;
606    /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
607    ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
608 }
609
610
611 /**
612  * Enable all OpenGL 2.0 features and extensions.
613  * A convenience function to be called by drivers.
614  */
615 void
616 _mesa_enable_2_0_extensions(struct gl_context *ctx)
617 {
618    /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
619 #if FEATURE_ARB_fragment_shader
620    ctx->Extensions.ARB_fragment_shader = GL_TRUE;
621 #endif
622    ctx->Extensions.ARB_point_sprite = GL_TRUE;
623    ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
624    ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
625 #if FEATURE_ARB_shader_objects
626    ctx->Extensions.ARB_shader_objects = GL_TRUE;
627 #endif
628 #if FEATURE_ARB_shading_language_100
629    ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
630 #endif
631    ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
632 #if FEATURE_ARB_vertex_shader
633    ctx->Extensions.ARB_vertex_shader = GL_TRUE;
634 #endif
635 }
636
637
638 /**
639  * Enable all OpenGL 2.1 features and extensions.
640  * A convenience function to be called by drivers.
641  */
642 void
643 _mesa_enable_2_1_extensions(struct gl_context *ctx)
644 {
645 #if FEATURE_EXT_pixel_buffer_object
646    ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
647 #endif
648 #if FEATURE_EXT_texture_sRGB
649    ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
650 #endif
651 }
652
653
654 /**
655  * Either enable or disable the named extension.
656  * \return GL_TRUE for success, GL_FALSE if invalid extension name
657  */
658 static GLboolean
659 set_extension( struct gl_context *ctx, const char *name, GLboolean state )
660 {
661    size_t offset;
662
663    if (ctx->Extensions.String) {
664       /* The string was already queried - can't change it now! */
665       _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
666       return GL_FALSE;
667    }
668
669    offset = name_to_offset(name);
670    if (offset == 0) {
671       _mesa_problem(ctx, "Trying to enable/disable unknown extension %s",
672                     name);
673       return GL_FALSE;
674    } else if (offset == o(dummy_true) && state == GL_FALSE) {
675       _mesa_problem(ctx, "Trying to disable a permanently enabled extension: "
676                           "%s", name);
677       return GL_FALSE;
678    } else {
679       GLboolean *base = (GLboolean *) &ctx->Extensions;
680       base[offset] = state;
681       return GL_TRUE;
682    }
683 }
684
685
686 /**
687  * Enable the named extension.
688  * Typically called by drivers.
689  */
690 void
691 _mesa_enable_extension( struct gl_context *ctx, const char *name )
692 {
693    if (!set_extension(ctx, name, GL_TRUE))
694       _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
695 }
696
697
698 /**
699  * Disable the named extension.
700  * XXX is this really needed???
701  */
702 void
703 _mesa_disable_extension( struct gl_context *ctx, const char *name )
704 {
705    if (!set_extension(ctx, name, GL_FALSE))
706       _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
707 }
708
709
710 /**
711  * Test if the named extension is enabled in this context.
712  */
713 GLboolean
714 _mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
715 {
716    size_t offset;
717    GLboolean *base;
718
719    if (name == 0)
720       return GL_FALSE;
721
722    offset = name_to_offset(name);
723    if (offset == 0)
724       return GL_FALSE;
725    base = (GLboolean *) &ctx->Extensions;
726    return base[offset];
727 }
728
729
730 /**
731  * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
732  *
733  * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
734  * enable or disable. The list is processed thus:
735  *    - Enable recognized extension names that are prefixed with '+'.
736  *    - Disable recognized extension names that are prefixed with '-'.
737  *    - Enable recognized extension names that are not prefixed.
738  *    - Collect unrecognized extension names in a new string.
739  *
740  * \return Space-separated list of unrecognized extension names (which must
741  *    be freed). Does not return \c NULL.
742  */
743 static char *
744 get_extension_override( struct gl_context *ctx )
745 {
746    const char *env_const = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
747    char *env;
748    char *ext;
749    char *extra_exts;
750    int len;
751
752    if (env_const == NULL) {
753       /* Return the empty string rather than NULL. This simplifies the logic
754        * of client functions. */
755       return calloc(4, sizeof(char));
756    }
757
758    /* extra_exts: List of unrecognized extensions. */
759    extra_exts = calloc(ALIGN(strlen(env_const) + 2, 4), sizeof(char));
760
761    /* Copy env_const because strtok() is destructive. */
762    env = strdup(env_const);
763    for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
764       int enable;
765       int recognized;
766       switch (ext[0]) {
767       case '+':
768          enable = 1;
769          ++ext;
770          break;
771       case '-':
772          enable = 0;
773          ++ext;
774          break;
775       default:
776          enable = 1;
777          break;
778       }
779       recognized = set_extension(ctx, ext, enable);
780       if (!recognized) {
781          strcat(extra_exts, ext);
782          strcat(extra_exts, " ");
783       }
784    }
785
786    /* Remove trailing space. */
787    len = strlen(extra_exts);
788    if (extra_exts[len - 1] == ' ')
789       extra_exts[len - 1] = '\0';
790
791    return extra_exts;
792 }
793
794
795 /**
796  * \brief Initialize extension tables and enable default extensions.
797  *
798  * This should be called during context initialization.
799  * Note: Sets gl_extensions.dummy_true to true.
800  */
801 void
802 _mesa_init_extensions( struct gl_context *ctx )
803 {
804    GLboolean *base = (GLboolean *) &ctx->Extensions;
805    GLboolean *sentinel = base + o(extension_sentinel);
806    GLboolean *i;
807    const size_t *j;
808
809    /* First, turn all extensions off. */
810    for (i = base; i != sentinel; ++i)
811       *i = GL_FALSE;
812
813    /* Then, selectively turn default extensions on. */
814    ctx->Extensions.dummy_true = GL_TRUE;
815    for (j = default_extensions; *j != 0; ++j)
816       base[*j] = GL_TRUE;
817 }
818
819
820 typedef unsigned short extension_index;
821
822
823 /**
824  * Compare two entries of the extensions table.  Sorts first by year,
825  * then by name.
826  *
827  * Arguments are indices into extension_table.
828  */
829 static int
830 extension_compare(const void *p1, const void *p2)
831 {
832    extension_index i1 = * (const extension_index *) p1;
833    extension_index i2 = * (const extension_index *) p2;
834    const struct extension *e1 = &extension_table[i1];
835    const struct extension *e2 = &extension_table[i2];
836    int res;
837
838    res = (int)e1->year - (int)e2->year;
839
840    if (res == 0) {
841       res = strcmp(e1->name, e2->name);
842    }
843
844    return res;
845 }
846
847
848 /**
849  * Construct the GL_EXTENSIONS string.  Called the first time that
850  * glGetString(GL_EXTENSIONS) is called.
851  */
852 GLubyte*
853 _mesa_make_extension_string(struct gl_context *ctx)
854 {
855    /* The extension string. */
856    char *exts = 0;
857    /* Length of extension string. */
858    size_t length = 0;
859    /* Number of extensions */
860    unsigned count;
861    /* Indices of the extensions sorted by year */
862    extension_index *extension_indices;
863    /* String of extra extensions. */
864    char *extra_extensions = get_extension_override(ctx);
865    GLboolean *base = (GLboolean *) &ctx->Extensions;
866    const struct extension *i;
867    unsigned j;
868    unsigned maxYear = ~0;
869
870    /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */
871    {
872       const char *env = getenv("MESA_EXTENSION_MAX_YEAR");
873       if (env) {
874          maxYear = atoi(env);
875          _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n",
876                      maxYear);
877       }
878    }
879
880    /* Compute length of the extension string. */
881    count = 0;
882    for (i = extension_table; i->name != 0; ++i) {
883       if (base[i->offset] &&
884           i->year <= maxYear &&
885           (i->api_set & (1 << ctx->API))) {
886          length += strlen(i->name) + 1; /* +1 for space */
887          ++count;
888       }
889    }
890    if (extra_extensions != NULL)
891       length += 1 + strlen(extra_extensions); /* +1 for space */
892
893    exts = (char *) calloc(ALIGN(length + 1, 4), sizeof(char));
894    if (exts == NULL) {
895       free(extra_extensions);
896       return NULL;
897    }
898
899    extension_indices = malloc(count * sizeof(extension_index));
900    if (extension_indices == NULL) {
901       free(exts);
902       free(extra_extensions);
903       return NULL;
904    }
905
906    /* Sort extensions in chronological order because certain old applications (e.g.,
907     * Quake3 demo) store the extension list in a static size buffer so chronologically
908     * order ensure that the extensions that such applications expect will fit into
909     * that buffer.
910     */
911    j = 0;
912    for (i = extension_table; i->name != 0; ++i) {
913       if (base[i->offset] &&
914           i->year <= maxYear &&
915           (i->api_set & (1 << ctx->API))) {
916          extension_indices[j++] = i - extension_table;
917       }
918    }
919    assert(j == count);
920    qsort(extension_indices, count, sizeof *extension_indices, extension_compare);
921
922    /* Build the extension string.*/
923    for (j = 0; j < count; ++j) {
924       i = &extension_table[extension_indices[j]];
925       assert(base[i->offset] && (i->api_set & (1 << ctx->API)));
926       strcat(exts, i->name);
927       strcat(exts, " ");
928    }
929    free(extension_indices);
930    if (extra_extensions != 0) {
931       strcat(exts, extra_extensions);
932       free(extra_extensions);
933    }
934
935    return (GLubyte *) exts;
936 }
937
938 /**
939  * Return number of enabled extensions.
940  */
941 GLuint
942 _mesa_get_extension_count(struct gl_context *ctx)
943 {
944    GLboolean *base;
945    const struct extension *i;
946
947    /* only count once */
948    if (ctx->Extensions.Count != 0)
949       return ctx->Extensions.Count;
950
951    base = (GLboolean *) &ctx->Extensions;
952    for (i = extension_table; i->name != 0; ++i) {
953       if (base[i->offset]) {
954          ctx->Extensions.Count++;
955       }
956    }
957    return ctx->Extensions.Count;
958 }
959
960 /**
961  * Return name of i-th enabled extension
962  */
963 const GLubyte *
964 _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
965 {
966    const GLboolean *base;
967    size_t n;
968    const struct extension *i;
969
970    if (index < 0)
971       return NULL;
972
973    base = (GLboolean*) &ctx->Extensions;
974    n = 0;
975    for (i = extension_table; i->name != 0; ++i) {
976       if (n == index && base[i->offset]) {
977          return (GLubyte*) i->name;
978       } else if (base[i->offset]) {
979          ++n;
980       }
981    }
982
983    return NULL;
984 }