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 if (gc
->vtable
->destroy
)
381 gc
->vtable
->destroy(gc
);
385 glXDestroyContext(Display
* dpy
, GLXContext gc
)
387 DestroyContext(dpy
, gc
);
391 ** Return the major and minor version #s for the GLX extension
394 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
396 struct glx_display
*priv
;
398 /* Init the extension. This fetches the major and minor version. */
399 priv
= __glXInitialize(dpy
);
404 *major
= priv
->majorVersion
;
406 *minor
= priv
->minorVersion
;
411 ** Query the existance of the GLX extension
414 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
416 int major_op
, erb
, evb
;
419 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
430 ** Put a barrier in the token stream that forces the GL to finish its
431 ** work before X can proceed.
436 struct glx_context
*gc
= __glXGetCurrentContext();
438 if (gc
&& gc
->vtable
->wait_gl
)
439 gc
->vtable
->wait_gl(gc
);
443 ** Put a barrier in the token stream that forces X to finish its
444 ** work before GL can proceed.
449 struct glx_context
*gc
= __glXGetCurrentContext();
451 if (gc
&& gc
->vtable
->wait_x
)
452 gc
->vtable
->wait_x(gc
);
456 glXUseXFont(Font font
, int first
, int count
, int listBase
)
458 struct glx_context
*gc
= __glXGetCurrentContext();
460 if (gc
&& gc
->vtable
->use_x_font
)
461 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
464 /************************************************************************/
467 ** Copy the source context to the destination context using the
471 glXCopyContext(Display
* dpy
, GLXContext source_user
,
472 GLXContext dest_user
, unsigned long mask
)
474 struct glx_context
*source
= (struct glx_context
*) source_user
;
475 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
476 #ifdef GLX_USE_APPLEGL
477 struct glx_context
*gc
= __glXGetCurrentContext();
481 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
482 mask
, &errorcode
, &x11error
)) {
483 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
487 xGLXCopyContextReq
*req
;
488 struct glx_context
*gc
= __glXGetCurrentContext();
492 opcode
= __glXSetupForCommand(dpy
);
497 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
499 /* NOT_DONE: This does not work yet */
504 ** If the source is the current context, send its tag so that the context
505 ** can be flushed before the copy.
507 if (source
== gc
&& dpy
== gc
->currentDpy
) {
508 tag
= gc
->currentContextTag
;
514 /* Send the glXCopyContext request */
516 GetReq(GLXCopyContext
, req
);
517 req
->reqType
= opcode
;
518 req
->glxCode
= X_GLXCopyContext
;
519 req
->source
= source
? source
->xid
: None
;
520 req
->dest
= dest
? dest
->xid
: None
;
522 req
->contextTag
= tag
;
525 #endif /* GLX_USE_APPLEGL */
530 * Determine if a context uses direct rendering.
532 * \param dpy Display where the context was created.
533 * \param contextID ID of the context to be tested.
535 * \returns \c GL_TRUE if the context is direct rendering or not.
538 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
540 #if !defined(USE_XCB)
541 xGLXIsDirectReq
*req
;
542 xGLXIsDirectReply reply
;
546 opcode
= __glXSetupForCommand(dpy
);
552 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
553 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
558 const Bool is_direct
= reply
->is_direct
? True
: False
;
563 /* Send the glXIsDirect request */
565 GetReq(GLXIsDirect
, req
);
566 req
->reqType
= opcode
;
567 req
->glxCode
= X_GLXIsDirect
;
568 req
->context
= contextID
;
569 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
573 return reply
.isDirect
;
579 * Shouldn't this function \b always return \c GL_FALSE when
580 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
581 * the GLX protocol here at all?
584 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
586 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
591 else if (gc
->isDirect
) {
594 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
597 return __glXIsDirect(dpy
, gc
->xid
);
602 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
604 #ifdef GLX_USE_APPLEGL
605 int screen
= vis
->screen
;
606 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
607 const struct glx_config
*config
;
609 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
611 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
616 xGLXCreateGLXPixmapReq
*req
;
620 opcode
= __glXSetupForCommand(dpy
);
625 /* Send the glXCreateGLXPixmap request */
627 GetReq(GLXCreateGLXPixmap
, req
);
628 req
->reqType
= opcode
;
629 req
->glxCode
= X_GLXCreateGLXPixmap
;
630 req
->screen
= vis
->screen
;
631 req
->visual
= vis
->visualid
;
632 req
->pixmap
= pixmap
;
633 req
->glxpixmap
= xid
= XAllocID(dpy
);
637 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
639 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
640 * is actually bound to a context... */
642 struct glx_display
*const priv
= __glXInitialize(dpy
);
643 __GLXDRIdrawable
*pdraw
;
644 struct glx_screen
*psc
;
645 struct glx_config
*config
;
647 psc
= priv
->screens
[vis
->screen
];
648 if (psc
->driScreen
== NULL
)
650 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
651 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
653 fprintf(stderr
, "failed to create pixmap\n");
657 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
658 (*pdraw
->destroyDrawable
) (pdraw
);
659 return None
; /* FIXME: Check what we're supposed to do here... */
669 ** Destroy the named pixmap
672 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
674 #ifdef GLX_USE_APPLEGL
675 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
676 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
678 xGLXDestroyGLXPixmapReq
*req
;
681 opcode
= __glXSetupForCommand(dpy
);
686 /* Send the glXDestroyGLXPixmap request */
688 GetReq(GLXDestroyGLXPixmap
, req
);
689 req
->reqType
= opcode
;
690 req
->glxCode
= X_GLXDestroyGLXPixmap
;
691 req
->glxpixmap
= glxpixmap
;
695 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
697 struct glx_display
*const priv
= __glXInitialize(dpy
);
698 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
701 (*pdraw
->destroyDrawable
) (pdraw
);
702 __glxHashDelete(priv
->drawHash
, glxpixmap
);
706 #endif /* GLX_USE_APPLEGL */
710 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
712 #ifdef GLX_USE_APPLEGL
713 struct glx_context
* gc
= __glXGetCurrentContext();
714 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
715 apple_glx_swap_buffers(gc
->driContext
);
717 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
720 struct glx_context
*gc
;
726 xGLXSwapBuffersReq
*req
;
729 gc
= __glXGetCurrentContext();
731 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
732 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
735 if (gc
&& drawable
== gc
->currentDrawable
) {
739 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
744 opcode
= __glXSetupForCommand(dpy
);
750 ** The calling thread may or may not have a current context. If it
751 ** does, send the context tag so the server can do a flush.
753 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
754 ((drawable
== gc
->currentDrawable
)
755 || (drawable
== gc
->currentReadable
))) {
756 tag
= gc
->currentContextTag
;
763 c
= XGetXCBConnection(dpy
);
764 xcb_glx_swap_buffers(c
, tag
, drawable
);
767 /* Send the glXSwapBuffers request */
769 GetReq(GLXSwapBuffers
, req
);
770 req
->reqType
= opcode
;
771 req
->glxCode
= X_GLXSwapBuffers
;
772 req
->drawable
= drawable
;
773 req
->contextTag
= tag
;
778 #endif /* GLX_USE_APPLEGL */
783 ** Return configuration information for the given display, screen and
784 ** visual combination.
787 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
790 struct glx_display
*priv
;
791 struct glx_screen
*psc
;
792 struct glx_config
*config
;
795 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
796 if (status
== Success
) {
797 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
799 /* Lookup attribute after first finding a match on the visual */
800 if (config
!= NULL
) {
801 return glx_config_get(config
, attribute
, value_return
);
804 status
= GLX_BAD_VISUAL
;
808 ** If we can't find the config for this visual, this visual is not
809 ** supported by the OpenGL implementation on the server.
811 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
812 *value_return
= GL_FALSE
;
819 /************************************************************************/
822 init_fbconfig_for_chooser(struct glx_config
* config
,
823 GLboolean fbconfig_style_tags
)
825 memset(config
, 0, sizeof(struct glx_config
));
826 config
->visualID
= (XID
) GLX_DONT_CARE
;
827 config
->visualType
= GLX_DONT_CARE
;
829 /* glXChooseFBConfig specifies different defaults for these two than
832 if (fbconfig_style_tags
) {
833 config
->rgbMode
= GL_TRUE
;
834 config
->doubleBufferMode
= GLX_DONT_CARE
;
837 config
->visualRating
= GLX_DONT_CARE
;
838 config
->transparentPixel
= GLX_NONE
;
839 config
->transparentRed
= GLX_DONT_CARE
;
840 config
->transparentGreen
= GLX_DONT_CARE
;
841 config
->transparentBlue
= GLX_DONT_CARE
;
842 config
->transparentAlpha
= GLX_DONT_CARE
;
843 config
->transparentIndex
= GLX_DONT_CARE
;
845 config
->drawableType
= GLX_WINDOW_BIT
;
847 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
848 config
->xRenderable
= GLX_DONT_CARE
;
849 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
851 config
->swapMethod
= GLX_DONT_CARE
;
854 #define MATCH_DONT_CARE( param ) \
856 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
857 && (a-> param != b-> param) ) { \
862 #define MATCH_MINIMUM( param ) \
864 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
865 && (a-> param > b-> param) ) { \
870 #define MATCH_EXACT( param ) \
872 if ( a-> param != b-> param) { \
877 /* Test that all bits from a are contained in b */
878 #define MATCH_MASK(param) \
880 if ((a->param & ~b->param) != 0) \
885 * Determine if two GLXFBConfigs are compatible.
887 * \param a Application specified config to test.
888 * \param b Server specified config to test against \c a.
891 fbconfigs_compatible(const struct glx_config
* const a
,
892 const struct glx_config
* const b
)
894 MATCH_DONT_CARE(doubleBufferMode
);
895 MATCH_DONT_CARE(visualType
);
896 MATCH_DONT_CARE(visualRating
);
897 MATCH_DONT_CARE(xRenderable
);
898 MATCH_DONT_CARE(fbconfigID
);
899 MATCH_DONT_CARE(swapMethod
);
901 MATCH_MINIMUM(rgbBits
);
902 MATCH_MINIMUM(numAuxBuffers
);
903 MATCH_MINIMUM(redBits
);
904 MATCH_MINIMUM(greenBits
);
905 MATCH_MINIMUM(blueBits
);
906 MATCH_MINIMUM(alphaBits
);
907 MATCH_MINIMUM(depthBits
);
908 MATCH_MINIMUM(stencilBits
);
909 MATCH_MINIMUM(accumRedBits
);
910 MATCH_MINIMUM(accumGreenBits
);
911 MATCH_MINIMUM(accumBlueBits
);
912 MATCH_MINIMUM(accumAlphaBits
);
913 MATCH_MINIMUM(sampleBuffers
);
914 MATCH_MINIMUM(maxPbufferWidth
);
915 MATCH_MINIMUM(maxPbufferHeight
);
916 MATCH_MINIMUM(maxPbufferPixels
);
917 MATCH_MINIMUM(samples
);
919 MATCH_DONT_CARE(stereoMode
);
922 MATCH_MASK(drawableType
);
923 MATCH_MASK(renderType
);
925 /* There is a bug in a few of the XFree86 DDX drivers. They contain
926 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
927 * Technically speaking, it is a bug in the DDX driver, but there is
928 * enough of an installed base to work around the problem here. In any
929 * case, 0 is not a valid value of the transparent type, so we'll treat 0
930 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
931 * 0 from the server to be a match to maintain backward compatibility with
932 * the (broken) drivers.
935 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
936 if (a
->transparentPixel
== GLX_NONE
) {
937 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
941 MATCH_EXACT(transparentPixel
);
944 switch (a
->transparentPixel
) {
945 case GLX_TRANSPARENT_RGB
:
946 MATCH_DONT_CARE(transparentRed
);
947 MATCH_DONT_CARE(transparentGreen
);
948 MATCH_DONT_CARE(transparentBlue
);
949 MATCH_DONT_CARE(transparentAlpha
);
952 case GLX_TRANSPARENT_INDEX
:
953 MATCH_DONT_CARE(transparentIndex
);
965 /* There's some trickly language in the GLX spec about how this is supposed
966 * to work. Basically, if a given component size is either not specified
967 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
968 * Well, that's really hard to do with the code as-is. This behavior is
969 * closer to correct, but still not technically right.
971 #define PREFER_LARGER_OR_ZERO(comp) \
973 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
974 if ( ((*a)-> comp) == 0 ) { \
977 else if ( ((*b)-> comp) == 0 ) { \
981 return ((*b)-> comp) - ((*a)-> comp) ; \
986 #define PREFER_LARGER(comp) \
988 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
989 return ((*b)-> comp) - ((*a)-> comp) ; \
993 #define PREFER_SMALLER(comp) \
995 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
996 return ((*a)-> comp) - ((*b)-> comp) ; \
1001 * Compare two GLXFBConfigs. This function is intended to be used as the
1002 * compare function passed in to qsort.
1004 * \returns If \c a is a "better" config, according to the specification of
1005 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1006 * better, then a number greater than zero is return. If both are
1007 * equal, zero is returned.
1008 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1011 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1013 /* The order of these comparisons must NOT change. It is defined by
1014 * the GLX 1.3 spec and ARB_multisample.
1017 PREFER_SMALLER(visualSelectGroup
);
1019 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1020 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1021 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1023 PREFER_SMALLER(visualRating
);
1025 /* This isn't quite right. It is supposed to compare the sum of the
1026 * components the user specifically set minimums for.
1028 PREFER_LARGER_OR_ZERO(redBits
);
1029 PREFER_LARGER_OR_ZERO(greenBits
);
1030 PREFER_LARGER_OR_ZERO(blueBits
);
1031 PREFER_LARGER_OR_ZERO(alphaBits
);
1033 PREFER_SMALLER(rgbBits
);
1035 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1036 /* Prefer single-buffer.
1038 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1041 PREFER_SMALLER(numAuxBuffers
);
1043 PREFER_LARGER_OR_ZERO(depthBits
);
1044 PREFER_SMALLER(stencilBits
);
1046 /* This isn't quite right. It is supposed to compare the sum of the
1047 * components the user specifically set minimums for.
1049 PREFER_LARGER_OR_ZERO(accumRedBits
);
1050 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1051 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1052 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1054 PREFER_SMALLER(visualType
);
1056 /* None of the multisample specs say where this comparison should happen,
1057 * so I put it near the end.
1059 PREFER_SMALLER(sampleBuffers
);
1060 PREFER_SMALLER(samples
);
1062 /* None of the pbuffer or fbconfig specs say that this comparison needs
1063 * to happen at all, but it seems like it should.
1065 PREFER_LARGER(maxPbufferWidth
);
1066 PREFER_LARGER(maxPbufferHeight
);
1067 PREFER_LARGER(maxPbufferPixels
);
1074 * Selects and sorts a subset of the supplied configs based on the attributes.
1075 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1076 * and \c glXChooseFBConfigSGIX.
1078 * \param configs Array of pointers to possible configs. The elements of
1079 * this array that do not meet the criteria will be set to
1080 * NULL. The remaining elements will be sorted according to
1081 * the various visual / FBConfig selection rules.
1082 * \param num_configs Number of elements in the \c configs array.
1083 * \param attribList Attributes used select from \c configs. This array is
1084 * terminated by a \c None tag. The array can either take
1085 * the form expected by \c glXChooseVisual (where boolean
1086 * tags do not have a value) or by \c glXChooseFBConfig
1087 * (where every tag has a value).
1088 * \param fbconfig_style_tags Selects whether \c attribList is in
1089 * \c glXChooseVisual style or
1090 * \c glXChooseFBConfig style.
1091 * \returns The number of valid elements left in \c configs.
1093 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1096 choose_visual(struct glx_config
** configs
, int num_configs
,
1097 const int *attribList
, GLboolean fbconfig_style_tags
)
1099 struct glx_config test_config
;
1103 /* This is a fairly direct implementation of the selection method
1104 * described by GLX_SGIX_fbconfig. Start by culling out all the
1105 * configs that are not compatible with the selected parameter
1109 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1110 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1111 (const INT32
*) attribList
,
1112 GL_TRUE
, fbconfig_style_tags
);
1115 for (i
= 0; i
< num_configs
; i
++) {
1116 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1117 configs
[base
] = configs
[i
];
1126 if (base
< num_configs
) {
1127 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1130 /* After the incompatible configs are removed, the resulting
1131 * list is sorted according to the rules set out in the various
1135 qsort(configs
, base
, sizeof(struct glx_config
*),
1136 (int (*)(const void *, const void *)) fbconfig_compare
);
1144 ** Return the visual that best matches the template. Return None if no
1145 ** visual matches the template.
1147 _X_EXPORT XVisualInfo
*
1148 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1150 XVisualInfo
*visualList
= NULL
;
1151 struct glx_display
*priv
;
1152 struct glx_screen
*psc
;
1153 struct glx_config test_config
;
1154 struct glx_config
*config
;
1155 struct glx_config
*best_config
= NULL
;
1158 ** Get a list of all visuals, return if list is empty
1160 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1166 ** Build a template from the defaults and the attribute list
1167 ** Free visual list and return if an unexpected token is encountered
1169 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1170 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1171 (const INT32
*) attribList
,
1175 ** Eliminate visuals that don't meet minimum requirements
1176 ** Compute a score for those that do
1177 ** Remember which visual, if any, got the highest score
1178 ** If no visual is acceptable, return None
1179 ** Otherwise, create an XVisualInfo list with just the selected X visual
1182 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1183 if (fbconfigs_compatible(&test_config
, config
)
1184 && ((best_config
== NULL
) ||
1185 (fbconfig_compare (&config
, &best_config
) < 0))) {
1186 XVisualInfo visualTemplate
;
1187 XVisualInfo
*newList
;
1190 visualTemplate
.screen
= screen
;
1191 visualTemplate
.visualid
= config
->visualID
;
1192 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1193 &visualTemplate
, &i
);
1197 visualList
= newList
;
1198 best_config
= config
;
1203 #ifdef GLX_USE_APPLEGL
1204 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1205 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1213 _X_EXPORT
const char *
1214 glXQueryExtensionsString(Display
* dpy
, int screen
)
1216 struct glx_screen
*psc
;
1217 struct glx_display
*priv
;
1219 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1223 if (!psc
->effectiveGLXexts
) {
1224 if (!psc
->serverGLXexts
) {
1225 psc
->serverGLXexts
=
1226 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1230 __glXCalculateUsableExtensions(psc
,
1231 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1232 (psc
->driScreen
!= NULL
),
1236 priv
->minorVersion
);
1239 return psc
->effectiveGLXexts
;
1242 _X_EXPORT
const char *
1243 glXGetClientString(Display
* dpy
, int name
)
1249 return (__glXGLXClientVendorName
);
1251 return (__glXGLXClientVersion
);
1252 case GLX_EXTENSIONS
:
1253 return (__glXGetClientExtensions());
1259 _X_EXPORT
const char *
1260 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1262 struct glx_screen
*psc
;
1263 struct glx_display
*priv
;
1267 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1273 str
= &priv
->serverGLXvendor
;
1276 str
= &priv
->serverGLXversion
;
1278 case GLX_EXTENSIONS
:
1279 str
= &psc
->serverGLXexts
;
1286 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1293 __glXClientInfo(Display
* dpy
, int opcode
)
1295 char *ext_str
= __glXGetClientGLExtensionString();
1296 int size
= strlen(ext_str
) + 1;
1299 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1300 xcb_glx_client_info(c
,
1301 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1303 xGLXClientInfoReq
*req
;
1305 /* Send the glXClientInfo request */
1307 GetReq(GLXClientInfo
, req
);
1308 req
->reqType
= opcode
;
1309 req
->glxCode
= X_GLXClientInfo
;
1310 req
->major
= GLX_MAJOR_VERSION
;
1311 req
->minor
= GLX_MINOR_VERSION
;
1313 req
->length
+= (size
+ 3) >> 2;
1314 req
->numbytes
= size
;
1315 Data(dpy
, ext_str
, size
);
1319 #endif /* USE_XCB */
1326 ** EXT_import_context
1330 glXGetCurrentDisplay(void)
1332 struct glx_context
*gc
= __glXGetCurrentContext();
1335 return gc
->currentDpy
;
1339 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1340 glXGetCurrentDisplay
)
1342 #ifndef GLX_USE_APPLEGL
1343 _X_EXPORT GLXContext
1344 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1346 struct glx_display
*priv
= __glXInitialize(dpy
);
1347 struct glx_screen
*psc
;
1348 xGLXQueryContextReply reply
;
1350 struct glx_context
*ctx
;
1351 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1354 struct glx_config
*mode
;
1356 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1359 opcode
= __glXSetupForCommand(dpy
);
1363 /* Send the glXQueryContextInfoEXT request */
1366 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1367 xGLXQueryContextReq
*req
;
1369 GetReq(GLXQueryContext
, req
);
1371 req
->reqType
= opcode
;
1372 req
->glxCode
= X_GLXQueryContext
;
1373 req
->context
= contextID
;
1376 xGLXVendorPrivateReq
*vpreq
;
1377 xGLXQueryContextInfoEXTReq
*req
;
1379 GetReqExtra(GLXVendorPrivate
,
1380 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1382 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1383 req
->reqType
= opcode
;
1384 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1385 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1386 req
->context
= contextID
;
1389 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1391 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1392 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1395 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1399 /* Look up screen first so we can look up visuals/fbconfigs later */
1401 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1402 if (pProp
[0] == GLX_SCREEN
)
1403 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1412 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1414 case GLX_SHARE_CONTEXT_EXT
:
1417 case GLX_VISUAL_ID_EXT
:
1418 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1420 case GLX_FBCONFIG_ID
:
1421 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1423 case GLX_RENDER_TYPE
:
1424 renderType
= pProp
[1];
1431 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1435 ctx
->xid
= contextID
;
1436 ctx
->imported
= GL_TRUE
;
1437 ctx
->share_xid
= share
;
1439 return (GLXContext
) ctx
;
1445 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1447 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1449 switch (attribute
) {
1450 case GLX_SHARE_CONTEXT_EXT
:
1451 *value
= ctx
->share_xid
;
1453 case GLX_VISUAL_ID_EXT
:
1454 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1457 *value
= ctx
->screen
;
1459 case GLX_FBCONFIG_ID
:
1460 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1462 case GLX_RENDER_TYPE
:
1463 *value
= ctx
->renderType
;
1466 return GLX_BAD_ATTRIBUTE
;
1472 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1473 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1474 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1476 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1478 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1484 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1486 DestroyContext(dpy
, ctx
);
1490 _X_EXPORT GLXFBConfig
*
1491 glXChooseFBConfig(Display
* dpy
, int screen
,
1492 const int *attribList
, int *nitems
)
1494 struct glx_config
**config_list
;
1498 config_list
= (struct glx_config
**)
1499 glXGetFBConfigs(dpy
, screen
, &list_size
);
1501 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1502 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1503 if (list_size
== 0) {
1509 *nitems
= list_size
;
1510 return (GLXFBConfig
*) config_list
;
1514 _X_EXPORT GLXContext
1515 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1516 int renderType
, GLXContext shareList
, Bool allowDirect
)
1518 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1520 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1521 allowDirect
, X_GLXCreateNewContext
, renderType
,
1526 _X_EXPORT GLXDrawable
1527 glXGetCurrentReadDrawable(void)
1529 struct glx_context
*gc
= __glXGetCurrentContext();
1531 return gc
->currentReadable
;
1535 _X_EXPORT GLXFBConfig
*
1536 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1538 struct glx_display
*priv
= __glXInitialize(dpy
);
1539 struct glx_config
**config_list
= NULL
;
1540 struct glx_config
*config
;
1541 unsigned num_configs
= 0;
1545 if (priv
&& (priv
->screens
!= NULL
)
1546 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1547 && (priv
->screens
[screen
]->configs
!= NULL
)
1548 && (priv
->screens
[screen
]->configs
->fbconfigID
1549 != (int) GLX_DONT_CARE
)) {
1551 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1552 config
= config
->next
) {
1553 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1558 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1559 if (config_list
!= NULL
) {
1560 *nelements
= num_configs
;
1562 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1563 config
= config
->next
) {
1564 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1565 config_list
[i
] = config
;
1572 return (GLXFBConfig
*) config_list
;
1577 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1578 int attribute
, int *value
)
1580 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1583 return GLXBadFBConfig
;
1585 return glx_config_get(config
, attribute
, value
);
1589 _X_EXPORT XVisualInfo
*
1590 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1592 XVisualInfo visualTemplate
;
1593 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1597 ** Get a list of all visuals, return if list is empty
1599 visualTemplate
.visualid
= config
->visualID
;
1600 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1603 #ifndef GLX_USE_APPLEGL
1605 ** GLX_SGI_swap_control
1608 __glXSwapIntervalSGI(int interval
)
1610 xGLXVendorPrivateReq
*req
;
1611 struct glx_context
*gc
= __glXGetCurrentContext();
1612 struct glx_screen
*psc
;
1614 CARD32
*interval_ptr
;
1618 return GLX_BAD_CONTEXT
;
1621 if (interval
<= 0) {
1622 return GLX_BAD_VALUE
;
1625 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1627 #ifdef GLX_DIRECT_RENDERING
1628 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1629 __GLXDRIdrawable
*pdraw
=
1630 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1631 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1636 dpy
= gc
->currentDpy
;
1637 opcode
= __glXSetupForCommand(dpy
);
1642 /* Send the glXSwapIntervalSGI request */
1644 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1645 req
->reqType
= opcode
;
1646 req
->glxCode
= X_GLXVendorPrivate
;
1647 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1648 req
->contextTag
= gc
->currentContextTag
;
1650 interval_ptr
= (CARD32
*) (req
+ 1);
1651 *interval_ptr
= interval
;
1662 ** GLX_MESA_swap_control
1665 __glXSwapIntervalMESA(unsigned int interval
)
1667 #ifdef GLX_DIRECT_RENDERING
1668 struct glx_context
*gc
= __glXGetCurrentContext();
1670 if (gc
!= NULL
&& gc
->isDirect
) {
1671 struct glx_screen
*psc
;
1673 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1674 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1675 __GLXDRIdrawable
*pdraw
=
1676 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1677 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1682 return GLX_BAD_CONTEXT
;
1687 __glXGetSwapIntervalMESA(void)
1689 #ifdef GLX_DIRECT_RENDERING
1690 struct glx_context
*gc
= __glXGetCurrentContext();
1692 if (gc
!= NULL
&& gc
->isDirect
) {
1693 struct glx_screen
*psc
;
1695 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1696 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1697 __GLXDRIdrawable
*pdraw
=
1698 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1699 return psc
->driScreen
->getSwapInterval(pdraw
);
1709 ** GLX_SGI_video_sync
1712 __glXGetVideoSyncSGI(unsigned int *count
)
1714 int64_t ust
, msc
, sbc
;
1716 struct glx_context
*gc
= __glXGetCurrentContext();
1717 struct glx_screen
*psc
;
1718 #ifdef GLX_DIRECT_RENDERING
1719 __GLXDRIdrawable
*pdraw
;
1723 return GLX_BAD_CONTEXT
;
1725 #ifdef GLX_DIRECT_RENDERING
1727 return GLX_BAD_CONTEXT
;
1730 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1731 #ifdef GLX_DIRECT_RENDERING
1732 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1735 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1736 * FIXME: there should be a GLX encoding for this call. I can find no
1737 * FIXME: documentation for the GLX encoding.
1739 #ifdef GLX_DIRECT_RENDERING
1740 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1741 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1742 *count
= (unsigned) msc
;
1743 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1747 return GLX_BAD_CONTEXT
;
1751 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1753 struct glx_context
*gc
= __glXGetCurrentContext();
1754 struct glx_screen
*psc
;
1755 #ifdef GLX_DIRECT_RENDERING
1756 __GLXDRIdrawable
*pdraw
;
1758 int64_t ust
, msc
, sbc
;
1761 if (divisor
<= 0 || remainder
< 0)
1762 return GLX_BAD_VALUE
;
1765 return GLX_BAD_CONTEXT
;
1767 #ifdef GLX_DIRECT_RENDERING
1769 return GLX_BAD_CONTEXT
;
1772 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1773 #ifdef GLX_DIRECT_RENDERING
1774 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1777 #ifdef GLX_DIRECT_RENDERING
1778 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1779 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1781 *count
= (unsigned) msc
;
1782 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1786 return GLX_BAD_CONTEXT
;
1789 #endif /* GLX_USE_APPLEGL */
1792 ** GLX_SGIX_fbconfig
1793 ** Many of these functions are aliased to GLX 1.3 entry points in the
1794 ** GLX_functions table.
1798 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1799 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1800 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1802 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1803 (Display
* dpy
, int screen
, int *attrib_list
,
1804 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1807 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1808 (Display
* dpy
, GLXFBConfigSGIX config
),
1809 (dpy
, config
), glXGetVisualFromFBConfig
)
1812 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1813 GLXFBConfigSGIX fbconfig
,
1816 #ifndef GLX_USE_APPLEGL
1817 xGLXVendorPrivateWithReplyReq
*vpreq
;
1818 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1819 GLXPixmap xid
= None
;
1821 struct glx_screen
*psc
;
1823 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1826 if ((dpy
== NULL
) || (config
== NULL
)) {
1829 #ifdef GLX_USE_APPLEGL
1830 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1835 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1837 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1838 opcode
= __glXSetupForCommand(dpy
);
1843 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1845 GetReqExtra(GLXVendorPrivateWithReply
,
1846 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1847 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1848 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1849 req
->reqType
= opcode
;
1850 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1851 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1852 req
->screen
= config
->screen
;
1853 req
->fbconfig
= config
->fbconfigID
;
1854 req
->pixmap
= pixmap
;
1855 req
->glxpixmap
= xid
= XAllocID(dpy
);
1864 _X_EXPORT GLXContext
1865 glXCreateContextWithConfigSGIX(Display
* dpy
,
1866 GLXFBConfigSGIX fbconfig
, int renderType
,
1867 GLXContext shareList
, Bool allowDirect
)
1869 GLXContext gc
= NULL
;
1870 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1871 struct glx_screen
*psc
;
1874 if ((dpy
== NULL
) || (config
== NULL
)) {
1878 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1880 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1881 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1883 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1891 _X_EXPORT GLXFBConfigSGIX
1892 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1894 struct glx_display
*priv
;
1895 struct glx_screen
*psc
= NULL
;
1897 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
1898 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1899 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1900 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1907 #ifndef GLX_USE_APPLEGL
1909 ** GLX_SGIX_swap_group
1912 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1922 ** GLX_SGIX_swap_barrier
1925 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1933 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
1943 ** GLX_OML_sync_control
1946 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
1947 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
1949 struct glx_display
* const priv
= __glXInitialize(dpy
);
1951 #ifdef GLX_DIRECT_RENDERING
1952 __GLXDRIdrawable
*pdraw
;
1954 struct glx_screen
*psc
;
1959 #ifdef GLX_DIRECT_RENDERING
1960 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1961 psc
= pdraw
? pdraw
->psc
: NULL
;
1962 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
1963 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
1971 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1973 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
1974 int32_t * numerator
, int32_t * denominator
)
1977 struct glx_screen
*psc
;
1978 XF86VidModeModeLine mode_line
;
1983 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
1984 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
1985 unsigned n
= dot_clock
* 1000;
1986 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
1988 # define V_INTERLACE 0x010
1989 # define V_DBLSCAN 0x020
1991 if (mode_line
.flags
& V_INTERLACE
)
1993 else if (mode_line
.flags
& V_DBLSCAN
)
1996 /* The OML_sync_control spec requires that if the refresh rate is a
1997 * whole number, that the returned numerator be equal to the refresh
1998 * rate and the denominator be 1.
2006 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2008 /* This is a poor man's way to reduce a fraction. It's far from
2009 * perfect, but it will work well enough for this situation.
2012 for (i
= 0; f
[i
] != 0; i
++) {
2013 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2033 * Determine the refresh rate of the specified drawable and display.
2035 * \param dpy Display whose refresh rate is to be determined.
2036 * \param drawable Drawable whose refresh rate is to be determined.
2037 * \param numerator Numerator of the refresh rate.
2038 * \param demoninator Denominator of the refresh rate.
2039 * \return If the refresh rate for the specified display and drawable could
2040 * be calculated, True is returned. Otherwise False is returned.
2042 * \note This function is implemented entirely client-side. A lot of other
2043 * functionality is required to export GLX_OML_sync_control, so on
2044 * XFree86 this function can be called for direct-rendering contexts
2045 * when GLX_OML_sync_control appears in the client extension string.
2049 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2050 int32_t * numerator
, int32_t * denominator
)
2052 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2053 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2058 return __glxGetMscRate(draw
, numerator
, denominator
);
2070 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2071 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2073 struct glx_context
*gc
= __glXGetCurrentContext();
2074 #ifdef GLX_DIRECT_RENDERING
2075 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2076 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2079 if (!gc
) /* no GLX for this */
2082 #ifdef GLX_DIRECT_RENDERING
2083 if (!pdraw
|| !gc
->isDirect
)
2087 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2088 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2089 * of -1 if the function failed because of errors detected in the input
2092 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2094 if (divisor
> 0 && remainder
>= divisor
)
2097 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2100 #ifdef GLX_DIRECT_RENDERING
2101 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2102 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2111 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2112 int64_t target_msc
, int64_t divisor
,
2113 int64_t remainder
, int64_t * ust
,
2114 int64_t * msc
, int64_t * sbc
)
2116 #ifdef GLX_DIRECT_RENDERING
2117 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2118 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2123 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2124 * error", but the return type in the spec is Bool.
2126 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2128 if (divisor
> 0 && remainder
>= divisor
)
2131 #ifdef GLX_DIRECT_RENDERING
2132 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2133 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2144 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2145 int64_t target_sbc
, int64_t * ust
,
2146 int64_t * msc
, int64_t * sbc
)
2148 #ifdef GLX_DIRECT_RENDERING
2149 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2150 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2154 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2155 * error", but the return type in the spec is Bool.
2160 #ifdef GLX_DIRECT_RENDERING
2161 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2162 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2174 * Mesa extension stubs. These will help reduce portability problems.
2179 * Release all buffers associated with the specified GLX drawable.
2182 * This function was intended for stand-alone Mesa. The issue there is that
2183 * the library doesn't get any notification when a window is closed. In
2184 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2185 * supported, there are 3 different functions to destroy a drawable. It
2186 * should be possible to create GLX protocol (or have it determine which
2187 * protocol to use based on the type of the drawable) to have one function
2188 * do the work of 3. For the direct-rendering case, this function could
2189 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2190 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2191 * would need to be used. This really should be done as part of the new DRI
2194 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2195 * __driGarbageCollectDrawables
2196 * glXDestroyGLXPixmap
2197 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2198 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2201 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2210 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2211 Pixmap pixmap
, Colormap cmap
)
2224 * GLX_MESA_copy_sub_buffer
2226 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2228 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2229 int x
, int y
, int width
, int height
)
2231 xGLXVendorPrivateReq
*req
;
2232 struct glx_context
*gc
;
2234 CARD32
*drawable_ptr
;
2235 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2238 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2239 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2240 if (pdraw
!= NULL
) {
2241 struct glx_screen
*psc
= pdraw
->psc
;
2242 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2244 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2251 opcode
= __glXSetupForCommand(dpy
);
2256 ** The calling thread may or may not have a current context. If it
2257 ** does, send the context tag so the server can do a flush.
2259 gc
= __glXGetCurrentContext();
2260 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2261 ((drawable
== gc
->currentDrawable
) ||
2262 (drawable
== gc
->currentReadable
))) {
2263 tag
= gc
->currentContextTag
;
2270 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2271 req
->reqType
= opcode
;
2272 req
->glxCode
= X_GLXVendorPrivate
;
2273 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2274 req
->contextTag
= tag
;
2276 drawable_ptr
= (CARD32
*) (req
+ 1);
2277 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2278 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2279 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2280 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2282 *drawable_ptr
= drawable
;
2294 __glXBindTexImageEXT(Display
* dpy
,
2295 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2297 struct glx_context
*gc
= __glXGetCurrentContext();
2299 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2302 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2306 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2308 struct glx_context
*gc
= __glXGetCurrentContext();
2310 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2313 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2318 #endif /* GLX_USE_APPLEGL */
2321 * \c strdup is actually not a standard ANSI C or POSIX routine.
2322 * Irix will not define it if ANSI mode is in effect.
2327 __glXstrdup(const char *str
)
2330 copy
= (char *) Xmalloc(strlen(str
) + 1);
2338 ** glXGetProcAddress support
2341 struct name_address_pair
2347 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2348 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2350 static const struct name_address_pair GLX_functions
[] = {
2351 /*** GLX_VERSION_1_0 ***/
2352 GLX_FUNCTION(glXChooseVisual
),
2353 GLX_FUNCTION(glXCopyContext
),
2354 GLX_FUNCTION(glXCreateContext
),
2355 GLX_FUNCTION(glXCreateGLXPixmap
),
2356 GLX_FUNCTION(glXDestroyContext
),
2357 GLX_FUNCTION(glXDestroyGLXPixmap
),
2358 GLX_FUNCTION(glXGetConfig
),
2359 GLX_FUNCTION(glXGetCurrentContext
),
2360 GLX_FUNCTION(glXGetCurrentDrawable
),
2361 GLX_FUNCTION(glXIsDirect
),
2362 GLX_FUNCTION(glXMakeCurrent
),
2363 GLX_FUNCTION(glXQueryExtension
),
2364 GLX_FUNCTION(glXQueryVersion
),
2365 GLX_FUNCTION(glXSwapBuffers
),
2366 GLX_FUNCTION(glXUseXFont
),
2367 GLX_FUNCTION(glXWaitGL
),
2368 GLX_FUNCTION(glXWaitX
),
2370 /*** GLX_VERSION_1_1 ***/
2371 GLX_FUNCTION(glXGetClientString
),
2372 GLX_FUNCTION(glXQueryExtensionsString
),
2373 GLX_FUNCTION(glXQueryServerString
),
2375 /*** GLX_VERSION_1_2 ***/
2376 GLX_FUNCTION(glXGetCurrentDisplay
),
2378 /*** GLX_VERSION_1_3 ***/
2379 GLX_FUNCTION(glXChooseFBConfig
),
2380 GLX_FUNCTION(glXCreateNewContext
),
2381 GLX_FUNCTION(glXCreatePbuffer
),
2382 GLX_FUNCTION(glXCreatePixmap
),
2383 GLX_FUNCTION(glXCreateWindow
),
2384 GLX_FUNCTION(glXDestroyPbuffer
),
2385 GLX_FUNCTION(glXDestroyPixmap
),
2386 GLX_FUNCTION(glXDestroyWindow
),
2387 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2388 GLX_FUNCTION(glXGetFBConfigAttrib
),
2389 GLX_FUNCTION(glXGetFBConfigs
),
2390 GLX_FUNCTION(glXGetSelectedEvent
),
2391 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2392 GLX_FUNCTION(glXMakeContextCurrent
),
2393 GLX_FUNCTION(glXQueryContext
),
2394 GLX_FUNCTION(glXQueryDrawable
),
2395 GLX_FUNCTION(glXSelectEvent
),
2397 #ifndef GLX_USE_APPLEGL
2398 /*** GLX_SGI_swap_control ***/
2399 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2401 /*** GLX_SGI_video_sync ***/
2402 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2403 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2405 /*** GLX_SGI_make_current_read ***/
2406 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2407 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2409 /*** GLX_EXT_import_context ***/
2410 GLX_FUNCTION(glXFreeContextEXT
),
2411 GLX_FUNCTION(glXGetContextIDEXT
),
2412 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2413 GLX_FUNCTION(glXImportContextEXT
),
2414 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2417 /*** GLX_SGIX_fbconfig ***/
2418 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2419 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2420 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2421 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2422 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2423 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2425 #ifndef GLX_USE_APPLEGL
2426 /*** GLX_SGIX_pbuffer ***/
2427 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2428 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2429 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2430 GLX_FUNCTION(glXSelectEventSGIX
),
2431 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2433 /*** GLX_SGIX_swap_group ***/
2434 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2436 /*** GLX_SGIX_swap_barrier ***/
2437 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2438 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2440 /*** GLX_MESA_copy_sub_buffer ***/
2441 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2443 /*** GLX_MESA_pixmap_colormap ***/
2444 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2446 /*** GLX_MESA_release_buffers ***/
2447 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2449 /*** GLX_MESA_swap_control ***/
2450 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2451 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2454 /*** GLX_ARB_get_proc_address ***/
2455 GLX_FUNCTION(glXGetProcAddressARB
),
2458 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2460 #ifndef GLX_USE_APPLEGL
2461 /*** GLX_OML_sync_control ***/
2462 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2463 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2464 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2465 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2466 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2468 /*** GLX_EXT_texture_from_pixmap ***/
2469 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2470 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2473 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2474 /*** DRI configuration ***/
2475 GLX_FUNCTION(glXGetScreenDriver
),
2476 GLX_FUNCTION(glXGetDriverConfig
),
2479 {NULL
, NULL
} /* end of list */
2482 #ifndef GLX_USE_APPLEGL
2483 static const GLvoid
*
2484 get_glx_proc_address(const char *funcName
)
2488 /* try static functions */
2489 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2490 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2491 return GLX_functions
[i
].Address
;
2499 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2500 * \c glXGetProcAddress.
2502 * \param procName Name of a GL or GLX function.
2503 * \returns A pointer to the named function
2505 * \sa glXGetProcAddress
2507 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2509 typedef void (*gl_function
) (void);
2513 /* Search the table of GLX and internal functions first. If that
2514 * fails and the supplied name could be a valid core GL name, try
2515 * searching the core GL function table. This check is done to prevent
2516 * DRI based drivers from searching the core GL function table for
2517 * internal API functions.
2519 #ifdef GLX_USE_APPLEGL
2520 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2522 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2523 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2524 && (procName
[2] != 'X')) {
2525 #ifdef GLX_SHARED_GLAPI
2526 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2529 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2536 * Get the address of a named GL function. This is the GLX 1.4 name for
2537 * \c glXGetProcAddressARB.
2539 * \param procName Name of a GL or GLX function.
2540 * \returns A pointer to the named function
2542 * \sa glXGetProcAddressARB
2544 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2545 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2546 __attribute__ ((alias("glXGetProcAddressARB")));
2549 return glXGetProcAddressARB(procName
);
2551 #endif /* __GNUC__ */
2554 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2556 * Get the unadjusted system time (UST). Currently, the UST is measured in
2557 * microseconds since Epoc. The actual resolution of the UST may vary from
2558 * system to system, and the units may vary from release to release.
2559 * Drivers should not call this function directly. They should instead use
2560 * \c glXGetProcAddress to obtain a pointer to the function.
2562 * \param ust Location to store the 64-bit UST
2563 * \returns Zero on success or a negative errno value on failure.
2565 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2567 * \since Internal API version 20030317.
2570 __glXGetUST(int64_t * ust
)
2578 if (gettimeofday(&tv
, NULL
) == 0) {
2579 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2586 #endif /* GLX_DIRECT_RENDERING */