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
);
71 static void * DriverCreateContextWrapper( const __GLXscreenConfigs
*psc
,
72 Display
*dpy
, XVisualInfo
*vis
, void *shared
, __DRIcontext
*ctx
,
73 const __GLcontextModes
*fbconfig
, int render_type
);
75 #ifndef DRI_NEW_INTERFACE_ONLY
76 static Bool
dummyBindContext2( Display
*dpy
, int scrn
,
77 GLXDrawable draw
, GLXDrawable read
, GLXContext gc
);
79 static Bool
dummyUnbindContext2( Display
*dpy
, int scrn
,
80 GLXDrawable draw
, GLXDrawable read
, GLXContext gc
);
82 /****************************************************************************/
85 * Used as glue when a driver does not support
86 * \c __DRIcontextRec::bindContext2.
88 * XXX .bindContext is only defined as a function pointer if
89 * !DRI_NEW_INTERFACE_ONLY.
91 * \sa DriverCreateContextWrapper, __DRIcontextRec::bindContext2
93 static Bool
dummyBindContext2( Display
*dpy
, int scrn
,
94 GLXDrawable draw
, GLXDrawable read
,
97 assert( draw
== read
);
98 return (*gc
->driContext
.bindContext
)( dpy
, scrn
, draw
, gc
);
102 * Used as glue when a driver does not support
103 * \c __DRIcontextRec::unbindContext2.
105 * XXX .unbindContext is only defined as a function pointer if
106 * !DRI_NEW_INTERFACE_ONLY.
108 * \sa DriverCreateContextWrapper, __DRIcontextRec::unbindContext2
110 static Bool
dummyUnbindContext2( Display
*dpy
, int scrn
,
111 GLXDrawable draw
, GLXDrawable read
,
114 assert( draw
== read
);
115 return (*gc
->driContext
.unbindContext
)( dpy
, scrn
, draw
, gc
, GL_FALSE
);
117 #endif /* DRI_NEW_INTERFACE_ONLY */
120 /****************************************************************************/
122 * Wrap the call to the driver's \c createContext function.
124 * The \c createContext function is wrapped because not all drivers support
125 * the "new" \c unbindContext2 and \c bindContext2 interfaces. libGL should
126 * not have to check to see which functions the driver supports. Instead,
127 * if either function is not supported it is wrapped. The wrappers test to
128 * make sure that both drawables are the same and pass control to the old
131 * \sa dummyBindContext2, dummyUnbindContext2,
132 * __DRIcontextRec::bindContext2, __DRIcontextRec::unbindContext2
135 static void * DriverCreateContextWrapper( const __GLXscreenConfigs
*psc
,
136 Display
*dpy
, XVisualInfo
*vis
,
139 const __GLcontextModes
*modes
,
142 void * ctx_priv
= NULL
;
144 if ( psc
->driScreen
.createNewContext
!= NULL
) {
145 assert( modes
!= NULL
);
146 ctx_priv
= (*psc
->driScreen
.createNewContext
)(dpy
, modes
, render_type
,
149 /* If the driver supports the createNewContext interface, then
150 * it MUST also support either the bindContext2 / unbindContext2
151 * interface or the bindContext3 / unbindContext3 interface.
154 assert( (ctx_priv
== NULL
) || (ctx
->unbindContext2
!= NULL
)
155 || (ctx
->unbindContext3
!= NULL
) );
156 assert( (ctx_priv
== NULL
) || (ctx
->bindContext2
!= NULL
)
157 || (ctx
->bindContext3
!= NULL
) );
159 #ifndef DRI_NEW_INTERFACE_ONLY
162 ctx_priv
= (*psc
->driScreen
.createContext
)(dpy
, vis
, shared
, ctx
);
164 if ( ctx_priv
!= NULL
) {
165 if ( ctx
->unbindContext2
== NULL
) {
166 ctx
->unbindContext2
= dummyUnbindContext2
;
169 if ( ctx
->bindContext2
== NULL
) {
170 ctx
->bindContext2
= dummyBindContext2
;
182 /****************************************************************************/
184 * Get the __DRIdrawable for the drawable associated with a GLXContext
186 * \param dpy The display associated with \c drawable.
187 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
188 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
189 * the drawable is not associated with a direct-rendering context.
192 #ifdef GLX_DIRECT_RENDERING
193 static __DRIdrawable
*
194 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
196 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
198 if ( (priv
!= NULL
) && (priv
->driDisplay
.private != NULL
) ) {
199 const unsigned screen_count
= ScreenCount(dpy
);
202 for ( i
= 0 ; i
< screen_count
; i
++ ) {
203 __DRIscreen
* const psc
= &priv
->screenConfigs
[i
].driScreen
;
204 __DRIdrawable
* const pdraw
= (psc
->private != NULL
)
205 ? (*psc
->getDrawable
)(dpy
, drawable
, psc
->private) : NULL
;
207 if ( pdraw
!= NULL
) {
208 if ( scrn_num
!= NULL
) {
222 * Get the GLX per-screen data structure associated with a GLX context.
224 * \param dpy Display for which the GLX per-screen information is to be
226 * \param scrn Screen on \c dpy for which the GLX per-screen information is
228 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
229 * specify a valid GLX screen, or NULL otherwise.
231 * \todo Should this function validate that \c scrn is within the screen
232 * number range for \c dpy?
235 static __GLXscreenConfigs
*
236 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
238 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
240 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
245 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
246 __GLXscreenConfigs
** ppsc
)
248 /* Initialize the extension, if needed . This has the added value
249 * of initializing/allocating the display private
253 return GLX_NO_EXTENSION
;
256 *ppriv
= __glXInitialize(dpy
);
257 if ( *ppriv
== NULL
) {
258 return GLX_NO_EXTENSION
;
261 /* Check screen number to see if its valid */
262 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
263 return GLX_BAD_SCREEN
;
266 /* Check to see if the GL is supported on this screen */
267 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
268 if ( (*ppsc
)->configs
== NULL
) {
269 /* No support for GL on this screen regardless of visual */
270 return GLX_BAD_VISUAL
;
278 * Determine if a \c GLXFBConfig supplied by the application is valid.
280 * \param dpy Application supplied \c Display pointer.
281 * \param config Application supplied \c GLXFBConfig.
283 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
284 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
287 static __GLcontextModes
*
288 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
290 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
291 const unsigned num_screens
= ScreenCount(dpy
);
293 const __GLcontextModes
* modes
;
296 if ( priv
!= NULL
) {
297 for ( i
= 0 ; i
< num_screens
; i
++ ) {
298 for ( modes
= priv
->screenConfigs
[i
].configs
300 ; modes
= modes
->next
) {
301 if ( modes
== (__GLcontextModes
*) config
) {
302 return (__GLcontextModes
*) config
;
313 * \todo It should be possible to move the allocate of \c client_state_private
314 * later in the function for direct-rendering contexts. Direct-rendering
315 * contexts don't need to track client state, so they don't need that memory
318 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
319 * function called \c __glXAllocateClientState that allocates the memory and
320 * does all the initialization (including the pixel pack / unpack).
323 GLXContext
AllocateGLXContext( Display
*dpy
)
328 __GLXattribute
*state
;
333 opcode
= __glXSetupForCommand(dpy
);
338 /* Allocate our context record */
339 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
344 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
346 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
352 gc
->client_state_private
= state
;
353 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
354 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
357 ** Create a temporary buffer to hold GLX rendering commands. The size
358 ** of the buffer is selected so that the maximum number of GLX rendering
359 ** commands can fit in a single X packet and still have room in the X
360 ** packet for the GLXRenderReq header.
363 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
364 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
366 Xfree(gc
->client_state_private
);
370 gc
->bufSize
= bufSize
;
372 /* Fill in the new context */
373 gc
->renderMode
= GL_RENDER
;
375 state
->storePack
.alignment
= 4;
376 state
->storeUnpack
.alignment
= 4;
378 __glXInitVertexArrayState(gc
);
380 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
383 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
384 ** Other code uses the fastImageUnpack bit, but it is never set
387 gc
->fastImageUnpack
= GL_FALSE
;
388 gc
->fillImage
= __glFillImage
;
389 gc
->isDirect
= GL_FALSE
;
391 gc
->bufEnd
= gc
->buf
+ bufSize
;
394 ** Set limit register so that there will be one command per packet
398 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
401 gc
->majorOpcode
= opcode
;
404 ** Constrain the maximum drawing command size allowed to be
405 ** transfered using the X_GLXRender protocol request. First
406 ** constrain by a software limit, then constrain by the protocl
409 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
410 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
412 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
413 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
415 gc
->maxSmallRenderCommandSize
= bufSize
;
421 * Create a new context. Exactly one of \c vis and \c fbconfig should be
424 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
425 * SGIX_fbconfig protocol be used?
426 * \param renderType For FBConfigs, what is the rendering type?
430 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
431 const __GLcontextModes
* const fbconfig
,
432 GLXContext shareList
,
433 Bool allowDirect
, GLXContextID contextID
,
434 Bool use_glx_1_3
, int renderType
)
441 gc
= AllocateGLXContext(dpy
);
445 if (None
== contextID
) {
446 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
449 #ifdef GLX_DIRECT_RENDERING
451 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
452 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
453 const __GLcontextModes
* mode
;
455 /* The value of fbconfig cannot change because it is tested
456 * later in the function.
458 if ( fbconfig
== NULL
) {
459 /* FIXME: Is it possible for the __GLcontextModes structure
460 * FIXME: to not be found?
462 mode
= _gl_context_modes_find_visual( psc
->configs
,
464 assert( mode
!= NULL
);
465 assert( mode
->screen
== screen
);
471 if (psc
&& psc
->driScreen
.private) {
472 void * const shared
= (shareList
!= NULL
)
473 ? shareList
->driContext
.private : NULL
;
474 gc
->driContext
.private =
475 DriverCreateContextWrapper( psc
, dpy
, vis
, shared
,
476 &gc
->driContext
, mode
,
478 if (gc
->driContext
.private) {
479 gc
->isDirect
= GL_TRUE
;
480 gc
->screen
= mode
->screen
;
481 gc
->vid
= mode
->visualID
;
482 gc
->fbconfigID
= mode
->fbconfigID
;
483 gc
->driContext
.mode
= mode
;
490 if ( fbconfig
== NULL
) {
491 xGLXCreateContextReq
*req
;
493 /* Send the glXCreateContext request */
494 GetReq(GLXCreateContext
,req
);
495 req
->reqType
= gc
->majorOpcode
;
496 req
->glxCode
= X_GLXCreateContext
;
497 req
->context
= gc
->xid
= XAllocID(dpy
);
498 req
->visual
= vis
->visualid
;
499 req
->screen
= vis
->screen
;
500 req
->shareList
= shareList
? shareList
->xid
: None
;
501 req
->isDirect
= gc
->isDirect
;
503 else if ( use_glx_1_3
) {
504 xGLXCreateNewContextReq
*req
;
506 /* Send the glXCreateNewContext request */
507 GetReq(GLXCreateNewContext
,req
);
508 req
->reqType
= gc
->majorOpcode
;
509 req
->glxCode
= X_GLXCreateNewContext
;
510 req
->context
= gc
->xid
= XAllocID(dpy
);
511 req
->fbconfig
= fbconfig
->fbconfigID
;
512 req
->screen
= fbconfig
->screen
;
513 req
->renderType
= renderType
;
514 req
->shareList
= shareList
? shareList
->xid
: None
;
515 req
->isDirect
= gc
->isDirect
;
518 xGLXVendorPrivateWithReplyReq
*vpreq
;
519 xGLXCreateContextWithConfigSGIXReq
*req
;
521 /* Send the glXCreateNewContext request */
522 GetReqExtra(GLXVendorPrivateWithReply
,
523 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
524 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
525 req
->reqType
= gc
->majorOpcode
;
526 req
->glxCode
= X_GLXVendorPrivateWithReply
;
527 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
528 req
->context
= gc
->xid
= XAllocID(dpy
);
529 req
->fbconfig
= fbconfig
->fbconfigID
;
530 req
->screen
= fbconfig
->screen
;
531 req
->renderType
= renderType
;
532 req
->shareList
= shareList
? shareList
->xid
: None
;
533 req
->isDirect
= gc
->isDirect
;
538 gc
->imported
= GL_FALSE
;
542 gc
->imported
= GL_TRUE
;
548 PUBLIC GLXContext
GLX_PREFIX(glXCreateContext
)(Display
*dpy
, XVisualInfo
*vis
,
549 GLXContext shareList
,
552 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
556 void __glXFreeContext(__GLXcontext
*gc
)
558 if (gc
->vendor
) XFree((char *) gc
->vendor
);
559 if (gc
->renderer
) XFree((char *) gc
->renderer
);
560 if (gc
->version
) XFree((char *) gc
->version
);
561 if (gc
->extensions
) XFree((char *) gc
->extensions
);
562 __glFreeAttributeState(gc
);
563 XFree((char *) gc
->buf
);
564 Xfree((char *) gc
->client_state_private
);
570 ** Destroy the named context
573 DestroyContext(Display
*dpy
, GLXContext gc
)
575 xGLXDestroyContextReq
*req
;
580 opcode
= __glXSetupForCommand(dpy
);
581 if (!opcode
|| !gc
) {
587 imported
= gc
->imported
;
590 #ifdef GLX_DIRECT_RENDERING
591 /* Destroy the direct rendering context */
593 if (gc
->driContext
.private) {
594 (*gc
->driContext
.destroyContext
)(dpy
, gc
->screen
,
595 gc
->driContext
.private);
596 gc
->driContext
.private = NULL
;
601 if (gc
->currentDpy
) {
602 /* Have to free later cuz it's in use now */
605 /* Destroy the handle if not current to anybody */
607 __glXFreeContext(gc
);
612 ** This dpy also created the server side part of the context.
613 ** Send the glXDestroyContext request.
616 GetReq(GLXDestroyContext
,req
);
617 req
->reqType
= opcode
;
618 req
->glxCode
= X_GLXDestroyContext
;
625 PUBLIC
void GLX_PREFIX(glXDestroyContext
)(Display
*dpy
, GLXContext gc
)
627 DestroyContext(dpy
, gc
);
631 ** Return the major and minor version #s for the GLX extension
633 PUBLIC Bool
GLX_PREFIX(glXQueryVersion
)(Display
*dpy
, int *major
, int *minor
)
635 __GLXdisplayPrivate
*priv
;
637 /* Init the extension. This fetches the major and minor version. */
638 priv
= __glXInitialize(dpy
);
639 if (!priv
) return GL_FALSE
;
641 if (major
) *major
= priv
->majorVersion
;
642 if (minor
) *minor
= priv
->minorVersion
;
647 ** Query the existance of the GLX extension
649 PUBLIC Bool
GLX_PREFIX(glXQueryExtension
)(Display
*dpy
, int *errorBase
,
652 int major_op
, erb
, evb
;
655 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
657 if (errorBase
) *errorBase
= erb
;
658 if (eventBase
) *eventBase
= evb
;
664 ** Put a barrier in the token stream that forces the GL to finish its
665 ** work before X can proceed.
667 PUBLIC
void GLX_PREFIX(glXWaitGL
)(void)
670 GLXContext gc
= __glXGetCurrentContext();
671 Display
*dpy
= gc
->currentDpy
;
675 /* Flush any pending commands out */
676 __glXFlushRenderBuffer(gc
, gc
->pc
);
678 #ifdef GLX_DIRECT_RENDERING
680 /* This bit of ugliness unwraps the glFinish function */
689 /* Send the glXWaitGL request */
691 GetReq(GLXWaitGL
,req
);
692 req
->reqType
= gc
->majorOpcode
;
693 req
->glxCode
= X_GLXWaitGL
;
694 req
->contextTag
= gc
->currentContextTag
;
700 ** Put a barrier in the token stream that forces X to finish its
701 ** work before GL can proceed.
703 PUBLIC
void GLX_PREFIX(glXWaitX
)(void)
706 GLXContext gc
= __glXGetCurrentContext();
707 Display
*dpy
= gc
->currentDpy
;
711 /* Flush any pending commands out */
712 __glXFlushRenderBuffer(gc
, gc
->pc
);
714 #ifdef GLX_DIRECT_RENDERING
722 ** Send the glXWaitX request.
725 GetReq(GLXWaitX
,req
);
726 req
->reqType
= gc
->majorOpcode
;
727 req
->glxCode
= X_GLXWaitX
;
728 req
->contextTag
= gc
->currentContextTag
;
733 PUBLIC
void GLX_PREFIX(glXUseXFont
)(Font font
, int first
, int count
,
736 xGLXUseXFontReq
*req
;
737 GLXContext gc
= __glXGetCurrentContext();
738 Display
*dpy
= gc
->currentDpy
;
742 /* Flush any pending commands out */
743 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
745 #ifdef GLX_DIRECT_RENDERING
747 DRI_glXUseXFont(font
, first
, count
, listBase
);
752 /* Send the glXUseFont request */
754 GetReq(GLXUseXFont
,req
);
755 req
->reqType
= gc
->majorOpcode
;
756 req
->glxCode
= X_GLXUseXFont
;
757 req
->contextTag
= gc
->currentContextTag
;
761 req
->listBase
= listBase
;
766 /************************************************************************/
769 ** Copy the source context to the destination context using the
772 PUBLIC
void GLX_PREFIX(glXCopyContext
)(Display
*dpy
, GLXContext source
,
773 GLXContext dest
, unsigned long mask
)
775 xGLXCopyContextReq
*req
;
776 GLXContext gc
= __glXGetCurrentContext();
780 opcode
= __glXSetupForCommand(dpy
);
785 #ifdef GLX_DIRECT_RENDERING
787 /* NOT_DONE: This does not work yet */
792 ** If the source is the current context, send its tag so that the context
793 ** can be flushed before the copy.
795 if (source
== gc
&& dpy
== gc
->currentDpy
) {
796 tag
= gc
->currentContextTag
;
801 /* Send the glXCopyContext request */
803 GetReq(GLXCopyContext
,req
);
804 req
->reqType
= opcode
;
805 req
->glxCode
= X_GLXCopyContext
;
806 req
->source
= source
? source
->xid
: None
;
807 req
->dest
= dest
? dest
->xid
: None
;
809 req
->contextTag
= tag
;
816 * Determine if a context uses direct rendering.
818 * \param dpy Display where the context was created.
819 * \param contextID ID of the context to be tested.
821 * \returns \c GL_TRUE if the context is direct rendering or not.
823 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
825 xGLXIsDirectReq
*req
;
826 xGLXIsDirectReply reply
;
829 opcode
= __glXSetupForCommand(dpy
);
834 /* Send the glXIsDirect request */
836 GetReq(GLXIsDirect
,req
);
837 req
->reqType
= opcode
;
838 req
->glxCode
= X_GLXIsDirect
;
839 req
->context
= contextID
;
840 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
844 return reply
.isDirect
;
847 PUBLIC Bool
GLX_PREFIX(glXIsDirect
)(Display
*dpy
, GLXContext gc
)
851 #ifdef GLX_DIRECT_RENDERING
852 } else if (gc
->isDirect
) {
856 return __glXIsDirect(dpy
, gc
->xid
);
859 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmap
)(Display
*dpy
, XVisualInfo
*vis
,
862 xGLXCreateGLXPixmapReq
*req
;
866 opcode
= __glXSetupForCommand(dpy
);
871 /* Send the glXCreateGLXPixmap request */
873 GetReq(GLXCreateGLXPixmap
,req
);
874 req
->reqType
= opcode
;
875 req
->glxCode
= X_GLXCreateGLXPixmap
;
876 req
->screen
= vis
->screen
;
877 req
->visual
= vis
->visualid
;
878 req
->pixmap
= pixmap
;
879 req
->glxpixmap
= xid
= XAllocID(dpy
);
886 ** Destroy the named pixmap
888 PUBLIC
void GLX_PREFIX(glXDestroyGLXPixmap
)(Display
*dpy
, GLXPixmap glxpixmap
)
890 xGLXDestroyGLXPixmapReq
*req
;
893 opcode
= __glXSetupForCommand(dpy
);
898 /* Send the glXDestroyGLXPixmap request */
900 GetReq(GLXDestroyGLXPixmap
,req
);
901 req
->reqType
= opcode
;
902 req
->glxCode
= X_GLXDestroyGLXPixmap
;
903 req
->glxpixmap
= glxpixmap
;
908 PUBLIC
void GLX_PREFIX(glXSwapBuffers
)(Display
*dpy
, GLXDrawable drawable
)
910 xGLXSwapBuffersReq
*req
;
914 #ifdef GLX_DIRECT_RENDERING
915 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
917 if ( pdraw
!= NULL
) {
918 (*pdraw
->swapBuffers
)(dpy
, pdraw
->private);
923 opcode
= __glXSetupForCommand(dpy
);
929 ** The calling thread may or may not have a current context. If it
930 ** does, send the context tag so the server can do a flush.
932 gc
= __glXGetCurrentContext();
933 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
934 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
935 tag
= gc
->currentContextTag
;
940 /* Send the glXSwapBuffers request */
942 GetReq(GLXSwapBuffers
,req
);
943 req
->reqType
= opcode
;
944 req
->glxCode
= X_GLXSwapBuffers
;
945 req
->drawable
= drawable
;
946 req
->contextTag
= tag
;
954 ** Return configuration information for the given display, screen and
955 ** visual combination.
957 PUBLIC
int GLX_PREFIX(glXGetConfig
)(Display
*dpy
, XVisualInfo
*vis
,
958 int attribute
, int *value_return
)
960 __GLXdisplayPrivate
*priv
;
961 __GLXscreenConfigs
*psc
;
964 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
965 if ( status
== Success
) {
966 const __GLcontextModes
* const modes
= _gl_context_modes_find_visual(
967 psc
->configs
, vis
->visualid
);
969 /* Lookup attribute after first finding a match on the visual */
970 if ( modes
!= NULL
) {
971 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
974 status
= GLX_BAD_VISUAL
;
978 ** If we can't find the config for this visual, this visual is not
979 ** supported by the OpenGL implementation on the server.
981 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
982 *value_return
= GL_FALSE
;
989 /************************************************************************/
992 init_fbconfig_for_chooser( __GLcontextModes
* config
,
993 GLboolean fbconfig_style_tags
)
995 memset( config
, 0, sizeof( __GLcontextModes
) );
996 config
->visualID
= (XID
) GLX_DONT_CARE
;
997 config
->visualType
= GLX_DONT_CARE
;
999 /* glXChooseFBConfig specifies different defaults for these two than
1002 if ( fbconfig_style_tags
) {
1003 config
->rgbMode
= GL_TRUE
;
1004 config
->doubleBufferMode
= GLX_DONT_CARE
;
1007 config
->visualRating
= GLX_DONT_CARE
;
1008 config
->transparentPixel
= GLX_NONE
;
1009 config
->transparentRed
= GLX_DONT_CARE
;
1010 config
->transparentGreen
= GLX_DONT_CARE
;
1011 config
->transparentBlue
= GLX_DONT_CARE
;
1012 config
->transparentAlpha
= GLX_DONT_CARE
;
1013 config
->transparentIndex
= GLX_DONT_CARE
;
1015 config
->drawableType
= GLX_WINDOW_BIT
;
1016 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1017 config
->xRenderable
= GLX_DONT_CARE
;
1018 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
1020 config
->swapMethod
= GLX_DONT_CARE
;
1023 #define MATCH_DONT_CARE( param ) \
1025 if ( (a-> param != GLX_DONT_CARE) \
1026 && (a-> param != b-> param) ) { \
1031 #define MATCH_MINIMUM( param ) \
1033 if ( (a-> param != GLX_DONT_CARE) \
1034 && (a-> param > b-> param) ) { \
1039 #define MATCH_EXACT( param ) \
1041 if ( a-> param != b-> param) { \
1047 * Determine if two GLXFBConfigs are compatible.
1049 * \param a Application specified config to test.
1050 * \param b Server specified config to test against \c a.
1053 fbconfigs_compatible( const __GLcontextModes
* const a
,
1054 const __GLcontextModes
* const b
)
1056 MATCH_DONT_CARE( doubleBufferMode
);
1057 MATCH_DONT_CARE( visualType
);
1058 MATCH_DONT_CARE( visualRating
);
1059 MATCH_DONT_CARE( xRenderable
);
1060 MATCH_DONT_CARE( fbconfigID
);
1061 MATCH_DONT_CARE( swapMethod
);
1063 MATCH_MINIMUM( rgbBits
);
1064 MATCH_MINIMUM( numAuxBuffers
);
1065 MATCH_MINIMUM( redBits
);
1066 MATCH_MINIMUM( greenBits
);
1067 MATCH_MINIMUM( blueBits
);
1068 MATCH_MINIMUM( alphaBits
);
1069 MATCH_MINIMUM( depthBits
);
1070 MATCH_MINIMUM( stencilBits
);
1071 MATCH_MINIMUM( accumRedBits
);
1072 MATCH_MINIMUM( accumGreenBits
);
1073 MATCH_MINIMUM( accumBlueBits
);
1074 MATCH_MINIMUM( accumAlphaBits
);
1075 MATCH_MINIMUM( sampleBuffers
);
1076 MATCH_MINIMUM( maxPbufferWidth
);
1077 MATCH_MINIMUM( maxPbufferHeight
);
1078 MATCH_MINIMUM( maxPbufferPixels
);
1079 MATCH_MINIMUM( samples
);
1081 MATCH_DONT_CARE( stereoMode
);
1082 MATCH_EXACT( level
);
1084 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1085 || ((a
->renderType
& b
->renderType
) == 0) ) {
1090 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1091 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1092 * Technically speaking, it is a bug in the DDX driver, but there is
1093 * enough of an installed base to work around the problem here. In any
1094 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1095 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1096 * 0 from the server to be a match to maintain backward compatibility with
1097 * the (broken) drivers.
1100 if ( a
->transparentPixel
!= GLX_DONT_CARE
1101 && a
->transparentPixel
!= 0 ) {
1102 if ( a
->transparentPixel
== GLX_NONE
) {
1103 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1106 MATCH_EXACT( transparentPixel
);
1109 switch ( a
->transparentPixel
) {
1110 case GLX_TRANSPARENT_RGB
:
1111 MATCH_DONT_CARE( transparentRed
);
1112 MATCH_DONT_CARE( transparentGreen
);
1113 MATCH_DONT_CARE( transparentBlue
);
1114 MATCH_DONT_CARE( transparentAlpha
);
1117 case GLX_TRANSPARENT_INDEX
:
1118 MATCH_DONT_CARE( transparentIndex
);
1130 /* There's some trickly language in the GLX spec about how this is supposed
1131 * to work. Basically, if a given component size is either not specified
1132 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1133 * Well, that's really hard to do with the code as-is. This behavior is
1134 * closer to correct, but still not technically right.
1136 #define PREFER_LARGER_OR_ZERO(comp) \
1138 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1139 if ( ((*a)-> comp) == 0 ) { \
1142 else if ( ((*b)-> comp) == 0 ) { \
1146 return ((*b)-> comp) - ((*a)-> comp) ; \
1151 #define PREFER_LARGER(comp) \
1153 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1154 return ((*b)-> comp) - ((*a)-> comp) ; \
1158 #define PREFER_SMALLER(comp) \
1160 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1161 return ((*a)-> comp) - ((*b)-> comp) ; \
1166 * Compare two GLXFBConfigs. This function is intended to be used as the
1167 * compare function passed in to qsort.
1169 * \returns If \c a is a "better" config, according to the specification of
1170 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1171 * better, then a number greater than zero is return. If both are
1172 * equal, zero is returned.
1173 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1176 fbconfig_compare( const __GLcontextModes
* const * const a
,
1177 const __GLcontextModes
* const * const b
)
1179 /* The order of these comparisons must NOT change. It is defined by
1180 * the GLX 1.3 spec and ARB_multisample.
1183 PREFER_SMALLER( visualSelectGroup
);
1185 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1186 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1187 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1189 PREFER_SMALLER( visualRating
);
1191 /* This isn't quite right. It is supposed to compare the sum of the
1192 * components the user specifically set minimums for.
1194 PREFER_LARGER_OR_ZERO( redBits
);
1195 PREFER_LARGER_OR_ZERO( greenBits
);
1196 PREFER_LARGER_OR_ZERO( blueBits
);
1197 PREFER_LARGER_OR_ZERO( alphaBits
);
1199 PREFER_SMALLER( rgbBits
);
1201 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1202 /* Prefer single-buffer.
1204 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1207 PREFER_SMALLER( numAuxBuffers
);
1209 PREFER_LARGER_OR_ZERO( depthBits
);
1210 PREFER_SMALLER( stencilBits
);
1212 /* This isn't quite right. It is supposed to compare the sum of the
1213 * components the user specifically set minimums for.
1215 PREFER_LARGER_OR_ZERO( accumRedBits
);
1216 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1217 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1218 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1220 PREFER_SMALLER( visualType
);
1222 /* None of the multisample specs say where this comparison should happen,
1223 * so I put it near the end.
1225 PREFER_SMALLER( sampleBuffers
);
1226 PREFER_SMALLER( samples
);
1228 /* None of the pbuffer or fbconfig specs say that this comparison needs
1229 * to happen at all, but it seems like it should.
1231 PREFER_LARGER( maxPbufferWidth
);
1232 PREFER_LARGER( maxPbufferHeight
);
1233 PREFER_LARGER( maxPbufferPixels
);
1240 * Selects and sorts a subset of the supplied configs based on the attributes.
1241 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1242 * and \c glXChooseFBConfigSGIX.
1244 * \param configs Array of pointers to possible configs. The elements of
1245 * this array that do not meet the criteria will be set to
1246 * NULL. The remaining elements will be sorted according to
1247 * the various visual / FBConfig selection rules.
1248 * \param num_configs Number of elements in the \c configs array.
1249 * \param attribList Attributes used select from \c configs. This array is
1250 * terminated by a \c None tag. The array can either take
1251 * the form expected by \c glXChooseVisual (where boolean
1252 * tags do not have a value) or by \c glXChooseFBConfig
1253 * (where every tag has a value).
1254 * \param fbconfig_style_tags Selects whether \c attribList is in
1255 * \c glXChooseVisual style or
1256 * \c glXChooseFBConfig style.
1257 * \returns The number of valid elements left in \c configs.
1259 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1262 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1263 const int *attribList
, GLboolean fbconfig_style_tags
)
1265 __GLcontextModes test_config
;
1269 /* This is a fairly direct implementation of the selection method
1270 * described by GLX_SGIX_fbconfig. Start by culling out all the
1271 * configs that are not compatible with the selected parameter
1275 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1276 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1277 (const INT32
*) attribList
,
1278 GL_TRUE
, fbconfig_style_tags
);
1281 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1282 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1283 configs
[ base
] = configs
[ i
];
1292 if ( base
< num_configs
) {
1293 (void) memset( & configs
[ base
], 0,
1294 sizeof( void * ) * (num_configs
- base
) );
1297 /* After the incompatible configs are removed, the resulting
1298 * list is sorted according to the rules set out in the various
1302 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1303 (int (*)(const void*, const void*)) fbconfig_compare
);
1311 ** Return the visual that best matches the template. Return None if no
1312 ** visual matches the template.
1314 PUBLIC XVisualInfo
*GLX_PREFIX(glXChooseVisual
)(Display
*dpy
, int screen
,
1317 XVisualInfo
*visualList
= NULL
;
1318 __GLXdisplayPrivate
*priv
;
1319 __GLXscreenConfigs
*psc
;
1320 __GLcontextModes test_config
;
1321 __GLcontextModes
*modes
;
1322 const __GLcontextModes
*best_config
= NULL
;
1325 ** Get a list of all visuals, return if list is empty
1327 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1333 ** Build a template from the defaults and the attribute list
1334 ** Free visual list and return if an unexpected token is encountered
1336 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1337 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1338 (const INT32
*) attribList
,
1339 GL_TRUE
, GL_FALSE
);
1342 ** Eliminate visuals that don't meet minimum requirements
1343 ** Compute a score for those that do
1344 ** Remember which visual, if any, got the highest score
1346 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
1347 if ( fbconfigs_compatible( & test_config
, modes
)
1348 && ((best_config
== NULL
)
1349 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1350 best_config
= modes
;
1355 ** If no visual is acceptable, return None
1356 ** Otherwise, create an XVisualInfo list with just the selected X visual
1359 if (best_config
!= NULL
) {
1360 XVisualInfo visualTemplate
;
1363 visualTemplate
.screen
= screen
;
1364 visualTemplate
.visualid
= best_config
->visualID
;
1365 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1366 &visualTemplate
, &i
);
1373 PUBLIC
const char *GLX_PREFIX(glXQueryExtensionsString
)( Display
*dpy
,
1376 __GLXscreenConfigs
*psc
;
1377 __GLXdisplayPrivate
*priv
;
1379 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1383 if (!psc
->effectiveGLXexts
) {
1384 if (!psc
->serverGLXexts
) {
1385 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1386 X_GLXQueryServerString
,
1387 screen
, GLX_EXTENSIONS
);
1390 __glXCalculateUsableExtensions(psc
,
1391 #ifdef GLX_DIRECT_RENDERING
1392 (priv
->driDisplay
.private != NULL
),
1396 priv
->minorVersion
);
1399 return psc
->effectiveGLXexts
;
1402 PUBLIC
const char *GLX_PREFIX(glXGetClientString
)( Display
*dpy
, int name
)
1406 return (__glXGLXClientVendorName
);
1408 return (__glXGLXClientVersion
);
1409 case GLX_EXTENSIONS
:
1410 return (__glXGetClientExtensions());
1416 PUBLIC
const char *GLX_PREFIX(glXQueryServerString
)( Display
*dpy
, int screen
,
1419 __GLXscreenConfigs
*psc
;
1420 __GLXdisplayPrivate
*priv
;
1424 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1430 str
= & priv
->serverGLXvendor
;
1433 str
= & priv
->serverGLXversion
;
1435 case GLX_EXTENSIONS
:
1436 str
= & psc
->serverGLXexts
;
1442 if ( *str
== NULL
) {
1443 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1444 X_GLXQueryServerString
, screen
, name
);
1450 void __glXClientInfo ( Display
*dpy
, int opcode
)
1452 xGLXClientInfoReq
*req
;
1454 char * ext_str
= __glXGetClientGLExtensionString();
1456 /* Send the glXClientInfo request */
1458 GetReq(GLXClientInfo
,req
);
1459 req
->reqType
= opcode
;
1460 req
->glxCode
= X_GLXClientInfo
;
1461 req
->major
= GLX_MAJOR_VERSION
;
1462 req
->minor
= GLX_MINOR_VERSION
;
1464 size
= strlen( ext_str
) + 1;
1465 req
->length
+= (size
+ 3) >> 2;
1466 req
->numbytes
= size
;
1467 Data(dpy
, ext_str
, size
);
1477 ** EXT_import_context
1480 PUBLIC Display
*glXGetCurrentDisplay(void)
1482 GLXContext gc
= __glXGetCurrentContext();
1483 if (NULL
== gc
) return NULL
;
1484 return gc
->currentDpy
;
1487 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1488 glXGetCurrentDisplay
)
1491 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1494 * \param dpy Display where \c ctx was created.
1495 * \param ctx Context to query.
1496 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1497 * or zero if the request failed due to internal problems (i.e.,
1498 * unable to allocate temporary memory, etc.)
1501 * This function dynamically determines whether to use the EXT_import_context
1502 * version of the protocol or the GLX 1.3 version of the protocol.
1504 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1506 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1507 xGLXQueryContextReply reply
;
1513 return GLX_BAD_CONTEXT
;
1515 opcode
= __glXSetupForCommand(dpy
);
1520 /* Send the glXQueryContextInfoEXT request */
1523 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1524 xGLXQueryContextReq
*req
;
1526 GetReq(GLXQueryContext
, req
);
1528 req
->reqType
= opcode
;
1529 req
->glxCode
= X_GLXQueryContext
;
1530 req
->context
= (unsigned int)(ctx
->xid
);
1533 xGLXVendorPrivateReq
*vpreq
;
1534 xGLXQueryContextInfoEXTReq
*req
;
1536 GetReqExtra( GLXVendorPrivate
,
1537 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1539 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1540 req
->reqType
= opcode
;
1541 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1542 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1543 req
->context
= (unsigned int)(ctx
->xid
);
1546 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1548 numValues
= reply
.n
;
1551 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1555 int *propList
, *pProp
;
1559 nPropListBytes
= numValues
<< 3;
1560 propList
= (int *) Xmalloc(nPropListBytes
);
1561 if (NULL
== propList
) {
1564 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1566 for (i
=0; i
< numValues
; i
++) {
1568 case GLX_SHARE_CONTEXT_EXT
:
1569 ctx
->share_xid
= *pProp
++;
1571 case GLX_VISUAL_ID_EXT
:
1572 ctx
->vid
= *pProp
++;
1575 ctx
->screen
= *pProp
++;
1577 case GLX_FBCONFIG_ID
:
1578 ctx
->fbconfigID
= *pProp
++;
1580 case GLX_RENDER_TYPE
:
1581 ctx
->renderType
= *pProp
++;
1588 Xfree((char *)propList
);
1598 GLX_PREFIX(glXQueryContext
)(Display
*dpy
, GLXContext ctx
,
1599 int attribute
, int *value
)
1603 /* get the information from the server if we don't have it already */
1604 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1605 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1606 if (Success
!= retVal
) return retVal
;
1608 switch (attribute
) {
1609 case GLX_SHARE_CONTEXT_EXT
:
1610 *value
= (int)(ctx
->share_xid
);
1612 case GLX_VISUAL_ID_EXT
:
1613 *value
= (int)(ctx
->vid
);
1616 *value
= (int)(ctx
->screen
);
1618 case GLX_FBCONFIG_ID
:
1619 *value
= (int)(ctx
->fbconfigID
);
1621 case GLX_RENDER_TYPE
:
1622 *value
= (int)(ctx
->renderType
);
1625 return GLX_BAD_ATTRIBUTE
;
1630 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1631 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1632 (dpy
, ctx
, attribute
, value
),
1635 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1640 PUBLIC GLXContext
GLX_PREFIX(glXImportContextEXT
)(Display
*dpy
,
1641 GLXContextID contextID
)
1645 if (contextID
== None
) {
1648 if (__glXIsDirect(dpy
, contextID
)) {
1652 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1654 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1661 PUBLIC
void GLX_PREFIX(glXFreeContextEXT
)(Display
*dpy
, GLXContext ctx
)
1663 DestroyContext(dpy
, ctx
);
1669 * GLX 1.3 functions - these are just stubs for now!
1672 PUBLIC GLXFBConfig
*GLX_PREFIX(glXChooseFBConfig
)(Display
*dpy
, int screen
,
1673 const int *attribList
,
1676 __GLcontextModes
** config_list
;
1680 config_list
= (__GLcontextModes
**)
1681 GLX_PREFIX(glXGetFBConfigs
)( dpy
, screen
, & list_size
);
1683 if ( (config_list
!= NULL
) && (list_size
> 0) ) {
1684 list_size
= choose_visual( config_list
, list_size
, attribList
,
1686 if ( list_size
== 0 ) {
1687 XFree( config_list
);
1692 *nitems
= list_size
;
1693 return (GLXFBConfig
*) config_list
;
1697 PUBLIC GLXContext
GLX_PREFIX(glXCreateNewContext
)(Display
*dpy
,
1700 GLXContext shareList
,
1703 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1704 allowDirect
, None
, True
, renderType
);
1708 PUBLIC GLXDrawable
GLX_PREFIX(glXGetCurrentReadDrawable
)(void)
1710 GLXContext gc
= __glXGetCurrentContext();
1711 return gc
->currentReadable
;
1715 PUBLIC GLXFBConfig
*GLX_PREFIX(glXGetFBConfigs
)(Display
*dpy
, int screen
,
1718 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1719 __GLcontextModes
** config
= NULL
;
1722 if ( (priv
->screenConfigs
!= NULL
)
1723 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1724 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1725 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1726 unsigned num_configs
= 0;
1727 __GLcontextModes
* modes
;
1730 for ( modes
= priv
->screenConfigs
[screen
].configs
1732 ; modes
= modes
->next
) {
1733 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1738 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1740 if ( config
!= NULL
) {
1741 *nelements
= num_configs
;
1743 for ( modes
= priv
->screenConfigs
[screen
].configs
1745 ; modes
= modes
->next
) {
1751 return (GLXFBConfig
*) config
;
1755 PUBLIC
int GLX_PREFIX(glXGetFBConfigAttrib
)(Display
*dpy
, GLXFBConfig config
,
1756 int attribute
, int *value
)
1758 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1760 return (modes
!= NULL
)
1761 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1766 PUBLIC XVisualInfo
*GLX_PREFIX(glXGetVisualFromFBConfig
)(Display
*dpy
,
1769 XVisualInfo visualTemplate
;
1770 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1774 ** Get a list of all visuals, return if list is empty
1776 visualTemplate
.visualid
= fbconfig
->visualID
;
1777 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1782 ** GLX_SGI_make_current_read
1785 PUBLIC
GLX_ALIAS(GLXDrawable
, glXGetCurrentReadDrawableSGI
, (void), (),
1786 glXGetCurrentReadDrawable
)
1790 ** GLX_SGI_swap_control
1792 PUBLIC
int GLX_PREFIX(glXSwapIntervalSGI
)(int interval
)
1794 xGLXVendorPrivateReq
*req
;
1795 GLXContext gc
= __glXGetCurrentContext();
1797 CARD32
* interval_ptr
;
1801 return GLX_BAD_CONTEXT
;
1804 if ( interval
<= 0 ) {
1805 return GLX_BAD_VALUE
;
1808 #ifdef GLX_DIRECT_RENDERING
1809 if ( gc
->isDirect
) {
1810 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1812 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1813 gc
->currentDrawable
,
1815 if ( __glXExtensionBitIsEnabled( psc
, SGI_swap_control_bit
)
1816 && (pdraw
!= NULL
) ) {
1817 pdraw
->swap_interval
= interval
;
1821 return GLX_BAD_CONTEXT
;
1825 dpy
= gc
->currentDpy
;
1826 opcode
= __glXSetupForCommand(dpy
);
1831 /* Send the glXSwapIntervalSGI request */
1833 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1834 req
->reqType
= opcode
;
1835 req
->glxCode
= X_GLXVendorPrivate
;
1836 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1837 req
->contextTag
= gc
->currentContextTag
;
1839 interval_ptr
= (CARD32
*) req
+ 1;
1840 *interval_ptr
= interval
;
1851 ** GLX_MESA_swap_control
1853 PUBLIC GLint
GLX_PREFIX(glXSwapIntervalMESA
)(unsigned interval
)
1855 #ifdef GLX_DIRECT_RENDERING
1856 GLXContext gc
= __glXGetCurrentContext();
1858 if ( interval
< 0 ) {
1859 return GLX_BAD_VALUE
;
1862 if ( (gc
!= NULL
) && gc
->isDirect
) {
1863 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1866 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1867 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1868 __DRIdrawable
* const pdraw
=
1869 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1870 gc
->currentDrawable
,
1871 psc
->driScreen
.private);
1872 if ( pdraw
!= NULL
) {
1873 pdraw
->swap_interval
= interval
;
1882 return GLX_BAD_CONTEXT
;
1885 PUBLIC GLint
GLX_PREFIX(glXGetSwapIntervalMESA
)( void )
1887 #ifdef GLX_DIRECT_RENDERING
1888 GLXContext gc
= __glXGetCurrentContext();
1890 if ( (gc
!= NULL
) && gc
->isDirect
) {
1891 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1894 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1895 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1896 __DRIdrawable
* const pdraw
=
1897 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1898 gc
->currentDrawable
,
1899 psc
->driScreen
.private);
1900 if ( pdraw
!= NULL
) {
1901 return pdraw
->swap_interval
;
1912 ** GLX_MESA_swap_frame_usage
1915 PUBLIC GLint
GLX_PREFIX(glXBeginFrameTrackingMESA
)(Display
*dpy
,
1916 GLXDrawable drawable
)
1918 int status
= GLX_BAD_CONTEXT
;
1919 #ifdef GLX_DIRECT_RENDERING
1921 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1922 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1924 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1925 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1926 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_TRUE
);
1936 PUBLIC GLint
GLX_PREFIX(glXEndFrameTrackingMESA
)(Display
*dpy
,
1937 GLXDrawable drawable
)
1939 int status
= GLX_BAD_CONTEXT
;
1940 #ifdef GLX_DIRECT_RENDERING
1942 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1943 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1945 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1946 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1947 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_FALSE
);
1957 PUBLIC GLint
GLX_PREFIX(glXGetFrameUsageMESA
)(Display
*dpy
,
1958 GLXDrawable drawable
,
1961 int status
= GLX_BAD_CONTEXT
;
1962 #ifdef GLX_DIRECT_RENDERING
1964 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1965 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1967 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1968 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1969 int64_t sbc
, missedFrames
;
1970 float lastMissedUsage
;
1972 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, &sbc
,
1973 &missedFrames
, &lastMissedUsage
,
1985 PUBLIC GLint
GLX_PREFIX(glXQueryFrameTrackingMESA
)(Display
*dpy
,
1986 GLXDrawable drawable
,
1988 int64_t *missedFrames
,
1989 GLfloat
*lastMissedUsage
)
1991 int status
= GLX_BAD_CONTEXT
;
1992 #ifdef GLX_DIRECT_RENDERING
1994 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1995 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1997 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1998 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
2001 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, sbc
,
2002 missedFrames
, lastMissedUsage
,
2009 (void) missedFrames
;
2010 (void) lastMissedUsage
;
2017 ** GLX_SGI_video_sync
2019 PUBLIC
int GLX_PREFIX(glXGetVideoSyncSGI
)(unsigned int *count
)
2021 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2022 * FIXME: there should be a GLX encoding for this call. I can find no
2023 * FIXME: documentation for the GLX encoding.
2025 #ifdef GLX_DIRECT_RENDERING
2026 GLXContext gc
= __glXGetCurrentContext();
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 && psc
->driScreen
.getMSC
) {
2037 ret
= psc
->driScreen
.getMSC( psc
->driScreen
.private, & temp
);
2038 *count
= (unsigned) temp
;
2039 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2045 return GLX_BAD_CONTEXT
;
2048 PUBLIC
int GLX_PREFIX(glXWaitVideoSyncSGI
)(int divisor
, int remainder
,
2049 unsigned int *count
)
2051 #ifdef GLX_DIRECT_RENDERING
2052 GLXContext gc
= __glXGetCurrentContext();
2054 if ( divisor
<= 0 || remainder
< 0 )
2055 return GLX_BAD_VALUE
;
2057 if ( (gc
!= NULL
) && gc
->isDirect
) {
2058 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2060 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
2061 && psc
->driScreen
.private ) {
2062 __DRIdrawable
* const pdraw
=
2063 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
2064 gc
->currentDrawable
,
2065 psc
->driScreen
.private);
2066 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
) ) {
2071 ret
= (*pdraw
->waitForMSC
)( gc
->currentDpy
, pdraw
->private,
2072 0, divisor
, remainder
,
2074 *count
= (unsigned) msc
;
2075 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2082 return GLX_BAD_CONTEXT
;
2087 ** GLX_SGIS_video_source
2091 PUBLIC GLXVideoSourceSGIX
GLX_PREFIX(glXCreateGLXVideoSourceSGIX
)(Display
*dpy
,
2092 int screen
, VLServer server
, VLPath path
,
2093 int nodeClass
, VLNode drainNode
)
2104 PUBLIC
void GLX_PREFIX(glXDestroyGLXVideoSourceSGIX
)(Display
*dpy
,
2105 GLXVideoSourceSGIX src
)
2115 ** GLX_SGIX_fbconfig
2116 ** Many of these functions are aliased to GLX 1.3 entry points in the
2117 ** GLX_functions table.
2120 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2121 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2122 (dpy
, config
, attribute
, value
),
2123 glXGetFBConfigAttrib
)
2125 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2126 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2127 (dpy
, screen
, attrib_list
, nelements
),
2130 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2131 (Display
* dpy
, GLXFBConfigSGIX config
),
2133 glXGetVisualFromFBConfig
)
2135 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapWithConfigSGIX
)(Display
*dpy
,
2136 GLXFBConfigSGIX config
, Pixmap pixmap
)
2138 xGLXVendorPrivateWithReplyReq
*vpreq
;
2139 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2140 GLXPixmap xid
= None
;
2142 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2143 __GLXscreenConfigs
* psc
;
2146 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2150 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2152 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2153 opcode
= __glXSetupForCommand(dpy
);
2158 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2160 GetReqExtra(GLXVendorPrivateWithReply
,
2161 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2162 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2163 req
->reqType
= opcode
;
2164 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2165 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2166 req
->screen
= fbconfig
->screen
;
2167 req
->fbconfig
= fbconfig
->fbconfigID
;
2168 req
->pixmap
= pixmap
;
2169 req
->glxpixmap
= xid
= XAllocID(dpy
);
2177 PUBLIC GLXContext
GLX_PREFIX(glXCreateContextWithConfigSGIX
)(Display
*dpy
,
2178 GLXFBConfigSGIX config
, int renderType
,
2179 GLXContext shareList
, Bool allowDirect
)
2181 GLXContext gc
= NULL
;
2182 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2183 __GLXscreenConfigs
* psc
;
2186 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2190 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2192 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2193 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2194 allowDirect
, None
, False
, renderType
);
2201 PUBLIC GLXFBConfigSGIX
GLX_PREFIX(glXGetFBConfigFromVisualSGIX
)(Display
*dpy
,
2204 __GLXdisplayPrivate
*priv
;
2205 __GLXscreenConfigs
*psc
;
2207 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2208 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2209 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2210 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2221 PUBLIC
void GLX_PREFIX(glXCushionSGI
)(Display
*dpy
, Window win
, float cushion
)
2230 ** GLX_SGIX_video_resize
2232 PUBLIC
int GLX_PREFIX(glXBindChannelToWindowSGIX
)(Display
*dpy
, int screen
,
2233 int channel
, Window window
)
2242 PUBLIC
int GLX_PREFIX(glXChannelRectSGIX
)(Display
*dpy
, int screen
, int channel
,
2243 int x
, int y
, int w
, int h
)
2255 PUBLIC
int GLX_PREFIX(glXQueryChannelRectSGIX
)(Display
*dpy
, int screen
,
2256 int channel
, int *x
, int *y
,
2269 int GLX_PREFIX(glXQueryChannelDeltasSGIX
)(Display
*dpy
, int screen
, int channel
,
2270 int *dx
, int *dy
, int *dw
, int *dh
)
2282 PUBLIC
int GLX_PREFIX(glXChannelRectSyncSGIX
)(Display
*dpy
, int screen
,
2283 int channel
, GLenum synctype
)
2293 #if defined(_DM_BUFFER_H_)
2295 PUBLIC Bool
GLX_PREFIX(glXAssociateDMPbufferSGIX
)(Display
*dpy
,
2296 GLXPbufferSGIX pbuffer
,
2311 ** GLX_SGIX_swap_group
2313 PUBLIC
void GLX_PREFIX(glXJoinSwapGroupSGIX
)(Display
*dpy
, GLXDrawable drawable
,
2323 ** GLX_SGIX_swap_barrier
2325 PUBLIC
void GLX_PREFIX(glXBindSwapBarrierSGIX
)(Display
*dpy
,
2326 GLXDrawable drawable
,
2334 PUBLIC Bool
GLX_PREFIX(glXQueryMaxSwapBarriersSGIX
)(Display
*dpy
, int screen
,
2345 ** GLX_SUN_get_transparent_index
2347 PUBLIC Status
GLX_PREFIX(glXGetTransparentIndexSUN
)(Display
*dpy
,
2355 (void) pTransparent
;
2361 ** GLX_OML_sync_control
2363 PUBLIC Bool
GLX_PREFIX(glXGetSyncValuesOML
)(Display
*dpy
, GLXDrawable drawable
,
2364 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2366 #ifdef GLX_DIRECT_RENDERING
2367 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2369 if ( priv
!= NULL
) {
2371 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2372 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2374 assert( (pdraw
== NULL
) || (i
!= -1) );
2375 return ( (pdraw
&& pdraw
->getSBC
&& psc
->driScreen
.getMSC
)
2376 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)
2377 && ((*psc
->driScreen
.getMSC
)( psc
->driScreen
.private, msc
) == 0)
2378 && ((*pdraw
->getSBC
)( dpy
, psc
->driScreen
.private, sbc
) == 0)
2379 && (__glXGetUST( ust
) == 0) );
2393 * Determine the refresh rate of the specified drawable and display.
2395 * \param dpy Display whose refresh rate is to be determined.
2396 * \param drawable Drawable whose refresh rate is to be determined.
2397 * \param numerator Numerator of the refresh rate.
2398 * \param demoninator Denominator of the refresh rate.
2399 * \return If the refresh rate for the specified display and drawable could
2400 * be calculated, True is returned. Otherwise False is returned.
2402 * \note This function is implemented entirely client-side. A lot of other
2403 * functionality is required to export GLX_OML_sync_control, so on
2404 * XFree86 this function can be called for direct-rendering contexts
2405 * when GLX_OML_sync_control appears in the client extension string.
2408 PUBLIC Bool
GLX_PREFIX(glXGetMscRateOML
)(Display
* dpy
, GLXDrawable drawable
,
2409 int32_t * numerator
, int32_t * denominator
)
2411 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2412 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2415 if ( priv
!= NULL
) {
2416 XF86VidModeModeLine mode_line
;
2422 GetDRIDrawable( dpy
, drawable
, & screen_num
);
2423 if ( (screen_num
!= -1)
2424 && XF86VidModeQueryVersion( dpy
, & i
, & i
)
2425 && XF86VidModeGetModeLine( dpy
, screen_num
, & dot_clock
,
2427 unsigned n
= dot_clock
* 1000;
2428 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2430 # define V_INTERLACE 0x010
2431 # define V_DBLSCAN 0x020
2433 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2436 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2440 /* The OML_sync_control spec requires that if the refresh rate is a
2441 * whole number, that the returned numerator be equal to the refresh
2442 * rate and the denominator be 1.
2445 if ( (n
% d
) == 0 ) {
2450 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2453 /* This is a poor man's way to reduce a fraction. It's far from
2454 * perfect, but it will work well enough for this situation.
2457 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2458 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2482 PUBLIC
int64_t GLX_PREFIX(glXSwapBuffersMscOML
)(Display
*dpy
,
2483 GLXDrawable drawable
,
2488 #ifdef GLX_DIRECT_RENDERING
2490 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2491 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2493 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2494 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2495 * of -1 if the function failed because of errors detected in the input
2498 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2500 if ( divisor
> 0 && remainder
>= divisor
)
2503 if ( (pdraw
!= NULL
) && (pdraw
->swapBuffersMSC
!= NULL
)
2504 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2505 return (*pdraw
->swapBuffersMSC
)(dpy
, pdraw
->private, target_msc
,
2506 divisor
, remainder
);
2519 PUBLIC Bool
GLX_PREFIX(glXWaitForMscOML
)(Display
* dpy
, GLXDrawable drawable
,
2520 int64_t target_msc
, int64_t divisor
,
2521 int64_t remainder
, int64_t *ust
,
2522 int64_t *msc
, int64_t *sbc
)
2524 #ifdef GLX_DIRECT_RENDERING
2526 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2527 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2530 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2531 * error", but the return type in the spec is Bool.
2533 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2535 if ( divisor
> 0 && remainder
>= divisor
)
2538 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
)
2539 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2540 ret
= (*pdraw
->waitForMSC
)( dpy
, pdraw
->private, target_msc
,
2541 divisor
, remainder
, msc
, sbc
);
2543 /* __glXGetUST returns zero on success and non-zero on failure.
2544 * This function returns True on success and False on failure.
2546 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2562 PUBLIC Bool
GLX_PREFIX(glXWaitForSbcOML
)(Display
* dpy
, GLXDrawable drawable
,
2563 int64_t target_sbc
, int64_t *ust
,
2564 int64_t *msc
, int64_t *sbc
)
2566 #ifdef GLX_DIRECT_RENDERING
2568 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2569 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2572 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2573 * error", but the return type in the spec is Bool.
2575 if ( target_sbc
< 0 )
2578 if ( (pdraw
!= NULL
) && (pdraw
->waitForSBC
!= NULL
)
2579 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)) {
2580 ret
= (*pdraw
->waitForSBC
)( dpy
, pdraw
->private, target_sbc
, msc
, sbc
);
2582 /* __glXGetUST returns zero on success and non-zero on failure.
2583 * This function returns True on success and False on failure.
2585 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2600 * GLX_MESA_allocate_memory
2604 PUBLIC
void *GLX_PREFIX(glXAllocateMemoryMESA
)(Display
*dpy
, int scrn
,
2605 size_t size
, float readFreq
,
2606 float writeFreq
, float priority
)
2608 #ifdef GLX_DIRECT_RENDERING
2609 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2611 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2612 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.allocateMemory
) {
2613 return (*psc
->driScreen
.allocateMemory
)( dpy
, scrn
, size
,
2614 readFreq
, writeFreq
,
2625 #endif /* GLX_DIRECT_RENDERING */
2631 PUBLIC
void GLX_PREFIX(glXFreeMemoryMESA
)(Display
*dpy
, int scrn
, void *pointer
)
2633 #ifdef GLX_DIRECT_RENDERING
2634 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2636 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2637 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.freeMemory
) {
2638 (*psc
->driScreen
.freeMemory
)( dpy
, scrn
, pointer
);
2645 #endif /* GLX_DIRECT_RENDERING */
2649 PUBLIC GLuint
GLX_PREFIX(glXGetMemoryOffsetMESA
)( Display
*dpy
, int scrn
,
2650 const void *pointer
)
2652 #ifdef GLX_DIRECT_RENDERING
2653 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2655 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2656 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.memoryOffset
) {
2657 return (*psc
->driScreen
.memoryOffset
)( dpy
, scrn
, pointer
);
2664 #endif /* GLX_DIRECT_RENDERING */
2672 * Mesa extension stubs. These will help reduce portability problems.
2677 * Release all buffers associated with the specified GLX drawable.
2680 * This function was intended for stand-alone Mesa. The issue there is that
2681 * the library doesn't get any notification when a window is closed. In
2682 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2683 * supported, there are 3 different functions to destroy a drawable. It
2684 * should be possible to create GLX protocol (or have it determine which
2685 * protocol to use based on the type of the drawable) to have one function
2686 * do the work of 3. For the direct-rendering case, this function could
2687 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2688 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2689 * would need to be used. This really should be done as part of the new DRI
2692 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2693 * __driGarbageCollectDrawables
2694 * glXDestroyGLXPixmap
2695 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2696 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2698 PUBLIC Bool
GLX_PREFIX(glXReleaseBuffersMESA
)( Display
*dpy
, GLXDrawable d
)
2706 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapMESA
)( Display
*dpy
,
2707 XVisualInfo
*visual
,
2719 PUBLIC
void GLX_PREFIX(glXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
,
2721 int width
, int height
)
2732 PUBLIC Bool
GLX_PREFIX(glXSet3DfxModeMESA
)( int mode
)
2742 * \c strdup is actually not a standard ANSI C or POSIX routine.
2743 * Irix will not define it if ANSI mode is in effect.
2748 __glXstrdup(const char *str
)
2751 copy
= (char *) Xmalloc(strlen(str
) + 1);
2759 ** glXGetProcAddress support
2762 struct name_address_pair
{
2767 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2768 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2770 static const struct name_address_pair GLX_functions
[] = {
2771 /*** GLX_VERSION_1_0 ***/
2772 GLX_FUNCTION( glXChooseVisual
),
2773 GLX_FUNCTION( glXCopyContext
),
2774 GLX_FUNCTION( glXCreateContext
),
2775 GLX_FUNCTION( glXCreateGLXPixmap
),
2776 GLX_FUNCTION( glXDestroyContext
),
2777 GLX_FUNCTION( glXDestroyGLXPixmap
),
2778 GLX_FUNCTION( glXGetConfig
),
2779 GLX_FUNCTION( glXGetCurrentContext
),
2780 GLX_FUNCTION( glXGetCurrentDrawable
),
2781 GLX_FUNCTION( glXIsDirect
),
2782 GLX_FUNCTION( glXMakeCurrent
),
2783 GLX_FUNCTION( glXQueryExtension
),
2784 GLX_FUNCTION( glXQueryVersion
),
2785 GLX_FUNCTION( glXSwapBuffers
),
2786 GLX_FUNCTION( glXUseXFont
),
2787 GLX_FUNCTION( glXWaitGL
),
2788 GLX_FUNCTION( glXWaitX
),
2790 /*** GLX_VERSION_1_1 ***/
2791 GLX_FUNCTION( glXGetClientString
),
2792 GLX_FUNCTION( glXQueryExtensionsString
),
2793 GLX_FUNCTION( glXQueryServerString
),
2795 /*** GLX_VERSION_1_2 ***/
2796 GLX_FUNCTION( glXGetCurrentDisplay
),
2798 /*** GLX_VERSION_1_3 ***/
2799 GLX_FUNCTION( glXChooseFBConfig
),
2800 GLX_FUNCTION( glXCreateNewContext
),
2801 GLX_FUNCTION( glXCreatePbuffer
),
2802 GLX_FUNCTION( glXCreatePixmap
),
2803 GLX_FUNCTION( glXCreateWindow
),
2804 GLX_FUNCTION( glXDestroyPbuffer
),
2805 GLX_FUNCTION( glXDestroyPixmap
),
2806 GLX_FUNCTION( glXDestroyWindow
),
2807 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2808 GLX_FUNCTION( glXGetFBConfigAttrib
),
2809 GLX_FUNCTION( glXGetFBConfigs
),
2810 GLX_FUNCTION( glXGetSelectedEvent
),
2811 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2812 GLX_FUNCTION( glXMakeContextCurrent
),
2813 GLX_FUNCTION( glXQueryContext
),
2814 GLX_FUNCTION( glXQueryDrawable
),
2815 GLX_FUNCTION( glXSelectEvent
),
2817 /*** GLX_SGI_swap_control ***/
2818 GLX_FUNCTION( glXSwapIntervalSGI
),
2820 /*** GLX_SGI_video_sync ***/
2821 GLX_FUNCTION( glXGetVideoSyncSGI
),
2822 GLX_FUNCTION( glXWaitVideoSyncSGI
),
2824 /*** GLX_SGI_make_current_read ***/
2825 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2826 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2828 /*** GLX_SGIX_video_source ***/
2830 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX
),
2831 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX
),
2834 /*** GLX_EXT_import_context ***/
2835 GLX_FUNCTION( glXFreeContextEXT
),
2836 GLX_FUNCTION( glXGetContextIDEXT
),
2837 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2838 GLX_FUNCTION( glXImportContextEXT
),
2839 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2841 /*** GLX_SGIX_fbconfig ***/
2842 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2843 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2844 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2845 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2846 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2847 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2849 /*** GLX_SGIX_pbuffer ***/
2850 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2851 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2852 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2853 GLX_FUNCTION( glXSelectEventSGIX
),
2854 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2856 /*** GLX_SGI_cushion ***/
2857 GLX_FUNCTION( glXCushionSGI
),
2859 /*** GLX_SGIX_video_resize ***/
2860 GLX_FUNCTION( glXBindChannelToWindowSGIX
),
2861 GLX_FUNCTION( glXChannelRectSGIX
),
2862 GLX_FUNCTION( glXQueryChannelRectSGIX
),
2863 GLX_FUNCTION( glXQueryChannelDeltasSGIX
),
2864 GLX_FUNCTION( glXChannelRectSyncSGIX
),
2866 /*** GLX_SGIX_dmbuffer **/
2867 #if defined(_DM_BUFFER_H_)
2868 GLX_FUNCTION( glXAssociateDMPbufferSGIX
),
2871 /*** GLX_SGIX_swap_group ***/
2872 GLX_FUNCTION( glXJoinSwapGroupSGIX
),
2874 /*** GLX_SGIX_swap_barrier ***/
2875 GLX_FUNCTION( glXBindSwapBarrierSGIX
),
2876 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX
),
2878 /*** GLX_SUN_get_transparent_index ***/
2879 GLX_FUNCTION( glXGetTransparentIndexSUN
),
2881 /*** GLX_MESA_allocate_memory ***/
2882 GLX_FUNCTION( glXAllocateMemoryMESA
),
2883 GLX_FUNCTION( glXFreeMemoryMESA
),
2884 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2886 /*** GLX_MESA_copy_sub_buffer ***/
2887 GLX_FUNCTION( glXCopySubBufferMESA
),
2889 /*** GLX_MESA_pixmap_colormap ***/
2890 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2892 /*** GLX_MESA_release_buffers ***/
2893 GLX_FUNCTION( glXReleaseBuffersMESA
),
2895 /*** GLX_MESA_set_3dfx_mode ***/
2896 GLX_FUNCTION( glXSet3DfxModeMESA
),
2898 /*** GLX_MESA_swap_control ***/
2899 GLX_FUNCTION( glXSwapIntervalMESA
),
2900 GLX_FUNCTION( glXGetSwapIntervalMESA
),
2902 /*** GLX_MESA_swap_frame_usage ***/
2903 GLX_FUNCTION( glXBeginFrameTrackingMESA
),
2904 GLX_FUNCTION( glXEndFrameTrackingMESA
),
2905 GLX_FUNCTION( glXGetFrameUsageMESA
),
2906 GLX_FUNCTION( glXQueryFrameTrackingMESA
),
2908 /*** GLX_ARB_get_proc_address ***/
2909 GLX_FUNCTION( glXGetProcAddressARB
),
2912 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2914 /*** GLX_OML_sync_control ***/
2915 GLX_FUNCTION( glXWaitForSbcOML
),
2916 GLX_FUNCTION( glXWaitForMscOML
),
2917 GLX_FUNCTION( glXSwapBuffersMscOML
),
2918 GLX_FUNCTION( glXGetMscRateOML
),
2919 GLX_FUNCTION( glXGetSyncValuesOML
),
2921 #ifdef GLX_DIRECT_RENDERING
2923 *** Internal functions useful to DRI drivers
2924 *** With this, the DRI drivers shouldn't need dlopen()/dlsym() to
2925 *** access internal libGL functions which may or may not exist.
2927 GLX_FUNCTION( __glXInitialize
),
2928 GLX_FUNCTION( __glXFindDRIScreen
),
2929 GLX_FUNCTION( __glXGetInternalVersion
),
2930 GLX_FUNCTION( __glXWindowExists
),
2931 GLX_FUNCTION2( __glXCreateContextWithConfig
, XF86DRICreateContextWithConfig
),
2932 GLX_FUNCTION2( __glXGetDrawableInfo
, XF86DRIGetDrawableInfo
),
2934 /*** DRI configuration ***/
2935 GLX_FUNCTION( glXGetScreenDriver
),
2936 GLX_FUNCTION( glXGetDriverConfig
),
2938 GLX_FUNCTION( __glXScrEnableExtension
),
2940 GLX_FUNCTION( __glXGetUST
),
2942 GLX_FUNCTION2( __glXCreateContextModes
, _gl_context_modes_create
),
2943 GLX_FUNCTION2( __glXDestroyContextModes
, _gl_context_modes_destroy
),
2946 { NULL
, NULL
} /* end of list */
2950 static const GLvoid
*
2951 get_glx_proc_address(const char *funcName
)
2955 /* try static functions */
2956 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2957 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2958 return GLX_functions
[i
].Address
;
2965 #ifndef GLX_BUILT_IN_XMESA
2967 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2968 * \c glXGetProcAddress.
2970 * \param procName Name of a GL or GLX function.
2971 * \returns A pointer to the named function
2973 * \sa glXGetProcAddress
2975 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2977 typedef void (*gl_function
)( void );
2981 /* Search the table of GLX and internal functions first. If that
2982 * fails and the supplied name could be a valid core GL name, try
2983 * searching the core GL function table. This check is done to prevent
2984 * DRI based drivers from searching the core GL function table for
2985 * internal API functions.
2988 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2989 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2990 && (procName
[2] != 'X') ) {
2991 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2998 * Get the address of a named GL function. This is the GLX 1.4 name for
2999 * \c glXGetProcAddressARB.
3001 * \param procName Name of a GL or GLX function.
3002 * \returns A pointer to the named function
3004 * \sa glXGetProcAddressARB
3006 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
3007 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3008 __attribute__ ((alias ("glXGetProcAddressARB")));
3011 return glXGetProcAddressARB(procName
);
3013 #endif /* __GNUC__ */
3014 #endif /* GLX_BUILT_IN_XMESA */
3017 #ifdef GLX_DIRECT_RENDERING
3019 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
3020 * might be used by the DRI drivers to determine how new libGL is at runtime.
3021 * Drivers should not call this function directly. They should instead use
3022 * \c glXGetProcAddress to obtain a pointer to the function.
3024 * \returns An 8-digit decimal number representing the internal libGL API in
3027 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
3029 * \since Internal API version 20021121.
3031 int __glXGetInternalVersion(void)
3034 * 20021121 - Initial version
3035 * 20021128 - Added __glXWindowExists() function
3036 * 20021207 - Added support for dynamic GLX extensions,
3037 * GLX_SGI_swap_control, GLX_SGI_video_sync,
3038 * GLX_OML_sync_control, and GLX_MESA_swap_control.
3039 * Never officially released. Do NOT test against
3040 * this version. Use 20030317 instead.
3041 * 20030317 - Added support GLX_SGIX_fbconfig,
3042 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
3043 * GLX_{ARB,SGIS}_multisample, and
3044 * GLX_SGIX_visual_select_group.
3045 * 20030606 - Added support for GLX_SGI_make_current_read.
3046 * 20030813 - Made support for dynamic extensions multi-head aware.
3047 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
3048 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
3050 * 20031201 - Added support for the first round of DRI interface changes.
3051 * Do NOT test against this version! It has binary
3052 * compatibility bugs, use 20040317 instead.
3053 * 20040317 - Added the 'mode' field to __DRIcontextRec.
3054 * 20040415 - Added support for bindContext3 and unbindContext3.
3055 * 20040602 - Add __glXGetDrawableInfo. I though that was there
3063 static Bool windowExistsFlag
;
3065 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
3067 if (xerr
->error_code
== BadWindow
) {
3068 windowExistsFlag
= GL_FALSE
;
3074 * Determine if a window associated with a \c GLXDrawable exists on the
3075 * X-server. This function is not used internally by libGL. It is provided
3076 * as a utility function for DRI drivers.
3077 * Drivers should not call this function directly. They should instead use
3078 * \c glXGetProcAddress to obtain a pointer to the function.
3080 * \param dpy Display associated with the drawable to be queried.
3081 * \param draw \c GLXDrawable to test.
3083 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
3084 * otherwise \c GL_FALSE is returned.
3086 * \warning This function is not currently thread-safe.
3088 * \sa glXGetProcAddress
3090 * \since Internal API version 20021128.
3092 static Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
)
3094 XWindowAttributes xwa
;
3095 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
3097 XSync(dpy
, GL_FALSE
);
3098 windowExistsFlag
= GL_TRUE
;
3099 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
3100 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
3101 XSetErrorHandler(oldXErrorHandler
);
3102 return windowExistsFlag
;
3107 * Get the unadjusted system time (UST). Currently, the UST is measured in
3108 * microseconds since Epoc. The actual resolution of the UST may vary from
3109 * system to system, and the units may vary from release to release.
3110 * Drivers should not call this function directly. They should instead use
3111 * \c glXGetProcAddress to obtain a pointer to the function.
3113 * \param ust Location to store the 64-bit UST
3114 * \returns Zero on success or a negative errno value on failure.
3116 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3118 * \since Internal API version 20030317.
3120 int __glXGetUST( int64_t * ust
)
3124 if ( ust
== NULL
) {
3128 if ( gettimeofday( & tv
, NULL
) == 0 ) {
3129 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3135 #endif /* GLX_DIRECT_RENDERING */