2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
39 #include "glcontextmodes.h"
41 #ifdef GLX_DIRECT_RENDERING
43 #include <X11/extensions/xf86vmode.h>
45 #define GC_IS_DIRECT(gc) ((gc)->driContext != NULL)
47 #define GC_IS_DIRECT(gc) (0)
51 #include <X11/Xlib-xcb.h>
56 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
57 static const char __glXGLXClientVersion
[] = "1.4";
60 /****************************************************************************/
62 #ifdef GLX_DIRECT_RENDERING
64 static Bool windowExistsFlag
;
66 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
70 if (xerr
->error_code
== BadWindow
) {
71 windowExistsFlag
= GL_FALSE
;
77 * Find drawables in the local hash that have been destroyed on the
80 * \param dpy Display to destroy drawables for
81 * \param screen Screen number to destroy drawables for
84 GarbageCollectDRIDrawables(Display
* dpy
, __GLXscreenConfigs
* sc
)
87 __GLXDRIdrawable
*pdraw
;
88 XWindowAttributes xwa
;
89 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
91 /* Set no-op error handler so Xlib doesn't bail out if the windows
92 * has alreay been destroyed on the server. */
94 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
96 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
98 windowExistsFlag
= GL_TRUE
;
99 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
100 if (!windowExistsFlag
) {
101 /* Destroy the local drawable data, if the drawable no
102 longer exists in the Xserver */
103 (*pdraw
->destroyDrawable
) (pdraw
);
104 __glxHashDelete(sc
->drawHash
, draw
);
106 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1);
109 XSync(dpy
, GL_FALSE
);
110 XSetErrorHandler(oldXErrorHandler
);
113 extern __GLXDRIdrawable
*GetGLXDRIDrawable(Display
* dpy
,
114 GLXDrawable drawable
,
115 int *const scrn_num
);
118 * Get the __DRIdrawable for the drawable associated with a GLXContext
120 * \param dpy The display associated with \c drawable.
121 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
122 * \param scrn_num If non-NULL, the drawables screen is stored there
123 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
124 * the drawable is not associated with a direct-rendering context.
126 _X_HIDDEN __GLXDRIdrawable
*
127 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
129 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
130 __GLXDRIdrawable
*pdraw
;
131 const unsigned screen_count
= ScreenCount(dpy
);
133 __GLXscreenConfigs
*psc
;
138 for (i
= 0; i
< screen_count
; i
++) {
139 psc
= &priv
->screenConfigs
[i
];
140 if (psc
->drawHash
== NULL
)
143 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
144 if (scrn_num
!= NULL
)
157 * Get the GLX per-screen data structure associated with a GLX context.
159 * \param dpy Display for which the GLX per-screen information is to be
161 * \param scrn Screen on \c dpy for which the GLX per-screen information is
163 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
164 * specify a valid GLX screen, or NULL otherwise.
166 * \todo Should this function validate that \c scrn is within the screen
167 * number range for \c dpy?
170 static __GLXscreenConfigs
*
171 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
173 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
176 && priv
->screenConfigs
!=
177 NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
182 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
183 __GLXscreenConfigs
** ppsc
)
185 /* Initialize the extension, if needed . This has the added value
186 * of initializing/allocating the display private
190 return GLX_NO_EXTENSION
;
193 *ppriv
= __glXInitialize(dpy
);
194 if (*ppriv
== NULL
) {
195 return GLX_NO_EXTENSION
;
198 /* Check screen number to see if its valid */
199 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
200 return GLX_BAD_SCREEN
;
203 /* Check to see if the GL is supported on this screen */
204 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
205 if ((*ppsc
)->configs
== NULL
) {
206 /* No support for GL on this screen regardless of visual */
207 return GLX_BAD_VISUAL
;
215 * Determine if a \c GLXFBConfig supplied by the application is valid.
217 * \param dpy Application supplied \c Display pointer.
218 * \param config Application supplied \c GLXFBConfig.
220 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
221 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
224 static __GLcontextModes
*
225 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
227 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
228 const unsigned num_screens
= ScreenCount(dpy
);
230 const __GLcontextModes
*modes
;
234 for (i
= 0; i
< num_screens
; i
++) {
235 for (modes
= priv
->screenConfigs
[i
].configs
; modes
!= NULL
;
236 modes
= modes
->next
) {
237 if (modes
== (__GLcontextModes
*) config
) {
238 return (__GLcontextModes
*) config
;
249 * \todo It should be possible to move the allocate of \c client_state_private
250 * later in the function for direct-rendering contexts. Direct-rendering
251 * contexts don't need to track client state, so they don't need that memory
254 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
255 * function called \c __glXAllocateClientState that allocates the memory and
256 * does all the initialization (including the pixel pack / unpack).
259 AllocateGLXContext(Display
* dpy
)
264 __GLXattribute
*state
;
269 opcode
= __glXSetupForCommand(dpy
);
274 /* Allocate our context record */
275 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
280 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
282 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
288 gc
->client_state_private
= state
;
289 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
290 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
293 ** Create a temporary buffer to hold GLX rendering commands. The size
294 ** of the buffer is selected so that the maximum number of GLX rendering
295 ** commands can fit in a single X packet and still have room in the X
296 ** packet for the GLXRenderReq header.
299 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
300 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
302 Xfree(gc
->client_state_private
);
306 gc
->bufSize
= bufSize
;
308 /* Fill in the new context */
309 gc
->renderMode
= GL_RENDER
;
311 state
->storePack
.alignment
= 4;
312 state
->storeUnpack
.alignment
= 4;
314 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
317 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
318 ** Other code uses the fastImageUnpack bit, but it is never set
321 gc
->fastImageUnpack
= GL_FALSE
;
322 gc
->fillImage
= __glFillImage
;
324 gc
->bufEnd
= gc
->buf
+ bufSize
;
325 gc
->isDirect
= GL_FALSE
;
328 ** Set limit register so that there will be one command per packet
333 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
336 gc
->majorOpcode
= opcode
;
339 ** Constrain the maximum drawing command size allowed to be
340 ** transfered using the X_GLXRender protocol request. First
341 ** constrain by a software limit, then constrain by the protocl
344 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
345 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
347 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
348 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
350 gc
->maxSmallRenderCommandSize
= bufSize
;
356 * Create a new context. Exactly one of \c vis and \c fbconfig should be
359 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
360 * SGIX_fbconfig protocol be used?
361 * \param renderType For FBConfigs, what is the rendering type?
365 CreateContext(Display
* dpy
, XVisualInfo
* vis
,
366 const __GLcontextModes
* const fbconfig
,
367 GLXContext shareList
,
368 Bool allowDirect
, GLXContextID contextID
,
369 Bool use_glx_1_3
, int renderType
)
372 #ifdef GLX_DIRECT_RENDERING
373 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
374 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
380 gc
= AllocateGLXContext(dpy
);
384 if (None
== contextID
) {
385 if ((vis
== NULL
) && (fbconfig
== NULL
))
388 #ifdef GLX_DIRECT_RENDERING
389 if (allowDirect
&& psc
->driScreen
) {
390 const __GLcontextModes
*mode
;
392 if (fbconfig
== NULL
) {
393 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
397 error
.errorCode
= BadValue
;
398 error
.resourceID
= vis
->visualid
;
399 error
.sequenceNumber
= dpy
->request
;
400 error
.type
= X_Error
;
401 error
.majorCode
= gc
->majorOpcode
;
402 error
.minorCode
= X_GLXCreateContext
;
403 _XError(dpy
, &error
);
406 if (renderType
== 0) {
407 /* Initialize renderType now */
408 renderType
= mode
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
415 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
418 if (gc
->driContext
!= NULL
) {
419 gc
->screen
= mode
->screen
;
422 gc
->isDirect
= GL_TRUE
;
428 if (fbconfig
== NULL
) {
429 xGLXCreateContextReq
*req
;
431 /* Send the glXCreateContext request */
432 GetReq(GLXCreateContext
, req
);
433 req
->reqType
= gc
->majorOpcode
;
434 req
->glxCode
= X_GLXCreateContext
;
435 req
->context
= gc
->xid
= XAllocID(dpy
);
436 req
->visual
= vis
->visualid
;
437 req
->screen
= vis
->screen
;
438 req
->shareList
= shareList
? shareList
->xid
: None
;
439 req
->isDirect
= GC_IS_DIRECT(gc
);
441 else if (use_glx_1_3
) {
442 xGLXCreateNewContextReq
*req
;
444 /* Send the glXCreateNewContext request */
445 GetReq(GLXCreateNewContext
, req
);
446 req
->reqType
= gc
->majorOpcode
;
447 req
->glxCode
= X_GLXCreateNewContext
;
448 req
->context
= gc
->xid
= XAllocID(dpy
);
449 req
->fbconfig
= fbconfig
->fbconfigID
;
450 req
->screen
= fbconfig
->screen
;
451 req
->renderType
= renderType
;
452 req
->shareList
= shareList
? shareList
->xid
: None
;
453 req
->isDirect
= GC_IS_DIRECT(gc
);
456 xGLXVendorPrivateWithReplyReq
*vpreq
;
457 xGLXCreateContextWithConfigSGIXReq
*req
;
459 /* Send the glXCreateNewContext request */
460 GetReqExtra(GLXVendorPrivateWithReply
,
461 sz_xGLXCreateContextWithConfigSGIXReq
-
462 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
463 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
464 req
->reqType
= gc
->majorOpcode
;
465 req
->glxCode
= X_GLXVendorPrivateWithReply
;
466 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
467 req
->context
= gc
->xid
= XAllocID(dpy
);
468 req
->fbconfig
= fbconfig
->fbconfigID
;
469 req
->screen
= fbconfig
->screen
;
470 req
->renderType
= renderType
;
471 req
->shareList
= shareList
? shareList
->xid
: None
;
472 req
->isDirect
= GC_IS_DIRECT(gc
);
477 gc
->imported
= GL_FALSE
;
481 gc
->imported
= GL_TRUE
;
484 gc
->renderType
= renderType
;
490 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
491 GLXContext shareList
, Bool allowDirect
)
493 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
498 __glXFreeContext(__GLXcontext
* gc
)
501 XFree((char *) gc
->vendor
);
503 XFree((char *) gc
->renderer
);
505 XFree((char *) gc
->version
);
507 XFree((char *) gc
->extensions
);
508 __glFreeAttributeState(gc
);
509 XFree((char *) gc
->buf
);
510 Xfree((char *) gc
->client_state_private
);
516 ** Destroy the named context
519 DestroyContext(Display
* dpy
, GLXContext gc
)
521 xGLXDestroyContextReq
*req
;
526 opcode
= __glXSetupForCommand(dpy
);
527 if (!opcode
|| !gc
) {
533 imported
= gc
->imported
;
536 if (gc
->currentDpy
) {
537 /* This context is bound to some thread. According to the man page,
538 * we should not actually delete the context until it's unbound.
539 * Note that we set gc->xid = None above. In MakeContextCurrent()
540 * we check for that and delete the context there.
546 #ifdef GLX_DIRECT_RENDERING
547 /* Destroy the direct rendering context */
548 if (gc
->driContext
) {
549 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
550 gc
->driContext
= NULL
;
551 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
555 __glXFreeVertexArrayState(gc
);
557 if (gc
->currentDpy
) {
558 /* Have to free later cuz it's in use now */
562 /* Destroy the handle if not current to anybody */
564 __glXFreeContext(gc
);
569 ** This dpy also created the server side part of the context.
570 ** Send the glXDestroyContext request.
573 GetReq(GLXDestroyContext
, req
);
574 req
->reqType
= opcode
;
575 req
->glxCode
= X_GLXDestroyContext
;
583 glXDestroyContext(Display
* dpy
, GLXContext gc
)
585 DestroyContext(dpy
, gc
);
589 ** Return the major and minor version #s for the GLX extension
592 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
594 __GLXdisplayPrivate
*priv
;
596 /* Init the extension. This fetches the major and minor version. */
597 priv
= __glXInitialize(dpy
);
602 *major
= priv
->majorVersion
;
604 *minor
= priv
->minorVersion
;
609 ** Query the existance of the GLX extension
612 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
614 int major_op
, erb
, evb
;
617 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
628 ** Put a barrier in the token stream that forces the GL to finish its
629 ** work before X can proceed.
635 GLXContext gc
= __glXGetCurrentContext();
636 Display
*dpy
= gc
->currentDpy
;
641 /* Flush any pending commands out */
642 __glXFlushRenderBuffer(gc
, gc
->pc
);
644 #ifdef GLX_DIRECT_RENDERING
645 if (gc
->driContext
) {
647 __GLXDRIdrawable
*pdraw
=
648 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
651 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
653 if (psc
->driScreen
->waitGL
!= NULL
)
654 (*psc
->driScreen
->waitGL
) (pdraw
);
660 /* Send the glXWaitGL request */
662 GetReq(GLXWaitGL
, req
);
663 req
->reqType
= gc
->majorOpcode
;
664 req
->glxCode
= X_GLXWaitGL
;
665 req
->contextTag
= gc
->currentContextTag
;
671 ** Put a barrier in the token stream that forces X to finish its
672 ** work before GL can proceed.
678 GLXContext gc
= __glXGetCurrentContext();
679 Display
*dpy
= gc
->currentDpy
;
684 /* Flush any pending commands out */
685 __glXFlushRenderBuffer(gc
, gc
->pc
);
687 #ifdef GLX_DIRECT_RENDERING
688 if (gc
->driContext
) {
690 __GLXDRIdrawable
*pdraw
=
691 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
694 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
695 if (psc
->driScreen
->waitX
!= NULL
)
696 (*psc
->driScreen
->waitX
) (pdraw
);
705 ** Send the glXWaitX request.
708 GetReq(GLXWaitX
, req
);
709 req
->reqType
= gc
->majorOpcode
;
710 req
->glxCode
= X_GLXWaitX
;
711 req
->contextTag
= gc
->currentContextTag
;
717 glXUseXFont(Font font
, int first
, int count
, int listBase
)
719 xGLXUseXFontReq
*req
;
720 GLXContext gc
= __glXGetCurrentContext();
721 Display
*dpy
= gc
->currentDpy
;
726 /* Flush any pending commands out */
727 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
729 #ifdef GLX_DIRECT_RENDERING
730 if (gc
->driContext
) {
731 DRI_glXUseXFont(font
, first
, count
, listBase
);
736 /* Send the glXUseFont request */
738 GetReq(GLXUseXFont
, req
);
739 req
->reqType
= gc
->majorOpcode
;
740 req
->glxCode
= X_GLXUseXFont
;
741 req
->contextTag
= gc
->currentContextTag
;
745 req
->listBase
= listBase
;
750 /************************************************************************/
753 ** Copy the source context to the destination context using the
757 glXCopyContext(Display
* dpy
, GLXContext source
,
758 GLXContext dest
, unsigned long mask
)
760 xGLXCopyContextReq
*req
;
761 GLXContext gc
= __glXGetCurrentContext();
765 opcode
= __glXSetupForCommand(dpy
);
770 #ifdef GLX_DIRECT_RENDERING
771 if (gc
->driContext
) {
772 /* NOT_DONE: This does not work yet */
777 ** If the source is the current context, send its tag so that the context
778 ** can be flushed before the copy.
780 if (source
== gc
&& dpy
== gc
->currentDpy
) {
781 tag
= gc
->currentContextTag
;
787 /* Send the glXCopyContext request */
789 GetReq(GLXCopyContext
, req
);
790 req
->reqType
= opcode
;
791 req
->glxCode
= X_GLXCopyContext
;
792 req
->source
= source
? source
->xid
: None
;
793 req
->dest
= dest
? dest
->xid
: None
;
795 req
->contextTag
= tag
;
802 * Determine if a context uses direct rendering.
804 * \param dpy Display where the context was created.
805 * \param contextID ID of the context to be tested.
807 * \returns \c GL_TRUE if the context is direct rendering or not.
810 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
812 #if !defined(USE_XCB)
813 xGLXIsDirectReq
*req
;
814 xGLXIsDirectReply reply
;
818 opcode
= __glXSetupForCommand(dpy
);
824 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
825 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
830 const Bool is_direct
= reply
->is_direct
? True
: False
;
835 /* Send the glXIsDirect request */
837 GetReq(GLXIsDirect
, req
);
838 req
->reqType
= opcode
;
839 req
->glxCode
= X_GLXIsDirect
;
840 req
->context
= contextID
;
841 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
845 return reply
.isDirect
;
851 * Shouldn't this function \b always return \c GL_FALSE when
852 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
853 * the GLX protocol here at all?
856 glXIsDirect(Display
* dpy
, GLXContext gc
)
861 else if (GC_IS_DIRECT(gc
)) {
864 return __glXIsDirect(dpy
, gc
->xid
);
868 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
870 xGLXCreateGLXPixmapReq
*req
;
874 opcode
= __glXSetupForCommand(dpy
);
879 /* Send the glXCreateGLXPixmap request */
881 GetReq(GLXCreateGLXPixmap
, req
);
882 req
->reqType
= opcode
;
883 req
->glxCode
= X_GLXCreateGLXPixmap
;
884 req
->screen
= vis
->screen
;
885 req
->visual
= vis
->visualid
;
886 req
->pixmap
= pixmap
;
887 req
->glxpixmap
= xid
= XAllocID(dpy
);
891 #ifdef GLX_DIRECT_RENDERING
893 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
894 * is actually bound to a context... */
896 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
897 __GLXDRIdrawable
*pdraw
;
898 __GLXscreenConfigs
*psc
;
899 __GLcontextModes
*modes
;
901 psc
= &priv
->screenConfigs
[vis
->screen
];
902 if (psc
->driScreen
== NULL
)
904 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
905 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
907 fprintf(stderr
, "failed to create pixmap\n");
911 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
912 (*pdraw
->destroyDrawable
) (pdraw
);
913 return None
; /* FIXME: Check what we're supposed to do here... */
922 ** Destroy the named pixmap
925 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
927 xGLXDestroyGLXPixmapReq
*req
;
930 opcode
= __glXSetupForCommand(dpy
);
935 /* Send the glXDestroyGLXPixmap request */
937 GetReq(GLXDestroyGLXPixmap
, req
);
938 req
->reqType
= opcode
;
939 req
->glxCode
= X_GLXDestroyGLXPixmap
;
940 req
->glxpixmap
= glxpixmap
;
944 #ifdef GLX_DIRECT_RENDERING
947 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
948 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
949 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
952 (*pdraw
->destroyDrawable
) (pdraw
);
953 __glxHashDelete(psc
->drawHash
, glxpixmap
);
960 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
968 xGLXSwapBuffersReq
*req
;
971 #ifdef GLX_DIRECT_RENDERING
972 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
976 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
981 opcode
= __glXSetupForCommand(dpy
);
987 ** The calling thread may or may not have a current context. If it
988 ** does, send the context tag so the server can do a flush.
990 gc
= __glXGetCurrentContext();
991 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
992 ((drawable
== gc
->currentDrawable
)
993 || (drawable
== gc
->currentReadable
))) {
994 tag
= gc
->currentContextTag
;
1001 c
= XGetXCBConnection(dpy
);
1002 xcb_glx_swap_buffers(c
, tag
, drawable
);
1005 /* Send the glXSwapBuffers request */
1007 GetReq(GLXSwapBuffers
, req
);
1008 req
->reqType
= opcode
;
1009 req
->glxCode
= X_GLXSwapBuffers
;
1010 req
->drawable
= drawable
;
1011 req
->contextTag
= tag
;
1015 #endif /* USE_XCB */
1020 ** Return configuration information for the given display, screen and
1021 ** visual combination.
1024 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1027 __GLXdisplayPrivate
*priv
;
1028 __GLXscreenConfigs
*psc
;
1029 __GLcontextModes
*modes
;
1032 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1033 if (status
== Success
) {
1034 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1036 /* Lookup attribute after first finding a match on the visual */
1037 if (modes
!= NULL
) {
1038 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1041 status
= GLX_BAD_VISUAL
;
1045 ** If we can't find the config for this visual, this visual is not
1046 ** supported by the OpenGL implementation on the server.
1048 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1049 *value_return
= GL_FALSE
;
1056 /************************************************************************/
1059 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1060 GLboolean fbconfig_style_tags
)
1062 memset(config
, 0, sizeof(__GLcontextModes
));
1063 config
->visualID
= (XID
) GLX_DONT_CARE
;
1064 config
->visualType
= GLX_DONT_CARE
;
1066 /* glXChooseFBConfig specifies different defaults for these two than
1069 if (fbconfig_style_tags
) {
1070 config
->rgbMode
= GL_TRUE
;
1071 config
->doubleBufferMode
= GLX_DONT_CARE
;
1074 config
->visualRating
= GLX_DONT_CARE
;
1075 config
->transparentPixel
= GLX_NONE
;
1076 config
->transparentRed
= GLX_DONT_CARE
;
1077 config
->transparentGreen
= GLX_DONT_CARE
;
1078 config
->transparentBlue
= GLX_DONT_CARE
;
1079 config
->transparentAlpha
= GLX_DONT_CARE
;
1080 config
->transparentIndex
= GLX_DONT_CARE
;
1082 config
->drawableType
= GLX_WINDOW_BIT
;
1083 config
->renderType
=
1084 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1085 config
->xRenderable
= GLX_DONT_CARE
;
1086 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1088 config
->swapMethod
= GLX_DONT_CARE
;
1091 #define MATCH_DONT_CARE( param ) \
1093 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1094 && (a-> param != b-> param) ) { \
1099 #define MATCH_MINIMUM( param ) \
1101 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1102 && (a-> param > b-> param) ) { \
1107 #define MATCH_EXACT( param ) \
1109 if ( a-> param != b-> param) { \
1115 * Determine if two GLXFBConfigs are compatible.
1117 * \param a Application specified config to test.
1118 * \param b Server specified config to test against \c a.
1121 fbconfigs_compatible(const __GLcontextModes
* const a
,
1122 const __GLcontextModes
* const b
)
1124 MATCH_DONT_CARE(doubleBufferMode
);
1125 MATCH_DONT_CARE(visualType
);
1126 MATCH_DONT_CARE(visualRating
);
1127 MATCH_DONT_CARE(xRenderable
);
1128 MATCH_DONT_CARE(fbconfigID
);
1129 MATCH_DONT_CARE(swapMethod
);
1131 MATCH_MINIMUM(rgbBits
);
1132 MATCH_MINIMUM(numAuxBuffers
);
1133 MATCH_MINIMUM(redBits
);
1134 MATCH_MINIMUM(greenBits
);
1135 MATCH_MINIMUM(blueBits
);
1136 MATCH_MINIMUM(alphaBits
);
1137 MATCH_MINIMUM(depthBits
);
1138 MATCH_MINIMUM(stencilBits
);
1139 MATCH_MINIMUM(accumRedBits
);
1140 MATCH_MINIMUM(accumGreenBits
);
1141 MATCH_MINIMUM(accumBlueBits
);
1142 MATCH_MINIMUM(accumAlphaBits
);
1143 MATCH_MINIMUM(sampleBuffers
);
1144 MATCH_MINIMUM(maxPbufferWidth
);
1145 MATCH_MINIMUM(maxPbufferHeight
);
1146 MATCH_MINIMUM(maxPbufferPixels
);
1147 MATCH_MINIMUM(samples
);
1149 MATCH_DONT_CARE(stereoMode
);
1152 if (((a
->drawableType
& b
->drawableType
) == 0)
1153 || ((a
->renderType
& b
->renderType
) == 0)) {
1158 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1159 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1160 * Technically speaking, it is a bug in the DDX driver, but there is
1161 * enough of an installed base to work around the problem here. In any
1162 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1163 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1164 * 0 from the server to be a match to maintain backward compatibility with
1165 * the (broken) drivers.
1168 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1169 if (a
->transparentPixel
== GLX_NONE
) {
1170 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1174 MATCH_EXACT(transparentPixel
);
1177 switch (a
->transparentPixel
) {
1178 case GLX_TRANSPARENT_RGB
:
1179 MATCH_DONT_CARE(transparentRed
);
1180 MATCH_DONT_CARE(transparentGreen
);
1181 MATCH_DONT_CARE(transparentBlue
);
1182 MATCH_DONT_CARE(transparentAlpha
);
1185 case GLX_TRANSPARENT_INDEX
:
1186 MATCH_DONT_CARE(transparentIndex
);
1198 /* There's some trickly language in the GLX spec about how this is supposed
1199 * to work. Basically, if a given component size is either not specified
1200 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1201 * Well, that's really hard to do with the code as-is. This behavior is
1202 * closer to correct, but still not technically right.
1204 #define PREFER_LARGER_OR_ZERO(comp) \
1206 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1207 if ( ((*a)-> comp) == 0 ) { \
1210 else if ( ((*b)-> comp) == 0 ) { \
1214 return ((*b)-> comp) - ((*a)-> comp) ; \
1219 #define PREFER_LARGER(comp) \
1221 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1222 return ((*b)-> comp) - ((*a)-> comp) ; \
1226 #define PREFER_SMALLER(comp) \
1228 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1229 return ((*a)-> comp) - ((*b)-> comp) ; \
1234 * Compare two GLXFBConfigs. This function is intended to be used as the
1235 * compare function passed in to qsort.
1237 * \returns If \c a is a "better" config, according to the specification of
1238 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1239 * better, then a number greater than zero is return. If both are
1240 * equal, zero is returned.
1241 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1244 fbconfig_compare(const __GLcontextModes
* const *const a
,
1245 const __GLcontextModes
* const *const b
)
1247 /* The order of these comparisons must NOT change. It is defined by
1248 * the GLX 1.3 spec and ARB_multisample.
1251 PREFER_SMALLER(visualSelectGroup
);
1253 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1254 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1255 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1257 PREFER_SMALLER(visualRating
);
1259 /* This isn't quite right. It is supposed to compare the sum of the
1260 * components the user specifically set minimums for.
1262 PREFER_LARGER_OR_ZERO(redBits
);
1263 PREFER_LARGER_OR_ZERO(greenBits
);
1264 PREFER_LARGER_OR_ZERO(blueBits
);
1265 PREFER_LARGER_OR_ZERO(alphaBits
);
1267 PREFER_SMALLER(rgbBits
);
1269 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1270 /* Prefer single-buffer.
1272 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1275 PREFER_SMALLER(numAuxBuffers
);
1277 PREFER_LARGER_OR_ZERO(depthBits
);
1278 PREFER_SMALLER(stencilBits
);
1280 /* This isn't quite right. It is supposed to compare the sum of the
1281 * components the user specifically set minimums for.
1283 PREFER_LARGER_OR_ZERO(accumRedBits
);
1284 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1285 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1286 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1288 PREFER_SMALLER(visualType
);
1290 /* None of the multisample specs say where this comparison should happen,
1291 * so I put it near the end.
1293 PREFER_SMALLER(sampleBuffers
);
1294 PREFER_SMALLER(samples
);
1296 /* None of the pbuffer or fbconfig specs say that this comparison needs
1297 * to happen at all, but it seems like it should.
1299 PREFER_LARGER(maxPbufferWidth
);
1300 PREFER_LARGER(maxPbufferHeight
);
1301 PREFER_LARGER(maxPbufferPixels
);
1308 * Selects and sorts a subset of the supplied configs based on the attributes.
1309 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1310 * and \c glXChooseFBConfigSGIX.
1312 * \param configs Array of pointers to possible configs. The elements of
1313 * this array that do not meet the criteria will be set to
1314 * NULL. The remaining elements will be sorted according to
1315 * the various visual / FBConfig selection rules.
1316 * \param num_configs Number of elements in the \c configs array.
1317 * \param attribList Attributes used select from \c configs. This array is
1318 * terminated by a \c None tag. The array can either take
1319 * the form expected by \c glXChooseVisual (where boolean
1320 * tags do not have a value) or by \c glXChooseFBConfig
1321 * (where every tag has a value).
1322 * \param fbconfig_style_tags Selects whether \c attribList is in
1323 * \c glXChooseVisual style or
1324 * \c glXChooseFBConfig style.
1325 * \returns The number of valid elements left in \c configs.
1327 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1330 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1331 const int *attribList
, GLboolean fbconfig_style_tags
)
1333 __GLcontextModes test_config
;
1337 /* This is a fairly direct implementation of the selection method
1338 * described by GLX_SGIX_fbconfig. Start by culling out all the
1339 * configs that are not compatible with the selected parameter
1343 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1344 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1345 (const INT32
*) attribList
,
1346 GL_TRUE
, fbconfig_style_tags
);
1349 for (i
= 0; i
< num_configs
; i
++) {
1350 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1351 configs
[base
] = configs
[i
];
1360 if (base
< num_configs
) {
1361 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1364 /* After the incompatible configs are removed, the resulting
1365 * list is sorted according to the rules set out in the various
1369 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1370 (int (*)(const void *, const void *)) fbconfig_compare
);
1378 ** Return the visual that best matches the template. Return None if no
1379 ** visual matches the template.
1381 PUBLIC XVisualInfo
*
1382 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1384 XVisualInfo
*visualList
= NULL
;
1385 __GLXdisplayPrivate
*priv
;
1386 __GLXscreenConfigs
*psc
;
1387 __GLcontextModes test_config
;
1388 __GLcontextModes
*modes
;
1389 const __GLcontextModes
*best_config
= NULL
;
1392 ** Get a list of all visuals, return if list is empty
1394 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1400 ** Build a template from the defaults and the attribute list
1401 ** Free visual list and return if an unexpected token is encountered
1403 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1404 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1405 (const INT32
*) attribList
,
1409 ** Eliminate visuals that don't meet minimum requirements
1410 ** Compute a score for those that do
1411 ** Remember which visual, if any, got the highest score
1412 ** If no visual is acceptable, return None
1413 ** Otherwise, create an XVisualInfo list with just the selected X visual
1416 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1417 if (fbconfigs_compatible(&test_config
, modes
)
1418 && ((best_config
== NULL
)
1421 ((const __GLcontextModes
* const *const) &modes
,
1422 &best_config
) < 0))) {
1423 XVisualInfo visualTemplate
;
1424 XVisualInfo
*newList
;
1427 visualTemplate
.screen
= screen
;
1428 visualTemplate
.visualid
= modes
->visualID
;
1429 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1430 &visualTemplate
, &i
);
1434 visualList
= newList
;
1435 best_config
= modes
;
1445 glXQueryExtensionsString(Display
* dpy
, int screen
)
1447 __GLXscreenConfigs
*psc
;
1448 __GLXdisplayPrivate
*priv
;
1450 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1454 if (!psc
->effectiveGLXexts
) {
1455 if (!psc
->serverGLXexts
) {
1456 psc
->serverGLXexts
=
1457 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1461 __glXCalculateUsableExtensions(psc
,
1462 #ifdef GLX_DIRECT_RENDERING
1463 (psc
->driScreen
!= NULL
),
1467 priv
->minorVersion
);
1470 return psc
->effectiveGLXexts
;
1474 glXGetClientString(Display
* dpy
, int name
)
1480 return (__glXGLXClientVendorName
);
1482 return (__glXGLXClientVersion
);
1483 case GLX_EXTENSIONS
:
1484 return (__glXGetClientExtensions());
1491 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1493 __GLXscreenConfigs
*psc
;
1494 __GLXdisplayPrivate
*priv
;
1498 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1504 str
= &priv
->serverGLXvendor
;
1507 str
= &priv
->serverGLXversion
;
1509 case GLX_EXTENSIONS
:
1510 str
= &psc
->serverGLXexts
;
1517 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1524 __glXClientInfo(Display
* dpy
, int opcode
)
1526 char *ext_str
= __glXGetClientGLExtensionString();
1527 int size
= strlen(ext_str
) + 1;
1530 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1531 xcb_glx_client_info(c
,
1532 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1534 xGLXClientInfoReq
*req
;
1536 /* Send the glXClientInfo request */
1538 GetReq(GLXClientInfo
, req
);
1539 req
->reqType
= opcode
;
1540 req
->glxCode
= X_GLXClientInfo
;
1541 req
->major
= GLX_MAJOR_VERSION
;
1542 req
->minor
= GLX_MINOR_VERSION
;
1544 req
->length
+= (size
+ 3) >> 2;
1545 req
->numbytes
= size
;
1546 Data(dpy
, ext_str
, size
);
1550 #endif /* USE_XCB */
1557 ** EXT_import_context
1561 glXGetCurrentDisplay(void)
1563 GLXContext gc
= __glXGetCurrentContext();
1566 return gc
->currentDpy
;
1570 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1571 glXGetCurrentDisplay
)
1574 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1577 * \param dpy Display where \c ctx was created.
1578 * \param ctx Context to query.
1579 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1580 * or zero if the request failed due to internal problems (i.e.,
1581 * unable to allocate temporary memory, etc.)
1584 * This function dynamically determines whether to use the EXT_import_context
1585 * version of the protocol or the GLX 1.3 version of the protocol.
1587 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1589 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1590 xGLXQueryContextReply reply
;
1596 return GLX_BAD_CONTEXT
;
1598 opcode
= __glXSetupForCommand(dpy
);
1603 /* Send the glXQueryContextInfoEXT request */
1606 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1607 xGLXQueryContextReq
*req
;
1609 GetReq(GLXQueryContext
, req
);
1611 req
->reqType
= opcode
;
1612 req
->glxCode
= X_GLXQueryContext
;
1613 req
->context
= (unsigned int) (ctx
->xid
);
1616 xGLXVendorPrivateReq
*vpreq
;
1617 xGLXQueryContextInfoEXTReq
*req
;
1619 GetReqExtra(GLXVendorPrivate
,
1620 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1622 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1623 req
->reqType
= opcode
;
1624 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1625 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1626 req
->context
= (unsigned int) (ctx
->xid
);
1629 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1631 numValues
= reply
.n
;
1634 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1637 int *propList
, *pProp
;
1640 nPropListBytes
= numValues
<< 3;
1641 propList
= (int *) Xmalloc(nPropListBytes
);
1642 if (NULL
== propList
) {
1648 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1650 for (i
= 0; i
< numValues
; i
++) {
1652 case GLX_SHARE_CONTEXT_EXT
:
1653 ctx
->share_xid
= *pProp
++;
1655 case GLX_VISUAL_ID_EXT
:
1657 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1660 ctx
->screen
= *pProp
++;
1662 case GLX_FBCONFIG_ID
:
1664 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1667 case GLX_RENDER_TYPE
:
1668 ctx
->renderType
= *pProp
++;
1675 Xfree((char *) propList
);
1685 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1689 /* get the information from the server if we don't have it already */
1690 #ifdef GLX_DIRECT_RENDERING
1691 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1693 if (ctx
->mode
== NULL
) {
1695 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1696 if (Success
!= retVal
)
1699 switch (attribute
) {
1700 case GLX_SHARE_CONTEXT_EXT
:
1701 *value
= (int) (ctx
->share_xid
);
1703 case GLX_VISUAL_ID_EXT
:
1704 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1707 *value
= (int) (ctx
->screen
);
1709 case GLX_FBCONFIG_ID
:
1710 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1712 case GLX_RENDER_TYPE
:
1713 *value
= (int) (ctx
->renderType
);
1716 return GLX_BAD_ATTRIBUTE
;
1722 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1723 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1724 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1726 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1732 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1736 if (contextID
== None
) {
1739 if (__glXIsDirect(dpy
, contextID
)) {
1743 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1745 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1753 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1755 DestroyContext(dpy
, ctx
);
1761 * GLX 1.3 functions - these are just stubs for now!
1764 PUBLIC GLXFBConfig
*
1765 glXChooseFBConfig(Display
* dpy
, int screen
,
1766 const int *attribList
, int *nitems
)
1768 __GLcontextModes
**config_list
;
1772 config_list
= (__GLcontextModes
**)
1773 glXGetFBConfigs(dpy
, screen
, &list_size
);
1775 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1776 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1777 if (list_size
== 0) {
1783 *nitems
= list_size
;
1784 return (GLXFBConfig
*) config_list
;
1789 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1790 int renderType
, GLXContext shareList
, Bool allowDirect
)
1792 return CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1793 allowDirect
, None
, True
, renderType
);
1798 glXGetCurrentReadDrawable(void)
1800 GLXContext gc
= __glXGetCurrentContext();
1801 return gc
->currentReadable
;
1805 PUBLIC GLXFBConfig
*
1806 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1808 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1809 __GLcontextModes
**config
= NULL
;
1813 if (priv
&& (priv
->screenConfigs
!= NULL
)
1814 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1815 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1816 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
1817 != (int) GLX_DONT_CARE
)) {
1818 unsigned num_configs
= 0;
1819 __GLcontextModes
*modes
;
1822 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1823 modes
= modes
->next
) {
1824 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1829 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1831 if (config
!= NULL
) {
1832 *nelements
= num_configs
;
1834 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1835 modes
= modes
->next
) {
1836 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1843 return (GLXFBConfig
*) config
;
1848 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1849 int attribute
, int *value
)
1851 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1853 return (modes
!= NULL
)
1854 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1859 PUBLIC XVisualInfo
*
1860 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1862 XVisualInfo visualTemplate
;
1863 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1867 ** Get a list of all visuals, return if list is empty
1869 visualTemplate
.visualid
= fbconfig
->visualID
;
1870 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1875 ** GLX_SGI_swap_control
1878 __glXSwapIntervalSGI(int interval
)
1880 xGLXVendorPrivateReq
*req
;
1881 GLXContext gc
= __glXGetCurrentContext();
1882 __GLXscreenConfigs
*psc
;
1884 CARD32
*interval_ptr
;
1888 return GLX_BAD_CONTEXT
;
1891 if (interval
<= 0) {
1892 return GLX_BAD_VALUE
;
1895 #ifdef __DRI_SWAP_CONTROL
1896 if (gc
->driContext
) {
1897 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1899 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1900 gc
->currentDrawable
,
1902 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1903 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1906 else if (pdraw
== NULL
) {
1907 return GLX_BAD_CONTEXT
;
1911 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1913 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1914 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1915 gc
->currentDrawable
,
1917 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1921 dpy
= gc
->currentDpy
;
1922 opcode
= __glXSetupForCommand(dpy
);
1927 /* Send the glXSwapIntervalSGI request */
1929 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1930 req
->reqType
= opcode
;
1931 req
->glxCode
= X_GLXVendorPrivate
;
1932 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1933 req
->contextTag
= gc
->currentContextTag
;
1935 interval_ptr
= (CARD32
*) (req
+ 1);
1936 *interval_ptr
= interval
;
1947 ** GLX_MESA_swap_control
1950 __glXSwapIntervalMESA(unsigned int interval
)
1952 GLXContext gc
= __glXGetCurrentContext();
1955 return GLX_BAD_VALUE
;
1958 #ifdef __DRI_SWAP_CONTROL
1959 if (gc
!= NULL
&& gc
->driContext
) {
1960 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1963 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1964 __GLXDRIdrawable
*pdraw
=
1965 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1966 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1967 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1974 if (gc
!= NULL
&& gc
->driContext
) {
1975 __GLXscreenConfigs
*psc
;
1977 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1978 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1979 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1980 gc
->currentDrawable
, NULL
);
1981 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1986 return GLX_BAD_CONTEXT
;
1991 __glXGetSwapIntervalMESA(void)
1993 #ifdef __DRI_SWAP_CONTROL
1994 GLXContext gc
= __glXGetCurrentContext();
1996 if (gc
!= NULL
&& gc
->driContext
) {
1997 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2000 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2001 __GLXDRIdrawable
*pdraw
=
2002 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2003 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2004 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2009 if (gc
!= NULL
&& gc
->driContext
) {
2010 __GLXscreenConfigs
*psc
;
2012 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2013 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2014 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2015 gc
->currentDrawable
, NULL
);
2016 return psc
->driScreen
->getSwapInterval(pdraw
);
2025 ** GLX_MESA_swap_frame_usage
2029 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2031 int status
= GLX_BAD_CONTEXT
;
2032 #ifdef __DRI_FRAME_TRACKING
2034 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2035 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2037 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2038 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2048 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2050 int status
= GLX_BAD_CONTEXT
;
2051 #ifdef __DRI_FRAME_TRACKING
2053 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2054 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2056 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2057 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2068 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2070 int status
= GLX_BAD_CONTEXT
;
2071 #ifdef __DRI_FRAME_TRACKING
2073 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2074 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2076 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2077 int64_t sbc
, missedFrames
;
2078 float lastMissedUsage
;
2080 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2096 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2097 int64_t * sbc
, int64_t * missedFrames
,
2098 GLfloat
* lastMissedUsage
)
2100 int status
= GLX_BAD_CONTEXT
;
2101 #ifdef __DRI_FRAME_TRACKING
2103 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2104 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2106 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2109 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2118 (void) missedFrames
;
2119 (void) lastMissedUsage
;
2126 ** GLX_SGI_video_sync
2129 __glXGetVideoSyncSGI(unsigned int *count
)
2131 int64_t ust
, msc
, sbc
;
2133 GLXContext gc
= __glXGetCurrentContext();
2134 __GLXscreenConfigs
*psc
;
2135 __GLXDRIdrawable
*pdraw
;
2137 if (!gc
|| !gc
->driContext
)
2138 return GLX_BAD_CONTEXT
;
2140 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2141 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2143 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2144 * FIXME: there should be a GLX encoding for this call. I can find no
2145 * FIXME: documentation for the GLX encoding.
2147 #ifdef __DRI_MEDIA_STREAM_COUNTER
2148 if ( psc
->msc
&& psc
->driScreen
) {
2149 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2150 pdraw
->driDrawable
, &msc
);
2151 *count
= (unsigned) msc
;
2153 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2156 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2157 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2158 *count
= (unsigned) msc
;
2159 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2162 return GLX_BAD_CONTEXT
;
2166 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2168 GLXContext gc
= __glXGetCurrentContext();
2169 __GLXscreenConfigs
*psc
;
2170 __GLXDRIdrawable
*pdraw
;
2171 int64_t ust
, msc
, sbc
;
2174 if (divisor
<= 0 || remainder
< 0)
2175 return GLX_BAD_VALUE
;
2177 if (!gc
|| !gc
->driContext
)
2178 return GLX_BAD_CONTEXT
;
2180 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2181 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2183 #ifdef __DRI_MEDIA_STREAM_COUNTER
2184 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2185 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2186 divisor
, remainder
, &msc
, &sbc
);
2187 *count
= (unsigned) msc
;
2188 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2191 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2192 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2194 *count
= (unsigned) msc
;
2195 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2198 return GLX_BAD_CONTEXT
;
2203 ** GLX_SGIX_fbconfig
2204 ** Many of these functions are aliased to GLX 1.3 entry points in the
2205 ** GLX_functions table.
2209 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2210 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2211 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2213 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2214 (Display
* dpy
, int screen
, int *attrib_list
,
2215 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2218 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2219 (Display
* dpy
, GLXFBConfigSGIX config
),
2220 (dpy
, config
), glXGetVisualFromFBConfig
)
2223 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2224 GLXFBConfigSGIX config
,
2227 xGLXVendorPrivateWithReplyReq
*vpreq
;
2228 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2229 GLXPixmap xid
= None
;
2231 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2232 __GLXscreenConfigs
*psc
;
2235 if ((dpy
== NULL
) || (config
== NULL
)) {
2239 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2241 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2242 opcode
= __glXSetupForCommand(dpy
);
2247 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2249 GetReqExtra(GLXVendorPrivateWithReply
,
2250 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2251 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2252 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2253 req
->reqType
= opcode
;
2254 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2255 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2256 req
->screen
= fbconfig
->screen
;
2257 req
->fbconfig
= fbconfig
->fbconfigID
;
2258 req
->pixmap
= pixmap
;
2259 req
->glxpixmap
= xid
= XAllocID(dpy
);
2268 glXCreateContextWithConfigSGIX(Display
* dpy
,
2269 GLXFBConfigSGIX config
, int renderType
,
2270 GLXContext shareList
, Bool allowDirect
)
2272 GLXContext gc
= NULL
;
2273 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2274 __GLXscreenConfigs
*psc
;
2277 if ((dpy
== NULL
) || (config
== NULL
)) {
2281 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2283 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2284 gc
= CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2285 allowDirect
, None
, False
, renderType
);
2292 PUBLIC GLXFBConfigSGIX
2293 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2295 __GLXdisplayPrivate
*priv
;
2296 __GLXscreenConfigs
*psc
= NULL
;
2298 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2299 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2300 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2301 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2310 ** GLX_SGIX_swap_group
2313 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2323 ** GLX_SGIX_swap_barrier
2326 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2334 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2344 ** GLX_OML_sync_control
2347 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2348 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2350 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2352 __GLXDRIdrawable
*pdraw
;
2353 __GLXscreenConfigs
*psc
;
2358 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2359 psc
= &priv
->screenConfigs
[i
];
2361 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2362 if (pdraw
&& psc
->sbc
&& psc
->sbc
)
2363 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2364 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2365 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2366 && (__glXGetUST(ust
) == 0) );
2368 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2369 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2376 #ifdef GLX_DIRECT_RENDERING
2378 __driGetMscRateOML(__DRIdrawable
* draw
,
2379 int32_t * numerator
, int32_t * denominator
, void *private)
2382 __GLXscreenConfigs
*psc
;
2383 XF86VidModeModeLine mode_line
;
2386 __GLXDRIdrawable
*glxDraw
= private;
2391 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2392 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2393 unsigned n
= dot_clock
* 1000;
2394 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2396 # define V_INTERLACE 0x010
2397 # define V_DBLSCAN 0x020
2399 if (mode_line
.flags
& V_INTERLACE
)
2401 else if (mode_line
.flags
& V_DBLSCAN
)
2404 /* The OML_sync_control spec requires that if the refresh rate is a
2405 * whole number, that the returned numerator be equal to the refresh
2406 * rate and the denominator be 1.
2414 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2416 /* This is a poor man's way to reduce a fraction. It's far from
2417 * perfect, but it will work well enough for this situation.
2420 for (i
= 0; f
[i
] != 0; i
++) {
2421 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2447 * Determine the refresh rate of the specified drawable and display.
2449 * \param dpy Display whose refresh rate is to be determined.
2450 * \param drawable Drawable whose refresh rate is to be determined.
2451 * \param numerator Numerator of the refresh rate.
2452 * \param demoninator Denominator of the refresh rate.
2453 * \return If the refresh rate for the specified display and drawable could
2454 * be calculated, True is returned. Otherwise False is returned.
2456 * \note This function is implemented entirely client-side. A lot of other
2457 * functionality is required to export GLX_OML_sync_control, so on
2458 * XFree86 this function can be called for direct-rendering contexts
2459 * when GLX_OML_sync_control appears in the client extension string.
2463 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2464 int32_t * numerator
, int32_t * denominator
)
2466 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2467 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2472 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2484 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2485 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2487 GLXContext gc
= __glXGetCurrentContext();
2489 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2490 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2492 if (!pdraw
|| !gc
->driContext
) /* no GLX for this */
2495 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2496 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2497 * of -1 if the function failed because of errors detected in the input
2500 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2502 if (divisor
> 0 && remainder
>= divisor
)
2505 #ifdef __DRI_SWAP_BUFFER_COUNTER
2506 if (psc
->counters
!= NULL
)
2507 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2508 divisor
, remainder
);
2511 #ifdef GLX_DIRECT_RENDERING
2512 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2513 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2522 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2523 int64_t target_msc
, int64_t divisor
,
2524 int64_t remainder
, int64_t * ust
,
2525 int64_t * msc
, int64_t * sbc
)
2528 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2529 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2532 fprintf(stderr
, "waitmsc: %lld, %lld, %lld\n", target_msc
, divisor
,
2535 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2536 * error", but the return type in the spec is Bool.
2538 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2540 if (divisor
> 0 && remainder
>= divisor
)
2543 #ifdef __DRI_MEDIA_STREAM_COUNTER
2544 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2545 fprintf(stderr
, "dri1 msc\n");
2546 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2547 divisor
, remainder
, msc
, sbc
);
2549 /* __glXGetUST returns zero on success and non-zero on failure.
2550 * This function returns True on success and False on failure.
2552 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2555 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2556 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2561 fprintf(stderr
, "no drawable??\n");
2567 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2568 int64_t target_sbc
, int64_t * ust
,
2569 int64_t * msc
, int64_t * sbc
)
2572 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2573 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2576 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2577 * error", but the return type in the spec is Bool.
2581 #ifdef __DRI_SWAP_BUFFER_COUNTER
2582 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2584 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2586 /* __glXGetUST returns zero on success and non-zero on failure.
2587 * This function returns True on success and False on failure.
2589 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2592 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2593 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2601 * GLX_MESA_allocate_memory
2606 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2607 size_t size
, float readFreq
,
2608 float writeFreq
, float priority
)
2610 #ifdef __DRI_ALLOCATE
2611 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2613 if (psc
&& psc
->allocate
)
2614 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2615 readFreq
, writeFreq
, priority
);
2624 #endif /* __DRI_ALLOCATE */
2631 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2633 #ifdef __DRI_ALLOCATE
2634 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2636 if (psc
&& psc
->allocate
)
2637 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2643 #endif /* __DRI_ALLOCATE */
2648 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2650 #ifdef __DRI_ALLOCATE
2651 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2653 if (psc
&& psc
->allocate
)
2654 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2660 #endif /* GLX_DIRECT_RENDERING */
2669 * Mesa extension stubs. These will help reduce portability problems.
2674 * Release all buffers associated with the specified GLX drawable.
2677 * This function was intended for stand-alone Mesa. The issue there is that
2678 * the library doesn't get any notification when a window is closed. In
2679 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2680 * supported, there are 3 different functions to destroy a drawable. It
2681 * should be possible to create GLX protocol (or have it determine which
2682 * protocol to use based on the type of the drawable) to have one function
2683 * do the work of 3. For the direct-rendering case, this function could
2684 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2685 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2686 * would need to be used. This really should be done as part of the new DRI
2689 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2690 * __driGarbageCollectDrawables
2691 * glXDestroyGLXPixmap
2692 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2693 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2696 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2705 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2706 Pixmap pixmap
, Colormap cmap
)
2719 * GLX_MESA_copy_sub_buffer
2721 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2723 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2724 int x
, int y
, int width
, int height
)
2726 xGLXVendorPrivateReq
*req
;
2729 CARD32
*drawable_ptr
;
2730 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2733 #ifdef __DRI_COPY_SUB_BUFFER
2735 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2736 if (pdraw
!= NULL
) {
2737 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2738 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2740 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2747 opcode
= __glXSetupForCommand(dpy
);
2752 ** The calling thread may or may not have a current context. If it
2753 ** does, send the context tag so the server can do a flush.
2755 gc
= __glXGetCurrentContext();
2756 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2757 ((drawable
== gc
->currentDrawable
) ||
2758 (drawable
== gc
->currentReadable
))) {
2759 tag
= gc
->currentContextTag
;
2766 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2767 req
->reqType
= opcode
;
2768 req
->glxCode
= X_GLXVendorPrivate
;
2769 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2770 req
->contextTag
= tag
;
2772 drawable_ptr
= (CARD32
*) (req
+ 1);
2773 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2774 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2775 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2776 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2778 *drawable_ptr
= drawable
;
2790 * GLX_EXT_texture_from_pixmap
2794 __glXBindTexImageEXT(Display
* dpy
,
2795 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2797 xGLXVendorPrivateReq
*req
;
2798 GLXContext gc
= __glXGetCurrentContext();
2799 CARD32
*drawable_ptr
;
2801 CARD32
*num_attrib_ptr
;
2811 while (attrib_list
[i
* 2] != None
)
2815 #ifdef GLX_DIRECT_RENDERING
2816 if (gc
->driContext
) {
2817 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2819 if (pdraw
!= NULL
) {
2820 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2821 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2822 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2823 pdraw
->textureTarget
,
2824 pdraw
->textureFormat
,
2825 pdraw
->driDrawable
);
2828 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2829 pdraw
->textureTarget
,
2830 pdraw
->driDrawable
);
2837 opcode
= __glXSetupForCommand(dpy
);
2842 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2843 req
->reqType
= opcode
;
2844 req
->glxCode
= X_GLXVendorPrivate
;
2845 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2846 req
->contextTag
= gc
->currentContextTag
;
2848 drawable_ptr
= (CARD32
*) (req
+ 1);
2849 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2850 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2851 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2853 *drawable_ptr
= drawable
;
2854 *buffer_ptr
= buffer
;
2855 *num_attrib_ptr
= (CARD32
) i
;
2859 while (attrib_list
[i
* 2] != None
) {
2860 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2861 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2871 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2873 xGLXVendorPrivateReq
*req
;
2874 GLXContext gc
= __glXGetCurrentContext();
2875 CARD32
*drawable_ptr
;
2879 if ((gc
== NULL
) || GC_IS_DIRECT(gc
))
2882 opcode
= __glXSetupForCommand(dpy
);
2887 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2888 req
->reqType
= opcode
;
2889 req
->glxCode
= X_GLXVendorPrivate
;
2890 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2891 req
->contextTag
= gc
->currentContextTag
;
2893 drawable_ptr
= (CARD32
*) (req
+ 1);
2894 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2896 *drawable_ptr
= drawable
;
2897 *buffer_ptr
= buffer
;
2906 * \c strdup is actually not a standard ANSI C or POSIX routine.
2907 * Irix will not define it if ANSI mode is in effect.
2912 __glXstrdup(const char *str
)
2915 copy
= (char *) Xmalloc(strlen(str
) + 1);
2923 ** glXGetProcAddress support
2926 struct name_address_pair
2932 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2933 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2935 static const struct name_address_pair GLX_functions
[] = {
2936 /*** GLX_VERSION_1_0 ***/
2937 GLX_FUNCTION(glXChooseVisual
),
2938 GLX_FUNCTION(glXCopyContext
),
2939 GLX_FUNCTION(glXCreateContext
),
2940 GLX_FUNCTION(glXCreateGLXPixmap
),
2941 GLX_FUNCTION(glXDestroyContext
),
2942 GLX_FUNCTION(glXDestroyGLXPixmap
),
2943 GLX_FUNCTION(glXGetConfig
),
2944 GLX_FUNCTION(glXGetCurrentContext
),
2945 GLX_FUNCTION(glXGetCurrentDrawable
),
2946 GLX_FUNCTION(glXIsDirect
),
2947 GLX_FUNCTION(glXMakeCurrent
),
2948 GLX_FUNCTION(glXQueryExtension
),
2949 GLX_FUNCTION(glXQueryVersion
),
2950 GLX_FUNCTION(glXSwapBuffers
),
2951 GLX_FUNCTION(glXUseXFont
),
2952 GLX_FUNCTION(glXWaitGL
),
2953 GLX_FUNCTION(glXWaitX
),
2955 /*** GLX_VERSION_1_1 ***/
2956 GLX_FUNCTION(glXGetClientString
),
2957 GLX_FUNCTION(glXQueryExtensionsString
),
2958 GLX_FUNCTION(glXQueryServerString
),
2960 /*** GLX_VERSION_1_2 ***/
2961 GLX_FUNCTION(glXGetCurrentDisplay
),
2963 /*** GLX_VERSION_1_3 ***/
2964 GLX_FUNCTION(glXChooseFBConfig
),
2965 GLX_FUNCTION(glXCreateNewContext
),
2966 GLX_FUNCTION(glXCreatePbuffer
),
2967 GLX_FUNCTION(glXCreatePixmap
),
2968 GLX_FUNCTION(glXCreateWindow
),
2969 GLX_FUNCTION(glXDestroyPbuffer
),
2970 GLX_FUNCTION(glXDestroyPixmap
),
2971 GLX_FUNCTION(glXDestroyWindow
),
2972 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2973 GLX_FUNCTION(glXGetFBConfigAttrib
),
2974 GLX_FUNCTION(glXGetFBConfigs
),
2975 GLX_FUNCTION(glXGetSelectedEvent
),
2976 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2977 GLX_FUNCTION(glXMakeContextCurrent
),
2978 GLX_FUNCTION(glXQueryContext
),
2979 GLX_FUNCTION(glXQueryDrawable
),
2980 GLX_FUNCTION(glXSelectEvent
),
2982 /*** GLX_SGI_swap_control ***/
2983 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2985 /*** GLX_SGI_video_sync ***/
2986 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2987 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2989 /*** GLX_SGI_make_current_read ***/
2990 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2991 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2993 /*** GLX_EXT_import_context ***/
2994 GLX_FUNCTION(glXFreeContextEXT
),
2995 GLX_FUNCTION(glXGetContextIDEXT
),
2996 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2997 GLX_FUNCTION(glXImportContextEXT
),
2998 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3000 /*** GLX_SGIX_fbconfig ***/
3001 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3002 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3003 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3004 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3005 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3006 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3008 /*** GLX_SGIX_pbuffer ***/
3009 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3010 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3011 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3012 GLX_FUNCTION(glXSelectEventSGIX
),
3013 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3015 /*** GLX_SGIX_swap_group ***/
3016 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3018 /*** GLX_SGIX_swap_barrier ***/
3019 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3020 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3022 /*** GLX_MESA_allocate_memory ***/
3023 GLX_FUNCTION(glXAllocateMemoryMESA
),
3024 GLX_FUNCTION(glXFreeMemoryMESA
),
3025 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3027 /*** GLX_MESA_copy_sub_buffer ***/
3028 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3030 /*** GLX_MESA_pixmap_colormap ***/
3031 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3033 /*** GLX_MESA_release_buffers ***/
3034 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3036 /*** GLX_MESA_swap_control ***/
3037 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3038 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3040 /*** GLX_MESA_swap_frame_usage ***/
3041 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3042 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3043 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3044 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3046 /*** GLX_ARB_get_proc_address ***/
3047 GLX_FUNCTION(glXGetProcAddressARB
),
3050 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3052 /*** GLX_OML_sync_control ***/
3053 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3054 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3055 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3056 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3057 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3059 /*** GLX_EXT_texture_from_pixmap ***/
3060 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3061 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3063 #ifdef GLX_DIRECT_RENDERING
3064 /*** DRI configuration ***/
3065 GLX_FUNCTION(glXGetScreenDriver
),
3066 GLX_FUNCTION(glXGetDriverConfig
),
3069 {NULL
, NULL
} /* end of list */
3073 static const GLvoid
*
3074 get_glx_proc_address(const char *funcName
)
3078 /* try static functions */
3079 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3080 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3081 return GLX_functions
[i
].Address
;
3089 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3090 * \c glXGetProcAddress.
3092 * \param procName Name of a GL or GLX function.
3093 * \returns A pointer to the named function
3095 * \sa glXGetProcAddress
3097 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3099 typedef void (*gl_function
) (void);
3103 /* Search the table of GLX and internal functions first. If that
3104 * fails and the supplied name could be a valid core GL name, try
3105 * searching the core GL function table. This check is done to prevent
3106 * DRI based drivers from searching the core GL function table for
3107 * internal API functions.
3110 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3111 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3112 && (procName
[2] != 'X')) {
3113 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3120 * Get the address of a named GL function. This is the GLX 1.4 name for
3121 * \c glXGetProcAddressARB.
3123 * \param procName Name of a GL or GLX function.
3124 * \returns A pointer to the named function
3126 * \sa glXGetProcAddressARB
3128 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3129 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3130 __attribute__ ((alias("glXGetProcAddressARB")));
3133 return glXGetProcAddressARB(procName
);
3135 #endif /* __GNUC__ */
3138 #ifdef GLX_DIRECT_RENDERING
3140 * Get the unadjusted system time (UST). Currently, the UST is measured in
3141 * microseconds since Epoc. The actual resolution of the UST may vary from
3142 * system to system, and the units may vary from release to release.
3143 * Drivers should not call this function directly. They should instead use
3144 * \c glXGetProcAddress to obtain a pointer to the function.
3146 * \param ust Location to store the 64-bit UST
3147 * \returns Zero on success or a negative errno value on failure.
3149 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3151 * \since Internal API version 20030317.
3154 __glXGetUST(int64_t * ust
)
3162 if (gettimeofday(&tv
, NULL
) == 0) {
3163 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3170 #endif /* GLX_DIRECT_RENDERING */