utils.c revision 1585c234e0db4bfb7cd85c4111594f6da1582e6f
193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell/*
274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * (C) Copyright IBM Corporation 2002, 2004
393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * All Rights Reserved.
493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * copy of this software and associated documentation files (the "Software"),
793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * to deal in the Software without restriction, including without limitation
893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * on the rights to use, copy, modify, merge, publish, distribute, sub
993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * license, and/or sell copies of the Software, and to permit persons to whom
1093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * the Software is furnished to do so, subject to the following conditions:
1193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
1293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * The above copyright notice and this permission notice (including the next
1393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * paragraph) shall be included in all copies or substantial portions of the
1493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * Software.
1593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
1693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
1993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
2093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * USE OR OTHER DEALINGS IN THE SOFTWARE.
23447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick */
24447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
25447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick/**
26447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick * \file utils.c
27447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick * Utility functions for DRI drivers.
2893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
29447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick * \author Ian Romanick <idr@us.ibm.com>
3093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell */
3193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
3293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include <string.h>
3393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include <stdlib.h>
3493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "mtypes.h"
3593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "extensions.h"
3693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "utils.h"
371585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#include "dispatch.h"
381585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
391585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanickunsigned driDispatchRemapTable[ driDispatchRemapTable_size ];
4093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
4193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#if defined(USE_X86_ASM)
42ecb1a5f7f98b9e42965318db99b6996f12b87e59Alan Hourihane#include "x86/common_x86_asm.h"
4393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
4493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
45447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#if defined(USE_PPC_ASM)
46447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#include "ppc/common_ppc_features.h"
47447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#endif
48447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
4993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned
5093a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriParseDebugString( const char * debug,
5193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		     const struct dri_debug_control * control  )
5293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
5393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   flag;
5493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
5593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
5693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   flag = 0;
5793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( debug != NULL ) {
5893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      while( control->string != NULL ) {
59462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane	 if ( !strcmp( debug, "all" ) ||
60462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane	      strstr( debug, control->string ) != NULL ) {
6193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	    flag |= control->flag;
6293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 }
6393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 control++;
6593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      }
6693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
6793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return flag;
6993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
7093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
7193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
7293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
73b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick/**
74b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Create the \c GL_RENDERER string for DRI drivers.
75b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
76b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Almost all DRI drivers use a \c GL_RENDERER string of the form:
77b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
78b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *    "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
79b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
80b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Using the supplied chip name, driver data, and AGP speed, this function
81b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * creates the string.
82b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
83b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param buffer         Buffer to hold the \c GL_RENDERER string.
84b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param hardware_name  Name of the hardware.
85b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param driver_date    Driver date.
86b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param agp_mode       AGP mode (speed).
87b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
88b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \returns
89b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * The length of the string stored in \c buffer.  This does \b not include
90b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * the terminating \c NUL character.
91b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick */
9293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned
9393a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriGetRendererString( char * buffer, const char * hardware_name,
9493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		      const char * driver_date, GLuint agp_mode )
9593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
96b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick#define MAX_INFO   4
97b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   const char * cpu[MAX_INFO];
98b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   unsigned   next = 0;
99b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   unsigned   i;
10093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   offset;
10193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
10293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
10393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date );
10493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
10593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Append any AGP-specific information.
10693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell    */
10793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   switch ( agp_mode ) {
10893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 1:
10993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 2:
11093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 4:
11193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 8:
11293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode );
11393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      break;
11493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
11593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   default:
11693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      break;
11793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
11893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
11993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Append any CPU-specific information.
12093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell    */
12193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#ifdef USE_X86_ASM
12293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( _mesa_x86_cpu_features ) {
123b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = " x86";
124b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
12593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
12693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_MMX_ASM
12793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_mmx ) {
128b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
129b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
13093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
13193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
13293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_3DNOW_ASM
13393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_3dnow ) {
134b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
135b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
13693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
13793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
13893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_SSE_ASM
13993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_xmm ) {
140b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
141b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
14293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
14393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
14493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
14593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#elif defined(USE_SPARC_ASM)
14693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
147b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   cpu[0] = " SPARC";
148b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   next = 1;
14993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
150447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#elif defined(USE_PPC_ASM)
151447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   if ( _mesa_ppc_cpu_features ) {
152447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      cpu[next] = (cpu_has_64) ? " PowerPC 64" : " PowerPC";
153447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      next++;
154447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   }
155447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
156447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick# ifdef USE_VMX_ASM
157447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   if ( cpu_has_vmx ) {
158447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      cpu[next] = "/Altivec";
159447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      next++;
160447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   }
161447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick# endif
162447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
163447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   if ( ! cpu_has_fpu ) {
164447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      cpu[next] = "/No FPU";
165447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      next++;
166447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   }
16793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
16893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
169b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   for ( i = 0 ; i < next ; i++ ) {
170b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      const size_t len = strlen( cpu[i] );
171b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick
172b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      strncpy( & buffer[ offset ], cpu[i], len );
173b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      offset += len;
174b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   }
175b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick
17693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return offset;
17793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
17893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
17993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
18093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
18193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
1821585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_ARB_multisample
1831585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_ARB_transpose_matrix
1841585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_ARB_window_pos
1851585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_compiled_vertex_array
1861585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_polygon_offset
1871585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_texture_object
1881585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_vertex_array
1891585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_MESA_window_pos
1901585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
1911585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#include "extension_helper.h"
1921585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
1931585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanickstatic const struct dri_extension all_mesa_extensions[] = {
1941585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_ARB_multisample",           GL_ARB_multisample_functions },
1951585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_ARB_transpose_matrix",      GL_ARB_transpose_matrix_functions },
1961585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_ARB_window_pos",            GL_ARB_window_pos_functions },
1971585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions },
1981585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_polygon_offset",        GL_EXT_polygon_offset_functions },
1991585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_texture_object",        GL_EXT_texture_object_functions },
2001585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_vertex_array",          GL_EXT_vertex_array_functions },
2011585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_MESA_window_pos",           GL_MESA_window_pos_functions },
2021585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { NULL,                           NULL }
2031585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick};
2041585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
2051585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
206c212abf99af494f024b0b981a83350f7ac9821efIan Romanick/**
207c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * Enable extensions supported by the driver.
208c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
209c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \bug
210c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * ARB_imaging isn't handled properly.  In Mesa, enabling ARB_imaging also
211c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * enables all the sub-extensions that are folded into it.  This means that
212c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * we need to add entry-points (via \c driInitSingleExtension) for those
213c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * new functions here.
214c212abf99af494f024b0b981a83350f7ac9821efIan Romanick */
21593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellvoid driInitExtensions( GLcontext * ctx,
216c212abf99af494f024b0b981a83350f7ac9821efIan Romanick			const struct dri_extension * extensions_to_enable,
217c212abf99af494f024b0b981a83350f7ac9821efIan Romanick			GLboolean enable_imaging )
21893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
2191585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   static int first_time = 1;
22093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   i;
22193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
2221585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   if ( first_time ) {
2231585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick      first_time = 0;
2241585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick      driInitExtensions( ctx, all_mesa_extensions, GL_FALSE );
2251585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   }
2261585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
2271585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   if ( (ctx != NULL) && enable_imaging ) {
22893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      _mesa_enable_imaging_extensions( ctx );
22993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
23093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
231c212abf99af494f024b0b981a83350f7ac9821efIan Romanick   for ( i = 0 ; extensions_to_enable[i].name != NULL ; i++ ) {
232c212abf99af494f024b0b981a83350f7ac9821efIan Romanick       driInitSingleExtension( ctx, & extensions_to_enable[i] );
23393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
23493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
23593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
23693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
23793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
23893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
239c212abf99af494f024b0b981a83350f7ac9821efIan Romanick/**
240c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * Enable and add dispatch functions for a single extension
241c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
242c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \param ctx  Context where extension is to be enabled.
243c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \param ext  Extension that is to be enabled.
244c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
245c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \sa driInitExtensions, _mesa_enable_extension, _glapi_add_entrypoint
246c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
247c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \todo
248c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * Determine if it would be better to use \c strlen instead of the hardcoded
249c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * for-loops.
250c212abf99af494f024b0b981a83350f7ac9821efIan Romanick */
251c212abf99af494f024b0b981a83350f7ac9821efIan Romanickvoid driInitSingleExtension( GLcontext * ctx,
252c212abf99af494f024b0b981a83350f7ac9821efIan Romanick			     const struct dri_extension * ext )
253c212abf99af494f024b0b981a83350f7ac9821efIan Romanick{
254c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    unsigned i;
255c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
2561585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
257c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    if ( ext->functions != NULL ) {
258c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	for ( i = 0 ; ext->functions[i].strings != NULL ; i++ ) {
259c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    const char * functions[16];
260c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    const char * parameter_signature;
261c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    const char * str = ext->functions[i].strings;
262c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    unsigned j;
2631585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    unsigned offset;
264c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
265c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
266c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    /* Separate the parameter signature from the rest of the string.
267c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * If the parameter signature is empty (i.e., the string starts
268c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * with a NUL character), then the function has a void parameter
269c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * list.
270c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     */
271c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    parameter_signature = str;
272c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    while ( str[0] != '\0' ) {
273c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		str++;
274c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
275c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    str++;
276c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
277c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
278c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    /* Divide the string into the substrings that name each
279c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * entry-point for the function.
280c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     */
281c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    for ( j = 0 ; j < 16 ; j++ ) {
282c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		if ( str[0] == '\0' ) {
283c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		    functions[j] = NULL;
284c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		    break;
285c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		}
286c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
287c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		functions[j] = str;
288c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
289c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		while ( str[0] != '\0' ) {
290c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		    str++;
291c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		}
292c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		str++;
293c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
294c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
295c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
296c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    /* Add each entry-point to the dispatch table.
297c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     */
2981585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    offset = _glapi_add_dispatch( functions, parameter_signature );
2991585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    if ( ext->functions[i].remap_index != -1 ) {
3001585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick		driDispatchRemapTable[ ext->functions[i].remap_index ] = offset;
3011585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    }
3021585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
3031585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    if ( (ext->functions[i].offset != -1)
3041585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick		 && (ext->functions[i].offset != offset) ) {
3051585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick		fprintf(stderr, "DISPATCH ERROR! %s -> %u != %u\n", functions[0],
3061585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick			driDispatchRemapTable[ ext->functions[i].remap_index ],
3071585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick			ext->functions[i].offset);
308c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
309c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	}
310c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    }
311c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
3121585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick    if ( ctx != NULL ) {
3131585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	_mesa_enable_extension( ctx, ext->name );
3141585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick    }
315c212abf99af494f024b0b981a83350f7ac9821efIan Romanick}
316c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
317c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
3185b98ada88071a752b6000756949a1951183cdd0bIan Romanick/**
3195b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components.
3205b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3215b98ada88071a752b6000756949a1951183cdd0bIan Romanick * If one of the version requirements is not met, a message is logged using
3225b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \c __driUtilMessage.
3235b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3245b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driver_name  Name of the driver.  Used in error messages.
3255b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driActual    Actual DRI version supplied __driCreateNewScreen.
3265b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driExpected  Minimum DRI version required by the driver.
3275b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxActual    Actual DDX version supplied __driCreateNewScreen.
3287104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger * \param ddxExpected  Minimum DDX minor and range of DDX major version required by the driver.
3295b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmActual    Actual DRM version supplied __driCreateNewScreen.
3305b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmExpected  Minimum DRM version required by the driver.
3315b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3325b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \returns \c GL_TRUE if all version requirements are met.  Otherwise,
3335b98ada88071a752b6000756949a1951183cdd0bIan Romanick *          \c GL_FALSE is returned.
3345b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
335c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2, __driUtilMessage
336c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick *
337c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * \todo
338c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
339c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * function and \c driCheckDriDdxDrmVersions2 should be renamed.
3405b98ada88071a752b6000756949a1951183cdd0bIan Romanick */
3415b98ada88071a752b6000756949a1951183cdd0bIan RomanickGLboolean
3427104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerdriCheckDriDdxDrmVersions3(const char * driver_name,
3435b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driActual,
3445b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driExpected,
3455b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * ddxActual,
3467104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIutilversion2 * ddxExpected,
3475b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmActual,
3485b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmExpected)
3495b98ada88071a752b6000756949a1951183cdd0bIan Romanick{
3505b98ada88071a752b6000756949a1951183cdd0bIan Romanick   static const char format[] = "%s DRI driver expected %s version %d.%d.x "
3515b98ada88071a752b6000756949a1951183cdd0bIan Romanick       "but got version %d.%d.%d";
3527104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   static const char format2[] = "%s DRI driver expected %s version %d-%d.%d.x "
3537104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger       "but got version %d.%d.%d";
3545b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3555b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3565b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check the DRI version */
3575b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (driActual->major != driExpected->major)
3585b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (driActual->minor < driExpected->minor) ) {
3595b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DRI",
3605b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driExpected->major, driExpected->minor,
3615b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driActual->major, driActual->minor, driActual->patch);
3625b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3635b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3645b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3655b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DDX driver version is compatible */
3667104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   if ( (ddxActual->major < ddxExpected->major_min)
3677104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger	|| (ddxActual->major > ddxExpected->major_max)
3685b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (ddxActual->minor < ddxExpected->minor) ) {
3697104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger      __driUtilMessage(format2, driver_name, "DDX",
3707104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger		       ddxExpected->major_min, ddxExpected->major_max, ddxExpected->minor,
3715b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       ddxActual->major, ddxActual->minor, ddxActual->patch);
3725b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3735b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3745b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3755b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DRM driver version is compatible */
3765b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (drmActual->major != drmExpected->major)
3775b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (drmActual->minor < drmExpected->minor) ) {
3785b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DRM",
3795b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmExpected->major, drmExpected->minor,
3805b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmActual->major, drmActual->minor, drmActual->patch);
3815b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3825b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3835b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3845b98ada88071a752b6000756949a1951183cdd0bIan Romanick   return GL_TRUE;
3855b98ada88071a752b6000756949a1951183cdd0bIan Romanick}
3865b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3877104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerGLboolean
3887104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerdriCheckDriDdxDrmVersions2(const char * driver_name,
3897104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * driActual,
3907104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * driExpected,
3917104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * ddxActual,
3927104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * ddxExpected,
3937104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * drmActual,
3947104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * drmExpected)
3957104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger{
3967104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   __DRIutilversion2 ddx_expected;
3977104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.major_min = ddxExpected->major;
3987104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.major_max = ddxExpected->major;
3997104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.minor = ddxExpected->minor;
4007104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.patch = ddxExpected->patch;
4017104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   return driCheckDriDdxDrmVersions3(driver_name, driActual,
4027104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger				driExpected, ddxActual, & ddx_expected,
4037104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger				drmActual, drmExpected);
4047104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger}
4057104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger
4067104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger
4077ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4087ed58285abede813fbf5fa0a2e29982043f1bbbeKeith WhitwellGLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
4097ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLint *x, GLint *y,
4107ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLsizei *width, GLsizei *height )
4117ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell{
4127ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* left clipping */
4137ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x < buffer->_Xmin) {
4147ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (buffer->_Xmin - *x);
4157ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *x = buffer->_Xmin;
4167ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
4177ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4187ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* right clipping */
4197ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x + *width > buffer->_Xmax)
4207ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (*x + *width - buffer->_Xmax - 1);
4217ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4227ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*width <= 0)
4237ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
4247ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4257ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* bottom clipping */
4267ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y < buffer->_Ymin) {
4277ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (buffer->_Ymin - *y);
4287ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *y = buffer->_Ymin;
4297ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
4307ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4317ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* top clipping */
4327ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y + *height > buffer->_Ymax)
4337ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (*y + *height - buffer->_Ymax - 1);
4347ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4357ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*height <= 0)
4367ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
4377ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4387ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   return GL_TRUE;
4397ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell}
44074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
44174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
44274396056977776919aaa7c22be1a3d17774ae321Ian Romanick
44374396056977776919aaa7c22be1a3d17774ae321Ian Romanick/**
44474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * Creates a set of \c __GLcontextModes that a driver will expose.
44574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
44674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * A set of \c __GLcontextModes will be created based on the supplied
44774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * parameters.  The number of modes processed will be 2 *
44874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c num_depth_stencil_bits * \c num_db_modes.
44974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
45074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
45174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c db_modes, and \c visType into each \c __GLcontextModes element.
45274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * However, the meanings of \c fb_format and \c fb_type require further
45374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * explanation.  The \c fb_format specifies which color components are in
45474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * each pixel and what the default order is.  For example, \c GL_RGB specifies
45574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * that red, green, blue are available and red is in the "most significant"
45674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * position and blue is in the "least significant".  The \c fb_type specifies
45774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the bit sizes of each component and the actual ordering.  For example, if
45874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
45974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * are the blue value, bits [10:5] are the green value, and bits [4:0] are
46074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the red value.
46174396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
46274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * One sublte issue is the combination of \c GL_RGB  or \c GL_BGR and either
46374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * of the \c GL_UNSIGNED_INT_8_8_8_8 modes.  The resulting mask values in the
46474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
46574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_BGRA case, except the \c alphaMask is zero.  This means that, as
46674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
46774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * still uses 32-bits.
46874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
46974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * If in doubt, look at the tables used in the function.
47074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
47174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param ptr_to_modes  Pointer to a pointer to a linked list of
47274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c __GLcontextModes.  Upon completion, a pointer to
47374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      the next element to be process will be stored here.
47474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      If the function fails and returns \c GL_FALSE, this
47574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      value will be unmodified, but some elements in the
47674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      linked list may be modified.
47774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_format     Format of the framebuffer.  Currently only \c GL_RGB,
47874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
47974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_type       Type of the pixels in the framebuffer.  Currently only
48074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_SHORT_5_6_5,
48174396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_SHORT_5_6_5_REV,
48274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_INT_8_8_8_8, and
48374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
48474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param depth_bits    Array of depth buffer sizes to be exposed.
48574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param stencil_bits  Array of stencil buffer sizes to be exposed.
48674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_depth_stencil_bits  Number of entries in both \c depth_bits and
48774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c stencil_bits.
48874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param db_modes      Array of buffer swap modes.  If an element has a
48974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      value of \c GLX_NONE, then it represents a
49074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      single-buffered mode.  Other valid values are
49174396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
49274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_SWAP_UNDEFINED_OML.  See the
49374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      GLX_OML_swap_method extension spec for more details.
49474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_db_modes  Number of entries in \c db_modes.
49574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param visType       GLX visual type.  Usually either \c GLX_TRUE_COLOR or
49674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_DIRECT_COLOR.
49774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
49874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \returns
49974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_TRUE on success or \c GL_FALSE on failure.  Currently the only
50074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
50174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c fb_type).
50274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
50374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \todo
50474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * There is currently no way to support packed RGB modes (i.e., modes with
50574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * exactly 3 bytes per pixel) or floating-point modes.  This could probably
50674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * be done by creating some new, private enums with clever names likes
50774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
50874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_4HALF_16_16_16_16, etc.  We can cross that bridge when we come to it.
50974396056977776919aaa7c22be1a3d17774ae321Ian Romanick */
51074396056977776919aaa7c22be1a3d17774ae321Ian RomanickGLboolean
51174396056977776919aaa7c22be1a3d17774ae321Ian RomanickdriFillInModes( __GLcontextModes ** ptr_to_modes,
51274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		GLenum fb_format, GLenum fb_type,
51338b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane		const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
51474396056977776919aaa7c22be1a3d17774ae321Ian Romanick		unsigned num_depth_stencil_bits,
51574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		const GLenum * db_modes, unsigned num_db_modes,
51674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		int visType )
51774396056977776919aaa7c22be1a3d17774ae321Ian Romanick{
51838b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int8_t bits_table[3][4] = {
51974396056977776919aaa7c22be1a3d17774ae321Ian Romanick     /* R  G  B  A */
52074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
52174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
52274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 8, 8, 8, 8 }  /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
52374396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
52474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
52574396056977776919aaa7c22be1a3d17774ae321Ian Romanick   /* The following arrays are all indexed by the fb_type masked with 0x07.
52674396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * Given the four supported fb_type values, this results in valid array
52774396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * indices of 3, 4, 5, and 7.
52874396056977776919aaa7c22be1a3d17774ae321Ian Romanick    */
52938b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_rgb[8][4] = {
53074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
53174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
53274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
533fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
53474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
53574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8     */
53674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
53774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }  /* 8_8_8_8_REV */
53874396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
53974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
54038b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_rgba[8][4] = {
54174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
54274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
54374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
544fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
54574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
54674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8     */
54774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
54874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
54974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
55074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
55138b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_bgr[8][4] = {
55274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
55374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
55474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
55574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
556fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
55774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8     */
55874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
55974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
56074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
56174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
56238b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_bgra[8][4] = {
56374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
56474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
56574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
56674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
567fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
56874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8     */
56974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
57074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
57174396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
57274396056977776919aaa7c22be1a3d17774ae321Ian Romanick
57338b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int8_t bytes_per_pixel[8] = {
57474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      0, 0, 0, 2, 2, 4, 0, 4
57574396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
57674396056977776919aaa7c22be1a3d17774ae321Ian Romanick
57738b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   const u_int8_t  * bits;
57838b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   const u_int32_t * masks;
57974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   const int index = fb_type & 0x07;
58074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   __GLcontextModes * modes = *ptr_to_modes;
58174396056977776919aaa7c22be1a3d17774ae321Ian Romanick   unsigned i;
58274396056977776919aaa7c22be1a3d17774ae321Ian Romanick   unsigned j;
58374396056977776919aaa7c22be1a3d17774ae321Ian Romanick   unsigned k;
58474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
58574396056977776919aaa7c22be1a3d17774ae321Ian Romanick
58674396056977776919aaa7c22be1a3d17774ae321Ian Romanick   if ( bytes_per_pixel[ index ] == 0 ) {
58774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      fprintf( stderr, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n",
58838b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane	       __FUNCTION__, __LINE__, fb_type );
58974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      return GL_FALSE;
59074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   }
59174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
59274396056977776919aaa7c22be1a3d17774ae321Ian Romanick
59374396056977776919aaa7c22be1a3d17774ae321Ian Romanick   /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
59474396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * the _REV versions.
59574396056977776919aaa7c22be1a3d17774ae321Ian Romanick    *
59674396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
59774396056977776919aaa7c22be1a3d17774ae321Ian Romanick    */
59874396056977776919aaa7c22be1a3d17774ae321Ian Romanick
59974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   switch ( fb_format ) {
60074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_RGB:
60174396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
60274396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[1];
60374396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_rgb[ index ];
60474396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
60574396056977776919aaa7c22be1a3d17774ae321Ian Romanick
60674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_RGBA:
60774396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
60874396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[2];
60974396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_rgba[ index ];
61074396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
61174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
61274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_BGR:
61374396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
61474396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[1];
61574396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_bgr[ index ];
61674396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
61774396056977776919aaa7c22be1a3d17774ae321Ian Romanick
61874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_BGRA:
61974396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
62074396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[2];
62174396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_bgra[ index ];
62274396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
62374396056977776919aaa7c22be1a3d17774ae321Ian Romanick
62474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      default:
62574396056977776919aaa7c22be1a3d17774ae321Ian Romanick         fprintf( stderr, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n",
62638b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane	       __FUNCTION__, __LINE__, fb_format );
62774396056977776919aaa7c22be1a3d17774ae321Ian Romanick         return GL_FALSE;
62874396056977776919aaa7c22be1a3d17774ae321Ian Romanick   }
62974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63174396056977776919aaa7c22be1a3d17774ae321Ian Romanick    for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
63274396056977776919aaa7c22be1a3d17774ae321Ian Romanick	for ( i = 0 ; i < num_db_modes ; i++ ) {
63374396056977776919aaa7c22be1a3d17774ae321Ian Romanick	    for ( j = 0 ; j < 2 ; j++ ) {
63474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->redBits   = bits[0];
63674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->greenBits = bits[1];
63774396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->blueBits  = bits[2];
63874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->alphaBits = bits[3];
63974396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->redMask   = masks[0];
64074396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->greenMask = masks[1];
64174396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->blueMask  = masks[2];
64274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->alphaMask = masks[3];
64374396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->rgbBits   = modes->redBits + modes->greenBits
64474396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    + modes->blueBits + modes->alphaBits;
64574396056977776919aaa7c22be1a3d17774ae321Ian Romanick
64674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumRedBits   = 16 * j;
64774396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumGreenBits = 16 * j;
64874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumBlueBits  = 16 * j;
64974396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
65074396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
65174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
65274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->stencilBits = stencil_bits[k];
65374396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->depthBits = depth_bits[k];
65474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
65574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->visualType = visType;
65674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->renderType = GLX_RGBA_BIT;
65774396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->drawableType = GLX_WINDOW_BIT;
65874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->rgbMode = GL_TRUE;
65974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
66074396056977776919aaa7c22be1a3d17774ae321Ian Romanick		if ( db_modes[i] == GLX_NONE ) {
66174396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    modes->doubleBufferMode = GL_FALSE;
66274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		}
66374396056977776919aaa7c22be1a3d17774ae321Ian Romanick		else {
66474396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    modes->doubleBufferMode = GL_TRUE;
66574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    modes->swapMethod = db_modes[i];
66674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		}
66774396056977776919aaa7c22be1a3d17774ae321Ian Romanick
6687f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell		modes->haveAccumBuffer = ((modes->accumRedBits +
6697f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumGreenBits +
6707f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumBlueBits +
6717f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumAlphaBits) > 0);
6727f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell		modes->haveDepthBuffer = (modes->depthBits > 0);
6737f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell		modes->haveStencilBuffer = (modes->stencilBits > 0);
6747f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell
67574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes = modes->next;
67674396056977776919aaa7c22be1a3d17774ae321Ian Romanick	    }
67774396056977776919aaa7c22be1a3d17774ae321Ian Romanick	}
67874396056977776919aaa7c22be1a3d17774ae321Ian Romanick    }
67974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
68074396056977776919aaa7c22be1a3d17774ae321Ian Romanick    *ptr_to_modes = modes;
68174396056977776919aaa7c22be1a3d17774ae321Ian Romanick    return GL_TRUE;
68274396056977776919aaa7c22be1a3d17774ae321Ian Romanick}
683