Brian Paul | 3c5bfac | 2003-01-14 04:49:07 +0000 | [diff] [blame^] | 1 | /* $Id: fakeglx.c,v 1.78 2003/01/14 04:49:07 brianp Exp $ */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
Brian Paul | 69e3c8b | 2002-11-14 16:14:50 +0000 | [diff] [blame] | 5 | * Version: 5.1 |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 6 | * |
Brian Paul | 8d687e7 | 2002-03-15 18:43:25 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 8 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 15 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 18 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 28 | /* |
Brian Paul | 36cfa38 | 1999-11-28 20:15:04 +0000 | [diff] [blame] | 29 | * This is an emulation of the GLX API which allows Mesa/GLX-based programs |
| 30 | * to run on X servers which do not have the real GLX extension. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 31 | * |
| 32 | * Thanks to the contributors: |
| 33 | * |
Brian Paul | ddf69f2 | 2000-08-02 20:35:09 +0000 | [diff] [blame] | 34 | * Initial version: Philip Brown (phil@bolthole.com) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 35 | * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu) |
| 36 | * Further visual-handling refinements: Wolfram Gloger |
| 37 | * (wmglo@Dent.MED.Uni-Muenchen.DE). |
| 38 | * |
| 39 | * Notes: |
| 40 | * Don't be fooled, stereo isn't supported yet. |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 45 | #include "glxheader.h" |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 46 | #include "glxapi.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 47 | #include "GL/xmesa.h" |
| 48 | #include "context.h" |
| 49 | #include "config.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 50 | #include "macros.h" |
Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 51 | #include "imports.h" |
Brian Paul | 71dea34 | 2000-04-19 01:44:01 +0000 | [diff] [blame] | 52 | #include "mmath.h" |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 53 | #include "mtypes.h" |
Brian Paul | 71dea34 | 2000-04-19 01:44:01 +0000 | [diff] [blame] | 54 | #include "xfonts.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 55 | #include "xmesaP.h" |
| 56 | |
| 57 | |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 58 | /* This indicates the client-side GLX API and GLX encoder version. */ |
| 59 | #define CLIENT_MAJOR_VERSION 1 |
Brian Paul | a573803 | 2001-09-23 16:10:02 +0000 | [diff] [blame] | 60 | #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */ |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 61 | |
| 62 | /* This indicates the server-side GLX decoder version. |
Brian Paul | ba57e52 | 2001-09-14 02:43:03 +0000 | [diff] [blame] | 63 | * GLX 1.4 indicates OpenGL 1.3 support |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 64 | */ |
| 65 | #define SERVER_MAJOR_VERSION 1 |
Brian Paul | ba57e52 | 2001-09-14 02:43:03 +0000 | [diff] [blame] | 66 | #define SERVER_MINOR_VERSION 4 |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 67 | |
| 68 | /* This is appended onto the glXGetClient/ServerString version strings. */ |
Brian Paul | 69e3c8b | 2002-11-14 16:14:50 +0000 | [diff] [blame] | 69 | #define MESA_GLX_VERSION "Mesa 5.1" |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 70 | |
| 71 | /* Who implemented this GLX? */ |
| 72 | #define VENDOR "Brian Paul" |
| 73 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 74 | #define EXTENSIONS \ |
| 75 | "GLX_MESA_set_3dfx_mode " \ |
| 76 | "GLX_MESA_copy_sub_buffer " \ |
| 77 | "GLX_MESA_pixmap_colormap " \ |
| 78 | "GLX_MESA_release_buffers " \ |
| 79 | "GLX_ARB_get_proc_address " \ |
| 80 | "GLX_EXT_visual_info " \ |
| 81 | "GLX_EXT_visual_rating " \ |
| 82 | "GLX_SGI_video_sync " \ |
| 83 | "GLX_SGIX_fbconfig " \ |
Brian Paul | 3c5bfac | 2003-01-14 04:49:07 +0000 | [diff] [blame^] | 84 | "GLX_SGIX_pbuffer" \ |
| 85 | "GLX_ARB_render_texture" |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 86 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 87 | |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 88 | /* Silence compiler warnings */ |
Brian Paul | e7b16b7 | 2000-03-17 15:33:09 +0000 | [diff] [blame] | 89 | extern void Fake_glXDummyFunc( void ); |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 90 | void Fake_glXDummyFunc( void ) |
| 91 | { |
| 92 | (void) kernel8; |
| 93 | (void) DitherValues; |
| 94 | (void) HPCR_DRGB; |
| 95 | (void) kernel1; |
| 96 | } |
| 97 | |
| 98 | |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 99 | /* |
| 100 | * Our fake GLX context will contain a "real" GLX context and an XMesa context. |
| 101 | * |
| 102 | * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context, |
| 103 | * and vice versa. |
| 104 | * |
| 105 | * We really just need this structure in order to make the libGL functions |
| 106 | * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay() |
| 107 | * work correctly. |
| 108 | */ |
| 109 | struct fake_glx_context { |
| 110 | __GLXcontext glxContext; /* this MUST be first! */ |
| 111 | XMesaContext xmesaContext; |
| 112 | }; |
| 113 | |
| 114 | |
| 115 | |
| 116 | /**********************************************************************/ |
| 117 | /*** GLX Visual Code ***/ |
| 118 | /**********************************************************************/ |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 119 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 120 | #define DONT_CARE -1 |
| 121 | |
| 122 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 123 | #define MAX_VISUALS 100 |
| 124 | static XMesaVisual VisualTable[MAX_VISUALS]; |
| 125 | static int NumVisuals = 0; |
| 126 | |
| 127 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 128 | /* |
| 129 | * This struct and some code fragments borrowed |
| 130 | * from Mark Kilgard's GLUT library. |
| 131 | */ |
| 132 | typedef struct _OverlayInfo { |
| 133 | /* Avoid 64-bit portability problems by being careful to use |
| 134 | longs due to the way XGetWindowProperty is specified. Note |
| 135 | that these parameters are passed as CARD32s over X |
| 136 | protocol. */ |
| 137 | unsigned long overlay_visual; |
| 138 | long transparent_type; |
| 139 | long value; |
| 140 | long layer; |
| 141 | } OverlayInfo; |
| 142 | |
| 143 | |
| 144 | |
| 145 | /* Macro to handle c_class vs class field name in XVisualInfo struct */ |
| 146 | #if defined(__cplusplus) || defined(c_plusplus) |
| 147 | #define CLASS c_class |
| 148 | #else |
| 149 | #define CLASS class |
| 150 | #endif |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | /* |
| 156 | * Test if the given XVisualInfo is usable for Mesa rendering. |
| 157 | */ |
| 158 | static GLboolean is_usable_visual( XVisualInfo *vinfo ) |
| 159 | { |
| 160 | switch (vinfo->CLASS) { |
| 161 | case StaticGray: |
| 162 | case GrayScale: |
| 163 | /* Any StaticGray/GrayScale visual works in RGB or CI mode */ |
| 164 | return GL_TRUE; |
| 165 | case StaticColor: |
| 166 | case PseudoColor: |
| 167 | /* Any StaticColor/PseudoColor visual of at least 4 bits */ |
| 168 | if (vinfo->depth>=4) { |
| 169 | return GL_TRUE; |
| 170 | } |
| 171 | else { |
| 172 | return GL_FALSE; |
| 173 | } |
| 174 | case TrueColor: |
| 175 | case DirectColor: |
| 176 | /* Any depth of TrueColor or DirectColor works in RGB mode */ |
| 177 | return GL_TRUE; |
| 178 | default: |
| 179 | /* This should never happen */ |
| 180 | return GL_FALSE; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | |
| 185 | |
| 186 | /* |
| 187 | * Return the level (overlay, normal, underlay) of a given XVisualInfo. |
| 188 | * Input: dpy - the X display |
| 189 | * vinfo - the XVisualInfo to test |
| 190 | * Return: level of the visual: |
| 191 | * 0 = normal planes |
| 192 | * >0 = overlay planes |
| 193 | * <0 = underlay planes |
| 194 | */ |
| 195 | static int level_of_visual( Display *dpy, XVisualInfo *vinfo ) |
| 196 | { |
| 197 | Atom overlayVisualsAtom; |
| 198 | OverlayInfo *overlay_info = NULL; |
| 199 | int numOverlaysPerScreen; |
| 200 | Status status; |
| 201 | Atom actualType; |
| 202 | int actualFormat; |
| 203 | unsigned long sizeData, bytesLeft; |
| 204 | int i; |
| 205 | |
| 206 | /* |
| 207 | * The SERVER_OVERLAY_VISUALS property on the root window contains |
| 208 | * a list of overlay visuals. Get that list now. |
| 209 | */ |
| 210 | overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True); |
| 211 | if (overlayVisualsAtom == None) { |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ), |
| 216 | overlayVisualsAtom, 0L, (long) 10000, False, |
| 217 | overlayVisualsAtom, &actualType, &actualFormat, |
| 218 | &sizeData, &bytesLeft, |
| 219 | (unsigned char **) &overlay_info ); |
| 220 | |
| 221 | if (status != Success || actualType != overlayVisualsAtom || |
| 222 | actualFormat != 32 || sizeData < 4) { |
| 223 | /* something went wrong */ |
| 224 | XFree((void *) overlay_info); |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /* search the overlay visual list for the visual ID of interest */ |
| 229 | numOverlaysPerScreen = (int) (sizeData / 4); |
| 230 | for (i=0;i<numOverlaysPerScreen;i++) { |
| 231 | OverlayInfo *ov; |
| 232 | ov = overlay_info + i; |
| 233 | if (ov->overlay_visual==vinfo->visualid) { |
| 234 | /* found the visual */ |
| 235 | if (/*ov->transparent_type==1 &&*/ ov->layer!=0) { |
| 236 | int level = ov->layer; |
| 237 | XFree((void *) overlay_info); |
| 238 | return level; |
| 239 | } |
| 240 | else { |
| 241 | XFree((void *) overlay_info); |
| 242 | return 0; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* The visual ID was not found in the overlay list. */ |
| 248 | XFree((void *) overlay_info); |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | /* |
| 256 | * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the |
| 257 | * configuration in our list of GLX visuals. |
| 258 | */ |
| 259 | static XMesaVisual |
| 260 | save_glx_visual( Display *dpy, XVisualInfo *vinfo, |
| 261 | GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag, |
| 262 | GLboolean stereoFlag, |
| 263 | GLint depth_size, GLint stencil_size, |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 264 | GLint accumRedSize, GLint accumGreenSize, |
| 265 | GLint accumBlueSize, GLint accumAlphaSize, |
| 266 | GLint level ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 267 | { |
| 268 | GLboolean ximageFlag = GL_TRUE; |
| 269 | XMesaVisual xmvis; |
| 270 | GLint i; |
| 271 | GLboolean comparePointers; |
| 272 | |
| 273 | if (dbFlag) { |
| 274 | /* Check if the MESA_BACK_BUFFER env var is set */ |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 275 | char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 276 | if (backbuffer) { |
| 277 | if (backbuffer[0]=='p' || backbuffer[0]=='P') { |
| 278 | ximageFlag = GL_FALSE; |
| 279 | } |
| 280 | else if (backbuffer[0]=='x' || backbuffer[0]=='X') { |
| 281 | ximageFlag = GL_TRUE; |
| 282 | } |
| 283 | else { |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 284 | _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage."); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /* Comparing IDs uses less memory but sometimes fails. */ |
| 290 | /* XXX revisit this after 3.0 is finished. */ |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 291 | if (_mesa_getenv("MESA_GLX_VISUAL_HACK")) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 292 | comparePointers = GL_TRUE; |
| 293 | else |
| 294 | comparePointers = GL_FALSE; |
| 295 | |
| 296 | /* First check if a matching visual is already in the list */ |
| 297 | for (i=0; i<NumVisuals; i++) { |
| 298 | XMesaVisual v = VisualTable[i]; |
| 299 | if (v->display == dpy |
| 300 | && v->level == level |
| 301 | && v->ximage_flag == ximageFlag |
Brian Paul | 1832f1c | 2001-04-27 21:18:25 +0000 | [diff] [blame] | 302 | && v->mesa_visual.rgbMode == rgbFlag |
| 303 | && v->mesa_visual.doubleBufferMode == dbFlag |
| 304 | && v->mesa_visual.stereoMode == stereoFlag |
| 305 | && (v->mesa_visual.alphaBits > 0) == alphaFlag |
| 306 | && (v->mesa_visual.depthBits >= depth_size || depth_size == 0) |
| 307 | && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0) |
| 308 | && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0) |
| 309 | && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0) |
| 310 | && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0) |
| 311 | && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 312 | /* now either compare XVisualInfo pointers or visual IDs */ |
Brian Paul | d0247f5 | 1999-11-18 15:17:01 +0000 | [diff] [blame] | 313 | if ((!comparePointers && v->visinfo->visualid == vinfo->visualid) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 314 | || (comparePointers && v->vishandle == vinfo)) { |
| 315 | return v; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /* Create a new visual and add it to the list. */ |
| 321 | |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 322 | if (NumVisuals >= MAX_VISUALS) { |
| 323 | _mesa_problem(NULL, "GLX Error: maximum number of visuals exceeded"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 324 | return NULL; |
| 325 | } |
| 326 | |
Brian Paul | c8735e8 | 2000-04-05 22:09:58 +0000 | [diff] [blame] | 327 | xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag, |
| 328 | stereoFlag, ximageFlag, |
| 329 | depth_size, stencil_size, |
| 330 | accumRedSize, accumBlueSize, |
| 331 | accumBlueSize, accumAlphaSize, 0, level, |
| 332 | GLX_NONE_EXT ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 333 | if (xmvis) { |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 334 | /* Save a copy of the pointer now so we can find this visual again |
| 335 | * if we need to search for it in find_glx_visual(). |
| 336 | */ |
| 337 | xmvis->vishandle = vinfo; |
| 338 | /* add xmvis to the list */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 339 | VisualTable[NumVisuals] = xmvis; |
| 340 | NumVisuals++; |
| 341 | } |
| 342 | return xmvis; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | |
| 347 | /* |
| 348 | * Create a GLX visual from a regular XVisualInfo. |
Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 349 | * This is called when Fake GLX is given an XVisualInfo which wasn't |
| 350 | * returned by glXChooseVisual. Since this is the first time we're |
| 351 | * considering this visual we'll take a guess at reasonable values |
| 352 | * for depth buffer size, stencil size, accum size, etc. |
| 353 | * This is the best we can do with a client-side emulation of GLX. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 354 | */ |
| 355 | static XMesaVisual |
| 356 | create_glx_visual( Display *dpy, XVisualInfo *visinfo ) |
| 357 | { |
| 358 | int vislevel; |
| 359 | |
| 360 | vislevel = level_of_visual( dpy, visinfo ); |
| 361 | if (vislevel) { |
| 362 | /* Configure this visual as a CI, single-buffered overlay */ |
| 363 | return save_glx_visual( dpy, visinfo, |
| 364 | GL_FALSE, /* rgb */ |
| 365 | GL_FALSE, /* alpha */ |
| 366 | GL_FALSE, /* double */ |
| 367 | GL_FALSE, /* stereo */ |
| 368 | 0, /* depth bits */ |
| 369 | 0, /* stencil bits */ |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 370 | 0,0,0,0, /* accum bits */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 371 | vislevel /* level */ |
| 372 | ); |
| 373 | } |
| 374 | else if (is_usable_visual( visinfo )) { |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 375 | if (_mesa_getenv("MESA_GLX_FORCE_CI")) { |
Brian Paul | 8f9a594 | 2001-02-17 00:17:31 +0000 | [diff] [blame] | 376 | /* Configure this visual as a COLOR INDEX visual. */ |
| 377 | return save_glx_visual( dpy, visinfo, |
| 378 | GL_FALSE, /* rgb */ |
| 379 | GL_FALSE, /* alpha */ |
| 380 | GL_TRUE, /* double */ |
| 381 | GL_FALSE, /* stereo */ |
| 382 | DEFAULT_SOFTWARE_DEPTH_BITS, |
| 383 | 8 * sizeof(GLstencil), |
| 384 | 0 * sizeof(GLaccum), /* r */ |
| 385 | 0 * sizeof(GLaccum), /* g */ |
| 386 | 0 * sizeof(GLaccum), /* b */ |
| 387 | 0 * sizeof(GLaccum), /* a */ |
| 388 | 0 /* level */ |
| 389 | ); |
| 390 | } |
| 391 | else { |
| 392 | /* Configure this visual as RGB, double-buffered, depth-buffered. */ |
| 393 | /* This is surely wrong for some people's needs but what else */ |
| 394 | /* can be done? They should use glXChooseVisual(). */ |
| 395 | return save_glx_visual( dpy, visinfo, |
| 396 | GL_TRUE, /* rgb */ |
| 397 | GL_FALSE, /* alpha */ |
| 398 | GL_TRUE, /* double */ |
| 399 | GL_FALSE, /* stereo */ |
| 400 | DEFAULT_SOFTWARE_DEPTH_BITS, |
| 401 | 8 * sizeof(GLstencil), |
| 402 | 8 * sizeof(GLaccum), /* r */ |
| 403 | 8 * sizeof(GLaccum), /* g */ |
| 404 | 8 * sizeof(GLaccum), /* b */ |
| 405 | 8 * sizeof(GLaccum), /* a */ |
| 406 | 0 /* level */ |
| 407 | ); |
| 408 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 409 | } |
| 410 | else { |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 411 | _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 412 | return NULL; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | |
| 417 | |
| 418 | /* |
| 419 | * Find the GLX visual associated with an XVisualInfo. |
| 420 | */ |
| 421 | static XMesaVisual |
| 422 | find_glx_visual( Display *dpy, XVisualInfo *vinfo ) |
| 423 | { |
| 424 | int i; |
| 425 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 426 | /* try to match visual id */ |
| 427 | for (i=0;i<NumVisuals;i++) { |
| 428 | if (VisualTable[i]->display==dpy |
| 429 | && VisualTable[i]->visinfo->visualid == vinfo->visualid) { |
| 430 | return VisualTable[i]; |
| 431 | } |
| 432 | } |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 433 | |
| 434 | /* if that fails, try to match pointers */ |
| 435 | for (i=0;i<NumVisuals;i++) { |
| 436 | if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) { |
| 437 | return VisualTable[i]; |
| 438 | } |
| 439 | } |
| 440 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 441 | return NULL; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | |
| 446 | /* |
| 447 | * Return the transparent pixel value for a GLX visual. |
| 448 | * Input: glxvis - the glx_visual |
| 449 | * Return: a pixel value or -1 if no transparent pixel |
| 450 | */ |
| 451 | static int transparent_pixel( XMesaVisual glxvis ) |
| 452 | { |
| 453 | Display *dpy = glxvis->display; |
| 454 | XVisualInfo *vinfo = glxvis->visinfo; |
| 455 | Atom overlayVisualsAtom; |
| 456 | OverlayInfo *overlay_info = NULL; |
| 457 | int numOverlaysPerScreen; |
| 458 | Status status; |
| 459 | Atom actualType; |
| 460 | int actualFormat; |
| 461 | unsigned long sizeData, bytesLeft; |
| 462 | int i; |
| 463 | |
| 464 | /* |
| 465 | * The SERVER_OVERLAY_VISUALS property on the root window contains |
| 466 | * a list of overlay visuals. Get that list now. |
| 467 | */ |
| 468 | overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True); |
| 469 | if (overlayVisualsAtom == None) { |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ), |
| 474 | overlayVisualsAtom, 0L, (long) 10000, False, |
| 475 | overlayVisualsAtom, &actualType, &actualFormat, |
| 476 | &sizeData, &bytesLeft, |
| 477 | (unsigned char **) &overlay_info ); |
| 478 | |
| 479 | if (status != Success || actualType != overlayVisualsAtom || |
| 480 | actualFormat != 32 || sizeData < 4) { |
| 481 | /* something went wrong */ |
| 482 | XFree((void *) overlay_info); |
| 483 | return -1; |
| 484 | } |
| 485 | |
| 486 | /* search the overlay visual list for the visual ID of interest */ |
| 487 | numOverlaysPerScreen = (int) (sizeData / 4); |
| 488 | for (i=0;i<numOverlaysPerScreen;i++) { |
| 489 | OverlayInfo *ov; |
| 490 | ov = overlay_info + i; |
| 491 | if (ov->overlay_visual==vinfo->visualid) { |
| 492 | /* found it! */ |
| 493 | if (ov->transparent_type==0) { |
| 494 | /* type 0 indicates no transparency */ |
| 495 | XFree((void *) overlay_info); |
| 496 | return -1; |
| 497 | } |
| 498 | else { |
| 499 | /* ov->value is the transparent pixel */ |
| 500 | XFree((void *) overlay_info); |
| 501 | return ov->value; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /* The visual ID was not found in the overlay list. */ |
| 507 | XFree((void *) overlay_info); |
| 508 | return -1; |
| 509 | } |
| 510 | |
| 511 | |
| 512 | |
| 513 | /* |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 514 | * Try to get an X visual which matches the given arguments. |
| 515 | */ |
| 516 | static XVisualInfo *get_visual( Display *dpy, int scr, |
| 517 | unsigned int depth, int xclass ) |
| 518 | { |
| 519 | XVisualInfo temp, *vis; |
| 520 | long mask; |
| 521 | int n; |
| 522 | unsigned int default_depth; |
| 523 | int default_class; |
| 524 | |
| 525 | mask = VisualScreenMask | VisualDepthMask | VisualClassMask; |
| 526 | temp.screen = scr; |
| 527 | temp.depth = depth; |
| 528 | temp.CLASS = xclass; |
| 529 | |
| 530 | default_depth = DefaultDepth(dpy,scr); |
| 531 | default_class = DefaultVisual(dpy,scr)->CLASS; |
| 532 | |
| 533 | if (depth==default_depth && xclass==default_class) { |
| 534 | /* try to get root window's visual */ |
| 535 | temp.visualid = DefaultVisual(dpy,scr)->visualid; |
| 536 | mask |= VisualIDMask; |
| 537 | } |
| 538 | |
| 539 | vis = XGetVisualInfo( dpy, mask, &temp, &n ); |
| 540 | |
| 541 | /* In case bits/pixel > 24, make sure color channels are still <=8 bits. |
| 542 | * An SGI Infinite Reality system, for example, can have 30bpp pixels: |
| 543 | * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel. |
| 544 | */ |
| 545 | if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) { |
Brian Paul | 71dea34 | 2000-04-19 01:44:01 +0000 | [diff] [blame] | 546 | if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 && |
| 547 | _mesa_bitcount((GLuint) vis->green_mask) <= 8 && |
| 548 | _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 549 | return vis; |
| 550 | } |
| 551 | else { |
| 552 | XFree((void *) vis); |
| 553 | return NULL; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | return vis; |
| 558 | } |
| 559 | |
| 560 | |
| 561 | |
| 562 | /* |
| 563 | * Retrieve the value of the given environment variable and find |
| 564 | * the X visual which matches it. |
| 565 | * Input: dpy - the display |
| 566 | * screen - the screen number |
| 567 | * varname - the name of the environment variable |
| 568 | * Return: an XVisualInfo pointer to NULL if error. |
| 569 | */ |
| 570 | static XVisualInfo *get_env_visual(Display *dpy, int scr, const char *varname) |
| 571 | { |
| 572 | char value[100], type[100]; |
| 573 | int depth, xclass = -1; |
| 574 | XVisualInfo *vis; |
| 575 | |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 576 | if (!_mesa_getenv( varname )) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 577 | return NULL; |
| 578 | } |
| 579 | |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 580 | _mesa_strncpy( value, _mesa_getenv(varname), 100 ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 581 | value[99] = 0; |
| 582 | |
| 583 | sscanf( value, "%s %d", type, &depth ); |
| 584 | |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 585 | if (_mesa_strcmp(type,"TrueColor")==0) xclass = TrueColor; |
| 586 | else if (_mesa_strcmp(type,"DirectColor")==0) xclass = DirectColor; |
| 587 | else if (_mesa_strcmp(type,"PseudoColor")==0) xclass = PseudoColor; |
| 588 | else if (_mesa_strcmp(type,"StaticColor")==0) xclass = StaticColor; |
| 589 | else if (_mesa_strcmp(type,"GrayScale")==0) xclass = GrayScale; |
| 590 | else if (_mesa_strcmp(type,"StaticGray")==0) xclass = StaticGray; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 591 | |
| 592 | if (xclass>-1 && depth>0) { |
| 593 | vis = get_visual( dpy, scr, depth, xclass ); |
| 594 | if (vis) { |
| 595 | return vis; |
| 596 | } |
| 597 | } |
| 598 | |
Brian Paul | 2ad5921 | 2002-10-30 20:24:45 +0000 | [diff] [blame] | 599 | _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.", |
| 600 | type, depth); |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 601 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 602 | return NULL; |
| 603 | } |
| 604 | |
| 605 | |
| 606 | |
| 607 | /* |
| 608 | * Select an X visual which satisfies the RGBA/CI flag and minimum depth. |
| 609 | * Input: dpy, screen - X display and screen number |
| 610 | * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode |
| 611 | * min_depth - minimum visual depth |
| 612 | * preferred_class - preferred GLX visual class or DONT_CARE |
| 613 | * Return: pointer to an XVisualInfo or NULL. |
| 614 | */ |
| 615 | static XVisualInfo *choose_x_visual( Display *dpy, int screen, |
| 616 | GLboolean rgba, int min_depth, |
| 617 | int preferred_class ) |
| 618 | { |
| 619 | XVisualInfo *vis; |
Brian Paul | db6aa58 | 2000-11-10 17:23:02 +0000 | [diff] [blame] | 620 | int xclass, visclass = 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 621 | int depth; |
| 622 | |
| 623 | if (rgba) { |
| 624 | Atom hp_cr_maps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", True); |
| 625 | /* First see if the MESA_RGB_VISUAL env var is defined */ |
| 626 | vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" ); |
| 627 | if (vis) { |
| 628 | return vis; |
| 629 | } |
| 630 | /* Otherwise, search for a suitable visual */ |
| 631 | if (preferred_class==DONT_CARE) { |
| 632 | for (xclass=0;xclass<6;xclass++) { |
| 633 | switch (xclass) { |
| 634 | case 0: visclass = TrueColor; break; |
| 635 | case 1: visclass = DirectColor; break; |
| 636 | case 2: visclass = PseudoColor; break; |
| 637 | case 3: visclass = StaticColor; break; |
| 638 | case 4: visclass = GrayScale; break; |
| 639 | case 5: visclass = StaticGray; break; |
| 640 | } |
| 641 | if (min_depth==0) { |
| 642 | /* start with shallowest */ |
| 643 | for (depth=0;depth<=32;depth++) { |
| 644 | if (visclass==TrueColor && depth==8 && !hp_cr_maps) { |
| 645 | /* Special case: try to get 8-bit PseudoColor before */ |
| 646 | /* 8-bit TrueColor */ |
| 647 | vis = get_visual( dpy, screen, 8, PseudoColor ); |
| 648 | if (vis) { |
| 649 | return vis; |
| 650 | } |
| 651 | } |
| 652 | vis = get_visual( dpy, screen, depth, visclass ); |
| 653 | if (vis) { |
| 654 | return vis; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | else { |
| 659 | /* start with deepest */ |
| 660 | for (depth=32;depth>=min_depth;depth--) { |
| 661 | if (visclass==TrueColor && depth==8 && !hp_cr_maps) { |
| 662 | /* Special case: try to get 8-bit PseudoColor before */ |
| 663 | /* 8-bit TrueColor */ |
| 664 | vis = get_visual( dpy, screen, 8, PseudoColor ); |
| 665 | if (vis) { |
| 666 | return vis; |
| 667 | } |
| 668 | } |
| 669 | vis = get_visual( dpy, screen, depth, visclass ); |
| 670 | if (vis) { |
| 671 | return vis; |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | else { |
| 678 | /* search for a specific visual class */ |
| 679 | switch (preferred_class) { |
| 680 | case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break; |
| 681 | case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break; |
| 682 | case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break; |
| 683 | case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break; |
| 684 | case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break; |
| 685 | case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break; |
| 686 | default: return NULL; |
| 687 | } |
| 688 | if (min_depth==0) { |
| 689 | /* start with shallowest */ |
| 690 | for (depth=0;depth<=32;depth++) { |
| 691 | vis = get_visual( dpy, screen, depth, visclass ); |
| 692 | if (vis) { |
| 693 | return vis; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | else { |
| 698 | /* start with deepest */ |
| 699 | for (depth=32;depth>=min_depth;depth--) { |
| 700 | vis = get_visual( dpy, screen, depth, visclass ); |
| 701 | if (vis) { |
| 702 | return vis; |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | else { |
| 709 | /* First see if the MESA_CI_VISUAL env var is defined */ |
| 710 | vis = get_env_visual( dpy, screen, "MESA_CI_VISUAL" ); |
| 711 | if (vis) { |
| 712 | return vis; |
| 713 | } |
| 714 | /* Otherwise, search for a suitable visual, starting with shallowest */ |
| 715 | if (preferred_class==DONT_CARE) { |
| 716 | for (xclass=0;xclass<4;xclass++) { |
| 717 | switch (xclass) { |
| 718 | case 0: visclass = PseudoColor; break; |
| 719 | case 1: visclass = StaticColor; break; |
| 720 | case 2: visclass = GrayScale; break; |
| 721 | case 3: visclass = StaticGray; break; |
| 722 | } |
| 723 | /* try 8-bit up through 16-bit */ |
| 724 | for (depth=8;depth<=16;depth++) { |
| 725 | vis = get_visual( dpy, screen, depth, visclass ); |
| 726 | if (vis) { |
| 727 | return vis; |
| 728 | } |
| 729 | } |
| 730 | /* try min_depth up to 8-bit */ |
| 731 | for (depth=min_depth;depth<8;depth++) { |
| 732 | vis = get_visual( dpy, screen, depth, visclass ); |
| 733 | if (vis) { |
| 734 | return vis; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | else { |
| 740 | /* search for a specific visual class */ |
| 741 | switch (preferred_class) { |
| 742 | case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break; |
| 743 | case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break; |
| 744 | case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break; |
| 745 | case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break; |
| 746 | case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break; |
| 747 | case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break; |
| 748 | default: return NULL; |
| 749 | } |
| 750 | /* try 8-bit up through 16-bit */ |
| 751 | for (depth=8;depth<=16;depth++) { |
| 752 | vis = get_visual( dpy, screen, depth, visclass ); |
| 753 | if (vis) { |
| 754 | return vis; |
| 755 | } |
| 756 | } |
| 757 | /* try min_depth up to 8-bit */ |
| 758 | for (depth=min_depth;depth<8;depth++) { |
| 759 | vis = get_visual( dpy, screen, depth, visclass ); |
| 760 | if (vis) { |
| 761 | return vis; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /* didn't find a visual */ |
| 768 | return NULL; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | |
| 773 | /* |
| 774 | * Find the deepest X over/underlay visual of at least min_depth. |
| 775 | * Input: dpy, screen - X display and screen number |
| 776 | * level - the over/underlay level |
| 777 | * trans_type - transparent pixel type: GLX_NONE_EXT, |
| 778 | * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT, |
| 779 | * or DONT_CARE |
| 780 | * trans_value - transparent pixel value or DONT_CARE |
| 781 | * min_depth - minimum visual depth |
| 782 | * preferred_class - preferred GLX visual class or DONT_CARE |
| 783 | * Return: pointer to an XVisualInfo or NULL. |
| 784 | */ |
| 785 | static XVisualInfo *choose_x_overlay_visual( Display *dpy, int scr, |
Brian Paul | 42f252f | 1999-10-14 18:47:37 +0000 | [diff] [blame] | 786 | GLboolean rgbFlag, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 787 | int level, int trans_type, |
| 788 | int trans_value, |
| 789 | int min_depth, |
| 790 | int preferred_class ) |
| 791 | { |
| 792 | Atom overlayVisualsAtom; |
| 793 | OverlayInfo *overlay_info; |
| 794 | int numOverlaysPerScreen; |
| 795 | Status status; |
| 796 | Atom actualType; |
| 797 | int actualFormat; |
| 798 | unsigned long sizeData, bytesLeft; |
| 799 | int i; |
| 800 | XVisualInfo *deepvis; |
| 801 | int deepest; |
| 802 | |
| 803 | /*DEBUG int tt, tv; */ |
| 804 | |
| 805 | switch (preferred_class) { |
| 806 | case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break; |
| 807 | case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break; |
| 808 | case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break; |
| 809 | case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break; |
| 810 | case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break; |
| 811 | case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break; |
| 812 | default: preferred_class = DONT_CARE; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * The SERVER_OVERLAY_VISUALS property on the root window contains |
| 817 | * a list of overlay visuals. Get that list now. |
| 818 | */ |
| 819 | overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True); |
| 820 | if (overlayVisualsAtom == (Atom) None) { |
| 821 | return NULL; |
| 822 | } |
| 823 | |
| 824 | status = XGetWindowProperty(dpy, RootWindow( dpy, scr ), |
| 825 | overlayVisualsAtom, 0L, (long) 10000, False, |
| 826 | overlayVisualsAtom, &actualType, &actualFormat, |
| 827 | &sizeData, &bytesLeft, |
| 828 | (unsigned char **) &overlay_info ); |
| 829 | |
| 830 | if (status != Success || actualType != overlayVisualsAtom || |
| 831 | actualFormat != 32 || sizeData < 4) { |
| 832 | /* something went wrong */ |
| 833 | return NULL; |
| 834 | } |
| 835 | |
| 836 | /* Search for the deepest overlay which satisifies all criteria. */ |
| 837 | deepest = min_depth; |
| 838 | deepvis = NULL; |
| 839 | |
| 840 | numOverlaysPerScreen = (int) (sizeData / 4); |
| 841 | for (i=0;i<numOverlaysPerScreen;i++) { |
| 842 | XVisualInfo *vislist, vistemplate; |
| 843 | int count; |
| 844 | OverlayInfo *ov; |
| 845 | ov = overlay_info + i; |
| 846 | |
| 847 | if (ov->layer!=level) { |
| 848 | /* failed overlay level criteria */ |
| 849 | continue; |
| 850 | } |
| 851 | if (!(trans_type==DONT_CARE |
| 852 | || (trans_type==GLX_TRANSPARENT_INDEX_EXT |
| 853 | && ov->transparent_type>0) |
| 854 | || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) { |
| 855 | /* failed transparent pixel type criteria */ |
| 856 | continue; |
| 857 | } |
| 858 | if (trans_value!=DONT_CARE && trans_value!=ov->value) { |
| 859 | /* failed transparent pixel value criteria */ |
| 860 | continue; |
| 861 | } |
| 862 | |
| 863 | /* get XVisualInfo and check the depth */ |
| 864 | vistemplate.visualid = ov->overlay_visual; |
| 865 | vistemplate.screen = scr; |
| 866 | vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask, |
| 867 | &vistemplate, &count ); |
| 868 | |
| 869 | if (count!=1) { |
| 870 | /* something went wrong */ |
| 871 | continue; |
| 872 | } |
| 873 | if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) { |
| 874 | /* wrong visual class */ |
| 875 | continue; |
| 876 | } |
| 877 | |
Brian Paul | 42f252f | 1999-10-14 18:47:37 +0000 | [diff] [blame] | 878 | /* if RGB was requested, make sure we have True/DirectColor */ |
| 879 | if (rgbFlag && vislist->CLASS != TrueColor |
| 880 | && vislist->CLASS != DirectColor) |
| 881 | continue; |
| 882 | |
| 883 | /* if CI was requested, make sure we have a color indexed visual */ |
| 884 | if (!rgbFlag |
| 885 | && (vislist->CLASS == TrueColor || vislist->CLASS == DirectColor)) |
| 886 | continue; |
| 887 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 888 | if (deepvis==NULL || vislist->depth > deepest) { |
| 889 | /* YES! found a satisfactory visual */ |
| 890 | if (deepvis) { |
Brian Paul | 80af361 | 1999-10-13 18:49:47 +0000 | [diff] [blame] | 891 | XFree( deepvis ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 892 | } |
| 893 | deepest = vislist->depth; |
| 894 | deepvis = vislist; |
| 895 | /* DEBUG tt = ov->transparent_type;*/ |
| 896 | /* DEBUG tv = ov->value; */ |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /*DEBUG |
| 901 | if (deepvis) { |
| 902 | printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n", |
| 903 | deepvis->visualid, level, deepvis->depth, tt, tv ); |
| 904 | } |
| 905 | */ |
| 906 | return deepvis; |
| 907 | } |
| 908 | |
| 909 | |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 910 | /**********************************************************************/ |
| 911 | /*** Begin Fake GLX API Functions ***/ |
| 912 | /**********************************************************************/ |
| 913 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 914 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 915 | static XMesaVisual choose_visual( Display *dpy, int screen, const int *list ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 916 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 917 | const int *parselist; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 918 | XVisualInfo *vis; |
| 919 | int min_ci = 0; |
| 920 | int min_red=0, min_green=0, min_blue=0; |
| 921 | GLboolean rgb_flag = GL_FALSE; |
| 922 | GLboolean alpha_flag = GL_FALSE; |
| 923 | GLboolean double_flag = GL_FALSE; |
| 924 | GLboolean stereo_flag = GL_FALSE; |
| 925 | GLint depth_size = 0; |
| 926 | GLint stencil_size = 0; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 927 | GLint accumRedSize = 0; |
| 928 | GLint accumGreenSize = 0; |
| 929 | GLint accumBlueSize = 0; |
| 930 | GLint accumAlphaSize = 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 931 | int level = 0; |
| 932 | int visual_type = DONT_CARE; |
| 933 | int trans_type = DONT_CARE; |
| 934 | int trans_value = DONT_CARE; |
Brian Paul | e1210b1 | 2000-03-31 01:17:52 +0000 | [diff] [blame] | 935 | GLint caveat = DONT_CARE; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 936 | XMesaVisual xmvis = NULL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 937 | |
| 938 | parselist = list; |
| 939 | |
| 940 | while (*parselist) { |
| 941 | |
| 942 | switch (*parselist) { |
| 943 | case GLX_USE_GL: |
| 944 | /* ignore */ |
| 945 | parselist++; |
| 946 | break; |
| 947 | case GLX_BUFFER_SIZE: |
| 948 | parselist++; |
| 949 | min_ci = *parselist++; |
| 950 | break; |
| 951 | case GLX_LEVEL: |
| 952 | parselist++; |
| 953 | level = *parselist++; |
| 954 | break; |
| 955 | case GLX_RGBA: |
| 956 | rgb_flag = GL_TRUE; |
| 957 | parselist++; |
| 958 | break; |
| 959 | case GLX_DOUBLEBUFFER: |
| 960 | double_flag = GL_TRUE; |
| 961 | parselist++; |
| 962 | break; |
| 963 | case GLX_STEREO: |
| 964 | stereo_flag = GL_TRUE; |
| 965 | return NULL; |
| 966 | case GLX_AUX_BUFFERS: |
| 967 | /* ignore */ |
| 968 | parselist++; |
| 969 | parselist++; |
| 970 | break; |
| 971 | case GLX_RED_SIZE: |
| 972 | parselist++; |
| 973 | min_red = *parselist++; |
| 974 | break; |
| 975 | case GLX_GREEN_SIZE: |
| 976 | parselist++; |
| 977 | min_green = *parselist++; |
| 978 | break; |
| 979 | case GLX_BLUE_SIZE: |
| 980 | parselist++; |
| 981 | min_blue = *parselist++; |
| 982 | break; |
| 983 | case GLX_ALPHA_SIZE: |
| 984 | parselist++; |
| 985 | { |
| 986 | GLint size = *parselist++; |
| 987 | alpha_flag = size>0 ? 1 : 0; |
| 988 | } |
| 989 | break; |
| 990 | case GLX_DEPTH_SIZE: |
| 991 | parselist++; |
| 992 | depth_size = *parselist++; |
| 993 | break; |
| 994 | case GLX_STENCIL_SIZE: |
| 995 | parselist++; |
| 996 | stencil_size = *parselist++; |
| 997 | break; |
| 998 | case GLX_ACCUM_RED_SIZE: |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 999 | parselist++; |
| 1000 | { |
| 1001 | GLint size = *parselist++; |
| 1002 | accumRedSize = MAX2( accumRedSize, size ); |
| 1003 | } |
| 1004 | break; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1005 | case GLX_ACCUM_GREEN_SIZE: |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1006 | parselist++; |
| 1007 | { |
| 1008 | GLint size = *parselist++; |
| 1009 | accumGreenSize = MAX2( accumGreenSize, size ); |
| 1010 | } |
| 1011 | break; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1012 | case GLX_ACCUM_BLUE_SIZE: |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1013 | parselist++; |
| 1014 | { |
| 1015 | GLint size = *parselist++; |
| 1016 | accumBlueSize = MAX2( accumBlueSize, size ); |
| 1017 | } |
| 1018 | break; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1019 | case GLX_ACCUM_ALPHA_SIZE: |
| 1020 | parselist++; |
| 1021 | { |
| 1022 | GLint size = *parselist++; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1023 | accumAlphaSize = MAX2( accumAlphaSize, size ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1024 | } |
| 1025 | break; |
| 1026 | |
| 1027 | /* |
| 1028 | * GLX_EXT_visual_info extension |
| 1029 | */ |
| 1030 | case GLX_X_VISUAL_TYPE_EXT: |
| 1031 | parselist++; |
| 1032 | visual_type = *parselist++; |
| 1033 | break; |
| 1034 | case GLX_TRANSPARENT_TYPE_EXT: |
| 1035 | parselist++; |
| 1036 | trans_type = *parselist++; |
| 1037 | break; |
| 1038 | case GLX_TRANSPARENT_INDEX_VALUE_EXT: |
| 1039 | parselist++; |
| 1040 | trans_value = *parselist++; |
| 1041 | break; |
| 1042 | case GLX_TRANSPARENT_RED_VALUE_EXT: |
| 1043 | case GLX_TRANSPARENT_GREEN_VALUE_EXT: |
| 1044 | case GLX_TRANSPARENT_BLUE_VALUE_EXT: |
| 1045 | case GLX_TRANSPARENT_ALPHA_VALUE_EXT: |
| 1046 | /* ignore */ |
| 1047 | parselist++; |
| 1048 | parselist++; |
| 1049 | break; |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1050 | |
Brian Paul | e1210b1 | 2000-03-31 01:17:52 +0000 | [diff] [blame] | 1051 | /* |
| 1052 | * GLX_EXT_visual_info extension |
| 1053 | */ |
| 1054 | case GLX_VISUAL_CAVEAT_EXT: |
| 1055 | parselist++; |
| 1056 | caveat = *parselist++; /* ignored for now */ |
| 1057 | break; |
| 1058 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1059 | /* |
Brian Paul | 66ab727 | 2002-11-05 21:11:18 +0000 | [diff] [blame] | 1060 | * GLX_ARB_multisample |
| 1061 | */ |
| 1062 | case GLX_SAMPLE_BUFFERS_ARB: |
| 1063 | /* ms not supported */ |
| 1064 | return NULL; |
| 1065 | case GLX_SAMPLES_ARB: |
| 1066 | /* ms not supported */ |
| 1067 | return NULL; |
| 1068 | |
| 1069 | /* |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1070 | * FBConfig attribs. |
| 1071 | */ |
| 1072 | case GLX_RENDER_TYPE: |
| 1073 | parselist++; |
| 1074 | if (*parselist == GLX_RGBA_BIT) { |
| 1075 | rgb_flag = GL_TRUE; |
| 1076 | } |
| 1077 | else if (*parselist == GLX_COLOR_INDEX_BIT) { |
| 1078 | rgb_flag = GL_FALSE; |
| 1079 | } |
| 1080 | else if (*parselist == 0) { |
| 1081 | rgb_flag = GL_TRUE; |
| 1082 | } |
| 1083 | parselist++; |
| 1084 | break; |
| 1085 | case GLX_DRAWABLE_TYPE: |
| 1086 | parselist++; |
| 1087 | if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) { |
| 1088 | return NULL; /* bad bit */ |
| 1089 | } |
| 1090 | parselist++; |
| 1091 | break; |
| 1092 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1093 | case None: |
| 1094 | break; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1095 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1096 | default: |
| 1097 | /* undefined attribute */ |
Brian Paul | 2ad5921 | 2002-10-30 20:24:45 +0000 | [diff] [blame] | 1098 | _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()", |
| 1099 | *parselist); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1100 | return NULL; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * Since we're only simulating the GLX extension this function will never |
| 1106 | * find any real GL visuals. Instead, all we can do is try to find an RGB |
| 1107 | * or CI visual of appropriate depth. Other requested attributes such as |
| 1108 | * double buffering, depth buffer, etc. will be associated with the X |
| 1109 | * visual and stored in the VisualTable[]. |
| 1110 | */ |
| 1111 | if (level==0) { |
| 1112 | /* normal color planes */ |
| 1113 | if (rgb_flag) { |
| 1114 | /* Get an RGB visual */ |
| 1115 | int min_rgb = min_red + min_green + min_blue; |
| 1116 | if (min_rgb>1 && min_rgb<8) { |
| 1117 | /* a special case to be sure we can get a monochrome visual */ |
| 1118 | min_rgb = 1; |
| 1119 | } |
| 1120 | vis = choose_x_visual( dpy, screen, rgb_flag, min_rgb, visual_type ); |
| 1121 | } |
| 1122 | else { |
| 1123 | /* Get a color index visual */ |
| 1124 | vis = choose_x_visual( dpy, screen, rgb_flag, min_ci, visual_type ); |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1125 | accumRedSize = accumGreenSize = accumBlueSize = accumAlphaSize = 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | else { |
| 1129 | /* over/underlay planes */ |
Brian Paul | 42f252f | 1999-10-14 18:47:37 +0000 | [diff] [blame] | 1130 | if (rgb_flag) { |
| 1131 | /* rgba overlay */ |
| 1132 | int min_rgb = min_red + min_green + min_blue; |
| 1133 | if (min_rgb>1 && min_rgb<8) { |
| 1134 | /* a special case to be sure we can get a monochrome visual */ |
| 1135 | min_rgb = 1; |
| 1136 | } |
| 1137 | vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level, |
| 1138 | trans_type, trans_value, min_rgb, visual_type ); |
| 1139 | } |
| 1140 | else { |
| 1141 | /* color index overlay */ |
| 1142 | vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level, |
| 1143 | trans_type, trans_value, min_ci, visual_type ); |
| 1144 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | if (vis) { |
Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 1148 | /* Note: we're not exactly obeying the glXChooseVisual rules here. |
| 1149 | * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the |
Brian Paul | 2c7e633 | 2000-10-05 17:38:21 +0000 | [diff] [blame] | 1150 | * largest depth buffer size, which is 32bits/value. Instead, we |
Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 1151 | * return 16 to maintain performance with earlier versions of Mesa. |
| 1152 | */ |
Brian Paul | 2c7e633 | 2000-10-05 17:38:21 +0000 | [diff] [blame] | 1153 | if (depth_size > 24) |
| 1154 | depth_size = 31; /* 32 causes int overflow problems */ |
Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 1155 | else if (depth_size > 16) |
| 1156 | depth_size = 24; |
Brian Paul | 2c7e633 | 2000-10-05 17:38:21 +0000 | [diff] [blame] | 1157 | else if (depth_size > 0) |
| 1158 | depth_size = DEFAULT_SOFTWARE_DEPTH_BITS; /*16*/ |
| 1159 | |
Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 1160 | /* we only support one size of stencil and accum buffers. */ |
| 1161 | if (stencil_size > 0) |
| 1162 | stencil_size = STENCIL_BITS; |
Brian Paul | 6d62d7f | 2001-03-23 21:37:05 +0000 | [diff] [blame] | 1163 | if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 || |
| 1164 | accumAlphaSize > 0) { |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1165 | accumRedSize = ACCUM_BITS; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1166 | accumGreenSize = ACCUM_BITS; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1167 | accumBlueSize = ACCUM_BITS; |
Brian Paul | 6d62d7f | 2001-03-23 21:37:05 +0000 | [diff] [blame] | 1168 | accumAlphaSize = alpha_flag ? ACCUM_BITS : 0; |
| 1169 | } |
| 1170 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1171 | xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag, |
| 1172 | stereo_flag, depth_size, stencil_size, |
| 1173 | accumRedSize, accumGreenSize, |
| 1174 | accumBlueSize, accumAlphaSize, level ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1177 | return xmvis; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1181 | static XVisualInfo * |
| 1182 | Fake_glXChooseVisual( Display *dpy, int screen, int *list ) |
| 1183 | { |
| 1184 | XMesaVisual xmvis = choose_visual(dpy, screen, list); |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1185 | if (xmvis) { |
| 1186 | #if 0 |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1187 | return xmvis->vishandle; |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1188 | #else |
| 1189 | /* create a new vishandle - the cached one may be stale */ |
| 1190 | xmvis->vishandle = _mesa_malloc(sizeof(XVisualInfo)); |
| 1191 | if (xmvis->vishandle) { |
| 1192 | _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); |
| 1193 | } |
| 1194 | return xmvis->vishandle; |
| 1195 | #endif |
| 1196 | } |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1197 | else |
| 1198 | return NULL; |
| 1199 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1200 | |
| 1201 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1202 | static GLXContext |
| 1203 | Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo, |
| 1204 | GLXContext share_list, Bool direct ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1205 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1206 | XMesaVisual xmvis; |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1207 | struct fake_glx_context *glxCtx; |
Brian Paul | 5e1680c | 2001-08-07 16:01:34 +0000 | [diff] [blame] | 1208 | struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list; |
Brian Paul | 99aab34 | 2002-04-02 23:52:53 +0000 | [diff] [blame] | 1209 | |
| 1210 | if (!dpy || !visinfo) |
| 1211 | return 0; |
| 1212 | |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1213 | glxCtx = CALLOC_STRUCT(fake_glx_context); |
| 1214 | if (!glxCtx) |
| 1215 | return 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1216 | |
| 1217 | /* deallocate unused windows/buffers */ |
| 1218 | XMesaGarbageCollect(); |
| 1219 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1220 | xmvis = find_glx_visual( dpy, visinfo ); |
| 1221 | if (!xmvis) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1222 | /* This visual wasn't found with glXChooseVisual() */ |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1223 | xmvis = create_glx_visual( dpy, visinfo ); |
| 1224 | if (!xmvis) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1225 | /* unusable visual */ |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1226 | FREE(glxCtx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1227 | return NULL; |
| 1228 | } |
| 1229 | } |
| 1230 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1231 | glxCtx->xmesaContext = XMesaCreateContext(xmvis, |
Brian Paul | 5e1680c | 2001-08-07 16:01:34 +0000 | [diff] [blame] | 1232 | shareCtx ? shareCtx->xmesaContext : NULL); |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1233 | if (!glxCtx->xmesaContext) { |
| 1234 | FREE(glxCtx); |
| 1235 | return NULL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1236 | } |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1237 | |
| 1238 | glxCtx->xmesaContext->direct = GL_FALSE; |
| 1239 | glxCtx->glxContext.isDirect = GL_FALSE; |
| 1240 | glxCtx->glxContext.currentDpy = dpy; |
| 1241 | glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ |
| 1242 | |
| 1243 | assert((void *) glxCtx == (void *) &(glxCtx->glxContext)); |
| 1244 | |
| 1245 | return (GLXContext) glxCtx; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1249 | /* XXX these may have to be removed due to thread-safety issues. */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1250 | static GLXContext MakeCurrent_PrevContext = 0; |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1251 | static GLXDrawable MakeCurrent_PrevDrawable = 0; |
| 1252 | static GLXDrawable MakeCurrent_PrevReadable = 0; |
| 1253 | static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0; |
| 1254 | static XMesaBuffer MakeCurrent_PrevReadBuffer = 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1255 | |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1256 | |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1257 | /* GLX 1.3 and later */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1258 | static Bool |
| 1259 | Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw, |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1260 | GLXDrawable read, GLXContext ctx ) |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1261 | { |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1262 | struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; |
| 1263 | |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1264 | if (ctx && draw && read) { |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1265 | XMesaBuffer drawBuffer, readBuffer; |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1266 | XMesaContext xmctx = glxCtx->xmesaContext; |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1267 | |
| 1268 | /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */ |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1269 | if (ctx == MakeCurrent_PrevContext |
| 1270 | && draw == MakeCurrent_PrevDrawable) { |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1271 | drawBuffer = MakeCurrent_PrevDrawBuffer; |
| 1272 | } |
| 1273 | else { |
| 1274 | drawBuffer = XMesaFindBuffer( dpy, draw ); |
| 1275 | } |
| 1276 | if (!drawBuffer) { |
| 1277 | /* drawable must be a new window! */ |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1278 | drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, xmctx); |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1279 | if (!drawBuffer) { |
| 1280 | /* Out of memory, or context/drawable depth mismatch */ |
| 1281 | return False; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */ |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1286 | if (ctx == MakeCurrent_PrevContext |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1287 | && read == MakeCurrent_PrevReadable) { |
| 1288 | readBuffer = MakeCurrent_PrevReadBuffer; |
| 1289 | } |
| 1290 | else { |
| 1291 | readBuffer = XMesaFindBuffer( dpy, read ); |
| 1292 | } |
| 1293 | if (!readBuffer) { |
| 1294 | /* drawable must be a new window! */ |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1295 | readBuffer = XMesaCreateWindowBuffer2(glxCtx->xmesaContext->xm_visual, |
| 1296 | read, xmctx); |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1297 | if (!readBuffer) { |
| 1298 | /* Out of memory, or context/drawable depth mismatch */ |
| 1299 | return False; |
| 1300 | } |
| 1301 | } |
| 1302 | |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1303 | MakeCurrent_PrevContext = ctx; |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1304 | MakeCurrent_PrevDrawable = draw; |
| 1305 | MakeCurrent_PrevReadable = read; |
| 1306 | MakeCurrent_PrevDrawBuffer = drawBuffer; |
| 1307 | MakeCurrent_PrevReadBuffer = readBuffer; |
| 1308 | |
| 1309 | /* Now make current! */ |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1310 | if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) { |
Brian Paul | 12c1bee | 2001-05-24 20:05:32 +0000 | [diff] [blame] | 1311 | ((__GLXcontext *) ctx)->currentDpy = dpy; |
| 1312 | ((__GLXcontext *) ctx)->currentDrawable = draw; |
Brian Paul | 8d687e7 | 2002-03-15 18:43:25 +0000 | [diff] [blame] | 1313 | #ifndef GLX_BUILT_IN_XMESA |
Brian Paul | 12c1bee | 2001-05-24 20:05:32 +0000 | [diff] [blame] | 1314 | ((__GLXcontext *) ctx)->currentReadable = read; |
Brian Paul | 8d687e7 | 2002-03-15 18:43:25 +0000 | [diff] [blame] | 1315 | #else |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1316 | __glXSetCurrentContext(ctx); |
| 1317 | #endif |
| 1318 | return True; |
| 1319 | } |
| 1320 | else { |
| 1321 | return False; |
| 1322 | } |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1323 | } |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1324 | else if (!ctx && !draw && !read) { |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1325 | /* release current context w/out assigning new one. */ |
| 1326 | XMesaMakeCurrent( NULL, NULL ); |
| 1327 | MakeCurrent_PrevContext = 0; |
| 1328 | MakeCurrent_PrevDrawable = 0; |
| 1329 | MakeCurrent_PrevReadable = 0; |
| 1330 | MakeCurrent_PrevDrawBuffer = 0; |
| 1331 | MakeCurrent_PrevReadBuffer = 0; |
Brian Paul | 84cac84 | 2001-05-29 23:15:07 +0000 | [diff] [blame] | 1332 | #ifdef GLX_BUILT_IN_XMESA |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 1333 | /* XXX bind dummy context with __glXSetCurrentContext(ctx); */ |
| 1334 | #endif |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1335 | return True; |
| 1336 | } |
| 1337 | else { |
| 1338 | /* The args must either all be non-zero or all zero. |
| 1339 | * This is an error. |
| 1340 | */ |
| 1341 | return False; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1346 | |
| 1347 | static Bool |
| 1348 | Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx ) |
| 1349 | { |
| 1350 | return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx ); |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1355 | static GLXPixmap |
| 1356 | Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1357 | { |
| 1358 | XMesaVisual v; |
| 1359 | XMesaBuffer b; |
| 1360 | |
| 1361 | v = find_glx_visual( dpy, visinfo ); |
| 1362 | if (!v) { |
| 1363 | v = create_glx_visual( dpy, visinfo ); |
| 1364 | if (!v) { |
| 1365 | /* unusable visual */ |
| 1366 | return 0; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); |
| 1371 | if (!b) { |
| 1372 | return 0; |
| 1373 | } |
| 1374 | return b->frontbuffer; |
| 1375 | } |
| 1376 | |
| 1377 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 1378 | /*** GLX_MESA_pixmap_colormap ***/ |
| 1379 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1380 | static GLXPixmap |
| 1381 | Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo, |
| 1382 | Pixmap pixmap, Colormap cmap ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1383 | { |
| 1384 | XMesaVisual v; |
| 1385 | XMesaBuffer b; |
| 1386 | |
| 1387 | v = find_glx_visual( dpy, visinfo ); |
| 1388 | if (!v) { |
| 1389 | v = create_glx_visual( dpy, visinfo ); |
| 1390 | if (!v) { |
| 1391 | /* unusable visual */ |
| 1392 | return 0; |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | b = XMesaCreatePixmapBuffer( v, pixmap, cmap ); |
| 1397 | if (!b) { |
| 1398 | return 0; |
| 1399 | } |
| 1400 | return b->frontbuffer; |
| 1401 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1402 | |
| 1403 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1404 | static void |
| 1405 | Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1406 | { |
| 1407 | XMesaBuffer b = XMesaFindBuffer(dpy, pixmap); |
| 1408 | if (b) { |
| 1409 | XMesaDestroyBuffer(b); |
| 1410 | } |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 1411 | else if (_mesa_getenv("MESA_DEBUG")) { |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 1412 | _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | |
Brian Paul | 4c07bd5 | 2000-06-08 22:50:28 +0000 | [diff] [blame] | 1417 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1418 | static void |
| 1419 | Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, |
Brian Paul | 3994b77 | 2000-02-27 18:26:54 +0000 | [diff] [blame] | 1420 | unsigned long mask ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1421 | { |
Brian Paul | 83b820a | 2002-06-16 03:56:11 +0000 | [diff] [blame] | 1422 | struct fake_glx_context *fakeSrc = (struct fake_glx_context *) src; |
| 1423 | struct fake_glx_context *fakeDst = (struct fake_glx_context *) dst; |
| 1424 | XMesaContext xm_src = fakeSrc->xmesaContext; |
| 1425 | XMesaContext xm_dst = fakeDst->xmesaContext; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1426 | (void) dpy; |
Keith Whitwell | 7a1f3a3 | 2001-01-08 04:55:22 +0000 | [diff] [blame] | 1427 | _mesa_copy_context( xm_src->gl_ctx, xm_dst->gl_ctx, (GLuint) mask ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | |
| 1431 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1432 | static Bool |
| 1433 | Fake_glXQueryExtension( Display *dpy, int *errorb, int *event ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1434 | { |
| 1435 | /* Mesa's GLX isn't really an X extension but we try to act like one. */ |
| 1436 | (void) dpy; |
| 1437 | (void) errorb; |
| 1438 | (void) event; |
| 1439 | return True; |
| 1440 | } |
| 1441 | |
| 1442 | |
Brian Paul | e7b16b7 | 2000-03-17 15:33:09 +0000 | [diff] [blame] | 1443 | extern void _kw_ungrab_all( Display *dpy ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1444 | void _kw_ungrab_all( Display *dpy ) |
| 1445 | { |
| 1446 | XUngrabPointer( dpy, CurrentTime ); |
| 1447 | XUngrabKeyboard( dpy, CurrentTime ); |
| 1448 | } |
| 1449 | |
| 1450 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1451 | static void |
| 1452 | Fake_glXDestroyContext( Display *dpy, GLXContext ctx ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1453 | { |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1454 | struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1455 | (void) dpy; |
| 1456 | MakeCurrent_PrevContext = 0; |
| 1457 | MakeCurrent_PrevDrawable = 0; |
Brian Paul | 086a151 | 1999-11-25 17:37:49 +0000 | [diff] [blame] | 1458 | MakeCurrent_PrevReadable = 0; |
| 1459 | MakeCurrent_PrevDrawBuffer = 0; |
| 1460 | MakeCurrent_PrevReadBuffer = 0; |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1461 | XMesaDestroyContext( glxCtx->xmesaContext ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1462 | XMesaGarbageCollect(); |
| 1463 | } |
| 1464 | |
| 1465 | |
| 1466 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1467 | static Bool |
| 1468 | Fake_glXIsDirect( Display *dpy, GLXContext ctx ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1469 | { |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1470 | struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1471 | (void) dpy; |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 1472 | return glxCtx->xmesaContext->direct; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | |
| 1476 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1477 | static void |
| 1478 | Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1479 | { |
| 1480 | XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1481 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1482 | if (buffer) { |
| 1483 | XMesaSwapBuffers(buffer); |
| 1484 | } |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 1485 | else if (_mesa_getenv("MESA_DEBUG")) { |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 1486 | _mesa_warning(NULL, "Mesa: glXSwapBuffers: invalid drawable\n"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | |
Brian Paul | 4c07bd5 | 2000-06-08 22:50:28 +0000 | [diff] [blame] | 1491 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 1492 | /*** GLX_MESA_copy_sub_buffer ***/ |
| 1493 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1494 | static void |
| 1495 | Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable, |
| 1496 | int x, int y, int width, int height ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1497 | { |
| 1498 | XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); |
| 1499 | if (buffer) { |
| 1500 | XMesaCopySubBuffer(buffer, x, y, width, height); |
| 1501 | } |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 1502 | else if (_mesa_getenv("MESA_DEBUG")) { |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 1503 | _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | |
| 1508 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1509 | static Bool |
| 1510 | Fake_glXQueryVersion( Display *dpy, int *maj, int *min ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1511 | { |
| 1512 | (void) dpy; |
| 1513 | /* Return GLX version, not Mesa version */ |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 1514 | assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION); |
| 1515 | *maj = CLIENT_MAJOR_VERSION; |
| 1516 | *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1517 | return True; |
| 1518 | } |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | /* |
| 1523 | * Query the GLX attributes of the given XVisualInfo. |
| 1524 | */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1525 | static int |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1526 | get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1527 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1528 | ASSERT(xmvis); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1529 | switch(attrib) { |
| 1530 | case GLX_USE_GL: |
| 1531 | *value = (int) True; |
| 1532 | return 0; |
| 1533 | case GLX_BUFFER_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1534 | *value = xmvis->visinfo->depth; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1535 | return 0; |
| 1536 | case GLX_LEVEL: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1537 | *value = xmvis->level; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1538 | return 0; |
| 1539 | case GLX_RGBA: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1540 | if (xmvis->mesa_visual.rgbMode) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1541 | *value = True; |
| 1542 | } |
| 1543 | else { |
| 1544 | *value = False; |
| 1545 | } |
| 1546 | return 0; |
| 1547 | case GLX_DOUBLEBUFFER: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1548 | *value = (int) xmvis->mesa_visual.doubleBufferMode; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1549 | return 0; |
| 1550 | case GLX_STEREO: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1551 | *value = (int) xmvis->mesa_visual.stereoMode; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1552 | return 0; |
| 1553 | case GLX_AUX_BUFFERS: |
| 1554 | *value = (int) False; |
| 1555 | return 0; |
| 1556 | case GLX_RED_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1557 | *value = xmvis->mesa_visual.redBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1558 | return 0; |
| 1559 | case GLX_GREEN_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1560 | *value = xmvis->mesa_visual.greenBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1561 | return 0; |
| 1562 | case GLX_BLUE_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1563 | *value = xmvis->mesa_visual.blueBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1564 | return 0; |
| 1565 | case GLX_ALPHA_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1566 | *value = xmvis->mesa_visual.alphaBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1567 | return 0; |
| 1568 | case GLX_DEPTH_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1569 | *value = xmvis->mesa_visual.depthBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1570 | return 0; |
| 1571 | case GLX_STENCIL_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1572 | *value = xmvis->mesa_visual.stencilBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1573 | return 0; |
| 1574 | case GLX_ACCUM_RED_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1575 | *value = xmvis->mesa_visual.accumRedBits; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1576 | return 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1577 | case GLX_ACCUM_GREEN_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1578 | *value = xmvis->mesa_visual.accumGreenBits; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1579 | return 0; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1580 | case GLX_ACCUM_BLUE_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1581 | *value = xmvis->mesa_visual.accumBlueBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1582 | return 0; |
| 1583 | case GLX_ACCUM_ALPHA_SIZE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1584 | *value = xmvis->mesa_visual.accumAlphaBits; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1585 | return 0; |
| 1586 | |
| 1587 | /* |
| 1588 | * GLX_EXT_visual_info extension |
| 1589 | */ |
| 1590 | case GLX_X_VISUAL_TYPE_EXT: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1591 | switch (xmvis->visinfo->CLASS) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1592 | case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0; |
| 1593 | case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0; |
| 1594 | case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0; |
| 1595 | case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0; |
| 1596 | case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0; |
| 1597 | case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0; |
| 1598 | } |
| 1599 | return 0; |
| 1600 | case GLX_TRANSPARENT_TYPE_EXT: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1601 | if (xmvis->level==0) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1602 | /* normal planes */ |
| 1603 | *value = GLX_NONE_EXT; |
| 1604 | } |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1605 | else if (xmvis->level>0) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1606 | /* overlay */ |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1607 | if (xmvis->mesa_visual.rgbMode) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1608 | *value = GLX_TRANSPARENT_RGB_EXT; |
| 1609 | } |
| 1610 | else { |
| 1611 | *value = GLX_TRANSPARENT_INDEX_EXT; |
| 1612 | } |
| 1613 | } |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1614 | else if (xmvis->level<0) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1615 | /* underlay */ |
| 1616 | *value = GLX_NONE_EXT; |
| 1617 | } |
| 1618 | return 0; |
| 1619 | case GLX_TRANSPARENT_INDEX_VALUE_EXT: |
| 1620 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1621 | int pixel = transparent_pixel( xmvis ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1622 | if (pixel>=0) { |
| 1623 | *value = pixel; |
| 1624 | } |
| 1625 | /* else undefined */ |
| 1626 | } |
| 1627 | return 0; |
| 1628 | case GLX_TRANSPARENT_RED_VALUE_EXT: |
| 1629 | /* undefined */ |
| 1630 | return 0; |
| 1631 | case GLX_TRANSPARENT_GREEN_VALUE_EXT: |
| 1632 | /* undefined */ |
| 1633 | return 0; |
| 1634 | case GLX_TRANSPARENT_BLUE_VALUE_EXT: |
| 1635 | /* undefined */ |
| 1636 | return 0; |
| 1637 | case GLX_TRANSPARENT_ALPHA_VALUE_EXT: |
| 1638 | /* undefined */ |
| 1639 | return 0; |
| 1640 | |
| 1641 | /* |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1642 | * GLX_EXT_visual_info extension |
| 1643 | */ |
| 1644 | case GLX_VISUAL_CAVEAT_EXT: |
Brian Paul | fc68be6 | 2000-03-31 01:12:40 +0000 | [diff] [blame] | 1645 | /* test for zero, just in case */ |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1646 | if (xmvis->VisualCaveat > 0) |
| 1647 | *value = xmvis->VisualCaveat; |
Brian Paul | 962f426 | 2000-03-31 18:17:01 +0000 | [diff] [blame] | 1648 | else |
| 1649 | *value = GLX_NONE_EXT; |
| 1650 | return 0; |
Brian Paul | b2e4600 | 2000-03-31 01:07:13 +0000 | [diff] [blame] | 1651 | |
| 1652 | /* |
Brian Paul | 66ab727 | 2002-11-05 21:11:18 +0000 | [diff] [blame] | 1653 | * GLX_ARB_multisample |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1654 | */ |
Brian Paul | 66ab727 | 2002-11-05 21:11:18 +0000 | [diff] [blame] | 1655 | case GLX_SAMPLE_BUFFERS_ARB: |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1656 | *value = 0; |
| 1657 | return 0; |
Brian Paul | 66ab727 | 2002-11-05 21:11:18 +0000 | [diff] [blame] | 1658 | case GLX_SAMPLES_ARB: |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1659 | *value = 0; |
| 1660 | return 0; |
| 1661 | |
| 1662 | /* |
| 1663 | * For FBConfigs: |
| 1664 | */ |
| 1665 | case GLX_SCREEN_EXT: |
| 1666 | if (!fbconfig) |
| 1667 | return GLX_BAD_ATTRIBUTE; |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1668 | *value = xmvis->visinfo->screen; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1669 | break; |
| 1670 | case GLX_DRAWABLE_TYPE: /*SGIX too */ |
| 1671 | if (!fbconfig) |
| 1672 | return GLX_BAD_ATTRIBUTE; |
| 1673 | *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; |
| 1674 | break; |
| 1675 | case GLX_RENDER_TYPE_SGIX: |
| 1676 | if (!fbconfig) |
| 1677 | return GLX_BAD_ATTRIBUTE; |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1678 | if (xmvis->mesa_visual.rgbMode) |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1679 | *value = GLX_RGBA_BIT; |
| 1680 | else |
| 1681 | *value = GLX_COLOR_INDEX_BIT; |
| 1682 | break; |
| 1683 | case GLX_X_RENDERABLE_SGIX: |
| 1684 | if (!fbconfig) |
| 1685 | return GLX_BAD_ATTRIBUTE; |
| 1686 | *value = True; /* XXX really? */ |
| 1687 | break; |
| 1688 | case GLX_FBCONFIG_ID_SGIX: |
| 1689 | if (!fbconfig) |
| 1690 | return GLX_BAD_ATTRIBUTE; |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1691 | *value = xmvis->visinfo->visualid; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1692 | break; |
| 1693 | case GLX_MAX_PBUFFER_WIDTH: |
| 1694 | if (!fbconfig) |
| 1695 | return GLX_BAD_ATTRIBUTE; |
| 1696 | /* XXX or MAX_WIDTH? */ |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1697 | *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen); |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1698 | break; |
| 1699 | case GLX_MAX_PBUFFER_HEIGHT: |
| 1700 | if (!fbconfig) |
| 1701 | return GLX_BAD_ATTRIBUTE; |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1702 | *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen); |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1703 | break; |
| 1704 | case GLX_MAX_PBUFFER_PIXELS: |
| 1705 | if (!fbconfig) |
| 1706 | return GLX_BAD_ATTRIBUTE; |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1707 | *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) * |
| 1708 | DisplayHeight(xmvis->display, xmvis->visinfo->screen); |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1709 | break; |
| 1710 | case GLX_VISUAL_ID: |
| 1711 | if (!fbconfig) |
| 1712 | return GLX_BAD_ATTRIBUTE; |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1713 | *value = xmvis->visinfo->visualid; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1714 | break; |
| 1715 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1716 | default: |
| 1717 | return GLX_BAD_ATTRIBUTE; |
| 1718 | } |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1719 | return Success; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1723 | static int |
| 1724 | Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo, |
| 1725 | int attrib, int *value ) |
| 1726 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1727 | XMesaVisual xmvis; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1728 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1729 | xmvis = find_glx_visual( dpy, visinfo ); |
| 1730 | if (!xmvis) { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1731 | /* this visual wasn't obtained with glXChooseVisual */ |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1732 | xmvis = create_glx_visual( dpy, visinfo ); |
| 1733 | if (!xmvis) { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1734 | /* this visual can't be used for GL rendering */ |
| 1735 | if (attrib==GLX_USE_GL) { |
| 1736 | *value = (int) False; |
| 1737 | return 0; |
| 1738 | } |
| 1739 | else { |
| 1740 | return GLX_BAD_VISUAL; |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1745 | return get_config(xmvis, attrib, value, GL_FALSE); |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1748 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1749 | static void |
| 1750 | Fake_glXWaitGL( void ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1751 | { |
| 1752 | XMesaContext xmesa = XMesaGetCurrentContext(); |
| 1753 | XMesaFlush( xmesa ); |
| 1754 | } |
| 1755 | |
| 1756 | |
| 1757 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1758 | static void |
| 1759 | Fake_glXWaitX( void ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1760 | { |
| 1761 | XMesaContext xmesa = XMesaGetCurrentContext(); |
| 1762 | XMesaFlush( xmesa ); |
| 1763 | } |
| 1764 | |
| 1765 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1766 | static const char * |
| 1767 | get_extensions( void ) |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1768 | { |
| 1769 | #ifdef FX |
Brian Paul | 367d308 | 2002-10-25 21:06:26 +0000 | [diff] [blame] | 1770 | const char *fx = _mesa_getenv("MESA_GLX_FX"); |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1771 | if (fx && fx[0] != 'd') { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1772 | return EXTENSIONS; |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1773 | } |
| 1774 | #endif |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 1775 | return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */ |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1776 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1777 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1778 | |
| 1779 | |
| 1780 | /* GLX 1.1 and later */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1781 | static const char * |
| 1782 | Fake_glXQueryExtensionsString( Display *dpy, int screen ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1783 | { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1784 | (void) dpy; |
| 1785 | (void) screen; |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1786 | return get_extensions(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | /* GLX 1.1 and later */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1792 | static const char * |
| 1793 | Fake_glXQueryServerString( Display *dpy, int screen, int name ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1794 | { |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 1795 | static char version[1000]; |
Brian Paul | 2ad5921 | 2002-10-30 20:24:45 +0000 | [diff] [blame] | 1796 | _mesa_sprintf(version, "%d.%d %s", |
| 1797 | SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1798 | |
| 1799 | (void) dpy; |
| 1800 | (void) screen; |
| 1801 | |
| 1802 | switch (name) { |
| 1803 | case GLX_EXTENSIONS: |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1804 | return get_extensions(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1805 | case GLX_VENDOR: |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 1806 | return VENDOR; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1807 | case GLX_VERSION: |
| 1808 | return version; |
| 1809 | default: |
| 1810 | return NULL; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | |
| 1816 | /* GLX 1.1 and later */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1817 | static const char * |
| 1818 | Fake_glXGetClientString( Display *dpy, int name ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1819 | { |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 1820 | static char version[1000]; |
Brian Paul | 2ad5921 | 2002-10-30 20:24:45 +0000 | [diff] [blame] | 1821 | _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, |
| 1822 | CLIENT_MINOR_VERSION, MESA_GLX_VERSION); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1823 | |
| 1824 | (void) dpy; |
| 1825 | |
| 1826 | switch (name) { |
| 1827 | case GLX_EXTENSIONS: |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 1828 | return get_extensions(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1829 | case GLX_VENDOR: |
Brian Paul | 78fc78e | 1999-11-22 22:17:06 +0000 | [diff] [blame] | 1830 | return VENDOR; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1831 | case GLX_VERSION: |
| 1832 | return version; |
| 1833 | default: |
| 1834 | return NULL; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | |
| 1839 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1840 | /* |
| 1841 | * GLX 1.3 and later |
| 1842 | */ |
| 1843 | |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1844 | |
Brian Paul | 5605798 | 2000-04-10 21:13:19 +0000 | [diff] [blame] | 1845 | static GLXFBConfig * |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1846 | Fake_glXChooseFBConfig( Display *dpy, int screen, |
| 1847 | const int *attribList, int *nitems ) |
| 1848 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1849 | XMesaVisual xmvis = choose_visual(dpy, screen, attribList); |
| 1850 | if (xmvis) { |
Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1851 | GLXFBConfig *config = _mesa_malloc(sizeof(XMesaVisual)); |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1852 | if (!config) { |
| 1853 | *nitems = 0; |
| 1854 | return NULL; |
| 1855 | } |
| 1856 | *nitems = 1; |
| 1857 | config[0] = (GLXFBConfig) xmvis; |
| 1858 | return (GLXFBConfig *) config; |
| 1859 | } |
| 1860 | else { |
| 1861 | *nitems = 0; |
| 1862 | return NULL; |
| 1863 | } |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | |
| 1867 | static int |
| 1868 | Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config, |
| 1869 | int attribute, int *value ) |
| 1870 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1871 | XMesaVisual v = (XMesaVisual) config; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1872 | (void) dpy; |
| 1873 | (void) config; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1874 | |
| 1875 | if (!dpy || !config || !value) |
| 1876 | return -1; |
| 1877 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1878 | return get_config(v, attribute, value, GL_TRUE); |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | |
Brian Paul | 5605798 | 2000-04-10 21:13:19 +0000 | [diff] [blame] | 1882 | static GLXFBConfig * |
| 1883 | Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements ) |
| 1884 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1885 | XVisualInfo *visuals, visTemplate; |
| 1886 | const long visMask = VisualScreenMask; |
| 1887 | int i; |
| 1888 | |
| 1889 | /* Get list of all X visuals */ |
| 1890 | visTemplate.screen = screen; |
| 1891 | visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements); |
| 1892 | if (*nelements > 0) { |
| 1893 | XMesaVisual *results; |
Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1894 | results = _mesa_malloc(*nelements * sizeof(XMesaVisual)); |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1895 | if (!results) { |
| 1896 | *nelements = 0; |
| 1897 | return NULL; |
| 1898 | } |
| 1899 | for (i = 0; i < *nelements; i++) { |
| 1900 | results[i] = create_glx_visual(dpy, visuals + i); |
| 1901 | } |
| 1902 | return (GLXFBConfig *) results; |
| 1903 | } |
| 1904 | return NULL; |
Brian Paul | 5605798 | 2000-04-10 21:13:19 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1908 | static XVisualInfo * |
| 1909 | Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config ) |
| 1910 | { |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1911 | if (dpy && config) { |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 1912 | XMesaVisual xmvis = (XMesaVisual) config; |
| 1913 | #if 0 |
| 1914 | return xmvis->vishandle; |
| 1915 | #else |
| 1916 | /* create a new vishandle - the cached one may be stale */ |
| 1917 | xmvis->vishandle = _mesa_malloc(sizeof(XVisualInfo)); |
| 1918 | if (xmvis->vishandle) { |
| 1919 | _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); |
| 1920 | } |
| 1921 | return xmvis->vishandle; |
| 1922 | #endif |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1923 | } |
| 1924 | else { |
| 1925 | return NULL; |
| 1926 | } |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | static GLXWindow |
| 1931 | Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win, |
| 1932 | const int *attribList ) |
| 1933 | { |
| 1934 | (void) dpy; |
| 1935 | (void) config; |
| 1936 | (void) win; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1937 | (void) attribList; /* Ignored in GLX 1.3 */ |
| 1938 | |
| 1939 | return win; /* A hack for now */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | |
| 1943 | static void |
| 1944 | Fake_glXDestroyWindow( Display *dpy, GLXWindow window ) |
| 1945 | { |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1946 | XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window); |
| 1947 | if (b) |
| 1948 | XMesaDestroyBuffer(b); |
| 1949 | /* don't destroy X window */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1953 | /* XXX untested */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1954 | static GLXPixmap |
| 1955 | Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap, |
| 1956 | const int *attribList ) |
| 1957 | { |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1958 | XMesaVisual v = (XMesaVisual) config; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1959 | XMesaBuffer b; |
| 1960 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1961 | (void) dpy; |
| 1962 | (void) config; |
| 1963 | (void) pixmap; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1964 | (void) attribList; /* Ignored in GLX 1.3 */ |
| 1965 | |
| 1966 | if (!dpy || !config || !pixmap) |
| 1967 | return 0; |
| 1968 | |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1969 | b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); |
| 1970 | if (!b) { |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
| 1974 | return pixmap; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | |
| 1978 | static void |
| 1979 | Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap ) |
| 1980 | { |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1981 | XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap); |
| 1982 | if (b) |
| 1983 | XMesaDestroyBuffer(b); |
| 1984 | /* don't destroy X pixmap */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | |
| 1988 | static GLXPbuffer |
| 1989 | Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config, |
| 1990 | const int *attribList ) |
| 1991 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 1992 | XMesaVisual xmvis = (XMesaVisual) config; |
| 1993 | XMesaBuffer xmbuf; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1994 | const int *attrib; |
| 1995 | int width = 0, height = 0; |
| 1996 | GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE; |
| 1997 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 1998 | (void) dpy; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 1999 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2000 | for (attrib = attribList; *attrib; attrib++) { |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2001 | switch (*attrib) { |
| 2002 | case GLX_PBUFFER_WIDTH: |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2003 | attrib++; |
| 2004 | width = *attrib; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | case GLX_PBUFFER_HEIGHT: |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2007 | attrib++; |
| 2008 | height = *attrib; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2009 | break; |
| 2010 | case GLX_PRESERVED_CONTENTS: |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2011 | attrib++; |
| 2012 | preserveContents = *attrib; /* ignored */ |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2013 | break; |
| 2014 | case GLX_LARGEST_PBUFFER: |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2015 | attrib++; |
| 2016 | useLargest = *attrib; /* ignored */ |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2017 | break; |
| 2018 | default: |
| 2019 | return 0; |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | if (width == 0 || height == 0) |
| 2024 | return 0; |
| 2025 | |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2026 | xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height); |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2027 | /* A GLXPbuffer handle must be an X Drawable because that's what |
| 2028 | * glXMakeCurrent takes. |
| 2029 | */ |
| 2030 | return (GLXPbuffer) xmbuf->frontbuffer; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | |
| 2034 | static void |
| 2035 | Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf ) |
| 2036 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2037 | XMesaBuffer b = XMesaFindBuffer(dpy, pbuf); |
| 2038 | if (b) { |
| 2039 | XMesaDestroyBuffer(b); |
| 2040 | } |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | |
| 2044 | static void |
| 2045 | Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, |
| 2046 | unsigned int *value ) |
| 2047 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2048 | XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw); |
| 2049 | if (!xmbuf) |
| 2050 | return; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2051 | |
| 2052 | switch (attribute) { |
| 2053 | case GLX_WIDTH: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2054 | *value = xmbuf->width; |
| 2055 | break; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2056 | case GLX_HEIGHT: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2057 | *value = xmbuf->height; |
| 2058 | break; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2059 | case GLX_PRESERVED_CONTENTS: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2060 | *value = True; |
| 2061 | break; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2062 | case GLX_LARGEST_PBUFFER: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2063 | *value = xmbuf->width * xmbuf->height; |
| 2064 | break; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2065 | case GLX_FBCONFIG_ID: |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 2066 | *value = xmbuf->xm_visual->visinfo->visualid; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2067 | return; |
| 2068 | default: |
| 2069 | return; /* GLX_BAD_ATTRIBUTE? */ |
| 2070 | } |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | |
| 2074 | static GLXContext |
| 2075 | Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config, |
| 2076 | int renderType, GLXContext shareList, Bool direct ) |
| 2077 | { |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 2078 | struct fake_glx_context *glxCtx; |
| 2079 | struct fake_glx_context *shareCtx = (struct fake_glx_context *) shareList; |
| 2080 | XMesaVisual xmvis = (XMesaVisual) config; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2081 | |
| 2082 | if (!dpy || !config || |
| 2083 | (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE)) |
| 2084 | return 0; |
| 2085 | |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 2086 | glxCtx = CALLOC_STRUCT(fake_glx_context); |
| 2087 | if (!glxCtx) |
| 2088 | return 0; |
| 2089 | |
| 2090 | /* deallocate unused windows/buffers */ |
| 2091 | XMesaGarbageCollect(); |
| 2092 | |
| 2093 | glxCtx->xmesaContext = XMesaCreateContext(xmvis, |
| 2094 | shareCtx ? shareCtx->xmesaContext : NULL); |
| 2095 | if (!glxCtx->xmesaContext) { |
| 2096 | FREE(glxCtx); |
| 2097 | return NULL; |
| 2098 | } |
| 2099 | |
| 2100 | glxCtx->xmesaContext->direct = GL_FALSE; |
| 2101 | glxCtx->glxContext.isDirect = GL_FALSE; |
| 2102 | glxCtx->glxContext.currentDpy = dpy; |
| 2103 | glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ |
| 2104 | |
| 2105 | assert((void *) glxCtx == (void *) &(glxCtx->glxContext)); |
| 2106 | |
| 2107 | return (GLXContext) glxCtx; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | |
| 2111 | static int |
| 2112 | Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value ) |
| 2113 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2114 | struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; |
| 2115 | XMesaContext xmctx = glxCtx->xmesaContext; |
| 2116 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2117 | (void) dpy; |
| 2118 | (void) ctx; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2119 | |
| 2120 | switch (attribute) { |
| 2121 | case GLX_FBCONFIG_ID: |
Brian Paul | f104619 | 2002-11-10 17:07:06 +0000 | [diff] [blame] | 2122 | *value = xmctx->xm_visual->visinfo->visualid; |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2123 | break; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2124 | case GLX_RENDER_TYPE: |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2125 | if (xmctx->xm_visual->mesa_visual.rgbMode) |
| 2126 | *value = GLX_RGBA_BIT; |
| 2127 | else |
| 2128 | *value = GLX_COLOR_INDEX_BIT; |
| 2129 | break; |
Brian Paul | 7d5656b | 2001-09-01 20:23:25 +0000 | [diff] [blame] | 2130 | case GLX_SCREEN: |
| 2131 | *value = 0; |
| 2132 | return Success; |
| 2133 | default: |
| 2134 | return GLX_BAD_ATTRIBUTE; |
| 2135 | } |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2136 | return 0; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | |
| 2140 | static void |
| 2141 | Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask ) |
| 2142 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2143 | XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); |
| 2144 | if (xmbuf) |
| 2145 | xmbuf->selectedEvents = mask; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | static void |
| 2150 | Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable, |
| 2151 | unsigned long *mask ) |
| 2152 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2153 | XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); |
| 2154 | if (xmbuf) |
| 2155 | *mask = xmbuf->selectedEvents; |
| 2156 | else |
| 2157 | *mask = 0; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2158 | } |
Brian Paul | b82d993 | 1999-11-22 21:52:23 +0000 | [diff] [blame] | 2159 | |
| 2160 | |
| 2161 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2162 | /*** GLX_SGI_swap_control ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2163 | |
| 2164 | static int |
| 2165 | Fake_glXSwapIntervalSGI(int interval) |
| 2166 | { |
| 2167 | (void) interval; |
| 2168 | return 0; |
| 2169 | } |
| 2170 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2171 | |
| 2172 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2173 | /*** GLX_SGI_video_sync ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2174 | |
| 2175 | static int |
| 2176 | Fake_glXGetVideoSyncSGI(unsigned int *count) |
| 2177 | { |
| 2178 | (void) count; |
| 2179 | return 0; |
| 2180 | } |
| 2181 | |
| 2182 | static int |
| 2183 | Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) |
| 2184 | { |
| 2185 | (void) divisor; |
| 2186 | (void) remainder; |
| 2187 | (void) count; |
| 2188 | return 0; |
| 2189 | } |
| 2190 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2191 | |
| 2192 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2193 | /*** GLX_SGI_make_current_read ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2194 | |
| 2195 | static Bool |
| 2196 | Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx) |
| 2197 | { |
Brian Paul | a078d75 | 2002-05-27 17:06:59 +0000 | [diff] [blame] | 2198 | return Fake_glXMakeContextCurrent( dpy, draw, read, ctx ); |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 2201 | /* not used |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2202 | static GLXDrawable |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2203 | Fake_glXGetCurrentReadDrawableSGI(void) |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2204 | { |
| 2205 | return 0; |
| 2206 | } |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 2207 | */ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2208 | |
| 2209 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2210 | /*** GLX_SGIX_video_source ***/ |
| 2211 | #if defined(_VL_H) |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2212 | |
| 2213 | static GLXVideoSourceSGIX |
| 2214 | Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode) |
| 2215 | { |
| 2216 | (void) dpy; |
| 2217 | (void) screen; |
| 2218 | (void) server; |
| 2219 | (void) path; |
| 2220 | (void) nodeClass; |
| 2221 | (void) drainNode; |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
| 2225 | static void |
| 2226 | Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src) |
| 2227 | { |
| 2228 | (void) dpy; |
| 2229 | (void) src; |
| 2230 | } |
| 2231 | |
| 2232 | #endif |
| 2233 | |
| 2234 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2235 | /*** GLX_EXT_import_context ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2236 | |
| 2237 | static void |
| 2238 | Fake_glXFreeContextEXT(Display *dpy, GLXContext context) |
| 2239 | { |
| 2240 | (void) dpy; |
| 2241 | (void) context; |
| 2242 | } |
| 2243 | |
| 2244 | static GLXContextID |
| 2245 | Fake_glXGetContextIDEXT(const GLXContext context) |
| 2246 | { |
| 2247 | (void) context; |
| 2248 | return 0; |
| 2249 | } |
| 2250 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2251 | static GLXContext |
| 2252 | Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID) |
| 2253 | { |
| 2254 | (void) dpy; |
| 2255 | (void) contextID; |
| 2256 | return 0; |
| 2257 | } |
| 2258 | |
| 2259 | static int |
| 2260 | Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value) |
| 2261 | { |
| 2262 | (void) dpy; |
| 2263 | (void) context; |
| 2264 | (void) attribute; |
| 2265 | (void) value; |
| 2266 | return 0; |
| 2267 | } |
| 2268 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2269 | |
| 2270 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2271 | /*** GLX_SGIX_fbconfig ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2272 | |
| 2273 | static int |
| 2274 | Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value) |
| 2275 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2276 | return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value); |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | static GLXFBConfigSGIX * |
| 2280 | Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements) |
| 2281 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2282 | return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements); |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2285 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2286 | static GLXPixmap |
| 2287 | Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap) |
| 2288 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2289 | XMesaVisual xmvis = (XMesaVisual) config; |
| 2290 | XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0); |
| 2291 | return xmbuf->frontbuffer; /* need to return an X ID */ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2294 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2295 | static GLXContext |
| 2296 | Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct) |
| 2297 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2298 | XMesaVisual xmvis = (XMesaVisual) config; |
| 2299 | struct fake_glx_context *glxCtx; |
| 2300 | struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list; |
| 2301 | |
| 2302 | glxCtx = CALLOC_STRUCT(fake_glx_context); |
| 2303 | if (!glxCtx) |
| 2304 | return 0; |
| 2305 | |
| 2306 | /* deallocate unused windows/buffers */ |
| 2307 | XMesaGarbageCollect(); |
| 2308 | |
| 2309 | glxCtx->xmesaContext = XMesaCreateContext(xmvis, |
| 2310 | shareCtx ? shareCtx->xmesaContext : NULL); |
| 2311 | if (!glxCtx->xmesaContext) { |
| 2312 | FREE(glxCtx); |
| 2313 | return NULL; |
| 2314 | } |
| 2315 | |
| 2316 | glxCtx->xmesaContext->direct = GL_FALSE; |
| 2317 | glxCtx->glxContext.isDirect = GL_FALSE; |
| 2318 | glxCtx->glxContext.currentDpy = dpy; |
| 2319 | glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ |
| 2320 | |
| 2321 | assert((void *) glxCtx == (void *) &(glxCtx->glxContext)); |
| 2322 | |
| 2323 | return (GLXContext) glxCtx; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2326 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2327 | static XVisualInfo * |
| 2328 | Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config) |
| 2329 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2330 | return Fake_glXGetVisualFromFBConfig(dpy, config); |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2333 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2334 | static GLXFBConfigSGIX |
| 2335 | Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis) |
| 2336 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2337 | XMesaVisual xmvis = find_glx_visual(dpy, vis); |
| 2338 | if (!xmvis) { |
| 2339 | /* This visual wasn't found with glXChooseVisual() */ |
| 2340 | xmvis = create_glx_visual(dpy, vis); |
| 2341 | } |
| 2342 | |
| 2343 | return (GLXFBConfigSGIX) xmvis; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2346 | |
| 2347 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2348 | /*** GLX_SGIX_pbuffer ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2349 | |
| 2350 | static GLXPbufferSGIX |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2351 | Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, |
| 2352 | unsigned int width, unsigned int height, |
| 2353 | int *attribList) |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2354 | { |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2355 | XMesaVisual xmvis = (XMesaVisual) config; |
| 2356 | XMesaBuffer xmbuf; |
| 2357 | const int *attrib; |
| 2358 | GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE; |
| 2359 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2360 | (void) dpy; |
Brian Paul | 3265fe5 | 2002-10-05 03:02:34 +0000 | [diff] [blame] | 2361 | |
| 2362 | for (attrib = attribList; *attrib; attrib++) { |
| 2363 | switch (*attrib) { |
| 2364 | case GLX_PRESERVED_CONTENTS_SGIX: |
| 2365 | attrib++; |
| 2366 | preserveContents = *attrib; /* ignored */ |
| 2367 | break; |
| 2368 | case GLX_LARGEST_PBUFFER_SGIX: |
| 2369 | attrib++; |
| 2370 | useLargest = *attrib; /* ignored */ |
| 2371 | break; |
| 2372 | default: |
| 2373 | return 0; |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height); |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2378 | /* A GLXPbuffer handle must be an X Drawable because that's what |
| 2379 | * glXMakeCurrent takes. |
| 2380 | */ |
| 2381 | return (GLXPbuffer) xmbuf->frontbuffer; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2384 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2385 | static void |
| 2386 | Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf) |
| 2387 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2388 | XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf); |
| 2389 | if (xmbuf) { |
| 2390 | XMesaDestroyBuffer(xmbuf); |
| 2391 | } |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2394 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2395 | static int |
| 2396 | Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value) |
| 2397 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2398 | const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf); |
| 2399 | |
| 2400 | if (!xmbuf) { |
| 2401 | /* Generate GLXBadPbufferSGIX for bad pbuffer */ |
| 2402 | return 0; |
| 2403 | } |
| 2404 | |
| 2405 | switch (attribute) { |
| 2406 | case GLX_PRESERVED_CONTENTS_SGIX: |
| 2407 | *value = True; |
| 2408 | break; |
| 2409 | case GLX_LARGEST_PBUFFER_SGIX: |
| 2410 | *value = xmbuf->width * xmbuf->height; |
| 2411 | break; |
| 2412 | case GLX_WIDTH_SGIX: |
| 2413 | *value = xmbuf->width; |
| 2414 | break; |
| 2415 | case GLX_HEIGHT_SGIX: |
| 2416 | *value = xmbuf->height; |
| 2417 | break; |
| 2418 | case GLX_EVENT_MASK_SGIX: |
| 2419 | *value = 0; /* XXX might be wrong */ |
| 2420 | break; |
| 2421 | default: |
| 2422 | *value = 0; |
| 2423 | } |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2424 | return 0; |
| 2425 | } |
| 2426 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2427 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2428 | static void |
| 2429 | Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask) |
| 2430 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2431 | XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); |
| 2432 | if (xmbuf) { |
| 2433 | /* Note: we'll never generate clobber events */ |
| 2434 | xmbuf->selectedEvents = mask; |
| 2435 | } |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2438 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2439 | static void |
| 2440 | Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask) |
| 2441 | { |
Brian Paul | e465600 | 2002-10-05 18:27:41 +0000 | [diff] [blame] | 2442 | XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); |
| 2443 | if (xmbuf) { |
| 2444 | *mask = xmbuf->selectedEvents; |
| 2445 | } |
| 2446 | else { |
| 2447 | *mask = 0; |
| 2448 | } |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2451 | |
| 2452 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2453 | /*** GLX_SGI_cushion ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2454 | |
| 2455 | static void |
| 2456 | Fake_glXCushionSGI(Display *dpy, Window win, float cushion) |
| 2457 | { |
| 2458 | (void) dpy; |
| 2459 | (void) win; |
| 2460 | (void) cushion; |
| 2461 | } |
| 2462 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2463 | |
| 2464 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2465 | /*** GLX_SGIX_video_resize ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2466 | |
| 2467 | static int |
| 2468 | Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window) |
| 2469 | { |
| 2470 | (void) dpy; |
| 2471 | (void) screen; |
| 2472 | (void) channel; |
| 2473 | (void) window; |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
| 2477 | static int |
| 2478 | Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h) |
| 2479 | { |
| 2480 | (void) dpy; |
| 2481 | (void) screen; |
| 2482 | (void) channel; |
| 2483 | (void) x; |
| 2484 | (void) y; |
| 2485 | (void) w; |
| 2486 | (void) h; |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
| 2490 | static int |
| 2491 | Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h) |
| 2492 | { |
| 2493 | (void) dpy; |
| 2494 | (void) screen; |
| 2495 | (void) channel; |
| 2496 | (void) x; |
| 2497 | (void) y; |
| 2498 | (void) w; |
| 2499 | (void) h; |
| 2500 | return 0; |
| 2501 | } |
| 2502 | |
| 2503 | static int |
| 2504 | Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh) |
| 2505 | { |
| 2506 | (void) dpy; |
| 2507 | (void) screen; |
| 2508 | (void) channel; |
| 2509 | (void) dx; |
| 2510 | (void) dy; |
| 2511 | (void) dw; |
| 2512 | (void) dh; |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
| 2516 | static int |
| 2517 | Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype) |
| 2518 | { |
| 2519 | (void) dpy; |
| 2520 | (void) screen; |
| 2521 | (void) channel; |
| 2522 | (void) synctype; |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2526 | |
| 2527 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2528 | /*** GLX_SGIX_dmbuffer **/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2529 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2530 | #if defined(_DM_BUFFER_H_) |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2531 | static Bool |
| 2532 | Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer) |
| 2533 | { |
| 2534 | (void) dpy; |
| 2535 | (void) pbuffer; |
| 2536 | (void) params; |
| 2537 | (void) dmbuffer; |
| 2538 | return False; |
| 2539 | } |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2540 | #endif |
| 2541 | |
| 2542 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2543 | /*** GLX_SGIX_swap_group ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2544 | |
| 2545 | static void |
| 2546 | Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member) |
| 2547 | { |
| 2548 | (void) dpy; |
| 2549 | (void) drawable; |
| 2550 | (void) member; |
| 2551 | } |
| 2552 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2553 | |
| 2554 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2555 | /*** GLX_SGIX_swap_barrier ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2556 | |
| 2557 | static void |
| 2558 | Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier) |
| 2559 | { |
| 2560 | (void) dpy; |
| 2561 | (void) drawable; |
| 2562 | (void) barrier; |
| 2563 | } |
| 2564 | |
| 2565 | static Bool |
| 2566 | Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max) |
| 2567 | { |
| 2568 | (void) dpy; |
| 2569 | (void) screen; |
| 2570 | (void) max; |
| 2571 | return False; |
| 2572 | } |
| 2573 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2574 | |
| 2575 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2576 | /*** GLX_SUN_get_transparent_index ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2577 | |
| 2578 | static Status |
| 2579 | Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent) |
| 2580 | { |
| 2581 | (void) dpy; |
| 2582 | (void) overlay; |
| 2583 | (void) underlay; |
| 2584 | (void) pTransparent; |
| 2585 | return 0; |
| 2586 | } |
| 2587 | |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2588 | |
| 2589 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2590 | /*** GLX_MESA_release_buffers ***/ |
| 2591 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2592 | /* |
| 2593 | * Release the depth, stencil, accum buffers attached to a GLXDrawable |
| 2594 | * (a window or pixmap) prior to destroying the GLXDrawable. |
| 2595 | */ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2596 | static Bool |
| 2597 | Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2598 | { |
| 2599 | XMesaBuffer b = XMesaFindBuffer(dpy, d); |
| 2600 | if (b) { |
| 2601 | XMesaDestroyBuffer(b); |
| 2602 | return True; |
| 2603 | } |
| 2604 | return False; |
| 2605 | } |
| 2606 | |
| 2607 | |
Brian Paul | 4c07bd5 | 2000-06-08 22:50:28 +0000 | [diff] [blame] | 2608 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2609 | /*** GLX_MESA_set_3dfx_mode ***/ |
| 2610 | |
Brian Paul | 4536021 | 2000-12-14 17:44:08 +0000 | [diff] [blame] | 2611 | static Bool |
| 2612 | Fake_glXSet3DfxModeMESA( int mode ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2613 | { |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 2614 | return XMesaSetFXmode( mode ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2615 | } |
Brian Paul | 4c07bd5 | 2000-06-08 22:50:28 +0000 | [diff] [blame] | 2616 | |
Brian Paul | 89a42b7 | 1999-09-11 11:33:45 +0000 | [diff] [blame] | 2617 | |
| 2618 | |
Brian Paul | 3c5bfac | 2003-01-14 04:49:07 +0000 | [diff] [blame^] | 2619 | /*** GLX_NV_vertex_array range ***/ |
Brian Paul | 8fefafa | 2002-08-22 21:10:01 +0000 | [diff] [blame] | 2620 | static void * |
| 2621 | Fake_glXAllocateMemoryNV( GLsizei size, |
| 2622 | GLfloat readFrequency, |
| 2623 | GLfloat writeFrequency, |
| 2624 | GLfloat priority ) |
| 2625 | { |
| 2626 | (void) size; |
| 2627 | (void) readFrequency; |
| 2628 | (void) writeFrequency; |
| 2629 | (void) priority; |
| 2630 | return NULL; |
| 2631 | } |
| 2632 | |
| 2633 | |
| 2634 | static void |
| 2635 | Fake_glXFreeMemoryNV( GLvoid *pointer ) |
| 2636 | { |
| 2637 | (void) pointer; |
| 2638 | } |
| 2639 | |
| 2640 | |
Brian Paul | 3c5bfac | 2003-01-14 04:49:07 +0000 | [diff] [blame^] | 2641 | /*** GLX_MESA_agp_offset ***/ |
Brian Paul | d6113fc | 2002-11-18 15:11:49 +0000 | [diff] [blame] | 2642 | |
| 2643 | static GLuint |
| 2644 | Fake_glXGetAGPOffsetMESA( const GLvoid *pointer ) |
| 2645 | { |
| 2646 | (void) pointer; |
| 2647 | return ~0; |
| 2648 | } |
| 2649 | |
| 2650 | |
Brian Paul | 3c5bfac | 2003-01-14 04:49:07 +0000 | [diff] [blame^] | 2651 | /*** GLX_ARB_render_texture ***/ |
| 2652 | |
| 2653 | static Bool |
| 2654 | Fake_glXBindTexImageARB( Display *dpy, GLXPbuffer pbuffer, int buffer ) |
| 2655 | { |
| 2656 | return False; |
| 2657 | } |
| 2658 | |
| 2659 | |
| 2660 | static Bool |
| 2661 | Fake_glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer ) |
| 2662 | { |
| 2663 | return False; |
| 2664 | } |
| 2665 | |
| 2666 | |
| 2667 | static Bool |
| 2668 | Fake_glXDrawableAttribARB( Display *dpy, GLXDrawable draw, const int *attribList ) |
| 2669 | { |
| 2670 | return False; |
| 2671 | } |
| 2672 | |
| 2673 | |
Brian Paul | 43c9c2c | 1999-09-16 15:52:51 +0000 | [diff] [blame] | 2674 | |
Brian Paul | e7b16b7 | 2000-03-17 15:33:09 +0000 | [diff] [blame] | 2675 | extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void); |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2676 | struct _glxapi_table *_mesa_GetGLXDispatchTable(void) |
| 2677 | { |
| 2678 | static struct _glxapi_table glx; |
| 2679 | |
| 2680 | /* be sure our dispatch table size <= libGL's table */ |
| 2681 | { |
Brian Paul | 01915e9 | 2001-03-08 15:23:46 +0000 | [diff] [blame] | 2682 | GLuint size = sizeof(struct _glxapi_table) / sizeof(void *); |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2683 | (void) size; |
| 2684 | assert(_glxapi_get_dispatch_table_size() >= size); |
| 2685 | } |
| 2686 | |
| 2687 | /* initialize the whole table to no-ops */ |
| 2688 | _glxapi_set_no_op_table(&glx); |
| 2689 | |
| 2690 | /* now initialize the table with the functions I implement */ |
| 2691 | glx.ChooseVisual = Fake_glXChooseVisual; |
| 2692 | glx.CopyContext = Fake_glXCopyContext; |
| 2693 | glx.CreateContext = Fake_glXCreateContext; |
| 2694 | glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap; |
| 2695 | glx.DestroyContext = Fake_glXDestroyContext; |
| 2696 | glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap; |
| 2697 | glx.GetConfig = Fake_glXGetConfig; |
| 2698 | /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/ |
| 2699 | /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/ |
| 2700 | glx.IsDirect = Fake_glXIsDirect; |
| 2701 | glx.MakeCurrent = Fake_glXMakeCurrent; |
| 2702 | glx.QueryExtension = Fake_glXQueryExtension; |
| 2703 | glx.QueryVersion = Fake_glXQueryVersion; |
| 2704 | glx.SwapBuffers = Fake_glXSwapBuffers; |
| 2705 | glx.UseXFont = Fake_glXUseXFont; |
| 2706 | glx.WaitGL = Fake_glXWaitGL; |
| 2707 | glx.WaitX = Fake_glXWaitX; |
| 2708 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2709 | /*** GLX_VERSION_1_1 ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2710 | glx.GetClientString = Fake_glXGetClientString; |
| 2711 | glx.QueryExtensionsString = Fake_glXQueryExtensionsString; |
| 2712 | glx.QueryServerString = Fake_glXQueryServerString; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2713 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2714 | /*** GLX_VERSION_1_2 ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2715 | /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2716 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2717 | /*** GLX_VERSION_1_3 ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2718 | glx.ChooseFBConfig = Fake_glXChooseFBConfig; |
| 2719 | glx.CreateNewContext = Fake_glXCreateNewContext; |
| 2720 | glx.CreatePbuffer = Fake_glXCreatePbuffer; |
| 2721 | glx.CreatePixmap = Fake_glXCreatePixmap; |
| 2722 | glx.CreateWindow = Fake_glXCreateWindow; |
| 2723 | glx.DestroyPbuffer = Fake_glXDestroyPbuffer; |
| 2724 | glx.DestroyPixmap = Fake_glXDestroyPixmap; |
| 2725 | glx.DestroyWindow = Fake_glXDestroyWindow; |
| 2726 | /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/ |
| 2727 | glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib; |
Brian Paul | 71dea34 | 2000-04-19 01:44:01 +0000 | [diff] [blame] | 2728 | glx.GetFBConfigs = Fake_glXGetFBConfigs; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2729 | glx.GetSelectedEvent = Fake_glXGetSelectedEvent; |
| 2730 | glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig; |
| 2731 | glx.MakeContextCurrent = Fake_glXMakeContextCurrent; |
| 2732 | glx.QueryContext = Fake_glXQueryContext; |
| 2733 | glx.QueryDrawable = Fake_glXQueryDrawable; |
| 2734 | glx.SelectEvent = Fake_glXSelectEvent; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2735 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2736 | /*** GLX_SGI_swap_control ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2737 | glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2738 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2739 | /*** GLX_SGI_video_sync ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2740 | glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI; |
| 2741 | glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2742 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2743 | /*** GLX_SGI_make_current_read ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2744 | glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI; |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 2745 | /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2746 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2747 | /*** GLX_SGIX_video_source ***/ |
| 2748 | #if defined(_VL_H) |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2749 | glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX; |
| 2750 | glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX; |
| 2751 | #endif |
| 2752 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2753 | /*** GLX_EXT_import_context ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2754 | glx.FreeContextEXT = Fake_glXFreeContextEXT; |
| 2755 | glx.GetContextIDEXT = Fake_glXGetContextIDEXT; |
Brian Paul | 7cf50e1 | 2001-05-24 19:06:21 +0000 | [diff] [blame] | 2756 | /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2757 | glx.ImportContextEXT = Fake_glXImportContextEXT; |
| 2758 | glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT; |
Brian Paul | 4536021 | 2000-12-14 17:44:08 +0000 | [diff] [blame] | 2759 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2760 | /*** GLX_SGIX_fbconfig ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2761 | glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX; |
| 2762 | glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX; |
| 2763 | glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX; |
| 2764 | glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX; |
| 2765 | glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX; |
| 2766 | glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2767 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2768 | /*** GLX_SGIX_pbuffer ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2769 | glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX; |
| 2770 | glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX; |
| 2771 | glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX; |
| 2772 | glx.SelectEventSGIX = Fake_glXSelectEventSGIX; |
| 2773 | glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2774 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2775 | /*** GLX_SGI_cushion ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2776 | glx.CushionSGI = Fake_glXCushionSGI; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2777 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2778 | /*** GLX_SGIX_video_resize ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2779 | glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX; |
| 2780 | glx.ChannelRectSGIX = Fake_glXChannelRectSGIX; |
| 2781 | glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX; |
| 2782 | glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX; |
| 2783 | glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2784 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2785 | /*** GLX_SGIX_dmbuffer **/ |
| 2786 | #if defined(_DM_BUFFER_H_) |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2787 | glx.AssociateDMPbufferSGIX = NULL; |
| 2788 | #endif |
| 2789 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2790 | /*** GLX_SGIX_swap_group ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2791 | glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2792 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2793 | /*** GLX_SGIX_swap_barrier ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2794 | glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX; |
| 2795 | glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX; |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2796 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2797 | /*** GLX_SUN_get_transparent_index ***/ |
Brian Paul | 783d7df | 2000-12-15 04:02:50 +0000 | [diff] [blame] | 2798 | glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN; |
Brian Paul | 4536021 | 2000-12-14 17:44:08 +0000 | [diff] [blame] | 2799 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2800 | /*** GLX_MESA_copy_sub_buffer ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2801 | glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2802 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2803 | /*** GLX_MESA_release_buffers ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2804 | glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2805 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2806 | /*** GLX_MESA_pixmap_colormap ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2807 | glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2808 | |
Brian Paul | b0bb4f6 | 2001-05-25 21:51:02 +0000 | [diff] [blame] | 2809 | /*** GLX_MESA_set_3dfx_mode ***/ |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2810 | glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA; |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2811 | |
Brian Paul | d6113fc | 2002-11-18 15:11:49 +0000 | [diff] [blame] | 2812 | /*** GLX_NV_vertex_array_range ***/ |
Brian Paul | 8fefafa | 2002-08-22 21:10:01 +0000 | [diff] [blame] | 2813 | glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV; |
| 2814 | glx.FreeMemoryNV = Fake_glXFreeMemoryNV; |
| 2815 | |
Brian Paul | d6113fc | 2002-11-18 15:11:49 +0000 | [diff] [blame] | 2816 | /*** GLX_MESA_agp_offset ***/ |
| 2817 | glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA; |
| 2818 | |
Brian Paul | 3c5bfac | 2003-01-14 04:49:07 +0000 | [diff] [blame^] | 2819 | /*** GLX_ARB_render_texture ***/ |
| 2820 | glx.BindTexImageARB = Fake_glXBindTexImageARB; |
| 2821 | glx.ReleaseTexImageARB = Fake_glXReleaseTexImageARB; |
| 2822 | glx.DrawableAttribARB = Fake_glXDrawableAttribARB; |
| 2823 | |
Brian Paul | 426cb9f | 1999-11-28 20:08:02 +0000 | [diff] [blame] | 2824 | return &glx; |
| 2825 | } |