2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
39 #include "glcontextmodes.h"
41 #ifdef GLX_DIRECT_RENDERING
43 #include <X11/extensions/xf86vmode.h>
48 #include <X11/Xlib-xcb.h>
53 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
54 static const char __glXGLXClientVersion
[] = "1.4";
57 /****************************************************************************/
59 #ifdef GLX_DIRECT_RENDERING
61 static Bool windowExistsFlag
;
63 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
65 if (xerr
->error_code
== BadWindow
) {
66 windowExistsFlag
= GL_FALSE
;
72 * Find drawables in the local hash that have been destroyed on the
75 * \param dpy Display to destroy drawables for
76 * \param screen Screen number to destroy drawables for
79 GarbageCollectDRIDrawables(Display
* dpy
, __GLXscreenConfigs
* sc
)
82 __GLXDRIdrawable
*pdraw
;
83 XWindowAttributes xwa
;
84 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
86 /* Set no-op error handler so Xlib doesn't bail out if the windows
87 * has alreay been destroyed on the server. */
89 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
91 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
93 windowExistsFlag
= GL_TRUE
;
94 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
95 if (!windowExistsFlag
) {
96 /* Destroy the local drawable data, if the drawable no
97 longer exists in the Xserver */
98 (*pdraw
->destroyDrawable
) (pdraw
);
99 __glxHashDelete(sc
->drawHash
, draw
);
101 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1);
104 XSync(dpy
, GL_FALSE
);
105 XSetErrorHandler(oldXErrorHandler
);
108 extern __GLXDRIdrawable
*GetGLXDRIDrawable(Display
* dpy
,
109 GLXDrawable drawable
,
110 int *const scrn_num
);
113 * Get the __DRIdrawable for the drawable associated with a GLXContext
115 * \param dpy The display associated with \c drawable.
116 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
117 * \param scrn_num If non-NULL, the drawables screen is stored there
118 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
119 * the drawable is not associated with a direct-rendering context.
121 _X_HIDDEN __GLXDRIdrawable
*
122 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
124 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
125 __GLXDRIdrawable
*pdraw
;
126 const unsigned screen_count
= ScreenCount(dpy
);
128 __GLXscreenConfigs
*psc
;
133 for (i
= 0; i
< screen_count
; i
++) {
134 psc
= &priv
->screenConfigs
[i
];
135 if (psc
->drawHash
== NULL
)
138 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
139 if (scrn_num
!= NULL
)
152 * Get the GLX per-screen data structure associated with a GLX context.
154 * \param dpy Display for which the GLX per-screen information is to be
156 * \param scrn Screen on \c dpy for which the GLX per-screen information is
158 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
159 * specify a valid GLX screen, or NULL otherwise.
161 * \todo Should this function validate that \c scrn is within the screen
162 * number range for \c dpy?
165 static __GLXscreenConfigs
*
166 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
168 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
171 && priv
->screenConfigs
!=
172 NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
177 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
178 __GLXscreenConfigs
** ppsc
)
180 /* Initialize the extension, if needed . This has the added value
181 * of initializing/allocating the display private
185 return GLX_NO_EXTENSION
;
188 *ppriv
= __glXInitialize(dpy
);
189 if (*ppriv
== NULL
) {
190 return GLX_NO_EXTENSION
;
193 /* Check screen number to see if its valid */
194 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
195 return GLX_BAD_SCREEN
;
198 /* Check to see if the GL is supported on this screen */
199 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
200 if ((*ppsc
)->configs
== NULL
) {
201 /* No support for GL on this screen regardless of visual */
202 return GLX_BAD_VISUAL
;
210 * Determine if a \c GLXFBConfig supplied by the application is valid.
212 * \param dpy Application supplied \c Display pointer.
213 * \param config Application supplied \c GLXFBConfig.
215 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
216 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
219 static __GLcontextModes
*
220 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
222 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
223 const unsigned num_screens
= ScreenCount(dpy
);
225 const __GLcontextModes
*modes
;
229 for (i
= 0; i
< num_screens
; i
++) {
230 for (modes
= priv
->screenConfigs
[i
].configs
; modes
!= NULL
;
231 modes
= modes
->next
) {
232 if (modes
== (__GLcontextModes
*) config
) {
233 return (__GLcontextModes
*) config
;
244 * \todo It should be possible to move the allocate of \c client_state_private
245 * later in the function for direct-rendering contexts. Direct-rendering
246 * contexts don't need to track client state, so they don't need that memory
249 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
250 * function called \c __glXAllocateClientState that allocates the memory and
251 * does all the initialization (including the pixel pack / unpack).
254 AllocateGLXContext(Display
* dpy
)
259 __GLXattribute
*state
;
264 opcode
= __glXSetupForCommand(dpy
);
269 /* Allocate our context record */
270 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
275 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
277 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
283 gc
->client_state_private
= state
;
284 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
285 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
288 ** Create a temporary buffer to hold GLX rendering commands. The size
289 ** of the buffer is selected so that the maximum number of GLX rendering
290 ** commands can fit in a single X packet and still have room in the X
291 ** packet for the GLXRenderReq header.
294 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
295 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
297 Xfree(gc
->client_state_private
);
301 gc
->bufSize
= bufSize
;
303 /* Fill in the new context */
304 gc
->renderMode
= GL_RENDER
;
306 state
->storePack
.alignment
= 4;
307 state
->storeUnpack
.alignment
= 4;
309 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
312 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
313 ** Other code uses the fastImageUnpack bit, but it is never set
316 gc
->fastImageUnpack
= GL_FALSE
;
317 gc
->fillImage
= __glFillImage
;
319 gc
->bufEnd
= gc
->buf
+ bufSize
;
320 gc
->isDirect
= GL_FALSE
;
323 ** Set limit register so that there will be one command per packet
328 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
331 gc
->majorOpcode
= opcode
;
334 ** Constrain the maximum drawing command size allowed to be
335 ** transfered using the X_GLXRender protocol request. First
336 ** constrain by a software limit, then constrain by the protocl
339 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
340 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
342 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
343 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
345 gc
->maxSmallRenderCommandSize
= bufSize
;
351 * Create a new context. Exactly one of \c vis and \c fbconfig should be
354 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
355 * SGIX_fbconfig protocol be used?
356 * \param renderType For FBConfigs, what is the rendering type?
360 CreateContext(Display
* dpy
, XVisualInfo
* vis
,
361 const __GLcontextModes
* const fbconfig
,
362 GLXContext shareList
,
363 Bool allowDirect
, GLXContextID contextID
,
364 Bool use_glx_1_3
, int renderType
)
367 #ifdef GLX_DIRECT_RENDERING
368 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
369 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
375 gc
= AllocateGLXContext(dpy
);
379 if (None
== contextID
) {
380 if ((vis
== NULL
) && (fbconfig
== NULL
))
383 #ifdef GLX_DIRECT_RENDERING
384 if (allowDirect
&& psc
->driScreen
) {
385 const __GLcontextModes
*mode
;
387 if (fbconfig
== NULL
) {
388 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
392 error
.errorCode
= BadValue
;
393 error
.resourceID
= vis
->visualid
;
394 error
.sequenceNumber
= dpy
->request
;
395 error
.type
= X_Error
;
396 error
.majorCode
= gc
->majorOpcode
;
397 error
.minorCode
= X_GLXCreateContext
;
398 _XError(dpy
, &error
);
401 if (renderType
== 0) {
402 /* Initialize renderType now */
403 renderType
= mode
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
410 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
413 if (gc
->driContext
!= NULL
) {
414 gc
->screen
= mode
->screen
;
417 gc
->isDirect
= GL_TRUE
;
423 if (fbconfig
== NULL
) {
424 xGLXCreateContextReq
*req
;
426 /* Send the glXCreateContext request */
427 GetReq(GLXCreateContext
, req
);
428 req
->reqType
= gc
->majorOpcode
;
429 req
->glxCode
= X_GLXCreateContext
;
430 req
->context
= gc
->xid
= XAllocID(dpy
);
431 req
->visual
= vis
->visualid
;
432 req
->screen
= vis
->screen
;
433 req
->shareList
= shareList
? shareList
->xid
: None
;
434 #ifdef GLX_DIRECT_RENDERING
435 req
->isDirect
= gc
->driContext
!= NULL
;
440 else if (use_glx_1_3
) {
441 xGLXCreateNewContextReq
*req
;
443 /* Send the glXCreateNewContext request */
444 GetReq(GLXCreateNewContext
, req
);
445 req
->reqType
= gc
->majorOpcode
;
446 req
->glxCode
= X_GLXCreateNewContext
;
447 req
->context
= gc
->xid
= XAllocID(dpy
);
448 req
->fbconfig
= fbconfig
->fbconfigID
;
449 req
->screen
= fbconfig
->screen
;
450 req
->renderType
= renderType
;
451 req
->shareList
= shareList
? shareList
->xid
: None
;
452 #ifdef GLX_DIRECT_RENDERING
453 req
->isDirect
= gc
->driContext
!= NULL
;
459 xGLXVendorPrivateWithReplyReq
*vpreq
;
460 xGLXCreateContextWithConfigSGIXReq
*req
;
462 /* Send the glXCreateNewContext request */
463 GetReqExtra(GLXVendorPrivateWithReply
,
464 sz_xGLXCreateContextWithConfigSGIXReq
-
465 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
466 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
467 req
->reqType
= gc
->majorOpcode
;
468 req
->glxCode
= X_GLXVendorPrivateWithReply
;
469 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
470 req
->context
= gc
->xid
= XAllocID(dpy
);
471 req
->fbconfig
= fbconfig
->fbconfigID
;
472 req
->screen
= fbconfig
->screen
;
473 req
->renderType
= renderType
;
474 req
->shareList
= shareList
? shareList
->xid
: None
;
475 #ifdef GLX_DIRECT_RENDERING
476 req
->isDirect
= gc
->driContext
!= NULL
;
484 gc
->imported
= GL_FALSE
;
488 gc
->imported
= GL_TRUE
;
491 gc
->renderType
= renderType
;
497 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
498 GLXContext shareList
, Bool allowDirect
)
500 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
505 __glXFreeContext(__GLXcontext
* gc
)
508 XFree((char *) gc
->vendor
);
510 XFree((char *) gc
->renderer
);
512 XFree((char *) gc
->version
);
514 XFree((char *) gc
->extensions
);
515 __glFreeAttributeState(gc
);
516 XFree((char *) gc
->buf
);
517 Xfree((char *) gc
->client_state_private
);
523 ** Destroy the named context
526 DestroyContext(Display
* dpy
, GLXContext gc
)
528 xGLXDestroyContextReq
*req
;
533 opcode
= __glXSetupForCommand(dpy
);
534 if (!opcode
|| !gc
) {
540 imported
= gc
->imported
;
543 if (gc
->currentDpy
) {
544 /* This context is bound to some thread. According to the man page,
545 * we should not actually delete the context until it's unbound.
546 * Note that we set gc->xid = None above. In MakeContextCurrent()
547 * we check for that and delete the context there.
553 #ifdef GLX_DIRECT_RENDERING
554 /* Destroy the direct rendering context */
555 if (gc
->driContext
) {
556 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
557 gc
->driContext
= NULL
;
558 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
562 __glXFreeVertexArrayState(gc
);
564 if (gc
->currentDpy
) {
565 /* Have to free later cuz it's in use now */
569 /* Destroy the handle if not current to anybody */
571 __glXFreeContext(gc
);
576 ** This dpy also created the server side part of the context.
577 ** Send the glXDestroyContext request.
580 GetReq(GLXDestroyContext
, req
);
581 req
->reqType
= opcode
;
582 req
->glxCode
= X_GLXDestroyContext
;
590 glXDestroyContext(Display
* dpy
, GLXContext gc
)
592 DestroyContext(dpy
, gc
);
596 ** Return the major and minor version #s for the GLX extension
599 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
601 __GLXdisplayPrivate
*priv
;
603 /* Init the extension. This fetches the major and minor version. */
604 priv
= __glXInitialize(dpy
);
609 *major
= priv
->majorVersion
;
611 *minor
= priv
->minorVersion
;
616 ** Query the existance of the GLX extension
619 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
621 int major_op
, erb
, evb
;
624 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
635 ** Put a barrier in the token stream that forces the GL to finish its
636 ** work before X can proceed.
642 GLXContext gc
= __glXGetCurrentContext();
643 Display
*dpy
= gc
->currentDpy
;
648 /* Flush any pending commands out */
649 __glXFlushRenderBuffer(gc
, gc
->pc
);
651 #ifdef GLX_DIRECT_RENDERING
652 if (gc
->driContext
) {
654 __GLXDRIdrawable
*pdraw
=
655 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
658 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
660 if (psc
->driScreen
->waitGL
!= NULL
)
661 (*psc
->driScreen
->waitGL
) (pdraw
);
667 /* Send the glXWaitGL request */
669 GetReq(GLXWaitGL
, req
);
670 req
->reqType
= gc
->majorOpcode
;
671 req
->glxCode
= X_GLXWaitGL
;
672 req
->contextTag
= gc
->currentContextTag
;
678 ** Put a barrier in the token stream that forces X to finish its
679 ** work before GL can proceed.
685 GLXContext gc
= __glXGetCurrentContext();
686 Display
*dpy
= gc
->currentDpy
;
691 /* Flush any pending commands out */
692 __glXFlushRenderBuffer(gc
, gc
->pc
);
694 #ifdef GLX_DIRECT_RENDERING
695 if (gc
->driContext
) {
697 __GLXDRIdrawable
*pdraw
=
698 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
701 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
702 if (psc
->driScreen
->waitX
!= NULL
)
703 (*psc
->driScreen
->waitX
) (pdraw
);
712 ** Send the glXWaitX request.
715 GetReq(GLXWaitX
, req
);
716 req
->reqType
= gc
->majorOpcode
;
717 req
->glxCode
= X_GLXWaitX
;
718 req
->contextTag
= gc
->currentContextTag
;
724 glXUseXFont(Font font
, int first
, int count
, int listBase
)
726 xGLXUseXFontReq
*req
;
727 GLXContext gc
= __glXGetCurrentContext();
728 Display
*dpy
= gc
->currentDpy
;
733 /* Flush any pending commands out */
734 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
736 #ifdef GLX_DIRECT_RENDERING
737 if (gc
->driContext
) {
738 DRI_glXUseXFont(font
, first
, count
, listBase
);
743 /* Send the glXUseFont request */
745 GetReq(GLXUseXFont
, req
);
746 req
->reqType
= gc
->majorOpcode
;
747 req
->glxCode
= X_GLXUseXFont
;
748 req
->contextTag
= gc
->currentContextTag
;
752 req
->listBase
= listBase
;
757 /************************************************************************/
760 ** Copy the source context to the destination context using the
764 glXCopyContext(Display
* dpy
, GLXContext source
,
765 GLXContext dest
, unsigned long mask
)
767 xGLXCopyContextReq
*req
;
768 GLXContext gc
= __glXGetCurrentContext();
772 opcode
= __glXSetupForCommand(dpy
);
777 #ifdef GLX_DIRECT_RENDERING
778 if (gc
->driContext
) {
779 /* NOT_DONE: This does not work yet */
784 ** If the source is the current context, send its tag so that the context
785 ** can be flushed before the copy.
787 if (source
== gc
&& dpy
== gc
->currentDpy
) {
788 tag
= gc
->currentContextTag
;
794 /* Send the glXCopyContext request */
796 GetReq(GLXCopyContext
, req
);
797 req
->reqType
= opcode
;
798 req
->glxCode
= X_GLXCopyContext
;
799 req
->source
= source
? source
->xid
: None
;
800 req
->dest
= dest
? dest
->xid
: None
;
802 req
->contextTag
= tag
;
809 * Determine if a context uses direct rendering.
811 * \param dpy Display where the context was created.
812 * \param contextID ID of the context to be tested.
814 * \returns \c GL_TRUE if the context is direct rendering or not.
817 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
819 #if !defined(USE_XCB)
820 xGLXIsDirectReq
*req
;
821 xGLXIsDirectReply reply
;
825 opcode
= __glXSetupForCommand(dpy
);
831 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
832 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
837 const Bool is_direct
= reply
->is_direct
? True
: False
;
842 /* Send the glXIsDirect request */
844 GetReq(GLXIsDirect
, req
);
845 req
->reqType
= opcode
;
846 req
->glxCode
= X_GLXIsDirect
;
847 req
->context
= contextID
;
848 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
852 return reply
.isDirect
;
858 * Shouldn't this function \b always return \c GL_FALSE when
859 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
860 * the GLX protocol here at all?
863 glXIsDirect(Display
* dpy
, GLXContext gc
)
867 #ifdef GLX_DIRECT_RENDERING
869 else if (gc
->driContext
) {
873 return __glXIsDirect(dpy
, gc
->xid
);
877 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
879 xGLXCreateGLXPixmapReq
*req
;
883 opcode
= __glXSetupForCommand(dpy
);
888 /* Send the glXCreateGLXPixmap request */
890 GetReq(GLXCreateGLXPixmap
, req
);
891 req
->reqType
= opcode
;
892 req
->glxCode
= X_GLXCreateGLXPixmap
;
893 req
->screen
= vis
->screen
;
894 req
->visual
= vis
->visualid
;
895 req
->pixmap
= pixmap
;
896 req
->glxpixmap
= xid
= XAllocID(dpy
);
900 #ifdef GLX_DIRECT_RENDERING
902 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
903 * is actually bound to a context... */
905 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
906 __GLXDRIdrawable
*pdraw
;
907 __GLXscreenConfigs
*psc
;
908 __GLcontextModes
*modes
;
910 psc
= &priv
->screenConfigs
[vis
->screen
];
911 if (psc
->driScreen
== NULL
)
913 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
914 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
916 fprintf(stderr
, "failed to create pixmap\n");
920 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
921 (*pdraw
->destroyDrawable
) (pdraw
);
922 return None
; /* FIXME: Check what we're supposed to do here... */
931 ** Destroy the named pixmap
934 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
936 xGLXDestroyGLXPixmapReq
*req
;
939 opcode
= __glXSetupForCommand(dpy
);
944 /* Send the glXDestroyGLXPixmap request */
946 GetReq(GLXDestroyGLXPixmap
, req
);
947 req
->reqType
= opcode
;
948 req
->glxCode
= X_GLXDestroyGLXPixmap
;
949 req
->glxpixmap
= glxpixmap
;
953 #ifdef GLX_DIRECT_RENDERING
956 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
957 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
958 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
961 (*pdraw
->destroyDrawable
) (pdraw
);
962 __glxHashDelete(psc
->drawHash
, glxpixmap
);
969 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
977 xGLXSwapBuffersReq
*req
;
980 #ifdef GLX_DIRECT_RENDERING
981 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
985 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
990 opcode
= __glXSetupForCommand(dpy
);
996 ** The calling thread may or may not have a current context. If it
997 ** does, send the context tag so the server can do a flush.
999 gc
= __glXGetCurrentContext();
1000 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1001 ((drawable
== gc
->currentDrawable
)
1002 || (drawable
== gc
->currentReadable
))) {
1003 tag
= gc
->currentContextTag
;
1010 c
= XGetXCBConnection(dpy
);
1011 xcb_glx_swap_buffers(c
, tag
, drawable
);
1014 /* Send the glXSwapBuffers request */
1016 GetReq(GLXSwapBuffers
, req
);
1017 req
->reqType
= opcode
;
1018 req
->glxCode
= X_GLXSwapBuffers
;
1019 req
->drawable
= drawable
;
1020 req
->contextTag
= tag
;
1024 #endif /* USE_XCB */
1029 ** Return configuration information for the given display, screen and
1030 ** visual combination.
1033 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1036 __GLXdisplayPrivate
*priv
;
1037 __GLXscreenConfigs
*psc
;
1038 __GLcontextModes
*modes
;
1041 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1042 if (status
== Success
) {
1043 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1045 /* Lookup attribute after first finding a match on the visual */
1046 if (modes
!= NULL
) {
1047 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1050 status
= GLX_BAD_VISUAL
;
1054 ** If we can't find the config for this visual, this visual is not
1055 ** supported by the OpenGL implementation on the server.
1057 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1058 *value_return
= GL_FALSE
;
1065 /************************************************************************/
1068 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1069 GLboolean fbconfig_style_tags
)
1071 memset(config
, 0, sizeof(__GLcontextModes
));
1072 config
->visualID
= (XID
) GLX_DONT_CARE
;
1073 config
->visualType
= GLX_DONT_CARE
;
1075 /* glXChooseFBConfig specifies different defaults for these two than
1078 if (fbconfig_style_tags
) {
1079 config
->rgbMode
= GL_TRUE
;
1080 config
->doubleBufferMode
= GLX_DONT_CARE
;
1083 config
->visualRating
= GLX_DONT_CARE
;
1084 config
->transparentPixel
= GLX_NONE
;
1085 config
->transparentRed
= GLX_DONT_CARE
;
1086 config
->transparentGreen
= GLX_DONT_CARE
;
1087 config
->transparentBlue
= GLX_DONT_CARE
;
1088 config
->transparentAlpha
= GLX_DONT_CARE
;
1089 config
->transparentIndex
= GLX_DONT_CARE
;
1091 config
->drawableType
= GLX_WINDOW_BIT
;
1092 config
->renderType
=
1093 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1094 config
->xRenderable
= GLX_DONT_CARE
;
1095 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1097 config
->swapMethod
= GLX_DONT_CARE
;
1100 #define MATCH_DONT_CARE( param ) \
1102 if ( (a-> param != GLX_DONT_CARE) \
1103 && (a-> param != b-> param) ) { \
1108 #define MATCH_MINIMUM( param ) \
1110 if ( (a-> param != GLX_DONT_CARE) \
1111 && (a-> param > b-> param) ) { \
1116 #define MATCH_EXACT( param ) \
1118 if ( a-> param != b-> param) { \
1124 * Determine if two GLXFBConfigs are compatible.
1126 * \param a Application specified config to test.
1127 * \param b Server specified config to test against \c a.
1130 fbconfigs_compatible(const __GLcontextModes
* const a
,
1131 const __GLcontextModes
* const b
)
1133 MATCH_DONT_CARE(doubleBufferMode
);
1134 MATCH_DONT_CARE(visualType
);
1135 MATCH_DONT_CARE(visualRating
);
1136 MATCH_DONT_CARE(xRenderable
);
1137 MATCH_DONT_CARE(fbconfigID
);
1138 MATCH_DONT_CARE(swapMethod
);
1140 MATCH_MINIMUM(rgbBits
);
1141 MATCH_MINIMUM(numAuxBuffers
);
1142 MATCH_MINIMUM(redBits
);
1143 MATCH_MINIMUM(greenBits
);
1144 MATCH_MINIMUM(blueBits
);
1145 MATCH_MINIMUM(alphaBits
);
1146 MATCH_MINIMUM(depthBits
);
1147 MATCH_MINIMUM(stencilBits
);
1148 MATCH_MINIMUM(accumRedBits
);
1149 MATCH_MINIMUM(accumGreenBits
);
1150 MATCH_MINIMUM(accumBlueBits
);
1151 MATCH_MINIMUM(accumAlphaBits
);
1152 MATCH_MINIMUM(sampleBuffers
);
1153 MATCH_MINIMUM(maxPbufferWidth
);
1154 MATCH_MINIMUM(maxPbufferHeight
);
1155 MATCH_MINIMUM(maxPbufferPixels
);
1156 MATCH_MINIMUM(samples
);
1158 MATCH_DONT_CARE(stereoMode
);
1161 if (((a
->drawableType
& b
->drawableType
) == 0)
1162 || ((a
->renderType
& b
->renderType
) == 0)) {
1167 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1168 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1169 * Technically speaking, it is a bug in the DDX driver, but there is
1170 * enough of an installed base to work around the problem here. In any
1171 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1172 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1173 * 0 from the server to be a match to maintain backward compatibility with
1174 * the (broken) drivers.
1177 if (a
->transparentPixel
!= GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1178 if (a
->transparentPixel
== GLX_NONE
) {
1179 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1183 MATCH_EXACT(transparentPixel
);
1186 switch (a
->transparentPixel
) {
1187 case GLX_TRANSPARENT_RGB
:
1188 MATCH_DONT_CARE(transparentRed
);
1189 MATCH_DONT_CARE(transparentGreen
);
1190 MATCH_DONT_CARE(transparentBlue
);
1191 MATCH_DONT_CARE(transparentAlpha
);
1194 case GLX_TRANSPARENT_INDEX
:
1195 MATCH_DONT_CARE(transparentIndex
);
1207 /* There's some trickly language in the GLX spec about how this is supposed
1208 * to work. Basically, if a given component size is either not specified
1209 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1210 * Well, that's really hard to do with the code as-is. This behavior is
1211 * closer to correct, but still not technically right.
1213 #define PREFER_LARGER_OR_ZERO(comp) \
1215 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1216 if ( ((*a)-> comp) == 0 ) { \
1219 else if ( ((*b)-> comp) == 0 ) { \
1223 return ((*b)-> comp) - ((*a)-> comp) ; \
1228 #define PREFER_LARGER(comp) \
1230 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1231 return ((*b)-> comp) - ((*a)-> comp) ; \
1235 #define PREFER_SMALLER(comp) \
1237 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1238 return ((*a)-> comp) - ((*b)-> comp) ; \
1243 * Compare two GLXFBConfigs. This function is intended to be used as the
1244 * compare function passed in to qsort.
1246 * \returns If \c a is a "better" config, according to the specification of
1247 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1248 * better, then a number greater than zero is return. If both are
1249 * equal, zero is returned.
1250 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1253 fbconfig_compare(const __GLcontextModes
* const *const a
,
1254 const __GLcontextModes
* const *const b
)
1256 /* The order of these comparisons must NOT change. It is defined by
1257 * the GLX 1.3 spec and ARB_multisample.
1260 PREFER_SMALLER(visualSelectGroup
);
1262 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1263 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1264 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1266 PREFER_SMALLER(visualRating
);
1268 /* This isn't quite right. It is supposed to compare the sum of the
1269 * components the user specifically set minimums for.
1271 PREFER_LARGER_OR_ZERO(redBits
);
1272 PREFER_LARGER_OR_ZERO(greenBits
);
1273 PREFER_LARGER_OR_ZERO(blueBits
);
1274 PREFER_LARGER_OR_ZERO(alphaBits
);
1276 PREFER_SMALLER(rgbBits
);
1278 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1279 /* Prefer single-buffer.
1281 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1284 PREFER_SMALLER(numAuxBuffers
);
1286 PREFER_LARGER_OR_ZERO(depthBits
);
1287 PREFER_SMALLER(stencilBits
);
1289 /* This isn't quite right. It is supposed to compare the sum of the
1290 * components the user specifically set minimums for.
1292 PREFER_LARGER_OR_ZERO(accumRedBits
);
1293 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1294 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1295 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1297 PREFER_SMALLER(visualType
);
1299 /* None of the multisample specs say where this comparison should happen,
1300 * so I put it near the end.
1302 PREFER_SMALLER(sampleBuffers
);
1303 PREFER_SMALLER(samples
);
1305 /* None of the pbuffer or fbconfig specs say that this comparison needs
1306 * to happen at all, but it seems like it should.
1308 PREFER_LARGER(maxPbufferWidth
);
1309 PREFER_LARGER(maxPbufferHeight
);
1310 PREFER_LARGER(maxPbufferPixels
);
1317 * Selects and sorts a subset of the supplied configs based on the attributes.
1318 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1319 * and \c glXChooseFBConfigSGIX.
1321 * \param configs Array of pointers to possible configs. The elements of
1322 * this array that do not meet the criteria will be set to
1323 * NULL. The remaining elements will be sorted according to
1324 * the various visual / FBConfig selection rules.
1325 * \param num_configs Number of elements in the \c configs array.
1326 * \param attribList Attributes used select from \c configs. This array is
1327 * terminated by a \c None tag. The array can either take
1328 * the form expected by \c glXChooseVisual (where boolean
1329 * tags do not have a value) or by \c glXChooseFBConfig
1330 * (where every tag has a value).
1331 * \param fbconfig_style_tags Selects whether \c attribList is in
1332 * \c glXChooseVisual style or
1333 * \c glXChooseFBConfig style.
1334 * \returns The number of valid elements left in \c configs.
1336 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1339 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1340 const int *attribList
, GLboolean fbconfig_style_tags
)
1342 __GLcontextModes test_config
;
1346 /* This is a fairly direct implementation of the selection method
1347 * described by GLX_SGIX_fbconfig. Start by culling out all the
1348 * configs that are not compatible with the selected parameter
1352 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1353 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1354 (const INT32
*) attribList
,
1355 GL_TRUE
, fbconfig_style_tags
);
1358 for (i
= 0; i
< num_configs
; i
++) {
1359 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1360 configs
[base
] = configs
[i
];
1369 if (base
< num_configs
) {
1370 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1373 /* After the incompatible configs are removed, the resulting
1374 * list is sorted according to the rules set out in the various
1378 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1379 (int (*)(const void *, const void *)) fbconfig_compare
);
1387 ** Return the visual that best matches the template. Return None if no
1388 ** visual matches the template.
1390 PUBLIC XVisualInfo
*
1391 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1393 XVisualInfo
*visualList
= NULL
;
1394 __GLXdisplayPrivate
*priv
;
1395 __GLXscreenConfigs
*psc
;
1396 __GLcontextModes test_config
;
1397 __GLcontextModes
*modes
;
1398 const __GLcontextModes
*best_config
= NULL
;
1401 ** Get a list of all visuals, return if list is empty
1403 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1409 ** Build a template from the defaults and the attribute list
1410 ** Free visual list and return if an unexpected token is encountered
1412 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1413 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1414 (const INT32
*) attribList
,
1418 ** Eliminate visuals that don't meet minimum requirements
1419 ** Compute a score for those that do
1420 ** Remember which visual, if any, got the highest score
1421 ** If no visual is acceptable, return None
1422 ** Otherwise, create an XVisualInfo list with just the selected X visual
1425 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1426 if (fbconfigs_compatible(&test_config
, modes
)
1427 && ((best_config
== NULL
)
1430 ((const __GLcontextModes
* const *const) &modes
,
1431 &best_config
) < 0))) {
1432 XVisualInfo visualTemplate
;
1433 XVisualInfo
*newList
;
1436 visualTemplate
.screen
= screen
;
1437 visualTemplate
.visualid
= modes
->visualID
;
1438 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1439 &visualTemplate
, &i
);
1443 visualList
= newList
;
1444 best_config
= modes
;
1454 glXQueryExtensionsString(Display
* dpy
, int screen
)
1456 __GLXscreenConfigs
*psc
;
1457 __GLXdisplayPrivate
*priv
;
1459 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1463 if (!psc
->effectiveGLXexts
) {
1464 if (!psc
->serverGLXexts
) {
1465 psc
->serverGLXexts
=
1466 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1470 __glXCalculateUsableExtensions(psc
,
1471 #ifdef GLX_DIRECT_RENDERING
1472 (psc
->driScreen
!= NULL
),
1476 priv
->minorVersion
);
1479 return psc
->effectiveGLXexts
;
1483 glXGetClientString(Display
* dpy
, int name
)
1487 return (__glXGLXClientVendorName
);
1489 return (__glXGLXClientVersion
);
1490 case GLX_EXTENSIONS
:
1491 return (__glXGetClientExtensions());
1498 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1500 __GLXscreenConfigs
*psc
;
1501 __GLXdisplayPrivate
*priv
;
1505 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1511 str
= &priv
->serverGLXvendor
;
1514 str
= &priv
->serverGLXversion
;
1516 case GLX_EXTENSIONS
:
1517 str
= &psc
->serverGLXexts
;
1524 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1531 __glXClientInfo(Display
* dpy
, int opcode
)
1533 char *ext_str
= __glXGetClientGLExtensionString();
1534 int size
= strlen(ext_str
) + 1;
1537 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1538 xcb_glx_client_info(c
,
1539 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1541 xGLXClientInfoReq
*req
;
1543 /* Send the glXClientInfo request */
1545 GetReq(GLXClientInfo
, req
);
1546 req
->reqType
= opcode
;
1547 req
->glxCode
= X_GLXClientInfo
;
1548 req
->major
= GLX_MAJOR_VERSION
;
1549 req
->minor
= GLX_MINOR_VERSION
;
1551 req
->length
+= (size
+ 3) >> 2;
1552 req
->numbytes
= size
;
1553 Data(dpy
, ext_str
, size
);
1557 #endif /* USE_XCB */
1564 ** EXT_import_context
1568 glXGetCurrentDisplay(void)
1570 GLXContext gc
= __glXGetCurrentContext();
1573 return gc
->currentDpy
;
1577 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1578 glXGetCurrentDisplay
)
1581 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1584 * \param dpy Display where \c ctx was created.
1585 * \param ctx Context to query.
1586 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1587 * or zero if the request failed due to internal problems (i.e.,
1588 * unable to allocate temporary memory, etc.)
1591 * This function dynamically determines whether to use the EXT_import_context
1592 * version of the protocol or the GLX 1.3 version of the protocol.
1594 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1596 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1597 xGLXQueryContextReply reply
;
1603 return GLX_BAD_CONTEXT
;
1605 opcode
= __glXSetupForCommand(dpy
);
1610 /* Send the glXQueryContextInfoEXT request */
1613 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1614 xGLXQueryContextReq
*req
;
1616 GetReq(GLXQueryContext
, req
);
1618 req
->reqType
= opcode
;
1619 req
->glxCode
= X_GLXQueryContext
;
1620 req
->context
= (unsigned int) (ctx
->xid
);
1623 xGLXVendorPrivateReq
*vpreq
;
1624 xGLXQueryContextInfoEXTReq
*req
;
1626 GetReqExtra(GLXVendorPrivate
,
1627 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1629 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1630 req
->reqType
= opcode
;
1631 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1632 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1633 req
->context
= (unsigned int) (ctx
->xid
);
1636 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1638 numValues
= reply
.n
;
1641 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1644 int *propList
, *pProp
;
1648 nPropListBytes
= numValues
<< 3;
1649 propList
= (int *) Xmalloc(nPropListBytes
);
1650 if (NULL
== propList
) {
1654 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1656 for (i
= 0; i
< numValues
; i
++) {
1658 case GLX_SHARE_CONTEXT_EXT
:
1659 ctx
->share_xid
= *pProp
++;
1661 case GLX_VISUAL_ID_EXT
:
1663 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1666 ctx
->screen
= *pProp
++;
1668 case GLX_FBCONFIG_ID
:
1670 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1673 case GLX_RENDER_TYPE
:
1674 ctx
->renderType
= *pProp
++;
1681 Xfree((char *) propList
);
1691 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1695 /* get the information from the server if we don't have it already */
1696 #ifdef GLX_DIRECT_RENDERING
1697 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1699 if (ctx
->mode
== NULL
) {
1701 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1702 if (Success
!= retVal
)
1705 switch (attribute
) {
1706 case GLX_SHARE_CONTEXT_EXT
:
1707 *value
= (int) (ctx
->share_xid
);
1709 case GLX_VISUAL_ID_EXT
:
1710 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1713 *value
= (int) (ctx
->screen
);
1715 case GLX_FBCONFIG_ID
:
1716 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1718 case GLX_RENDER_TYPE
:
1719 *value
= (int) (ctx
->renderType
);
1722 return GLX_BAD_ATTRIBUTE
;
1728 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1729 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1730 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1732 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1738 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1742 if (contextID
== None
) {
1745 if (__glXIsDirect(dpy
, contextID
)) {
1749 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1751 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1759 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1761 DestroyContext(dpy
, ctx
);
1767 * GLX 1.3 functions - these are just stubs for now!
1770 PUBLIC GLXFBConfig
*
1771 glXChooseFBConfig(Display
* dpy
, int screen
,
1772 const int *attribList
, int *nitems
)
1774 __GLcontextModes
**config_list
;
1778 config_list
= (__GLcontextModes
**)
1779 glXGetFBConfigs(dpy
, screen
, &list_size
);
1781 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1782 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1783 if (list_size
== 0) {
1789 *nitems
= list_size
;
1790 return (GLXFBConfig
*) config_list
;
1795 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1796 int renderType
, GLXContext shareList
, Bool allowDirect
)
1798 return CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1799 allowDirect
, None
, True
, renderType
);
1804 glXGetCurrentReadDrawable(void)
1806 GLXContext gc
= __glXGetCurrentContext();
1807 return gc
->currentReadable
;
1811 PUBLIC GLXFBConfig
*
1812 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1814 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1815 __GLcontextModes
**config
= NULL
;
1819 if (priv
&& (priv
->screenConfigs
!= NULL
)
1820 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1821 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1822 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
)) {
1823 unsigned num_configs
= 0;
1824 __GLcontextModes
*modes
;
1827 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1828 modes
= modes
->next
) {
1829 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1834 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1836 if (config
!= NULL
) {
1837 *nelements
= num_configs
;
1839 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1840 modes
= modes
->next
) {
1841 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1848 return (GLXFBConfig
*) config
;
1853 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1854 int attribute
, int *value
)
1856 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1858 return (modes
!= NULL
)
1859 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1864 PUBLIC XVisualInfo
*
1865 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1867 XVisualInfo visualTemplate
;
1868 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1872 ** Get a list of all visuals, return if list is empty
1874 visualTemplate
.visualid
= fbconfig
->visualID
;
1875 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1880 ** GLX_SGI_swap_control
1883 __glXSwapIntervalSGI(int interval
)
1885 xGLXVendorPrivateReq
*req
;
1886 GLXContext gc
= __glXGetCurrentContext();
1887 __GLXscreenConfigs
*psc
;
1889 CARD32
*interval_ptr
;
1893 return GLX_BAD_CONTEXT
;
1896 if (interval
<= 0) {
1897 return GLX_BAD_VALUE
;
1900 #ifdef __DRI_SWAP_CONTROL
1901 if (gc
->driContext
) {
1902 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1904 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1905 gc
->currentDrawable
,
1907 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1908 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1911 else if (pdraw
== NULL
) {
1912 return GLX_BAD_CONTEXT
;
1916 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1918 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1919 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1920 gc
->currentDrawable
,
1922 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1926 dpy
= gc
->currentDpy
;
1927 opcode
= __glXSetupForCommand(dpy
);
1932 /* Send the glXSwapIntervalSGI request */
1934 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1935 req
->reqType
= opcode
;
1936 req
->glxCode
= X_GLXVendorPrivate
;
1937 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1938 req
->contextTag
= gc
->currentContextTag
;
1940 interval_ptr
= (CARD32
*) (req
+ 1);
1941 *interval_ptr
= interval
;
1952 ** GLX_MESA_swap_control
1955 __glXSwapIntervalMESA(unsigned int interval
)
1957 GLXContext gc
= __glXGetCurrentContext();
1960 return GLX_BAD_VALUE
;
1963 #ifdef __DRI_SWAP_CONTROL
1964 if (gc
!= NULL
&& gc
->driContext
) {
1965 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1968 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1969 __GLXDRIdrawable
*pdraw
=
1970 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1971 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1972 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1979 if (gc
!= NULL
&& gc
->driContext
) {
1980 __GLXscreenConfigs
*psc
;
1982 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1983 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1984 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1985 gc
->currentDrawable
, NULL
);
1986 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1991 return GLX_BAD_CONTEXT
;
1996 __glXGetSwapIntervalMESA(void)
1998 #ifdef __DRI_SWAP_CONTROL
1999 GLXContext gc
= __glXGetCurrentContext();
2001 if (gc
!= NULL
&& gc
->driContext
) {
2002 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2005 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2006 __GLXDRIdrawable
*pdraw
=
2007 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2008 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2009 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2014 if (gc
!= NULL
&& gc
->driContext
) {
2015 __GLXscreenConfigs
*psc
;
2017 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2018 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2019 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2020 gc
->currentDrawable
, NULL
);
2021 return psc
->driScreen
->getSwapInterval(pdraw
);
2030 ** GLX_MESA_swap_frame_usage
2034 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2036 int status
= GLX_BAD_CONTEXT
;
2037 #ifdef __DRI_FRAME_TRACKING
2039 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2040 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2042 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2043 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2053 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2055 int status
= GLX_BAD_CONTEXT
;
2056 #ifdef __DRI_FRAME_TRACKING
2058 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2059 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2061 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2062 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2073 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2075 int status
= GLX_BAD_CONTEXT
;
2076 #ifdef __DRI_FRAME_TRACKING
2078 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2079 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2081 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2082 int64_t sbc
, missedFrames
;
2083 float lastMissedUsage
;
2085 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2101 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2102 int64_t * sbc
, int64_t * missedFrames
,
2103 GLfloat
* lastMissedUsage
)
2105 int status
= GLX_BAD_CONTEXT
;
2106 #ifdef __DRI_FRAME_TRACKING
2108 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2109 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2111 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2114 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2123 (void) missedFrames
;
2124 (void) lastMissedUsage
;
2131 ** GLX_SGI_video_sync
2134 __glXGetVideoSyncSGI(unsigned int *count
)
2136 int64_t ust
, msc
, sbc
;
2138 GLXContext gc
= __glXGetCurrentContext();
2139 __GLXscreenConfigs
*psc
;
2140 __GLXDRIdrawable
*pdraw
;
2142 if (!gc
|| !gc
->driContext
)
2143 return GLX_BAD_CONTEXT
;
2145 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2146 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2148 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2149 * FIXME: there should be a GLX encoding for this call. I can find no
2150 * FIXME: documentation for the GLX encoding.
2152 #ifdef __DRI_MEDIA_STREAM_COUNTER
2153 if ( psc
->msc
&& psc
->driScreen
) {
2154 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2155 pdraw
->driDrawable
, &msc
);
2156 *count
= (unsigned) msc
;
2158 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2161 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2162 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2163 *count
= (unsigned) msc
;
2164 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2167 return GLX_BAD_CONTEXT
;
2171 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2173 GLXContext gc
= __glXGetCurrentContext();
2174 __GLXscreenConfigs
*psc
;
2175 __GLXDRIdrawable
*pdraw
;
2176 int64_t ust
, msc
, sbc
;
2179 if (divisor
<= 0 || remainder
< 0)
2180 return GLX_BAD_VALUE
;
2182 if (!gc
|| !gc
->driContext
)
2183 return GLX_BAD_CONTEXT
;
2185 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2186 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2188 #ifdef __DRI_MEDIA_STREAM_COUNTER
2189 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2190 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2191 divisor
, remainder
, &msc
, &sbc
);
2192 *count
= (unsigned) msc
;
2193 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2196 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2197 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2199 *count
= (unsigned) msc
;
2200 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2203 return GLX_BAD_CONTEXT
;
2208 ** GLX_SGIX_fbconfig
2209 ** Many of these functions are aliased to GLX 1.3 entry points in the
2210 ** GLX_functions table.
2214 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2215 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2216 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2218 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2219 (Display
* dpy
, int screen
, int *attrib_list
,
2220 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2223 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2224 (Display
* dpy
, GLXFBConfigSGIX config
),
2225 (dpy
, config
), glXGetVisualFromFBConfig
)
2228 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2229 GLXFBConfigSGIX config
,
2232 xGLXVendorPrivateWithReplyReq
*vpreq
;
2233 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2234 GLXPixmap xid
= None
;
2236 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2237 __GLXscreenConfigs
*psc
;
2240 if ((dpy
== NULL
) || (config
== NULL
)) {
2244 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2246 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2247 opcode
= __glXSetupForCommand(dpy
);
2252 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2254 GetReqExtra(GLXVendorPrivateWithReply
,
2255 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2256 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2257 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2258 req
->reqType
= opcode
;
2259 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2260 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2261 req
->screen
= fbconfig
->screen
;
2262 req
->fbconfig
= fbconfig
->fbconfigID
;
2263 req
->pixmap
= pixmap
;
2264 req
->glxpixmap
= xid
= XAllocID(dpy
);
2273 glXCreateContextWithConfigSGIX(Display
* dpy
,
2274 GLXFBConfigSGIX config
, int renderType
,
2275 GLXContext shareList
, Bool allowDirect
)
2277 GLXContext gc
= NULL
;
2278 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2279 __GLXscreenConfigs
*psc
;
2282 if ((dpy
== NULL
) || (config
== NULL
)) {
2286 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2288 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2289 gc
= CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2290 allowDirect
, None
, False
, renderType
);
2297 PUBLIC GLXFBConfigSGIX
2298 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2300 __GLXdisplayPrivate
*priv
;
2301 __GLXscreenConfigs
*psc
= NULL
;
2303 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2304 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2305 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
)) {
2306 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2315 ** GLX_SGIX_swap_group
2318 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2328 ** GLX_SGIX_swap_barrier
2331 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2339 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2349 ** GLX_OML_sync_control
2352 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2353 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2355 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2357 __GLXDRIdrawable
*pdraw
;
2358 __GLXscreenConfigs
*psc
;
2363 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2364 psc
= &priv
->screenConfigs
[i
];
2366 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2367 if (pdraw
&& psc
->sbc
&& psc
->sbc
)
2368 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2369 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2370 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2371 && (__glXGetUST(ust
) == 0) );
2373 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2374 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2381 #ifdef GLX_DIRECT_RENDERING
2383 __driGetMscRateOML(__DRIdrawable
* draw
,
2384 int32_t * numerator
, int32_t * denominator
, void *private)
2387 __GLXscreenConfigs
*psc
;
2388 XF86VidModeModeLine mode_line
;
2391 __GLXDRIdrawable
*glxDraw
= private;
2394 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2395 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2396 unsigned n
= dot_clock
* 1000;
2397 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2399 # define V_INTERLACE 0x010
2400 # define V_DBLSCAN 0x020
2402 if (mode_line
.flags
& V_INTERLACE
)
2404 else if (mode_line
.flags
& V_DBLSCAN
)
2407 /* The OML_sync_control spec requires that if the refresh rate is a
2408 * whole number, that the returned numerator be equal to the refresh
2409 * rate and the denominator be 1.
2417 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2419 /* This is a poor man's way to reduce a fraction. It's far from
2420 * perfect, but it will work well enough for this situation.
2423 for (i
= 0; f
[i
] != 0; i
++) {
2424 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2445 * Determine the refresh rate of the specified drawable and display.
2447 * \param dpy Display whose refresh rate is to be determined.
2448 * \param drawable Drawable whose refresh rate is to be determined.
2449 * \param numerator Numerator of the refresh rate.
2450 * \param demoninator Denominator of the refresh rate.
2451 * \return If the refresh rate for the specified display and drawable could
2452 * be calculated, True is returned. Otherwise False is returned.
2454 * \note This function is implemented entirely client-side. A lot of other
2455 * functionality is required to export GLX_OML_sync_control, so on
2456 * XFree86 this function can be called for direct-rendering contexts
2457 * when GLX_OML_sync_control appears in the client extension string.
2461 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2462 int32_t * numerator
, int32_t * denominator
)
2464 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2465 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2470 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2482 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2483 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2485 GLXContext gc
= __glXGetCurrentContext();
2487 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2488 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2490 if (!pdraw
|| !gc
->driContext
) /* no GLX for this */
2493 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2494 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2495 * of -1 if the function failed because of errors detected in the input
2498 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2500 if (divisor
> 0 && remainder
>= divisor
)
2503 #ifdef __DRI_SWAP_BUFFER_COUNTER
2504 if (psc
->counters
!= NULL
)
2505 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2506 divisor
, remainder
);
2509 #ifdef GLX_DIRECT_RENDERING
2510 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2511 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2520 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2521 int64_t target_msc
, int64_t divisor
,
2522 int64_t remainder
, int64_t * ust
,
2523 int64_t * msc
, int64_t * sbc
)
2526 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2527 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2530 fprintf(stderr
, "waitmsc: %lld, %lld, %lld\n", target_msc
, divisor
,
2533 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2534 * error", but the return type in the spec is Bool.
2536 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2538 if (divisor
> 0 && remainder
>= divisor
)
2541 #ifdef __DRI_MEDIA_STREAM_COUNTER
2542 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2543 fprintf(stderr
, "dri1 msc\n");
2544 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2545 divisor
, remainder
, msc
, sbc
);
2547 /* __glXGetUST returns zero on success and non-zero on failure.
2548 * This function returns True on success and False on failure.
2550 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2553 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2554 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2559 fprintf(stderr
, "no drawable??\n");
2565 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2566 int64_t target_sbc
, int64_t * ust
,
2567 int64_t * msc
, int64_t * sbc
)
2570 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2571 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2574 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2575 * error", but the return type in the spec is Bool.
2579 #ifdef __DRI_SWAP_BUFFER_COUNTER
2580 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2582 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2584 /* __glXGetUST returns zero on success and non-zero on failure.
2585 * This function returns True on success and False on failure.
2587 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2590 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2591 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2599 * GLX_MESA_allocate_memory
2604 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2605 size_t size
, float readFreq
,
2606 float writeFreq
, float priority
)
2608 #ifdef __DRI_ALLOCATE
2609 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2611 if (psc
&& psc
->allocate
)
2612 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2613 readFreq
, writeFreq
, priority
);
2622 #endif /* __DRI_ALLOCATE */
2629 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2631 #ifdef __DRI_ALLOCATE
2632 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2634 if (psc
&& psc
->allocate
)
2635 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2641 #endif /* __DRI_ALLOCATE */
2646 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2648 #ifdef __DRI_ALLOCATE
2649 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2651 if (psc
&& psc
->allocate
)
2652 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2658 #endif /* GLX_DIRECT_RENDERING */
2667 * Mesa extension stubs. These will help reduce portability problems.
2672 * Release all buffers associated with the specified GLX drawable.
2675 * This function was intended for stand-alone Mesa. The issue there is that
2676 * the library doesn't get any notification when a window is closed. In
2677 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2678 * supported, there are 3 different functions to destroy a drawable. It
2679 * should be possible to create GLX protocol (or have it determine which
2680 * protocol to use based on the type of the drawable) to have one function
2681 * do the work of 3. For the direct-rendering case, this function could
2682 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2683 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2684 * would need to be used. This really should be done as part of the new DRI
2687 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2688 * __driGarbageCollectDrawables
2689 * glXDestroyGLXPixmap
2690 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2691 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2694 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2703 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2704 Pixmap pixmap
, Colormap cmap
)
2717 * GLX_MESA_copy_sub_buffer
2719 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2721 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2722 int x
, int y
, int width
, int height
)
2724 xGLXVendorPrivateReq
*req
;
2727 CARD32
*drawable_ptr
;
2728 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2731 #ifdef __DRI_COPY_SUB_BUFFER
2733 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2734 if (pdraw
!= NULL
) {
2735 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2736 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2738 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2745 opcode
= __glXSetupForCommand(dpy
);
2750 ** The calling thread may or may not have a current context. If it
2751 ** does, send the context tag so the server can do a flush.
2753 gc
= __glXGetCurrentContext();
2754 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2755 ((drawable
== gc
->currentDrawable
) ||
2756 (drawable
== gc
->currentReadable
))) {
2757 tag
= gc
->currentContextTag
;
2764 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2765 req
->reqType
= opcode
;
2766 req
->glxCode
= X_GLXVendorPrivate
;
2767 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2768 req
->contextTag
= tag
;
2770 drawable_ptr
= (CARD32
*) (req
+ 1);
2771 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2772 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2773 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2774 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2776 *drawable_ptr
= drawable
;
2788 * GLX_EXT_texture_from_pixmap
2792 __glXBindTexImageEXT(Display
* dpy
,
2793 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2795 xGLXVendorPrivateReq
*req
;
2796 GLXContext gc
= __glXGetCurrentContext();
2797 CARD32
*drawable_ptr
;
2799 CARD32
*num_attrib_ptr
;
2809 while (attrib_list
[i
* 2] != None
)
2813 #ifdef GLX_DIRECT_RENDERING
2814 if (gc
->driContext
) {
2815 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2817 if (pdraw
!= NULL
) {
2818 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2819 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2820 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2821 pdraw
->textureTarget
,
2822 pdraw
->textureFormat
,
2823 pdraw
->driDrawable
);
2826 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2827 pdraw
->textureTarget
,
2828 pdraw
->driDrawable
);
2835 opcode
= __glXSetupForCommand(dpy
);
2840 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2841 req
->reqType
= opcode
;
2842 req
->glxCode
= X_GLXVendorPrivate
;
2843 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2844 req
->contextTag
= gc
->currentContextTag
;
2846 drawable_ptr
= (CARD32
*) (req
+ 1);
2847 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2848 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2849 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2851 *drawable_ptr
= drawable
;
2852 *buffer_ptr
= buffer
;
2853 *num_attrib_ptr
= (CARD32
) i
;
2857 while (attrib_list
[i
* 2] != None
) {
2858 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2859 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2869 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2871 xGLXVendorPrivateReq
*req
;
2872 GLXContext gc
= __glXGetCurrentContext();
2873 CARD32
*drawable_ptr
;
2880 #ifdef GLX_DIRECT_RENDERING
2885 opcode
= __glXSetupForCommand(dpy
);
2890 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2891 req
->reqType
= opcode
;
2892 req
->glxCode
= X_GLXVendorPrivate
;
2893 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2894 req
->contextTag
= gc
->currentContextTag
;
2896 drawable_ptr
= (CARD32
*) (req
+ 1);
2897 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2899 *drawable_ptr
= drawable
;
2900 *buffer_ptr
= buffer
;
2909 * \c strdup is actually not a standard ANSI C or POSIX routine.
2910 * Irix will not define it if ANSI mode is in effect.
2915 __glXstrdup(const char *str
)
2918 copy
= (char *) Xmalloc(strlen(str
) + 1);
2926 ** glXGetProcAddress support
2929 struct name_address_pair
2935 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2936 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2938 static const struct name_address_pair GLX_functions
[] = {
2939 /*** GLX_VERSION_1_0 ***/
2940 GLX_FUNCTION(glXChooseVisual
),
2941 GLX_FUNCTION(glXCopyContext
),
2942 GLX_FUNCTION(glXCreateContext
),
2943 GLX_FUNCTION(glXCreateGLXPixmap
),
2944 GLX_FUNCTION(glXDestroyContext
),
2945 GLX_FUNCTION(glXDestroyGLXPixmap
),
2946 GLX_FUNCTION(glXGetConfig
),
2947 GLX_FUNCTION(glXGetCurrentContext
),
2948 GLX_FUNCTION(glXGetCurrentDrawable
),
2949 GLX_FUNCTION(glXIsDirect
),
2950 GLX_FUNCTION(glXMakeCurrent
),
2951 GLX_FUNCTION(glXQueryExtension
),
2952 GLX_FUNCTION(glXQueryVersion
),
2953 GLX_FUNCTION(glXSwapBuffers
),
2954 GLX_FUNCTION(glXUseXFont
),
2955 GLX_FUNCTION(glXWaitGL
),
2956 GLX_FUNCTION(glXWaitX
),
2958 /*** GLX_VERSION_1_1 ***/
2959 GLX_FUNCTION(glXGetClientString
),
2960 GLX_FUNCTION(glXQueryExtensionsString
),
2961 GLX_FUNCTION(glXQueryServerString
),
2963 /*** GLX_VERSION_1_2 ***/
2964 GLX_FUNCTION(glXGetCurrentDisplay
),
2966 /*** GLX_VERSION_1_3 ***/
2967 GLX_FUNCTION(glXChooseFBConfig
),
2968 GLX_FUNCTION(glXCreateNewContext
),
2969 GLX_FUNCTION(glXCreatePbuffer
),
2970 GLX_FUNCTION(glXCreatePixmap
),
2971 GLX_FUNCTION(glXCreateWindow
),
2972 GLX_FUNCTION(glXDestroyPbuffer
),
2973 GLX_FUNCTION(glXDestroyPixmap
),
2974 GLX_FUNCTION(glXDestroyWindow
),
2975 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2976 GLX_FUNCTION(glXGetFBConfigAttrib
),
2977 GLX_FUNCTION(glXGetFBConfigs
),
2978 GLX_FUNCTION(glXGetSelectedEvent
),
2979 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2980 GLX_FUNCTION(glXMakeContextCurrent
),
2981 GLX_FUNCTION(glXQueryContext
),
2982 GLX_FUNCTION(glXQueryDrawable
),
2983 GLX_FUNCTION(glXSelectEvent
),
2985 /*** GLX_SGI_swap_control ***/
2986 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2988 /*** GLX_SGI_video_sync ***/
2989 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2990 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2992 /*** GLX_SGI_make_current_read ***/
2993 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2994 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2996 /*** GLX_EXT_import_context ***/
2997 GLX_FUNCTION(glXFreeContextEXT
),
2998 GLX_FUNCTION(glXGetContextIDEXT
),
2999 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
3000 GLX_FUNCTION(glXImportContextEXT
),
3001 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3003 /*** GLX_SGIX_fbconfig ***/
3004 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3005 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3006 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3007 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3008 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3009 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3011 /*** GLX_SGIX_pbuffer ***/
3012 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3013 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3014 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3015 GLX_FUNCTION(glXSelectEventSGIX
),
3016 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3018 /*** GLX_SGIX_swap_group ***/
3019 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3021 /*** GLX_SGIX_swap_barrier ***/
3022 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3023 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3025 /*** GLX_MESA_allocate_memory ***/
3026 GLX_FUNCTION(glXAllocateMemoryMESA
),
3027 GLX_FUNCTION(glXFreeMemoryMESA
),
3028 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3030 /*** GLX_MESA_copy_sub_buffer ***/
3031 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3033 /*** GLX_MESA_pixmap_colormap ***/
3034 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3036 /*** GLX_MESA_release_buffers ***/
3037 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3039 /*** GLX_MESA_swap_control ***/
3040 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3041 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3043 /*** GLX_MESA_swap_frame_usage ***/
3044 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3045 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3046 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3047 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3049 /*** GLX_ARB_get_proc_address ***/
3050 GLX_FUNCTION(glXGetProcAddressARB
),
3053 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3055 /*** GLX_OML_sync_control ***/
3056 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3057 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3058 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3059 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3060 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3062 /*** GLX_EXT_texture_from_pixmap ***/
3063 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3064 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3066 #ifdef GLX_DIRECT_RENDERING
3067 /*** DRI configuration ***/
3068 GLX_FUNCTION(glXGetScreenDriver
),
3069 GLX_FUNCTION(glXGetDriverConfig
),
3072 {NULL
, NULL
} /* end of list */
3076 static const GLvoid
*
3077 get_glx_proc_address(const char *funcName
)
3081 /* try static functions */
3082 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3083 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3084 return GLX_functions
[i
].Address
;
3092 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3093 * \c glXGetProcAddress.
3095 * \param procName Name of a GL or GLX function.
3096 * \returns A pointer to the named function
3098 * \sa glXGetProcAddress
3100 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3102 typedef void (*gl_function
) (void);
3106 /* Search the table of GLX and internal functions first. If that
3107 * fails and the supplied name could be a valid core GL name, try
3108 * searching the core GL function table. This check is done to prevent
3109 * DRI based drivers from searching the core GL function table for
3110 * internal API functions.
3113 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3114 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3115 && (procName
[2] != 'X')) {
3116 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3123 * Get the address of a named GL function. This is the GLX 1.4 name for
3124 * \c glXGetProcAddressARB.
3126 * \param procName Name of a GL or GLX function.
3127 * \returns A pointer to the named function
3129 * \sa glXGetProcAddressARB
3131 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3132 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3133 __attribute__ ((alias("glXGetProcAddressARB")));
3136 return glXGetProcAddressARB(procName
);
3138 #endif /* __GNUC__ */
3141 #ifdef GLX_DIRECT_RENDERING
3143 * Get the unadjusted system time (UST). Currently, the UST is measured in
3144 * microseconds since Epoc. The actual resolution of the UST may vary from
3145 * system to system, and the units may vary from release to release.
3146 * Drivers should not call this function directly. They should instead use
3147 * \c glXGetProcAddress to obtain a pointer to the function.
3149 * \param ust Location to store the 64-bit UST
3150 * \returns Zero on success or a negative errno value on failure.
3152 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3154 * \since Internal API version 20030317.
3157 __glXGetUST(int64_t * ust
)
3165 if (gettimeofday(&tv
, NULL
) == 0) {
3166 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3173 #endif /* GLX_DIRECT_RENDERING */