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"
40 #ifdef GLX_DIRECT_RENDERING
41 #ifdef GLX_USE_APPLEGL
42 #include "apple_glx_context.h"
43 #include "apple_glx.h"
44 #include "glx_error.h"
48 #include <X11/extensions/xf86vmode.h>
56 #include <X11/Xlib-xcb.h>
61 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
62 static const char __glXGLXClientVersion
[] = "1.4";
64 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
67 * Get the __DRIdrawable for the drawable associated with a GLXContext
69 * \param dpy The display associated with \c drawable.
70 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
71 * \param scrn_num If non-NULL, the drawables screen is stored there
72 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
73 * the drawable is not associated with a direct-rendering context.
75 _X_HIDDEN __GLXDRIdrawable
*
76 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
78 struct glx_display
*priv
= __glXInitialize(dpy
);
79 __GLXDRIdrawable
*pdraw
;
84 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
94 * Get the GLX per-screen data structure associated with a GLX context.
96 * \param dpy Display for which the GLX per-screen information is to be
98 * \param scrn Screen on \c dpy for which the GLX per-screen information is
100 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
101 * specify a valid GLX screen, or NULL otherwise.
103 * \todo Should this function validate that \c scrn is within the screen
104 * number range for \c dpy?
107 static struct glx_screen
*
108 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
110 struct glx_display
*const priv
= __glXInitialize(dpy
);
114 NULL
) ? priv
->screens
[scrn
] : NULL
;
119 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
120 struct glx_screen
** ppsc
)
122 /* Initialize the extension, if needed . This has the added value
123 * of initializing/allocating the display private
127 return GLX_NO_EXTENSION
;
130 *ppriv
= __glXInitialize(dpy
);
131 if (*ppriv
== NULL
) {
132 return GLX_NO_EXTENSION
;
135 /* Check screen number to see if its valid */
136 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
137 return GLX_BAD_SCREEN
;
140 /* Check to see if the GL is supported on this screen */
141 *ppsc
= (*ppriv
)->screens
[scrn
];
142 if ((*ppsc
)->configs
== NULL
) {
143 /* No support for GL on this screen regardless of visual */
144 return GLX_BAD_VISUAL
;
152 * Determine if a \c GLXFBConfig supplied by the application is valid.
154 * \param dpy Application supplied \c Display pointer.
155 * \param config Application supplied \c GLXFBConfig.
157 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
158 * \c struct glx_config structure is returned. Otherwise, \c NULL
161 static struct glx_config
*
162 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
164 struct glx_display
*const priv
= __glXInitialize(dpy
);
165 int num_screens
= ScreenCount(dpy
);
167 struct glx_config
*config
;
170 for (i
= 0; i
< num_screens
; i
++) {
171 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
172 config
= config
->next
) {
173 if (config
== (struct glx_config
*) fbconfig
) {
184 glx_context_init(struct glx_context
*gc
,
185 struct glx_screen
*psc
, struct glx_config
*config
)
187 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
188 if (!gc
->majorOpcode
)
191 gc
->screen
= psc
->scr
;
194 gc
->isDirect
= GL_TRUE
;
195 gc
->currentContextTag
= -1;
202 * Create a new context. Exactly one of \c vis and \c fbconfig should be
205 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
206 * SGIX_fbconfig protocol be used?
207 * \param renderType For FBConfigs, what is the rendering type?
211 CreateContext(Display
* dpy
, int generic_id
,
212 struct glx_config
*config
,
213 GLXContext shareList_user
,
215 unsigned code
, int renderType
, int screen
)
217 struct glx_context
*gc
= NULL
;
218 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
219 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
223 if (generic_id
== None
)
227 if (allowDirect
&& psc
->vtable
->create_context
)
228 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
230 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
236 case X_GLXCreateContext
: {
237 xGLXCreateContextReq
*req
;
239 /* Send the glXCreateContext request */
240 GetReq(GLXCreateContext
, req
);
241 req
->reqType
= gc
->majorOpcode
;
242 req
->glxCode
= X_GLXCreateContext
;
243 req
->context
= gc
->xid
= XAllocID(dpy
);
244 req
->visual
= generic_id
;
245 req
->screen
= screen
;
246 req
->shareList
= shareList
? shareList
->xid
: None
;
247 req
->isDirect
= gc
->isDirect
;
251 case X_GLXCreateNewContext
: {
252 xGLXCreateNewContextReq
*req
;
254 /* Send the glXCreateNewContext request */
255 GetReq(GLXCreateNewContext
, req
);
256 req
->reqType
= gc
->majorOpcode
;
257 req
->glxCode
= X_GLXCreateNewContext
;
258 req
->context
= gc
->xid
= XAllocID(dpy
);
259 req
->fbconfig
= generic_id
;
260 req
->screen
= screen
;
261 req
->renderType
= renderType
;
262 req
->shareList
= shareList
? shareList
->xid
: None
;
263 req
->isDirect
= gc
->isDirect
;
267 case X_GLXvop_CreateContextWithConfigSGIX
: {
268 xGLXVendorPrivateWithReplyReq
*vpreq
;
269 xGLXCreateContextWithConfigSGIXReq
*req
;
271 /* Send the glXCreateNewContext request */
272 GetReqExtra(GLXVendorPrivateWithReply
,
273 sz_xGLXCreateContextWithConfigSGIXReq
-
274 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
275 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
276 req
->reqType
= gc
->majorOpcode
;
277 req
->glxCode
= X_GLXVendorPrivateWithReply
;
278 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
279 req
->context
= gc
->xid
= XAllocID(dpy
);
280 req
->fbconfig
= generic_id
;
281 req
->screen
= screen
;
282 req
->renderType
= renderType
;
283 req
->shareList
= shareList
? shareList
->xid
: None
;
284 req
->isDirect
= gc
->isDirect
;
289 /* What to do here? This case is the sign of an internal error. It
290 * should never be reachable.
298 gc
->imported
= GL_FALSE
;
299 gc
->renderType
= renderType
;
301 return (GLXContext
) gc
;
305 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
306 GLXContext shareList
, Bool allowDirect
)
308 struct glx_config
*config
= NULL
;
311 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
312 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
314 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
315 if (config
== NULL
) {
318 error
.errorCode
= BadValue
;
319 error
.resourceID
= vis
->visualid
;
320 error
.sequenceNumber
= dpy
->request
;
321 error
.type
= X_Error
;
322 error
.majorCode
= __glXSetupForCommand(dpy
);
323 error
.minorCode
= X_GLXCreateContext
;
324 _XError(dpy
, &error
);
328 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
331 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
332 X_GLXCreateContext
, renderType
, vis
->screen
);
336 glx_send_destroy_context(Display
*dpy
, XID xid
)
338 CARD8 opcode
= __glXSetupForCommand(dpy
);
339 xGLXDestroyContextReq
*req
;
342 GetReq(GLXDestroyContext
, req
);
343 req
->reqType
= opcode
;
344 req
->glxCode
= X_GLXDestroyContext
;
351 ** Destroy the named context
354 DestroyContext(Display
* dpy
, GLXContext ctx
)
356 struct glx_context
*gc
= (struct glx_context
*) ctx
;
362 if (gc
->currentDpy
) {
363 /* This context is bound to some thread. According to the man page,
364 * we should not actually delete the context until it's unbound.
365 * Note that we set gc->xid = None above. In MakeContextCurrent()
366 * we check for that and delete the context there.
369 glx_send_destroy_context(dpy
, gc
->xid
);
376 if (gc
->vtable
->destroy
)
377 gc
->vtable
->destroy(gc
);
381 glXDestroyContext(Display
* dpy
, GLXContext gc
)
383 DestroyContext(dpy
, gc
);
387 ** Return the major and minor version #s for the GLX extension
390 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
392 struct glx_display
*priv
;
394 /* Init the extension. This fetches the major and minor version. */
395 priv
= __glXInitialize(dpy
);
400 *major
= priv
->majorVersion
;
402 *minor
= priv
->minorVersion
;
407 ** Query the existance of the GLX extension
410 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
412 int major_op
, erb
, evb
;
415 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
426 ** Put a barrier in the token stream that forces the GL to finish its
427 ** work before X can proceed.
432 struct glx_context
*gc
= __glXGetCurrentContext();
434 if (gc
&& gc
->vtable
->wait_gl
)
435 gc
->vtable
->wait_gl(gc
);
439 ** Put a barrier in the token stream that forces X to finish its
440 ** work before GL can proceed.
445 struct glx_context
*gc
= __glXGetCurrentContext();
447 if (gc
&& gc
->vtable
->wait_x
)
448 gc
->vtable
->wait_x(gc
);
452 glXUseXFont(Font font
, int first
, int count
, int listBase
)
454 struct glx_context
*gc
= __glXGetCurrentContext();
456 if (gc
&& gc
->vtable
->use_x_font
)
457 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
460 /************************************************************************/
463 ** Copy the source context to the destination context using the
467 glXCopyContext(Display
* dpy
, GLXContext source_user
,
468 GLXContext dest_user
, unsigned long mask
)
470 struct glx_context
*source
= (struct glx_context
*) source_user
;
471 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
472 #ifdef GLX_USE_APPLEGL
473 struct glx_context
*gc
= __glXGetCurrentContext();
477 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
478 mask
, &errorcode
, &x11error
)) {
479 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
483 xGLXCopyContextReq
*req
;
484 struct glx_context
*gc
= __glXGetCurrentContext();
488 opcode
= __glXSetupForCommand(dpy
);
493 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
495 /* NOT_DONE: This does not work yet */
500 ** If the source is the current context, send its tag so that the context
501 ** can be flushed before the copy.
503 if (source
== gc
&& dpy
== gc
->currentDpy
) {
504 tag
= gc
->currentContextTag
;
510 /* Send the glXCopyContext request */
512 GetReq(GLXCopyContext
, req
);
513 req
->reqType
= opcode
;
514 req
->glxCode
= X_GLXCopyContext
;
515 req
->source
= source
? source
->xid
: None
;
516 req
->dest
= dest
? dest
->xid
: None
;
518 req
->contextTag
= tag
;
521 #endif /* GLX_USE_APPLEGL */
526 * Determine if a context uses direct rendering.
528 * \param dpy Display where the context was created.
529 * \param contextID ID of the context to be tested.
531 * \returns \c GL_TRUE if the context is direct rendering or not.
534 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
536 #if !defined(USE_XCB)
537 xGLXIsDirectReq
*req
;
538 xGLXIsDirectReply reply
;
542 opcode
= __glXSetupForCommand(dpy
);
548 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
549 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
554 const Bool is_direct
= reply
->is_direct
? True
: False
;
559 /* Send the glXIsDirect request */
561 GetReq(GLXIsDirect
, req
);
562 req
->reqType
= opcode
;
563 req
->glxCode
= X_GLXIsDirect
;
564 req
->context
= contextID
;
565 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
569 return reply
.isDirect
;
575 * Shouldn't this function \b always return \c GL_FALSE when
576 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
577 * the GLX protocol here at all?
580 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
582 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
587 else if (gc
->isDirect
) {
590 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
593 return __glXIsDirect(dpy
, gc
->xid
);
598 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
600 #ifdef GLX_USE_APPLEGL
601 int screen
= vis
->screen
;
602 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
603 const struct glx_config
*config
;
605 config
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
607 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
612 xGLXCreateGLXPixmapReq
*req
;
616 opcode
= __glXSetupForCommand(dpy
);
621 /* Send the glXCreateGLXPixmap request */
623 GetReq(GLXCreateGLXPixmap
, req
);
624 req
->reqType
= opcode
;
625 req
->glxCode
= X_GLXCreateGLXPixmap
;
626 req
->screen
= vis
->screen
;
627 req
->visual
= vis
->visualid
;
628 req
->pixmap
= pixmap
;
629 req
->glxpixmap
= xid
= XAllocID(dpy
);
633 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
635 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
636 * is actually bound to a context... */
638 struct glx_display
*const priv
= __glXInitialize(dpy
);
639 __GLXDRIdrawable
*pdraw
;
640 struct glx_screen
*psc
;
641 struct glx_config
*config
;
643 psc
= priv
->screens
[vis
->screen
];
644 if (psc
->driScreen
== NULL
)
646 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
647 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, config
);
649 fprintf(stderr
, "failed to create pixmap\n");
653 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
654 (*pdraw
->destroyDrawable
) (pdraw
);
655 return None
; /* FIXME: Check what we're supposed to do here... */
665 ** Destroy the named pixmap
668 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
670 #ifdef GLX_USE_APPLEGL
671 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
672 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
674 xGLXDestroyGLXPixmapReq
*req
;
677 opcode
= __glXSetupForCommand(dpy
);
682 /* Send the glXDestroyGLXPixmap request */
684 GetReq(GLXDestroyGLXPixmap
, req
);
685 req
->reqType
= opcode
;
686 req
->glxCode
= X_GLXDestroyGLXPixmap
;
687 req
->glxpixmap
= glxpixmap
;
691 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
693 struct glx_display
*const priv
= __glXInitialize(dpy
);
694 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
697 (*pdraw
->destroyDrawable
) (pdraw
);
698 __glxHashDelete(priv
->drawHash
, glxpixmap
);
702 #endif /* GLX_USE_APPLEGL */
706 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
708 #ifdef GLX_USE_APPLEGL
709 GLXContext gc
= glXGetCurrentContext();
710 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
711 apple_glx_swap_buffers(gc
->driContext
);
713 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
716 struct glx_context
*gc
;
722 xGLXSwapBuffersReq
*req
;
725 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
726 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
730 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
735 opcode
= __glXSetupForCommand(dpy
);
741 ** The calling thread may or may not have a current context. If it
742 ** does, send the context tag so the server can do a flush.
744 gc
= __glXGetCurrentContext();
745 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
746 ((drawable
== gc
->currentDrawable
)
747 || (drawable
== gc
->currentReadable
))) {
748 tag
= gc
->currentContextTag
;
755 c
= XGetXCBConnection(dpy
);
756 xcb_glx_swap_buffers(c
, tag
, drawable
);
759 /* Send the glXSwapBuffers request */
761 GetReq(GLXSwapBuffers
, req
);
762 req
->reqType
= opcode
;
763 req
->glxCode
= X_GLXSwapBuffers
;
764 req
->drawable
= drawable
;
765 req
->contextTag
= tag
;
770 #endif /* GLX_USE_APPLEGL */
775 ** Return configuration information for the given display, screen and
776 ** visual combination.
779 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
782 struct glx_display
*priv
;
783 struct glx_screen
*psc
;
784 struct glx_config
*config
;
787 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
788 if (status
== Success
) {
789 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
791 /* Lookup attribute after first finding a match on the visual */
792 if (config
!= NULL
) {
793 return glx_config_get(config
, attribute
, value_return
);
796 status
= GLX_BAD_VISUAL
;
800 ** If we can't find the config for this visual, this visual is not
801 ** supported by the OpenGL implementation on the server.
803 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
804 *value_return
= GL_FALSE
;
811 /************************************************************************/
814 init_fbconfig_for_chooser(struct glx_config
* config
,
815 GLboolean fbconfig_style_tags
)
817 memset(config
, 0, sizeof(struct glx_config
));
818 config
->visualID
= (XID
) GLX_DONT_CARE
;
819 config
->visualType
= GLX_DONT_CARE
;
821 /* glXChooseFBConfig specifies different defaults for these two than
824 if (fbconfig_style_tags
) {
825 config
->rgbMode
= GL_TRUE
;
826 config
->doubleBufferMode
= GLX_DONT_CARE
;
829 config
->visualRating
= GLX_DONT_CARE
;
830 config
->transparentPixel
= GLX_NONE
;
831 config
->transparentRed
= GLX_DONT_CARE
;
832 config
->transparentGreen
= GLX_DONT_CARE
;
833 config
->transparentBlue
= GLX_DONT_CARE
;
834 config
->transparentAlpha
= GLX_DONT_CARE
;
835 config
->transparentIndex
= GLX_DONT_CARE
;
837 config
->drawableType
= GLX_WINDOW_BIT
;
839 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
840 config
->xRenderable
= GLX_DONT_CARE
;
841 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
843 config
->swapMethod
= GLX_DONT_CARE
;
846 #define MATCH_DONT_CARE( param ) \
848 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
849 && (a-> param != b-> param) ) { \
854 #define MATCH_MINIMUM( param ) \
856 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
857 && (a-> param > b-> param) ) { \
862 #define MATCH_EXACT( param ) \
864 if ( a-> param != b-> param) { \
869 /* Test that all bits from a are contained in b */
870 #define MATCH_MASK(param) \
872 if ((a->param & ~b->param) != 0) \
877 * Determine if two GLXFBConfigs are compatible.
879 * \param a Application specified config to test.
880 * \param b Server specified config to test against \c a.
883 fbconfigs_compatible(const struct glx_config
* const a
,
884 const struct glx_config
* const b
)
886 MATCH_DONT_CARE(doubleBufferMode
);
887 MATCH_DONT_CARE(visualType
);
888 MATCH_DONT_CARE(visualRating
);
889 MATCH_DONT_CARE(xRenderable
);
890 MATCH_DONT_CARE(fbconfigID
);
891 MATCH_DONT_CARE(swapMethod
);
893 MATCH_MINIMUM(rgbBits
);
894 MATCH_MINIMUM(numAuxBuffers
);
895 MATCH_MINIMUM(redBits
);
896 MATCH_MINIMUM(greenBits
);
897 MATCH_MINIMUM(blueBits
);
898 MATCH_MINIMUM(alphaBits
);
899 MATCH_MINIMUM(depthBits
);
900 MATCH_MINIMUM(stencilBits
);
901 MATCH_MINIMUM(accumRedBits
);
902 MATCH_MINIMUM(accumGreenBits
);
903 MATCH_MINIMUM(accumBlueBits
);
904 MATCH_MINIMUM(accumAlphaBits
);
905 MATCH_MINIMUM(sampleBuffers
);
906 MATCH_MINIMUM(maxPbufferWidth
);
907 MATCH_MINIMUM(maxPbufferHeight
);
908 MATCH_MINIMUM(maxPbufferPixels
);
909 MATCH_MINIMUM(samples
);
911 MATCH_DONT_CARE(stereoMode
);
914 MATCH_MASK(drawableType
);
915 MATCH_MASK(renderType
);
917 /* There is a bug in a few of the XFree86 DDX drivers. They contain
918 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
919 * Technically speaking, it is a bug in the DDX driver, but there is
920 * enough of an installed base to work around the problem here. In any
921 * case, 0 is not a valid value of the transparent type, so we'll treat 0
922 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
923 * 0 from the server to be a match to maintain backward compatibility with
924 * the (broken) drivers.
927 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
928 if (a
->transparentPixel
== GLX_NONE
) {
929 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
933 MATCH_EXACT(transparentPixel
);
936 switch (a
->transparentPixel
) {
937 case GLX_TRANSPARENT_RGB
:
938 MATCH_DONT_CARE(transparentRed
);
939 MATCH_DONT_CARE(transparentGreen
);
940 MATCH_DONT_CARE(transparentBlue
);
941 MATCH_DONT_CARE(transparentAlpha
);
944 case GLX_TRANSPARENT_INDEX
:
945 MATCH_DONT_CARE(transparentIndex
);
957 /* There's some trickly language in the GLX spec about how this is supposed
958 * to work. Basically, if a given component size is either not specified
959 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
960 * Well, that's really hard to do with the code as-is. This behavior is
961 * closer to correct, but still not technically right.
963 #define PREFER_LARGER_OR_ZERO(comp) \
965 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
966 if ( ((*a)-> comp) == 0 ) { \
969 else if ( ((*b)-> comp) == 0 ) { \
973 return ((*b)-> comp) - ((*a)-> comp) ; \
978 #define PREFER_LARGER(comp) \
980 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
981 return ((*b)-> comp) - ((*a)-> comp) ; \
985 #define PREFER_SMALLER(comp) \
987 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
988 return ((*a)-> comp) - ((*b)-> comp) ; \
993 * Compare two GLXFBConfigs. This function is intended to be used as the
994 * compare function passed in to qsort.
996 * \returns If \c a is a "better" config, according to the specification of
997 * SGIX_fbconfig, a number less than zero is returned. If \c b is
998 * better, then a number greater than zero is return. If both are
999 * equal, zero is returned.
1000 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1003 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1005 /* The order of these comparisons must NOT change. It is defined by
1006 * the GLX 1.3 spec and ARB_multisample.
1009 PREFER_SMALLER(visualSelectGroup
);
1011 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1012 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1013 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1015 PREFER_SMALLER(visualRating
);
1017 /* This isn't quite right. It is supposed to compare the sum of the
1018 * components the user specifically set minimums for.
1020 PREFER_LARGER_OR_ZERO(redBits
);
1021 PREFER_LARGER_OR_ZERO(greenBits
);
1022 PREFER_LARGER_OR_ZERO(blueBits
);
1023 PREFER_LARGER_OR_ZERO(alphaBits
);
1025 PREFER_SMALLER(rgbBits
);
1027 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1028 /* Prefer single-buffer.
1030 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1033 PREFER_SMALLER(numAuxBuffers
);
1035 PREFER_LARGER_OR_ZERO(depthBits
);
1036 PREFER_SMALLER(stencilBits
);
1038 /* This isn't quite right. It is supposed to compare the sum of the
1039 * components the user specifically set minimums for.
1041 PREFER_LARGER_OR_ZERO(accumRedBits
);
1042 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1043 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1044 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1046 PREFER_SMALLER(visualType
);
1048 /* None of the multisample specs say where this comparison should happen,
1049 * so I put it near the end.
1051 PREFER_SMALLER(sampleBuffers
);
1052 PREFER_SMALLER(samples
);
1054 /* None of the pbuffer or fbconfig specs say that this comparison needs
1055 * to happen at all, but it seems like it should.
1057 PREFER_LARGER(maxPbufferWidth
);
1058 PREFER_LARGER(maxPbufferHeight
);
1059 PREFER_LARGER(maxPbufferPixels
);
1066 * Selects and sorts a subset of the supplied configs based on the attributes.
1067 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1068 * and \c glXChooseFBConfigSGIX.
1070 * \param configs Array of pointers to possible configs. The elements of
1071 * this array that do not meet the criteria will be set to
1072 * NULL. The remaining elements will be sorted according to
1073 * the various visual / FBConfig selection rules.
1074 * \param num_configs Number of elements in the \c configs array.
1075 * \param attribList Attributes used select from \c configs. This array is
1076 * terminated by a \c None tag. The array can either take
1077 * the form expected by \c glXChooseVisual (where boolean
1078 * tags do not have a value) or by \c glXChooseFBConfig
1079 * (where every tag has a value).
1080 * \param fbconfig_style_tags Selects whether \c attribList is in
1081 * \c glXChooseVisual style or
1082 * \c glXChooseFBConfig style.
1083 * \returns The number of valid elements left in \c configs.
1085 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1088 choose_visual(struct glx_config
** configs
, int num_configs
,
1089 const int *attribList
, GLboolean fbconfig_style_tags
)
1091 struct glx_config test_config
;
1095 /* This is a fairly direct implementation of the selection method
1096 * described by GLX_SGIX_fbconfig. Start by culling out all the
1097 * configs that are not compatible with the selected parameter
1101 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1102 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1103 (const INT32
*) attribList
,
1104 GL_TRUE
, fbconfig_style_tags
);
1107 for (i
= 0; i
< num_configs
; i
++) {
1108 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1109 configs
[base
] = configs
[i
];
1118 if (base
< num_configs
) {
1119 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1122 /* After the incompatible configs are removed, the resulting
1123 * list is sorted according to the rules set out in the various
1127 qsort(configs
, base
, sizeof(struct glx_config
*),
1128 (int (*)(const void *, const void *)) fbconfig_compare
);
1136 ** Return the visual that best matches the template. Return None if no
1137 ** visual matches the template.
1139 _X_EXPORT XVisualInfo
*
1140 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1142 XVisualInfo
*visualList
= NULL
;
1143 struct glx_display
*priv
;
1144 struct glx_screen
*psc
;
1145 struct glx_config test_config
;
1146 struct glx_config
*config
;
1147 struct glx_config
*best_config
= NULL
;
1150 ** Get a list of all visuals, return if list is empty
1152 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1158 ** Build a template from the defaults and the attribute list
1159 ** Free visual list and return if an unexpected token is encountered
1161 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1162 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1163 (const INT32
*) attribList
,
1167 ** Eliminate visuals that don't meet minimum requirements
1168 ** Compute a score for those that do
1169 ** Remember which visual, if any, got the highest score
1170 ** If no visual is acceptable, return None
1171 ** Otherwise, create an XVisualInfo list with just the selected X visual
1174 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1175 if (fbconfigs_compatible(&test_config
, config
)
1176 && ((best_config
== NULL
) ||
1177 (fbconfig_compare (&config
, &best_config
) < 0))) {
1178 XVisualInfo visualTemplate
;
1179 XVisualInfo
*newList
;
1182 visualTemplate
.screen
= screen
;
1183 visualTemplate
.visualid
= config
->visualID
;
1184 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1185 &visualTemplate
, &i
);
1189 visualList
= newList
;
1190 best_config
= config
;
1195 #ifdef GLX_USE_APPLEGL
1196 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1197 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1205 _X_EXPORT
const char *
1206 glXQueryExtensionsString(Display
* dpy
, int screen
)
1208 struct glx_screen
*psc
;
1209 struct glx_display
*priv
;
1211 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1215 if (!psc
->effectiveGLXexts
) {
1216 if (!psc
->serverGLXexts
) {
1217 psc
->serverGLXexts
=
1218 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1222 __glXCalculateUsableExtensions(psc
,
1223 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1224 (psc
->driScreen
!= NULL
),
1228 priv
->minorVersion
);
1231 return psc
->effectiveGLXexts
;
1234 _X_EXPORT
const char *
1235 glXGetClientString(Display
* dpy
, int name
)
1241 return (__glXGLXClientVendorName
);
1243 return (__glXGLXClientVersion
);
1244 case GLX_EXTENSIONS
:
1245 return (__glXGetClientExtensions());
1251 _X_EXPORT
const char *
1252 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1254 struct glx_screen
*psc
;
1255 struct glx_display
*priv
;
1259 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1265 str
= &priv
->serverGLXvendor
;
1268 str
= &priv
->serverGLXversion
;
1270 case GLX_EXTENSIONS
:
1271 str
= &psc
->serverGLXexts
;
1278 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1285 __glXClientInfo(Display
* dpy
, int opcode
)
1287 char *ext_str
= __glXGetClientGLExtensionString();
1288 int size
= strlen(ext_str
) + 1;
1291 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1292 xcb_glx_client_info(c
,
1293 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1295 xGLXClientInfoReq
*req
;
1297 /* Send the glXClientInfo request */
1299 GetReq(GLXClientInfo
, req
);
1300 req
->reqType
= opcode
;
1301 req
->glxCode
= X_GLXClientInfo
;
1302 req
->major
= GLX_MAJOR_VERSION
;
1303 req
->minor
= GLX_MINOR_VERSION
;
1305 req
->length
+= (size
+ 3) >> 2;
1306 req
->numbytes
= size
;
1307 Data(dpy
, ext_str
, size
);
1311 #endif /* USE_XCB */
1318 ** EXT_import_context
1322 glXGetCurrentDisplay(void)
1324 struct glx_context
*gc
= __glXGetCurrentContext();
1327 return gc
->currentDpy
;
1331 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1332 glXGetCurrentDisplay
)
1334 #ifndef GLX_USE_APPLEGL
1335 _X_EXPORT GLXContext
1336 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1338 struct glx_display
*priv
= __glXInitialize(dpy
);
1339 struct glx_screen
*psc
;
1340 xGLXQueryContextReply reply
;
1342 struct glx_context
*ctx
;
1343 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1346 struct glx_config
*mode
;
1348 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1351 opcode
= __glXSetupForCommand(dpy
);
1355 /* Send the glXQueryContextInfoEXT request */
1358 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1359 xGLXQueryContextReq
*req
;
1361 GetReq(GLXQueryContext
, req
);
1363 req
->reqType
= opcode
;
1364 req
->glxCode
= X_GLXQueryContext
;
1365 req
->context
= contextID
;
1368 xGLXVendorPrivateReq
*vpreq
;
1369 xGLXQueryContextInfoEXTReq
*req
;
1371 GetReqExtra(GLXVendorPrivate
,
1372 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1374 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1375 req
->reqType
= opcode
;
1376 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1377 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1378 req
->context
= contextID
;
1381 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1383 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1384 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1387 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1391 /* Look up screen first so we can look up visuals/fbconfigs later */
1393 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1394 if (pProp
[0] == GLX_SCREEN
)
1395 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1404 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1406 case GLX_SHARE_CONTEXT_EXT
:
1409 case GLX_VISUAL_ID_EXT
:
1410 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1412 case GLX_FBCONFIG_ID
:
1413 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1415 case GLX_RENDER_TYPE
:
1416 renderType
= pProp
[1];
1423 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1427 ctx
->xid
= contextID
;
1428 ctx
->imported
= GL_TRUE
;
1429 ctx
->share_xid
= share
;
1431 return (GLXContext
) ctx
;
1437 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1439 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1441 switch (attribute
) {
1442 case GLX_SHARE_CONTEXT_EXT
:
1443 *value
= ctx
->share_xid
;
1445 case GLX_VISUAL_ID_EXT
:
1446 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1449 *value
= ctx
->screen
;
1451 case GLX_FBCONFIG_ID
:
1452 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1454 case GLX_RENDER_TYPE
:
1455 *value
= ctx
->renderType
;
1458 return GLX_BAD_ATTRIBUTE
;
1464 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1465 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1466 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1468 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1470 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1476 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1478 DestroyContext(dpy
, ctx
);
1482 _X_EXPORT GLXFBConfig
*
1483 glXChooseFBConfig(Display
* dpy
, int screen
,
1484 const int *attribList
, int *nitems
)
1486 struct glx_config
**config_list
;
1490 config_list
= (struct glx_config
**)
1491 glXGetFBConfigs(dpy
, screen
, &list_size
);
1493 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1494 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1495 if (list_size
== 0) {
1501 *nitems
= list_size
;
1502 return (GLXFBConfig
*) config_list
;
1506 _X_EXPORT GLXContext
1507 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1508 int renderType
, GLXContext shareList
, Bool allowDirect
)
1510 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1512 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1513 allowDirect
, X_GLXCreateNewContext
, renderType
,
1518 _X_EXPORT GLXDrawable
1519 glXGetCurrentReadDrawable(void)
1521 struct glx_context
*gc
= __glXGetCurrentContext();
1523 return gc
->currentReadable
;
1527 _X_EXPORT GLXFBConfig
*
1528 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1530 struct glx_display
*priv
= __glXInitialize(dpy
);
1531 struct glx_config
**config_list
= NULL
;
1532 struct glx_config
*config
;
1533 unsigned num_configs
= 0;
1537 if (priv
&& (priv
->screens
!= NULL
)
1538 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1539 && (priv
->screens
[screen
]->configs
!= NULL
)
1540 && (priv
->screens
[screen
]->configs
->fbconfigID
1541 != (int) GLX_DONT_CARE
)) {
1543 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1544 config
= config
->next
) {
1545 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1550 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1551 if (config_list
!= NULL
) {
1552 *nelements
= num_configs
;
1554 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1555 config
= config
->next
) {
1556 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1557 config_list
[i
] = config
;
1564 return (GLXFBConfig
*) config_list
;
1569 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1570 int attribute
, int *value
)
1572 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1575 return GLXBadFBConfig
;
1577 return glx_config_get(config
, attribute
, value
);
1581 _X_EXPORT XVisualInfo
*
1582 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1584 XVisualInfo visualTemplate
;
1585 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1589 ** Get a list of all visuals, return if list is empty
1591 visualTemplate
.visualid
= config
->visualID
;
1592 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1595 #ifndef GLX_USE_APPLEGL
1597 ** GLX_SGI_swap_control
1600 __glXSwapIntervalSGI(int interval
)
1602 xGLXVendorPrivateReq
*req
;
1603 struct glx_context
*gc
= __glXGetCurrentContext();
1604 struct glx_screen
*psc
;
1606 CARD32
*interval_ptr
;
1610 return GLX_BAD_CONTEXT
;
1613 if (interval
<= 0) {
1614 return GLX_BAD_VALUE
;
1617 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1619 #ifdef GLX_DIRECT_RENDERING
1620 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1621 __GLXDRIdrawable
*pdraw
=
1622 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1623 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1628 dpy
= gc
->currentDpy
;
1629 opcode
= __glXSetupForCommand(dpy
);
1634 /* Send the glXSwapIntervalSGI request */
1636 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1637 req
->reqType
= opcode
;
1638 req
->glxCode
= X_GLXVendorPrivate
;
1639 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1640 req
->contextTag
= gc
->currentContextTag
;
1642 interval_ptr
= (CARD32
*) (req
+ 1);
1643 *interval_ptr
= interval
;
1654 ** GLX_MESA_swap_control
1657 __glXSwapIntervalMESA(unsigned int interval
)
1659 #ifdef GLX_DIRECT_RENDERING
1660 struct glx_context
*gc
= __glXGetCurrentContext();
1662 if (gc
!= NULL
&& gc
->isDirect
) {
1663 struct glx_screen
*psc
;
1665 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1666 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1667 __GLXDRIdrawable
*pdraw
=
1668 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1669 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1674 return GLX_BAD_CONTEXT
;
1679 __glXGetSwapIntervalMESA(void)
1681 #ifdef GLX_DIRECT_RENDERING
1682 struct glx_context
*gc
= __glXGetCurrentContext();
1684 if (gc
!= NULL
&& gc
->isDirect
) {
1685 struct glx_screen
*psc
;
1687 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1688 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1689 __GLXDRIdrawable
*pdraw
=
1690 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1691 return psc
->driScreen
->getSwapInterval(pdraw
);
1701 ** GLX_SGI_video_sync
1704 __glXGetVideoSyncSGI(unsigned int *count
)
1706 int64_t ust
, msc
, sbc
;
1708 struct glx_context
*gc
= __glXGetCurrentContext();
1709 struct glx_screen
*psc
;
1710 #ifdef GLX_DIRECT_RENDERING
1711 __GLXDRIdrawable
*pdraw
;
1715 return GLX_BAD_CONTEXT
;
1717 #ifdef GLX_DIRECT_RENDERING
1719 return GLX_BAD_CONTEXT
;
1722 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1723 #ifdef GLX_DIRECT_RENDERING
1724 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1727 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1728 * FIXME: there should be a GLX encoding for this call. I can find no
1729 * FIXME: documentation for the GLX encoding.
1731 #ifdef GLX_DIRECT_RENDERING
1732 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1733 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1734 *count
= (unsigned) msc
;
1735 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1739 return GLX_BAD_CONTEXT
;
1743 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1745 struct glx_context
*gc
= __glXGetCurrentContext();
1746 struct glx_screen
*psc
;
1747 #ifdef GLX_DIRECT_RENDERING
1748 __GLXDRIdrawable
*pdraw
;
1750 int64_t ust
, msc
, sbc
;
1753 if (divisor
<= 0 || remainder
< 0)
1754 return GLX_BAD_VALUE
;
1757 return GLX_BAD_CONTEXT
;
1759 #ifdef GLX_DIRECT_RENDERING
1761 return GLX_BAD_CONTEXT
;
1764 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1765 #ifdef GLX_DIRECT_RENDERING
1766 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1769 #ifdef GLX_DIRECT_RENDERING
1770 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1771 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1773 *count
= (unsigned) msc
;
1774 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1778 return GLX_BAD_CONTEXT
;
1781 #endif /* GLX_USE_APPLEGL */
1784 ** GLX_SGIX_fbconfig
1785 ** Many of these functions are aliased to GLX 1.3 entry points in the
1786 ** GLX_functions table.
1790 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1791 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1792 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1794 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1795 (Display
* dpy
, int screen
, int *attrib_list
,
1796 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1799 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1800 (Display
* dpy
, GLXFBConfigSGIX config
),
1801 (dpy
, config
), glXGetVisualFromFBConfig
)
1804 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1805 GLXFBConfigSGIX fbconfig
,
1808 #ifndef GLX_USE_APPLEGL
1809 xGLXVendorPrivateWithReplyReq
*vpreq
;
1810 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1811 GLXPixmap xid
= None
;
1813 struct glx_screen
*psc
;
1815 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1818 if ((dpy
== NULL
) || (config
== NULL
)) {
1821 #ifdef GLX_USE_APPLEGL
1822 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1827 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1829 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1830 opcode
= __glXSetupForCommand(dpy
);
1835 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1837 GetReqExtra(GLXVendorPrivateWithReply
,
1838 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1839 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1840 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1841 req
->reqType
= opcode
;
1842 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1843 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1844 req
->screen
= config
->screen
;
1845 req
->fbconfig
= config
->fbconfigID
;
1846 req
->pixmap
= pixmap
;
1847 req
->glxpixmap
= xid
= XAllocID(dpy
);
1856 _X_EXPORT GLXContext
1857 glXCreateContextWithConfigSGIX(Display
* dpy
,
1858 GLXFBConfigSGIX fbconfig
, int renderType
,
1859 GLXContext shareList
, Bool allowDirect
)
1861 GLXContext gc
= NULL
;
1862 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1863 struct glx_screen
*psc
;
1866 if ((dpy
== NULL
) || (config
== NULL
)) {
1870 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1872 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1873 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1875 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1883 _X_EXPORT GLXFBConfigSGIX
1884 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1886 struct glx_display
*priv
;
1887 struct glx_screen
*psc
= NULL
;
1889 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
1890 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1891 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1892 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1899 #ifndef GLX_USE_APPLEGL
1901 ** GLX_SGIX_swap_group
1904 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1914 ** GLX_SGIX_swap_barrier
1917 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1925 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
1935 ** GLX_OML_sync_control
1938 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
1939 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
1941 struct glx_display
* const priv
= __glXInitialize(dpy
);
1943 #ifdef GLX_DIRECT_RENDERING
1944 __GLXDRIdrawable
*pdraw
;
1946 struct glx_screen
*psc
;
1951 #ifdef GLX_DIRECT_RENDERING
1952 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1953 psc
= pdraw
? pdraw
->psc
: NULL
;
1954 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
1955 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
1963 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1965 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
1966 int32_t * numerator
, int32_t * denominator
)
1969 struct glx_screen
*psc
;
1970 XF86VidModeModeLine mode_line
;
1975 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
1976 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
1977 unsigned n
= dot_clock
* 1000;
1978 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
1980 # define V_INTERLACE 0x010
1981 # define V_DBLSCAN 0x020
1983 if (mode_line
.flags
& V_INTERLACE
)
1985 else if (mode_line
.flags
& V_DBLSCAN
)
1988 /* The OML_sync_control spec requires that if the refresh rate is a
1989 * whole number, that the returned numerator be equal to the refresh
1990 * rate and the denominator be 1.
1998 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2000 /* This is a poor man's way to reduce a fraction. It's far from
2001 * perfect, but it will work well enough for this situation.
2004 for (i
= 0; f
[i
] != 0; i
++) {
2005 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2025 * Determine the refresh rate of the specified drawable and display.
2027 * \param dpy Display whose refresh rate is to be determined.
2028 * \param drawable Drawable whose refresh rate is to be determined.
2029 * \param numerator Numerator of the refresh rate.
2030 * \param demoninator Denominator of the refresh rate.
2031 * \return If the refresh rate for the specified display and drawable could
2032 * be calculated, True is returned. Otherwise False is returned.
2034 * \note This function is implemented entirely client-side. A lot of other
2035 * functionality is required to export GLX_OML_sync_control, so on
2036 * XFree86 this function can be called for direct-rendering contexts
2037 * when GLX_OML_sync_control appears in the client extension string.
2041 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2042 int32_t * numerator
, int32_t * denominator
)
2044 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2045 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2050 return __glxGetMscRate(draw
, numerator
, denominator
);
2062 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2063 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2065 struct glx_context
*gc
= __glXGetCurrentContext();
2066 #ifdef GLX_DIRECT_RENDERING
2067 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2068 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2071 if (!gc
) /* no GLX for this */
2074 #ifdef GLX_DIRECT_RENDERING
2075 if (!pdraw
|| !gc
->isDirect
)
2079 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2080 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2081 * of -1 if the function failed because of errors detected in the input
2084 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2086 if (divisor
> 0 && remainder
>= divisor
)
2089 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2092 #ifdef GLX_DIRECT_RENDERING
2093 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2094 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2103 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2104 int64_t target_msc
, int64_t divisor
,
2105 int64_t remainder
, int64_t * ust
,
2106 int64_t * msc
, int64_t * sbc
)
2108 #ifdef GLX_DIRECT_RENDERING
2109 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2110 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2115 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2116 * error", but the return type in the spec is Bool.
2118 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2120 if (divisor
> 0 && remainder
>= divisor
)
2123 #ifdef GLX_DIRECT_RENDERING
2124 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2125 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2136 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2137 int64_t target_sbc
, int64_t * ust
,
2138 int64_t * msc
, int64_t * sbc
)
2140 #ifdef GLX_DIRECT_RENDERING
2141 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2142 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2146 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2147 * error", but the return type in the spec is Bool.
2152 #ifdef GLX_DIRECT_RENDERING
2153 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2154 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2166 * Mesa extension stubs. These will help reduce portability problems.
2171 * Release all buffers associated with the specified GLX drawable.
2174 * This function was intended for stand-alone Mesa. The issue there is that
2175 * the library doesn't get any notification when a window is closed. In
2176 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2177 * supported, there are 3 different functions to destroy a drawable. It
2178 * should be possible to create GLX protocol (or have it determine which
2179 * protocol to use based on the type of the drawable) to have one function
2180 * do the work of 3. For the direct-rendering case, this function could
2181 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2182 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2183 * would need to be used. This really should be done as part of the new DRI
2186 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2187 * __driGarbageCollectDrawables
2188 * glXDestroyGLXPixmap
2189 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2190 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2193 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2202 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2203 Pixmap pixmap
, Colormap cmap
)
2216 * GLX_MESA_copy_sub_buffer
2218 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2220 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2221 int x
, int y
, int width
, int height
)
2223 xGLXVendorPrivateReq
*req
;
2224 struct glx_context
*gc
;
2226 CARD32
*drawable_ptr
;
2227 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2230 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2231 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2232 if (pdraw
!= NULL
) {
2233 struct glx_screen
*psc
= pdraw
->psc
;
2234 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2236 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2243 opcode
= __glXSetupForCommand(dpy
);
2248 ** The calling thread may or may not have a current context. If it
2249 ** does, send the context tag so the server can do a flush.
2251 gc
= __glXGetCurrentContext();
2252 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2253 ((drawable
== gc
->currentDrawable
) ||
2254 (drawable
== gc
->currentReadable
))) {
2255 tag
= gc
->currentContextTag
;
2262 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2263 req
->reqType
= opcode
;
2264 req
->glxCode
= X_GLXVendorPrivate
;
2265 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2266 req
->contextTag
= tag
;
2268 drawable_ptr
= (CARD32
*) (req
+ 1);
2269 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2270 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2271 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2272 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2274 *drawable_ptr
= drawable
;
2286 __glXBindTexImageEXT(Display
* dpy
,
2287 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2289 struct glx_context
*gc
= __glXGetCurrentContext();
2291 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2294 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2298 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2300 struct glx_context
*gc
= __glXGetCurrentContext();
2302 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2305 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2310 #endif /* GLX_USE_APPLEGL */
2313 * \c strdup is actually not a standard ANSI C or POSIX routine.
2314 * Irix will not define it if ANSI mode is in effect.
2319 __glXstrdup(const char *str
)
2322 copy
= (char *) Xmalloc(strlen(str
) + 1);
2330 ** glXGetProcAddress support
2333 struct name_address_pair
2339 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2340 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2342 static const struct name_address_pair GLX_functions
[] = {
2343 /*** GLX_VERSION_1_0 ***/
2344 GLX_FUNCTION(glXChooseVisual
),
2345 GLX_FUNCTION(glXCopyContext
),
2346 GLX_FUNCTION(glXCreateContext
),
2347 GLX_FUNCTION(glXCreateGLXPixmap
),
2348 GLX_FUNCTION(glXDestroyContext
),
2349 GLX_FUNCTION(glXDestroyGLXPixmap
),
2350 GLX_FUNCTION(glXGetConfig
),
2351 GLX_FUNCTION(glXGetCurrentContext
),
2352 GLX_FUNCTION(glXGetCurrentDrawable
),
2353 GLX_FUNCTION(glXIsDirect
),
2354 GLX_FUNCTION(glXMakeCurrent
),
2355 GLX_FUNCTION(glXQueryExtension
),
2356 GLX_FUNCTION(glXQueryVersion
),
2357 GLX_FUNCTION(glXSwapBuffers
),
2358 GLX_FUNCTION(glXUseXFont
),
2359 GLX_FUNCTION(glXWaitGL
),
2360 GLX_FUNCTION(glXWaitX
),
2362 /*** GLX_VERSION_1_1 ***/
2363 GLX_FUNCTION(glXGetClientString
),
2364 GLX_FUNCTION(glXQueryExtensionsString
),
2365 GLX_FUNCTION(glXQueryServerString
),
2367 /*** GLX_VERSION_1_2 ***/
2368 GLX_FUNCTION(glXGetCurrentDisplay
),
2370 /*** GLX_VERSION_1_3 ***/
2371 GLX_FUNCTION(glXChooseFBConfig
),
2372 GLX_FUNCTION(glXCreateNewContext
),
2373 GLX_FUNCTION(glXCreatePbuffer
),
2374 GLX_FUNCTION(glXCreatePixmap
),
2375 GLX_FUNCTION(glXCreateWindow
),
2376 GLX_FUNCTION(glXDestroyPbuffer
),
2377 GLX_FUNCTION(glXDestroyPixmap
),
2378 GLX_FUNCTION(glXDestroyWindow
),
2379 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2380 GLX_FUNCTION(glXGetFBConfigAttrib
),
2381 GLX_FUNCTION(glXGetFBConfigs
),
2382 GLX_FUNCTION(glXGetSelectedEvent
),
2383 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2384 GLX_FUNCTION(glXMakeContextCurrent
),
2385 GLX_FUNCTION(glXQueryContext
),
2386 GLX_FUNCTION(glXQueryDrawable
),
2387 GLX_FUNCTION(glXSelectEvent
),
2389 #ifndef GLX_USE_APPLEGL
2390 /*** GLX_SGI_swap_control ***/
2391 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2393 /*** GLX_SGI_video_sync ***/
2394 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2395 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2397 /*** GLX_SGI_make_current_read ***/
2398 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2399 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2401 /*** GLX_EXT_import_context ***/
2402 GLX_FUNCTION(glXFreeContextEXT
),
2403 GLX_FUNCTION(glXGetContextIDEXT
),
2404 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2405 GLX_FUNCTION(glXImportContextEXT
),
2406 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2409 /*** GLX_SGIX_fbconfig ***/
2410 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2411 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2412 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2413 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2414 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2415 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2417 #ifndef GLX_USE_APPLEGL
2418 /*** GLX_SGIX_pbuffer ***/
2419 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2420 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2421 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2422 GLX_FUNCTION(glXSelectEventSGIX
),
2423 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2425 /*** GLX_SGIX_swap_group ***/
2426 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2428 /*** GLX_SGIX_swap_barrier ***/
2429 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2430 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2432 /*** GLX_MESA_copy_sub_buffer ***/
2433 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2435 /*** GLX_MESA_pixmap_colormap ***/
2436 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2438 /*** GLX_MESA_release_buffers ***/
2439 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2441 /*** GLX_MESA_swap_control ***/
2442 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2443 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2446 /*** GLX_ARB_get_proc_address ***/
2447 GLX_FUNCTION(glXGetProcAddressARB
),
2450 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2452 #ifndef GLX_USE_APPLEGL
2453 /*** GLX_OML_sync_control ***/
2454 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2455 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2456 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2457 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2458 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2460 /*** GLX_EXT_texture_from_pixmap ***/
2461 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2462 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2465 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2466 /*** DRI configuration ***/
2467 GLX_FUNCTION(glXGetScreenDriver
),
2468 GLX_FUNCTION(glXGetDriverConfig
),
2471 {NULL
, NULL
} /* end of list */
2474 #ifndef GLX_USE_APPLEGL
2475 static const GLvoid
*
2476 get_glx_proc_address(const char *funcName
)
2480 /* try static functions */
2481 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2482 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2483 return GLX_functions
[i
].Address
;
2491 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2492 * \c glXGetProcAddress.
2494 * \param procName Name of a GL or GLX function.
2495 * \returns A pointer to the named function
2497 * \sa glXGetProcAddress
2499 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2501 typedef void (*gl_function
) (void);
2505 /* Search the table of GLX and internal functions first. If that
2506 * fails and the supplied name could be a valid core GL name, try
2507 * searching the core GL function table. This check is done to prevent
2508 * DRI based drivers from searching the core GL function table for
2509 * internal API functions.
2511 #ifdef GLX_USE_APPLEGL
2512 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2514 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2515 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2516 && (procName
[2] != 'X')) {
2517 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2524 * Get the address of a named GL function. This is the GLX 1.4 name for
2525 * \c glXGetProcAddressARB.
2527 * \param procName Name of a GL or GLX function.
2528 * \returns A pointer to the named function
2530 * \sa glXGetProcAddressARB
2532 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2533 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2534 __attribute__ ((alias("glXGetProcAddressARB")));
2537 return glXGetProcAddressARB(procName
);
2539 #endif /* __GNUC__ */
2542 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2544 * Get the unadjusted system time (UST). Currently, the UST is measured in
2545 * microseconds since Epoc. The actual resolution of the UST may vary from
2546 * system to system, and the units may vary from release to release.
2547 * Drivers should not call this function directly. They should instead use
2548 * \c glXGetProcAddress to obtain a pointer to the function.
2550 * \param ust Location to store the 64-bit UST
2551 * \returns Zero on success or a negative errno value on failure.
2553 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2555 * \since Internal API version 20030317.
2558 __glXGetUST(int64_t * ust
)
2566 if (gettimeofday(&tv
, NULL
) == 0) {
2567 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2574 #endif /* GLX_DIRECT_RENDERING */