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.
42 #include "glxclient.h"
44 #include "glxextensions.h"
45 #include "glcontextmodes.h"
48 #ifdef GLX_DIRECT_RENDERING
50 #include <X11/extensions/xf86vmode.h>
54 static const char __glXGLXClientVendorName
[] = "SGI";
55 static const char __glXGLXClientVersion
[] = "1.4";
58 /****************************************************************************/
60 #ifdef GLX_DIRECT_RENDERING
62 static Bool windowExistsFlag
;
63 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
65 if (xerr
->error_code
== BadWindow
) {
66 windowExistsFlag
= GL_FALSE
;
72 * Find drawables in the local hash that have been destroyed on the
75 * \param dpy Display to destroy drawables for
76 * \param screen Screen number to destroy drawables for
78 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
81 __GLXDRIdrawable
*pdraw
;
82 XWindowAttributes xwa
;
83 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
85 /* Set no-op error handler so Xlib doesn't bail out if the windows
86 * has alreay been destroyed on the server. */
88 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
90 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
92 windowExistsFlag
= GL_TRUE
;
93 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
94 if (!windowExistsFlag
) {
95 /* Destroy the local drawable data, if the drawable no
96 longer exists in the Xserver */
97 (*pdraw
->destroyDrawable
)(pdraw
);
98 __glxHashDelete(sc
->drawHash
, draw
);
100 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
103 XSync(dpy
, GL_FALSE
);
104 XSetErrorHandler(oldXErrorHandler
);
107 extern __GLXDRIdrawable
*
108 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
);
111 * Get the __DRIdrawable for the drawable associated with a GLXContext
113 * \param dpy The display associated with \c drawable.
114 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
115 * \param scrn_num If non-NULL, the drawables screen is stored there
116 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
117 * the drawable is not associated with a direct-rendering context.
119 _X_HIDDEN __GLXDRIdrawable
*
120 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
122 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
123 __GLXDRIdrawable
*pdraw
;
124 const unsigned screen_count
= ScreenCount(dpy
);
126 __GLXscreenConfigs
*psc
;
131 for (i
= 0; i
< screen_count
; i
++) {
132 psc
= &priv
->screenConfigs
[i
];
133 if (psc
->drawHash
== NULL
)
136 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
137 if (scrn_num
!= NULL
)
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
;
316 gc
->bufEnd
= gc
->buf
+ bufSize
;
317 gc
->isDirect
= GL_FALSE
;
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
)
363 #ifdef GLX_DIRECT_RENDERING
364 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
365 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
371 gc
= AllocateGLXContext(dpy
);
375 if (None
== contextID
) {
376 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
379 #ifdef GLX_DIRECT_RENDERING
380 if (allowDirect
&& psc
->driScreen
) {
381 const __GLcontextModes
* mode
;
383 if (fbconfig
== NULL
) {
384 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
388 error
.errorCode
= BadValue
;
389 error
.resourceID
= vis
->visualid
;
390 error
.sequenceNumber
= dpy
->request
;
391 error
.type
= X_Error
;
392 error
.majorCode
= gc
->majorOpcode
;
393 error
.minorCode
= X_GLXCreateContext
;
394 _XError(dpy
, &error
);
402 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
405 if (gc
->driContext
!= NULL
) {
406 gc
->screen
= mode
->screen
;
409 gc
->isDirect
= GL_TRUE
;
415 if ( fbconfig
== NULL
) {
416 xGLXCreateContextReq
*req
;
418 /* Send the glXCreateContext request */
419 GetReq(GLXCreateContext
,req
);
420 req
->reqType
= gc
->majorOpcode
;
421 req
->glxCode
= X_GLXCreateContext
;
422 req
->context
= gc
->xid
= XAllocID(dpy
);
423 req
->visual
= vis
->visualid
;
424 req
->screen
= vis
->screen
;
425 req
->shareList
= shareList
? shareList
->xid
: None
;
426 #ifdef GLX_DIRECT_RENDERING
427 req
->isDirect
= gc
->driContext
!= NULL
;
432 else if ( use_glx_1_3
) {
433 xGLXCreateNewContextReq
*req
;
435 /* Send the glXCreateNewContext request */
436 GetReq(GLXCreateNewContext
,req
);
437 req
->reqType
= gc
->majorOpcode
;
438 req
->glxCode
= X_GLXCreateNewContext
;
439 req
->context
= gc
->xid
= XAllocID(dpy
);
440 req
->fbconfig
= fbconfig
->fbconfigID
;
441 req
->screen
= fbconfig
->screen
;
442 req
->renderType
= renderType
;
443 req
->shareList
= shareList
? shareList
->xid
: None
;
444 #ifdef GLX_DIRECT_RENDERING
445 req
->isDirect
= gc
->driContext
!= NULL
;
451 xGLXVendorPrivateWithReplyReq
*vpreq
;
452 xGLXCreateContextWithConfigSGIXReq
*req
;
454 /* Send the glXCreateNewContext request */
455 GetReqExtra(GLXVendorPrivateWithReply
,
456 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
457 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
458 req
->reqType
= gc
->majorOpcode
;
459 req
->glxCode
= X_GLXVendorPrivateWithReply
;
460 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
461 req
->context
= gc
->xid
= XAllocID(dpy
);
462 req
->fbconfig
= fbconfig
->fbconfigID
;
463 req
->screen
= fbconfig
->screen
;
464 req
->renderType
= renderType
;
465 req
->shareList
= shareList
? shareList
->xid
: None
;
466 #ifdef GLX_DIRECT_RENDERING
467 req
->isDirect
= gc
->driContext
!= NULL
;
475 gc
->imported
= GL_FALSE
;
479 gc
->imported
= GL_TRUE
;
485 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
486 GLXContext shareList
, Bool allowDirect
)
488 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
492 _X_HIDDEN
void __glXFreeContext(__GLXcontext
*gc
)
494 if (gc
->vendor
) XFree((char *) gc
->vendor
);
495 if (gc
->renderer
) XFree((char *) gc
->renderer
);
496 if (gc
->version
) XFree((char *) gc
->version
);
497 if (gc
->extensions
) XFree((char *) gc
->extensions
);
498 __glFreeAttributeState(gc
);
499 XFree((char *) gc
->buf
);
500 Xfree((char *) gc
->client_state_private
);
506 ** Destroy the named context
509 DestroyContext(Display
*dpy
, GLXContext gc
)
511 xGLXDestroyContextReq
*req
;
516 opcode
= __glXSetupForCommand(dpy
);
517 if (!opcode
|| !gc
) {
523 imported
= gc
->imported
;
526 #ifdef GLX_DIRECT_RENDERING
527 /* Destroy the direct rendering context */
528 if (gc
->driContext
) {
529 (*gc
->driContext
->destroyContext
)(gc
->driContext
, gc
->psc
, dpy
);
530 gc
->driContext
= NULL
;
531 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
535 __glXFreeVertexArrayState(gc
);
537 if (gc
->currentDpy
) {
538 /* Have to free later cuz it's in use now */
541 /* Destroy the handle if not current to anybody */
543 __glXFreeContext(gc
);
548 ** This dpy also created the server side part of the context.
549 ** Send the glXDestroyContext request.
552 GetReq(GLXDestroyContext
,req
);
553 req
->reqType
= opcode
;
554 req
->glxCode
= X_GLXDestroyContext
;
561 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
563 DestroyContext(dpy
, gc
);
567 ** Return the major and minor version #s for the GLX extension
569 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
571 __GLXdisplayPrivate
*priv
;
573 /* Init the extension. This fetches the major and minor version. */
574 priv
= __glXInitialize(dpy
);
575 if (!priv
) return GL_FALSE
;
577 if (major
) *major
= priv
->majorVersion
;
578 if (minor
) *minor
= priv
->minorVersion
;
583 ** Query the existance of the GLX extension
585 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
587 int major_op
, erb
, evb
;
590 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
592 if (errorBase
) *errorBase
= erb
;
593 if (eventBase
) *eventBase
= evb
;
599 ** Put a barrier in the token stream that forces the GL to finish its
600 ** work before X can proceed.
602 PUBLIC
void glXWaitGL(void)
605 GLXContext gc
= __glXGetCurrentContext();
606 Display
*dpy
= gc
->currentDpy
;
610 /* Flush any pending commands out */
611 __glXFlushRenderBuffer(gc
, gc
->pc
);
613 #ifdef GLX_DIRECT_RENDERING
614 if (gc
->driContext
) {
615 /* This bit of ugliness unwraps the glFinish function */
624 /* Send the glXWaitGL request */
626 GetReq(GLXWaitGL
,req
);
627 req
->reqType
= gc
->majorOpcode
;
628 req
->glxCode
= X_GLXWaitGL
;
629 req
->contextTag
= gc
->currentContextTag
;
635 ** Put a barrier in the token stream that forces X to finish its
636 ** work before GL can proceed.
638 PUBLIC
void glXWaitX(void)
641 GLXContext gc
= __glXGetCurrentContext();
642 Display
*dpy
= gc
->currentDpy
;
646 /* Flush any pending commands out */
647 __glXFlushRenderBuffer(gc
, gc
->pc
);
649 #ifdef GLX_DIRECT_RENDERING
650 if (gc
->driContext
) {
657 ** Send the glXWaitX request.
660 GetReq(GLXWaitX
,req
);
661 req
->reqType
= gc
->majorOpcode
;
662 req
->glxCode
= X_GLXWaitX
;
663 req
->contextTag
= gc
->currentContextTag
;
668 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
670 xGLXUseXFontReq
*req
;
671 GLXContext gc
= __glXGetCurrentContext();
672 Display
*dpy
= gc
->currentDpy
;
676 /* Flush any pending commands out */
677 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
679 #ifdef GLX_DIRECT_RENDERING
680 if (gc
->driContext
) {
681 DRI_glXUseXFont(font
, first
, count
, listBase
);
686 /* Send the glXUseFont request */
688 GetReq(GLXUseXFont
,req
);
689 req
->reqType
= gc
->majorOpcode
;
690 req
->glxCode
= X_GLXUseXFont
;
691 req
->contextTag
= gc
->currentContextTag
;
695 req
->listBase
= listBase
;
700 /************************************************************************/
703 ** Copy the source context to the destination context using the
706 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
707 GLXContext dest
, unsigned long mask
)
709 xGLXCopyContextReq
*req
;
710 GLXContext gc
= __glXGetCurrentContext();
714 opcode
= __glXSetupForCommand(dpy
);
719 #ifdef GLX_DIRECT_RENDERING
720 if (gc
->driContext
) {
721 /* NOT_DONE: This does not work yet */
726 ** If the source is the current context, send its tag so that the context
727 ** can be flushed before the copy.
729 if (source
== gc
&& dpy
== gc
->currentDpy
) {
730 tag
= gc
->currentContextTag
;
735 /* Send the glXCopyContext request */
737 GetReq(GLXCopyContext
,req
);
738 req
->reqType
= opcode
;
739 req
->glxCode
= X_GLXCopyContext
;
740 req
->source
= source
? source
->xid
: None
;
741 req
->dest
= dest
? dest
->xid
: None
;
743 req
->contextTag
= tag
;
750 * Determine if a context uses direct rendering.
752 * \param dpy Display where the context was created.
753 * \param contextID ID of the context to be tested.
755 * \returns \c GL_TRUE if the context is direct rendering or not.
757 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
759 xGLXIsDirectReq
*req
;
760 xGLXIsDirectReply reply
;
763 opcode
= __glXSetupForCommand(dpy
);
768 /* Send the glXIsDirect request */
770 GetReq(GLXIsDirect
,req
);
771 req
->reqType
= opcode
;
772 req
->glxCode
= X_GLXIsDirect
;
773 req
->context
= contextID
;
774 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
778 return reply
.isDirect
;
783 * Shouldn't this function \b always return \c GL_FALSE when
784 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
785 * the GLX protocol here at all?
787 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
791 #ifdef GLX_DIRECT_RENDERING
792 } else if (gc
->driContext
) {
796 return __glXIsDirect(dpy
, gc
->xid
);
799 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
802 xGLXCreateGLXPixmapReq
*req
;
806 opcode
= __glXSetupForCommand(dpy
);
811 /* Send the glXCreateGLXPixmap request */
813 GetReq(GLXCreateGLXPixmap
,req
);
814 req
->reqType
= opcode
;
815 req
->glxCode
= X_GLXCreateGLXPixmap
;
816 req
->screen
= vis
->screen
;
817 req
->visual
= vis
->visualid
;
818 req
->pixmap
= pixmap
;
819 req
->glxpixmap
= xid
= XAllocID(dpy
);
826 ** Destroy the named pixmap
828 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
830 xGLXDestroyGLXPixmapReq
*req
;
833 opcode
= __glXSetupForCommand(dpy
);
838 /* Send the glXDestroyGLXPixmap request */
840 GetReq(GLXDestroyGLXPixmap
,req
);
841 req
->reqType
= opcode
;
842 req
->glxCode
= X_GLXDestroyGLXPixmap
;
843 req
->glxpixmap
= glxpixmap
;
848 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
850 xGLXSwapBuffersReq
*req
;
854 #ifdef GLX_DIRECT_RENDERING
855 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
858 (*pdraw
->psc
->core
->swapBuffers
)(pdraw
->driDrawable
);
863 opcode
= __glXSetupForCommand(dpy
);
869 ** The calling thread may or may not have a current context. If it
870 ** does, send the context tag so the server can do a flush.
872 gc
= __glXGetCurrentContext();
873 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
874 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
875 tag
= gc
->currentContextTag
;
880 /* Send the glXSwapBuffers request */
882 GetReq(GLXSwapBuffers
,req
);
883 req
->reqType
= opcode
;
884 req
->glxCode
= X_GLXSwapBuffers
;
885 req
->drawable
= drawable
;
886 req
->contextTag
= tag
;
894 ** Return configuration information for the given display, screen and
895 ** visual combination.
897 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
900 __GLXdisplayPrivate
*priv
;
901 __GLXscreenConfigs
*psc
;
902 __GLcontextModes
*modes
;
905 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
906 if ( status
== Success
) {
907 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
909 /* Lookup attribute after first finding a match on the visual */
910 if ( modes
!= NULL
) {
911 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
914 status
= GLX_BAD_VISUAL
;
918 ** If we can't find the config for this visual, this visual is not
919 ** supported by the OpenGL implementation on the server.
921 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
922 *value_return
= GL_FALSE
;
929 /************************************************************************/
932 init_fbconfig_for_chooser( __GLcontextModes
* config
,
933 GLboolean fbconfig_style_tags
)
935 memset( config
, 0, sizeof( __GLcontextModes
) );
936 config
->visualID
= (XID
) GLX_DONT_CARE
;
937 config
->visualType
= GLX_DONT_CARE
;
939 /* glXChooseFBConfig specifies different defaults for these two than
942 if ( fbconfig_style_tags
) {
943 config
->rgbMode
= GL_TRUE
;
944 config
->doubleBufferMode
= GLX_DONT_CARE
;
947 config
->visualRating
= GLX_DONT_CARE
;
948 config
->transparentPixel
= GLX_NONE
;
949 config
->transparentRed
= GLX_DONT_CARE
;
950 config
->transparentGreen
= GLX_DONT_CARE
;
951 config
->transparentBlue
= GLX_DONT_CARE
;
952 config
->transparentAlpha
= GLX_DONT_CARE
;
953 config
->transparentIndex
= GLX_DONT_CARE
;
955 config
->drawableType
= GLX_WINDOW_BIT
;
956 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
957 config
->xRenderable
= GLX_DONT_CARE
;
958 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
960 config
->swapMethod
= GLX_DONT_CARE
;
963 #define MATCH_DONT_CARE( param ) \
965 if ( (a-> param != GLX_DONT_CARE) \
966 && (a-> param != b-> param) ) { \
971 #define MATCH_MINIMUM( param ) \
973 if ( (a-> param != GLX_DONT_CARE) \
974 && (a-> param > b-> param) ) { \
979 #define MATCH_EXACT( param ) \
981 if ( a-> param != b-> param) { \
987 * Determine if two GLXFBConfigs are compatible.
989 * \param a Application specified config to test.
990 * \param b Server specified config to test against \c a.
993 fbconfigs_compatible( const __GLcontextModes
* const a
,
994 const __GLcontextModes
* const b
)
996 MATCH_DONT_CARE( doubleBufferMode
);
997 MATCH_DONT_CARE( visualType
);
998 MATCH_DONT_CARE( visualRating
);
999 MATCH_DONT_CARE( xRenderable
);
1000 MATCH_DONT_CARE( fbconfigID
);
1001 MATCH_DONT_CARE( swapMethod
);
1003 MATCH_MINIMUM( rgbBits
);
1004 MATCH_MINIMUM( numAuxBuffers
);
1005 MATCH_MINIMUM( redBits
);
1006 MATCH_MINIMUM( greenBits
);
1007 MATCH_MINIMUM( blueBits
);
1008 MATCH_MINIMUM( alphaBits
);
1009 MATCH_MINIMUM( depthBits
);
1010 MATCH_MINIMUM( stencilBits
);
1011 MATCH_MINIMUM( accumRedBits
);
1012 MATCH_MINIMUM( accumGreenBits
);
1013 MATCH_MINIMUM( accumBlueBits
);
1014 MATCH_MINIMUM( accumAlphaBits
);
1015 MATCH_MINIMUM( sampleBuffers
);
1016 MATCH_MINIMUM( maxPbufferWidth
);
1017 MATCH_MINIMUM( maxPbufferHeight
);
1018 MATCH_MINIMUM( maxPbufferPixels
);
1019 MATCH_MINIMUM( samples
);
1021 MATCH_DONT_CARE( stereoMode
);
1022 MATCH_EXACT( level
);
1024 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1025 || ((a
->renderType
& b
->renderType
) == 0) ) {
1030 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1031 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1032 * Technically speaking, it is a bug in the DDX driver, but there is
1033 * enough of an installed base to work around the problem here. In any
1034 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1035 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1036 * 0 from the server to be a match to maintain backward compatibility with
1037 * the (broken) drivers.
1040 if ( a
->transparentPixel
!= GLX_DONT_CARE
1041 && a
->transparentPixel
!= 0 ) {
1042 if ( a
->transparentPixel
== GLX_NONE
) {
1043 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1046 MATCH_EXACT( transparentPixel
);
1049 switch ( a
->transparentPixel
) {
1050 case GLX_TRANSPARENT_RGB
:
1051 MATCH_DONT_CARE( transparentRed
);
1052 MATCH_DONT_CARE( transparentGreen
);
1053 MATCH_DONT_CARE( transparentBlue
);
1054 MATCH_DONT_CARE( transparentAlpha
);
1057 case GLX_TRANSPARENT_INDEX
:
1058 MATCH_DONT_CARE( transparentIndex
);
1070 /* There's some trickly language in the GLX spec about how this is supposed
1071 * to work. Basically, if a given component size is either not specified
1072 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1073 * Well, that's really hard to do with the code as-is. This behavior is
1074 * closer to correct, but still not technically right.
1076 #define PREFER_LARGER_OR_ZERO(comp) \
1078 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1079 if ( ((*a)-> comp) == 0 ) { \
1082 else if ( ((*b)-> comp) == 0 ) { \
1086 return ((*b)-> comp) - ((*a)-> comp) ; \
1091 #define PREFER_LARGER(comp) \
1093 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1094 return ((*b)-> comp) - ((*a)-> comp) ; \
1098 #define PREFER_SMALLER(comp) \
1100 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1101 return ((*a)-> comp) - ((*b)-> comp) ; \
1106 * Compare two GLXFBConfigs. This function is intended to be used as the
1107 * compare function passed in to qsort.
1109 * \returns If \c a is a "better" config, according to the specification of
1110 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1111 * better, then a number greater than zero is return. If both are
1112 * equal, zero is returned.
1113 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1116 fbconfig_compare( const __GLcontextModes
* const * const a
,
1117 const __GLcontextModes
* const * const b
)
1119 /* The order of these comparisons must NOT change. It is defined by
1120 * the GLX 1.3 spec and ARB_multisample.
1123 PREFER_SMALLER( visualSelectGroup
);
1125 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1126 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1127 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1129 PREFER_SMALLER( visualRating
);
1131 /* This isn't quite right. It is supposed to compare the sum of the
1132 * components the user specifically set minimums for.
1134 PREFER_LARGER_OR_ZERO( redBits
);
1135 PREFER_LARGER_OR_ZERO( greenBits
);
1136 PREFER_LARGER_OR_ZERO( blueBits
);
1137 PREFER_LARGER_OR_ZERO( alphaBits
);
1139 PREFER_SMALLER( rgbBits
);
1141 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1142 /* Prefer single-buffer.
1144 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1147 PREFER_SMALLER( numAuxBuffers
);
1149 PREFER_LARGER_OR_ZERO( depthBits
);
1150 PREFER_SMALLER( stencilBits
);
1152 /* This isn't quite right. It is supposed to compare the sum of the
1153 * components the user specifically set minimums for.
1155 PREFER_LARGER_OR_ZERO( accumRedBits
);
1156 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1157 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1158 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1160 PREFER_SMALLER( visualType
);
1162 /* None of the multisample specs say where this comparison should happen,
1163 * so I put it near the end.
1165 PREFER_SMALLER( sampleBuffers
);
1166 PREFER_SMALLER( samples
);
1168 /* None of the pbuffer or fbconfig specs say that this comparison needs
1169 * to happen at all, but it seems like it should.
1171 PREFER_LARGER( maxPbufferWidth
);
1172 PREFER_LARGER( maxPbufferHeight
);
1173 PREFER_LARGER( maxPbufferPixels
);
1180 * Selects and sorts a subset of the supplied configs based on the attributes.
1181 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1182 * and \c glXChooseFBConfigSGIX.
1184 * \param configs Array of pointers to possible configs. The elements of
1185 * this array that do not meet the criteria will be set to
1186 * NULL. The remaining elements will be sorted according to
1187 * the various visual / FBConfig selection rules.
1188 * \param num_configs Number of elements in the \c configs array.
1189 * \param attribList Attributes used select from \c configs. This array is
1190 * terminated by a \c None tag. The array can either take
1191 * the form expected by \c glXChooseVisual (where boolean
1192 * tags do not have a value) or by \c glXChooseFBConfig
1193 * (where every tag has a value).
1194 * \param fbconfig_style_tags Selects whether \c attribList is in
1195 * \c glXChooseVisual style or
1196 * \c glXChooseFBConfig style.
1197 * \returns The number of valid elements left in \c configs.
1199 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1202 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1203 const int *attribList
, GLboolean fbconfig_style_tags
)
1205 __GLcontextModes test_config
;
1209 /* This is a fairly direct implementation of the selection method
1210 * described by GLX_SGIX_fbconfig. Start by culling out all the
1211 * configs that are not compatible with the selected parameter
1215 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1216 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1217 (const INT32
*) attribList
,
1218 GL_TRUE
, fbconfig_style_tags
);
1221 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1222 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1223 configs
[ base
] = configs
[ i
];
1232 if ( base
< num_configs
) {
1233 (void) memset( & configs
[ base
], 0,
1234 sizeof( void * ) * (num_configs
- base
) );
1237 /* After the incompatible configs are removed, the resulting
1238 * list is sorted according to the rules set out in the various
1242 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1243 (int (*)(const void*, const void*)) fbconfig_compare
);
1251 ** Return the visual that best matches the template. Return None if no
1252 ** visual matches the template.
1254 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1256 XVisualInfo
*visualList
= NULL
;
1257 __GLXdisplayPrivate
*priv
;
1258 __GLXscreenConfigs
*psc
;
1259 __GLcontextModes test_config
;
1260 __GLcontextModes
*modes
;
1261 const __GLcontextModes
*best_config
= NULL
;
1264 ** Get a list of all visuals, return if list is empty
1266 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1272 ** Build a template from the defaults and the attribute list
1273 ** Free visual list and return if an unexpected token is encountered
1275 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1276 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1277 (const INT32
*) attribList
,
1278 GL_TRUE
, GL_FALSE
);
1281 ** Eliminate visuals that don't meet minimum requirements
1282 ** Compute a score for those that do
1283 ** Remember which visual, if any, got the highest score
1285 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1286 if ( fbconfigs_compatible( & test_config
, modes
)
1287 && ((best_config
== NULL
)
1288 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1289 best_config
= modes
;
1294 ** If no visual is acceptable, return None
1295 ** Otherwise, create an XVisualInfo list with just the selected X visual
1298 if (best_config
!= NULL
) {
1299 XVisualInfo visualTemplate
;
1302 visualTemplate
.screen
= screen
;
1303 visualTemplate
.visualid
= best_config
->visualID
;
1304 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1305 &visualTemplate
, &i
);
1312 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1314 __GLXscreenConfigs
*psc
;
1315 __GLXdisplayPrivate
*priv
;
1317 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1321 if (!psc
->effectiveGLXexts
) {
1322 if (!psc
->serverGLXexts
) {
1323 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1324 X_GLXQueryServerString
,
1325 screen
, GLX_EXTENSIONS
);
1328 __glXCalculateUsableExtensions(psc
,
1329 #ifdef GLX_DIRECT_RENDERING
1330 (psc
->driScreen
!= NULL
),
1334 priv
->minorVersion
);
1337 return psc
->effectiveGLXexts
;
1340 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1344 return (__glXGLXClientVendorName
);
1346 return (__glXGLXClientVersion
);
1347 case GLX_EXTENSIONS
:
1348 return (__glXGetClientExtensions());
1354 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1356 __GLXscreenConfigs
*psc
;
1357 __GLXdisplayPrivate
*priv
;
1361 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1367 str
= & priv
->serverGLXvendor
;
1370 str
= & priv
->serverGLXversion
;
1372 case GLX_EXTENSIONS
:
1373 str
= & psc
->serverGLXexts
;
1379 if ( *str
== NULL
) {
1380 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1381 X_GLXQueryServerString
, screen
, name
);
1387 void __glXClientInfo ( Display
*dpy
, int opcode
)
1389 xGLXClientInfoReq
*req
;
1391 char * ext_str
= __glXGetClientGLExtensionString();
1393 /* Send the glXClientInfo request */
1395 GetReq(GLXClientInfo
,req
);
1396 req
->reqType
= opcode
;
1397 req
->glxCode
= X_GLXClientInfo
;
1398 req
->major
= GLX_MAJOR_VERSION
;
1399 req
->minor
= GLX_MINOR_VERSION
;
1401 size
= strlen( ext_str
) + 1;
1402 req
->length
+= (size
+ 3) >> 2;
1403 req
->numbytes
= size
;
1404 Data(dpy
, ext_str
, size
);
1414 ** EXT_import_context
1417 PUBLIC Display
*glXGetCurrentDisplay(void)
1419 GLXContext gc
= __glXGetCurrentContext();
1420 if (NULL
== gc
) return NULL
;
1421 return gc
->currentDpy
;
1424 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1425 glXGetCurrentDisplay
)
1428 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1431 * \param dpy Display where \c ctx was created.
1432 * \param ctx Context to query.
1433 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1434 * or zero if the request failed due to internal problems (i.e.,
1435 * unable to allocate temporary memory, etc.)
1438 * This function dynamically determines whether to use the EXT_import_context
1439 * version of the protocol or the GLX 1.3 version of the protocol.
1441 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1443 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1444 xGLXQueryContextReply reply
;
1450 return GLX_BAD_CONTEXT
;
1452 opcode
= __glXSetupForCommand(dpy
);
1457 /* Send the glXQueryContextInfoEXT request */
1460 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1461 xGLXQueryContextReq
*req
;
1463 GetReq(GLXQueryContext
, req
);
1465 req
->reqType
= opcode
;
1466 req
->glxCode
= X_GLXQueryContext
;
1467 req
->context
= (unsigned int)(ctx
->xid
);
1470 xGLXVendorPrivateReq
*vpreq
;
1471 xGLXQueryContextInfoEXTReq
*req
;
1473 GetReqExtra( GLXVendorPrivate
,
1474 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1476 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1477 req
->reqType
= opcode
;
1478 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1479 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1480 req
->context
= (unsigned int)(ctx
->xid
);
1483 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1485 numValues
= reply
.n
;
1488 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1492 int *propList
, *pProp
;
1496 nPropListBytes
= numValues
<< 3;
1497 propList
= (int *) Xmalloc(nPropListBytes
);
1498 if (NULL
== propList
) {
1501 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1503 for (i
=0; i
< numValues
; i
++) {
1505 case GLX_SHARE_CONTEXT_EXT
:
1506 ctx
->share_xid
= *pProp
++;
1508 case GLX_VISUAL_ID_EXT
:
1510 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1513 ctx
->screen
= *pProp
++;
1515 case GLX_FBCONFIG_ID
:
1517 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1519 case GLX_RENDER_TYPE
:
1520 ctx
->renderType
= *pProp
++;
1527 Xfree((char *)propList
);
1537 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1541 /* get the information from the server if we don't have it already */
1542 #ifdef GLX_DIRECT_RENDERING
1543 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1545 if (ctx
->mode
== NULL
) {
1547 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1548 if (Success
!= retVal
) return retVal
;
1550 switch (attribute
) {
1551 case GLX_SHARE_CONTEXT_EXT
:
1552 *value
= (int)(ctx
->share_xid
);
1554 case GLX_VISUAL_ID_EXT
:
1555 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1558 *value
= (int)(ctx
->screen
);
1560 case GLX_FBCONFIG_ID
:
1561 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1563 case GLX_RENDER_TYPE
:
1564 *value
= (int)(ctx
->renderType
);
1567 return GLX_BAD_ATTRIBUTE
;
1572 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1573 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1574 (dpy
, ctx
, attribute
, value
),
1577 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1582 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1586 if (contextID
== None
) {
1589 if (__glXIsDirect(dpy
, contextID
)) {
1593 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1595 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1602 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1604 DestroyContext(dpy
, ctx
);
1610 * GLX 1.3 functions - these are just stubs for now!
1613 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1614 const int *attribList
, int *nitems
)
1616 __GLcontextModes
** config_list
;
1620 config_list
= (__GLcontextModes
**)
1621 glXGetFBConfigs( dpy
, screen
, & list_size
);
1623 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1624 list_size
= choose_visual( config_list
, list_size
, attribList
,
1626 if ( list_size
== 0 ) {
1627 XFree( config_list
);
1632 *nitems
= list_size
;
1633 return (GLXFBConfig
*) config_list
;
1637 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1638 int renderType
, GLXContext shareList
,
1641 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1642 allowDirect
, None
, True
, renderType
);
1646 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1648 GLXContext gc
= __glXGetCurrentContext();
1649 return gc
->currentReadable
;
1653 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1655 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1656 __GLcontextModes
** config
= NULL
;
1660 if ( (priv
->screenConfigs
!= NULL
)
1661 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1662 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1663 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1664 unsigned num_configs
= 0;
1665 __GLcontextModes
* modes
;
1668 for ( modes
= priv
->screenConfigs
[screen
].configs
1670 ; modes
= modes
->next
) {
1671 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1676 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1678 if ( config
!= NULL
) {
1679 *nelements
= num_configs
;
1681 for ( modes
= priv
->screenConfigs
[screen
].configs
1683 ; modes
= modes
->next
) {
1684 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1691 return (GLXFBConfig
*) config
;
1695 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1696 int attribute
, int *value
)
1698 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1700 return (modes
!= NULL
)
1701 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1706 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1708 XVisualInfo visualTemplate
;
1709 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1713 ** Get a list of all visuals, return if list is empty
1715 visualTemplate
.visualid
= fbconfig
->visualID
;
1716 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1721 ** GLX_SGI_swap_control
1723 static int __glXSwapIntervalSGI(int interval
)
1725 xGLXVendorPrivateReq
*req
;
1726 GLXContext gc
= __glXGetCurrentContext();
1728 CARD32
* interval_ptr
;
1732 return GLX_BAD_CONTEXT
;
1735 if ( interval
<= 0 ) {
1736 return GLX_BAD_VALUE
;
1739 #ifdef __DRI_SWAP_CONTROL
1740 if (gc
->driContext
) {
1741 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1743 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1744 gc
->currentDrawable
,
1746 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1747 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1751 return GLX_BAD_CONTEXT
;
1755 dpy
= gc
->currentDpy
;
1756 opcode
= __glXSetupForCommand(dpy
);
1761 /* Send the glXSwapIntervalSGI request */
1763 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1764 req
->reqType
= opcode
;
1765 req
->glxCode
= X_GLXVendorPrivate
;
1766 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1767 req
->contextTag
= gc
->currentContextTag
;
1769 interval_ptr
= (CARD32
*) (req
+ 1);
1770 *interval_ptr
= interval
;
1781 ** GLX_MESA_swap_control
1783 static int __glXSwapIntervalMESA(unsigned int interval
)
1785 #ifdef __DRI_SWAP_CONTROL
1786 GLXContext gc
= __glXGetCurrentContext();
1788 if ( interval
< 0 ) {
1789 return GLX_BAD_VALUE
;
1792 if (gc
!= NULL
&& gc
->driContext
) {
1793 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1796 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1797 __GLXDRIdrawable
*pdraw
=
1798 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1799 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1800 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1809 return GLX_BAD_CONTEXT
;
1813 static int __glXGetSwapIntervalMESA(void)
1815 #ifdef __DRI_SWAP_CONTROL
1816 GLXContext gc
= __glXGetCurrentContext();
1818 if (gc
!= NULL
&& gc
->driContext
) {
1819 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1822 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1823 __GLXDRIdrawable
*pdraw
=
1824 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1825 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1826 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1837 ** GLX_MESA_swap_frame_usage
1840 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1842 int status
= GLX_BAD_CONTEXT
;
1843 #ifdef __DRI_FRAME_TRACKING
1845 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1846 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1848 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1849 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1858 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1860 int status
= GLX_BAD_CONTEXT
;
1861 #ifdef __DRI_FRAME_TRACKING
1863 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1864 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1866 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1867 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1877 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1880 int status
= GLX_BAD_CONTEXT
;
1881 #ifdef __DRI_FRAME_TRACKING
1883 __GLXDRIdrawable
* const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1884 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1886 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1887 int64_t sbc
, missedFrames
;
1888 float lastMissedUsage
;
1890 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1905 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1906 int64_t *sbc
, int64_t *missedFrames
,
1907 GLfloat
*lastMissedUsage
)
1909 int status
= GLX_BAD_CONTEXT
;
1910 #ifdef __DRI_FRAME_TRACKING
1912 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1913 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1915 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1918 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1920 lastMissedUsage
, &usage
);
1926 (void) missedFrames
;
1927 (void) lastMissedUsage
;
1934 ** GLX_SGI_video_sync
1936 static int __glXGetVideoSyncSGI(unsigned int *count
)
1938 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1939 * FIXME: there should be a GLX encoding for this call. I can find no
1940 * FIXME: documentation for the GLX encoding.
1942 #ifdef __DRI_MEDIA_STREAM_COUNTER
1943 GLXContext gc
= __glXGetCurrentContext();
1946 if (gc
!= NULL
&& gc
->driContext
) {
1947 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1949 if ( psc
->msc
&& psc
->driScreen
) {
1950 __GLXDRIdrawable
*pdraw
=
1951 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1955 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
1956 pdraw
->driDrawable
, &temp
);
1957 *count
= (unsigned) temp
;
1959 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1965 return GLX_BAD_CONTEXT
;
1968 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1970 #ifdef __DRI_MEDIA_STREAM_COUNTER
1971 GLXContext gc
= __glXGetCurrentContext();
1973 if ( divisor
<= 0 || remainder
< 0 )
1974 return GLX_BAD_VALUE
;
1976 if (gc
!= NULL
&& gc
->driContext
) {
1977 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1979 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
1980 __GLXDRIdrawable
*pdraw
=
1981 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1986 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
1987 divisor
, remainder
, &msc
, &sbc
);
1988 *count
= (unsigned) msc
;
1989 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1995 return GLX_BAD_CONTEXT
;
2000 ** GLX_SGIX_fbconfig
2001 ** Many of these functions are aliased to GLX 1.3 entry points in the
2002 ** GLX_functions table.
2005 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2006 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2007 (dpy
, config
, attribute
, value
),
2008 glXGetFBConfigAttrib
)
2010 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2011 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2012 (dpy
, screen
, attrib_list
, nelements
),
2015 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2016 (Display
* dpy
, GLXFBConfigSGIX config
),
2018 glXGetVisualFromFBConfig
)
2020 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2021 GLXFBConfigSGIX config
, Pixmap pixmap
)
2023 xGLXVendorPrivateWithReplyReq
*vpreq
;
2024 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2025 GLXPixmap xid
= None
;
2027 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2028 __GLXscreenConfigs
* psc
;
2031 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2035 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2037 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2038 opcode
= __glXSetupForCommand(dpy
);
2043 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2045 GetReqExtra(GLXVendorPrivateWithReply
,
2046 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2047 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2048 req
->reqType
= opcode
;
2049 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2050 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2051 req
->screen
= fbconfig
->screen
;
2052 req
->fbconfig
= fbconfig
->fbconfigID
;
2053 req
->pixmap
= pixmap
;
2054 req
->glxpixmap
= xid
= XAllocID(dpy
);
2062 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2063 GLXFBConfigSGIX config
, int renderType
,
2064 GLXContext shareList
, Bool allowDirect
)
2066 GLXContext gc
= NULL
;
2067 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2068 __GLXscreenConfigs
* psc
;
2071 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2075 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2077 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2078 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2079 allowDirect
, None
, False
, renderType
);
2086 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2089 __GLXdisplayPrivate
*priv
;
2090 __GLXscreenConfigs
*psc
;
2092 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2093 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2094 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2095 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2104 ** GLX_SGIX_swap_group
2106 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2116 ** GLX_SGIX_swap_barrier
2118 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2126 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2136 ** GLX_OML_sync_control
2138 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2139 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2141 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2142 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2144 if ( priv
!= NULL
) {
2146 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2147 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2149 assert( (pdraw
== NULL
) || (i
!= -1) );
2150 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2151 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2152 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2153 && (__glXGetUST(ust
) == 0) );
2165 #ifdef GLX_DIRECT_RENDERING
2167 __driGetMscRateOML(__DRIdrawable
*draw
,
2168 int32_t *numerator
, int32_t *denominator
, void *private)
2171 __GLXscreenConfigs
*psc
;
2172 XF86VidModeModeLine mode_line
;
2175 __GLXDRIdrawable
*glxDraw
= private;
2178 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2179 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2180 unsigned n
= dot_clock
* 1000;
2181 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2183 # define V_INTERLACE 0x010
2184 # define V_DBLSCAN 0x020
2186 if (mode_line
.flags
& V_INTERLACE
)
2188 else if (mode_line
.flags
& V_DBLSCAN
)
2191 /* The OML_sync_control spec requires that if the refresh rate is a
2192 * whole number, that the returned numerator be equal to the refresh
2193 * rate and the denominator be 1.
2201 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2203 /* This is a poor man's way to reduce a fraction. It's far from
2204 * perfect, but it will work well enough for this situation.
2207 for (i
= 0; f
[i
] != 0; i
++) {
2208 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2229 * Determine the refresh rate of the specified drawable and display.
2231 * \param dpy Display whose refresh rate is to be determined.
2232 * \param drawable Drawable whose refresh rate is to be determined.
2233 * \param numerator Numerator of the refresh rate.
2234 * \param demoninator Denominator of the refresh rate.
2235 * \return If the refresh rate for the specified display and drawable could
2236 * be calculated, True is returned. Otherwise False is returned.
2238 * \note This function is implemented entirely client-side. A lot of other
2239 * functionality is required to export GLX_OML_sync_control, so on
2240 * XFree86 this function can be called for direct-rendering contexts
2241 * when GLX_OML_sync_control appears in the client extension string.
2244 _X_HIDDEN GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2245 int32_t * numerator
,
2246 int32_t * denominator
)
2248 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2249 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2254 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2265 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2266 int64_t target_msc
, int64_t divisor
,
2269 #ifdef __DRI_SWAP_BUFFER_COUNTER
2271 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2272 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2274 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2275 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2276 * of -1 if the function failed because of errors detected in the input
2279 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2281 if ( divisor
> 0 && remainder
>= divisor
)
2284 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2285 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2286 divisor
, remainder
);
2299 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2300 int64_t target_msc
, int64_t divisor
,
2301 int64_t remainder
, int64_t *ust
,
2302 int64_t *msc
, int64_t *sbc
)
2304 #ifdef __DRI_MEDIA_STREAM_COUNTER
2306 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2307 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2310 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2311 * error", but the return type in the spec is Bool.
2313 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2315 if ( divisor
> 0 && remainder
>= divisor
)
2318 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2319 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, target_msc
,
2320 divisor
, remainder
, msc
, sbc
);
2322 /* __glXGetUST returns zero on success and non-zero on failure.
2323 * This function returns True on success and False on failure.
2325 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2341 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2342 int64_t target_sbc
, int64_t *ust
,
2343 int64_t *msc
, int64_t *sbc
)
2345 #ifdef __DRI_SWAP_BUFFER_COUNTER
2347 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2348 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2351 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2352 * error", but the return type in the spec is Bool.
2354 if ( target_sbc
< 0 )
2357 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2358 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2360 /* __glXGetUST returns zero on success and non-zero on failure.
2361 * This function returns True on success and False on failure.
2363 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2378 * GLX_MESA_allocate_memory
2382 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2383 size_t size
, float readFreq
,
2384 float writeFreq
, float priority
)
2386 #ifdef __DRI_ALLOCATE
2387 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2389 if (psc
&& psc
->allocate
)
2390 return (*psc
->allocate
->allocateMemory
)(psc
->__driScreen
, size
,
2391 readFreq
, writeFreq
, priority
);
2400 #endif /* GLX_DIRECT_RENDERING */
2406 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2408 #ifdef __DRI_ALLOCATE
2409 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2411 if (psc
&& psc
->allocate
)
2412 (*psc
->allocate
->freeMemory
)(psc
->__driScreen
, pointer
);
2418 #endif /* GLX_DIRECT_RENDERING */
2422 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2423 const void *pointer
)
2425 #ifdef __DRI_ALLOCATE
2426 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2428 if (psc
&& psc
->allocate
)
2429 return (*psc
->allocate
->memoryOffset
)(psc
->__driScreen
, pointer
);
2435 #endif /* GLX_DIRECT_RENDERING */
2443 * Mesa extension stubs. These will help reduce portability problems.
2448 * Release all buffers associated with the specified GLX drawable.
2451 * This function was intended for stand-alone Mesa. The issue there is that
2452 * the library doesn't get any notification when a window is closed. In
2453 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2454 * supported, there are 3 different functions to destroy a drawable. It
2455 * should be possible to create GLX protocol (or have it determine which
2456 * protocol to use based on the type of the drawable) to have one function
2457 * do the work of 3. For the direct-rendering case, this function could
2458 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2459 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2460 * would need to be used. This really should be done as part of the new DRI
2463 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2464 * __driGarbageCollectDrawables
2465 * glXDestroyGLXPixmap
2466 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2467 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2469 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2477 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2478 Pixmap pixmap
, Colormap cmap
)
2490 * GLX_MESA_copy_sub_buffer
2492 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2493 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2494 int x
, int y
, int width
, int height
)
2496 xGLXVendorPrivateReq
*req
;
2499 CARD32
*drawable_ptr
;
2500 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2503 #ifdef __DRI_COPY_SUB_BUFFER
2505 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2506 if ( pdraw
!= NULL
) {
2507 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2508 if (psc
->copySubBuffer
!= NULL
) {
2509 (*psc
->copySubBuffer
->copySubBuffer
)(pdraw
->driDrawable
,
2510 x
, y
, width
, height
);
2517 opcode
= __glXSetupForCommand(dpy
);
2522 ** The calling thread may or may not have a current context. If it
2523 ** does, send the context tag so the server can do a flush.
2525 gc
= __glXGetCurrentContext();
2526 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2527 ((drawable
== gc
->currentDrawable
) ||
2528 (drawable
== gc
->currentReadable
)) ) {
2529 tag
= gc
->currentContextTag
;
2535 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2536 req
->reqType
= opcode
;
2537 req
->glxCode
= X_GLXVendorPrivate
;
2538 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2539 req
->contextTag
= tag
;
2541 drawable_ptr
= (CARD32
*) (req
+ 1);
2542 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2543 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2544 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2545 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2547 *drawable_ptr
= drawable
;
2559 * GLX_EXT_texture_from_pixmap
2562 static void __glXBindTexImageEXT(Display
*dpy
,
2563 GLXDrawable drawable
,
2565 const int *attrib_list
)
2567 xGLXVendorPrivateReq
*req
;
2568 GLXContext gc
= __glXGetCurrentContext();
2569 CARD32
*drawable_ptr
;
2571 CARD32
*num_attrib_ptr
;
2581 while (attrib_list
[i
* 2] != None
)
2585 #ifdef GLX_DIRECT_RENDERING
2586 if (gc
->driContext
) {
2587 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2590 (*pdraw
->psc
->texBuffer
->setTexBuffer
)(gc
->__driContext
,
2591 pdraw
->textureTarget
,
2592 pdraw
->driDrawable
);
2598 opcode
= __glXSetupForCommand(dpy
);
2603 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2604 req
->reqType
= opcode
;
2605 req
->glxCode
= X_GLXVendorPrivate
;
2606 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2607 req
->contextTag
= gc
->currentContextTag
;
2609 drawable_ptr
= (CARD32
*) (req
+ 1);
2610 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2611 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2612 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2614 *drawable_ptr
= drawable
;
2615 *buffer_ptr
= buffer
;
2616 *num_attrib_ptr
= (CARD32
) i
;
2620 while (attrib_list
[i
* 2] != None
)
2622 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2623 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2632 static void __glXReleaseTexImageEXT(Display
*dpy
,
2633 GLXDrawable drawable
,
2636 xGLXVendorPrivateReq
*req
;
2637 GLXContext gc
= __glXGetCurrentContext();
2638 CARD32
*drawable_ptr
;
2645 #ifdef GLX_DIRECT_RENDERING
2650 opcode
= __glXSetupForCommand(dpy
);
2655 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2656 req
->reqType
= opcode
;
2657 req
->glxCode
= X_GLXVendorPrivate
;
2658 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2659 req
->contextTag
= gc
->currentContextTag
;
2661 drawable_ptr
= (CARD32
*) (req
+ 1);
2662 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2664 *drawable_ptr
= drawable
;
2665 *buffer_ptr
= buffer
;
2673 * \c strdup is actually not a standard ANSI C or POSIX routine.
2674 * Irix will not define it if ANSI mode is in effect.
2679 __glXstrdup(const char *str
)
2682 copy
= (char *) Xmalloc(strlen(str
) + 1);
2690 ** glXGetProcAddress support
2693 struct name_address_pair
{
2698 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2699 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2701 static const struct name_address_pair GLX_functions
[] = {
2702 /*** GLX_VERSION_1_0 ***/
2703 GLX_FUNCTION( glXChooseVisual
),
2704 GLX_FUNCTION( glXCopyContext
),
2705 GLX_FUNCTION( glXCreateContext
),
2706 GLX_FUNCTION( glXCreateGLXPixmap
),
2707 GLX_FUNCTION( glXDestroyContext
),
2708 GLX_FUNCTION( glXDestroyGLXPixmap
),
2709 GLX_FUNCTION( glXGetConfig
),
2710 GLX_FUNCTION( glXGetCurrentContext
),
2711 GLX_FUNCTION( glXGetCurrentDrawable
),
2712 GLX_FUNCTION( glXIsDirect
),
2713 GLX_FUNCTION( glXMakeCurrent
),
2714 GLX_FUNCTION( glXQueryExtension
),
2715 GLX_FUNCTION( glXQueryVersion
),
2716 GLX_FUNCTION( glXSwapBuffers
),
2717 GLX_FUNCTION( glXUseXFont
),
2718 GLX_FUNCTION( glXWaitGL
),
2719 GLX_FUNCTION( glXWaitX
),
2721 /*** GLX_VERSION_1_1 ***/
2722 GLX_FUNCTION( glXGetClientString
),
2723 GLX_FUNCTION( glXQueryExtensionsString
),
2724 GLX_FUNCTION( glXQueryServerString
),
2726 /*** GLX_VERSION_1_2 ***/
2727 GLX_FUNCTION( glXGetCurrentDisplay
),
2729 /*** GLX_VERSION_1_3 ***/
2730 GLX_FUNCTION( glXChooseFBConfig
),
2731 GLX_FUNCTION( glXCreateNewContext
),
2732 GLX_FUNCTION( glXCreatePbuffer
),
2733 GLX_FUNCTION( glXCreatePixmap
),
2734 GLX_FUNCTION( glXCreateWindow
),
2735 GLX_FUNCTION( glXDestroyPbuffer
),
2736 GLX_FUNCTION( glXDestroyPixmap
),
2737 GLX_FUNCTION( glXDestroyWindow
),
2738 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2739 GLX_FUNCTION( glXGetFBConfigAttrib
),
2740 GLX_FUNCTION( glXGetFBConfigs
),
2741 GLX_FUNCTION( glXGetSelectedEvent
),
2742 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2743 GLX_FUNCTION( glXMakeContextCurrent
),
2744 GLX_FUNCTION( glXQueryContext
),
2745 GLX_FUNCTION( glXQueryDrawable
),
2746 GLX_FUNCTION( glXSelectEvent
),
2748 /*** GLX_SGI_swap_control ***/
2749 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2751 /*** GLX_SGI_video_sync ***/
2752 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2753 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2755 /*** GLX_SGI_make_current_read ***/
2756 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2757 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2759 /*** GLX_EXT_import_context ***/
2760 GLX_FUNCTION( glXFreeContextEXT
),
2761 GLX_FUNCTION( glXGetContextIDEXT
),
2762 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2763 GLX_FUNCTION( glXImportContextEXT
),
2764 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2766 /*** GLX_SGIX_fbconfig ***/
2767 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2768 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2769 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2770 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2771 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2772 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2774 /*** GLX_SGIX_pbuffer ***/
2775 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2776 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2777 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2778 GLX_FUNCTION( glXSelectEventSGIX
),
2779 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2781 /*** GLX_SGIX_swap_group ***/
2782 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2784 /*** GLX_SGIX_swap_barrier ***/
2785 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2786 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2788 /*** GLX_MESA_allocate_memory ***/
2789 GLX_FUNCTION( glXAllocateMemoryMESA
),
2790 GLX_FUNCTION( glXFreeMemoryMESA
),
2791 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2793 /*** GLX_MESA_copy_sub_buffer ***/
2794 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2796 /*** GLX_MESA_pixmap_colormap ***/
2797 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2799 /*** GLX_MESA_release_buffers ***/
2800 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2802 /*** GLX_MESA_swap_control ***/
2803 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2804 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2806 /*** GLX_MESA_swap_frame_usage ***/
2807 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2808 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2809 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2810 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2812 /*** GLX_ARB_get_proc_address ***/
2813 GLX_FUNCTION( glXGetProcAddressARB
),
2816 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2818 /*** GLX_OML_sync_control ***/
2819 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2820 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2821 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2822 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2823 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2825 /*** GLX_EXT_texture_from_pixmap ***/
2826 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2827 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2829 #ifdef GLX_DIRECT_RENDERING
2830 /*** DRI configuration ***/
2831 GLX_FUNCTION( glXGetScreenDriver
),
2832 GLX_FUNCTION( glXGetDriverConfig
),
2835 { NULL
, NULL
} /* end of list */
2839 static const GLvoid
*
2840 get_glx_proc_address(const char *funcName
)
2844 /* try static functions */
2845 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2846 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2847 return GLX_functions
[i
].Address
;
2855 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2856 * \c glXGetProcAddress.
2858 * \param procName Name of a GL or GLX function.
2859 * \returns A pointer to the named function
2861 * \sa glXGetProcAddress
2863 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2865 typedef void (*gl_function
)( void );
2869 /* Search the table of GLX and internal functions first. If that
2870 * fails and the supplied name could be a valid core GL name, try
2871 * searching the core GL function table. This check is done to prevent
2872 * DRI based drivers from searching the core GL function table for
2873 * internal API functions.
2876 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2877 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2878 && (procName
[2] != 'X') ) {
2879 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2886 * Get the address of a named GL function. This is the GLX 1.4 name for
2887 * \c glXGetProcAddressARB.
2889 * \param procName Name of a GL or GLX function.
2890 * \returns A pointer to the named function
2892 * \sa glXGetProcAddressARB
2894 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2895 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2896 __attribute__ ((alias ("glXGetProcAddressARB")));
2899 return glXGetProcAddressARB(procName
);
2901 #endif /* __GNUC__ */
2904 #ifdef GLX_DIRECT_RENDERING
2906 * Get the unadjusted system time (UST). Currently, the UST is measured in
2907 * microseconds since Epoc. The actual resolution of the UST may vary from
2908 * system to system, and the units may vary from release to release.
2909 * Drivers should not call this function directly. They should instead use
2910 * \c glXGetProcAddress to obtain a pointer to the function.
2912 * \param ust Location to store the 64-bit UST
2913 * \returns Zero on success or a negative errno value on failure.
2915 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2917 * \since Internal API version 20030317.
2919 _X_HIDDEN
int __glXGetUST( int64_t * ust
)
2923 if ( ust
== NULL
) {
2927 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2928 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2934 #endif /* GLX_DIRECT_RENDERING */