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"
58 #define GLX_PREFIX(x) x
59 #endif /* IN_DOXYGEN */
61 static const char __glXGLXClientVendorName
[] = "SGI";
62 static const char __glXGLXClientVersion
[] = "1.4";
65 #if defined(GLX_DIRECT_RENDERING)
68 static Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
);
70 static void * DriverCreateContextWrapper( const __GLXscreenConfigs
*psc
,
71 Display
*dpy
, XVisualInfo
*vis
, void *shared
, __DRIcontext
*ctx
,
72 const __GLcontextModes
*fbconfig
, int render_type
);
74 static Bool
dummyBindContext2( Display
*dpy
, int scrn
,
75 GLXDrawable draw
, GLXDrawable read
, GLXContext gc
);
77 static Bool
dummyUnbindContext2( Display
*dpy
, int scrn
,
78 GLXDrawable draw
, GLXDrawable read
, GLXContext gc
);
80 /****************************************************************************/
83 * Used as glue when a driver does not support
84 * \c __DRIcontextRec::bindContext2.
86 * XXX .bindContext is only defined as a function pointer if
87 * !DRI_NEW_INTERFACE_ONLY.
89 * \sa DriverCreateContextWrapper, __DRIcontextRec::bindContext2
91 static Bool
dummyBindContext2( Display
*dpy
, int scrn
,
92 GLXDrawable draw
, GLXDrawable read
,
95 assert( draw
== read
);
96 return (*gc
->driContext
.bindContext
)( dpy
, scrn
, draw
, gc
);
100 * Used as glue when a driver does not support
101 * \c __DRIcontextRec::unbindContext2.
103 * XXX .unbindContext is only defined as a function pointer if
104 * !DRI_NEW_INTERFACE_ONLY.
106 * \sa DriverCreateContextWrapper, __DRIcontextRec::unbindContext2
108 static Bool
dummyUnbindContext2( Display
*dpy
, int scrn
,
109 GLXDrawable draw
, GLXDrawable read
,
112 assert( draw
== read
);
113 return (*gc
->driContext
.unbindContext
)( dpy
, scrn
, draw
, gc
, GL_FALSE
);
117 /****************************************************************************/
119 * Wrap the call to the driver's \c createContext function.
121 * The \c createContext function is wrapped because not all drivers support
122 * the "new" \c unbindContext2 and \c bindContext2 interfaces. libGL should
123 * not have to check to see which functions the driver supports. Instead,
124 * if either function is not supported it is wrapped. The wrappers test to
125 * make sure that both drawables are the same and pass control to the old
128 * \sa dummyBindContext2, dummyUnbindContext2,
129 * __DRIcontextRec::bindContext2, __DRIcontextRec::unbindContext2
132 static void * DriverCreateContextWrapper( const __GLXscreenConfigs
*psc
,
133 Display
*dpy
, XVisualInfo
*vis
,
136 const __GLcontextModes
*modes
,
139 void * ctx_priv
= NULL
;
141 if ( psc
->driScreen
.createNewContext
!= NULL
) {
142 assert( modes
!= NULL
);
143 ctx_priv
= (*psc
->driScreen
.createNewContext
)(dpy
, modes
, render_type
,
146 /* If the driver supports the createNewContext interface, then
147 * it MUST also support either the bindContext2 / unbindContext2
148 * interface or the bindContext3 / unbindContext3 interface.
151 assert( (ctx_priv
== NULL
) || (ctx
->unbindContext2
!= NULL
)
152 || (ctx
->unbindContext3
!= NULL
) );
153 assert( (ctx_priv
== NULL
) || (ctx
->bindContext2
!= NULL
)
154 || (ctx
->bindContext3
!= NULL
) );
158 ctx_priv
= (*psc
->driScreen
.createContext
)(dpy
, vis
, shared
, ctx
);
160 if ( ctx_priv
!= NULL
) {
161 if ( ctx
->unbindContext2
== NULL
) {
162 ctx
->unbindContext2
= dummyUnbindContext2
;
165 if ( ctx
->bindContext2
== NULL
) {
166 ctx
->bindContext2
= dummyBindContext2
;
177 /****************************************************************************/
179 * Get the __DRIdrawable for the drawable associated with a GLXContext
181 * \param dpy The display associated with \c drawable.
182 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
183 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
184 * the drawable is not associated with a direct-rendering context.
187 #ifdef GLX_DIRECT_RENDERING
188 static __DRIdrawable
*
189 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
191 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
193 if ( (priv
!= NULL
) && (priv
->driDisplay
.private != NULL
) ) {
194 const unsigned screen_count
= ScreenCount(dpy
);
197 for ( i
= 0 ; i
< screen_count
; i
++ ) {
198 __DRIscreen
* const psc
= &priv
->screenConfigs
[i
].driScreen
;
199 __DRIdrawable
* const pdraw
= (psc
->private != NULL
)
200 ? (*psc
->getDrawable
)(dpy
, drawable
, psc
->private) : NULL
;
202 if ( pdraw
!= NULL
) {
203 if ( scrn_num
!= NULL
) {
217 * Get the GLX per-screen data structure associated with a GLX context.
219 * \param dpy Display for which the GLX per-screen information is to be
221 * \param scrn Screen on \c dpy for which the GLX per-screen information is
223 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
224 * specify a valid GLX screen, or NULL otherwise.
226 * \todo Should this function validate that \c scrn is within the screen
227 * number range for \c dpy?
230 static __GLXscreenConfigs
*
231 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
233 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
235 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
240 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
241 __GLXscreenConfigs
** ppsc
)
243 /* Initialize the extension, if needed . This has the added value
244 * of initializing/allocating the display private
248 return GLX_NO_EXTENSION
;
251 *ppriv
= __glXInitialize(dpy
);
252 if ( *ppriv
== NULL
) {
253 return GLX_NO_EXTENSION
;
256 /* Check screen number to see if its valid */
257 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
258 return GLX_BAD_SCREEN
;
261 /* Check to see if the GL is supported on this screen */
262 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
263 if ( (*ppsc
)->configs
== NULL
) {
264 /* No support for GL on this screen regardless of visual */
265 return GLX_BAD_VISUAL
;
273 * Determine if a \c GLXFBConfig supplied by the application is valid.
275 * \param dpy Application supplied \c Display pointer.
276 * \param config Application supplied \c GLXFBConfig.
278 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
279 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
282 static __GLcontextModes
*
283 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
285 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
286 const unsigned num_screens
= ScreenCount(dpy
);
288 const __GLcontextModes
* modes
;
291 if ( priv
!= NULL
) {
292 for ( i
= 0 ; i
< num_screens
; i
++ ) {
293 for ( modes
= priv
->screenConfigs
[i
].configs
295 ; modes
= modes
->next
) {
296 if ( modes
== (__GLcontextModes
*) config
) {
297 return (__GLcontextModes
*) config
;
308 * \todo It should be possible to move the allocate of \c client_state_private
309 * later in the function for direct-rendering contexts. Direct-rendering
310 * contexts don't need to track client state, so they don't need that memory
313 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
314 * function called \c __glXAllocateClientState that allocates the memory and
315 * does all the initialization (including the pixel pack / unpack).
318 GLXContext
AllocateGLXContext( Display
*dpy
)
323 __GLXattribute
*state
;
328 opcode
= __glXSetupForCommand(dpy
);
333 /* Allocate our context record */
334 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
339 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
341 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
347 gc
->client_state_private
= state
;
348 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
349 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
352 ** Create a temporary buffer to hold GLX rendering commands. The size
353 ** of the buffer is selected so that the maximum number of GLX rendering
354 ** commands can fit in a single X packet and still have room in the X
355 ** packet for the GLXRenderReq header.
358 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
359 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
361 Xfree(gc
->client_state_private
);
365 gc
->bufSize
= bufSize
;
367 /* Fill in the new context */
368 gc
->renderMode
= GL_RENDER
;
370 state
->storePack
.alignment
= 4;
371 state
->storeUnpack
.alignment
= 4;
373 __glXInitVertexArrayState(gc
);
375 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
378 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
379 ** Other code uses the fastImageUnpack bit, but it is never set
382 gc
->fastImageUnpack
= GL_FALSE
;
383 gc
->fillImage
= __glFillImage
;
384 gc
->isDirect
= GL_FALSE
;
386 gc
->bufEnd
= gc
->buf
+ bufSize
;
389 ** Set limit register so that there will be one command per packet
393 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
396 gc
->majorOpcode
= opcode
;
399 ** Constrain the maximum drawing command size allowed to be
400 ** transfered using the X_GLXRender protocol request. First
401 ** constrain by a software limit, then constrain by the protocl
404 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
405 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
407 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
408 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
410 gc
->maxSmallRenderCommandSize
= bufSize
;
416 * Create a new context. Exactly one of \c vis and \c fbconfig should be
419 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
420 * SGIX_fbconfig protocol be used?
421 * \param renderType For FBConfigs, what is the rendering type?
425 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
426 const __GLcontextModes
* const fbconfig
,
427 GLXContext shareList
,
428 Bool allowDirect
, GLXContextID contextID
,
429 Bool use_glx_1_3
, int renderType
)
436 gc
= AllocateGLXContext(dpy
);
440 if (None
== contextID
) {
441 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
444 #ifdef GLX_DIRECT_RENDERING
446 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
447 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
448 const __GLcontextModes
* mode
;
450 /* The value of fbconfig cannot change because it is tested
451 * later in the function.
453 if ( fbconfig
== NULL
) {
454 /* FIXME: Is it possible for the __GLcontextModes structure
455 * FIXME: to not be found?
457 mode
= _gl_context_modes_find_visual( psc
->configs
,
459 assert( mode
!= NULL
);
460 assert( mode
->screen
== screen
);
466 if (psc
&& psc
->driScreen
.private) {
467 void * const shared
= (shareList
!= NULL
)
468 ? shareList
->driContext
.private : NULL
;
469 gc
->driContext
.private =
470 DriverCreateContextWrapper( psc
, dpy
, vis
, shared
,
471 &gc
->driContext
, mode
,
473 if (gc
->driContext
.private) {
474 gc
->isDirect
= GL_TRUE
;
475 gc
->screen
= mode
->screen
;
476 gc
->vid
= mode
->visualID
;
477 gc
->fbconfigID
= mode
->fbconfigID
;
478 gc
->driContext
.mode
= mode
;
485 if ( fbconfig
== NULL
) {
486 xGLXCreateContextReq
*req
;
488 /* Send the glXCreateContext request */
489 GetReq(GLXCreateContext
,req
);
490 req
->reqType
= gc
->majorOpcode
;
491 req
->glxCode
= X_GLXCreateContext
;
492 req
->context
= gc
->xid
= XAllocID(dpy
);
493 req
->visual
= vis
->visualid
;
494 req
->screen
= vis
->screen
;
495 req
->shareList
= shareList
? shareList
->xid
: None
;
496 req
->isDirect
= gc
->isDirect
;
498 else if ( use_glx_1_3
) {
499 xGLXCreateNewContextReq
*req
;
501 /* Send the glXCreateNewContext request */
502 GetReq(GLXCreateNewContext
,req
);
503 req
->reqType
= gc
->majorOpcode
;
504 req
->glxCode
= X_GLXCreateNewContext
;
505 req
->context
= gc
->xid
= XAllocID(dpy
);
506 req
->fbconfig
= fbconfig
->fbconfigID
;
507 req
->screen
= fbconfig
->screen
;
508 req
->renderType
= renderType
;
509 req
->shareList
= shareList
? shareList
->xid
: None
;
510 req
->isDirect
= gc
->isDirect
;
513 xGLXVendorPrivateWithReplyReq
*vpreq
;
514 xGLXCreateContextWithConfigSGIXReq
*req
;
516 /* Send the glXCreateNewContext request */
517 GetReqExtra(GLXVendorPrivateWithReply
,
518 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
519 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
520 req
->reqType
= gc
->majorOpcode
;
521 req
->glxCode
= X_GLXVendorPrivateWithReply
;
522 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
523 req
->context
= gc
->xid
= XAllocID(dpy
);
524 req
->fbconfig
= fbconfig
->fbconfigID
;
525 req
->screen
= fbconfig
->screen
;
526 req
->renderType
= renderType
;
527 req
->shareList
= shareList
? shareList
->xid
: None
;
528 req
->isDirect
= gc
->isDirect
;
533 gc
->imported
= GL_FALSE
;
537 gc
->imported
= GL_TRUE
;
544 GLXContext
GLX_PREFIX(glXCreateContext
)(Display
*dpy
, XVisualInfo
*vis
,
545 GLXContext shareList
, Bool allowDirect
)
547 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
551 void __glXFreeContext(__GLXcontext
*gc
)
553 if (gc
->vendor
) XFree((char *) gc
->vendor
);
554 if (gc
->renderer
) XFree((char *) gc
->renderer
);
555 if (gc
->version
) XFree((char *) gc
->version
);
556 if (gc
->extensions
) XFree((char *) gc
->extensions
);
557 __glFreeAttributeState(gc
);
558 XFree((char *) gc
->buf
);
559 Xfree((char *) gc
->client_state_private
);
565 ** Destroy the named context
568 DestroyContext(Display
*dpy
, GLXContext gc
)
570 xGLXDestroyContextReq
*req
;
575 opcode
= __glXSetupForCommand(dpy
);
576 if (!opcode
|| !gc
) {
582 imported
= gc
->imported
;
585 #ifdef GLX_DIRECT_RENDERING
586 /* Destroy the direct rendering context */
588 if (gc
->driContext
.private) {
589 (*gc
->driContext
.destroyContext
)(dpy
, gc
->screen
,
590 gc
->driContext
.private);
591 gc
->driContext
.private = NULL
;
596 if (gc
->currentDpy
) {
597 /* Have to free later cuz it's in use now */
600 /* Destroy the handle if not current to anybody */
602 __glXFreeContext(gc
);
607 ** This dpy also created the server side part of the context.
608 ** Send the glXDestroyContext request.
611 GetReq(GLXDestroyContext
,req
);
612 req
->reqType
= opcode
;
613 req
->glxCode
= X_GLXDestroyContext
;
619 void GLX_PREFIX(glXDestroyContext
)(Display
*dpy
, GLXContext gc
)
621 DestroyContext(dpy
, gc
);
625 ** Return the major and minor version #s for the GLX extension
627 Bool
GLX_PREFIX(glXQueryVersion
)(Display
*dpy
, int *major
, int *minor
)
629 __GLXdisplayPrivate
*priv
;
631 /* Init the extension. This fetches the major and minor version. */
632 priv
= __glXInitialize(dpy
);
633 if (!priv
) return GL_FALSE
;
635 if (major
) *major
= priv
->majorVersion
;
636 if (minor
) *minor
= priv
->minorVersion
;
641 ** Query the existance of the GLX extension
643 Bool
GLX_PREFIX(glXQueryExtension
)(Display
*dpy
, int *errorBase
, int *eventBase
)
645 int major_op
, erb
, evb
;
648 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
650 if (errorBase
) *errorBase
= erb
;
651 if (eventBase
) *eventBase
= evb
;
657 ** Put a barrier in the token stream that forces the GL to finish its
658 ** work before X can proceed.
660 void GLX_PREFIX(glXWaitGL
)(void)
663 GLXContext gc
= __glXGetCurrentContext();
664 Display
*dpy
= gc
->currentDpy
;
668 /* Flush any pending commands out */
669 __glXFlushRenderBuffer(gc
, gc
->pc
);
671 #ifdef GLX_DIRECT_RENDERING
673 /* This bit of ugliness unwraps the glFinish function */
682 /* Send the glXWaitGL request */
684 GetReq(GLXWaitGL
,req
);
685 req
->reqType
= gc
->majorOpcode
;
686 req
->glxCode
= X_GLXWaitGL
;
687 req
->contextTag
= gc
->currentContextTag
;
693 ** Put a barrier in the token stream that forces X to finish its
694 ** work before GL can proceed.
696 void GLX_PREFIX(glXWaitX
)(void)
699 GLXContext gc
= __glXGetCurrentContext();
700 Display
*dpy
= gc
->currentDpy
;
704 /* Flush any pending commands out */
705 __glXFlushRenderBuffer(gc
, gc
->pc
);
707 #ifdef GLX_DIRECT_RENDERING
715 ** Send the glXWaitX request.
718 GetReq(GLXWaitX
,req
);
719 req
->reqType
= gc
->majorOpcode
;
720 req
->glxCode
= X_GLXWaitX
;
721 req
->contextTag
= gc
->currentContextTag
;
726 void GLX_PREFIX(glXUseXFont
)(Font font
, int first
, int count
, int listBase
)
728 xGLXUseXFontReq
*req
;
729 GLXContext gc
= __glXGetCurrentContext();
730 Display
*dpy
= gc
->currentDpy
;
734 /* Flush any pending commands out */
735 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
737 #ifdef GLX_DIRECT_RENDERING
739 DRI_glXUseXFont(font
, first
, count
, listBase
);
744 /* Send the glXUseFont request */
746 GetReq(GLXUseXFont
,req
);
747 req
->reqType
= gc
->majorOpcode
;
748 req
->glxCode
= X_GLXUseXFont
;
749 req
->contextTag
= gc
->currentContextTag
;
753 req
->listBase
= listBase
;
758 /************************************************************************/
761 ** Copy the source context to the destination context using the
764 void GLX_PREFIX(glXCopyContext
)(Display
*dpy
, GLXContext source
, GLXContext dest
,
767 xGLXCopyContextReq
*req
;
768 GLXContext gc
= __glXGetCurrentContext();
772 opcode
= __glXSetupForCommand(dpy
);
777 #ifdef GLX_DIRECT_RENDERING
779 /* NOT_DONE: This does not work yet */
784 ** If the source is the current context, send its tag so that the context
785 ** can be flushed before the copy.
787 if (source
== gc
&& dpy
== gc
->currentDpy
) {
788 tag
= gc
->currentContextTag
;
793 /* Send the glXCopyContext request */
795 GetReq(GLXCopyContext
,req
);
796 req
->reqType
= opcode
;
797 req
->glxCode
= X_GLXCopyContext
;
798 req
->source
= source
? source
->xid
: None
;
799 req
->dest
= dest
? dest
->xid
: None
;
801 req
->contextTag
= tag
;
808 * Determine if a context uses direct rendering.
810 * \param dpy Display where the context was created.
811 * \param contextID ID of the context to be tested.
813 * \returns \c GL_TRUE if the context is direct rendering or not.
815 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
817 xGLXIsDirectReq
*req
;
818 xGLXIsDirectReply reply
;
821 opcode
= __glXSetupForCommand(dpy
);
826 /* Send the glXIsDirect request */
828 GetReq(GLXIsDirect
,req
);
829 req
->reqType
= opcode
;
830 req
->glxCode
= X_GLXIsDirect
;
831 req
->context
= contextID
;
832 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
836 return reply
.isDirect
;
839 Bool
GLX_PREFIX(glXIsDirect
)(Display
*dpy
, GLXContext gc
)
843 #ifdef GLX_DIRECT_RENDERING
844 } else if (gc
->isDirect
) {
848 return __glXIsDirect(dpy
, gc
->xid
);
851 GLXPixmap
GLX_PREFIX(glXCreateGLXPixmap
)(Display
*dpy
, XVisualInfo
*vis
, Pixmap pixmap
)
853 xGLXCreateGLXPixmapReq
*req
;
857 opcode
= __glXSetupForCommand(dpy
);
862 /* Send the glXCreateGLXPixmap request */
864 GetReq(GLXCreateGLXPixmap
,req
);
865 req
->reqType
= opcode
;
866 req
->glxCode
= X_GLXCreateGLXPixmap
;
867 req
->screen
= vis
->screen
;
868 req
->visual
= vis
->visualid
;
869 req
->pixmap
= pixmap
;
870 req
->glxpixmap
= xid
= XAllocID(dpy
);
877 ** Destroy the named pixmap
879 void GLX_PREFIX(glXDestroyGLXPixmap
)(Display
*dpy
, GLXPixmap glxpixmap
)
881 xGLXDestroyGLXPixmapReq
*req
;
884 opcode
= __glXSetupForCommand(dpy
);
889 /* Send the glXDestroyGLXPixmap request */
891 GetReq(GLXDestroyGLXPixmap
,req
);
892 req
->reqType
= opcode
;
893 req
->glxCode
= X_GLXDestroyGLXPixmap
;
894 req
->glxpixmap
= glxpixmap
;
899 void GLX_PREFIX(glXSwapBuffers
)(Display
*dpy
, GLXDrawable drawable
)
901 xGLXSwapBuffersReq
*req
;
905 #ifdef GLX_DIRECT_RENDERING
906 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
908 if ( pdraw
!= NULL
) {
909 (*pdraw
->swapBuffers
)(dpy
, pdraw
->private);
914 opcode
= __glXSetupForCommand(dpy
);
920 ** The calling thread may or may not have a current context. If it
921 ** does, send the context tag so the server can do a flush.
923 gc
= __glXGetCurrentContext();
924 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
925 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
926 tag
= gc
->currentContextTag
;
931 /* Send the glXSwapBuffers request */
933 GetReq(GLXSwapBuffers
,req
);
934 req
->reqType
= opcode
;
935 req
->glxCode
= X_GLXSwapBuffers
;
936 req
->drawable
= drawable
;
937 req
->contextTag
= tag
;
945 ** Return configuration information for the given display, screen and
946 ** visual combination.
948 int GLX_PREFIX(glXGetConfig
)(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
951 __GLXdisplayPrivate
*priv
;
952 __GLXscreenConfigs
*psc
;
955 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
956 if ( status
== Success
) {
957 const __GLcontextModes
* const modes
= _gl_context_modes_find_visual(
958 psc
->configs
, vis
->visualid
);
960 /* Lookup attribute after first finding a match on the visual */
961 if ( modes
!= NULL
) {
962 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
965 status
= GLX_BAD_VISUAL
;
969 ** If we can't find the config for this visual, this visual is not
970 ** supported by the OpenGL implementation on the server.
972 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
973 *value_return
= GL_FALSE
;
980 /************************************************************************/
983 init_fbconfig_for_chooser( __GLcontextModes
* config
,
984 GLboolean fbconfig_style_tags
)
986 memset( config
, 0, sizeof( __GLcontextModes
) );
987 config
->visualID
= (XID
) GLX_DONT_CARE
;
988 config
->visualType
= GLX_DONT_CARE
;
990 /* glXChooseFBConfig specifies different defaults for these two than
993 if ( fbconfig_style_tags
) {
994 config
->rgbMode
= GL_TRUE
;
995 config
->doubleBufferMode
= GLX_DONT_CARE
;
998 config
->visualRating
= GLX_DONT_CARE
;
999 config
->transparentPixel
= GLX_NONE
;
1000 config
->transparentRed
= GLX_DONT_CARE
;
1001 config
->transparentGreen
= GLX_DONT_CARE
;
1002 config
->transparentBlue
= GLX_DONT_CARE
;
1003 config
->transparentAlpha
= GLX_DONT_CARE
;
1004 config
->transparentIndex
= GLX_DONT_CARE
;
1006 config
->drawableType
= GLX_WINDOW_BIT
;
1007 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1008 config
->xRenderable
= GLX_DONT_CARE
;
1009 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
1011 config
->swapMethod
= GLX_DONT_CARE
;
1014 #define MATCH_DONT_CARE( param ) \
1016 if ( (a-> param != GLX_DONT_CARE) \
1017 && (a-> param != b-> param) ) { \
1022 #define MATCH_MINIMUM( param ) \
1024 if ( (a-> param != GLX_DONT_CARE) \
1025 && (a-> param > b-> param) ) { \
1030 #define MATCH_EXACT( param ) \
1032 if ( a-> param != b-> param) { \
1038 * Determine if two GLXFBConfigs are compatible.
1040 * \param a Application specified config to test.
1041 * \param b Server specified config to test against \c a.
1044 fbconfigs_compatible( const __GLcontextModes
* const a
,
1045 const __GLcontextModes
* const b
)
1047 MATCH_DONT_CARE( doubleBufferMode
);
1048 MATCH_DONT_CARE( visualType
);
1049 MATCH_DONT_CARE( visualRating
);
1050 MATCH_DONT_CARE( xRenderable
);
1051 MATCH_DONT_CARE( fbconfigID
);
1052 MATCH_DONT_CARE( swapMethod
);
1054 MATCH_MINIMUM( rgbBits
);
1055 MATCH_MINIMUM( numAuxBuffers
);
1056 MATCH_MINIMUM( redBits
);
1057 MATCH_MINIMUM( greenBits
);
1058 MATCH_MINIMUM( blueBits
);
1059 MATCH_MINIMUM( alphaBits
);
1060 MATCH_MINIMUM( depthBits
);
1061 MATCH_MINIMUM( stencilBits
);
1062 MATCH_MINIMUM( accumRedBits
);
1063 MATCH_MINIMUM( accumGreenBits
);
1064 MATCH_MINIMUM( accumBlueBits
);
1065 MATCH_MINIMUM( accumAlphaBits
);
1066 MATCH_MINIMUM( sampleBuffers
);
1067 MATCH_MINIMUM( maxPbufferWidth
);
1068 MATCH_MINIMUM( maxPbufferHeight
);
1069 MATCH_MINIMUM( maxPbufferPixels
);
1070 MATCH_MINIMUM( samples
);
1072 MATCH_DONT_CARE( stereoMode
);
1073 MATCH_EXACT( level
);
1075 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1076 || ((a
->renderType
& b
->renderType
) == 0) ) {
1081 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1082 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1083 * Technically speaking, it is a bug in the DDX driver, but there is
1084 * enough of an installed base to work around the problem here. In any
1085 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1086 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1087 * 0 from the server to be a match to maintain backward compatibility with
1088 * the (broken) drivers.
1091 if ( a
->transparentPixel
!= GLX_DONT_CARE
1092 && a
->transparentPixel
!= 0 ) {
1093 if ( a
->transparentPixel
== GLX_NONE
) {
1094 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1097 MATCH_EXACT( transparentPixel
);
1100 switch ( a
->transparentPixel
) {
1101 case GLX_TRANSPARENT_RGB
:
1102 MATCH_DONT_CARE( transparentRed
);
1103 MATCH_DONT_CARE( transparentGreen
);
1104 MATCH_DONT_CARE( transparentBlue
);
1105 MATCH_DONT_CARE( transparentAlpha
);
1108 case GLX_TRANSPARENT_INDEX
:
1109 MATCH_DONT_CARE( transparentIndex
);
1121 /* There's some trickly language in the GLX spec about how this is supposed
1122 * to work. Basically, if a given component size is either not specified
1123 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1124 * Well, that's really hard to do with the code as-is. This behavior is
1125 * closer to correct, but still not technically right.
1127 #define PREFER_LARGER_OR_ZERO(comp) \
1129 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1130 if ( ((*a)-> comp) == 0 ) { \
1133 else if ( ((*b)-> comp) == 0 ) { \
1137 return ((*b)-> comp) - ((*a)-> comp) ; \
1142 #define PREFER_LARGER(comp) \
1144 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1145 return ((*b)-> comp) - ((*a)-> comp) ; \
1149 #define PREFER_SMALLER(comp) \
1151 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1152 return ((*a)-> comp) - ((*b)-> comp) ; \
1157 * Compare two GLXFBConfigs. This function is intended to be used as the
1158 * compare function passed in to qsort.
1160 * \returns If \c a is a "better" config, according to the specification of
1161 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1162 * better, then a number greater than zero is return. If both are
1163 * equal, zero is returned.
1164 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1167 fbconfig_compare( const __GLcontextModes
* const * const a
,
1168 const __GLcontextModes
* const * const b
)
1170 /* The order of these comparisons must NOT change. It is defined by
1171 * the GLX 1.3 spec and ARB_multisample.
1174 PREFER_SMALLER( visualSelectGroup
);
1176 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1177 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1178 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1180 PREFER_SMALLER( visualRating
);
1182 /* This isn't quite right. It is supposed to compare the sum of the
1183 * components the user specifically set minimums for.
1185 PREFER_LARGER_OR_ZERO( redBits
);
1186 PREFER_LARGER_OR_ZERO( greenBits
);
1187 PREFER_LARGER_OR_ZERO( blueBits
);
1188 PREFER_LARGER_OR_ZERO( alphaBits
);
1190 PREFER_SMALLER( rgbBits
);
1192 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1193 /* Prefer single-buffer.
1195 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1198 PREFER_SMALLER( numAuxBuffers
);
1200 PREFER_LARGER_OR_ZERO( depthBits
);
1201 PREFER_SMALLER( stencilBits
);
1203 /* This isn't quite right. It is supposed to compare the sum of the
1204 * components the user specifically set minimums for.
1206 PREFER_LARGER_OR_ZERO( accumRedBits
);
1207 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1208 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1209 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1211 PREFER_SMALLER( visualType
);
1213 /* None of the multisample specs say where this comparison should happen,
1214 * so I put it near the end.
1216 PREFER_SMALLER( sampleBuffers
);
1217 PREFER_SMALLER( samples
);
1219 /* None of the pbuffer or fbconfig specs say that this comparison needs
1220 * to happen at all, but it seems like it should.
1222 PREFER_LARGER( maxPbufferWidth
);
1223 PREFER_LARGER( maxPbufferHeight
);
1224 PREFER_LARGER( maxPbufferPixels
);
1231 * Selects and sorts a subset of the supplied configs based on the attributes.
1232 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1233 * and \c glXChooseFBConfigSGIX.
1235 * \param configs Array of pointers to possible configs. The elements of
1236 * this array that do not meet the criteria will be set to
1237 * NULL. The remaining elements will be sorted according to
1238 * the various visual / FBConfig selection rules.
1239 * \param num_configs Number of elements in the \c configs array.
1240 * \param attribList Attributes used select from \c configs. This array is
1241 * terminated by a \c None tag. The array can either take
1242 * the form expected by \c glXChooseVisual (where boolean
1243 * tags do not have a value) or by \c glXChooseFBConfig
1244 * (where every tag has a value).
1245 * \param fbconfig_style_tags Selects whether \c attribList is in
1246 * \c glXChooseVisual style or
1247 * \c glXChooseFBConfig style.
1248 * \returns The number of valid elements left in \c configs.
1250 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1253 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1254 const int *attribList
, GLboolean fbconfig_style_tags
)
1256 __GLcontextModes test_config
;
1260 /* This is a fairly direct implementation of the selection method
1261 * described by GLX_SGIX_fbconfig. Start by culling out all the
1262 * configs that are not compatible with the selected parameter
1266 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1267 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1268 (const INT32
*) attribList
,
1269 GL_TRUE
, fbconfig_style_tags
);
1272 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1273 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1274 configs
[ base
] = configs
[ i
];
1283 if ( base
< num_configs
) {
1284 (void) memset( & configs
[ base
], 0,
1285 sizeof( void * ) * (num_configs
- base
) );
1288 /* After the incompatible configs are removed, the resulting
1289 * list is sorted according to the rules set out in the various
1293 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1294 (int (*)(const void*, const void*)) fbconfig_compare
);
1302 ** Return the visual that best matches the template. Return None if no
1303 ** visual matches the template.
1305 XVisualInfo
*GLX_PREFIX(glXChooseVisual
)(Display
*dpy
, int screen
, int *attribList
)
1307 XVisualInfo
*visualList
= NULL
;
1308 __GLXdisplayPrivate
*priv
;
1309 __GLXscreenConfigs
*psc
;
1310 __GLcontextModes test_config
;
1311 __GLcontextModes
*modes
;
1312 const __GLcontextModes
*best_config
= NULL
;
1315 ** Get a list of all visuals, return if list is empty
1317 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1323 ** Build a template from the defaults and the attribute list
1324 ** Free visual list and return if an unexpected token is encountered
1326 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1327 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1328 (const INT32
*) attribList
,
1329 GL_TRUE
, GL_FALSE
);
1332 ** Eliminate visuals that don't meet minimum requirements
1333 ** Compute a score for those that do
1334 ** Remember which visual, if any, got the highest score
1336 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
1337 if ( fbconfigs_compatible( & test_config
, modes
)
1338 && ((best_config
== NULL
)
1339 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1340 best_config
= modes
;
1345 ** If no visual is acceptable, return None
1346 ** Otherwise, create an XVisualInfo list with just the selected X visual
1349 if (best_config
!= NULL
) {
1350 XVisualInfo visualTemplate
;
1353 visualTemplate
.screen
= screen
;
1354 visualTemplate
.visualid
= best_config
->visualID
;
1355 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1356 &visualTemplate
, &i
);
1363 const char *GLX_PREFIX(glXQueryExtensionsString
)( Display
*dpy
, int screen
)
1365 __GLXscreenConfigs
*psc
;
1366 __GLXdisplayPrivate
*priv
;
1368 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1372 if (!psc
->effectiveGLXexts
) {
1373 if (!psc
->serverGLXexts
) {
1374 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1375 X_GLXQueryServerString
,
1376 screen
, GLX_EXTENSIONS
);
1379 __glXCalculateUsableExtensions(psc
,
1380 #ifdef GLX_DIRECT_RENDERING
1381 (priv
->driDisplay
.private != NULL
),
1385 priv
->minorVersion
);
1388 return psc
->effectiveGLXexts
;
1391 const char *GLX_PREFIX(glXGetClientString
)( Display
*dpy
, int name
)
1395 return (__glXGLXClientVendorName
);
1397 return (__glXGLXClientVersion
);
1398 case GLX_EXTENSIONS
:
1399 return (__glXGetClientExtensions());
1405 const char *GLX_PREFIX(glXQueryServerString
)( Display
*dpy
, int screen
, int name
)
1407 __GLXscreenConfigs
*psc
;
1408 __GLXdisplayPrivate
*priv
;
1412 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1418 str
= & priv
->serverGLXvendor
;
1421 str
= & priv
->serverGLXversion
;
1423 case GLX_EXTENSIONS
:
1424 str
= & psc
->serverGLXexts
;
1430 if ( *str
== NULL
) {
1431 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1432 X_GLXQueryServerString
, screen
, name
);
1438 void __glXClientInfo ( Display
*dpy
, int opcode
)
1440 xGLXClientInfoReq
*req
;
1442 char * ext_str
= __glXGetClientGLExtensionString();
1444 /* Send the glXClientInfo request */
1446 GetReq(GLXClientInfo
,req
);
1447 req
->reqType
= opcode
;
1448 req
->glxCode
= X_GLXClientInfo
;
1449 req
->major
= GLX_MAJOR_VERSION
;
1450 req
->minor
= GLX_MINOR_VERSION
;
1452 size
= strlen( ext_str
) + 1;
1453 req
->length
+= (size
+ 3) >> 2;
1454 req
->numbytes
= size
;
1455 Data(dpy
, ext_str
, size
);
1465 ** EXT_import_context
1468 Display
*glXGetCurrentDisplay(void)
1470 GLXContext gc
= __glXGetCurrentContext();
1471 if (NULL
== gc
) return NULL
;
1472 return gc
->currentDpy
;
1475 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1476 glXGetCurrentDisplay
)
1479 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1482 * \param dpy Display where \c ctx was created.
1483 * \param ctx Context to query.
1484 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1485 * or zero if the request failed due to internal problems (i.e.,
1486 * unable to allocate temporary memory, etc.)
1489 * This function dynamically determines whether to use the EXT_import_context
1490 * version of the protocol or the GLX 1.3 version of the protocol.
1492 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1494 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1495 xGLXQueryContextReply reply
;
1501 return GLX_BAD_CONTEXT
;
1503 opcode
= __glXSetupForCommand(dpy
);
1508 /* Send the glXQueryContextInfoEXT request */
1511 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1512 xGLXQueryContextReq
*req
;
1514 GetReq(GLXQueryContext
, req
);
1516 req
->reqType
= opcode
;
1517 req
->glxCode
= X_GLXQueryContext
;
1518 req
->context
= (unsigned int)(ctx
->xid
);
1521 xGLXVendorPrivateReq
*vpreq
;
1522 xGLXQueryContextInfoEXTReq
*req
;
1524 GetReqExtra( GLXVendorPrivate
,
1525 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1527 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1528 req
->reqType
= opcode
;
1529 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1530 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1531 req
->context
= (unsigned int)(ctx
->xid
);
1534 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1536 numValues
= reply
.n
;
1539 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1543 int *propList
, *pProp
;
1547 nPropListBytes
= numValues
<< 3;
1548 propList
= (int *) Xmalloc(nPropListBytes
);
1549 if (NULL
== propList
) {
1552 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1554 for (i
=0; i
< numValues
; i
++) {
1556 case GLX_SHARE_CONTEXT_EXT
:
1557 ctx
->share_xid
= *pProp
++;
1559 case GLX_VISUAL_ID_EXT
:
1560 ctx
->vid
= *pProp
++;
1563 ctx
->screen
= *pProp
++;
1565 case GLX_FBCONFIG_ID
:
1566 ctx
->fbconfigID
= *pProp
++;
1568 case GLX_RENDER_TYPE
:
1569 ctx
->renderType
= *pProp
++;
1576 Xfree((char *)propList
);
1586 GLX_PREFIX(glXQueryContext
)(Display
*dpy
, GLXContext ctx
,
1587 int attribute
, int *value
)
1591 /* get the information from the server if we don't have it already */
1592 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1593 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1594 if (Success
!= retVal
) return retVal
;
1596 switch (attribute
) {
1597 case GLX_SHARE_CONTEXT_EXT
:
1598 *value
= (int)(ctx
->share_xid
);
1600 case GLX_VISUAL_ID_EXT
:
1601 *value
= (int)(ctx
->vid
);
1604 *value
= (int)(ctx
->screen
);
1606 case GLX_FBCONFIG_ID
:
1607 *value
= (int)(ctx
->fbconfigID
);
1609 case GLX_RENDER_TYPE
:
1610 *value
= (int)(ctx
->renderType
);
1613 return GLX_BAD_ATTRIBUTE
;
1618 GLX_ALIAS( int, glXQueryContextInfoEXT
,
1619 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1620 (dpy
, ctx
, attribute
, value
),
1623 GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1628 GLXContext
GLX_PREFIX(glXImportContextEXT
)(Display
*dpy
, GLXContextID contextID
)
1632 if (contextID
== None
) {
1635 if (__glXIsDirect(dpy
, contextID
)) {
1639 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1641 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1648 void GLX_PREFIX(glXFreeContextEXT
)(Display
*dpy
, GLXContext ctx
)
1650 DestroyContext(dpy
, ctx
);
1656 * GLX 1.3 functions - these are just stubs for now!
1659 GLXFBConfig
*GLX_PREFIX(glXChooseFBConfig
)(Display
*dpy
, int screen
, const int *attribList
, int *nitems
)
1661 __GLcontextModes
** config_list
;
1665 config_list
= (__GLcontextModes
**)
1666 GLX_PREFIX(glXGetFBConfigs
)( dpy
, screen
, & list_size
);
1668 if ( (config_list
!= NULL
) && (list_size
> 0) ) {
1669 list_size
= choose_visual( config_list
, list_size
, attribList
,
1671 if ( list_size
== 0 ) {
1672 XFree( config_list
);
1677 *nitems
= list_size
;
1678 return (GLXFBConfig
*) config_list
;
1682 GLXContext
GLX_PREFIX(glXCreateNewContext
)(Display
*dpy
, GLXFBConfig config
, int renderType
, GLXContext shareList
, Bool allowDirect
)
1684 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1685 allowDirect
, None
, True
, renderType
);
1689 GLXDrawable
GLX_PREFIX(glXGetCurrentReadDrawable
)(void)
1691 GLXContext gc
= __glXGetCurrentContext();
1692 return gc
->currentReadable
;
1696 GLXFBConfig
*GLX_PREFIX(glXGetFBConfigs
)(Display
*dpy
, int screen
, int *nelements
)
1698 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1699 __GLcontextModes
** config
= NULL
;
1702 if ( (priv
->screenConfigs
!= NULL
)
1703 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1704 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1705 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1706 unsigned num_configs
= 0;
1707 __GLcontextModes
* modes
;
1710 for ( modes
= priv
->screenConfigs
[screen
].configs
1712 ; modes
= modes
->next
) {
1713 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1718 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1720 if ( config
!= NULL
) {
1721 *nelements
= num_configs
;
1723 for ( modes
= priv
->screenConfigs
[screen
].configs
1725 ; modes
= modes
->next
) {
1731 return (GLXFBConfig
*) config
;
1735 int GLX_PREFIX(glXGetFBConfigAttrib
)(Display
*dpy
, GLXFBConfig config
, int attribute
, int *value
)
1737 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1739 return (modes
!= NULL
)
1740 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1745 XVisualInfo
*GLX_PREFIX(glXGetVisualFromFBConfig
)(Display
*dpy
, GLXFBConfig config
)
1747 XVisualInfo visualTemplate
;
1748 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1752 ** Get a list of all visuals, return if list is empty
1754 visualTemplate
.visualid
= fbconfig
->visualID
;
1755 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1760 ** GLX_SGI_make_current_read
1763 GLX_ALIAS(GLXDrawable
, glXGetCurrentReadDrawableSGI
, (void), (),
1764 glXGetCurrentReadDrawable
)
1768 ** GLX_SGI_swap_control
1770 int GLX_PREFIX(glXSwapIntervalSGI
)(int interval
)
1772 xGLXVendorPrivateReq
*req
;
1773 GLXContext gc
= __glXGetCurrentContext();
1775 CARD32
* interval_ptr
;
1779 return GLX_BAD_CONTEXT
;
1782 if ( interval
<= 0 ) {
1783 return GLX_BAD_VALUE
;
1786 #ifdef GLX_DIRECT_RENDERING
1787 if ( gc
->isDirect
) {
1788 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1790 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1791 gc
->currentDrawable
,
1793 if ( __glXExtensionBitIsEnabled( psc
, SGI_swap_control_bit
)
1794 && (pdraw
!= NULL
) ) {
1795 pdraw
->swap_interval
= interval
;
1799 return GLX_BAD_CONTEXT
;
1803 dpy
= gc
->currentDpy
;
1804 opcode
= __glXSetupForCommand(dpy
);
1809 /* Send the glXSwapIntervalSGI request */
1811 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1812 req
->reqType
= opcode
;
1813 req
->glxCode
= X_GLXVendorPrivate
;
1814 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1815 req
->contextTag
= gc
->currentContextTag
;
1817 interval_ptr
= (CARD32
*) req
+ 1;
1818 *interval_ptr
= interval
;
1829 ** GLX_MESA_swap_control
1831 GLint
GLX_PREFIX(glXSwapIntervalMESA
)(unsigned interval
)
1833 #ifdef GLX_DIRECT_RENDERING
1834 GLXContext gc
= __glXGetCurrentContext();
1836 if ( interval
< 0 ) {
1837 return GLX_BAD_VALUE
;
1840 if ( (gc
!= NULL
) && gc
->isDirect
) {
1841 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1844 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1845 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1846 __DRIdrawable
* const pdraw
=
1847 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1848 gc
->currentDrawable
,
1849 psc
->driScreen
.private);
1850 if ( pdraw
!= NULL
) {
1851 pdraw
->swap_interval
= interval
;
1860 return GLX_BAD_CONTEXT
;
1863 GLint
GLX_PREFIX(glXGetSwapIntervalMESA
)( void )
1865 #ifdef GLX_DIRECT_RENDERING
1866 GLXContext gc
= __glXGetCurrentContext();
1868 if ( (gc
!= NULL
) && gc
->isDirect
) {
1869 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1872 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1873 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1874 __DRIdrawable
* const pdraw
=
1875 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1876 gc
->currentDrawable
,
1877 psc
->driScreen
.private);
1878 if ( pdraw
!= NULL
) {
1879 return pdraw
->swap_interval
;
1890 ** GLX_MESA_swap_frame_usage
1893 GLint
GLX_PREFIX(glXBeginFrameTrackingMESA
)(Display
*dpy
, GLXDrawable drawable
)
1895 int status
= GLX_BAD_CONTEXT
;
1896 #ifdef GLX_DIRECT_RENDERING
1898 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1899 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1901 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1902 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1903 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_TRUE
);
1913 GLint
GLX_PREFIX(glXEndFrameTrackingMESA
)(Display
*dpy
, GLXDrawable drawable
)
1915 int status
= GLX_BAD_CONTEXT
;
1916 #ifdef GLX_DIRECT_RENDERING
1918 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1919 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1921 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1922 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1923 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_FALSE
);
1933 GLint
GLX_PREFIX(glXGetFrameUsageMESA
)(Display
*dpy
, GLXDrawable drawable
,
1936 int status
= GLX_BAD_CONTEXT
;
1937 #ifdef GLX_DIRECT_RENDERING
1939 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1940 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1942 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1943 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1944 int64_t sbc
, missedFrames
;
1945 float lastMissedUsage
;
1947 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, &sbc
,
1948 &missedFrames
, &lastMissedUsage
,
1960 GLint
GLX_PREFIX(glXQueryFrameTrackingMESA
)(Display
*dpy
, GLXDrawable drawable
,
1961 int64_t *sbc
, int64_t *missedFrames
,
1962 GLfloat
*lastMissedUsage
)
1964 int status
= GLX_BAD_CONTEXT
;
1965 #ifdef GLX_DIRECT_RENDERING
1967 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1968 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1970 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1971 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1974 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, sbc
,
1975 missedFrames
, lastMissedUsage
,
1982 (void) missedFrames
;
1983 (void) lastMissedUsage
;
1990 ** GLX_SGI_video_sync
1992 int GLX_PREFIX(glXGetVideoSyncSGI
)(unsigned int *count
)
1994 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1995 * FIXME: there should be a GLX encoding for this call. I can find no
1996 * FIXME: documentation for the GLX encoding.
1998 #ifdef GLX_DIRECT_RENDERING
1999 GLXContext gc
= __glXGetCurrentContext();
2002 if ( (gc
!= NULL
) && gc
->isDirect
) {
2003 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2005 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
2006 && psc
->driScreen
.private && psc
->driScreen
.getMSC
) {
2010 ret
= psc
->driScreen
.getMSC( psc
->driScreen
.private, & temp
);
2011 *count
= (unsigned) temp
;
2012 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2018 return GLX_BAD_CONTEXT
;
2021 int GLX_PREFIX(glXWaitVideoSyncSGI
)(int divisor
, int remainder
, unsigned int *count
)
2023 #ifdef GLX_DIRECT_RENDERING
2024 GLXContext gc
= __glXGetCurrentContext();
2026 if ( divisor
<= 0 || remainder
< 0 )
2027 return GLX_BAD_VALUE
;
2029 if ( (gc
!= NULL
) && gc
->isDirect
) {
2030 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2032 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
2033 && psc
->driScreen
.private ) {
2034 __DRIdrawable
* const pdraw
=
2035 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
2036 gc
->currentDrawable
,
2037 psc
->driScreen
.private);
2038 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
) ) {
2043 ret
= (*pdraw
->waitForMSC
)( gc
->currentDpy
, pdraw
->private,
2044 0, divisor
, remainder
,
2046 *count
= (unsigned) msc
;
2047 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2054 return GLX_BAD_CONTEXT
;
2059 ** GLX_SGIS_video_source
2063 GLXVideoSourceSGIX
GLX_PREFIX(glXCreateGLXVideoSourceSGIX
)(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2074 void GLX_PREFIX(glXDestroyGLXVideoSourceSGIX
)(Display
*dpy
, GLXVideoSourceSGIX src
)
2084 ** GLX_SGIX_fbconfig
2085 ** Many of these functions are aliased to GLX 1.3 entry points in the
2086 ** GLX_functions table.
2089 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2090 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2091 (dpy
, config
, attribute
, value
),
2092 glXGetFBConfigAttrib
)
2094 GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2095 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2096 (dpy
, screen
, attrib_list
, nelements
),
2099 GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2100 (Display
* dpy
, GLXFBConfigSGIX config
),
2102 glXGetVisualFromFBConfig
)
2104 GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapWithConfigSGIX
)(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2106 xGLXVendorPrivateWithReplyReq
*vpreq
;
2107 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2108 GLXPixmap xid
= None
;
2110 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2111 __GLXscreenConfigs
* psc
;
2114 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2118 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2120 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2121 opcode
= __glXSetupForCommand(dpy
);
2126 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2128 GetReqExtra(GLXVendorPrivateWithReply
,
2129 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2130 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2131 req
->reqType
= opcode
;
2132 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2133 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2134 req
->screen
= fbconfig
->screen
;
2135 req
->fbconfig
= fbconfig
->fbconfigID
;
2136 req
->pixmap
= pixmap
;
2137 req
->glxpixmap
= xid
= XAllocID(dpy
);
2145 GLXContext
GLX_PREFIX(glXCreateContextWithConfigSGIX
)(Display
*dpy
, GLXFBConfigSGIX config
, int renderType
, GLXContext shareList
, Bool allowDirect
)
2147 GLXContext gc
= NULL
;
2148 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2149 __GLXscreenConfigs
* psc
;
2152 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2156 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2158 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2159 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2160 allowDirect
, None
, False
, renderType
);
2167 GLXFBConfigSGIX
GLX_PREFIX(glXGetFBConfigFromVisualSGIX
)(Display
*dpy
, XVisualInfo
*vis
)
2169 __GLXdisplayPrivate
*priv
;
2170 __GLXscreenConfigs
*psc
;
2172 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2173 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2174 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2175 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2186 void GLX_PREFIX(glXCushionSGI
)(Display
*dpy
, Window win
, float cushion
)
2195 ** GLX_SGIX_video_resize
2197 int GLX_PREFIX(glXBindChannelToWindowSGIX
)(Display
*dpy
, int screen
, int channel
, Window window
)
2206 int GLX_PREFIX(glXChannelRectSGIX
)(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2218 int GLX_PREFIX(glXQueryChannelRectSGIX
)(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2230 int GLX_PREFIX(glXQueryChannelDeltasSGIX
)(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2242 int GLX_PREFIX(glXChannelRectSyncSGIX
)(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2252 #if defined(_DM_BUFFER_H_)
2254 Bool
GLX_PREFIX(glXAssociateDMPbufferSGIX
)(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2267 ** GLX_SGIX_swap_group
2269 void GLX_PREFIX(glXJoinSwapGroupSGIX
)(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2278 ** GLX_SGIX_swap_barrier
2280 void GLX_PREFIX(glXBindSwapBarrierSGIX
)(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2287 Bool
GLX_PREFIX(glXQueryMaxSwapBarriersSGIX
)(Display
*dpy
, int screen
, int *max
)
2297 ** GLX_SUN_get_transparent_index
2299 Status
GLX_PREFIX(glXGetTransparentIndexSUN
)(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2304 (void) pTransparent
;
2310 ** GLX_OML_sync_control
2312 Bool
GLX_PREFIX(glXGetSyncValuesOML
)(Display
*dpy
, GLXDrawable drawable
,
2313 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2315 #ifdef GLX_DIRECT_RENDERING
2316 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2318 if ( priv
!= NULL
) {
2320 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2321 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2323 assert( (pdraw
== NULL
) || (i
!= -1) );
2324 return ( (pdraw
&& pdraw
->getSBC
&& psc
->driScreen
.getMSC
)
2325 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)
2326 && ((*psc
->driScreen
.getMSC
)( psc
->driScreen
.private, msc
) == 0)
2327 && ((*pdraw
->getSBC
)( dpy
, psc
->driScreen
.private, sbc
) == 0)
2328 && (__glXGetUST( ust
) == 0) );
2342 * Determine the refresh rate of the specified drawable and display.
2344 * \param dpy Display whose refresh rate is to be determined.
2345 * \param drawable Drawable whose refresh rate is to be determined.
2346 * \param numerator Numerator of the refresh rate.
2347 * \param demoninator Denominator of the refresh rate.
2348 * \return If the refresh rate for the specified display and drawable could
2349 * be calculated, True is returned. Otherwise False is returned.
2351 * \note This function is implemented entirely client-side. A lot of other
2352 * functionality is required to export GLX_OML_sync_control, so on
2353 * XFree86 this function can be called for direct-rendering contexts
2354 * when GLX_OML_sync_control appears in the client extension string.
2357 Bool
GLX_PREFIX(glXGetMscRateOML
)(Display
* dpy
, GLXDrawable drawable
,
2358 int32_t * numerator
, int32_t * denominator
)
2360 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2361 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2364 if ( priv
!= NULL
) {
2365 XF86VidModeModeLine mode_line
;
2371 GetDRIDrawable( dpy
, drawable
, & screen_num
);
2372 if ( (screen_num
!= -1)
2373 && XF86VidModeQueryVersion( dpy
, & i
, & i
)
2374 && XF86VidModeGetModeLine( dpy
, screen_num
, & dot_clock
,
2376 unsigned n
= dot_clock
* 1000;
2377 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2379 # define V_INTERLACE 0x010
2380 # define V_DBLSCAN 0x020
2382 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2385 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2389 /* The OML_sync_control spec requires that if the refresh rate is a
2390 * whole number, that the returned numerator be equal to the refresh
2391 * rate and the denominator be 1.
2394 if ( (n
% d
) == 0 ) {
2399 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2402 /* This is a poor man's way to reduce a fraction. It's far from
2403 * perfect, but it will work well enough for this situation.
2406 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2407 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2431 int64_t GLX_PREFIX(glXSwapBuffersMscOML
)(Display
*dpy
, GLXDrawable drawable
,
2433 int64_t divisor
, int64_t remainder
)
2435 #ifdef GLX_DIRECT_RENDERING
2437 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2438 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2440 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2441 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2442 * of -1 if the function failed because of errors detected in the input
2445 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2447 if ( divisor
> 0 && remainder
>= divisor
)
2450 if ( (pdraw
!= NULL
) && (pdraw
->swapBuffersMSC
!= NULL
)
2451 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2452 return (*pdraw
->swapBuffersMSC
)(dpy
, pdraw
->private, target_msc
,
2453 divisor
, remainder
);
2466 Bool
GLX_PREFIX(glXWaitForMscOML
)(Display
* dpy
, GLXDrawable drawable
,
2468 int64_t divisor
, int64_t remainder
,
2469 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2471 #ifdef GLX_DIRECT_RENDERING
2473 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2474 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2477 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2478 * error", but the return type in the spec is Bool.
2480 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2482 if ( divisor
> 0 && remainder
>= divisor
)
2485 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
)
2486 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2487 ret
= (*pdraw
->waitForMSC
)( dpy
, pdraw
->private, target_msc
,
2488 divisor
, remainder
, msc
, sbc
);
2490 /* __glXGetUST returns zero on success and non-zero on failure.
2491 * This function returns True on success and False on failure.
2493 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2509 Bool
GLX_PREFIX(glXWaitForSbcOML
)(Display
* dpy
, GLXDrawable drawable
,
2511 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2513 #ifdef GLX_DIRECT_RENDERING
2515 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2516 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2519 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2520 * error", but the return type in the spec is Bool.
2522 if ( target_sbc
< 0 )
2525 if ( (pdraw
!= NULL
) && (pdraw
->waitForSBC
!= NULL
)
2526 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)) {
2527 ret
= (*pdraw
->waitForSBC
)( dpy
, pdraw
->private, target_sbc
, msc
, sbc
);
2529 /* __glXGetUST returns zero on success and non-zero on failure.
2530 * This function returns True on success and False on failure.
2532 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2547 * GLX_MESA_allocate_memory
2551 void *GLX_PREFIX(glXAllocateMemoryMESA
)(Display
*dpy
, int scrn
,
2557 #ifdef GLX_DIRECT_RENDERING
2558 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2560 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2561 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.allocateMemory
) {
2562 return (*psc
->driScreen
.allocateMemory
)( dpy
, scrn
, size
,
2563 readFreq
, writeFreq
,
2574 #endif /* GLX_DIRECT_RENDERING */
2580 void GLX_PREFIX(glXFreeMemoryMESA
)(Display
*dpy
, int scrn
, void *pointer
)
2582 #ifdef GLX_DIRECT_RENDERING
2583 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2585 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2586 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.freeMemory
) {
2587 (*psc
->driScreen
.freeMemory
)( dpy
, scrn
, pointer
);
2594 #endif /* GLX_DIRECT_RENDERING */
2598 GLuint
GLX_PREFIX(glXGetMemoryOffsetMESA
)( Display
*dpy
, int scrn
,
2599 const void *pointer
)
2601 #ifdef GLX_DIRECT_RENDERING
2602 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2604 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2605 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.memoryOffset
) {
2606 return (*psc
->driScreen
.memoryOffset
)( dpy
, scrn
, pointer
);
2613 #endif /* GLX_DIRECT_RENDERING */
2621 * Mesa extension stubs. These will help reduce portability problems.
2626 * Release all buffers associated with the specified GLX drawable.
2629 * This function was intended for stand-alone Mesa. The issue there is that
2630 * the library doesn't get any notification when a window is closed. In
2631 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2632 * supported, there are 3 different functions to destroy a drawable. It
2633 * should be possible to create GLX protocol (or have it determine which
2634 * protocol to use based on the type of the drawable) to have one function
2635 * do the work of 3. For the direct-rendering case, this function could
2636 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2637 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2638 * would need to be used. This really should be done as part of the new DRI
2641 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2642 * __driGarbageCollectDrawables
2643 * glXDestroyGLXPixmap
2644 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2645 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2647 Bool
GLX_PREFIX(glXReleaseBuffersMESA
)( Display
*dpy
, GLXDrawable d
)
2655 GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapMESA
)( Display
*dpy
,
2656 XVisualInfo
*visual
,
2657 Pixmap pixmap
, Colormap cmap
)
2667 void GLX_PREFIX(glXCopySubBufferMESA
)( Display
*dpy
, GLXDrawable drawable
,
2668 int x
, int y
, int width
, int height
)
2679 Bool
GLX_PREFIX(glXSet3DfxModeMESA
)( int mode
)
2689 * \c strdup is actually not a standard ANSI C or POSIX routine.
2690 * Irix will not define it if ANSI mode is in effect.
2695 __glXstrdup(const char *str
)
2698 copy
= (char *) Xmalloc(strlen(str
) + 1);
2706 ** glXGetProcAddress support
2709 struct name_address_pair
{
2714 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2715 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2717 static const struct name_address_pair GLX_functions
[] = {
2718 /*** GLX_VERSION_1_0 ***/
2719 GLX_FUNCTION( glXChooseVisual
),
2720 GLX_FUNCTION( glXCopyContext
),
2721 GLX_FUNCTION( glXCreateContext
),
2722 GLX_FUNCTION( glXCreateGLXPixmap
),
2723 GLX_FUNCTION( glXDestroyContext
),
2724 GLX_FUNCTION( glXDestroyGLXPixmap
),
2725 GLX_FUNCTION( glXGetConfig
),
2726 GLX_FUNCTION( glXGetCurrentContext
),
2727 GLX_FUNCTION( glXGetCurrentDrawable
),
2728 GLX_FUNCTION( glXIsDirect
),
2729 GLX_FUNCTION( glXMakeCurrent
),
2730 GLX_FUNCTION( glXQueryExtension
),
2731 GLX_FUNCTION( glXQueryVersion
),
2732 GLX_FUNCTION( glXSwapBuffers
),
2733 GLX_FUNCTION( glXUseXFont
),
2734 GLX_FUNCTION( glXWaitGL
),
2735 GLX_FUNCTION( glXWaitX
),
2737 /*** GLX_VERSION_1_1 ***/
2738 GLX_FUNCTION( glXGetClientString
),
2739 GLX_FUNCTION( glXQueryExtensionsString
),
2740 GLX_FUNCTION( glXQueryServerString
),
2742 /*** GLX_VERSION_1_2 ***/
2743 GLX_FUNCTION( glXGetCurrentDisplay
),
2745 /*** GLX_VERSION_1_3 ***/
2746 GLX_FUNCTION( glXChooseFBConfig
),
2747 GLX_FUNCTION( glXCreateNewContext
),
2748 GLX_FUNCTION( glXCreatePbuffer
),
2749 GLX_FUNCTION( glXCreatePixmap
),
2750 GLX_FUNCTION( glXCreateWindow
),
2751 GLX_FUNCTION( glXDestroyPbuffer
),
2752 GLX_FUNCTION( glXDestroyPixmap
),
2753 GLX_FUNCTION( glXDestroyWindow
),
2754 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2755 GLX_FUNCTION( glXGetFBConfigAttrib
),
2756 GLX_FUNCTION( glXGetFBConfigs
),
2757 GLX_FUNCTION( glXGetSelectedEvent
),
2758 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2759 GLX_FUNCTION( glXMakeContextCurrent
),
2760 GLX_FUNCTION( glXQueryContext
),
2761 GLX_FUNCTION( glXQueryDrawable
),
2762 GLX_FUNCTION( glXSelectEvent
),
2764 /*** GLX_SGI_swap_control ***/
2765 GLX_FUNCTION( glXSwapIntervalSGI
),
2767 /*** GLX_SGI_video_sync ***/
2768 GLX_FUNCTION( glXGetVideoSyncSGI
),
2769 GLX_FUNCTION( glXWaitVideoSyncSGI
),
2771 /*** GLX_SGI_make_current_read ***/
2772 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2773 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2775 /*** GLX_SGIX_video_source ***/
2777 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX
),
2778 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX
),
2781 /*** GLX_EXT_import_context ***/
2782 GLX_FUNCTION( glXFreeContextEXT
),
2783 GLX_FUNCTION( glXGetContextIDEXT
),
2784 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2785 GLX_FUNCTION( glXImportContextEXT
),
2786 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2788 /*** GLX_SGIX_fbconfig ***/
2789 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2790 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2791 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2792 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2793 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2794 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2796 /*** GLX_SGIX_pbuffer ***/
2797 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2798 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2799 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2800 GLX_FUNCTION( glXSelectEventSGIX
),
2801 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2803 /*** GLX_SGI_cushion ***/
2804 GLX_FUNCTION( glXCushionSGI
),
2806 /*** GLX_SGIX_video_resize ***/
2807 GLX_FUNCTION( glXBindChannelToWindowSGIX
),
2808 GLX_FUNCTION( glXChannelRectSGIX
),
2809 GLX_FUNCTION( glXQueryChannelRectSGIX
),
2810 GLX_FUNCTION( glXQueryChannelDeltasSGIX
),
2811 GLX_FUNCTION( glXChannelRectSyncSGIX
),
2813 /*** GLX_SGIX_dmbuffer **/
2814 #if defined(_DM_BUFFER_H_)
2815 GLX_FUNCTION( glXAssociateDMPbufferSGIX
),
2818 /*** GLX_SGIX_swap_group ***/
2819 GLX_FUNCTION( glXJoinSwapGroupSGIX
),
2821 /*** GLX_SGIX_swap_barrier ***/
2822 GLX_FUNCTION( glXBindSwapBarrierSGIX
),
2823 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX
),
2825 /*** GLX_SUN_get_transparent_index ***/
2826 GLX_FUNCTION( glXGetTransparentIndexSUN
),
2828 /*** GLX_MESA_allocate_memory ***/
2829 GLX_FUNCTION( glXAllocateMemoryMESA
),
2830 GLX_FUNCTION( glXFreeMemoryMESA
),
2831 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2833 /*** GLX_MESA_copy_sub_buffer ***/
2834 GLX_FUNCTION( glXCopySubBufferMESA
),
2836 /*** GLX_MESA_pixmap_colormap ***/
2837 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2839 /*** GLX_MESA_release_buffers ***/
2840 GLX_FUNCTION( glXReleaseBuffersMESA
),
2842 /*** GLX_MESA_set_3dfx_mode ***/
2843 GLX_FUNCTION( glXSet3DfxModeMESA
),
2845 /*** GLX_MESA_swap_control ***/
2846 GLX_FUNCTION( glXSwapIntervalMESA
),
2847 GLX_FUNCTION( glXGetSwapIntervalMESA
),
2849 /*** GLX_MESA_swap_frame_usage ***/
2850 GLX_FUNCTION( glXBeginFrameTrackingMESA
),
2851 GLX_FUNCTION( glXEndFrameTrackingMESA
),
2852 GLX_FUNCTION( glXGetFrameUsageMESA
),
2853 GLX_FUNCTION( glXQueryFrameTrackingMESA
),
2855 /*** GLX_ARB_get_proc_address ***/
2856 GLX_FUNCTION( glXGetProcAddressARB
),
2859 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2861 /*** GLX_OML_sync_control ***/
2862 GLX_FUNCTION( glXWaitForSbcOML
),
2863 GLX_FUNCTION( glXWaitForMscOML
),
2864 GLX_FUNCTION( glXSwapBuffersMscOML
),
2865 GLX_FUNCTION( glXGetMscRateOML
),
2866 GLX_FUNCTION( glXGetSyncValuesOML
),
2868 #ifdef GLX_DIRECT_RENDERING
2870 *** Internal functions useful to DRI drivers
2871 *** With this, the DRI drivers shouldn't need dlopen()/dlsym() to
2872 *** access internal libGL functions which may or may not exist.
2874 GLX_FUNCTION( __glXInitialize
),
2875 GLX_FUNCTION( __glXFindDRIScreen
),
2876 GLX_FUNCTION( __glXGetInternalVersion
),
2877 GLX_FUNCTION( __glXWindowExists
),
2878 GLX_FUNCTION2( __glXCreateContextWithConfig
, XF86DRICreateContextWithConfig
),
2879 GLX_FUNCTION2( __glXGetDrawableInfo
, XF86DRIGetDrawableInfo
),
2881 /*** DRI configuration ***/
2882 GLX_FUNCTION( glXGetScreenDriver
),
2883 GLX_FUNCTION( glXGetDriverConfig
),
2885 GLX_FUNCTION( __glXScrEnableExtension
),
2887 GLX_FUNCTION( __glXGetUST
),
2889 GLX_FUNCTION2( __glXCreateContextModes
, _gl_context_modes_create
),
2890 GLX_FUNCTION2( __glXDestroyContextModes
, _gl_context_modes_destroy
),
2893 { NULL
, NULL
} /* end of list */
2897 static const GLvoid
*
2898 get_glx_proc_address(const char *funcName
)
2902 /* try static functions */
2903 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2904 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2905 return GLX_functions
[i
].Address
;
2912 #ifndef GLX_BUILT_IN_XMESA
2914 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2915 * \c glXGetProcAddress.
2917 * \param procName Name of a GL or GLX function.
2918 * \returns A pointer to the named function
2920 * \sa glXGetProcAddress
2922 void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2924 typedef void (*gl_function
)( void );
2928 /* Search the table of GLX and internal functions first. If that
2929 * fails and the supplied name could be a valid core GL name, try
2930 * searching the core GL function table. This check is done to prevent
2931 * DRI based drivers from searching the core GL function table for
2932 * internal API functions.
2935 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2936 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2937 && (procName
[2] != 'X') ) {
2938 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2945 * Get the address of a named GL function. This is the GLX 1.4 name for
2946 * \c glXGetProcAddressARB.
2948 * \param procName Name of a GL or GLX function.
2949 * \returns A pointer to the named function
2951 * \sa glXGetProcAddressARB
2953 void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2954 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2955 __attribute__ ((alias ("glXGetProcAddressARB")));
2958 return glXGetProcAddressARB(procName
);
2960 #endif /* __GNUC__ */
2961 #endif /* GLX_BUILT_IN_XMESA */
2964 #ifdef GLX_DIRECT_RENDERING
2966 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2967 * might be used by the DRI drivers to determine how new libGL is at runtime.
2968 * Drivers should not call this function directly. They should instead use
2969 * \c glXGetProcAddress to obtain a pointer to the function.
2971 * \returns An 8-digit decimal number representing the internal libGL API in
2974 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2976 * \since Internal API version 20021121.
2978 int __glXGetInternalVersion(void)
2981 * 20021121 - Initial version
2982 * 20021128 - Added __glXWindowExists() function
2983 * 20021207 - Added support for dynamic GLX extensions,
2984 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2985 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2986 * Never officially released. Do NOT test against
2987 * this version. Use 20030317 instead.
2988 * 20030317 - Added support GLX_SGIX_fbconfig,
2989 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2990 * GLX_{ARB,SGIS}_multisample, and
2991 * GLX_SGIX_visual_select_group.
2992 * 20030606 - Added support for GLX_SGI_make_current_read.
2993 * 20030813 - Made support for dynamic extensions multi-head aware.
2994 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2995 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2997 * 20031201 - Added support for the first round of DRI interface changes.
2998 * Do NOT test against this version! It has binary
2999 * compatibility bugs, use 20040317 instead.
3000 * 20040317 - Added the 'mode' field to __DRIcontextRec.
3001 * 20040415 - Added support for bindContext3 and unbindContext3.
3002 * 20040602 - Add __glXGetDrawableInfo. I though that was there
3010 static Bool windowExistsFlag
;
3012 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
3014 if (xerr
->error_code
== BadWindow
) {
3015 windowExistsFlag
= GL_FALSE
;
3021 * Determine if a window associated with a \c GLXDrawable exists on the
3022 * X-server. This function is not used internally by libGL. It is provided
3023 * as a utility function for DRI drivers.
3024 * Drivers should not call this function directly. They should instead use
3025 * \c glXGetProcAddress to obtain a pointer to the function.
3027 * \param dpy Display associated with the drawable to be queried.
3028 * \param draw \c GLXDrawable to test.
3030 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
3031 * otherwise \c GL_FALSE is returned.
3033 * \warning This function is not currently thread-safe.
3035 * \sa glXGetProcAddress
3037 * \since Internal API version 20021128.
3039 static Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
)
3041 XWindowAttributes xwa
;
3042 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
3044 XSync(dpy
, GL_FALSE
);
3045 windowExistsFlag
= GL_TRUE
;
3046 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
3047 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
3048 XSetErrorHandler(oldXErrorHandler
);
3049 return windowExistsFlag
;
3054 * Get the unadjusted system time (UST). Currently, the UST is measured in
3055 * microseconds since Epoc. The actual resolution of the UST may vary from
3056 * system to system, and the units may vary from release to release.
3057 * Drivers should not call this function directly. They should instead use
3058 * \c glXGetProcAddress to obtain a pointer to the function.
3060 * \param ust Location to store the 64-bit UST
3061 * \returns Zero on success or a negative errno value on failure.
3063 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3065 * \since Internal API version 20030317.
3067 int __glXGetUST( int64_t * ust
)
3071 if ( ust
== NULL
) {
3075 if ( gettimeofday( & tv
, NULL
) == 0 ) {
3076 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3082 #endif /* GLX_DIRECT_RENDERING */