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 __glFreeAttributeState(gc
);
543 XFree((char *) gc
->buf
);
544 Xfree((char *) gc
->client_state_private
);
550 ** Destroy the named context
553 DestroyContext(Display
* dpy
, GLXContext gc
)
555 #ifndef GLX_USE_APPLEGL /* TODO: darwin: indirect */
556 xGLXDestroyContextReq
*req
;
561 opcode
= __glXSetupForCommand(dpy
);
562 if (!opcode
|| !gc
) {
568 imported
= gc
->imported
;
571 if (gc
->currentDpy
) {
572 /* This context is bound to some thread. According to the man page,
573 * we should not actually delete the context until it's unbound.
574 * Note that we set gc->xid = None above. In MakeContextCurrent()
575 * we check for that and delete the context there.
581 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
582 /* Destroy the direct rendering context */
583 if (gc
->driContext
) {
584 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
585 gc
->driContext
= NULL
;
586 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
590 __glXFreeVertexArrayState(gc
);
593 #endif /* GLX_USE_APPLEGL */
595 if (gc
->currentDpy
) {
596 #ifdef GLX_USE_APPLEGL
598 * Set the Bool that indicates that we should destroy this GLX context
599 * when the context is no longer current.
601 gc
->do_destroy
= True
;
603 /* Have to free later cuz it's in use now */
607 /* Destroy the handle if not current to anybody */
609 #ifdef GLX_USE_APPLEGL
611 apple_glx_destroy_context(&gc
->driContext
, dpy
);
613 __glXFreeContext(gc
);
615 #ifndef GLX_USE_APPLEGL
618 ** This dpy also created the server side part of the context.
619 ** Send the glXDestroyContext request.
622 GetReq(GLXDestroyContext
, req
);
623 req
->reqType
= opcode
;
624 req
->glxCode
= X_GLXDestroyContext
;
633 glXDestroyContext(Display
* dpy
, GLXContext gc
)
635 DestroyContext(dpy
, gc
);
639 ** Return the major and minor version #s for the GLX extension
642 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
644 __GLXdisplayPrivate
*priv
;
646 /* Init the extension. This fetches the major and minor version. */
647 priv
= __glXInitialize(dpy
);
652 *major
= priv
->majorVersion
;
654 *minor
= priv
->minorVersion
;
659 ** Query the existance of the GLX extension
662 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
664 int major_op
, erb
, evb
;
667 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
678 ** Put a barrier in the token stream that forces the GL to finish its
679 ** work before X can proceed.
684 #ifndef GLX_USE_APPLEGL
687 GLXContext gc
= __glXGetCurrentContext();
688 Display
*dpy
= gc
->currentDpy
;
693 /* Flush any pending commands out */
694 __glXFlushRenderBuffer(gc
, gc
->pc
);
695 #ifdef GLX_USE_APPLEGL
698 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
699 if (gc
->driContext
) {
701 __GLXDRIdrawable
*pdraw
=
702 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
705 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
707 if (psc
->driScreen
->waitGL
!= NULL
)
708 (*psc
->driScreen
->waitGL
) (pdraw
);
714 /* Send the glXWaitGL request */
716 GetReq(GLXWaitGL
, req
);
717 req
->reqType
= gc
->majorOpcode
;
718 req
->glxCode
= X_GLXWaitGL
;
719 req
->contextTag
= gc
->currentContextTag
;
722 #endif /* GLX_USE_APPLEGL */
726 ** Put a barrier in the token stream that forces X to finish its
727 ** work before GL can proceed.
732 #ifndef GLX_USE_APPLEGL
735 GLXContext gc
= __glXGetCurrentContext();
736 Display
*dpy
= gc
->currentDpy
;
741 /* Flush any pending commands out */
742 __glXFlushRenderBuffer(gc
, gc
->pc
);
744 #ifdef GLX_USE_APPLEGL
745 apple_glx_waitx(dpy
, gc
->driContext
);
747 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
748 if (gc
->driContext
) {
750 __GLXDRIdrawable
*pdraw
=
751 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
754 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
755 if (psc
->driScreen
->waitX
!= NULL
)
756 (*psc
->driScreen
->waitX
) (pdraw
);
765 ** Send the glXWaitX request.
768 GetReq(GLXWaitX
, req
);
769 req
->reqType
= gc
->majorOpcode
;
770 req
->glxCode
= X_GLXWaitX
;
771 req
->contextTag
= gc
->currentContextTag
;
774 #endif /* GLX_USE_APPLEGL */
778 glXUseXFont(Font font
, int first
, int count
, int listBase
)
780 #ifndef GLX_USE_APPLEGL
781 xGLXUseXFontReq
*req
;
783 GLXContext gc
= __glXGetCurrentContext();
784 Display
*dpy
= gc
->currentDpy
;
789 /* Flush any pending commands out */
790 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
791 #ifdef GLX_USE_APPLEGL
792 DRI_glXUseXFont(font
, first
, count
, listBase
);
794 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
795 if (gc
->driContext
) {
796 DRI_glXUseXFont(font
, first
, count
, listBase
);
801 /* Send the glXUseFont request */
803 GetReq(GLXUseXFont
, req
);
804 req
->reqType
= gc
->majorOpcode
;
805 req
->glxCode
= X_GLXUseXFont
;
806 req
->contextTag
= gc
->currentContextTag
;
810 req
->listBase
= listBase
;
813 #endif /* GLX_USE_APPLEGL */
816 /************************************************************************/
819 ** Copy the source context to the destination context using the
823 glXCopyContext(Display
* dpy
, GLXContext source
,
824 GLXContext dest
, unsigned long mask
)
826 #ifdef GLX_USE_APPLEGL
827 GLXContext gc
= __glXGetCurrentContext();
831 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
832 mask
, &errorcode
, &x11error
)) {
833 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
837 xGLXCopyContextReq
*req
;
838 GLXContext gc
= __glXGetCurrentContext();
842 opcode
= __glXSetupForCommand(dpy
);
847 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
848 if (gc
->driContext
) {
849 /* NOT_DONE: This does not work yet */
854 ** If the source is the current context, send its tag so that the context
855 ** can be flushed before the copy.
857 if (source
== gc
&& dpy
== gc
->currentDpy
) {
858 tag
= gc
->currentContextTag
;
864 /* Send the glXCopyContext request */
866 GetReq(GLXCopyContext
, req
);
867 req
->reqType
= opcode
;
868 req
->glxCode
= X_GLXCopyContext
;
869 req
->source
= source
? source
->xid
: None
;
870 req
->dest
= dest
? dest
->xid
: None
;
872 req
->contextTag
= tag
;
875 #endif /* GLX_USE_APPLEGL */
880 * Determine if a context uses direct rendering.
882 * \param dpy Display where the context was created.
883 * \param contextID ID of the context to be tested.
885 * \returns \c GL_TRUE if the context is direct rendering or not.
888 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
890 #if !defined(USE_XCB)
891 xGLXIsDirectReq
*req
;
892 xGLXIsDirectReply reply
;
896 opcode
= __glXSetupForCommand(dpy
);
902 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
903 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
908 const Bool is_direct
= reply
->is_direct
? True
: False
;
913 /* Send the glXIsDirect request */
915 GetReq(GLXIsDirect
, req
);
916 req
->reqType
= opcode
;
917 req
->glxCode
= X_GLXIsDirect
;
918 req
->context
= contextID
;
919 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
923 return reply
.isDirect
;
929 * Shouldn't this function \b always return \c GL_FALSE when
930 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
931 * the GLX protocol here at all?
934 glXIsDirect(Display
* dpy
, GLXContext gc
)
939 else if (GC_IS_DIRECT(gc
)) {
942 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
945 return __glXIsDirect(dpy
, gc
->xid
);
950 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
952 #ifdef GLX_USE_APPLEGL
953 int screen
= vis
->screen
;
954 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
955 const __GLcontextModes
*modes
;
957 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
959 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, modes
))
964 xGLXCreateGLXPixmapReq
*req
;
968 opcode
= __glXSetupForCommand(dpy
);
973 /* Send the glXCreateGLXPixmap request */
975 GetReq(GLXCreateGLXPixmap
, req
);
976 req
->reqType
= opcode
;
977 req
->glxCode
= X_GLXCreateGLXPixmap
;
978 req
->screen
= vis
->screen
;
979 req
->visual
= vis
->visualid
;
980 req
->pixmap
= pixmap
;
981 req
->glxpixmap
= xid
= XAllocID(dpy
);
985 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
987 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
988 * is actually bound to a context... */
990 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
991 __GLXDRIdrawable
*pdraw
;
992 __GLXscreenConfigs
*psc
;
993 __GLcontextModes
*modes
;
995 psc
= &priv
->screenConfigs
[vis
->screen
];
996 if (psc
->driScreen
== NULL
)
998 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
999 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
1000 if (pdraw
== NULL
) {
1001 fprintf(stderr
, "failed to create pixmap\n");
1005 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
1006 (*pdraw
->destroyDrawable
) (pdraw
);
1007 return None
; /* FIXME: Check what we're supposed to do here... */
1017 ** Destroy the named pixmap
1020 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
1022 #ifdef GLX_USE_APPLEGL
1023 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
1024 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
1026 xGLXDestroyGLXPixmapReq
*req
;
1029 opcode
= __glXSetupForCommand(dpy
);
1034 /* Send the glXDestroyGLXPixmap request */
1036 GetReq(GLXDestroyGLXPixmap
, req
);
1037 req
->reqType
= opcode
;
1038 req
->glxCode
= X_GLXDestroyGLXPixmap
;
1039 req
->glxpixmap
= glxpixmap
;
1043 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1046 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
1047 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
1048 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
1050 if (pdraw
!= NULL
) {
1051 (*pdraw
->destroyDrawable
) (pdraw
);
1052 __glxHashDelete(psc
->drawHash
, glxpixmap
);
1056 #endif /* GLX_USE_APPLEGL */
1060 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
1062 #ifdef GLX_USE_APPLEGL
1063 GLXContext gc
= glXGetCurrentContext();
1064 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
1065 apple_glx_swap_buffers(gc
->driContext
);
1067 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
1074 xcb_connection_t
*c
;
1076 xGLXSwapBuffersReq
*req
;
1079 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1080 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
1082 if (pdraw
!= NULL
) {
1084 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
1089 opcode
= __glXSetupForCommand(dpy
);
1095 ** The calling thread may or may not have a current context. If it
1096 ** does, send the context tag so the server can do a flush.
1098 gc
= __glXGetCurrentContext();
1099 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1100 ((drawable
== gc
->currentDrawable
)
1101 || (drawable
== gc
->currentReadable
))) {
1102 tag
= gc
->currentContextTag
;
1109 c
= XGetXCBConnection(dpy
);
1110 xcb_glx_swap_buffers(c
, tag
, drawable
);
1113 /* Send the glXSwapBuffers request */
1115 GetReq(GLXSwapBuffers
, req
);
1116 req
->reqType
= opcode
;
1117 req
->glxCode
= X_GLXSwapBuffers
;
1118 req
->drawable
= drawable
;
1119 req
->contextTag
= tag
;
1123 #endif /* USE_XCB */
1124 #endif /* GLX_USE_APPLEGL */
1129 ** Return configuration information for the given display, screen and
1130 ** visual combination.
1133 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1136 __GLXdisplayPrivate
*priv
;
1137 __GLXscreenConfigs
*psc
;
1138 __GLcontextModes
*modes
;
1141 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1142 if (status
== Success
) {
1143 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1145 /* Lookup attribute after first finding a match on the visual */
1146 if (modes
!= NULL
) {
1147 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1150 status
= GLX_BAD_VISUAL
;
1154 ** If we can't find the config for this visual, this visual is not
1155 ** supported by the OpenGL implementation on the server.
1157 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1158 *value_return
= GL_FALSE
;
1165 /************************************************************************/
1168 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1169 GLboolean fbconfig_style_tags
)
1171 memset(config
, 0, sizeof(__GLcontextModes
));
1172 config
->visualID
= (XID
) GLX_DONT_CARE
;
1173 config
->visualType
= GLX_DONT_CARE
;
1175 /* glXChooseFBConfig specifies different defaults for these two than
1178 if (fbconfig_style_tags
) {
1179 config
->rgbMode
= GL_TRUE
;
1180 config
->doubleBufferMode
= GLX_DONT_CARE
;
1183 config
->visualRating
= GLX_DONT_CARE
;
1184 config
->transparentPixel
= GLX_NONE
;
1185 config
->transparentRed
= GLX_DONT_CARE
;
1186 config
->transparentGreen
= GLX_DONT_CARE
;
1187 config
->transparentBlue
= GLX_DONT_CARE
;
1188 config
->transparentAlpha
= GLX_DONT_CARE
;
1189 config
->transparentIndex
= GLX_DONT_CARE
;
1191 config
->drawableType
= GLX_WINDOW_BIT
;
1192 config
->renderType
=
1193 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1194 config
->xRenderable
= GLX_DONT_CARE
;
1195 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1197 config
->swapMethod
= GLX_DONT_CARE
;
1200 #define MATCH_DONT_CARE( param ) \
1202 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1203 && (a-> param != b-> param) ) { \
1208 #define MATCH_MINIMUM( param ) \
1210 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1211 && (a-> param > b-> param) ) { \
1216 #define MATCH_EXACT( param ) \
1218 if ( a-> param != b-> param) { \
1223 /* Test that all bits from a are contained in b */
1224 #define MATCH_MASK(param) \
1226 if ((a->param & ~b->param) != 0) \
1231 * Determine if two GLXFBConfigs are compatible.
1233 * \param a Application specified config to test.
1234 * \param b Server specified config to test against \c a.
1237 fbconfigs_compatible(const __GLcontextModes
* const a
,
1238 const __GLcontextModes
* const b
)
1240 MATCH_DONT_CARE(doubleBufferMode
);
1241 MATCH_DONT_CARE(visualType
);
1242 MATCH_DONT_CARE(visualRating
);
1243 MATCH_DONT_CARE(xRenderable
);
1244 MATCH_DONT_CARE(fbconfigID
);
1245 MATCH_DONT_CARE(swapMethod
);
1247 MATCH_MINIMUM(rgbBits
);
1248 MATCH_MINIMUM(numAuxBuffers
);
1249 MATCH_MINIMUM(redBits
);
1250 MATCH_MINIMUM(greenBits
);
1251 MATCH_MINIMUM(blueBits
);
1252 MATCH_MINIMUM(alphaBits
);
1253 MATCH_MINIMUM(depthBits
);
1254 MATCH_MINIMUM(stencilBits
);
1255 MATCH_MINIMUM(accumRedBits
);
1256 MATCH_MINIMUM(accumGreenBits
);
1257 MATCH_MINIMUM(accumBlueBits
);
1258 MATCH_MINIMUM(accumAlphaBits
);
1259 MATCH_MINIMUM(sampleBuffers
);
1260 MATCH_MINIMUM(maxPbufferWidth
);
1261 MATCH_MINIMUM(maxPbufferHeight
);
1262 MATCH_MINIMUM(maxPbufferPixels
);
1263 MATCH_MINIMUM(samples
);
1265 MATCH_DONT_CARE(stereoMode
);
1268 MATCH_MASK(drawableType
);
1269 MATCH_MASK(renderType
);
1271 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1272 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1273 * Technically speaking, it is a bug in the DDX driver, but there is
1274 * enough of an installed base to work around the problem here. In any
1275 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1276 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1277 * 0 from the server to be a match to maintain backward compatibility with
1278 * the (broken) drivers.
1281 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1282 if (a
->transparentPixel
== GLX_NONE
) {
1283 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1287 MATCH_EXACT(transparentPixel
);
1290 switch (a
->transparentPixel
) {
1291 case GLX_TRANSPARENT_RGB
:
1292 MATCH_DONT_CARE(transparentRed
);
1293 MATCH_DONT_CARE(transparentGreen
);
1294 MATCH_DONT_CARE(transparentBlue
);
1295 MATCH_DONT_CARE(transparentAlpha
);
1298 case GLX_TRANSPARENT_INDEX
:
1299 MATCH_DONT_CARE(transparentIndex
);
1311 /* There's some trickly language in the GLX spec about how this is supposed
1312 * to work. Basically, if a given component size is either not specified
1313 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1314 * Well, that's really hard to do with the code as-is. This behavior is
1315 * closer to correct, but still not technically right.
1317 #define PREFER_LARGER_OR_ZERO(comp) \
1319 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1320 if ( ((*a)-> comp) == 0 ) { \
1323 else if ( ((*b)-> comp) == 0 ) { \
1327 return ((*b)-> comp) - ((*a)-> comp) ; \
1332 #define PREFER_LARGER(comp) \
1334 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1335 return ((*b)-> comp) - ((*a)-> comp) ; \
1339 #define PREFER_SMALLER(comp) \
1341 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1342 return ((*a)-> comp) - ((*b)-> comp) ; \
1347 * Compare two GLXFBConfigs. This function is intended to be used as the
1348 * compare function passed in to qsort.
1350 * \returns If \c a is a "better" config, according to the specification of
1351 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1352 * better, then a number greater than zero is return. If both are
1353 * equal, zero is returned.
1354 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1357 fbconfig_compare(const __GLcontextModes
* const *const a
,
1358 const __GLcontextModes
* const *const b
)
1360 /* The order of these comparisons must NOT change. It is defined by
1361 * the GLX 1.3 spec and ARB_multisample.
1364 PREFER_SMALLER(visualSelectGroup
);
1366 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1367 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1368 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1370 PREFER_SMALLER(visualRating
);
1372 /* This isn't quite right. It is supposed to compare the sum of the
1373 * components the user specifically set minimums for.
1375 PREFER_LARGER_OR_ZERO(redBits
);
1376 PREFER_LARGER_OR_ZERO(greenBits
);
1377 PREFER_LARGER_OR_ZERO(blueBits
);
1378 PREFER_LARGER_OR_ZERO(alphaBits
);
1380 PREFER_SMALLER(rgbBits
);
1382 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1383 /* Prefer single-buffer.
1385 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1388 PREFER_SMALLER(numAuxBuffers
);
1390 PREFER_LARGER_OR_ZERO(depthBits
);
1391 PREFER_SMALLER(stencilBits
);
1393 /* This isn't quite right. It is supposed to compare the sum of the
1394 * components the user specifically set minimums for.
1396 PREFER_LARGER_OR_ZERO(accumRedBits
);
1397 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1398 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1399 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1401 PREFER_SMALLER(visualType
);
1403 /* None of the multisample specs say where this comparison should happen,
1404 * so I put it near the end.
1406 PREFER_SMALLER(sampleBuffers
);
1407 PREFER_SMALLER(samples
);
1409 /* None of the pbuffer or fbconfig specs say that this comparison needs
1410 * to happen at all, but it seems like it should.
1412 PREFER_LARGER(maxPbufferWidth
);
1413 PREFER_LARGER(maxPbufferHeight
);
1414 PREFER_LARGER(maxPbufferPixels
);
1421 * Selects and sorts a subset of the supplied configs based on the attributes.
1422 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1423 * and \c glXChooseFBConfigSGIX.
1425 * \param configs Array of pointers to possible configs. The elements of
1426 * this array that do not meet the criteria will be set to
1427 * NULL. The remaining elements will be sorted according to
1428 * the various visual / FBConfig selection rules.
1429 * \param num_configs Number of elements in the \c configs array.
1430 * \param attribList Attributes used select from \c configs. This array is
1431 * terminated by a \c None tag. The array can either take
1432 * the form expected by \c glXChooseVisual (where boolean
1433 * tags do not have a value) or by \c glXChooseFBConfig
1434 * (where every tag has a value).
1435 * \param fbconfig_style_tags Selects whether \c attribList is in
1436 * \c glXChooseVisual style or
1437 * \c glXChooseFBConfig style.
1438 * \returns The number of valid elements left in \c configs.
1440 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1443 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1444 const int *attribList
, GLboolean fbconfig_style_tags
)
1446 __GLcontextModes test_config
;
1450 /* This is a fairly direct implementation of the selection method
1451 * described by GLX_SGIX_fbconfig. Start by culling out all the
1452 * configs that are not compatible with the selected parameter
1456 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1457 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1458 (const INT32
*) attribList
,
1459 GL_TRUE
, fbconfig_style_tags
);
1462 for (i
= 0; i
< num_configs
; i
++) {
1463 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1464 configs
[base
] = configs
[i
];
1473 if (base
< num_configs
) {
1474 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1477 /* After the incompatible configs are removed, the resulting
1478 * list is sorted according to the rules set out in the various
1482 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1483 (int (*)(const void *, const void *)) fbconfig_compare
);
1491 ** Return the visual that best matches the template. Return None if no
1492 ** visual matches the template.
1494 PUBLIC XVisualInfo
*
1495 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1497 XVisualInfo
*visualList
= NULL
;
1498 __GLXdisplayPrivate
*priv
;
1499 __GLXscreenConfigs
*psc
;
1500 __GLcontextModes test_config
;
1501 __GLcontextModes
*modes
;
1502 const __GLcontextModes
*best_config
= NULL
;
1505 ** Get a list of all visuals, return if list is empty
1507 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1513 ** Build a template from the defaults and the attribute list
1514 ** Free visual list and return if an unexpected token is encountered
1516 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1517 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1518 (const INT32
*) attribList
,
1522 ** Eliminate visuals that don't meet minimum requirements
1523 ** Compute a score for those that do
1524 ** Remember which visual, if any, got the highest score
1525 ** If no visual is acceptable, return None
1526 ** Otherwise, create an XVisualInfo list with just the selected X visual
1529 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1530 if (fbconfigs_compatible(&test_config
, modes
)
1531 && ((best_config
== NULL
)
1534 ((const __GLcontextModes
* const *const) &modes
,
1535 &best_config
) < 0))) {
1536 XVisualInfo visualTemplate
;
1537 XVisualInfo
*newList
;
1540 visualTemplate
.screen
= screen
;
1541 visualTemplate
.visualid
= modes
->visualID
;
1542 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1543 &visualTemplate
, &i
);
1547 visualList
= newList
;
1548 best_config
= modes
;
1553 #ifdef GLX_USE_APPLEGL
1554 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1555 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1564 glXQueryExtensionsString(Display
* dpy
, int screen
)
1566 __GLXscreenConfigs
*psc
;
1567 __GLXdisplayPrivate
*priv
;
1569 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1573 if (!psc
->effectiveGLXexts
) {
1574 if (!psc
->serverGLXexts
) {
1575 psc
->serverGLXexts
=
1576 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1580 __glXCalculateUsableExtensions(psc
,
1581 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1582 (psc
->driScreen
!= NULL
),
1586 priv
->minorVersion
);
1589 return psc
->effectiveGLXexts
;
1593 glXGetClientString(Display
* dpy
, int name
)
1599 return (__glXGLXClientVendorName
);
1601 return (__glXGLXClientVersion
);
1602 case GLX_EXTENSIONS
:
1603 return (__glXGetClientExtensions());
1610 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1612 __GLXscreenConfigs
*psc
;
1613 __GLXdisplayPrivate
*priv
;
1617 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1623 str
= &priv
->serverGLXvendor
;
1626 str
= &priv
->serverGLXversion
;
1628 case GLX_EXTENSIONS
:
1629 str
= &psc
->serverGLXexts
;
1636 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1643 __glXClientInfo(Display
* dpy
, int opcode
)
1645 char *ext_str
= __glXGetClientGLExtensionString();
1646 int size
= strlen(ext_str
) + 1;
1649 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1650 xcb_glx_client_info(c
,
1651 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1653 xGLXClientInfoReq
*req
;
1655 /* Send the glXClientInfo request */
1657 GetReq(GLXClientInfo
, req
);
1658 req
->reqType
= opcode
;
1659 req
->glxCode
= X_GLXClientInfo
;
1660 req
->major
= GLX_MAJOR_VERSION
;
1661 req
->minor
= GLX_MINOR_VERSION
;
1663 req
->length
+= (size
+ 3) >> 2;
1664 req
->numbytes
= size
;
1665 Data(dpy
, ext_str
, size
);
1669 #endif /* USE_XCB */
1676 ** EXT_import_context
1680 glXGetCurrentDisplay(void)
1682 GLXContext gc
= __glXGetCurrentContext();
1685 return gc
->currentDpy
;
1689 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1690 glXGetCurrentDisplay
)
1692 #ifndef GLX_USE_APPLEGL
1694 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1697 * \param dpy Display where \c ctx was created.
1698 * \param ctx Context to query.
1699 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1700 * or zero if the request failed due to internal problems (i.e.,
1701 * unable to allocate temporary memory, etc.)
1704 * This function dynamically determines whether to use the EXT_import_context
1705 * version of the protocol or the GLX 1.3 version of the protocol.
1707 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1709 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1710 xGLXQueryContextReply reply
;
1716 return GLX_BAD_CONTEXT
;
1718 opcode
= __glXSetupForCommand(dpy
);
1723 /* Send the glXQueryContextInfoEXT request */
1726 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1727 xGLXQueryContextReq
*req
;
1729 GetReq(GLXQueryContext
, req
);
1731 req
->reqType
= opcode
;
1732 req
->glxCode
= X_GLXQueryContext
;
1733 req
->context
= (unsigned int) (ctx
->xid
);
1736 xGLXVendorPrivateReq
*vpreq
;
1737 xGLXQueryContextInfoEXTReq
*req
;
1739 GetReqExtra(GLXVendorPrivate
,
1740 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1742 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1743 req
->reqType
= opcode
;
1744 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1745 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1746 req
->context
= (unsigned int) (ctx
->xid
);
1749 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1751 numValues
= reply
.n
;
1754 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1757 int *propList
, *pProp
;
1760 nPropListBytes
= numValues
<< 3;
1761 propList
= (int *) Xmalloc(nPropListBytes
);
1762 if (NULL
== propList
) {
1768 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1770 /* Look up screen first so we can look up visuals/fbconfigs later */
1772 for (i
= 0; i
< numValues
; i
++, pProp
+= 2)
1773 if (pProp
[0] == GLX_SCREEN
) {
1774 ctx
->screen
= pProp
[1];
1775 ctx
->psc
= GetGLXScreenConfigs(dpy
, ctx
->screen
);
1779 for (i
= 0; i
< numValues
; i
++) {
1781 case GLX_SHARE_CONTEXT_EXT
:
1782 ctx
->share_xid
= *pProp
++;
1784 case GLX_VISUAL_ID_EXT
:
1786 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1788 case GLX_FBCONFIG_ID
:
1790 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1793 case GLX_RENDER_TYPE
:
1794 ctx
->renderType
= *pProp
++;
1802 Xfree((char *) propList
);
1814 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1816 #ifndef GLX_USE_APPLEGL
1819 /* get the information from the server if we don't have it already */
1820 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1821 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1823 if (ctx
->mode
== NULL
) {
1825 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1826 if (Success
!= retVal
)
1831 switch (attribute
) {
1832 #ifndef GLX_USE_APPLEGL
1833 case GLX_SHARE_CONTEXT_EXT
:
1834 *value
= (int) (ctx
->share_xid
);
1836 case GLX_VISUAL_ID_EXT
:
1837 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1841 *value
= (int) (ctx
->screen
);
1843 case GLX_FBCONFIG_ID
:
1844 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1846 case GLX_RENDER_TYPE
:
1847 *value
= (int) (ctx
->renderType
);
1850 return GLX_BAD_ATTRIBUTE
;
1856 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1857 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1858 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1860 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1866 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1868 #ifdef GLX_USE_APPLEGL
1873 if (contextID
== None
) {
1876 if (__glXIsDirect(dpy
, contextID
)) {
1880 ctx
= AllocateGLXContext(dpy
);
1882 ctx
->xid
= contextID
;
1883 ctx
->imported
= GL_TRUE
;
1885 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1886 __glXFreeContext(ctx
);
1895 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1897 DestroyContext(dpy
, ctx
);
1903 * GLX 1.3 functions - these are just stubs for now!
1906 PUBLIC GLXFBConfig
*
1907 glXChooseFBConfig(Display
* dpy
, int screen
,
1908 const int *attribList
, int *nitems
)
1910 __GLcontextModes
**config_list
;
1914 config_list
= (__GLcontextModes
**)
1915 glXGetFBConfigs(dpy
, screen
, &list_size
);
1917 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1918 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1919 if (list_size
== 0) {
1925 *nitems
= list_size
;
1926 return (GLXFBConfig
*) config_list
;
1931 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1932 int renderType
, GLXContext shareList
, Bool allowDirect
)
1934 const __GLcontextModes
*const fbconfig
=
1935 (const __GLcontextModes
*const) config
;
1937 return CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
1938 allowDirect
, X_GLXCreateNewContext
, renderType
,
1944 glXGetCurrentReadDrawable(void)
1946 GLXContext gc
= __glXGetCurrentContext();
1947 return gc
->currentReadable
;
1951 PUBLIC GLXFBConfig
*
1952 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1954 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1955 __GLcontextModes
**config
= NULL
;
1959 if (priv
&& (priv
->screenConfigs
!= NULL
)
1960 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1961 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1962 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
1963 != (int) GLX_DONT_CARE
)) {
1964 unsigned num_configs
= 0;
1965 __GLcontextModes
*modes
;
1968 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1969 modes
= modes
->next
) {
1970 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1975 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1977 if (config
!= NULL
) {
1978 *nelements
= num_configs
;
1980 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1981 modes
= modes
->next
) {
1982 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1989 return (GLXFBConfig
*) config
;
1994 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1995 int attribute
, int *value
)
1997 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1999 return (modes
!= NULL
)
2000 ? _gl_get_context_mode_data(modes
, attribute
, value
)
2005 PUBLIC XVisualInfo
*
2006 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
2008 XVisualInfo visualTemplate
;
2009 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
2013 ** Get a list of all visuals, return if list is empty
2015 visualTemplate
.visualid
= fbconfig
->visualID
;
2016 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
2019 #ifndef GLX_USE_APPLEGL
2021 ** GLX_SGI_swap_control
2024 __glXSwapIntervalSGI(int interval
)
2026 xGLXVendorPrivateReq
*req
;
2027 GLXContext gc
= __glXGetCurrentContext();
2028 __GLXscreenConfigs
*psc
;
2030 CARD32
*interval_ptr
;
2034 return GLX_BAD_CONTEXT
;
2037 if (interval
<= 0) {
2038 return GLX_BAD_VALUE
;
2041 #ifdef __DRI_SWAP_CONTROL
2042 if (gc
->driContext
) {
2043 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2045 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2046 gc
->currentDrawable
,
2048 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2049 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
2052 else if (pdraw
== NULL
) {
2053 return GLX_BAD_CONTEXT
;
2057 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2059 #ifdef GLX_DIRECT_RENDERING
2060 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2061 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2062 gc
->currentDrawable
,
2064 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2069 dpy
= gc
->currentDpy
;
2070 opcode
= __glXSetupForCommand(dpy
);
2075 /* Send the glXSwapIntervalSGI request */
2077 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
2078 req
->reqType
= opcode
;
2079 req
->glxCode
= X_GLXVendorPrivate
;
2080 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
2081 req
->contextTag
= gc
->currentContextTag
;
2083 interval_ptr
= (CARD32
*) (req
+ 1);
2084 *interval_ptr
= interval
;
2095 ** GLX_MESA_swap_control
2098 __glXSwapIntervalMESA(unsigned int interval
)
2100 GLXContext gc
= __glXGetCurrentContext();
2102 #ifdef __DRI_SWAP_CONTROL
2103 if (gc
!= NULL
&& gc
->driContext
) {
2104 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2107 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2108 __GLXDRIdrawable
*pdraw
=
2109 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2110 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2111 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
2118 #ifdef GLX_DIRECT_RENDERING
2119 if (gc
!= NULL
&& gc
->driContext
) {
2120 __GLXscreenConfigs
*psc
;
2122 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2123 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2124 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2125 gc
->currentDrawable
, NULL
);
2126 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2132 return GLX_BAD_CONTEXT
;
2137 __glXGetSwapIntervalMESA(void)
2139 #ifdef __DRI_SWAP_CONTROL
2140 GLXContext gc
= __glXGetCurrentContext();
2142 if (gc
!= NULL
&& gc
->driContext
) {
2143 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2146 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2147 __GLXDRIdrawable
*pdraw
=
2148 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2149 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2150 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2156 #ifdef GLX_DIRECT_RENDERING
2157 if (gc
!= NULL
&& gc
->driContext
) {
2158 __GLXscreenConfigs
*psc
;
2160 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2161 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2162 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2163 gc
->currentDrawable
, NULL
);
2164 return psc
->driScreen
->getSwapInterval(pdraw
);
2174 ** GLX_MESA_swap_frame_usage
2178 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2180 int status
= GLX_BAD_CONTEXT
;
2181 #ifdef __DRI_FRAME_TRACKING
2183 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2184 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2186 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2187 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2197 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2199 int status
= GLX_BAD_CONTEXT
;
2200 #ifdef __DRI_FRAME_TRACKING
2202 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2203 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2205 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2206 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2217 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2219 int status
= GLX_BAD_CONTEXT
;
2220 #ifdef __DRI_FRAME_TRACKING
2222 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2223 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2225 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2226 int64_t sbc
, missedFrames
;
2227 float lastMissedUsage
;
2229 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2245 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2246 int64_t * sbc
, int64_t * missedFrames
,
2247 GLfloat
* lastMissedUsage
)
2249 int status
= GLX_BAD_CONTEXT
;
2250 #ifdef __DRI_FRAME_TRACKING
2252 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2253 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2255 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2258 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2267 (void) missedFrames
;
2268 (void) lastMissedUsage
;
2275 ** GLX_SGI_video_sync
2278 __glXGetVideoSyncSGI(unsigned int *count
)
2280 int64_t ust
, msc
, sbc
;
2282 GLXContext gc
= __glXGetCurrentContext();
2283 __GLXscreenConfigs
*psc
;
2284 #ifdef GLX_DIRECT_RENDERING
2285 __GLXDRIdrawable
*pdraw
;
2289 return GLX_BAD_CONTEXT
;
2291 #ifdef GLX_DIRECT_RENDERING
2292 if (!gc
->driContext
)
2293 return GLX_BAD_CONTEXT
;
2296 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2297 #ifdef GLX_DIRECT_RENDERING
2298 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2301 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2302 * FIXME: there should be a GLX encoding for this call. I can find no
2303 * FIXME: documentation for the GLX encoding.
2305 #ifdef __DRI_MEDIA_STREAM_COUNTER
2306 if ( psc
->msc
&& psc
->driScreen
) {
2307 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2308 pdraw
->driDrawable
, &msc
);
2309 *count
= (unsigned) msc
;
2311 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2315 #ifdef GLX_DIRECT_RENDERING
2316 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2317 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2318 *count
= (unsigned) msc
;
2319 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2323 return GLX_BAD_CONTEXT
;
2327 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2329 GLXContext gc
= __glXGetCurrentContext();
2330 __GLXscreenConfigs
*psc
;
2331 #ifdef GLX_DIRECT_RENDERING
2332 __GLXDRIdrawable
*pdraw
;
2334 int64_t ust
, msc
, sbc
;
2337 if (divisor
<= 0 || remainder
< 0)
2338 return GLX_BAD_VALUE
;
2341 return GLX_BAD_CONTEXT
;
2343 #ifdef GLX_DIRECT_RENDERING
2344 if (!gc
->driContext
)
2345 return GLX_BAD_CONTEXT
;
2348 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2349 #ifdef GLX_DIRECT_RENDERING
2350 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2353 #ifdef __DRI_MEDIA_STREAM_COUNTER
2354 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2355 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2356 divisor
, remainder
, &msc
, &sbc
);
2357 *count
= (unsigned) msc
;
2358 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2362 #ifdef GLX_DIRECT_RENDERING
2363 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2364 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2366 *count
= (unsigned) msc
;
2367 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2371 return GLX_BAD_CONTEXT
;
2374 #endif /* GLX_USE_APPLEGL */
2377 ** GLX_SGIX_fbconfig
2378 ** Many of these functions are aliased to GLX 1.3 entry points in the
2379 ** GLX_functions table.
2383 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2384 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2385 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2387 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2388 (Display
* dpy
, int screen
, int *attrib_list
,
2389 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2392 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2393 (Display
* dpy
, GLXFBConfigSGIX config
),
2394 (dpy
, config
), glXGetVisualFromFBConfig
)
2397 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2398 GLXFBConfigSGIX config
,
2401 #ifndef GLX_USE_APPLEGL
2402 xGLXVendorPrivateWithReplyReq
*vpreq
;
2403 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2404 GLXPixmap xid
= None
;
2406 __GLXscreenConfigs
*psc
;
2408 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2411 if ((dpy
== NULL
) || (config
== NULL
)) {
2414 #ifdef GLX_USE_APPLEGL
2415 if(apple_glx_pixmap_create(dpy
, fbconfig
->screen
, pixmap
, fbconfig
))
2420 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2422 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2423 opcode
= __glXSetupForCommand(dpy
);
2428 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2430 GetReqExtra(GLXVendorPrivateWithReply
,
2431 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2432 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2433 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2434 req
->reqType
= opcode
;
2435 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2436 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2437 req
->screen
= fbconfig
->screen
;
2438 req
->fbconfig
= fbconfig
->fbconfigID
;
2439 req
->pixmap
= pixmap
;
2440 req
->glxpixmap
= xid
= XAllocID(dpy
);
2450 glXCreateContextWithConfigSGIX(Display
* dpy
,
2451 GLXFBConfigSGIX config
, int renderType
,
2452 GLXContext shareList
, Bool allowDirect
)
2454 GLXContext gc
= NULL
;
2455 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2456 __GLXscreenConfigs
*psc
;
2459 if ((dpy
== NULL
) || (config
== NULL
)) {
2463 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2465 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2466 gc
= CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
2468 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2476 PUBLIC GLXFBConfigSGIX
2477 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2479 __GLXdisplayPrivate
*priv
;
2480 __GLXscreenConfigs
*psc
= NULL
;
2482 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2483 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2484 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2485 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2492 #ifndef GLX_USE_APPLEGL
2494 ** GLX_SGIX_swap_group
2497 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2507 ** GLX_SGIX_swap_barrier
2510 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2518 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2528 ** GLX_OML_sync_control
2531 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2532 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2534 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2536 #ifdef GLX_DIRECT_RENDERING
2537 __GLXDRIdrawable
*pdraw
;
2539 __GLXscreenConfigs
*psc
;
2544 #ifdef GLX_DIRECT_RENDERING
2545 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2547 psc
= &priv
->screenConfigs
[i
];
2549 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2550 if (pdraw
&& psc
->sbc
&& psc
->msc
)
2551 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2552 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2553 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2554 && (__glXGetUST(ust
) == 0) );
2557 #ifdef GLX_DIRECT_RENDERING
2558 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2559 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2567 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2569 __driGetMscRateOML(__DRIdrawable
* draw
,
2570 int32_t * numerator
, int32_t * denominator
, void *private)
2573 __GLXscreenConfigs
*psc
;
2574 XF86VidModeModeLine mode_line
;
2577 __GLXDRIdrawable
*glxDraw
= private;
2582 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2583 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2584 unsigned n
= dot_clock
* 1000;
2585 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2587 # define V_INTERLACE 0x010
2588 # define V_DBLSCAN 0x020
2590 if (mode_line
.flags
& V_INTERLACE
)
2592 else if (mode_line
.flags
& V_DBLSCAN
)
2595 /* The OML_sync_control spec requires that if the refresh rate is a
2596 * whole number, that the returned numerator be equal to the refresh
2597 * rate and the denominator be 1.
2605 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2607 /* This is a poor man's way to reduce a fraction. It's far from
2608 * perfect, but it will work well enough for this situation.
2611 for (i
= 0; f
[i
] != 0; i
++) {
2612 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2638 * Determine the refresh rate of the specified drawable and display.
2640 * \param dpy Display whose refresh rate is to be determined.
2641 * \param drawable Drawable whose refresh rate is to be determined.
2642 * \param numerator Numerator of the refresh rate.
2643 * \param demoninator Denominator of the refresh rate.
2644 * \return If the refresh rate for the specified display and drawable could
2645 * be calculated, True is returned. Otherwise False is returned.
2647 * \note This function is implemented entirely client-side. A lot of other
2648 * functionality is required to export GLX_OML_sync_control, so on
2649 * XFree86 this function can be called for direct-rendering contexts
2650 * when GLX_OML_sync_control appears in the client extension string.
2654 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2655 int32_t * numerator
, int32_t * denominator
)
2657 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2658 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2663 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2675 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2676 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2678 GLXContext gc
= __glXGetCurrentContext();
2680 #ifdef GLX_DIRECT_RENDERING
2681 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2683 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2685 if (!gc
) /* no GLX for this */
2688 #ifdef GLX_DIRECT_RENDERING
2689 if (!pdraw
|| !gc
->driContext
)
2693 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2694 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2695 * of -1 if the function failed because of errors detected in the input
2698 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2700 if (divisor
> 0 && remainder
>= divisor
)
2703 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2706 #ifdef __DRI_SWAP_BUFFER_COUNTER
2707 if (psc
->counters
!= NULL
)
2708 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2709 divisor
, remainder
);
2712 #ifdef GLX_DIRECT_RENDERING
2713 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2714 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2723 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2724 int64_t target_msc
, int64_t divisor
,
2725 int64_t remainder
, int64_t * ust
,
2726 int64_t * msc
, int64_t * sbc
)
2729 #ifdef GLX_DIRECT_RENDERING
2730 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2732 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2736 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2737 * error", but the return type in the spec is Bool.
2739 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2741 if (divisor
> 0 && remainder
>= divisor
)
2744 #ifdef __DRI_MEDIA_STREAM_COUNTER
2745 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2746 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2747 divisor
, remainder
, msc
, sbc
);
2749 /* __glXGetUST returns zero on success and non-zero on failure.
2750 * This function returns True on success and False on failure.
2752 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2756 #ifdef GLX_DIRECT_RENDERING
2757 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2758 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2769 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2770 int64_t target_sbc
, int64_t * ust
,
2771 int64_t * msc
, int64_t * sbc
)
2774 #ifdef GLX_DIRECT_RENDERING
2775 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2777 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2780 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2781 * error", but the return type in the spec is Bool.
2785 #ifdef __DRI_SWAP_BUFFER_COUNTER
2786 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2788 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2790 /* __glXGetUST returns zero on success and non-zero on failure.
2791 * This function returns True on success and False on failure.
2793 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2797 #ifdef GLX_DIRECT_RENDERING
2798 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2799 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2809 * GLX_MESA_allocate_memory
2814 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2815 size_t size
, float readFreq
,
2816 float writeFreq
, float priority
)
2818 #ifdef __DRI_ALLOCATE
2819 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2821 if (psc
&& psc
->allocate
)
2822 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2823 readFreq
, writeFreq
, priority
);
2832 #endif /* __DRI_ALLOCATE */
2839 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2841 #ifdef __DRI_ALLOCATE
2842 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2844 if (psc
&& psc
->allocate
)
2845 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2851 #endif /* __DRI_ALLOCATE */
2856 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2858 #ifdef __DRI_ALLOCATE
2859 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2861 if (psc
&& psc
->allocate
)
2862 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2868 #endif /* GLX_DIRECT_RENDERING */
2877 * Mesa extension stubs. These will help reduce portability problems.
2882 * Release all buffers associated with the specified GLX drawable.
2885 * This function was intended for stand-alone Mesa. The issue there is that
2886 * the library doesn't get any notification when a window is closed. In
2887 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2888 * supported, there are 3 different functions to destroy a drawable. It
2889 * should be possible to create GLX protocol (or have it determine which
2890 * protocol to use based on the type of the drawable) to have one function
2891 * do the work of 3. For the direct-rendering case, this function could
2892 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2893 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2894 * would need to be used. This really should be done as part of the new DRI
2897 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2898 * __driGarbageCollectDrawables
2899 * glXDestroyGLXPixmap
2900 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2901 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2904 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2913 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2914 Pixmap pixmap
, Colormap cmap
)
2927 * GLX_MESA_copy_sub_buffer
2929 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2931 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2932 int x
, int y
, int width
, int height
)
2934 xGLXVendorPrivateReq
*req
;
2937 CARD32
*drawable_ptr
;
2938 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2941 #ifdef __DRI_COPY_SUB_BUFFER
2943 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2944 if (pdraw
!= NULL
) {
2945 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2946 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2948 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2955 opcode
= __glXSetupForCommand(dpy
);
2960 ** The calling thread may or may not have a current context. If it
2961 ** does, send the context tag so the server can do a flush.
2963 gc
= __glXGetCurrentContext();
2964 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2965 ((drawable
== gc
->currentDrawable
) ||
2966 (drawable
== gc
->currentReadable
))) {
2967 tag
= gc
->currentContextTag
;
2974 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2975 req
->reqType
= opcode
;
2976 req
->glxCode
= X_GLXVendorPrivate
;
2977 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2978 req
->contextTag
= tag
;
2980 drawable_ptr
= (CARD32
*) (req
+ 1);
2981 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2982 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2983 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2984 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2986 *drawable_ptr
= drawable
;
2998 * GLX_EXT_texture_from_pixmap
3002 __glXBindTexImageEXT(Display
* dpy
,
3003 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
3005 xGLXVendorPrivateReq
*req
;
3006 GLXContext gc
= __glXGetCurrentContext();
3007 CARD32
*drawable_ptr
;
3009 CARD32
*num_attrib_ptr
;
3019 while (attrib_list
[i
* 2] != None
)
3023 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3024 if (gc
->driContext
) {
3025 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
3027 if (pdraw
!= NULL
) {
3028 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
3029 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
3030 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
3031 pdraw
->textureTarget
,
3032 pdraw
->textureFormat
,
3033 pdraw
->driDrawable
);
3036 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
3037 pdraw
->textureTarget
,
3038 pdraw
->driDrawable
);
3045 opcode
= __glXSetupForCommand(dpy
);
3050 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
3051 req
->reqType
= opcode
;
3052 req
->glxCode
= X_GLXVendorPrivate
;
3053 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
3054 req
->contextTag
= gc
->currentContextTag
;
3056 drawable_ptr
= (CARD32
*) (req
+ 1);
3057 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
3058 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
3059 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
3061 *drawable_ptr
= drawable
;
3062 *buffer_ptr
= buffer
;
3063 *num_attrib_ptr
= (CARD32
) i
;
3067 while (attrib_list
[i
* 2] != None
) {
3068 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
3069 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
3079 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
3081 xGLXVendorPrivateReq
*req
;
3082 GLXContext gc
= __glXGetCurrentContext();
3083 CARD32
*drawable_ptr
;
3087 if ((gc
== NULL
) || GC_IS_DIRECT(gc
))
3090 opcode
= __glXSetupForCommand(dpy
);
3095 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
3096 req
->reqType
= opcode
;
3097 req
->glxCode
= X_GLXVendorPrivate
;
3098 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
3099 req
->contextTag
= gc
->currentContextTag
;
3101 drawable_ptr
= (CARD32
*) (req
+ 1);
3102 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
3104 *drawable_ptr
= drawable
;
3105 *buffer_ptr
= buffer
;
3113 #endif /* GLX_USE_APPLEGL */
3116 * \c strdup is actually not a standard ANSI C or POSIX routine.
3117 * Irix will not define it if ANSI mode is in effect.
3122 __glXstrdup(const char *str
)
3125 copy
= (char *) Xmalloc(strlen(str
) + 1);
3133 ** glXGetProcAddress support
3136 struct name_address_pair
3142 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
3143 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
3145 static const struct name_address_pair GLX_functions
[] = {
3146 /*** GLX_VERSION_1_0 ***/
3147 GLX_FUNCTION(glXChooseVisual
),
3148 GLX_FUNCTION(glXCopyContext
),
3149 GLX_FUNCTION(glXCreateContext
),
3150 GLX_FUNCTION(glXCreateGLXPixmap
),
3151 GLX_FUNCTION(glXDestroyContext
),
3152 GLX_FUNCTION(glXDestroyGLXPixmap
),
3153 GLX_FUNCTION(glXGetConfig
),
3154 GLX_FUNCTION(glXGetCurrentContext
),
3155 GLX_FUNCTION(glXGetCurrentDrawable
),
3156 GLX_FUNCTION(glXIsDirect
),
3157 GLX_FUNCTION(glXMakeCurrent
),
3158 GLX_FUNCTION(glXQueryExtension
),
3159 GLX_FUNCTION(glXQueryVersion
),
3160 GLX_FUNCTION(glXSwapBuffers
),
3161 GLX_FUNCTION(glXUseXFont
),
3162 GLX_FUNCTION(glXWaitGL
),
3163 GLX_FUNCTION(glXWaitX
),
3165 /*** GLX_VERSION_1_1 ***/
3166 GLX_FUNCTION(glXGetClientString
),
3167 GLX_FUNCTION(glXQueryExtensionsString
),
3168 GLX_FUNCTION(glXQueryServerString
),
3170 /*** GLX_VERSION_1_2 ***/
3171 GLX_FUNCTION(glXGetCurrentDisplay
),
3173 /*** GLX_VERSION_1_3 ***/
3174 GLX_FUNCTION(glXChooseFBConfig
),
3175 GLX_FUNCTION(glXCreateNewContext
),
3176 GLX_FUNCTION(glXCreatePbuffer
),
3177 GLX_FUNCTION(glXCreatePixmap
),
3178 GLX_FUNCTION(glXCreateWindow
),
3179 GLX_FUNCTION(glXDestroyPbuffer
),
3180 GLX_FUNCTION(glXDestroyPixmap
),
3181 GLX_FUNCTION(glXDestroyWindow
),
3182 GLX_FUNCTION(glXGetCurrentReadDrawable
),
3183 GLX_FUNCTION(glXGetFBConfigAttrib
),
3184 GLX_FUNCTION(glXGetFBConfigs
),
3185 GLX_FUNCTION(glXGetSelectedEvent
),
3186 GLX_FUNCTION(glXGetVisualFromFBConfig
),
3187 GLX_FUNCTION(glXMakeContextCurrent
),
3188 GLX_FUNCTION(glXQueryContext
),
3189 GLX_FUNCTION(glXQueryDrawable
),
3190 GLX_FUNCTION(glXSelectEvent
),
3192 #ifndef GLX_USE_APPLEGL
3193 /*** GLX_SGI_swap_control ***/
3194 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
3196 /*** GLX_SGI_video_sync ***/
3197 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
3198 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
3200 /*** GLX_SGI_make_current_read ***/
3201 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
3202 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
3204 /*** GLX_EXT_import_context ***/
3205 GLX_FUNCTION(glXFreeContextEXT
),
3206 GLX_FUNCTION(glXGetContextIDEXT
),
3207 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
3208 GLX_FUNCTION(glXImportContextEXT
),
3209 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3212 /*** GLX_SGIX_fbconfig ***/
3213 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3214 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3215 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3216 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3217 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3218 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3220 #ifndef GLX_USE_APPLEGL
3221 /*** GLX_SGIX_pbuffer ***/
3222 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3223 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3224 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3225 GLX_FUNCTION(glXSelectEventSGIX
),
3226 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3228 /*** GLX_SGIX_swap_group ***/
3229 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3231 /*** GLX_SGIX_swap_barrier ***/
3232 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3233 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3235 /*** GLX_MESA_allocate_memory ***/
3236 GLX_FUNCTION(glXAllocateMemoryMESA
),
3237 GLX_FUNCTION(glXFreeMemoryMESA
),
3238 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3240 /*** GLX_MESA_copy_sub_buffer ***/
3241 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3243 /*** GLX_MESA_pixmap_colormap ***/
3244 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3246 /*** GLX_MESA_release_buffers ***/
3247 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3249 /*** GLX_MESA_swap_control ***/
3250 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3251 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3253 /*** GLX_MESA_swap_frame_usage ***/
3254 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3255 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3256 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3257 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3260 /*** GLX_ARB_get_proc_address ***/
3261 GLX_FUNCTION(glXGetProcAddressARB
),
3264 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3266 #ifndef GLX_USE_APPLEGL
3267 /*** GLX_OML_sync_control ***/
3268 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3269 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3270 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3271 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3272 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3274 /*** GLX_EXT_texture_from_pixmap ***/
3275 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3276 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3279 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3280 /*** DRI configuration ***/
3281 GLX_FUNCTION(glXGetScreenDriver
),
3282 GLX_FUNCTION(glXGetDriverConfig
),
3285 {NULL
, NULL
} /* end of list */
3288 #ifndef GLX_USE_APPLEGL
3289 static const GLvoid
*
3290 get_glx_proc_address(const char *funcName
)
3294 /* try static functions */
3295 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3296 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3297 return GLX_functions
[i
].Address
;
3305 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3306 * \c glXGetProcAddress.
3308 * \param procName Name of a GL or GLX function.
3309 * \returns A pointer to the named function
3311 * \sa glXGetProcAddress
3313 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3315 typedef void (*gl_function
) (void);
3319 /* Search the table of GLX and internal functions first. If that
3320 * fails and the supplied name could be a valid core GL name, try
3321 * searching the core GL function table. This check is done to prevent
3322 * DRI based drivers from searching the core GL function table for
3323 * internal API functions.
3325 #ifdef GLX_USE_APPLEGL
3326 f
= (gl_function
) apple_glx_get_proc_address(procName
);
3328 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3329 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3330 && (procName
[2] != 'X')) {
3331 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3338 * Get the address of a named GL function. This is the GLX 1.4 name for
3339 * \c glXGetProcAddressARB.
3341 * \param procName Name of a GL or GLX function.
3342 * \returns A pointer to the named function
3344 * \sa glXGetProcAddressARB
3346 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3347 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3348 __attribute__ ((alias("glXGetProcAddressARB")));
3351 return glXGetProcAddressARB(procName
);
3353 #endif /* __GNUC__ */
3356 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3358 * Get the unadjusted system time (UST). Currently, the UST is measured in
3359 * microseconds since Epoc. The actual resolution of the UST may vary from
3360 * system to system, and the units may vary from release to release.
3361 * Drivers should not call this function directly. They should instead use
3362 * \c glXGetProcAddress to obtain a pointer to the function.
3364 * \param ust Location to store the 64-bit UST
3365 * \returns Zero on success or a negative errno value on failure.
3367 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3369 * \since Internal API version 20030317.
3372 __glXGetUST(int64_t * ust
)
3380 if (gettimeofday(&tv
, NULL
) == 0) {
3381 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3388 #endif /* GLX_DIRECT_RENDERING */