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 gc
= __glXGetCurrentContext();
732 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
733 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
736 if (gc
&& drawable
== gc
->currentDrawable
) {
740 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
745 opcode
= __glXSetupForCommand(dpy
);
751 ** The calling thread may or may not have a current context. If it
752 ** does, send the context tag so the server can do a flush.
754 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
755 ((drawable
== gc
->currentDrawable
)
756 || (drawable
== gc
->currentReadable
))) {
757 tag
= gc
->currentContextTag
;
764 c
= XGetXCBConnection(dpy
);
765 xcb_glx_swap_buffers(c
, tag
, drawable
);
768 /* Send the glXSwapBuffers request */
770 GetReq(GLXSwapBuffers
, req
);
771 req
->reqType
= opcode
;
772 req
->glxCode
= X_GLXSwapBuffers
;
773 req
->drawable
= drawable
;
774 req
->contextTag
= tag
;
779 #endif /* GLX_USE_APPLEGL */
784 ** Return configuration information for the given display, screen and
785 ** visual combination.
788 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
791 struct glx_display
*priv
;
792 struct glx_screen
*psc
;
793 struct glx_config
*config
;
796 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
797 if (status
== Success
) {
798 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
800 /* Lookup attribute after first finding a match on the visual */
801 if (config
!= NULL
) {
802 return glx_config_get(config
, attribute
, value_return
);
805 status
= GLX_BAD_VISUAL
;
809 ** If we can't find the config for this visual, this visual is not
810 ** supported by the OpenGL implementation on the server.
812 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
813 *value_return
= GL_FALSE
;
820 /************************************************************************/
823 init_fbconfig_for_chooser(struct glx_config
* config
,
824 GLboolean fbconfig_style_tags
)
826 memset(config
, 0, sizeof(struct glx_config
));
827 config
->visualID
= (XID
) GLX_DONT_CARE
;
828 config
->visualType
= GLX_DONT_CARE
;
830 /* glXChooseFBConfig specifies different defaults for these two than
833 if (fbconfig_style_tags
) {
834 config
->rgbMode
= GL_TRUE
;
835 config
->doubleBufferMode
= GLX_DONT_CARE
;
838 config
->visualRating
= GLX_DONT_CARE
;
839 config
->transparentPixel
= GLX_NONE
;
840 config
->transparentRed
= GLX_DONT_CARE
;
841 config
->transparentGreen
= GLX_DONT_CARE
;
842 config
->transparentBlue
= GLX_DONT_CARE
;
843 config
->transparentAlpha
= GLX_DONT_CARE
;
844 config
->transparentIndex
= GLX_DONT_CARE
;
846 config
->drawableType
= GLX_WINDOW_BIT
;
848 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
849 config
->xRenderable
= GLX_DONT_CARE
;
850 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
852 config
->swapMethod
= GLX_DONT_CARE
;
855 #define MATCH_DONT_CARE( param ) \
857 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
858 && (a-> param != b-> param) ) { \
863 #define MATCH_MINIMUM( param ) \
865 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
866 && (a-> param > b-> param) ) { \
871 #define MATCH_EXACT( param ) \
873 if ( a-> param != b-> param) { \
878 /* Test that all bits from a are contained in b */
879 #define MATCH_MASK(param) \
881 if ((a->param & ~b->param) != 0) \
886 * Determine if two GLXFBConfigs are compatible.
888 * \param a Application specified config to test.
889 * \param b Server specified config to test against \c a.
892 fbconfigs_compatible(const struct glx_config
* const a
,
893 const struct glx_config
* const b
)
895 MATCH_DONT_CARE(doubleBufferMode
);
896 MATCH_DONT_CARE(visualType
);
897 MATCH_DONT_CARE(visualRating
);
898 MATCH_DONT_CARE(xRenderable
);
899 MATCH_DONT_CARE(fbconfigID
);
900 MATCH_DONT_CARE(swapMethod
);
902 MATCH_MINIMUM(rgbBits
);
903 MATCH_MINIMUM(numAuxBuffers
);
904 MATCH_MINIMUM(redBits
);
905 MATCH_MINIMUM(greenBits
);
906 MATCH_MINIMUM(blueBits
);
907 MATCH_MINIMUM(alphaBits
);
908 MATCH_MINIMUM(depthBits
);
909 MATCH_MINIMUM(stencilBits
);
910 MATCH_MINIMUM(accumRedBits
);
911 MATCH_MINIMUM(accumGreenBits
);
912 MATCH_MINIMUM(accumBlueBits
);
913 MATCH_MINIMUM(accumAlphaBits
);
914 MATCH_MINIMUM(sampleBuffers
);
915 MATCH_MINIMUM(maxPbufferWidth
);
916 MATCH_MINIMUM(maxPbufferHeight
);
917 MATCH_MINIMUM(maxPbufferPixels
);
918 MATCH_MINIMUM(samples
);
920 MATCH_DONT_CARE(stereoMode
);
923 MATCH_MASK(drawableType
);
924 MATCH_MASK(renderType
);
926 /* There is a bug in a few of the XFree86 DDX drivers. They contain
927 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
928 * Technically speaking, it is a bug in the DDX driver, but there is
929 * enough of an installed base to work around the problem here. In any
930 * case, 0 is not a valid value of the transparent type, so we'll treat 0
931 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
932 * 0 from the server to be a match to maintain backward compatibility with
933 * the (broken) drivers.
936 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
937 if (a
->transparentPixel
== GLX_NONE
) {
938 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
942 MATCH_EXACT(transparentPixel
);
945 switch (a
->transparentPixel
) {
946 case GLX_TRANSPARENT_RGB
:
947 MATCH_DONT_CARE(transparentRed
);
948 MATCH_DONT_CARE(transparentGreen
);
949 MATCH_DONT_CARE(transparentBlue
);
950 MATCH_DONT_CARE(transparentAlpha
);
953 case GLX_TRANSPARENT_INDEX
:
954 MATCH_DONT_CARE(transparentIndex
);
966 /* There's some trickly language in the GLX spec about how this is supposed
967 * to work. Basically, if a given component size is either not specified
968 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
969 * Well, that's really hard to do with the code as-is. This behavior is
970 * closer to correct, but still not technically right.
972 #define PREFER_LARGER_OR_ZERO(comp) \
974 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
975 if ( ((*a)-> comp) == 0 ) { \
978 else if ( ((*b)-> comp) == 0 ) { \
982 return ((*b)-> comp) - ((*a)-> comp) ; \
987 #define PREFER_LARGER(comp) \
989 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
990 return ((*b)-> comp) - ((*a)-> comp) ; \
994 #define PREFER_SMALLER(comp) \
996 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
997 return ((*a)-> comp) - ((*b)-> comp) ; \
1002 * Compare two GLXFBConfigs. This function is intended to be used as the
1003 * compare function passed in to qsort.
1005 * \returns If \c a is a "better" config, according to the specification of
1006 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1007 * better, then a number greater than zero is return. If both are
1008 * equal, zero is returned.
1009 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1012 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1014 /* The order of these comparisons must NOT change. It is defined by
1015 * the GLX 1.3 spec and ARB_multisample.
1018 PREFER_SMALLER(visualSelectGroup
);
1020 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1021 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1022 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1024 PREFER_SMALLER(visualRating
);
1026 /* This isn't quite right. It is supposed to compare the sum of the
1027 * components the user specifically set minimums for.
1029 PREFER_LARGER_OR_ZERO(redBits
);
1030 PREFER_LARGER_OR_ZERO(greenBits
);
1031 PREFER_LARGER_OR_ZERO(blueBits
);
1032 PREFER_LARGER_OR_ZERO(alphaBits
);
1034 PREFER_SMALLER(rgbBits
);
1036 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1037 /* Prefer single-buffer.
1039 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1042 PREFER_SMALLER(numAuxBuffers
);
1044 PREFER_LARGER_OR_ZERO(depthBits
);
1045 PREFER_SMALLER(stencilBits
);
1047 /* This isn't quite right. It is supposed to compare the sum of the
1048 * components the user specifically set minimums for.
1050 PREFER_LARGER_OR_ZERO(accumRedBits
);
1051 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1052 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1053 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1055 PREFER_SMALLER(visualType
);
1057 /* None of the multisample specs say where this comparison should happen,
1058 * so I put it near the end.
1060 PREFER_SMALLER(sampleBuffers
);
1061 PREFER_SMALLER(samples
);
1063 /* None of the pbuffer or fbconfig specs say that this comparison needs
1064 * to happen at all, but it seems like it should.
1066 PREFER_LARGER(maxPbufferWidth
);
1067 PREFER_LARGER(maxPbufferHeight
);
1068 PREFER_LARGER(maxPbufferPixels
);
1075 * Selects and sorts a subset of the supplied configs based on the attributes.
1076 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1077 * and \c glXChooseFBConfigSGIX.
1079 * \param configs Array of pointers to possible configs. The elements of
1080 * this array that do not meet the criteria will be set to
1081 * NULL. The remaining elements will be sorted according to
1082 * the various visual / FBConfig selection rules.
1083 * \param num_configs Number of elements in the \c configs array.
1084 * \param attribList Attributes used select from \c configs. This array is
1085 * terminated by a \c None tag. The array can either take
1086 * the form expected by \c glXChooseVisual (where boolean
1087 * tags do not have a value) or by \c glXChooseFBConfig
1088 * (where every tag has a value).
1089 * \param fbconfig_style_tags Selects whether \c attribList is in
1090 * \c glXChooseVisual style or
1091 * \c glXChooseFBConfig style.
1092 * \returns The number of valid elements left in \c configs.
1094 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1097 choose_visual(struct glx_config
** configs
, int num_configs
,
1098 const int *attribList
, GLboolean fbconfig_style_tags
)
1100 struct glx_config test_config
;
1104 /* This is a fairly direct implementation of the selection method
1105 * described by GLX_SGIX_fbconfig. Start by culling out all the
1106 * configs that are not compatible with the selected parameter
1110 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1111 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1112 (const INT32
*) attribList
,
1113 GL_TRUE
, fbconfig_style_tags
);
1116 for (i
= 0; i
< num_configs
; i
++) {
1117 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1118 configs
[base
] = configs
[i
];
1127 if (base
< num_configs
) {
1128 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1131 /* After the incompatible configs are removed, the resulting
1132 * list is sorted according to the rules set out in the various
1136 qsort(configs
, base
, sizeof(struct glx_config
*),
1137 (int (*)(const void *, const void *)) fbconfig_compare
);
1145 ** Return the visual that best matches the template. Return None if no
1146 ** visual matches the template.
1148 _X_EXPORT XVisualInfo
*
1149 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1151 XVisualInfo
*visualList
= NULL
;
1152 struct glx_display
*priv
;
1153 struct glx_screen
*psc
;
1154 struct glx_config test_config
;
1155 struct glx_config
*config
;
1156 struct glx_config
*best_config
= NULL
;
1159 ** Get a list of all visuals, return if list is empty
1161 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1167 ** Build a template from the defaults and the attribute list
1168 ** Free visual list and return if an unexpected token is encountered
1170 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1171 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1172 (const INT32
*) attribList
,
1176 ** Eliminate visuals that don't meet minimum requirements
1177 ** Compute a score for those that do
1178 ** Remember which visual, if any, got the highest score
1179 ** If no visual is acceptable, return None
1180 ** Otherwise, create an XVisualInfo list with just the selected X visual
1183 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1184 if (fbconfigs_compatible(&test_config
, config
)
1185 && ((best_config
== NULL
) ||
1186 (fbconfig_compare (&config
, &best_config
) < 0))) {
1187 XVisualInfo visualTemplate
;
1188 XVisualInfo
*newList
;
1191 visualTemplate
.screen
= screen
;
1192 visualTemplate
.visualid
= config
->visualID
;
1193 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1194 &visualTemplate
, &i
);
1198 visualList
= newList
;
1199 best_config
= config
;
1204 #ifdef GLX_USE_APPLEGL
1205 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1206 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1214 _X_EXPORT
const char *
1215 glXQueryExtensionsString(Display
* dpy
, int screen
)
1217 struct glx_screen
*psc
;
1218 struct glx_display
*priv
;
1220 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1224 if (!psc
->effectiveGLXexts
) {
1225 if (!psc
->serverGLXexts
) {
1226 psc
->serverGLXexts
=
1227 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1231 __glXCalculateUsableExtensions(psc
,
1232 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1233 (psc
->driScreen
!= NULL
),
1237 priv
->minorVersion
);
1240 return psc
->effectiveGLXexts
;
1243 _X_EXPORT
const char *
1244 glXGetClientString(Display
* dpy
, int name
)
1250 return (__glXGLXClientVendorName
);
1252 return (__glXGLXClientVersion
);
1253 case GLX_EXTENSIONS
:
1254 return (__glXGetClientExtensions());
1260 _X_EXPORT
const char *
1261 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1263 struct glx_screen
*psc
;
1264 struct glx_display
*priv
;
1268 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1274 str
= &priv
->serverGLXvendor
;
1277 str
= &priv
->serverGLXversion
;
1279 case GLX_EXTENSIONS
:
1280 str
= &psc
->serverGLXexts
;
1287 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1294 __glXClientInfo(Display
* dpy
, int opcode
)
1296 char *ext_str
= __glXGetClientGLExtensionString();
1297 int size
= strlen(ext_str
) + 1;
1300 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1301 xcb_glx_client_info(c
,
1302 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1304 xGLXClientInfoReq
*req
;
1306 /* Send the glXClientInfo request */
1308 GetReq(GLXClientInfo
, req
);
1309 req
->reqType
= opcode
;
1310 req
->glxCode
= X_GLXClientInfo
;
1311 req
->major
= GLX_MAJOR_VERSION
;
1312 req
->minor
= GLX_MINOR_VERSION
;
1314 req
->length
+= (size
+ 3) >> 2;
1315 req
->numbytes
= size
;
1316 Data(dpy
, ext_str
, size
);
1320 #endif /* USE_XCB */
1327 ** EXT_import_context
1331 glXGetCurrentDisplay(void)
1333 struct glx_context
*gc
= __glXGetCurrentContext();
1336 return gc
->currentDpy
;
1340 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1341 glXGetCurrentDisplay
)
1343 #ifndef GLX_USE_APPLEGL
1344 _X_EXPORT GLXContext
1345 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1347 struct glx_display
*priv
= __glXInitialize(dpy
);
1348 struct glx_screen
*psc
;
1349 xGLXQueryContextReply reply
;
1351 struct glx_context
*ctx
;
1352 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1355 struct glx_config
*mode
;
1357 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1360 opcode
= __glXSetupForCommand(dpy
);
1364 /* Send the glXQueryContextInfoEXT request */
1367 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1368 xGLXQueryContextReq
*req
;
1370 GetReq(GLXQueryContext
, req
);
1372 req
->reqType
= opcode
;
1373 req
->glxCode
= X_GLXQueryContext
;
1374 req
->context
= contextID
;
1377 xGLXVendorPrivateReq
*vpreq
;
1378 xGLXQueryContextInfoEXTReq
*req
;
1380 GetReqExtra(GLXVendorPrivate
,
1381 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1383 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1384 req
->reqType
= opcode
;
1385 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1386 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1387 req
->context
= contextID
;
1390 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1392 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1393 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1396 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1400 /* Look up screen first so we can look up visuals/fbconfigs later */
1402 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1403 if (pProp
[0] == GLX_SCREEN
)
1404 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1413 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1415 case GLX_SHARE_CONTEXT_EXT
:
1418 case GLX_VISUAL_ID_EXT
:
1419 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1421 case GLX_FBCONFIG_ID
:
1422 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1424 case GLX_RENDER_TYPE
:
1425 renderType
= pProp
[1];
1432 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1436 ctx
->xid
= contextID
;
1437 ctx
->imported
= GL_TRUE
;
1438 ctx
->share_xid
= share
;
1440 return (GLXContext
) ctx
;
1446 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1448 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1450 switch (attribute
) {
1451 case GLX_SHARE_CONTEXT_EXT
:
1452 *value
= ctx
->share_xid
;
1454 case GLX_VISUAL_ID_EXT
:
1455 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1458 *value
= ctx
->screen
;
1460 case GLX_FBCONFIG_ID
:
1461 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1463 case GLX_RENDER_TYPE
:
1464 *value
= ctx
->renderType
;
1467 return GLX_BAD_ATTRIBUTE
;
1473 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1474 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1475 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1477 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1479 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1485 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1487 DestroyContext(dpy
, ctx
);
1491 _X_EXPORT GLXFBConfig
*
1492 glXChooseFBConfig(Display
* dpy
, int screen
,
1493 const int *attribList
, int *nitems
)
1495 struct glx_config
**config_list
;
1499 config_list
= (struct glx_config
**)
1500 glXGetFBConfigs(dpy
, screen
, &list_size
);
1502 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1503 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1504 if (list_size
== 0) {
1510 *nitems
= list_size
;
1511 return (GLXFBConfig
*) config_list
;
1515 _X_EXPORT GLXContext
1516 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1517 int renderType
, GLXContext shareList
, Bool allowDirect
)
1519 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1521 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1522 allowDirect
, X_GLXCreateNewContext
, renderType
,
1527 _X_EXPORT GLXDrawable
1528 glXGetCurrentReadDrawable(void)
1530 struct glx_context
*gc
= __glXGetCurrentContext();
1532 return gc
->currentReadable
;
1536 _X_EXPORT GLXFBConfig
*
1537 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1539 struct glx_display
*priv
= __glXInitialize(dpy
);
1540 struct glx_config
**config_list
= NULL
;
1541 struct glx_config
*config
;
1542 unsigned num_configs
= 0;
1546 if (priv
&& (priv
->screens
!= NULL
)
1547 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1548 && (priv
->screens
[screen
]->configs
!= NULL
)
1549 && (priv
->screens
[screen
]->configs
->fbconfigID
1550 != (int) GLX_DONT_CARE
)) {
1552 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1553 config
= config
->next
) {
1554 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1559 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1560 if (config_list
!= NULL
) {
1561 *nelements
= num_configs
;
1563 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1564 config
= config
->next
) {
1565 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1566 config_list
[i
] = config
;
1573 return (GLXFBConfig
*) config_list
;
1578 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1579 int attribute
, int *value
)
1581 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1584 return GLXBadFBConfig
;
1586 return glx_config_get(config
, attribute
, value
);
1590 _X_EXPORT XVisualInfo
*
1591 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1593 XVisualInfo visualTemplate
;
1594 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1598 ** Get a list of all visuals, return if list is empty
1600 visualTemplate
.visualid
= config
->visualID
;
1601 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1604 #ifndef GLX_USE_APPLEGL
1606 ** GLX_SGI_swap_control
1609 __glXSwapIntervalSGI(int interval
)
1611 xGLXVendorPrivateReq
*req
;
1612 struct glx_context
*gc
= __glXGetCurrentContext();
1613 struct glx_screen
*psc
;
1615 CARD32
*interval_ptr
;
1619 return GLX_BAD_CONTEXT
;
1622 if (interval
<= 0) {
1623 return GLX_BAD_VALUE
;
1626 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1628 #ifdef GLX_DIRECT_RENDERING
1629 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1630 __GLXDRIdrawable
*pdraw
=
1631 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1632 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1637 dpy
= gc
->currentDpy
;
1638 opcode
= __glXSetupForCommand(dpy
);
1643 /* Send the glXSwapIntervalSGI request */
1645 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1646 req
->reqType
= opcode
;
1647 req
->glxCode
= X_GLXVendorPrivate
;
1648 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1649 req
->contextTag
= gc
->currentContextTag
;
1651 interval_ptr
= (CARD32
*) (req
+ 1);
1652 *interval_ptr
= interval
;
1663 ** GLX_MESA_swap_control
1666 __glXSwapIntervalMESA(unsigned int interval
)
1668 #ifdef GLX_DIRECT_RENDERING
1669 struct glx_context
*gc
= __glXGetCurrentContext();
1671 if (gc
!= NULL
&& gc
->isDirect
) {
1672 struct glx_screen
*psc
;
1674 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1675 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1676 __GLXDRIdrawable
*pdraw
=
1677 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1678 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1683 return GLX_BAD_CONTEXT
;
1688 __glXGetSwapIntervalMESA(void)
1690 #ifdef GLX_DIRECT_RENDERING
1691 struct glx_context
*gc
= __glXGetCurrentContext();
1693 if (gc
!= NULL
&& gc
->isDirect
) {
1694 struct glx_screen
*psc
;
1696 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1697 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1698 __GLXDRIdrawable
*pdraw
=
1699 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1700 return psc
->driScreen
->getSwapInterval(pdraw
);
1710 ** GLX_SGI_video_sync
1713 __glXGetVideoSyncSGI(unsigned int *count
)
1715 int64_t ust
, msc
, sbc
;
1717 struct glx_context
*gc
= __glXGetCurrentContext();
1718 struct glx_screen
*psc
;
1719 #ifdef GLX_DIRECT_RENDERING
1720 __GLXDRIdrawable
*pdraw
;
1724 return GLX_BAD_CONTEXT
;
1726 #ifdef GLX_DIRECT_RENDERING
1728 return GLX_BAD_CONTEXT
;
1731 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1732 #ifdef GLX_DIRECT_RENDERING
1733 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1736 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1737 * FIXME: there should be a GLX encoding for this call. I can find no
1738 * FIXME: documentation for the GLX encoding.
1740 #ifdef GLX_DIRECT_RENDERING
1741 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1742 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1743 *count
= (unsigned) msc
;
1744 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1748 return GLX_BAD_CONTEXT
;
1752 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1754 struct glx_context
*gc
= __glXGetCurrentContext();
1755 struct glx_screen
*psc
;
1756 #ifdef GLX_DIRECT_RENDERING
1757 __GLXDRIdrawable
*pdraw
;
1759 int64_t ust
, msc
, sbc
;
1762 if (divisor
<= 0 || remainder
< 0)
1763 return GLX_BAD_VALUE
;
1766 return GLX_BAD_CONTEXT
;
1768 #ifdef GLX_DIRECT_RENDERING
1770 return GLX_BAD_CONTEXT
;
1773 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1774 #ifdef GLX_DIRECT_RENDERING
1775 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1778 #ifdef GLX_DIRECT_RENDERING
1779 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1780 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1782 *count
= (unsigned) msc
;
1783 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1787 return GLX_BAD_CONTEXT
;
1790 #endif /* GLX_USE_APPLEGL */
1793 ** GLX_SGIX_fbconfig
1794 ** Many of these functions are aliased to GLX 1.3 entry points in the
1795 ** GLX_functions table.
1799 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1800 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1801 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1803 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1804 (Display
* dpy
, int screen
, int *attrib_list
,
1805 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1808 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1809 (Display
* dpy
, GLXFBConfigSGIX config
),
1810 (dpy
, config
), glXGetVisualFromFBConfig
)
1813 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1814 GLXFBConfigSGIX fbconfig
,
1817 #ifndef GLX_USE_APPLEGL
1818 xGLXVendorPrivateWithReplyReq
*vpreq
;
1819 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1820 GLXPixmap xid
= None
;
1822 struct glx_screen
*psc
;
1824 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1827 if ((dpy
== NULL
) || (config
== NULL
)) {
1830 #ifdef GLX_USE_APPLEGL
1831 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1836 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1838 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1839 opcode
= __glXSetupForCommand(dpy
);
1844 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1846 GetReqExtra(GLXVendorPrivateWithReply
,
1847 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1848 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1849 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1850 req
->reqType
= opcode
;
1851 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1852 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1853 req
->screen
= config
->screen
;
1854 req
->fbconfig
= config
->fbconfigID
;
1855 req
->pixmap
= pixmap
;
1856 req
->glxpixmap
= xid
= XAllocID(dpy
);
1865 _X_EXPORT GLXContext
1866 glXCreateContextWithConfigSGIX(Display
* dpy
,
1867 GLXFBConfigSGIX fbconfig
, int renderType
,
1868 GLXContext shareList
, Bool allowDirect
)
1870 GLXContext gc
= NULL
;
1871 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1872 struct glx_screen
*psc
;
1875 if ((dpy
== NULL
) || (config
== NULL
)) {
1879 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1881 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1882 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1884 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1892 _X_EXPORT GLXFBConfigSGIX
1893 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1895 struct glx_display
*priv
;
1896 struct glx_screen
*psc
= NULL
;
1898 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
1899 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1900 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1901 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1908 #ifndef GLX_USE_APPLEGL
1910 ** GLX_SGIX_swap_group
1913 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1923 ** GLX_SGIX_swap_barrier
1926 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1934 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
1944 ** GLX_OML_sync_control
1947 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
1948 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
1950 struct glx_display
* const priv
= __glXInitialize(dpy
);
1952 #ifdef GLX_DIRECT_RENDERING
1953 __GLXDRIdrawable
*pdraw
;
1955 struct glx_screen
*psc
;
1960 #ifdef GLX_DIRECT_RENDERING
1961 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1962 psc
= pdraw
? pdraw
->psc
: NULL
;
1963 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
1964 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
1972 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1974 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
1975 int32_t * numerator
, int32_t * denominator
)
1978 struct glx_screen
*psc
;
1979 XF86VidModeModeLine mode_line
;
1984 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
1985 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
1986 unsigned n
= dot_clock
* 1000;
1987 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
1989 # define V_INTERLACE 0x010
1990 # define V_DBLSCAN 0x020
1992 if (mode_line
.flags
& V_INTERLACE
)
1994 else if (mode_line
.flags
& V_DBLSCAN
)
1997 /* The OML_sync_control spec requires that if the refresh rate is a
1998 * whole number, that the returned numerator be equal to the refresh
1999 * rate and the denominator be 1.
2007 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2009 /* This is a poor man's way to reduce a fraction. It's far from
2010 * perfect, but it will work well enough for this situation.
2013 for (i
= 0; f
[i
] != 0; i
++) {
2014 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2034 * Determine the refresh rate of the specified drawable and display.
2036 * \param dpy Display whose refresh rate is to be determined.
2037 * \param drawable Drawable whose refresh rate is to be determined.
2038 * \param numerator Numerator of the refresh rate.
2039 * \param demoninator Denominator of the refresh rate.
2040 * \return If the refresh rate for the specified display and drawable could
2041 * be calculated, True is returned. Otherwise False is returned.
2043 * \note This function is implemented entirely client-side. A lot of other
2044 * functionality is required to export GLX_OML_sync_control, so on
2045 * XFree86 this function can be called for direct-rendering contexts
2046 * when GLX_OML_sync_control appears in the client extension string.
2050 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2051 int32_t * numerator
, int32_t * denominator
)
2053 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2054 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2059 return __glxGetMscRate(draw
, numerator
, denominator
);
2071 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2072 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2074 struct glx_context
*gc
= __glXGetCurrentContext();
2075 #ifdef GLX_DIRECT_RENDERING
2076 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2077 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2080 if (!gc
) /* no GLX for this */
2083 #ifdef GLX_DIRECT_RENDERING
2084 if (!pdraw
|| !gc
->isDirect
)
2088 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2089 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2090 * of -1 if the function failed because of errors detected in the input
2093 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2095 if (divisor
> 0 && remainder
>= divisor
)
2098 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2101 #ifdef GLX_DIRECT_RENDERING
2102 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2103 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2112 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2113 int64_t target_msc
, int64_t divisor
,
2114 int64_t remainder
, int64_t * ust
,
2115 int64_t * msc
, int64_t * sbc
)
2117 #ifdef GLX_DIRECT_RENDERING
2118 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2119 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2124 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2125 * error", but the return type in the spec is Bool.
2127 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2129 if (divisor
> 0 && remainder
>= divisor
)
2132 #ifdef GLX_DIRECT_RENDERING
2133 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2134 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2145 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2146 int64_t target_sbc
, int64_t * ust
,
2147 int64_t * msc
, int64_t * sbc
)
2149 #ifdef GLX_DIRECT_RENDERING
2150 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2151 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2155 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2156 * error", but the return type in the spec is Bool.
2161 #ifdef GLX_DIRECT_RENDERING
2162 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2163 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2175 * Mesa extension stubs. These will help reduce portability problems.
2180 * Release all buffers associated with the specified GLX drawable.
2183 * This function was intended for stand-alone Mesa. The issue there is that
2184 * the library doesn't get any notification when a window is closed. In
2185 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2186 * supported, there are 3 different functions to destroy a drawable. It
2187 * should be possible to create GLX protocol (or have it determine which
2188 * protocol to use based on the type of the drawable) to have one function
2189 * do the work of 3. For the direct-rendering case, this function could
2190 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2191 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2192 * would need to be used. This really should be done as part of the new DRI
2195 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2196 * __driGarbageCollectDrawables
2197 * glXDestroyGLXPixmap
2198 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2199 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2202 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2211 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2212 Pixmap pixmap
, Colormap cmap
)
2225 * GLX_MESA_copy_sub_buffer
2227 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2229 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2230 int x
, int y
, int width
, int height
)
2232 xGLXVendorPrivateReq
*req
;
2233 struct glx_context
*gc
;
2235 CARD32
*drawable_ptr
;
2236 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2239 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2240 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2241 if (pdraw
!= NULL
) {
2242 struct glx_screen
*psc
= pdraw
->psc
;
2243 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2245 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2252 opcode
= __glXSetupForCommand(dpy
);
2257 ** The calling thread may or may not have a current context. If it
2258 ** does, send the context tag so the server can do a flush.
2260 gc
= __glXGetCurrentContext();
2261 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2262 ((drawable
== gc
->currentDrawable
) ||
2263 (drawable
== gc
->currentReadable
))) {
2264 tag
= gc
->currentContextTag
;
2271 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2272 req
->reqType
= opcode
;
2273 req
->glxCode
= X_GLXVendorPrivate
;
2274 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2275 req
->contextTag
= tag
;
2277 drawable_ptr
= (CARD32
*) (req
+ 1);
2278 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2279 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2280 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2281 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2283 *drawable_ptr
= drawable
;
2295 __glXBindTexImageEXT(Display
* dpy
,
2296 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2298 struct glx_context
*gc
= __glXGetCurrentContext();
2300 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2303 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2307 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2309 struct glx_context
*gc
= __glXGetCurrentContext();
2311 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2314 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2319 #endif /* GLX_USE_APPLEGL */
2322 * \c strdup is actually not a standard ANSI C or POSIX routine.
2323 * Irix will not define it if ANSI mode is in effect.
2328 __glXstrdup(const char *str
)
2331 copy
= (char *) Xmalloc(strlen(str
) + 1);
2339 ** glXGetProcAddress support
2342 struct name_address_pair
2348 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2349 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2351 static const struct name_address_pair GLX_functions
[] = {
2352 /*** GLX_VERSION_1_0 ***/
2353 GLX_FUNCTION(glXChooseVisual
),
2354 GLX_FUNCTION(glXCopyContext
),
2355 GLX_FUNCTION(glXCreateContext
),
2356 GLX_FUNCTION(glXCreateGLXPixmap
),
2357 GLX_FUNCTION(glXDestroyContext
),
2358 GLX_FUNCTION(glXDestroyGLXPixmap
),
2359 GLX_FUNCTION(glXGetConfig
),
2360 GLX_FUNCTION(glXGetCurrentContext
),
2361 GLX_FUNCTION(glXGetCurrentDrawable
),
2362 GLX_FUNCTION(glXIsDirect
),
2363 GLX_FUNCTION(glXMakeCurrent
),
2364 GLX_FUNCTION(glXQueryExtension
),
2365 GLX_FUNCTION(glXQueryVersion
),
2366 GLX_FUNCTION(glXSwapBuffers
),
2367 GLX_FUNCTION(glXUseXFont
),
2368 GLX_FUNCTION(glXWaitGL
),
2369 GLX_FUNCTION(glXWaitX
),
2371 /*** GLX_VERSION_1_1 ***/
2372 GLX_FUNCTION(glXGetClientString
),
2373 GLX_FUNCTION(glXQueryExtensionsString
),
2374 GLX_FUNCTION(glXQueryServerString
),
2376 /*** GLX_VERSION_1_2 ***/
2377 GLX_FUNCTION(glXGetCurrentDisplay
),
2379 /*** GLX_VERSION_1_3 ***/
2380 GLX_FUNCTION(glXChooseFBConfig
),
2381 GLX_FUNCTION(glXCreateNewContext
),
2382 GLX_FUNCTION(glXCreatePbuffer
),
2383 GLX_FUNCTION(glXCreatePixmap
),
2384 GLX_FUNCTION(glXCreateWindow
),
2385 GLX_FUNCTION(glXDestroyPbuffer
),
2386 GLX_FUNCTION(glXDestroyPixmap
),
2387 GLX_FUNCTION(glXDestroyWindow
),
2388 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2389 GLX_FUNCTION(glXGetFBConfigAttrib
),
2390 GLX_FUNCTION(glXGetFBConfigs
),
2391 GLX_FUNCTION(glXGetSelectedEvent
),
2392 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2393 GLX_FUNCTION(glXMakeContextCurrent
),
2394 GLX_FUNCTION(glXQueryContext
),
2395 GLX_FUNCTION(glXQueryDrawable
),
2396 GLX_FUNCTION(glXSelectEvent
),
2398 #ifndef GLX_USE_APPLEGL
2399 /*** GLX_SGI_swap_control ***/
2400 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2402 /*** GLX_SGI_video_sync ***/
2403 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2404 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2406 /*** GLX_SGI_make_current_read ***/
2407 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2408 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2410 /*** GLX_EXT_import_context ***/
2411 GLX_FUNCTION(glXFreeContextEXT
),
2412 GLX_FUNCTION(glXGetContextIDEXT
),
2413 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2414 GLX_FUNCTION(glXImportContextEXT
),
2415 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2418 /*** GLX_SGIX_fbconfig ***/
2419 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2420 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2421 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2422 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2423 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2424 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2426 #ifndef GLX_USE_APPLEGL
2427 /*** GLX_SGIX_pbuffer ***/
2428 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2429 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2430 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2431 GLX_FUNCTION(glXSelectEventSGIX
),
2432 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2434 /*** GLX_SGIX_swap_group ***/
2435 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2437 /*** GLX_SGIX_swap_barrier ***/
2438 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2439 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2441 /*** GLX_MESA_copy_sub_buffer ***/
2442 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2444 /*** GLX_MESA_pixmap_colormap ***/
2445 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2447 /*** GLX_MESA_release_buffers ***/
2448 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2450 /*** GLX_MESA_swap_control ***/
2451 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2452 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2455 /*** GLX_ARB_get_proc_address ***/
2456 GLX_FUNCTION(glXGetProcAddressARB
),
2459 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2461 #ifndef GLX_USE_APPLEGL
2462 /*** GLX_OML_sync_control ***/
2463 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2464 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2465 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2466 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2467 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2469 /*** GLX_EXT_texture_from_pixmap ***/
2470 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2471 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2474 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2475 /*** DRI configuration ***/
2476 GLX_FUNCTION(glXGetScreenDriver
),
2477 GLX_FUNCTION(glXGetDriverConfig
),
2480 {NULL
, NULL
} /* end of list */
2483 #ifndef GLX_USE_APPLEGL
2484 static const GLvoid
*
2485 get_glx_proc_address(const char *funcName
)
2489 /* try static functions */
2490 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2491 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2492 return GLX_functions
[i
].Address
;
2500 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2501 * \c glXGetProcAddress.
2503 * \param procName Name of a GL or GLX function.
2504 * \returns A pointer to the named function
2506 * \sa glXGetProcAddress
2508 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2510 typedef void (*gl_function
) (void);
2514 /* Search the table of GLX and internal functions first. If that
2515 * fails and the supplied name could be a valid core GL name, try
2516 * searching the core GL function table. This check is done to prevent
2517 * DRI based drivers from searching the core GL function table for
2518 * internal API functions.
2520 #ifdef GLX_USE_APPLEGL
2521 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2523 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2524 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2525 && (procName
[2] != 'X')) {
2526 #ifdef GLX_SHARED_GLAPI
2527 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2530 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2537 * Get the address of a named GL function. This is the GLX 1.4 name for
2538 * \c glXGetProcAddressARB.
2540 * \param procName Name of a GL or GLX function.
2541 * \returns A pointer to the named function
2543 * \sa glXGetProcAddressARB
2545 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2546 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2547 __attribute__ ((alias("glXGetProcAddressARB")));
2550 return glXGetProcAddressARB(procName
);
2552 #endif /* __GNUC__ */
2555 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2557 * Get the unadjusted system time (UST). Currently, the UST is measured in
2558 * microseconds since Epoc. The actual resolution of the UST may vary from
2559 * system to system, and the units may vary from release to release.
2560 * Drivers should not call this function directly. They should instead use
2561 * \c glXGetProcAddress to obtain a pointer to the function.
2563 * \param ust Location to store the 64-bit UST
2564 * \returns Zero on success or a negative errno value on failure.
2566 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2568 * \since Internal API version 20030317.
2571 __glXGetUST(int64_t * ust
)
2579 if (gettimeofday(&tv
, NULL
) == 0) {
2580 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2587 #endif /* GLX_DIRECT_RENDERING */