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