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.
205 * \param renderType For FBConfigs, what is the rendering type?
209 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
210 GLXContext shareList_user
, Bool allowDirect
,
211 unsigned code
, int renderType
, int screen
)
213 struct glx_context
*gc
;
214 struct glx_screen
*psc
;
215 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
219 psc
= GetGLXScreenConfigs(dpy
, screen
);
223 if (generic_id
== None
)
227 #ifdef GLX_USE_APPLEGL
228 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
230 if (allowDirect
&& psc
->vtable
->create_context
)
231 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
233 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
240 case X_GLXCreateContext
: {
241 xGLXCreateContextReq
*req
;
243 /* Send the glXCreateContext request */
244 GetReq(GLXCreateContext
, req
);
245 req
->reqType
= gc
->majorOpcode
;
246 req
->glxCode
= X_GLXCreateContext
;
247 req
->context
= gc
->xid
= XAllocID(dpy
);
248 req
->visual
= generic_id
;
249 req
->screen
= screen
;
250 req
->shareList
= shareList
? shareList
->xid
: None
;
251 req
->isDirect
= gc
->isDirect
;
255 case X_GLXCreateNewContext
: {
256 xGLXCreateNewContextReq
*req
;
258 /* Send the glXCreateNewContext request */
259 GetReq(GLXCreateNewContext
, req
);
260 req
->reqType
= gc
->majorOpcode
;
261 req
->glxCode
= X_GLXCreateNewContext
;
262 req
->context
= gc
->xid
= XAllocID(dpy
);
263 req
->fbconfig
= generic_id
;
264 req
->screen
= screen
;
265 req
->renderType
= renderType
;
266 req
->shareList
= shareList
? shareList
->xid
: None
;
267 req
->isDirect
= gc
->isDirect
;
271 case X_GLXvop_CreateContextWithConfigSGIX
: {
272 xGLXVendorPrivateWithReplyReq
*vpreq
;
273 xGLXCreateContextWithConfigSGIXReq
*req
;
275 /* Send the glXCreateNewContext request */
276 GetReqExtra(GLXVendorPrivateWithReply
,
277 sz_xGLXCreateContextWithConfigSGIXReq
-
278 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
279 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
280 req
->reqType
= gc
->majorOpcode
;
281 req
->glxCode
= X_GLXVendorPrivateWithReply
;
282 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
283 req
->context
= gc
->xid
= XAllocID(dpy
);
284 req
->fbconfig
= generic_id
;
285 req
->screen
= screen
;
286 req
->renderType
= renderType
;
287 req
->shareList
= shareList
? shareList
->xid
: None
;
288 req
->isDirect
= gc
->isDirect
;
293 /* What to do here? This case is the sign of an internal error. It
294 * should never be reachable.
302 gc
->imported
= GL_FALSE
;
303 gc
->renderType
= renderType
;
305 return (GLXContext
) gc
;
309 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
310 GLXContext shareList
, Bool allowDirect
)
312 struct glx_config
*config
= NULL
;
315 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
316 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
318 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
319 if (config
== NULL
) {
322 error
.errorCode
= BadValue
;
323 error
.resourceID
= vis
->visualid
;
324 error
.sequenceNumber
= dpy
->request
;
325 error
.type
= X_Error
;
326 error
.majorCode
= __glXSetupForCommand(dpy
);
327 error
.minorCode
= X_GLXCreateContext
;
328 _XError(dpy
, &error
);
332 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
335 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
336 X_GLXCreateContext
, renderType
, vis
->screen
);
340 glx_send_destroy_context(Display
*dpy
, XID xid
)
342 CARD8 opcode
= __glXSetupForCommand(dpy
);
343 xGLXDestroyContextReq
*req
;
346 GetReq(GLXDestroyContext
, req
);
347 req
->reqType
= opcode
;
348 req
->glxCode
= X_GLXDestroyContext
;
355 ** Destroy the named context
358 DestroyContext(Display
* dpy
, GLXContext ctx
)
360 struct glx_context
*gc
= (struct glx_context
*) ctx
;
366 if (gc
->currentDpy
) {
367 /* This context is bound to some thread. According to the man page,
368 * we should not actually delete the context until it's unbound.
369 * Note that we set gc->xid = None above. In MakeContextCurrent()
370 * we check for that and delete the context there.
373 glx_send_destroy_context(dpy
, gc
->xid
);
380 gc
->vtable
->destroy(gc
);
384 glXDestroyContext(Display
* dpy
, GLXContext gc
)
386 DestroyContext(dpy
, gc
);
390 ** Return the major and minor version #s for the GLX extension
393 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
395 struct glx_display
*priv
;
397 /* Init the extension. This fetches the major and minor version. */
398 priv
= __glXInitialize(dpy
);
403 *major
= priv
->majorVersion
;
405 *minor
= priv
->minorVersion
;
410 ** Query the existance of the GLX extension
413 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
415 int major_op
, erb
, evb
;
418 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
429 ** Put a barrier in the token stream that forces the GL to finish its
430 ** work before X can proceed.
435 struct glx_context
*gc
= __glXGetCurrentContext();
437 if (gc
&& gc
->vtable
->wait_gl
)
438 gc
->vtable
->wait_gl(gc
);
442 ** Put a barrier in the token stream that forces X to finish its
443 ** work before GL can proceed.
448 struct glx_context
*gc
= __glXGetCurrentContext();
450 if (gc
&& gc
->vtable
->wait_x
)
451 gc
->vtable
->wait_x(gc
);
455 glXUseXFont(Font font
, int first
, int count
, int listBase
)
457 struct glx_context
*gc
= __glXGetCurrentContext();
459 if (gc
&& gc
->vtable
->use_x_font
)
460 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
463 /************************************************************************/
466 ** Copy the source context to the destination context using the
470 glXCopyContext(Display
* dpy
, GLXContext source_user
,
471 GLXContext dest_user
, unsigned long mask
)
473 struct glx_context
*source
= (struct glx_context
*) source_user
;
474 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
475 #ifdef GLX_USE_APPLEGL
476 struct glx_context
*gc
= __glXGetCurrentContext();
480 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
481 mask
, &errorcode
, &x11error
)) {
482 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
486 xGLXCopyContextReq
*req
;
487 struct glx_context
*gc
= __glXGetCurrentContext();
491 opcode
= __glXSetupForCommand(dpy
);
496 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
498 /* NOT_DONE: This does not work yet */
503 ** If the source is the current context, send its tag so that the context
504 ** can be flushed before the copy.
506 if (source
== gc
&& dpy
== gc
->currentDpy
) {
507 tag
= gc
->currentContextTag
;
513 /* Send the glXCopyContext request */
515 GetReq(GLXCopyContext
, req
);
516 req
->reqType
= opcode
;
517 req
->glxCode
= X_GLXCopyContext
;
518 req
->source
= source
? source
->xid
: None
;
519 req
->dest
= dest
? dest
->xid
: None
;
521 req
->contextTag
= tag
;
524 #endif /* GLX_USE_APPLEGL */
529 * Determine if a context uses direct rendering.
531 * \param dpy Display where the context was created.
532 * \param contextID ID of the context to be tested.
534 * \returns \c GL_TRUE if the context is direct rendering or not.
537 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
539 #if !defined(USE_XCB)
540 xGLXIsDirectReq
*req
;
541 xGLXIsDirectReply reply
;
545 opcode
= __glXSetupForCommand(dpy
);
551 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
552 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
557 const Bool is_direct
= reply
->is_direct
? True
: False
;
562 /* Send the glXIsDirect request */
564 GetReq(GLXIsDirect
, req
);
565 req
->reqType
= opcode
;
566 req
->glxCode
= X_GLXIsDirect
;
567 req
->context
= contextID
;
568 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
572 return reply
.isDirect
;
578 * Shouldn't this function \b always return \c GL_FALSE when
579 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
580 * the GLX protocol here at all?
583 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
585 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
590 else if (gc
->isDirect
) {
593 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
596 return __glXIsDirect(dpy
, gc
->xid
);
601 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
603 #ifdef GLX_USE_APPLEGL
604 int screen
= vis
->screen
;
605 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
606 const struct glx_config
*config
;
608 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
610 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
615 xGLXCreateGLXPixmapReq
*req
;
619 opcode
= __glXSetupForCommand(dpy
);
624 /* Send the glXCreateGLXPixmap request */
626 GetReq(GLXCreateGLXPixmap
, req
);
627 req
->reqType
= opcode
;
628 req
->glxCode
= X_GLXCreateGLXPixmap
;
629 req
->screen
= vis
->screen
;
630 req
->visual
= vis
->visualid
;
631 req
->pixmap
= pixmap
;
632 req
->glxpixmap
= xid
= XAllocID(dpy
);
636 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
638 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
639 * is actually bound to a context... */
641 struct glx_display
*const priv
= __glXInitialize(dpy
);
642 __GLXDRIdrawable
*pdraw
;
643 struct glx_screen
*psc
;
644 struct glx_config
*config
;
646 psc
= priv
->screens
[vis
->screen
];
647 if (psc
->driScreen
== NULL
)
649 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
650 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
652 fprintf(stderr
, "failed to create pixmap\n");
656 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
657 (*pdraw
->destroyDrawable
) (pdraw
);
658 return None
; /* FIXME: Check what we're supposed to do here... */
668 ** Destroy the named pixmap
671 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
673 #ifdef GLX_USE_APPLEGL
674 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
675 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
677 xGLXDestroyGLXPixmapReq
*req
;
680 opcode
= __glXSetupForCommand(dpy
);
685 /* Send the glXDestroyGLXPixmap request */
687 GetReq(GLXDestroyGLXPixmap
, req
);
688 req
->reqType
= opcode
;
689 req
->glxCode
= X_GLXDestroyGLXPixmap
;
690 req
->glxpixmap
= glxpixmap
;
694 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
696 struct glx_display
*const priv
= __glXInitialize(dpy
);
697 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
700 (*pdraw
->destroyDrawable
) (pdraw
);
701 __glxHashDelete(priv
->drawHash
, glxpixmap
);
705 #endif /* GLX_USE_APPLEGL */
709 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
711 #ifdef GLX_USE_APPLEGL
712 struct glx_context
* gc
= __glXGetCurrentContext();
713 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
714 apple_glx_swap_buffers(gc
->driContext
);
716 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
719 struct glx_context
*gc
;
725 xGLXSwapBuffersReq
*req
;
728 gc
= __glXGetCurrentContext();
730 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
731 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
734 if (gc
&& drawable
== gc
->currentDrawable
) {
738 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
743 opcode
= __glXSetupForCommand(dpy
);
749 ** The calling thread may or may not have a current context. If it
750 ** does, send the context tag so the server can do a flush.
752 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
753 ((drawable
== gc
->currentDrawable
)
754 || (drawable
== gc
->currentReadable
))) {
755 tag
= gc
->currentContextTag
;
762 c
= XGetXCBConnection(dpy
);
763 xcb_glx_swap_buffers(c
, tag
, drawable
);
766 /* Send the glXSwapBuffers request */
768 GetReq(GLXSwapBuffers
, req
);
769 req
->reqType
= opcode
;
770 req
->glxCode
= X_GLXSwapBuffers
;
771 req
->drawable
= drawable
;
772 req
->contextTag
= tag
;
777 #endif /* GLX_USE_APPLEGL */
782 ** Return configuration information for the given display, screen and
783 ** visual combination.
786 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
789 struct glx_display
*priv
;
790 struct glx_screen
*psc
;
791 struct glx_config
*config
;
794 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
795 if (status
== Success
) {
796 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
798 /* Lookup attribute after first finding a match on the visual */
799 if (config
!= NULL
) {
800 return glx_config_get(config
, attribute
, value_return
);
803 status
= GLX_BAD_VISUAL
;
807 ** If we can't find the config for this visual, this visual is not
808 ** supported by the OpenGL implementation on the server.
810 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
811 *value_return
= GL_FALSE
;
818 /************************************************************************/
821 init_fbconfig_for_chooser(struct glx_config
* config
,
822 GLboolean fbconfig_style_tags
)
824 memset(config
, 0, sizeof(struct glx_config
));
825 config
->visualID
= (XID
) GLX_DONT_CARE
;
826 config
->visualType
= GLX_DONT_CARE
;
828 /* glXChooseFBConfig specifies different defaults for these two than
831 if (fbconfig_style_tags
) {
832 config
->rgbMode
= GL_TRUE
;
833 config
->doubleBufferMode
= GLX_DONT_CARE
;
836 config
->visualRating
= GLX_DONT_CARE
;
837 config
->transparentPixel
= GLX_NONE
;
838 config
->transparentRed
= GLX_DONT_CARE
;
839 config
->transparentGreen
= GLX_DONT_CARE
;
840 config
->transparentBlue
= GLX_DONT_CARE
;
841 config
->transparentAlpha
= GLX_DONT_CARE
;
842 config
->transparentIndex
= GLX_DONT_CARE
;
844 config
->drawableType
= GLX_WINDOW_BIT
;
846 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
847 config
->xRenderable
= GLX_DONT_CARE
;
848 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
850 config
->swapMethod
= GLX_DONT_CARE
;
853 #define MATCH_DONT_CARE( param ) \
855 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
856 && (a-> param != b-> param) ) { \
861 #define MATCH_MINIMUM( param ) \
863 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
864 && (a-> param > b-> param) ) { \
869 #define MATCH_EXACT( param ) \
871 if ( a-> param != b-> param) { \
876 /* Test that all bits from a are contained in b */
877 #define MATCH_MASK(param) \
879 if ((a->param & ~b->param) != 0) \
884 * Determine if two GLXFBConfigs are compatible.
886 * \param a Application specified config to test.
887 * \param b Server specified config to test against \c a.
890 fbconfigs_compatible(const struct glx_config
* const a
,
891 const struct glx_config
* const b
)
893 MATCH_DONT_CARE(doubleBufferMode
);
894 MATCH_DONT_CARE(visualType
);
895 MATCH_DONT_CARE(visualRating
);
896 MATCH_DONT_CARE(xRenderable
);
897 MATCH_DONT_CARE(fbconfigID
);
898 MATCH_DONT_CARE(swapMethod
);
900 MATCH_MINIMUM(rgbBits
);
901 MATCH_MINIMUM(numAuxBuffers
);
902 MATCH_MINIMUM(redBits
);
903 MATCH_MINIMUM(greenBits
);
904 MATCH_MINIMUM(blueBits
);
905 MATCH_MINIMUM(alphaBits
);
906 MATCH_MINIMUM(depthBits
);
907 MATCH_MINIMUM(stencilBits
);
908 MATCH_MINIMUM(accumRedBits
);
909 MATCH_MINIMUM(accumGreenBits
);
910 MATCH_MINIMUM(accumBlueBits
);
911 MATCH_MINIMUM(accumAlphaBits
);
912 MATCH_MINIMUM(sampleBuffers
);
913 MATCH_MINIMUM(maxPbufferWidth
);
914 MATCH_MINIMUM(maxPbufferHeight
);
915 MATCH_MINIMUM(maxPbufferPixels
);
916 MATCH_MINIMUM(samples
);
918 MATCH_DONT_CARE(stereoMode
);
921 MATCH_MASK(drawableType
);
922 MATCH_MASK(renderType
);
924 /* There is a bug in a few of the XFree86 DDX drivers. They contain
925 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
926 * Technically speaking, it is a bug in the DDX driver, but there is
927 * enough of an installed base to work around the problem here. In any
928 * case, 0 is not a valid value of the transparent type, so we'll treat 0
929 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
930 * 0 from the server to be a match to maintain backward compatibility with
931 * the (broken) drivers.
934 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
935 if (a
->transparentPixel
== GLX_NONE
) {
936 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
940 MATCH_EXACT(transparentPixel
);
943 switch (a
->transparentPixel
) {
944 case GLX_TRANSPARENT_RGB
:
945 MATCH_DONT_CARE(transparentRed
);
946 MATCH_DONT_CARE(transparentGreen
);
947 MATCH_DONT_CARE(transparentBlue
);
948 MATCH_DONT_CARE(transparentAlpha
);
951 case GLX_TRANSPARENT_INDEX
:
952 MATCH_DONT_CARE(transparentIndex
);
964 /* There's some trickly language in the GLX spec about how this is supposed
965 * to work. Basically, if a given component size is either not specified
966 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
967 * Well, that's really hard to do with the code as-is. This behavior is
968 * closer to correct, but still not technically right.
970 #define PREFER_LARGER_OR_ZERO(comp) \
972 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
973 if ( ((*a)-> comp) == 0 ) { \
976 else if ( ((*b)-> comp) == 0 ) { \
980 return ((*b)-> comp) - ((*a)-> comp) ; \
985 #define PREFER_LARGER(comp) \
987 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
988 return ((*b)-> comp) - ((*a)-> comp) ; \
992 #define PREFER_SMALLER(comp) \
994 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
995 return ((*a)-> comp) - ((*b)-> comp) ; \
1000 * Compare two GLXFBConfigs. This function is intended to be used as the
1001 * compare function passed in to qsort.
1003 * \returns If \c a is a "better" config, according to the specification of
1004 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1005 * better, then a number greater than zero is return. If both are
1006 * equal, zero is returned.
1007 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1010 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1012 /* The order of these comparisons must NOT change. It is defined by
1013 * the GLX 1.3 spec and ARB_multisample.
1016 PREFER_SMALLER(visualSelectGroup
);
1018 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1019 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1020 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1022 PREFER_SMALLER(visualRating
);
1024 /* This isn't quite right. It is supposed to compare the sum of the
1025 * components the user specifically set minimums for.
1027 PREFER_LARGER_OR_ZERO(redBits
);
1028 PREFER_LARGER_OR_ZERO(greenBits
);
1029 PREFER_LARGER_OR_ZERO(blueBits
);
1030 PREFER_LARGER_OR_ZERO(alphaBits
);
1032 PREFER_SMALLER(rgbBits
);
1034 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1035 /* Prefer single-buffer.
1037 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1040 PREFER_SMALLER(numAuxBuffers
);
1042 PREFER_LARGER_OR_ZERO(depthBits
);
1043 PREFER_SMALLER(stencilBits
);
1045 /* This isn't quite right. It is supposed to compare the sum of the
1046 * components the user specifically set minimums for.
1048 PREFER_LARGER_OR_ZERO(accumRedBits
);
1049 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1050 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1051 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1053 PREFER_SMALLER(visualType
);
1055 /* None of the multisample specs say where this comparison should happen,
1056 * so I put it near the end.
1058 PREFER_SMALLER(sampleBuffers
);
1059 PREFER_SMALLER(samples
);
1061 /* None of the pbuffer or fbconfig specs say that this comparison needs
1062 * to happen at all, but it seems like it should.
1064 PREFER_LARGER(maxPbufferWidth
);
1065 PREFER_LARGER(maxPbufferHeight
);
1066 PREFER_LARGER(maxPbufferPixels
);
1073 * Selects and sorts a subset of the supplied configs based on the attributes.
1074 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1075 * and \c glXChooseFBConfigSGIX.
1077 * \param configs Array of pointers to possible configs. The elements of
1078 * this array that do not meet the criteria will be set to
1079 * NULL. The remaining elements will be sorted according to
1080 * the various visual / FBConfig selection rules.
1081 * \param num_configs Number of elements in the \c configs array.
1082 * \param attribList Attributes used select from \c configs. This array is
1083 * terminated by a \c None tag. The array can either take
1084 * the form expected by \c glXChooseVisual (where boolean
1085 * tags do not have a value) or by \c glXChooseFBConfig
1086 * (where every tag has a value).
1087 * \param fbconfig_style_tags Selects whether \c attribList is in
1088 * \c glXChooseVisual style or
1089 * \c glXChooseFBConfig style.
1090 * \returns The number of valid elements left in \c configs.
1092 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1095 choose_visual(struct glx_config
** configs
, int num_configs
,
1096 const int *attribList
, GLboolean fbconfig_style_tags
)
1098 struct glx_config test_config
;
1102 /* This is a fairly direct implementation of the selection method
1103 * described by GLX_SGIX_fbconfig. Start by culling out all the
1104 * configs that are not compatible with the selected parameter
1108 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1109 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1110 (const INT32
*) attribList
,
1111 GL_TRUE
, fbconfig_style_tags
);
1114 for (i
= 0; i
< num_configs
; i
++) {
1115 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1116 configs
[base
] = configs
[i
];
1125 if (base
< num_configs
) {
1126 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1129 /* After the incompatible configs are removed, the resulting
1130 * list is sorted according to the rules set out in the various
1134 qsort(configs
, base
, sizeof(struct glx_config
*),
1135 (int (*)(const void *, const void *)) fbconfig_compare
);
1143 ** Return the visual that best matches the template. Return None if no
1144 ** visual matches the template.
1146 _X_EXPORT XVisualInfo
*
1147 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1149 XVisualInfo
*visualList
= NULL
;
1150 struct glx_display
*priv
;
1151 struct glx_screen
*psc
;
1152 struct glx_config test_config
;
1153 struct glx_config
*config
;
1154 struct glx_config
*best_config
= NULL
;
1157 ** Get a list of all visuals, return if list is empty
1159 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1165 ** Build a template from the defaults and the attribute list
1166 ** Free visual list and return if an unexpected token is encountered
1168 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1169 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1170 (const INT32
*) attribList
,
1174 ** Eliminate visuals that don't meet minimum requirements
1175 ** Compute a score for those that do
1176 ** Remember which visual, if any, got the highest score
1177 ** If no visual is acceptable, return None
1178 ** Otherwise, create an XVisualInfo list with just the selected X visual
1181 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1182 if (fbconfigs_compatible(&test_config
, config
)
1183 && ((best_config
== NULL
) ||
1184 (fbconfig_compare (&config
, &best_config
) < 0))) {
1185 XVisualInfo visualTemplate
;
1186 XVisualInfo
*newList
;
1189 visualTemplate
.screen
= screen
;
1190 visualTemplate
.visualid
= config
->visualID
;
1191 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1192 &visualTemplate
, &i
);
1196 visualList
= newList
;
1197 best_config
= config
;
1202 #ifdef GLX_USE_APPLEGL
1203 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1204 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1212 _X_EXPORT
const char *
1213 glXQueryExtensionsString(Display
* dpy
, int screen
)
1215 struct glx_screen
*psc
;
1216 struct glx_display
*priv
;
1218 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1222 if (!psc
->effectiveGLXexts
) {
1223 if (!psc
->serverGLXexts
) {
1224 psc
->serverGLXexts
=
1225 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1229 __glXCalculateUsableExtensions(psc
,
1230 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1231 (psc
->driScreen
!= NULL
),
1235 priv
->minorVersion
);
1238 return psc
->effectiveGLXexts
;
1241 _X_EXPORT
const char *
1242 glXGetClientString(Display
* dpy
, int name
)
1248 return (__glXGLXClientVendorName
);
1250 return (__glXGLXClientVersion
);
1251 case GLX_EXTENSIONS
:
1252 return (__glXGetClientExtensions());
1258 _X_EXPORT
const char *
1259 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1261 struct glx_screen
*psc
;
1262 struct glx_display
*priv
;
1266 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1272 str
= &priv
->serverGLXvendor
;
1275 str
= &priv
->serverGLXversion
;
1277 case GLX_EXTENSIONS
:
1278 str
= &psc
->serverGLXexts
;
1285 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1292 __glXClientInfo(Display
* dpy
, int opcode
)
1294 char *ext_str
= __glXGetClientGLExtensionString();
1295 int size
= strlen(ext_str
) + 1;
1298 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1299 xcb_glx_client_info(c
,
1300 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1302 xGLXClientInfoReq
*req
;
1304 /* Send the glXClientInfo request */
1306 GetReq(GLXClientInfo
, req
);
1307 req
->reqType
= opcode
;
1308 req
->glxCode
= X_GLXClientInfo
;
1309 req
->major
= GLX_MAJOR_VERSION
;
1310 req
->minor
= GLX_MINOR_VERSION
;
1312 req
->length
+= (size
+ 3) >> 2;
1313 req
->numbytes
= size
;
1314 Data(dpy
, ext_str
, size
);
1318 #endif /* USE_XCB */
1325 ** EXT_import_context
1329 glXGetCurrentDisplay(void)
1331 struct glx_context
*gc
= __glXGetCurrentContext();
1334 return gc
->currentDpy
;
1338 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1339 glXGetCurrentDisplay
)
1341 #ifndef GLX_USE_APPLEGL
1342 _X_EXPORT GLXContext
1343 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1345 struct glx_display
*priv
= __glXInitialize(dpy
);
1346 struct glx_screen
*psc
;
1347 xGLXQueryContextReply reply
;
1349 struct glx_context
*ctx
;
1350 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1353 struct glx_config
*mode
;
1355 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1358 opcode
= __glXSetupForCommand(dpy
);
1362 /* Send the glXQueryContextInfoEXT request */
1365 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1366 xGLXQueryContextReq
*req
;
1368 GetReq(GLXQueryContext
, req
);
1370 req
->reqType
= opcode
;
1371 req
->glxCode
= X_GLXQueryContext
;
1372 req
->context
= contextID
;
1375 xGLXVendorPrivateReq
*vpreq
;
1376 xGLXQueryContextInfoEXTReq
*req
;
1378 GetReqExtra(GLXVendorPrivate
,
1379 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1381 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1382 req
->reqType
= opcode
;
1383 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1384 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1385 req
->context
= contextID
;
1388 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1390 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1391 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1394 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1398 /* Look up screen first so we can look up visuals/fbconfigs later */
1400 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1401 if (pProp
[0] == GLX_SCREEN
)
1402 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1411 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1413 case GLX_SHARE_CONTEXT_EXT
:
1416 case GLX_VISUAL_ID_EXT
:
1417 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1419 case GLX_FBCONFIG_ID
:
1420 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1422 case GLX_RENDER_TYPE
:
1423 renderType
= pProp
[1];
1430 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1434 ctx
->xid
= contextID
;
1435 ctx
->imported
= GL_TRUE
;
1436 ctx
->share_xid
= share
;
1438 return (GLXContext
) ctx
;
1444 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1446 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1448 switch (attribute
) {
1449 case GLX_SHARE_CONTEXT_EXT
:
1450 *value
= ctx
->share_xid
;
1452 case GLX_VISUAL_ID_EXT
:
1453 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1456 *value
= ctx
->screen
;
1458 case GLX_FBCONFIG_ID
:
1459 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1461 case GLX_RENDER_TYPE
:
1462 *value
= ctx
->renderType
;
1465 return GLX_BAD_ATTRIBUTE
;
1471 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1472 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1473 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1475 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1477 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1483 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1485 DestroyContext(dpy
, ctx
);
1489 _X_EXPORT GLXFBConfig
*
1490 glXChooseFBConfig(Display
* dpy
, int screen
,
1491 const int *attribList
, int *nitems
)
1493 struct glx_config
**config_list
;
1497 config_list
= (struct glx_config
**)
1498 glXGetFBConfigs(dpy
, screen
, &list_size
);
1500 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1501 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1502 if (list_size
== 0) {
1508 *nitems
= list_size
;
1509 return (GLXFBConfig
*) config_list
;
1513 _X_EXPORT GLXContext
1514 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1515 int renderType
, GLXContext shareList
, Bool allowDirect
)
1517 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1519 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1520 allowDirect
, X_GLXCreateNewContext
, renderType
,
1525 _X_EXPORT GLXDrawable
1526 glXGetCurrentReadDrawable(void)
1528 struct glx_context
*gc
= __glXGetCurrentContext();
1530 return gc
->currentReadable
;
1534 _X_EXPORT GLXFBConfig
*
1535 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1537 struct glx_display
*priv
= __glXInitialize(dpy
);
1538 struct glx_config
**config_list
= NULL
;
1539 struct glx_config
*config
;
1540 unsigned num_configs
= 0;
1544 if (priv
&& (priv
->screens
!= NULL
)
1545 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1546 && (priv
->screens
[screen
]->configs
!= NULL
)
1547 && (priv
->screens
[screen
]->configs
->fbconfigID
1548 != (int) GLX_DONT_CARE
)) {
1550 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1551 config
= config
->next
) {
1552 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1557 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1558 if (config_list
!= NULL
) {
1559 *nelements
= num_configs
;
1561 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1562 config
= config
->next
) {
1563 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1564 config_list
[i
] = config
;
1571 return (GLXFBConfig
*) config_list
;
1576 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1577 int attribute
, int *value
)
1579 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1582 return GLXBadFBConfig
;
1584 return glx_config_get(config
, attribute
, value
);
1588 _X_EXPORT XVisualInfo
*
1589 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1591 XVisualInfo visualTemplate
;
1592 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1596 ** Get a list of all visuals, return if list is empty
1598 visualTemplate
.visualid
= config
->visualID
;
1599 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1602 #ifndef GLX_USE_APPLEGL
1604 ** GLX_SGI_swap_control
1607 __glXSwapIntervalSGI(int interval
)
1609 xGLXVendorPrivateReq
*req
;
1610 struct glx_context
*gc
= __glXGetCurrentContext();
1611 struct glx_screen
*psc
;
1613 CARD32
*interval_ptr
;
1617 return GLX_BAD_CONTEXT
;
1620 if (interval
<= 0) {
1621 return GLX_BAD_VALUE
;
1624 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1626 #ifdef GLX_DIRECT_RENDERING
1627 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1628 __GLXDRIdrawable
*pdraw
=
1629 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1630 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1635 dpy
= gc
->currentDpy
;
1636 opcode
= __glXSetupForCommand(dpy
);
1641 /* Send the glXSwapIntervalSGI request */
1643 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1644 req
->reqType
= opcode
;
1645 req
->glxCode
= X_GLXVendorPrivate
;
1646 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1647 req
->contextTag
= gc
->currentContextTag
;
1649 interval_ptr
= (CARD32
*) (req
+ 1);
1650 *interval_ptr
= interval
;
1661 ** GLX_MESA_swap_control
1664 __glXSwapIntervalMESA(unsigned int interval
)
1666 #ifdef GLX_DIRECT_RENDERING
1667 struct glx_context
*gc
= __glXGetCurrentContext();
1669 if (gc
!= NULL
&& gc
->isDirect
) {
1670 struct glx_screen
*psc
;
1672 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1673 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1674 __GLXDRIdrawable
*pdraw
=
1675 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1676 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1681 return GLX_BAD_CONTEXT
;
1686 __glXGetSwapIntervalMESA(void)
1688 #ifdef GLX_DIRECT_RENDERING
1689 struct glx_context
*gc
= __glXGetCurrentContext();
1691 if (gc
!= NULL
&& gc
->isDirect
) {
1692 struct glx_screen
*psc
;
1694 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1695 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1696 __GLXDRIdrawable
*pdraw
=
1697 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1698 return psc
->driScreen
->getSwapInterval(pdraw
);
1708 ** GLX_SGI_video_sync
1711 __glXGetVideoSyncSGI(unsigned int *count
)
1713 int64_t ust
, msc
, sbc
;
1715 struct glx_context
*gc
= __glXGetCurrentContext();
1716 struct glx_screen
*psc
;
1717 #ifdef GLX_DIRECT_RENDERING
1718 __GLXDRIdrawable
*pdraw
;
1722 return GLX_BAD_CONTEXT
;
1724 #ifdef GLX_DIRECT_RENDERING
1726 return GLX_BAD_CONTEXT
;
1729 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1730 #ifdef GLX_DIRECT_RENDERING
1731 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1734 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1735 * FIXME: there should be a GLX encoding for this call. I can find no
1736 * FIXME: documentation for the GLX encoding.
1738 #ifdef GLX_DIRECT_RENDERING
1739 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1740 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1741 *count
= (unsigned) msc
;
1742 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1746 return GLX_BAD_CONTEXT
;
1750 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1752 struct glx_context
*gc
= __glXGetCurrentContext();
1753 struct glx_screen
*psc
;
1754 #ifdef GLX_DIRECT_RENDERING
1755 __GLXDRIdrawable
*pdraw
;
1757 int64_t ust
, msc
, sbc
;
1760 if (divisor
<= 0 || remainder
< 0)
1761 return GLX_BAD_VALUE
;
1764 return GLX_BAD_CONTEXT
;
1766 #ifdef GLX_DIRECT_RENDERING
1768 return GLX_BAD_CONTEXT
;
1771 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1772 #ifdef GLX_DIRECT_RENDERING
1773 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1776 #ifdef GLX_DIRECT_RENDERING
1777 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1778 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1780 *count
= (unsigned) msc
;
1781 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1785 return GLX_BAD_CONTEXT
;
1788 #endif /* GLX_USE_APPLEGL */
1791 ** GLX_SGIX_fbconfig
1792 ** Many of these functions are aliased to GLX 1.3 entry points in the
1793 ** GLX_functions table.
1797 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1798 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1799 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1801 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1802 (Display
* dpy
, int screen
, int *attrib_list
,
1803 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1806 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1807 (Display
* dpy
, GLXFBConfigSGIX config
),
1808 (dpy
, config
), glXGetVisualFromFBConfig
)
1811 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1812 GLXFBConfigSGIX fbconfig
,
1815 #ifndef GLX_USE_APPLEGL
1816 xGLXVendorPrivateWithReplyReq
*vpreq
;
1817 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1818 GLXPixmap xid
= None
;
1820 struct glx_screen
*psc
;
1822 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1825 if ((dpy
== NULL
) || (config
== NULL
)) {
1828 #ifdef GLX_USE_APPLEGL
1829 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1834 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1836 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1837 opcode
= __glXSetupForCommand(dpy
);
1842 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1844 GetReqExtra(GLXVendorPrivateWithReply
,
1845 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1846 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1847 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1848 req
->reqType
= opcode
;
1849 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1850 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1851 req
->screen
= config
->screen
;
1852 req
->fbconfig
= config
->fbconfigID
;
1853 req
->pixmap
= pixmap
;
1854 req
->glxpixmap
= xid
= XAllocID(dpy
);
1863 _X_EXPORT GLXContext
1864 glXCreateContextWithConfigSGIX(Display
* dpy
,
1865 GLXFBConfigSGIX fbconfig
, int renderType
,
1866 GLXContext shareList
, Bool allowDirect
)
1868 GLXContext gc
= NULL
;
1869 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1870 struct glx_screen
*psc
;
1873 if ((dpy
== NULL
) || (config
== NULL
)) {
1877 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1879 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1880 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1882 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1890 _X_EXPORT GLXFBConfigSGIX
1891 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1893 struct glx_display
*priv
;
1894 struct glx_screen
*psc
= NULL
;
1896 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
1897 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1898 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1899 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1906 #ifndef GLX_USE_APPLEGL
1908 ** GLX_SGIX_swap_group
1911 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1921 ** GLX_SGIX_swap_barrier
1924 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1932 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
1942 ** GLX_OML_sync_control
1945 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
1946 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
1948 struct glx_display
* const priv
= __glXInitialize(dpy
);
1950 #ifdef GLX_DIRECT_RENDERING
1951 __GLXDRIdrawable
*pdraw
;
1953 struct glx_screen
*psc
;
1958 #ifdef GLX_DIRECT_RENDERING
1959 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1960 psc
= pdraw
? pdraw
->psc
: NULL
;
1961 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
1962 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
1970 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1972 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
1973 int32_t * numerator
, int32_t * denominator
)
1976 struct glx_screen
*psc
;
1977 XF86VidModeModeLine mode_line
;
1982 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
1983 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
1984 unsigned n
= dot_clock
* 1000;
1985 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
1987 # define V_INTERLACE 0x010
1988 # define V_DBLSCAN 0x020
1990 if (mode_line
.flags
& V_INTERLACE
)
1992 else if (mode_line
.flags
& V_DBLSCAN
)
1995 /* The OML_sync_control spec requires that if the refresh rate is a
1996 * whole number, that the returned numerator be equal to the refresh
1997 * rate and the denominator be 1.
2005 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2007 /* This is a poor man's way to reduce a fraction. It's far from
2008 * perfect, but it will work well enough for this situation.
2011 for (i
= 0; f
[i
] != 0; i
++) {
2012 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2032 * Determine the refresh rate of the specified drawable and display.
2034 * \param dpy Display whose refresh rate is to be determined.
2035 * \param drawable Drawable whose refresh rate is to be determined.
2036 * \param numerator Numerator of the refresh rate.
2037 * \param demoninator Denominator of the refresh rate.
2038 * \return If the refresh rate for the specified display and drawable could
2039 * be calculated, True is returned. Otherwise False is returned.
2041 * \note This function is implemented entirely client-side. A lot of other
2042 * functionality is required to export GLX_OML_sync_control, so on
2043 * XFree86 this function can be called for direct-rendering contexts
2044 * when GLX_OML_sync_control appears in the client extension string.
2048 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2049 int32_t * numerator
, int32_t * denominator
)
2051 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2052 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2057 return __glxGetMscRate(draw
, numerator
, denominator
);
2069 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2070 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2072 struct glx_context
*gc
= __glXGetCurrentContext();
2073 #ifdef GLX_DIRECT_RENDERING
2074 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2075 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2078 if (!gc
) /* no GLX for this */
2081 #ifdef GLX_DIRECT_RENDERING
2082 if (!pdraw
|| !gc
->isDirect
)
2086 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2087 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2088 * of -1 if the function failed because of errors detected in the input
2091 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2093 if (divisor
> 0 && remainder
>= divisor
)
2096 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2099 #ifdef GLX_DIRECT_RENDERING
2100 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2101 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2110 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2111 int64_t target_msc
, int64_t divisor
,
2112 int64_t remainder
, int64_t * ust
,
2113 int64_t * msc
, int64_t * sbc
)
2115 #ifdef GLX_DIRECT_RENDERING
2116 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2117 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2122 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2123 * error", but the return type in the spec is Bool.
2125 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2127 if (divisor
> 0 && remainder
>= divisor
)
2130 #ifdef GLX_DIRECT_RENDERING
2131 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2132 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2143 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2144 int64_t target_sbc
, int64_t * ust
,
2145 int64_t * msc
, int64_t * sbc
)
2147 #ifdef GLX_DIRECT_RENDERING
2148 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2149 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2153 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2154 * error", but the return type in the spec is Bool.
2159 #ifdef GLX_DIRECT_RENDERING
2160 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2161 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2173 * Mesa extension stubs. These will help reduce portability problems.
2178 * Release all buffers associated with the specified GLX drawable.
2181 * This function was intended for stand-alone Mesa. The issue there is that
2182 * the library doesn't get any notification when a window is closed. In
2183 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2184 * supported, there are 3 different functions to destroy a drawable. It
2185 * should be possible to create GLX protocol (or have it determine which
2186 * protocol to use based on the type of the drawable) to have one function
2187 * do the work of 3. For the direct-rendering case, this function could
2188 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2189 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2190 * would need to be used. This really should be done as part of the new DRI
2193 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2194 * __driGarbageCollectDrawables
2195 * glXDestroyGLXPixmap
2196 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2197 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2200 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2209 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2210 Pixmap pixmap
, Colormap cmap
)
2223 * GLX_MESA_copy_sub_buffer
2225 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2227 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2228 int x
, int y
, int width
, int height
)
2230 xGLXVendorPrivateReq
*req
;
2231 struct glx_context
*gc
;
2233 CARD32
*drawable_ptr
;
2234 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2237 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2238 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2239 if (pdraw
!= NULL
) {
2240 struct glx_screen
*psc
= pdraw
->psc
;
2241 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2243 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2250 opcode
= __glXSetupForCommand(dpy
);
2255 ** The calling thread may or may not have a current context. If it
2256 ** does, send the context tag so the server can do a flush.
2258 gc
= __glXGetCurrentContext();
2259 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2260 ((drawable
== gc
->currentDrawable
) ||
2261 (drawable
== gc
->currentReadable
))) {
2262 tag
= gc
->currentContextTag
;
2269 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2270 req
->reqType
= opcode
;
2271 req
->glxCode
= X_GLXVendorPrivate
;
2272 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2273 req
->contextTag
= tag
;
2275 drawable_ptr
= (CARD32
*) (req
+ 1);
2276 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2277 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2278 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2279 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2281 *drawable_ptr
= drawable
;
2293 __glXBindTexImageEXT(Display
* dpy
,
2294 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2296 struct glx_context
*gc
= __glXGetCurrentContext();
2298 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2301 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2305 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2307 struct glx_context
*gc
= __glXGetCurrentContext();
2309 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2312 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2317 #endif /* GLX_USE_APPLEGL */
2320 * \c strdup is actually not a standard ANSI C or POSIX routine.
2321 * Irix will not define it if ANSI mode is in effect.
2326 __glXstrdup(const char *str
)
2329 copy
= (char *) Xmalloc(strlen(str
) + 1);
2337 ** glXGetProcAddress support
2340 struct name_address_pair
2346 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2347 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2349 static const struct name_address_pair GLX_functions
[] = {
2350 /*** GLX_VERSION_1_0 ***/
2351 GLX_FUNCTION(glXChooseVisual
),
2352 GLX_FUNCTION(glXCopyContext
),
2353 GLX_FUNCTION(glXCreateContext
),
2354 GLX_FUNCTION(glXCreateGLXPixmap
),
2355 GLX_FUNCTION(glXDestroyContext
),
2356 GLX_FUNCTION(glXDestroyGLXPixmap
),
2357 GLX_FUNCTION(glXGetConfig
),
2358 GLX_FUNCTION(glXGetCurrentContext
),
2359 GLX_FUNCTION(glXGetCurrentDrawable
),
2360 GLX_FUNCTION(glXIsDirect
),
2361 GLX_FUNCTION(glXMakeCurrent
),
2362 GLX_FUNCTION(glXQueryExtension
),
2363 GLX_FUNCTION(glXQueryVersion
),
2364 GLX_FUNCTION(glXSwapBuffers
),
2365 GLX_FUNCTION(glXUseXFont
),
2366 GLX_FUNCTION(glXWaitGL
),
2367 GLX_FUNCTION(glXWaitX
),
2369 /*** GLX_VERSION_1_1 ***/
2370 GLX_FUNCTION(glXGetClientString
),
2371 GLX_FUNCTION(glXQueryExtensionsString
),
2372 GLX_FUNCTION(glXQueryServerString
),
2374 /*** GLX_VERSION_1_2 ***/
2375 GLX_FUNCTION(glXGetCurrentDisplay
),
2377 /*** GLX_VERSION_1_3 ***/
2378 GLX_FUNCTION(glXChooseFBConfig
),
2379 GLX_FUNCTION(glXCreateNewContext
),
2380 GLX_FUNCTION(glXCreatePbuffer
),
2381 GLX_FUNCTION(glXCreatePixmap
),
2382 GLX_FUNCTION(glXCreateWindow
),
2383 GLX_FUNCTION(glXDestroyPbuffer
),
2384 GLX_FUNCTION(glXDestroyPixmap
),
2385 GLX_FUNCTION(glXDestroyWindow
),
2386 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2387 GLX_FUNCTION(glXGetFBConfigAttrib
),
2388 GLX_FUNCTION(glXGetFBConfigs
),
2389 GLX_FUNCTION(glXGetSelectedEvent
),
2390 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2391 GLX_FUNCTION(glXMakeContextCurrent
),
2392 GLX_FUNCTION(glXQueryContext
),
2393 GLX_FUNCTION(glXQueryDrawable
),
2394 GLX_FUNCTION(glXSelectEvent
),
2396 #ifndef GLX_USE_APPLEGL
2397 /*** GLX_SGI_swap_control ***/
2398 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2400 /*** GLX_SGI_video_sync ***/
2401 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2402 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2404 /*** GLX_SGI_make_current_read ***/
2405 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2406 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2408 /*** GLX_EXT_import_context ***/
2409 GLX_FUNCTION(glXFreeContextEXT
),
2410 GLX_FUNCTION(glXGetContextIDEXT
),
2411 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2412 GLX_FUNCTION(glXImportContextEXT
),
2413 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2416 /*** GLX_SGIX_fbconfig ***/
2417 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2418 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2419 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2420 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2421 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2422 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2424 #ifndef GLX_USE_APPLEGL
2425 /*** GLX_SGIX_pbuffer ***/
2426 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2427 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2428 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2429 GLX_FUNCTION(glXSelectEventSGIX
),
2430 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2432 /*** GLX_SGIX_swap_group ***/
2433 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2435 /*** GLX_SGIX_swap_barrier ***/
2436 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2437 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2439 /*** GLX_MESA_copy_sub_buffer ***/
2440 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2442 /*** GLX_MESA_pixmap_colormap ***/
2443 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2445 /*** GLX_MESA_release_buffers ***/
2446 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2448 /*** GLX_MESA_swap_control ***/
2449 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2450 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2453 /*** GLX_ARB_get_proc_address ***/
2454 GLX_FUNCTION(glXGetProcAddressARB
),
2457 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2459 #ifndef GLX_USE_APPLEGL
2460 /*** GLX_OML_sync_control ***/
2461 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2462 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2463 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2464 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2465 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2467 /*** GLX_EXT_texture_from_pixmap ***/
2468 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2469 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2472 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2473 /*** DRI configuration ***/
2474 GLX_FUNCTION(glXGetScreenDriver
),
2475 GLX_FUNCTION(glXGetDriverConfig
),
2478 {NULL
, NULL
} /* end of list */
2481 static const GLvoid
*
2482 get_glx_proc_address(const char *funcName
)
2486 /* try static functions */
2487 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2488 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2489 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 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2517 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2518 && (procName
[2] != 'X')) {
2519 #ifdef GLX_SHARED_GLAPI
2520 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2523 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2525 struct glx_context
*gc
= __glXGetCurrentContext();
2527 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2528 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2535 * Get the address of a named GL function. This is the GLX 1.4 name for
2536 * \c glXGetProcAddressARB.
2538 * \param procName Name of a GL or GLX function.
2539 * \returns A pointer to the named function
2541 * \sa glXGetProcAddressARB
2543 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2544 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2545 __attribute__ ((alias("glXGetProcAddressARB")));
2548 return glXGetProcAddressARB(procName
);
2550 #endif /* __GNUC__ */
2553 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2555 * Get the unadjusted system time (UST). Currently, the UST is measured in
2556 * microseconds since Epoc. The actual resolution of the UST may vary from
2557 * system to system, and the units may vary from release to release.
2558 * Drivers should not call this function directly. They should instead use
2559 * \c glXGetProcAddress to obtain a pointer to the function.
2561 * \param ust Location to store the 64-bit UST
2562 * \returns Zero on success or a negative errno value on failure.
2564 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2566 * \since Internal API version 20030317.
2569 __glXGetUST(int64_t * ust
)
2577 if (gettimeofday(&tv
, NULL
) == 0) {
2578 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2585 #endif /* GLX_DIRECT_RENDERING */