2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
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.
31 * Thanks to the contributors:
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).
39 * Don't be fooled, stereo isn't supported yet.
44 #include "glxheader.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"
56 #define sprintf sprintf
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 */
63 /* This indicates the server-side GLX decoder version.
64 * GLX 1.4 indicates OpenGL 1.3 support
66 #define SERVER_MAJOR_VERSION 1
67 #define SERVER_MINOR_VERSION 4
69 /* This is appended onto the glXGetClient/ServerString version strings. */
70 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
72 /* Who implemented this GLX? */
73 #define VENDOR "Brian Paul"
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 " \
89 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
91 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
94 * We really just need this structure in order to make the libGL functions
95 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
98 struct fake_glx_context
{
99 __GLXcontext glxContext
; /* this MUST be first! */
100 XMesaContext xmesaContext
;
105 /**********************************************************************/
106 /*** GLX Visual Code ***/
107 /**********************************************************************/
112 static XMesaVisual
*VisualTable
= NULL
;
113 static int NumVisuals
= 0;
117 * This struct and some code fragments borrowed
118 * from Mark Kilgard's GLUT library.
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
125 unsigned long overlay_visual
;
126 long transparent_type
;
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
143 * Test if the given XVisualInfo is usable for Mesa rendering.
146 is_usable_visual( XVisualInfo
*vinfo
)
148 switch (vinfo
->CLASS
) {
151 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
155 /* Color-index rendering is not supported. */
159 /* Any depth of TrueColor or DirectColor works in RGB mode */
162 /* This should never happen */
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()
177 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
179 Atom overlayVisualsAtom
;
182 unsigned char *ovInfo
;
183 unsigned long sizeData
, bytesLeft
;
187 * The SERVER_OVERLAY_VISUALS property on the root window contains
188 * a list of overlay visuals. Get that list now.
190 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
191 if (overlayVisualsAtom
== None
) {
195 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
196 overlayVisualsAtom
, 0L, (long) 10000, False
,
197 overlayVisualsAtom
, &actualType
, &actualFormat
,
198 &sizeData
, &bytesLeft
,
201 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
202 actualFormat
!= 32 || sizeData
< 4) {
203 /* something went wrong */
204 free((void *) ovInfo
);
209 *numOverlays
= sizeData
/ 4;
210 return (OverlayInfo
*) ovInfo
;
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:
221 * >0 = overlay planes
222 * <0 = underlay planes
225 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
227 OverlayInfo
*overlay_info
;
228 int numOverlaysPerScreen
, i
;
230 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
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
);
246 free((void *) overlay_info
);
252 /* The visual ID was not found in the overlay list. */
253 free((void *) overlay_info
);
261 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
262 * configuration in our list of GLX visuals.
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
)
273 GLboolean ximageFlag
= GL_TRUE
;
276 GLboolean comparePointers
;
279 /* Check if the MESA_BACK_BUFFER env var is set */
280 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
282 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
283 ximageFlag
= GL_FALSE
;
285 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
286 ximageFlag
= GL_TRUE
;
289 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
295 /* stereo not supported */
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
;
304 comparePointers
= GL_FALSE
;
306 /* Force the visual to have an alpha channel */
307 if (_mesa_getenv("MESA_GLX_FORCE_ALPHA"))
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
)) {
334 /* Create a new visual and add it to the list. */
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
,
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().
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
;
354 /* XXX minor hack, because XMesaCreateVisual doesn't support an
355 * aux buffers parameter.
357 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
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.
370 default_depth_bits(void)
373 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
377 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
382 default_alpha_bits(void)
385 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
394 default_accum_bits(void)
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.
410 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
413 GLint zBits
= default_depth_bits();
414 GLint accBits
= default_accum_bits();
415 GLboolean alphaFlag
= default_alpha_bits() > 0;
417 vislevel
= level_of_visual( dpy
, visinfo
);
419 /* Color-index rendering to overlays is not supported. */
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 */
431 8, /* stencil bits */
441 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
449 * Find the GLX visual associated with an XVisualInfo.
452 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
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
];
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
];
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
482 transparent_pixel( XMesaVisual glxvis
)
484 Display
*dpy
= glxvis
->display
;
485 XVisualInfo
*vinfo
= glxvis
->visinfo
;
486 OverlayInfo
*overlay_info
;
487 int numOverlaysPerScreen
, i
;
489 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
494 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
495 const OverlayInfo
*ov
= overlay_info
+ i
;
496 if (ov
->overlay_visual
== vinfo
->visualid
) {
498 if (ov
->transparent_type
== 0) {
499 /* type 0 indicates no transparency */
500 free((void *) overlay_info
);
504 /* ov->value is the transparent pixel */
505 free((void *) overlay_info
);
511 /* The visual ID was not found in the overlay list. */
512 free((void *) overlay_info
);
519 * Try to get an X visual which matches the given arguments.
522 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
524 XVisualInfo temp
, *vis
;
527 unsigned int default_depth
;
530 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
535 default_depth
= DefaultDepth(dpy
,scr
);
536 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
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
;
544 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
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.
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) {
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.
576 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
578 char value
[100], type
[100];
579 int depth
, xclass
= -1;
582 if (!_mesa_getenv( varname
)) {
586 strncpy( value
, _mesa_getenv(varname
), 100 );
589 sscanf( value
, "%s %d", type
, &depth
);
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
;
596 if (xclass
>-1 && depth
>0) {
597 vis
= get_visual( dpy
, scr
, depth
, xclass
);
603 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
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.
619 choose_x_visual(Display
*dpy
, int screen
, int min_depth
, int preferred_class
)
622 int xclass
, visclass
= 0;
625 /* First see if the MESA_RGB_VISUAL env var is defined */
626 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
630 /* Otherwise, search for a suitable visual */
631 if (preferred_class
==DONT_CARE
) {
632 for (xclass
=0;xclass
<4;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;
640 /* start with shallowest */
641 for (depth
=0;depth
<=32;depth
++) {
642 vis
= get_visual( dpy
, screen
, depth
, visclass
);
649 /* start with deepest */
650 for (depth
=32;depth
>=min_depth
;depth
--) {
651 vis
= get_visual( dpy
, screen
, depth
, visclass
);
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
;
671 /* start with shallowest */
672 for (depth
=0;depth
<=32;depth
++) {
673 vis
= get_visual( dpy
, screen
, depth
, visclass
);
680 /* start with deepest */
681 for (depth
=32;depth
>=min_depth
;depth
--) {
682 vis
= get_visual( dpy
, screen
, depth
, visclass
);
690 /* didn't find a visual */
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,
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.
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
)
713 OverlayInfo
*overlay_info
;
714 int numOverlaysPerScreen
;
716 XVisualInfo
*deepvis
;
719 /*DEBUG int tt, tv; */
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
;
731 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
736 /* Search for the deepest overlay which satisifies all criteria. */
740 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
741 const OverlayInfo
*ov
= overlay_info
+ i
;
742 XVisualInfo
*vislist
, vistemplate
;
745 if (ov
->layer
!=level
) {
746 /* failed overlay level criteria */
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 */
756 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
757 /* failed transparent pixel value criteria */
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
);
768 /* something went wrong */
771 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
772 /* wrong visual class */
776 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
777 if (vislist
->CLASS
!= TrueColor
&& vislist
->CLASS
!= DirectColor
)
780 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
781 /* YES! found a satisfactory visual */
785 deepest
= vislist
->depth
;
787 /* DEBUG tt = ov->transparent_type;*/
788 /* DEBUG tv = ov->value; */
794 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
795 deepvis->visualid, level, deepvis->depth, tt, tv );
802 /**********************************************************************/
803 /*** Display-related functions ***/
804 /**********************************************************************/
808 * Free all XMesaVisuals which are associated with the given display.
811 destroy_visuals_on_display(Display
*dpy
)
814 for (i
= 0; i
< NumVisuals
; i
++) {
815 if (VisualTable
[i
]->display
== dpy
) {
816 /* remove this visual */
818 free(VisualTable
[i
]);
819 for (j
= i
; j
< NumVisuals
- 1; j
++)
820 VisualTable
[j
] = VisualTable
[j
+ 1];
828 * Called from XCloseDisplay() to let us free our display-related data.
831 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
833 destroy_visuals_on_display(dpy
);
834 xmesa_destroy_buffers_on_display(dpy
);
840 * Look for the named extension on given display and return a pointer
841 * to the _XExtension data, or NULL if extension not found.
844 lookup_extension(Display
*dpy
, const char *extName
)
847 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
848 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
857 * Whenever we're given a new Display pointer, call this function to
858 * register our close_display_callback function.
861 register_with_display(Display
*dpy
)
863 const char *extName
= "MesaGLX";
866 ext
= lookup_extension(dpy
, extName
);
868 XExtCodes
*c
= XAddExtension(dpy
);
869 ext
= dpy
->ext_procs
; /* new extension is at head of list */
870 assert(c
->extension
== ext
->codes
.extension
);
871 (void) c
; /* silence warning */
872 ext
->name
= _mesa_strdup(extName
);
873 ext
->close_display
= close_display_callback
;
878 /**********************************************************************/
879 /*** Begin Fake GLX API Functions ***/
880 /**********************************************************************/
884 * Helper used by glXChooseVisual and glXChooseFBConfig.
885 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
887 * In either case, the attribute list is terminated with the value 'None'.
890 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
892 const GLboolean rgbModeDefault
= fbConfig
;
893 const int *parselist
;
896 int min_red
=0, min_green
=0, min_blue
=0;
897 GLboolean rgb_flag
= rgbModeDefault
;
898 GLboolean alpha_flag
= GL_FALSE
;
899 GLboolean double_flag
= GL_FALSE
;
900 GLboolean stereo_flag
= GL_FALSE
;
901 GLint depth_size
= 0;
902 GLint stencil_size
= 0;
903 GLint accumRedSize
= 0;
904 GLint accumGreenSize
= 0;
905 GLint accumBlueSize
= 0;
906 GLint accumAlphaSize
= 0;
908 int visual_type
= DONT_CARE
;
909 int trans_type
= DONT_CARE
;
910 int trans_value
= DONT_CARE
;
911 GLint caveat
= DONT_CARE
;
912 XMesaVisual xmvis
= NULL
;
913 int desiredVisualID
= -1;
920 switch (*parselist
) {
931 case GLX_BUFFER_SIZE
:
933 min_ci
= *parselist
++;
937 level
= *parselist
++;
949 case GLX_DOUBLEBUFFER
:
952 double_flag
= *parselist
++;
955 double_flag
= GL_TRUE
;
961 stereo_flag
= *parselist
++;
964 stereo_flag
= GL_TRUE
;
967 case GLX_AUX_BUFFERS
:
969 numAux
= *parselist
++;
970 if (numAux
> MAX_AUX_BUFFERS
)
975 min_red
= *parselist
++;
979 min_green
= *parselist
++;
983 min_blue
= *parselist
++;
988 GLint size
= *parselist
++;
989 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
994 depth_size
= *parselist
++;
996 case GLX_STENCIL_SIZE
:
998 stencil_size
= *parselist
++;
1000 case GLX_ACCUM_RED_SIZE
:
1003 GLint size
= *parselist
++;
1004 accumRedSize
= MAX2( accumRedSize
, size
);
1007 case GLX_ACCUM_GREEN_SIZE
:
1010 GLint size
= *parselist
++;
1011 accumGreenSize
= MAX2( accumGreenSize
, size
);
1014 case GLX_ACCUM_BLUE_SIZE
:
1017 GLint size
= *parselist
++;
1018 accumBlueSize
= MAX2( accumBlueSize
, size
);
1021 case GLX_ACCUM_ALPHA_SIZE
:
1024 GLint size
= *parselist
++;
1025 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1030 * GLX_EXT_visual_info extension
1032 case GLX_X_VISUAL_TYPE_EXT
:
1034 visual_type
= *parselist
++;
1036 case GLX_TRANSPARENT_TYPE_EXT
:
1038 trans_type
= *parselist
++;
1040 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1042 trans_value
= *parselist
++;
1044 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1045 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1046 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1047 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1054 * GLX_EXT_visual_info extension
1056 case GLX_VISUAL_CAVEAT_EXT
:
1058 caveat
= *parselist
++; /* ignored for now */
1062 * GLX_ARB_multisample
1064 case GLX_SAMPLE_BUFFERS_ARB
:
1065 case GLX_SAMPLES_ARB
:
1067 if (*parselist
++ != 0)
1068 /* ms not supported */
1075 case GLX_RENDER_TYPE
:
1079 if (*parselist
& GLX_RGBA_BIT
) {
1082 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
1083 rgb_flag
= GL_FALSE
;
1085 else if (*parselist
== 0) {
1090 case GLX_DRAWABLE_TYPE
:
1094 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1095 return NULL
; /* bad bit */
1099 case GLX_FBCONFIG_ID
:
1104 desiredVisualID
= *parselist
++;
1106 case GLX_X_RENDERABLE
:
1107 case GLX_MAX_PBUFFER_WIDTH
:
1108 case GLX_MAX_PBUFFER_HEIGHT
:
1109 case GLX_MAX_PBUFFER_PIXELS
:
1116 #ifdef GLX_EXT_texture_from_pixmap
1117 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1118 parselist
++; /*skip*/
1120 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1121 parselist
++; /*skip*/
1123 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1124 parselist
++; /*skip*/
1126 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1128 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1129 GLX_TEXTURE_2D_BIT_EXT
|
1130 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1135 case GLX_Y_INVERTED_EXT
:
1136 parselist
++; /*skip*/
1145 /* undefined attribute */
1146 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1159 * Since we're only simulating the GLX extension this function will never
1160 * find any real GL visuals. Instead, all we can do is try to find an RGB
1161 * or CI visual of appropriate depth. Other requested attributes such as
1162 * double buffering, depth buffer, etc. will be associated with the X
1163 * visual and stored in the VisualTable[].
1165 if (desiredVisualID
!= -1) {
1166 /* try to get a specific visual, by visualID */
1169 temp
.visualid
= desiredVisualID
;
1170 temp
.screen
= screen
;
1171 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1173 /* give the visual some useful GLX attributes */
1174 double_flag
= GL_TRUE
;
1175 if (vis
->depth
<= 8)
1177 depth_size
= default_depth_bits();
1184 int min_rgb
= min_red
+ min_green
+ min_blue
;
1185 if (min_rgb
>1 && min_rgb
<8) {
1186 /* a special case to be sure we can get a monochrome visual */
1191 vis
= choose_x_visual(dpy
, screen
, min_rgb
, visual_type
);
1194 vis
= choose_x_overlay_visual(dpy
, screen
, level
,
1195 trans_type
, trans_value
, min_rgb
, visual_type
);
1200 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1201 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1202 * largest depth buffer size, which is 32bits/value. Instead, we
1203 * return 16 to maintain performance with earlier versions of Mesa.
1205 if (depth_size
> 24)
1207 else if (depth_size
> 16)
1209 else if (depth_size
> 0) {
1210 depth_size
= default_depth_bits();
1214 alpha_flag
= default_alpha_bits() > 0;
1217 /* we only support one size of stencil and accum buffers. */
1218 if (stencil_size
> 0)
1220 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1221 accumAlphaSize
> 0) {
1224 accumBlueSize
= default_accum_bits();
1225 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1228 xmvis
= save_glx_visual( dpy
, vis
, alpha_flag
, double_flag
,
1229 stereo_flag
, depth_size
, stencil_size
,
1230 accumRedSize
, accumGreenSize
,
1231 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1238 static XVisualInfo
*
1239 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1243 /* register ourselves as an extension on this display */
1244 register_with_display(dpy
);
1246 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1249 return xmvis
->vishandle
;
1251 /* create a new vishandle - the cached one may be stale */
1252 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1253 if (xmvis
->vishandle
) {
1254 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1256 return xmvis
->vishandle
;
1265 * Init basic fields of a new fake_glx_context.
1268 init_glx_context(struct fake_glx_context
*glxCtx
, Display
*dpy
)
1270 /* Always return True. See if anyone's confused... */
1271 GLboolean direct
= GL_TRUE
;
1273 glxCtx
->xmesaContext
->direct
= direct
;
1274 glxCtx
->glxContext
.isDirect
= direct
;
1275 glxCtx
->glxContext
.currentDpy
= dpy
;
1276 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1278 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1284 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1285 GLXContext share_list
, Bool direct
)
1288 struct fake_glx_context
*glxCtx
;
1289 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1291 if (!dpy
|| !visinfo
)
1294 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1298 /* deallocate unused windows/buffers */
1300 XMesaGarbageCollect(dpy
);
1303 xmvis
= find_glx_visual( dpy
, visinfo
);
1305 /* This visual wasn't found with glXChooseVisual() */
1306 xmvis
= create_glx_visual( dpy
, visinfo
);
1308 /* unusable visual */
1314 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1315 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1316 if (!glxCtx
->xmesaContext
) {
1321 init_glx_context(glxCtx
, dpy
);
1323 return (GLXContext
) glxCtx
;
1327 /* XXX these may have to be removed due to thread-safety issues. */
1328 static GLXContext MakeCurrent_PrevContext
= 0;
1329 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1330 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1331 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1332 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1335 /* GLX 1.3 and later */
1337 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1338 GLXDrawable read
, GLXContext ctx
)
1340 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1342 if (ctx
&& draw
&& read
) {
1343 XMesaBuffer drawBuffer
, readBuffer
;
1344 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1346 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1347 if (ctx
== MakeCurrent_PrevContext
1348 && draw
== MakeCurrent_PrevDrawable
) {
1349 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1352 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1355 /* drawable must be a new window! */
1356 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1358 /* Out of memory, or context/drawable depth mismatch */
1363 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1364 if (ctx
== MakeCurrent_PrevContext
1365 && read
== MakeCurrent_PrevReadable
) {
1366 readBuffer
= MakeCurrent_PrevReadBuffer
;
1369 readBuffer
= XMesaFindBuffer( dpy
, read
);
1372 /* drawable must be a new window! */
1373 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1375 /* Out of memory, or context/drawable depth mismatch */
1380 MakeCurrent_PrevContext
= ctx
;
1381 MakeCurrent_PrevDrawable
= draw
;
1382 MakeCurrent_PrevReadable
= read
;
1383 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1384 MakeCurrent_PrevReadBuffer
= readBuffer
;
1386 /* Now make current! */
1387 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1388 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1389 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1390 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1397 else if (!ctx
&& !draw
&& !read
) {
1398 /* release current context w/out assigning new one. */
1399 XMesaMakeCurrent( NULL
, NULL
);
1400 MakeCurrent_PrevContext
= 0;
1401 MakeCurrent_PrevDrawable
= 0;
1402 MakeCurrent_PrevReadable
= 0;
1403 MakeCurrent_PrevDrawBuffer
= 0;
1404 MakeCurrent_PrevReadBuffer
= 0;
1408 /* The args must either all be non-zero or all zero.
1417 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1419 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1424 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1429 v
= find_glx_visual( dpy
, visinfo
);
1431 v
= create_glx_visual( dpy
, visinfo
);
1433 /* unusable visual */
1438 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1442 return b
->frontxrb
->pixmap
;
1446 /*** GLX_MESA_pixmap_colormap ***/
1449 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1450 Pixmap pixmap
, Colormap cmap
)
1455 v
= find_glx_visual( dpy
, visinfo
);
1457 v
= create_glx_visual( dpy
, visinfo
);
1459 /* unusable visual */
1464 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1468 return b
->frontxrb
->pixmap
;
1473 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1475 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1477 XMesaDestroyBuffer(b
);
1479 else if (_mesa_getenv("MESA_DEBUG")) {
1480 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1486 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1487 unsigned long mask
)
1489 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1490 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1491 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1492 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1494 if (MakeCurrent_PrevContext
== src
) {
1497 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1502 Fake_glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1505 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1506 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1512 return True
; /* we're faking GLX so always return success */
1516 extern void _kw_ungrab_all( Display
*dpy
);
1517 void _kw_ungrab_all( Display
*dpy
)
1519 XUngrabPointer( dpy
, CurrentTime
);
1520 XUngrabKeyboard( dpy
, CurrentTime
);
1525 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1527 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1529 MakeCurrent_PrevContext
= 0;
1530 MakeCurrent_PrevDrawable
= 0;
1531 MakeCurrent_PrevReadable
= 0;
1532 MakeCurrent_PrevDrawBuffer
= 0;
1533 MakeCurrent_PrevReadBuffer
= 0;
1534 XMesaDestroyContext( glxCtx
->xmesaContext
);
1535 XMesaGarbageCollect(dpy
);
1541 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1543 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1545 return glxCtx
->xmesaContext
->direct
;
1551 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1553 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1556 XMesaSwapBuffers(buffer
);
1558 else if (_mesa_getenv("MESA_DEBUG")) {
1559 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1566 /*** GLX_MESA_copy_sub_buffer ***/
1569 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1570 int x
, int y
, int width
, int height
)
1572 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1574 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1576 else if (_mesa_getenv("MESA_DEBUG")) {
1577 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1583 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1586 /* Return GLX version, not Mesa version */
1587 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1588 *maj
= CLIENT_MAJOR_VERSION
;
1589 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1595 * Query the GLX attributes of the given XVisualInfo.
1598 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1604 return GLX_BAD_ATTRIBUTE
;
1605 *value
= (int) True
;
1607 case GLX_BUFFER_SIZE
:
1608 *value
= xmvis
->visinfo
->depth
;
1611 *value
= xmvis
->mesa_visual
.level
;
1615 return GLX_BAD_ATTRIBUTE
;
1616 if (xmvis
->mesa_visual
.rgbMode
) {
1623 case GLX_DOUBLEBUFFER
:
1624 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1627 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1629 case GLX_AUX_BUFFERS
:
1630 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1633 *value
= xmvis
->mesa_visual
.redBits
;
1635 case GLX_GREEN_SIZE
:
1636 *value
= xmvis
->mesa_visual
.greenBits
;
1639 *value
= xmvis
->mesa_visual
.blueBits
;
1641 case GLX_ALPHA_SIZE
:
1642 *value
= xmvis
->mesa_visual
.alphaBits
;
1644 case GLX_DEPTH_SIZE
:
1645 *value
= xmvis
->mesa_visual
.depthBits
;
1647 case GLX_STENCIL_SIZE
:
1648 *value
= xmvis
->mesa_visual
.stencilBits
;
1650 case GLX_ACCUM_RED_SIZE
:
1651 *value
= xmvis
->mesa_visual
.accumRedBits
;
1653 case GLX_ACCUM_GREEN_SIZE
:
1654 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1656 case GLX_ACCUM_BLUE_SIZE
:
1657 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1659 case GLX_ACCUM_ALPHA_SIZE
:
1660 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1664 * GLX_EXT_visual_info extension
1666 case GLX_X_VISUAL_TYPE_EXT
:
1667 switch (xmvis
->visinfo
->CLASS
) {
1668 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1669 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1670 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1671 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1672 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1673 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1676 case GLX_TRANSPARENT_TYPE_EXT
:
1677 if (xmvis
->mesa_visual
.level
==0) {
1679 *value
= GLX_NONE_EXT
;
1681 else if (xmvis
->mesa_visual
.level
>0) {
1683 if (xmvis
->mesa_visual
.rgbMode
) {
1684 *value
= GLX_TRANSPARENT_RGB_EXT
;
1687 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1690 else if (xmvis
->mesa_visual
.level
<0) {
1692 *value
= GLX_NONE_EXT
;
1695 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1697 int pixel
= transparent_pixel( xmvis
);
1701 /* else undefined */
1704 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1707 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1710 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1713 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1718 * GLX_EXT_visual_info extension
1720 case GLX_VISUAL_CAVEAT_EXT
:
1721 /* test for zero, just in case */
1722 if (xmvis
->mesa_visual
.visualRating
> 0)
1723 *value
= xmvis
->mesa_visual
.visualRating
;
1725 *value
= GLX_NONE_EXT
;
1729 * GLX_ARB_multisample
1731 case GLX_SAMPLE_BUFFERS_ARB
:
1734 case GLX_SAMPLES_ARB
:
1741 case GLX_SCREEN_EXT
:
1743 return GLX_BAD_ATTRIBUTE
;
1744 *value
= xmvis
->visinfo
->screen
;
1746 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1748 return GLX_BAD_ATTRIBUTE
;
1749 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1751 case GLX_RENDER_TYPE_SGIX
:
1753 return GLX_BAD_ATTRIBUTE
;
1754 if (xmvis
->mesa_visual
.rgbMode
)
1755 *value
= GLX_RGBA_BIT
;
1757 *value
= GLX_COLOR_INDEX_BIT
;
1759 case GLX_X_RENDERABLE_SGIX
:
1761 return GLX_BAD_ATTRIBUTE
;
1762 *value
= True
; /* XXX really? */
1764 case GLX_FBCONFIG_ID_SGIX
:
1766 return GLX_BAD_ATTRIBUTE
;
1767 *value
= xmvis
->visinfo
->visualid
;
1769 case GLX_MAX_PBUFFER_WIDTH
:
1771 return GLX_BAD_ATTRIBUTE
;
1772 /* XXX or MAX_WIDTH? */
1773 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1775 case GLX_MAX_PBUFFER_HEIGHT
:
1777 return GLX_BAD_ATTRIBUTE
;
1778 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1780 case GLX_MAX_PBUFFER_PIXELS
:
1782 return GLX_BAD_ATTRIBUTE
;
1783 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1784 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1788 return GLX_BAD_ATTRIBUTE
;
1789 *value
= xmvis
->visinfo
->visualid
;
1792 #ifdef GLX_EXT_texture_from_pixmap
1793 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1794 *value
= True
; /*XXX*/
1796 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1798 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1800 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1801 *value
= True
; /*XXX*/
1803 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1804 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1805 GLX_TEXTURE_2D_BIT_EXT
|
1806 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1808 case GLX_Y_INVERTED_EXT
:
1809 *value
= True
; /*XXX*/
1814 return GLX_BAD_ATTRIBUTE
;
1821 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1822 int attrib
, int *value
)
1826 if (!dpy
|| !visinfo
)
1827 return GLX_BAD_ATTRIBUTE
;
1829 xmvis
= find_glx_visual( dpy
, visinfo
);
1831 /* this visual wasn't obtained with glXChooseVisual */
1832 xmvis
= create_glx_visual( dpy
, visinfo
);
1834 /* this visual can't be used for GL rendering */
1835 if (attrib
==GLX_USE_GL
) {
1836 *value
= (int) False
;
1840 return GLX_BAD_VISUAL
;
1845 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1851 Fake_glXWaitGL( void )
1853 XMesaContext xmesa
= XMesaGetCurrentContext();
1854 XMesaFlush( xmesa
);
1860 Fake_glXWaitX( void )
1862 XMesaContext xmesa
= XMesaGetCurrentContext();
1863 XMesaFlush( xmesa
);
1868 get_extensions( void )
1870 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1875 /* GLX 1.1 and later */
1877 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1881 return get_extensions();
1886 /* GLX 1.1 and later */
1888 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1890 static char version
[1000];
1891 sprintf(version
, "%d.%d %s",
1892 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1898 case GLX_EXTENSIONS
:
1899 return get_extensions();
1911 /* GLX 1.1 and later */
1913 Fake_glXGetClientString( Display
*dpy
, int name
)
1915 static char version
[1000];
1916 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1917 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1922 case GLX_EXTENSIONS
:
1923 return get_extensions();
1941 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1942 int attribute
, int *value
)
1944 XMesaVisual v
= (XMesaVisual
) config
;
1948 if (!dpy
|| !config
|| !value
)
1951 return get_config(v
, attribute
, value
, GL_TRUE
);
1955 static GLXFBConfig
*
1956 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1958 XVisualInfo
*visuals
, visTemplate
;
1959 const long visMask
= VisualScreenMask
;
1962 /* Get list of all X visuals */
1963 visTemplate
.screen
= screen
;
1964 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1965 if (*nelements
> 0) {
1966 XMesaVisual
*results
;
1967 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1972 for (i
= 0; i
< *nelements
; i
++) {
1973 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1975 return (GLXFBConfig
*) results
;
1981 static GLXFBConfig
*
1982 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1983 const int *attribList
, int *nitems
)
1987 /* register ourselves as an extension on this display */
1988 register_with_display(dpy
);
1990 if (!attribList
|| !attribList
[0]) {
1991 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1992 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
1995 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1997 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
2003 config
[0] = (GLXFBConfig
) xmvis
;
2004 return (GLXFBConfig
*) config
;
2013 static XVisualInfo
*
2014 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2016 if (dpy
&& config
) {
2017 XMesaVisual xmvis
= (XMesaVisual
) config
;
2019 return xmvis
->vishandle
;
2021 /* create a new vishandle - the cached one may be stale */
2022 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
2023 if (xmvis
->vishandle
) {
2024 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2026 return xmvis
->vishandle
;
2036 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2037 const int *attribList
)
2039 XMesaVisual xmvis
= (XMesaVisual
) config
;
2044 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2049 (void) attribList
; /* Ignored in GLX 1.3 */
2051 return win
; /* A hack for now */
2056 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2058 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2060 XMesaDestroyBuffer(b
);
2061 /* don't destroy X window */
2067 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2068 const int *attribList
)
2070 XMesaVisual v
= (XMesaVisual
) config
;
2073 int target
= 0, format
= 0, mipmap
= 0;
2076 if (!dpy
|| !config
|| !pixmap
)
2079 for (attr
= attribList
; attr
&& *attr
; attr
++) {
2081 case GLX_TEXTURE_FORMAT_EXT
:
2084 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2085 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2086 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2094 case GLX_TEXTURE_TARGET_EXT
:
2097 case GLX_TEXTURE_1D_EXT
:
2098 case GLX_TEXTURE_2D_EXT
:
2099 case GLX_TEXTURE_RECTANGLE_EXT
:
2107 case GLX_MIPMAP_TEXTURE_EXT
:
2118 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2119 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2120 &value
, GL_TRUE
) != Success
2122 return 0; /* error! */
2125 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2126 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2127 &value
, GL_TRUE
) != Success
2129 return 0; /* error! */
2133 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2134 &value
, GL_TRUE
) != Success
2136 return 0; /* error! */
2139 if (target
== GLX_TEXTURE_1D_EXT
) {
2140 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2141 &value
, GL_TRUE
) != Success
2142 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2143 return 0; /* error! */
2146 else if (target
== GLX_TEXTURE_2D_EXT
) {
2147 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2148 &value
, GL_TRUE
) != Success
2149 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2150 return 0; /* error! */
2153 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2154 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2155 &value
, GL_TRUE
) != Success
2156 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2157 return 0; /* error! */
2161 if (format
|| target
|| mipmap
) {
2162 /* texture from pixmap */
2163 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2166 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2177 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2179 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2181 XMesaDestroyBuffer(b
);
2182 /* don't destroy X pixmap */
2187 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2188 const int *attribList
)
2190 XMesaVisual xmvis
= (XMesaVisual
) config
;
2193 int width
= 0, height
= 0;
2194 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2198 for (attrib
= attribList
; *attrib
; attrib
++) {
2200 case GLX_PBUFFER_WIDTH
:
2204 case GLX_PBUFFER_HEIGHT
:
2208 case GLX_PRESERVED_CONTENTS
:
2210 preserveContents
= *attrib
;
2212 case GLX_LARGEST_PBUFFER
:
2214 useLargest
= *attrib
;
2221 if (width
== 0 || height
== 0)
2224 if (width
> SWRAST_MAX_WIDTH
|| height
> SWRAST_MAX_HEIGHT
) {
2225 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2226 * allocate the largest possible buffer.
2229 width
= SWRAST_MAX_WIDTH
;
2230 height
= SWRAST_MAX_HEIGHT
;
2234 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2235 /* A GLXPbuffer handle must be an X Drawable because that's what
2236 * glXMakeCurrent takes.
2239 xmbuf
->largestPbuffer
= useLargest
;
2240 xmbuf
->preservedContents
= preserveContents
;
2241 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2250 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2252 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2254 XMesaDestroyBuffer(b
);
2260 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2261 unsigned int *value
)
2263 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2267 /* make sure buffer's dimensions are up to date */
2268 xmesa_check_and_update_buffer_size(NULL
, xmbuf
);
2270 switch (attribute
) {
2272 *value
= xmbuf
->mesa_buffer
.Width
;
2275 *value
= xmbuf
->mesa_buffer
.Height
;
2277 case GLX_PRESERVED_CONTENTS
:
2278 *value
= xmbuf
->preservedContents
;
2280 case GLX_LARGEST_PBUFFER
:
2281 *value
= xmbuf
->largestPbuffer
;
2283 case GLX_FBCONFIG_ID
:
2284 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2286 #ifdef GLX_EXT_texture_from_pixmap
2287 case GLX_TEXTURE_FORMAT_EXT
:
2288 *value
= xmbuf
->TextureFormat
;
2290 case GLX_TEXTURE_TARGET_EXT
:
2291 *value
= xmbuf
->TextureTarget
;
2293 case GLX_MIPMAP_TEXTURE_EXT
:
2294 *value
= xmbuf
->TextureMipmap
;
2299 return; /* raise BadValue error */
2305 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2306 int renderType
, GLXContext shareList
, Bool direct
)
2308 struct fake_glx_context
*glxCtx
;
2309 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2310 XMesaVisual xmvis
= (XMesaVisual
) config
;
2312 if (!dpy
|| !config
||
2313 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2316 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2320 /* deallocate unused windows/buffers */
2321 XMesaGarbageCollect(dpy
);
2323 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2324 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2325 if (!glxCtx
->xmesaContext
) {
2330 init_glx_context(glxCtx
, dpy
);
2332 return (GLXContext
) glxCtx
;
2337 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2339 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2340 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2345 switch (attribute
) {
2346 case GLX_FBCONFIG_ID
:
2347 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2349 case GLX_RENDER_TYPE
:
2350 *value
= GLX_RGBA_TYPE
;
2356 return GLX_BAD_ATTRIBUTE
;
2363 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2365 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2367 xmbuf
->selectedEvents
= mask
;
2372 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2373 unsigned long *mask
)
2375 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2377 *mask
= xmbuf
->selectedEvents
;
2384 /*** GLX_SGI_swap_control ***/
2387 Fake_glXSwapIntervalSGI(int interval
)
2395 /*** GLX_SGI_video_sync ***/
2397 static unsigned int FrameCounter
= 0;
2400 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2402 /* this is a bogus implementation */
2403 *count
= FrameCounter
++;
2408 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2410 if (divisor
<= 0 || remainder
< 0)
2411 return GLX_BAD_VALUE
;
2412 /* this is a bogus implementation */
2414 while (FrameCounter
% divisor
!= remainder
)
2416 *count
= FrameCounter
;
2422 /*** GLX_SGI_make_current_read ***/
2425 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2427 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2432 Fake_glXGetCurrentReadDrawableSGI(void)
2439 /*** GLX_SGIX_video_source ***/
2442 static GLXVideoSourceSGIX
2443 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2455 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2464 /*** GLX_EXT_import_context ***/
2467 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2474 Fake_glXGetContextIDEXT(const GLXContext context
)
2481 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2489 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2500 /*** GLX_SGIX_fbconfig ***/
2503 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2505 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2508 static GLXFBConfigSGIX
*
2509 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2511 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2516 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2518 XMesaVisual xmvis
= (XMesaVisual
) config
;
2519 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2520 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2525 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2527 XMesaVisual xmvis
= (XMesaVisual
) config
;
2528 struct fake_glx_context
*glxCtx
;
2529 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2531 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2535 /* deallocate unused windows/buffers */
2536 XMesaGarbageCollect(dpy
);
2538 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2539 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2540 if (!glxCtx
->xmesaContext
) {
2545 init_glx_context(glxCtx
, dpy
);
2547 return (GLXContext
) glxCtx
;
2551 static XVisualInfo
*
2552 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2554 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2558 static GLXFBConfigSGIX
2559 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2561 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2563 /* This visual wasn't found with glXChooseVisual() */
2564 xmvis
= create_glx_visual(dpy
, vis
);
2567 return (GLXFBConfigSGIX
) xmvis
;
2572 /*** GLX_SGIX_pbuffer ***/
2574 static GLXPbufferSGIX
2575 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2576 unsigned int width
, unsigned int height
,
2579 XMesaVisual xmvis
= (XMesaVisual
) config
;
2582 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2586 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2588 case GLX_PRESERVED_CONTENTS_SGIX
:
2590 preserveContents
= *attrib
; /* ignored */
2592 case GLX_LARGEST_PBUFFER_SGIX
:
2594 useLargest
= *attrib
; /* ignored */
2601 /* not used at this time */
2603 (void) preserveContents
;
2605 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2606 /* A GLXPbuffer handle must be an X Drawable because that's what
2607 * glXMakeCurrent takes.
2609 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2614 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2616 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2618 XMesaDestroyBuffer(xmbuf
);
2624 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2626 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2629 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2633 switch (attribute
) {
2634 case GLX_PRESERVED_CONTENTS_SGIX
:
2635 *value
= xmbuf
->preservedContents
;
2637 case GLX_LARGEST_PBUFFER_SGIX
:
2638 *value
= xmbuf
->largestPbuffer
;
2640 case GLX_WIDTH_SGIX
:
2641 *value
= xmbuf
->mesa_buffer
.Width
;
2643 case GLX_HEIGHT_SGIX
:
2644 *value
= xmbuf
->mesa_buffer
.Height
;
2646 case GLX_EVENT_MASK_SGIX
:
2647 *value
= 0; /* XXX might be wrong */
2657 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2659 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2661 /* Note: we'll never generate clobber events */
2662 xmbuf
->selectedEvents
= mask
;
2668 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2670 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2672 *mask
= xmbuf
->selectedEvents
;
2681 /*** GLX_SGI_cushion ***/
2684 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2693 /*** GLX_SGIX_video_resize ***/
2696 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2706 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2719 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2732 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2745 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2756 /*** GLX_SGIX_dmbuffer **/
2758 #if defined(_DM_BUFFER_H_)
2760 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2771 /*** GLX_SGIX_swap_group ***/
2774 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2783 /*** GLX_SGIX_swap_barrier ***/
2786 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2794 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2804 /*** GLX_SUN_get_transparent_index ***/
2807 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2812 (void) pTransparent
;
2818 /*** GLX_MESA_release_buffers ***/
2821 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2822 * (a window or pixmap) prior to destroying the GLXDrawable.
2825 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2827 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2829 XMesaDestroyBuffer(b
);
2837 /*** GLX_MESA_set_3dfx_mode ***/
2840 Fake_glXSet3DfxModeMESA( int mode
)
2842 return XMesaSetFXmode( mode
);
2847 /*** GLX_NV_vertex_array range ***/
2849 Fake_glXAllocateMemoryNV( GLsizei size
,
2850 GLfloat readFrequency
,
2851 GLfloat writeFrequency
,
2855 (void) readFrequency
;
2856 (void) writeFrequency
;
2863 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2869 /*** GLX_MESA_agp_offset ***/
2872 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
2879 /*** GLX_EXT_texture_from_pixmap ***/
2882 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2883 const int *attrib_list
)
2885 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2887 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2891 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2893 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2895 XMesaReleaseTexImage(dpy
, b
, buffer
);
2899 /* silence warning */
2900 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2904 * Create a new GLX API dispatch table with its function pointers
2905 * initialized to point to Mesa's "fake" GLX API functions.
2906 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2907 * returns a new dispatch table with all pointers initalized to point
2908 * to "real" GLX functions (which understand GLX wire protocol, etc).
2910 struct _glxapi_table
*
2911 _mesa_GetGLXDispatchTable(void)
2913 static struct _glxapi_table glx
;
2915 /* be sure our dispatch table size <= libGL's table */
2917 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2919 assert(_glxapi_get_dispatch_table_size() >= size
);
2922 /* initialize the whole table to no-ops */
2923 _glxapi_set_no_op_table(&glx
);
2925 /* now initialize the table with the functions I implement */
2926 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2927 glx
.CopyContext
= Fake_glXCopyContext
;
2928 glx
.CreateContext
= Fake_glXCreateContext
;
2929 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2930 glx
.DestroyContext
= Fake_glXDestroyContext
;
2931 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2932 glx
.GetConfig
= Fake_glXGetConfig
;
2933 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2934 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2935 glx
.IsDirect
= Fake_glXIsDirect
;
2936 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2937 glx
.QueryExtension
= Fake_glXQueryExtension
;
2938 glx
.QueryVersion
= Fake_glXQueryVersion
;
2939 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2940 glx
.UseXFont
= Fake_glXUseXFont
;
2941 glx
.WaitGL
= Fake_glXWaitGL
;
2942 glx
.WaitX
= Fake_glXWaitX
;
2944 /*** GLX_VERSION_1_1 ***/
2945 glx
.GetClientString
= Fake_glXGetClientString
;
2946 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2947 glx
.QueryServerString
= Fake_glXQueryServerString
;
2949 /*** GLX_VERSION_1_2 ***/
2950 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2952 /*** GLX_VERSION_1_3 ***/
2953 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2954 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2955 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2956 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2957 glx
.CreateWindow
= Fake_glXCreateWindow
;
2958 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2959 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2960 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2961 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2962 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2963 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2964 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2965 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2966 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2967 glx
.QueryContext
= Fake_glXQueryContext
;
2968 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2969 glx
.SelectEvent
= Fake_glXSelectEvent
;
2971 /*** GLX_SGI_swap_control ***/
2972 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2974 /*** GLX_SGI_video_sync ***/
2975 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2976 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2978 /*** GLX_SGI_make_current_read ***/
2979 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2980 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2982 /*** GLX_SGIX_video_source ***/
2984 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2985 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2988 /*** GLX_EXT_import_context ***/
2989 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2990 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2991 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2992 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2993 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2995 /*** GLX_SGIX_fbconfig ***/
2996 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2997 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2998 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2999 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3000 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3001 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3003 /*** GLX_SGIX_pbuffer ***/
3004 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3005 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3006 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3007 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3008 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3010 /*** GLX_SGI_cushion ***/
3011 glx
.CushionSGI
= Fake_glXCushionSGI
;
3013 /*** GLX_SGIX_video_resize ***/
3014 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3015 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3016 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3017 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3018 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3020 /*** GLX_SGIX_dmbuffer **/
3021 #if defined(_DM_BUFFER_H_)
3022 glx
.AssociateDMPbufferSGIX
= NULL
;
3025 /*** GLX_SGIX_swap_group ***/
3026 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3028 /*** GLX_SGIX_swap_barrier ***/
3029 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3030 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3032 /*** GLX_SUN_get_transparent_index ***/
3033 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3035 /*** GLX_MESA_copy_sub_buffer ***/
3036 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3038 /*** GLX_MESA_release_buffers ***/
3039 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3041 /*** GLX_MESA_pixmap_colormap ***/
3042 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3044 /*** GLX_MESA_set_3dfx_mode ***/
3045 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3047 /*** GLX_NV_vertex_array_range ***/
3048 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3049 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3051 /*** GLX_MESA_agp_offset ***/
3052 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3054 /*** GLX_EXT_texture_from_pixmap ***/
3055 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3056 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;