blob: 480bc0a50678a20d072d50494441a73bf534f278 [file] [log] [blame]
Brian Paul3c5bfac2003-01-14 04:49:07 +00001/* $Id: fakeglx.c,v 1.78 2003/01/14 04:49:07 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul69e3c8b2002-11-14 16:14:50 +00005 * Version: 5.1
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Brian Paul8d687e72002-03-15 18:43:25 +00007 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00008 *
jtgafb833d1999-08-19 00:55:39 +00009 * 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 Jansen5e3bc0c2000-11-22 07:32:16 +000015 *
jtgafb833d1999-08-19 00:55:39 +000016 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000018 *
jtgafb833d1999-08-19 00:55:39 +000019 * 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
jtgafb833d1999-08-19 00:55:39 +000028/*
Brian Paul36cfa381999-11-28 20:15:04 +000029 * 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.
jtgafb833d1999-08-19 00:55:39 +000031 *
32 * Thanks to the contributors:
33 *
Brian Paulddf69f22000-08-02 20:35:09 +000034 * Initial version: Philip Brown (phil@bolthole.com)
jtgafb833d1999-08-19 00:55:39 +000035 * 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 Paulfbd8f211999-11-11 01:22:25 +000045#include "glxheader.h"
Brian Paul426cb9f1999-11-28 20:08:02 +000046#include "glxapi.h"
jtgafb833d1999-08-19 00:55:39 +000047#include "GL/xmesa.h"
48#include "context.h"
49#include "config.h"
jtgafb833d1999-08-19 00:55:39 +000050#include "macros.h"
Brian Paul3c634522002-10-24 23:57:19 +000051#include "imports.h"
Brian Paul71dea342000-04-19 01:44:01 +000052#include "mmath.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
Brian Paul71dea342000-04-19 01:44:01 +000054#include "xfonts.h"
jtgafb833d1999-08-19 00:55:39 +000055#include "xmesaP.h"
56
57
Brian Paul78fc78e1999-11-22 22:17:06 +000058/* This indicates the client-side GLX API and GLX encoder version. */
59#define CLIENT_MAJOR_VERSION 1
Brian Paula5738032001-09-23 16:10:02 +000060#define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
Brian Paul78fc78e1999-11-22 22:17:06 +000061
62/* This indicates the server-side GLX decoder version.
Brian Paulba57e522001-09-14 02:43:03 +000063 * GLX 1.4 indicates OpenGL 1.3 support
Brian Paul78fc78e1999-11-22 22:17:06 +000064 */
65#define SERVER_MAJOR_VERSION 1
Brian Paulba57e522001-09-14 02:43:03 +000066#define SERVER_MINOR_VERSION 4
Brian Paul78fc78e1999-11-22 22:17:06 +000067
68/* This is appended onto the glXGetClient/ServerString version strings. */
Brian Paul69e3c8b2002-11-14 16:14:50 +000069#define MESA_GLX_VERSION "Mesa 5.1"
Brian Paul78fc78e1999-11-22 22:17:06 +000070
71/* Who implemented this GLX? */
72#define VENDOR "Brian Paul"
73
Brian Paule4656002002-10-05 18:27:41 +000074#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 Paul3c5bfac2003-01-14 04:49:07 +000084 "GLX_SGIX_pbuffer" \
85 "GLX_ARB_render_texture"
Brian Paul78fc78e1999-11-22 22:17:06 +000086
jtgafb833d1999-08-19 00:55:39 +000087
Brian Paul43c9c2c1999-09-16 15:52:51 +000088/* Silence compiler warnings */
Brian Paule7b16b72000-03-17 15:33:09 +000089extern void Fake_glXDummyFunc( void );
Brian Paul43c9c2c1999-09-16 15:52:51 +000090void Fake_glXDummyFunc( void )
91{
92 (void) kernel8;
93 (void) DitherValues;
94 (void) HPCR_DRGB;
95 (void) kernel1;
96}
97
98
Brian Paul7cf50e12001-05-24 19:06:21 +000099/*
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 */
109struct fake_glx_context {
110 __GLXcontext glxContext; /* this MUST be first! */
111 XMesaContext xmesaContext;
112};
113
114
115
116/**********************************************************************/
117/*** GLX Visual Code ***/
118/**********************************************************************/
Brian Paul43c9c2c1999-09-16 15:52:51 +0000119
jtgafb833d1999-08-19 00:55:39 +0000120#define DONT_CARE -1
121
122
jtgafb833d1999-08-19 00:55:39 +0000123#define MAX_VISUALS 100
124static XMesaVisual VisualTable[MAX_VISUALS];
125static int NumVisuals = 0;
126
127
jtgafb833d1999-08-19 00:55:39 +0000128/*
129 * This struct and some code fragments borrowed
130 * from Mark Kilgard's GLUT library.
131 */
132typedef 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 */
158static 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 */
195static 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 */
259static XMesaVisual
260save_glx_visual( Display *dpy, XVisualInfo *vinfo,
261 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
262 GLboolean stereoFlag,
263 GLint depth_size, GLint stencil_size,
Brian Paulb2e46002000-03-31 01:07:13 +0000264 GLint accumRedSize, GLint accumGreenSize,
265 GLint accumBlueSize, GLint accumAlphaSize,
266 GLint level )
jtgafb833d1999-08-19 00:55:39 +0000267{
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 Paul367d3082002-10-25 21:06:26 +0000275 char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");
jtgafb833d1999-08-19 00:55:39 +0000276 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 Pauld09a1d82002-06-13 04:49:17 +0000284 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
jtgafb833d1999-08-19 00:55:39 +0000285 }
286 }
287 }
288
289 /* Comparing IDs uses less memory but sometimes fails. */
290 /* XXX revisit this after 3.0 is finished. */
Brian Paul367d3082002-10-25 21:06:26 +0000291 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
jtgafb833d1999-08-19 00:55:39 +0000292 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 Paul1832f1c2001-04-27 21:18:25 +0000302 && 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)) {
jtgafb833d1999-08-19 00:55:39 +0000312 /* now either compare XVisualInfo pointers or visual IDs */
Brian Pauld0247f51999-11-18 15:17:01 +0000313 if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
jtgafb833d1999-08-19 00:55:39 +0000314 || (comparePointers && v->vishandle == vinfo)) {
315 return v;
316 }
317 }
318 }
319
320 /* Create a new visual and add it to the list. */
321
Brian Pauld09a1d82002-06-13 04:49:17 +0000322 if (NumVisuals >= MAX_VISUALS) {
323 _mesa_problem(NULL, "GLX Error: maximum number of visuals exceeded");
jtgafb833d1999-08-19 00:55:39 +0000324 return NULL;
325 }
326
Brian Paulc8735e82000-04-05 22:09:58 +0000327 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 );
jtgafb833d1999-08-19 00:55:39 +0000333 if (xmvis) {
Brian Paulf1046192002-11-10 17:07:06 +0000334 /* 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 */
jtgafb833d1999-08-19 00:55:39 +0000339 VisualTable[NumVisuals] = xmvis;
340 NumVisuals++;
341 }
342 return xmvis;
343}
344
345
346
347/*
348 * Create a GLX visual from a regular XVisualInfo.
Brian Pauled30dfa2000-03-03 17:47:39 +0000349 * 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.
jtgafb833d1999-08-19 00:55:39 +0000354 */
355static XMesaVisual
356create_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 Paulb2e46002000-03-31 01:07:13 +0000370 0,0,0,0, /* accum bits */
jtgafb833d1999-08-19 00:55:39 +0000371 vislevel /* level */
372 );
373 }
374 else if (is_usable_visual( visinfo )) {
Brian Paul367d3082002-10-25 21:06:26 +0000375 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
Brian Paul8f9a5942001-02-17 00:17:31 +0000376 /* 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 }
jtgafb833d1999-08-19 00:55:39 +0000409 }
410 else {
Brian Pauld09a1d82002-06-13 04:49:17 +0000411 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
jtgafb833d1999-08-19 00:55:39 +0000412 return NULL;
413 }
414}
415
416
417
418/*
419 * Find the GLX visual associated with an XVisualInfo.
420 */
421static XMesaVisual
422find_glx_visual( Display *dpy, XVisualInfo *vinfo )
423{
424 int i;
425
jtgafb833d1999-08-19 00:55:39 +0000426 /* 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 Paulf1046192002-11-10 17:07:06 +0000433
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
jtgafb833d1999-08-19 00:55:39 +0000441 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 */
451static 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/*
jtgafb833d1999-08-19 00:55:39 +0000514 * Try to get an X visual which matches the given arguments.
515 */
516static 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 Paul71dea342000-04-19 01:44:01 +0000546 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
547 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
548 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
jtgafb833d1999-08-19 00:55:39 +0000549 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 */
570static 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 Paul367d3082002-10-25 21:06:26 +0000576 if (!_mesa_getenv( varname )) {
jtgafb833d1999-08-19 00:55:39 +0000577 return NULL;
578 }
579
Brian Paul367d3082002-10-25 21:06:26 +0000580 _mesa_strncpy( value, _mesa_getenv(varname), 100 );
jtgafb833d1999-08-19 00:55:39 +0000581 value[99] = 0;
582
583 sscanf( value, "%s %d", type, &depth );
584
Brian Paul367d3082002-10-25 21:06:26 +0000585 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;
jtgafb833d1999-08-19 00:55:39 +0000591
592 if (xclass>-1 && depth>0) {
593 vis = get_visual( dpy, scr, depth, xclass );
594 if (vis) {
595 return vis;
596 }
597 }
598
Brian Paul2ad59212002-10-30 20:24:45 +0000599 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
600 type, depth);
Brian Pauld09a1d82002-06-13 04:49:17 +0000601
jtgafb833d1999-08-19 00:55:39 +0000602 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 */
615static XVisualInfo *choose_x_visual( Display *dpy, int screen,
616 GLboolean rgba, int min_depth,
617 int preferred_class )
618{
619 XVisualInfo *vis;
Brian Pauldb6aa582000-11-10 17:23:02 +0000620 int xclass, visclass = 0;
jtgafb833d1999-08-19 00:55:39 +0000621 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 */
785static XVisualInfo *choose_x_overlay_visual( Display *dpy, int scr,
Brian Paul42f252f1999-10-14 18:47:37 +0000786 GLboolean rgbFlag,
jtgafb833d1999-08-19 00:55:39 +0000787 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 Paul42f252f1999-10-14 18:47:37 +0000878 /* 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
jtgafb833d1999-08-19 00:55:39 +0000888 if (deepvis==NULL || vislist->depth > deepest) {
889 /* YES! found a satisfactory visual */
890 if (deepvis) {
Brian Paul80af3611999-10-13 18:49:47 +0000891 XFree( deepvis );
jtgafb833d1999-08-19 00:55:39 +0000892 }
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 Paul7cf50e12001-05-24 19:06:21 +0000910/**********************************************************************/
911/*** Begin Fake GLX API Functions ***/
912/**********************************************************************/
913
jtgafb833d1999-08-19 00:55:39 +0000914
Brian Paul3265fe52002-10-05 03:02:34 +0000915static XMesaVisual choose_visual( Display *dpy, int screen, const int *list )
jtgafb833d1999-08-19 00:55:39 +0000916{
Brian Paul3265fe52002-10-05 03:02:34 +0000917 const int *parselist;
jtgafb833d1999-08-19 00:55:39 +0000918 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 Paulb2e46002000-03-31 01:07:13 +0000927 GLint accumRedSize = 0;
928 GLint accumGreenSize = 0;
929 GLint accumBlueSize = 0;
930 GLint accumAlphaSize = 0;
jtgafb833d1999-08-19 00:55:39 +0000931 int level = 0;
932 int visual_type = DONT_CARE;
933 int trans_type = DONT_CARE;
934 int trans_value = DONT_CARE;
Brian Paule1210b12000-03-31 01:17:52 +0000935 GLint caveat = DONT_CARE;
Brian Paul3265fe52002-10-05 03:02:34 +0000936 XMesaVisual xmvis = NULL;
jtgafb833d1999-08-19 00:55:39 +0000937
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 Paulb2e46002000-03-31 01:07:13 +0000999 parselist++;
1000 {
1001 GLint size = *parselist++;
1002 accumRedSize = MAX2( accumRedSize, size );
1003 }
1004 break;
jtgafb833d1999-08-19 00:55:39 +00001005 case GLX_ACCUM_GREEN_SIZE:
Brian Paulb2e46002000-03-31 01:07:13 +00001006 parselist++;
1007 {
1008 GLint size = *parselist++;
1009 accumGreenSize = MAX2( accumGreenSize, size );
1010 }
1011 break;
jtgafb833d1999-08-19 00:55:39 +00001012 case GLX_ACCUM_BLUE_SIZE:
Brian Paulb2e46002000-03-31 01:07:13 +00001013 parselist++;
1014 {
1015 GLint size = *parselist++;
1016 accumBlueSize = MAX2( accumBlueSize, size );
1017 }
1018 break;
jtgafb833d1999-08-19 00:55:39 +00001019 case GLX_ACCUM_ALPHA_SIZE:
1020 parselist++;
1021 {
1022 GLint size = *parselist++;
Brian Paulb2e46002000-03-31 01:07:13 +00001023 accumAlphaSize = MAX2( accumAlphaSize, size );
jtgafb833d1999-08-19 00:55:39 +00001024 }
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 Jansen5e3bc0c2000-11-22 07:32:16 +00001050
Brian Paule1210b12000-03-31 01:17:52 +00001051 /*
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 Paul3265fe52002-10-05 03:02:34 +00001059 /*
Brian Paul66ab7272002-11-05 21:11:18 +00001060 * 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 Paul3265fe52002-10-05 03:02:34 +00001070 * 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
jtgafb833d1999-08-19 00:55:39 +00001093 case None:
1094 break;
Brian Paul3265fe52002-10-05 03:02:34 +00001095
jtgafb833d1999-08-19 00:55:39 +00001096 default:
1097 /* undefined attribute */
Brian Paul2ad59212002-10-30 20:24:45 +00001098 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
1099 *parselist);
jtgafb833d1999-08-19 00:55:39 +00001100 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 Paulb2e46002000-03-31 01:07:13 +00001125 accumRedSize = accumGreenSize = accumBlueSize = accumAlphaSize = 0;
jtgafb833d1999-08-19 00:55:39 +00001126 }
1127 }
1128 else {
1129 /* over/underlay planes */
Brian Paul42f252f1999-10-14 18:47:37 +00001130 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 }
jtgafb833d1999-08-19 00:55:39 +00001145 }
1146
1147 if (vis) {
Brian Pauled30dfa2000-03-03 17:47:39 +00001148 /* 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 Paul2c7e6332000-10-05 17:38:21 +00001150 * largest depth buffer size, which is 32bits/value. Instead, we
Brian Pauled30dfa2000-03-03 17:47:39 +00001151 * return 16 to maintain performance with earlier versions of Mesa.
1152 */
Brian Paul2c7e6332000-10-05 17:38:21 +00001153 if (depth_size > 24)
1154 depth_size = 31; /* 32 causes int overflow problems */
Brian Pauled30dfa2000-03-03 17:47:39 +00001155 else if (depth_size > 16)
1156 depth_size = 24;
Brian Paul2c7e6332000-10-05 17:38:21 +00001157 else if (depth_size > 0)
1158 depth_size = DEFAULT_SOFTWARE_DEPTH_BITS; /*16*/
1159
Brian Pauled30dfa2000-03-03 17:47:39 +00001160 /* we only support one size of stencil and accum buffers. */
1161 if (stencil_size > 0)
1162 stencil_size = STENCIL_BITS;
Brian Paul6d62d7f2001-03-23 21:37:05 +00001163 if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 ||
1164 accumAlphaSize > 0) {
Brian Paulb2e46002000-03-31 01:07:13 +00001165 accumRedSize = ACCUM_BITS;
Brian Paulb2e46002000-03-31 01:07:13 +00001166 accumGreenSize = ACCUM_BITS;
Brian Paulb2e46002000-03-31 01:07:13 +00001167 accumBlueSize = ACCUM_BITS;
Brian Paul6d62d7f2001-03-23 21:37:05 +00001168 accumAlphaSize = alpha_flag ? ACCUM_BITS : 0;
1169 }
1170
Brian Paul3265fe52002-10-05 03:02:34 +00001171 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 );
jtgafb833d1999-08-19 00:55:39 +00001175 }
1176
Brian Paul3265fe52002-10-05 03:02:34 +00001177 return xmvis;
jtgafb833d1999-08-19 00:55:39 +00001178}
1179
1180
Brian Paul3265fe52002-10-05 03:02:34 +00001181static XVisualInfo *
1182Fake_glXChooseVisual( Display *dpy, int screen, int *list )
1183{
1184 XMesaVisual xmvis = choose_visual(dpy, screen, list);
Brian Paulf1046192002-11-10 17:07:06 +00001185 if (xmvis) {
1186#if 0
Brian Paul3265fe52002-10-05 03:02:34 +00001187 return xmvis->vishandle;
Brian Paulf1046192002-11-10 17:07:06 +00001188#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 Paul3265fe52002-10-05 03:02:34 +00001197 else
1198 return NULL;
1199}
jtgafb833d1999-08-19 00:55:39 +00001200
1201
Brian Paul426cb9f1999-11-28 20:08:02 +00001202static GLXContext
1203Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1204 GLXContext share_list, Bool direct )
jtgafb833d1999-08-19 00:55:39 +00001205{
Brian Paule4656002002-10-05 18:27:41 +00001206 XMesaVisual xmvis;
Brian Paul7cf50e12001-05-24 19:06:21 +00001207 struct fake_glx_context *glxCtx;
Brian Paul5e1680c2001-08-07 16:01:34 +00001208 struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
Brian Paul99aab342002-04-02 23:52:53 +00001209
1210 if (!dpy || !visinfo)
1211 return 0;
1212
Brian Paul7cf50e12001-05-24 19:06:21 +00001213 glxCtx = CALLOC_STRUCT(fake_glx_context);
1214 if (!glxCtx)
1215 return 0;
jtgafb833d1999-08-19 00:55:39 +00001216
1217 /* deallocate unused windows/buffers */
1218 XMesaGarbageCollect();
1219
Brian Paule4656002002-10-05 18:27:41 +00001220 xmvis = find_glx_visual( dpy, visinfo );
1221 if (!xmvis) {
jtgafb833d1999-08-19 00:55:39 +00001222 /* This visual wasn't found with glXChooseVisual() */
Brian Paule4656002002-10-05 18:27:41 +00001223 xmvis = create_glx_visual( dpy, visinfo );
1224 if (!xmvis) {
jtgafb833d1999-08-19 00:55:39 +00001225 /* unusable visual */
Brian Paul7cf50e12001-05-24 19:06:21 +00001226 FREE(glxCtx);
jtgafb833d1999-08-19 00:55:39 +00001227 return NULL;
1228 }
1229 }
1230
Brian Paule4656002002-10-05 18:27:41 +00001231 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
Brian Paul5e1680c2001-08-07 16:01:34 +00001232 shareCtx ? shareCtx->xmesaContext : NULL);
Brian Paul7cf50e12001-05-24 19:06:21 +00001233 if (!glxCtx->xmesaContext) {
1234 FREE(glxCtx);
1235 return NULL;
jtgafb833d1999-08-19 00:55:39 +00001236 }
Brian Paul7cf50e12001-05-24 19:06:21 +00001237
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;
jtgafb833d1999-08-19 00:55:39 +00001246}
1247
1248
Brian Paul7cf50e12001-05-24 19:06:21 +00001249/* XXX these may have to be removed due to thread-safety issues. */
jtgafb833d1999-08-19 00:55:39 +00001250static GLXContext MakeCurrent_PrevContext = 0;
Brian Paul086a1511999-11-25 17:37:49 +00001251static GLXDrawable MakeCurrent_PrevDrawable = 0;
1252static GLXDrawable MakeCurrent_PrevReadable = 0;
1253static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1254static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
jtgafb833d1999-08-19 00:55:39 +00001255
Brian Paul7cf50e12001-05-24 19:06:21 +00001256
Brian Paul086a1511999-11-25 17:37:49 +00001257/* GLX 1.3 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001258static Bool
1259Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001260 GLXDrawable read, GLXContext ctx )
Brian Paul086a1511999-11-25 17:37:49 +00001261{
Brian Paul7cf50e12001-05-24 19:06:21 +00001262 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1263
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001264 if (ctx && draw && read) {
Brian Paul086a1511999-11-25 17:37:49 +00001265 XMesaBuffer drawBuffer, readBuffer;
Brian Paul7cf50e12001-05-24 19:06:21 +00001266 XMesaContext xmctx = glxCtx->xmesaContext;
Brian Paul086a1511999-11-25 17:37:49 +00001267
1268 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001269 if (ctx == MakeCurrent_PrevContext
1270 && draw == MakeCurrent_PrevDrawable) {
Brian Paul086a1511999-11-25 17:37:49 +00001271 drawBuffer = MakeCurrent_PrevDrawBuffer;
1272 }
1273 else {
1274 drawBuffer = XMesaFindBuffer( dpy, draw );
1275 }
1276 if (!drawBuffer) {
1277 /* drawable must be a new window! */
Brian Paul7cf50e12001-05-24 19:06:21 +00001278 drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, xmctx);
Brian Paul086a1511999-11-25 17:37:49 +00001279 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 Whitwell7a1f3a32001-01-08 04:55:22 +00001286 if (ctx == MakeCurrent_PrevContext
Brian Paul086a1511999-11-25 17:37:49 +00001287 && 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 Paul7cf50e12001-05-24 19:06:21 +00001295 readBuffer = XMesaCreateWindowBuffer2(glxCtx->xmesaContext->xm_visual,
1296 read, xmctx);
Brian Paul086a1511999-11-25 17:37:49 +00001297 if (!readBuffer) {
1298 /* Out of memory, or context/drawable depth mismatch */
1299 return False;
1300 }
1301 }
1302
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001303 MakeCurrent_PrevContext = ctx;
Brian Paul086a1511999-11-25 17:37:49 +00001304 MakeCurrent_PrevDrawable = draw;
1305 MakeCurrent_PrevReadable = read;
1306 MakeCurrent_PrevDrawBuffer = drawBuffer;
1307 MakeCurrent_PrevReadBuffer = readBuffer;
1308
1309 /* Now make current! */
Brian Paul7cf50e12001-05-24 19:06:21 +00001310 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
Brian Paul12c1bee2001-05-24 20:05:32 +00001311 ((__GLXcontext *) ctx)->currentDpy = dpy;
1312 ((__GLXcontext *) ctx)->currentDrawable = draw;
Brian Paul8d687e72002-03-15 18:43:25 +00001313#ifndef GLX_BUILT_IN_XMESA
Brian Paul12c1bee2001-05-24 20:05:32 +00001314 ((__GLXcontext *) ctx)->currentReadable = read;
Brian Paul8d687e72002-03-15 18:43:25 +00001315#else
Brian Paul7cf50e12001-05-24 19:06:21 +00001316 __glXSetCurrentContext(ctx);
1317#endif
1318 return True;
1319 }
1320 else {
1321 return False;
1322 }
Brian Paul086a1511999-11-25 17:37:49 +00001323 }
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001324 else if (!ctx && !draw && !read) {
Brian Paul086a1511999-11-25 17:37:49 +00001325 /* 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 Paul84cac842001-05-29 23:15:07 +00001332#ifdef GLX_BUILT_IN_XMESA
Brian Paulb0bb4f62001-05-25 21:51:02 +00001333 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1334#endif
Brian Paul086a1511999-11-25 17:37:49 +00001335 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 Paul426cb9f1999-11-28 20:08:02 +00001346
1347static Bool
1348Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1349{
1350 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1351}
1352
1353
1354
Brian Paul426cb9f1999-11-28 20:08:02 +00001355static GLXPixmap
1356Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
jtgafb833d1999-08-19 00:55:39 +00001357{
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 Paulb0bb4f62001-05-25 21:51:02 +00001378/*** GLX_MESA_pixmap_colormap ***/
1379
Brian Paul426cb9f1999-11-28 20:08:02 +00001380static GLXPixmap
1381Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1382 Pixmap pixmap, Colormap cmap )
jtgafb833d1999-08-19 00:55:39 +00001383{
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}
jtgafb833d1999-08-19 00:55:39 +00001402
1403
Brian Paul426cb9f1999-11-28 20:08:02 +00001404static void
1405Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
jtgafb833d1999-08-19 00:55:39 +00001406{
1407 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1408 if (b) {
1409 XMesaDestroyBuffer(b);
1410 }
Brian Paul367d3082002-10-25 21:06:26 +00001411 else if (_mesa_getenv("MESA_DEBUG")) {
Brian Pauld09a1d82002-06-13 04:49:17 +00001412 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
jtgafb833d1999-08-19 00:55:39 +00001413 }
1414}
1415
1416
Brian Paul4c07bd52000-06-08 22:50:28 +00001417
Brian Paul426cb9f1999-11-28 20:08:02 +00001418static void
1419Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
Brian Paul3994b772000-02-27 18:26:54 +00001420 unsigned long mask )
jtgafb833d1999-08-19 00:55:39 +00001421{
Brian Paul83b820a2002-06-16 03:56:11 +00001422 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;
jtgafb833d1999-08-19 00:55:39 +00001426 (void) dpy;
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001427 _mesa_copy_context( xm_src->gl_ctx, xm_dst->gl_ctx, (GLuint) mask );
jtgafb833d1999-08-19 00:55:39 +00001428}
1429
1430
1431
Brian Paul426cb9f1999-11-28 20:08:02 +00001432static Bool
1433Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
jtgafb833d1999-08-19 00:55:39 +00001434{
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 Paule7b16b72000-03-17 15:33:09 +00001443extern void _kw_ungrab_all( Display *dpy );
jtgafb833d1999-08-19 00:55:39 +00001444void _kw_ungrab_all( Display *dpy )
1445{
1446 XUngrabPointer( dpy, CurrentTime );
1447 XUngrabKeyboard( dpy, CurrentTime );
1448}
1449
1450
Brian Paul426cb9f1999-11-28 20:08:02 +00001451static void
1452Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
jtgafb833d1999-08-19 00:55:39 +00001453{
Brian Paul7cf50e12001-05-24 19:06:21 +00001454 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
jtgafb833d1999-08-19 00:55:39 +00001455 (void) dpy;
1456 MakeCurrent_PrevContext = 0;
1457 MakeCurrent_PrevDrawable = 0;
Brian Paul086a1511999-11-25 17:37:49 +00001458 MakeCurrent_PrevReadable = 0;
1459 MakeCurrent_PrevDrawBuffer = 0;
1460 MakeCurrent_PrevReadBuffer = 0;
Brian Paul7cf50e12001-05-24 19:06:21 +00001461 XMesaDestroyContext( glxCtx->xmesaContext );
jtgafb833d1999-08-19 00:55:39 +00001462 XMesaGarbageCollect();
1463}
1464
1465
1466
Brian Paul426cb9f1999-11-28 20:08:02 +00001467static Bool
1468Fake_glXIsDirect( Display *dpy, GLXContext ctx )
jtgafb833d1999-08-19 00:55:39 +00001469{
Brian Paul7cf50e12001-05-24 19:06:21 +00001470 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
jtgafb833d1999-08-19 00:55:39 +00001471 (void) dpy;
Brian Paul7cf50e12001-05-24 19:06:21 +00001472 return glxCtx->xmesaContext->direct;
jtgafb833d1999-08-19 00:55:39 +00001473}
1474
1475
1476
Brian Paul426cb9f1999-11-28 20:08:02 +00001477static void
1478Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
jtgafb833d1999-08-19 00:55:39 +00001479{
1480 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
jtgafb833d1999-08-19 00:55:39 +00001481
jtgafb833d1999-08-19 00:55:39 +00001482 if (buffer) {
1483 XMesaSwapBuffers(buffer);
1484 }
Brian Paul367d3082002-10-25 21:06:26 +00001485 else if (_mesa_getenv("MESA_DEBUG")) {
Brian Pauld09a1d82002-06-13 04:49:17 +00001486 _mesa_warning(NULL, "Mesa: glXSwapBuffers: invalid drawable\n");
jtgafb833d1999-08-19 00:55:39 +00001487 }
1488}
1489
1490
Brian Paul4c07bd52000-06-08 22:50:28 +00001491
Brian Paulb0bb4f62001-05-25 21:51:02 +00001492/*** GLX_MESA_copy_sub_buffer ***/
1493
Brian Paul426cb9f1999-11-28 20:08:02 +00001494static void
1495Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1496 int x, int y, int width, int height )
jtgafb833d1999-08-19 00:55:39 +00001497{
1498 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1499 if (buffer) {
1500 XMesaCopySubBuffer(buffer, x, y, width, height);
1501 }
Brian Paul367d3082002-10-25 21:06:26 +00001502 else if (_mesa_getenv("MESA_DEBUG")) {
Brian Pauld09a1d82002-06-13 04:49:17 +00001503 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
jtgafb833d1999-08-19 00:55:39 +00001504 }
1505}
1506
1507
1508
Brian Paul426cb9f1999-11-28 20:08:02 +00001509static Bool
1510Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
jtgafb833d1999-08-19 00:55:39 +00001511{
1512 (void) dpy;
1513 /* Return GLX version, not Mesa version */
Brian Paul78fc78e1999-11-22 22:17:06 +00001514 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1515 *maj = CLIENT_MAJOR_VERSION;
1516 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
jtgafb833d1999-08-19 00:55:39 +00001517 return True;
1518}
1519
1520
1521
1522/*
1523 * Query the GLX attributes of the given XVisualInfo.
1524 */
Brian Paul426cb9f1999-11-28 20:08:02 +00001525static int
Brian Paule4656002002-10-05 18:27:41 +00001526get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
jtgafb833d1999-08-19 00:55:39 +00001527{
Brian Paule4656002002-10-05 18:27:41 +00001528 ASSERT(xmvis);
jtgafb833d1999-08-19 00:55:39 +00001529 switch(attrib) {
1530 case GLX_USE_GL:
1531 *value = (int) True;
1532 return 0;
1533 case GLX_BUFFER_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001534 *value = xmvis->visinfo->depth;
jtgafb833d1999-08-19 00:55:39 +00001535 return 0;
1536 case GLX_LEVEL:
Brian Paule4656002002-10-05 18:27:41 +00001537 *value = xmvis->level;
jtgafb833d1999-08-19 00:55:39 +00001538 return 0;
1539 case GLX_RGBA:
Brian Paule4656002002-10-05 18:27:41 +00001540 if (xmvis->mesa_visual.rgbMode) {
jtgafb833d1999-08-19 00:55:39 +00001541 *value = True;
1542 }
1543 else {
1544 *value = False;
1545 }
1546 return 0;
1547 case GLX_DOUBLEBUFFER:
Brian Paule4656002002-10-05 18:27:41 +00001548 *value = (int) xmvis->mesa_visual.doubleBufferMode;
jtgafb833d1999-08-19 00:55:39 +00001549 return 0;
1550 case GLX_STEREO:
Brian Paule4656002002-10-05 18:27:41 +00001551 *value = (int) xmvis->mesa_visual.stereoMode;
jtgafb833d1999-08-19 00:55:39 +00001552 return 0;
1553 case GLX_AUX_BUFFERS:
1554 *value = (int) False;
1555 return 0;
1556 case GLX_RED_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001557 *value = xmvis->mesa_visual.redBits;
jtgafb833d1999-08-19 00:55:39 +00001558 return 0;
1559 case GLX_GREEN_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001560 *value = xmvis->mesa_visual.greenBits;
jtgafb833d1999-08-19 00:55:39 +00001561 return 0;
1562 case GLX_BLUE_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001563 *value = xmvis->mesa_visual.blueBits;
jtgafb833d1999-08-19 00:55:39 +00001564 return 0;
1565 case GLX_ALPHA_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001566 *value = xmvis->mesa_visual.alphaBits;
jtgafb833d1999-08-19 00:55:39 +00001567 return 0;
1568 case GLX_DEPTH_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001569 *value = xmvis->mesa_visual.depthBits;
jtgafb833d1999-08-19 00:55:39 +00001570 return 0;
1571 case GLX_STENCIL_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001572 *value = xmvis->mesa_visual.stencilBits;
jtgafb833d1999-08-19 00:55:39 +00001573 return 0;
1574 case GLX_ACCUM_RED_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001575 *value = xmvis->mesa_visual.accumRedBits;
Brian Paulb2e46002000-03-31 01:07:13 +00001576 return 0;
jtgafb833d1999-08-19 00:55:39 +00001577 case GLX_ACCUM_GREEN_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001578 *value = xmvis->mesa_visual.accumGreenBits;
Brian Paulb2e46002000-03-31 01:07:13 +00001579 return 0;
jtgafb833d1999-08-19 00:55:39 +00001580 case GLX_ACCUM_BLUE_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001581 *value = xmvis->mesa_visual.accumBlueBits;
jtgafb833d1999-08-19 00:55:39 +00001582 return 0;
1583 case GLX_ACCUM_ALPHA_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001584 *value = xmvis->mesa_visual.accumAlphaBits;
jtgafb833d1999-08-19 00:55:39 +00001585 return 0;
1586
1587 /*
1588 * GLX_EXT_visual_info extension
1589 */
1590 case GLX_X_VISUAL_TYPE_EXT:
Brian Paule4656002002-10-05 18:27:41 +00001591 switch (xmvis->visinfo->CLASS) {
jtgafb833d1999-08-19 00:55:39 +00001592 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 Paule4656002002-10-05 18:27:41 +00001601 if (xmvis->level==0) {
jtgafb833d1999-08-19 00:55:39 +00001602 /* normal planes */
1603 *value = GLX_NONE_EXT;
1604 }
Brian Paule4656002002-10-05 18:27:41 +00001605 else if (xmvis->level>0) {
jtgafb833d1999-08-19 00:55:39 +00001606 /* overlay */
Brian Paule4656002002-10-05 18:27:41 +00001607 if (xmvis->mesa_visual.rgbMode) {
jtgafb833d1999-08-19 00:55:39 +00001608 *value = GLX_TRANSPARENT_RGB_EXT;
1609 }
1610 else {
1611 *value = GLX_TRANSPARENT_INDEX_EXT;
1612 }
1613 }
Brian Paule4656002002-10-05 18:27:41 +00001614 else if (xmvis->level<0) {
jtgafb833d1999-08-19 00:55:39 +00001615 /* underlay */
1616 *value = GLX_NONE_EXT;
1617 }
1618 return 0;
1619 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1620 {
Brian Paule4656002002-10-05 18:27:41 +00001621 int pixel = transparent_pixel( xmvis );
jtgafb833d1999-08-19 00:55:39 +00001622 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 Paulb2e46002000-03-31 01:07:13 +00001642 * GLX_EXT_visual_info extension
1643 */
1644 case GLX_VISUAL_CAVEAT_EXT:
Brian Paulfc68be62000-03-31 01:12:40 +00001645 /* test for zero, just in case */
Brian Paule4656002002-10-05 18:27:41 +00001646 if (xmvis->VisualCaveat > 0)
1647 *value = xmvis->VisualCaveat;
Brian Paul962f4262000-03-31 18:17:01 +00001648 else
1649 *value = GLX_NONE_EXT;
1650 return 0;
Brian Paulb2e46002000-03-31 01:07:13 +00001651
1652 /*
Brian Paul66ab7272002-11-05 21:11:18 +00001653 * GLX_ARB_multisample
jtgafb833d1999-08-19 00:55:39 +00001654 */
Brian Paul66ab7272002-11-05 21:11:18 +00001655 case GLX_SAMPLE_BUFFERS_ARB:
Brian Paul3265fe52002-10-05 03:02:34 +00001656 *value = 0;
1657 return 0;
Brian Paul66ab7272002-11-05 21:11:18 +00001658 case GLX_SAMPLES_ARB:
Brian Paul3265fe52002-10-05 03:02:34 +00001659 *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 Paule4656002002-10-05 18:27:41 +00001668 *value = xmvis->visinfo->screen;
Brian Paul3265fe52002-10-05 03:02:34 +00001669 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 Paule4656002002-10-05 18:27:41 +00001678 if (xmvis->mesa_visual.rgbMode)
Brian Paul3265fe52002-10-05 03:02:34 +00001679 *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 Paulf1046192002-11-10 17:07:06 +00001691 *value = xmvis->visinfo->visualid;
Brian Paul3265fe52002-10-05 03:02:34 +00001692 break;
1693 case GLX_MAX_PBUFFER_WIDTH:
1694 if (!fbconfig)
1695 return GLX_BAD_ATTRIBUTE;
1696 /* XXX or MAX_WIDTH? */
Brian Paulf1046192002-11-10 17:07:06 +00001697 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
Brian Paul3265fe52002-10-05 03:02:34 +00001698 break;
1699 case GLX_MAX_PBUFFER_HEIGHT:
1700 if (!fbconfig)
1701 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001702 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
Brian Paul3265fe52002-10-05 03:02:34 +00001703 break;
1704 case GLX_MAX_PBUFFER_PIXELS:
1705 if (!fbconfig)
1706 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001707 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1708 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
Brian Paul3265fe52002-10-05 03:02:34 +00001709 break;
1710 case GLX_VISUAL_ID:
1711 if (!fbconfig)
1712 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001713 *value = xmvis->visinfo->visualid;
Brian Paul3265fe52002-10-05 03:02:34 +00001714 break;
1715
jtgafb833d1999-08-19 00:55:39 +00001716 default:
1717 return GLX_BAD_ATTRIBUTE;
1718 }
Brian Paul3265fe52002-10-05 03:02:34 +00001719 return Success;
jtgafb833d1999-08-19 00:55:39 +00001720}
1721
1722
Brian Paul3265fe52002-10-05 03:02:34 +00001723static int
1724Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1725 int attrib, int *value )
1726{
Brian Paule4656002002-10-05 18:27:41 +00001727 XMesaVisual xmvis;
Brian Paul3265fe52002-10-05 03:02:34 +00001728
Brian Paule4656002002-10-05 18:27:41 +00001729 xmvis = find_glx_visual( dpy, visinfo );
1730 if (!xmvis) {
Brian Paul3265fe52002-10-05 03:02:34 +00001731 /* this visual wasn't obtained with glXChooseVisual */
Brian Paule4656002002-10-05 18:27:41 +00001732 xmvis = create_glx_visual( dpy, visinfo );
1733 if (!xmvis) {
Brian Paul3265fe52002-10-05 03:02:34 +00001734 /* 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 Paule4656002002-10-05 18:27:41 +00001745 return get_config(xmvis, attrib, value, GL_FALSE);
Brian Paul3265fe52002-10-05 03:02:34 +00001746}
1747
jtgafb833d1999-08-19 00:55:39 +00001748
Brian Paul426cb9f1999-11-28 20:08:02 +00001749static void
1750Fake_glXWaitGL( void )
jtgafb833d1999-08-19 00:55:39 +00001751{
1752 XMesaContext xmesa = XMesaGetCurrentContext();
1753 XMesaFlush( xmesa );
1754}
1755
1756
1757
Brian Paul426cb9f1999-11-28 20:08:02 +00001758static void
1759Fake_glXWaitX( void )
jtgafb833d1999-08-19 00:55:39 +00001760{
1761 XMesaContext xmesa = XMesaGetCurrentContext();
1762 XMesaFlush( xmesa );
1763}
1764
1765
Brian Paule4656002002-10-05 18:27:41 +00001766static const char *
1767get_extensions( void )
Brian Paul43c9c2c1999-09-16 15:52:51 +00001768{
1769#ifdef FX
Brian Paul367d3082002-10-25 21:06:26 +00001770 const char *fx = _mesa_getenv("MESA_GLX_FX");
Brian Paul43c9c2c1999-09-16 15:52:51 +00001771 if (fx && fx[0] != 'd') {
Brian Paule4656002002-10-05 18:27:41 +00001772 return EXTENSIONS;
Brian Paul43c9c2c1999-09-16 15:52:51 +00001773 }
1774#endif
Brian Paule4656002002-10-05 18:27:41 +00001775 return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */
Brian Paul43c9c2c1999-09-16 15:52:51 +00001776}
jtgafb833d1999-08-19 00:55:39 +00001777
jtgafb833d1999-08-19 00:55:39 +00001778
1779
1780/* GLX 1.1 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001781static const char *
1782Fake_glXQueryExtensionsString( Display *dpy, int screen )
jtgafb833d1999-08-19 00:55:39 +00001783{
jtgafb833d1999-08-19 00:55:39 +00001784 (void) dpy;
1785 (void) screen;
Brian Paul43c9c2c1999-09-16 15:52:51 +00001786 return get_extensions();
jtgafb833d1999-08-19 00:55:39 +00001787}
1788
1789
1790
1791/* GLX 1.1 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001792static const char *
1793Fake_glXQueryServerString( Display *dpy, int screen, int name )
jtgafb833d1999-08-19 00:55:39 +00001794{
Brian Paul78fc78e1999-11-22 22:17:06 +00001795 static char version[1000];
Brian Paul2ad59212002-10-30 20:24:45 +00001796 _mesa_sprintf(version, "%d.%d %s",
1797 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
jtgafb833d1999-08-19 00:55:39 +00001798
1799 (void) dpy;
1800 (void) screen;
1801
1802 switch (name) {
1803 case GLX_EXTENSIONS:
Brian Paul43c9c2c1999-09-16 15:52:51 +00001804 return get_extensions();
jtgafb833d1999-08-19 00:55:39 +00001805 case GLX_VENDOR:
Brian Paul78fc78e1999-11-22 22:17:06 +00001806 return VENDOR;
jtgafb833d1999-08-19 00:55:39 +00001807 case GLX_VERSION:
1808 return version;
1809 default:
1810 return NULL;
1811 }
1812}
1813
1814
1815
1816/* GLX 1.1 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001817static const char *
1818Fake_glXGetClientString( Display *dpy, int name )
jtgafb833d1999-08-19 00:55:39 +00001819{
Brian Paul78fc78e1999-11-22 22:17:06 +00001820 static char version[1000];
Brian Paul2ad59212002-10-30 20:24:45 +00001821 _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1822 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
jtgafb833d1999-08-19 00:55:39 +00001823
1824 (void) dpy;
1825
1826 switch (name) {
1827 case GLX_EXTENSIONS:
Brian Paul43c9c2c1999-09-16 15:52:51 +00001828 return get_extensions();
jtgafb833d1999-08-19 00:55:39 +00001829 case GLX_VENDOR:
Brian Paul78fc78e1999-11-22 22:17:06 +00001830 return VENDOR;
jtgafb833d1999-08-19 00:55:39 +00001831 case GLX_VERSION:
1832 return version;
1833 default:
1834 return NULL;
1835 }
1836}
1837
1838
1839
Brian Paul426cb9f1999-11-28 20:08:02 +00001840/*
1841 * GLX 1.3 and later
1842 */
1843
Brian Paul7d5656b2001-09-01 20:23:25 +00001844
Brian Paul56057982000-04-10 21:13:19 +00001845static GLXFBConfig *
Brian Paul426cb9f1999-11-28 20:08:02 +00001846Fake_glXChooseFBConfig( Display *dpy, int screen,
1847 const int *attribList, int *nitems )
1848{
Brian Paul3265fe52002-10-05 03:02:34 +00001849 XMesaVisual xmvis = choose_visual(dpy, screen, attribList);
1850 if (xmvis) {
Brian Paul3c634522002-10-24 23:57:19 +00001851 GLXFBConfig *config = _mesa_malloc(sizeof(XMesaVisual));
Brian Paul3265fe52002-10-05 03:02:34 +00001852 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 Paul426cb9f1999-11-28 20:08:02 +00001864}
1865
1866
1867static int
1868Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1869 int attribute, int *value )
1870{
Brian Paul3265fe52002-10-05 03:02:34 +00001871 XMesaVisual v = (XMesaVisual) config;
Brian Paul426cb9f1999-11-28 20:08:02 +00001872 (void) dpy;
1873 (void) config;
Brian Paul7d5656b2001-09-01 20:23:25 +00001874
1875 if (!dpy || !config || !value)
1876 return -1;
1877
Brian Paul3265fe52002-10-05 03:02:34 +00001878 return get_config(v, attribute, value, GL_TRUE);
Brian Paul426cb9f1999-11-28 20:08:02 +00001879}
1880
1881
Brian Paul56057982000-04-10 21:13:19 +00001882static GLXFBConfig *
1883Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1884{
Brian Paul3265fe52002-10-05 03:02:34 +00001885 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 Paul3c634522002-10-24 23:57:19 +00001894 results = _mesa_malloc(*nelements * sizeof(XMesaVisual));
Brian Paul3265fe52002-10-05 03:02:34 +00001895 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 Paul56057982000-04-10 21:13:19 +00001905}
1906
1907
Brian Paul426cb9f1999-11-28 20:08:02 +00001908static XVisualInfo *
1909Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1910{
Brian Paul7d5656b2001-09-01 20:23:25 +00001911 if (dpy && config) {
Brian Paulf1046192002-11-10 17:07:06 +00001912 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 Paul7d5656b2001-09-01 20:23:25 +00001923 }
1924 else {
1925 return NULL;
1926 }
Brian Paul426cb9f1999-11-28 20:08:02 +00001927}
1928
1929
1930static GLXWindow
1931Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1932 const int *attribList )
1933{
1934 (void) dpy;
1935 (void) config;
1936 (void) win;
Brian Paul7d5656b2001-09-01 20:23:25 +00001937 (void) attribList; /* Ignored in GLX 1.3 */
1938
1939 return win; /* A hack for now */
Brian Paul426cb9f1999-11-28 20:08:02 +00001940}
1941
1942
1943static void
1944Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1945{
Brian Paul7d5656b2001-09-01 20:23:25 +00001946 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
1947 if (b)
1948 XMesaDestroyBuffer(b);
1949 /* don't destroy X window */
Brian Paul426cb9f1999-11-28 20:08:02 +00001950}
1951
1952
Brian Paul7d5656b2001-09-01 20:23:25 +00001953/* XXX untested */
Brian Paul426cb9f1999-11-28 20:08:02 +00001954static GLXPixmap
1955Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1956 const int *attribList )
1957{
Brian Paul7d5656b2001-09-01 20:23:25 +00001958 XMesaVisual v = (XMesaVisual) config;
Brian Paul7d5656b2001-09-01 20:23:25 +00001959 XMesaBuffer b;
1960
Brian Paul426cb9f1999-11-28 20:08:02 +00001961 (void) dpy;
1962 (void) config;
1963 (void) pixmap;
Brian Paul7d5656b2001-09-01 20:23:25 +00001964 (void) attribList; /* Ignored in GLX 1.3 */
1965
1966 if (!dpy || !config || !pixmap)
1967 return 0;
1968
Brian Paul7d5656b2001-09-01 20:23:25 +00001969 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1970 if (!b) {
1971 return 0;
1972 }
1973
1974 return pixmap;
Brian Paul426cb9f1999-11-28 20:08:02 +00001975}
1976
1977
1978static void
1979Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
1980{
Brian Paul7d5656b2001-09-01 20:23:25 +00001981 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
1982 if (b)
1983 XMesaDestroyBuffer(b);
1984 /* don't destroy X pixmap */
Brian Paul426cb9f1999-11-28 20:08:02 +00001985}
1986
1987
1988static GLXPbuffer
1989Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
1990 const int *attribList )
1991{
Brian Paul3265fe52002-10-05 03:02:34 +00001992 XMesaVisual xmvis = (XMesaVisual) config;
1993 XMesaBuffer xmbuf;
Brian Paul7d5656b2001-09-01 20:23:25 +00001994 const int *attrib;
1995 int width = 0, height = 0;
1996 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
1997
Brian Paul426cb9f1999-11-28 20:08:02 +00001998 (void) dpy;
Brian Paul7d5656b2001-09-01 20:23:25 +00001999
Brian Paul3265fe52002-10-05 03:02:34 +00002000 for (attrib = attribList; *attrib; attrib++) {
Brian Paul7d5656b2001-09-01 20:23:25 +00002001 switch (*attrib) {
2002 case GLX_PBUFFER_WIDTH:
Brian Paul3265fe52002-10-05 03:02:34 +00002003 attrib++;
2004 width = *attrib;
Brian Paul7d5656b2001-09-01 20:23:25 +00002005 break;
2006 case GLX_PBUFFER_HEIGHT:
Brian Paul3265fe52002-10-05 03:02:34 +00002007 attrib++;
2008 height = *attrib;
Brian Paul7d5656b2001-09-01 20:23:25 +00002009 break;
2010 case GLX_PRESERVED_CONTENTS:
Brian Paul3265fe52002-10-05 03:02:34 +00002011 attrib++;
2012 preserveContents = *attrib; /* ignored */
Brian Paul7d5656b2001-09-01 20:23:25 +00002013 break;
2014 case GLX_LARGEST_PBUFFER:
Brian Paul3265fe52002-10-05 03:02:34 +00002015 attrib++;
2016 useLargest = *attrib; /* ignored */
Brian Paul7d5656b2001-09-01 20:23:25 +00002017 break;
2018 default:
2019 return 0;
2020 }
2021 }
2022
2023 if (width == 0 || height == 0)
2024 return 0;
2025
Brian Paul3265fe52002-10-05 03:02:34 +00002026 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
Brian Paule4656002002-10-05 18:27:41 +00002027 /* A GLXPbuffer handle must be an X Drawable because that's what
2028 * glXMakeCurrent takes.
2029 */
2030 return (GLXPbuffer) xmbuf->frontbuffer;
Brian Paul426cb9f1999-11-28 20:08:02 +00002031}
2032
2033
2034static void
2035Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2036{
Brian Paule4656002002-10-05 18:27:41 +00002037 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2038 if (b) {
2039 XMesaDestroyBuffer(b);
2040 }
Brian Paul426cb9f1999-11-28 20:08:02 +00002041}
2042
2043
2044static void
2045Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2046 unsigned int *value )
2047{
Brian Paule4656002002-10-05 18:27:41 +00002048 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2049 if (!xmbuf)
2050 return;
Brian Paul7d5656b2001-09-01 20:23:25 +00002051
2052 switch (attribute) {
2053 case GLX_WIDTH:
Brian Paule4656002002-10-05 18:27:41 +00002054 *value = xmbuf->width;
2055 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002056 case GLX_HEIGHT:
Brian Paule4656002002-10-05 18:27:41 +00002057 *value = xmbuf->height;
2058 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002059 case GLX_PRESERVED_CONTENTS:
Brian Paule4656002002-10-05 18:27:41 +00002060 *value = True;
2061 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002062 case GLX_LARGEST_PBUFFER:
Brian Paule4656002002-10-05 18:27:41 +00002063 *value = xmbuf->width * xmbuf->height;
2064 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002065 case GLX_FBCONFIG_ID:
Brian Paulf1046192002-11-10 17:07:06 +00002066 *value = xmbuf->xm_visual->visinfo->visualid;
Brian Paul7d5656b2001-09-01 20:23:25 +00002067 return;
2068 default:
2069 return; /* GLX_BAD_ATTRIBUTE? */
2070 }
Brian Paul426cb9f1999-11-28 20:08:02 +00002071}
2072
2073
2074static GLXContext
2075Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2076 int renderType, GLXContext shareList, Bool direct )
2077{
Brian Paulf1046192002-11-10 17:07:06 +00002078 struct fake_glx_context *glxCtx;
2079 struct fake_glx_context *shareCtx = (struct fake_glx_context *) shareList;
2080 XMesaVisual xmvis = (XMesaVisual) config;
Brian Paul7d5656b2001-09-01 20:23:25 +00002081
2082 if (!dpy || !config ||
2083 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2084 return 0;
2085
Brian Paulf1046192002-11-10 17:07:06 +00002086 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 Paul426cb9f1999-11-28 20:08:02 +00002108}
2109
2110
2111static int
2112Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2113{
Brian Paule4656002002-10-05 18:27:41 +00002114 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
2115 XMesaContext xmctx = glxCtx->xmesaContext;
2116
Brian Paul426cb9f1999-11-28 20:08:02 +00002117 (void) dpy;
2118 (void) ctx;
Brian Paul7d5656b2001-09-01 20:23:25 +00002119
2120 switch (attribute) {
2121 case GLX_FBCONFIG_ID:
Brian Paulf1046192002-11-10 17:07:06 +00002122 *value = xmctx->xm_visual->visinfo->visualid;
Brian Paule4656002002-10-05 18:27:41 +00002123 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002124 case GLX_RENDER_TYPE:
Brian Paule4656002002-10-05 18:27:41 +00002125 if (xmctx->xm_visual->mesa_visual.rgbMode)
2126 *value = GLX_RGBA_BIT;
2127 else
2128 *value = GLX_COLOR_INDEX_BIT;
2129 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002130 case GLX_SCREEN:
2131 *value = 0;
2132 return Success;
2133 default:
2134 return GLX_BAD_ATTRIBUTE;
2135 }
Brian Paule4656002002-10-05 18:27:41 +00002136 return 0;
Brian Paul426cb9f1999-11-28 20:08:02 +00002137}
2138
2139
2140static void
2141Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2142{
Brian Paule4656002002-10-05 18:27:41 +00002143 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2144 if (xmbuf)
2145 xmbuf->selectedEvents = mask;
Brian Paul426cb9f1999-11-28 20:08:02 +00002146}
2147
2148
2149static void
2150Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2151 unsigned long *mask )
2152{
Brian Paule4656002002-10-05 18:27:41 +00002153 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2154 if (xmbuf)
2155 *mask = xmbuf->selectedEvents;
2156 else
2157 *mask = 0;
Brian Paul426cb9f1999-11-28 20:08:02 +00002158}
Brian Paulb82d9931999-11-22 21:52:23 +00002159
2160
2161
Brian Paulb0bb4f62001-05-25 21:51:02 +00002162/*** GLX_SGI_swap_control ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002163
2164static int
2165Fake_glXSwapIntervalSGI(int interval)
2166{
2167 (void) interval;
2168 return 0;
2169}
2170
Brian Paul783d7df2000-12-15 04:02:50 +00002171
2172
Brian Paulb0bb4f62001-05-25 21:51:02 +00002173/*** GLX_SGI_video_sync ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002174
2175static int
2176Fake_glXGetVideoSyncSGI(unsigned int *count)
2177{
2178 (void) count;
2179 return 0;
2180}
2181
2182static int
2183Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2184{
2185 (void) divisor;
2186 (void) remainder;
2187 (void) count;
2188 return 0;
2189}
2190
Brian Paul783d7df2000-12-15 04:02:50 +00002191
2192
Brian Paulb0bb4f62001-05-25 21:51:02 +00002193/*** GLX_SGI_make_current_read ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002194
2195static Bool
2196Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2197{
Brian Paula078d752002-05-27 17:06:59 +00002198 return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
Brian Paul783d7df2000-12-15 04:02:50 +00002199}
2200
Brian Paul7cf50e12001-05-24 19:06:21 +00002201/* not used
Brian Paul783d7df2000-12-15 04:02:50 +00002202static GLXDrawable
Brian Paulb0bb4f62001-05-25 21:51:02 +00002203Fake_glXGetCurrentReadDrawableSGI(void)
Brian Paul783d7df2000-12-15 04:02:50 +00002204{
2205 return 0;
2206}
Brian Paul7cf50e12001-05-24 19:06:21 +00002207*/
Brian Paul783d7df2000-12-15 04:02:50 +00002208
2209
Brian Paulb0bb4f62001-05-25 21:51:02 +00002210/*** GLX_SGIX_video_source ***/
2211#if defined(_VL_H)
Brian Paul783d7df2000-12-15 04:02:50 +00002212
2213static GLXVideoSourceSGIX
2214Fake_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
2225static void
2226Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2227{
2228 (void) dpy;
2229 (void) src;
2230}
2231
2232#endif
2233
2234
Brian Paulb0bb4f62001-05-25 21:51:02 +00002235/*** GLX_EXT_import_context ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002236
2237static void
2238Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2239{
2240 (void) dpy;
2241 (void) context;
2242}
2243
2244static GLXContextID
2245Fake_glXGetContextIDEXT(const GLXContext context)
2246{
2247 (void) context;
2248 return 0;
2249}
2250
Brian Paul783d7df2000-12-15 04:02:50 +00002251static GLXContext
2252Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2253{
2254 (void) dpy;
2255 (void) contextID;
2256 return 0;
2257}
2258
2259static int
2260Fake_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 Paul783d7df2000-12-15 04:02:50 +00002269
2270
Brian Paulb0bb4f62001-05-25 21:51:02 +00002271/*** GLX_SGIX_fbconfig ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002272
2273static int
2274Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2275{
Brian Paul3265fe52002-10-05 03:02:34 +00002276 return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
Brian Paul783d7df2000-12-15 04:02:50 +00002277}
2278
2279static GLXFBConfigSGIX *
2280Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2281{
Brian Paul3265fe52002-10-05 03:02:34 +00002282 return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
Brian Paul783d7df2000-12-15 04:02:50 +00002283}
2284
Brian Paule4656002002-10-05 18:27:41 +00002285
Brian Paul783d7df2000-12-15 04:02:50 +00002286static GLXPixmap
2287Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2288{
Brian Paule4656002002-10-05 18:27:41 +00002289 XMesaVisual xmvis = (XMesaVisual) config;
2290 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2291 return xmbuf->frontbuffer; /* need to return an X ID */
Brian Paul783d7df2000-12-15 04:02:50 +00002292}
2293
Brian Paule4656002002-10-05 18:27:41 +00002294
Brian Paul783d7df2000-12-15 04:02:50 +00002295static GLXContext
2296Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2297{
Brian Paule4656002002-10-05 18:27:41 +00002298 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 Paul783d7df2000-12-15 04:02:50 +00002324}
2325
Brian Paule4656002002-10-05 18:27:41 +00002326
Brian Paul783d7df2000-12-15 04:02:50 +00002327static XVisualInfo *
2328Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2329{
Brian Paul3265fe52002-10-05 03:02:34 +00002330 return Fake_glXGetVisualFromFBConfig(dpy, config);
Brian Paul783d7df2000-12-15 04:02:50 +00002331}
2332
Brian Paule4656002002-10-05 18:27:41 +00002333
Brian Paul783d7df2000-12-15 04:02:50 +00002334static GLXFBConfigSGIX
2335Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2336{
Brian Paule4656002002-10-05 18:27:41 +00002337 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 Paul783d7df2000-12-15 04:02:50 +00002344}
2345
Brian Paul783d7df2000-12-15 04:02:50 +00002346
2347
Brian Paulb0bb4f62001-05-25 21:51:02 +00002348/*** GLX_SGIX_pbuffer ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002349
2350static GLXPbufferSGIX
Brian Paul3265fe52002-10-05 03:02:34 +00002351Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2352 unsigned int width, unsigned int height,
2353 int *attribList)
Brian Paul783d7df2000-12-15 04:02:50 +00002354{
Brian Paul3265fe52002-10-05 03:02:34 +00002355 XMesaVisual xmvis = (XMesaVisual) config;
2356 XMesaBuffer xmbuf;
2357 const int *attrib;
2358 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2359
Brian Paul783d7df2000-12-15 04:02:50 +00002360 (void) dpy;
Brian Paul3265fe52002-10-05 03:02:34 +00002361
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 Paule4656002002-10-05 18:27:41 +00002378 /* A GLXPbuffer handle must be an X Drawable because that's what
2379 * glXMakeCurrent takes.
2380 */
2381 return (GLXPbuffer) xmbuf->frontbuffer;
Brian Paul783d7df2000-12-15 04:02:50 +00002382}
2383
Brian Paule4656002002-10-05 18:27:41 +00002384
Brian Paul783d7df2000-12-15 04:02:50 +00002385static void
2386Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2387{
Brian Paule4656002002-10-05 18:27:41 +00002388 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2389 if (xmbuf) {
2390 XMesaDestroyBuffer(xmbuf);
2391 }
Brian Paul783d7df2000-12-15 04:02:50 +00002392}
2393
Brian Paule4656002002-10-05 18:27:41 +00002394
Brian Paul783d7df2000-12-15 04:02:50 +00002395static int
2396Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2397{
Brian Paule4656002002-10-05 18:27:41 +00002398 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 Paul783d7df2000-12-15 04:02:50 +00002424 return 0;
2425}
2426
Brian Paule4656002002-10-05 18:27:41 +00002427
Brian Paul783d7df2000-12-15 04:02:50 +00002428static void
2429Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2430{
Brian Paule4656002002-10-05 18:27:41 +00002431 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2432 if (xmbuf) {
2433 /* Note: we'll never generate clobber events */
2434 xmbuf->selectedEvents = mask;
2435 }
Brian Paul783d7df2000-12-15 04:02:50 +00002436}
2437
Brian Paule4656002002-10-05 18:27:41 +00002438
Brian Paul783d7df2000-12-15 04:02:50 +00002439static void
2440Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2441{
Brian Paule4656002002-10-05 18:27:41 +00002442 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2443 if (xmbuf) {
2444 *mask = xmbuf->selectedEvents;
2445 }
2446 else {
2447 *mask = 0;
2448 }
Brian Paul783d7df2000-12-15 04:02:50 +00002449}
2450
Brian Paul783d7df2000-12-15 04:02:50 +00002451
2452
Brian Paulb0bb4f62001-05-25 21:51:02 +00002453/*** GLX_SGI_cushion ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002454
2455static void
2456Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2457{
2458 (void) dpy;
2459 (void) win;
2460 (void) cushion;
2461}
2462
Brian Paul783d7df2000-12-15 04:02:50 +00002463
2464
Brian Paulb0bb4f62001-05-25 21:51:02 +00002465/*** GLX_SGIX_video_resize ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002466
2467static int
2468Fake_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
2477static int
2478Fake_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
2490static int
2491Fake_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
2503static int
2504Fake_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
2516static int
2517Fake_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 Paul783d7df2000-12-15 04:02:50 +00002526
2527
Brian Paulb0bb4f62001-05-25 21:51:02 +00002528/*** GLX_SGIX_dmbuffer **/
Brian Paul783d7df2000-12-15 04:02:50 +00002529
Brian Paulb0bb4f62001-05-25 21:51:02 +00002530#if defined(_DM_BUFFER_H_)
Brian Paul783d7df2000-12-15 04:02:50 +00002531static Bool
2532Fake_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 Paul783d7df2000-12-15 04:02:50 +00002540#endif
2541
2542
Brian Paulb0bb4f62001-05-25 21:51:02 +00002543/*** GLX_SGIX_swap_group ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002544
2545static void
2546Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2547{
2548 (void) dpy;
2549 (void) drawable;
2550 (void) member;
2551}
2552
Brian Paul783d7df2000-12-15 04:02:50 +00002553
2554
Brian Paulb0bb4f62001-05-25 21:51:02 +00002555/*** GLX_SGIX_swap_barrier ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002556
2557static void
2558Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2559{
2560 (void) dpy;
2561 (void) drawable;
2562 (void) barrier;
2563}
2564
2565static Bool
2566Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2567{
2568 (void) dpy;
2569 (void) screen;
2570 (void) max;
2571 return False;
2572}
2573
Brian Paul783d7df2000-12-15 04:02:50 +00002574
2575
Brian Paulb0bb4f62001-05-25 21:51:02 +00002576/*** GLX_SUN_get_transparent_index ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002577
2578static Status
2579Fake_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 Paul783d7df2000-12-15 04:02:50 +00002588
2589
Brian Paulb0bb4f62001-05-25 21:51:02 +00002590/*** GLX_MESA_release_buffers ***/
2591
jtgafb833d1999-08-19 00:55:39 +00002592/*
2593 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2594 * (a window or pixmap) prior to destroying the GLXDrawable.
2595 */
Brian Paul426cb9f1999-11-28 20:08:02 +00002596static Bool
2597Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
jtgafb833d1999-08-19 00:55:39 +00002598{
2599 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2600 if (b) {
2601 XMesaDestroyBuffer(b);
2602 return True;
2603 }
2604 return False;
2605}
2606
2607
Brian Paul4c07bd52000-06-08 22:50:28 +00002608
Brian Paulb0bb4f62001-05-25 21:51:02 +00002609/*** GLX_MESA_set_3dfx_mode ***/
2610
Brian Paul45360212000-12-14 17:44:08 +00002611static Bool
2612Fake_glXSet3DfxModeMESA( int mode )
jtgafb833d1999-08-19 00:55:39 +00002613{
Brian Paul43c9c2c1999-09-16 15:52:51 +00002614 return XMesaSetFXmode( mode );
jtgafb833d1999-08-19 00:55:39 +00002615}
Brian Paul4c07bd52000-06-08 22:50:28 +00002616
Brian Paul89a42b71999-09-11 11:33:45 +00002617
2618
Brian Paul3c5bfac2003-01-14 04:49:07 +00002619/*** GLX_NV_vertex_array range ***/
Brian Paul8fefafa2002-08-22 21:10:01 +00002620static void *
2621Fake_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
2634static void
2635Fake_glXFreeMemoryNV( GLvoid *pointer )
2636{
2637 (void) pointer;
2638}
2639
2640
Brian Paul3c5bfac2003-01-14 04:49:07 +00002641/*** GLX_MESA_agp_offset ***/
Brian Pauld6113fc2002-11-18 15:11:49 +00002642
2643static GLuint
2644Fake_glXGetAGPOffsetMESA( const GLvoid *pointer )
2645{
2646 (void) pointer;
2647 return ~0;
2648}
2649
2650
Brian Paul3c5bfac2003-01-14 04:49:07 +00002651/*** GLX_ARB_render_texture ***/
2652
2653static Bool
2654Fake_glXBindTexImageARB( Display *dpy, GLXPbuffer pbuffer, int buffer )
2655{
2656 return False;
2657}
2658
2659
2660static Bool
2661Fake_glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer )
2662{
2663 return False;
2664}
2665
2666
2667static Bool
2668Fake_glXDrawableAttribARB( Display *dpy, GLXDrawable draw, const int *attribList )
2669{
2670 return False;
2671}
2672
2673
Brian Paul43c9c2c1999-09-16 15:52:51 +00002674
Brian Paule7b16b72000-03-17 15:33:09 +00002675extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
Brian Paul426cb9f1999-11-28 20:08:02 +00002676struct _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 Paul01915e92001-03-08 15:23:46 +00002682 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
Brian Paul426cb9f1999-11-28 20:08:02 +00002683 (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 Paulb0bb4f62001-05-25 21:51:02 +00002709 /*** GLX_VERSION_1_1 ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002710 glx.GetClientString = Fake_glXGetClientString;
2711 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2712 glx.QueryServerString = Fake_glXQueryServerString;
Brian Paul426cb9f1999-11-28 20:08:02 +00002713
Brian Paulb0bb4f62001-05-25 21:51:02 +00002714 /*** GLX_VERSION_1_2 ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002715 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
Brian Paul426cb9f1999-11-28 20:08:02 +00002716
Brian Paulb0bb4f62001-05-25 21:51:02 +00002717 /*** GLX_VERSION_1_3 ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002718 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 Paul71dea342000-04-19 01:44:01 +00002728 glx.GetFBConfigs = Fake_glXGetFBConfigs;
Brian Paul426cb9f1999-11-28 20:08:02 +00002729 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 Paul426cb9f1999-11-28 20:08:02 +00002735
Brian Paulb0bb4f62001-05-25 21:51:02 +00002736 /*** GLX_SGI_swap_control ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002737 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
Brian Paul783d7df2000-12-15 04:02:50 +00002738
Brian Paulb0bb4f62001-05-25 21:51:02 +00002739 /*** GLX_SGI_video_sync ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002740 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2741 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
Brian Paul426cb9f1999-11-28 20:08:02 +00002742
Brian Paulb0bb4f62001-05-25 21:51:02 +00002743 /*** GLX_SGI_make_current_read ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002744 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
Brian Paul7cf50e12001-05-24 19:06:21 +00002745 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
Brian Paul783d7df2000-12-15 04:02:50 +00002746
Brian Paulb0bb4f62001-05-25 21:51:02 +00002747/*** GLX_SGIX_video_source ***/
2748#if defined(_VL_H)
Brian Paul783d7df2000-12-15 04:02:50 +00002749 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2750 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2751#endif
2752
Brian Paulb0bb4f62001-05-25 21:51:02 +00002753 /*** GLX_EXT_import_context ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002754 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2755 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
Brian Paul7cf50e12001-05-24 19:06:21 +00002756 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
Brian Paul783d7df2000-12-15 04:02:50 +00002757 glx.ImportContextEXT = Fake_glXImportContextEXT;
2758 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
Brian Paul45360212000-12-14 17:44:08 +00002759
Brian Paulb0bb4f62001-05-25 21:51:02 +00002760 /*** GLX_SGIX_fbconfig ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002761 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 Paul783d7df2000-12-15 04:02:50 +00002767
Brian Paulb0bb4f62001-05-25 21:51:02 +00002768 /*** GLX_SGIX_pbuffer ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002769 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 Paul783d7df2000-12-15 04:02:50 +00002774
Brian Paulb0bb4f62001-05-25 21:51:02 +00002775 /*** GLX_SGI_cushion ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002776 glx.CushionSGI = Fake_glXCushionSGI;
Brian Paul783d7df2000-12-15 04:02:50 +00002777
Brian Paulb0bb4f62001-05-25 21:51:02 +00002778 /*** GLX_SGIX_video_resize ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002779 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 Paul783d7df2000-12-15 04:02:50 +00002784
Brian Paulb0bb4f62001-05-25 21:51:02 +00002785 /*** GLX_SGIX_dmbuffer **/
2786#if defined(_DM_BUFFER_H_)
Brian Paul783d7df2000-12-15 04:02:50 +00002787 glx.AssociateDMPbufferSGIX = NULL;
2788#endif
2789
Brian Paulb0bb4f62001-05-25 21:51:02 +00002790 /*** GLX_SGIX_swap_group ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002791 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002792
Brian Paulb0bb4f62001-05-25 21:51:02 +00002793 /*** GLX_SGIX_swap_barrier ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002794 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2795 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002796
Brian Paulb0bb4f62001-05-25 21:51:02 +00002797 /*** GLX_SUN_get_transparent_index ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002798 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
Brian Paul45360212000-12-14 17:44:08 +00002799
Brian Paulb0bb4f62001-05-25 21:51:02 +00002800 /*** GLX_MESA_copy_sub_buffer ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002801 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002802
Brian Paulb0bb4f62001-05-25 21:51:02 +00002803 /*** GLX_MESA_release_buffers ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002804 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002805
Brian Paulb0bb4f62001-05-25 21:51:02 +00002806 /*** GLX_MESA_pixmap_colormap ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002807 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002808
Brian Paulb0bb4f62001-05-25 21:51:02 +00002809 /*** GLX_MESA_set_3dfx_mode ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002810 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002811
Brian Pauld6113fc2002-11-18 15:11:49 +00002812 /*** GLX_NV_vertex_array_range ***/
Brian Paul8fefafa2002-08-22 21:10:01 +00002813 glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
2814 glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
2815
Brian Pauld6113fc2002-11-18 15:11:49 +00002816 /*** GLX_MESA_agp_offset ***/
2817 glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
2818
Brian Paul3c5bfac2003-01-14 04:49:07 +00002819 /*** GLX_ARB_render_texture ***/
2820 glx.BindTexImageARB = Fake_glXBindTexImageARB;
2821 glx.ReleaseTexImageARB = Fake_glXReleaseTexImageARB;
2822 glx.DrawableAttribARB = Fake_glXDrawableAttribARB;
2823
Brian Paul426cb9f1999-11-28 20:08:02 +00002824 return &glx;
2825}