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
[] = "SGI";
54 static const char __glXGLXClientVersion
[] = "1.4";
57 /****************************************************************************/
59 #ifdef GLX_DIRECT_RENDERING
61 static Bool windowExistsFlag
;
62 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
64 if (xerr
->error_code
== BadWindow
) {
65 windowExistsFlag
= GL_FALSE
;
71 * Find drawables in the local hash that have been destroyed on the
74 * \param dpy Display to destroy drawables for
75 * \param screen Screen number to destroy drawables for
77 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
80 __GLXDRIdrawable
*pdraw
;
81 XWindowAttributes xwa
;
82 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
84 /* Set no-op error handler so Xlib doesn't bail out if the windows
85 * has alreay been destroyed on the server. */
87 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
89 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
91 windowExistsFlag
= GL_TRUE
;
92 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
93 if (!windowExistsFlag
) {
94 /* Destroy the local drawable data, if the drawable no
95 longer exists in the Xserver */
96 (*pdraw
->destroyDrawable
)(pdraw
);
97 __glxHashDelete(sc
->drawHash
, draw
);
99 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
102 XSync(dpy
, GL_FALSE
);
103 XSetErrorHandler(oldXErrorHandler
);
106 extern __GLXDRIdrawable
*
107 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
);
110 * Get the __DRIdrawable for the drawable associated with a GLXContext
112 * \param dpy The display associated with \c drawable.
113 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
114 * \param scrn_num If non-NULL, the drawables screen is stored there
115 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
116 * the drawable is not associated with a direct-rendering context.
118 _X_HIDDEN __GLXDRIdrawable
*
119 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
121 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
122 __GLXDRIdrawable
*pdraw
;
123 const unsigned screen_count
= ScreenCount(dpy
);
125 __GLXscreenConfigs
*psc
;
130 for (i
= 0; i
< screen_count
; i
++) {
131 psc
= &priv
->screenConfigs
[i
];
132 if (psc
->drawHash
== NULL
)
135 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
136 if (scrn_num
!= NULL
)
149 * Get the GLX per-screen data structure associated with a GLX context.
151 * \param dpy Display for which the GLX per-screen information is to be
153 * \param scrn Screen on \c dpy for which the GLX per-screen information is
155 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
156 * specify a valid GLX screen, or NULL otherwise.
158 * \todo Should this function validate that \c scrn is within the screen
159 * number range for \c dpy?
162 static __GLXscreenConfigs
*
163 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
165 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
167 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
172 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
173 __GLXscreenConfigs
** ppsc
)
175 /* Initialize the extension, if needed . This has the added value
176 * of initializing/allocating the display private
180 return GLX_NO_EXTENSION
;
183 *ppriv
= __glXInitialize(dpy
);
184 if ( *ppriv
== NULL
) {
185 return GLX_NO_EXTENSION
;
188 /* Check screen number to see if its valid */
189 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
190 return GLX_BAD_SCREEN
;
193 /* Check to see if the GL is supported on this screen */
194 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
195 if ( (*ppsc
)->configs
== NULL
) {
196 /* No support for GL on this screen regardless of visual */
197 return GLX_BAD_VISUAL
;
205 * Determine if a \c GLXFBConfig supplied by the application is valid.
207 * \param dpy Application supplied \c Display pointer.
208 * \param config Application supplied \c GLXFBConfig.
210 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
211 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
214 static __GLcontextModes
*
215 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
217 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
218 const unsigned num_screens
= ScreenCount(dpy
);
220 const __GLcontextModes
* modes
;
223 if ( priv
!= NULL
) {
224 for ( i
= 0 ; i
< num_screens
; i
++ ) {
225 for ( modes
= priv
->screenConfigs
[i
].configs
227 ; modes
= modes
->next
) {
228 if ( modes
== (__GLcontextModes
*) config
) {
229 return (__GLcontextModes
*) config
;
240 * \todo It should be possible to move the allocate of \c client_state_private
241 * later in the function for direct-rendering contexts. Direct-rendering
242 * contexts don't need to track client state, so they don't need that memory
245 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
246 * function called \c __glXAllocateClientState that allocates the memory and
247 * does all the initialization (including the pixel pack / unpack).
250 GLXContext
AllocateGLXContext( Display
*dpy
)
255 __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
327 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
330 gc
->majorOpcode
= opcode
;
333 ** Constrain the maximum drawing command size allowed to be
334 ** transfered using the X_GLXRender protocol request. First
335 ** constrain by a software limit, then constrain by the protocl
338 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
339 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
341 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
342 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
344 gc
->maxSmallRenderCommandSize
= bufSize
;
350 * Create a new context. Exactly one of \c vis and \c fbconfig should be
353 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
354 * SGIX_fbconfig protocol be used?
355 * \param renderType For FBConfigs, what is the rendering type?
359 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
360 const __GLcontextModes
* const fbconfig
,
361 GLXContext shareList
,
362 Bool allowDirect
, GLXContextID contextID
,
363 Bool use_glx_1_3
, int renderType
)
366 #ifdef GLX_DIRECT_RENDERING
367 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
368 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
374 gc
= AllocateGLXContext(dpy
);
378 if (None
== contextID
) {
379 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
382 #ifdef GLX_DIRECT_RENDERING
383 if (allowDirect
&& psc
->driScreen
) {
384 const __GLcontextModes
* mode
;
386 if (fbconfig
== NULL
) {
387 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
391 error
.errorCode
= BadValue
;
392 error
.resourceID
= vis
->visualid
;
393 error
.sequenceNumber
= dpy
->request
;
394 error
.type
= X_Error
;
395 error
.majorCode
= gc
->majorOpcode
;
396 error
.minorCode
= X_GLXCreateContext
;
397 _XError(dpy
, &error
);
405 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
408 if (gc
->driContext
!= NULL
) {
409 gc
->screen
= mode
->screen
;
412 gc
->isDirect
= GL_TRUE
;
418 if ( fbconfig
== NULL
) {
419 xGLXCreateContextReq
*req
;
421 /* Send the glXCreateContext request */
422 GetReq(GLXCreateContext
,req
);
423 req
->reqType
= gc
->majorOpcode
;
424 req
->glxCode
= X_GLXCreateContext
;
425 req
->context
= gc
->xid
= XAllocID(dpy
);
426 req
->visual
= vis
->visualid
;
427 req
->screen
= vis
->screen
;
428 req
->shareList
= shareList
? shareList
->xid
: None
;
429 #ifdef GLX_DIRECT_RENDERING
430 req
->isDirect
= gc
->driContext
!= NULL
;
435 else if ( use_glx_1_3
) {
436 xGLXCreateNewContextReq
*req
;
438 /* Send the glXCreateNewContext request */
439 GetReq(GLXCreateNewContext
,req
);
440 req
->reqType
= gc
->majorOpcode
;
441 req
->glxCode
= X_GLXCreateNewContext
;
442 req
->context
= gc
->xid
= XAllocID(dpy
);
443 req
->fbconfig
= fbconfig
->fbconfigID
;
444 req
->screen
= fbconfig
->screen
;
445 req
->renderType
= renderType
;
446 req
->shareList
= shareList
? shareList
->xid
: None
;
447 #ifdef GLX_DIRECT_RENDERING
448 req
->isDirect
= gc
->driContext
!= NULL
;
454 xGLXVendorPrivateWithReplyReq
*vpreq
;
455 xGLXCreateContextWithConfigSGIXReq
*req
;
457 /* Send the glXCreateNewContext request */
458 GetReqExtra(GLXVendorPrivateWithReply
,
459 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
460 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
461 req
->reqType
= gc
->majorOpcode
;
462 req
->glxCode
= X_GLXVendorPrivateWithReply
;
463 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
464 req
->context
= gc
->xid
= XAllocID(dpy
);
465 req
->fbconfig
= fbconfig
->fbconfigID
;
466 req
->screen
= fbconfig
->screen
;
467 req
->renderType
= renderType
;
468 req
->shareList
= shareList
? shareList
->xid
: None
;
469 #ifdef GLX_DIRECT_RENDERING
470 req
->isDirect
= gc
->driContext
!= NULL
;
478 gc
->imported
= GL_FALSE
;
482 gc
->imported
= GL_TRUE
;
488 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
489 GLXContext shareList
, Bool allowDirect
)
491 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
495 _X_HIDDEN
void __glXFreeContext(__GLXcontext
*gc
)
497 if (gc
->vendor
) XFree((char *) gc
->vendor
);
498 if (gc
->renderer
) XFree((char *) gc
->renderer
);
499 if (gc
->version
) XFree((char *) gc
->version
);
500 if (gc
->extensions
) XFree((char *) gc
->extensions
);
501 __glFreeAttributeState(gc
);
502 XFree((char *) gc
->buf
);
503 Xfree((char *) gc
->client_state_private
);
509 ** Destroy the named context
512 DestroyContext(Display
*dpy
, GLXContext gc
)
514 xGLXDestroyContextReq
*req
;
519 opcode
= __glXSetupForCommand(dpy
);
520 if (!opcode
|| !gc
) {
526 imported
= gc
->imported
;
529 #ifdef GLX_DIRECT_RENDERING
530 /* Destroy the direct rendering context */
531 if (gc
->driContext
) {
532 (*gc
->driContext
->destroyContext
)(gc
->driContext
, gc
->psc
, dpy
);
533 gc
->driContext
= NULL
;
534 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
538 __glXFreeVertexArrayState(gc
);
540 if (gc
->currentDpy
) {
541 /* Have to free later cuz it's in use now */
544 /* Destroy the handle if not current to anybody */
546 __glXFreeContext(gc
);
551 ** This dpy also created the server side part of the context.
552 ** Send the glXDestroyContext request.
555 GetReq(GLXDestroyContext
,req
);
556 req
->reqType
= opcode
;
557 req
->glxCode
= X_GLXDestroyContext
;
564 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
566 DestroyContext(dpy
, gc
);
570 ** Return the major and minor version #s for the GLX extension
572 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
574 __GLXdisplayPrivate
*priv
;
576 /* Init the extension. This fetches the major and minor version. */
577 priv
= __glXInitialize(dpy
);
578 if (!priv
) return GL_FALSE
;
580 if (major
) *major
= priv
->majorVersion
;
581 if (minor
) *minor
= priv
->minorVersion
;
586 ** Query the existance of the GLX extension
588 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
590 int major_op
, erb
, evb
;
593 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
595 if (errorBase
) *errorBase
= erb
;
596 if (eventBase
) *eventBase
= evb
;
602 ** Put a barrier in the token stream that forces the GL to finish its
603 ** work before X can proceed.
605 PUBLIC
void glXWaitGL(void)
608 GLXContext gc
= __glXGetCurrentContext();
609 Display
*dpy
= gc
->currentDpy
;
613 /* Flush any pending commands out */
614 __glXFlushRenderBuffer(gc
, gc
->pc
);
616 #ifdef GLX_DIRECT_RENDERING
617 if (gc
->driContext
) {
618 /* This bit of ugliness unwraps the glFinish function */
627 /* Send the glXWaitGL request */
629 GetReq(GLXWaitGL
,req
);
630 req
->reqType
= gc
->majorOpcode
;
631 req
->glxCode
= X_GLXWaitGL
;
632 req
->contextTag
= gc
->currentContextTag
;
638 ** Put a barrier in the token stream that forces X to finish its
639 ** work before GL can proceed.
641 PUBLIC
void glXWaitX(void)
644 GLXContext gc
= __glXGetCurrentContext();
645 Display
*dpy
= gc
->currentDpy
;
649 /* Flush any pending commands out */
650 __glXFlushRenderBuffer(gc
, gc
->pc
);
652 #ifdef GLX_DIRECT_RENDERING
653 if (gc
->driContext
) {
660 ** Send the glXWaitX request.
663 GetReq(GLXWaitX
,req
);
664 req
->reqType
= gc
->majorOpcode
;
665 req
->glxCode
= X_GLXWaitX
;
666 req
->contextTag
= gc
->currentContextTag
;
671 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
673 xGLXUseXFontReq
*req
;
674 GLXContext gc
= __glXGetCurrentContext();
675 Display
*dpy
= gc
->currentDpy
;
679 /* Flush any pending commands out */
680 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
682 #ifdef GLX_DIRECT_RENDERING
683 if (gc
->driContext
) {
684 DRI_glXUseXFont(font
, first
, count
, listBase
);
689 /* Send the glXUseFont request */
691 GetReq(GLXUseXFont
,req
);
692 req
->reqType
= gc
->majorOpcode
;
693 req
->glxCode
= X_GLXUseXFont
;
694 req
->contextTag
= gc
->currentContextTag
;
698 req
->listBase
= listBase
;
703 /************************************************************************/
706 ** Copy the source context to the destination context using the
709 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
710 GLXContext dest
, unsigned long mask
)
712 xGLXCopyContextReq
*req
;
713 GLXContext gc
= __glXGetCurrentContext();
717 opcode
= __glXSetupForCommand(dpy
);
722 #ifdef GLX_DIRECT_RENDERING
723 if (gc
->driContext
) {
724 /* NOT_DONE: This does not work yet */
729 ** If the source is the current context, send its tag so that the context
730 ** can be flushed before the copy.
732 if (source
== gc
&& dpy
== gc
->currentDpy
) {
733 tag
= gc
->currentContextTag
;
738 /* Send the glXCopyContext request */
740 GetReq(GLXCopyContext
,req
);
741 req
->reqType
= opcode
;
742 req
->glxCode
= X_GLXCopyContext
;
743 req
->source
= source
? source
->xid
: None
;
744 req
->dest
= dest
? dest
->xid
: None
;
746 req
->contextTag
= tag
;
753 * Determine if a context uses direct rendering.
755 * \param dpy Display where the context was created.
756 * \param contextID ID of the context to be tested.
758 * \returns \c GL_TRUE if the context is direct rendering or not.
760 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
762 #if !defined(USE_XCB)
763 xGLXIsDirectReq
*req
;
764 xGLXIsDirectReply reply
;
768 opcode
= __glXSetupForCommand(dpy
);
774 xcb_connection_t
* c
= XGetXCBConnection(dpy
);
775 xcb_glx_is_direct_reply_t
* reply
=
776 xcb_glx_is_direct_reply(c
,
777 xcb_glx_is_direct(c
, contextID
),
780 const Bool is_direct
= reply
->is_direct
? True
: False
;
785 /* Send the glXIsDirect request */
787 GetReq(GLXIsDirect
,req
);
788 req
->reqType
= opcode
;
789 req
->glxCode
= X_GLXIsDirect
;
790 req
->context
= contextID
;
791 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
795 return reply
.isDirect
;
801 * Shouldn't this function \b always return \c GL_FALSE when
802 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
803 * the GLX protocol here at all?
805 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
809 #ifdef GLX_DIRECT_RENDERING
810 } else if (gc
->driContext
) {
814 return __glXIsDirect(dpy
, gc
->xid
);
817 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
820 xGLXCreateGLXPixmapReq
*req
;
824 opcode
= __glXSetupForCommand(dpy
);
829 /* Send the glXCreateGLXPixmap request */
831 GetReq(GLXCreateGLXPixmap
,req
);
832 req
->reqType
= opcode
;
833 req
->glxCode
= X_GLXCreateGLXPixmap
;
834 req
->screen
= vis
->screen
;
835 req
->visual
= vis
->visualid
;
836 req
->pixmap
= pixmap
;
837 req
->glxpixmap
= xid
= XAllocID(dpy
);
844 ** Destroy the named pixmap
846 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
848 xGLXDestroyGLXPixmapReq
*req
;
851 opcode
= __glXSetupForCommand(dpy
);
856 /* Send the glXDestroyGLXPixmap request */
858 GetReq(GLXDestroyGLXPixmap
,req
);
859 req
->reqType
= opcode
;
860 req
->glxCode
= X_GLXDestroyGLXPixmap
;
861 req
->glxpixmap
= glxpixmap
;
866 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
871 #ifdef GLX_DIRECT_RENDERING
872 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
876 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
);
881 opcode
= __glXSetupForCommand(dpy
);
887 ** The calling thread may or may not have a current context. If it
888 ** does, send the context tag so the server can do a flush.
890 gc
= __glXGetCurrentContext();
891 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
892 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
893 tag
= gc
->currentContextTag
;
899 xcb_connection_t
* c
= XGetXCBConnection(dpy
);
900 xcb_glx_swap_buffers(c
, tag
, drawable
);
903 xGLXSwapBuffersReq
*req
;
905 /* Send the glXSwapBuffers request */
907 GetReq(GLXSwapBuffers
,req
);
908 req
->reqType
= opcode
;
909 req
->glxCode
= X_GLXSwapBuffers
;
910 req
->drawable
= drawable
;
911 req
->contextTag
= tag
;
920 ** Return configuration information for the given display, screen and
921 ** visual combination.
923 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
926 __GLXdisplayPrivate
*priv
;
927 __GLXscreenConfigs
*psc
;
928 __GLcontextModes
*modes
;
931 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
932 if ( status
== Success
) {
933 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
935 /* Lookup attribute after first finding a match on the visual */
936 if ( modes
!= NULL
) {
937 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
940 status
= GLX_BAD_VISUAL
;
944 ** If we can't find the config for this visual, this visual is not
945 ** supported by the OpenGL implementation on the server.
947 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
948 *value_return
= GL_FALSE
;
955 /************************************************************************/
958 init_fbconfig_for_chooser( __GLcontextModes
* config
,
959 GLboolean fbconfig_style_tags
)
961 memset( config
, 0, sizeof( __GLcontextModes
) );
962 config
->visualID
= (XID
) GLX_DONT_CARE
;
963 config
->visualType
= GLX_DONT_CARE
;
965 /* glXChooseFBConfig specifies different defaults for these two than
968 if ( fbconfig_style_tags
) {
969 config
->rgbMode
= GL_TRUE
;
970 config
->doubleBufferMode
= GLX_DONT_CARE
;
973 config
->visualRating
= GLX_DONT_CARE
;
974 config
->transparentPixel
= GLX_NONE
;
975 config
->transparentRed
= GLX_DONT_CARE
;
976 config
->transparentGreen
= GLX_DONT_CARE
;
977 config
->transparentBlue
= GLX_DONT_CARE
;
978 config
->transparentAlpha
= GLX_DONT_CARE
;
979 config
->transparentIndex
= GLX_DONT_CARE
;
981 config
->drawableType
= GLX_WINDOW_BIT
;
982 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
983 config
->xRenderable
= GLX_DONT_CARE
;
984 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
986 config
->swapMethod
= GLX_DONT_CARE
;
989 #define MATCH_DONT_CARE( param ) \
991 if ( (a-> param != GLX_DONT_CARE) \
992 && (a-> param != b-> param) ) { \
997 #define MATCH_MINIMUM( param ) \
999 if ( (a-> param != GLX_DONT_CARE) \
1000 && (a-> param > b-> param) ) { \
1005 #define MATCH_EXACT( param ) \
1007 if ( a-> param != b-> param) { \
1013 * Determine if two GLXFBConfigs are compatible.
1015 * \param a Application specified config to test.
1016 * \param b Server specified config to test against \c a.
1019 fbconfigs_compatible( const __GLcontextModes
* const a
,
1020 const __GLcontextModes
* const b
)
1022 MATCH_DONT_CARE( doubleBufferMode
);
1023 MATCH_DONT_CARE( visualType
);
1024 MATCH_DONT_CARE( visualRating
);
1025 MATCH_DONT_CARE( xRenderable
);
1026 MATCH_DONT_CARE( fbconfigID
);
1027 MATCH_DONT_CARE( swapMethod
);
1029 MATCH_MINIMUM( rgbBits
);
1030 MATCH_MINIMUM( numAuxBuffers
);
1031 MATCH_MINIMUM( redBits
);
1032 MATCH_MINIMUM( greenBits
);
1033 MATCH_MINIMUM( blueBits
);
1034 MATCH_MINIMUM( alphaBits
);
1035 MATCH_MINIMUM( depthBits
);
1036 MATCH_MINIMUM( stencilBits
);
1037 MATCH_MINIMUM( accumRedBits
);
1038 MATCH_MINIMUM( accumGreenBits
);
1039 MATCH_MINIMUM( accumBlueBits
);
1040 MATCH_MINIMUM( accumAlphaBits
);
1041 MATCH_MINIMUM( sampleBuffers
);
1042 MATCH_MINIMUM( maxPbufferWidth
);
1043 MATCH_MINIMUM( maxPbufferHeight
);
1044 MATCH_MINIMUM( maxPbufferPixels
);
1045 MATCH_MINIMUM( samples
);
1047 MATCH_DONT_CARE( stereoMode
);
1048 MATCH_EXACT( level
);
1050 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1051 || ((a
->renderType
& b
->renderType
) == 0) ) {
1056 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1057 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1058 * Technically speaking, it is a bug in the DDX driver, but there is
1059 * enough of an installed base to work around the problem here. In any
1060 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1061 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1062 * 0 from the server to be a match to maintain backward compatibility with
1063 * the (broken) drivers.
1066 if ( a
->transparentPixel
!= GLX_DONT_CARE
1067 && a
->transparentPixel
!= 0 ) {
1068 if ( a
->transparentPixel
== GLX_NONE
) {
1069 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1072 MATCH_EXACT( transparentPixel
);
1075 switch ( a
->transparentPixel
) {
1076 case GLX_TRANSPARENT_RGB
:
1077 MATCH_DONT_CARE( transparentRed
);
1078 MATCH_DONT_CARE( transparentGreen
);
1079 MATCH_DONT_CARE( transparentBlue
);
1080 MATCH_DONT_CARE( transparentAlpha
);
1083 case GLX_TRANSPARENT_INDEX
:
1084 MATCH_DONT_CARE( transparentIndex
);
1096 /* There's some trickly language in the GLX spec about how this is supposed
1097 * to work. Basically, if a given component size is either not specified
1098 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1099 * Well, that's really hard to do with the code as-is. This behavior is
1100 * closer to correct, but still not technically right.
1102 #define PREFER_LARGER_OR_ZERO(comp) \
1104 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1105 if ( ((*a)-> comp) == 0 ) { \
1108 else if ( ((*b)-> comp) == 0 ) { \
1112 return ((*b)-> comp) - ((*a)-> comp) ; \
1117 #define PREFER_LARGER(comp) \
1119 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1120 return ((*b)-> comp) - ((*a)-> comp) ; \
1124 #define PREFER_SMALLER(comp) \
1126 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1127 return ((*a)-> comp) - ((*b)-> comp) ; \
1132 * Compare two GLXFBConfigs. This function is intended to be used as the
1133 * compare function passed in to qsort.
1135 * \returns If \c a is a "better" config, according to the specification of
1136 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1137 * better, then a number greater than zero is return. If both are
1138 * equal, zero is returned.
1139 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1142 fbconfig_compare( const __GLcontextModes
* const * const a
,
1143 const __GLcontextModes
* const * const b
)
1145 /* The order of these comparisons must NOT change. It is defined by
1146 * the GLX 1.3 spec and ARB_multisample.
1149 PREFER_SMALLER( visualSelectGroup
);
1151 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1152 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1153 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1155 PREFER_SMALLER( visualRating
);
1157 /* This isn't quite right. It is supposed to compare the sum of the
1158 * components the user specifically set minimums for.
1160 PREFER_LARGER_OR_ZERO( redBits
);
1161 PREFER_LARGER_OR_ZERO( greenBits
);
1162 PREFER_LARGER_OR_ZERO( blueBits
);
1163 PREFER_LARGER_OR_ZERO( alphaBits
);
1165 PREFER_SMALLER( rgbBits
);
1167 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1168 /* Prefer single-buffer.
1170 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1173 PREFER_SMALLER( numAuxBuffers
);
1175 PREFER_LARGER_OR_ZERO( depthBits
);
1176 PREFER_SMALLER( stencilBits
);
1178 /* This isn't quite right. It is supposed to compare the sum of the
1179 * components the user specifically set minimums for.
1181 PREFER_LARGER_OR_ZERO( accumRedBits
);
1182 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1183 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1184 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1186 PREFER_SMALLER( visualType
);
1188 /* None of the multisample specs say where this comparison should happen,
1189 * so I put it near the end.
1191 PREFER_SMALLER( sampleBuffers
);
1192 PREFER_SMALLER( samples
);
1194 /* None of the pbuffer or fbconfig specs say that this comparison needs
1195 * to happen at all, but it seems like it should.
1197 PREFER_LARGER( maxPbufferWidth
);
1198 PREFER_LARGER( maxPbufferHeight
);
1199 PREFER_LARGER( maxPbufferPixels
);
1206 * Selects and sorts a subset of the supplied configs based on the attributes.
1207 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1208 * and \c glXChooseFBConfigSGIX.
1210 * \param configs Array of pointers to possible configs. The elements of
1211 * this array that do not meet the criteria will be set to
1212 * NULL. The remaining elements will be sorted according to
1213 * the various visual / FBConfig selection rules.
1214 * \param num_configs Number of elements in the \c configs array.
1215 * \param attribList Attributes used select from \c configs. This array is
1216 * terminated by a \c None tag. The array can either take
1217 * the form expected by \c glXChooseVisual (where boolean
1218 * tags do not have a value) or by \c glXChooseFBConfig
1219 * (where every tag has a value).
1220 * \param fbconfig_style_tags Selects whether \c attribList is in
1221 * \c glXChooseVisual style or
1222 * \c glXChooseFBConfig style.
1223 * \returns The number of valid elements left in \c configs.
1225 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1228 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1229 const int *attribList
, GLboolean fbconfig_style_tags
)
1231 __GLcontextModes test_config
;
1235 /* This is a fairly direct implementation of the selection method
1236 * described by GLX_SGIX_fbconfig. Start by culling out all the
1237 * configs that are not compatible with the selected parameter
1241 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1242 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1243 (const INT32
*) attribList
,
1244 GL_TRUE
, fbconfig_style_tags
);
1247 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1248 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1249 configs
[ base
] = configs
[ i
];
1258 if ( base
< num_configs
) {
1259 (void) memset( & configs
[ base
], 0,
1260 sizeof( void * ) * (num_configs
- base
) );
1263 /* After the incompatible configs are removed, the resulting
1264 * list is sorted according to the rules set out in the various
1268 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1269 (int (*)(const void*, const void*)) fbconfig_compare
);
1277 ** Return the visual that best matches the template. Return None if no
1278 ** visual matches the template.
1280 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1282 XVisualInfo
*visualList
= NULL
;
1283 __GLXdisplayPrivate
*priv
;
1284 __GLXscreenConfigs
*psc
;
1285 __GLcontextModes test_config
;
1286 __GLcontextModes
*modes
;
1287 const __GLcontextModes
*best_config
= NULL
;
1290 ** Get a list of all visuals, return if list is empty
1292 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1298 ** Build a template from the defaults and the attribute list
1299 ** Free visual list and return if an unexpected token is encountered
1301 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1302 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1303 (const INT32
*) attribList
,
1304 GL_TRUE
, GL_FALSE
);
1307 ** Eliminate visuals that don't meet minimum requirements
1308 ** Compute a score for those that do
1309 ** Remember which visual, if any, got the highest score
1311 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1312 if ( fbconfigs_compatible( & test_config
, modes
)
1313 && ((best_config
== NULL
)
1314 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1315 best_config
= modes
;
1320 ** If no visual is acceptable, return None
1321 ** Otherwise, create an XVisualInfo list with just the selected X visual
1324 if (best_config
!= NULL
) {
1325 XVisualInfo visualTemplate
;
1328 visualTemplate
.screen
= screen
;
1329 visualTemplate
.visualid
= best_config
->visualID
;
1330 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1331 &visualTemplate
, &i
);
1338 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1340 __GLXscreenConfigs
*psc
;
1341 __GLXdisplayPrivate
*priv
;
1343 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1347 if (!psc
->effectiveGLXexts
) {
1348 if (!psc
->serverGLXexts
) {
1349 psc
->serverGLXexts
=
1350 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
1353 __glXCalculateUsableExtensions(psc
,
1354 #ifdef GLX_DIRECT_RENDERING
1355 (psc
->driScreen
!= NULL
),
1359 priv
->minorVersion
);
1362 return psc
->effectiveGLXexts
;
1365 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1369 return (__glXGLXClientVendorName
);
1371 return (__glXGLXClientVersion
);
1372 case GLX_EXTENSIONS
:
1373 return (__glXGetClientExtensions());
1379 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1381 __GLXscreenConfigs
*psc
;
1382 __GLXdisplayPrivate
*priv
;
1386 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1392 str
= & priv
->serverGLXvendor
;
1395 str
= & priv
->serverGLXversion
;
1397 case GLX_EXTENSIONS
:
1398 str
= & psc
->serverGLXexts
;
1404 if ( *str
== NULL
) {
1405 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1411 void __glXClientInfo ( Display
*dpy
, int opcode
)
1413 char * ext_str
= __glXGetClientGLExtensionString();
1414 int size
= strlen( ext_str
) + 1;
1417 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1418 xcb_glx_client_info(c
,
1422 (const uint8_t *)ext_str
);
1424 xGLXClientInfoReq
*req
;
1426 /* Send the glXClientInfo request */
1428 GetReq(GLXClientInfo
,req
);
1429 req
->reqType
= opcode
;
1430 req
->glxCode
= X_GLXClientInfo
;
1431 req
->major
= GLX_MAJOR_VERSION
;
1432 req
->minor
= GLX_MINOR_VERSION
;
1434 req
->length
+= (size
+ 3) >> 2;
1435 req
->numbytes
= size
;
1436 Data(dpy
, ext_str
, size
);
1440 #endif /* USE_XCB */
1447 ** EXT_import_context
1450 PUBLIC Display
*glXGetCurrentDisplay(void)
1452 GLXContext gc
= __glXGetCurrentContext();
1453 if (NULL
== gc
) return NULL
;
1454 return gc
->currentDpy
;
1457 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1458 glXGetCurrentDisplay
)
1461 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1464 * \param dpy Display where \c ctx was created.
1465 * \param ctx Context to query.
1466 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1467 * or zero if the request failed due to internal problems (i.e.,
1468 * unable to allocate temporary memory, etc.)
1471 * This function dynamically determines whether to use the EXT_import_context
1472 * version of the protocol or the GLX 1.3 version of the protocol.
1474 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1476 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1477 xGLXQueryContextReply reply
;
1483 return GLX_BAD_CONTEXT
;
1485 opcode
= __glXSetupForCommand(dpy
);
1490 /* Send the glXQueryContextInfoEXT request */
1493 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1494 xGLXQueryContextReq
*req
;
1496 GetReq(GLXQueryContext
, req
);
1498 req
->reqType
= opcode
;
1499 req
->glxCode
= X_GLXQueryContext
;
1500 req
->context
= (unsigned int)(ctx
->xid
);
1503 xGLXVendorPrivateReq
*vpreq
;
1504 xGLXQueryContextInfoEXTReq
*req
;
1506 GetReqExtra( GLXVendorPrivate
,
1507 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1509 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1510 req
->reqType
= opcode
;
1511 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1512 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1513 req
->context
= (unsigned int)(ctx
->xid
);
1516 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1518 numValues
= reply
.n
;
1521 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1525 int *propList
, *pProp
;
1529 nPropListBytes
= numValues
<< 3;
1530 propList
= (int *) Xmalloc(nPropListBytes
);
1531 if (NULL
== propList
) {
1534 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1536 for (i
=0; i
< numValues
; i
++) {
1538 case GLX_SHARE_CONTEXT_EXT
:
1539 ctx
->share_xid
= *pProp
++;
1541 case GLX_VISUAL_ID_EXT
:
1543 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1546 ctx
->screen
= *pProp
++;
1548 case GLX_FBCONFIG_ID
:
1550 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1552 case GLX_RENDER_TYPE
:
1553 ctx
->renderType
= *pProp
++;
1560 Xfree((char *)propList
);
1570 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1574 /* get the information from the server if we don't have it already */
1575 #ifdef GLX_DIRECT_RENDERING
1576 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1578 if (ctx
->mode
== NULL
) {
1580 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1581 if (Success
!= retVal
) return retVal
;
1583 switch (attribute
) {
1584 case GLX_SHARE_CONTEXT_EXT
:
1585 *value
= (int)(ctx
->share_xid
);
1587 case GLX_VISUAL_ID_EXT
:
1588 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1591 *value
= (int)(ctx
->screen
);
1593 case GLX_FBCONFIG_ID
:
1594 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1596 case GLX_RENDER_TYPE
:
1597 *value
= (int)(ctx
->renderType
);
1600 return GLX_BAD_ATTRIBUTE
;
1605 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1606 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1607 (dpy
, ctx
, attribute
, value
),
1610 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1615 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1619 if (contextID
== None
) {
1622 if (__glXIsDirect(dpy
, contextID
)) {
1626 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1628 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1635 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1637 DestroyContext(dpy
, ctx
);
1643 * GLX 1.3 functions - these are just stubs for now!
1646 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1647 const int *attribList
, int *nitems
)
1649 __GLcontextModes
** config_list
;
1653 config_list
= (__GLcontextModes
**)
1654 glXGetFBConfigs( dpy
, screen
, & list_size
);
1656 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1657 list_size
= choose_visual( config_list
, list_size
, attribList
,
1659 if ( list_size
== 0 ) {
1660 XFree( config_list
);
1665 *nitems
= list_size
;
1666 return (GLXFBConfig
*) config_list
;
1670 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1671 int renderType
, GLXContext shareList
,
1674 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1675 allowDirect
, None
, True
, renderType
);
1679 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1681 GLXContext gc
= __glXGetCurrentContext();
1682 return gc
->currentReadable
;
1686 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1688 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1689 __GLcontextModes
** config
= NULL
;
1693 if ( (priv
->screenConfigs
!= NULL
)
1694 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1695 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1696 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1697 unsigned num_configs
= 0;
1698 __GLcontextModes
* modes
;
1701 for ( modes
= priv
->screenConfigs
[screen
].configs
1703 ; modes
= modes
->next
) {
1704 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1709 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1711 if ( config
!= NULL
) {
1712 *nelements
= num_configs
;
1714 for ( modes
= priv
->screenConfigs
[screen
].configs
1716 ; modes
= modes
->next
) {
1717 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1724 return (GLXFBConfig
*) config
;
1728 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1729 int attribute
, int *value
)
1731 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1733 return (modes
!= NULL
)
1734 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1739 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1741 XVisualInfo visualTemplate
;
1742 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1746 ** Get a list of all visuals, return if list is empty
1748 visualTemplate
.visualid
= fbconfig
->visualID
;
1749 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1754 ** GLX_SGI_swap_control
1756 static int __glXSwapIntervalSGI(int interval
)
1758 xGLXVendorPrivateReq
*req
;
1759 GLXContext gc
= __glXGetCurrentContext();
1761 CARD32
* interval_ptr
;
1765 return GLX_BAD_CONTEXT
;
1768 if ( interval
<= 0 ) {
1769 return GLX_BAD_VALUE
;
1772 #ifdef __DRI_SWAP_CONTROL
1773 if (gc
->driContext
) {
1774 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1776 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1777 gc
->currentDrawable
,
1779 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1780 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1784 return GLX_BAD_CONTEXT
;
1788 dpy
= gc
->currentDpy
;
1789 opcode
= __glXSetupForCommand(dpy
);
1794 /* Send the glXSwapIntervalSGI request */
1796 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1797 req
->reqType
= opcode
;
1798 req
->glxCode
= X_GLXVendorPrivate
;
1799 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1800 req
->contextTag
= gc
->currentContextTag
;
1802 interval_ptr
= (CARD32
*) (req
+ 1);
1803 *interval_ptr
= interval
;
1814 ** GLX_MESA_swap_control
1816 static int __glXSwapIntervalMESA(unsigned int interval
)
1818 #ifdef __DRI_SWAP_CONTROL
1819 GLXContext gc
= __glXGetCurrentContext();
1821 if ( interval
< 0 ) {
1822 return GLX_BAD_VALUE
;
1825 if (gc
!= NULL
&& gc
->driContext
) {
1826 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1829 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1830 __GLXDRIdrawable
*pdraw
=
1831 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1832 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1833 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1842 return GLX_BAD_CONTEXT
;
1846 static int __glXGetSwapIntervalMESA(void)
1848 #ifdef __DRI_SWAP_CONTROL
1849 GLXContext gc
= __glXGetCurrentContext();
1851 if (gc
!= NULL
&& gc
->driContext
) {
1852 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1855 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1856 __GLXDRIdrawable
*pdraw
=
1857 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1858 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1859 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1870 ** GLX_MESA_swap_frame_usage
1873 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1875 int status
= GLX_BAD_CONTEXT
;
1876 #ifdef __DRI_FRAME_TRACKING
1878 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1879 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1881 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1882 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1891 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1893 int status
= GLX_BAD_CONTEXT
;
1894 #ifdef __DRI_FRAME_TRACKING
1896 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1897 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1899 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1900 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1910 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1913 int status
= GLX_BAD_CONTEXT
;
1914 #ifdef __DRI_FRAME_TRACKING
1916 __GLXDRIdrawable
* const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1917 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1919 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1920 int64_t sbc
, missedFrames
;
1921 float lastMissedUsage
;
1923 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1938 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1939 int64_t *sbc
, int64_t *missedFrames
,
1940 GLfloat
*lastMissedUsage
)
1942 int status
= GLX_BAD_CONTEXT
;
1943 #ifdef __DRI_FRAME_TRACKING
1945 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1946 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1948 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1951 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1953 lastMissedUsage
, &usage
);
1959 (void) missedFrames
;
1960 (void) lastMissedUsage
;
1967 ** GLX_SGI_video_sync
1969 static int __glXGetVideoSyncSGI(unsigned int *count
)
1971 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1972 * FIXME: there should be a GLX encoding for this call. I can find no
1973 * FIXME: documentation for the GLX encoding.
1975 #ifdef __DRI_MEDIA_STREAM_COUNTER
1976 GLXContext gc
= __glXGetCurrentContext();
1979 if (gc
!= NULL
&& gc
->driContext
) {
1980 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1982 if ( psc
->msc
&& psc
->driScreen
) {
1983 __GLXDRIdrawable
*pdraw
=
1984 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1988 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
1989 pdraw
->driDrawable
, &temp
);
1990 *count
= (unsigned) temp
;
1992 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1998 return GLX_BAD_CONTEXT
;
2001 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2003 #ifdef __DRI_MEDIA_STREAM_COUNTER
2004 GLXContext gc
= __glXGetCurrentContext();
2006 if ( divisor
<= 0 || remainder
< 0 )
2007 return GLX_BAD_VALUE
;
2009 if (gc
!= NULL
&& gc
->driContext
) {
2010 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
2012 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2013 __GLXDRIdrawable
*pdraw
=
2014 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2019 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2020 divisor
, remainder
, &msc
, &sbc
);
2021 *count
= (unsigned) msc
;
2022 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2028 return GLX_BAD_CONTEXT
;
2033 ** GLX_SGIX_fbconfig
2034 ** Many of these functions are aliased to GLX 1.3 entry points in the
2035 ** GLX_functions table.
2038 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2039 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2040 (dpy
, config
, attribute
, value
),
2041 glXGetFBConfigAttrib
)
2043 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2044 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2045 (dpy
, screen
, attrib_list
, nelements
),
2048 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2049 (Display
* dpy
, GLXFBConfigSGIX config
),
2051 glXGetVisualFromFBConfig
)
2053 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2054 GLXFBConfigSGIX config
, Pixmap pixmap
)
2056 xGLXVendorPrivateWithReplyReq
*vpreq
;
2057 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2058 GLXPixmap xid
= None
;
2060 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2061 __GLXscreenConfigs
* psc
;
2064 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2068 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2070 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2071 opcode
= __glXSetupForCommand(dpy
);
2076 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2078 GetReqExtra(GLXVendorPrivateWithReply
,
2079 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2080 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2081 req
->reqType
= opcode
;
2082 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2083 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2084 req
->screen
= fbconfig
->screen
;
2085 req
->fbconfig
= fbconfig
->fbconfigID
;
2086 req
->pixmap
= pixmap
;
2087 req
->glxpixmap
= xid
= XAllocID(dpy
);
2095 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2096 GLXFBConfigSGIX config
, int renderType
,
2097 GLXContext shareList
, Bool allowDirect
)
2099 GLXContext gc
= NULL
;
2100 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2101 __GLXscreenConfigs
* psc
;
2104 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2108 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2110 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2111 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2112 allowDirect
, None
, False
, renderType
);
2119 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2122 __GLXdisplayPrivate
*priv
;
2123 __GLXscreenConfigs
*psc
;
2125 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2126 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2127 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2128 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2137 ** GLX_SGIX_swap_group
2139 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2149 ** GLX_SGIX_swap_barrier
2151 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2159 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2169 ** GLX_OML_sync_control
2171 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2172 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2174 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2175 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2177 if ( priv
!= NULL
) {
2179 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2180 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2182 assert( (pdraw
== NULL
) || (i
!= -1) );
2183 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2184 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2185 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2186 && (__glXGetUST(ust
) == 0) );
2198 #ifdef GLX_DIRECT_RENDERING
2200 __driGetMscRateOML(__DRIdrawable
*draw
,
2201 int32_t *numerator
, int32_t *denominator
, void *private)
2204 __GLXscreenConfigs
*psc
;
2205 XF86VidModeModeLine mode_line
;
2208 __GLXDRIdrawable
*glxDraw
= private;
2211 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2212 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2213 unsigned n
= dot_clock
* 1000;
2214 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2216 # define V_INTERLACE 0x010
2217 # define V_DBLSCAN 0x020
2219 if (mode_line
.flags
& V_INTERLACE
)
2221 else if (mode_line
.flags
& V_DBLSCAN
)
2224 /* The OML_sync_control spec requires that if the refresh rate is a
2225 * whole number, that the returned numerator be equal to the refresh
2226 * rate and the denominator be 1.
2234 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2236 /* This is a poor man's way to reduce a fraction. It's far from
2237 * perfect, but it will work well enough for this situation.
2240 for (i
= 0; f
[i
] != 0; i
++) {
2241 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2262 * Determine the refresh rate of the specified drawable and display.
2264 * \param dpy Display whose refresh rate is to be determined.
2265 * \param drawable Drawable whose refresh rate is to be determined.
2266 * \param numerator Numerator of the refresh rate.
2267 * \param demoninator Denominator of the refresh rate.
2268 * \return If the refresh rate for the specified display and drawable could
2269 * be calculated, True is returned. Otherwise False is returned.
2271 * \note This function is implemented entirely client-side. A lot of other
2272 * functionality is required to export GLX_OML_sync_control, so on
2273 * XFree86 this function can be called for direct-rendering contexts
2274 * when GLX_OML_sync_control appears in the client extension string.
2277 _X_HIDDEN GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2278 int32_t * numerator
,
2279 int32_t * denominator
)
2281 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2282 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2287 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2298 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2299 int64_t target_msc
, int64_t divisor
,
2302 #ifdef __DRI_SWAP_BUFFER_COUNTER
2304 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2305 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2307 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2308 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2309 * of -1 if the function failed because of errors detected in the input
2312 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2314 if ( divisor
> 0 && remainder
>= divisor
)
2317 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2318 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2319 divisor
, remainder
);
2332 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2333 int64_t target_msc
, int64_t divisor
,
2334 int64_t remainder
, int64_t *ust
,
2335 int64_t *msc
, int64_t *sbc
)
2337 #ifdef __DRI_MEDIA_STREAM_COUNTER
2339 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2340 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2343 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2344 * error", but the return type in the spec is Bool.
2346 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2348 if ( divisor
> 0 && remainder
>= divisor
)
2351 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2352 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, target_msc
,
2353 divisor
, remainder
, msc
, sbc
);
2355 /* __glXGetUST returns zero on success and non-zero on failure.
2356 * This function returns True on success and False on failure.
2358 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2374 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2375 int64_t target_sbc
, int64_t *ust
,
2376 int64_t *msc
, int64_t *sbc
)
2378 #ifdef __DRI_SWAP_BUFFER_COUNTER
2380 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2381 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2384 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2385 * error", but the return type in the spec is Bool.
2387 if ( target_sbc
< 0 )
2390 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2391 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2393 /* __glXGetUST returns zero on success and non-zero on failure.
2394 * This function returns True on success and False on failure.
2396 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2411 * GLX_MESA_allocate_memory
2415 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2416 size_t size
, float readFreq
,
2417 float writeFreq
, float priority
)
2419 #ifdef __DRI_ALLOCATE
2420 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2422 if (psc
&& psc
->allocate
)
2423 return (*psc
->allocate
->allocateMemory
)(psc
->__driScreen
, size
,
2424 readFreq
, writeFreq
, priority
);
2433 #endif /* GLX_DIRECT_RENDERING */
2439 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2441 #ifdef __DRI_ALLOCATE
2442 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2444 if (psc
&& psc
->allocate
)
2445 (*psc
->allocate
->freeMemory
)(psc
->__driScreen
, pointer
);
2451 #endif /* GLX_DIRECT_RENDERING */
2455 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2456 const void *pointer
)
2458 #ifdef __DRI_ALLOCATE
2459 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2461 if (psc
&& psc
->allocate
)
2462 return (*psc
->allocate
->memoryOffset
)(psc
->__driScreen
, pointer
);
2468 #endif /* GLX_DIRECT_RENDERING */
2476 * Mesa extension stubs. These will help reduce portability problems.
2481 * Release all buffers associated with the specified GLX drawable.
2484 * This function was intended for stand-alone Mesa. The issue there is that
2485 * the library doesn't get any notification when a window is closed. In
2486 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2487 * supported, there are 3 different functions to destroy a drawable. It
2488 * should be possible to create GLX protocol (or have it determine which
2489 * protocol to use based on the type of the drawable) to have one function
2490 * do the work of 3. For the direct-rendering case, this function could
2491 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2492 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2493 * would need to be used. This really should be done as part of the new DRI
2496 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2497 * __driGarbageCollectDrawables
2498 * glXDestroyGLXPixmap
2499 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2500 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2502 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2510 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2511 Pixmap pixmap
, Colormap cmap
)
2523 * GLX_MESA_copy_sub_buffer
2525 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2526 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2527 int x
, int y
, int width
, int height
)
2529 xGLXVendorPrivateReq
*req
;
2532 CARD32
*drawable_ptr
;
2533 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2536 #ifdef __DRI_COPY_SUB_BUFFER
2538 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2539 if ( pdraw
!= NULL
) {
2540 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
2541 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2543 (*psc
->driScreen
->copySubBuffer
)(pdraw
, x
, y
, width
, height
);
2550 opcode
= __glXSetupForCommand(dpy
);
2555 ** The calling thread may or may not have a current context. If it
2556 ** does, send the context tag so the server can do a flush.
2558 gc
= __glXGetCurrentContext();
2559 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2560 ((drawable
== gc
->currentDrawable
) ||
2561 (drawable
== gc
->currentReadable
)) ) {
2562 tag
= gc
->currentContextTag
;
2568 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2569 req
->reqType
= opcode
;
2570 req
->glxCode
= X_GLXVendorPrivate
;
2571 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2572 req
->contextTag
= tag
;
2574 drawable_ptr
= (CARD32
*) (req
+ 1);
2575 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2576 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2577 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2578 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2580 *drawable_ptr
= drawable
;
2592 * GLX_EXT_texture_from_pixmap
2595 static void __glXBindTexImageEXT(Display
*dpy
,
2596 GLXDrawable drawable
,
2598 const int *attrib_list
)
2600 xGLXVendorPrivateReq
*req
;
2601 GLXContext gc
= __glXGetCurrentContext();
2602 CARD32
*drawable_ptr
;
2604 CARD32
*num_attrib_ptr
;
2614 while (attrib_list
[i
* 2] != None
)
2618 #ifdef GLX_DIRECT_RENDERING
2619 if (gc
->driContext
) {
2620 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2623 (*pdraw
->psc
->texBuffer
->setTexBuffer
)(gc
->__driContext
,
2624 pdraw
->textureTarget
,
2625 pdraw
->driDrawable
);
2631 opcode
= __glXSetupForCommand(dpy
);
2636 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2637 req
->reqType
= opcode
;
2638 req
->glxCode
= X_GLXVendorPrivate
;
2639 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2640 req
->contextTag
= gc
->currentContextTag
;
2642 drawable_ptr
= (CARD32
*) (req
+ 1);
2643 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2644 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2645 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2647 *drawable_ptr
= drawable
;
2648 *buffer_ptr
= buffer
;
2649 *num_attrib_ptr
= (CARD32
) i
;
2653 while (attrib_list
[i
* 2] != None
)
2655 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2656 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2665 static void __glXReleaseTexImageEXT(Display
*dpy
,
2666 GLXDrawable drawable
,
2669 xGLXVendorPrivateReq
*req
;
2670 GLXContext gc
= __glXGetCurrentContext();
2671 CARD32
*drawable_ptr
;
2678 #ifdef GLX_DIRECT_RENDERING
2683 opcode
= __glXSetupForCommand(dpy
);
2688 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2689 req
->reqType
= opcode
;
2690 req
->glxCode
= X_GLXVendorPrivate
;
2691 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2692 req
->contextTag
= gc
->currentContextTag
;
2694 drawable_ptr
= (CARD32
*) (req
+ 1);
2695 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2697 *drawable_ptr
= drawable
;
2698 *buffer_ptr
= buffer
;
2706 * \c strdup is actually not a standard ANSI C or POSIX routine.
2707 * Irix will not define it if ANSI mode is in effect.
2712 __glXstrdup(const char *str
)
2715 copy
= (char *) Xmalloc(strlen(str
) + 1);
2723 ** glXGetProcAddress support
2726 struct name_address_pair
{
2731 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2732 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2734 static const struct name_address_pair GLX_functions
[] = {
2735 /*** GLX_VERSION_1_0 ***/
2736 GLX_FUNCTION( glXChooseVisual
),
2737 GLX_FUNCTION( glXCopyContext
),
2738 GLX_FUNCTION( glXCreateContext
),
2739 GLX_FUNCTION( glXCreateGLXPixmap
),
2740 GLX_FUNCTION( glXDestroyContext
),
2741 GLX_FUNCTION( glXDestroyGLXPixmap
),
2742 GLX_FUNCTION( glXGetConfig
),
2743 GLX_FUNCTION( glXGetCurrentContext
),
2744 GLX_FUNCTION( glXGetCurrentDrawable
),
2745 GLX_FUNCTION( glXIsDirect
),
2746 GLX_FUNCTION( glXMakeCurrent
),
2747 GLX_FUNCTION( glXQueryExtension
),
2748 GLX_FUNCTION( glXQueryVersion
),
2749 GLX_FUNCTION( glXSwapBuffers
),
2750 GLX_FUNCTION( glXUseXFont
),
2751 GLX_FUNCTION( glXWaitGL
),
2752 GLX_FUNCTION( glXWaitX
),
2754 /*** GLX_VERSION_1_1 ***/
2755 GLX_FUNCTION( glXGetClientString
),
2756 GLX_FUNCTION( glXQueryExtensionsString
),
2757 GLX_FUNCTION( glXQueryServerString
),
2759 /*** GLX_VERSION_1_2 ***/
2760 GLX_FUNCTION( glXGetCurrentDisplay
),
2762 /*** GLX_VERSION_1_3 ***/
2763 GLX_FUNCTION( glXChooseFBConfig
),
2764 GLX_FUNCTION( glXCreateNewContext
),
2765 GLX_FUNCTION( glXCreatePbuffer
),
2766 GLX_FUNCTION( glXCreatePixmap
),
2767 GLX_FUNCTION( glXCreateWindow
),
2768 GLX_FUNCTION( glXDestroyPbuffer
),
2769 GLX_FUNCTION( glXDestroyPixmap
),
2770 GLX_FUNCTION( glXDestroyWindow
),
2771 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2772 GLX_FUNCTION( glXGetFBConfigAttrib
),
2773 GLX_FUNCTION( glXGetFBConfigs
),
2774 GLX_FUNCTION( glXGetSelectedEvent
),
2775 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2776 GLX_FUNCTION( glXMakeContextCurrent
),
2777 GLX_FUNCTION( glXQueryContext
),
2778 GLX_FUNCTION( glXQueryDrawable
),
2779 GLX_FUNCTION( glXSelectEvent
),
2781 /*** GLX_SGI_swap_control ***/
2782 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2784 /*** GLX_SGI_video_sync ***/
2785 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2786 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2788 /*** GLX_SGI_make_current_read ***/
2789 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2790 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2792 /*** GLX_EXT_import_context ***/
2793 GLX_FUNCTION( glXFreeContextEXT
),
2794 GLX_FUNCTION( glXGetContextIDEXT
),
2795 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2796 GLX_FUNCTION( glXImportContextEXT
),
2797 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2799 /*** GLX_SGIX_fbconfig ***/
2800 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2801 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2802 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2803 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2804 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2805 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2807 /*** GLX_SGIX_pbuffer ***/
2808 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2809 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2810 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2811 GLX_FUNCTION( glXSelectEventSGIX
),
2812 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2814 /*** GLX_SGIX_swap_group ***/
2815 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2817 /*** GLX_SGIX_swap_barrier ***/
2818 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2819 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2821 /*** GLX_MESA_allocate_memory ***/
2822 GLX_FUNCTION( glXAllocateMemoryMESA
),
2823 GLX_FUNCTION( glXFreeMemoryMESA
),
2824 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2826 /*** GLX_MESA_copy_sub_buffer ***/
2827 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2829 /*** GLX_MESA_pixmap_colormap ***/
2830 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2832 /*** GLX_MESA_release_buffers ***/
2833 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2835 /*** GLX_MESA_swap_control ***/
2836 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2837 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2839 /*** GLX_MESA_swap_frame_usage ***/
2840 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2841 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2842 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2843 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2845 /*** GLX_ARB_get_proc_address ***/
2846 GLX_FUNCTION( glXGetProcAddressARB
),
2849 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2851 /*** GLX_OML_sync_control ***/
2852 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2853 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2854 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2855 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2856 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2858 /*** GLX_EXT_texture_from_pixmap ***/
2859 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2860 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2862 #ifdef GLX_DIRECT_RENDERING
2863 /*** DRI configuration ***/
2864 GLX_FUNCTION( glXGetScreenDriver
),
2865 GLX_FUNCTION( glXGetDriverConfig
),
2868 { NULL
, NULL
} /* end of list */
2872 static const GLvoid
*
2873 get_glx_proc_address(const char *funcName
)
2877 /* try static functions */
2878 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2879 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2880 return GLX_functions
[i
].Address
;
2888 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2889 * \c glXGetProcAddress.
2891 * \param procName Name of a GL or GLX function.
2892 * \returns A pointer to the named function
2894 * \sa glXGetProcAddress
2896 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2898 typedef void (*gl_function
)( void );
2902 /* Search the table of GLX and internal functions first. If that
2903 * fails and the supplied name could be a valid core GL name, try
2904 * searching the core GL function table. This check is done to prevent
2905 * DRI based drivers from searching the core GL function table for
2906 * internal API functions.
2909 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2910 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2911 && (procName
[2] != 'X') ) {
2912 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2919 * Get the address of a named GL function. This is the GLX 1.4 name for
2920 * \c glXGetProcAddressARB.
2922 * \param procName Name of a GL or GLX function.
2923 * \returns A pointer to the named function
2925 * \sa glXGetProcAddressARB
2927 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2928 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2929 __attribute__ ((alias ("glXGetProcAddressARB")));
2932 return glXGetProcAddressARB(procName
);
2934 #endif /* __GNUC__ */
2937 #ifdef GLX_DIRECT_RENDERING
2939 * Get the unadjusted system time (UST). Currently, the UST is measured in
2940 * microseconds since Epoc. The actual resolution of the UST may vary from
2941 * system to system, and the units may vary from release to release.
2942 * Drivers should not call this function directly. They should instead use
2943 * \c glXGetProcAddress to obtain a pointer to the function.
2945 * \param ust Location to store the 64-bit UST
2946 * \returns Zero on success or a negative errno value on failure.
2948 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2950 * \since Internal API version 20030317.
2952 _X_HIDDEN
int __glXGetUST( int64_t * ust
)
2956 if ( ust
== NULL
) {
2960 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2961 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2967 #endif /* GLX_DIRECT_RENDERING */