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 unsigned code
, int renderType
, int screen
)
372 #ifdef GLX_DIRECT_RENDERING
373 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
381 gc
= AllocateGLXContext(dpy
);
385 if (None
== contextID
) {
386 if ((vis
== NULL
) && (fbconfig
== NULL
))
389 #ifdef GLX_DIRECT_RENDERING
390 if (allowDirect
&& psc
->driScreen
) {
391 const __GLcontextModes
*mode
;
393 if (fbconfig
== NULL
) {
394 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
398 error
.errorCode
= BadValue
;
399 error
.resourceID
= vis
->visualid
;
400 error
.sequenceNumber
= dpy
->request
;
401 error
.type
= X_Error
;
402 error
.majorCode
= gc
->majorOpcode
;
403 error
.minorCode
= X_GLXCreateContext
;
404 _XError(dpy
, &error
);
407 if (renderType
== 0) {
408 /* Initialize renderType now */
409 renderType
= mode
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
416 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
419 if (gc
->driContext
!= NULL
) {
420 gc
->screen
= mode
->screen
;
423 gc
->isDirect
= GL_TRUE
;
430 case X_GLXCreateContext
: {
431 xGLXCreateContextReq
*req
;
433 /* Send the glXCreateContext request */
434 GetReq(GLXCreateContext
, req
);
435 req
->reqType
= gc
->majorOpcode
;
436 req
->glxCode
= X_GLXCreateContext
;
437 req
->context
= gc
->xid
= XAllocID(dpy
);
438 req
->visual
= vis
->visualid
;
439 req
->screen
= vis
->screen
;
440 req
->shareList
= shareList
? shareList
->xid
: None
;
441 req
->isDirect
= GC_IS_DIRECT(gc
);
445 case X_GLXCreateNewContext
: {
446 xGLXCreateNewContextReq
*req
;
448 /* Send the glXCreateNewContext request */
449 GetReq(GLXCreateNewContext
, req
);
450 req
->reqType
= gc
->majorOpcode
;
451 req
->glxCode
= X_GLXCreateNewContext
;
452 req
->context
= gc
->xid
= XAllocID(dpy
);
453 req
->fbconfig
= fbconfig
->fbconfigID
;
454 req
->screen
= fbconfig
->screen
;
455 req
->renderType
= renderType
;
456 req
->shareList
= shareList
? shareList
->xid
: None
;
457 req
->isDirect
= GC_IS_DIRECT(gc
);
461 case X_GLXvop_CreateContextWithConfigSGIX
: {
462 xGLXVendorPrivateWithReplyReq
*vpreq
;
463 xGLXCreateContextWithConfigSGIXReq
*req
;
465 /* Send the glXCreateNewContext request */
466 GetReqExtra(GLXVendorPrivateWithReply
,
467 sz_xGLXCreateContextWithConfigSGIXReq
-
468 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
469 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
470 req
->reqType
= gc
->majorOpcode
;
471 req
->glxCode
= X_GLXVendorPrivateWithReply
;
472 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
473 req
->context
= gc
->xid
= XAllocID(dpy
);
474 req
->fbconfig
= fbconfig
->fbconfigID
;
475 req
->screen
= fbconfig
->screen
;
476 req
->renderType
= renderType
;
477 req
->shareList
= shareList
? shareList
->xid
: None
;
478 req
->isDirect
= GC_IS_DIRECT(gc
);
483 /* What to do here? This case is the sign of an internal error. It
484 * should never be reachable.
491 gc
->imported
= GL_FALSE
;
495 gc
->imported
= GL_TRUE
;
498 gc
->renderType
= renderType
;
504 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
505 GLXContext shareList
, Bool allowDirect
)
507 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
508 X_GLXCreateContext
, 0, vis
->screen
);
512 __glXFreeContext(__GLXcontext
* gc
)
515 XFree((char *) gc
->vendor
);
517 XFree((char *) gc
->renderer
);
519 XFree((char *) gc
->version
);
521 XFree((char *) gc
->extensions
);
522 __glFreeAttributeState(gc
);
523 XFree((char *) gc
->buf
);
524 Xfree((char *) gc
->client_state_private
);
530 ** Destroy the named context
533 DestroyContext(Display
* dpy
, GLXContext gc
)
535 xGLXDestroyContextReq
*req
;
540 opcode
= __glXSetupForCommand(dpy
);
541 if (!opcode
|| !gc
) {
547 imported
= gc
->imported
;
550 if (gc
->currentDpy
) {
551 /* This context is bound to some thread. According to the man page,
552 * we should not actually delete the context until it's unbound.
553 * Note that we set gc->xid = None above. In MakeContextCurrent()
554 * we check for that and delete the context there.
560 #ifdef GLX_DIRECT_RENDERING
561 /* Destroy the direct rendering context */
562 if (gc
->driContext
) {
563 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
564 gc
->driContext
= NULL
;
565 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
569 __glXFreeVertexArrayState(gc
);
571 if (gc
->currentDpy
) {
572 /* Have to free later cuz it's in use now */
576 /* Destroy the handle if not current to anybody */
578 __glXFreeContext(gc
);
583 ** This dpy also created the server side part of the context.
584 ** Send the glXDestroyContext request.
587 GetReq(GLXDestroyContext
, req
);
588 req
->reqType
= opcode
;
589 req
->glxCode
= X_GLXDestroyContext
;
597 glXDestroyContext(Display
* dpy
, GLXContext gc
)
599 DestroyContext(dpy
, gc
);
603 ** Return the major and minor version #s for the GLX extension
606 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
608 __GLXdisplayPrivate
*priv
;
610 /* Init the extension. This fetches the major and minor version. */
611 priv
= __glXInitialize(dpy
);
616 *major
= priv
->majorVersion
;
618 *minor
= priv
->minorVersion
;
623 ** Query the existance of the GLX extension
626 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
628 int major_op
, erb
, evb
;
631 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
642 ** Put a barrier in the token stream that forces the GL to finish its
643 ** work before X can proceed.
649 GLXContext gc
= __glXGetCurrentContext();
650 Display
*dpy
= gc
->currentDpy
;
655 /* Flush any pending commands out */
656 __glXFlushRenderBuffer(gc
, gc
->pc
);
658 #ifdef GLX_DIRECT_RENDERING
659 if (gc
->driContext
) {
661 __GLXDRIdrawable
*pdraw
=
662 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
665 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
667 if (psc
->driScreen
->waitGL
!= NULL
)
668 (*psc
->driScreen
->waitGL
) (pdraw
);
674 /* Send the glXWaitGL request */
676 GetReq(GLXWaitGL
, req
);
677 req
->reqType
= gc
->majorOpcode
;
678 req
->glxCode
= X_GLXWaitGL
;
679 req
->contextTag
= gc
->currentContextTag
;
685 ** Put a barrier in the token stream that forces X to finish its
686 ** work before GL can proceed.
692 GLXContext gc
= __glXGetCurrentContext();
693 Display
*dpy
= gc
->currentDpy
;
698 /* Flush any pending commands out */
699 __glXFlushRenderBuffer(gc
, gc
->pc
);
701 #ifdef GLX_DIRECT_RENDERING
702 if (gc
->driContext
) {
704 __GLXDRIdrawable
*pdraw
=
705 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
708 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
709 if (psc
->driScreen
->waitX
!= NULL
)
710 (*psc
->driScreen
->waitX
) (pdraw
);
719 ** Send the glXWaitX request.
722 GetReq(GLXWaitX
, req
);
723 req
->reqType
= gc
->majorOpcode
;
724 req
->glxCode
= X_GLXWaitX
;
725 req
->contextTag
= gc
->currentContextTag
;
731 glXUseXFont(Font font
, int first
, int count
, int listBase
)
733 xGLXUseXFontReq
*req
;
734 GLXContext gc
= __glXGetCurrentContext();
735 Display
*dpy
= gc
->currentDpy
;
740 /* Flush any pending commands out */
741 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
743 #ifdef GLX_DIRECT_RENDERING
744 if (gc
->driContext
) {
745 DRI_glXUseXFont(font
, first
, count
, listBase
);
750 /* Send the glXUseFont request */
752 GetReq(GLXUseXFont
, req
);
753 req
->reqType
= gc
->majorOpcode
;
754 req
->glxCode
= X_GLXUseXFont
;
755 req
->contextTag
= gc
->currentContextTag
;
759 req
->listBase
= listBase
;
764 /************************************************************************/
767 ** Copy the source context to the destination context using the
771 glXCopyContext(Display
* dpy
, GLXContext source
,
772 GLXContext dest
, unsigned long mask
)
774 xGLXCopyContextReq
*req
;
775 GLXContext gc
= __glXGetCurrentContext();
779 opcode
= __glXSetupForCommand(dpy
);
784 #ifdef GLX_DIRECT_RENDERING
785 if (gc
->driContext
) {
786 /* NOT_DONE: This does not work yet */
791 ** If the source is the current context, send its tag so that the context
792 ** can be flushed before the copy.
794 if (source
== gc
&& dpy
== gc
->currentDpy
) {
795 tag
= gc
->currentContextTag
;
801 /* Send the glXCopyContext request */
803 GetReq(GLXCopyContext
, req
);
804 req
->reqType
= opcode
;
805 req
->glxCode
= X_GLXCopyContext
;
806 req
->source
= source
? source
->xid
: None
;
807 req
->dest
= dest
? dest
->xid
: None
;
809 req
->contextTag
= tag
;
816 * Determine if a context uses direct rendering.
818 * \param dpy Display where the context was created.
819 * \param contextID ID of the context to be tested.
821 * \returns \c GL_TRUE if the context is direct rendering or not.
824 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
826 #if !defined(USE_XCB)
827 xGLXIsDirectReq
*req
;
828 xGLXIsDirectReply reply
;
832 opcode
= __glXSetupForCommand(dpy
);
838 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
839 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
844 const Bool is_direct
= reply
->is_direct
? True
: False
;
849 /* Send the glXIsDirect request */
851 GetReq(GLXIsDirect
, req
);
852 req
->reqType
= opcode
;
853 req
->glxCode
= X_GLXIsDirect
;
854 req
->context
= contextID
;
855 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
859 return reply
.isDirect
;
865 * Shouldn't this function \b always return \c GL_FALSE when
866 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
867 * the GLX protocol here at all?
870 glXIsDirect(Display
* dpy
, GLXContext gc
)
875 else if (GC_IS_DIRECT(gc
)) {
878 return __glXIsDirect(dpy
, gc
->xid
);
882 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
884 xGLXCreateGLXPixmapReq
*req
;
888 opcode
= __glXSetupForCommand(dpy
);
893 /* Send the glXCreateGLXPixmap request */
895 GetReq(GLXCreateGLXPixmap
, req
);
896 req
->reqType
= opcode
;
897 req
->glxCode
= X_GLXCreateGLXPixmap
;
898 req
->screen
= vis
->screen
;
899 req
->visual
= vis
->visualid
;
900 req
->pixmap
= pixmap
;
901 req
->glxpixmap
= xid
= XAllocID(dpy
);
905 #ifdef GLX_DIRECT_RENDERING
907 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
908 * is actually bound to a context... */
910 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
911 __GLXDRIdrawable
*pdraw
;
912 __GLXscreenConfigs
*psc
;
913 __GLcontextModes
*modes
;
915 psc
= &priv
->screenConfigs
[vis
->screen
];
916 if (psc
->driScreen
== NULL
)
918 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
919 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
921 fprintf(stderr
, "failed to create pixmap\n");
925 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
926 (*pdraw
->destroyDrawable
) (pdraw
);
927 return None
; /* FIXME: Check what we're supposed to do here... */
936 ** Destroy the named pixmap
939 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
941 xGLXDestroyGLXPixmapReq
*req
;
944 opcode
= __glXSetupForCommand(dpy
);
949 /* Send the glXDestroyGLXPixmap request */
951 GetReq(GLXDestroyGLXPixmap
, req
);
952 req
->reqType
= opcode
;
953 req
->glxCode
= X_GLXDestroyGLXPixmap
;
954 req
->glxpixmap
= glxpixmap
;
958 #ifdef GLX_DIRECT_RENDERING
961 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
962 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
963 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
966 (*pdraw
->destroyDrawable
) (pdraw
);
967 __glxHashDelete(psc
->drawHash
, glxpixmap
);
974 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
982 xGLXSwapBuffersReq
*req
;
985 #ifdef GLX_DIRECT_RENDERING
986 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
990 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
995 opcode
= __glXSetupForCommand(dpy
);
1001 ** The calling thread may or may not have a current context. If it
1002 ** does, send the context tag so the server can do a flush.
1004 gc
= __glXGetCurrentContext();
1005 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1006 ((drawable
== gc
->currentDrawable
)
1007 || (drawable
== gc
->currentReadable
))) {
1008 tag
= gc
->currentContextTag
;
1015 c
= XGetXCBConnection(dpy
);
1016 xcb_glx_swap_buffers(c
, tag
, drawable
);
1019 /* Send the glXSwapBuffers request */
1021 GetReq(GLXSwapBuffers
, req
);
1022 req
->reqType
= opcode
;
1023 req
->glxCode
= X_GLXSwapBuffers
;
1024 req
->drawable
= drawable
;
1025 req
->contextTag
= tag
;
1029 #endif /* USE_XCB */
1034 ** Return configuration information for the given display, screen and
1035 ** visual combination.
1038 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1041 __GLXdisplayPrivate
*priv
;
1042 __GLXscreenConfigs
*psc
;
1043 __GLcontextModes
*modes
;
1046 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1047 if (status
== Success
) {
1048 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1050 /* Lookup attribute after first finding a match on the visual */
1051 if (modes
!= NULL
) {
1052 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1055 status
= GLX_BAD_VISUAL
;
1059 ** If we can't find the config for this visual, this visual is not
1060 ** supported by the OpenGL implementation on the server.
1062 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1063 *value_return
= GL_FALSE
;
1070 /************************************************************************/
1073 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1074 GLboolean fbconfig_style_tags
)
1076 memset(config
, 0, sizeof(__GLcontextModes
));
1077 config
->visualID
= (XID
) GLX_DONT_CARE
;
1078 config
->visualType
= GLX_DONT_CARE
;
1080 /* glXChooseFBConfig specifies different defaults for these two than
1083 if (fbconfig_style_tags
) {
1084 config
->rgbMode
= GL_TRUE
;
1085 config
->doubleBufferMode
= GLX_DONT_CARE
;
1088 config
->visualRating
= GLX_DONT_CARE
;
1089 config
->transparentPixel
= GLX_NONE
;
1090 config
->transparentRed
= GLX_DONT_CARE
;
1091 config
->transparentGreen
= GLX_DONT_CARE
;
1092 config
->transparentBlue
= GLX_DONT_CARE
;
1093 config
->transparentAlpha
= GLX_DONT_CARE
;
1094 config
->transparentIndex
= GLX_DONT_CARE
;
1096 config
->drawableType
= GLX_WINDOW_BIT
;
1097 config
->renderType
=
1098 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1099 config
->xRenderable
= GLX_DONT_CARE
;
1100 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1102 config
->swapMethod
= GLX_DONT_CARE
;
1105 #define MATCH_DONT_CARE( param ) \
1107 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1108 && (a-> param != b-> param) ) { \
1113 #define MATCH_MINIMUM( param ) \
1115 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1116 && (a-> param > b-> param) ) { \
1121 #define MATCH_EXACT( param ) \
1123 if ( a-> param != b-> param) { \
1129 * Determine if two GLXFBConfigs are compatible.
1131 * \param a Application specified config to test.
1132 * \param b Server specified config to test against \c a.
1135 fbconfigs_compatible(const __GLcontextModes
* const a
,
1136 const __GLcontextModes
* const b
)
1138 MATCH_DONT_CARE(doubleBufferMode
);
1139 MATCH_DONT_CARE(visualType
);
1140 MATCH_DONT_CARE(visualRating
);
1141 MATCH_DONT_CARE(xRenderable
);
1142 MATCH_DONT_CARE(fbconfigID
);
1143 MATCH_DONT_CARE(swapMethod
);
1145 MATCH_MINIMUM(rgbBits
);
1146 MATCH_MINIMUM(numAuxBuffers
);
1147 MATCH_MINIMUM(redBits
);
1148 MATCH_MINIMUM(greenBits
);
1149 MATCH_MINIMUM(blueBits
);
1150 MATCH_MINIMUM(alphaBits
);
1151 MATCH_MINIMUM(depthBits
);
1152 MATCH_MINIMUM(stencilBits
);
1153 MATCH_MINIMUM(accumRedBits
);
1154 MATCH_MINIMUM(accumGreenBits
);
1155 MATCH_MINIMUM(accumBlueBits
);
1156 MATCH_MINIMUM(accumAlphaBits
);
1157 MATCH_MINIMUM(sampleBuffers
);
1158 MATCH_MINIMUM(maxPbufferWidth
);
1159 MATCH_MINIMUM(maxPbufferHeight
);
1160 MATCH_MINIMUM(maxPbufferPixels
);
1161 MATCH_MINIMUM(samples
);
1163 MATCH_DONT_CARE(stereoMode
);
1166 if (((a
->drawableType
& b
->drawableType
) == 0)
1167 || ((a
->renderType
& b
->renderType
) == 0)) {
1172 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1173 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1174 * Technically speaking, it is a bug in the DDX driver, but there is
1175 * enough of an installed base to work around the problem here. In any
1176 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1177 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1178 * 0 from the server to be a match to maintain backward compatibility with
1179 * the (broken) drivers.
1182 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1183 if (a
->transparentPixel
== GLX_NONE
) {
1184 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1188 MATCH_EXACT(transparentPixel
);
1191 switch (a
->transparentPixel
) {
1192 case GLX_TRANSPARENT_RGB
:
1193 MATCH_DONT_CARE(transparentRed
);
1194 MATCH_DONT_CARE(transparentGreen
);
1195 MATCH_DONT_CARE(transparentBlue
);
1196 MATCH_DONT_CARE(transparentAlpha
);
1199 case GLX_TRANSPARENT_INDEX
:
1200 MATCH_DONT_CARE(transparentIndex
);
1212 /* There's some trickly language in the GLX spec about how this is supposed
1213 * to work. Basically, if a given component size is either not specified
1214 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1215 * Well, that's really hard to do with the code as-is. This behavior is
1216 * closer to correct, but still not technically right.
1218 #define PREFER_LARGER_OR_ZERO(comp) \
1220 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1221 if ( ((*a)-> comp) == 0 ) { \
1224 else if ( ((*b)-> comp) == 0 ) { \
1228 return ((*b)-> comp) - ((*a)-> comp) ; \
1233 #define PREFER_LARGER(comp) \
1235 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1236 return ((*b)-> comp) - ((*a)-> comp) ; \
1240 #define PREFER_SMALLER(comp) \
1242 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1243 return ((*a)-> comp) - ((*b)-> comp) ; \
1248 * Compare two GLXFBConfigs. This function is intended to be used as the
1249 * compare function passed in to qsort.
1251 * \returns If \c a is a "better" config, according to the specification of
1252 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1253 * better, then a number greater than zero is return. If both are
1254 * equal, zero is returned.
1255 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1258 fbconfig_compare(const __GLcontextModes
* const *const a
,
1259 const __GLcontextModes
* const *const b
)
1261 /* The order of these comparisons must NOT change. It is defined by
1262 * the GLX 1.3 spec and ARB_multisample.
1265 PREFER_SMALLER(visualSelectGroup
);
1267 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1268 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1269 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1271 PREFER_SMALLER(visualRating
);
1273 /* This isn't quite right. It is supposed to compare the sum of the
1274 * components the user specifically set minimums for.
1276 PREFER_LARGER_OR_ZERO(redBits
);
1277 PREFER_LARGER_OR_ZERO(greenBits
);
1278 PREFER_LARGER_OR_ZERO(blueBits
);
1279 PREFER_LARGER_OR_ZERO(alphaBits
);
1281 PREFER_SMALLER(rgbBits
);
1283 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1284 /* Prefer single-buffer.
1286 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1289 PREFER_SMALLER(numAuxBuffers
);
1291 PREFER_LARGER_OR_ZERO(depthBits
);
1292 PREFER_SMALLER(stencilBits
);
1294 /* This isn't quite right. It is supposed to compare the sum of the
1295 * components the user specifically set minimums for.
1297 PREFER_LARGER_OR_ZERO(accumRedBits
);
1298 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1299 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1300 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1302 PREFER_SMALLER(visualType
);
1304 /* None of the multisample specs say where this comparison should happen,
1305 * so I put it near the end.
1307 PREFER_SMALLER(sampleBuffers
);
1308 PREFER_SMALLER(samples
);
1310 /* None of the pbuffer or fbconfig specs say that this comparison needs
1311 * to happen at all, but it seems like it should.
1313 PREFER_LARGER(maxPbufferWidth
);
1314 PREFER_LARGER(maxPbufferHeight
);
1315 PREFER_LARGER(maxPbufferPixels
);
1322 * Selects and sorts a subset of the supplied configs based on the attributes.
1323 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1324 * and \c glXChooseFBConfigSGIX.
1326 * \param configs Array of pointers to possible configs. The elements of
1327 * this array that do not meet the criteria will be set to
1328 * NULL. The remaining elements will be sorted according to
1329 * the various visual / FBConfig selection rules.
1330 * \param num_configs Number of elements in the \c configs array.
1331 * \param attribList Attributes used select from \c configs. This array is
1332 * terminated by a \c None tag. The array can either take
1333 * the form expected by \c glXChooseVisual (where boolean
1334 * tags do not have a value) or by \c glXChooseFBConfig
1335 * (where every tag has a value).
1336 * \param fbconfig_style_tags Selects whether \c attribList is in
1337 * \c glXChooseVisual style or
1338 * \c glXChooseFBConfig style.
1339 * \returns The number of valid elements left in \c configs.
1341 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1344 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1345 const int *attribList
, GLboolean fbconfig_style_tags
)
1347 __GLcontextModes test_config
;
1351 /* This is a fairly direct implementation of the selection method
1352 * described by GLX_SGIX_fbconfig. Start by culling out all the
1353 * configs that are not compatible with the selected parameter
1357 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1358 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1359 (const INT32
*) attribList
,
1360 GL_TRUE
, fbconfig_style_tags
);
1363 for (i
= 0; i
< num_configs
; i
++) {
1364 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1365 configs
[base
] = configs
[i
];
1374 if (base
< num_configs
) {
1375 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1378 /* After the incompatible configs are removed, the resulting
1379 * list is sorted according to the rules set out in the various
1383 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1384 (int (*)(const void *, const void *)) fbconfig_compare
);
1392 ** Return the visual that best matches the template. Return None if no
1393 ** visual matches the template.
1395 PUBLIC XVisualInfo
*
1396 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1398 XVisualInfo
*visualList
= NULL
;
1399 __GLXdisplayPrivate
*priv
;
1400 __GLXscreenConfigs
*psc
;
1401 __GLcontextModes test_config
;
1402 __GLcontextModes
*modes
;
1403 const __GLcontextModes
*best_config
= NULL
;
1406 ** Get a list of all visuals, return if list is empty
1408 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1414 ** Build a template from the defaults and the attribute list
1415 ** Free visual list and return if an unexpected token is encountered
1417 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1418 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1419 (const INT32
*) attribList
,
1423 ** Eliminate visuals that don't meet minimum requirements
1424 ** Compute a score for those that do
1425 ** Remember which visual, if any, got the highest score
1426 ** If no visual is acceptable, return None
1427 ** Otherwise, create an XVisualInfo list with just the selected X visual
1430 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1431 if (fbconfigs_compatible(&test_config
, modes
)
1432 && ((best_config
== NULL
)
1435 ((const __GLcontextModes
* const *const) &modes
,
1436 &best_config
) < 0))) {
1437 XVisualInfo visualTemplate
;
1438 XVisualInfo
*newList
;
1441 visualTemplate
.screen
= screen
;
1442 visualTemplate
.visualid
= modes
->visualID
;
1443 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1444 &visualTemplate
, &i
);
1448 visualList
= newList
;
1449 best_config
= modes
;
1459 glXQueryExtensionsString(Display
* dpy
, int screen
)
1461 __GLXscreenConfigs
*psc
;
1462 __GLXdisplayPrivate
*priv
;
1464 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1468 if (!psc
->effectiveGLXexts
) {
1469 if (!psc
->serverGLXexts
) {
1470 psc
->serverGLXexts
=
1471 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1475 __glXCalculateUsableExtensions(psc
,
1476 #ifdef GLX_DIRECT_RENDERING
1477 (psc
->driScreen
!= NULL
),
1481 priv
->minorVersion
);
1484 return psc
->effectiveGLXexts
;
1488 glXGetClientString(Display
* dpy
, int name
)
1494 return (__glXGLXClientVendorName
);
1496 return (__glXGLXClientVersion
);
1497 case GLX_EXTENSIONS
:
1498 return (__glXGetClientExtensions());
1505 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1507 __GLXscreenConfigs
*psc
;
1508 __GLXdisplayPrivate
*priv
;
1512 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1518 str
= &priv
->serverGLXvendor
;
1521 str
= &priv
->serverGLXversion
;
1523 case GLX_EXTENSIONS
:
1524 str
= &psc
->serverGLXexts
;
1531 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1538 __glXClientInfo(Display
* dpy
, int opcode
)
1540 char *ext_str
= __glXGetClientGLExtensionString();
1541 int size
= strlen(ext_str
) + 1;
1544 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1545 xcb_glx_client_info(c
,
1546 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1548 xGLXClientInfoReq
*req
;
1550 /* Send the glXClientInfo request */
1552 GetReq(GLXClientInfo
, req
);
1553 req
->reqType
= opcode
;
1554 req
->glxCode
= X_GLXClientInfo
;
1555 req
->major
= GLX_MAJOR_VERSION
;
1556 req
->minor
= GLX_MINOR_VERSION
;
1558 req
->length
+= (size
+ 3) >> 2;
1559 req
->numbytes
= size
;
1560 Data(dpy
, ext_str
, size
);
1564 #endif /* USE_XCB */
1571 ** EXT_import_context
1575 glXGetCurrentDisplay(void)
1577 GLXContext gc
= __glXGetCurrentContext();
1580 return gc
->currentDpy
;
1584 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1585 glXGetCurrentDisplay
)
1588 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1591 * \param dpy Display where \c ctx was created.
1592 * \param ctx Context to query.
1593 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1594 * or zero if the request failed due to internal problems (i.e.,
1595 * unable to allocate temporary memory, etc.)
1598 * This function dynamically determines whether to use the EXT_import_context
1599 * version of the protocol or the GLX 1.3 version of the protocol.
1601 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1603 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1604 xGLXQueryContextReply reply
;
1610 return GLX_BAD_CONTEXT
;
1612 opcode
= __glXSetupForCommand(dpy
);
1617 /* Send the glXQueryContextInfoEXT request */
1620 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1621 xGLXQueryContextReq
*req
;
1623 GetReq(GLXQueryContext
, req
);
1625 req
->reqType
= opcode
;
1626 req
->glxCode
= X_GLXQueryContext
;
1627 req
->context
= (unsigned int) (ctx
->xid
);
1630 xGLXVendorPrivateReq
*vpreq
;
1631 xGLXQueryContextInfoEXTReq
*req
;
1633 GetReqExtra(GLXVendorPrivate
,
1634 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1636 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1637 req
->reqType
= opcode
;
1638 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1639 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1640 req
->context
= (unsigned int) (ctx
->xid
);
1643 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1645 numValues
= reply
.n
;
1648 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1651 int *propList
, *pProp
;
1654 nPropListBytes
= numValues
<< 3;
1655 propList
= (int *) Xmalloc(nPropListBytes
);
1656 if (NULL
== propList
) {
1662 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1664 for (i
= 0; i
< numValues
; i
++) {
1666 case GLX_SHARE_CONTEXT_EXT
:
1667 ctx
->share_xid
= *pProp
++;
1669 case GLX_VISUAL_ID_EXT
:
1671 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1674 ctx
->screen
= *pProp
++;
1676 case GLX_FBCONFIG_ID
:
1678 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1681 case GLX_RENDER_TYPE
:
1682 ctx
->renderType
= *pProp
++;
1689 Xfree((char *) propList
);
1699 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1703 /* get the information from the server if we don't have it already */
1704 #ifdef GLX_DIRECT_RENDERING
1705 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1707 if (ctx
->mode
== NULL
) {
1709 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1710 if (Success
!= retVal
)
1713 switch (attribute
) {
1714 case GLX_SHARE_CONTEXT_EXT
:
1715 *value
= (int) (ctx
->share_xid
);
1717 case GLX_VISUAL_ID_EXT
:
1718 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1721 *value
= (int) (ctx
->screen
);
1723 case GLX_FBCONFIG_ID
:
1724 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1726 case GLX_RENDER_TYPE
:
1727 *value
= (int) (ctx
->renderType
);
1730 return GLX_BAD_ATTRIBUTE
;
1736 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1737 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1738 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1740 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1746 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1750 if (contextID
== None
) {
1753 if (__glXIsDirect(dpy
, contextID
)) {
1757 /* FIXME: Why does this call CreateContext? There is no protocol sent for
1758 * FIXME: this function.
1760 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
,
1761 X_GLXCreateContext
, 0, 0);
1763 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1771 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1773 DestroyContext(dpy
, ctx
);
1779 * GLX 1.3 functions - these are just stubs for now!
1782 PUBLIC GLXFBConfig
*
1783 glXChooseFBConfig(Display
* dpy
, int screen
,
1784 const int *attribList
, int *nitems
)
1786 __GLcontextModes
**config_list
;
1790 config_list
= (__GLcontextModes
**)
1791 glXGetFBConfigs(dpy
, screen
, &list_size
);
1793 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1794 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1795 if (list_size
== 0) {
1801 *nitems
= list_size
;
1802 return (GLXFBConfig
*) config_list
;
1807 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1808 int renderType
, GLXContext shareList
, Bool allowDirect
)
1810 const __GLcontextModes
*const fbconfig
=
1811 (const __GLcontextModes
*const) config
;
1813 return CreateContext(dpy
, NULL
, fbconfig
, shareList
,
1814 allowDirect
, None
, X_GLXCreateNewContext
, renderType
,
1820 glXGetCurrentReadDrawable(void)
1822 GLXContext gc
= __glXGetCurrentContext();
1823 return gc
->currentReadable
;
1827 PUBLIC GLXFBConfig
*
1828 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1830 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1831 __GLcontextModes
**config
= NULL
;
1835 if (priv
&& (priv
->screenConfigs
!= NULL
)
1836 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1837 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1838 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
1839 != (int) GLX_DONT_CARE
)) {
1840 unsigned num_configs
= 0;
1841 __GLcontextModes
*modes
;
1844 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1845 modes
= modes
->next
) {
1846 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1851 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1853 if (config
!= NULL
) {
1854 *nelements
= num_configs
;
1856 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1857 modes
= modes
->next
) {
1858 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1865 return (GLXFBConfig
*) config
;
1870 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1871 int attribute
, int *value
)
1873 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1875 return (modes
!= NULL
)
1876 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1881 PUBLIC XVisualInfo
*
1882 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1884 XVisualInfo visualTemplate
;
1885 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1889 ** Get a list of all visuals, return if list is empty
1891 visualTemplate
.visualid
= fbconfig
->visualID
;
1892 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1897 ** GLX_SGI_swap_control
1900 __glXSwapIntervalSGI(int interval
)
1902 xGLXVendorPrivateReq
*req
;
1903 GLXContext gc
= __glXGetCurrentContext();
1904 __GLXscreenConfigs
*psc
;
1906 CARD32
*interval_ptr
;
1910 return GLX_BAD_CONTEXT
;
1913 if (interval
<= 0) {
1914 return GLX_BAD_VALUE
;
1917 #ifdef __DRI_SWAP_CONTROL
1918 if (gc
->driContext
) {
1919 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1921 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1922 gc
->currentDrawable
,
1924 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1925 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1928 else if (pdraw
== NULL
) {
1929 return GLX_BAD_CONTEXT
;
1933 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1935 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1936 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1937 gc
->currentDrawable
,
1939 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1943 dpy
= gc
->currentDpy
;
1944 opcode
= __glXSetupForCommand(dpy
);
1949 /* Send the glXSwapIntervalSGI request */
1951 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1952 req
->reqType
= opcode
;
1953 req
->glxCode
= X_GLXVendorPrivate
;
1954 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1955 req
->contextTag
= gc
->currentContextTag
;
1957 interval_ptr
= (CARD32
*) (req
+ 1);
1958 *interval_ptr
= interval
;
1969 ** GLX_MESA_swap_control
1972 __glXSwapIntervalMESA(unsigned int interval
)
1974 GLXContext gc
= __glXGetCurrentContext();
1976 #ifdef __DRI_SWAP_CONTROL
1977 if (gc
!= NULL
&& gc
->driContext
) {
1978 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1981 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1982 __GLXDRIdrawable
*pdraw
=
1983 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1984 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1985 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1992 if (gc
!= NULL
&& gc
->driContext
) {
1993 __GLXscreenConfigs
*psc
;
1995 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1996 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1997 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1998 gc
->currentDrawable
, NULL
);
1999 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2004 return GLX_BAD_CONTEXT
;
2009 __glXGetSwapIntervalMESA(void)
2011 #ifdef __DRI_SWAP_CONTROL
2012 GLXContext gc
= __glXGetCurrentContext();
2014 if (gc
!= NULL
&& gc
->driContext
) {
2015 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2018 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2019 __GLXDRIdrawable
*pdraw
=
2020 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2021 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2022 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2027 if (gc
!= NULL
&& gc
->driContext
) {
2028 __GLXscreenConfigs
*psc
;
2030 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2031 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2032 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2033 gc
->currentDrawable
, NULL
);
2034 return psc
->driScreen
->getSwapInterval(pdraw
);
2043 ** GLX_MESA_swap_frame_usage
2047 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2049 int status
= GLX_BAD_CONTEXT
;
2050 #ifdef __DRI_FRAME_TRACKING
2052 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2053 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2055 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2056 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2066 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2068 int status
= GLX_BAD_CONTEXT
;
2069 #ifdef __DRI_FRAME_TRACKING
2071 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2072 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2074 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2075 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2086 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2088 int status
= GLX_BAD_CONTEXT
;
2089 #ifdef __DRI_FRAME_TRACKING
2091 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2092 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2094 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2095 int64_t sbc
, missedFrames
;
2096 float lastMissedUsage
;
2098 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2114 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2115 int64_t * sbc
, int64_t * missedFrames
,
2116 GLfloat
* lastMissedUsage
)
2118 int status
= GLX_BAD_CONTEXT
;
2119 #ifdef __DRI_FRAME_TRACKING
2121 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2122 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2124 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2127 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2136 (void) missedFrames
;
2137 (void) lastMissedUsage
;
2144 ** GLX_SGI_video_sync
2147 __glXGetVideoSyncSGI(unsigned int *count
)
2149 int64_t ust
, msc
, sbc
;
2151 GLXContext gc
= __glXGetCurrentContext();
2152 __GLXscreenConfigs
*psc
;
2153 __GLXDRIdrawable
*pdraw
;
2155 if (!gc
|| !gc
->driContext
)
2156 return GLX_BAD_CONTEXT
;
2158 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2159 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2161 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2162 * FIXME: there should be a GLX encoding for this call. I can find no
2163 * FIXME: documentation for the GLX encoding.
2165 #ifdef __DRI_MEDIA_STREAM_COUNTER
2166 if ( psc
->msc
&& psc
->driScreen
) {
2167 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2168 pdraw
->driDrawable
, &msc
);
2169 *count
= (unsigned) msc
;
2171 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2174 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2175 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2176 *count
= (unsigned) msc
;
2177 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2180 return GLX_BAD_CONTEXT
;
2184 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2186 GLXContext gc
= __glXGetCurrentContext();
2187 __GLXscreenConfigs
*psc
;
2188 __GLXDRIdrawable
*pdraw
;
2189 int64_t ust
, msc
, sbc
;
2192 if (divisor
<= 0 || remainder
< 0)
2193 return GLX_BAD_VALUE
;
2195 if (!gc
|| !gc
->driContext
)
2196 return GLX_BAD_CONTEXT
;
2198 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2199 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2201 #ifdef __DRI_MEDIA_STREAM_COUNTER
2202 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2203 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2204 divisor
, remainder
, &msc
, &sbc
);
2205 *count
= (unsigned) msc
;
2206 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2209 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2210 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2212 *count
= (unsigned) msc
;
2213 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2216 return GLX_BAD_CONTEXT
;
2221 ** GLX_SGIX_fbconfig
2222 ** Many of these functions are aliased to GLX 1.3 entry points in the
2223 ** GLX_functions table.
2227 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2228 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2229 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2231 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2232 (Display
* dpy
, int screen
, int *attrib_list
,
2233 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2236 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2237 (Display
* dpy
, GLXFBConfigSGIX config
),
2238 (dpy
, config
), glXGetVisualFromFBConfig
)
2241 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2242 GLXFBConfigSGIX config
,
2245 xGLXVendorPrivateWithReplyReq
*vpreq
;
2246 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2247 GLXPixmap xid
= None
;
2249 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2250 __GLXscreenConfigs
*psc
;
2253 if ((dpy
== NULL
) || (config
== NULL
)) {
2257 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2259 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2260 opcode
= __glXSetupForCommand(dpy
);
2265 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2267 GetReqExtra(GLXVendorPrivateWithReply
,
2268 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2269 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2270 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2271 req
->reqType
= opcode
;
2272 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2273 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2274 req
->screen
= fbconfig
->screen
;
2275 req
->fbconfig
= fbconfig
->fbconfigID
;
2276 req
->pixmap
= pixmap
;
2277 req
->glxpixmap
= xid
= XAllocID(dpy
);
2286 glXCreateContextWithConfigSGIX(Display
* dpy
,
2287 GLXFBConfigSGIX config
, int renderType
,
2288 GLXContext shareList
, Bool allowDirect
)
2290 GLXContext gc
= NULL
;
2291 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2292 __GLXscreenConfigs
*psc
;
2295 if ((dpy
== NULL
) || (config
== NULL
)) {
2299 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2301 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2302 gc
= CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2304 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2312 PUBLIC GLXFBConfigSGIX
2313 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2315 __GLXdisplayPrivate
*priv
;
2316 __GLXscreenConfigs
*psc
= NULL
;
2318 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2319 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2320 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2321 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2330 ** GLX_SGIX_swap_group
2333 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2343 ** GLX_SGIX_swap_barrier
2346 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2354 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2364 ** GLX_OML_sync_control
2367 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2368 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2370 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2372 __GLXDRIdrawable
*pdraw
;
2373 __GLXscreenConfigs
*psc
;
2378 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2379 psc
= &priv
->screenConfigs
[i
];
2381 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2382 if (pdraw
&& psc
->sbc
&& psc
->sbc
)
2383 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2384 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2385 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2386 && (__glXGetUST(ust
) == 0) );
2388 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2389 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2396 #ifdef GLX_DIRECT_RENDERING
2398 __driGetMscRateOML(__DRIdrawable
* draw
,
2399 int32_t * numerator
, int32_t * denominator
, void *private)
2402 __GLXscreenConfigs
*psc
;
2403 XF86VidModeModeLine mode_line
;
2406 __GLXDRIdrawable
*glxDraw
= private;
2411 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2412 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2413 unsigned n
= dot_clock
* 1000;
2414 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2416 # define V_INTERLACE 0x010
2417 # define V_DBLSCAN 0x020
2419 if (mode_line
.flags
& V_INTERLACE
)
2421 else if (mode_line
.flags
& V_DBLSCAN
)
2424 /* The OML_sync_control spec requires that if the refresh rate is a
2425 * whole number, that the returned numerator be equal to the refresh
2426 * rate and the denominator be 1.
2434 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2436 /* This is a poor man's way to reduce a fraction. It's far from
2437 * perfect, but it will work well enough for this situation.
2440 for (i
= 0; f
[i
] != 0; i
++) {
2441 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2467 * Determine the refresh rate of the specified drawable and display.
2469 * \param dpy Display whose refresh rate is to be determined.
2470 * \param drawable Drawable whose refresh rate is to be determined.
2471 * \param numerator Numerator of the refresh rate.
2472 * \param demoninator Denominator of the refresh rate.
2473 * \return If the refresh rate for the specified display and drawable could
2474 * be calculated, True is returned. Otherwise False is returned.
2476 * \note This function is implemented entirely client-side. A lot of other
2477 * functionality is required to export GLX_OML_sync_control, so on
2478 * XFree86 this function can be called for direct-rendering contexts
2479 * when GLX_OML_sync_control appears in the client extension string.
2483 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2484 int32_t * numerator
, int32_t * denominator
)
2486 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2487 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2492 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2504 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2505 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2507 GLXContext gc
= __glXGetCurrentContext();
2509 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2510 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2512 if (!pdraw
|| !gc
->driContext
) /* no GLX for this */
2515 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2516 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2517 * of -1 if the function failed because of errors detected in the input
2520 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2522 if (divisor
> 0 && remainder
>= divisor
)
2525 #ifdef __DRI_SWAP_BUFFER_COUNTER
2526 if (psc
->counters
!= NULL
)
2527 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2528 divisor
, remainder
);
2531 #ifdef GLX_DIRECT_RENDERING
2532 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2533 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2542 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2543 int64_t target_msc
, int64_t divisor
,
2544 int64_t remainder
, int64_t * ust
,
2545 int64_t * msc
, int64_t * sbc
)
2548 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2549 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2552 fprintf(stderr
, "waitmsc: %lld, %lld, %lld\n", target_msc
, divisor
,
2555 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2556 * error", but the return type in the spec is Bool.
2558 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2560 if (divisor
> 0 && remainder
>= divisor
)
2563 #ifdef __DRI_MEDIA_STREAM_COUNTER
2564 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2565 fprintf(stderr
, "dri1 msc\n");
2566 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2567 divisor
, remainder
, msc
, sbc
);
2569 /* __glXGetUST returns zero on success and non-zero on failure.
2570 * This function returns True on success and False on failure.
2572 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2575 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2576 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2581 fprintf(stderr
, "no drawable??\n");
2587 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2588 int64_t target_sbc
, int64_t * ust
,
2589 int64_t * msc
, int64_t * sbc
)
2592 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2593 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2596 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2597 * error", but the return type in the spec is Bool.
2601 #ifdef __DRI_SWAP_BUFFER_COUNTER
2602 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2604 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2606 /* __glXGetUST returns zero on success and non-zero on failure.
2607 * This function returns True on success and False on failure.
2609 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2612 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2613 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2621 * GLX_MESA_allocate_memory
2626 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2627 size_t size
, float readFreq
,
2628 float writeFreq
, float priority
)
2630 #ifdef __DRI_ALLOCATE
2631 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2633 if (psc
&& psc
->allocate
)
2634 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2635 readFreq
, writeFreq
, priority
);
2644 #endif /* __DRI_ALLOCATE */
2651 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2653 #ifdef __DRI_ALLOCATE
2654 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2656 if (psc
&& psc
->allocate
)
2657 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2663 #endif /* __DRI_ALLOCATE */
2668 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2670 #ifdef __DRI_ALLOCATE
2671 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2673 if (psc
&& psc
->allocate
)
2674 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2680 #endif /* GLX_DIRECT_RENDERING */
2689 * Mesa extension stubs. These will help reduce portability problems.
2694 * Release all buffers associated with the specified GLX drawable.
2697 * This function was intended for stand-alone Mesa. The issue there is that
2698 * the library doesn't get any notification when a window is closed. In
2699 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2700 * supported, there are 3 different functions to destroy a drawable. It
2701 * should be possible to create GLX protocol (or have it determine which
2702 * protocol to use based on the type of the drawable) to have one function
2703 * do the work of 3. For the direct-rendering case, this function could
2704 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2705 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2706 * would need to be used. This really should be done as part of the new DRI
2709 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2710 * __driGarbageCollectDrawables
2711 * glXDestroyGLXPixmap
2712 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2713 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2716 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2725 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2726 Pixmap pixmap
, Colormap cmap
)
2739 * GLX_MESA_copy_sub_buffer
2741 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2743 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2744 int x
, int y
, int width
, int height
)
2746 xGLXVendorPrivateReq
*req
;
2749 CARD32
*drawable_ptr
;
2750 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2753 #ifdef __DRI_COPY_SUB_BUFFER
2755 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2756 if (pdraw
!= NULL
) {
2757 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2758 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2760 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2767 opcode
= __glXSetupForCommand(dpy
);
2772 ** The calling thread may or may not have a current context. If it
2773 ** does, send the context tag so the server can do a flush.
2775 gc
= __glXGetCurrentContext();
2776 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2777 ((drawable
== gc
->currentDrawable
) ||
2778 (drawable
== gc
->currentReadable
))) {
2779 tag
= gc
->currentContextTag
;
2786 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2787 req
->reqType
= opcode
;
2788 req
->glxCode
= X_GLXVendorPrivate
;
2789 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2790 req
->contextTag
= tag
;
2792 drawable_ptr
= (CARD32
*) (req
+ 1);
2793 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2794 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2795 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2796 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2798 *drawable_ptr
= drawable
;
2810 * GLX_EXT_texture_from_pixmap
2814 __glXBindTexImageEXT(Display
* dpy
,
2815 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2817 xGLXVendorPrivateReq
*req
;
2818 GLXContext gc
= __glXGetCurrentContext();
2819 CARD32
*drawable_ptr
;
2821 CARD32
*num_attrib_ptr
;
2831 while (attrib_list
[i
* 2] != None
)
2835 #ifdef GLX_DIRECT_RENDERING
2836 if (gc
->driContext
) {
2837 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2839 if (pdraw
!= NULL
) {
2840 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2841 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2842 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2843 pdraw
->textureTarget
,
2844 pdraw
->textureFormat
,
2845 pdraw
->driDrawable
);
2848 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2849 pdraw
->textureTarget
,
2850 pdraw
->driDrawable
);
2857 opcode
= __glXSetupForCommand(dpy
);
2862 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2863 req
->reqType
= opcode
;
2864 req
->glxCode
= X_GLXVendorPrivate
;
2865 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2866 req
->contextTag
= gc
->currentContextTag
;
2868 drawable_ptr
= (CARD32
*) (req
+ 1);
2869 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2870 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2871 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2873 *drawable_ptr
= drawable
;
2874 *buffer_ptr
= buffer
;
2875 *num_attrib_ptr
= (CARD32
) i
;
2879 while (attrib_list
[i
* 2] != None
) {
2880 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2881 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2891 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2893 xGLXVendorPrivateReq
*req
;
2894 GLXContext gc
= __glXGetCurrentContext();
2895 CARD32
*drawable_ptr
;
2899 if ((gc
== NULL
) || GC_IS_DIRECT(gc
))
2902 opcode
= __glXSetupForCommand(dpy
);
2907 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2908 req
->reqType
= opcode
;
2909 req
->glxCode
= X_GLXVendorPrivate
;
2910 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2911 req
->contextTag
= gc
->currentContextTag
;
2913 drawable_ptr
= (CARD32
*) (req
+ 1);
2914 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2916 *drawable_ptr
= drawable
;
2917 *buffer_ptr
= buffer
;
2926 * \c strdup is actually not a standard ANSI C or POSIX routine.
2927 * Irix will not define it if ANSI mode is in effect.
2932 __glXstrdup(const char *str
)
2935 copy
= (char *) Xmalloc(strlen(str
) + 1);
2943 ** glXGetProcAddress support
2946 struct name_address_pair
2952 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2953 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2955 static const struct name_address_pair GLX_functions
[] = {
2956 /*** GLX_VERSION_1_0 ***/
2957 GLX_FUNCTION(glXChooseVisual
),
2958 GLX_FUNCTION(glXCopyContext
),
2959 GLX_FUNCTION(glXCreateContext
),
2960 GLX_FUNCTION(glXCreateGLXPixmap
),
2961 GLX_FUNCTION(glXDestroyContext
),
2962 GLX_FUNCTION(glXDestroyGLXPixmap
),
2963 GLX_FUNCTION(glXGetConfig
),
2964 GLX_FUNCTION(glXGetCurrentContext
),
2965 GLX_FUNCTION(glXGetCurrentDrawable
),
2966 GLX_FUNCTION(glXIsDirect
),
2967 GLX_FUNCTION(glXMakeCurrent
),
2968 GLX_FUNCTION(glXQueryExtension
),
2969 GLX_FUNCTION(glXQueryVersion
),
2970 GLX_FUNCTION(glXSwapBuffers
),
2971 GLX_FUNCTION(glXUseXFont
),
2972 GLX_FUNCTION(glXWaitGL
),
2973 GLX_FUNCTION(glXWaitX
),
2975 /*** GLX_VERSION_1_1 ***/
2976 GLX_FUNCTION(glXGetClientString
),
2977 GLX_FUNCTION(glXQueryExtensionsString
),
2978 GLX_FUNCTION(glXQueryServerString
),
2980 /*** GLX_VERSION_1_2 ***/
2981 GLX_FUNCTION(glXGetCurrentDisplay
),
2983 /*** GLX_VERSION_1_3 ***/
2984 GLX_FUNCTION(glXChooseFBConfig
),
2985 GLX_FUNCTION(glXCreateNewContext
),
2986 GLX_FUNCTION(glXCreatePbuffer
),
2987 GLX_FUNCTION(glXCreatePixmap
),
2988 GLX_FUNCTION(glXCreateWindow
),
2989 GLX_FUNCTION(glXDestroyPbuffer
),
2990 GLX_FUNCTION(glXDestroyPixmap
),
2991 GLX_FUNCTION(glXDestroyWindow
),
2992 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2993 GLX_FUNCTION(glXGetFBConfigAttrib
),
2994 GLX_FUNCTION(glXGetFBConfigs
),
2995 GLX_FUNCTION(glXGetSelectedEvent
),
2996 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2997 GLX_FUNCTION(glXMakeContextCurrent
),
2998 GLX_FUNCTION(glXQueryContext
),
2999 GLX_FUNCTION(glXQueryDrawable
),
3000 GLX_FUNCTION(glXSelectEvent
),
3002 /*** GLX_SGI_swap_control ***/
3003 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
3005 /*** GLX_SGI_video_sync ***/
3006 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
3007 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
3009 /*** GLX_SGI_make_current_read ***/
3010 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
3011 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
3013 /*** GLX_EXT_import_context ***/
3014 GLX_FUNCTION(glXFreeContextEXT
),
3015 GLX_FUNCTION(glXGetContextIDEXT
),
3016 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
3017 GLX_FUNCTION(glXImportContextEXT
),
3018 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3020 /*** GLX_SGIX_fbconfig ***/
3021 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3022 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3023 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3024 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3025 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3026 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3028 /*** GLX_SGIX_pbuffer ***/
3029 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3030 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3031 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3032 GLX_FUNCTION(glXSelectEventSGIX
),
3033 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3035 /*** GLX_SGIX_swap_group ***/
3036 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3038 /*** GLX_SGIX_swap_barrier ***/
3039 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3040 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3042 /*** GLX_MESA_allocate_memory ***/
3043 GLX_FUNCTION(glXAllocateMemoryMESA
),
3044 GLX_FUNCTION(glXFreeMemoryMESA
),
3045 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3047 /*** GLX_MESA_copy_sub_buffer ***/
3048 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3050 /*** GLX_MESA_pixmap_colormap ***/
3051 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3053 /*** GLX_MESA_release_buffers ***/
3054 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3056 /*** GLX_MESA_swap_control ***/
3057 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3058 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3060 /*** GLX_MESA_swap_frame_usage ***/
3061 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3062 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3063 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3064 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3066 /*** GLX_ARB_get_proc_address ***/
3067 GLX_FUNCTION(glXGetProcAddressARB
),
3070 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3072 /*** GLX_OML_sync_control ***/
3073 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3074 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3075 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3076 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3077 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3079 /*** GLX_EXT_texture_from_pixmap ***/
3080 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3081 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3083 #ifdef GLX_DIRECT_RENDERING
3084 /*** DRI configuration ***/
3085 GLX_FUNCTION(glXGetScreenDriver
),
3086 GLX_FUNCTION(glXGetDriverConfig
),
3089 {NULL
, NULL
} /* end of list */
3093 static const GLvoid
*
3094 get_glx_proc_address(const char *funcName
)
3098 /* try static functions */
3099 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3100 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3101 return GLX_functions
[i
].Address
;
3109 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3110 * \c glXGetProcAddress.
3112 * \param procName Name of a GL or GLX function.
3113 * \returns A pointer to the named function
3115 * \sa glXGetProcAddress
3117 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3119 typedef void (*gl_function
) (void);
3123 /* Search the table of GLX and internal functions first. If that
3124 * fails and the supplied name could be a valid core GL name, try
3125 * searching the core GL function table. This check is done to prevent
3126 * DRI based drivers from searching the core GL function table for
3127 * internal API functions.
3130 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3131 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3132 && (procName
[2] != 'X')) {
3133 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3140 * Get the address of a named GL function. This is the GLX 1.4 name for
3141 * \c glXGetProcAddressARB.
3143 * \param procName Name of a GL or GLX function.
3144 * \returns A pointer to the named function
3146 * \sa glXGetProcAddressARB
3148 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3149 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3150 __attribute__ ((alias("glXGetProcAddressARB")));
3153 return glXGetProcAddressARB(procName
);
3155 #endif /* __GNUC__ */
3158 #ifdef GLX_DIRECT_RENDERING
3160 * Get the unadjusted system time (UST). Currently, the UST is measured in
3161 * microseconds since Epoc. The actual resolution of the UST may vary from
3162 * system to system, and the units may vary from release to release.
3163 * Drivers should not call this function directly. They should instead use
3164 * \c glXGetProcAddress to obtain a pointer to the function.
3166 * \param ust Location to store the 64-bit UST
3167 * \returns Zero on success or a negative errno value on failure.
3169 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3171 * \since Internal API version 20030317.
3174 __glXGetUST(int64_t * ust
)
3182 if (gettimeofday(&tv
, NULL
) == 0) {
3183 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3190 #endif /* GLX_DIRECT_RENDERING */