2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
39 #include "glcontextmodes.h"
41 #ifdef GLX_DIRECT_RENDERING
43 #include <X11/extensions/xf86vmode.h>
48 #include <X11/Xlib-xcb.h>
53 static const char __glXGLXClientVendorName
[] = "SGI";
54 static const char __glXGLXClientVersion
[] = "1.4";
57 /****************************************************************************/
59 #ifdef GLX_DIRECT_RENDERING
61 static Bool windowExistsFlag
;
62 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
64 if (xerr
->error_code
== BadWindow
) {
65 windowExistsFlag
= GL_FALSE
;
71 * Find drawables in the local hash that have been destroyed on the
74 * \param dpy Display to destroy drawables for
75 * \param screen Screen number to destroy drawables for
77 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
80 __GLXDRIdrawable
*pdraw
;
81 XWindowAttributes xwa
;
82 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
84 /* Set no-op error handler so Xlib doesn't bail out if the windows
85 * has alreay been destroyed on the server. */
87 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
89 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
91 windowExistsFlag
= GL_TRUE
;
92 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
93 if (!windowExistsFlag
) {
94 /* Destroy the local drawable data, if the drawable no
95 longer exists in the Xserver */
96 (*pdraw
->destroyDrawable
)(pdraw
);
97 __glxHashDelete(sc
->drawHash
, draw
);
99 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
102 XSync(dpy
, GL_FALSE
);
103 XSetErrorHandler(oldXErrorHandler
);
106 extern __GLXDRIdrawable
*
107 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
);
110 * Get the __DRIdrawable for the drawable associated with a GLXContext
112 * \param dpy The display associated with \c drawable.
113 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
114 * \param scrn_num If non-NULL, the drawables screen is stored there
115 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
116 * the drawable is not associated with a direct-rendering context.
118 _X_HIDDEN __GLXDRIdrawable
*
119 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
121 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
122 __GLXDRIdrawable
*pdraw
;
123 const unsigned screen_count
= ScreenCount(dpy
);
125 __GLXscreenConfigs
*psc
;
130 for (i
= 0; i
< screen_count
; i
++) {
131 psc
= &priv
->screenConfigs
[i
];
132 if (psc
->drawHash
== NULL
)
135 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
136 if (scrn_num
!= NULL
)
149 * Get the GLX per-screen data structure associated with a GLX context.
151 * \param dpy Display for which the GLX per-screen information is to be
153 * \param scrn Screen on \c dpy for which the GLX per-screen information is
155 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
156 * specify a valid GLX screen, or NULL otherwise.
158 * \todo Should this function validate that \c scrn is within the screen
159 * number range for \c dpy?
162 static __GLXscreenConfigs
*
163 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
165 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
167 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
172 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
173 __GLXscreenConfigs
** ppsc
)
175 /* Initialize the extension, if needed . This has the added value
176 * of initializing/allocating the display private
180 return GLX_NO_EXTENSION
;
183 *ppriv
= __glXInitialize(dpy
);
184 if ( *ppriv
== NULL
) {
185 return GLX_NO_EXTENSION
;
188 /* Check screen number to see if its valid */
189 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
190 return GLX_BAD_SCREEN
;
193 /* Check to see if the GL is supported on this screen */
194 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
195 if ( (*ppsc
)->configs
== NULL
) {
196 /* No support for GL on this screen regardless of visual */
197 return GLX_BAD_VISUAL
;
205 * Determine if a \c GLXFBConfig supplied by the application is valid.
207 * \param dpy Application supplied \c Display pointer.
208 * \param config Application supplied \c GLXFBConfig.
210 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
211 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
214 static __GLcontextModes
*
215 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
217 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
218 const unsigned num_screens
= ScreenCount(dpy
);
220 const __GLcontextModes
* modes
;
223 if ( priv
!= NULL
) {
224 for ( i
= 0 ; i
< num_screens
; i
++ ) {
225 for ( modes
= priv
->screenConfigs
[i
].configs
227 ; modes
= modes
->next
) {
228 if ( modes
== (__GLcontextModes
*) config
) {
229 return (__GLcontextModes
*) config
;
240 * \todo It should be possible to move the allocate of \c client_state_private
241 * later in the function for direct-rendering contexts. Direct-rendering
242 * contexts don't need to track client state, so they don't need that memory
245 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
246 * function called \c __glXAllocateClientState that allocates the memory and
247 * does all the initialization (including the pixel pack / unpack).
250 GLXContext
AllocateGLXContext( Display
*dpy
)
255 __GLXattribute
*state
;
260 opcode
= __glXSetupForCommand(dpy
);
265 /* Allocate our context record */
266 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
271 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
273 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
279 gc
->client_state_private
= state
;
280 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
281 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
284 ** Create a temporary buffer to hold GLX rendering commands. The size
285 ** of the buffer is selected so that the maximum number of GLX rendering
286 ** commands can fit in a single X packet and still have room in the X
287 ** packet for the GLXRenderReq header.
290 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
291 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
293 Xfree(gc
->client_state_private
);
297 gc
->bufSize
= bufSize
;
299 /* Fill in the new context */
300 gc
->renderMode
= GL_RENDER
;
302 state
->storePack
.alignment
= 4;
303 state
->storeUnpack
.alignment
= 4;
305 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
308 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
309 ** Other code uses the fastImageUnpack bit, but it is never set
312 gc
->fastImageUnpack
= GL_FALSE
;
313 gc
->fillImage
= __glFillImage
;
315 gc
->bufEnd
= gc
->buf
+ bufSize
;
316 gc
->isDirect
= GL_FALSE
;
319 ** Set limit register so that there will be one command per packet
323 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
326 gc
->majorOpcode
= opcode
;
329 ** Constrain the maximum drawing command size allowed to be
330 ** transfered using the X_GLXRender protocol request. First
331 ** constrain by a software limit, then constrain by the protocl
334 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
335 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
337 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
338 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
340 gc
->maxSmallRenderCommandSize
= bufSize
;
346 * Create a new context. Exactly one of \c vis and \c fbconfig should be
349 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
350 * SGIX_fbconfig protocol be used?
351 * \param renderType For FBConfigs, what is the rendering type?
355 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
356 const __GLcontextModes
* const fbconfig
,
357 GLXContext shareList
,
358 Bool allowDirect
, GLXContextID contextID
,
359 Bool use_glx_1_3
, int renderType
)
362 #ifdef GLX_DIRECT_RENDERING
363 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
364 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
370 gc
= AllocateGLXContext(dpy
);
374 if (None
== contextID
) {
375 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
378 #ifdef GLX_DIRECT_RENDERING
379 if (allowDirect
&& psc
->driScreen
) {
380 const __GLcontextModes
* mode
;
382 if (fbconfig
== NULL
) {
383 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
387 error
.errorCode
= BadValue
;
388 error
.resourceID
= vis
->visualid
;
389 error
.sequenceNumber
= dpy
->request
;
390 error
.type
= X_Error
;
391 error
.majorCode
= gc
->majorOpcode
;
392 error
.minorCode
= X_GLXCreateContext
;
393 _XError(dpy
, &error
);
401 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
404 if (gc
->driContext
!= NULL
) {
405 gc
->screen
= mode
->screen
;
408 gc
->isDirect
= GL_TRUE
;
414 if ( fbconfig
== NULL
) {
415 xGLXCreateContextReq
*req
;
417 /* Send the glXCreateContext request */
418 GetReq(GLXCreateContext
,req
);
419 req
->reqType
= gc
->majorOpcode
;
420 req
->glxCode
= X_GLXCreateContext
;
421 req
->context
= gc
->xid
= XAllocID(dpy
);
422 req
->visual
= vis
->visualid
;
423 req
->screen
= vis
->screen
;
424 req
->shareList
= shareList
? shareList
->xid
: None
;
425 #ifdef GLX_DIRECT_RENDERING
426 req
->isDirect
= gc
->driContext
!= NULL
;
431 else if ( use_glx_1_3
) {
432 xGLXCreateNewContextReq
*req
;
434 /* Send the glXCreateNewContext request */
435 GetReq(GLXCreateNewContext
,req
);
436 req
->reqType
= gc
->majorOpcode
;
437 req
->glxCode
= X_GLXCreateNewContext
;
438 req
->context
= gc
->xid
= XAllocID(dpy
);
439 req
->fbconfig
= fbconfig
->fbconfigID
;
440 req
->screen
= fbconfig
->screen
;
441 req
->renderType
= renderType
;
442 req
->shareList
= shareList
? shareList
->xid
: None
;
443 #ifdef GLX_DIRECT_RENDERING
444 req
->isDirect
= gc
->driContext
!= NULL
;
450 xGLXVendorPrivateWithReplyReq
*vpreq
;
451 xGLXCreateContextWithConfigSGIXReq
*req
;
453 /* Send the glXCreateNewContext request */
454 GetReqExtra(GLXVendorPrivateWithReply
,
455 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
456 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
457 req
->reqType
= gc
->majorOpcode
;
458 req
->glxCode
= X_GLXVendorPrivateWithReply
;
459 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
460 req
->context
= gc
->xid
= XAllocID(dpy
);
461 req
->fbconfig
= fbconfig
->fbconfigID
;
462 req
->screen
= fbconfig
->screen
;
463 req
->renderType
= renderType
;
464 req
->shareList
= shareList
? shareList
->xid
: None
;
465 #ifdef GLX_DIRECT_RENDERING
466 req
->isDirect
= gc
->driContext
!= NULL
;
474 gc
->imported
= GL_FALSE
;
478 gc
->imported
= GL_TRUE
;
484 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
485 GLXContext shareList
, Bool allowDirect
)
487 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
491 _X_HIDDEN
void __glXFreeContext(__GLXcontext
*gc
)
493 if (gc
->vendor
) XFree((char *) gc
->vendor
);
494 if (gc
->renderer
) XFree((char *) gc
->renderer
);
495 if (gc
->version
) XFree((char *) gc
->version
);
496 if (gc
->extensions
) XFree((char *) gc
->extensions
);
497 __glFreeAttributeState(gc
);
498 XFree((char *) gc
->buf
);
499 Xfree((char *) gc
->client_state_private
);
505 ** Destroy the named context
508 DestroyContext(Display
*dpy
, GLXContext gc
)
510 xGLXDestroyContextReq
*req
;
515 opcode
= __glXSetupForCommand(dpy
);
516 if (!opcode
|| !gc
) {
522 imported
= gc
->imported
;
525 #ifdef GLX_DIRECT_RENDERING
526 /* Destroy the direct rendering context */
527 if (gc
->driContext
) {
528 (*gc
->driContext
->destroyContext
)(gc
->driContext
, gc
->psc
, dpy
);
529 gc
->driContext
= NULL
;
530 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
534 __glXFreeVertexArrayState(gc
);
536 if (gc
->currentDpy
) {
537 /* Have to free later cuz it's in use now */
540 /* Destroy the handle if not current to anybody */
542 __glXFreeContext(gc
);
547 ** This dpy also created the server side part of the context.
548 ** Send the glXDestroyContext request.
551 GetReq(GLXDestroyContext
,req
);
552 req
->reqType
= opcode
;
553 req
->glxCode
= X_GLXDestroyContext
;
560 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
562 DestroyContext(dpy
, gc
);
566 ** Return the major and minor version #s for the GLX extension
568 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
570 __GLXdisplayPrivate
*priv
;
572 /* Init the extension. This fetches the major and minor version. */
573 priv
= __glXInitialize(dpy
);
574 if (!priv
) return GL_FALSE
;
576 if (major
) *major
= priv
->majorVersion
;
577 if (minor
) *minor
= priv
->minorVersion
;
582 ** Query the existance of the GLX extension
584 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
586 int major_op
, erb
, evb
;
589 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
591 if (errorBase
) *errorBase
= erb
;
592 if (eventBase
) *eventBase
= evb
;
598 ** Put a barrier in the token stream that forces the GL to finish its
599 ** work before X can proceed.
601 PUBLIC
void glXWaitGL(void)
604 GLXContext gc
= __glXGetCurrentContext();
605 Display
*dpy
= gc
->currentDpy
;
609 /* Flush any pending commands out */
610 __glXFlushRenderBuffer(gc
, gc
->pc
);
612 #ifdef GLX_DIRECT_RENDERING
613 if (gc
->driContext
) {
615 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
617 if ( pdraw
!= NULL
) {
618 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
620 if (psc
->driScreen
->waitGL
!= NULL
)
621 (*psc
->driScreen
->waitGL
)(pdraw
);
627 /* Send the glXWaitGL request */
629 GetReq(GLXWaitGL
,req
);
630 req
->reqType
= gc
->majorOpcode
;
631 req
->glxCode
= X_GLXWaitGL
;
632 req
->contextTag
= gc
->currentContextTag
;
638 ** Put a barrier in the token stream that forces X to finish its
639 ** work before GL can proceed.
641 PUBLIC
void glXWaitX(void)
644 GLXContext gc
= __glXGetCurrentContext();
645 Display
*dpy
= gc
->currentDpy
;
649 /* Flush any pending commands out */
650 __glXFlushRenderBuffer(gc
, gc
->pc
);
652 #ifdef GLX_DIRECT_RENDERING
653 if (gc
->driContext
) {
655 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
657 if ( pdraw
!= NULL
) {
658 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
659 if (psc
->driScreen
->waitX
!= NULL
)
660 (*psc
->driScreen
->waitX
)(pdraw
);
668 ** Send the glXWaitX request.
671 GetReq(GLXWaitX
,req
);
672 req
->reqType
= gc
->majorOpcode
;
673 req
->glxCode
= X_GLXWaitX
;
674 req
->contextTag
= gc
->currentContextTag
;
679 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
681 xGLXUseXFontReq
*req
;
682 GLXContext gc
= __glXGetCurrentContext();
683 Display
*dpy
= gc
->currentDpy
;
687 /* Flush any pending commands out */
688 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
690 #ifdef GLX_DIRECT_RENDERING
691 if (gc
->driContext
) {
692 DRI_glXUseXFont(font
, first
, count
, listBase
);
697 /* Send the glXUseFont request */
699 GetReq(GLXUseXFont
,req
);
700 req
->reqType
= gc
->majorOpcode
;
701 req
->glxCode
= X_GLXUseXFont
;
702 req
->contextTag
= gc
->currentContextTag
;
706 req
->listBase
= listBase
;
711 /************************************************************************/
714 ** Copy the source context to the destination context using the
717 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
718 GLXContext dest
, unsigned long mask
)
720 xGLXCopyContextReq
*req
;
721 GLXContext gc
= __glXGetCurrentContext();
725 opcode
= __glXSetupForCommand(dpy
);
730 #ifdef GLX_DIRECT_RENDERING
731 if (gc
->driContext
) {
732 /* NOT_DONE: This does not work yet */
737 ** If the source is the current context, send its tag so that the context
738 ** can be flushed before the copy.
740 if (source
== gc
&& dpy
== gc
->currentDpy
) {
741 tag
= gc
->currentContextTag
;
746 /* Send the glXCopyContext request */
748 GetReq(GLXCopyContext
,req
);
749 req
->reqType
= opcode
;
750 req
->glxCode
= X_GLXCopyContext
;
751 req
->source
= source
? source
->xid
: None
;
752 req
->dest
= dest
? dest
->xid
: None
;
754 req
->contextTag
= tag
;
761 * Determine if a context uses direct rendering.
763 * \param dpy Display where the context was created.
764 * \param contextID ID of the context to be tested.
766 * \returns \c GL_TRUE if the context is direct rendering or not.
768 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
770 #if !defined(USE_XCB)
771 xGLXIsDirectReq
*req
;
772 xGLXIsDirectReply reply
;
776 opcode
= __glXSetupForCommand(dpy
);
782 xcb_connection_t
* c
= XGetXCBConnection(dpy
);
783 xcb_glx_is_direct_reply_t
* reply
=
784 xcb_glx_is_direct_reply(c
,
785 xcb_glx_is_direct(c
, contextID
),
788 const Bool is_direct
= reply
->is_direct
? True
: False
;
793 /* Send the glXIsDirect request */
795 GetReq(GLXIsDirect
,req
);
796 req
->reqType
= opcode
;
797 req
->glxCode
= X_GLXIsDirect
;
798 req
->context
= contextID
;
799 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
803 return reply
.isDirect
;
809 * Shouldn't this function \b always return \c GL_FALSE when
810 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
811 * the GLX protocol here at all?
813 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
817 #ifdef GLX_DIRECT_RENDERING
818 } else if (gc
->driContext
) {
822 return __glXIsDirect(dpy
, gc
->xid
);
825 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
828 xGLXCreateGLXPixmapReq
*req
;
832 opcode
= __glXSetupForCommand(dpy
);
837 /* Send the glXCreateGLXPixmap request */
839 GetReq(GLXCreateGLXPixmap
,req
);
840 req
->reqType
= opcode
;
841 req
->glxCode
= X_GLXCreateGLXPixmap
;
842 req
->screen
= vis
->screen
;
843 req
->visual
= vis
->visualid
;
844 req
->pixmap
= pixmap
;
845 req
->glxpixmap
= xid
= XAllocID(dpy
);
852 ** Destroy the named pixmap
854 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
856 xGLXDestroyGLXPixmapReq
*req
;
859 opcode
= __glXSetupForCommand(dpy
);
864 /* Send the glXDestroyGLXPixmap request */
866 GetReq(GLXDestroyGLXPixmap
,req
);
867 req
->reqType
= opcode
;
868 req
->glxCode
= X_GLXDestroyGLXPixmap
;
869 req
->glxpixmap
= glxpixmap
;
874 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
882 xGLXSwapBuffersReq
*req
;
885 #ifdef GLX_DIRECT_RENDERING
886 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
890 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
);
895 opcode
= __glXSetupForCommand(dpy
);
901 ** The calling thread may or may not have a current context. If it
902 ** does, send the context tag so the server can do a flush.
904 gc
= __glXGetCurrentContext();
905 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
906 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
907 tag
= gc
->currentContextTag
;
913 c
= XGetXCBConnection(dpy
);
914 xcb_glx_swap_buffers(c
, tag
, drawable
);
917 /* Send the glXSwapBuffers request */
919 GetReq(GLXSwapBuffers
,req
);
920 req
->reqType
= opcode
;
921 req
->glxCode
= X_GLXSwapBuffers
;
922 req
->drawable
= drawable
;
923 req
->contextTag
= tag
;
932 ** Return configuration information for the given display, screen and
933 ** visual combination.
935 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
938 __GLXdisplayPrivate
*priv
;
939 __GLXscreenConfigs
*psc
;
940 __GLcontextModes
*modes
;
943 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
944 if ( status
== Success
) {
945 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
947 /* Lookup attribute after first finding a match on the visual */
948 if ( modes
!= NULL
) {
949 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
952 status
= GLX_BAD_VISUAL
;
956 ** If we can't find the config for this visual, this visual is not
957 ** supported by the OpenGL implementation on the server.
959 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
960 *value_return
= GL_FALSE
;
967 /************************************************************************/
970 init_fbconfig_for_chooser( __GLcontextModes
* config
,
971 GLboolean fbconfig_style_tags
)
973 memset( config
, 0, sizeof( __GLcontextModes
) );
974 config
->visualID
= (XID
) GLX_DONT_CARE
;
975 config
->visualType
= GLX_DONT_CARE
;
977 /* glXChooseFBConfig specifies different defaults for these two than
980 if ( fbconfig_style_tags
) {
981 config
->rgbMode
= GL_TRUE
;
982 config
->doubleBufferMode
= GLX_DONT_CARE
;
985 config
->visualRating
= GLX_DONT_CARE
;
986 config
->transparentPixel
= GLX_NONE
;
987 config
->transparentRed
= GLX_DONT_CARE
;
988 config
->transparentGreen
= GLX_DONT_CARE
;
989 config
->transparentBlue
= GLX_DONT_CARE
;
990 config
->transparentAlpha
= GLX_DONT_CARE
;
991 config
->transparentIndex
= GLX_DONT_CARE
;
993 config
->drawableType
= GLX_WINDOW_BIT
;
994 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
995 config
->xRenderable
= GLX_DONT_CARE
;
996 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
998 config
->swapMethod
= GLX_DONT_CARE
;
1001 #define MATCH_DONT_CARE( param ) \
1003 if ( (a-> param != GLX_DONT_CARE) \
1004 && (a-> param != b-> param) ) { \
1009 #define MATCH_MINIMUM( param ) \
1011 if ( (a-> param != GLX_DONT_CARE) \
1012 && (a-> param > b-> param) ) { \
1017 #define MATCH_EXACT( param ) \
1019 if ( a-> param != b-> param) { \
1025 * Determine if two GLXFBConfigs are compatible.
1027 * \param a Application specified config to test.
1028 * \param b Server specified config to test against \c a.
1031 fbconfigs_compatible( const __GLcontextModes
* const a
,
1032 const __GLcontextModes
* const b
)
1034 MATCH_DONT_CARE( doubleBufferMode
);
1035 MATCH_DONT_CARE( visualType
);
1036 MATCH_DONT_CARE( visualRating
);
1037 MATCH_DONT_CARE( xRenderable
);
1038 MATCH_DONT_CARE( fbconfigID
);
1039 MATCH_DONT_CARE( swapMethod
);
1041 MATCH_MINIMUM( rgbBits
);
1042 MATCH_MINIMUM( numAuxBuffers
);
1043 MATCH_MINIMUM( redBits
);
1044 MATCH_MINIMUM( greenBits
);
1045 MATCH_MINIMUM( blueBits
);
1046 MATCH_MINIMUM( alphaBits
);
1047 MATCH_MINIMUM( depthBits
);
1048 MATCH_MINIMUM( stencilBits
);
1049 MATCH_MINIMUM( accumRedBits
);
1050 MATCH_MINIMUM( accumGreenBits
);
1051 MATCH_MINIMUM( accumBlueBits
);
1052 MATCH_MINIMUM( accumAlphaBits
);
1053 MATCH_MINIMUM( sampleBuffers
);
1054 MATCH_MINIMUM( maxPbufferWidth
);
1055 MATCH_MINIMUM( maxPbufferHeight
);
1056 MATCH_MINIMUM( maxPbufferPixels
);
1057 MATCH_MINIMUM( samples
);
1059 MATCH_DONT_CARE( stereoMode
);
1060 MATCH_EXACT( level
);
1062 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1063 || ((a
->renderType
& b
->renderType
) == 0) ) {
1068 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1069 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1070 * Technically speaking, it is a bug in the DDX driver, but there is
1071 * enough of an installed base to work around the problem here. In any
1072 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1073 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1074 * 0 from the server to be a match to maintain backward compatibility with
1075 * the (broken) drivers.
1078 if ( a
->transparentPixel
!= GLX_DONT_CARE
1079 && a
->transparentPixel
!= 0 ) {
1080 if ( a
->transparentPixel
== GLX_NONE
) {
1081 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1084 MATCH_EXACT( transparentPixel
);
1087 switch ( a
->transparentPixel
) {
1088 case GLX_TRANSPARENT_RGB
:
1089 MATCH_DONT_CARE( transparentRed
);
1090 MATCH_DONT_CARE( transparentGreen
);
1091 MATCH_DONT_CARE( transparentBlue
);
1092 MATCH_DONT_CARE( transparentAlpha
);
1095 case GLX_TRANSPARENT_INDEX
:
1096 MATCH_DONT_CARE( transparentIndex
);
1108 /* There's some trickly language in the GLX spec about how this is supposed
1109 * to work. Basically, if a given component size is either not specified
1110 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1111 * Well, that's really hard to do with the code as-is. This behavior is
1112 * closer to correct, but still not technically right.
1114 #define PREFER_LARGER_OR_ZERO(comp) \
1116 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1117 if ( ((*a)-> comp) == 0 ) { \
1120 else if ( ((*b)-> comp) == 0 ) { \
1124 return ((*b)-> comp) - ((*a)-> comp) ; \
1129 #define PREFER_LARGER(comp) \
1131 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1132 return ((*b)-> comp) - ((*a)-> comp) ; \
1136 #define PREFER_SMALLER(comp) \
1138 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1139 return ((*a)-> comp) - ((*b)-> comp) ; \
1144 * Compare two GLXFBConfigs. This function is intended to be used as the
1145 * compare function passed in to qsort.
1147 * \returns If \c a is a "better" config, according to the specification of
1148 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1149 * better, then a number greater than zero is return. If both are
1150 * equal, zero is returned.
1151 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1154 fbconfig_compare( const __GLcontextModes
* const * const a
,
1155 const __GLcontextModes
* const * const b
)
1157 /* The order of these comparisons must NOT change. It is defined by
1158 * the GLX 1.3 spec and ARB_multisample.
1161 PREFER_SMALLER( visualSelectGroup
);
1163 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1164 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1165 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1167 PREFER_SMALLER( visualRating
);
1169 /* This isn't quite right. It is supposed to compare the sum of the
1170 * components the user specifically set minimums for.
1172 PREFER_LARGER_OR_ZERO( redBits
);
1173 PREFER_LARGER_OR_ZERO( greenBits
);
1174 PREFER_LARGER_OR_ZERO( blueBits
);
1175 PREFER_LARGER_OR_ZERO( alphaBits
);
1177 PREFER_SMALLER( rgbBits
);
1179 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1180 /* Prefer single-buffer.
1182 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1185 PREFER_SMALLER( numAuxBuffers
);
1187 PREFER_LARGER_OR_ZERO( depthBits
);
1188 PREFER_SMALLER( stencilBits
);
1190 /* This isn't quite right. It is supposed to compare the sum of the
1191 * components the user specifically set minimums for.
1193 PREFER_LARGER_OR_ZERO( accumRedBits
);
1194 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1195 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1196 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1198 PREFER_SMALLER( visualType
);
1200 /* None of the multisample specs say where this comparison should happen,
1201 * so I put it near the end.
1203 PREFER_SMALLER( sampleBuffers
);
1204 PREFER_SMALLER( samples
);
1206 /* None of the pbuffer or fbconfig specs say that this comparison needs
1207 * to happen at all, but it seems like it should.
1209 PREFER_LARGER( maxPbufferWidth
);
1210 PREFER_LARGER( maxPbufferHeight
);
1211 PREFER_LARGER( maxPbufferPixels
);
1218 * Selects and sorts a subset of the supplied configs based on the attributes.
1219 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1220 * and \c glXChooseFBConfigSGIX.
1222 * \param configs Array of pointers to possible configs. The elements of
1223 * this array that do not meet the criteria will be set to
1224 * NULL. The remaining elements will be sorted according to
1225 * the various visual / FBConfig selection rules.
1226 * \param num_configs Number of elements in the \c configs array.
1227 * \param attribList Attributes used select from \c configs. This array is
1228 * terminated by a \c None tag. The array can either take
1229 * the form expected by \c glXChooseVisual (where boolean
1230 * tags do not have a value) or by \c glXChooseFBConfig
1231 * (where every tag has a value).
1232 * \param fbconfig_style_tags Selects whether \c attribList is in
1233 * \c glXChooseVisual style or
1234 * \c glXChooseFBConfig style.
1235 * \returns The number of valid elements left in \c configs.
1237 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1240 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1241 const int *attribList
, GLboolean fbconfig_style_tags
)
1243 __GLcontextModes test_config
;
1247 /* This is a fairly direct implementation of the selection method
1248 * described by GLX_SGIX_fbconfig. Start by culling out all the
1249 * configs that are not compatible with the selected parameter
1253 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1254 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1255 (const INT32
*) attribList
,
1256 GL_TRUE
, fbconfig_style_tags
);
1259 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1260 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1261 configs
[ base
] = configs
[ i
];
1270 if ( base
< num_configs
) {
1271 (void) memset( & configs
[ base
], 0,
1272 sizeof( void * ) * (num_configs
- base
) );
1275 /* After the incompatible configs are removed, the resulting
1276 * list is sorted according to the rules set out in the various
1280 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1281 (int (*)(const void*, const void*)) fbconfig_compare
);
1289 ** Return the visual that best matches the template. Return None if no
1290 ** visual matches the template.
1292 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1294 XVisualInfo
*visualList
= NULL
;
1295 __GLXdisplayPrivate
*priv
;
1296 __GLXscreenConfigs
*psc
;
1297 __GLcontextModes test_config
;
1298 __GLcontextModes
*modes
;
1299 const __GLcontextModes
*best_config
= NULL
;
1302 ** Get a list of all visuals, return if list is empty
1304 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1310 ** Build a template from the defaults and the attribute list
1311 ** Free visual list and return if an unexpected token is encountered
1313 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1314 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1315 (const INT32
*) attribList
,
1316 GL_TRUE
, GL_FALSE
);
1319 ** Eliminate visuals that don't meet minimum requirements
1320 ** Compute a score for those that do
1321 ** Remember which visual, if any, got the highest score
1322 ** If no visual is acceptable, return None
1323 ** Otherwise, create an XVisualInfo list with just the selected X visual
1326 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1327 if ( fbconfigs_compatible( & test_config
, modes
)
1328 && ((best_config
== NULL
)
1329 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1330 XVisualInfo visualTemplate
;
1331 XVisualInfo
*newList
;
1334 visualTemplate
.screen
= screen
;
1335 visualTemplate
.visualid
= modes
->visualID
;
1336 newList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1337 &visualTemplate
, &i
);
1341 visualList
= newList
;
1342 best_config
= modes
;
1351 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1353 __GLXscreenConfigs
*psc
;
1354 __GLXdisplayPrivate
*priv
;
1356 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1360 if (!psc
->effectiveGLXexts
) {
1361 if (!psc
->serverGLXexts
) {
1362 psc
->serverGLXexts
=
1363 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
1366 __glXCalculateUsableExtensions(psc
,
1367 #ifdef GLX_DIRECT_RENDERING
1368 (psc
->driScreen
!= NULL
),
1372 priv
->minorVersion
);
1375 return psc
->effectiveGLXexts
;
1378 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1382 return (__glXGLXClientVendorName
);
1384 return (__glXGLXClientVersion
);
1385 case GLX_EXTENSIONS
:
1386 return (__glXGetClientExtensions());
1392 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1394 __GLXscreenConfigs
*psc
;
1395 __GLXdisplayPrivate
*priv
;
1399 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1405 str
= & priv
->serverGLXvendor
;
1408 str
= & priv
->serverGLXversion
;
1410 case GLX_EXTENSIONS
:
1411 str
= & psc
->serverGLXexts
;
1417 if ( *str
== NULL
) {
1418 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1424 void __glXClientInfo ( Display
*dpy
, int opcode
)
1426 char * ext_str
= __glXGetClientGLExtensionString();
1427 int size
= strlen( ext_str
) + 1;
1430 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1431 xcb_glx_client_info(c
,
1435 (const uint8_t *)ext_str
);
1437 xGLXClientInfoReq
*req
;
1439 /* Send the glXClientInfo request */
1441 GetReq(GLXClientInfo
,req
);
1442 req
->reqType
= opcode
;
1443 req
->glxCode
= X_GLXClientInfo
;
1444 req
->major
= GLX_MAJOR_VERSION
;
1445 req
->minor
= GLX_MINOR_VERSION
;
1447 req
->length
+= (size
+ 3) >> 2;
1448 req
->numbytes
= size
;
1449 Data(dpy
, ext_str
, size
);
1453 #endif /* USE_XCB */
1460 ** EXT_import_context
1463 PUBLIC Display
*glXGetCurrentDisplay(void)
1465 GLXContext gc
= __glXGetCurrentContext();
1466 if (NULL
== gc
) return NULL
;
1467 return gc
->currentDpy
;
1470 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1471 glXGetCurrentDisplay
)
1474 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1477 * \param dpy Display where \c ctx was created.
1478 * \param ctx Context to query.
1479 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1480 * or zero if the request failed due to internal problems (i.e.,
1481 * unable to allocate temporary memory, etc.)
1484 * This function dynamically determines whether to use the EXT_import_context
1485 * version of the protocol or the GLX 1.3 version of the protocol.
1487 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1489 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1490 xGLXQueryContextReply reply
;
1496 return GLX_BAD_CONTEXT
;
1498 opcode
= __glXSetupForCommand(dpy
);
1503 /* Send the glXQueryContextInfoEXT request */
1506 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1507 xGLXQueryContextReq
*req
;
1509 GetReq(GLXQueryContext
, req
);
1511 req
->reqType
= opcode
;
1512 req
->glxCode
= X_GLXQueryContext
;
1513 req
->context
= (unsigned int)(ctx
->xid
);
1516 xGLXVendorPrivateReq
*vpreq
;
1517 xGLXQueryContextInfoEXTReq
*req
;
1519 GetReqExtra( GLXVendorPrivate
,
1520 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1522 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1523 req
->reqType
= opcode
;
1524 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1525 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1526 req
->context
= (unsigned int)(ctx
->xid
);
1529 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1531 numValues
= reply
.n
;
1534 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1538 int *propList
, *pProp
;
1542 nPropListBytes
= numValues
<< 3;
1543 propList
= (int *) Xmalloc(nPropListBytes
);
1544 if (NULL
== propList
) {
1547 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1549 for (i
=0; i
< numValues
; i
++) {
1551 case GLX_SHARE_CONTEXT_EXT
:
1552 ctx
->share_xid
= *pProp
++;
1554 case GLX_VISUAL_ID_EXT
:
1556 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1559 ctx
->screen
= *pProp
++;
1561 case GLX_FBCONFIG_ID
:
1563 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1565 case GLX_RENDER_TYPE
:
1566 ctx
->renderType
= *pProp
++;
1573 Xfree((char *)propList
);
1583 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1587 /* get the information from the server if we don't have it already */
1588 #ifdef GLX_DIRECT_RENDERING
1589 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1591 if (ctx
->mode
== NULL
) {
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
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1604 *value
= (int)(ctx
->screen
);
1606 case GLX_FBCONFIG_ID
:
1607 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1609 case GLX_RENDER_TYPE
:
1610 *value
= (int)(ctx
->renderType
);
1613 return GLX_BAD_ATTRIBUTE
;
1618 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1619 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1620 (dpy
, ctx
, attribute
, value
),
1623 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1628 PUBLIC GLXContext
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 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1650 DestroyContext(dpy
, ctx
);
1656 * GLX 1.3 functions - these are just stubs for now!
1659 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1660 const int *attribList
, int *nitems
)
1662 __GLcontextModes
** config_list
;
1666 config_list
= (__GLcontextModes
**)
1667 glXGetFBConfigs( dpy
, screen
, & list_size
);
1669 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1670 list_size
= choose_visual( config_list
, list_size
, attribList
,
1672 if ( list_size
== 0 ) {
1673 XFree( config_list
);
1678 *nitems
= list_size
;
1679 return (GLXFBConfig
*) config_list
;
1683 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1684 int renderType
, GLXContext shareList
,
1687 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1688 allowDirect
, None
, True
, renderType
);
1692 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1694 GLXContext gc
= __glXGetCurrentContext();
1695 return gc
->currentReadable
;
1699 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1701 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1702 __GLcontextModes
** config
= NULL
;
1707 && (priv
->screenConfigs
!= NULL
)
1708 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1709 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1710 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1711 unsigned num_configs
= 0;
1712 __GLcontextModes
* modes
;
1715 for ( modes
= priv
->screenConfigs
[screen
].configs
1717 ; modes
= modes
->next
) {
1718 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1723 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1725 if ( config
!= NULL
) {
1726 *nelements
= num_configs
;
1728 for ( modes
= priv
->screenConfigs
[screen
].configs
1730 ; modes
= modes
->next
) {
1731 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1738 return (GLXFBConfig
*) config
;
1742 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1743 int attribute
, int *value
)
1745 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1747 return (modes
!= NULL
)
1748 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1753 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1755 XVisualInfo visualTemplate
;
1756 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1760 ** Get a list of all visuals, return if list is empty
1762 visualTemplate
.visualid
= fbconfig
->visualID
;
1763 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1768 ** GLX_SGI_swap_control
1770 static int __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 __DRI_SWAP_CONTROL
1787 if (gc
->driContext
) {
1788 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1790 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1791 gc
->currentDrawable
,
1793 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1794 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1798 return GLX_BAD_CONTEXT
;
1802 dpy
= gc
->currentDpy
;
1803 opcode
= __glXSetupForCommand(dpy
);
1808 /* Send the glXSwapIntervalSGI request */
1810 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1811 req
->reqType
= opcode
;
1812 req
->glxCode
= X_GLXVendorPrivate
;
1813 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1814 req
->contextTag
= gc
->currentContextTag
;
1816 interval_ptr
= (CARD32
*) (req
+ 1);
1817 *interval_ptr
= interval
;
1828 ** GLX_MESA_swap_control
1830 static int __glXSwapIntervalMESA(unsigned int interval
)
1832 #ifdef __DRI_SWAP_CONTROL
1833 GLXContext gc
= __glXGetCurrentContext();
1835 if ( interval
< 0 ) {
1836 return GLX_BAD_VALUE
;
1839 if (gc
!= NULL
&& gc
->driContext
) {
1840 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1843 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1844 __GLXDRIdrawable
*pdraw
=
1845 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1846 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1847 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1856 return GLX_BAD_CONTEXT
;
1860 static int __glXGetSwapIntervalMESA(void)
1862 #ifdef __DRI_SWAP_CONTROL
1863 GLXContext gc
= __glXGetCurrentContext();
1865 if (gc
!= NULL
&& gc
->driContext
) {
1866 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1869 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1870 __GLXDRIdrawable
*pdraw
=
1871 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1872 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1873 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1884 ** GLX_MESA_swap_frame_usage
1887 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1889 int status
= GLX_BAD_CONTEXT
;
1890 #ifdef __DRI_FRAME_TRACKING
1892 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1893 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1895 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1896 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1905 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1907 int status
= GLX_BAD_CONTEXT
;
1908 #ifdef __DRI_FRAME_TRACKING
1910 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1911 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1913 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1914 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1924 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1927 int status
= GLX_BAD_CONTEXT
;
1928 #ifdef __DRI_FRAME_TRACKING
1930 __GLXDRIdrawable
* const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1931 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1933 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1934 int64_t sbc
, missedFrames
;
1935 float lastMissedUsage
;
1937 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1952 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1953 int64_t *sbc
, int64_t *missedFrames
,
1954 GLfloat
*lastMissedUsage
)
1956 int status
= GLX_BAD_CONTEXT
;
1957 #ifdef __DRI_FRAME_TRACKING
1959 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1960 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1962 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1965 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1967 lastMissedUsage
, &usage
);
1973 (void) missedFrames
;
1974 (void) lastMissedUsage
;
1981 ** GLX_SGI_video_sync
1983 static int __glXGetVideoSyncSGI(unsigned int *count
)
1985 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1986 * FIXME: there should be a GLX encoding for this call. I can find no
1987 * FIXME: documentation for the GLX encoding.
1989 #ifdef __DRI_MEDIA_STREAM_COUNTER
1990 GLXContext gc
= __glXGetCurrentContext();
1993 if (gc
!= NULL
&& gc
->driContext
) {
1994 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1996 if ( psc
->msc
&& psc
->driScreen
) {
1997 __GLXDRIdrawable
*pdraw
=
1998 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2002 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2003 pdraw
->driDrawable
, &temp
);
2004 *count
= (unsigned) temp
;
2006 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2012 return GLX_BAD_CONTEXT
;
2015 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2017 #ifdef __DRI_MEDIA_STREAM_COUNTER
2018 GLXContext gc
= __glXGetCurrentContext();
2020 if ( divisor
<= 0 || remainder
< 0 )
2021 return GLX_BAD_VALUE
;
2023 if (gc
!= NULL
&& gc
->driContext
) {
2024 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2026 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2027 __GLXDRIdrawable
*pdraw
=
2028 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2033 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2034 divisor
, remainder
, &msc
, &sbc
);
2035 *count
= (unsigned) msc
;
2036 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2042 return GLX_BAD_CONTEXT
;
2047 ** GLX_SGIX_fbconfig
2048 ** Many of these functions are aliased to GLX 1.3 entry points in the
2049 ** GLX_functions table.
2052 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2053 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2054 (dpy
, config
, attribute
, value
),
2055 glXGetFBConfigAttrib
)
2057 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2058 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2059 (dpy
, screen
, attrib_list
, nelements
),
2062 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2063 (Display
* dpy
, GLXFBConfigSGIX config
),
2065 glXGetVisualFromFBConfig
)
2067 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2068 GLXFBConfigSGIX config
, Pixmap pixmap
)
2070 xGLXVendorPrivateWithReplyReq
*vpreq
;
2071 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2072 GLXPixmap xid
= None
;
2074 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2075 __GLXscreenConfigs
* psc
;
2078 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2082 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2084 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2085 opcode
= __glXSetupForCommand(dpy
);
2090 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2092 GetReqExtra(GLXVendorPrivateWithReply
,
2093 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2094 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2095 req
->reqType
= opcode
;
2096 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2097 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2098 req
->screen
= fbconfig
->screen
;
2099 req
->fbconfig
= fbconfig
->fbconfigID
;
2100 req
->pixmap
= pixmap
;
2101 req
->glxpixmap
= xid
= XAllocID(dpy
);
2109 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2110 GLXFBConfigSGIX config
, int renderType
,
2111 GLXContext shareList
, Bool allowDirect
)
2113 GLXContext gc
= NULL
;
2114 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2115 __GLXscreenConfigs
* psc
;
2118 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2122 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2124 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2125 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2126 allowDirect
, None
, False
, renderType
);
2133 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2136 __GLXdisplayPrivate
*priv
;
2137 __GLXscreenConfigs
*psc
;
2139 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2140 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2141 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2142 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2151 ** GLX_SGIX_swap_group
2153 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2163 ** GLX_SGIX_swap_barrier
2165 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2173 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2183 ** GLX_OML_sync_control
2185 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2186 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2188 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2189 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2191 if ( priv
!= NULL
) {
2193 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2194 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2196 assert( (pdraw
== NULL
) || (i
!= -1) );
2197 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2198 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2199 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2200 && (__glXGetUST(ust
) == 0) );
2212 #ifdef GLX_DIRECT_RENDERING
2214 __driGetMscRateOML(__DRIdrawable
*draw
,
2215 int32_t *numerator
, int32_t *denominator
, void *private)
2218 __GLXscreenConfigs
*psc
;
2219 XF86VidModeModeLine mode_line
;
2222 __GLXDRIdrawable
*glxDraw
= private;
2225 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2226 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2227 unsigned n
= dot_clock
* 1000;
2228 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2230 # define V_INTERLACE 0x010
2231 # define V_DBLSCAN 0x020
2233 if (mode_line
.flags
& V_INTERLACE
)
2235 else if (mode_line
.flags
& V_DBLSCAN
)
2238 /* The OML_sync_control spec requires that if the refresh rate is a
2239 * whole number, that the returned numerator be equal to the refresh
2240 * rate and the denominator be 1.
2248 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2250 /* This is a poor man's way to reduce a fraction. It's far from
2251 * perfect, but it will work well enough for this situation.
2254 for (i
= 0; f
[i
] != 0; i
++) {
2255 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2276 * Determine the refresh rate of the specified drawable and display.
2278 * \param dpy Display whose refresh rate is to be determined.
2279 * \param drawable Drawable whose refresh rate is to be determined.
2280 * \param numerator Numerator of the refresh rate.
2281 * \param demoninator Denominator of the refresh rate.
2282 * \return If the refresh rate for the specified display and drawable could
2283 * be calculated, True is returned. Otherwise False is returned.
2285 * \note This function is implemented entirely client-side. A lot of other
2286 * functionality is required to export GLX_OML_sync_control, so on
2287 * XFree86 this function can be called for direct-rendering contexts
2288 * when GLX_OML_sync_control appears in the client extension string.
2291 _X_HIDDEN GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2292 int32_t * numerator
,
2293 int32_t * denominator
)
2295 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2296 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2301 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2312 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2313 int64_t target_msc
, int64_t divisor
,
2316 #ifdef __DRI_SWAP_BUFFER_COUNTER
2318 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2319 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2321 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2322 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2323 * of -1 if the function failed because of errors detected in the input
2326 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2328 if ( divisor
> 0 && remainder
>= divisor
)
2331 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2332 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2333 divisor
, remainder
);
2346 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2347 int64_t target_msc
, int64_t divisor
,
2348 int64_t remainder
, int64_t *ust
,
2349 int64_t *msc
, int64_t *sbc
)
2351 #ifdef __DRI_MEDIA_STREAM_COUNTER
2353 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2354 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2357 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2358 * error", but the return type in the spec is Bool.
2360 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2362 if ( divisor
> 0 && remainder
>= divisor
)
2365 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2366 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, target_msc
,
2367 divisor
, remainder
, msc
, sbc
);
2369 /* __glXGetUST returns zero on success and non-zero on failure.
2370 * This function returns True on success and False on failure.
2372 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2388 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2389 int64_t target_sbc
, int64_t *ust
,
2390 int64_t *msc
, int64_t *sbc
)
2392 #ifdef __DRI_SWAP_BUFFER_COUNTER
2394 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2395 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2398 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2399 * error", but the return type in the spec is Bool.
2401 if ( target_sbc
< 0 )
2404 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2405 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2407 /* __glXGetUST returns zero on success and non-zero on failure.
2408 * This function returns True on success and False on failure.
2410 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2425 * GLX_MESA_allocate_memory
2429 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2430 size_t size
, float readFreq
,
2431 float writeFreq
, float priority
)
2433 #ifdef __DRI_ALLOCATE
2434 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2436 if (psc
&& psc
->allocate
)
2437 return (*psc
->allocate
->allocateMemory
)(psc
->__driScreen
, size
,
2438 readFreq
, writeFreq
, priority
);
2447 #endif /* GLX_DIRECT_RENDERING */
2453 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2455 #ifdef __DRI_ALLOCATE
2456 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2458 if (psc
&& psc
->allocate
)
2459 (*psc
->allocate
->freeMemory
)(psc
->__driScreen
, pointer
);
2465 #endif /* GLX_DIRECT_RENDERING */
2469 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2470 const void *pointer
)
2472 #ifdef __DRI_ALLOCATE
2473 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2475 if (psc
&& psc
->allocate
)
2476 return (*psc
->allocate
->memoryOffset
)(psc
->__driScreen
, pointer
);
2482 #endif /* GLX_DIRECT_RENDERING */
2490 * Mesa extension stubs. These will help reduce portability problems.
2495 * Release all buffers associated with the specified GLX drawable.
2498 * This function was intended for stand-alone Mesa. The issue there is that
2499 * the library doesn't get any notification when a window is closed. In
2500 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2501 * supported, there are 3 different functions to destroy a drawable. It
2502 * should be possible to create GLX protocol (or have it determine which
2503 * protocol to use based on the type of the drawable) to have one function
2504 * do the work of 3. For the direct-rendering case, this function could
2505 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2506 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2507 * would need to be used. This really should be done as part of the new DRI
2510 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2511 * __driGarbageCollectDrawables
2512 * glXDestroyGLXPixmap
2513 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2514 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2516 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2524 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2525 Pixmap pixmap
, Colormap cmap
)
2537 * GLX_MESA_copy_sub_buffer
2539 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2540 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2541 int x
, int y
, int width
, int height
)
2543 xGLXVendorPrivateReq
*req
;
2546 CARD32
*drawable_ptr
;
2547 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2550 #ifdef __DRI_COPY_SUB_BUFFER
2552 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2553 if ( pdraw
!= NULL
) {
2554 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
2555 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2557 (*psc
->driScreen
->copySubBuffer
)(pdraw
, x
, y
, width
, height
);
2564 opcode
= __glXSetupForCommand(dpy
);
2569 ** The calling thread may or may not have a current context. If it
2570 ** does, send the context tag so the server can do a flush.
2572 gc
= __glXGetCurrentContext();
2573 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2574 ((drawable
== gc
->currentDrawable
) ||
2575 (drawable
== gc
->currentReadable
)) ) {
2576 tag
= gc
->currentContextTag
;
2582 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2583 req
->reqType
= opcode
;
2584 req
->glxCode
= X_GLXVendorPrivate
;
2585 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2586 req
->contextTag
= tag
;
2588 drawable_ptr
= (CARD32
*) (req
+ 1);
2589 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2590 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2591 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2592 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2594 *drawable_ptr
= drawable
;
2606 * GLX_EXT_texture_from_pixmap
2609 static void __glXBindTexImageEXT(Display
*dpy
,
2610 GLXDrawable drawable
,
2612 const int *attrib_list
)
2614 xGLXVendorPrivateReq
*req
;
2615 GLXContext gc
= __glXGetCurrentContext();
2616 CARD32
*drawable_ptr
;
2618 CARD32
*num_attrib_ptr
;
2628 while (attrib_list
[i
* 2] != None
)
2632 #ifdef GLX_DIRECT_RENDERING
2633 if (gc
->driContext
) {
2634 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2636 if (pdraw
!= NULL
) {
2637 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2638 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2639 (*pdraw
->psc
->texBuffer
->setTexBuffer2
)(gc
->__driContext
,
2640 pdraw
->textureTarget
,
2641 pdraw
->textureFormat
,
2642 pdraw
->driDrawable
);
2644 (*pdraw
->psc
->texBuffer
->setTexBuffer
)(gc
->__driContext
,
2645 pdraw
->textureTarget
,
2646 pdraw
->driDrawable
);
2653 opcode
= __glXSetupForCommand(dpy
);
2658 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2659 req
->reqType
= opcode
;
2660 req
->glxCode
= X_GLXVendorPrivate
;
2661 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2662 req
->contextTag
= gc
->currentContextTag
;
2664 drawable_ptr
= (CARD32
*) (req
+ 1);
2665 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2666 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2667 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2669 *drawable_ptr
= drawable
;
2670 *buffer_ptr
= buffer
;
2671 *num_attrib_ptr
= (CARD32
) i
;
2675 while (attrib_list
[i
* 2] != None
)
2677 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2678 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2687 static void __glXReleaseTexImageEXT(Display
*dpy
,
2688 GLXDrawable drawable
,
2691 xGLXVendorPrivateReq
*req
;
2692 GLXContext gc
= __glXGetCurrentContext();
2693 CARD32
*drawable_ptr
;
2700 #ifdef GLX_DIRECT_RENDERING
2705 opcode
= __glXSetupForCommand(dpy
);
2710 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2711 req
->reqType
= opcode
;
2712 req
->glxCode
= X_GLXVendorPrivate
;
2713 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2714 req
->contextTag
= gc
->currentContextTag
;
2716 drawable_ptr
= (CARD32
*) (req
+ 1);
2717 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2719 *drawable_ptr
= drawable
;
2720 *buffer_ptr
= buffer
;
2728 * \c strdup is actually not a standard ANSI C or POSIX routine.
2729 * Irix will not define it if ANSI mode is in effect.
2734 __glXstrdup(const char *str
)
2737 copy
= (char *) Xmalloc(strlen(str
) + 1);
2745 ** glXGetProcAddress support
2748 struct name_address_pair
{
2753 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2754 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2756 static const struct name_address_pair GLX_functions
[] = {
2757 /*** GLX_VERSION_1_0 ***/
2758 GLX_FUNCTION( glXChooseVisual
),
2759 GLX_FUNCTION( glXCopyContext
),
2760 GLX_FUNCTION( glXCreateContext
),
2761 GLX_FUNCTION( glXCreateGLXPixmap
),
2762 GLX_FUNCTION( glXDestroyContext
),
2763 GLX_FUNCTION( glXDestroyGLXPixmap
),
2764 GLX_FUNCTION( glXGetConfig
),
2765 GLX_FUNCTION( glXGetCurrentContext
),
2766 GLX_FUNCTION( glXGetCurrentDrawable
),
2767 GLX_FUNCTION( glXIsDirect
),
2768 GLX_FUNCTION( glXMakeCurrent
),
2769 GLX_FUNCTION( glXQueryExtension
),
2770 GLX_FUNCTION( glXQueryVersion
),
2771 GLX_FUNCTION( glXSwapBuffers
),
2772 GLX_FUNCTION( glXUseXFont
),
2773 GLX_FUNCTION( glXWaitGL
),
2774 GLX_FUNCTION( glXWaitX
),
2776 /*** GLX_VERSION_1_1 ***/
2777 GLX_FUNCTION( glXGetClientString
),
2778 GLX_FUNCTION( glXQueryExtensionsString
),
2779 GLX_FUNCTION( glXQueryServerString
),
2781 /*** GLX_VERSION_1_2 ***/
2782 GLX_FUNCTION( glXGetCurrentDisplay
),
2784 /*** GLX_VERSION_1_3 ***/
2785 GLX_FUNCTION( glXChooseFBConfig
),
2786 GLX_FUNCTION( glXCreateNewContext
),
2787 GLX_FUNCTION( glXCreatePbuffer
),
2788 GLX_FUNCTION( glXCreatePixmap
),
2789 GLX_FUNCTION( glXCreateWindow
),
2790 GLX_FUNCTION( glXDestroyPbuffer
),
2791 GLX_FUNCTION( glXDestroyPixmap
),
2792 GLX_FUNCTION( glXDestroyWindow
),
2793 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2794 GLX_FUNCTION( glXGetFBConfigAttrib
),
2795 GLX_FUNCTION( glXGetFBConfigs
),
2796 GLX_FUNCTION( glXGetSelectedEvent
),
2797 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2798 GLX_FUNCTION( glXMakeContextCurrent
),
2799 GLX_FUNCTION( glXQueryContext
),
2800 GLX_FUNCTION( glXQueryDrawable
),
2801 GLX_FUNCTION( glXSelectEvent
),
2803 /*** GLX_SGI_swap_control ***/
2804 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2806 /*** GLX_SGI_video_sync ***/
2807 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2808 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2810 /*** GLX_SGI_make_current_read ***/
2811 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2812 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2814 /*** GLX_EXT_import_context ***/
2815 GLX_FUNCTION( glXFreeContextEXT
),
2816 GLX_FUNCTION( glXGetContextIDEXT
),
2817 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2818 GLX_FUNCTION( glXImportContextEXT
),
2819 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2821 /*** GLX_SGIX_fbconfig ***/
2822 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2823 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2824 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2825 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2826 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2827 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2829 /*** GLX_SGIX_pbuffer ***/
2830 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2831 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2832 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2833 GLX_FUNCTION( glXSelectEventSGIX
),
2834 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2836 /*** GLX_SGIX_swap_group ***/
2837 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2839 /*** GLX_SGIX_swap_barrier ***/
2840 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2841 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2843 /*** GLX_MESA_allocate_memory ***/
2844 GLX_FUNCTION( glXAllocateMemoryMESA
),
2845 GLX_FUNCTION( glXFreeMemoryMESA
),
2846 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2848 /*** GLX_MESA_copy_sub_buffer ***/
2849 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2851 /*** GLX_MESA_pixmap_colormap ***/
2852 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2854 /*** GLX_MESA_release_buffers ***/
2855 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2857 /*** GLX_MESA_swap_control ***/
2858 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2859 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2861 /*** GLX_MESA_swap_frame_usage ***/
2862 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2863 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2864 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2865 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2867 /*** GLX_ARB_get_proc_address ***/
2868 GLX_FUNCTION( glXGetProcAddressARB
),
2871 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2873 /*** GLX_OML_sync_control ***/
2874 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2875 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2876 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2877 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2878 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2880 /*** GLX_EXT_texture_from_pixmap ***/
2881 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2882 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2884 #ifdef GLX_DIRECT_RENDERING
2885 /*** DRI configuration ***/
2886 GLX_FUNCTION( glXGetScreenDriver
),
2887 GLX_FUNCTION( glXGetDriverConfig
),
2890 { NULL
, NULL
} /* end of list */
2894 static const GLvoid
*
2895 get_glx_proc_address(const char *funcName
)
2899 /* try static functions */
2900 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2901 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2902 return GLX_functions
[i
].Address
;
2910 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2911 * \c glXGetProcAddress.
2913 * \param procName Name of a GL or GLX function.
2914 * \returns A pointer to the named function
2916 * \sa glXGetProcAddress
2918 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2920 typedef void (*gl_function
)( void );
2924 /* Search the table of GLX and internal functions first. If that
2925 * fails and the supplied name could be a valid core GL name, try
2926 * searching the core GL function table. This check is done to prevent
2927 * DRI based drivers from searching the core GL function table for
2928 * internal API functions.
2931 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2932 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2933 && (procName
[2] != 'X') ) {
2934 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2941 * Get the address of a named GL function. This is the GLX 1.4 name for
2942 * \c glXGetProcAddressARB.
2944 * \param procName Name of a GL or GLX function.
2945 * \returns A pointer to the named function
2947 * \sa glXGetProcAddressARB
2949 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2950 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2951 __attribute__ ((alias ("glXGetProcAddressARB")));
2954 return glXGetProcAddressARB(procName
);
2956 #endif /* __GNUC__ */
2959 #ifdef GLX_DIRECT_RENDERING
2961 * Get the unadjusted system time (UST). Currently, the UST is measured in
2962 * microseconds since Epoc. The actual resolution of the UST may vary from
2963 * system to system, and the units may vary from release to release.
2964 * Drivers should not call this function directly. They should instead use
2965 * \c glXGetProcAddress to obtain a pointer to the function.
2967 * \param ust Location to store the 64-bit UST
2968 * \returns Zero on success or a negative errno value on failure.
2970 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2972 * \since Internal API version 20030317.
2974 _X_HIDDEN
int __glXGetUST( int64_t * ust
)
2978 if ( ust
== NULL
) {
2982 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2983 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2989 #endif /* GLX_DIRECT_RENDERING */