Merge branch 'xa_branch'
[mesa.git] / src / mesa / drivers / dri / intel / intel_extensions.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * 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
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "main/mfeatures.h"
29
30 #include "intel_chipset.h"
31 #include "intel_context.h"
32 #include "intel_extensions.h"
33 #include "utils.h"
34
35
36 #define need_GL_ARB_ES2_compatibility
37 #define need_GL_ARB_draw_elements_base_vertex
38 #define need_GL_ARB_framebuffer_object
39 #define need_GL_ARB_map_buffer_range
40 #define need_GL_ARB_occlusion_query
41 #define need_GL_ARB_point_parameters
42 #define need_GL_ARB_shader_objects
43 #define need_GL_ARB_sync
44 #define need_GL_ARB_vertex_array_object
45 #define need_GL_ARB_vertex_program
46 #define need_GL_ARB_vertex_shader
47 #define need_GL_ARB_window_pos
48 #define need_GL_EXT_blend_color
49 #define need_GL_EXT_blend_equation_separate
50 #define need_GL_EXT_blend_func_separate
51 #define need_GL_EXT_blend_minmax
52 #define need_GL_EXT_draw_buffers2
53 #define need_GL_EXT_fog_coord
54 #define need_GL_EXT_framebuffer_blit
55 #define need_GL_EXT_framebuffer_multisample
56 #define need_GL_EXT_framebuffer_object
57 #define need_GL_EXT_gpu_program_parameters
58 #define need_GL_EXT_point_parameters
59 #define need_GL_EXT_provoking_vertex
60 #define need_GL_EXT_secondary_color
61 #define need_GL_EXT_separate_shader_objects
62 #define need_GL_EXT_stencil_two_side
63 #define need_GL_EXT_timer_query
64 #define need_GL_APPLE_vertex_array_object
65 #define need_GL_APPLE_object_purgeable
66 #define need_GL_ATI_separate_stencil
67 #define need_GL_ATI_envmap_bumpmap
68 #define need_GL_NV_point_sprite
69 #define need_GL_NV_vertex_program
70 #define need_GL_OES_EGL_image
71 #define need_GL_VERSION_2_0
72 #define need_GL_VERSION_2_1
73
74 #include "main/remap_helper.h"
75
76
77 /**
78 * Extension strings exported by the intel driver.
79 *
80 * Extensions supported by all chips supported by i830_dri, i915_dri, or
81 * i965_dri.
82 */
83 static const struct dri_extension card_extensions[] = {
84 { "GL_ARB_ES2_compatibility", GL_ARB_ES2_compatibility_functions },
85 { "GL_ARB_draw_elements_base_vertex", GL_ARB_draw_elements_base_vertex_functions },
86 { "GL_ARB_explicit_attrib_location", NULL },
87 { "GL_ARB_framebuffer_object", GL_ARB_framebuffer_object_functions},
88 { "GL_ARB_half_float_pixel", NULL },
89 { "GL_ARB_map_buffer_range", GL_ARB_map_buffer_range_functions },
90 { "GL_ARB_multitexture", NULL },
91 { "GL_ARB_pixel_buffer_object", NULL },
92 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions },
93 { "GL_ARB_point_sprite", NULL },
94 { "GL_ARB_sampler_objects", NULL },
95 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions },
96 { "GL_ARB_shading_language_100", GL_VERSION_2_0_functions },
97 { "GL_ARB_sync", GL_ARB_sync_functions },
98 { "GL_ARB_texture_border_clamp", NULL },
99 { "GL_ARB_texture_cube_map", NULL },
100 { "GL_ARB_texture_env_add", NULL },
101 { "GL_ARB_texture_env_combine", NULL },
102 { "GL_ARB_texture_env_crossbar", NULL },
103 { "GL_ARB_texture_env_dot3", NULL },
104 { "GL_ARB_texture_mirrored_repeat", NULL },
105 { "GL_ARB_texture_rectangle", NULL },
106 { "GL_ARB_vertex_array_object", GL_ARB_vertex_array_object_functions},
107 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
108 { "GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions },
109 { "GL_ARB_window_pos", GL_ARB_window_pos_functions },
110 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
111 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
112 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
113 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
114 { "GL_EXT_blend_logic_op", NULL },
115 { "GL_EXT_blend_subtract", NULL },
116 { "GL_EXT_framebuffer_blit", GL_EXT_framebuffer_blit_functions },
117 { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions },
118 { "GL_EXT_framebuffer_multisample", GL_EXT_framebuffer_multisample_functions },
119 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
120 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions },
121 { "GL_EXT_packed_depth_stencil", NULL },
122 { "GL_EXT_provoking_vertex", GL_EXT_provoking_vertex_functions },
123 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
124 { "GL_EXT_separate_shader_objects", GL_EXT_separate_shader_objects_functions },
125 { "GL_EXT_stencil_wrap", NULL },
126 { "GL_EXT_texture_edge_clamp", NULL },
127 { "GL_EXT_texture_env_combine", NULL },
128 { "GL_EXT_texture_env_dot3", NULL },
129 { "GL_EXT_texture_filter_anisotropic", NULL },
130 { "GL_EXT_texture_lod_bias", NULL },
131 { "GL_3DFX_texture_compression_FXT1", NULL },
132 { "GL_APPLE_client_storage", NULL },
133 { "GL_APPLE_object_purgeable", GL_APPLE_object_purgeable_functions },
134 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions},
135 { "GL_MESA_pack_invert", NULL },
136 { "GL_MESA_ycbcr_texture", NULL },
137 { "GL_NV_blend_square", NULL },
138 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
139 { "GL_NV_vertex_program1_1", NULL },
140 #if FEATURE_OES_EGL_image
141 { "GL_OES_EGL_image", GL_OES_EGL_image_functions },
142 #endif
143 { NULL, NULL }
144 };
145
146
147 /** i915 / i945-only extensions */
148 static const struct dri_extension i915_extensions[] = {
149 { "GL_ARB_depth_texture", NULL },
150 { "GL_ARB_fragment_program", NULL },
151 { "GL_ARB_shadow", NULL },
152 { "GL_ARB_texture_non_power_of_two", NULL },
153 { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions },
154 { "GL_ATI_texture_env_combine3", NULL },
155 { "GL_EXT_shadow_funcs", NULL },
156 { "GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions },
157 { "GL_NV_texture_env_combine4", NULL },
158 { NULL, NULL }
159 };
160
161
162 /** i965-only extensions */
163 static const struct dri_extension brw_extensions[] = {
164 { "GL_ARB_color_buffer_float", NULL },
165 { "GL_ARB_depth_clamp", NULL },
166 { "GL_ARB_depth_texture", NULL },
167 { "GL_ARB_fragment_coord_conventions", NULL },
168 { "GL_ARB_fragment_program", NULL },
169 { "GL_ARB_fragment_program_shadow", NULL },
170 { "GL_ARB_fragment_shader", NULL },
171 { "GL_ARB_half_float_vertex", NULL },
172 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions },
173 { "GL_ARB_point_sprite", NULL },
174 { "GL_ARB_seamless_cube_map", NULL },
175 { "GL_ARB_shader_texture_lod", NULL },
176 { "GL_ARB_shadow", NULL },
177 #ifdef TEXTURE_FLOAT_ENABLED
178 { "GL_ARB_texture_float", NULL },
179 #endif
180 { "GL_MESA_texture_signed_rgba", NULL },
181 { "GL_ARB_texture_compression_rgtc", NULL },
182 { "GL_ARB_texture_non_power_of_two", NULL },
183 { "GL_ARB_texture_rg", NULL },
184 { "GL_EXT_draw_buffers2", GL_EXT_draw_buffers2_functions },
185 { "GL_EXT_framebuffer_sRGB", NULL },
186 { "GL_EXT_shadow_funcs", NULL },
187 { "GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions },
188 { "GL_EXT_texture_sRGB", NULL },
189 { "GL_EXT_texture_sRGB_decode", NULL },
190 { "GL_EXT_texture_swizzle", NULL },
191 { "GL_EXT_vertex_array_bgra", NULL },
192 { "GL_ATI_envmap_bumpmap", GL_ATI_envmap_bumpmap_functions },
193 { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions },
194 { "GL_ATI_texture_env_combine3", NULL },
195 { "GL_NV_conditional_render", NULL },
196 { "GL_NV_texture_env_combine4", NULL },
197 { NULL, NULL }
198 };
199
200 static const struct dri_extension ironlake_extensions[] = {
201 { "GL_EXT_timer_query", GL_EXT_timer_query_functions },
202 };
203
204 static const struct dri_extension arb_oq_extensions[] = {
205 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions },
206 { NULL, NULL }
207 };
208
209
210 static const struct dri_extension fragment_shader_extensions[] = {
211 { "GL_ARB_fragment_shader", NULL },
212 { NULL, NULL }
213 };
214
215 /**
216 * \brief Get GLSL version from the environment.
217 *
218 * If the environment variable INTEL_GLSL_VERSION is set, convert its value
219 * to an integer and return it. Otherwise, return the default version, 120.
220 */
221 static GLuint
222 get_glsl_version()
223 {
224 const char * s = getenv("INTEL_GLSL_VERSION");
225 if (s == NULL)
226 return 120;
227 else
228 return (GLuint) atoi(s);
229 }
230
231 /**
232 * Initializes potential list of extensions if ctx == NULL, or actually enables
233 * extensions for a context.
234 */
235 void
236 intelInitExtensions(struct gl_context *ctx)
237 {
238 struct intel_context *intel = intel_context(ctx);
239
240 driInitExtensions(ctx, card_extensions, GL_FALSE);
241
242 _mesa_map_function_array(GL_VERSION_2_1_functions);
243
244 ctx->Const.GLSLVersion = get_glsl_version();
245
246 if (intel->gen >= 5)
247 driInitExtensions(ctx, ironlake_extensions, GL_FALSE);
248
249 if (intel->gen >= 4)
250 driInitExtensions(ctx, brw_extensions, GL_FALSE);
251
252 if (intel->gen == 3) {
253 driInitExtensions(ctx, i915_extensions, GL_FALSE);
254
255 if (driQueryOptionb(&intel->optionCache, "fragment_shader"))
256 driInitExtensions(ctx, fragment_shader_extensions, GL_FALSE);
257
258 if (driQueryOptionb(&intel->optionCache, "stub_occlusion_query"))
259 driInitExtensions(ctx, arb_oq_extensions, GL_FALSE);
260 }
261 }