1 /* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11 ** http://oss.sgi.com/projects/FreeB
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
39 * Client-side GLX interface.
43 #include "glxclient.h"
44 #include <X11/extensions/extutil.h>
45 #include <X11/extensions/Xext.h>
49 #ifdef GLX_DIRECT_RENDERING
50 #include "indirect_init.h"
51 #include <X11/extensions/xf86vmode.h>
54 #include "glxextensions.h"
55 #include "glcontextmodes.h"
59 static const char __glXGLXClientVendorName
[] = "SGI";
60 static const char __glXGLXClientVersion
[] = "1.4";
63 /****************************************************************************/
65 #ifdef GLX_DIRECT_RENDERING
67 static Bool windowExistsFlag
;
68 static int 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
83 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
87 XWindowAttributes xwa
;
88 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
90 /* Set no-op error handler so Xlib doesn't bail out if the windows
91 * has alreay been destroyed on the server. */
93 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
95 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
97 windowExistsFlag
= GL_TRUE
;
98 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
99 if (!windowExistsFlag
) {
100 /* Destroy the local drawable data, if the drawable no
101 longer exists in the Xserver */
102 (*pdraw
->driDrawable
.destroyDrawable
)(&pdraw
->driDrawable
);
103 XF86DRIDestroyDrawable(dpy
, sc
->scr
, draw
);
106 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
109 XSync(dpy
, GL_FALSE
);
110 XSetErrorHandler(oldXErrorHandler
);
114 * Get the __DRIdrawable for the drawable associated with a GLXContext
116 * \param dpy The display associated with \c drawable.
117 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
118 * \param scrn_num If non-NULL, the drawables screen is stored there
119 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
120 * the drawable is not associated with a direct-rendering context.
122 static __DRIdrawable
*
123 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
125 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
126 __GLXdrawable
* const pdraw
;
127 const unsigned screen_count
= ScreenCount(dpy
);
129 __GLXscreenConfigs
*sc
;
131 if (priv
== NULL
|| priv
->driDisplay
.private == NULL
)
134 for (i
= 0; i
< screen_count
; i
++) {
135 sc
= &priv
->screenConfigs
[i
];
136 if (__glxHashLookup(sc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
137 if (scrn_num
!= NULL
)
139 return &pdraw
->driDrawable
;
150 * Get the GLX per-screen data structure associated with a GLX context.
152 * \param dpy Display for which the GLX per-screen information is to be
154 * \param scrn Screen on \c dpy for which the GLX per-screen information is
156 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
157 * specify a valid GLX screen, or NULL otherwise.
159 * \todo Should this function validate that \c scrn is within the screen
160 * number range for \c dpy?
163 static __GLXscreenConfigs
*
164 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
166 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
168 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
173 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
174 __GLXscreenConfigs
** ppsc
)
176 /* Initialize the extension, if needed . This has the added value
177 * of initializing/allocating the display private
181 return GLX_NO_EXTENSION
;
184 *ppriv
= __glXInitialize(dpy
);
185 if ( *ppriv
== NULL
) {
186 return GLX_NO_EXTENSION
;
189 /* Check screen number to see if its valid */
190 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
191 return GLX_BAD_SCREEN
;
194 /* Check to see if the GL is supported on this screen */
195 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
196 if ( (*ppsc
)->configs
== NULL
) {
197 /* No support for GL on this screen regardless of visual */
198 return GLX_BAD_VISUAL
;
206 * Determine if a \c GLXFBConfig supplied by the application is valid.
208 * \param dpy Application supplied \c Display pointer.
209 * \param config Application supplied \c GLXFBConfig.
211 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
212 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
215 static __GLcontextModes
*
216 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
218 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
219 const unsigned num_screens
= ScreenCount(dpy
);
221 const __GLcontextModes
* modes
;
224 if ( priv
!= NULL
) {
225 for ( i
= 0 ; i
< num_screens
; i
++ ) {
226 for ( modes
= priv
->screenConfigs
[i
].configs
228 ; modes
= modes
->next
) {
229 if ( modes
== (__GLcontextModes
*) config
) {
230 return (__GLcontextModes
*) config
;
241 * \todo It should be possible to move the allocate of \c client_state_private
242 * later in the function for direct-rendering contexts. Direct-rendering
243 * contexts don't need to track client state, so they don't need that memory
246 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
247 * function called \c __glXAllocateClientState that allocates the memory and
248 * does all the initialization (including the pixel pack / unpack).
251 GLXContext
AllocateGLXContext( Display
*dpy
)
256 __GLXattribute
*state
;
261 opcode
= __glXSetupForCommand(dpy
);
266 /* Allocate our context record */
267 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
272 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
274 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
280 gc
->client_state_private
= state
;
281 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
282 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
285 ** Create a temporary buffer to hold GLX rendering commands. The size
286 ** of the buffer is selected so that the maximum number of GLX rendering
287 ** commands can fit in a single X packet and still have room in the X
288 ** packet for the GLXRenderReq header.
291 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
292 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
294 Xfree(gc
->client_state_private
);
298 gc
->bufSize
= bufSize
;
300 /* Fill in the new context */
301 gc
->renderMode
= GL_RENDER
;
303 state
->storePack
.alignment
= 4;
304 state
->storeUnpack
.alignment
= 4;
306 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
309 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
310 ** Other code uses the fastImageUnpack bit, but it is never set
313 gc
->fastImageUnpack
= GL_FALSE
;
314 gc
->fillImage
= __glFillImage
;
315 gc
->isDirect
= GL_FALSE
;
317 gc
->bufEnd
= gc
->buf
+ bufSize
;
320 ** Set limit register so that there will be one command per packet
324 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
327 gc
->majorOpcode
= opcode
;
330 ** Constrain the maximum drawing command size allowed to be
331 ** transfered using the X_GLXRender protocol request. First
332 ** constrain by a software limit, then constrain by the protocl
335 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
336 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
338 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
339 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
341 gc
->maxSmallRenderCommandSize
= bufSize
;
347 * Create a new context. Exactly one of \c vis and \c fbconfig should be
350 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
351 * SGIX_fbconfig protocol be used?
352 * \param renderType For FBConfigs, what is the rendering type?
356 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
357 const __GLcontextModes
* const fbconfig
,
358 GLXContext shareList
,
359 Bool allowDirect
, GLXContextID contextID
,
360 Bool use_glx_1_3
, int renderType
)
367 gc
= AllocateGLXContext(dpy
);
371 if (None
== contextID
) {
372 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
375 #ifdef GLX_DIRECT_RENDERING
377 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
378 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
379 const __GLcontextModes
* mode
;
380 drm_context_t hwContext
;
382 /* The value of fbconfig cannot change because it is tested
383 * later in the function.
385 if ( fbconfig
== NULL
) {
386 /* FIXME: Is it possible for the __GLcontextModes structure
387 * FIXME: to not be found?
389 mode
= _gl_context_modes_find_visual( psc
->configs
,
391 assert( mode
!= NULL
);
392 assert( mode
->screen
== screen
);
398 if (psc
&& psc
->driScreen
.private) {
399 __DRIcontext
*shared
= (shareList
!= NULL
)
400 ? &shareList
->driContext
: NULL
;
403 if (!XF86DRICreateContextWithConfig(dpy
, psc
->scr
,
405 &gc
->hwContextID
, &hwContext
))
406 /* gah, handle this better */
409 gc
->driContext
.private =
410 (*psc
->driScreen
.createNewContext
)( &psc
->driScreen
,
415 if (gc
->driContext
.private) {
416 gc
->isDirect
= GL_TRUE
;
417 gc
->screen
= mode
->screen
;
419 gc
->vid
= mode
->visualID
;
420 gc
->fbconfigID
= mode
->fbconfigID
;
424 XF86DRIDestroyContext(dpy
, psc
->scr
, gc
->hwContextID
);
431 if ( fbconfig
== NULL
) {
432 xGLXCreateContextReq
*req
;
434 /* Send the glXCreateContext request */
435 GetReq(GLXCreateContext
,req
);
436 req
->reqType
= gc
->majorOpcode
;
437 req
->glxCode
= X_GLXCreateContext
;
438 req
->context
= gc
->xid
= XAllocID(dpy
);
439 req
->visual
= vis
->visualid
;
440 req
->screen
= vis
->screen
;
441 req
->shareList
= shareList
? shareList
->xid
: None
;
442 req
->isDirect
= gc
->isDirect
;
444 else if ( use_glx_1_3
) {
445 xGLXCreateNewContextReq
*req
;
447 /* Send the glXCreateNewContext request */
448 GetReq(GLXCreateNewContext
,req
);
449 req
->reqType
= gc
->majorOpcode
;
450 req
->glxCode
= X_GLXCreateNewContext
;
451 req
->context
= gc
->xid
= XAllocID(dpy
);
452 req
->fbconfig
= fbconfig
->fbconfigID
;
453 req
->screen
= fbconfig
->screen
;
454 req
->renderType
= renderType
;
455 req
->shareList
= shareList
? shareList
->xid
: None
;
456 req
->isDirect
= gc
->isDirect
;
459 xGLXVendorPrivateWithReplyReq
*vpreq
;
460 xGLXCreateContextWithConfigSGIXReq
*req
;
462 /* Send the glXCreateNewContext request */
463 GetReqExtra(GLXVendorPrivateWithReply
,
464 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
465 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
466 req
->reqType
= gc
->majorOpcode
;
467 req
->glxCode
= X_GLXVendorPrivateWithReply
;
468 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
469 req
->context
= gc
->xid
= XAllocID(dpy
);
470 req
->fbconfig
= fbconfig
->fbconfigID
;
471 req
->screen
= fbconfig
->screen
;
472 req
->renderType
= renderType
;
473 req
->shareList
= shareList
? shareList
->xid
: None
;
474 req
->isDirect
= gc
->isDirect
;
479 gc
->imported
= GL_FALSE
;
483 gc
->imported
= GL_TRUE
;
489 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
490 GLXContext shareList
, Bool allowDirect
)
492 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
496 void __glXFreeContext(__GLXcontext
*gc
)
498 if (gc
->vendor
) XFree((char *) gc
->vendor
);
499 if (gc
->renderer
) XFree((char *) gc
->renderer
);
500 if (gc
->version
) XFree((char *) gc
->version
);
501 if (gc
->extensions
) XFree((char *) gc
->extensions
);
502 __glFreeAttributeState(gc
);
503 XFree((char *) gc
->buf
);
504 Xfree((char *) gc
->client_state_private
);
510 ** Destroy the named context
513 DestroyContext(Display
*dpy
, GLXContext gc
)
515 xGLXDestroyContextReq
*req
;
520 opcode
= __glXSetupForCommand(dpy
);
521 if (!opcode
|| !gc
) {
527 imported
= gc
->imported
;
530 #ifdef GLX_DIRECT_RENDERING
531 /* Destroy the direct rendering context */
533 if (gc
->driContext
.private) {
534 (*gc
->driContext
.destroyContext
)(&gc
->driContext
);
535 XF86DRIDestroyContext(dpy
, gc
->psc
->scr
, gc
->hwContextID
);
536 gc
->driContext
.private = NULL
;
538 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
542 if (gc
->currentDpy
) {
543 /* Have to free later cuz it's in use now */
546 /* Destroy the handle if not current to anybody */
548 __glXFreeContext(gc
);
553 ** This dpy also created the server side part of the context.
554 ** Send the glXDestroyContext request.
557 GetReq(GLXDestroyContext
,req
);
558 req
->reqType
= opcode
;
559 req
->glxCode
= X_GLXDestroyContext
;
566 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
568 DestroyContext(dpy
, gc
);
572 ** Return the major and minor version #s for the GLX extension
574 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
576 __GLXdisplayPrivate
*priv
;
578 /* Init the extension. This fetches the major and minor version. */
579 priv
= __glXInitialize(dpy
);
580 if (!priv
) return GL_FALSE
;
582 if (major
) *major
= priv
->majorVersion
;
583 if (minor
) *minor
= priv
->minorVersion
;
588 ** Query the existance of the GLX extension
590 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
592 int major_op
, erb
, evb
;
595 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
597 if (errorBase
) *errorBase
= erb
;
598 if (eventBase
) *eventBase
= evb
;
604 ** Put a barrier in the token stream that forces the GL to finish its
605 ** work before X can proceed.
607 PUBLIC
void glXWaitGL(void)
610 GLXContext gc
= __glXGetCurrentContext();
611 Display
*dpy
= gc
->currentDpy
;
615 /* Flush any pending commands out */
616 __glXFlushRenderBuffer(gc
, gc
->pc
);
618 #ifdef GLX_DIRECT_RENDERING
620 /* This bit of ugliness unwraps the glFinish function */
629 /* Send the glXWaitGL request */
631 GetReq(GLXWaitGL
,req
);
632 req
->reqType
= gc
->majorOpcode
;
633 req
->glxCode
= X_GLXWaitGL
;
634 req
->contextTag
= gc
->currentContextTag
;
640 ** Put a barrier in the token stream that forces X to finish its
641 ** work before GL can proceed.
643 PUBLIC
void glXWaitX(void)
646 GLXContext gc
= __glXGetCurrentContext();
647 Display
*dpy
= gc
->currentDpy
;
651 /* Flush any pending commands out */
652 __glXFlushRenderBuffer(gc
, gc
->pc
);
654 #ifdef GLX_DIRECT_RENDERING
662 ** Send the glXWaitX request.
665 GetReq(GLXWaitX
,req
);
666 req
->reqType
= gc
->majorOpcode
;
667 req
->glxCode
= X_GLXWaitX
;
668 req
->contextTag
= gc
->currentContextTag
;
673 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
675 xGLXUseXFontReq
*req
;
676 GLXContext gc
= __glXGetCurrentContext();
677 Display
*dpy
= gc
->currentDpy
;
681 /* Flush any pending commands out */
682 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
684 #ifdef GLX_DIRECT_RENDERING
686 DRI_glXUseXFont(font
, first
, count
, listBase
);
691 /* Send the glXUseFont request */
693 GetReq(GLXUseXFont
,req
);
694 req
->reqType
= gc
->majorOpcode
;
695 req
->glxCode
= X_GLXUseXFont
;
696 req
->contextTag
= gc
->currentContextTag
;
700 req
->listBase
= listBase
;
705 /************************************************************************/
708 ** Copy the source context to the destination context using the
711 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
712 GLXContext dest
, unsigned long mask
)
714 xGLXCopyContextReq
*req
;
715 GLXContext gc
= __glXGetCurrentContext();
719 opcode
= __glXSetupForCommand(dpy
);
724 #ifdef GLX_DIRECT_RENDERING
726 /* NOT_DONE: This does not work yet */
731 ** If the source is the current context, send its tag so that the context
732 ** can be flushed before the copy.
734 if (source
== gc
&& dpy
== gc
->currentDpy
) {
735 tag
= gc
->currentContextTag
;
740 /* Send the glXCopyContext request */
742 GetReq(GLXCopyContext
,req
);
743 req
->reqType
= opcode
;
744 req
->glxCode
= X_GLXCopyContext
;
745 req
->source
= source
? source
->xid
: None
;
746 req
->dest
= dest
? dest
->xid
: None
;
748 req
->contextTag
= tag
;
755 * Determine if a context uses direct rendering.
757 * \param dpy Display where the context was created.
758 * \param contextID ID of the context to be tested.
760 * \returns \c GL_TRUE if the context is direct rendering or not.
762 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
764 xGLXIsDirectReq
*req
;
765 xGLXIsDirectReply reply
;
768 opcode
= __glXSetupForCommand(dpy
);
773 /* Send the glXIsDirect request */
775 GetReq(GLXIsDirect
,req
);
776 req
->reqType
= opcode
;
777 req
->glxCode
= X_GLXIsDirect
;
778 req
->context
= contextID
;
779 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
783 return reply
.isDirect
;
788 * Shouldn't this function \b always return \c GL_FALSE when
789 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
790 * the GLX protocol here at all?
792 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
796 #ifdef GLX_DIRECT_RENDERING
797 } else if (gc
->isDirect
) {
801 return __glXIsDirect(dpy
, gc
->xid
);
804 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
807 xGLXCreateGLXPixmapReq
*req
;
811 opcode
= __glXSetupForCommand(dpy
);
816 /* Send the glXCreateGLXPixmap request */
818 GetReq(GLXCreateGLXPixmap
,req
);
819 req
->reqType
= opcode
;
820 req
->glxCode
= X_GLXCreateGLXPixmap
;
821 req
->screen
= vis
->screen
;
822 req
->visual
= vis
->visualid
;
823 req
->pixmap
= pixmap
;
824 req
->glxpixmap
= xid
= XAllocID(dpy
);
831 ** Destroy the named pixmap
833 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
835 xGLXDestroyGLXPixmapReq
*req
;
838 opcode
= __glXSetupForCommand(dpy
);
843 /* Send the glXDestroyGLXPixmap request */
845 GetReq(GLXDestroyGLXPixmap
,req
);
846 req
->reqType
= opcode
;
847 req
->glxCode
= X_GLXDestroyGLXPixmap
;
848 req
->glxpixmap
= glxpixmap
;
853 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
855 xGLXSwapBuffersReq
*req
;
859 #ifdef GLX_DIRECT_RENDERING
860 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
862 if ( pdraw
!= NULL
) {
863 (*pdraw
->swapBuffers
)(pdraw
);
868 opcode
= __glXSetupForCommand(dpy
);
874 ** The calling thread may or may not have a current context. If it
875 ** does, send the context tag so the server can do a flush.
877 gc
= __glXGetCurrentContext();
878 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
879 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
880 tag
= gc
->currentContextTag
;
885 /* Send the glXSwapBuffers request */
887 GetReq(GLXSwapBuffers
,req
);
888 req
->reqType
= opcode
;
889 req
->glxCode
= X_GLXSwapBuffers
;
890 req
->drawable
= drawable
;
891 req
->contextTag
= tag
;
899 ** Return configuration information for the given display, screen and
900 ** visual combination.
902 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
905 __GLXdisplayPrivate
*priv
;
906 __GLXscreenConfigs
*psc
;
907 __GLcontextModes
*modes
;
910 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
911 if ( status
== Success
) {
912 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
914 /* Lookup attribute after first finding a match on the visual */
915 if ( modes
!= NULL
) {
916 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
919 status
= GLX_BAD_VISUAL
;
923 ** If we can't find the config for this visual, this visual is not
924 ** supported by the OpenGL implementation on the server.
926 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
927 *value_return
= GL_FALSE
;
934 /************************************************************************/
937 init_fbconfig_for_chooser( __GLcontextModes
* config
,
938 GLboolean fbconfig_style_tags
)
940 memset( config
, 0, sizeof( __GLcontextModes
) );
941 config
->visualID
= (XID
) GLX_DONT_CARE
;
942 config
->visualType
= GLX_DONT_CARE
;
944 /* glXChooseFBConfig specifies different defaults for these two than
947 if ( fbconfig_style_tags
) {
948 config
->rgbMode
= GL_TRUE
;
949 config
->doubleBufferMode
= GLX_DONT_CARE
;
952 config
->visualRating
= GLX_DONT_CARE
;
953 config
->transparentPixel
= GLX_NONE
;
954 config
->transparentRed
= GLX_DONT_CARE
;
955 config
->transparentGreen
= GLX_DONT_CARE
;
956 config
->transparentBlue
= GLX_DONT_CARE
;
957 config
->transparentAlpha
= GLX_DONT_CARE
;
958 config
->transparentIndex
= GLX_DONT_CARE
;
960 config
->drawableType
= GLX_WINDOW_BIT
;
961 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
962 config
->xRenderable
= GLX_DONT_CARE
;
963 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
965 config
->swapMethod
= GLX_DONT_CARE
;
968 #define MATCH_DONT_CARE( param ) \
970 if ( (a-> param != GLX_DONT_CARE) \
971 && (a-> param != b-> param) ) { \
976 #define MATCH_MINIMUM( param ) \
978 if ( (a-> param != GLX_DONT_CARE) \
979 && (a-> param > b-> param) ) { \
984 #define MATCH_EXACT( param ) \
986 if ( a-> param != b-> param) { \
992 * Determine if two GLXFBConfigs are compatible.
994 * \param a Application specified config to test.
995 * \param b Server specified config to test against \c a.
998 fbconfigs_compatible( const __GLcontextModes
* const a
,
999 const __GLcontextModes
* const b
)
1001 MATCH_DONT_CARE( doubleBufferMode
);
1002 MATCH_DONT_CARE( visualType
);
1003 MATCH_DONT_CARE( visualRating
);
1004 MATCH_DONT_CARE( xRenderable
);
1005 MATCH_DONT_CARE( fbconfigID
);
1006 MATCH_DONT_CARE( swapMethod
);
1008 MATCH_MINIMUM( rgbBits
);
1009 MATCH_MINIMUM( numAuxBuffers
);
1010 MATCH_MINIMUM( redBits
);
1011 MATCH_MINIMUM( greenBits
);
1012 MATCH_MINIMUM( blueBits
);
1013 MATCH_MINIMUM( alphaBits
);
1014 MATCH_MINIMUM( depthBits
);
1015 MATCH_MINIMUM( stencilBits
);
1016 MATCH_MINIMUM( accumRedBits
);
1017 MATCH_MINIMUM( accumGreenBits
);
1018 MATCH_MINIMUM( accumBlueBits
);
1019 MATCH_MINIMUM( accumAlphaBits
);
1020 MATCH_MINIMUM( sampleBuffers
);
1021 MATCH_MINIMUM( maxPbufferWidth
);
1022 MATCH_MINIMUM( maxPbufferHeight
);
1023 MATCH_MINIMUM( maxPbufferPixels
);
1024 MATCH_MINIMUM( samples
);
1026 MATCH_DONT_CARE( stereoMode
);
1027 MATCH_EXACT( level
);
1029 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1030 || ((a
->renderType
& b
->renderType
) == 0) ) {
1035 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1036 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1037 * Technically speaking, it is a bug in the DDX driver, but there is
1038 * enough of an installed base to work around the problem here. In any
1039 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1040 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1041 * 0 from the server to be a match to maintain backward compatibility with
1042 * the (broken) drivers.
1045 if ( a
->transparentPixel
!= GLX_DONT_CARE
1046 && a
->transparentPixel
!= 0 ) {
1047 if ( a
->transparentPixel
== GLX_NONE
) {
1048 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1051 MATCH_EXACT( transparentPixel
);
1054 switch ( a
->transparentPixel
) {
1055 case GLX_TRANSPARENT_RGB
:
1056 MATCH_DONT_CARE( transparentRed
);
1057 MATCH_DONT_CARE( transparentGreen
);
1058 MATCH_DONT_CARE( transparentBlue
);
1059 MATCH_DONT_CARE( transparentAlpha
);
1062 case GLX_TRANSPARENT_INDEX
:
1063 MATCH_DONT_CARE( transparentIndex
);
1075 /* There's some trickly language in the GLX spec about how this is supposed
1076 * to work. Basically, if a given component size is either not specified
1077 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1078 * Well, that's really hard to do with the code as-is. This behavior is
1079 * closer to correct, but still not technically right.
1081 #define PREFER_LARGER_OR_ZERO(comp) \
1083 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1084 if ( ((*a)-> comp) == 0 ) { \
1087 else if ( ((*b)-> comp) == 0 ) { \
1091 return ((*b)-> comp) - ((*a)-> comp) ; \
1096 #define PREFER_LARGER(comp) \
1098 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1099 return ((*b)-> comp) - ((*a)-> comp) ; \
1103 #define PREFER_SMALLER(comp) \
1105 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1106 return ((*a)-> comp) - ((*b)-> comp) ; \
1111 * Compare two GLXFBConfigs. This function is intended to be used as the
1112 * compare function passed in to qsort.
1114 * \returns If \c a is a "better" config, according to the specification of
1115 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1116 * better, then a number greater than zero is return. If both are
1117 * equal, zero is returned.
1118 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1121 fbconfig_compare( const __GLcontextModes
* const * const a
,
1122 const __GLcontextModes
* const * const b
)
1124 /* The order of these comparisons must NOT change. It is defined by
1125 * the GLX 1.3 spec and ARB_multisample.
1128 PREFER_SMALLER( visualSelectGroup
);
1130 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1131 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1132 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1134 PREFER_SMALLER( visualRating
);
1136 /* This isn't quite right. It is supposed to compare the sum of the
1137 * components the user specifically set minimums for.
1139 PREFER_LARGER_OR_ZERO( redBits
);
1140 PREFER_LARGER_OR_ZERO( greenBits
);
1141 PREFER_LARGER_OR_ZERO( blueBits
);
1142 PREFER_LARGER_OR_ZERO( alphaBits
);
1144 PREFER_SMALLER( rgbBits
);
1146 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1147 /* Prefer single-buffer.
1149 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1152 PREFER_SMALLER( numAuxBuffers
);
1154 PREFER_LARGER_OR_ZERO( depthBits
);
1155 PREFER_SMALLER( stencilBits
);
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( accumRedBits
);
1161 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1162 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1163 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1165 PREFER_SMALLER( visualType
);
1167 /* None of the multisample specs say where this comparison should happen,
1168 * so I put it near the end.
1170 PREFER_SMALLER( sampleBuffers
);
1171 PREFER_SMALLER( samples
);
1173 /* None of the pbuffer or fbconfig specs say that this comparison needs
1174 * to happen at all, but it seems like it should.
1176 PREFER_LARGER( maxPbufferWidth
);
1177 PREFER_LARGER( maxPbufferHeight
);
1178 PREFER_LARGER( maxPbufferPixels
);
1185 * Selects and sorts a subset of the supplied configs based on the attributes.
1186 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1187 * and \c glXChooseFBConfigSGIX.
1189 * \param configs Array of pointers to possible configs. The elements of
1190 * this array that do not meet the criteria will be set to
1191 * NULL. The remaining elements will be sorted according to
1192 * the various visual / FBConfig selection rules.
1193 * \param num_configs Number of elements in the \c configs array.
1194 * \param attribList Attributes used select from \c configs. This array is
1195 * terminated by a \c None tag. The array can either take
1196 * the form expected by \c glXChooseVisual (where boolean
1197 * tags do not have a value) or by \c glXChooseFBConfig
1198 * (where every tag has a value).
1199 * \param fbconfig_style_tags Selects whether \c attribList is in
1200 * \c glXChooseVisual style or
1201 * \c glXChooseFBConfig style.
1202 * \returns The number of valid elements left in \c configs.
1204 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1207 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1208 const int *attribList
, GLboolean fbconfig_style_tags
)
1210 __GLcontextModes test_config
;
1214 /* This is a fairly direct implementation of the selection method
1215 * described by GLX_SGIX_fbconfig. Start by culling out all the
1216 * configs that are not compatible with the selected parameter
1220 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1221 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1222 (const INT32
*) attribList
,
1223 GL_TRUE
, fbconfig_style_tags
);
1226 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1227 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1228 configs
[ base
] = configs
[ i
];
1237 if ( base
< num_configs
) {
1238 (void) memset( & configs
[ base
], 0,
1239 sizeof( void * ) * (num_configs
- base
) );
1242 /* After the incompatible configs are removed, the resulting
1243 * list is sorted according to the rules set out in the various
1247 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1248 (int (*)(const void*, const void*)) fbconfig_compare
);
1256 ** Return the visual that best matches the template. Return None if no
1257 ** visual matches the template.
1259 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1261 XVisualInfo
*visualList
= NULL
;
1262 __GLXdisplayPrivate
*priv
;
1263 __GLXscreenConfigs
*psc
;
1264 __GLcontextModes test_config
;
1265 __GLcontextModes
*modes
;
1266 const __GLcontextModes
*best_config
= NULL
;
1269 ** Get a list of all visuals, return if list is empty
1271 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1277 ** Build a template from the defaults and the attribute list
1278 ** Free visual list and return if an unexpected token is encountered
1280 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1281 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1282 (const INT32
*) attribList
,
1283 GL_TRUE
, GL_FALSE
);
1286 ** Eliminate visuals that don't meet minimum requirements
1287 ** Compute a score for those that do
1288 ** Remember which visual, if any, got the highest score
1290 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1291 if ( fbconfigs_compatible( & test_config
, modes
)
1292 && ((best_config
== NULL
)
1293 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1294 best_config
= modes
;
1299 ** If no visual is acceptable, return None
1300 ** Otherwise, create an XVisualInfo list with just the selected X visual
1303 if (best_config
!= NULL
) {
1304 XVisualInfo visualTemplate
;
1307 visualTemplate
.screen
= screen
;
1308 visualTemplate
.visualid
= best_config
->visualID
;
1309 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1310 &visualTemplate
, &i
);
1317 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1319 __GLXscreenConfigs
*psc
;
1320 __GLXdisplayPrivate
*priv
;
1322 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1326 if (!psc
->effectiveGLXexts
) {
1327 if (!psc
->serverGLXexts
) {
1328 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1329 X_GLXQueryServerString
,
1330 screen
, GLX_EXTENSIONS
);
1333 __glXCalculateUsableExtensions(psc
,
1334 #ifdef GLX_DIRECT_RENDERING
1335 (psc
->driScreen
.private != NULL
),
1339 priv
->minorVersion
);
1342 return psc
->effectiveGLXexts
;
1345 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1349 return (__glXGLXClientVendorName
);
1351 return (__glXGLXClientVersion
);
1352 case GLX_EXTENSIONS
:
1353 return (__glXGetClientExtensions());
1359 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1361 __GLXscreenConfigs
*psc
;
1362 __GLXdisplayPrivate
*priv
;
1366 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1372 str
= & priv
->serverGLXvendor
;
1375 str
= & priv
->serverGLXversion
;
1377 case GLX_EXTENSIONS
:
1378 str
= & psc
->serverGLXexts
;
1384 if ( *str
== NULL
) {
1385 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1386 X_GLXQueryServerString
, screen
, name
);
1392 void __glXClientInfo ( Display
*dpy
, int opcode
)
1394 xGLXClientInfoReq
*req
;
1396 char * ext_str
= __glXGetClientGLExtensionString();
1398 /* Send the glXClientInfo request */
1400 GetReq(GLXClientInfo
,req
);
1401 req
->reqType
= opcode
;
1402 req
->glxCode
= X_GLXClientInfo
;
1403 req
->major
= GLX_MAJOR_VERSION
;
1404 req
->minor
= GLX_MINOR_VERSION
;
1406 size
= strlen( ext_str
) + 1;
1407 req
->length
+= (size
+ 3) >> 2;
1408 req
->numbytes
= size
;
1409 Data(dpy
, ext_str
, size
);
1419 ** EXT_import_context
1422 PUBLIC Display
*glXGetCurrentDisplay(void)
1424 GLXContext gc
= __glXGetCurrentContext();
1425 if (NULL
== gc
) return NULL
;
1426 return gc
->currentDpy
;
1429 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1430 glXGetCurrentDisplay
)
1433 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1436 * \param dpy Display where \c ctx was created.
1437 * \param ctx Context to query.
1438 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1439 * or zero if the request failed due to internal problems (i.e.,
1440 * unable to allocate temporary memory, etc.)
1443 * This function dynamically determines whether to use the EXT_import_context
1444 * version of the protocol or the GLX 1.3 version of the protocol.
1446 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1448 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1449 xGLXQueryContextReply reply
;
1455 return GLX_BAD_CONTEXT
;
1457 opcode
= __glXSetupForCommand(dpy
);
1462 /* Send the glXQueryContextInfoEXT request */
1465 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1466 xGLXQueryContextReq
*req
;
1468 GetReq(GLXQueryContext
, req
);
1470 req
->reqType
= opcode
;
1471 req
->glxCode
= X_GLXQueryContext
;
1472 req
->context
= (unsigned int)(ctx
->xid
);
1475 xGLXVendorPrivateReq
*vpreq
;
1476 xGLXQueryContextInfoEXTReq
*req
;
1478 GetReqExtra( GLXVendorPrivate
,
1479 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1481 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1482 req
->reqType
= opcode
;
1483 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1484 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1485 req
->context
= (unsigned int)(ctx
->xid
);
1488 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1490 numValues
= reply
.n
;
1493 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1497 int *propList
, *pProp
;
1501 nPropListBytes
= numValues
<< 3;
1502 propList
= (int *) Xmalloc(nPropListBytes
);
1503 if (NULL
== propList
) {
1506 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1508 for (i
=0; i
< numValues
; i
++) {
1510 case GLX_SHARE_CONTEXT_EXT
:
1511 ctx
->share_xid
= *pProp
++;
1513 case GLX_VISUAL_ID_EXT
:
1514 ctx
->vid
= *pProp
++;
1517 ctx
->screen
= *pProp
++;
1519 case GLX_FBCONFIG_ID
:
1520 ctx
->fbconfigID
= *pProp
++;
1522 case GLX_RENDER_TYPE
:
1523 ctx
->renderType
= *pProp
++;
1530 Xfree((char *)propList
);
1540 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1544 /* get the information from the server if we don't have it already */
1545 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1546 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1547 if (Success
!= retVal
) return retVal
;
1549 switch (attribute
) {
1550 case GLX_SHARE_CONTEXT_EXT
:
1551 *value
= (int)(ctx
->share_xid
);
1553 case GLX_VISUAL_ID_EXT
:
1554 *value
= (int)(ctx
->vid
);
1557 *value
= (int)(ctx
->screen
);
1559 case GLX_FBCONFIG_ID
:
1560 *value
= (int)(ctx
->fbconfigID
);
1562 case GLX_RENDER_TYPE
:
1563 *value
= (int)(ctx
->renderType
);
1566 return GLX_BAD_ATTRIBUTE
;
1571 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1572 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1573 (dpy
, ctx
, attribute
, value
),
1576 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1581 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1585 if (contextID
== None
) {
1588 if (__glXIsDirect(dpy
, contextID
)) {
1592 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1594 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1601 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1603 DestroyContext(dpy
, ctx
);
1609 * GLX 1.3 functions - these are just stubs for now!
1612 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1613 const int *attribList
, int *nitems
)
1615 __GLcontextModes
** config_list
;
1619 config_list
= (__GLcontextModes
**)
1620 glXGetFBConfigs( dpy
, screen
, & list_size
);
1622 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1623 list_size
= choose_visual( config_list
, list_size
, attribList
,
1625 if ( list_size
== 0 ) {
1626 XFree( config_list
);
1631 *nitems
= list_size
;
1632 return (GLXFBConfig
*) config_list
;
1636 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1637 int renderType
, GLXContext shareList
,
1640 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1641 allowDirect
, None
, True
, renderType
);
1645 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1647 GLXContext gc
= __glXGetCurrentContext();
1648 return gc
->currentReadable
;
1652 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1654 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1655 __GLcontextModes
** config
= NULL
;
1659 if ( (priv
->screenConfigs
!= NULL
)
1660 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1661 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1662 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1663 unsigned num_configs
= 0;
1664 __GLcontextModes
* modes
;
1667 for ( modes
= priv
->screenConfigs
[screen
].configs
1669 ; modes
= modes
->next
) {
1670 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1675 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1677 if ( config
!= NULL
) {
1678 *nelements
= num_configs
;
1680 for ( modes
= priv
->screenConfigs
[screen
].configs
1682 ; modes
= modes
->next
) {
1683 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1690 return (GLXFBConfig
*) config
;
1694 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1695 int attribute
, int *value
)
1697 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1699 return (modes
!= NULL
)
1700 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1705 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1707 XVisualInfo visualTemplate
;
1708 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1712 ** Get a list of all visuals, return if list is empty
1714 visualTemplate
.visualid
= fbconfig
->visualID
;
1715 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1720 ** GLX_SGI_swap_control
1722 static int __glXSwapIntervalSGI(int interval
)
1724 xGLXVendorPrivateReq
*req
;
1725 GLXContext gc
= __glXGetCurrentContext();
1727 CARD32
* interval_ptr
;
1731 return GLX_BAD_CONTEXT
;
1734 if ( interval
<= 0 ) {
1735 return GLX_BAD_VALUE
;
1738 #ifdef __DRI_SWAP_CONTROL
1739 if ( gc
->isDirect
) {
1740 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1742 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1743 gc
->currentDrawable
,
1745 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1746 psc
->swapControl
->setSwapInterval(pdraw
, interval
);
1750 return GLX_BAD_CONTEXT
;
1754 dpy
= gc
->currentDpy
;
1755 opcode
= __glXSetupForCommand(dpy
);
1760 /* Send the glXSwapIntervalSGI request */
1762 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1763 req
->reqType
= opcode
;
1764 req
->glxCode
= X_GLXVendorPrivate
;
1765 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1766 req
->contextTag
= gc
->currentContextTag
;
1768 interval_ptr
= (CARD32
*) (req
+ 1);
1769 *interval_ptr
= interval
;
1780 ** GLX_MESA_swap_control
1782 static int __glXSwapIntervalMESA(unsigned int interval
)
1784 #ifdef __DRI_SWAP_CONTROL
1785 GLXContext gc
= __glXGetCurrentContext();
1787 if ( interval
< 0 ) {
1788 return GLX_BAD_VALUE
;
1791 if ( (gc
!= NULL
) && gc
->isDirect
) {
1792 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1795 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
) ) {
1796 __DRIdrawable
* const pdraw
=
1797 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1798 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1799 psc
->swapControl
->setSwapInterval(pdraw
, interval
);
1808 return GLX_BAD_CONTEXT
;
1812 static int __glXGetSwapIntervalMESA(void)
1814 #ifdef __DRI_SWAP_CONTROL
1815 GLXContext gc
= __glXGetCurrentContext();
1817 if ( (gc
!= NULL
) && gc
->isDirect
) {
1818 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1821 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
) ) {
1822 __DRIdrawable
* const pdraw
=
1823 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1824 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1825 return psc
->swapControl
->getSwapInterval(pdraw
);
1836 ** GLX_MESA_swap_frame_usage
1839 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1841 int status
= GLX_BAD_CONTEXT
;
1842 #ifdef __DRI_FRAME_TRACKING
1844 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1845 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1847 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1848 status
= psc
->frameTracking
->frameTracking(pdraw
, GL_TRUE
);
1857 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1859 int status
= GLX_BAD_CONTEXT
;
1860 #ifdef __DRI_FRAME_TRACKING
1862 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1863 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1865 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1866 status
= psc
->frameTracking
->frameTracking(pdraw
, GL_FALSE
);
1875 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1878 int status
= GLX_BAD_CONTEXT
;
1879 #ifdef __DRI_FRAME_TRACKING
1881 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1882 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1884 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1885 int64_t sbc
, missedFrames
;
1886 float lastMissedUsage
;
1888 status
= psc
->frameTracking
->queryFrameTracking(pdraw
, &sbc
,
1902 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1903 int64_t *sbc
, int64_t *missedFrames
,
1904 GLfloat
*lastMissedUsage
)
1906 int status
= GLX_BAD_CONTEXT
;
1907 #ifdef __DRI_FRAME_TRACKING
1909 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1910 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1912 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1915 status
= psc
->frameTracking
->queryFrameTracking(pdraw
, sbc
, missedFrames
,
1916 lastMissedUsage
, &usage
);
1922 (void) missedFrames
;
1923 (void) lastMissedUsage
;
1930 ** GLX_SGI_video_sync
1932 static int __glXGetVideoSyncSGI(unsigned int *count
)
1934 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1935 * FIXME: there should be a GLX encoding for this call. I can find no
1936 * FIXME: documentation for the GLX encoding.
1938 #ifdef __DRI_MEDIA_STREAM_COUNTER
1939 GLXContext gc
= __glXGetCurrentContext();
1942 if ( (gc
!= NULL
) && gc
->isDirect
) {
1943 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1945 if ( psc
->msc
&& psc
->driScreen
.private ) {
1946 __DRIdrawable
* const pdraw
=
1947 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1952 * Try to use getDrawableMSC first so we get the right
1955 if (psc
->msc
->base
.version
>= 2 && psc
->msc
->getDrawableMSC
)
1956 ret
= (*psc
->msc
->getDrawableMSC
)( &psc
->driScreen
,
1960 ret
= (*psc
->msc
->getMSC
)( &psc
->driScreen
, & temp
);
1961 *count
= (unsigned) temp
;
1962 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1968 return GLX_BAD_CONTEXT
;
1971 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1973 #ifdef __DRI_MEDIA_STREAM_COUNTER
1974 GLXContext gc
= __glXGetCurrentContext();
1976 if ( divisor
<= 0 || remainder
< 0 )
1977 return GLX_BAD_VALUE
;
1979 if ( (gc
!= NULL
) && gc
->isDirect
) {
1980 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1982 if (psc
->msc
!= NULL
&& psc
->driScreen
.private ) {
1983 __DRIdrawable
* const pdraw
=
1984 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1989 ret
= (*psc
->msc
->waitForMSC
)(pdraw
, 0, divisor
, remainder
, &msc
,
1991 *count
= (unsigned) msc
;
1992 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1998 return GLX_BAD_CONTEXT
;
2003 ** GLX_SGIX_fbconfig
2004 ** Many of these functions are aliased to GLX 1.3 entry points in the
2005 ** GLX_functions table.
2008 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2009 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2010 (dpy
, config
, attribute
, value
),
2011 glXGetFBConfigAttrib
)
2013 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2014 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2015 (dpy
, screen
, attrib_list
, nelements
),
2018 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2019 (Display
* dpy
, GLXFBConfigSGIX config
),
2021 glXGetVisualFromFBConfig
)
2023 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2024 GLXFBConfigSGIX config
, Pixmap pixmap
)
2026 xGLXVendorPrivateWithReplyReq
*vpreq
;
2027 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2028 GLXPixmap xid
= None
;
2030 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2031 __GLXscreenConfigs
* psc
;
2034 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2038 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2040 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2041 opcode
= __glXSetupForCommand(dpy
);
2046 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2048 GetReqExtra(GLXVendorPrivateWithReply
,
2049 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2050 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2051 req
->reqType
= opcode
;
2052 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2053 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2054 req
->screen
= fbconfig
->screen
;
2055 req
->fbconfig
= fbconfig
->fbconfigID
;
2056 req
->pixmap
= pixmap
;
2057 req
->glxpixmap
= xid
= XAllocID(dpy
);
2065 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2066 GLXFBConfigSGIX config
, int renderType
,
2067 GLXContext shareList
, Bool allowDirect
)
2069 GLXContext gc
= NULL
;
2070 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2071 __GLXscreenConfigs
* psc
;
2074 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2078 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2080 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2081 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2082 allowDirect
, None
, False
, renderType
);
2089 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2092 __GLXdisplayPrivate
*priv
;
2093 __GLXscreenConfigs
*psc
;
2095 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2096 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2097 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2098 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2107 ** GLX_SGIX_swap_group
2109 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2119 ** GLX_SGIX_swap_barrier
2121 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2129 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2139 ** GLX_OML_sync_control
2141 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2142 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2144 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2145 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2147 if ( priv
!= NULL
) {
2149 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2150 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2152 assert( (pdraw
== NULL
) || (i
!= -1) );
2153 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2154 && ((*psc
->msc
->getMSC
)(&psc
->driScreen
, msc
) == 0)
2155 && ((*psc
->sbc
->getSBC
)(pdraw
, sbc
) == 0)
2156 && (__glXGetUST(ust
) == 0) );
2170 * Determine the refresh rate of the specified drawable and display.
2172 * \param dpy Display whose refresh rate is to be determined.
2173 * \param drawable Drawable whose refresh rate is to be determined.
2174 * \param numerator Numerator of the refresh rate.
2175 * \param demoninator Denominator of the refresh rate.
2176 * \return If the refresh rate for the specified display and drawable could
2177 * be calculated, True is returned. Otherwise False is returned.
2179 * \note This function is implemented entirely client-side. A lot of other
2180 * functionality is required to export GLX_OML_sync_control, so on
2181 * XFree86 this function can be called for direct-rendering contexts
2182 * when GLX_OML_sync_control appears in the client extension string.
2185 GLboolean
__glXGetMscRateOML(__DRIdrawable
*draw
,
2186 int32_t * numerator
, int32_t * denominator
)
2188 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2189 __GLXdrawable
*glxDraw
=
2190 containerOf(draw
, __GLXdrawable
, driDrawable
);
2191 __GLXscreenConfigs
*psc
= glxDraw
->psc
;
2192 Display
*dpy
= psc
->dpy
;
2193 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2196 if ( priv
!= NULL
) {
2197 XF86VidModeModeLine mode_line
;
2202 if (XF86VidModeQueryVersion( dpy
, & i
, & i
) &&
2203 XF86VidModeGetModeLine(dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2204 unsigned n
= dot_clock
* 1000;
2205 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2207 # define V_INTERLACE 0x010
2208 # define V_DBLSCAN 0x020
2210 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2213 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2217 /* The OML_sync_control spec requires that if the refresh rate is a
2218 * whole number, that the returned numerator be equal to the refresh
2219 * rate and the denominator be 1.
2222 if ( (n
% d
) == 0 ) {
2227 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2230 /* This is a poor man's way to reduce a fraction. It's far from
2231 * perfect, but it will work well enough for this situation.
2234 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2235 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2257 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2258 int64_t target_msc
, int64_t divisor
,
2261 #ifdef __DRI_SWAP_BUFFER_COUNTER
2263 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2264 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2266 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2267 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2268 * of -1 if the function failed because of errors detected in the input
2271 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2273 if ( divisor
> 0 && remainder
>= divisor
)
2276 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2277 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
, target_msc
,
2278 divisor
, remainder
);
2291 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2292 int64_t target_msc
, int64_t divisor
,
2293 int64_t remainder
, int64_t *ust
,
2294 int64_t *msc
, int64_t *sbc
)
2296 #ifdef __DRI_MEDIA_STREAM_COUNTER
2298 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2299 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2302 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2303 * error", but the return type in the spec is Bool.
2305 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2307 if ( divisor
> 0 && remainder
>= divisor
)
2310 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2311 ret
= (*psc
->msc
->waitForMSC
)(pdraw
, target_msc
,
2312 divisor
, remainder
, msc
, sbc
);
2314 /* __glXGetUST returns zero on success and non-zero on failure.
2315 * This function returns True on success and False on failure.
2317 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2333 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2334 int64_t target_sbc
, int64_t *ust
,
2335 int64_t *msc
, int64_t *sbc
)
2337 #ifdef __DRI_SWAP_BUFFER_COUNTER
2339 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2340 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2343 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2344 * error", but the return type in the spec is Bool.
2346 if ( target_sbc
< 0 )
2349 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2350 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
, target_sbc
, msc
, sbc
);
2352 /* __glXGetUST returns zero on success and non-zero on failure.
2353 * This function returns True on success and False on failure.
2355 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2370 * GLX_MESA_allocate_memory
2374 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2375 size_t size
, float readFreq
,
2376 float writeFreq
, float priority
)
2378 #ifdef __DRI_ALLOCATE
2379 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2381 if (psc
&& psc
->allocate
)
2382 return (*psc
->allocate
->allocateMemory
)( &psc
->driScreen
, size
,
2383 readFreq
, writeFreq
,
2393 #endif /* GLX_DIRECT_RENDERING */
2399 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2401 #ifdef __DRI_ALLOCATE
2402 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2404 if (psc
&& psc
->allocate
)
2405 (*psc
->allocate
->freeMemory
)( &psc
->driScreen
, pointer
);
2411 #endif /* GLX_DIRECT_RENDERING */
2415 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2416 const void *pointer
)
2418 #ifdef __DRI_ALLOCATE
2419 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2421 if (psc
&& psc
->allocate
)
2422 return (*psc
->allocate
->memoryOffset
)( &psc
->driScreen
, pointer
);
2428 #endif /* GLX_DIRECT_RENDERING */
2436 * Mesa extension stubs. These will help reduce portability problems.
2441 * Release all buffers associated with the specified GLX drawable.
2444 * This function was intended for stand-alone Mesa. The issue there is that
2445 * the library doesn't get any notification when a window is closed. In
2446 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2447 * supported, there are 3 different functions to destroy a drawable. It
2448 * should be possible to create GLX protocol (or have it determine which
2449 * protocol to use based on the type of the drawable) to have one function
2450 * do the work of 3. For the direct-rendering case, this function could
2451 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2452 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2453 * would need to be used. This really should be done as part of the new DRI
2456 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2457 * __driGarbageCollectDrawables
2458 * glXDestroyGLXPixmap
2459 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2460 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2462 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2470 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2471 Pixmap pixmap
, Colormap cmap
)
2483 * GLX_MESA_copy_sub_buffer
2485 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2486 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2487 int x
, int y
, int width
, int height
)
2489 xGLXVendorPrivateReq
*req
;
2492 CARD32
*drawable_ptr
;
2493 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2496 #ifdef __DRI_COPY_SUB_BUFFER
2498 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2499 if ( pdraw
!= NULL
) {
2500 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2501 if (psc
->copySubBuffer
!= NULL
) {
2502 (*psc
->copySubBuffer
->copySubBuffer
)(pdraw
, x
, y
, width
, height
);
2509 opcode
= __glXSetupForCommand(dpy
);
2514 ** The calling thread may or may not have a current context. If it
2515 ** does, send the context tag so the server can do a flush.
2517 gc
= __glXGetCurrentContext();
2518 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2519 ((drawable
== gc
->currentDrawable
) ||
2520 (drawable
== gc
->currentReadable
)) ) {
2521 tag
= gc
->currentContextTag
;
2527 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2528 req
->reqType
= opcode
;
2529 req
->glxCode
= X_GLXVendorPrivate
;
2530 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2531 req
->contextTag
= tag
;
2533 drawable_ptr
= (CARD32
*) (req
+ 1);
2534 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2535 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2536 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2537 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2539 *drawable_ptr
= drawable
;
2551 * GLX_EXT_texture_from_pixmap
2554 static void __glXBindTexImageEXT(Display
*dpy
,
2555 GLXDrawable drawable
,
2557 const int *attrib_list
)
2559 xGLXVendorPrivateReq
*req
;
2560 GLXContext gc
= __glXGetCurrentContext();
2561 CARD32
*drawable_ptr
;
2563 CARD32
*num_attrib_ptr
;
2573 while (attrib_list
[i
* 2] != None
)
2577 #ifdef GLX_DIRECT_RENDERING
2582 opcode
= __glXSetupForCommand(dpy
);
2587 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2588 req
->reqType
= opcode
;
2589 req
->glxCode
= X_GLXVendorPrivate
;
2590 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2591 req
->contextTag
= gc
->currentContextTag
;
2593 drawable_ptr
= (CARD32
*) (req
+ 1);
2594 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2595 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2596 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2598 *drawable_ptr
= drawable
;
2599 *buffer_ptr
= buffer
;
2600 *num_attrib_ptr
= (CARD32
) i
;
2604 while (attrib_list
[i
* 2] != None
)
2606 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2607 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2616 static void __glXReleaseTexImageEXT(Display
*dpy
,
2617 GLXDrawable drawable
,
2620 xGLXVendorPrivateReq
*req
;
2621 GLXContext gc
= __glXGetCurrentContext();
2622 CARD32
*drawable_ptr
;
2629 #ifdef GLX_DIRECT_RENDERING
2634 opcode
= __glXSetupForCommand(dpy
);
2639 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2640 req
->reqType
= opcode
;
2641 req
->glxCode
= X_GLXVendorPrivate
;
2642 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2643 req
->contextTag
= gc
->currentContextTag
;
2645 drawable_ptr
= (CARD32
*) (req
+ 1);
2646 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2648 *drawable_ptr
= drawable
;
2649 *buffer_ptr
= buffer
;
2657 * \c strdup is actually not a standard ANSI C or POSIX routine.
2658 * Irix will not define it if ANSI mode is in effect.
2663 __glXstrdup(const char *str
)
2666 copy
= (char *) Xmalloc(strlen(str
) + 1);
2674 ** glXGetProcAddress support
2677 struct name_address_pair
{
2682 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2683 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2685 static const struct name_address_pair GLX_functions
[] = {
2686 /*** GLX_VERSION_1_0 ***/
2687 GLX_FUNCTION( glXChooseVisual
),
2688 GLX_FUNCTION( glXCopyContext
),
2689 GLX_FUNCTION( glXCreateContext
),
2690 GLX_FUNCTION( glXCreateGLXPixmap
),
2691 GLX_FUNCTION( glXDestroyContext
),
2692 GLX_FUNCTION( glXDestroyGLXPixmap
),
2693 GLX_FUNCTION( glXGetConfig
),
2694 GLX_FUNCTION( glXGetCurrentContext
),
2695 GLX_FUNCTION( glXGetCurrentDrawable
),
2696 GLX_FUNCTION( glXIsDirect
),
2697 GLX_FUNCTION( glXMakeCurrent
),
2698 GLX_FUNCTION( glXQueryExtension
),
2699 GLX_FUNCTION( glXQueryVersion
),
2700 GLX_FUNCTION( glXSwapBuffers
),
2701 GLX_FUNCTION( glXUseXFont
),
2702 GLX_FUNCTION( glXWaitGL
),
2703 GLX_FUNCTION( glXWaitX
),
2705 /*** GLX_VERSION_1_1 ***/
2706 GLX_FUNCTION( glXGetClientString
),
2707 GLX_FUNCTION( glXQueryExtensionsString
),
2708 GLX_FUNCTION( glXQueryServerString
),
2710 /*** GLX_VERSION_1_2 ***/
2711 GLX_FUNCTION( glXGetCurrentDisplay
),
2713 /*** GLX_VERSION_1_3 ***/
2714 GLX_FUNCTION( glXChooseFBConfig
),
2715 GLX_FUNCTION( glXCreateNewContext
),
2716 GLX_FUNCTION( glXCreatePbuffer
),
2717 GLX_FUNCTION( glXCreatePixmap
),
2718 GLX_FUNCTION( glXCreateWindow
),
2719 GLX_FUNCTION( glXDestroyPbuffer
),
2720 GLX_FUNCTION( glXDestroyPixmap
),
2721 GLX_FUNCTION( glXDestroyWindow
),
2722 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2723 GLX_FUNCTION( glXGetFBConfigAttrib
),
2724 GLX_FUNCTION( glXGetFBConfigs
),
2725 GLX_FUNCTION( glXGetSelectedEvent
),
2726 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2727 GLX_FUNCTION( glXMakeContextCurrent
),
2728 GLX_FUNCTION( glXQueryContext
),
2729 GLX_FUNCTION( glXQueryDrawable
),
2730 GLX_FUNCTION( glXSelectEvent
),
2732 /*** GLX_SGI_swap_control ***/
2733 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2735 /*** GLX_SGI_video_sync ***/
2736 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2737 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2739 /*** GLX_SGI_make_current_read ***/
2740 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2741 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2743 /*** GLX_EXT_import_context ***/
2744 GLX_FUNCTION( glXFreeContextEXT
),
2745 GLX_FUNCTION( glXGetContextIDEXT
),
2746 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2747 GLX_FUNCTION( glXImportContextEXT
),
2748 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2750 /*** GLX_SGIX_fbconfig ***/
2751 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2752 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2753 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2754 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2755 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2756 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2758 /*** GLX_SGIX_pbuffer ***/
2759 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2760 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2761 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2762 GLX_FUNCTION( glXSelectEventSGIX
),
2763 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2765 /*** GLX_SGIX_swap_group ***/
2766 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2768 /*** GLX_SGIX_swap_barrier ***/
2769 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2770 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2772 /*** GLX_MESA_allocate_memory ***/
2773 GLX_FUNCTION( glXAllocateMemoryMESA
),
2774 GLX_FUNCTION( glXFreeMemoryMESA
),
2775 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2777 /*** GLX_MESA_copy_sub_buffer ***/
2778 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2780 /*** GLX_MESA_pixmap_colormap ***/
2781 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2783 /*** GLX_MESA_release_buffers ***/
2784 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2786 /*** GLX_MESA_swap_control ***/
2787 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2788 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2790 /*** GLX_MESA_swap_frame_usage ***/
2791 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2792 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2793 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2794 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2796 /*** GLX_ARB_get_proc_address ***/
2797 GLX_FUNCTION( glXGetProcAddressARB
),
2800 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2802 /*** GLX_OML_sync_control ***/
2803 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2804 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2805 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2806 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2807 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2809 /*** GLX_EXT_texture_from_pixmap ***/
2810 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2811 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2813 #ifdef GLX_DIRECT_RENDERING
2814 /*** DRI configuration ***/
2815 GLX_FUNCTION( glXGetScreenDriver
),
2816 GLX_FUNCTION( glXGetDriverConfig
),
2819 { NULL
, NULL
} /* end of list */
2823 static const GLvoid
*
2824 get_glx_proc_address(const char *funcName
)
2828 /* try static functions */
2829 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2830 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2831 return GLX_functions
[i
].Address
;
2839 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2840 * \c glXGetProcAddress.
2842 * \param procName Name of a GL or GLX function.
2843 * \returns A pointer to the named function
2845 * \sa glXGetProcAddress
2847 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2849 typedef void (*gl_function
)( void );
2853 /* Search the table of GLX and internal functions first. If that
2854 * fails and the supplied name could be a valid core GL name, try
2855 * searching the core GL function table. This check is done to prevent
2856 * DRI based drivers from searching the core GL function table for
2857 * internal API functions.
2860 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2861 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2862 && (procName
[2] != 'X') ) {
2863 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2870 * Get the address of a named GL function. This is the GLX 1.4 name for
2871 * \c glXGetProcAddressARB.
2873 * \param procName Name of a GL or GLX function.
2874 * \returns A pointer to the named function
2876 * \sa glXGetProcAddressARB
2878 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2879 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2880 __attribute__ ((alias ("glXGetProcAddressARB")));
2883 return glXGetProcAddressARB(procName
);
2885 #endif /* __GNUC__ */
2888 #ifdef GLX_DIRECT_RENDERING
2890 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2891 * might be used by the DRI drivers to determine how new libGL is at runtime.
2892 * Drivers should not call this function directly. They should instead use
2893 * \c glXGetProcAddress to obtain a pointer to the function.
2895 * \returns An 8-digit decimal number representing the internal libGL API in
2898 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2900 * \since Internal API version 20021121.
2902 int __glXGetInternalVersion(void)
2905 * 20021121 - Initial version
2906 * 20021128 - Added __glXWindowExists() function
2907 * 20021207 - Added support for dynamic GLX extensions,
2908 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2909 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2910 * Never officially released. Do NOT test against
2911 * this version. Use 20030317 instead.
2912 * 20030317 - Added support GLX_SGIX_fbconfig,
2913 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2914 * GLX_{ARB,SGIS}_multisample, and
2915 * GLX_SGIX_visual_select_group.
2916 * 20030606 - Added support for GLX_SGI_make_current_read.
2917 * 20030813 - Made support for dynamic extensions multi-head aware.
2918 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2919 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2921 * 20031201 - Added support for the first round of DRI interface changes.
2922 * Do NOT test against this version! It has binary
2923 * compatibility bugs, use 20040317 instead.
2924 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2925 * 20040415 - Added support for bindContext3 and unbindContext3.
2926 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2928 * 20050727 - Gut all the old interfaces. This breaks compatability with
2929 * any DRI driver built to any previous version.
2930 * 20060314 - Added support for GLX_MESA_copy_sub_buffer.
2931 * 20070105 - Added support for damage reporting.
2938 * Get the unadjusted system time (UST). Currently, the UST is measured in
2939 * microseconds since Epoc. The actual resolution of the UST may vary from
2940 * system to system, and the units may vary from release to release.
2941 * Drivers should not call this function directly. They should instead use
2942 * \c glXGetProcAddress to obtain a pointer to the function.
2944 * \param ust Location to store the 64-bit UST
2945 * \returns Zero on success or a negative errno value on failure.
2947 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2949 * \since Internal API version 20030317.
2951 int __glXGetUST( int64_t * ust
)
2955 if ( ust
== NULL
) {
2959 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2960 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2966 #endif /* GLX_DIRECT_RENDERING */