1cdc920a0Smrg/* 2cdc920a0Smrg * (C) Copyright IBM Corporation 2002, 2004 3cdc920a0Smrg * All Rights Reserved. 4cdc920a0Smrg * 5cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6cdc920a0Smrg * copy of this software and associated documentation files (the "Software"), 7cdc920a0Smrg * to deal in the Software without restriction, including without limitation 8cdc920a0Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 9cdc920a0Smrg * license, and/or sell copies of the Software, and to permit persons to whom 10cdc920a0Smrg * the Software is furnished to do so, subject to the following conditions: 11cdc920a0Smrg * 12cdc920a0Smrg * The above copyright notice and this permission notice (including the next 13cdc920a0Smrg * paragraph) shall be included in all copies or substantial portions of the 14cdc920a0Smrg * Software. 15cdc920a0Smrg * 16cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17cdc920a0Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18cdc920a0Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19cdc920a0Smrg * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20cdc920a0Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21cdc920a0Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22cdc920a0Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 23cdc920a0Smrg */ 24cdc920a0Smrg 25cdc920a0Smrg/** 26cdc920a0Smrg * \file glxextensions.c 27cdc920a0Smrg * 28cdc920a0Smrg * \author Ian Romanick <idr@us.ibm.com> 29cdc920a0Smrg */ 30cdc920a0Smrg 31cdc920a0Smrg#include "glxclient.h" 32cdc920a0Smrg#include <X11/extensions/extutil.h> 33cdc920a0Smrg#include <X11/extensions/Xext.h> 34cdc920a0Smrg#include <string.h> 35cdc920a0Smrg#include "glxextensions.h" 36cdc920a0Smrg 377ec681f3Smrg#include "util/driconf.h" 38cdc920a0Smrg 39cdc920a0Smrg#define SET_BIT(m,b) (m[ (b) / 8 ] |= (1U << ((b) % 8))) 40cdc920a0Smrg#define CLR_BIT(m,b) (m[ (b) / 8 ] &= ~(1U << ((b) % 8))) 41cdc920a0Smrg#define IS_SET(m,b) ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0) 42cdc920a0Smrg#define CONCAT(a,b) a ## b 43cdc920a0Smrg#define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit) 44cdc920a0Smrg#define GL(n) "GL_" # n, 3 + sizeof( # n ) - 1, GL_ ## n ## _bit 45cdc920a0Smrg#define Y 1 46cdc920a0Smrg#define N 0 47cdc920a0Smrg#define EXT_ENABLED(bit,supported) (IS_SET( supported, bit )) 48cdc920a0Smrg 49cdc920a0Smrg 50cdc920a0Smrgstruct extension_info 51cdc920a0Smrg{ 52cdc920a0Smrg const char *const name; 53cdc920a0Smrg unsigned name_len; 54cdc920a0Smrg 55cdc920a0Smrg unsigned char bit; 56cdc920a0Smrg 5701e04c3fSmrg /** 5801e04c3fSmrg * The direct-renderer (e.g., i965_dri.so) supports this extension. 5901e04c3fSmrg * 6001e04c3fSmrg * For cases where all of the infrastructure to support the extension is a 6101e04c3fSmrg * required part of the loader/driver interface, this can default to Y. 6201e04c3fSmrg * For most cases, extended functionality, usually in the form of DRI2 6301e04c3fSmrg * extensions, is necessary to support the extension. The loader will set 6401e04c3fSmrg * the flag true if all the requirements are met. 6501e04c3fSmrg * 6601e04c3fSmrg * If the display is capable of direct rendering, ::direct_support is 6701e04c3fSmrg * required for the extension to be enabled. 6801e04c3fSmrg */ 69cdc920a0Smrg unsigned char direct_support; 7001e04c3fSmrg 7101e04c3fSmrg /** 7201e04c3fSmrg * The extension only functions with direct-rendering contexts 7301e04c3fSmrg * 7401e04c3fSmrg * The extension has no GLX protocol, and, therefore, no explicit 7501e04c3fSmrg * dependency on the server. The functionality is contained entirely in 7601e04c3fSmrg * the client library and the direct renderer. A few of the swap-related 7701e04c3fSmrg * extensions are intended to behave this way. 7801e04c3fSmrg */ 7901e04c3fSmrg unsigned char direct_only; 80cdc920a0Smrg}; 81cdc920a0Smrg 82cdc920a0Smrg/* *INDENT-OFF* */ 83cdc920a0Smrgstatic const struct extension_info known_glx_extensions[] = { 847ec681f3Smrg { GLX(ARB_context_flush_control), N, N }, 857ec681f3Smrg { GLX(ARB_create_context), N, N }, 867ec681f3Smrg { GLX(ARB_create_context_no_error), N, N }, 877ec681f3Smrg { GLX(ARB_create_context_profile), N, N }, 887ec681f3Smrg { GLX(ARB_create_context_robustness), N, N }, 897ec681f3Smrg { GLX(ARB_fbconfig_float), Y, N }, 907ec681f3Smrg { GLX(ARB_framebuffer_sRGB), Y, N }, 917ec681f3Smrg { GLX(ARB_get_proc_address), N, N }, 927ec681f3Smrg { GLX(ARB_multisample), Y, N }, 937ec681f3Smrg { GLX(EXT_buffer_age), N, Y }, 947ec681f3Smrg { GLX(EXT_create_context_es2_profile), N, N }, 957ec681f3Smrg { GLX(EXT_create_context_es_profile), N, N }, 967ec681f3Smrg { GLX(EXT_fbconfig_packed_float), Y, N }, 977ec681f3Smrg { GLX(EXT_framebuffer_sRGB), Y, N }, 987ec681f3Smrg { GLX(EXT_import_context), Y, N }, 997ec681f3Smrg { GLX(EXT_no_config_context), N, N }, 1007ec681f3Smrg { GLX(EXT_swap_control), N, Y }, 1017ec681f3Smrg { GLX(EXT_swap_control_tear), N, Y }, 1027ec681f3Smrg { GLX(EXT_texture_from_pixmap), N, N }, 1037ec681f3Smrg { GLX(EXT_visual_info), Y, N }, 1047ec681f3Smrg { GLX(EXT_visual_rating), Y, N }, 1057ec681f3Smrg { GLX(ATI_pixel_format_float), N, N }, 1067ec681f3Smrg { GLX(INTEL_swap_event), N, N }, 1077ec681f3Smrg { GLX(MESA_copy_sub_buffer), N, N }, 1087ec681f3Smrg { GLX(MESA_multithread_makecurrent), N, Y }, 1097ec681f3Smrg { GLX(MESA_query_renderer), N, Y }, 1107ec681f3Smrg { GLX(MESA_swap_control), N, Y }, 1117ec681f3Smrg { GLX(NV_float_buffer), N, N }, 1127ec681f3Smrg { GLX(OML_swap_method), Y, N }, 1137ec681f3Smrg { GLX(OML_sync_control), N, Y }, 1147ec681f3Smrg { GLX(SGIS_multisample), Y, N }, 1157ec681f3Smrg { GLX(SGIX_fbconfig), Y, N }, 1167ec681f3Smrg { GLX(SGIX_pbuffer), Y, N }, 1177ec681f3Smrg { GLX(SGIX_visual_select_group), Y, N }, 1187ec681f3Smrg { GLX(SGI_make_current_read), N, N }, 1197ec681f3Smrg { GLX(SGI_swap_control), N, N }, 1207ec681f3Smrg { GLX(SGI_video_sync), N, Y }, 121cdc920a0Smrg { NULL } 122cdc920a0Smrg}; 123cdc920a0Smrg 124cdc920a0Smrgstatic const struct extension_info known_gl_extensions[] = { 1257ec681f3Smrg { GL(ARB_depth_texture), N, N }, 1267ec681f3Smrg { GL(ARB_draw_buffers), N, N }, 1277ec681f3Smrg { GL(ARB_fragment_program), N, N }, 1287ec681f3Smrg { GL(ARB_fragment_program_shadow), N, N }, 1297ec681f3Smrg { GL(ARB_framebuffer_object), N, N }, 1307ec681f3Smrg { GL(ARB_imaging), N, N }, 1317ec681f3Smrg { GL(ARB_multisample), N, N }, 1327ec681f3Smrg { GL(ARB_multitexture), N, N }, 1337ec681f3Smrg { GL(ARB_occlusion_query), N, N }, 1347ec681f3Smrg { GL(ARB_point_parameters), N, N }, 1357ec681f3Smrg { GL(ARB_point_sprite), N, N }, 1367ec681f3Smrg { GL(ARB_shadow), N, N }, 1377ec681f3Smrg { GL(ARB_shadow_ambient), N, N }, 1387ec681f3Smrg { GL(ARB_texture_border_clamp), N, N }, 1397ec681f3Smrg { GL(ARB_texture_compression), N, N }, 1407ec681f3Smrg { GL(ARB_texture_cube_map), N, N }, 1417ec681f3Smrg { GL(ARB_texture_env_add), N, N }, 1427ec681f3Smrg { GL(ARB_texture_env_combine), N, N }, 1437ec681f3Smrg { GL(ARB_texture_env_crossbar), N, N }, 1447ec681f3Smrg { GL(ARB_texture_env_dot3), N, N }, 1457ec681f3Smrg { GL(ARB_texture_filter_anisotropic), N, N }, 1467ec681f3Smrg { GL(ARB_texture_mirrored_repeat), N, N }, 1477ec681f3Smrg { GL(ARB_texture_non_power_of_two), N, N }, 1487ec681f3Smrg { GL(ARB_texture_rectangle), N, N }, 1497ec681f3Smrg { GL(ARB_texture_rg), N, N }, 1507ec681f3Smrg { GL(ARB_transpose_matrix), N, N }, 1517ec681f3Smrg { GL(ARB_vertex_program), N, N }, 1527ec681f3Smrg { GL(ARB_window_pos), N, N }, 1537ec681f3Smrg { GL(EXT_abgr), N, N }, 1547ec681f3Smrg { GL(EXT_bgra), N, N }, 1557ec681f3Smrg { GL(EXT_blend_color), N, N }, 1567ec681f3Smrg { GL(EXT_blend_equation_separate), N, N }, 1577ec681f3Smrg { GL(EXT_blend_func_separate), N, N }, 1587ec681f3Smrg { GL(EXT_blend_logic_op), N, N }, 1597ec681f3Smrg { GL(EXT_blend_minmax), N, N }, 1607ec681f3Smrg { GL(EXT_blend_subtract), N, N }, 1617ec681f3Smrg { GL(EXT_clip_volume_hint), N, N }, 1627ec681f3Smrg { GL(EXT_copy_texture), N, N }, 1637ec681f3Smrg { GL(EXT_draw_range_elements), N, N }, 1647ec681f3Smrg { GL(EXT_fog_coord), N, N }, 1657ec681f3Smrg { GL(EXT_framebuffer_blit), N, N }, 1667ec681f3Smrg { GL(EXT_framebuffer_multisample), N, N }, 1677ec681f3Smrg { GL(EXT_framebuffer_object), N, N }, 1687ec681f3Smrg { GL(EXT_framebuffer_sRGB), N, N }, 1697ec681f3Smrg { GL(EXT_multi_draw_arrays), N, N }, 1707ec681f3Smrg { GL(EXT_packed_depth_stencil), N, N }, 1717ec681f3Smrg { GL(EXT_packed_pixels), N, N }, 1727ec681f3Smrg { GL(EXT_paletted_texture), N, N }, 1737ec681f3Smrg { GL(EXT_point_parameters), N, N }, 1747ec681f3Smrg { GL(EXT_polygon_offset), N, N }, 1757ec681f3Smrg { GL(EXT_rescale_normal), N, N }, 1767ec681f3Smrg { GL(EXT_secondary_color), N, N }, 1777ec681f3Smrg { GL(EXT_separate_specular_color), N, N }, 1787ec681f3Smrg { GL(EXT_shadow_funcs), N, N }, 1797ec681f3Smrg { GL(EXT_shared_texture_palette), N, N }, 1807ec681f3Smrg { GL(EXT_stencil_two_side), N, N }, 1817ec681f3Smrg { GL(EXT_stencil_wrap), N, N }, 1827ec681f3Smrg { GL(EXT_subtexture), N, N }, 1837ec681f3Smrg { GL(EXT_texture), N, N }, 1847ec681f3Smrg { GL(EXT_texture3D), N, N }, 1857ec681f3Smrg { GL(EXT_texture_compression_dxt1), N, N }, 1867ec681f3Smrg { GL(EXT_texture_compression_s3tc), N, N }, 1877ec681f3Smrg { GL(EXT_texture_edge_clamp), N, N }, 1887ec681f3Smrg { GL(EXT_texture_env_add), N, N }, 1897ec681f3Smrg { GL(EXT_texture_env_combine), N, N }, 1907ec681f3Smrg { GL(EXT_texture_env_dot3), N, N }, 1917ec681f3Smrg { GL(EXT_texture_filter_anisotropic), N, N }, 1927ec681f3Smrg { GL(EXT_texture_integer), N, N }, 1937ec681f3Smrg { GL(EXT_texture_lod), N, N }, 1947ec681f3Smrg { GL(EXT_texture_lod_bias), N, N }, 1957ec681f3Smrg { GL(EXT_texture_mirror_clamp), N, N }, 1967ec681f3Smrg { GL(EXT_texture_object), N, N }, 1977ec681f3Smrg { GL(EXT_texture_rectangle), N, N }, 1987ec681f3Smrg { GL(EXT_vertex_array), N, N }, 1997ec681f3Smrg { GL(3DFX_texture_compression_FXT1), N, N }, 2007ec681f3Smrg { GL(APPLE_packed_pixels), N, N }, 2017ec681f3Smrg { GL(APPLE_ycbcr_422), N, N }, 2027ec681f3Smrg { GL(ATI_draw_buffers), N, N }, 2037ec681f3Smrg { GL(ATI_text_fragment_shader), N, N }, 2047ec681f3Smrg { GL(ATI_texture_env_combine3), N, N }, 2057ec681f3Smrg { GL(ATI_texture_float), N, N }, 2067ec681f3Smrg { GL(ATI_texture_mirror_once), N, N }, 2077ec681f3Smrg { GL(ATIX_texture_env_combine3), N, N }, 2087ec681f3Smrg { GL(HP_convolution_border_modes), N, N }, 2097ec681f3Smrg { GL(HP_occlusion_test), N, N }, 2107ec681f3Smrg { GL(IBM_cull_vertex), N, N }, 2117ec681f3Smrg { GL(IBM_pixel_filter_hint), N, N }, 2127ec681f3Smrg { GL(IBM_rasterpos_clip), N, N }, 2137ec681f3Smrg { GL(IBM_texture_clamp_nodraw), N, N }, 2147ec681f3Smrg { GL(IBM_texture_mirrored_repeat), N, N }, 2157ec681f3Smrg { GL(INGR_blend_func_separate), N, N }, 2167ec681f3Smrg { GL(INGR_interlace_read), N, N }, 2177ec681f3Smrg { GL(MESA_pack_invert), N, N }, 2187ec681f3Smrg { GL(MESA_ycbcr_texture), N, N }, 2197ec681f3Smrg { GL(NV_blend_square), N, N }, 2207ec681f3Smrg { GL(NV_copy_depth_to_color), N, N }, 2217ec681f3Smrg { GL(NV_depth_clamp), N, N }, 2227ec681f3Smrg { GL(NV_fog_distance), N, N }, 2237ec681f3Smrg { GL(NV_fragment_program), N, N }, 2247ec681f3Smrg { GL(NV_fragment_program_option), N, N }, 2257ec681f3Smrg { GL(NV_fragment_program2), N, N }, 2267ec681f3Smrg { GL(NV_light_max_exponent), N, N }, 2277ec681f3Smrg { GL(NV_multisample_filter_hint), N, N }, 2287ec681f3Smrg { GL(NV_packed_depth_stencil), N, N }, 2297ec681f3Smrg { GL(NV_point_sprite), N, N }, 2307ec681f3Smrg { GL(NV_texgen_reflection), N, N }, 2317ec681f3Smrg { GL(NV_texture_compression_vtc), N, N }, 2327ec681f3Smrg { GL(NV_texture_env_combine4), N, N }, 2337ec681f3Smrg { GL(NV_texture_rectangle), N, N }, 2347ec681f3Smrg { GL(NV_vertex_program), N, N }, 2357ec681f3Smrg { GL(NV_vertex_program1_1), N, N }, 2367ec681f3Smrg { GL(NV_vertex_program2), N, N }, 2377ec681f3Smrg { GL(NV_vertex_program2_option), N, N }, 2387ec681f3Smrg { GL(NV_vertex_program3), N, N }, 2397ec681f3Smrg { GL(OES_read_format), N, N }, 2407ec681f3Smrg { GL(OES_compressed_paletted_texture), N, N }, 2417ec681f3Smrg { GL(SGI_color_matrix), N, N }, 2427ec681f3Smrg { GL(SGI_color_table), N, N }, 2437ec681f3Smrg { GL(SGI_texture_color_table), N, N }, 2447ec681f3Smrg { GL(SGIS_generate_mipmap), N, N }, 2457ec681f3Smrg { GL(SGIS_multisample), N, N }, 2467ec681f3Smrg { GL(SGIS_texture_border_clamp), N, N }, 2477ec681f3Smrg { GL(SGIS_texture_edge_clamp), N, N }, 2487ec681f3Smrg { GL(SGIS_texture_lod), N, N }, 2497ec681f3Smrg { GL(SGIX_blend_alpha_minmax), N, N }, 2507ec681f3Smrg { GL(SGIX_clipmap), N, N }, 2517ec681f3Smrg { GL(SGIX_depth_texture), N, N }, 2527ec681f3Smrg { GL(SGIX_fog_offset), N, N }, 2537ec681f3Smrg { GL(SGIX_shadow), N, N }, 2547ec681f3Smrg { GL(SGIX_shadow_ambient), N, N }, 2557ec681f3Smrg { GL(SGIX_texture_coordinate_clamp), N, N }, 2567ec681f3Smrg { GL(SGIX_texture_lod_bias), N, N }, 2577ec681f3Smrg { GL(SGIX_texture_range), N, N }, 2587ec681f3Smrg { GL(SGIX_texture_scale_bias), N, N }, 2597ec681f3Smrg { GL(SGIX_vertex_preclip), N, N }, 2607ec681f3Smrg { GL(SGIX_vertex_preclip_hint), N, N }, 2617ec681f3Smrg { GL(SGIX_ycrcb), N, N }, 2627ec681f3Smrg { GL(SUN_convolution_border_modes), N, N }, 2637ec681f3Smrg { GL(SUN_multi_draw_arrays), N, N }, 2647ec681f3Smrg { GL(SUN_slice_accum), N, N }, 265cdc920a0Smrg { NULL } 266cdc920a0Smrg}; 267cdc920a0Smrg/* *INDENT-ON* */ 268cdc920a0Smrg 269cdc920a0Smrg 270cdc920a0Smrg/* global bit-fields of available extensions and their characteristics */ 2717ec681f3Smrgstatic unsigned char client_glx_only[__GLX_EXT_BYTES]; 2727ec681f3Smrgstatic unsigned char direct_glx_only[__GLX_EXT_BYTES]; 273cdc920a0Smrg 274cdc920a0Smrg/** 275cdc920a0Smrg * Bits representing the set of extensions that are enabled by default in all 276cdc920a0Smrg * direct rendering drivers. 277cdc920a0Smrg */ 2787ec681f3Smrgstatic unsigned char direct_glx_support[__GLX_EXT_BYTES]; 279cdc920a0Smrg 280cdc920a0Smrg/* client extensions string */ 281cdc920a0Smrgstatic const char *__glXGLXClientExtensions = NULL; 282cdc920a0Smrg 283cdc920a0Smrgstatic void __glXExtensionsCtr(void); 2843464ebd5Sriastradhstatic void __glXExtensionsCtrScreen(struct glx_screen * psc); 285cdc920a0Smrgstatic void __glXProcessServerString(const struct extension_info *ext, 286cdc920a0Smrg const char *server_string, 287cdc920a0Smrg unsigned char *server_support); 288cdc920a0Smrg 289cdc920a0Smrg/** 2907ec681f3Smrg * Find an extension in the list based on its name. 291cdc920a0Smrg * 2927ec681f3Smrg * \param ext List of extensions where to search. 293cdc920a0Smrg * \param name Name of the extension. 294cdc920a0Smrg * \param name_len Length, in characters, of the extension name. 295cdc920a0Smrg */ 2967ec681f3Smrgstatic const struct extension_info * 2977ec681f3Smrgfind_extension(const struct extension_info *ext, const char *name, 2987ec681f3Smrg unsigned name_len) 299cdc920a0Smrg{ 300cdc920a0Smrg unsigned i; 301cdc920a0Smrg 302cdc920a0Smrg for (i = 0; ext[i].name != NULL; i++) { 303cdc920a0Smrg if ((name_len == ext[i].name_len) 304cdc920a0Smrg && (strncmp(ext[i].name, name, name_len) == 0)) { 3057ec681f3Smrg return &ext[i]; 306cdc920a0Smrg } 307cdc920a0Smrg } 3087ec681f3Smrg 3097ec681f3Smrg return NULL; 3107ec681f3Smrg} 3117ec681f3Smrg 3127ec681f3Smrg/** 3137ec681f3Smrg * Set the state of a GLX extension. 3147ec681f3Smrg * 3157ec681f3Smrg * \param name Name of the extension. 3167ec681f3Smrg * \param name_len Length, in characters, of the extension name. 3177ec681f3Smrg * \param state New state (either enabled or disabled) of the extension. 3187ec681f3Smrg * \param supported Table in which the state of the extension is to be set. 3197ec681f3Smrg */ 3207ec681f3Smrgstatic void 3217ec681f3Smrgset_glx_extension(const struct extension_info *ext_list, 3227ec681f3Smrg const char *name, unsigned name_len, GLboolean state, 3237ec681f3Smrg unsigned char *supported) 3247ec681f3Smrg{ 3257ec681f3Smrg const struct extension_info *ext = find_extension(ext_list, name, name_len); 3267ec681f3Smrg if (!ext) 3277ec681f3Smrg return; 3287ec681f3Smrg 3297ec681f3Smrg if (state) { 3307ec681f3Smrg SET_BIT(supported, ext->bit); 3317ec681f3Smrg } else { 3327ec681f3Smrg CLR_BIT(supported, ext->bit); 3337ec681f3Smrg } 334cdc920a0Smrg} 335cdc920a0Smrg 336cdc920a0Smrg 337cdc920a0Smrg#define NUL '\0' 338cdc920a0Smrg#define SEPARATOR ' ' 339cdc920a0Smrg 340cdc920a0Smrg/** 341cdc920a0Smrg * Convert the server's extension string to a bit-field. 342cdc920a0Smrg * 343cdc920a0Smrg * \param server_string GLX extension string from the server. 344cdc920a0Smrg * \param server_support Bit-field of supported extensions. 345cdc920a0Smrg * 346cdc920a0Smrg * \note 347cdc920a0Smrg * This function is used to process both GLX and GL extension strings. The 348cdc920a0Smrg * bit-fields used to track each of these have different sizes. Therefore, 349cdc920a0Smrg * the data pointed by \c server_support must be preinitialized to zero. 350cdc920a0Smrg */ 351cdc920a0Smrgstatic void 352cdc920a0Smrg__glXProcessServerString(const struct extension_info *ext, 353cdc920a0Smrg const char *server_string, 354cdc920a0Smrg unsigned char *server_support) 355cdc920a0Smrg{ 356cdc920a0Smrg unsigned base; 357cdc920a0Smrg unsigned len; 358cdc920a0Smrg 359cdc920a0Smrg for (base = 0; server_string[base] != NUL; /* empty */ ) { 360cdc920a0Smrg /* Determine the length of the next extension name. 361cdc920a0Smrg */ 362cdc920a0Smrg for (len = 0; (server_string[base + len] != SEPARATOR) 363cdc920a0Smrg && (server_string[base + len] != NUL); len++) { 364cdc920a0Smrg /* empty */ 365cdc920a0Smrg } 366cdc920a0Smrg 367cdc920a0Smrg /* Set the bit for the extension in the server_support table. 368cdc920a0Smrg */ 369cdc920a0Smrg set_glx_extension(ext, &server_string[base], len, GL_TRUE, 370cdc920a0Smrg server_support); 371cdc920a0Smrg 372cdc920a0Smrg 373cdc920a0Smrg /* Advance to the next extension string. This means that we skip 374cdc920a0Smrg * over the previous string and any trialing white-space. 375cdc920a0Smrg */ 376cdc920a0Smrg for (base += len; (server_string[base] == SEPARATOR) 377cdc920a0Smrg && (server_string[base] != NUL); base++) { 378cdc920a0Smrg /* empty */ 379cdc920a0Smrg } 380cdc920a0Smrg } 381cdc920a0Smrg} 382cdc920a0Smrg 383cdc920a0Smrgvoid 3843464ebd5Sriastradh__glXEnableDirectExtension(struct glx_screen * psc, const char *name) 385cdc920a0Smrg{ 386cdc920a0Smrg __glXExtensionsCtr(); 387cdc920a0Smrg __glXExtensionsCtrScreen(psc); 388cdc920a0Smrg 389cdc920a0Smrg set_glx_extension(known_glx_extensions, 390cdc920a0Smrg name, strlen(name), GL_TRUE, psc->direct_support); 391cdc920a0Smrg} 392cdc920a0Smrg 3937ec681f3Smrgstatic void 3947ec681f3Smrg__ParseExtensionOverride(struct glx_screen *psc, 3957ec681f3Smrg const struct extension_info *ext_list, 3967ec681f3Smrg unsigned char *force_enable, 3977ec681f3Smrg unsigned char *force_disable, 3987ec681f3Smrg const char *override) 3997ec681f3Smrg{ 4007ec681f3Smrg const struct extension_info *ext; 4017ec681f3Smrg char *env, *field; 4027ec681f3Smrg 4037ec681f3Smrg if (override == NULL) 4047ec681f3Smrg return; 4057ec681f3Smrg 4067ec681f3Smrg /* Copy env_const because strtok() is destructive. */ 4077ec681f3Smrg env = strdup(override); 4087ec681f3Smrg if (env == NULL) 4097ec681f3Smrg return; 4107ec681f3Smrg 4117ec681f3Smrg for (field = strtok(env, " "); field!= NULL; field = strtok(NULL, " ")) { 4127ec681f3Smrg GLboolean enable; 4137ec681f3Smrg 4147ec681f3Smrg switch (field[0]) { 4157ec681f3Smrg case '+': 4167ec681f3Smrg enable = GL_TRUE; 4177ec681f3Smrg ++field; 4187ec681f3Smrg break; 4197ec681f3Smrg case '-': 4207ec681f3Smrg enable = GL_FALSE; 4217ec681f3Smrg ++field; 4227ec681f3Smrg break; 4237ec681f3Smrg default: 4247ec681f3Smrg enable = GL_TRUE; 4257ec681f3Smrg break; 4267ec681f3Smrg } 4277ec681f3Smrg 4287ec681f3Smrg ext = find_extension(ext_list, field, strlen(field)); 4297ec681f3Smrg if (ext) { 4307ec681f3Smrg if (enable) 4317ec681f3Smrg SET_BIT(force_enable, ext->bit); 4327ec681f3Smrg else 4337ec681f3Smrg SET_BIT(force_disable, ext->bit); 4347ec681f3Smrg } else { 4357ec681f3Smrg fprintf(stderr, "WARNING: Trying to %s the unknown extension '%s'\n", 4367ec681f3Smrg enable ? "enable" : "disable", field); 4377ec681f3Smrg } 4387ec681f3Smrg } 4397ec681f3Smrg 4407ec681f3Smrg free(env); 4417ec681f3Smrg} 4427ec681f3Smrg 4437ec681f3Smrg/** 4447ec681f3Smrg * \brief Parse the list of GLX extensions that the user wants to 4457ec681f3Smrg * force-enable/disable by using \c override, and write the results to the 4467ec681f3Smrg * screen's context. 4477ec681f3Smrg * 4487ec681f3Smrg * \param psc Pointer to GLX per-screen record. 4497ec681f3Smrg * \param override A space-separated list of extensions to enable or disable. 4507ec681f3Smrg * The list is processed thus: 4517ec681f3Smrg * - Enable recognized extension names that are prefixed with '+'. 4527ec681f3Smrg * - Disable recognized extension names that are prefixed with '-'. 4537ec681f3Smrg * - Enable recognized extension names that are not prefixed. 4547ec681f3Smrg */ 4557ec681f3Smrgvoid 4567ec681f3Smrg__glXParseExtensionOverride(struct glx_screen *psc, const char *override) 4577ec681f3Smrg{ 4587ec681f3Smrg __ParseExtensionOverride(psc, known_glx_extensions, psc->glx_force_enabled, 4597ec681f3Smrg psc->glx_force_disabled, override); 4607ec681f3Smrg} 4617ec681f3Smrg 4627ec681f3Smrg/** 4637ec681f3Smrg * \brief Parse the list of GL extensions that the user wants to 4647ec681f3Smrg * force-enable/disable by using \c override, and write the results to the 4657ec681f3Smrg * screen's context. 4667ec681f3Smrg * 4677ec681f3Smrg * \param psc Pointer to GLX per-screen record. 4687ec681f3Smrg * \param override A space-separated list of extensions to enable or disable. 4697ec681f3Smrg * The list is processed thus: 4707ec681f3Smrg * - Enable recognized extension names that are prefixed with '+'. 4717ec681f3Smrg * - Disable recognized extension names that are prefixed with '-'. 4727ec681f3Smrg * - Enable recognized extension names that are not prefixed. 4737ec681f3Smrg */ 4747ec681f3Smrgvoid 4757ec681f3Smrg__IndirectGlParseExtensionOverride(struct glx_screen *psc, const char *override) 4767ec681f3Smrg{ 4777ec681f3Smrg __ParseExtensionOverride(psc, known_gl_extensions, psc->gl_force_enabled, 4787ec681f3Smrg psc->gl_force_disabled, override); 4797ec681f3Smrg} 4807ec681f3Smrg 4817ec681f3Smrg 482cdc920a0Smrg/** 483cdc920a0Smrg * Initialize global extension support tables. 484cdc920a0Smrg */ 485cdc920a0Smrg 486cdc920a0Smrgstatic void 487cdc920a0Smrg__glXExtensionsCtr(void) 488cdc920a0Smrg{ 489cdc920a0Smrg unsigned i; 490cdc920a0Smrg static GLboolean ext_list_first_time = GL_TRUE; 491cdc920a0Smrg 492cdc920a0Smrg 493cdc920a0Smrg if (ext_list_first_time) { 494cdc920a0Smrg ext_list_first_time = GL_FALSE; 495cdc920a0Smrg 496cdc920a0Smrg (void) memset(direct_glx_support, 0, sizeof(direct_glx_support)); 497cdc920a0Smrg (void) memset(client_glx_only, 0, sizeof(client_glx_only)); 498cdc920a0Smrg (void) memset(direct_glx_only, 0, sizeof(direct_glx_only)); 499cdc920a0Smrg 5007ec681f3Smrg SET_BIT(client_glx_only, ARB_get_proc_address_bit); 501cdc920a0Smrg for (i = 0; known_glx_extensions[i].name != NULL; i++) { 502cdc920a0Smrg const unsigned bit = known_glx_extensions[i].bit; 503cdc920a0Smrg 504cdc920a0Smrg if (known_glx_extensions[i].direct_support) { 505cdc920a0Smrg SET_BIT(direct_glx_support, bit); 506cdc920a0Smrg } 507cdc920a0Smrg 508cdc920a0Smrg if (known_glx_extensions[i].direct_only) { 509cdc920a0Smrg SET_BIT(direct_glx_only, bit); 510cdc920a0Smrg } 511cdc920a0Smrg } 512cdc920a0Smrg } 513cdc920a0Smrg} 514cdc920a0Smrg 515cdc920a0Smrg 516cdc920a0Smrg/** 517cdc920a0Smrg * Make sure that per-screen direct-support table is initialized. 518cdc920a0Smrg * 519cdc920a0Smrg * \param psc Pointer to GLX per-screen record. 520cdc920a0Smrg */ 521cdc920a0Smrg 522cdc920a0Smrgstatic void 5233464ebd5Sriastradh__glXExtensionsCtrScreen(struct glx_screen * psc) 524cdc920a0Smrg{ 525cdc920a0Smrg if (psc->ext_list_first_time) { 526cdc920a0Smrg psc->ext_list_first_time = GL_FALSE; 527cdc920a0Smrg (void) memcpy(psc->direct_support, direct_glx_support, 528cdc920a0Smrg sizeof(direct_glx_support)); 5297ec681f3Smrg (void) memset(psc->glx_force_enabled, 0, 5307ec681f3Smrg sizeof(psc->glx_force_enabled)); 5317ec681f3Smrg (void) memset(psc->glx_force_disabled, 0, 5327ec681f3Smrg sizeof(psc->glx_force_disabled)); 5337ec681f3Smrg (void) memset(psc->gl_force_enabled, 0, 5347ec681f3Smrg sizeof(psc->gl_force_enabled)); 5357ec681f3Smrg (void) memset(psc->gl_force_disabled, 0, 5367ec681f3Smrg sizeof(psc->gl_force_disabled)); 537cdc920a0Smrg } 538cdc920a0Smrg} 539cdc920a0Smrg 540cdc920a0Smrg 541cdc920a0Smrg/** 542cdc920a0Smrg * Check if a certain extension is enabled on a given screen. 543cdc920a0Smrg * 544cdc920a0Smrg * \param psc Pointer to GLX per-screen record. 545cdc920a0Smrg * \param bit Bit index in the direct-support table. 546cdc920a0Smrg * \returns If the extension bit is enabled for the screen, \c GL_TRUE is 547cdc920a0Smrg * returned. If the extension bit is not enabled or if \c psc is 548cdc920a0Smrg * \c NULL, then \c GL_FALSE is returned. 549cdc920a0Smrg */ 550cdc920a0SmrgGLboolean 5513464ebd5Sriastradh__glXExtensionBitIsEnabled(struct glx_screen * psc, unsigned bit) 552cdc920a0Smrg{ 553cdc920a0Smrg GLboolean enabled = GL_FALSE; 554cdc920a0Smrg 555cdc920a0Smrg if (psc != NULL) { 556cdc920a0Smrg __glXExtensionsCtr(); 557cdc920a0Smrg __glXExtensionsCtrScreen(psc); 558cdc920a0Smrg enabled = EXT_ENABLED(bit, psc->direct_support); 559cdc920a0Smrg } 560cdc920a0Smrg 561cdc920a0Smrg return enabled; 562cdc920a0Smrg} 563cdc920a0Smrg 564cdc920a0Smrg 565cdc920a0Smrg/** 566cdc920a0Smrg * Check if a certain extension is enabled in a given context. 567cdc920a0Smrg * 568cdc920a0Smrg */ 569cdc920a0SmrgGLboolean 5703464ebd5Sriastradh__glExtensionBitIsEnabled(struct glx_context *gc, unsigned bit) 571cdc920a0Smrg{ 572cdc920a0Smrg GLboolean enabled = GL_FALSE; 573cdc920a0Smrg 574cdc920a0Smrg if (gc != NULL) { 575cdc920a0Smrg enabled = EXT_ENABLED(bit, gc->gl_extension_bits); 576cdc920a0Smrg } 577cdc920a0Smrg 578cdc920a0Smrg return enabled; 579cdc920a0Smrg} 580cdc920a0Smrg 581cdc920a0Smrg 582cdc920a0Smrg 583cdc920a0Smrg/** 584cdc920a0Smrg * Convert a bit-field to a string of supported extensions. 585cdc920a0Smrg */ 586cdc920a0Smrgstatic char * 587cdc920a0Smrg__glXGetStringFromTable(const struct extension_info *ext, 5887ec681f3Smrg const unsigned char *filter) 589cdc920a0Smrg{ 590cdc920a0Smrg unsigned i; 591cdc920a0Smrg unsigned ext_str_len; 592cdc920a0Smrg char *ext_str; 593cdc920a0Smrg char *point; 594cdc920a0Smrg 595cdc920a0Smrg 596cdc920a0Smrg ext_str_len = 0; 597cdc920a0Smrg for (i = 0; ext[i].name != NULL; i++) { 5987ec681f3Smrg if (!filter || EXT_ENABLED(ext[i].bit, filter)) { 599cdc920a0Smrg ext_str_len += ext[i].name_len + 1; 600cdc920a0Smrg } 601cdc920a0Smrg } 602cdc920a0Smrg 603af69d88dSmrg ext_str = malloc(ext_str_len + 1); 604cdc920a0Smrg if (ext_str != NULL) { 605cdc920a0Smrg point = ext_str; 606cdc920a0Smrg 607cdc920a0Smrg for (i = 0; ext[i].name != NULL; i++) { 6087ec681f3Smrg if (!filter || EXT_ENABLED(ext[i].bit, filter)) { 609cdc920a0Smrg (void) memcpy(point, ext[i].name, ext[i].name_len); 610cdc920a0Smrg point += ext[i].name_len; 611cdc920a0Smrg 612cdc920a0Smrg *point = ' '; 613cdc920a0Smrg point++; 614cdc920a0Smrg } 615cdc920a0Smrg } 616cdc920a0Smrg 617cdc920a0Smrg *point = '\0'; 618cdc920a0Smrg } 619cdc920a0Smrg 620cdc920a0Smrg return ext_str; 621cdc920a0Smrg} 622cdc920a0Smrg 623cdc920a0Smrg 624cdc920a0Smrg/** 625cdc920a0Smrg * Get the string of client library supported extensions. 626cdc920a0Smrg */ 627cdc920a0Smrgconst char * 6287ec681f3Smrg__glXGetClientExtensions(Display *dpy) 629cdc920a0Smrg{ 630cdc920a0Smrg if (__glXGLXClientExtensions == NULL) { 631cdc920a0Smrg __glXExtensionsCtr(); 632cdc920a0Smrg __glXGLXClientExtensions = __glXGetStringFromTable(known_glx_extensions, 6337ec681f3Smrg NULL); 634cdc920a0Smrg } 635cdc920a0Smrg 636cdc920a0Smrg return __glXGLXClientExtensions; 637cdc920a0Smrg} 638cdc920a0Smrg 639cdc920a0Smrg 640cdc920a0Smrg/** 641cdc920a0Smrg * Calculate the list of application usable extensions. The resulting 642cdc920a0Smrg * string is stored in \c psc->effectiveGLXexts. 643cdc920a0Smrg * 644cdc920a0Smrg * \param psc Pointer to GLX per-screen record. 645cdc920a0Smrg * \param display_is_direct_capable True if the display is capable of 646cdc920a0Smrg * direct rendering. 647cdc920a0Smrg */ 648cdc920a0Smrg 649cdc920a0Smrgvoid 6503464ebd5Sriastradh__glXCalculateUsableExtensions(struct glx_screen * psc, 6517ec681f3Smrg GLboolean display_is_direct_capable) 652cdc920a0Smrg{ 6537ec681f3Smrg unsigned char server_support[__GLX_EXT_BYTES]; 6547ec681f3Smrg unsigned char usable[__GLX_EXT_BYTES]; 655cdc920a0Smrg unsigned i; 656cdc920a0Smrg 657cdc920a0Smrg __glXExtensionsCtr(); 658cdc920a0Smrg __glXExtensionsCtrScreen(psc); 659cdc920a0Smrg 660cdc920a0Smrg (void) memset(server_support, 0, sizeof(server_support)); 661cdc920a0Smrg __glXProcessServerString(known_glx_extensions, 662cdc920a0Smrg psc->serverGLXexts, server_support); 663cdc920a0Smrg 664cdc920a0Smrg 665cdc920a0Smrg /* An extension is supported if the client-side (i.e., libGL) supports 666cdc920a0Smrg * it and the "server" supports it. In this case that means that either 667cdc920a0Smrg * the true server supports it or it is only for direct-rendering and 668cdc920a0Smrg * the direct rendering driver supports it. 669cdc920a0Smrg * 670cdc920a0Smrg * If the display is not capable of direct rendering, then the extension 671cdc920a0Smrg * is enabled if and only if the client-side library and the server 672cdc920a0Smrg * support it. 673cdc920a0Smrg */ 674cdc920a0Smrg 675cdc920a0Smrg if (display_is_direct_capable) { 6767ec681f3Smrg for (i = 0; i < __GLX_EXT_BYTES; i++) { 6777ec681f3Smrg /* Enable extensions that the client supports that only have a client-side 6787ec681f3Smrg * component. 6797ec681f3Smrg */ 6807ec681f3Smrg unsigned char u = client_glx_only[i]; 6817ec681f3Smrg 6827ec681f3Smrg /* Enable extensions that are supported for direct rendering, and either 6837ec681f3Smrg * are supported by the server or only have a direct-rendering component. 6847ec681f3Smrg */ 6857ec681f3Smrg u |= psc->direct_support[i] & (server_support[i] | direct_glx_only[i]); 6867ec681f3Smrg 6877ec681f3Smrg /* Finally, apply driconf options to force some extension bits either 6887ec681f3Smrg * enabled or disabled. 6897ec681f3Smrg */ 6907ec681f3Smrg u |= psc->glx_force_enabled[i]; 6917ec681f3Smrg u &= ~psc->glx_force_disabled[i]; 6927ec681f3Smrg 6937ec681f3Smrg usable[i] = u; 694cdc920a0Smrg } 695cdc920a0Smrg } 696cdc920a0Smrg else { 6977ec681f3Smrg for (i = 0; i < __GLX_EXT_BYTES; i++) { 6987ec681f3Smrg /* Enable extensions that the client supports that only have a 6997ec681f3Smrg * client-side component. 7007ec681f3Smrg */ 7017ec681f3Smrg unsigned char u = client_glx_only[i]; 7027ec681f3Smrg 7037ec681f3Smrg /* Enable extensions that the client and server both support */ 7047ec681f3Smrg u |= server_support[i]; 7057ec681f3Smrg 7067ec681f3Smrg /* Finally, apply driconf options to force some extension bits either 7077ec681f3Smrg * enabled or disabled. 7087ec681f3Smrg */ 7097ec681f3Smrg u |= psc->glx_force_enabled[i]; 7107ec681f3Smrg u &= ~psc->glx_force_disabled[i]; 7117ec681f3Smrg 7127ec681f3Smrg usable[i] = u; 713cdc920a0Smrg } 714cdc920a0Smrg } 715cdc920a0Smrg 716cdc920a0Smrg psc->effectiveGLXexts = __glXGetStringFromTable(known_glx_extensions, 717cdc920a0Smrg usable); 718cdc920a0Smrg} 719cdc920a0Smrg 720cdc920a0Smrg/** 721cdc920a0Smrg * Calculate the list of application usable extensions. The resulting 722cdc920a0Smrg * string is stored in \c gc->extensions. 723cdc920a0Smrg * 724cdc920a0Smrg * \param gc Pointer to GLX context. 725cdc920a0Smrg * \param server_string Extension string from the server. 726cdc920a0Smrg */ 727cdc920a0Smrg 728cdc920a0Smrgvoid 7293464ebd5Sriastradh__glXCalculateUsableGLExtensions(struct glx_context * gc, 7307ec681f3Smrg const char *server_string) 731cdc920a0Smrg{ 7327ec681f3Smrg struct glx_screen *psc = gc->psc; 733cdc920a0Smrg unsigned char server_support[__GL_EXT_BYTES]; 734cdc920a0Smrg unsigned char usable[__GL_EXT_BYTES]; 735cdc920a0Smrg unsigned i; 736cdc920a0Smrg 737cdc920a0Smrg (void) memset(server_support, 0, sizeof(server_support)); 738cdc920a0Smrg __glXProcessServerString(known_gl_extensions, server_string, 739cdc920a0Smrg server_support); 740cdc920a0Smrg 7417ec681f3Smrg /* These extensions are wholly inside the client-side indirect code */ 7427ec681f3Smrg (void) memset(usable, 0, sizeof(usable)); 7437ec681f3Smrg SET_BIT(usable, GL_ARB_transpose_matrix_bit); 7447ec681f3Smrg SET_BIT(usable, GL_EXT_draw_range_elements_bit); 7457ec681f3Smrg SET_BIT(usable, GL_EXT_multi_draw_arrays_bit); 7467ec681f3Smrg SET_BIT(usable, GL_SUN_multi_draw_arrays_bit); 747cdc920a0Smrg 748cdc920a0Smrg for (i = 0; i < __GL_EXT_BYTES; i++) { 7497ec681f3Smrg /* Usable if the server supports it, or if it's been forced on */ 7507ec681f3Smrg usable[i] = server_support[i] | psc->gl_force_enabled[i]; 751cdc920a0Smrg 7527ec681f3Smrg /* But not if it's been forced off */ 7537ec681f3Smrg usable[i] &= ~psc->gl_force_disabled[i]; 754cdc920a0Smrg } 755cdc920a0Smrg 756cdc920a0Smrg gc->extensions = (unsigned char *) 757cdc920a0Smrg __glXGetStringFromTable(known_gl_extensions, usable); 758cdc920a0Smrg (void) memcpy(gc->gl_extension_bits, usable, sizeof(usable)); 759cdc920a0Smrg} 760cdc920a0Smrg 761cdc920a0Smrg/** 762cdc920a0Smrg * Get a string representing the set of extensions supported by the client 763cdc920a0Smrg * library. This is currently only used to send the list of extensions 764cdc920a0Smrg * supported by the client to the server. 765cdc920a0Smrg */ 766cdc920a0Smrgchar * 767cdc920a0Smrg__glXGetClientGLExtensionString(void) 768cdc920a0Smrg{ 7697ec681f3Smrg return __glXGetStringFromTable(known_gl_extensions, NULL); 770cdc920a0Smrg} 771