2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
39 #include "glcontextmodes.h"
41 #ifdef GLX_DIRECT_RENDERING
43 #include <X11/extensions/xf86vmode.h>
47 static const char __glXGLXClientVendorName
[] = "SGI";
48 static const char __glXGLXClientVersion
[] = "1.4";
51 /****************************************************************************/
53 #ifdef GLX_DIRECT_RENDERING
55 static Bool windowExistsFlag
;
56 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
58 if (xerr
->error_code
== BadWindow
) {
59 windowExistsFlag
= GL_FALSE
;
65 * Find drawables in the local hash that have been destroyed on the
68 * \param dpy Display to destroy drawables for
69 * \param screen Screen number to destroy drawables for
71 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
74 __GLXDRIdrawable
*pdraw
;
75 XWindowAttributes xwa
;
76 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
78 /* Set no-op error handler so Xlib doesn't bail out if the windows
79 * has alreay been destroyed on the server. */
81 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
83 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
85 windowExistsFlag
= GL_TRUE
;
86 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
87 if (!windowExistsFlag
) {
88 /* Destroy the local drawable data, if the drawable no
89 longer exists in the Xserver */
90 (*pdraw
->destroyDrawable
)(pdraw
);
91 __glxHashDelete(sc
->drawHash
, draw
);
93 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
97 XSetErrorHandler(oldXErrorHandler
);
100 extern __GLXDRIdrawable
*
101 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
);
104 * Get the __DRIdrawable for the drawable associated with a GLXContext
106 * \param dpy The display associated with \c drawable.
107 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
108 * \param scrn_num If non-NULL, the drawables screen is stored there
109 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
110 * the drawable is not associated with a direct-rendering context.
112 _X_HIDDEN __GLXDRIdrawable
*
113 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
115 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
116 __GLXDRIdrawable
*pdraw
;
117 const unsigned screen_count
= ScreenCount(dpy
);
119 __GLXscreenConfigs
*psc
;
124 for (i
= 0; i
< screen_count
; i
++) {
125 psc
= &priv
->screenConfigs
[i
];
126 if (psc
->drawHash
== NULL
)
129 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
130 if (scrn_num
!= NULL
)
143 * Get the GLX per-screen data structure associated with a GLX context.
145 * \param dpy Display for which the GLX per-screen information is to be
147 * \param scrn Screen on \c dpy for which the GLX per-screen information is
149 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
150 * specify a valid GLX screen, or NULL otherwise.
152 * \todo Should this function validate that \c scrn is within the screen
153 * number range for \c dpy?
156 static __GLXscreenConfigs
*
157 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
159 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
161 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
166 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
167 __GLXscreenConfigs
** ppsc
)
169 /* Initialize the extension, if needed . This has the added value
170 * of initializing/allocating the display private
174 return GLX_NO_EXTENSION
;
177 *ppriv
= __glXInitialize(dpy
);
178 if ( *ppriv
== NULL
) {
179 return GLX_NO_EXTENSION
;
182 /* Check screen number to see if its valid */
183 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
184 return GLX_BAD_SCREEN
;
187 /* Check to see if the GL is supported on this screen */
188 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
189 if ( (*ppsc
)->configs
== NULL
) {
190 /* No support for GL on this screen regardless of visual */
191 return GLX_BAD_VISUAL
;
199 * Determine if a \c GLXFBConfig supplied by the application is valid.
201 * \param dpy Application supplied \c Display pointer.
202 * \param config Application supplied \c GLXFBConfig.
204 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
205 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
208 static __GLcontextModes
*
209 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
211 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
212 const unsigned num_screens
= ScreenCount(dpy
);
214 const __GLcontextModes
* modes
;
217 if ( priv
!= NULL
) {
218 for ( i
= 0 ; i
< num_screens
; i
++ ) {
219 for ( modes
= priv
->screenConfigs
[i
].configs
221 ; modes
= modes
->next
) {
222 if ( modes
== (__GLcontextModes
*) config
) {
223 return (__GLcontextModes
*) config
;
234 * \todo It should be possible to move the allocate of \c client_state_private
235 * later in the function for direct-rendering contexts. Direct-rendering
236 * contexts don't need to track client state, so they don't need that memory
239 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
240 * function called \c __glXAllocateClientState that allocates the memory and
241 * does all the initialization (including the pixel pack / unpack).
244 GLXContext
AllocateGLXContext( Display
*dpy
)
249 __GLXattribute
*state
;
254 opcode
= __glXSetupForCommand(dpy
);
259 /* Allocate our context record */
260 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
265 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
267 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
273 gc
->client_state_private
= state
;
274 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
275 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
278 ** Create a temporary buffer to hold GLX rendering commands. The size
279 ** of the buffer is selected so that the maximum number of GLX rendering
280 ** commands can fit in a single X packet and still have room in the X
281 ** packet for the GLXRenderReq header.
284 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
285 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
287 Xfree(gc
->client_state_private
);
291 gc
->bufSize
= bufSize
;
293 /* Fill in the new context */
294 gc
->renderMode
= GL_RENDER
;
296 state
->storePack
.alignment
= 4;
297 state
->storeUnpack
.alignment
= 4;
299 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
302 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
303 ** Other code uses the fastImageUnpack bit, but it is never set
306 gc
->fastImageUnpack
= GL_FALSE
;
307 gc
->fillImage
= __glFillImage
;
309 gc
->bufEnd
= gc
->buf
+ bufSize
;
310 gc
->isDirect
= GL_FALSE
;
313 ** Set limit register so that there will be one command per packet
317 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
320 gc
->majorOpcode
= opcode
;
323 ** Constrain the maximum drawing command size allowed to be
324 ** transfered using the X_GLXRender protocol request. First
325 ** constrain by a software limit, then constrain by the protocl
328 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
329 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
331 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
332 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
334 gc
->maxSmallRenderCommandSize
= bufSize
;
340 * Create a new context. Exactly one of \c vis and \c fbconfig should be
343 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
344 * SGIX_fbconfig protocol be used?
345 * \param renderType For FBConfigs, what is the rendering type?
349 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
350 const __GLcontextModes
* const fbconfig
,
351 GLXContext shareList
,
352 Bool allowDirect
, GLXContextID contextID
,
353 Bool use_glx_1_3
, int renderType
)
356 #ifdef GLX_DIRECT_RENDERING
357 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
358 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
364 gc
= AllocateGLXContext(dpy
);
368 if (None
== contextID
) {
369 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
372 #ifdef GLX_DIRECT_RENDERING
373 if (allowDirect
&& psc
->driScreen
) {
374 const __GLcontextModes
* mode
;
376 if (fbconfig
== NULL
) {
377 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
381 error
.errorCode
= BadValue
;
382 error
.resourceID
= vis
->visualid
;
383 error
.sequenceNumber
= dpy
->request
;
384 error
.type
= X_Error
;
385 error
.majorCode
= gc
->majorOpcode
;
386 error
.minorCode
= X_GLXCreateContext
;
387 _XError(dpy
, &error
);
395 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
398 if (gc
->driContext
!= NULL
) {
399 gc
->screen
= mode
->screen
;
402 gc
->isDirect
= GL_TRUE
;
408 if ( fbconfig
== NULL
) {
409 xGLXCreateContextReq
*req
;
411 /* Send the glXCreateContext request */
412 GetReq(GLXCreateContext
,req
);
413 req
->reqType
= gc
->majorOpcode
;
414 req
->glxCode
= X_GLXCreateContext
;
415 req
->context
= gc
->xid
= XAllocID(dpy
);
416 req
->visual
= vis
->visualid
;
417 req
->screen
= vis
->screen
;
418 req
->shareList
= shareList
? shareList
->xid
: None
;
419 #ifdef GLX_DIRECT_RENDERING
420 req
->isDirect
= gc
->driContext
!= NULL
;
425 else if ( use_glx_1_3
) {
426 xGLXCreateNewContextReq
*req
;
428 /* Send the glXCreateNewContext request */
429 GetReq(GLXCreateNewContext
,req
);
430 req
->reqType
= gc
->majorOpcode
;
431 req
->glxCode
= X_GLXCreateNewContext
;
432 req
->context
= gc
->xid
= XAllocID(dpy
);
433 req
->fbconfig
= fbconfig
->fbconfigID
;
434 req
->screen
= fbconfig
->screen
;
435 req
->renderType
= renderType
;
436 req
->shareList
= shareList
? shareList
->xid
: None
;
437 #ifdef GLX_DIRECT_RENDERING
438 req
->isDirect
= gc
->driContext
!= NULL
;
444 xGLXVendorPrivateWithReplyReq
*vpreq
;
445 xGLXCreateContextWithConfigSGIXReq
*req
;
447 /* Send the glXCreateNewContext request */
448 GetReqExtra(GLXVendorPrivateWithReply
,
449 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
450 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
451 req
->reqType
= gc
->majorOpcode
;
452 req
->glxCode
= X_GLXVendorPrivateWithReply
;
453 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
454 req
->context
= gc
->xid
= XAllocID(dpy
);
455 req
->fbconfig
= fbconfig
->fbconfigID
;
456 req
->screen
= fbconfig
->screen
;
457 req
->renderType
= renderType
;
458 req
->shareList
= shareList
? shareList
->xid
: None
;
459 #ifdef GLX_DIRECT_RENDERING
460 req
->isDirect
= gc
->driContext
!= NULL
;
468 gc
->imported
= GL_FALSE
;
472 gc
->imported
= GL_TRUE
;
478 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
479 GLXContext shareList
, Bool allowDirect
)
481 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
485 _X_HIDDEN
void __glXFreeContext(__GLXcontext
*gc
)
487 if (gc
->vendor
) XFree((char *) gc
->vendor
);
488 if (gc
->renderer
) XFree((char *) gc
->renderer
);
489 if (gc
->version
) XFree((char *) gc
->version
);
490 if (gc
->extensions
) XFree((char *) gc
->extensions
);
491 __glFreeAttributeState(gc
);
492 XFree((char *) gc
->buf
);
493 Xfree((char *) gc
->client_state_private
);
499 ** Destroy the named context
502 DestroyContext(Display
*dpy
, GLXContext gc
)
504 xGLXDestroyContextReq
*req
;
509 opcode
= __glXSetupForCommand(dpy
);
510 if (!opcode
|| !gc
) {
516 imported
= gc
->imported
;
519 #ifdef GLX_DIRECT_RENDERING
520 /* Destroy the direct rendering context */
521 if (gc
->driContext
) {
522 (*gc
->driContext
->destroyContext
)(gc
->driContext
, gc
->psc
, dpy
);
523 gc
->driContext
= NULL
;
524 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
528 __glXFreeVertexArrayState(gc
);
530 if (gc
->currentDpy
) {
531 /* Have to free later cuz it's in use now */
534 /* Destroy the handle if not current to anybody */
536 __glXFreeContext(gc
);
541 ** This dpy also created the server side part of the context.
542 ** Send the glXDestroyContext request.
545 GetReq(GLXDestroyContext
,req
);
546 req
->reqType
= opcode
;
547 req
->glxCode
= X_GLXDestroyContext
;
554 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
556 DestroyContext(dpy
, gc
);
560 ** Return the major and minor version #s for the GLX extension
562 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
564 __GLXdisplayPrivate
*priv
;
566 /* Init the extension. This fetches the major and minor version. */
567 priv
= __glXInitialize(dpy
);
568 if (!priv
) return GL_FALSE
;
570 if (major
) *major
= priv
->majorVersion
;
571 if (minor
) *minor
= priv
->minorVersion
;
576 ** Query the existance of the GLX extension
578 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
580 int major_op
, erb
, evb
;
583 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
585 if (errorBase
) *errorBase
= erb
;
586 if (eventBase
) *eventBase
= evb
;
592 ** Put a barrier in the token stream that forces the GL to finish its
593 ** work before X can proceed.
595 PUBLIC
void glXWaitGL(void)
598 GLXContext gc
= __glXGetCurrentContext();
599 Display
*dpy
= gc
->currentDpy
;
603 /* Flush any pending commands out */
604 __glXFlushRenderBuffer(gc
, gc
->pc
);
606 #ifdef GLX_DIRECT_RENDERING
607 if (gc
->driContext
) {
608 /* This bit of ugliness unwraps the glFinish function */
617 /* Send the glXWaitGL request */
619 GetReq(GLXWaitGL
,req
);
620 req
->reqType
= gc
->majorOpcode
;
621 req
->glxCode
= X_GLXWaitGL
;
622 req
->contextTag
= gc
->currentContextTag
;
628 ** Put a barrier in the token stream that forces X to finish its
629 ** work before GL can proceed.
631 PUBLIC
void glXWaitX(void)
634 GLXContext gc
= __glXGetCurrentContext();
635 Display
*dpy
= gc
->currentDpy
;
639 /* Flush any pending commands out */
640 __glXFlushRenderBuffer(gc
, gc
->pc
);
642 #ifdef GLX_DIRECT_RENDERING
643 if (gc
->driContext
) {
650 ** Send the glXWaitX request.
653 GetReq(GLXWaitX
,req
);
654 req
->reqType
= gc
->majorOpcode
;
655 req
->glxCode
= X_GLXWaitX
;
656 req
->contextTag
= gc
->currentContextTag
;
661 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
663 xGLXUseXFontReq
*req
;
664 GLXContext gc
= __glXGetCurrentContext();
665 Display
*dpy
= gc
->currentDpy
;
669 /* Flush any pending commands out */
670 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
672 #ifdef GLX_DIRECT_RENDERING
673 if (gc
->driContext
) {
674 DRI_glXUseXFont(font
, first
, count
, listBase
);
679 /* Send the glXUseFont request */
681 GetReq(GLXUseXFont
,req
);
682 req
->reqType
= gc
->majorOpcode
;
683 req
->glxCode
= X_GLXUseXFont
;
684 req
->contextTag
= gc
->currentContextTag
;
688 req
->listBase
= listBase
;
693 /************************************************************************/
696 ** Copy the source context to the destination context using the
699 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
700 GLXContext dest
, unsigned long mask
)
702 xGLXCopyContextReq
*req
;
703 GLXContext gc
= __glXGetCurrentContext();
707 opcode
= __glXSetupForCommand(dpy
);
712 #ifdef GLX_DIRECT_RENDERING
713 if (gc
->driContext
) {
714 /* NOT_DONE: This does not work yet */
719 ** If the source is the current context, send its tag so that the context
720 ** can be flushed before the copy.
722 if (source
== gc
&& dpy
== gc
->currentDpy
) {
723 tag
= gc
->currentContextTag
;
728 /* Send the glXCopyContext request */
730 GetReq(GLXCopyContext
,req
);
731 req
->reqType
= opcode
;
732 req
->glxCode
= X_GLXCopyContext
;
733 req
->source
= source
? source
->xid
: None
;
734 req
->dest
= dest
? dest
->xid
: None
;
736 req
->contextTag
= tag
;
743 * Determine if a context uses direct rendering.
745 * \param dpy Display where the context was created.
746 * \param contextID ID of the context to be tested.
748 * \returns \c GL_TRUE if the context is direct rendering or not.
750 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
752 xGLXIsDirectReq
*req
;
753 xGLXIsDirectReply reply
;
756 opcode
= __glXSetupForCommand(dpy
);
761 /* Send the glXIsDirect request */
763 GetReq(GLXIsDirect
,req
);
764 req
->reqType
= opcode
;
765 req
->glxCode
= X_GLXIsDirect
;
766 req
->context
= contextID
;
767 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
771 return reply
.isDirect
;
776 * Shouldn't this function \b always return \c GL_FALSE when
777 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
778 * the GLX protocol here at all?
780 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
784 #ifdef GLX_DIRECT_RENDERING
785 } else if (gc
->driContext
) {
789 return __glXIsDirect(dpy
, gc
->xid
);
792 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
795 xGLXCreateGLXPixmapReq
*req
;
799 opcode
= __glXSetupForCommand(dpy
);
804 /* Send the glXCreateGLXPixmap request */
806 GetReq(GLXCreateGLXPixmap
,req
);
807 req
->reqType
= opcode
;
808 req
->glxCode
= X_GLXCreateGLXPixmap
;
809 req
->screen
= vis
->screen
;
810 req
->visual
= vis
->visualid
;
811 req
->pixmap
= pixmap
;
812 req
->glxpixmap
= xid
= XAllocID(dpy
);
819 ** Destroy the named pixmap
821 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
823 xGLXDestroyGLXPixmapReq
*req
;
826 opcode
= __glXSetupForCommand(dpy
);
831 /* Send the glXDestroyGLXPixmap request */
833 GetReq(GLXDestroyGLXPixmap
,req
);
834 req
->reqType
= opcode
;
835 req
->glxCode
= X_GLXDestroyGLXPixmap
;
836 req
->glxpixmap
= glxpixmap
;
841 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
843 xGLXSwapBuffersReq
*req
;
847 #ifdef GLX_DIRECT_RENDERING
848 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
852 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
);
857 opcode
= __glXSetupForCommand(dpy
);
863 ** The calling thread may or may not have a current context. If it
864 ** does, send the context tag so the server can do a flush.
866 gc
= __glXGetCurrentContext();
867 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
868 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
869 tag
= gc
->currentContextTag
;
874 /* Send the glXSwapBuffers request */
876 GetReq(GLXSwapBuffers
,req
);
877 req
->reqType
= opcode
;
878 req
->glxCode
= X_GLXSwapBuffers
;
879 req
->drawable
= drawable
;
880 req
->contextTag
= tag
;
888 ** Return configuration information for the given display, screen and
889 ** visual combination.
891 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
894 __GLXdisplayPrivate
*priv
;
895 __GLXscreenConfigs
*psc
;
896 __GLcontextModes
*modes
;
899 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
900 if ( status
== Success
) {
901 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
903 /* Lookup attribute after first finding a match on the visual */
904 if ( modes
!= NULL
) {
905 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
908 status
= GLX_BAD_VISUAL
;
912 ** If we can't find the config for this visual, this visual is not
913 ** supported by the OpenGL implementation on the server.
915 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
916 *value_return
= GL_FALSE
;
923 /************************************************************************/
926 init_fbconfig_for_chooser( __GLcontextModes
* config
,
927 GLboolean fbconfig_style_tags
)
929 memset( config
, 0, sizeof( __GLcontextModes
) );
930 config
->visualID
= (XID
) GLX_DONT_CARE
;
931 config
->visualType
= GLX_DONT_CARE
;
933 /* glXChooseFBConfig specifies different defaults for these two than
936 if ( fbconfig_style_tags
) {
937 config
->rgbMode
= GL_TRUE
;
938 config
->doubleBufferMode
= GLX_DONT_CARE
;
941 config
->visualRating
= GLX_DONT_CARE
;
942 config
->transparentPixel
= GLX_NONE
;
943 config
->transparentRed
= GLX_DONT_CARE
;
944 config
->transparentGreen
= GLX_DONT_CARE
;
945 config
->transparentBlue
= GLX_DONT_CARE
;
946 config
->transparentAlpha
= GLX_DONT_CARE
;
947 config
->transparentIndex
= GLX_DONT_CARE
;
949 config
->drawableType
= GLX_WINDOW_BIT
;
950 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
951 config
->xRenderable
= GLX_DONT_CARE
;
952 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
954 config
->swapMethod
= GLX_DONT_CARE
;
957 #define MATCH_DONT_CARE( param ) \
959 if ( (a-> param != GLX_DONT_CARE) \
960 && (a-> param != b-> param) ) { \
965 #define MATCH_MINIMUM( param ) \
967 if ( (a-> param != GLX_DONT_CARE) \
968 && (a-> param > b-> param) ) { \
973 #define MATCH_EXACT( param ) \
975 if ( a-> param != b-> param) { \
981 * Determine if two GLXFBConfigs are compatible.
983 * \param a Application specified config to test.
984 * \param b Server specified config to test against \c a.
987 fbconfigs_compatible( const __GLcontextModes
* const a
,
988 const __GLcontextModes
* const b
)
990 MATCH_DONT_CARE( doubleBufferMode
);
991 MATCH_DONT_CARE( visualType
);
992 MATCH_DONT_CARE( visualRating
);
993 MATCH_DONT_CARE( xRenderable
);
994 MATCH_DONT_CARE( fbconfigID
);
995 MATCH_DONT_CARE( swapMethod
);
997 MATCH_MINIMUM( rgbBits
);
998 MATCH_MINIMUM( numAuxBuffers
);
999 MATCH_MINIMUM( redBits
);
1000 MATCH_MINIMUM( greenBits
);
1001 MATCH_MINIMUM( blueBits
);
1002 MATCH_MINIMUM( alphaBits
);
1003 MATCH_MINIMUM( depthBits
);
1004 MATCH_MINIMUM( stencilBits
);
1005 MATCH_MINIMUM( accumRedBits
);
1006 MATCH_MINIMUM( accumGreenBits
);
1007 MATCH_MINIMUM( accumBlueBits
);
1008 MATCH_MINIMUM( accumAlphaBits
);
1009 MATCH_MINIMUM( sampleBuffers
);
1010 MATCH_MINIMUM( maxPbufferWidth
);
1011 MATCH_MINIMUM( maxPbufferHeight
);
1012 MATCH_MINIMUM( maxPbufferPixels
);
1013 MATCH_MINIMUM( samples
);
1015 MATCH_DONT_CARE( stereoMode
);
1016 MATCH_EXACT( level
);
1018 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1019 || ((a
->renderType
& b
->renderType
) == 0) ) {
1024 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1025 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1026 * Technically speaking, it is a bug in the DDX driver, but there is
1027 * enough of an installed base to work around the problem here. In any
1028 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1029 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1030 * 0 from the server to be a match to maintain backward compatibility with
1031 * the (broken) drivers.
1034 if ( a
->transparentPixel
!= GLX_DONT_CARE
1035 && a
->transparentPixel
!= 0 ) {
1036 if ( a
->transparentPixel
== GLX_NONE
) {
1037 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1040 MATCH_EXACT( transparentPixel
);
1043 switch ( a
->transparentPixel
) {
1044 case GLX_TRANSPARENT_RGB
:
1045 MATCH_DONT_CARE( transparentRed
);
1046 MATCH_DONT_CARE( transparentGreen
);
1047 MATCH_DONT_CARE( transparentBlue
);
1048 MATCH_DONT_CARE( transparentAlpha
);
1051 case GLX_TRANSPARENT_INDEX
:
1052 MATCH_DONT_CARE( transparentIndex
);
1064 /* There's some trickly language in the GLX spec about how this is supposed
1065 * to work. Basically, if a given component size is either not specified
1066 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1067 * Well, that's really hard to do with the code as-is. This behavior is
1068 * closer to correct, but still not technically right.
1070 #define PREFER_LARGER_OR_ZERO(comp) \
1072 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1073 if ( ((*a)-> comp) == 0 ) { \
1076 else if ( ((*b)-> comp) == 0 ) { \
1080 return ((*b)-> comp) - ((*a)-> comp) ; \
1085 #define PREFER_LARGER(comp) \
1087 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1088 return ((*b)-> comp) - ((*a)-> comp) ; \
1092 #define PREFER_SMALLER(comp) \
1094 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1095 return ((*a)-> comp) - ((*b)-> comp) ; \
1100 * Compare two GLXFBConfigs. This function is intended to be used as the
1101 * compare function passed in to qsort.
1103 * \returns If \c a is a "better" config, according to the specification of
1104 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1105 * better, then a number greater than zero is return. If both are
1106 * equal, zero is returned.
1107 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1110 fbconfig_compare( const __GLcontextModes
* const * const a
,
1111 const __GLcontextModes
* const * const b
)
1113 /* The order of these comparisons must NOT change. It is defined by
1114 * the GLX 1.3 spec and ARB_multisample.
1117 PREFER_SMALLER( visualSelectGroup
);
1119 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1120 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1121 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1123 PREFER_SMALLER( visualRating
);
1125 /* This isn't quite right. It is supposed to compare the sum of the
1126 * components the user specifically set minimums for.
1128 PREFER_LARGER_OR_ZERO( redBits
);
1129 PREFER_LARGER_OR_ZERO( greenBits
);
1130 PREFER_LARGER_OR_ZERO( blueBits
);
1131 PREFER_LARGER_OR_ZERO( alphaBits
);
1133 PREFER_SMALLER( rgbBits
);
1135 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1136 /* Prefer single-buffer.
1138 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1141 PREFER_SMALLER( numAuxBuffers
);
1143 PREFER_LARGER_OR_ZERO( depthBits
);
1144 PREFER_SMALLER( stencilBits
);
1146 /* This isn't quite right. It is supposed to compare the sum of the
1147 * components the user specifically set minimums for.
1149 PREFER_LARGER_OR_ZERO( accumRedBits
);
1150 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1151 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1152 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1154 PREFER_SMALLER( visualType
);
1156 /* None of the multisample specs say where this comparison should happen,
1157 * so I put it near the end.
1159 PREFER_SMALLER( sampleBuffers
);
1160 PREFER_SMALLER( samples
);
1162 /* None of the pbuffer or fbconfig specs say that this comparison needs
1163 * to happen at all, but it seems like it should.
1165 PREFER_LARGER( maxPbufferWidth
);
1166 PREFER_LARGER( maxPbufferHeight
);
1167 PREFER_LARGER( maxPbufferPixels
);
1174 * Selects and sorts a subset of the supplied configs based on the attributes.
1175 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1176 * and \c glXChooseFBConfigSGIX.
1178 * \param configs Array of pointers to possible configs. The elements of
1179 * this array that do not meet the criteria will be set to
1180 * NULL. The remaining elements will be sorted according to
1181 * the various visual / FBConfig selection rules.
1182 * \param num_configs Number of elements in the \c configs array.
1183 * \param attribList Attributes used select from \c configs. This array is
1184 * terminated by a \c None tag. The array can either take
1185 * the form expected by \c glXChooseVisual (where boolean
1186 * tags do not have a value) or by \c glXChooseFBConfig
1187 * (where every tag has a value).
1188 * \param fbconfig_style_tags Selects whether \c attribList is in
1189 * \c glXChooseVisual style or
1190 * \c glXChooseFBConfig style.
1191 * \returns The number of valid elements left in \c configs.
1193 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1196 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1197 const int *attribList
, GLboolean fbconfig_style_tags
)
1199 __GLcontextModes test_config
;
1203 /* This is a fairly direct implementation of the selection method
1204 * described by GLX_SGIX_fbconfig. Start by culling out all the
1205 * configs that are not compatible with the selected parameter
1209 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1210 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1211 (const INT32
*) attribList
,
1212 GL_TRUE
, fbconfig_style_tags
);
1215 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1216 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1217 configs
[ base
] = configs
[ i
];
1226 if ( base
< num_configs
) {
1227 (void) memset( & configs
[ base
], 0,
1228 sizeof( void * ) * (num_configs
- base
) );
1231 /* After the incompatible configs are removed, the resulting
1232 * list is sorted according to the rules set out in the various
1236 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1237 (int (*)(const void*, const void*)) fbconfig_compare
);
1245 ** Return the visual that best matches the template. Return None if no
1246 ** visual matches the template.
1248 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1250 XVisualInfo
*visualList
= NULL
;
1251 __GLXdisplayPrivate
*priv
;
1252 __GLXscreenConfigs
*psc
;
1253 __GLcontextModes test_config
;
1254 __GLcontextModes
*modes
;
1255 const __GLcontextModes
*best_config
= NULL
;
1258 ** Get a list of all visuals, return if list is empty
1260 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1266 ** Build a template from the defaults and the attribute list
1267 ** Free visual list and return if an unexpected token is encountered
1269 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1270 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1271 (const INT32
*) attribList
,
1272 GL_TRUE
, GL_FALSE
);
1275 ** Eliminate visuals that don't meet minimum requirements
1276 ** Compute a score for those that do
1277 ** Remember which visual, if any, got the highest score
1279 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1280 if ( fbconfigs_compatible( & test_config
, modes
)
1281 && ((best_config
== NULL
)
1282 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1283 best_config
= modes
;
1288 ** If no visual is acceptable, return None
1289 ** Otherwise, create an XVisualInfo list with just the selected X visual
1292 if (best_config
!= NULL
) {
1293 XVisualInfo visualTemplate
;
1296 visualTemplate
.screen
= screen
;
1297 visualTemplate
.visualid
= best_config
->visualID
;
1298 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1299 &visualTemplate
, &i
);
1306 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1308 __GLXscreenConfigs
*psc
;
1309 __GLXdisplayPrivate
*priv
;
1311 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1315 if (!psc
->effectiveGLXexts
) {
1316 if (!psc
->serverGLXexts
) {
1317 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1318 X_GLXQueryServerString
,
1319 screen
, GLX_EXTENSIONS
);
1322 __glXCalculateUsableExtensions(psc
,
1323 #ifdef GLX_DIRECT_RENDERING
1324 (psc
->driScreen
!= NULL
),
1328 priv
->minorVersion
);
1331 return psc
->effectiveGLXexts
;
1334 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1338 return (__glXGLXClientVendorName
);
1340 return (__glXGLXClientVersion
);
1341 case GLX_EXTENSIONS
:
1342 return (__glXGetClientExtensions());
1348 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1350 __GLXscreenConfigs
*psc
;
1351 __GLXdisplayPrivate
*priv
;
1355 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1361 str
= & priv
->serverGLXvendor
;
1364 str
= & priv
->serverGLXversion
;
1366 case GLX_EXTENSIONS
:
1367 str
= & psc
->serverGLXexts
;
1373 if ( *str
== NULL
) {
1374 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1375 X_GLXQueryServerString
, screen
, name
);
1381 void __glXClientInfo ( Display
*dpy
, int opcode
)
1383 xGLXClientInfoReq
*req
;
1385 char * ext_str
= __glXGetClientGLExtensionString();
1387 /* Send the glXClientInfo request */
1389 GetReq(GLXClientInfo
,req
);
1390 req
->reqType
= opcode
;
1391 req
->glxCode
= X_GLXClientInfo
;
1392 req
->major
= GLX_MAJOR_VERSION
;
1393 req
->minor
= GLX_MINOR_VERSION
;
1395 size
= strlen( ext_str
) + 1;
1396 req
->length
+= (size
+ 3) >> 2;
1397 req
->numbytes
= size
;
1398 Data(dpy
, ext_str
, size
);
1408 ** EXT_import_context
1411 PUBLIC Display
*glXGetCurrentDisplay(void)
1413 GLXContext gc
= __glXGetCurrentContext();
1414 if (NULL
== gc
) return NULL
;
1415 return gc
->currentDpy
;
1418 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1419 glXGetCurrentDisplay
)
1422 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1425 * \param dpy Display where \c ctx was created.
1426 * \param ctx Context to query.
1427 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1428 * or zero if the request failed due to internal problems (i.e.,
1429 * unable to allocate temporary memory, etc.)
1432 * This function dynamically determines whether to use the EXT_import_context
1433 * version of the protocol or the GLX 1.3 version of the protocol.
1435 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1437 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1438 xGLXQueryContextReply reply
;
1444 return GLX_BAD_CONTEXT
;
1446 opcode
= __glXSetupForCommand(dpy
);
1451 /* Send the glXQueryContextInfoEXT request */
1454 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1455 xGLXQueryContextReq
*req
;
1457 GetReq(GLXQueryContext
, req
);
1459 req
->reqType
= opcode
;
1460 req
->glxCode
= X_GLXQueryContext
;
1461 req
->context
= (unsigned int)(ctx
->xid
);
1464 xGLXVendorPrivateReq
*vpreq
;
1465 xGLXQueryContextInfoEXTReq
*req
;
1467 GetReqExtra( GLXVendorPrivate
,
1468 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1470 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1471 req
->reqType
= opcode
;
1472 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1473 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1474 req
->context
= (unsigned int)(ctx
->xid
);
1477 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1479 numValues
= reply
.n
;
1482 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1486 int *propList
, *pProp
;
1490 nPropListBytes
= numValues
<< 3;
1491 propList
= (int *) Xmalloc(nPropListBytes
);
1492 if (NULL
== propList
) {
1495 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1497 for (i
=0; i
< numValues
; i
++) {
1499 case GLX_SHARE_CONTEXT_EXT
:
1500 ctx
->share_xid
= *pProp
++;
1502 case GLX_VISUAL_ID_EXT
:
1504 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1507 ctx
->screen
= *pProp
++;
1509 case GLX_FBCONFIG_ID
:
1511 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1513 case GLX_RENDER_TYPE
:
1514 ctx
->renderType
= *pProp
++;
1521 Xfree((char *)propList
);
1531 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1535 /* get the information from the server if we don't have it already */
1536 #ifdef GLX_DIRECT_RENDERING
1537 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1539 if (ctx
->mode
== NULL
) {
1541 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1542 if (Success
!= retVal
) return retVal
;
1544 switch (attribute
) {
1545 case GLX_SHARE_CONTEXT_EXT
:
1546 *value
= (int)(ctx
->share_xid
);
1548 case GLX_VISUAL_ID_EXT
:
1549 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1552 *value
= (int)(ctx
->screen
);
1554 case GLX_FBCONFIG_ID
:
1555 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1557 case GLX_RENDER_TYPE
:
1558 *value
= (int)(ctx
->renderType
);
1561 return GLX_BAD_ATTRIBUTE
;
1566 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1567 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1568 (dpy
, ctx
, attribute
, value
),
1571 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1576 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1580 if (contextID
== None
) {
1583 if (__glXIsDirect(dpy
, contextID
)) {
1587 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1589 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1596 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1598 DestroyContext(dpy
, ctx
);
1604 * GLX 1.3 functions - these are just stubs for now!
1607 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1608 const int *attribList
, int *nitems
)
1610 __GLcontextModes
** config_list
;
1614 config_list
= (__GLcontextModes
**)
1615 glXGetFBConfigs( dpy
, screen
, & list_size
);
1617 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1618 list_size
= choose_visual( config_list
, list_size
, attribList
,
1620 if ( list_size
== 0 ) {
1621 XFree( config_list
);
1626 *nitems
= list_size
;
1627 return (GLXFBConfig
*) config_list
;
1631 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1632 int renderType
, GLXContext shareList
,
1635 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1636 allowDirect
, None
, True
, renderType
);
1640 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1642 GLXContext gc
= __glXGetCurrentContext();
1643 return gc
->currentReadable
;
1647 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1649 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1650 __GLcontextModes
** config
= NULL
;
1654 if ( (priv
->screenConfigs
!= NULL
)
1655 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1656 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1657 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1658 unsigned num_configs
= 0;
1659 __GLcontextModes
* modes
;
1662 for ( modes
= priv
->screenConfigs
[screen
].configs
1664 ; modes
= modes
->next
) {
1665 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1670 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1672 if ( config
!= NULL
) {
1673 *nelements
= num_configs
;
1675 for ( modes
= priv
->screenConfigs
[screen
].configs
1677 ; modes
= modes
->next
) {
1678 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1685 return (GLXFBConfig
*) config
;
1689 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1690 int attribute
, int *value
)
1692 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1694 return (modes
!= NULL
)
1695 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1700 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1702 XVisualInfo visualTemplate
;
1703 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1707 ** Get a list of all visuals, return if list is empty
1709 visualTemplate
.visualid
= fbconfig
->visualID
;
1710 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1715 ** GLX_SGI_swap_control
1717 static int __glXSwapIntervalSGI(int interval
)
1719 xGLXVendorPrivateReq
*req
;
1720 GLXContext gc
= __glXGetCurrentContext();
1722 CARD32
* interval_ptr
;
1726 return GLX_BAD_CONTEXT
;
1729 if ( interval
<= 0 ) {
1730 return GLX_BAD_VALUE
;
1733 #ifdef __DRI_SWAP_CONTROL
1734 if (gc
->driContext
) {
1735 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1737 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1738 gc
->currentDrawable
,
1740 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1741 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1745 return GLX_BAD_CONTEXT
;
1749 dpy
= gc
->currentDpy
;
1750 opcode
= __glXSetupForCommand(dpy
);
1755 /* Send the glXSwapIntervalSGI request */
1757 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1758 req
->reqType
= opcode
;
1759 req
->glxCode
= X_GLXVendorPrivate
;
1760 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1761 req
->contextTag
= gc
->currentContextTag
;
1763 interval_ptr
= (CARD32
*) (req
+ 1);
1764 *interval_ptr
= interval
;
1775 ** GLX_MESA_swap_control
1777 static int __glXSwapIntervalMESA(unsigned int interval
)
1779 #ifdef __DRI_SWAP_CONTROL
1780 GLXContext gc
= __glXGetCurrentContext();
1782 if ( interval
< 0 ) {
1783 return GLX_BAD_VALUE
;
1786 if (gc
!= NULL
&& gc
->driContext
) {
1787 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1790 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1791 __GLXDRIdrawable
*pdraw
=
1792 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1793 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1794 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1803 return GLX_BAD_CONTEXT
;
1807 static int __glXGetSwapIntervalMESA(void)
1809 #ifdef __DRI_SWAP_CONTROL
1810 GLXContext gc
= __glXGetCurrentContext();
1812 if (gc
!= NULL
&& gc
->driContext
) {
1813 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1816 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1817 __GLXDRIdrawable
*pdraw
=
1818 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1819 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1820 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1831 ** GLX_MESA_swap_frame_usage
1834 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1836 int status
= GLX_BAD_CONTEXT
;
1837 #ifdef __DRI_FRAME_TRACKING
1839 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1840 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1842 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1843 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1852 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1854 int status
= GLX_BAD_CONTEXT
;
1855 #ifdef __DRI_FRAME_TRACKING
1857 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1858 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1860 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1861 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1871 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1874 int status
= GLX_BAD_CONTEXT
;
1875 #ifdef __DRI_FRAME_TRACKING
1877 __GLXDRIdrawable
* const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1878 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1880 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1881 int64_t sbc
, missedFrames
;
1882 float lastMissedUsage
;
1884 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1899 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1900 int64_t *sbc
, int64_t *missedFrames
,
1901 GLfloat
*lastMissedUsage
)
1903 int status
= GLX_BAD_CONTEXT
;
1904 #ifdef __DRI_FRAME_TRACKING
1906 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1907 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1909 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1912 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
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
->driContext
) {
1941 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1943 if ( psc
->msc
&& psc
->driScreen
) {
1944 __GLXDRIdrawable
*pdraw
=
1945 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1949 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
1950 pdraw
->driDrawable
, &temp
);
1951 *count
= (unsigned) temp
;
1953 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1959 return GLX_BAD_CONTEXT
;
1962 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1964 #ifdef __DRI_MEDIA_STREAM_COUNTER
1965 GLXContext gc
= __glXGetCurrentContext();
1967 if ( divisor
<= 0 || remainder
< 0 )
1968 return GLX_BAD_VALUE
;
1970 if (gc
!= NULL
&& gc
->driContext
) {
1971 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1973 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
1974 __GLXDRIdrawable
*pdraw
=
1975 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1980 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
1981 divisor
, remainder
, &msc
, &sbc
);
1982 *count
= (unsigned) msc
;
1983 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1989 return GLX_BAD_CONTEXT
;
1994 ** GLX_SGIX_fbconfig
1995 ** Many of these functions are aliased to GLX 1.3 entry points in the
1996 ** GLX_functions table.
1999 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2000 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2001 (dpy
, config
, attribute
, value
),
2002 glXGetFBConfigAttrib
)
2004 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2005 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2006 (dpy
, screen
, attrib_list
, nelements
),
2009 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2010 (Display
* dpy
, GLXFBConfigSGIX config
),
2012 glXGetVisualFromFBConfig
)
2014 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2015 GLXFBConfigSGIX config
, Pixmap pixmap
)
2017 xGLXVendorPrivateWithReplyReq
*vpreq
;
2018 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2019 GLXPixmap xid
= None
;
2021 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2022 __GLXscreenConfigs
* psc
;
2025 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2029 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2031 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2032 opcode
= __glXSetupForCommand(dpy
);
2037 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2039 GetReqExtra(GLXVendorPrivateWithReply
,
2040 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2041 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2042 req
->reqType
= opcode
;
2043 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2044 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2045 req
->screen
= fbconfig
->screen
;
2046 req
->fbconfig
= fbconfig
->fbconfigID
;
2047 req
->pixmap
= pixmap
;
2048 req
->glxpixmap
= xid
= XAllocID(dpy
);
2056 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2057 GLXFBConfigSGIX config
, int renderType
,
2058 GLXContext shareList
, Bool allowDirect
)
2060 GLXContext gc
= NULL
;
2061 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2062 __GLXscreenConfigs
* psc
;
2065 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2069 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2071 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2072 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2073 allowDirect
, None
, False
, renderType
);
2080 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2083 __GLXdisplayPrivate
*priv
;
2084 __GLXscreenConfigs
*psc
;
2086 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2087 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2088 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2089 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2098 ** GLX_SGIX_swap_group
2100 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2110 ** GLX_SGIX_swap_barrier
2112 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2120 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2130 ** GLX_OML_sync_control
2132 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2133 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2135 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2136 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2138 if ( priv
!= NULL
) {
2140 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2141 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2143 assert( (pdraw
== NULL
) || (i
!= -1) );
2144 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2145 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2146 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2147 && (__glXGetUST(ust
) == 0) );
2159 #ifdef GLX_DIRECT_RENDERING
2161 __driGetMscRateOML(__DRIdrawable
*draw
,
2162 int32_t *numerator
, int32_t *denominator
, void *private)
2165 __GLXscreenConfigs
*psc
;
2166 XF86VidModeModeLine mode_line
;
2169 __GLXDRIdrawable
*glxDraw
= private;
2172 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2173 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2174 unsigned n
= dot_clock
* 1000;
2175 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2177 # define V_INTERLACE 0x010
2178 # define V_DBLSCAN 0x020
2180 if (mode_line
.flags
& V_INTERLACE
)
2182 else if (mode_line
.flags
& V_DBLSCAN
)
2185 /* The OML_sync_control spec requires that if the refresh rate is a
2186 * whole number, that the returned numerator be equal to the refresh
2187 * rate and the denominator be 1.
2195 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2197 /* This is a poor man's way to reduce a fraction. It's far from
2198 * perfect, but it will work well enough for this situation.
2201 for (i
= 0; f
[i
] != 0; i
++) {
2202 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2223 * Determine the refresh rate of the specified drawable and display.
2225 * \param dpy Display whose refresh rate is to be determined.
2226 * \param drawable Drawable whose refresh rate is to be determined.
2227 * \param numerator Numerator of the refresh rate.
2228 * \param demoninator Denominator of the refresh rate.
2229 * \return If the refresh rate for the specified display and drawable could
2230 * be calculated, True is returned. Otherwise False is returned.
2232 * \note This function is implemented entirely client-side. A lot of other
2233 * functionality is required to export GLX_OML_sync_control, so on
2234 * XFree86 this function can be called for direct-rendering contexts
2235 * when GLX_OML_sync_control appears in the client extension string.
2238 _X_HIDDEN GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2239 int32_t * numerator
,
2240 int32_t * denominator
)
2242 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2243 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2248 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2259 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2260 int64_t target_msc
, int64_t divisor
,
2263 #ifdef __DRI_SWAP_BUFFER_COUNTER
2265 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2266 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2268 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2269 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2270 * of -1 if the function failed because of errors detected in the input
2273 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2275 if ( divisor
> 0 && remainder
>= divisor
)
2278 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2279 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2280 divisor
, remainder
);
2293 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2294 int64_t target_msc
, int64_t divisor
,
2295 int64_t remainder
, int64_t *ust
,
2296 int64_t *msc
, int64_t *sbc
)
2298 #ifdef __DRI_MEDIA_STREAM_COUNTER
2300 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2301 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2304 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2305 * error", but the return type in the spec is Bool.
2307 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2309 if ( divisor
> 0 && remainder
>= divisor
)
2312 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2313 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, target_msc
,
2314 divisor
, remainder
, msc
, sbc
);
2316 /* __glXGetUST returns zero on success and non-zero on failure.
2317 * This function returns True on success and False on failure.
2319 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2335 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2336 int64_t target_sbc
, int64_t *ust
,
2337 int64_t *msc
, int64_t *sbc
)
2339 #ifdef __DRI_SWAP_BUFFER_COUNTER
2341 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2342 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2345 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2346 * error", but the return type in the spec is Bool.
2348 if ( target_sbc
< 0 )
2351 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2352 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2354 /* __glXGetUST returns zero on success and non-zero on failure.
2355 * This function returns True on success and False on failure.
2357 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2372 * GLX_MESA_allocate_memory
2376 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2377 size_t size
, float readFreq
,
2378 float writeFreq
, float priority
)
2380 #ifdef __DRI_ALLOCATE
2381 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2383 if (psc
&& psc
->allocate
)
2384 return (*psc
->allocate
->allocateMemory
)(psc
->__driScreen
, size
,
2385 readFreq
, writeFreq
, priority
);
2394 #endif /* GLX_DIRECT_RENDERING */
2400 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2402 #ifdef __DRI_ALLOCATE
2403 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2405 if (psc
&& psc
->allocate
)
2406 (*psc
->allocate
->freeMemory
)(psc
->__driScreen
, pointer
);
2412 #endif /* GLX_DIRECT_RENDERING */
2416 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2417 const void *pointer
)
2419 #ifdef __DRI_ALLOCATE
2420 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2422 if (psc
&& psc
->allocate
)
2423 return (*psc
->allocate
->memoryOffset
)(psc
->__driScreen
, pointer
);
2429 #endif /* GLX_DIRECT_RENDERING */
2437 * Mesa extension stubs. These will help reduce portability problems.
2442 * Release all buffers associated with the specified GLX drawable.
2445 * This function was intended for stand-alone Mesa. The issue there is that
2446 * the library doesn't get any notification when a window is closed. In
2447 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2448 * supported, there are 3 different functions to destroy a drawable. It
2449 * should be possible to create GLX protocol (or have it determine which
2450 * protocol to use based on the type of the drawable) to have one function
2451 * do the work of 3. For the direct-rendering case, this function could
2452 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2453 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2454 * would need to be used. This really should be done as part of the new DRI
2457 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2458 * __driGarbageCollectDrawables
2459 * glXDestroyGLXPixmap
2460 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2461 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2463 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2471 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2472 Pixmap pixmap
, Colormap cmap
)
2484 * GLX_MESA_copy_sub_buffer
2486 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2487 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2488 int x
, int y
, int width
, int height
)
2490 xGLXVendorPrivateReq
*req
;
2493 CARD32
*drawable_ptr
;
2494 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2497 #ifdef __DRI_COPY_SUB_BUFFER
2499 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2500 if ( pdraw
!= NULL
) {
2501 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2502 if (psc
->copySubBuffer
!= NULL
) {
2503 (*psc
->copySubBuffer
->copySubBuffer
)(pdraw
->driDrawable
,
2504 x
, y
, width
, height
);
2511 opcode
= __glXSetupForCommand(dpy
);
2516 ** The calling thread may or may not have a current context. If it
2517 ** does, send the context tag so the server can do a flush.
2519 gc
= __glXGetCurrentContext();
2520 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2521 ((drawable
== gc
->currentDrawable
) ||
2522 (drawable
== gc
->currentReadable
)) ) {
2523 tag
= gc
->currentContextTag
;
2529 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2530 req
->reqType
= opcode
;
2531 req
->glxCode
= X_GLXVendorPrivate
;
2532 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2533 req
->contextTag
= tag
;
2535 drawable_ptr
= (CARD32
*) (req
+ 1);
2536 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2537 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2538 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2539 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2541 *drawable_ptr
= drawable
;
2553 * GLX_EXT_texture_from_pixmap
2556 static void __glXBindTexImageEXT(Display
*dpy
,
2557 GLXDrawable drawable
,
2559 const int *attrib_list
)
2561 xGLXVendorPrivateReq
*req
;
2562 GLXContext gc
= __glXGetCurrentContext();
2563 CARD32
*drawable_ptr
;
2565 CARD32
*num_attrib_ptr
;
2575 while (attrib_list
[i
* 2] != None
)
2579 #ifdef GLX_DIRECT_RENDERING
2580 if (gc
->driContext
) {
2581 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2584 (*pdraw
->psc
->texBuffer
->setTexBuffer
)(gc
->__driContext
,
2585 pdraw
->textureTarget
,
2586 pdraw
->driDrawable
);
2592 opcode
= __glXSetupForCommand(dpy
);
2597 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2598 req
->reqType
= opcode
;
2599 req
->glxCode
= X_GLXVendorPrivate
;
2600 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2601 req
->contextTag
= gc
->currentContextTag
;
2603 drawable_ptr
= (CARD32
*) (req
+ 1);
2604 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2605 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2606 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2608 *drawable_ptr
= drawable
;
2609 *buffer_ptr
= buffer
;
2610 *num_attrib_ptr
= (CARD32
) i
;
2614 while (attrib_list
[i
* 2] != None
)
2616 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2617 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2626 static void __glXReleaseTexImageEXT(Display
*dpy
,
2627 GLXDrawable drawable
,
2630 xGLXVendorPrivateReq
*req
;
2631 GLXContext gc
= __glXGetCurrentContext();
2632 CARD32
*drawable_ptr
;
2639 #ifdef GLX_DIRECT_RENDERING
2644 opcode
= __glXSetupForCommand(dpy
);
2649 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2650 req
->reqType
= opcode
;
2651 req
->glxCode
= X_GLXVendorPrivate
;
2652 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2653 req
->contextTag
= gc
->currentContextTag
;
2655 drawable_ptr
= (CARD32
*) (req
+ 1);
2656 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2658 *drawable_ptr
= drawable
;
2659 *buffer_ptr
= buffer
;
2667 * \c strdup is actually not a standard ANSI C or POSIX routine.
2668 * Irix will not define it if ANSI mode is in effect.
2673 __glXstrdup(const char *str
)
2676 copy
= (char *) Xmalloc(strlen(str
) + 1);
2684 ** glXGetProcAddress support
2687 struct name_address_pair
{
2692 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2693 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2695 static const struct name_address_pair GLX_functions
[] = {
2696 /*** GLX_VERSION_1_0 ***/
2697 GLX_FUNCTION( glXChooseVisual
),
2698 GLX_FUNCTION( glXCopyContext
),
2699 GLX_FUNCTION( glXCreateContext
),
2700 GLX_FUNCTION( glXCreateGLXPixmap
),
2701 GLX_FUNCTION( glXDestroyContext
),
2702 GLX_FUNCTION( glXDestroyGLXPixmap
),
2703 GLX_FUNCTION( glXGetConfig
),
2704 GLX_FUNCTION( glXGetCurrentContext
),
2705 GLX_FUNCTION( glXGetCurrentDrawable
),
2706 GLX_FUNCTION( glXIsDirect
),
2707 GLX_FUNCTION( glXMakeCurrent
),
2708 GLX_FUNCTION( glXQueryExtension
),
2709 GLX_FUNCTION( glXQueryVersion
),
2710 GLX_FUNCTION( glXSwapBuffers
),
2711 GLX_FUNCTION( glXUseXFont
),
2712 GLX_FUNCTION( glXWaitGL
),
2713 GLX_FUNCTION( glXWaitX
),
2715 /*** GLX_VERSION_1_1 ***/
2716 GLX_FUNCTION( glXGetClientString
),
2717 GLX_FUNCTION( glXQueryExtensionsString
),
2718 GLX_FUNCTION( glXQueryServerString
),
2720 /*** GLX_VERSION_1_2 ***/
2721 GLX_FUNCTION( glXGetCurrentDisplay
),
2723 /*** GLX_VERSION_1_3 ***/
2724 GLX_FUNCTION( glXChooseFBConfig
),
2725 GLX_FUNCTION( glXCreateNewContext
),
2726 GLX_FUNCTION( glXCreatePbuffer
),
2727 GLX_FUNCTION( glXCreatePixmap
),
2728 GLX_FUNCTION( glXCreateWindow
),
2729 GLX_FUNCTION( glXDestroyPbuffer
),
2730 GLX_FUNCTION( glXDestroyPixmap
),
2731 GLX_FUNCTION( glXDestroyWindow
),
2732 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2733 GLX_FUNCTION( glXGetFBConfigAttrib
),
2734 GLX_FUNCTION( glXGetFBConfigs
),
2735 GLX_FUNCTION( glXGetSelectedEvent
),
2736 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2737 GLX_FUNCTION( glXMakeContextCurrent
),
2738 GLX_FUNCTION( glXQueryContext
),
2739 GLX_FUNCTION( glXQueryDrawable
),
2740 GLX_FUNCTION( glXSelectEvent
),
2742 /*** GLX_SGI_swap_control ***/
2743 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2745 /*** GLX_SGI_video_sync ***/
2746 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2747 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2749 /*** GLX_SGI_make_current_read ***/
2750 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2751 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2753 /*** GLX_EXT_import_context ***/
2754 GLX_FUNCTION( glXFreeContextEXT
),
2755 GLX_FUNCTION( glXGetContextIDEXT
),
2756 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2757 GLX_FUNCTION( glXImportContextEXT
),
2758 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2760 /*** GLX_SGIX_fbconfig ***/
2761 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2762 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2763 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2764 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2765 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2766 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2768 /*** GLX_SGIX_pbuffer ***/
2769 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2770 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2771 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2772 GLX_FUNCTION( glXSelectEventSGIX
),
2773 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2775 /*** GLX_SGIX_swap_group ***/
2776 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2778 /*** GLX_SGIX_swap_barrier ***/
2779 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2780 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2782 /*** GLX_MESA_allocate_memory ***/
2783 GLX_FUNCTION( glXAllocateMemoryMESA
),
2784 GLX_FUNCTION( glXFreeMemoryMESA
),
2785 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2787 /*** GLX_MESA_copy_sub_buffer ***/
2788 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2790 /*** GLX_MESA_pixmap_colormap ***/
2791 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2793 /*** GLX_MESA_release_buffers ***/
2794 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2796 /*** GLX_MESA_swap_control ***/
2797 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2798 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2800 /*** GLX_MESA_swap_frame_usage ***/
2801 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2802 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2803 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2804 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2806 /*** GLX_ARB_get_proc_address ***/
2807 GLX_FUNCTION( glXGetProcAddressARB
),
2810 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2812 /*** GLX_OML_sync_control ***/
2813 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2814 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2815 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2816 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2817 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2819 /*** GLX_EXT_texture_from_pixmap ***/
2820 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2821 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2823 #ifdef GLX_DIRECT_RENDERING
2824 /*** DRI configuration ***/
2825 GLX_FUNCTION( glXGetScreenDriver
),
2826 GLX_FUNCTION( glXGetDriverConfig
),
2829 { NULL
, NULL
} /* end of list */
2833 static const GLvoid
*
2834 get_glx_proc_address(const char *funcName
)
2838 /* try static functions */
2839 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2840 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2841 return GLX_functions
[i
].Address
;
2849 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2850 * \c glXGetProcAddress.
2852 * \param procName Name of a GL or GLX function.
2853 * \returns A pointer to the named function
2855 * \sa glXGetProcAddress
2857 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2859 typedef void (*gl_function
)( void );
2863 /* Search the table of GLX and internal functions first. If that
2864 * fails and the supplied name could be a valid core GL name, try
2865 * searching the core GL function table. This check is done to prevent
2866 * DRI based drivers from searching the core GL function table for
2867 * internal API functions.
2870 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2871 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2872 && (procName
[2] != 'X') ) {
2873 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2880 * Get the address of a named GL function. This is the GLX 1.4 name for
2881 * \c glXGetProcAddressARB.
2883 * \param procName Name of a GL or GLX function.
2884 * \returns A pointer to the named function
2886 * \sa glXGetProcAddressARB
2888 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2889 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2890 __attribute__ ((alias ("glXGetProcAddressARB")));
2893 return glXGetProcAddressARB(procName
);
2895 #endif /* __GNUC__ */
2898 #ifdef GLX_DIRECT_RENDERING
2900 * Get the unadjusted system time (UST). Currently, the UST is measured in
2901 * microseconds since Epoc. The actual resolution of the UST may vary from
2902 * system to system, and the units may vary from release to release.
2903 * Drivers should not call this function directly. They should instead use
2904 * \c glXGetProcAddress to obtain a pointer to the function.
2906 * \param ust Location to store the 64-bit UST
2907 * \returns Zero on success or a negative errno value on failure.
2909 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2911 * \since Internal API version 20030317.
2913 _X_HIDDEN
int __glXGetUST( int64_t * ust
)
2917 if ( ust
== NULL
) {
2921 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2922 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2928 #endif /* GLX_DIRECT_RENDERING */