1 /* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11 ** http://oss.sgi.com/projects/FreeB
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
39 * Client-side GLX interface.
43 #include "glxclient.h"
49 #ifdef GLX_DIRECT_RENDERING
50 #include "indirect_init.h"
51 #include "xf86vmode.h"
53 #include "glxextensions.h"
54 #include "glcontextmodes.h"
59 #define GLX_PREFIX(x) x
60 #endif /* IN_DOXYGEN */
62 static const char __glXGLXClientVendorName
[] = "SGI";
63 static const char __glXGLXClientVersion
[] = "1.4";
66 #if defined(GLX_DIRECT_RENDERING)
69 static Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
);
73 /****************************************************************************/
75 * Get the __DRIdrawable for the drawable associated with a GLXContext
77 * \param dpy The display associated with \c drawable.
78 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
79 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
80 * the drawable is not associated with a direct-rendering context.
83 #ifdef GLX_DIRECT_RENDERING
84 static __DRIdrawable
*
85 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
87 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
89 if ( (priv
!= NULL
) && (priv
->driDisplay
.private != NULL
) ) {
90 const unsigned screen_count
= ScreenCount(dpy
);
93 for ( i
= 0 ; i
< screen_count
; i
++ ) {
94 __DRIscreen
* const psc
= &priv
->screenConfigs
[i
].driScreen
;
95 __DRIdrawable
* const pdraw
= (psc
->private != NULL
)
96 ? (*psc
->getDrawable
)(dpy
, drawable
, psc
->private) : NULL
;
98 if ( pdraw
!= NULL
) {
99 if ( scrn_num
!= NULL
) {
113 * Get the GLX per-screen data structure associated with a GLX context.
115 * \param dpy Display for which the GLX per-screen information is to be
117 * \param scrn Screen on \c dpy for which the GLX per-screen information is
119 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
120 * specify a valid GLX screen, or NULL otherwise.
122 * \todo Should this function validate that \c scrn is within the screen
123 * number range for \c dpy?
126 static __GLXscreenConfigs
*
127 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
129 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
131 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
136 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
137 __GLXscreenConfigs
** ppsc
)
139 /* Initialize the extension, if needed . This has the added value
140 * of initializing/allocating the display private
144 return GLX_NO_EXTENSION
;
147 *ppriv
= __glXInitialize(dpy
);
148 if ( *ppriv
== NULL
) {
149 return GLX_NO_EXTENSION
;
152 /* Check screen number to see if its valid */
153 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
154 return GLX_BAD_SCREEN
;
157 /* Check to see if the GL is supported on this screen */
158 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
159 if ( (*ppsc
)->configs
== NULL
) {
160 /* No support for GL on this screen regardless of visual */
161 return GLX_BAD_VISUAL
;
169 * Determine if a \c GLXFBConfig supplied by the application is valid.
171 * \param dpy Application supplied \c Display pointer.
172 * \param config Application supplied \c GLXFBConfig.
174 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
175 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
178 static __GLcontextModes
*
179 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
181 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
182 const unsigned num_screens
= ScreenCount(dpy
);
184 const __GLcontextModes
* modes
;
187 if ( priv
!= NULL
) {
188 for ( i
= 0 ; i
< num_screens
; i
++ ) {
189 for ( modes
= priv
->screenConfigs
[i
].configs
191 ; modes
= modes
->next
) {
192 if ( modes
== (__GLcontextModes
*) config
) {
193 return (__GLcontextModes
*) config
;
204 * \todo It should be possible to move the allocate of \c client_state_private
205 * later in the function for direct-rendering contexts. Direct-rendering
206 * contexts don't need to track client state, so they don't need that memory
209 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
210 * function called \c __glXAllocateClientState that allocates the memory and
211 * does all the initialization (including the pixel pack / unpack).
214 GLXContext
AllocateGLXContext( Display
*dpy
)
219 __GLXattribute
*state
;
224 opcode
= __glXSetupForCommand(dpy
);
229 /* Allocate our context record */
230 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
235 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
237 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
243 gc
->client_state_private
= state
;
244 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
245 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
248 ** Create a temporary buffer to hold GLX rendering commands. The size
249 ** of the buffer is selected so that the maximum number of GLX rendering
250 ** commands can fit in a single X packet and still have room in the X
251 ** packet for the GLXRenderReq header.
254 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
255 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
257 Xfree(gc
->client_state_private
);
261 gc
->bufSize
= bufSize
;
263 /* Fill in the new context */
264 gc
->renderMode
= GL_RENDER
;
266 state
->storePack
.alignment
= 4;
267 state
->storeUnpack
.alignment
= 4;
269 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
272 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
273 ** Other code uses the fastImageUnpack bit, but it is never set
276 gc
->fastImageUnpack
= GL_FALSE
;
277 gc
->fillImage
= __glFillImage
;
278 gc
->isDirect
= GL_FALSE
;
280 gc
->bufEnd
= gc
->buf
+ bufSize
;
283 ** Set limit register so that there will be one command per packet
287 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
290 gc
->majorOpcode
= opcode
;
293 ** Constrain the maximum drawing command size allowed to be
294 ** transfered using the X_GLXRender protocol request. First
295 ** constrain by a software limit, then constrain by the protocl
298 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
299 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
301 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
302 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
304 gc
->maxSmallRenderCommandSize
= bufSize
;
310 * Create a new context. Exactly one of \c vis and \c fbconfig should be
313 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
314 * SGIX_fbconfig protocol be used?
315 * \param renderType For FBConfigs, what is the rendering type?
319 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
320 const __GLcontextModes
* const fbconfig
,
321 GLXContext shareList
,
322 Bool allowDirect
, GLXContextID contextID
,
323 Bool use_glx_1_3
, int renderType
)
330 gc
= AllocateGLXContext(dpy
);
334 if (None
== contextID
) {
335 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
338 #ifdef GLX_DIRECT_RENDERING
340 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
341 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
342 const __GLcontextModes
* mode
;
344 /* The value of fbconfig cannot change because it is tested
345 * later in the function.
347 if ( fbconfig
== NULL
) {
348 /* FIXME: Is it possible for the __GLcontextModes structure
349 * FIXME: to not be found?
351 mode
= _gl_context_modes_find_visual( psc
->configs
,
353 assert( mode
!= NULL
);
354 assert( mode
->screen
== screen
);
360 if (psc
&& psc
->driScreen
.private) {
361 void * const shared
= (shareList
!= NULL
)
362 ? shareList
->driContext
.private : NULL
;
363 gc
->driContext
.private =
364 (*psc
->driScreen
.createNewContext
)( dpy
, mode
, renderType
,
367 if (gc
->driContext
.private) {
368 gc
->isDirect
= GL_TRUE
;
369 gc
->screen
= mode
->screen
;
370 gc
->vid
= mode
->visualID
;
371 gc
->fbconfigID
= mode
->fbconfigID
;
372 gc
->driContext
.mode
= mode
;
379 if ( fbconfig
== NULL
) {
380 xGLXCreateContextReq
*req
;
382 /* Send the glXCreateContext request */
383 GetReq(GLXCreateContext
,req
);
384 req
->reqType
= gc
->majorOpcode
;
385 req
->glxCode
= X_GLXCreateContext
;
386 req
->context
= gc
->xid
= XAllocID(dpy
);
387 req
->visual
= vis
->visualid
;
388 req
->screen
= vis
->screen
;
389 req
->shareList
= shareList
? shareList
->xid
: None
;
390 req
->isDirect
= gc
->isDirect
;
392 else if ( use_glx_1_3
) {
393 xGLXCreateNewContextReq
*req
;
395 /* Send the glXCreateNewContext request */
396 GetReq(GLXCreateNewContext
,req
);
397 req
->reqType
= gc
->majorOpcode
;
398 req
->glxCode
= X_GLXCreateNewContext
;
399 req
->context
= gc
->xid
= XAllocID(dpy
);
400 req
->fbconfig
= fbconfig
->fbconfigID
;
401 req
->screen
= fbconfig
->screen
;
402 req
->renderType
= renderType
;
403 req
->shareList
= shareList
? shareList
->xid
: None
;
404 req
->isDirect
= gc
->isDirect
;
407 xGLXVendorPrivateWithReplyReq
*vpreq
;
408 xGLXCreateContextWithConfigSGIXReq
*req
;
410 /* Send the glXCreateNewContext request */
411 GetReqExtra(GLXVendorPrivateWithReply
,
412 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
413 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
414 req
->reqType
= gc
->majorOpcode
;
415 req
->glxCode
= X_GLXVendorPrivateWithReply
;
416 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
417 req
->context
= gc
->xid
= XAllocID(dpy
);
418 req
->fbconfig
= fbconfig
->fbconfigID
;
419 req
->screen
= fbconfig
->screen
;
420 req
->renderType
= renderType
;
421 req
->shareList
= shareList
? shareList
->xid
: None
;
422 req
->isDirect
= gc
->isDirect
;
427 gc
->imported
= GL_FALSE
;
431 gc
->imported
= GL_TRUE
;
437 PUBLIC GLXContext
GLX_PREFIX(glXCreateContext
)(Display
*dpy
, XVisualInfo
*vis
,
438 GLXContext shareList
,
441 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
445 void __glXFreeContext(__GLXcontext
*gc
)
447 if (gc
->vendor
) XFree((char *) gc
->vendor
);
448 if (gc
->renderer
) XFree((char *) gc
->renderer
);
449 if (gc
->version
) XFree((char *) gc
->version
);
450 if (gc
->extensions
) XFree((char *) gc
->extensions
);
451 __glFreeAttributeState(gc
);
452 XFree((char *) gc
->buf
);
453 Xfree((char *) gc
->client_state_private
);
459 ** Destroy the named context
462 DestroyContext(Display
*dpy
, GLXContext gc
)
464 xGLXDestroyContextReq
*req
;
469 opcode
= __glXSetupForCommand(dpy
);
470 if (!opcode
|| !gc
) {
476 imported
= gc
->imported
;
479 #ifdef GLX_DIRECT_RENDERING
480 /* Destroy the direct rendering context */
482 if (gc
->driContext
.private) {
483 (*gc
->driContext
.destroyContext
)(dpy
, gc
->screen
,
484 gc
->driContext
.private);
485 gc
->driContext
.private = NULL
;
490 if (gc
->currentDpy
) {
491 /* Have to free later cuz it's in use now */
494 /* Destroy the handle if not current to anybody */
496 __glXFreeContext(gc
);
501 ** This dpy also created the server side part of the context.
502 ** Send the glXDestroyContext request.
505 GetReq(GLXDestroyContext
,req
);
506 req
->reqType
= opcode
;
507 req
->glxCode
= X_GLXDestroyContext
;
514 PUBLIC
void GLX_PREFIX(glXDestroyContext
)(Display
*dpy
, GLXContext gc
)
516 DestroyContext(dpy
, gc
);
520 ** Return the major and minor version #s for the GLX extension
522 PUBLIC Bool
GLX_PREFIX(glXQueryVersion
)(Display
*dpy
, int *major
, int *minor
)
524 __GLXdisplayPrivate
*priv
;
526 /* Init the extension. This fetches the major and minor version. */
527 priv
= __glXInitialize(dpy
);
528 if (!priv
) return GL_FALSE
;
530 if (major
) *major
= priv
->majorVersion
;
531 if (minor
) *minor
= priv
->minorVersion
;
536 ** Query the existance of the GLX extension
538 PUBLIC Bool
GLX_PREFIX(glXQueryExtension
)(Display
*dpy
, int *errorBase
,
541 int major_op
, erb
, evb
;
544 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
546 if (errorBase
) *errorBase
= erb
;
547 if (eventBase
) *eventBase
= evb
;
553 ** Put a barrier in the token stream that forces the GL to finish its
554 ** work before X can proceed.
556 PUBLIC
void GLX_PREFIX(glXWaitGL
)(void)
559 GLXContext gc
= __glXGetCurrentContext();
560 Display
*dpy
= gc
->currentDpy
;
564 /* Flush any pending commands out */
565 __glXFlushRenderBuffer(gc
, gc
->pc
);
567 #ifdef GLX_DIRECT_RENDERING
569 /* This bit of ugliness unwraps the glFinish function */
578 /* Send the glXWaitGL request */
580 GetReq(GLXWaitGL
,req
);
581 req
->reqType
= gc
->majorOpcode
;
582 req
->glxCode
= X_GLXWaitGL
;
583 req
->contextTag
= gc
->currentContextTag
;
589 ** Put a barrier in the token stream that forces X to finish its
590 ** work before GL can proceed.
592 PUBLIC
void GLX_PREFIX(glXWaitX
)(void)
595 GLXContext gc
= __glXGetCurrentContext();
596 Display
*dpy
= gc
->currentDpy
;
600 /* Flush any pending commands out */
601 __glXFlushRenderBuffer(gc
, gc
->pc
);
603 #ifdef GLX_DIRECT_RENDERING
611 ** Send the glXWaitX request.
614 GetReq(GLXWaitX
,req
);
615 req
->reqType
= gc
->majorOpcode
;
616 req
->glxCode
= X_GLXWaitX
;
617 req
->contextTag
= gc
->currentContextTag
;
622 PUBLIC
void GLX_PREFIX(glXUseXFont
)(Font font
, int first
, int count
,
625 xGLXUseXFontReq
*req
;
626 GLXContext gc
= __glXGetCurrentContext();
627 Display
*dpy
= gc
->currentDpy
;
631 /* Flush any pending commands out */
632 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
634 #ifdef GLX_DIRECT_RENDERING
636 DRI_glXUseXFont(font
, first
, count
, listBase
);
641 /* Send the glXUseFont request */
643 GetReq(GLXUseXFont
,req
);
644 req
->reqType
= gc
->majorOpcode
;
645 req
->glxCode
= X_GLXUseXFont
;
646 req
->contextTag
= gc
->currentContextTag
;
650 req
->listBase
= listBase
;
655 /************************************************************************/
658 ** Copy the source context to the destination context using the
661 PUBLIC
void GLX_PREFIX(glXCopyContext
)(Display
*dpy
, GLXContext source
,
662 GLXContext dest
, unsigned long mask
)
664 xGLXCopyContextReq
*req
;
665 GLXContext gc
= __glXGetCurrentContext();
669 opcode
= __glXSetupForCommand(dpy
);
674 #ifdef GLX_DIRECT_RENDERING
676 /* NOT_DONE: This does not work yet */
681 ** If the source is the current context, send its tag so that the context
682 ** can be flushed before the copy.
684 if (source
== gc
&& dpy
== gc
->currentDpy
) {
685 tag
= gc
->currentContextTag
;
690 /* Send the glXCopyContext request */
692 GetReq(GLXCopyContext
,req
);
693 req
->reqType
= opcode
;
694 req
->glxCode
= X_GLXCopyContext
;
695 req
->source
= source
? source
->xid
: None
;
696 req
->dest
= dest
? dest
->xid
: None
;
698 req
->contextTag
= tag
;
705 * Determine if a context uses direct rendering.
707 * \param dpy Display where the context was created.
708 * \param contextID ID of the context to be tested.
710 * \returns \c GL_TRUE if the context is direct rendering or not.
712 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
714 xGLXIsDirectReq
*req
;
715 xGLXIsDirectReply reply
;
718 opcode
= __glXSetupForCommand(dpy
);
723 /* Send the glXIsDirect request */
725 GetReq(GLXIsDirect
,req
);
726 req
->reqType
= opcode
;
727 req
->glxCode
= X_GLXIsDirect
;
728 req
->context
= contextID
;
729 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
733 return reply
.isDirect
;
738 * Shouldn't this function \b always return \c GL_FALSE when
739 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
740 * the GLX protocol here at all?
742 PUBLIC Bool
GLX_PREFIX(glXIsDirect
)(Display
*dpy
, GLXContext gc
)
746 #ifdef GLX_DIRECT_RENDERING
747 } else if (gc
->isDirect
) {
751 return __glXIsDirect(dpy
, gc
->xid
);
754 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmap
)(Display
*dpy
, XVisualInfo
*vis
,
757 xGLXCreateGLXPixmapReq
*req
;
761 opcode
= __glXSetupForCommand(dpy
);
766 /* Send the glXCreateGLXPixmap request */
768 GetReq(GLXCreateGLXPixmap
,req
);
769 req
->reqType
= opcode
;
770 req
->glxCode
= X_GLXCreateGLXPixmap
;
771 req
->screen
= vis
->screen
;
772 req
->visual
= vis
->visualid
;
773 req
->pixmap
= pixmap
;
774 req
->glxpixmap
= xid
= XAllocID(dpy
);
781 ** Destroy the named pixmap
783 PUBLIC
void GLX_PREFIX(glXDestroyGLXPixmap
)(Display
*dpy
, GLXPixmap glxpixmap
)
785 xGLXDestroyGLXPixmapReq
*req
;
788 opcode
= __glXSetupForCommand(dpy
);
793 /* Send the glXDestroyGLXPixmap request */
795 GetReq(GLXDestroyGLXPixmap
,req
);
796 req
->reqType
= opcode
;
797 req
->glxCode
= X_GLXDestroyGLXPixmap
;
798 req
->glxpixmap
= glxpixmap
;
803 PUBLIC
void GLX_PREFIX(glXSwapBuffers
)(Display
*dpy
, GLXDrawable drawable
)
805 xGLXSwapBuffersReq
*req
;
809 #ifdef GLX_DIRECT_RENDERING
810 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
812 if ( pdraw
!= NULL
) {
813 (*pdraw
->swapBuffers
)(dpy
, pdraw
->private);
818 opcode
= __glXSetupForCommand(dpy
);
824 ** The calling thread may or may not have a current context. If it
825 ** does, send the context tag so the server can do a flush.
827 gc
= __glXGetCurrentContext();
828 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
829 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
830 tag
= gc
->currentContextTag
;
835 /* Send the glXSwapBuffers request */
837 GetReq(GLXSwapBuffers
,req
);
838 req
->reqType
= opcode
;
839 req
->glxCode
= X_GLXSwapBuffers
;
840 req
->drawable
= drawable
;
841 req
->contextTag
= tag
;
849 ** Return configuration information for the given display, screen and
850 ** visual combination.
852 PUBLIC
int GLX_PREFIX(glXGetConfig
)(Display
*dpy
, XVisualInfo
*vis
,
853 int attribute
, int *value_return
)
855 __GLXdisplayPrivate
*priv
;
856 __GLXscreenConfigs
*psc
;
859 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
860 if ( status
== Success
) {
861 const __GLcontextModes
* const modes
= _gl_context_modes_find_visual(
862 psc
->configs
, vis
->visualid
);
864 /* Lookup attribute after first finding a match on the visual */
865 if ( modes
!= NULL
) {
866 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
869 status
= GLX_BAD_VISUAL
;
873 ** If we can't find the config for this visual, this visual is not
874 ** supported by the OpenGL implementation on the server.
876 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
877 *value_return
= GL_FALSE
;
884 /************************************************************************/
887 init_fbconfig_for_chooser( __GLcontextModes
* config
,
888 GLboolean fbconfig_style_tags
)
890 memset( config
, 0, sizeof( __GLcontextModes
) );
891 config
->visualID
= (XID
) GLX_DONT_CARE
;
892 config
->visualType
= GLX_DONT_CARE
;
894 /* glXChooseFBConfig specifies different defaults for these two than
897 if ( fbconfig_style_tags
) {
898 config
->rgbMode
= GL_TRUE
;
899 config
->doubleBufferMode
= GLX_DONT_CARE
;
902 config
->visualRating
= GLX_DONT_CARE
;
903 config
->transparentPixel
= GLX_NONE
;
904 config
->transparentRed
= GLX_DONT_CARE
;
905 config
->transparentGreen
= GLX_DONT_CARE
;
906 config
->transparentBlue
= GLX_DONT_CARE
;
907 config
->transparentAlpha
= GLX_DONT_CARE
;
908 config
->transparentIndex
= GLX_DONT_CARE
;
910 config
->drawableType
= GLX_WINDOW_BIT
;
911 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
912 config
->xRenderable
= GLX_DONT_CARE
;
913 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
915 config
->swapMethod
= GLX_DONT_CARE
;
918 #define MATCH_DONT_CARE( param ) \
920 if ( (a-> param != GLX_DONT_CARE) \
921 && (a-> param != b-> param) ) { \
926 #define MATCH_MINIMUM( param ) \
928 if ( (a-> param != GLX_DONT_CARE) \
929 && (a-> param > b-> param) ) { \
934 #define MATCH_EXACT( param ) \
936 if ( a-> param != b-> param) { \
942 * Determine if two GLXFBConfigs are compatible.
944 * \param a Application specified config to test.
945 * \param b Server specified config to test against \c a.
948 fbconfigs_compatible( const __GLcontextModes
* const a
,
949 const __GLcontextModes
* const b
)
951 MATCH_DONT_CARE( doubleBufferMode
);
952 MATCH_DONT_CARE( visualType
);
953 MATCH_DONT_CARE( visualRating
);
954 MATCH_DONT_CARE( xRenderable
);
955 MATCH_DONT_CARE( fbconfigID
);
956 MATCH_DONT_CARE( swapMethod
);
958 MATCH_MINIMUM( rgbBits
);
959 MATCH_MINIMUM( numAuxBuffers
);
960 MATCH_MINIMUM( redBits
);
961 MATCH_MINIMUM( greenBits
);
962 MATCH_MINIMUM( blueBits
);
963 MATCH_MINIMUM( alphaBits
);
964 MATCH_MINIMUM( depthBits
);
965 MATCH_MINIMUM( stencilBits
);
966 MATCH_MINIMUM( accumRedBits
);
967 MATCH_MINIMUM( accumGreenBits
);
968 MATCH_MINIMUM( accumBlueBits
);
969 MATCH_MINIMUM( accumAlphaBits
);
970 MATCH_MINIMUM( sampleBuffers
);
971 MATCH_MINIMUM( maxPbufferWidth
);
972 MATCH_MINIMUM( maxPbufferHeight
);
973 MATCH_MINIMUM( maxPbufferPixels
);
974 MATCH_MINIMUM( samples
);
976 MATCH_DONT_CARE( stereoMode
);
977 MATCH_EXACT( level
);
979 if ( ((a
->drawableType
& b
->drawableType
) == 0)
980 || ((a
->renderType
& b
->renderType
) == 0) ) {
985 /* There is a bug in a few of the XFree86 DDX drivers. They contain
986 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
987 * Technically speaking, it is a bug in the DDX driver, but there is
988 * enough of an installed base to work around the problem here. In any
989 * case, 0 is not a valid value of the transparent type, so we'll treat 0
990 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
991 * 0 from the server to be a match to maintain backward compatibility with
992 * the (broken) drivers.
995 if ( a
->transparentPixel
!= GLX_DONT_CARE
996 && a
->transparentPixel
!= 0 ) {
997 if ( a
->transparentPixel
== GLX_NONE
) {
998 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1001 MATCH_EXACT( transparentPixel
);
1004 switch ( a
->transparentPixel
) {
1005 case GLX_TRANSPARENT_RGB
:
1006 MATCH_DONT_CARE( transparentRed
);
1007 MATCH_DONT_CARE( transparentGreen
);
1008 MATCH_DONT_CARE( transparentBlue
);
1009 MATCH_DONT_CARE( transparentAlpha
);
1012 case GLX_TRANSPARENT_INDEX
:
1013 MATCH_DONT_CARE( transparentIndex
);
1025 /* There's some trickly language in the GLX spec about how this is supposed
1026 * to work. Basically, if a given component size is either not specified
1027 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1028 * Well, that's really hard to do with the code as-is. This behavior is
1029 * closer to correct, but still not technically right.
1031 #define PREFER_LARGER_OR_ZERO(comp) \
1033 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1034 if ( ((*a)-> comp) == 0 ) { \
1037 else if ( ((*b)-> comp) == 0 ) { \
1041 return ((*b)-> comp) - ((*a)-> comp) ; \
1046 #define PREFER_LARGER(comp) \
1048 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1049 return ((*b)-> comp) - ((*a)-> comp) ; \
1053 #define PREFER_SMALLER(comp) \
1055 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1056 return ((*a)-> comp) - ((*b)-> comp) ; \
1061 * Compare two GLXFBConfigs. This function is intended to be used as the
1062 * compare function passed in to qsort.
1064 * \returns If \c a is a "better" config, according to the specification of
1065 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1066 * better, then a number greater than zero is return. If both are
1067 * equal, zero is returned.
1068 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1071 fbconfig_compare( const __GLcontextModes
* const * const a
,
1072 const __GLcontextModes
* const * const b
)
1074 /* The order of these comparisons must NOT change. It is defined by
1075 * the GLX 1.3 spec and ARB_multisample.
1078 PREFER_SMALLER( visualSelectGroup
);
1080 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1081 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1082 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1084 PREFER_SMALLER( visualRating
);
1086 /* This isn't quite right. It is supposed to compare the sum of the
1087 * components the user specifically set minimums for.
1089 PREFER_LARGER_OR_ZERO( redBits
);
1090 PREFER_LARGER_OR_ZERO( greenBits
);
1091 PREFER_LARGER_OR_ZERO( blueBits
);
1092 PREFER_LARGER_OR_ZERO( alphaBits
);
1094 PREFER_SMALLER( rgbBits
);
1096 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1097 /* Prefer single-buffer.
1099 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1102 PREFER_SMALLER( numAuxBuffers
);
1104 PREFER_LARGER_OR_ZERO( depthBits
);
1105 PREFER_SMALLER( stencilBits
);
1107 /* This isn't quite right. It is supposed to compare the sum of the
1108 * components the user specifically set minimums for.
1110 PREFER_LARGER_OR_ZERO( accumRedBits
);
1111 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1112 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1113 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1115 PREFER_SMALLER( visualType
);
1117 /* None of the multisample specs say where this comparison should happen,
1118 * so I put it near the end.
1120 PREFER_SMALLER( sampleBuffers
);
1121 PREFER_SMALLER( samples
);
1123 /* None of the pbuffer or fbconfig specs say that this comparison needs
1124 * to happen at all, but it seems like it should.
1126 PREFER_LARGER( maxPbufferWidth
);
1127 PREFER_LARGER( maxPbufferHeight
);
1128 PREFER_LARGER( maxPbufferPixels
);
1135 * Selects and sorts a subset of the supplied configs based on the attributes.
1136 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1137 * and \c glXChooseFBConfigSGIX.
1139 * \param configs Array of pointers to possible configs. The elements of
1140 * this array that do not meet the criteria will be set to
1141 * NULL. The remaining elements will be sorted according to
1142 * the various visual / FBConfig selection rules.
1143 * \param num_configs Number of elements in the \c configs array.
1144 * \param attribList Attributes used select from \c configs. This array is
1145 * terminated by a \c None tag. The array can either take
1146 * the form expected by \c glXChooseVisual (where boolean
1147 * tags do not have a value) or by \c glXChooseFBConfig
1148 * (where every tag has a value).
1149 * \param fbconfig_style_tags Selects whether \c attribList is in
1150 * \c glXChooseVisual style or
1151 * \c glXChooseFBConfig style.
1152 * \returns The number of valid elements left in \c configs.
1154 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1157 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1158 const int *attribList
, GLboolean fbconfig_style_tags
)
1160 __GLcontextModes test_config
;
1164 /* This is a fairly direct implementation of the selection method
1165 * described by GLX_SGIX_fbconfig. Start by culling out all the
1166 * configs that are not compatible with the selected parameter
1170 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1171 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1172 (const INT32
*) attribList
,
1173 GL_TRUE
, fbconfig_style_tags
);
1176 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1177 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1178 configs
[ base
] = configs
[ i
];
1187 if ( base
< num_configs
) {
1188 (void) memset( & configs
[ base
], 0,
1189 sizeof( void * ) * (num_configs
- base
) );
1192 /* After the incompatible configs are removed, the resulting
1193 * list is sorted according to the rules set out in the various
1197 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1198 (int (*)(const void*, const void*)) fbconfig_compare
);
1206 ** Return the visual that best matches the template. Return None if no
1207 ** visual matches the template.
1209 PUBLIC XVisualInfo
*GLX_PREFIX(glXChooseVisual
)(Display
*dpy
, int screen
,
1212 XVisualInfo
*visualList
= NULL
;
1213 __GLXdisplayPrivate
*priv
;
1214 __GLXscreenConfigs
*psc
;
1215 __GLcontextModes test_config
;
1216 __GLcontextModes
*modes
;
1217 const __GLcontextModes
*best_config
= NULL
;
1220 ** Get a list of all visuals, return if list is empty
1222 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1228 ** Build a template from the defaults and the attribute list
1229 ** Free visual list and return if an unexpected token is encountered
1231 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1232 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1233 (const INT32
*) attribList
,
1234 GL_TRUE
, GL_FALSE
);
1237 ** Eliminate visuals that don't meet minimum requirements
1238 ** Compute a score for those that do
1239 ** Remember which visual, if any, got the highest score
1241 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
1242 if ( fbconfigs_compatible( & test_config
, modes
)
1243 && ((best_config
== NULL
)
1244 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1245 best_config
= modes
;
1250 ** If no visual is acceptable, return None
1251 ** Otherwise, create an XVisualInfo list with just the selected X visual
1254 if (best_config
!= NULL
) {
1255 XVisualInfo visualTemplate
;
1258 visualTemplate
.screen
= screen
;
1259 visualTemplate
.visualid
= best_config
->visualID
;
1260 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1261 &visualTemplate
, &i
);
1268 PUBLIC
const char *GLX_PREFIX(glXQueryExtensionsString
)( Display
*dpy
,
1271 __GLXscreenConfigs
*psc
;
1272 __GLXdisplayPrivate
*priv
;
1274 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1278 if (!psc
->effectiveGLXexts
) {
1279 if (!psc
->serverGLXexts
) {
1280 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1281 X_GLXQueryServerString
,
1282 screen
, GLX_EXTENSIONS
);
1285 __glXCalculateUsableExtensions(psc
,
1286 #ifdef GLX_DIRECT_RENDERING
1287 (priv
->driDisplay
.private != NULL
),
1291 priv
->minorVersion
);
1294 return psc
->effectiveGLXexts
;
1297 PUBLIC
const char *GLX_PREFIX(glXGetClientString
)( Display
*dpy
, int name
)
1301 return (__glXGLXClientVendorName
);
1303 return (__glXGLXClientVersion
);
1304 case GLX_EXTENSIONS
:
1305 return (__glXGetClientExtensions());
1311 PUBLIC
const char *GLX_PREFIX(glXQueryServerString
)( Display
*dpy
, int screen
,
1314 __GLXscreenConfigs
*psc
;
1315 __GLXdisplayPrivate
*priv
;
1319 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1325 str
= & priv
->serverGLXvendor
;
1328 str
= & priv
->serverGLXversion
;
1330 case GLX_EXTENSIONS
:
1331 str
= & psc
->serverGLXexts
;
1337 if ( *str
== NULL
) {
1338 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1339 X_GLXQueryServerString
, screen
, name
);
1345 void __glXClientInfo ( Display
*dpy
, int opcode
)
1347 xGLXClientInfoReq
*req
;
1349 char * ext_str
= __glXGetClientGLExtensionString();
1351 /* Send the glXClientInfo request */
1353 GetReq(GLXClientInfo
,req
);
1354 req
->reqType
= opcode
;
1355 req
->glxCode
= X_GLXClientInfo
;
1356 req
->major
= GLX_MAJOR_VERSION
;
1357 req
->minor
= GLX_MINOR_VERSION
;
1359 size
= strlen( ext_str
) + 1;
1360 req
->length
+= (size
+ 3) >> 2;
1361 req
->numbytes
= size
;
1362 Data(dpy
, ext_str
, size
);
1372 ** EXT_import_context
1375 PUBLIC Display
*glXGetCurrentDisplay(void)
1377 GLXContext gc
= __glXGetCurrentContext();
1378 if (NULL
== gc
) return NULL
;
1379 return gc
->currentDpy
;
1382 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1383 glXGetCurrentDisplay
)
1386 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1389 * \param dpy Display where \c ctx was created.
1390 * \param ctx Context to query.
1391 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1392 * or zero if the request failed due to internal problems (i.e.,
1393 * unable to allocate temporary memory, etc.)
1396 * This function dynamically determines whether to use the EXT_import_context
1397 * version of the protocol or the GLX 1.3 version of the protocol.
1399 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1401 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1402 xGLXQueryContextReply reply
;
1408 return GLX_BAD_CONTEXT
;
1410 opcode
= __glXSetupForCommand(dpy
);
1415 /* Send the glXQueryContextInfoEXT request */
1418 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1419 xGLXQueryContextReq
*req
;
1421 GetReq(GLXQueryContext
, req
);
1423 req
->reqType
= opcode
;
1424 req
->glxCode
= X_GLXQueryContext
;
1425 req
->context
= (unsigned int)(ctx
->xid
);
1428 xGLXVendorPrivateReq
*vpreq
;
1429 xGLXQueryContextInfoEXTReq
*req
;
1431 GetReqExtra( GLXVendorPrivate
,
1432 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1434 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1435 req
->reqType
= opcode
;
1436 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1437 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1438 req
->context
= (unsigned int)(ctx
->xid
);
1441 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1443 numValues
= reply
.n
;
1446 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1450 int *propList
, *pProp
;
1454 nPropListBytes
= numValues
<< 3;
1455 propList
= (int *) Xmalloc(nPropListBytes
);
1456 if (NULL
== propList
) {
1459 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1461 for (i
=0; i
< numValues
; i
++) {
1463 case GLX_SHARE_CONTEXT_EXT
:
1464 ctx
->share_xid
= *pProp
++;
1466 case GLX_VISUAL_ID_EXT
:
1467 ctx
->vid
= *pProp
++;
1470 ctx
->screen
= *pProp
++;
1472 case GLX_FBCONFIG_ID
:
1473 ctx
->fbconfigID
= *pProp
++;
1475 case GLX_RENDER_TYPE
:
1476 ctx
->renderType
= *pProp
++;
1483 Xfree((char *)propList
);
1493 GLX_PREFIX(glXQueryContext
)(Display
*dpy
, GLXContext ctx
,
1494 int attribute
, int *value
)
1498 /* get the information from the server if we don't have it already */
1499 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1500 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1501 if (Success
!= retVal
) return retVal
;
1503 switch (attribute
) {
1504 case GLX_SHARE_CONTEXT_EXT
:
1505 *value
= (int)(ctx
->share_xid
);
1507 case GLX_VISUAL_ID_EXT
:
1508 *value
= (int)(ctx
->vid
);
1511 *value
= (int)(ctx
->screen
);
1513 case GLX_FBCONFIG_ID
:
1514 *value
= (int)(ctx
->fbconfigID
);
1516 case GLX_RENDER_TYPE
:
1517 *value
= (int)(ctx
->renderType
);
1520 return GLX_BAD_ATTRIBUTE
;
1525 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1526 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1527 (dpy
, ctx
, attribute
, value
),
1530 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1535 PUBLIC GLXContext
GLX_PREFIX(glXImportContextEXT
)(Display
*dpy
,
1536 GLXContextID contextID
)
1540 if (contextID
== None
) {
1543 if (__glXIsDirect(dpy
, contextID
)) {
1547 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1549 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1556 PUBLIC
void GLX_PREFIX(glXFreeContextEXT
)(Display
*dpy
, GLXContext ctx
)
1558 DestroyContext(dpy
, ctx
);
1564 * GLX 1.3 functions - these are just stubs for now!
1567 PUBLIC GLXFBConfig
*GLX_PREFIX(glXChooseFBConfig
)(Display
*dpy
, int screen
,
1568 const int *attribList
,
1571 __GLcontextModes
** config_list
;
1575 config_list
= (__GLcontextModes
**)
1576 GLX_PREFIX(glXGetFBConfigs
)( dpy
, screen
, & list_size
);
1578 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1579 list_size
= choose_visual( config_list
, list_size
, attribList
,
1581 if ( list_size
== 0 ) {
1582 XFree( config_list
);
1587 *nitems
= list_size
;
1588 return (GLXFBConfig
*) config_list
;
1592 PUBLIC GLXContext
GLX_PREFIX(glXCreateNewContext
)(Display
*dpy
,
1595 GLXContext shareList
,
1598 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1599 allowDirect
, None
, True
, renderType
);
1603 PUBLIC GLXDrawable
GLX_PREFIX(glXGetCurrentReadDrawable
)(void)
1605 GLXContext gc
= __glXGetCurrentContext();
1606 return gc
->currentReadable
;
1610 PUBLIC GLXFBConfig
*GLX_PREFIX(glXGetFBConfigs
)(Display
*dpy
, int screen
,
1613 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1614 __GLcontextModes
** config
= NULL
;
1617 if ( (priv
->screenConfigs
!= NULL
)
1618 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1619 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1620 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1621 unsigned num_configs
= 0;
1622 __GLcontextModes
* modes
;
1625 for ( modes
= priv
->screenConfigs
[screen
].configs
1627 ; modes
= modes
->next
) {
1628 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1633 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1635 if ( config
!= NULL
) {
1636 *nelements
= num_configs
;
1638 for ( modes
= priv
->screenConfigs
[screen
].configs
1640 ; modes
= modes
->next
) {
1646 return (GLXFBConfig
*) config
;
1650 PUBLIC
int GLX_PREFIX(glXGetFBConfigAttrib
)(Display
*dpy
, GLXFBConfig config
,
1651 int attribute
, int *value
)
1653 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1655 return (modes
!= NULL
)
1656 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1661 PUBLIC XVisualInfo
*GLX_PREFIX(glXGetVisualFromFBConfig
)(Display
*dpy
,
1664 XVisualInfo visualTemplate
;
1665 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1669 ** Get a list of all visuals, return if list is empty
1671 visualTemplate
.visualid
= fbconfig
->visualID
;
1672 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1677 ** GLX_SGI_make_current_read
1680 PUBLIC
GLX_ALIAS(GLXDrawable
, glXGetCurrentReadDrawableSGI
, (void), (),
1681 glXGetCurrentReadDrawable
)
1685 ** GLX_SGI_swap_control
1687 PUBLIC
int GLX_PREFIX(glXSwapIntervalSGI
)(int interval
)
1689 xGLXVendorPrivateReq
*req
;
1690 GLXContext gc
= __glXGetCurrentContext();
1692 CARD32
* interval_ptr
;
1696 return GLX_BAD_CONTEXT
;
1699 if ( interval
<= 0 ) {
1700 return GLX_BAD_VALUE
;
1703 #ifdef GLX_DIRECT_RENDERING
1704 if ( gc
->isDirect
) {
1705 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1707 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1708 gc
->currentDrawable
,
1710 if ( __glXExtensionBitIsEnabled( psc
, SGI_swap_control_bit
)
1711 && (pdraw
!= NULL
) ) {
1712 pdraw
->swap_interval
= interval
;
1716 return GLX_BAD_CONTEXT
;
1720 dpy
= gc
->currentDpy
;
1721 opcode
= __glXSetupForCommand(dpy
);
1726 /* Send the glXSwapIntervalSGI request */
1728 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1729 req
->reqType
= opcode
;
1730 req
->glxCode
= X_GLXVendorPrivate
;
1731 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1732 req
->contextTag
= gc
->currentContextTag
;
1734 interval_ptr
= (CARD32
*) req
+ 1;
1735 *interval_ptr
= interval
;
1746 ** GLX_MESA_swap_control
1748 PUBLIC GLint
GLX_PREFIX(glXSwapIntervalMESA
)(unsigned interval
)
1750 #ifdef GLX_DIRECT_RENDERING
1751 GLXContext gc
= __glXGetCurrentContext();
1753 if ( interval
< 0 ) {
1754 return GLX_BAD_VALUE
;
1757 if ( (gc
!= NULL
) && gc
->isDirect
) {
1758 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1761 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1762 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1763 __DRIdrawable
* const pdraw
=
1764 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1765 gc
->currentDrawable
,
1766 psc
->driScreen
.private);
1767 if ( pdraw
!= NULL
) {
1768 pdraw
->swap_interval
= interval
;
1777 return GLX_BAD_CONTEXT
;
1780 PUBLIC GLint
GLX_PREFIX(glXGetSwapIntervalMESA
)( void )
1782 #ifdef GLX_DIRECT_RENDERING
1783 GLXContext gc
= __glXGetCurrentContext();
1785 if ( (gc
!= NULL
) && gc
->isDirect
) {
1786 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1789 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1790 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1791 __DRIdrawable
* const pdraw
=
1792 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1793 gc
->currentDrawable
,
1794 psc
->driScreen
.private);
1795 if ( pdraw
!= NULL
) {
1796 return pdraw
->swap_interval
;
1807 ** GLX_MESA_swap_frame_usage
1810 PUBLIC GLint
GLX_PREFIX(glXBeginFrameTrackingMESA
)(Display
*dpy
,
1811 GLXDrawable drawable
)
1813 int status
= GLX_BAD_CONTEXT
;
1814 #ifdef GLX_DIRECT_RENDERING
1816 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1817 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1819 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1820 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1821 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_TRUE
);
1831 PUBLIC GLint
GLX_PREFIX(glXEndFrameTrackingMESA
)(Display
*dpy
,
1832 GLXDrawable drawable
)
1834 int status
= GLX_BAD_CONTEXT
;
1835 #ifdef GLX_DIRECT_RENDERING
1837 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1838 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1840 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1841 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1842 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_FALSE
);
1852 PUBLIC GLint
GLX_PREFIX(glXGetFrameUsageMESA
)(Display
*dpy
,
1853 GLXDrawable drawable
,
1856 int status
= GLX_BAD_CONTEXT
;
1857 #ifdef GLX_DIRECT_RENDERING
1859 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1860 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1862 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1863 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1864 int64_t sbc
, missedFrames
;
1865 float lastMissedUsage
;
1867 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, &sbc
,
1868 &missedFrames
, &lastMissedUsage
,
1880 PUBLIC GLint
GLX_PREFIX(glXQueryFrameTrackingMESA
)(Display
*dpy
,
1881 GLXDrawable drawable
,
1883 int64_t *missedFrames
,
1884 GLfloat
*lastMissedUsage
)
1886 int status
= GLX_BAD_CONTEXT
;
1887 #ifdef GLX_DIRECT_RENDERING
1889 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1890 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1892 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1893 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1896 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, sbc
,
1897 missedFrames
, lastMissedUsage
,
1904 (void) missedFrames
;
1905 (void) lastMissedUsage
;
1912 ** GLX_SGI_video_sync
1914 PUBLIC
int GLX_PREFIX(glXGetVideoSyncSGI
)(unsigned int *count
)
1916 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1917 * FIXME: there should be a GLX encoding for this call. I can find no
1918 * FIXME: documentation for the GLX encoding.
1920 #ifdef GLX_DIRECT_RENDERING
1921 GLXContext gc
= __glXGetCurrentContext();
1924 if ( (gc
!= NULL
) && gc
->isDirect
) {
1925 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1927 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
1928 && psc
->driScreen
.private && psc
->driScreen
.getMSC
) {
1932 ret
= psc
->driScreen
.getMSC( psc
->driScreen
.private, & temp
);
1933 *count
= (unsigned) temp
;
1934 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1940 return GLX_BAD_CONTEXT
;
1943 PUBLIC
int GLX_PREFIX(glXWaitVideoSyncSGI
)(int divisor
, int remainder
,
1944 unsigned int *count
)
1946 #ifdef GLX_DIRECT_RENDERING
1947 GLXContext gc
= __glXGetCurrentContext();
1949 if ( divisor
<= 0 || remainder
< 0 )
1950 return GLX_BAD_VALUE
;
1952 if ( (gc
!= NULL
) && gc
->isDirect
) {
1953 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1955 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
1956 && psc
->driScreen
.private ) {
1957 __DRIdrawable
* const pdraw
=
1958 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1959 gc
->currentDrawable
,
1960 psc
->driScreen
.private);
1961 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
) ) {
1966 ret
= (*pdraw
->waitForMSC
)( gc
->currentDpy
, pdraw
->private,
1967 0, divisor
, remainder
,
1969 *count
= (unsigned) msc
;
1970 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1977 return GLX_BAD_CONTEXT
;
1982 ** GLX_SGIS_video_source
1986 PUBLIC GLXVideoSourceSGIX
GLX_PREFIX(glXCreateGLXVideoSourceSGIX
)(Display
*dpy
,
1987 int screen
, VLServer server
, VLPath path
,
1988 int nodeClass
, VLNode drainNode
)
1999 PUBLIC
void GLX_PREFIX(glXDestroyGLXVideoSourceSGIX
)(Display
*dpy
,
2000 GLXVideoSourceSGIX src
)
2010 ** GLX_SGIX_fbconfig
2011 ** Many of these functions are aliased to GLX 1.3 entry points in the
2012 ** GLX_functions table.
2015 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2016 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2017 (dpy
, config
, attribute
, value
),
2018 glXGetFBConfigAttrib
)
2020 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2021 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2022 (dpy
, screen
, attrib_list
, nelements
),
2025 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2026 (Display
* dpy
, GLXFBConfigSGIX config
),
2028 glXGetVisualFromFBConfig
)
2030 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapWithConfigSGIX
)(Display
*dpy
,
2031 GLXFBConfigSGIX config
, Pixmap pixmap
)
2033 xGLXVendorPrivateWithReplyReq
*vpreq
;
2034 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2035 GLXPixmap xid
= None
;
2037 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2038 __GLXscreenConfigs
* psc
;
2041 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2045 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2047 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2048 opcode
= __glXSetupForCommand(dpy
);
2053 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2055 GetReqExtra(GLXVendorPrivateWithReply
,
2056 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2057 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2058 req
->reqType
= opcode
;
2059 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2060 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2061 req
->screen
= fbconfig
->screen
;
2062 req
->fbconfig
= fbconfig
->fbconfigID
;
2063 req
->pixmap
= pixmap
;
2064 req
->glxpixmap
= xid
= XAllocID(dpy
);
2072 PUBLIC GLXContext
GLX_PREFIX(glXCreateContextWithConfigSGIX
)(Display
*dpy
,
2073 GLXFBConfigSGIX config
, int renderType
,
2074 GLXContext shareList
, Bool allowDirect
)
2076 GLXContext gc
= NULL
;
2077 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2078 __GLXscreenConfigs
* psc
;
2081 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2085 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2087 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2088 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2089 allowDirect
, None
, False
, renderType
);
2096 PUBLIC GLXFBConfigSGIX
GLX_PREFIX(glXGetFBConfigFromVisualSGIX
)(Display
*dpy
,
2099 __GLXdisplayPrivate
*priv
;
2100 __GLXscreenConfigs
*psc
;
2102 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2103 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2104 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2105 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2116 PUBLIC
void GLX_PREFIX(glXCushionSGI
)(Display
*dpy
, Window win
, float cushion
)
2125 ** GLX_SGIX_video_resize
2127 PUBLIC
int GLX_PREFIX(glXBindChannelToWindowSGIX
)(Display
*dpy
, int screen
,
2128 int channel
, Window window
)
2137 PUBLIC
int GLX_PREFIX(glXChannelRectSGIX
)(Display
*dpy
, int screen
, int channel
,
2138 int x
, int y
, int w
, int h
)
2150 PUBLIC
int GLX_PREFIX(glXQueryChannelRectSGIX
)(Display
*dpy
, int screen
,
2151 int channel
, int *x
, int *y
,
2164 int GLX_PREFIX(glXQueryChannelDeltasSGIX
)(Display
*dpy
, int screen
, int channel
,
2165 int *dx
, int *dy
, int *dw
, int *dh
)
2177 PUBLIC
int GLX_PREFIX(glXChannelRectSyncSGIX
)(Display
*dpy
, int screen
,
2178 int channel
, GLenum synctype
)
2188 #if defined(_DM_BUFFER_H_)
2190 PUBLIC Bool
GLX_PREFIX(glXAssociateDMPbufferSGIX
)(Display
*dpy
,
2191 GLXPbufferSGIX pbuffer
,
2206 ** GLX_SGIX_swap_group
2208 PUBLIC
void GLX_PREFIX(glXJoinSwapGroupSGIX
)(Display
*dpy
, GLXDrawable drawable
,
2218 ** GLX_SGIX_swap_barrier
2220 PUBLIC
void GLX_PREFIX(glXBindSwapBarrierSGIX
)(Display
*dpy
,
2221 GLXDrawable drawable
,
2229 PUBLIC Bool
GLX_PREFIX(glXQueryMaxSwapBarriersSGIX
)(Display
*dpy
, int screen
,
2240 ** GLX_SUN_get_transparent_index
2242 PUBLIC Status
GLX_PREFIX(glXGetTransparentIndexSUN
)(Display
*dpy
,
2250 (void) pTransparent
;
2256 ** GLX_OML_sync_control
2258 PUBLIC Bool
GLX_PREFIX(glXGetSyncValuesOML
)(Display
*dpy
, GLXDrawable drawable
,
2259 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2261 #ifdef GLX_DIRECT_RENDERING
2262 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2264 if ( priv
!= NULL
) {
2266 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2267 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2269 assert( (pdraw
== NULL
) || (i
!= -1) );
2270 return ( (pdraw
&& pdraw
->getSBC
&& psc
->driScreen
.getMSC
)
2271 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)
2272 && ((*psc
->driScreen
.getMSC
)( psc
->driScreen
.private, msc
) == 0)
2273 && ((*pdraw
->getSBC
)( dpy
, psc
->driScreen
.private, sbc
) == 0)
2274 && (__glXGetUST( ust
) == 0) );
2288 * Determine the refresh rate of the specified drawable and display.
2290 * \param dpy Display whose refresh rate is to be determined.
2291 * \param drawable Drawable whose refresh rate is to be determined.
2292 * \param numerator Numerator of the refresh rate.
2293 * \param demoninator Denominator of the refresh rate.
2294 * \return If the refresh rate for the specified display and drawable could
2295 * be calculated, True is returned. Otherwise False is returned.
2297 * \note This function is implemented entirely client-side. A lot of other
2298 * functionality is required to export GLX_OML_sync_control, so on
2299 * XFree86 this function can be called for direct-rendering contexts
2300 * when GLX_OML_sync_control appears in the client extension string.
2303 PUBLIC Bool
GLX_PREFIX(glXGetMscRateOML
)(Display
* dpy
, GLXDrawable drawable
,
2304 int32_t * numerator
, int32_t * denominator
)
2306 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2307 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2310 if ( priv
!= NULL
) {
2311 XF86VidModeModeLine mode_line
;
2317 GetDRIDrawable( dpy
, drawable
, & screen_num
);
2318 if ( (screen_num
!= -1)
2319 && XF86VidModeQueryVersion( dpy
, & i
, & i
)
2320 && XF86VidModeGetModeLine( dpy
, screen_num
, & dot_clock
,
2322 unsigned n
= dot_clock
* 1000;
2323 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2325 # define V_INTERLACE 0x010
2326 # define V_DBLSCAN 0x020
2328 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2331 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2335 /* The OML_sync_control spec requires that if the refresh rate is a
2336 * whole number, that the returned numerator be equal to the refresh
2337 * rate and the denominator be 1.
2340 if ( (n
% d
) == 0 ) {
2345 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2348 /* This is a poor man's way to reduce a fraction. It's far from
2349 * perfect, but it will work well enough for this situation.
2352 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2353 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2377 PUBLIC
int64_t GLX_PREFIX(glXSwapBuffersMscOML
)(Display
*dpy
,
2378 GLXDrawable drawable
,
2383 #ifdef GLX_DIRECT_RENDERING
2385 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2386 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2388 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2389 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2390 * of -1 if the function failed because of errors detected in the input
2393 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2395 if ( divisor
> 0 && remainder
>= divisor
)
2398 if ( (pdraw
!= NULL
) && (pdraw
->swapBuffersMSC
!= NULL
)
2399 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2400 return (*pdraw
->swapBuffersMSC
)(dpy
, pdraw
->private, target_msc
,
2401 divisor
, remainder
);
2414 PUBLIC Bool
GLX_PREFIX(glXWaitForMscOML
)(Display
* dpy
, GLXDrawable drawable
,
2415 int64_t target_msc
, int64_t divisor
,
2416 int64_t remainder
, int64_t *ust
,
2417 int64_t *msc
, int64_t *sbc
)
2419 #ifdef GLX_DIRECT_RENDERING
2421 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2422 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2425 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2426 * error", but the return type in the spec is Bool.
2428 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2430 if ( divisor
> 0 && remainder
>= divisor
)
2433 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
)
2434 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2435 ret
= (*pdraw
->waitForMSC
)( dpy
, pdraw
->private, target_msc
,
2436 divisor
, remainder
, msc
, sbc
);
2438 /* __glXGetUST returns zero on success and non-zero on failure.
2439 * This function returns True on success and False on failure.
2441 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2457 PUBLIC Bool
GLX_PREFIX(glXWaitForSbcOML
)(Display
* dpy
, GLXDrawable drawable
,
2458 int64_t target_sbc
, int64_t *ust
,
2459 int64_t *msc
, int64_t *sbc
)
2461 #ifdef GLX_DIRECT_RENDERING
2463 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2464 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2467 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2468 * error", but the return type in the spec is Bool.
2470 if ( target_sbc
< 0 )
2473 if ( (pdraw
!= NULL
) && (pdraw
->waitForSBC
!= NULL
)
2474 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)) {
2475 ret
= (*pdraw
->waitForSBC
)( dpy
, pdraw
->private, target_sbc
, msc
, sbc
);
2477 /* __glXGetUST returns zero on success and non-zero on failure.
2478 * This function returns True on success and False on failure.
2480 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2495 * GLX_MESA_allocate_memory
2499 PUBLIC
void *GLX_PREFIX(glXAllocateMemoryMESA
)(Display
*dpy
, int scrn
,
2500 size_t size
, float readFreq
,
2501 float writeFreq
, float priority
)
2503 #ifdef GLX_DIRECT_RENDERING
2504 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2506 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2507 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.allocateMemory
) {
2508 return (*psc
->driScreen
.allocateMemory
)( dpy
, scrn
, size
,
2509 readFreq
, writeFreq
,
2520 #endif /* GLX_DIRECT_RENDERING */
2526 PUBLIC
void GLX_PREFIX(glXFreeMemoryMESA
)(Display
*dpy
, int scrn
, void *pointer
)
2528 #ifdef GLX_DIRECT_RENDERING
2529 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2531 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2532 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.freeMemory
) {
2533 (*psc
->driScreen
.freeMemory
)( dpy
, scrn
, pointer
);
2540 #endif /* GLX_DIRECT_RENDERING */
2544 PUBLIC GLuint
GLX_PREFIX(glXGetMemoryOffsetMESA
)( Display
*dpy
, int scrn
,
2545 const void *pointer
)
2547 #ifdef GLX_DIRECT_RENDERING
2548 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2550 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2551 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.memoryOffset
) {
2552 return (*psc
->driScreen
.memoryOffset
)( dpy
, scrn
, pointer
);
2559 #endif /* GLX_DIRECT_RENDERING */
2567 * Mesa extension stubs. These will help reduce portability problems.
2572 * Release all buffers associated with the specified GLX drawable.
2575 * This function was intended for stand-alone Mesa. The issue there is that
2576 * the library doesn't get any notification when a window is closed. In
2577 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2578 * supported, there are 3 different functions to destroy a drawable. It
2579 * should be possible to create GLX protocol (or have it determine which
2580 * protocol to use based on the type of the drawable) to have one function
2581 * do the work of 3. For the direct-rendering case, this function could
2582 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2583 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2584 * would need to be used. This really should be done as part of the new DRI
2587 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2588 * __driGarbageCollectDrawables
2589 * glXDestroyGLXPixmap
2590 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2591 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2593 PUBLIC Bool
GLX_PREFIX(glXReleaseBuffersMESA
)( Display
*dpy
, GLXDrawable d
)
2601 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapMESA
)( Display
*dpy
,
2602 XVisualInfo
*visual
,
2614 PUBLIC
void GLX_PREFIX(glXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
,
2616 int width
, int height
)
2627 PUBLIC Bool
GLX_PREFIX(glXSet3DfxModeMESA
)( int mode
)
2637 * \c strdup is actually not a standard ANSI C or POSIX routine.
2638 * Irix will not define it if ANSI mode is in effect.
2643 __glXstrdup(const char *str
)
2646 copy
= (char *) Xmalloc(strlen(str
) + 1);
2654 ** glXGetProcAddress support
2657 struct name_address_pair
{
2662 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2663 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2665 static const struct name_address_pair GLX_functions
[] = {
2666 /*** GLX_VERSION_1_0 ***/
2667 GLX_FUNCTION( glXChooseVisual
),
2668 GLX_FUNCTION( glXCopyContext
),
2669 GLX_FUNCTION( glXCreateContext
),
2670 GLX_FUNCTION( glXCreateGLXPixmap
),
2671 GLX_FUNCTION( glXDestroyContext
),
2672 GLX_FUNCTION( glXDestroyGLXPixmap
),
2673 GLX_FUNCTION( glXGetConfig
),
2674 GLX_FUNCTION( glXGetCurrentContext
),
2675 GLX_FUNCTION( glXGetCurrentDrawable
),
2676 GLX_FUNCTION( glXIsDirect
),
2677 GLX_FUNCTION( glXMakeCurrent
),
2678 GLX_FUNCTION( glXQueryExtension
),
2679 GLX_FUNCTION( glXQueryVersion
),
2680 GLX_FUNCTION( glXSwapBuffers
),
2681 GLX_FUNCTION( glXUseXFont
),
2682 GLX_FUNCTION( glXWaitGL
),
2683 GLX_FUNCTION( glXWaitX
),
2685 /*** GLX_VERSION_1_1 ***/
2686 GLX_FUNCTION( glXGetClientString
),
2687 GLX_FUNCTION( glXQueryExtensionsString
),
2688 GLX_FUNCTION( glXQueryServerString
),
2690 /*** GLX_VERSION_1_2 ***/
2691 GLX_FUNCTION( glXGetCurrentDisplay
),
2693 /*** GLX_VERSION_1_3 ***/
2694 GLX_FUNCTION( glXChooseFBConfig
),
2695 GLX_FUNCTION( glXCreateNewContext
),
2696 GLX_FUNCTION( glXCreatePbuffer
),
2697 GLX_FUNCTION( glXCreatePixmap
),
2698 GLX_FUNCTION( glXCreateWindow
),
2699 GLX_FUNCTION( glXDestroyPbuffer
),
2700 GLX_FUNCTION( glXDestroyPixmap
),
2701 GLX_FUNCTION( glXDestroyWindow
),
2702 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2703 GLX_FUNCTION( glXGetFBConfigAttrib
),
2704 GLX_FUNCTION( glXGetFBConfigs
),
2705 GLX_FUNCTION( glXGetSelectedEvent
),
2706 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2707 GLX_FUNCTION( glXMakeContextCurrent
),
2708 GLX_FUNCTION( glXQueryContext
),
2709 GLX_FUNCTION( glXQueryDrawable
),
2710 GLX_FUNCTION( glXSelectEvent
),
2712 /*** GLX_SGI_swap_control ***/
2713 GLX_FUNCTION( glXSwapIntervalSGI
),
2715 /*** GLX_SGI_video_sync ***/
2716 GLX_FUNCTION( glXGetVideoSyncSGI
),
2717 GLX_FUNCTION( glXWaitVideoSyncSGI
),
2719 /*** GLX_SGI_make_current_read ***/
2720 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2721 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2723 /*** GLX_SGIX_video_source ***/
2725 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX
),
2726 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX
),
2729 /*** GLX_EXT_import_context ***/
2730 GLX_FUNCTION( glXFreeContextEXT
),
2731 GLX_FUNCTION( glXGetContextIDEXT
),
2732 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2733 GLX_FUNCTION( glXImportContextEXT
),
2734 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2736 /*** GLX_SGIX_fbconfig ***/
2737 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2738 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2739 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2740 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2741 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2742 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2744 /*** GLX_SGIX_pbuffer ***/
2745 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2746 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2747 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2748 GLX_FUNCTION( glXSelectEventSGIX
),
2749 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2751 /*** GLX_SGI_cushion ***/
2752 GLX_FUNCTION( glXCushionSGI
),
2754 /*** GLX_SGIX_video_resize ***/
2755 GLX_FUNCTION( glXBindChannelToWindowSGIX
),
2756 GLX_FUNCTION( glXChannelRectSGIX
),
2757 GLX_FUNCTION( glXQueryChannelRectSGIX
),
2758 GLX_FUNCTION( glXQueryChannelDeltasSGIX
),
2759 GLX_FUNCTION( glXChannelRectSyncSGIX
),
2761 /*** GLX_SGIX_dmbuffer **/
2762 #if defined(_DM_BUFFER_H_)
2763 GLX_FUNCTION( glXAssociateDMPbufferSGIX
),
2766 /*** GLX_SGIX_swap_group ***/
2767 GLX_FUNCTION( glXJoinSwapGroupSGIX
),
2769 /*** GLX_SGIX_swap_barrier ***/
2770 GLX_FUNCTION( glXBindSwapBarrierSGIX
),
2771 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX
),
2773 /*** GLX_SUN_get_transparent_index ***/
2774 GLX_FUNCTION( glXGetTransparentIndexSUN
),
2776 /*** GLX_MESA_allocate_memory ***/
2777 GLX_FUNCTION( glXAllocateMemoryMESA
),
2778 GLX_FUNCTION( glXFreeMemoryMESA
),
2779 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2781 /*** GLX_MESA_copy_sub_buffer ***/
2782 GLX_FUNCTION( glXCopySubBufferMESA
),
2784 /*** GLX_MESA_pixmap_colormap ***/
2785 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2787 /*** GLX_MESA_release_buffers ***/
2788 GLX_FUNCTION( glXReleaseBuffersMESA
),
2790 /*** GLX_MESA_set_3dfx_mode ***/
2791 GLX_FUNCTION( glXSet3DfxModeMESA
),
2793 /*** GLX_MESA_swap_control ***/
2794 GLX_FUNCTION( glXSwapIntervalMESA
),
2795 GLX_FUNCTION( glXGetSwapIntervalMESA
),
2797 /*** GLX_MESA_swap_frame_usage ***/
2798 GLX_FUNCTION( glXBeginFrameTrackingMESA
),
2799 GLX_FUNCTION( glXEndFrameTrackingMESA
),
2800 GLX_FUNCTION( glXGetFrameUsageMESA
),
2801 GLX_FUNCTION( glXQueryFrameTrackingMESA
),
2803 /*** GLX_ARB_get_proc_address ***/
2804 GLX_FUNCTION( glXGetProcAddressARB
),
2807 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2809 /*** GLX_OML_sync_control ***/
2810 GLX_FUNCTION( glXWaitForSbcOML
),
2811 GLX_FUNCTION( glXWaitForMscOML
),
2812 GLX_FUNCTION( glXSwapBuffersMscOML
),
2813 GLX_FUNCTION( glXGetMscRateOML
),
2814 GLX_FUNCTION( glXGetSyncValuesOML
),
2816 #ifdef GLX_DIRECT_RENDERING
2818 *** Internal functions useful to DRI drivers
2819 *** With this, the DRI drivers shouldn't need dlopen()/dlsym() to
2820 *** access internal libGL functions which may or may not exist.
2822 GLX_FUNCTION( __glXInitialize
),
2823 GLX_FUNCTION( __glXFindDRIScreen
),
2824 GLX_FUNCTION( __glXGetInternalVersion
),
2825 GLX_FUNCTION( __glXWindowExists
),
2826 GLX_FUNCTION2( __glXCreateContextWithConfig
, XF86DRICreateContextWithConfig
),
2827 GLX_FUNCTION2( __glXGetDrawableInfo
, XF86DRIGetDrawableInfo
),
2829 /*** DRI configuration ***/
2830 GLX_FUNCTION( glXGetScreenDriver
),
2831 GLX_FUNCTION( glXGetDriverConfig
),
2833 GLX_FUNCTION( __glXScrEnableExtension
),
2835 GLX_FUNCTION( __glXGetUST
),
2837 GLX_FUNCTION2( __glXCreateContextModes
, _gl_context_modes_create
),
2838 GLX_FUNCTION2( __glXDestroyContextModes
, _gl_context_modes_destroy
),
2841 { NULL
, NULL
} /* end of list */
2845 static const GLvoid
*
2846 get_glx_proc_address(const char *funcName
)
2850 /* try static functions */
2851 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2852 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2853 return GLX_functions
[i
].Address
;
2860 #ifndef GLX_BUILT_IN_XMESA
2862 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2863 * \c glXGetProcAddress.
2865 * \param procName Name of a GL or GLX function.
2866 * \returns A pointer to the named function
2868 * \sa glXGetProcAddress
2870 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2872 typedef void (*gl_function
)( void );
2876 /* Search the table of GLX and internal functions first. If that
2877 * fails and the supplied name could be a valid core GL name, try
2878 * searching the core GL function table. This check is done to prevent
2879 * DRI based drivers from searching the core GL function table for
2880 * internal API functions.
2883 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2884 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2885 && (procName
[2] != 'X') ) {
2886 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2893 * Get the address of a named GL function. This is the GLX 1.4 name for
2894 * \c glXGetProcAddressARB.
2896 * \param procName Name of a GL or GLX function.
2897 * \returns A pointer to the named function
2899 * \sa glXGetProcAddressARB
2901 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2902 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2903 __attribute__ ((alias ("glXGetProcAddressARB")));
2906 return glXGetProcAddressARB(procName
);
2908 #endif /* __GNUC__ */
2909 #endif /* GLX_BUILT_IN_XMESA */
2912 #ifdef GLX_DIRECT_RENDERING
2914 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2915 * might be used by the DRI drivers to determine how new libGL is at runtime.
2916 * Drivers should not call this function directly. They should instead use
2917 * \c glXGetProcAddress to obtain a pointer to the function.
2919 * \returns An 8-digit decimal number representing the internal libGL API in
2922 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2924 * \since Internal API version 20021121.
2926 int __glXGetInternalVersion(void)
2929 * 20021121 - Initial version
2930 * 20021128 - Added __glXWindowExists() function
2931 * 20021207 - Added support for dynamic GLX extensions,
2932 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2933 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2934 * Never officially released. Do NOT test against
2935 * this version. Use 20030317 instead.
2936 * 20030317 - Added support GLX_SGIX_fbconfig,
2937 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2938 * GLX_{ARB,SGIS}_multisample, and
2939 * GLX_SGIX_visual_select_group.
2940 * 20030606 - Added support for GLX_SGI_make_current_read.
2941 * 20030813 - Made support for dynamic extensions multi-head aware.
2942 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2943 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2945 * 20031201 - Added support for the first round of DRI interface changes.
2946 * Do NOT test against this version! It has binary
2947 * compatibility bugs, use 20040317 instead.
2948 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2949 * 20040415 - Added support for bindContext3 and unbindContext3.
2950 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2952 * 20050722 - Gut all the old interfaces. This breaks compatability with
2953 * any DRI driver built to any previous version.
2960 static Bool windowExistsFlag
;
2962 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
2964 if (xerr
->error_code
== BadWindow
) {
2965 windowExistsFlag
= GL_FALSE
;
2971 * Determine if a window associated with a \c GLXDrawable exists on the
2972 * X-server. This function is not used internally by libGL. It is provided
2973 * as a utility function for DRI drivers.
2974 * Drivers should not call this function directly. They should instead use
2975 * \c glXGetProcAddress to obtain a pointer to the function.
2977 * \param dpy Display associated with the drawable to be queried.
2978 * \param draw \c GLXDrawable to test.
2980 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
2981 * otherwise \c GL_FALSE is returned.
2983 * \warning This function is not currently thread-safe.
2985 * \sa glXGetProcAddress
2987 * \since Internal API version 20021128.
2989 static Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
)
2991 XWindowAttributes xwa
;
2992 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
2994 XSync(dpy
, GL_FALSE
);
2995 windowExistsFlag
= GL_TRUE
;
2996 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
2997 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
2998 XSetErrorHandler(oldXErrorHandler
);
2999 return windowExistsFlag
;
3004 * Get the unadjusted system time (UST). Currently, the UST is measured in
3005 * microseconds since Epoc. The actual resolution of the UST may vary from
3006 * system to system, and the units may vary from release to release.
3007 * Drivers should not call this function directly. They should instead use
3008 * \c glXGetProcAddress to obtain a pointer to the function.
3010 * \param ust Location to store the 64-bit UST
3011 * \returns Zero on success or a negative errno value on failure.
3013 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3015 * \since Internal API version 20030317.
3017 int __glXGetUST( int64_t * ust
)
3021 if ( ust
== NULL
) {
3025 if ( gettimeofday( & tv
, NULL
) == 0 ) {
3026 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3032 #endif /* GLX_DIRECT_RENDERING */