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