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";
65 static const struct glx_context_vtable glx_indirect_context_vtable
;
67 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
69 static Bool windowExistsFlag
;
71 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
75 if (xerr
->error_code
== BadWindow
) {
76 windowExistsFlag
= GL_FALSE
;
82 * Find drawables in the local hash that have been destroyed on the
85 * \param dpy Display to destroy drawables for
86 * \param screen Screen number to destroy drawables for
89 GarbageCollectDRIDrawables(__GLXscreenConfigs
* sc
)
92 __GLXDRIdrawable
*pdraw
;
93 __GLXdisplayPrivate
*priv
= sc
->display
;
94 XWindowAttributes xwa
;
95 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
97 /* Set no-op error handler so Xlib doesn't bail out if the windows
98 * has alreay been destroyed on the server. */
99 XSync(priv
->dpy
, GL_FALSE
);
100 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
102 if (__glxHashFirst(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
104 windowExistsFlag
= GL_TRUE
;
105 XGetWindowAttributes(priv
->dpy
, draw
, &xwa
); /* dummy request */
106 if (!windowExistsFlag
) {
107 /* Destroy the local drawable data, if the drawable no
108 longer exists in the Xserver */
109 (*pdraw
->destroyDrawable
) (pdraw
);
110 __glxHashDelete(priv
->drawHash
, draw
);
112 } while (__glxHashNext(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1);
115 XSync(priv
->dpy
, GL_FALSE
);
116 XSetErrorHandler(oldXErrorHandler
);
120 * Get the __DRIdrawable for the drawable associated with a GLXContext
122 * \param dpy The display associated with \c drawable.
123 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
124 * \param scrn_num If non-NULL, the drawables screen is stored there
125 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
126 * the drawable is not associated with a direct-rendering context.
128 _X_HIDDEN __GLXDRIdrawable
*
129 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
131 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
132 __GLXDRIdrawable
*pdraw
;
137 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
138 if (scrn_num
!= NULL
)
139 *scrn_num
= pdraw
->psc
->scr
;
150 * Get the GLX per-screen data structure associated with a GLX context.
152 * \param dpy Display for which the GLX per-screen information is to be
154 * \param scrn Screen on \c dpy for which the GLX per-screen information is
156 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
157 * specify a valid GLX screen, or NULL otherwise.
159 * \todo Should this function validate that \c scrn is within the screen
160 * number range for \c dpy?
163 static __GLXscreenConfigs
*
164 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
166 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
169 && priv
->screenConfigs
!=
170 NULL
) ? priv
->screenConfigs
[scrn
] : NULL
;
175 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
176 __GLXscreenConfigs
** ppsc
)
178 /* Initialize the extension, if needed . This has the added value
179 * of initializing/allocating the display private
183 return GLX_NO_EXTENSION
;
186 *ppriv
= __glXInitialize(dpy
);
187 if (*ppriv
== NULL
) {
188 return GLX_NO_EXTENSION
;
191 /* Check screen number to see if its valid */
192 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
193 return GLX_BAD_SCREEN
;
196 /* Check to see if the GL is supported on this screen */
197 *ppsc
= (*ppriv
)->screenConfigs
[scrn
];
198 if ((*ppsc
)->configs
== NULL
) {
199 /* No support for GL on this screen regardless of visual */
200 return GLX_BAD_VISUAL
;
208 * Determine if a \c GLXFBConfig supplied by the application is valid.
210 * \param dpy Application supplied \c Display pointer.
211 * \param config Application supplied \c GLXFBConfig.
213 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
214 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
217 static __GLcontextModes
*
218 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
220 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
221 const unsigned num_screens
= ScreenCount(dpy
);
223 const __GLcontextModes
*modes
;
227 for (i
= 0; i
< num_screens
; i
++) {
228 for (modes
= priv
->screenConfigs
[i
]->configs
; modes
!= NULL
;
229 modes
= modes
->next
) {
230 if (modes
== (__GLcontextModes
*) config
) {
231 return (__GLcontextModes
*) config
;
242 * \todo It should be possible to move the allocate of \c client_state_private
243 * later in the function for direct-rendering contexts. Direct-rendering
244 * contexts don't need to track client state, so they don't need that memory
247 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
248 * function called \c __glXAllocateClientState that allocates the memory and
249 * does all the initialization (including the pixel pack / unpack).
252 AllocateGLXContext(Display
* dpy
)
257 __GLXattribute
*state
;
262 opcode
= __glXSetupForCommand(dpy
);
267 /* Allocate our context record */
268 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
273 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
275 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
281 gc
->client_state_private
= state
;
282 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
283 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
286 ** Create a temporary buffer to hold GLX rendering commands. The size
287 ** of the buffer is selected so that the maximum number of GLX rendering
288 ** commands can fit in a single X packet and still have room in the X
289 ** packet for the GLXRenderReq header.
292 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
293 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
295 Xfree(gc
->client_state_private
);
299 gc
->bufSize
= bufSize
;
301 /* Fill in the new context */
302 gc
->renderMode
= GL_RENDER
;
304 state
->storePack
.alignment
= 4;
305 state
->storeUnpack
.alignment
= 4;
307 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
310 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
311 ** Other code uses the fastImageUnpack bit, but it is never set
314 gc
->fastImageUnpack
= GL_FALSE
;
315 gc
->fillImage
= __glFillImage
;
317 gc
->bufEnd
= gc
->buf
+ bufSize
;
318 gc
->isDirect
= GL_FALSE
;
321 ** Set limit register so that there will be one command per packet
326 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
329 gc
->majorOpcode
= opcode
;
332 ** Constrain the maximum drawing command size allowed to be
333 ** transfered using the X_GLXRender protocol request. First
334 ** constrain by a software limit, then constrain by the protocl
337 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
338 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
340 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
341 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
343 gc
->maxSmallRenderCommandSize
= bufSize
;
345 #ifdef GLX_USE_APPLEGL
346 gc
->driContext
= NULL
;
347 gc
->do_destroy
= False
;
355 * Create a new context. Exactly one of \c vis and \c fbconfig should be
358 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
359 * SGIX_fbconfig protocol be used?
360 * \param renderType For FBConfigs, what is the rendering type?
364 CreateContext(Display
* dpy
, int generic_id
,
365 const __GLcontextModes
* const fbconfig
,
366 GLXContext shareList
,
368 unsigned code
, int renderType
, int screen
)
371 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
372 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL)
380 if (generic_id
== None
)
383 gc
= AllocateGLXContext(dpy
);
387 #ifndef GLX_USE_APPLEGL /* TODO: darwin indirect */
388 #ifdef GLX_DIRECT_RENDERING
389 if (allowDirect
&& psc
->driScreen
) {
390 gc
->driContext
= psc
->driScreen
->createContext(psc
, fbconfig
, gc
,
391 shareList
, renderType
);
392 if (gc
->driContext
!= NULL
) {
396 gc
->isDirect
= GL_TRUE
;
401 if (gc
->driContext
!= NULL
)
402 gc
->vtable
= psc
->direct_context_vtable
;
404 gc
->vtable
= &glx_indirect_context_vtable
;
408 case X_GLXCreateContext
: {
409 xGLXCreateContextReq
*req
;
411 /* Send the glXCreateContext request */
412 GetReq(GLXCreateContext
, req
);
413 req
->reqType
= gc
->majorOpcode
;
414 req
->glxCode
= X_GLXCreateContext
;
415 req
->context
= gc
->xid
= XAllocID(dpy
);
416 req
->visual
= generic_id
;
417 req
->screen
= screen
;
418 req
->shareList
= shareList
? shareList
->xid
: None
;
419 req
->isDirect
= GC_IS_DIRECT(gc
);
423 case X_GLXCreateNewContext
: {
424 xGLXCreateNewContextReq
*req
;
426 /* Send the glXCreateNewContext request */
427 GetReq(GLXCreateNewContext
, req
);
428 req
->reqType
= gc
->majorOpcode
;
429 req
->glxCode
= X_GLXCreateNewContext
;
430 req
->context
= gc
->xid
= XAllocID(dpy
);
431 req
->fbconfig
= generic_id
;
432 req
->screen
= screen
;
433 req
->renderType
= renderType
;
434 req
->shareList
= shareList
? shareList
->xid
: None
;
435 req
->isDirect
= GC_IS_DIRECT(gc
);
439 case X_GLXvop_CreateContextWithConfigSGIX
: {
440 xGLXVendorPrivateWithReplyReq
*vpreq
;
441 xGLXCreateContextWithConfigSGIXReq
*req
;
443 /* Send the glXCreateNewContext request */
444 GetReqExtra(GLXVendorPrivateWithReply
,
445 sz_xGLXCreateContextWithConfigSGIXReq
-
446 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
447 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
448 req
->reqType
= gc
->majorOpcode
;
449 req
->glxCode
= X_GLXVendorPrivateWithReply
;
450 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
451 req
->context
= gc
->xid
= XAllocID(dpy
);
452 req
->fbconfig
= generic_id
;
453 req
->screen
= screen
;
454 req
->renderType
= renderType
;
455 req
->shareList
= shareList
? shareList
->xid
: None
;
456 req
->isDirect
= GC_IS_DIRECT(gc
);
461 /* What to do here? This case is the sign of an internal error. It
462 * should never be reachable.
471 gc
->imported
= GL_FALSE
;
472 gc
->renderType
= renderType
;
474 /* TODO: darwin: Integrate with above to do indirect */
475 #ifdef GLX_USE_APPLEGL
476 if(apple_glx_create_context(&gc
->driContext
, dpy
, screen
, fbconfig
,
477 shareList
? shareList
->driContext
: NULL
,
478 &errorcode
, &x11error
)) {
479 __glXSendError(dpy
, errorcode
, 0, X_GLXCreateContext
, x11error
);
480 __glXFreeContext(gc
);
484 gc
->currentContextTag
= -1;
486 gc
->isDirect
= allowDirect
;
493 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
494 GLXContext shareList
, Bool allowDirect
)
496 const __GLcontextModes
*mode
= NULL
;
499 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
500 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
502 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
506 error
.errorCode
= BadValue
;
507 error
.resourceID
= vis
->visualid
;
508 error
.sequenceNumber
= dpy
->request
;
509 error
.type
= X_Error
;
510 error
.majorCode
= __glXSetupForCommand(dpy
);
511 error
.minorCode
= X_GLXCreateContext
;
512 _XError(dpy
, &error
);
516 renderType
= mode
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
519 return CreateContext(dpy
, vis
->visualid
, mode
, shareList
, allowDirect
,
520 X_GLXCreateContext
, renderType
, vis
->screen
);
524 __glXFreeContext(__GLXcontext
* gc
)
527 XFree((char *) gc
->vendor
);
529 XFree((char *) gc
->renderer
);
531 XFree((char *) gc
->version
);
533 XFree((char *) gc
->extensions
);
534 __glFreeAttributeState(gc
);
535 XFree((char *) gc
->buf
);
536 Xfree((char *) gc
->client_state_private
);
542 ** Destroy the named context
545 DestroyContext(Display
* dpy
, GLXContext gc
)
547 #ifndef GLX_USE_APPLEGL /* TODO: darwin: indirect */
548 xGLXDestroyContextReq
*req
;
553 opcode
= __glXSetupForCommand(dpy
);
554 if (!opcode
|| !gc
) {
560 imported
= gc
->imported
;
563 if (gc
->currentDpy
) {
564 /* This context is bound to some thread. According to the man page,
565 * we should not actually delete the context until it's unbound.
566 * Note that we set gc->xid = None above. In MakeContextCurrent()
567 * we check for that and delete the context there.
573 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
574 /* Destroy the direct rendering context */
575 if (gc
->driContext
) {
576 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
577 gc
->driContext
= NULL
;
578 GarbageCollectDRIDrawables(gc
->psc
);
582 __glXFreeVertexArrayState(gc
);
585 #endif /* GLX_USE_APPLEGL */
587 if (gc
->currentDpy
) {
588 #ifdef GLX_USE_APPLEGL
590 * Set the Bool that indicates that we should destroy this GLX context
591 * when the context is no longer current.
593 gc
->do_destroy
= True
;
595 /* Have to free later cuz it's in use now */
599 /* Destroy the handle if not current to anybody */
601 #ifdef GLX_USE_APPLEGL
603 apple_glx_destroy_context(&gc
->driContext
, dpy
);
605 __glXFreeContext(gc
);
607 #ifndef GLX_USE_APPLEGL
610 ** This dpy also created the server side part of the context.
611 ** Send the glXDestroyContext request.
614 GetReq(GLXDestroyContext
, req
);
615 req
->reqType
= opcode
;
616 req
->glxCode
= X_GLXDestroyContext
;
625 glXDestroyContext(Display
* dpy
, GLXContext gc
)
627 DestroyContext(dpy
, gc
);
631 ** Return the major and minor version #s for the GLX extension
634 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
636 __GLXdisplayPrivate
*priv
;
638 /* Init the extension. This fetches the major and minor version. */
639 priv
= __glXInitialize(dpy
);
644 *major
= priv
->majorVersion
;
646 *minor
= priv
->minorVersion
;
651 ** Query the existance of the GLX extension
654 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
656 int major_op
, erb
, evb
;
659 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
670 ** Put a barrier in the token stream that forces the GL to finish its
671 ** work before X can proceed.
676 #ifndef GLX_USE_APPLEGL
679 GLXContext gc
= __glXGetCurrentContext();
680 Display
*dpy
= gc
->currentDpy
;
685 /* Flush any pending commands out */
686 __glXFlushRenderBuffer(gc
, gc
->pc
);
687 #ifdef GLX_USE_APPLEGL
690 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
691 if (gc
->driContext
) {
693 __GLXDRIdrawable
*pdraw
=
694 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
697 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
699 if (psc
->driScreen
->waitGL
!= NULL
)
700 (*psc
->driScreen
->waitGL
) (pdraw
);
706 /* Send the glXWaitGL request */
708 GetReq(GLXWaitGL
, req
);
709 req
->reqType
= gc
->majorOpcode
;
710 req
->glxCode
= X_GLXWaitGL
;
711 req
->contextTag
= gc
->currentContextTag
;
714 #endif /* GLX_USE_APPLEGL */
718 ** Put a barrier in the token stream that forces X to finish its
719 ** work before GL can proceed.
724 #ifndef GLX_USE_APPLEGL
727 GLXContext gc
= __glXGetCurrentContext();
728 Display
*dpy
= gc
->currentDpy
;
733 /* Flush any pending commands out */
734 __glXFlushRenderBuffer(gc
, gc
->pc
);
736 #ifdef GLX_USE_APPLEGL
737 apple_glx_waitx(dpy
, gc
->driContext
);
739 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
740 if (gc
->driContext
) {
742 __GLXDRIdrawable
*pdraw
=
743 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
746 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
747 if (psc
->driScreen
->waitX
!= NULL
)
748 (*psc
->driScreen
->waitX
) (pdraw
);
757 ** Send the glXWaitX request.
760 GetReq(GLXWaitX
, req
);
761 req
->reqType
= gc
->majorOpcode
;
762 req
->glxCode
= X_GLXWaitX
;
763 req
->contextTag
= gc
->currentContextTag
;
766 #endif /* GLX_USE_APPLEGL */
770 glXUseXFont(Font font
, int first
, int count
, int listBase
)
772 #ifndef GLX_USE_APPLEGL
773 xGLXUseXFontReq
*req
;
775 GLXContext gc
= __glXGetCurrentContext();
776 Display
*dpy
= gc
->currentDpy
;
781 /* Flush any pending commands out */
782 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
783 #ifdef GLX_USE_APPLEGL
784 DRI_glXUseXFont(font
, first
, count
, listBase
);
786 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
787 if (gc
->driContext
) {
788 DRI_glXUseXFont(font
, first
, count
, listBase
);
793 /* Send the glXUseFont request */
795 GetReq(GLXUseXFont
, req
);
796 req
->reqType
= gc
->majorOpcode
;
797 req
->glxCode
= X_GLXUseXFont
;
798 req
->contextTag
= gc
->currentContextTag
;
802 req
->listBase
= listBase
;
805 #endif /* GLX_USE_APPLEGL */
808 /************************************************************************/
811 ** Copy the source context to the destination context using the
815 glXCopyContext(Display
* dpy
, GLXContext source
,
816 GLXContext dest
, unsigned long mask
)
818 #ifdef GLX_USE_APPLEGL
819 GLXContext gc
= __glXGetCurrentContext();
823 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
824 mask
, &errorcode
, &x11error
)) {
825 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
829 xGLXCopyContextReq
*req
;
830 GLXContext gc
= __glXGetCurrentContext();
834 opcode
= __glXSetupForCommand(dpy
);
839 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
840 if (gc
->driContext
) {
841 /* NOT_DONE: This does not work yet */
846 ** If the source is the current context, send its tag so that the context
847 ** can be flushed before the copy.
849 if (source
== gc
&& dpy
== gc
->currentDpy
) {
850 tag
= gc
->currentContextTag
;
856 /* Send the glXCopyContext request */
858 GetReq(GLXCopyContext
, req
);
859 req
->reqType
= opcode
;
860 req
->glxCode
= X_GLXCopyContext
;
861 req
->source
= source
? source
->xid
: None
;
862 req
->dest
= dest
? dest
->xid
: None
;
864 req
->contextTag
= tag
;
867 #endif /* GLX_USE_APPLEGL */
872 * Determine if a context uses direct rendering.
874 * \param dpy Display where the context was created.
875 * \param contextID ID of the context to be tested.
877 * \returns \c GL_TRUE if the context is direct rendering or not.
880 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
882 #if !defined(USE_XCB)
883 xGLXIsDirectReq
*req
;
884 xGLXIsDirectReply reply
;
888 opcode
= __glXSetupForCommand(dpy
);
894 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
895 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
900 const Bool is_direct
= reply
->is_direct
? True
: False
;
905 /* Send the glXIsDirect request */
907 GetReq(GLXIsDirect
, req
);
908 req
->reqType
= opcode
;
909 req
->glxCode
= X_GLXIsDirect
;
910 req
->context
= contextID
;
911 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
915 return reply
.isDirect
;
921 * Shouldn't this function \b always return \c GL_FALSE when
922 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
923 * the GLX protocol here at all?
926 glXIsDirect(Display
* dpy
, GLXContext gc
)
931 else if (GC_IS_DIRECT(gc
)) {
934 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
937 return __glXIsDirect(dpy
, gc
->xid
);
942 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
944 #ifdef GLX_USE_APPLEGL
945 int screen
= vis
->screen
;
946 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
947 const __GLcontextModes
*modes
;
949 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
951 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, modes
))
956 xGLXCreateGLXPixmapReq
*req
;
960 opcode
= __glXSetupForCommand(dpy
);
965 /* Send the glXCreateGLXPixmap request */
967 GetReq(GLXCreateGLXPixmap
, req
);
968 req
->reqType
= opcode
;
969 req
->glxCode
= X_GLXCreateGLXPixmap
;
970 req
->screen
= vis
->screen
;
971 req
->visual
= vis
->visualid
;
972 req
->pixmap
= pixmap
;
973 req
->glxpixmap
= xid
= XAllocID(dpy
);
977 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
979 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
980 * is actually bound to a context... */
982 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
983 __GLXDRIdrawable
*pdraw
;
984 __GLXscreenConfigs
*psc
;
985 __GLcontextModes
*modes
;
987 psc
= priv
->screenConfigs
[vis
->screen
];
988 if (psc
->driScreen
== NULL
)
990 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
991 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
993 fprintf(stderr
, "failed to create pixmap\n");
997 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
998 (*pdraw
->destroyDrawable
) (pdraw
);
999 return None
; /* FIXME: Check what we're supposed to do here... */
1009 ** Destroy the named pixmap
1012 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
1014 #ifdef GLX_USE_APPLEGL
1015 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
1016 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
1018 xGLXDestroyGLXPixmapReq
*req
;
1021 opcode
= __glXSetupForCommand(dpy
);
1026 /* Send the glXDestroyGLXPixmap request */
1028 GetReq(GLXDestroyGLXPixmap
, req
);
1029 req
->reqType
= opcode
;
1030 req
->glxCode
= X_GLXDestroyGLXPixmap
;
1031 req
->glxpixmap
= glxpixmap
;
1035 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1037 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
1038 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, NULL
);
1040 if (pdraw
!= NULL
) {
1041 (*pdraw
->destroyDrawable
) (pdraw
);
1042 __glxHashDelete(priv
->drawHash
, glxpixmap
);
1046 #endif /* GLX_USE_APPLEGL */
1050 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
1052 #ifdef GLX_USE_APPLEGL
1053 GLXContext gc
= glXGetCurrentContext();
1054 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
1055 apple_glx_swap_buffers(gc
->driContext
);
1057 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
1064 xcb_connection_t
*c
;
1066 xGLXSwapBuffersReq
*req
;
1069 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1070 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
1072 if (pdraw
!= NULL
) {
1074 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
1079 opcode
= __glXSetupForCommand(dpy
);
1085 ** The calling thread may or may not have a current context. If it
1086 ** does, send the context tag so the server can do a flush.
1088 gc
= __glXGetCurrentContext();
1089 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1090 ((drawable
== gc
->currentDrawable
)
1091 || (drawable
== gc
->currentReadable
))) {
1092 tag
= gc
->currentContextTag
;
1099 c
= XGetXCBConnection(dpy
);
1100 xcb_glx_swap_buffers(c
, tag
, drawable
);
1103 /* Send the glXSwapBuffers request */
1105 GetReq(GLXSwapBuffers
, req
);
1106 req
->reqType
= opcode
;
1107 req
->glxCode
= X_GLXSwapBuffers
;
1108 req
->drawable
= drawable
;
1109 req
->contextTag
= tag
;
1113 #endif /* USE_XCB */
1114 #endif /* GLX_USE_APPLEGL */
1119 ** Return configuration information for the given display, screen and
1120 ** visual combination.
1123 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1126 __GLXdisplayPrivate
*priv
;
1127 __GLXscreenConfigs
*psc
;
1128 __GLcontextModes
*modes
;
1131 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1132 if (status
== Success
) {
1133 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1135 /* Lookup attribute after first finding a match on the visual */
1136 if (modes
!= NULL
) {
1137 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1140 status
= GLX_BAD_VISUAL
;
1144 ** If we can't find the config for this visual, this visual is not
1145 ** supported by the OpenGL implementation on the server.
1147 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1148 *value_return
= GL_FALSE
;
1155 /************************************************************************/
1158 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1159 GLboolean fbconfig_style_tags
)
1161 memset(config
, 0, sizeof(__GLcontextModes
));
1162 config
->visualID
= (XID
) GLX_DONT_CARE
;
1163 config
->visualType
= GLX_DONT_CARE
;
1165 /* glXChooseFBConfig specifies different defaults for these two than
1168 if (fbconfig_style_tags
) {
1169 config
->rgbMode
= GL_TRUE
;
1170 config
->doubleBufferMode
= GLX_DONT_CARE
;
1173 config
->visualRating
= GLX_DONT_CARE
;
1174 config
->transparentPixel
= GLX_NONE
;
1175 config
->transparentRed
= GLX_DONT_CARE
;
1176 config
->transparentGreen
= GLX_DONT_CARE
;
1177 config
->transparentBlue
= GLX_DONT_CARE
;
1178 config
->transparentAlpha
= GLX_DONT_CARE
;
1179 config
->transparentIndex
= GLX_DONT_CARE
;
1181 config
->drawableType
= GLX_WINDOW_BIT
;
1182 config
->renderType
=
1183 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1184 config
->xRenderable
= GLX_DONT_CARE
;
1185 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1187 config
->swapMethod
= GLX_DONT_CARE
;
1190 #define MATCH_DONT_CARE( param ) \
1192 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1193 && (a-> param != b-> param) ) { \
1198 #define MATCH_MINIMUM( param ) \
1200 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1201 && (a-> param > b-> param) ) { \
1206 #define MATCH_EXACT( param ) \
1208 if ( a-> param != b-> param) { \
1213 /* Test that all bits from a are contained in b */
1214 #define MATCH_MASK(param) \
1216 if ((a->param & ~b->param) != 0) \
1221 * Determine if two GLXFBConfigs are compatible.
1223 * \param a Application specified config to test.
1224 * \param b Server specified config to test against \c a.
1227 fbconfigs_compatible(const __GLcontextModes
* const a
,
1228 const __GLcontextModes
* const b
)
1230 MATCH_DONT_CARE(doubleBufferMode
);
1231 MATCH_DONT_CARE(visualType
);
1232 MATCH_DONT_CARE(visualRating
);
1233 MATCH_DONT_CARE(xRenderable
);
1234 MATCH_DONT_CARE(fbconfigID
);
1235 MATCH_DONT_CARE(swapMethod
);
1237 MATCH_MINIMUM(rgbBits
);
1238 MATCH_MINIMUM(numAuxBuffers
);
1239 MATCH_MINIMUM(redBits
);
1240 MATCH_MINIMUM(greenBits
);
1241 MATCH_MINIMUM(blueBits
);
1242 MATCH_MINIMUM(alphaBits
);
1243 MATCH_MINIMUM(depthBits
);
1244 MATCH_MINIMUM(stencilBits
);
1245 MATCH_MINIMUM(accumRedBits
);
1246 MATCH_MINIMUM(accumGreenBits
);
1247 MATCH_MINIMUM(accumBlueBits
);
1248 MATCH_MINIMUM(accumAlphaBits
);
1249 MATCH_MINIMUM(sampleBuffers
);
1250 MATCH_MINIMUM(maxPbufferWidth
);
1251 MATCH_MINIMUM(maxPbufferHeight
);
1252 MATCH_MINIMUM(maxPbufferPixels
);
1253 MATCH_MINIMUM(samples
);
1255 MATCH_DONT_CARE(stereoMode
);
1258 MATCH_MASK(drawableType
);
1259 MATCH_MASK(renderType
);
1261 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1262 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1263 * Technically speaking, it is a bug in the DDX driver, but there is
1264 * enough of an installed base to work around the problem here. In any
1265 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1266 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1267 * 0 from the server to be a match to maintain backward compatibility with
1268 * the (broken) drivers.
1271 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1272 if (a
->transparentPixel
== GLX_NONE
) {
1273 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1277 MATCH_EXACT(transparentPixel
);
1280 switch (a
->transparentPixel
) {
1281 case GLX_TRANSPARENT_RGB
:
1282 MATCH_DONT_CARE(transparentRed
);
1283 MATCH_DONT_CARE(transparentGreen
);
1284 MATCH_DONT_CARE(transparentBlue
);
1285 MATCH_DONT_CARE(transparentAlpha
);
1288 case GLX_TRANSPARENT_INDEX
:
1289 MATCH_DONT_CARE(transparentIndex
);
1301 /* There's some trickly language in the GLX spec about how this is supposed
1302 * to work. Basically, if a given component size is either not specified
1303 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1304 * Well, that's really hard to do with the code as-is. This behavior is
1305 * closer to correct, but still not technically right.
1307 #define PREFER_LARGER_OR_ZERO(comp) \
1309 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1310 if ( ((*a)-> comp) == 0 ) { \
1313 else if ( ((*b)-> comp) == 0 ) { \
1317 return ((*b)-> comp) - ((*a)-> comp) ; \
1322 #define PREFER_LARGER(comp) \
1324 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1325 return ((*b)-> comp) - ((*a)-> comp) ; \
1329 #define PREFER_SMALLER(comp) \
1331 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1332 return ((*a)-> comp) - ((*b)-> comp) ; \
1337 * Compare two GLXFBConfigs. This function is intended to be used as the
1338 * compare function passed in to qsort.
1340 * \returns If \c a is a "better" config, according to the specification of
1341 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1342 * better, then a number greater than zero is return. If both are
1343 * equal, zero is returned.
1344 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1347 fbconfig_compare(const __GLcontextModes
* const *const a
,
1348 const __GLcontextModes
* const *const b
)
1350 /* The order of these comparisons must NOT change. It is defined by
1351 * the GLX 1.3 spec and ARB_multisample.
1354 PREFER_SMALLER(visualSelectGroup
);
1356 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1357 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1358 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1360 PREFER_SMALLER(visualRating
);
1362 /* This isn't quite right. It is supposed to compare the sum of the
1363 * components the user specifically set minimums for.
1365 PREFER_LARGER_OR_ZERO(redBits
);
1366 PREFER_LARGER_OR_ZERO(greenBits
);
1367 PREFER_LARGER_OR_ZERO(blueBits
);
1368 PREFER_LARGER_OR_ZERO(alphaBits
);
1370 PREFER_SMALLER(rgbBits
);
1372 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1373 /* Prefer single-buffer.
1375 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1378 PREFER_SMALLER(numAuxBuffers
);
1380 PREFER_LARGER_OR_ZERO(depthBits
);
1381 PREFER_SMALLER(stencilBits
);
1383 /* This isn't quite right. It is supposed to compare the sum of the
1384 * components the user specifically set minimums for.
1386 PREFER_LARGER_OR_ZERO(accumRedBits
);
1387 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1388 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1389 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1391 PREFER_SMALLER(visualType
);
1393 /* None of the multisample specs say where this comparison should happen,
1394 * so I put it near the end.
1396 PREFER_SMALLER(sampleBuffers
);
1397 PREFER_SMALLER(samples
);
1399 /* None of the pbuffer or fbconfig specs say that this comparison needs
1400 * to happen at all, but it seems like it should.
1402 PREFER_LARGER(maxPbufferWidth
);
1403 PREFER_LARGER(maxPbufferHeight
);
1404 PREFER_LARGER(maxPbufferPixels
);
1411 * Selects and sorts a subset of the supplied configs based on the attributes.
1412 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1413 * and \c glXChooseFBConfigSGIX.
1415 * \param configs Array of pointers to possible configs. The elements of
1416 * this array that do not meet the criteria will be set to
1417 * NULL. The remaining elements will be sorted according to
1418 * the various visual / FBConfig selection rules.
1419 * \param num_configs Number of elements in the \c configs array.
1420 * \param attribList Attributes used select from \c configs. This array is
1421 * terminated by a \c None tag. The array can either take
1422 * the form expected by \c glXChooseVisual (where boolean
1423 * tags do not have a value) or by \c glXChooseFBConfig
1424 * (where every tag has a value).
1425 * \param fbconfig_style_tags Selects whether \c attribList is in
1426 * \c glXChooseVisual style or
1427 * \c glXChooseFBConfig style.
1428 * \returns The number of valid elements left in \c configs.
1430 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1433 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1434 const int *attribList
, GLboolean fbconfig_style_tags
)
1436 __GLcontextModes test_config
;
1440 /* This is a fairly direct implementation of the selection method
1441 * described by GLX_SGIX_fbconfig. Start by culling out all the
1442 * configs that are not compatible with the selected parameter
1446 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1447 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1448 (const INT32
*) attribList
,
1449 GL_TRUE
, fbconfig_style_tags
);
1452 for (i
= 0; i
< num_configs
; i
++) {
1453 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1454 configs
[base
] = configs
[i
];
1463 if (base
< num_configs
) {
1464 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1467 /* After the incompatible configs are removed, the resulting
1468 * list is sorted according to the rules set out in the various
1472 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1473 (int (*)(const void *, const void *)) fbconfig_compare
);
1481 ** Return the visual that best matches the template. Return None if no
1482 ** visual matches the template.
1484 PUBLIC XVisualInfo
*
1485 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1487 XVisualInfo
*visualList
= NULL
;
1488 __GLXdisplayPrivate
*priv
;
1489 __GLXscreenConfigs
*psc
;
1490 __GLcontextModes test_config
;
1491 __GLcontextModes
*modes
;
1492 const __GLcontextModes
*best_config
= NULL
;
1495 ** Get a list of all visuals, return if list is empty
1497 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1503 ** Build a template from the defaults and the attribute list
1504 ** Free visual list and return if an unexpected token is encountered
1506 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1507 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1508 (const INT32
*) attribList
,
1512 ** Eliminate visuals that don't meet minimum requirements
1513 ** Compute a score for those that do
1514 ** Remember which visual, if any, got the highest score
1515 ** If no visual is acceptable, return None
1516 ** Otherwise, create an XVisualInfo list with just the selected X visual
1519 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1520 if (fbconfigs_compatible(&test_config
, modes
)
1521 && ((best_config
== NULL
)
1524 ((const __GLcontextModes
* const *const) &modes
,
1525 &best_config
) < 0))) {
1526 XVisualInfo visualTemplate
;
1527 XVisualInfo
*newList
;
1530 visualTemplate
.screen
= screen
;
1531 visualTemplate
.visualid
= modes
->visualID
;
1532 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1533 &visualTemplate
, &i
);
1537 visualList
= newList
;
1538 best_config
= modes
;
1543 #ifdef GLX_USE_APPLEGL
1544 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1545 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1554 glXQueryExtensionsString(Display
* dpy
, int screen
)
1556 __GLXscreenConfigs
*psc
;
1557 __GLXdisplayPrivate
*priv
;
1559 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1563 if (!psc
->effectiveGLXexts
) {
1564 if (!psc
->serverGLXexts
) {
1565 psc
->serverGLXexts
=
1566 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1570 __glXCalculateUsableExtensions(psc
,
1571 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1572 (psc
->driScreen
!= NULL
),
1576 priv
->minorVersion
);
1579 return psc
->effectiveGLXexts
;
1583 glXGetClientString(Display
* dpy
, int name
)
1589 return (__glXGLXClientVendorName
);
1591 return (__glXGLXClientVersion
);
1592 case GLX_EXTENSIONS
:
1593 return (__glXGetClientExtensions());
1600 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1602 __GLXscreenConfigs
*psc
;
1603 __GLXdisplayPrivate
*priv
;
1607 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1613 str
= &priv
->serverGLXvendor
;
1616 str
= &priv
->serverGLXversion
;
1618 case GLX_EXTENSIONS
:
1619 str
= &psc
->serverGLXexts
;
1626 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1633 __glXClientInfo(Display
* dpy
, int opcode
)
1635 char *ext_str
= __glXGetClientGLExtensionString();
1636 int size
= strlen(ext_str
) + 1;
1639 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1640 xcb_glx_client_info(c
,
1641 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1643 xGLXClientInfoReq
*req
;
1645 /* Send the glXClientInfo request */
1647 GetReq(GLXClientInfo
, req
);
1648 req
->reqType
= opcode
;
1649 req
->glxCode
= X_GLXClientInfo
;
1650 req
->major
= GLX_MAJOR_VERSION
;
1651 req
->minor
= GLX_MINOR_VERSION
;
1653 req
->length
+= (size
+ 3) >> 2;
1654 req
->numbytes
= size
;
1655 Data(dpy
, ext_str
, size
);
1659 #endif /* USE_XCB */
1666 ** EXT_import_context
1670 glXGetCurrentDisplay(void)
1672 GLXContext gc
= __glXGetCurrentContext();
1675 return gc
->currentDpy
;
1679 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1680 glXGetCurrentDisplay
)
1682 #ifndef GLX_USE_APPLEGL
1684 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1687 * \param dpy Display where \c ctx was created.
1688 * \param ctx Context to query.
1689 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1690 * or zero if the request failed due to internal problems (i.e.,
1691 * unable to allocate temporary memory, etc.)
1694 * This function dynamically determines whether to use the EXT_import_context
1695 * version of the protocol or the GLX 1.3 version of the protocol.
1697 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1699 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1700 xGLXQueryContextReply reply
;
1706 return GLX_BAD_CONTEXT
;
1708 opcode
= __glXSetupForCommand(dpy
);
1713 /* Send the glXQueryContextInfoEXT request */
1716 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1717 xGLXQueryContextReq
*req
;
1719 GetReq(GLXQueryContext
, req
);
1721 req
->reqType
= opcode
;
1722 req
->glxCode
= X_GLXQueryContext
;
1723 req
->context
= (unsigned int) (ctx
->xid
);
1726 xGLXVendorPrivateReq
*vpreq
;
1727 xGLXQueryContextInfoEXTReq
*req
;
1729 GetReqExtra(GLXVendorPrivate
,
1730 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1732 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1733 req
->reqType
= opcode
;
1734 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1735 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1736 req
->context
= (unsigned int) (ctx
->xid
);
1739 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1741 numValues
= reply
.n
;
1744 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1747 int *propList
, *pProp
;
1750 nPropListBytes
= numValues
<< 3;
1751 propList
= (int *) Xmalloc(nPropListBytes
);
1752 if (NULL
== propList
) {
1758 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1760 /* Look up screen first so we can look up visuals/fbconfigs later */
1762 for (i
= 0; i
< numValues
; i
++, pProp
+= 2)
1763 if (pProp
[0] == GLX_SCREEN
) {
1764 ctx
->screen
= pProp
[1];
1765 ctx
->psc
= GetGLXScreenConfigs(dpy
, ctx
->screen
);
1769 for (i
= 0; i
< numValues
; i
++) {
1771 case GLX_SHARE_CONTEXT_EXT
:
1772 ctx
->share_xid
= *pProp
++;
1774 case GLX_VISUAL_ID_EXT
:
1776 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1778 case GLX_FBCONFIG_ID
:
1780 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1783 case GLX_RENDER_TYPE
:
1784 ctx
->renderType
= *pProp
++;
1792 Xfree((char *) propList
);
1804 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1806 #ifndef GLX_USE_APPLEGL
1809 /* get the information from the server if we don't have it already */
1810 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1811 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1813 if (ctx
->mode
== NULL
) {
1815 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1816 if (Success
!= retVal
)
1821 switch (attribute
) {
1822 #ifndef GLX_USE_APPLEGL
1823 case GLX_SHARE_CONTEXT_EXT
:
1824 *value
= (int) (ctx
->share_xid
);
1826 case GLX_VISUAL_ID_EXT
:
1827 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1831 *value
= (int) (ctx
->screen
);
1833 case GLX_FBCONFIG_ID
:
1834 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1836 case GLX_RENDER_TYPE
:
1837 *value
= (int) (ctx
->renderType
);
1840 return GLX_BAD_ATTRIBUTE
;
1846 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1847 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1848 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1850 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1856 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1858 #ifdef GLX_USE_APPLEGL
1863 if (contextID
== None
) {
1866 if (__glXIsDirect(dpy
, contextID
)) {
1870 ctx
= AllocateGLXContext(dpy
);
1872 ctx
->xid
= contextID
;
1873 ctx
->imported
= GL_TRUE
;
1875 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1876 __glXFreeContext(ctx
);
1885 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1887 DestroyContext(dpy
, ctx
);
1893 * GLX 1.3 functions - these are just stubs for now!
1896 PUBLIC GLXFBConfig
*
1897 glXChooseFBConfig(Display
* dpy
, int screen
,
1898 const int *attribList
, int *nitems
)
1900 __GLcontextModes
**config_list
;
1904 config_list
= (__GLcontextModes
**)
1905 glXGetFBConfigs(dpy
, screen
, &list_size
);
1907 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1908 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1909 if (list_size
== 0) {
1915 *nitems
= list_size
;
1916 return (GLXFBConfig
*) config_list
;
1921 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1922 int renderType
, GLXContext shareList
, Bool allowDirect
)
1924 const __GLcontextModes
*const fbconfig
=
1925 (const __GLcontextModes
*const) config
;
1927 return CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
1928 allowDirect
, X_GLXCreateNewContext
, renderType
,
1934 glXGetCurrentReadDrawable(void)
1936 GLXContext gc
= __glXGetCurrentContext();
1937 return gc
->currentReadable
;
1941 PUBLIC GLXFBConfig
*
1942 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1944 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1945 __GLcontextModes
**config
= NULL
;
1949 if (priv
&& (priv
->screenConfigs
!= NULL
)
1950 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1951 && (priv
->screenConfigs
[screen
]->configs
!= NULL
)
1952 && (priv
->screenConfigs
[screen
]->configs
->fbconfigID
1953 != (int) GLX_DONT_CARE
)) {
1954 unsigned num_configs
= 0;
1955 __GLcontextModes
*modes
;
1958 for (modes
= priv
->screenConfigs
[screen
]->configs
; modes
!= NULL
;
1959 modes
= modes
->next
) {
1960 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1965 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1967 if (config
!= NULL
) {
1968 *nelements
= num_configs
;
1970 for (modes
= priv
->screenConfigs
[screen
]->configs
; modes
!= NULL
;
1971 modes
= modes
->next
) {
1972 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1979 return (GLXFBConfig
*) config
;
1984 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1985 int attribute
, int *value
)
1987 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1989 return (modes
!= NULL
)
1990 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1995 PUBLIC XVisualInfo
*
1996 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1998 XVisualInfo visualTemplate
;
1999 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
2003 ** Get a list of all visuals, return if list is empty
2005 visualTemplate
.visualid
= fbconfig
->visualID
;
2006 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
2009 #ifndef GLX_USE_APPLEGL
2011 ** GLX_SGI_swap_control
2014 __glXSwapIntervalSGI(int interval
)
2016 xGLXVendorPrivateReq
*req
;
2017 GLXContext gc
= __glXGetCurrentContext();
2018 __GLXscreenConfigs
*psc
;
2020 CARD32
*interval_ptr
;
2024 return GLX_BAD_CONTEXT
;
2027 if (interval
<= 0) {
2028 return GLX_BAD_VALUE
;
2031 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2033 #ifdef GLX_DIRECT_RENDERING
2034 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2035 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2036 gc
->currentDrawable
,
2038 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2043 dpy
= gc
->currentDpy
;
2044 opcode
= __glXSetupForCommand(dpy
);
2049 /* Send the glXSwapIntervalSGI request */
2051 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
2052 req
->reqType
= opcode
;
2053 req
->glxCode
= X_GLXVendorPrivate
;
2054 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
2055 req
->contextTag
= gc
->currentContextTag
;
2057 interval_ptr
= (CARD32
*) (req
+ 1);
2058 *interval_ptr
= interval
;
2069 ** GLX_MESA_swap_control
2072 __glXSwapIntervalMESA(unsigned int interval
)
2074 #ifdef GLX_DIRECT_RENDERING
2075 GLXContext gc
= __glXGetCurrentContext();
2077 if (gc
!= NULL
&& gc
->driContext
) {
2078 __GLXscreenConfigs
*psc
;
2080 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2081 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2082 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2083 gc
->currentDrawable
, NULL
);
2084 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2089 return GLX_BAD_CONTEXT
;
2094 __glXGetSwapIntervalMESA(void)
2096 #ifdef GLX_DIRECT_RENDERING
2097 GLXContext gc
= __glXGetCurrentContext();
2099 if (gc
!= NULL
&& gc
->driContext
) {
2100 __GLXscreenConfigs
*psc
;
2102 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2103 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2104 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2105 gc
->currentDrawable
, NULL
);
2106 return psc
->driScreen
->getSwapInterval(pdraw
);
2116 ** GLX_SGI_video_sync
2119 __glXGetVideoSyncSGI(unsigned int *count
)
2121 int64_t ust
, msc
, sbc
;
2123 GLXContext gc
= __glXGetCurrentContext();
2124 __GLXscreenConfigs
*psc
;
2125 #ifdef GLX_DIRECT_RENDERING
2126 __GLXDRIdrawable
*pdraw
;
2130 return GLX_BAD_CONTEXT
;
2132 #ifdef GLX_DIRECT_RENDERING
2133 if (!gc
->driContext
)
2134 return GLX_BAD_CONTEXT
;
2137 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2138 #ifdef GLX_DIRECT_RENDERING
2139 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2142 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2143 * FIXME: there should be a GLX encoding for this call. I can find no
2144 * FIXME: documentation for the GLX encoding.
2146 #ifdef GLX_DIRECT_RENDERING
2147 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2148 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2149 *count
= (unsigned) msc
;
2150 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2154 return GLX_BAD_CONTEXT
;
2158 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2160 GLXContext gc
= __glXGetCurrentContext();
2161 __GLXscreenConfigs
*psc
;
2162 #ifdef GLX_DIRECT_RENDERING
2163 __GLXDRIdrawable
*pdraw
;
2165 int64_t ust
, msc
, sbc
;
2168 if (divisor
<= 0 || remainder
< 0)
2169 return GLX_BAD_VALUE
;
2172 return GLX_BAD_CONTEXT
;
2174 #ifdef GLX_DIRECT_RENDERING
2175 if (!gc
->driContext
)
2176 return GLX_BAD_CONTEXT
;
2179 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2180 #ifdef GLX_DIRECT_RENDERING
2181 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2184 #ifdef GLX_DIRECT_RENDERING
2185 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2186 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2188 *count
= (unsigned) msc
;
2189 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2193 return GLX_BAD_CONTEXT
;
2196 #endif /* GLX_USE_APPLEGL */
2199 ** GLX_SGIX_fbconfig
2200 ** Many of these functions are aliased to GLX 1.3 entry points in the
2201 ** GLX_functions table.
2205 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2206 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2207 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2209 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2210 (Display
* dpy
, int screen
, int *attrib_list
,
2211 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2214 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2215 (Display
* dpy
, GLXFBConfigSGIX config
),
2216 (dpy
, config
), glXGetVisualFromFBConfig
)
2219 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2220 GLXFBConfigSGIX config
,
2223 #ifndef GLX_USE_APPLEGL
2224 xGLXVendorPrivateWithReplyReq
*vpreq
;
2225 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2226 GLXPixmap xid
= None
;
2228 __GLXscreenConfigs
*psc
;
2230 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2233 if ((dpy
== NULL
) || (config
== NULL
)) {
2236 #ifdef GLX_USE_APPLEGL
2237 if(apple_glx_pixmap_create(dpy
, fbconfig
->screen
, pixmap
, fbconfig
))
2242 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2244 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2245 opcode
= __glXSetupForCommand(dpy
);
2250 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2252 GetReqExtra(GLXVendorPrivateWithReply
,
2253 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2254 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2255 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2256 req
->reqType
= opcode
;
2257 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2258 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2259 req
->screen
= fbconfig
->screen
;
2260 req
->fbconfig
= fbconfig
->fbconfigID
;
2261 req
->pixmap
= pixmap
;
2262 req
->glxpixmap
= xid
= XAllocID(dpy
);
2272 glXCreateContextWithConfigSGIX(Display
* dpy
,
2273 GLXFBConfigSGIX config
, int renderType
,
2274 GLXContext shareList
, Bool allowDirect
)
2276 GLXContext gc
= NULL
;
2277 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2278 __GLXscreenConfigs
*psc
;
2281 if ((dpy
== NULL
) || (config
== NULL
)) {
2285 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2287 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2288 gc
= CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
2290 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2298 PUBLIC GLXFBConfigSGIX
2299 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2301 __GLXdisplayPrivate
*priv
;
2302 __GLXscreenConfigs
*psc
= NULL
;
2304 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2305 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2306 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2307 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2314 #ifndef GLX_USE_APPLEGL
2316 ** GLX_SGIX_swap_group
2319 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2329 ** GLX_SGIX_swap_barrier
2332 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2340 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2350 ** GLX_OML_sync_control
2353 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2354 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2356 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2358 #ifdef GLX_DIRECT_RENDERING
2359 __GLXDRIdrawable
*pdraw
;
2361 __GLXscreenConfigs
*psc
;
2366 #ifdef GLX_DIRECT_RENDERING
2367 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2368 psc
= priv
->screenConfigs
[i
];
2369 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2370 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2378 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2380 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2381 int32_t * numerator
, int32_t * denominator
)
2384 __GLXscreenConfigs
*psc
;
2385 XF86VidModeModeLine mode_line
;
2390 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2391 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2392 unsigned n
= dot_clock
* 1000;
2393 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2395 # define V_INTERLACE 0x010
2396 # define V_DBLSCAN 0x020
2398 if (mode_line
.flags
& V_INTERLACE
)
2400 else if (mode_line
.flags
& V_DBLSCAN
)
2403 /* The OML_sync_control spec requires that if the refresh rate is a
2404 * whole number, that the returned numerator be equal to the refresh
2405 * rate and the denominator be 1.
2413 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2415 /* This is a poor man's way to reduce a fraction. It's far from
2416 * perfect, but it will work well enough for this situation.
2419 for (i
= 0; f
[i
] != 0; i
++) {
2420 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2446 * Determine the refresh rate of the specified drawable and display.
2448 * \param dpy Display whose refresh rate is to be determined.
2449 * \param drawable Drawable whose refresh rate is to be determined.
2450 * \param numerator Numerator of the refresh rate.
2451 * \param demoninator Denominator of the refresh rate.
2452 * \return If the refresh rate for the specified display and drawable could
2453 * be calculated, True is returned. Otherwise False is returned.
2455 * \note This function is implemented entirely client-side. A lot of other
2456 * functionality is required to export GLX_OML_sync_control, so on
2457 * XFree86 this function can be called for direct-rendering contexts
2458 * when GLX_OML_sync_control appears in the client extension string.
2462 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2463 int32_t * numerator
, int32_t * denominator
)
2465 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2466 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2471 return __glxGetMscRate(draw
, numerator
, denominator
);
2483 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2484 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2486 GLXContext gc
= __glXGetCurrentContext();
2488 #ifdef GLX_DIRECT_RENDERING
2489 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2491 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2493 if (!gc
) /* no GLX for this */
2496 #ifdef GLX_DIRECT_RENDERING
2497 if (!pdraw
|| !gc
->driContext
)
2501 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2502 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2503 * of -1 if the function failed because of errors detected in the input
2506 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2508 if (divisor
> 0 && remainder
>= divisor
)
2511 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2514 #ifdef GLX_DIRECT_RENDERING
2515 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2516 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2525 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2526 int64_t target_msc
, int64_t divisor
,
2527 int64_t remainder
, int64_t * ust
,
2528 int64_t * msc
, int64_t * sbc
)
2531 #ifdef GLX_DIRECT_RENDERING
2532 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2534 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2538 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2539 * error", but the return type in the spec is Bool.
2541 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2543 if (divisor
> 0 && remainder
>= divisor
)
2546 #ifdef GLX_DIRECT_RENDERING
2547 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2548 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2559 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2560 int64_t target_sbc
, int64_t * ust
,
2561 int64_t * msc
, int64_t * sbc
)
2564 #ifdef GLX_DIRECT_RENDERING
2565 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2567 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2570 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2571 * error", but the return type in the spec is Bool.
2576 #ifdef GLX_DIRECT_RENDERING
2577 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2578 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2590 * Mesa extension stubs. These will help reduce portability problems.
2595 * Release all buffers associated with the specified GLX drawable.
2598 * This function was intended for stand-alone Mesa. The issue there is that
2599 * the library doesn't get any notification when a window is closed. In
2600 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2601 * supported, there are 3 different functions to destroy a drawable. It
2602 * should be possible to create GLX protocol (or have it determine which
2603 * protocol to use based on the type of the drawable) to have one function
2604 * do the work of 3. For the direct-rendering case, this function could
2605 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2606 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2607 * would need to be used. This really should be done as part of the new DRI
2610 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2611 * __driGarbageCollectDrawables
2612 * glXDestroyGLXPixmap
2613 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2614 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2617 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2626 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2627 Pixmap pixmap
, Colormap cmap
)
2640 * GLX_MESA_copy_sub_buffer
2642 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2644 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2645 int x
, int y
, int width
, int height
)
2647 xGLXVendorPrivateReq
*req
;
2650 CARD32
*drawable_ptr
;
2651 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2654 #ifdef __DRI_COPY_SUB_BUFFER
2656 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2657 if (pdraw
!= NULL
) {
2658 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2659 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2661 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2668 opcode
= __glXSetupForCommand(dpy
);
2673 ** The calling thread may or may not have a current context. If it
2674 ** does, send the context tag so the server can do a flush.
2676 gc
= __glXGetCurrentContext();
2677 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2678 ((drawable
== gc
->currentDrawable
) ||
2679 (drawable
== gc
->currentReadable
))) {
2680 tag
= gc
->currentContextTag
;
2687 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2688 req
->reqType
= opcode
;
2689 req
->glxCode
= X_GLXVendorPrivate
;
2690 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2691 req
->contextTag
= tag
;
2693 drawable_ptr
= (CARD32
*) (req
+ 1);
2694 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2695 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2696 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2697 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2699 *drawable_ptr
= drawable
;
2711 * GLX_EXT_texture_from_pixmap
2714 glx_indirect_bind_tex_image(Display
* dpy
,
2715 GLXDrawable drawable
,
2716 int buffer
, const int *attrib_list
)
2718 xGLXVendorPrivateReq
*req
;
2719 GLXContext gc
= __glXGetCurrentContext();
2720 CARD32
*drawable_ptr
;
2722 CARD32
*num_attrib_ptr
;
2729 while (attrib_list
[i
* 2] != None
)
2733 opcode
= __glXSetupForCommand(dpy
);
2738 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2739 req
->reqType
= opcode
;
2740 req
->glxCode
= X_GLXVendorPrivate
;
2741 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2742 req
->contextTag
= gc
->currentContextTag
;
2744 drawable_ptr
= (CARD32
*) (req
+ 1);
2745 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2746 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2747 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2749 *drawable_ptr
= drawable
;
2750 *buffer_ptr
= buffer
;
2751 *num_attrib_ptr
= (CARD32
) i
;
2755 while (attrib_list
[i
* 2] != None
) {
2756 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2757 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2767 glx_indirect_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2769 xGLXVendorPrivateReq
*req
;
2770 GLXContext gc
= __glXGetCurrentContext();
2771 CARD32
*drawable_ptr
;
2775 opcode
= __glXSetupForCommand(dpy
);
2780 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2781 req
->reqType
= opcode
;
2782 req
->glxCode
= X_GLXVendorPrivate
;
2783 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2784 req
->contextTag
= gc
->currentContextTag
;
2786 drawable_ptr
= (CARD32
*) (req
+ 1);
2787 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2789 *drawable_ptr
= drawable
;
2790 *buffer_ptr
= buffer
;
2796 static const struct glx_context_vtable glx_indirect_context_vtable
= {
2797 glx_indirect_bind_tex_image
,
2798 glx_indirect_release_tex_image
,
2803 __glXBindTexImageEXT(Display
* dpy
,
2804 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2806 GLXContext gc
= __glXGetCurrentContext();
2808 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2811 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2815 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2817 GLXContext gc
= __glXGetCurrentContext();
2819 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2822 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2827 #endif /* GLX_USE_APPLEGL */
2830 * \c strdup is actually not a standard ANSI C or POSIX routine.
2831 * Irix will not define it if ANSI mode is in effect.
2836 __glXstrdup(const char *str
)
2839 copy
= (char *) Xmalloc(strlen(str
) + 1);
2847 ** glXGetProcAddress support
2850 struct name_address_pair
2856 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2857 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2859 static const struct name_address_pair GLX_functions
[] = {
2860 /*** GLX_VERSION_1_0 ***/
2861 GLX_FUNCTION(glXChooseVisual
),
2862 GLX_FUNCTION(glXCopyContext
),
2863 GLX_FUNCTION(glXCreateContext
),
2864 GLX_FUNCTION(glXCreateGLXPixmap
),
2865 GLX_FUNCTION(glXDestroyContext
),
2866 GLX_FUNCTION(glXDestroyGLXPixmap
),
2867 GLX_FUNCTION(glXGetConfig
),
2868 GLX_FUNCTION(glXGetCurrentContext
),
2869 GLX_FUNCTION(glXGetCurrentDrawable
),
2870 GLX_FUNCTION(glXIsDirect
),
2871 GLX_FUNCTION(glXMakeCurrent
),
2872 GLX_FUNCTION(glXQueryExtension
),
2873 GLX_FUNCTION(glXQueryVersion
),
2874 GLX_FUNCTION(glXSwapBuffers
),
2875 GLX_FUNCTION(glXUseXFont
),
2876 GLX_FUNCTION(glXWaitGL
),
2877 GLX_FUNCTION(glXWaitX
),
2879 /*** GLX_VERSION_1_1 ***/
2880 GLX_FUNCTION(glXGetClientString
),
2881 GLX_FUNCTION(glXQueryExtensionsString
),
2882 GLX_FUNCTION(glXQueryServerString
),
2884 /*** GLX_VERSION_1_2 ***/
2885 GLX_FUNCTION(glXGetCurrentDisplay
),
2887 /*** GLX_VERSION_1_3 ***/
2888 GLX_FUNCTION(glXChooseFBConfig
),
2889 GLX_FUNCTION(glXCreateNewContext
),
2890 GLX_FUNCTION(glXCreatePbuffer
),
2891 GLX_FUNCTION(glXCreatePixmap
),
2892 GLX_FUNCTION(glXCreateWindow
),
2893 GLX_FUNCTION(glXDestroyPbuffer
),
2894 GLX_FUNCTION(glXDestroyPixmap
),
2895 GLX_FUNCTION(glXDestroyWindow
),
2896 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2897 GLX_FUNCTION(glXGetFBConfigAttrib
),
2898 GLX_FUNCTION(glXGetFBConfigs
),
2899 GLX_FUNCTION(glXGetSelectedEvent
),
2900 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2901 GLX_FUNCTION(glXMakeContextCurrent
),
2902 GLX_FUNCTION(glXQueryContext
),
2903 GLX_FUNCTION(glXQueryDrawable
),
2904 GLX_FUNCTION(glXSelectEvent
),
2906 #ifndef GLX_USE_APPLEGL
2907 /*** GLX_SGI_swap_control ***/
2908 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2910 /*** GLX_SGI_video_sync ***/
2911 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2912 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2914 /*** GLX_SGI_make_current_read ***/
2915 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2916 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2918 /*** GLX_EXT_import_context ***/
2919 GLX_FUNCTION(glXFreeContextEXT
),
2920 GLX_FUNCTION(glXGetContextIDEXT
),
2921 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2922 GLX_FUNCTION(glXImportContextEXT
),
2923 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2926 /*** GLX_SGIX_fbconfig ***/
2927 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2928 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2929 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2930 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2931 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2932 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2934 #ifndef GLX_USE_APPLEGL
2935 /*** GLX_SGIX_pbuffer ***/
2936 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2937 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2938 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2939 GLX_FUNCTION(glXSelectEventSGIX
),
2940 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2942 /*** GLX_SGIX_swap_group ***/
2943 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2945 /*** GLX_SGIX_swap_barrier ***/
2946 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2947 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2949 /*** GLX_MESA_copy_sub_buffer ***/
2950 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2952 /*** GLX_MESA_pixmap_colormap ***/
2953 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2955 /*** GLX_MESA_release_buffers ***/
2956 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2958 /*** GLX_MESA_swap_control ***/
2959 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2960 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2963 /*** GLX_ARB_get_proc_address ***/
2964 GLX_FUNCTION(glXGetProcAddressARB
),
2967 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2969 #ifndef GLX_USE_APPLEGL
2970 /*** GLX_OML_sync_control ***/
2971 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2972 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2973 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2974 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2975 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2977 /*** GLX_EXT_texture_from_pixmap ***/
2978 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2979 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2982 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2983 /*** DRI configuration ***/
2984 GLX_FUNCTION(glXGetScreenDriver
),
2985 GLX_FUNCTION(glXGetDriverConfig
),
2988 {NULL
, NULL
} /* end of list */
2991 #ifndef GLX_USE_APPLEGL
2992 static const GLvoid
*
2993 get_glx_proc_address(const char *funcName
)
2997 /* try static functions */
2998 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2999 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3000 return GLX_functions
[i
].Address
;
3008 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3009 * \c glXGetProcAddress.
3011 * \param procName Name of a GL or GLX function.
3012 * \returns A pointer to the named function
3014 * \sa glXGetProcAddress
3016 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3018 typedef void (*gl_function
) (void);
3022 /* Search the table of GLX and internal functions first. If that
3023 * fails and the supplied name could be a valid core GL name, try
3024 * searching the core GL function table. This check is done to prevent
3025 * DRI based drivers from searching the core GL function table for
3026 * internal API functions.
3028 #ifdef GLX_USE_APPLEGL
3029 f
= (gl_function
) apple_glx_get_proc_address(procName
);
3031 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3032 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3033 && (procName
[2] != 'X')) {
3034 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3041 * Get the address of a named GL function. This is the GLX 1.4 name for
3042 * \c glXGetProcAddressARB.
3044 * \param procName Name of a GL or GLX function.
3045 * \returns A pointer to the named function
3047 * \sa glXGetProcAddressARB
3049 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3050 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3051 __attribute__ ((alias("glXGetProcAddressARB")));
3054 return glXGetProcAddressARB(procName
);
3056 #endif /* __GNUC__ */
3059 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3061 * Get the unadjusted system time (UST). Currently, the UST is measured in
3062 * microseconds since Epoc. The actual resolution of the UST may vary from
3063 * system to system, and the units may vary from release to release.
3064 * Drivers should not call this function directly. They should instead use
3065 * \c glXGetProcAddress to obtain a pointer to the function.
3067 * \param ust Location to store the 64-bit UST
3068 * \returns Zero on success or a negative errno value on failure.
3070 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3072 * \since Internal API version 20030317.
3075 __glXGetUST(int64_t * ust
)
3083 if (gettimeofday(&tv
, NULL
) == 0) {
3084 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3091 #endif /* GLX_DIRECT_RENDERING */