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 XSetErrorHandler(oldXErrorHandler
);
113 * Get the __DRIdrawable for the drawable associated with a GLXContext
115 * \param dpy The display associated with \c drawable.
116 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
117 * \param scrn_num If non-NULL, the drawables screen is stored there
118 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
119 * the drawable is not associated with a direct-rendering context.
121 static __DRIdrawable
*
122 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
124 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
125 __GLXdrawable
* const pdraw
;
126 const unsigned screen_count
= ScreenCount(dpy
);
128 __GLXscreenConfigs
*sc
;
130 if (priv
== NULL
|| priv
->driDisplay
.private == NULL
)
133 for (i
= 0; i
< screen_count
; i
++) {
134 sc
= &priv
->screenConfigs
[i
];
135 if (__glxHashLookup(sc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
136 if (scrn_num
!= NULL
)
138 return &pdraw
->driDrawable
;
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
;
260 opcode
= __glXSetupForCommand(dpy
);
265 /* Allocate our context record */
266 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
271 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
273 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
279 gc
->client_state_private
= state
;
280 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
281 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
284 ** Create a temporary buffer to hold GLX rendering commands. The size
285 ** of the buffer is selected so that the maximum number of GLX rendering
286 ** commands can fit in a single X packet and still have room in the X
287 ** packet for the GLXRenderReq header.
290 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
291 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
293 Xfree(gc
->client_state_private
);
297 gc
->bufSize
= bufSize
;
299 /* Fill in the new context */
300 gc
->renderMode
= GL_RENDER
;
302 state
->storePack
.alignment
= 4;
303 state
->storeUnpack
.alignment
= 4;
305 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
308 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
309 ** Other code uses the fastImageUnpack bit, but it is never set
312 gc
->fastImageUnpack
= GL_FALSE
;
313 gc
->fillImage
= __glFillImage
;
314 gc
->isDirect
= GL_FALSE
;
316 gc
->bufEnd
= gc
->buf
+ bufSize
;
319 ** Set limit register so that there will be one command per packet
323 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
326 gc
->majorOpcode
= opcode
;
329 ** Constrain the maximum drawing command size allowed to be
330 ** transfered using the X_GLXRender protocol request. First
331 ** constrain by a software limit, then constrain by the protocl
334 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
335 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
337 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
338 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
340 gc
->maxSmallRenderCommandSize
= bufSize
;
346 * Create a new context. Exactly one of \c vis and \c fbconfig should be
349 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
350 * SGIX_fbconfig protocol be used?
351 * \param renderType For FBConfigs, what is the rendering type?
355 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
356 const __GLcontextModes
* const fbconfig
,
357 GLXContext shareList
,
358 Bool allowDirect
, GLXContextID contextID
,
359 Bool use_glx_1_3
, int renderType
)
366 gc
= AllocateGLXContext(dpy
);
370 if (None
== contextID
) {
371 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
374 #ifdef GLX_DIRECT_RENDERING
376 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
377 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
378 const __GLcontextModes
* mode
;
379 drm_context_t hwContext
;
381 /* The value of fbconfig cannot change because it is tested
382 * later in the function.
384 if ( fbconfig
== NULL
) {
385 /* FIXME: Is it possible for the __GLcontextModes structure
386 * FIXME: to not be found?
388 mode
= _gl_context_modes_find_visual( psc
->configs
,
390 assert( mode
!= NULL
);
391 assert( mode
->screen
== screen
);
397 if (psc
&& psc
->driScreen
.private) {
398 __DRIcontext
*shared
= (shareList
!= NULL
)
399 ? &shareList
->driContext
: NULL
;
402 if (!XF86DRICreateContextWithConfig(dpy
, psc
->scr
,
404 &gc
->hwContextID
, &hwContext
))
405 /* gah, handle this better */
408 gc
->driContext
.private =
409 (*psc
->driScreen
.createNewContext
)( &psc
->driScreen
,
414 if (gc
->driContext
.private) {
415 gc
->isDirect
= GL_TRUE
;
416 gc
->screen
= mode
->screen
;
418 gc
->vid
= mode
->visualID
;
419 gc
->fbconfigID
= mode
->fbconfigID
;
423 XF86DRIDestroyContext(dpy
, psc
->scr
, gc
->hwContextID
);
430 if ( fbconfig
== NULL
) {
431 xGLXCreateContextReq
*req
;
433 /* Send the glXCreateContext request */
434 GetReq(GLXCreateContext
,req
);
435 req
->reqType
= gc
->majorOpcode
;
436 req
->glxCode
= X_GLXCreateContext
;
437 req
->context
= gc
->xid
= XAllocID(dpy
);
438 req
->visual
= vis
->visualid
;
439 req
->screen
= vis
->screen
;
440 req
->shareList
= shareList
? shareList
->xid
: None
;
441 req
->isDirect
= gc
->isDirect
;
443 else if ( use_glx_1_3
) {
444 xGLXCreateNewContextReq
*req
;
446 /* Send the glXCreateNewContext request */
447 GetReq(GLXCreateNewContext
,req
);
448 req
->reqType
= gc
->majorOpcode
;
449 req
->glxCode
= X_GLXCreateNewContext
;
450 req
->context
= gc
->xid
= XAllocID(dpy
);
451 req
->fbconfig
= fbconfig
->fbconfigID
;
452 req
->screen
= fbconfig
->screen
;
453 req
->renderType
= renderType
;
454 req
->shareList
= shareList
? shareList
->xid
: None
;
455 req
->isDirect
= gc
->isDirect
;
458 xGLXVendorPrivateWithReplyReq
*vpreq
;
459 xGLXCreateContextWithConfigSGIXReq
*req
;
461 /* Send the glXCreateNewContext request */
462 GetReqExtra(GLXVendorPrivateWithReply
,
463 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
464 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
465 req
->reqType
= gc
->majorOpcode
;
466 req
->glxCode
= X_GLXVendorPrivateWithReply
;
467 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
468 req
->context
= gc
->xid
= XAllocID(dpy
);
469 req
->fbconfig
= fbconfig
->fbconfigID
;
470 req
->screen
= fbconfig
->screen
;
471 req
->renderType
= renderType
;
472 req
->shareList
= shareList
? shareList
->xid
: None
;
473 req
->isDirect
= gc
->isDirect
;
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 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 */
532 if (gc
->driContext
.private) {
533 (*gc
->driContext
.destroyContext
)(&gc
->driContext
);
534 XF86DRIDestroyContext(dpy
, gc
->psc
->scr
, gc
->hwContextID
);
535 gc
->driContext
.private = NULL
;
537 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
541 if (gc
->currentDpy
) {
542 /* Have to free later cuz it's in use now */
545 /* Destroy the handle if not current to anybody */
547 __glXFreeContext(gc
);
552 ** This dpy also created the server side part of the context.
553 ** Send the glXDestroyContext request.
556 GetReq(GLXDestroyContext
,req
);
557 req
->reqType
= opcode
;
558 req
->glxCode
= X_GLXDestroyContext
;
565 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
567 DestroyContext(dpy
, gc
);
571 ** Return the major and minor version #s for the GLX extension
573 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
575 __GLXdisplayPrivate
*priv
;
577 /* Init the extension. This fetches the major and minor version. */
578 priv
= __glXInitialize(dpy
);
579 if (!priv
) return GL_FALSE
;
581 if (major
) *major
= priv
->majorVersion
;
582 if (minor
) *minor
= priv
->minorVersion
;
587 ** Query the existance of the GLX extension
589 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
591 int major_op
, erb
, evb
;
594 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
596 if (errorBase
) *errorBase
= erb
;
597 if (eventBase
) *eventBase
= evb
;
603 ** Put a barrier in the token stream that forces the GL to finish its
604 ** work before X can proceed.
606 PUBLIC
void glXWaitGL(void)
609 GLXContext gc
= __glXGetCurrentContext();
610 Display
*dpy
= gc
->currentDpy
;
614 /* Flush any pending commands out */
615 __glXFlushRenderBuffer(gc
, gc
->pc
);
617 #ifdef GLX_DIRECT_RENDERING
619 /* This bit of ugliness unwraps the glFinish function */
628 /* Send the glXWaitGL request */
630 GetReq(GLXWaitGL
,req
);
631 req
->reqType
= gc
->majorOpcode
;
632 req
->glxCode
= X_GLXWaitGL
;
633 req
->contextTag
= gc
->currentContextTag
;
639 ** Put a barrier in the token stream that forces X to finish its
640 ** work before GL can proceed.
642 PUBLIC
void glXWaitX(void)
645 GLXContext gc
= __glXGetCurrentContext();
646 Display
*dpy
= gc
->currentDpy
;
650 /* Flush any pending commands out */
651 __glXFlushRenderBuffer(gc
, gc
->pc
);
653 #ifdef GLX_DIRECT_RENDERING
661 ** Send the glXWaitX request.
664 GetReq(GLXWaitX
,req
);
665 req
->reqType
= gc
->majorOpcode
;
666 req
->glxCode
= X_GLXWaitX
;
667 req
->contextTag
= gc
->currentContextTag
;
672 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
674 xGLXUseXFontReq
*req
;
675 GLXContext gc
= __glXGetCurrentContext();
676 Display
*dpy
= gc
->currentDpy
;
680 /* Flush any pending commands out */
681 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
683 #ifdef GLX_DIRECT_RENDERING
685 DRI_glXUseXFont(font
, first
, count
, listBase
);
690 /* Send the glXUseFont request */
692 GetReq(GLXUseXFont
,req
);
693 req
->reqType
= gc
->majorOpcode
;
694 req
->glxCode
= X_GLXUseXFont
;
695 req
->contextTag
= gc
->currentContextTag
;
699 req
->listBase
= listBase
;
704 /************************************************************************/
707 ** Copy the source context to the destination context using the
710 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
711 GLXContext dest
, unsigned long mask
)
713 xGLXCopyContextReq
*req
;
714 GLXContext gc
= __glXGetCurrentContext();
718 opcode
= __glXSetupForCommand(dpy
);
723 #ifdef GLX_DIRECT_RENDERING
725 /* NOT_DONE: This does not work yet */
730 ** If the source is the current context, send its tag so that the context
731 ** can be flushed before the copy.
733 if (source
== gc
&& dpy
== gc
->currentDpy
) {
734 tag
= gc
->currentContextTag
;
739 /* Send the glXCopyContext request */
741 GetReq(GLXCopyContext
,req
);
742 req
->reqType
= opcode
;
743 req
->glxCode
= X_GLXCopyContext
;
744 req
->source
= source
? source
->xid
: None
;
745 req
->dest
= dest
? dest
->xid
: None
;
747 req
->contextTag
= tag
;
754 * Determine if a context uses direct rendering.
756 * \param dpy Display where the context was created.
757 * \param contextID ID of the context to be tested.
759 * \returns \c GL_TRUE if the context is direct rendering or not.
761 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
763 xGLXIsDirectReq
*req
;
764 xGLXIsDirectReply reply
;
767 opcode
= __glXSetupForCommand(dpy
);
772 /* Send the glXIsDirect request */
774 GetReq(GLXIsDirect
,req
);
775 req
->reqType
= opcode
;
776 req
->glxCode
= X_GLXIsDirect
;
777 req
->context
= contextID
;
778 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
782 return reply
.isDirect
;
787 * Shouldn't this function \b always return \c GL_FALSE when
788 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
789 * the GLX protocol here at all?
791 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
795 #ifdef GLX_DIRECT_RENDERING
796 } else if (gc
->isDirect
) {
800 return __glXIsDirect(dpy
, gc
->xid
);
803 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
806 xGLXCreateGLXPixmapReq
*req
;
810 opcode
= __glXSetupForCommand(dpy
);
815 /* Send the glXCreateGLXPixmap request */
817 GetReq(GLXCreateGLXPixmap
,req
);
818 req
->reqType
= opcode
;
819 req
->glxCode
= X_GLXCreateGLXPixmap
;
820 req
->screen
= vis
->screen
;
821 req
->visual
= vis
->visualid
;
822 req
->pixmap
= pixmap
;
823 req
->glxpixmap
= xid
= XAllocID(dpy
);
830 ** Destroy the named pixmap
832 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
834 xGLXDestroyGLXPixmapReq
*req
;
837 opcode
= __glXSetupForCommand(dpy
);
842 /* Send the glXDestroyGLXPixmap request */
844 GetReq(GLXDestroyGLXPixmap
,req
);
845 req
->reqType
= opcode
;
846 req
->glxCode
= X_GLXDestroyGLXPixmap
;
847 req
->glxpixmap
= glxpixmap
;
852 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
854 xGLXSwapBuffersReq
*req
;
858 #ifdef GLX_DIRECT_RENDERING
859 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
861 if ( pdraw
!= NULL
) {
862 (*pdraw
->swapBuffers
)(pdraw
);
867 opcode
= __glXSetupForCommand(dpy
);
873 ** The calling thread may or may not have a current context. If it
874 ** does, send the context tag so the server can do a flush.
876 gc
= __glXGetCurrentContext();
877 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
878 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
879 tag
= gc
->currentContextTag
;
884 /* Send the glXSwapBuffers request */
886 GetReq(GLXSwapBuffers
,req
);
887 req
->reqType
= opcode
;
888 req
->glxCode
= X_GLXSwapBuffers
;
889 req
->drawable
= drawable
;
890 req
->contextTag
= tag
;
898 ** Return configuration information for the given display, screen and
899 ** visual combination.
901 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
904 __GLXdisplayPrivate
*priv
;
905 __GLXscreenConfigs
*psc
;
908 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
909 if ( status
== Success
) {
910 const __GLcontextModes
* const modes
= _gl_context_modes_find_visual(
911 psc
->configs
, vis
->visualid
);
913 /* Lookup attribute after first finding a match on the visual */
914 if ( modes
!= NULL
) {
915 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
918 status
= GLX_BAD_VISUAL
;
922 ** If we can't find the config for this visual, this visual is not
923 ** supported by the OpenGL implementation on the server.
925 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
926 *value_return
= GL_FALSE
;
933 /************************************************************************/
936 init_fbconfig_for_chooser( __GLcontextModes
* config
,
937 GLboolean fbconfig_style_tags
)
939 memset( config
, 0, sizeof( __GLcontextModes
) );
940 config
->visualID
= (XID
) GLX_DONT_CARE
;
941 config
->visualType
= GLX_DONT_CARE
;
943 /* glXChooseFBConfig specifies different defaults for these two than
946 if ( fbconfig_style_tags
) {
947 config
->rgbMode
= GL_TRUE
;
948 config
->doubleBufferMode
= GLX_DONT_CARE
;
951 config
->visualRating
= GLX_DONT_CARE
;
952 config
->transparentPixel
= GLX_NONE
;
953 config
->transparentRed
= GLX_DONT_CARE
;
954 config
->transparentGreen
= GLX_DONT_CARE
;
955 config
->transparentBlue
= GLX_DONT_CARE
;
956 config
->transparentAlpha
= GLX_DONT_CARE
;
957 config
->transparentIndex
= GLX_DONT_CARE
;
959 config
->drawableType
= GLX_WINDOW_BIT
;
960 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
961 config
->xRenderable
= GLX_DONT_CARE
;
962 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
964 config
->swapMethod
= GLX_DONT_CARE
;
967 #define MATCH_DONT_CARE( param ) \
969 if ( (a-> param != GLX_DONT_CARE) \
970 && (a-> param != b-> param) ) { \
975 #define MATCH_MINIMUM( param ) \
977 if ( (a-> param != GLX_DONT_CARE) \
978 && (a-> param > b-> param) ) { \
983 #define MATCH_EXACT( param ) \
985 if ( a-> param != b-> param) { \
991 * Determine if two GLXFBConfigs are compatible.
993 * \param a Application specified config to test.
994 * \param b Server specified config to test against \c a.
997 fbconfigs_compatible( const __GLcontextModes
* const a
,
998 const __GLcontextModes
* const b
)
1000 MATCH_DONT_CARE( doubleBufferMode
);
1001 MATCH_DONT_CARE( visualType
);
1002 MATCH_DONT_CARE( visualRating
);
1003 MATCH_DONT_CARE( xRenderable
);
1004 MATCH_DONT_CARE( fbconfigID
);
1005 MATCH_DONT_CARE( swapMethod
);
1007 MATCH_MINIMUM( rgbBits
);
1008 MATCH_MINIMUM( numAuxBuffers
);
1009 MATCH_MINIMUM( redBits
);
1010 MATCH_MINIMUM( greenBits
);
1011 MATCH_MINIMUM( blueBits
);
1012 MATCH_MINIMUM( alphaBits
);
1013 MATCH_MINIMUM( depthBits
);
1014 MATCH_MINIMUM( stencilBits
);
1015 MATCH_MINIMUM( accumRedBits
);
1016 MATCH_MINIMUM( accumGreenBits
);
1017 MATCH_MINIMUM( accumBlueBits
);
1018 MATCH_MINIMUM( accumAlphaBits
);
1019 MATCH_MINIMUM( sampleBuffers
);
1020 MATCH_MINIMUM( maxPbufferWidth
);
1021 MATCH_MINIMUM( maxPbufferHeight
);
1022 MATCH_MINIMUM( maxPbufferPixels
);
1023 MATCH_MINIMUM( samples
);
1025 MATCH_DONT_CARE( stereoMode
);
1026 MATCH_EXACT( level
);
1028 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1029 || ((a
->renderType
& b
->renderType
) == 0) ) {
1034 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1035 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1036 * Technically speaking, it is a bug in the DDX driver, but there is
1037 * enough of an installed base to work around the problem here. In any
1038 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1039 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1040 * 0 from the server to be a match to maintain backward compatibility with
1041 * the (broken) drivers.
1044 if ( a
->transparentPixel
!= GLX_DONT_CARE
1045 && a
->transparentPixel
!= 0 ) {
1046 if ( a
->transparentPixel
== GLX_NONE
) {
1047 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1050 MATCH_EXACT( transparentPixel
);
1053 switch ( a
->transparentPixel
) {
1054 case GLX_TRANSPARENT_RGB
:
1055 MATCH_DONT_CARE( transparentRed
);
1056 MATCH_DONT_CARE( transparentGreen
);
1057 MATCH_DONT_CARE( transparentBlue
);
1058 MATCH_DONT_CARE( transparentAlpha
);
1061 case GLX_TRANSPARENT_INDEX
:
1062 MATCH_DONT_CARE( transparentIndex
);
1074 /* There's some trickly language in the GLX spec about how this is supposed
1075 * to work. Basically, if a given component size is either not specified
1076 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1077 * Well, that's really hard to do with the code as-is. This behavior is
1078 * closer to correct, but still not technically right.
1080 #define PREFER_LARGER_OR_ZERO(comp) \
1082 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1083 if ( ((*a)-> comp) == 0 ) { \
1086 else if ( ((*b)-> comp) == 0 ) { \
1090 return ((*b)-> comp) - ((*a)-> comp) ; \
1095 #define PREFER_LARGER(comp) \
1097 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1098 return ((*b)-> comp) - ((*a)-> comp) ; \
1102 #define PREFER_SMALLER(comp) \
1104 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1105 return ((*a)-> comp) - ((*b)-> comp) ; \
1110 * Compare two GLXFBConfigs. This function is intended to be used as the
1111 * compare function passed in to qsort.
1113 * \returns If \c a is a "better" config, according to the specification of
1114 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1115 * better, then a number greater than zero is return. If both are
1116 * equal, zero is returned.
1117 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1120 fbconfig_compare( const __GLcontextModes
* const * const a
,
1121 const __GLcontextModes
* const * const b
)
1123 /* The order of these comparisons must NOT change. It is defined by
1124 * the GLX 1.3 spec and ARB_multisample.
1127 PREFER_SMALLER( visualSelectGroup
);
1129 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1130 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1131 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1133 PREFER_SMALLER( visualRating
);
1135 /* This isn't quite right. It is supposed to compare the sum of the
1136 * components the user specifically set minimums for.
1138 PREFER_LARGER_OR_ZERO( redBits
);
1139 PREFER_LARGER_OR_ZERO( greenBits
);
1140 PREFER_LARGER_OR_ZERO( blueBits
);
1141 PREFER_LARGER_OR_ZERO( alphaBits
);
1143 PREFER_SMALLER( rgbBits
);
1145 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1146 /* Prefer single-buffer.
1148 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1151 PREFER_SMALLER( numAuxBuffers
);
1153 PREFER_LARGER_OR_ZERO( depthBits
);
1154 PREFER_SMALLER( stencilBits
);
1156 /* This isn't quite right. It is supposed to compare the sum of the
1157 * components the user specifically set minimums for.
1159 PREFER_LARGER_OR_ZERO( accumRedBits
);
1160 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1161 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1162 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1164 PREFER_SMALLER( visualType
);
1166 /* None of the multisample specs say where this comparison should happen,
1167 * so I put it near the end.
1169 PREFER_SMALLER( sampleBuffers
);
1170 PREFER_SMALLER( samples
);
1172 /* None of the pbuffer or fbconfig specs say that this comparison needs
1173 * to happen at all, but it seems like it should.
1175 PREFER_LARGER( maxPbufferWidth
);
1176 PREFER_LARGER( maxPbufferHeight
);
1177 PREFER_LARGER( maxPbufferPixels
);
1184 * Selects and sorts a subset of the supplied configs based on the attributes.
1185 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1186 * and \c glXChooseFBConfigSGIX.
1188 * \param configs Array of pointers to possible configs. The elements of
1189 * this array that do not meet the criteria will be set to
1190 * NULL. The remaining elements will be sorted according to
1191 * the various visual / FBConfig selection rules.
1192 * \param num_configs Number of elements in the \c configs array.
1193 * \param attribList Attributes used select from \c configs. This array is
1194 * terminated by a \c None tag. The array can either take
1195 * the form expected by \c glXChooseVisual (where boolean
1196 * tags do not have a value) or by \c glXChooseFBConfig
1197 * (where every tag has a value).
1198 * \param fbconfig_style_tags Selects whether \c attribList is in
1199 * \c glXChooseVisual style or
1200 * \c glXChooseFBConfig style.
1201 * \returns The number of valid elements left in \c configs.
1203 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1206 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1207 const int *attribList
, GLboolean fbconfig_style_tags
)
1209 __GLcontextModes test_config
;
1213 /* This is a fairly direct implementation of the selection method
1214 * described by GLX_SGIX_fbconfig. Start by culling out all the
1215 * configs that are not compatible with the selected parameter
1219 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1220 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1221 (const INT32
*) attribList
,
1222 GL_TRUE
, fbconfig_style_tags
);
1225 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1226 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1227 configs
[ base
] = configs
[ i
];
1236 if ( base
< num_configs
) {
1237 (void) memset( & configs
[ base
], 0,
1238 sizeof( void * ) * (num_configs
- base
) );
1241 /* After the incompatible configs are removed, the resulting
1242 * list is sorted according to the rules set out in the various
1246 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1247 (int (*)(const void*, const void*)) fbconfig_compare
);
1255 ** Return the visual that best matches the template. Return None if no
1256 ** visual matches the template.
1258 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1260 XVisualInfo
*visualList
= NULL
;
1261 __GLXdisplayPrivate
*priv
;
1262 __GLXscreenConfigs
*psc
;
1263 __GLcontextModes test_config
;
1264 __GLcontextModes
*modes
;
1265 const __GLcontextModes
*best_config
= NULL
;
1268 ** Get a list of all visuals, return if list is empty
1270 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1276 ** Build a template from the defaults and the attribute list
1277 ** Free visual list and return if an unexpected token is encountered
1279 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1280 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1281 (const INT32
*) attribList
,
1282 GL_TRUE
, GL_FALSE
);
1285 ** Eliminate visuals that don't meet minimum requirements
1286 ** Compute a score for those that do
1287 ** Remember which visual, if any, got the highest score
1289 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
1290 if ( fbconfigs_compatible( & test_config
, modes
)
1291 && ((best_config
== NULL
)
1292 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1293 best_config
= modes
;
1298 ** If no visual is acceptable, return None
1299 ** Otherwise, create an XVisualInfo list with just the selected X visual
1302 if (best_config
!= NULL
) {
1303 XVisualInfo visualTemplate
;
1306 visualTemplate
.screen
= screen
;
1307 visualTemplate
.visualid
= best_config
->visualID
;
1308 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1309 &visualTemplate
, &i
);
1316 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1318 __GLXscreenConfigs
*psc
;
1319 __GLXdisplayPrivate
*priv
;
1321 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1325 if (!psc
->effectiveGLXexts
) {
1326 if (!psc
->serverGLXexts
) {
1327 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1328 X_GLXQueryServerString
,
1329 screen
, GLX_EXTENSIONS
);
1332 __glXCalculateUsableExtensions(psc
,
1333 #ifdef GLX_DIRECT_RENDERING
1334 (psc
->driScreen
.private != NULL
),
1338 priv
->minorVersion
);
1341 return psc
->effectiveGLXexts
;
1344 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1348 return (__glXGLXClientVendorName
);
1350 return (__glXGLXClientVersion
);
1351 case GLX_EXTENSIONS
:
1352 return (__glXGetClientExtensions());
1358 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1360 __GLXscreenConfigs
*psc
;
1361 __GLXdisplayPrivate
*priv
;
1365 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1371 str
= & priv
->serverGLXvendor
;
1374 str
= & priv
->serverGLXversion
;
1376 case GLX_EXTENSIONS
:
1377 str
= & psc
->serverGLXexts
;
1383 if ( *str
== NULL
) {
1384 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1385 X_GLXQueryServerString
, screen
, name
);
1391 void __glXClientInfo ( Display
*dpy
, int opcode
)
1393 xGLXClientInfoReq
*req
;
1395 char * ext_str
= __glXGetClientGLExtensionString();
1397 /* Send the glXClientInfo request */
1399 GetReq(GLXClientInfo
,req
);
1400 req
->reqType
= opcode
;
1401 req
->glxCode
= X_GLXClientInfo
;
1402 req
->major
= GLX_MAJOR_VERSION
;
1403 req
->minor
= GLX_MINOR_VERSION
;
1405 size
= strlen( ext_str
) + 1;
1406 req
->length
+= (size
+ 3) >> 2;
1407 req
->numbytes
= size
;
1408 Data(dpy
, ext_str
, size
);
1418 ** EXT_import_context
1421 PUBLIC Display
*glXGetCurrentDisplay(void)
1423 GLXContext gc
= __glXGetCurrentContext();
1424 if (NULL
== gc
) return NULL
;
1425 return gc
->currentDpy
;
1428 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1429 glXGetCurrentDisplay
)
1432 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1435 * \param dpy Display where \c ctx was created.
1436 * \param ctx Context to query.
1437 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1438 * or zero if the request failed due to internal problems (i.e.,
1439 * unable to allocate temporary memory, etc.)
1442 * This function dynamically determines whether to use the EXT_import_context
1443 * version of the protocol or the GLX 1.3 version of the protocol.
1445 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1447 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1448 xGLXQueryContextReply reply
;
1454 return GLX_BAD_CONTEXT
;
1456 opcode
= __glXSetupForCommand(dpy
);
1461 /* Send the glXQueryContextInfoEXT request */
1464 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1465 xGLXQueryContextReq
*req
;
1467 GetReq(GLXQueryContext
, req
);
1469 req
->reqType
= opcode
;
1470 req
->glxCode
= X_GLXQueryContext
;
1471 req
->context
= (unsigned int)(ctx
->xid
);
1474 xGLXVendorPrivateReq
*vpreq
;
1475 xGLXQueryContextInfoEXTReq
*req
;
1477 GetReqExtra( GLXVendorPrivate
,
1478 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1480 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1481 req
->reqType
= opcode
;
1482 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1483 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1484 req
->context
= (unsigned int)(ctx
->xid
);
1487 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1489 numValues
= reply
.n
;
1492 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1496 int *propList
, *pProp
;
1500 nPropListBytes
= numValues
<< 3;
1501 propList
= (int *) Xmalloc(nPropListBytes
);
1502 if (NULL
== propList
) {
1505 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1507 for (i
=0; i
< numValues
; i
++) {
1509 case GLX_SHARE_CONTEXT_EXT
:
1510 ctx
->share_xid
= *pProp
++;
1512 case GLX_VISUAL_ID_EXT
:
1513 ctx
->vid
= *pProp
++;
1516 ctx
->screen
= *pProp
++;
1518 case GLX_FBCONFIG_ID
:
1519 ctx
->fbconfigID
= *pProp
++;
1521 case GLX_RENDER_TYPE
:
1522 ctx
->renderType
= *pProp
++;
1529 Xfree((char *)propList
);
1539 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1543 /* get the information from the server if we don't have it already */
1544 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1545 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1546 if (Success
!= retVal
) return retVal
;
1548 switch (attribute
) {
1549 case GLX_SHARE_CONTEXT_EXT
:
1550 *value
= (int)(ctx
->share_xid
);
1552 case GLX_VISUAL_ID_EXT
:
1553 *value
= (int)(ctx
->vid
);
1556 *value
= (int)(ctx
->screen
);
1558 case GLX_FBCONFIG_ID
:
1559 *value
= (int)(ctx
->fbconfigID
);
1561 case GLX_RENDER_TYPE
:
1562 *value
= (int)(ctx
->renderType
);
1565 return GLX_BAD_ATTRIBUTE
;
1570 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1571 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1572 (dpy
, ctx
, attribute
, value
),
1575 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1580 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1584 if (contextID
== None
) {
1587 if (__glXIsDirect(dpy
, contextID
)) {
1591 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1593 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1600 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1602 DestroyContext(dpy
, ctx
);
1608 * GLX 1.3 functions - these are just stubs for now!
1611 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1612 const int *attribList
, int *nitems
)
1614 __GLcontextModes
** config_list
;
1618 config_list
= (__GLcontextModes
**)
1619 glXGetFBConfigs( dpy
, screen
, & list_size
);
1621 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1622 list_size
= choose_visual( config_list
, list_size
, attribList
,
1624 if ( list_size
== 0 ) {
1625 XFree( config_list
);
1630 *nitems
= list_size
;
1631 return (GLXFBConfig
*) config_list
;
1635 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1636 int renderType
, GLXContext shareList
,
1639 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1640 allowDirect
, None
, True
, renderType
);
1644 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1646 GLXContext gc
= __glXGetCurrentContext();
1647 return gc
->currentReadable
;
1651 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1653 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1654 __GLcontextModes
** config
= NULL
;
1657 if ( (priv
->screenConfigs
!= NULL
)
1658 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1659 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1660 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1661 unsigned num_configs
= 0;
1662 __GLcontextModes
* modes
;
1665 for ( modes
= priv
->screenConfigs
[screen
].configs
1667 ; modes
= modes
->next
) {
1668 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1673 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1675 if ( config
!= NULL
) {
1676 *nelements
= num_configs
;
1678 for ( modes
= priv
->screenConfigs
[screen
].configs
1680 ; modes
= modes
->next
) {
1681 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1688 return (GLXFBConfig
*) config
;
1692 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1693 int attribute
, int *value
)
1695 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1697 return (modes
!= NULL
)
1698 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1703 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1705 XVisualInfo visualTemplate
;
1706 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1710 ** Get a list of all visuals, return if list is empty
1712 visualTemplate
.visualid
= fbconfig
->visualID
;
1713 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1718 ** GLX_SGI_swap_control
1720 static int __glXSwapIntervalSGI(int interval
)
1722 xGLXVendorPrivateReq
*req
;
1723 GLXContext gc
= __glXGetCurrentContext();
1725 CARD32
* interval_ptr
;
1729 return GLX_BAD_CONTEXT
;
1732 if ( interval
<= 0 ) {
1733 return GLX_BAD_VALUE
;
1736 #ifdef __DRI_SWAP_CONTROL
1737 if ( gc
->isDirect
) {
1738 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1740 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1741 gc
->currentDrawable
,
1743 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1744 psc
->swapControl
->setSwapInterval(pdraw
, interval
);
1748 return GLX_BAD_CONTEXT
;
1752 dpy
= gc
->currentDpy
;
1753 opcode
= __glXSetupForCommand(dpy
);
1758 /* Send the glXSwapIntervalSGI request */
1760 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1761 req
->reqType
= opcode
;
1762 req
->glxCode
= X_GLXVendorPrivate
;
1763 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1764 req
->contextTag
= gc
->currentContextTag
;
1766 interval_ptr
= (CARD32
*) (req
+ 1);
1767 *interval_ptr
= interval
;
1778 ** GLX_MESA_swap_control
1780 static int __glXSwapIntervalMESA(unsigned int interval
)
1782 #ifdef __DRI_SWAP_CONTROL
1783 GLXContext gc
= __glXGetCurrentContext();
1785 if ( interval
< 0 ) {
1786 return GLX_BAD_VALUE
;
1789 if ( (gc
!= NULL
) && gc
->isDirect
) {
1790 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1793 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
) ) {
1794 __DRIdrawable
* const pdraw
=
1795 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1796 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1797 psc
->swapControl
->setSwapInterval(pdraw
, interval
);
1806 return GLX_BAD_CONTEXT
;
1810 static int __glXGetSwapIntervalMESA(void)
1812 #ifdef __DRI_SWAP_CONTROL
1813 GLXContext gc
= __glXGetCurrentContext();
1815 if ( (gc
!= NULL
) && gc
->isDirect
) {
1816 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1819 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
) ) {
1820 __DRIdrawable
* const pdraw
=
1821 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1822 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1823 return psc
->swapControl
->getSwapInterval(pdraw
);
1834 ** GLX_MESA_swap_frame_usage
1837 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1839 int status
= GLX_BAD_CONTEXT
;
1840 #ifdef __DRI_FRAME_TRACKING
1842 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1843 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1845 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1846 status
= psc
->frameTracking
->frameTracking(pdraw
, GL_TRUE
);
1855 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1857 int status
= GLX_BAD_CONTEXT
;
1858 #ifdef __DRI_FRAME_TRACKING
1860 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1861 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1863 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1864 status
= psc
->frameTracking
->frameTracking(pdraw
, GL_FALSE
);
1873 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1876 int status
= GLX_BAD_CONTEXT
;
1877 #ifdef __DRI_FRAME_TRACKING
1879 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1880 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1882 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1883 int64_t sbc
, missedFrames
;
1884 float lastMissedUsage
;
1886 status
= psc
->frameTracking
->queryFrameTracking(pdraw
, &sbc
,
1900 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1901 int64_t *sbc
, int64_t *missedFrames
,
1902 GLfloat
*lastMissedUsage
)
1904 int status
= GLX_BAD_CONTEXT
;
1905 #ifdef __DRI_FRAME_TRACKING
1907 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1908 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1910 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1913 status
= psc
->frameTracking
->queryFrameTracking(pdraw
, sbc
, missedFrames
,
1914 lastMissedUsage
, &usage
);
1920 (void) missedFrames
;
1921 (void) lastMissedUsage
;
1928 ** GLX_SGI_video_sync
1930 static int __glXGetVideoSyncSGI(unsigned int *count
)
1932 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1933 * FIXME: there should be a GLX encoding for this call. I can find no
1934 * FIXME: documentation for the GLX encoding.
1936 #ifdef __DRI_MEDIA_STREAM_COUNTER
1937 GLXContext gc
= __glXGetCurrentContext();
1940 if ( (gc
!= NULL
) && gc
->isDirect
) {
1941 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1943 if (psc
->msc
!= NULL
&& psc
->driScreen
.private != NULL
) {
1947 ret
= psc
->msc
->getMSC(&psc
->driScreen
, &temp
);
1948 *count
= (unsigned) temp
;
1949 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1955 return GLX_BAD_CONTEXT
;
1958 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1960 #ifdef __DRI_MEDIA_STREAM_COUNTER
1961 GLXContext gc
= __glXGetCurrentContext();
1963 if ( divisor
<= 0 || remainder
< 0 )
1964 return GLX_BAD_VALUE
;
1966 if ( (gc
!= NULL
) && gc
->isDirect
) {
1967 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1969 if (psc
->msc
!= NULL
&& psc
->driScreen
.private ) {
1970 __DRIdrawable
* const pdraw
=
1971 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1972 if (pdraw
!= NULL
) {
1977 ret
= (*psc
->msc
->waitForMSC
)(pdraw
, 0,
1978 divisor
, remainder
, &msc
, &sbc
);
1979 *count
= (unsigned) msc
;
1980 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1987 return GLX_BAD_CONTEXT
;
1992 ** GLX_SGIX_fbconfig
1993 ** Many of these functions are aliased to GLX 1.3 entry points in the
1994 ** GLX_functions table.
1997 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1998 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1999 (dpy
, config
, attribute
, value
),
2000 glXGetFBConfigAttrib
)
2002 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2003 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2004 (dpy
, screen
, attrib_list
, nelements
),
2007 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2008 (Display
* dpy
, GLXFBConfigSGIX config
),
2010 glXGetVisualFromFBConfig
)
2012 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2013 GLXFBConfigSGIX config
, Pixmap pixmap
)
2015 xGLXVendorPrivateWithReplyReq
*vpreq
;
2016 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2017 GLXPixmap xid
= None
;
2019 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2020 __GLXscreenConfigs
* psc
;
2023 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2027 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2029 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2030 opcode
= __glXSetupForCommand(dpy
);
2035 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2037 GetReqExtra(GLXVendorPrivateWithReply
,
2038 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2039 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2040 req
->reqType
= opcode
;
2041 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2042 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2043 req
->screen
= fbconfig
->screen
;
2044 req
->fbconfig
= fbconfig
->fbconfigID
;
2045 req
->pixmap
= pixmap
;
2046 req
->glxpixmap
= xid
= XAllocID(dpy
);
2054 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2055 GLXFBConfigSGIX config
, int renderType
,
2056 GLXContext shareList
, Bool allowDirect
)
2058 GLXContext gc
= NULL
;
2059 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2060 __GLXscreenConfigs
* psc
;
2063 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2067 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2069 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2070 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2071 allowDirect
, None
, False
, renderType
);
2078 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2081 __GLXdisplayPrivate
*priv
;
2082 __GLXscreenConfigs
*psc
;
2084 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2085 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2086 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2087 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2096 ** GLX_SGIX_swap_group
2098 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2108 ** GLX_SGIX_swap_barrier
2110 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2118 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2128 ** GLX_OML_sync_control
2130 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2131 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2133 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2134 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2136 if ( priv
!= NULL
) {
2138 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2139 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2141 assert( (pdraw
== NULL
) || (i
!= -1) );
2142 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2143 && ((*psc
->msc
->getMSC
)(&psc
->driScreen
, msc
) == 0)
2144 && ((*psc
->sbc
->getSBC
)(pdraw
, sbc
) == 0)
2145 && (__glXGetUST(ust
) == 0) );
2159 * Determine the refresh rate of the specified drawable and display.
2161 * \param dpy Display whose refresh rate is to be determined.
2162 * \param drawable Drawable whose refresh rate is to be determined.
2163 * \param numerator Numerator of the refresh rate.
2164 * \param demoninator Denominator of the refresh rate.
2165 * \return If the refresh rate for the specified display and drawable could
2166 * be calculated, True is returned. Otherwise False is returned.
2168 * \note This function is implemented entirely client-side. A lot of other
2169 * functionality is required to export GLX_OML_sync_control, so on
2170 * XFree86 this function can be called for direct-rendering contexts
2171 * when GLX_OML_sync_control appears in the client extension string.
2174 GLboolean
__glXGetMscRateOML(__DRIdrawable
*draw
,
2175 int32_t * numerator
, int32_t * denominator
)
2177 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2178 __GLXdrawable
*glxDraw
=
2179 containerOf(draw
, __GLXdrawable
, driDrawable
);
2180 __GLXscreenConfigs
*psc
= glxDraw
->psc
;
2181 Display
*dpy
= psc
->dpy
;
2182 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2185 if ( priv
!= NULL
) {
2186 XF86VidModeModeLine mode_line
;
2191 if (XF86VidModeQueryVersion( dpy
, & i
, & i
) &&
2192 XF86VidModeGetModeLine(dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2193 unsigned n
= dot_clock
* 1000;
2194 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2196 # define V_INTERLACE 0x010
2197 # define V_DBLSCAN 0x020
2199 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2202 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2206 /* The OML_sync_control spec requires that if the refresh rate is a
2207 * whole number, that the returned numerator be equal to the refresh
2208 * rate and the denominator be 1.
2211 if ( (n
% d
) == 0 ) {
2216 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2219 /* This is a poor man's way to reduce a fraction. It's far from
2220 * perfect, but it will work well enough for this situation.
2223 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2224 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2246 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2247 int64_t target_msc
, int64_t divisor
,
2250 #ifdef __DRI_SWAP_BUFFER_COUNTER
2252 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2253 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2255 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2256 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2257 * of -1 if the function failed because of errors detected in the input
2260 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2262 if ( divisor
> 0 && remainder
>= divisor
)
2265 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2266 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
, target_msc
,
2267 divisor
, remainder
);
2280 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2281 int64_t target_msc
, int64_t divisor
,
2282 int64_t remainder
, int64_t *ust
,
2283 int64_t *msc
, int64_t *sbc
)
2285 #ifdef __DRI_MEDIA_STREAM_COUNTER
2287 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2288 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2291 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2292 * error", but the return type in the spec is Bool.
2294 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2296 if ( divisor
> 0 && remainder
>= divisor
)
2299 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2300 ret
= (*psc
->msc
->waitForMSC
)(pdraw
, target_msc
,
2301 divisor
, remainder
, msc
, sbc
);
2303 /* __glXGetUST returns zero on success and non-zero on failure.
2304 * This function returns True on success and False on failure.
2306 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2322 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2323 int64_t target_sbc
, int64_t *ust
,
2324 int64_t *msc
, int64_t *sbc
)
2326 #ifdef __DRI_SWAP_BUFFER_COUNTER
2328 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2329 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2332 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2333 * error", but the return type in the spec is Bool.
2335 if ( target_sbc
< 0 )
2338 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2339 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
, target_sbc
, msc
, sbc
);
2341 /* __glXGetUST returns zero on success and non-zero on failure.
2342 * This function returns True on success and False on failure.
2344 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2359 * GLX_MESA_allocate_memory
2363 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2364 size_t size
, float readFreq
,
2365 float writeFreq
, float priority
)
2367 #ifdef __DRI_ALLOCATE
2368 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2370 if (psc
&& psc
->allocate
)
2371 return (*psc
->allocate
->allocateMemory
)( &psc
->driScreen
, size
,
2372 readFreq
, writeFreq
,
2382 #endif /* GLX_DIRECT_RENDERING */
2388 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2390 #ifdef __DRI_ALLOCATE
2391 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2393 if (psc
&& psc
->allocate
)
2394 (*psc
->allocate
->freeMemory
)( &psc
->driScreen
, pointer
);
2400 #endif /* GLX_DIRECT_RENDERING */
2404 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2405 const void *pointer
)
2407 #ifdef __DRI_ALLOCATE
2408 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2410 if (psc
&& psc
->allocate
)
2411 return (*psc
->allocate
->memoryOffset
)( &psc
->driScreen
, pointer
);
2417 #endif /* GLX_DIRECT_RENDERING */
2425 * Mesa extension stubs. These will help reduce portability problems.
2430 * Release all buffers associated with the specified GLX drawable.
2433 * This function was intended for stand-alone Mesa. The issue there is that
2434 * the library doesn't get any notification when a window is closed. In
2435 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2436 * supported, there are 3 different functions to destroy a drawable. It
2437 * should be possible to create GLX protocol (or have it determine which
2438 * protocol to use based on the type of the drawable) to have one function
2439 * do the work of 3. For the direct-rendering case, this function could
2440 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2441 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2442 * would need to be used. This really should be done as part of the new DRI
2445 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2446 * __driGarbageCollectDrawables
2447 * glXDestroyGLXPixmap
2448 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2449 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2451 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2459 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2460 Pixmap pixmap
, Colormap cmap
)
2472 * GLX_MESA_copy_sub_buffer
2474 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2475 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2476 int x
, int y
, int width
, int height
)
2478 xGLXVendorPrivateReq
*req
;
2481 CARD32
*drawable_ptr
;
2482 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2485 #ifdef __DRI_COPY_SUB_BUFFER
2487 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2488 if ( pdraw
!= NULL
) {
2489 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2490 if (psc
->copySubBuffer
!= NULL
) {
2491 (*psc
->copySubBuffer
->copySubBuffer
)(pdraw
, x
, y
, width
, height
);
2498 opcode
= __glXSetupForCommand(dpy
);
2503 ** The calling thread may or may not have a current context. If it
2504 ** does, send the context tag so the server can do a flush.
2506 gc
= __glXGetCurrentContext();
2507 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2508 ((drawable
== gc
->currentDrawable
) ||
2509 (drawable
== gc
->currentReadable
)) ) {
2510 tag
= gc
->currentContextTag
;
2516 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2517 req
->reqType
= opcode
;
2518 req
->glxCode
= X_GLXVendorPrivate
;
2519 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2520 req
->contextTag
= tag
;
2522 drawable_ptr
= (CARD32
*) (req
+ 1);
2523 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2524 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2525 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2526 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2528 *drawable_ptr
= drawable
;
2540 * GLX_EXT_texture_from_pixmap
2543 static void __glXBindTexImageEXT(Display
*dpy
,
2544 GLXDrawable drawable
,
2546 const int *attrib_list
)
2548 xGLXVendorPrivateReq
*req
;
2549 GLXContext gc
= __glXGetCurrentContext();
2550 CARD32
*drawable_ptr
;
2552 CARD32
*num_attrib_ptr
;
2562 while (attrib_list
[i
* 2] != None
)
2566 #ifdef GLX_DIRECT_RENDERING
2571 opcode
= __glXSetupForCommand(dpy
);
2576 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2577 req
->reqType
= opcode
;
2578 req
->glxCode
= X_GLXVendorPrivate
;
2579 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2580 req
->contextTag
= gc
->currentContextTag
;
2582 drawable_ptr
= (CARD32
*) (req
+ 1);
2583 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2584 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2585 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2587 *drawable_ptr
= drawable
;
2588 *buffer_ptr
= buffer
;
2589 *num_attrib_ptr
= (CARD32
) i
;
2593 while (attrib_list
[i
* 2] != None
)
2595 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2596 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2605 static void __glXReleaseTexImageEXT(Display
*dpy
,
2606 GLXDrawable drawable
,
2609 xGLXVendorPrivateReq
*req
;
2610 GLXContext gc
= __glXGetCurrentContext();
2611 CARD32
*drawable_ptr
;
2618 #ifdef GLX_DIRECT_RENDERING
2623 opcode
= __glXSetupForCommand(dpy
);
2628 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2629 req
->reqType
= opcode
;
2630 req
->glxCode
= X_GLXVendorPrivate
;
2631 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2632 req
->contextTag
= gc
->currentContextTag
;
2634 drawable_ptr
= (CARD32
*) (req
+ 1);
2635 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2637 *drawable_ptr
= drawable
;
2638 *buffer_ptr
= buffer
;
2646 * \c strdup is actually not a standard ANSI C or POSIX routine.
2647 * Irix will not define it if ANSI mode is in effect.
2652 __glXstrdup(const char *str
)
2655 copy
= (char *) Xmalloc(strlen(str
) + 1);
2663 ** glXGetProcAddress support
2666 struct name_address_pair
{
2671 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2672 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2674 static const struct name_address_pair GLX_functions
[] = {
2675 /*** GLX_VERSION_1_0 ***/
2676 GLX_FUNCTION( glXChooseVisual
),
2677 GLX_FUNCTION( glXCopyContext
),
2678 GLX_FUNCTION( glXCreateContext
),
2679 GLX_FUNCTION( glXCreateGLXPixmap
),
2680 GLX_FUNCTION( glXDestroyContext
),
2681 GLX_FUNCTION( glXDestroyGLXPixmap
),
2682 GLX_FUNCTION( glXGetConfig
),
2683 GLX_FUNCTION( glXGetCurrentContext
),
2684 GLX_FUNCTION( glXGetCurrentDrawable
),
2685 GLX_FUNCTION( glXIsDirect
),
2686 GLX_FUNCTION( glXMakeCurrent
),
2687 GLX_FUNCTION( glXQueryExtension
),
2688 GLX_FUNCTION( glXQueryVersion
),
2689 GLX_FUNCTION( glXSwapBuffers
),
2690 GLX_FUNCTION( glXUseXFont
),
2691 GLX_FUNCTION( glXWaitGL
),
2692 GLX_FUNCTION( glXWaitX
),
2694 /*** GLX_VERSION_1_1 ***/
2695 GLX_FUNCTION( glXGetClientString
),
2696 GLX_FUNCTION( glXQueryExtensionsString
),
2697 GLX_FUNCTION( glXQueryServerString
),
2699 /*** GLX_VERSION_1_2 ***/
2700 GLX_FUNCTION( glXGetCurrentDisplay
),
2702 /*** GLX_VERSION_1_3 ***/
2703 GLX_FUNCTION( glXChooseFBConfig
),
2704 GLX_FUNCTION( glXCreateNewContext
),
2705 GLX_FUNCTION( glXCreatePbuffer
),
2706 GLX_FUNCTION( glXCreatePixmap
),
2707 GLX_FUNCTION( glXCreateWindow
),
2708 GLX_FUNCTION( glXDestroyPbuffer
),
2709 GLX_FUNCTION( glXDestroyPixmap
),
2710 GLX_FUNCTION( glXDestroyWindow
),
2711 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2712 GLX_FUNCTION( glXGetFBConfigAttrib
),
2713 GLX_FUNCTION( glXGetFBConfigs
),
2714 GLX_FUNCTION( glXGetSelectedEvent
),
2715 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2716 GLX_FUNCTION( glXMakeContextCurrent
),
2717 GLX_FUNCTION( glXQueryContext
),
2718 GLX_FUNCTION( glXQueryDrawable
),
2719 GLX_FUNCTION( glXSelectEvent
),
2721 /*** GLX_SGI_swap_control ***/
2722 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2724 /*** GLX_SGI_video_sync ***/
2725 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2726 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2728 /*** GLX_SGI_make_current_read ***/
2729 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2730 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2732 /*** GLX_EXT_import_context ***/
2733 GLX_FUNCTION( glXFreeContextEXT
),
2734 GLX_FUNCTION( glXGetContextIDEXT
),
2735 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2736 GLX_FUNCTION( glXImportContextEXT
),
2737 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2739 /*** GLX_SGIX_fbconfig ***/
2740 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2741 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2742 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2743 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2744 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2745 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2747 /*** GLX_SGIX_pbuffer ***/
2748 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2749 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2750 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2751 GLX_FUNCTION( glXSelectEventSGIX
),
2752 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2754 /*** GLX_SGIX_swap_group ***/
2755 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2757 /*** GLX_SGIX_swap_barrier ***/
2758 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2759 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2761 /*** GLX_MESA_allocate_memory ***/
2762 GLX_FUNCTION( glXAllocateMemoryMESA
),
2763 GLX_FUNCTION( glXFreeMemoryMESA
),
2764 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2766 /*** GLX_MESA_copy_sub_buffer ***/
2767 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2769 /*** GLX_MESA_pixmap_colormap ***/
2770 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2772 /*** GLX_MESA_release_buffers ***/
2773 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2775 /*** GLX_MESA_swap_control ***/
2776 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2777 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2779 /*** GLX_MESA_swap_frame_usage ***/
2780 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2781 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2782 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2783 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2785 /*** GLX_ARB_get_proc_address ***/
2786 GLX_FUNCTION( glXGetProcAddressARB
),
2789 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2791 /*** GLX_OML_sync_control ***/
2792 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2793 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2794 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2795 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2796 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2798 /*** GLX_EXT_texture_from_pixmap ***/
2799 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2800 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2802 #ifdef GLX_DIRECT_RENDERING
2803 /*** DRI configuration ***/
2804 GLX_FUNCTION( glXGetScreenDriver
),
2805 GLX_FUNCTION( glXGetDriverConfig
),
2808 { NULL
, NULL
} /* end of list */
2812 static const GLvoid
*
2813 get_glx_proc_address(const char *funcName
)
2817 /* try static functions */
2818 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2819 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2820 return GLX_functions
[i
].Address
;
2828 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2829 * \c glXGetProcAddress.
2831 * \param procName Name of a GL or GLX function.
2832 * \returns A pointer to the named function
2834 * \sa glXGetProcAddress
2836 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2838 typedef void (*gl_function
)( void );
2842 /* Search the table of GLX and internal functions first. If that
2843 * fails and the supplied name could be a valid core GL name, try
2844 * searching the core GL function table. This check is done to prevent
2845 * DRI based drivers from searching the core GL function table for
2846 * internal API functions.
2849 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2850 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2851 && (procName
[2] != 'X') ) {
2852 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2859 * Get the address of a named GL function. This is the GLX 1.4 name for
2860 * \c glXGetProcAddressARB.
2862 * \param procName Name of a GL or GLX function.
2863 * \returns A pointer to the named function
2865 * \sa glXGetProcAddressARB
2867 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2868 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2869 __attribute__ ((alias ("glXGetProcAddressARB")));
2872 return glXGetProcAddressARB(procName
);
2874 #endif /* __GNUC__ */
2877 #ifdef GLX_DIRECT_RENDERING
2879 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2880 * might be used by the DRI drivers to determine how new libGL is at runtime.
2881 * Drivers should not call this function directly. They should instead use
2882 * \c glXGetProcAddress to obtain a pointer to the function.
2884 * \returns An 8-digit decimal number representing the internal libGL API in
2887 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2889 * \since Internal API version 20021121.
2891 int __glXGetInternalVersion(void)
2894 * 20021121 - Initial version
2895 * 20021128 - Added __glXWindowExists() function
2896 * 20021207 - Added support for dynamic GLX extensions,
2897 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2898 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2899 * Never officially released. Do NOT test against
2900 * this version. Use 20030317 instead.
2901 * 20030317 - Added support GLX_SGIX_fbconfig,
2902 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2903 * GLX_{ARB,SGIS}_multisample, and
2904 * GLX_SGIX_visual_select_group.
2905 * 20030606 - Added support for GLX_SGI_make_current_read.
2906 * 20030813 - Made support for dynamic extensions multi-head aware.
2907 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2908 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2910 * 20031201 - Added support for the first round of DRI interface changes.
2911 * Do NOT test against this version! It has binary
2912 * compatibility bugs, use 20040317 instead.
2913 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2914 * 20040415 - Added support for bindContext3 and unbindContext3.
2915 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2917 * 20050727 - Gut all the old interfaces. This breaks compatability with
2918 * any DRI driver built to any previous version.
2919 * 20060314 - Added support for GLX_MESA_copy_sub_buffer.
2920 * 20070105 - Added support for damage reporting.
2927 * Get the unadjusted system time (UST). Currently, the UST is measured in
2928 * microseconds since Epoc. The actual resolution of the UST may vary from
2929 * system to system, and the units may vary from release to release.
2930 * Drivers should not call this function directly. They should instead use
2931 * \c glXGetProcAddress to obtain a pointer to the function.
2933 * \param ust Location to store the 64-bit UST
2934 * \returns Zero on success or a negative errno value on failure.
2936 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2938 * \since Internal API version 20030317.
2940 int __glXGetUST( int64_t * ust
)
2944 if ( ust
== NULL
) {
2948 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2949 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2955 #endif /* GLX_DIRECT_RENDERING */