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"
41 #ifdef GLX_DIRECT_RENDERING
42 #ifdef GLX_USE_APPLEGL
43 #include "apple_glx_context.h"
44 #include "apple_glx.h"
45 #include "glx_error.h"
49 #include <X11/extensions/xf86vmode.h>
57 #include <X11/Xlib-xcb.h>
62 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
63 static const char __glXGLXClientVersion
[] = "1.4";
65 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
68 * Get the __DRIdrawable for the drawable associated with a GLXContext
70 * \param dpy The display associated with \c drawable.
71 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
72 * \param scrn_num If non-NULL, the drawables screen is stored there
73 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
74 * the drawable is not associated with a direct-rendering context.
76 _X_HIDDEN __GLXDRIdrawable
*
77 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
79 struct glx_display
*priv
= __glXInitialize(dpy
);
80 __GLXDRIdrawable
*pdraw
;
85 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
95 * Get the GLX per-screen data structure associated with a GLX context.
97 * \param dpy Display for which the GLX per-screen information is to be
99 * \param scrn Screen on \c dpy for which the GLX per-screen information is
101 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
102 * specify a valid GLX screen, or NULL otherwise.
104 * \todo Should this function validate that \c scrn is within the screen
105 * number range for \c dpy?
108 static struct glx_screen
*
109 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
111 struct glx_display
*const priv
= __glXInitialize(dpy
);
115 NULL
) ? priv
->screens
[scrn
] : NULL
;
120 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
121 struct glx_screen
** ppsc
)
123 /* Initialize the extension, if needed . This has the added value
124 * of initializing/allocating the display private
128 return GLX_NO_EXTENSION
;
131 *ppriv
= __glXInitialize(dpy
);
132 if (*ppriv
== NULL
) {
133 return GLX_NO_EXTENSION
;
136 /* Check screen number to see if its valid */
137 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
138 return GLX_BAD_SCREEN
;
141 /* Check to see if the GL is supported on this screen */
142 *ppsc
= (*ppriv
)->screens
[scrn
];
143 if ((*ppsc
)->configs
== NULL
) {
144 /* No support for GL on this screen regardless of visual */
145 return GLX_BAD_VISUAL
;
153 * Determine if a \c GLXFBConfig supplied by the application is valid.
155 * \param dpy Application supplied \c Display pointer.
156 * \param config Application supplied \c GLXFBConfig.
158 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
159 * \c struct glx_config structure is returned. Otherwise, \c NULL
162 static struct glx_config
*
163 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
165 struct glx_display
*const priv
= __glXInitialize(dpy
);
166 int num_screens
= ScreenCount(dpy
);
168 struct glx_config
*config
;
171 for (i
= 0; i
< num_screens
; i
++) {
172 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
173 config
= config
->next
) {
174 if (config
== (struct glx_config
*) fbconfig
) {
185 glx_context_init(struct glx_context
*gc
,
186 struct glx_screen
*psc
, struct glx_config
*config
)
188 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
189 if (!gc
->majorOpcode
)
192 gc
->screen
= psc
->scr
;
195 gc
->isDirect
= GL_TRUE
;
196 gc
->currentContextTag
= -1;
203 * Create a new context. Exactly one of \c vis and \c fbconfig should be
206 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
207 * SGIX_fbconfig protocol be used?
208 * \param renderType For FBConfigs, what is the rendering type?
212 CreateContext(Display
* dpy
, int generic_id
,
213 struct glx_config
*config
,
214 GLXContext shareList_user
,
216 unsigned code
, int renderType
, int screen
)
218 struct glx_context
*gc
;
219 struct glx_screen
*psc
;
220 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
224 psc
= GetGLXScreenConfigs(dpy
, screen
);
228 if (generic_id
== None
)
232 if (allowDirect
&& psc
->vtable
->create_context
)
233 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
235 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
241 case X_GLXCreateContext
: {
242 xGLXCreateContextReq
*req
;
244 /* Send the glXCreateContext request */
245 GetReq(GLXCreateContext
, req
);
246 req
->reqType
= gc
->majorOpcode
;
247 req
->glxCode
= X_GLXCreateContext
;
248 req
->context
= gc
->xid
= XAllocID(dpy
);
249 req
->visual
= generic_id
;
250 req
->screen
= screen
;
251 req
->shareList
= shareList
? shareList
->xid
: None
;
252 req
->isDirect
= gc
->isDirect
;
256 case X_GLXCreateNewContext
: {
257 xGLXCreateNewContextReq
*req
;
259 /* Send the glXCreateNewContext request */
260 GetReq(GLXCreateNewContext
, req
);
261 req
->reqType
= gc
->majorOpcode
;
262 req
->glxCode
= X_GLXCreateNewContext
;
263 req
->context
= gc
->xid
= XAllocID(dpy
);
264 req
->fbconfig
= generic_id
;
265 req
->screen
= screen
;
266 req
->renderType
= renderType
;
267 req
->shareList
= shareList
? shareList
->xid
: None
;
268 req
->isDirect
= gc
->isDirect
;
272 case X_GLXvop_CreateContextWithConfigSGIX
: {
273 xGLXVendorPrivateWithReplyReq
*vpreq
;
274 xGLXCreateContextWithConfigSGIXReq
*req
;
276 /* Send the glXCreateNewContext request */
277 GetReqExtra(GLXVendorPrivateWithReply
,
278 sz_xGLXCreateContextWithConfigSGIXReq
-
279 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
280 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
281 req
->reqType
= gc
->majorOpcode
;
282 req
->glxCode
= X_GLXVendorPrivateWithReply
;
283 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
284 req
->context
= gc
->xid
= XAllocID(dpy
);
285 req
->fbconfig
= generic_id
;
286 req
->screen
= screen
;
287 req
->renderType
= renderType
;
288 req
->shareList
= shareList
? shareList
->xid
: None
;
289 req
->isDirect
= gc
->isDirect
;
294 /* What to do here? This case is the sign of an internal error. It
295 * should never be reachable.
303 gc
->imported
= GL_FALSE
;
304 gc
->renderType
= renderType
;
306 return (GLXContext
) gc
;
310 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
311 GLXContext shareList
, Bool allowDirect
)
313 struct glx_config
*config
= NULL
;
316 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
317 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
319 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
320 if (config
== NULL
) {
323 error
.errorCode
= BadValue
;
324 error
.resourceID
= vis
->visualid
;
325 error
.sequenceNumber
= dpy
->request
;
326 error
.type
= X_Error
;
327 error
.majorCode
= __glXSetupForCommand(dpy
);
328 error
.minorCode
= X_GLXCreateContext
;
329 _XError(dpy
, &error
);
333 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
336 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
337 X_GLXCreateContext
, renderType
, vis
->screen
);
341 glx_send_destroy_context(Display
*dpy
, XID xid
)
343 CARD8 opcode
= __glXSetupForCommand(dpy
);
344 xGLXDestroyContextReq
*req
;
347 GetReq(GLXDestroyContext
, req
);
348 req
->reqType
= opcode
;
349 req
->glxCode
= X_GLXDestroyContext
;
356 ** Destroy the named context
359 DestroyContext(Display
* dpy
, GLXContext ctx
)
361 struct glx_context
*gc
= (struct glx_context
*) ctx
;
367 if (gc
->currentDpy
) {
368 /* This context is bound to some thread. According to the man page,
369 * we should not actually delete the context until it's unbound.
370 * Note that we set gc->xid = None above. In MakeContextCurrent()
371 * we check for that and delete the context there.
374 glx_send_destroy_context(dpy
, gc
->xid
);
381 if (gc
->vtable
->destroy
)
382 gc
->vtable
->destroy(gc
);
386 glXDestroyContext(Display
* dpy
, GLXContext gc
)
388 DestroyContext(dpy
, gc
);
392 ** Return the major and minor version #s for the GLX extension
395 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
397 struct glx_display
*priv
;
399 /* Init the extension. This fetches the major and minor version. */
400 priv
= __glXInitialize(dpy
);
405 *major
= priv
->majorVersion
;
407 *minor
= priv
->minorVersion
;
412 ** Query the existance of the GLX extension
415 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
417 int major_op
, erb
, evb
;
420 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
431 ** Put a barrier in the token stream that forces the GL to finish its
432 ** work before X can proceed.
437 struct glx_context
*gc
= __glXGetCurrentContext();
439 if (gc
&& gc
->vtable
->wait_gl
)
440 gc
->vtable
->wait_gl(gc
);
444 ** Put a barrier in the token stream that forces X to finish its
445 ** work before GL can proceed.
450 struct glx_context
*gc
= __glXGetCurrentContext();
452 if (gc
&& gc
->vtable
->wait_x
)
453 gc
->vtable
->wait_x(gc
);
457 glXUseXFont(Font font
, int first
, int count
, int listBase
)
459 struct glx_context
*gc
= __glXGetCurrentContext();
461 if (gc
&& gc
->vtable
->use_x_font
)
462 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
465 /************************************************************************/
468 ** Copy the source context to the destination context using the
472 glXCopyContext(Display
* dpy
, GLXContext source_user
,
473 GLXContext dest_user
, unsigned long mask
)
475 struct glx_context
*source
= (struct glx_context
*) source_user
;
476 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
477 #ifdef GLX_USE_APPLEGL
478 struct glx_context
*gc
= __glXGetCurrentContext();
482 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
483 mask
, &errorcode
, &x11error
)) {
484 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
488 xGLXCopyContextReq
*req
;
489 struct glx_context
*gc
= __glXGetCurrentContext();
493 opcode
= __glXSetupForCommand(dpy
);
498 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
500 /* NOT_DONE: This does not work yet */
505 ** If the source is the current context, send its tag so that the context
506 ** can be flushed before the copy.
508 if (source
== gc
&& dpy
== gc
->currentDpy
) {
509 tag
= gc
->currentContextTag
;
515 /* Send the glXCopyContext request */
517 GetReq(GLXCopyContext
, req
);
518 req
->reqType
= opcode
;
519 req
->glxCode
= X_GLXCopyContext
;
520 req
->source
= source
? source
->xid
: None
;
521 req
->dest
= dest
? dest
->xid
: None
;
523 req
->contextTag
= tag
;
526 #endif /* GLX_USE_APPLEGL */
531 * Determine if a context uses direct rendering.
533 * \param dpy Display where the context was created.
534 * \param contextID ID of the context to be tested.
536 * \returns \c GL_TRUE if the context is direct rendering or not.
539 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
541 #if !defined(USE_XCB)
542 xGLXIsDirectReq
*req
;
543 xGLXIsDirectReply reply
;
547 opcode
= __glXSetupForCommand(dpy
);
553 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
554 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
559 const Bool is_direct
= reply
->is_direct
? True
: False
;
564 /* Send the glXIsDirect request */
566 GetReq(GLXIsDirect
, req
);
567 req
->reqType
= opcode
;
568 req
->glxCode
= X_GLXIsDirect
;
569 req
->context
= contextID
;
570 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
574 return reply
.isDirect
;
580 * Shouldn't this function \b always return \c GL_FALSE when
581 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
582 * the GLX protocol here at all?
585 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
587 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
592 else if (gc
->isDirect
) {
595 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
598 return __glXIsDirect(dpy
, gc
->xid
);
603 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
605 #ifdef GLX_USE_APPLEGL
606 int screen
= vis
->screen
;
607 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
608 const struct glx_config
*config
;
610 config
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
612 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
617 xGLXCreateGLXPixmapReq
*req
;
621 opcode
= __glXSetupForCommand(dpy
);
626 /* Send the glXCreateGLXPixmap request */
628 GetReq(GLXCreateGLXPixmap
, req
);
629 req
->reqType
= opcode
;
630 req
->glxCode
= X_GLXCreateGLXPixmap
;
631 req
->screen
= vis
->screen
;
632 req
->visual
= vis
->visualid
;
633 req
->pixmap
= pixmap
;
634 req
->glxpixmap
= xid
= XAllocID(dpy
);
638 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
640 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
641 * is actually bound to a context... */
643 struct glx_display
*const priv
= __glXInitialize(dpy
);
644 __GLXDRIdrawable
*pdraw
;
645 struct glx_screen
*psc
;
646 struct glx_config
*config
;
648 psc
= priv
->screens
[vis
->screen
];
649 if (psc
->driScreen
== NULL
)
651 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
652 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, config
);
654 fprintf(stderr
, "failed to create pixmap\n");
658 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
659 (*pdraw
->destroyDrawable
) (pdraw
);
660 return None
; /* FIXME: Check what we're supposed to do here... */
670 ** Destroy the named pixmap
673 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
675 #ifdef GLX_USE_APPLEGL
676 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
677 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
679 xGLXDestroyGLXPixmapReq
*req
;
682 opcode
= __glXSetupForCommand(dpy
);
687 /* Send the glXDestroyGLXPixmap request */
689 GetReq(GLXDestroyGLXPixmap
, req
);
690 req
->reqType
= opcode
;
691 req
->glxCode
= X_GLXDestroyGLXPixmap
;
692 req
->glxpixmap
= glxpixmap
;
696 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
698 struct glx_display
*const priv
= __glXInitialize(dpy
);
699 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
702 (*pdraw
->destroyDrawable
) (pdraw
);
703 __glxHashDelete(priv
->drawHash
, glxpixmap
);
707 #endif /* GLX_USE_APPLEGL */
711 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
713 #ifdef GLX_USE_APPLEGL
714 GLXContext gc
= glXGetCurrentContext();
715 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
716 apple_glx_swap_buffers(gc
->driContext
);
718 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
721 struct glx_context
*gc
;
727 xGLXSwapBuffersReq
*req
;
730 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
731 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
735 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
740 opcode
= __glXSetupForCommand(dpy
);
746 ** The calling thread may or may not have a current context. If it
747 ** does, send the context tag so the server can do a flush.
749 gc
= __glXGetCurrentContext();
750 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
751 ((drawable
== gc
->currentDrawable
)
752 || (drawable
== gc
->currentReadable
))) {
753 tag
= gc
->currentContextTag
;
760 c
= XGetXCBConnection(dpy
);
761 xcb_glx_swap_buffers(c
, tag
, drawable
);
764 /* Send the glXSwapBuffers request */
766 GetReq(GLXSwapBuffers
, req
);
767 req
->reqType
= opcode
;
768 req
->glxCode
= X_GLXSwapBuffers
;
769 req
->drawable
= drawable
;
770 req
->contextTag
= tag
;
775 #endif /* GLX_USE_APPLEGL */
780 ** Return configuration information for the given display, screen and
781 ** visual combination.
784 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
787 struct glx_display
*priv
;
788 struct glx_screen
*psc
;
789 struct glx_config
*config
;
792 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
793 if (status
== Success
) {
794 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
796 /* Lookup attribute after first finding a match on the visual */
797 if (config
!= NULL
) {
798 return glx_config_get(config
, attribute
, value_return
);
801 status
= GLX_BAD_VISUAL
;
805 ** If we can't find the config for this visual, this visual is not
806 ** supported by the OpenGL implementation on the server.
808 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
809 *value_return
= GL_FALSE
;
816 /************************************************************************/
819 init_fbconfig_for_chooser(struct glx_config
* config
,
820 GLboolean fbconfig_style_tags
)
822 memset(config
, 0, sizeof(struct glx_config
));
823 config
->visualID
= (XID
) GLX_DONT_CARE
;
824 config
->visualType
= GLX_DONT_CARE
;
826 /* glXChooseFBConfig specifies different defaults for these two than
829 if (fbconfig_style_tags
) {
830 config
->rgbMode
= GL_TRUE
;
831 config
->doubleBufferMode
= GLX_DONT_CARE
;
834 config
->visualRating
= GLX_DONT_CARE
;
835 config
->transparentPixel
= GLX_NONE
;
836 config
->transparentRed
= GLX_DONT_CARE
;
837 config
->transparentGreen
= GLX_DONT_CARE
;
838 config
->transparentBlue
= GLX_DONT_CARE
;
839 config
->transparentAlpha
= GLX_DONT_CARE
;
840 config
->transparentIndex
= GLX_DONT_CARE
;
842 config
->drawableType
= GLX_WINDOW_BIT
;
844 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
845 config
->xRenderable
= GLX_DONT_CARE
;
846 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
848 config
->swapMethod
= GLX_DONT_CARE
;
851 #define MATCH_DONT_CARE( param ) \
853 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
854 && (a-> param != b-> param) ) { \
859 #define MATCH_MINIMUM( param ) \
861 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
862 && (a-> param > b-> param) ) { \
867 #define MATCH_EXACT( param ) \
869 if ( a-> param != b-> param) { \
874 /* Test that all bits from a are contained in b */
875 #define MATCH_MASK(param) \
877 if ((a->param & ~b->param) != 0) \
882 * Determine if two GLXFBConfigs are compatible.
884 * \param a Application specified config to test.
885 * \param b Server specified config to test against \c a.
888 fbconfigs_compatible(const struct glx_config
* const a
,
889 const struct glx_config
* const b
)
891 MATCH_DONT_CARE(doubleBufferMode
);
892 MATCH_DONT_CARE(visualType
);
893 MATCH_DONT_CARE(visualRating
);
894 MATCH_DONT_CARE(xRenderable
);
895 MATCH_DONT_CARE(fbconfigID
);
896 MATCH_DONT_CARE(swapMethod
);
898 MATCH_MINIMUM(rgbBits
);
899 MATCH_MINIMUM(numAuxBuffers
);
900 MATCH_MINIMUM(redBits
);
901 MATCH_MINIMUM(greenBits
);
902 MATCH_MINIMUM(blueBits
);
903 MATCH_MINIMUM(alphaBits
);
904 MATCH_MINIMUM(depthBits
);
905 MATCH_MINIMUM(stencilBits
);
906 MATCH_MINIMUM(accumRedBits
);
907 MATCH_MINIMUM(accumGreenBits
);
908 MATCH_MINIMUM(accumBlueBits
);
909 MATCH_MINIMUM(accumAlphaBits
);
910 MATCH_MINIMUM(sampleBuffers
);
911 MATCH_MINIMUM(maxPbufferWidth
);
912 MATCH_MINIMUM(maxPbufferHeight
);
913 MATCH_MINIMUM(maxPbufferPixels
);
914 MATCH_MINIMUM(samples
);
916 MATCH_DONT_CARE(stereoMode
);
919 MATCH_MASK(drawableType
);
920 MATCH_MASK(renderType
);
922 /* There is a bug in a few of the XFree86 DDX drivers. They contain
923 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
924 * Technically speaking, it is a bug in the DDX driver, but there is
925 * enough of an installed base to work around the problem here. In any
926 * case, 0 is not a valid value of the transparent type, so we'll treat 0
927 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
928 * 0 from the server to be a match to maintain backward compatibility with
929 * the (broken) drivers.
932 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
933 if (a
->transparentPixel
== GLX_NONE
) {
934 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
938 MATCH_EXACT(transparentPixel
);
941 switch (a
->transparentPixel
) {
942 case GLX_TRANSPARENT_RGB
:
943 MATCH_DONT_CARE(transparentRed
);
944 MATCH_DONT_CARE(transparentGreen
);
945 MATCH_DONT_CARE(transparentBlue
);
946 MATCH_DONT_CARE(transparentAlpha
);
949 case GLX_TRANSPARENT_INDEX
:
950 MATCH_DONT_CARE(transparentIndex
);
962 /* There's some trickly language in the GLX spec about how this is supposed
963 * to work. Basically, if a given component size is either not specified
964 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
965 * Well, that's really hard to do with the code as-is. This behavior is
966 * closer to correct, but still not technically right.
968 #define PREFER_LARGER_OR_ZERO(comp) \
970 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
971 if ( ((*a)-> comp) == 0 ) { \
974 else if ( ((*b)-> comp) == 0 ) { \
978 return ((*b)-> comp) - ((*a)-> comp) ; \
983 #define PREFER_LARGER(comp) \
985 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
986 return ((*b)-> comp) - ((*a)-> comp) ; \
990 #define PREFER_SMALLER(comp) \
992 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
993 return ((*a)-> comp) - ((*b)-> comp) ; \
998 * Compare two GLXFBConfigs. This function is intended to be used as the
999 * compare function passed in to qsort.
1001 * \returns If \c a is a "better" config, according to the specification of
1002 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1003 * better, then a number greater than zero is return. If both are
1004 * equal, zero is returned.
1005 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1008 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1010 /* The order of these comparisons must NOT change. It is defined by
1011 * the GLX 1.3 spec and ARB_multisample.
1014 PREFER_SMALLER(visualSelectGroup
);
1016 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1017 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1018 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1020 PREFER_SMALLER(visualRating
);
1022 /* This isn't quite right. It is supposed to compare the sum of the
1023 * components the user specifically set minimums for.
1025 PREFER_LARGER_OR_ZERO(redBits
);
1026 PREFER_LARGER_OR_ZERO(greenBits
);
1027 PREFER_LARGER_OR_ZERO(blueBits
);
1028 PREFER_LARGER_OR_ZERO(alphaBits
);
1030 PREFER_SMALLER(rgbBits
);
1032 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1033 /* Prefer single-buffer.
1035 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1038 PREFER_SMALLER(numAuxBuffers
);
1040 PREFER_LARGER_OR_ZERO(depthBits
);
1041 PREFER_SMALLER(stencilBits
);
1043 /* This isn't quite right. It is supposed to compare the sum of the
1044 * components the user specifically set minimums for.
1046 PREFER_LARGER_OR_ZERO(accumRedBits
);
1047 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1048 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1049 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1051 PREFER_SMALLER(visualType
);
1053 /* None of the multisample specs say where this comparison should happen,
1054 * so I put it near the end.
1056 PREFER_SMALLER(sampleBuffers
);
1057 PREFER_SMALLER(samples
);
1059 /* None of the pbuffer or fbconfig specs say that this comparison needs
1060 * to happen at all, but it seems like it should.
1062 PREFER_LARGER(maxPbufferWidth
);
1063 PREFER_LARGER(maxPbufferHeight
);
1064 PREFER_LARGER(maxPbufferPixels
);
1071 * Selects and sorts a subset of the supplied configs based on the attributes.
1072 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1073 * and \c glXChooseFBConfigSGIX.
1075 * \param configs Array of pointers to possible configs. The elements of
1076 * this array that do not meet the criteria will be set to
1077 * NULL. The remaining elements will be sorted according to
1078 * the various visual / FBConfig selection rules.
1079 * \param num_configs Number of elements in the \c configs array.
1080 * \param attribList Attributes used select from \c configs. This array is
1081 * terminated by a \c None tag. The array can either take
1082 * the form expected by \c glXChooseVisual (where boolean
1083 * tags do not have a value) or by \c glXChooseFBConfig
1084 * (where every tag has a value).
1085 * \param fbconfig_style_tags Selects whether \c attribList is in
1086 * \c glXChooseVisual style or
1087 * \c glXChooseFBConfig style.
1088 * \returns The number of valid elements left in \c configs.
1090 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1093 choose_visual(struct glx_config
** configs
, int num_configs
,
1094 const int *attribList
, GLboolean fbconfig_style_tags
)
1096 struct glx_config test_config
;
1100 /* This is a fairly direct implementation of the selection method
1101 * described by GLX_SGIX_fbconfig. Start by culling out all the
1102 * configs that are not compatible with the selected parameter
1106 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1107 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1108 (const INT32
*) attribList
,
1109 GL_TRUE
, fbconfig_style_tags
);
1112 for (i
= 0; i
< num_configs
; i
++) {
1113 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1114 configs
[base
] = configs
[i
];
1123 if (base
< num_configs
) {
1124 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1127 /* After the incompatible configs are removed, the resulting
1128 * list is sorted according to the rules set out in the various
1132 qsort(configs
, base
, sizeof(struct glx_config
*),
1133 (int (*)(const void *, const void *)) fbconfig_compare
);
1141 ** Return the visual that best matches the template. Return None if no
1142 ** visual matches the template.
1144 _X_EXPORT XVisualInfo
*
1145 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1147 XVisualInfo
*visualList
= NULL
;
1148 struct glx_display
*priv
;
1149 struct glx_screen
*psc
;
1150 struct glx_config test_config
;
1151 struct glx_config
*config
;
1152 struct glx_config
*best_config
= NULL
;
1155 ** Get a list of all visuals, return if list is empty
1157 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1163 ** Build a template from the defaults and the attribute list
1164 ** Free visual list and return if an unexpected token is encountered
1166 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1167 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1168 (const INT32
*) attribList
,
1172 ** Eliminate visuals that don't meet minimum requirements
1173 ** Compute a score for those that do
1174 ** Remember which visual, if any, got the highest score
1175 ** If no visual is acceptable, return None
1176 ** Otherwise, create an XVisualInfo list with just the selected X visual
1179 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1180 if (fbconfigs_compatible(&test_config
, config
)
1181 && ((best_config
== NULL
) ||
1182 (fbconfig_compare (&config
, &best_config
) < 0))) {
1183 XVisualInfo visualTemplate
;
1184 XVisualInfo
*newList
;
1187 visualTemplate
.screen
= screen
;
1188 visualTemplate
.visualid
= config
->visualID
;
1189 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1190 &visualTemplate
, &i
);
1194 visualList
= newList
;
1195 best_config
= config
;
1200 #ifdef GLX_USE_APPLEGL
1201 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1202 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1210 _X_EXPORT
const char *
1211 glXQueryExtensionsString(Display
* dpy
, int screen
)
1213 struct glx_screen
*psc
;
1214 struct glx_display
*priv
;
1216 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1220 if (!psc
->effectiveGLXexts
) {
1221 if (!psc
->serverGLXexts
) {
1222 psc
->serverGLXexts
=
1223 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1227 __glXCalculateUsableExtensions(psc
,
1228 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1229 (psc
->driScreen
!= NULL
),
1233 priv
->minorVersion
);
1236 return psc
->effectiveGLXexts
;
1239 _X_EXPORT
const char *
1240 glXGetClientString(Display
* dpy
, int name
)
1246 return (__glXGLXClientVendorName
);
1248 return (__glXGLXClientVersion
);
1249 case GLX_EXTENSIONS
:
1250 return (__glXGetClientExtensions());
1256 _X_EXPORT
const char *
1257 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1259 struct glx_screen
*psc
;
1260 struct glx_display
*priv
;
1264 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1270 str
= &priv
->serverGLXvendor
;
1273 str
= &priv
->serverGLXversion
;
1275 case GLX_EXTENSIONS
:
1276 str
= &psc
->serverGLXexts
;
1283 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1290 __glXClientInfo(Display
* dpy
, int opcode
)
1292 char *ext_str
= __glXGetClientGLExtensionString();
1293 int size
= strlen(ext_str
) + 1;
1296 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1297 xcb_glx_client_info(c
,
1298 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1300 xGLXClientInfoReq
*req
;
1302 /* Send the glXClientInfo request */
1304 GetReq(GLXClientInfo
, req
);
1305 req
->reqType
= opcode
;
1306 req
->glxCode
= X_GLXClientInfo
;
1307 req
->major
= GLX_MAJOR_VERSION
;
1308 req
->minor
= GLX_MINOR_VERSION
;
1310 req
->length
+= (size
+ 3) >> 2;
1311 req
->numbytes
= size
;
1312 Data(dpy
, ext_str
, size
);
1316 #endif /* USE_XCB */
1323 ** EXT_import_context
1327 glXGetCurrentDisplay(void)
1329 struct glx_context
*gc
= __glXGetCurrentContext();
1332 return gc
->currentDpy
;
1336 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1337 glXGetCurrentDisplay
)
1339 #ifndef GLX_USE_APPLEGL
1340 _X_EXPORT GLXContext
1341 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1343 struct glx_display
*priv
= __glXInitialize(dpy
);
1344 struct glx_screen
*psc
;
1345 xGLXQueryContextReply reply
;
1347 struct glx_context
*ctx
;
1348 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1351 struct glx_config
*mode
;
1353 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1356 opcode
= __glXSetupForCommand(dpy
);
1360 /* Send the glXQueryContextInfoEXT request */
1363 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1364 xGLXQueryContextReq
*req
;
1366 GetReq(GLXQueryContext
, req
);
1368 req
->reqType
= opcode
;
1369 req
->glxCode
= X_GLXQueryContext
;
1370 req
->context
= contextID
;
1373 xGLXVendorPrivateReq
*vpreq
;
1374 xGLXQueryContextInfoEXTReq
*req
;
1376 GetReqExtra(GLXVendorPrivate
,
1377 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1379 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1380 req
->reqType
= opcode
;
1381 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1382 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1383 req
->context
= contextID
;
1386 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1388 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1389 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1392 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1396 /* Look up screen first so we can look up visuals/fbconfigs later */
1398 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1399 if (pProp
[0] == GLX_SCREEN
)
1400 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1409 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1411 case GLX_SHARE_CONTEXT_EXT
:
1414 case GLX_VISUAL_ID_EXT
:
1415 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1417 case GLX_FBCONFIG_ID
:
1418 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1420 case GLX_RENDER_TYPE
:
1421 renderType
= pProp
[1];
1428 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1432 ctx
->xid
= contextID
;
1433 ctx
->imported
= GL_TRUE
;
1434 ctx
->share_xid
= share
;
1436 return (GLXContext
) ctx
;
1442 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1444 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1446 switch (attribute
) {
1447 case GLX_SHARE_CONTEXT_EXT
:
1448 *value
= ctx
->share_xid
;
1450 case GLX_VISUAL_ID_EXT
:
1451 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1454 *value
= ctx
->screen
;
1456 case GLX_FBCONFIG_ID
:
1457 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1459 case GLX_RENDER_TYPE
:
1460 *value
= ctx
->renderType
;
1463 return GLX_BAD_ATTRIBUTE
;
1469 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1470 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1471 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1473 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1475 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1481 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1483 DestroyContext(dpy
, ctx
);
1487 _X_EXPORT GLXFBConfig
*
1488 glXChooseFBConfig(Display
* dpy
, int screen
,
1489 const int *attribList
, int *nitems
)
1491 struct glx_config
**config_list
;
1495 config_list
= (struct glx_config
**)
1496 glXGetFBConfigs(dpy
, screen
, &list_size
);
1498 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1499 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1500 if (list_size
== 0) {
1506 *nitems
= list_size
;
1507 return (GLXFBConfig
*) config_list
;
1511 _X_EXPORT GLXContext
1512 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1513 int renderType
, GLXContext shareList
, Bool allowDirect
)
1515 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1517 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1518 allowDirect
, X_GLXCreateNewContext
, renderType
,
1523 _X_EXPORT GLXDrawable
1524 glXGetCurrentReadDrawable(void)
1526 struct glx_context
*gc
= __glXGetCurrentContext();
1528 return gc
->currentReadable
;
1532 _X_EXPORT GLXFBConfig
*
1533 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1535 struct glx_display
*priv
= __glXInitialize(dpy
);
1536 struct glx_config
**config_list
= NULL
;
1537 struct glx_config
*config
;
1538 unsigned num_configs
= 0;
1542 if (priv
&& (priv
->screens
!= NULL
)
1543 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1544 && (priv
->screens
[screen
]->configs
!= NULL
)
1545 && (priv
->screens
[screen
]->configs
->fbconfigID
1546 != (int) GLX_DONT_CARE
)) {
1548 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1549 config
= config
->next
) {
1550 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1555 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1556 if (config_list
!= NULL
) {
1557 *nelements
= num_configs
;
1559 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1560 config
= config
->next
) {
1561 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1562 config_list
[i
] = config
;
1569 return (GLXFBConfig
*) config_list
;
1574 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1575 int attribute
, int *value
)
1577 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1580 return GLXBadFBConfig
;
1582 return glx_config_get(config
, attribute
, value
);
1586 _X_EXPORT XVisualInfo
*
1587 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1589 XVisualInfo visualTemplate
;
1590 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1594 ** Get a list of all visuals, return if list is empty
1596 visualTemplate
.visualid
= config
->visualID
;
1597 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1600 #ifndef GLX_USE_APPLEGL
1602 ** GLX_SGI_swap_control
1605 __glXSwapIntervalSGI(int interval
)
1607 xGLXVendorPrivateReq
*req
;
1608 struct glx_context
*gc
= __glXGetCurrentContext();
1609 struct glx_screen
*psc
;
1611 CARD32
*interval_ptr
;
1615 return GLX_BAD_CONTEXT
;
1618 if (interval
<= 0) {
1619 return GLX_BAD_VALUE
;
1622 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1624 #ifdef GLX_DIRECT_RENDERING
1625 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1626 __GLXDRIdrawable
*pdraw
=
1627 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1628 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1633 dpy
= gc
->currentDpy
;
1634 opcode
= __glXSetupForCommand(dpy
);
1639 /* Send the glXSwapIntervalSGI request */
1641 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1642 req
->reqType
= opcode
;
1643 req
->glxCode
= X_GLXVendorPrivate
;
1644 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1645 req
->contextTag
= gc
->currentContextTag
;
1647 interval_ptr
= (CARD32
*) (req
+ 1);
1648 *interval_ptr
= interval
;
1659 ** GLX_MESA_swap_control
1662 __glXSwapIntervalMESA(unsigned int interval
)
1664 #ifdef GLX_DIRECT_RENDERING
1665 struct glx_context
*gc
= __glXGetCurrentContext();
1667 if (gc
!= NULL
&& gc
->isDirect
) {
1668 struct glx_screen
*psc
;
1670 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1671 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1672 __GLXDRIdrawable
*pdraw
=
1673 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1674 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1679 return GLX_BAD_CONTEXT
;
1684 __glXGetSwapIntervalMESA(void)
1686 #ifdef GLX_DIRECT_RENDERING
1687 struct glx_context
*gc
= __glXGetCurrentContext();
1689 if (gc
!= NULL
&& gc
->isDirect
) {
1690 struct glx_screen
*psc
;
1692 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1693 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1694 __GLXDRIdrawable
*pdraw
=
1695 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1696 return psc
->driScreen
->getSwapInterval(pdraw
);
1706 ** GLX_SGI_video_sync
1709 __glXGetVideoSyncSGI(unsigned int *count
)
1711 int64_t ust
, msc
, sbc
;
1713 struct glx_context
*gc
= __glXGetCurrentContext();
1714 struct glx_screen
*psc
;
1715 #ifdef GLX_DIRECT_RENDERING
1716 __GLXDRIdrawable
*pdraw
;
1720 return GLX_BAD_CONTEXT
;
1722 #ifdef GLX_DIRECT_RENDERING
1724 return GLX_BAD_CONTEXT
;
1727 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1728 #ifdef GLX_DIRECT_RENDERING
1729 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1732 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1733 * FIXME: there should be a GLX encoding for this call. I can find no
1734 * FIXME: documentation for the GLX encoding.
1736 #ifdef GLX_DIRECT_RENDERING
1737 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1738 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1739 *count
= (unsigned) msc
;
1740 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1744 return GLX_BAD_CONTEXT
;
1748 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1750 struct glx_context
*gc
= __glXGetCurrentContext();
1751 struct glx_screen
*psc
;
1752 #ifdef GLX_DIRECT_RENDERING
1753 __GLXDRIdrawable
*pdraw
;
1755 int64_t ust
, msc
, sbc
;
1758 if (divisor
<= 0 || remainder
< 0)
1759 return GLX_BAD_VALUE
;
1762 return GLX_BAD_CONTEXT
;
1764 #ifdef GLX_DIRECT_RENDERING
1766 return GLX_BAD_CONTEXT
;
1769 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1770 #ifdef GLX_DIRECT_RENDERING
1771 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1774 #ifdef GLX_DIRECT_RENDERING
1775 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1776 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1778 *count
= (unsigned) msc
;
1779 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1783 return GLX_BAD_CONTEXT
;
1786 #endif /* GLX_USE_APPLEGL */
1789 ** GLX_SGIX_fbconfig
1790 ** Many of these functions are aliased to GLX 1.3 entry points in the
1791 ** GLX_functions table.
1795 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1796 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1797 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1799 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1800 (Display
* dpy
, int screen
, int *attrib_list
,
1801 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1804 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1805 (Display
* dpy
, GLXFBConfigSGIX config
),
1806 (dpy
, config
), glXGetVisualFromFBConfig
)
1809 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1810 GLXFBConfigSGIX fbconfig
,
1813 #ifndef GLX_USE_APPLEGL
1814 xGLXVendorPrivateWithReplyReq
*vpreq
;
1815 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1816 GLXPixmap xid
= None
;
1818 struct glx_screen
*psc
;
1820 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1823 if ((dpy
== NULL
) || (config
== NULL
)) {
1826 #ifdef GLX_USE_APPLEGL
1827 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1832 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1834 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1835 opcode
= __glXSetupForCommand(dpy
);
1840 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1842 GetReqExtra(GLXVendorPrivateWithReply
,
1843 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1844 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1845 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1846 req
->reqType
= opcode
;
1847 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1848 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1849 req
->screen
= config
->screen
;
1850 req
->fbconfig
= config
->fbconfigID
;
1851 req
->pixmap
= pixmap
;
1852 req
->glxpixmap
= xid
= XAllocID(dpy
);
1861 _X_EXPORT GLXContext
1862 glXCreateContextWithConfigSGIX(Display
* dpy
,
1863 GLXFBConfigSGIX fbconfig
, int renderType
,
1864 GLXContext shareList
, Bool allowDirect
)
1866 GLXContext gc
= NULL
;
1867 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1868 struct glx_screen
*psc
;
1871 if ((dpy
== NULL
) || (config
== NULL
)) {
1875 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1877 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1878 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1880 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1888 _X_EXPORT GLXFBConfigSGIX
1889 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1891 struct glx_display
*priv
;
1892 struct glx_screen
*psc
= NULL
;
1894 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
1895 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1896 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1897 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1904 #ifndef GLX_USE_APPLEGL
1906 ** GLX_SGIX_swap_group
1909 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1919 ** GLX_SGIX_swap_barrier
1922 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1930 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
1940 ** GLX_OML_sync_control
1943 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
1944 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
1946 struct glx_display
* const priv
= __glXInitialize(dpy
);
1948 #ifdef GLX_DIRECT_RENDERING
1949 __GLXDRIdrawable
*pdraw
;
1951 struct glx_screen
*psc
;
1956 #ifdef GLX_DIRECT_RENDERING
1957 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1958 psc
= pdraw
? pdraw
->psc
: NULL
;
1959 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
1960 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
1968 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1970 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
1971 int32_t * numerator
, int32_t * denominator
)
1974 struct glx_screen
*psc
;
1975 XF86VidModeModeLine mode_line
;
1980 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
1981 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
1982 unsigned n
= dot_clock
* 1000;
1983 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
1985 # define V_INTERLACE 0x010
1986 # define V_DBLSCAN 0x020
1988 if (mode_line
.flags
& V_INTERLACE
)
1990 else if (mode_line
.flags
& V_DBLSCAN
)
1993 /* The OML_sync_control spec requires that if the refresh rate is a
1994 * whole number, that the returned numerator be equal to the refresh
1995 * rate and the denominator be 1.
2003 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2005 /* This is a poor man's way to reduce a fraction. It's far from
2006 * perfect, but it will work well enough for this situation.
2009 for (i
= 0; f
[i
] != 0; i
++) {
2010 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2030 * Determine the refresh rate of the specified drawable and display.
2032 * \param dpy Display whose refresh rate is to be determined.
2033 * \param drawable Drawable whose refresh rate is to be determined.
2034 * \param numerator Numerator of the refresh rate.
2035 * \param demoninator Denominator of the refresh rate.
2036 * \return If the refresh rate for the specified display and drawable could
2037 * be calculated, True is returned. Otherwise False is returned.
2039 * \note This function is implemented entirely client-side. A lot of other
2040 * functionality is required to export GLX_OML_sync_control, so on
2041 * XFree86 this function can be called for direct-rendering contexts
2042 * when GLX_OML_sync_control appears in the client extension string.
2046 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2047 int32_t * numerator
, int32_t * denominator
)
2049 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2050 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2055 return __glxGetMscRate(draw
, numerator
, denominator
);
2067 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2068 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2070 struct glx_context
*gc
= __glXGetCurrentContext();
2071 #ifdef GLX_DIRECT_RENDERING
2072 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2073 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2076 if (!gc
) /* no GLX for this */
2079 #ifdef GLX_DIRECT_RENDERING
2080 if (!pdraw
|| !gc
->isDirect
)
2084 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2085 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2086 * of -1 if the function failed because of errors detected in the input
2089 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2091 if (divisor
> 0 && remainder
>= divisor
)
2094 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2097 #ifdef GLX_DIRECT_RENDERING
2098 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2099 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2108 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2109 int64_t target_msc
, int64_t divisor
,
2110 int64_t remainder
, int64_t * ust
,
2111 int64_t * msc
, int64_t * sbc
)
2113 #ifdef GLX_DIRECT_RENDERING
2114 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2115 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2120 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2121 * error", but the return type in the spec is Bool.
2123 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2125 if (divisor
> 0 && remainder
>= divisor
)
2128 #ifdef GLX_DIRECT_RENDERING
2129 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2130 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2141 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2142 int64_t target_sbc
, int64_t * ust
,
2143 int64_t * msc
, int64_t * sbc
)
2145 #ifdef GLX_DIRECT_RENDERING
2146 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2147 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2151 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2152 * error", but the return type in the spec is Bool.
2157 #ifdef GLX_DIRECT_RENDERING
2158 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2159 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2171 * Mesa extension stubs. These will help reduce portability problems.
2176 * Release all buffers associated with the specified GLX drawable.
2179 * This function was intended for stand-alone Mesa. The issue there is that
2180 * the library doesn't get any notification when a window is closed. In
2181 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2182 * supported, there are 3 different functions to destroy a drawable. It
2183 * should be possible to create GLX protocol (or have it determine which
2184 * protocol to use based on the type of the drawable) to have one function
2185 * do the work of 3. For the direct-rendering case, this function could
2186 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2187 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2188 * would need to be used. This really should be done as part of the new DRI
2191 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2192 * __driGarbageCollectDrawables
2193 * glXDestroyGLXPixmap
2194 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2195 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2198 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2207 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2208 Pixmap pixmap
, Colormap cmap
)
2221 * GLX_MESA_copy_sub_buffer
2223 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2225 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2226 int x
, int y
, int width
, int height
)
2228 xGLXVendorPrivateReq
*req
;
2229 struct glx_context
*gc
;
2231 CARD32
*drawable_ptr
;
2232 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2235 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2236 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2237 if (pdraw
!= NULL
) {
2238 struct glx_screen
*psc
= pdraw
->psc
;
2239 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2241 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2248 opcode
= __glXSetupForCommand(dpy
);
2253 ** The calling thread may or may not have a current context. If it
2254 ** does, send the context tag so the server can do a flush.
2256 gc
= __glXGetCurrentContext();
2257 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2258 ((drawable
== gc
->currentDrawable
) ||
2259 (drawable
== gc
->currentReadable
))) {
2260 tag
= gc
->currentContextTag
;
2267 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2268 req
->reqType
= opcode
;
2269 req
->glxCode
= X_GLXVendorPrivate
;
2270 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2271 req
->contextTag
= tag
;
2273 drawable_ptr
= (CARD32
*) (req
+ 1);
2274 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2275 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2276 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2277 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2279 *drawable_ptr
= drawable
;
2291 __glXBindTexImageEXT(Display
* dpy
,
2292 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2294 struct glx_context
*gc
= __glXGetCurrentContext();
2296 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2299 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2303 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2305 struct glx_context
*gc
= __glXGetCurrentContext();
2307 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2310 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2315 #endif /* GLX_USE_APPLEGL */
2318 * \c strdup is actually not a standard ANSI C or POSIX routine.
2319 * Irix will not define it if ANSI mode is in effect.
2324 __glXstrdup(const char *str
)
2327 copy
= (char *) Xmalloc(strlen(str
) + 1);
2335 ** glXGetProcAddress support
2338 struct name_address_pair
2344 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2345 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2347 static const struct name_address_pair GLX_functions
[] = {
2348 /*** GLX_VERSION_1_0 ***/
2349 GLX_FUNCTION(glXChooseVisual
),
2350 GLX_FUNCTION(glXCopyContext
),
2351 GLX_FUNCTION(glXCreateContext
),
2352 GLX_FUNCTION(glXCreateGLXPixmap
),
2353 GLX_FUNCTION(glXDestroyContext
),
2354 GLX_FUNCTION(glXDestroyGLXPixmap
),
2355 GLX_FUNCTION(glXGetConfig
),
2356 GLX_FUNCTION(glXGetCurrentContext
),
2357 GLX_FUNCTION(glXGetCurrentDrawable
),
2358 GLX_FUNCTION(glXIsDirect
),
2359 GLX_FUNCTION(glXMakeCurrent
),
2360 GLX_FUNCTION(glXQueryExtension
),
2361 GLX_FUNCTION(glXQueryVersion
),
2362 GLX_FUNCTION(glXSwapBuffers
),
2363 GLX_FUNCTION(glXUseXFont
),
2364 GLX_FUNCTION(glXWaitGL
),
2365 GLX_FUNCTION(glXWaitX
),
2367 /*** GLX_VERSION_1_1 ***/
2368 GLX_FUNCTION(glXGetClientString
),
2369 GLX_FUNCTION(glXQueryExtensionsString
),
2370 GLX_FUNCTION(glXQueryServerString
),
2372 /*** GLX_VERSION_1_2 ***/
2373 GLX_FUNCTION(glXGetCurrentDisplay
),
2375 /*** GLX_VERSION_1_3 ***/
2376 GLX_FUNCTION(glXChooseFBConfig
),
2377 GLX_FUNCTION(glXCreateNewContext
),
2378 GLX_FUNCTION(glXCreatePbuffer
),
2379 GLX_FUNCTION(glXCreatePixmap
),
2380 GLX_FUNCTION(glXCreateWindow
),
2381 GLX_FUNCTION(glXDestroyPbuffer
),
2382 GLX_FUNCTION(glXDestroyPixmap
),
2383 GLX_FUNCTION(glXDestroyWindow
),
2384 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2385 GLX_FUNCTION(glXGetFBConfigAttrib
),
2386 GLX_FUNCTION(glXGetFBConfigs
),
2387 GLX_FUNCTION(glXGetSelectedEvent
),
2388 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2389 GLX_FUNCTION(glXMakeContextCurrent
),
2390 GLX_FUNCTION(glXQueryContext
),
2391 GLX_FUNCTION(glXQueryDrawable
),
2392 GLX_FUNCTION(glXSelectEvent
),
2394 #ifndef GLX_USE_APPLEGL
2395 /*** GLX_SGI_swap_control ***/
2396 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2398 /*** GLX_SGI_video_sync ***/
2399 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2400 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2402 /*** GLX_SGI_make_current_read ***/
2403 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2404 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2406 /*** GLX_EXT_import_context ***/
2407 GLX_FUNCTION(glXFreeContextEXT
),
2408 GLX_FUNCTION(glXGetContextIDEXT
),
2409 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2410 GLX_FUNCTION(glXImportContextEXT
),
2411 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2414 /*** GLX_SGIX_fbconfig ***/
2415 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2416 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2417 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2418 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2419 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2420 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2422 #ifndef GLX_USE_APPLEGL
2423 /*** GLX_SGIX_pbuffer ***/
2424 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2425 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2426 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2427 GLX_FUNCTION(glXSelectEventSGIX
),
2428 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2430 /*** GLX_SGIX_swap_group ***/
2431 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2433 /*** GLX_SGIX_swap_barrier ***/
2434 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2435 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2437 /*** GLX_MESA_copy_sub_buffer ***/
2438 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2440 /*** GLX_MESA_pixmap_colormap ***/
2441 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2443 /*** GLX_MESA_release_buffers ***/
2444 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2446 /*** GLX_MESA_swap_control ***/
2447 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2448 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2451 /*** GLX_ARB_get_proc_address ***/
2452 GLX_FUNCTION(glXGetProcAddressARB
),
2455 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2457 #ifndef GLX_USE_APPLEGL
2458 /*** GLX_OML_sync_control ***/
2459 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2460 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2461 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2462 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2463 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2465 /*** GLX_EXT_texture_from_pixmap ***/
2466 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2467 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2470 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2471 /*** DRI configuration ***/
2472 GLX_FUNCTION(glXGetScreenDriver
),
2473 GLX_FUNCTION(glXGetDriverConfig
),
2476 {NULL
, NULL
} /* end of list */
2479 #ifndef GLX_USE_APPLEGL
2480 static const GLvoid
*
2481 get_glx_proc_address(const char *funcName
)
2485 /* try static functions */
2486 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2487 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2488 return GLX_functions
[i
].Address
;
2496 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2497 * \c glXGetProcAddress.
2499 * \param procName Name of a GL or GLX function.
2500 * \returns A pointer to the named function
2502 * \sa glXGetProcAddress
2504 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2506 typedef void (*gl_function
) (void);
2510 /* Search the table of GLX and internal functions first. If that
2511 * fails and the supplied name could be a valid core GL name, try
2512 * searching the core GL function table. This check is done to prevent
2513 * DRI based drivers from searching the core GL function table for
2514 * internal API functions.
2516 #ifdef GLX_USE_APPLEGL
2517 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2519 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2520 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2521 && (procName
[2] != 'X')) {
2522 #ifdef GLX_SHARED_GLAPI
2523 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2526 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2533 * Get the address of a named GL function. This is the GLX 1.4 name for
2534 * \c glXGetProcAddressARB.
2536 * \param procName Name of a GL or GLX function.
2537 * \returns A pointer to the named function
2539 * \sa glXGetProcAddressARB
2541 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2542 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2543 __attribute__ ((alias("glXGetProcAddressARB")));
2546 return glXGetProcAddressARB(procName
);
2548 #endif /* __GNUC__ */
2551 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2553 * Get the unadjusted system time (UST). Currently, the UST is measured in
2554 * microseconds since Epoc. The actual resolution of the UST may vary from
2555 * system to system, and the units may vary from release to release.
2556 * Drivers should not call this function directly. They should instead use
2557 * \c glXGetProcAddress to obtain a pointer to the function.
2559 * \param ust Location to store the 64-bit UST
2560 * \returns Zero on success or a negative errno value on failure.
2562 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2564 * \since Internal API version 20030317.
2567 __glXGetUST(int64_t * ust
)
2575 if (gettimeofday(&tv
, NULL
) == 0) {
2576 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2583 #endif /* GLX_DIRECT_RENDERING */