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
42 #ifdef GLX_USE_APPLEGL
43 #include "apple_glx_context.h"
44 #include "apple_glx.h"
45 #include "glx_error.h"
46 #define GC_IS_DIRECT(gc) ((gc)->isDirect)
49 #include <X11/extensions/xf86vmode.h>
51 #define GC_IS_DIRECT(gc) ((gc)->driContext != NULL)
54 #define GC_IS_DIRECT(gc) (0)
58 #include <X11/Xlib-xcb.h>
63 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
64 static const char __glXGLXClientVersion
[] = "1.4";
67 /****************************************************************************/
69 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
71 static Bool windowExistsFlag
;
73 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
77 if (xerr
->error_code
== BadWindow
) {
78 windowExistsFlag
= GL_FALSE
;
84 * Find drawables in the local hash that have been destroyed on the
87 * \param dpy Display to destroy drawables for
88 * \param screen Screen number to destroy drawables for
91 GarbageCollectDRIDrawables(Display
* dpy
, __GLXscreenConfigs
* sc
)
94 __GLXDRIdrawable
*pdraw
;
95 XWindowAttributes xwa
;
96 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
98 /* Set no-op error handler so Xlib doesn't bail out if the windows
99 * has alreay been destroyed on the server. */
100 XSync(dpy
, GL_FALSE
);
101 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
103 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
105 windowExistsFlag
= GL_TRUE
;
106 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
107 if (!windowExistsFlag
) {
108 /* Destroy the local drawable data, if the drawable no
109 longer exists in the Xserver */
110 (*pdraw
->destroyDrawable
) (pdraw
);
111 __glxHashDelete(sc
->drawHash
, draw
);
113 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1);
116 XSync(dpy
, GL_FALSE
);
117 XSetErrorHandler(oldXErrorHandler
);
121 * Get the __DRIdrawable for the drawable associated with a GLXContext
123 * \param dpy The display associated with \c drawable.
124 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
125 * \param scrn_num If non-NULL, the drawables screen is stored there
126 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
127 * the drawable is not associated with a direct-rendering context.
129 _X_HIDDEN __GLXDRIdrawable
*
130 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
132 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
133 __GLXDRIdrawable
*pdraw
;
134 const unsigned screen_count
= ScreenCount(dpy
);
136 __GLXscreenConfigs
*psc
;
141 for (i
= 0; i
< screen_count
; i
++) {
142 psc
= &priv
->screenConfigs
[i
];
143 if (psc
->drawHash
== NULL
)
146 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
147 if (scrn_num
!= NULL
)
160 * Get the GLX per-screen data structure associated with a GLX context.
162 * \param dpy Display for which the GLX per-screen information is to be
164 * \param scrn Screen on \c dpy for which the GLX per-screen information is
166 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
167 * specify a valid GLX screen, or NULL otherwise.
169 * \todo Should this function validate that \c scrn is within the screen
170 * number range for \c dpy?
173 static __GLXscreenConfigs
*
174 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
176 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
179 && priv
->screenConfigs
!=
180 NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
185 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
186 __GLXscreenConfigs
** ppsc
)
188 /* Initialize the extension, if needed . This has the added value
189 * of initializing/allocating the display private
193 return GLX_NO_EXTENSION
;
196 *ppriv
= __glXInitialize(dpy
);
197 if (*ppriv
== NULL
) {
198 return GLX_NO_EXTENSION
;
201 /* Check screen number to see if its valid */
202 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
203 return GLX_BAD_SCREEN
;
206 /* Check to see if the GL is supported on this screen */
207 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
208 if ((*ppsc
)->configs
== NULL
) {
209 /* No support for GL on this screen regardless of visual */
210 return GLX_BAD_VISUAL
;
218 * Determine if a \c GLXFBConfig supplied by the application is valid.
220 * \param dpy Application supplied \c Display pointer.
221 * \param config Application supplied \c GLXFBConfig.
223 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
224 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
227 static __GLcontextModes
*
228 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
230 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
231 const unsigned num_screens
= ScreenCount(dpy
);
233 const __GLcontextModes
*modes
;
237 for (i
= 0; i
< num_screens
; i
++) {
238 for (modes
= priv
->screenConfigs
[i
].configs
; modes
!= NULL
;
239 modes
= modes
->next
) {
240 if (modes
== (__GLcontextModes
*) config
) {
241 return (__GLcontextModes
*) config
;
252 * \todo It should be possible to move the allocate of \c client_state_private
253 * later in the function for direct-rendering contexts. Direct-rendering
254 * contexts don't need to track client state, so they don't need that memory
257 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
258 * function called \c __glXAllocateClientState that allocates the memory and
259 * does all the initialization (including the pixel pack / unpack).
262 AllocateGLXContext(Display
* dpy
)
267 __GLXattribute
*state
;
272 opcode
= __glXSetupForCommand(dpy
);
277 /* Allocate our context record */
278 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
283 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
285 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
291 gc
->client_state_private
= state
;
292 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
293 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
296 ** Create a temporary buffer to hold GLX rendering commands. The size
297 ** of the buffer is selected so that the maximum number of GLX rendering
298 ** commands can fit in a single X packet and still have room in the X
299 ** packet for the GLXRenderReq header.
302 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
303 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
305 Xfree(gc
->client_state_private
);
309 gc
->bufSize
= bufSize
;
311 /* Fill in the new context */
312 gc
->renderMode
= GL_RENDER
;
314 state
->storePack
.alignment
= 4;
315 state
->storeUnpack
.alignment
= 4;
317 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
320 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
321 ** Other code uses the fastImageUnpack bit, but it is never set
324 gc
->fastImageUnpack
= GL_FALSE
;
325 gc
->fillImage
= __glFillImage
;
327 gc
->bufEnd
= gc
->buf
+ bufSize
;
328 gc
->isDirect
= GL_FALSE
;
331 ** Set limit register so that there will be one command per packet
336 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
339 gc
->majorOpcode
= opcode
;
342 ** Constrain the maximum drawing command size allowed to be
343 ** transfered using the X_GLXRender protocol request. First
344 ** constrain by a software limit, then constrain by the protocl
347 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
348 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
350 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
351 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
353 gc
->maxSmallRenderCommandSize
= bufSize
;
355 #ifdef GLX_USE_APPLEGL
356 gc
->driContext
= NULL
;
357 gc
->do_destroy
= False
;
365 * Create a new context. Exactly one of \c vis and \c fbconfig should be
368 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
369 * SGIX_fbconfig protocol be used?
370 * \param renderType For FBConfigs, what is the rendering type?
374 CreateContext(Display
* dpy
, int generic_id
,
375 const __GLcontextModes
* const fbconfig
,
376 GLXContext shareList
,
378 unsigned code
, int renderType
, int screen
)
381 #ifdef GLX_DIRECT_RENDERING
382 #ifdef GLX_USE_APPLEGL
386 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
393 if (generic_id
== None
)
396 gc
= AllocateGLXContext(dpy
);
400 #ifndef GLX_USE_APPLEGL /* TODO: darwin indirect */
401 #ifdef GLX_DIRECT_RENDERING
402 if (allowDirect
&& psc
->driScreen
) {
403 gc
->driContext
= psc
->driScreen
->createContext(psc
, fbconfig
, gc
,
404 shareList
, renderType
);
405 if (gc
->driContext
!= NULL
) {
409 gc
->isDirect
= GL_TRUE
;
416 case X_GLXCreateContext
: {
417 xGLXCreateContextReq
*req
;
419 /* Send the glXCreateContext request */
420 GetReq(GLXCreateContext
, req
);
421 req
->reqType
= gc
->majorOpcode
;
422 req
->glxCode
= X_GLXCreateContext
;
423 req
->context
= gc
->xid
= XAllocID(dpy
);
424 req
->visual
= generic_id
;
425 req
->screen
= screen
;
426 req
->shareList
= shareList
? shareList
->xid
: None
;
427 req
->isDirect
= GC_IS_DIRECT(gc
);
431 case X_GLXCreateNewContext
: {
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
= generic_id
;
440 req
->screen
= screen
;
441 req
->renderType
= renderType
;
442 req
->shareList
= shareList
? shareList
->xid
: None
;
443 req
->isDirect
= GC_IS_DIRECT(gc
);
447 case X_GLXvop_CreateContextWithConfigSGIX
: {
448 xGLXVendorPrivateWithReplyReq
*vpreq
;
449 xGLXCreateContextWithConfigSGIXReq
*req
;
451 /* Send the glXCreateNewContext request */
452 GetReqExtra(GLXVendorPrivateWithReply
,
453 sz_xGLXCreateContextWithConfigSGIXReq
-
454 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
455 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
456 req
->reqType
= gc
->majorOpcode
;
457 req
->glxCode
= X_GLXVendorPrivateWithReply
;
458 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
459 req
->context
= gc
->xid
= XAllocID(dpy
);
460 req
->fbconfig
= generic_id
;
461 req
->screen
= screen
;
462 req
->renderType
= renderType
;
463 req
->shareList
= shareList
? shareList
->xid
: None
;
464 req
->isDirect
= GC_IS_DIRECT(gc
);
469 /* What to do here? This case is the sign of an internal error. It
470 * should never be reachable.
479 gc
->imported
= GL_FALSE
;
480 gc
->renderType
= renderType
;
482 /* TODO: darwin: Integrate with above to do indirect */
483 #ifdef GLX_USE_APPLEGL
484 if(apple_glx_create_context(&gc
->driContext
, dpy
, screen
, fbconfig
,
485 shareList
? shareList
->driContext
: NULL
,
486 &errorcode
, &x11error
)) {
487 __glXSendError(dpy
, errorcode
, 0, X_GLXCreateContext
, x11error
);
488 __glXFreeContext(gc
);
492 gc
->currentContextTag
= -1;
494 gc
->isDirect
= allowDirect
;
501 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
502 GLXContext shareList
, Bool allowDirect
)
504 const __GLcontextModes
*mode
= NULL
;
507 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
508 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
510 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
514 error
.errorCode
= BadValue
;
515 error
.resourceID
= vis
->visualid
;
516 error
.sequenceNumber
= dpy
->request
;
517 error
.type
= X_Error
;
518 error
.majorCode
= __glXSetupForCommand(dpy
);
519 error
.minorCode
= X_GLXCreateContext
;
520 _XError(dpy
, &error
);
524 renderType
= mode
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
527 return CreateContext(dpy
, vis
->visualid
, mode
, shareList
, allowDirect
,
528 X_GLXCreateContext
, renderType
, vis
->screen
);
532 __glXFreeContext(__GLXcontext
* gc
)
535 XFree((char *) gc
->vendor
);
537 XFree((char *) gc
->renderer
);
539 XFree((char *) gc
->version
);
541 XFree((char *) gc
->extensions
);
542 #ifndef GLX_USE_APPLEGL /* TODO: clientattrib */
543 __glFreeAttributeState(gc
);
545 XFree((char *) gc
->buf
);
546 Xfree((char *) gc
->client_state_private
);
552 ** Destroy the named context
555 DestroyContext(Display
* dpy
, GLXContext gc
)
557 #ifndef GLX_USE_APPLEGL /* TODO: darwin: indirect */
558 xGLXDestroyContextReq
*req
;
563 opcode
= __glXSetupForCommand(dpy
);
564 if (!opcode
|| !gc
) {
570 imported
= gc
->imported
;
573 if (gc
->currentDpy
) {
574 /* This context is bound to some thread. According to the man page,
575 * we should not actually delete the context until it's unbound.
576 * Note that we set gc->xid = None above. In MakeContextCurrent()
577 * we check for that and delete the context there.
583 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
584 /* Destroy the direct rendering context */
585 if (gc
->driContext
) {
586 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
587 gc
->driContext
= NULL
;
588 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
592 __glXFreeVertexArrayState(gc
);
595 #endif /* GLX_USE_APPLEGL */
597 if (gc
->currentDpy
) {
598 #ifdef GLX_USE_APPLEGL
600 * Set the Bool that indicates that we should destroy this GLX context
601 * when the context is no longer current.
603 gc
->do_destroy
= True
;
605 /* Have to free later cuz it's in use now */
609 /* Destroy the handle if not current to anybody */
611 #ifdef GLX_USE_APPLEGL
613 apple_glx_destroy_context(&gc
->driContext
, dpy
);
615 __glXFreeContext(gc
);
617 #ifndef GLX_USE_APPLEGL
620 ** This dpy also created the server side part of the context.
621 ** Send the glXDestroyContext request.
624 GetReq(GLXDestroyContext
, req
);
625 req
->reqType
= opcode
;
626 req
->glxCode
= X_GLXDestroyContext
;
635 glXDestroyContext(Display
* dpy
, GLXContext gc
)
637 DestroyContext(dpy
, gc
);
641 ** Return the major and minor version #s for the GLX extension
644 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
646 __GLXdisplayPrivate
*priv
;
648 /* Init the extension. This fetches the major and minor version. */
649 priv
= __glXInitialize(dpy
);
654 *major
= priv
->majorVersion
;
656 *minor
= priv
->minorVersion
;
661 ** Query the existance of the GLX extension
664 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
666 int major_op
, erb
, evb
;
669 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
680 ** Put a barrier in the token stream that forces the GL to finish its
681 ** work before X can proceed.
686 #ifndef GLX_USE_APPLEGL
689 GLXContext gc
= __glXGetCurrentContext();
690 Display
*dpy
= gc
->currentDpy
;
695 /* Flush any pending commands out */
696 __glXFlushRenderBuffer(gc
, gc
->pc
);
697 #ifdef GLX_USE_APPLEGL
700 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
701 if (gc
->driContext
) {
703 __GLXDRIdrawable
*pdraw
=
704 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
707 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
709 if (psc
->driScreen
->waitGL
!= NULL
)
710 (*psc
->driScreen
->waitGL
) (pdraw
);
716 /* Send the glXWaitGL request */
718 GetReq(GLXWaitGL
, req
);
719 req
->reqType
= gc
->majorOpcode
;
720 req
->glxCode
= X_GLXWaitGL
;
721 req
->contextTag
= gc
->currentContextTag
;
724 #endif /* GLX_USE_APPLEGL */
728 ** Put a barrier in the token stream that forces X to finish its
729 ** work before GL can proceed.
734 #ifndef GLX_USE_APPLEGL
737 GLXContext gc
= __glXGetCurrentContext();
738 Display
*dpy
= gc
->currentDpy
;
743 /* Flush any pending commands out */
744 __glXFlushRenderBuffer(gc
, gc
->pc
);
746 #ifdef GLX_USE_APPLEGL
747 apple_glx_waitx(dpy
, gc
->driContext
);
749 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
750 if (gc
->driContext
) {
752 __GLXDRIdrawable
*pdraw
=
753 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
756 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
757 if (psc
->driScreen
->waitX
!= NULL
)
758 (*psc
->driScreen
->waitX
) (pdraw
);
767 ** Send the glXWaitX request.
770 GetReq(GLXWaitX
, req
);
771 req
->reqType
= gc
->majorOpcode
;
772 req
->glxCode
= X_GLXWaitX
;
773 req
->contextTag
= gc
->currentContextTag
;
776 #endif /* GLX_USE_APPLEGL */
780 glXUseXFont(Font font
, int first
, int count
, int listBase
)
782 #ifndef GLX_USE_APPLEGL
783 xGLXUseXFontReq
*req
;
785 GLXContext gc
= __glXGetCurrentContext();
786 Display
*dpy
= gc
->currentDpy
;
791 /* Flush any pending commands out */
792 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
793 #ifdef GLX_USE_APPLEGL
794 DRI_glXUseXFont(font
, first
, count
, listBase
);
796 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
797 if (gc
->driContext
) {
798 DRI_glXUseXFont(font
, first
, count
, listBase
);
803 /* Send the glXUseFont request */
805 GetReq(GLXUseXFont
, req
);
806 req
->reqType
= gc
->majorOpcode
;
807 req
->glxCode
= X_GLXUseXFont
;
808 req
->contextTag
= gc
->currentContextTag
;
812 req
->listBase
= listBase
;
815 #endif /* GLX_USE_APPLEGL */
818 /************************************************************************/
821 ** Copy the source context to the destination context using the
825 glXCopyContext(Display
* dpy
, GLXContext source
,
826 GLXContext dest
, unsigned long mask
)
828 #ifdef GLX_USE_APPLEGL
829 GLXContext gc
= __glXGetCurrentContext();
833 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
834 mask
, &errorcode
, &x11error
)) {
835 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
839 xGLXCopyContextReq
*req
;
840 GLXContext gc
= __glXGetCurrentContext();
844 opcode
= __glXSetupForCommand(dpy
);
849 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
850 if (gc
->driContext
) {
851 /* NOT_DONE: This does not work yet */
856 ** If the source is the current context, send its tag so that the context
857 ** can be flushed before the copy.
859 if (source
== gc
&& dpy
== gc
->currentDpy
) {
860 tag
= gc
->currentContextTag
;
866 /* Send the glXCopyContext request */
868 GetReq(GLXCopyContext
, req
);
869 req
->reqType
= opcode
;
870 req
->glxCode
= X_GLXCopyContext
;
871 req
->source
= source
? source
->xid
: None
;
872 req
->dest
= dest
? dest
->xid
: None
;
874 req
->contextTag
= tag
;
877 #endif /* GLX_USE_APPLEGL */
882 * Determine if a context uses direct rendering.
884 * \param dpy Display where the context was created.
885 * \param contextID ID of the context to be tested.
887 * \returns \c GL_TRUE if the context is direct rendering or not.
890 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
892 #ifndef GLX_USE_APPLEGL /* TODO: apple indirect */
893 return GC_IS_DIRECT(gc
);
895 #if !defined(USE_XCB)
896 xGLXIsDirectReq
*req
;
897 xGLXIsDirectReply reply
;
901 opcode
= __glXSetupForCommand(dpy
);
907 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
908 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
913 const Bool is_direct
= reply
->is_direct
? True
: False
;
918 /* Send the glXIsDirect request */
920 GetReq(GLXIsDirect
, req
);
921 req
->reqType
= opcode
;
922 req
->glxCode
= X_GLXIsDirect
;
923 req
->context
= contextID
;
924 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
928 return reply
.isDirect
;
930 #endif /* GLX_USE_APPLEGL */
935 * Shouldn't this function \b always return \c GL_FALSE when
936 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
937 * the GLX protocol here at all?
940 glXIsDirect(Display
* dpy
, GLXContext gc
)
945 else if (GC_IS_DIRECT(gc
)) {
948 return __glXIsDirect(dpy
, gc
->xid
);
952 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
954 #ifdef GLX_USE_APPLEGL
955 int screen
= vis
->screen
;
956 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
957 const __GLcontextModes
*modes
;
959 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
961 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, modes
))
966 xGLXCreateGLXPixmapReq
*req
;
970 opcode
= __glXSetupForCommand(dpy
);
975 /* Send the glXCreateGLXPixmap request */
977 GetReq(GLXCreateGLXPixmap
, req
);
978 req
->reqType
= opcode
;
979 req
->glxCode
= X_GLXCreateGLXPixmap
;
980 req
->screen
= vis
->screen
;
981 req
->visual
= vis
->visualid
;
982 req
->pixmap
= pixmap
;
983 req
->glxpixmap
= xid
= XAllocID(dpy
);
987 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
989 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
990 * is actually bound to a context... */
992 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
993 __GLXDRIdrawable
*pdraw
;
994 __GLXscreenConfigs
*psc
;
995 __GLcontextModes
*modes
;
997 psc
= &priv
->screenConfigs
[vis
->screen
];
998 if (psc
->driScreen
== NULL
)
1000 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1001 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
1002 if (pdraw
== NULL
) {
1003 fprintf(stderr
, "failed to create pixmap\n");
1007 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
1008 (*pdraw
->destroyDrawable
) (pdraw
);
1009 return None
; /* FIXME: Check what we're supposed to do here... */
1019 ** Destroy the named pixmap
1022 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
1024 #ifdef GLX_USE_APPLEGL
1025 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
1026 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
1028 xGLXDestroyGLXPixmapReq
*req
;
1031 opcode
= __glXSetupForCommand(dpy
);
1036 /* Send the glXDestroyGLXPixmap request */
1038 GetReq(GLXDestroyGLXPixmap
, req
);
1039 req
->reqType
= opcode
;
1040 req
->glxCode
= X_GLXDestroyGLXPixmap
;
1041 req
->glxpixmap
= glxpixmap
;
1045 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1048 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
1049 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
1050 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
1052 if (pdraw
!= NULL
) {
1053 (*pdraw
->destroyDrawable
) (pdraw
);
1054 __glxHashDelete(psc
->drawHash
, glxpixmap
);
1058 #endif /* GLX_USE_APPLEGL */
1062 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
1064 #ifdef GLX_USE_APPLEGL
1065 GLXContext gc
= glXGetCurrentContext();
1066 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
1067 apple_glx_swap_buffers(gc
->driContext
);
1069 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
1076 xcb_connection_t
*c
;
1078 xGLXSwapBuffersReq
*req
;
1081 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1082 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
1084 if (pdraw
!= NULL
) {
1086 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
1091 opcode
= __glXSetupForCommand(dpy
);
1097 ** The calling thread may or may not have a current context. If it
1098 ** does, send the context tag so the server can do a flush.
1100 gc
= __glXGetCurrentContext();
1101 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1102 ((drawable
== gc
->currentDrawable
)
1103 || (drawable
== gc
->currentReadable
))) {
1104 tag
= gc
->currentContextTag
;
1111 c
= XGetXCBConnection(dpy
);
1112 xcb_glx_swap_buffers(c
, tag
, drawable
);
1115 /* Send the glXSwapBuffers request */
1117 GetReq(GLXSwapBuffers
, req
);
1118 req
->reqType
= opcode
;
1119 req
->glxCode
= X_GLXSwapBuffers
;
1120 req
->drawable
= drawable
;
1121 req
->contextTag
= tag
;
1125 #endif /* USE_XCB */
1126 #endif /* GLX_USE_APPLEGL */
1131 ** Return configuration information for the given display, screen and
1132 ** visual combination.
1135 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1138 __GLXdisplayPrivate
*priv
;
1139 __GLXscreenConfigs
*psc
;
1140 __GLcontextModes
*modes
;
1143 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1144 if (status
== Success
) {
1145 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1147 /* Lookup attribute after first finding a match on the visual */
1148 if (modes
!= NULL
) {
1149 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1152 status
= GLX_BAD_VISUAL
;
1156 ** If we can't find the config for this visual, this visual is not
1157 ** supported by the OpenGL implementation on the server.
1159 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1160 *value_return
= GL_FALSE
;
1167 /************************************************************************/
1170 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1171 GLboolean fbconfig_style_tags
)
1173 memset(config
, 0, sizeof(__GLcontextModes
));
1174 config
->visualID
= (XID
) GLX_DONT_CARE
;
1175 config
->visualType
= GLX_DONT_CARE
;
1177 /* glXChooseFBConfig specifies different defaults for these two than
1180 if (fbconfig_style_tags
) {
1181 config
->rgbMode
= GL_TRUE
;
1182 config
->doubleBufferMode
= GLX_DONT_CARE
;
1185 config
->visualRating
= GLX_DONT_CARE
;
1186 config
->transparentPixel
= GLX_NONE
;
1187 config
->transparentRed
= GLX_DONT_CARE
;
1188 config
->transparentGreen
= GLX_DONT_CARE
;
1189 config
->transparentBlue
= GLX_DONT_CARE
;
1190 config
->transparentAlpha
= GLX_DONT_CARE
;
1191 config
->transparentIndex
= GLX_DONT_CARE
;
1193 config
->drawableType
= GLX_WINDOW_BIT
;
1194 config
->renderType
=
1195 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1196 config
->xRenderable
= GLX_DONT_CARE
;
1197 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1199 config
->swapMethod
= GLX_DONT_CARE
;
1202 #define MATCH_DONT_CARE( param ) \
1204 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1205 && (a-> param != b-> param) ) { \
1210 #define MATCH_MINIMUM( param ) \
1212 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1213 && (a-> param > b-> param) ) { \
1218 #define MATCH_EXACT( param ) \
1220 if ( a-> param != b-> param) { \
1225 /* Test that all bits from a are contained in b */
1226 #define MATCH_MASK(param) \
1228 if ((a->param & ~b->param) != 0) \
1233 * Determine if two GLXFBConfigs are compatible.
1235 * \param a Application specified config to test.
1236 * \param b Server specified config to test against \c a.
1239 fbconfigs_compatible(const __GLcontextModes
* const a
,
1240 const __GLcontextModes
* const b
)
1242 MATCH_DONT_CARE(doubleBufferMode
);
1243 MATCH_DONT_CARE(visualType
);
1244 MATCH_DONT_CARE(visualRating
);
1245 MATCH_DONT_CARE(xRenderable
);
1246 MATCH_DONT_CARE(fbconfigID
);
1247 MATCH_DONT_CARE(swapMethod
);
1249 MATCH_MINIMUM(rgbBits
);
1250 MATCH_MINIMUM(numAuxBuffers
);
1251 MATCH_MINIMUM(redBits
);
1252 MATCH_MINIMUM(greenBits
);
1253 MATCH_MINIMUM(blueBits
);
1254 MATCH_MINIMUM(alphaBits
);
1255 MATCH_MINIMUM(depthBits
);
1256 MATCH_MINIMUM(stencilBits
);
1257 MATCH_MINIMUM(accumRedBits
);
1258 MATCH_MINIMUM(accumGreenBits
);
1259 MATCH_MINIMUM(accumBlueBits
);
1260 MATCH_MINIMUM(accumAlphaBits
);
1261 MATCH_MINIMUM(sampleBuffers
);
1262 MATCH_MINIMUM(maxPbufferWidth
);
1263 MATCH_MINIMUM(maxPbufferHeight
);
1264 MATCH_MINIMUM(maxPbufferPixels
);
1265 MATCH_MINIMUM(samples
);
1267 MATCH_DONT_CARE(stereoMode
);
1270 MATCH_MASK(drawableType
);
1271 MATCH_MASK(renderType
);
1273 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1274 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1275 * Technically speaking, it is a bug in the DDX driver, but there is
1276 * enough of an installed base to work around the problem here. In any
1277 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1278 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1279 * 0 from the server to be a match to maintain backward compatibility with
1280 * the (broken) drivers.
1283 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1284 if (a
->transparentPixel
== GLX_NONE
) {
1285 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1289 MATCH_EXACT(transparentPixel
);
1292 switch (a
->transparentPixel
) {
1293 case GLX_TRANSPARENT_RGB
:
1294 MATCH_DONT_CARE(transparentRed
);
1295 MATCH_DONT_CARE(transparentGreen
);
1296 MATCH_DONT_CARE(transparentBlue
);
1297 MATCH_DONT_CARE(transparentAlpha
);
1300 case GLX_TRANSPARENT_INDEX
:
1301 MATCH_DONT_CARE(transparentIndex
);
1313 /* There's some trickly language in the GLX spec about how this is supposed
1314 * to work. Basically, if a given component size is either not specified
1315 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1316 * Well, that's really hard to do with the code as-is. This behavior is
1317 * closer to correct, but still not technically right.
1319 #define PREFER_LARGER_OR_ZERO(comp) \
1321 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1322 if ( ((*a)-> comp) == 0 ) { \
1325 else if ( ((*b)-> comp) == 0 ) { \
1329 return ((*b)-> comp) - ((*a)-> comp) ; \
1334 #define PREFER_LARGER(comp) \
1336 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1337 return ((*b)-> comp) - ((*a)-> comp) ; \
1341 #define PREFER_SMALLER(comp) \
1343 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1344 return ((*a)-> comp) - ((*b)-> comp) ; \
1349 * Compare two GLXFBConfigs. This function is intended to be used as the
1350 * compare function passed in to qsort.
1352 * \returns If \c a is a "better" config, according to the specification of
1353 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1354 * better, then a number greater than zero is return. If both are
1355 * equal, zero is returned.
1356 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1359 fbconfig_compare(const __GLcontextModes
* const *const a
,
1360 const __GLcontextModes
* const *const b
)
1362 /* The order of these comparisons must NOT change. It is defined by
1363 * the GLX 1.3 spec and ARB_multisample.
1366 PREFER_SMALLER(visualSelectGroup
);
1368 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1369 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1370 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1372 PREFER_SMALLER(visualRating
);
1374 /* This isn't quite right. It is supposed to compare the sum of the
1375 * components the user specifically set minimums for.
1377 PREFER_LARGER_OR_ZERO(redBits
);
1378 PREFER_LARGER_OR_ZERO(greenBits
);
1379 PREFER_LARGER_OR_ZERO(blueBits
);
1380 PREFER_LARGER_OR_ZERO(alphaBits
);
1382 PREFER_SMALLER(rgbBits
);
1384 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1385 /* Prefer single-buffer.
1387 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1390 PREFER_SMALLER(numAuxBuffers
);
1392 PREFER_LARGER_OR_ZERO(depthBits
);
1393 PREFER_SMALLER(stencilBits
);
1395 /* This isn't quite right. It is supposed to compare the sum of the
1396 * components the user specifically set minimums for.
1398 PREFER_LARGER_OR_ZERO(accumRedBits
);
1399 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1400 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1401 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1403 PREFER_SMALLER(visualType
);
1405 /* None of the multisample specs say where this comparison should happen,
1406 * so I put it near the end.
1408 PREFER_SMALLER(sampleBuffers
);
1409 PREFER_SMALLER(samples
);
1411 /* None of the pbuffer or fbconfig specs say that this comparison needs
1412 * to happen at all, but it seems like it should.
1414 PREFER_LARGER(maxPbufferWidth
);
1415 PREFER_LARGER(maxPbufferHeight
);
1416 PREFER_LARGER(maxPbufferPixels
);
1423 * Selects and sorts a subset of the supplied configs based on the attributes.
1424 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1425 * and \c glXChooseFBConfigSGIX.
1427 * \param configs Array of pointers to possible configs. The elements of
1428 * this array that do not meet the criteria will be set to
1429 * NULL. The remaining elements will be sorted according to
1430 * the various visual / FBConfig selection rules.
1431 * \param num_configs Number of elements in the \c configs array.
1432 * \param attribList Attributes used select from \c configs. This array is
1433 * terminated by a \c None tag. The array can either take
1434 * the form expected by \c glXChooseVisual (where boolean
1435 * tags do not have a value) or by \c glXChooseFBConfig
1436 * (where every tag has a value).
1437 * \param fbconfig_style_tags Selects whether \c attribList is in
1438 * \c glXChooseVisual style or
1439 * \c glXChooseFBConfig style.
1440 * \returns The number of valid elements left in \c configs.
1442 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1445 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1446 const int *attribList
, GLboolean fbconfig_style_tags
)
1448 __GLcontextModes test_config
;
1452 /* This is a fairly direct implementation of the selection method
1453 * described by GLX_SGIX_fbconfig. Start by culling out all the
1454 * configs that are not compatible with the selected parameter
1458 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1459 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1460 (const INT32
*) attribList
,
1461 GL_TRUE
, fbconfig_style_tags
);
1464 for (i
= 0; i
< num_configs
; i
++) {
1465 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1466 configs
[base
] = configs
[i
];
1475 if (base
< num_configs
) {
1476 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1479 /* After the incompatible configs are removed, the resulting
1480 * list is sorted according to the rules set out in the various
1484 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1485 (int (*)(const void *, const void *)) fbconfig_compare
);
1493 ** Return the visual that best matches the template. Return None if no
1494 ** visual matches the template.
1496 PUBLIC XVisualInfo
*
1497 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1499 XVisualInfo
*visualList
= NULL
;
1500 __GLXdisplayPrivate
*priv
;
1501 __GLXscreenConfigs
*psc
;
1502 __GLcontextModes test_config
;
1503 __GLcontextModes
*modes
;
1504 const __GLcontextModes
*best_config
= NULL
;
1507 ** Get a list of all visuals, return if list is empty
1509 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1515 ** Build a template from the defaults and the attribute list
1516 ** Free visual list and return if an unexpected token is encountered
1518 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1519 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1520 (const INT32
*) attribList
,
1524 ** Eliminate visuals that don't meet minimum requirements
1525 ** Compute a score for those that do
1526 ** Remember which visual, if any, got the highest score
1527 ** If no visual is acceptable, return None
1528 ** Otherwise, create an XVisualInfo list with just the selected X visual
1531 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1532 if (fbconfigs_compatible(&test_config
, modes
)
1533 && ((best_config
== NULL
)
1536 ((const __GLcontextModes
* const *const) &modes
,
1537 &best_config
) < 0))) {
1538 XVisualInfo visualTemplate
;
1539 XVisualInfo
*newList
;
1542 visualTemplate
.screen
= screen
;
1543 visualTemplate
.visualid
= modes
->visualID
;
1544 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1545 &visualTemplate
, &i
);
1549 visualList
= newList
;
1550 best_config
= modes
;
1555 #ifdef GLX_USE_APPLEGL
1556 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1557 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1566 glXQueryExtensionsString(Display
* dpy
, int screen
)
1568 __GLXscreenConfigs
*psc
;
1569 __GLXdisplayPrivate
*priv
;
1571 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1575 if (!psc
->effectiveGLXexts
) {
1576 if (!psc
->serverGLXexts
) {
1577 psc
->serverGLXexts
=
1578 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1582 __glXCalculateUsableExtensions(psc
,
1583 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1584 (psc
->driScreen
!= NULL
),
1588 priv
->minorVersion
);
1591 return psc
->effectiveGLXexts
;
1595 glXGetClientString(Display
* dpy
, int name
)
1601 return (__glXGLXClientVendorName
);
1603 return (__glXGLXClientVersion
);
1604 case GLX_EXTENSIONS
:
1605 return (__glXGetClientExtensions());
1612 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1614 __GLXscreenConfigs
*psc
;
1615 __GLXdisplayPrivate
*priv
;
1619 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1625 str
= &priv
->serverGLXvendor
;
1628 str
= &priv
->serverGLXversion
;
1630 case GLX_EXTENSIONS
:
1631 str
= &psc
->serverGLXexts
;
1638 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1645 __glXClientInfo(Display
* dpy
, int opcode
)
1647 char *ext_str
= __glXGetClientGLExtensionString();
1648 int size
= strlen(ext_str
) + 1;
1651 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1652 xcb_glx_client_info(c
,
1653 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1655 xGLXClientInfoReq
*req
;
1657 /* Send the glXClientInfo request */
1659 GetReq(GLXClientInfo
, req
);
1660 req
->reqType
= opcode
;
1661 req
->glxCode
= X_GLXClientInfo
;
1662 req
->major
= GLX_MAJOR_VERSION
;
1663 req
->minor
= GLX_MINOR_VERSION
;
1665 req
->length
+= (size
+ 3) >> 2;
1666 req
->numbytes
= size
;
1667 Data(dpy
, ext_str
, size
);
1671 #endif /* USE_XCB */
1678 ** EXT_import_context
1682 glXGetCurrentDisplay(void)
1684 GLXContext gc
= __glXGetCurrentContext();
1687 return gc
->currentDpy
;
1691 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1692 glXGetCurrentDisplay
)
1694 #ifndef GLX_USE_APPLEGL
1696 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1699 * \param dpy Display where \c ctx was created.
1700 * \param ctx Context to query.
1701 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1702 * or zero if the request failed due to internal problems (i.e.,
1703 * unable to allocate temporary memory, etc.)
1706 * This function dynamically determines whether to use the EXT_import_context
1707 * version of the protocol or the GLX 1.3 version of the protocol.
1709 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1711 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1712 xGLXQueryContextReply reply
;
1718 return GLX_BAD_CONTEXT
;
1720 opcode
= __glXSetupForCommand(dpy
);
1725 /* Send the glXQueryContextInfoEXT request */
1728 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1729 xGLXQueryContextReq
*req
;
1731 GetReq(GLXQueryContext
, req
);
1733 req
->reqType
= opcode
;
1734 req
->glxCode
= X_GLXQueryContext
;
1735 req
->context
= (unsigned int) (ctx
->xid
);
1738 xGLXVendorPrivateReq
*vpreq
;
1739 xGLXQueryContextInfoEXTReq
*req
;
1741 GetReqExtra(GLXVendorPrivate
,
1742 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1744 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1745 req
->reqType
= opcode
;
1746 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1747 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1748 req
->context
= (unsigned int) (ctx
->xid
);
1751 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1753 numValues
= reply
.n
;
1756 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1759 int *propList
, *pProp
;
1762 nPropListBytes
= numValues
<< 3;
1763 propList
= (int *) Xmalloc(nPropListBytes
);
1764 if (NULL
== propList
) {
1770 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1772 for (i
= 0; i
< numValues
; i
++) {
1774 case GLX_SHARE_CONTEXT_EXT
:
1775 ctx
->share_xid
= *pProp
++;
1777 case GLX_VISUAL_ID_EXT
:
1779 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1782 ctx
->screen
= *pProp
++;
1784 case GLX_FBCONFIG_ID
:
1786 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1789 case GLX_RENDER_TYPE
:
1790 ctx
->renderType
= *pProp
++;
1797 Xfree((char *) propList
);
1809 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1811 #ifndef GLX_USE_APPLEGL
1814 /* get the information from the server if we don't have it already */
1815 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1816 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1818 if (ctx
->mode
== NULL
) {
1820 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1821 if (Success
!= retVal
)
1826 switch (attribute
) {
1827 #ifndef GLX_USE_APPLEGL
1828 case GLX_SHARE_CONTEXT_EXT
:
1829 *value
= (int) (ctx
->share_xid
);
1831 case GLX_VISUAL_ID_EXT
:
1832 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1836 *value
= (int) (ctx
->screen
);
1838 case GLX_FBCONFIG_ID
:
1839 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1841 case GLX_RENDER_TYPE
:
1842 *value
= (int) (ctx
->renderType
);
1845 return GLX_BAD_ATTRIBUTE
;
1851 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1852 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1853 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1855 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1861 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1863 #ifdef GLX_USE_APPLEGL
1868 if (contextID
== None
) {
1871 if (__glXIsDirect(dpy
, contextID
)) {
1875 ctx
= AllocateGLXContext(dpy
);
1877 ctx
->xid
= contextID
;
1878 ctx
->imported
= GL_TRUE
;
1880 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1881 __glXFreeContext(ctx
);
1890 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1892 DestroyContext(dpy
, ctx
);
1898 * GLX 1.3 functions - these are just stubs for now!
1901 PUBLIC GLXFBConfig
*
1902 glXChooseFBConfig(Display
* dpy
, int screen
,
1903 const int *attribList
, int *nitems
)
1905 __GLcontextModes
**config_list
;
1909 config_list
= (__GLcontextModes
**)
1910 glXGetFBConfigs(dpy
, screen
, &list_size
);
1912 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1913 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1914 if (list_size
== 0) {
1920 *nitems
= list_size
;
1921 return (GLXFBConfig
*) config_list
;
1926 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1927 int renderType
, GLXContext shareList
, Bool allowDirect
)
1929 const __GLcontextModes
*const fbconfig
=
1930 (const __GLcontextModes
*const) config
;
1932 return CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
1933 allowDirect
, X_GLXCreateNewContext
, renderType
,
1939 glXGetCurrentReadDrawable(void)
1941 GLXContext gc
= __glXGetCurrentContext();
1942 return gc
->currentReadable
;
1946 PUBLIC GLXFBConfig
*
1947 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1949 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1950 __GLcontextModes
**config
= NULL
;
1954 if (priv
&& (priv
->screenConfigs
!= NULL
)
1955 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1956 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1957 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
1958 != (int) GLX_DONT_CARE
)) {
1959 unsigned num_configs
= 0;
1960 __GLcontextModes
*modes
;
1963 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1964 modes
= modes
->next
) {
1965 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1970 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1972 if (config
!= NULL
) {
1973 *nelements
= num_configs
;
1975 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1976 modes
= modes
->next
) {
1977 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1984 return (GLXFBConfig
*) config
;
1989 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1990 int attribute
, int *value
)
1992 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1994 return (modes
!= NULL
)
1995 ? _gl_get_context_mode_data(modes
, attribute
, value
)
2000 PUBLIC XVisualInfo
*
2001 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
2003 XVisualInfo visualTemplate
;
2004 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
2008 ** Get a list of all visuals, return if list is empty
2010 visualTemplate
.visualid
= fbconfig
->visualID
;
2011 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
2014 #ifndef GLX_USE_APPLEGL
2016 ** GLX_SGI_swap_control
2019 __glXSwapIntervalSGI(int interval
)
2021 xGLXVendorPrivateReq
*req
;
2022 GLXContext gc
= __glXGetCurrentContext();
2023 __GLXscreenConfigs
*psc
;
2025 CARD32
*interval_ptr
;
2029 return GLX_BAD_CONTEXT
;
2032 if (interval
<= 0) {
2033 return GLX_BAD_VALUE
;
2036 #ifdef __DRI_SWAP_CONTROL
2037 if (gc
->driContext
) {
2038 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2040 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2041 gc
->currentDrawable
,
2043 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2044 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
2047 else if (pdraw
== NULL
) {
2048 return GLX_BAD_CONTEXT
;
2052 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2054 #ifdef GLX_DIRECT_RENDERING
2055 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2056 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2057 gc
->currentDrawable
,
2059 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2064 dpy
= gc
->currentDpy
;
2065 opcode
= __glXSetupForCommand(dpy
);
2070 /* Send the glXSwapIntervalSGI request */
2072 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
2073 req
->reqType
= opcode
;
2074 req
->glxCode
= X_GLXVendorPrivate
;
2075 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
2076 req
->contextTag
= gc
->currentContextTag
;
2078 interval_ptr
= (CARD32
*) (req
+ 1);
2079 *interval_ptr
= interval
;
2090 ** GLX_MESA_swap_control
2093 __glXSwapIntervalMESA(unsigned int interval
)
2095 GLXContext gc
= __glXGetCurrentContext();
2097 #ifdef __DRI_SWAP_CONTROL
2098 if (gc
!= NULL
&& gc
->driContext
) {
2099 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2102 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2103 __GLXDRIdrawable
*pdraw
=
2104 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2105 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2106 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
2113 #ifdef GLX_DIRECT_RENDERING
2114 if (gc
!= NULL
&& gc
->driContext
) {
2115 __GLXscreenConfigs
*psc
;
2117 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2118 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2119 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2120 gc
->currentDrawable
, NULL
);
2121 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2127 return GLX_BAD_CONTEXT
;
2132 __glXGetSwapIntervalMESA(void)
2134 #ifdef __DRI_SWAP_CONTROL
2135 GLXContext gc
= __glXGetCurrentContext();
2137 if (gc
!= NULL
&& gc
->driContext
) {
2138 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2141 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2142 __GLXDRIdrawable
*pdraw
=
2143 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2144 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2145 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2151 #ifdef GLX_DIRECT_RENDERING
2152 if (gc
!= NULL
&& gc
->driContext
) {
2153 __GLXscreenConfigs
*psc
;
2155 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2156 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2157 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2158 gc
->currentDrawable
, NULL
);
2159 return psc
->driScreen
->getSwapInterval(pdraw
);
2169 ** GLX_MESA_swap_frame_usage
2173 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2175 int status
= GLX_BAD_CONTEXT
;
2176 #ifdef __DRI_FRAME_TRACKING
2178 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2179 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2181 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2182 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2192 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2194 int status
= GLX_BAD_CONTEXT
;
2195 #ifdef __DRI_FRAME_TRACKING
2197 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2198 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2200 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2201 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2212 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2214 int status
= GLX_BAD_CONTEXT
;
2215 #ifdef __DRI_FRAME_TRACKING
2217 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2218 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2220 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2221 int64_t sbc
, missedFrames
;
2222 float lastMissedUsage
;
2224 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2240 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2241 int64_t * sbc
, int64_t * missedFrames
,
2242 GLfloat
* lastMissedUsage
)
2244 int status
= GLX_BAD_CONTEXT
;
2245 #ifdef __DRI_FRAME_TRACKING
2247 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2248 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2250 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2253 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2262 (void) missedFrames
;
2263 (void) lastMissedUsage
;
2270 ** GLX_SGI_video_sync
2273 __glXGetVideoSyncSGI(unsigned int *count
)
2275 int64_t ust
, msc
, sbc
;
2277 GLXContext gc
= __glXGetCurrentContext();
2278 __GLXscreenConfigs
*psc
;
2279 #ifdef GLX_DIRECT_RENDERING
2280 __GLXDRIdrawable
*pdraw
;
2284 return GLX_BAD_CONTEXT
;
2286 #ifdef GLX_DIRECT_RENDERING
2287 if (!gc
->driContext
)
2288 return GLX_BAD_CONTEXT
;
2291 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2292 #ifdef GLX_DIRECT_RENDERING
2293 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2296 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2297 * FIXME: there should be a GLX encoding for this call. I can find no
2298 * FIXME: documentation for the GLX encoding.
2300 #ifdef __DRI_MEDIA_STREAM_COUNTER
2301 if ( psc
->msc
&& psc
->driScreen
) {
2302 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2303 pdraw
->driDrawable
, &msc
);
2304 *count
= (unsigned) msc
;
2306 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2310 #ifdef GLX_DIRECT_RENDERING
2311 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2312 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2313 *count
= (unsigned) msc
;
2314 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2318 return GLX_BAD_CONTEXT
;
2322 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2324 GLXContext gc
= __glXGetCurrentContext();
2325 __GLXscreenConfigs
*psc
;
2326 #ifdef GLX_DIRECT_RENDERING
2327 __GLXDRIdrawable
*pdraw
;
2329 int64_t ust
, msc
, sbc
;
2332 if (divisor
<= 0 || remainder
< 0)
2333 return GLX_BAD_VALUE
;
2336 return GLX_BAD_CONTEXT
;
2338 #ifdef GLX_DIRECT_RENDERING
2339 if (!gc
->driContext
)
2340 return GLX_BAD_CONTEXT
;
2343 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2344 #ifdef GLX_DIRECT_RENDERING
2345 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2348 #ifdef __DRI_MEDIA_STREAM_COUNTER
2349 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2350 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2351 divisor
, remainder
, &msc
, &sbc
);
2352 *count
= (unsigned) msc
;
2353 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2357 #ifdef GLX_DIRECT_RENDERING
2358 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2359 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2361 *count
= (unsigned) msc
;
2362 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2366 return GLX_BAD_CONTEXT
;
2369 #endif /* GLX_USE_APPLEGL */
2372 ** GLX_SGIX_fbconfig
2373 ** Many of these functions are aliased to GLX 1.3 entry points in the
2374 ** GLX_functions table.
2378 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2379 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2380 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2382 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2383 (Display
* dpy
, int screen
, int *attrib_list
,
2384 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2387 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2388 (Display
* dpy
, GLXFBConfigSGIX config
),
2389 (dpy
, config
), glXGetVisualFromFBConfig
)
2392 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2393 GLXFBConfigSGIX config
,
2396 #ifndef GLX_USE_APPLEGL
2397 xGLXVendorPrivateWithReplyReq
*vpreq
;
2398 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2399 GLXPixmap xid
= None
;
2401 __GLXscreenConfigs
*psc
;
2403 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2406 if ((dpy
== NULL
) || (config
== NULL
)) {
2409 #ifdef GLX_USE_APPLEGL
2410 if(apple_glx_pixmap_create(dpy
, fbconfig
->screen
, pixmap
, fbconfig
))
2415 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2417 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2418 opcode
= __glXSetupForCommand(dpy
);
2423 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2425 GetReqExtra(GLXVendorPrivateWithReply
,
2426 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2427 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2428 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2429 req
->reqType
= opcode
;
2430 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2431 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2432 req
->screen
= fbconfig
->screen
;
2433 req
->fbconfig
= fbconfig
->fbconfigID
;
2434 req
->pixmap
= pixmap
;
2435 req
->glxpixmap
= xid
= XAllocID(dpy
);
2445 glXCreateContextWithConfigSGIX(Display
* dpy
,
2446 GLXFBConfigSGIX config
, int renderType
,
2447 GLXContext shareList
, Bool allowDirect
)
2449 GLXContext gc
= NULL
;
2450 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2451 __GLXscreenConfigs
*psc
;
2454 if ((dpy
== NULL
) || (config
== NULL
)) {
2458 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2460 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2461 gc
= CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
2463 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2471 PUBLIC GLXFBConfigSGIX
2472 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2474 __GLXdisplayPrivate
*priv
;
2475 __GLXscreenConfigs
*psc
= NULL
;
2477 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2478 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2479 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2480 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2487 #ifndef GLX_USE_APPLEGL
2489 ** GLX_SGIX_swap_group
2492 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2502 ** GLX_SGIX_swap_barrier
2505 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2513 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2523 ** GLX_OML_sync_control
2526 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2527 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2529 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2531 #ifdef GLX_DIRECT_RENDERING
2532 __GLXDRIdrawable
*pdraw
;
2534 __GLXscreenConfigs
*psc
;
2539 #ifdef GLX_DIRECT_RENDERING
2540 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2542 psc
= &priv
->screenConfigs
[i
];
2544 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2545 if (pdraw
&& psc
->sbc
&& psc
->msc
)
2546 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2547 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2548 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2549 && (__glXGetUST(ust
) == 0) );
2552 #ifdef GLX_DIRECT_RENDERING
2553 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2554 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2562 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2564 __driGetMscRateOML(__DRIdrawable
* draw
,
2565 int32_t * numerator
, int32_t * denominator
, void *private)
2568 __GLXscreenConfigs
*psc
;
2569 XF86VidModeModeLine mode_line
;
2572 __GLXDRIdrawable
*glxDraw
= private;
2577 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2578 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2579 unsigned n
= dot_clock
* 1000;
2580 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2582 # define V_INTERLACE 0x010
2583 # define V_DBLSCAN 0x020
2585 if (mode_line
.flags
& V_INTERLACE
)
2587 else if (mode_line
.flags
& V_DBLSCAN
)
2590 /* The OML_sync_control spec requires that if the refresh rate is a
2591 * whole number, that the returned numerator be equal to the refresh
2592 * rate and the denominator be 1.
2600 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2602 /* This is a poor man's way to reduce a fraction. It's far from
2603 * perfect, but it will work well enough for this situation.
2606 for (i
= 0; f
[i
] != 0; i
++) {
2607 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2633 * Determine the refresh rate of the specified drawable and display.
2635 * \param dpy Display whose refresh rate is to be determined.
2636 * \param drawable Drawable whose refresh rate is to be determined.
2637 * \param numerator Numerator of the refresh rate.
2638 * \param demoninator Denominator of the refresh rate.
2639 * \return If the refresh rate for the specified display and drawable could
2640 * be calculated, True is returned. Otherwise False is returned.
2642 * \note This function is implemented entirely client-side. A lot of other
2643 * functionality is required to export GLX_OML_sync_control, so on
2644 * XFree86 this function can be called for direct-rendering contexts
2645 * when GLX_OML_sync_control appears in the client extension string.
2649 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2650 int32_t * numerator
, int32_t * denominator
)
2652 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2653 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2658 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2670 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2671 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2673 GLXContext gc
= __glXGetCurrentContext();
2675 #ifdef GLX_DIRECT_RENDERING
2676 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2678 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2680 if (!gc
) /* no GLX for this */
2683 #ifdef GLX_DIRECT_RENDERING
2684 if (!pdraw
|| !gc
->driContext
)
2688 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2689 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2690 * of -1 if the function failed because of errors detected in the input
2693 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2695 if (divisor
> 0 && remainder
>= divisor
)
2698 #ifdef __DRI_SWAP_BUFFER_COUNTER
2699 if (psc
->counters
!= NULL
)
2700 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2701 divisor
, remainder
);
2704 #ifdef GLX_DIRECT_RENDERING
2705 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2706 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2715 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2716 int64_t target_msc
, int64_t divisor
,
2717 int64_t remainder
, int64_t * ust
,
2718 int64_t * msc
, int64_t * sbc
)
2721 #ifdef GLX_DIRECT_RENDERING
2722 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2724 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2728 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2729 * error", but the return type in the spec is Bool.
2731 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2733 if (divisor
> 0 && remainder
>= divisor
)
2736 #ifdef __DRI_MEDIA_STREAM_COUNTER
2737 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2738 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2739 divisor
, remainder
, msc
, sbc
);
2741 /* __glXGetUST returns zero on success and non-zero on failure.
2742 * This function returns True on success and False on failure.
2744 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2748 #ifdef GLX_DIRECT_RENDERING
2749 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2750 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2761 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2762 int64_t target_sbc
, int64_t * ust
,
2763 int64_t * msc
, int64_t * sbc
)
2766 #ifdef GLX_DIRECT_RENDERING
2767 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2769 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2772 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2773 * error", but the return type in the spec is Bool.
2777 #ifdef __DRI_SWAP_BUFFER_COUNTER
2778 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2780 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2782 /* __glXGetUST returns zero on success and non-zero on failure.
2783 * This function returns True on success and False on failure.
2785 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2789 #ifdef GLX_DIRECT_RENDERING
2790 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2791 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2801 * GLX_MESA_allocate_memory
2806 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2807 size_t size
, float readFreq
,
2808 float writeFreq
, float priority
)
2810 #ifdef __DRI_ALLOCATE
2811 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2813 if (psc
&& psc
->allocate
)
2814 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2815 readFreq
, writeFreq
, priority
);
2824 #endif /* __DRI_ALLOCATE */
2831 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2833 #ifdef __DRI_ALLOCATE
2834 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2836 if (psc
&& psc
->allocate
)
2837 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2843 #endif /* __DRI_ALLOCATE */
2848 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2850 #ifdef __DRI_ALLOCATE
2851 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2853 if (psc
&& psc
->allocate
)
2854 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2860 #endif /* GLX_DIRECT_RENDERING */
2869 * Mesa extension stubs. These will help reduce portability problems.
2874 * Release all buffers associated with the specified GLX drawable.
2877 * This function was intended for stand-alone Mesa. The issue there is that
2878 * the library doesn't get any notification when a window is closed. In
2879 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2880 * supported, there are 3 different functions to destroy a drawable. It
2881 * should be possible to create GLX protocol (or have it determine which
2882 * protocol to use based on the type of the drawable) to have one function
2883 * do the work of 3. For the direct-rendering case, this function could
2884 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2885 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2886 * would need to be used. This really should be done as part of the new DRI
2889 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2890 * __driGarbageCollectDrawables
2891 * glXDestroyGLXPixmap
2892 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2893 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2896 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2905 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2906 Pixmap pixmap
, Colormap cmap
)
2919 * GLX_MESA_copy_sub_buffer
2921 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2923 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2924 int x
, int y
, int width
, int height
)
2926 xGLXVendorPrivateReq
*req
;
2929 CARD32
*drawable_ptr
;
2930 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2933 #ifdef __DRI_COPY_SUB_BUFFER
2935 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2936 if (pdraw
!= NULL
) {
2937 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2938 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2940 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2947 opcode
= __glXSetupForCommand(dpy
);
2952 ** The calling thread may or may not have a current context. If it
2953 ** does, send the context tag so the server can do a flush.
2955 gc
= __glXGetCurrentContext();
2956 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2957 ((drawable
== gc
->currentDrawable
) ||
2958 (drawable
== gc
->currentReadable
))) {
2959 tag
= gc
->currentContextTag
;
2966 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2967 req
->reqType
= opcode
;
2968 req
->glxCode
= X_GLXVendorPrivate
;
2969 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2970 req
->contextTag
= tag
;
2972 drawable_ptr
= (CARD32
*) (req
+ 1);
2973 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2974 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2975 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2976 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2978 *drawable_ptr
= drawable
;
2990 * GLX_EXT_texture_from_pixmap
2994 __glXBindTexImageEXT(Display
* dpy
,
2995 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2997 xGLXVendorPrivateReq
*req
;
2998 GLXContext gc
= __glXGetCurrentContext();
2999 CARD32
*drawable_ptr
;
3001 CARD32
*num_attrib_ptr
;
3011 while (attrib_list
[i
* 2] != None
)
3015 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3016 if (gc
->driContext
) {
3017 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
3019 if (pdraw
!= NULL
) {
3020 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
3021 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
3022 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
3023 pdraw
->textureTarget
,
3024 pdraw
->textureFormat
,
3025 pdraw
->driDrawable
);
3028 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
3029 pdraw
->textureTarget
,
3030 pdraw
->driDrawable
);
3037 opcode
= __glXSetupForCommand(dpy
);
3042 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
3043 req
->reqType
= opcode
;
3044 req
->glxCode
= X_GLXVendorPrivate
;
3045 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
3046 req
->contextTag
= gc
->currentContextTag
;
3048 drawable_ptr
= (CARD32
*) (req
+ 1);
3049 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
3050 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
3051 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
3053 *drawable_ptr
= drawable
;
3054 *buffer_ptr
= buffer
;
3055 *num_attrib_ptr
= (CARD32
) i
;
3059 while (attrib_list
[i
* 2] != None
) {
3060 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
3061 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
3071 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
3073 xGLXVendorPrivateReq
*req
;
3074 GLXContext gc
= __glXGetCurrentContext();
3075 CARD32
*drawable_ptr
;
3079 if ((gc
== NULL
) || GC_IS_DIRECT(gc
))
3082 opcode
= __glXSetupForCommand(dpy
);
3087 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
3088 req
->reqType
= opcode
;
3089 req
->glxCode
= X_GLXVendorPrivate
;
3090 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
3091 req
->contextTag
= gc
->currentContextTag
;
3093 drawable_ptr
= (CARD32
*) (req
+ 1);
3094 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
3096 *drawable_ptr
= drawable
;
3097 *buffer_ptr
= buffer
;
3105 #endif /* GLX_USE_APPLEGL */
3108 * \c strdup is actually not a standard ANSI C or POSIX routine.
3109 * Irix will not define it if ANSI mode is in effect.
3114 __glXstrdup(const char *str
)
3117 copy
= (char *) Xmalloc(strlen(str
) + 1);
3125 ** glXGetProcAddress support
3128 struct name_address_pair
3134 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
3135 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
3137 static const struct name_address_pair GLX_functions
[] = {
3138 /*** GLX_VERSION_1_0 ***/
3139 GLX_FUNCTION(glXChooseVisual
),
3140 GLX_FUNCTION(glXCopyContext
),
3141 GLX_FUNCTION(glXCreateContext
),
3142 GLX_FUNCTION(glXCreateGLXPixmap
),
3143 GLX_FUNCTION(glXDestroyContext
),
3144 GLX_FUNCTION(glXDestroyGLXPixmap
),
3145 GLX_FUNCTION(glXGetConfig
),
3146 GLX_FUNCTION(glXGetCurrentContext
),
3147 GLX_FUNCTION(glXGetCurrentDrawable
),
3148 GLX_FUNCTION(glXIsDirect
),
3149 GLX_FUNCTION(glXMakeCurrent
),
3150 GLX_FUNCTION(glXQueryExtension
),
3151 GLX_FUNCTION(glXQueryVersion
),
3152 GLX_FUNCTION(glXSwapBuffers
),
3153 GLX_FUNCTION(glXUseXFont
),
3154 GLX_FUNCTION(glXWaitGL
),
3155 GLX_FUNCTION(glXWaitX
),
3157 /*** GLX_VERSION_1_1 ***/
3158 GLX_FUNCTION(glXGetClientString
),
3159 GLX_FUNCTION(glXQueryExtensionsString
),
3160 GLX_FUNCTION(glXQueryServerString
),
3162 /*** GLX_VERSION_1_2 ***/
3163 GLX_FUNCTION(glXGetCurrentDisplay
),
3165 /*** GLX_VERSION_1_3 ***/
3166 GLX_FUNCTION(glXChooseFBConfig
),
3167 GLX_FUNCTION(glXCreateNewContext
),
3168 GLX_FUNCTION(glXCreatePbuffer
),
3169 GLX_FUNCTION(glXCreatePixmap
),
3170 GLX_FUNCTION(glXCreateWindow
),
3171 GLX_FUNCTION(glXDestroyPbuffer
),
3172 GLX_FUNCTION(glXDestroyPixmap
),
3173 GLX_FUNCTION(glXDestroyWindow
),
3174 GLX_FUNCTION(glXGetCurrentReadDrawable
),
3175 GLX_FUNCTION(glXGetFBConfigAttrib
),
3176 GLX_FUNCTION(glXGetFBConfigs
),
3177 GLX_FUNCTION(glXGetSelectedEvent
),
3178 GLX_FUNCTION(glXGetVisualFromFBConfig
),
3179 GLX_FUNCTION(glXMakeContextCurrent
),
3180 GLX_FUNCTION(glXQueryContext
),
3181 GLX_FUNCTION(glXQueryDrawable
),
3182 GLX_FUNCTION(glXSelectEvent
),
3184 #ifndef GLX_USE_APPLEGL
3185 /*** GLX_SGI_swap_control ***/
3186 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
3188 /*** GLX_SGI_video_sync ***/
3189 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
3190 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
3192 /*** GLX_SGI_make_current_read ***/
3193 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
3194 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
3196 /*** GLX_EXT_import_context ***/
3197 GLX_FUNCTION(glXFreeContextEXT
),
3198 GLX_FUNCTION(glXGetContextIDEXT
),
3199 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
3200 GLX_FUNCTION(glXImportContextEXT
),
3201 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3204 /*** GLX_SGIX_fbconfig ***/
3205 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3206 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3207 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3208 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3209 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3210 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3212 #ifndef GLX_USE_APPLEGL
3213 /*** GLX_SGIX_pbuffer ***/
3214 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3215 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3216 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3217 GLX_FUNCTION(glXSelectEventSGIX
),
3218 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3220 /*** GLX_SGIX_swap_group ***/
3221 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3223 /*** GLX_SGIX_swap_barrier ***/
3224 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3225 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3227 /*** GLX_MESA_allocate_memory ***/
3228 GLX_FUNCTION(glXAllocateMemoryMESA
),
3229 GLX_FUNCTION(glXFreeMemoryMESA
),
3230 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3232 /*** GLX_MESA_copy_sub_buffer ***/
3233 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3235 /*** GLX_MESA_pixmap_colormap ***/
3236 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3238 /*** GLX_MESA_release_buffers ***/
3239 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3241 /*** GLX_MESA_swap_control ***/
3242 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3243 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3245 /*** GLX_MESA_swap_frame_usage ***/
3246 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3247 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3248 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3249 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3252 /*** GLX_ARB_get_proc_address ***/
3253 GLX_FUNCTION(glXGetProcAddressARB
),
3256 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3258 #ifndef GLX_USE_APPLEGL
3259 /*** GLX_OML_sync_control ***/
3260 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3261 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3262 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3263 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3264 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3266 /*** GLX_EXT_texture_from_pixmap ***/
3267 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3268 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3271 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3272 /*** DRI configuration ***/
3273 GLX_FUNCTION(glXGetScreenDriver
),
3274 GLX_FUNCTION(glXGetDriverConfig
),
3277 {NULL
, NULL
} /* end of list */
3280 #ifndef GLX_USE_APPLEGL
3281 static const GLvoid
*
3282 get_glx_proc_address(const char *funcName
)
3286 /* try static functions */
3287 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3288 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3289 return GLX_functions
[i
].Address
;
3297 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3298 * \c glXGetProcAddress.
3300 * \param procName Name of a GL or GLX function.
3301 * \returns A pointer to the named function
3303 * \sa glXGetProcAddress
3305 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3307 typedef void (*gl_function
) (void);
3311 /* Search the table of GLX and internal functions first. If that
3312 * fails and the supplied name could be a valid core GL name, try
3313 * searching the core GL function table. This check is done to prevent
3314 * DRI based drivers from searching the core GL function table for
3315 * internal API functions.
3317 #ifdef GLX_USE_APPLEGL
3318 f
= (gl_function
) apple_glx_get_proc_address(procName
);
3320 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3321 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3322 && (procName
[2] != 'X')) {
3323 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3330 * Get the address of a named GL function. This is the GLX 1.4 name for
3331 * \c glXGetProcAddressARB.
3333 * \param procName Name of a GL or GLX function.
3334 * \returns A pointer to the named function
3336 * \sa glXGetProcAddressARB
3338 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3339 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3340 __attribute__ ((alias("glXGetProcAddressARB")));
3343 return glXGetProcAddressARB(procName
);
3345 #endif /* __GNUC__ */
3348 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3350 * Get the unadjusted system time (UST). Currently, the UST is measured in
3351 * microseconds since Epoc. The actual resolution of the UST may vary from
3352 * system to system, and the units may vary from release to release.
3353 * Drivers should not call this function directly. They should instead use
3354 * \c glXGetProcAddress to obtain a pointer to the function.
3356 * \param ust Location to store the 64-bit UST
3357 * \returns Zero on success or a negative errno value on failure.
3359 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3361 * \since Internal API version 20030317.
3364 __glXGetUST(int64_t * ust
)
3372 if (gettimeofday(&tv
, NULL
) == 0) {
3373 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3380 #endif /* GLX_DIRECT_RENDERING */