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 #include "glx_error.h"
42 #ifdef GLX_DIRECT_RENDERING
43 #ifdef GLX_USE_APPLEGL
44 #include "apple_glx_context.h"
45 #include "apple_glx.h"
49 #include <X11/extensions/xf86vmode.h>
56 #include <X11/Xlib-xcb.h>
60 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
61 static const char __glXGLXClientVersion
[] = "1.4";
63 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
66 * Get the __DRIdrawable for the drawable associated with a GLXContext
68 * \param dpy The display associated with \c drawable.
69 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
70 * \param scrn_num If non-NULL, the drawables screen is stored there
71 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
72 * the drawable is not associated with a direct-rendering context.
74 _X_HIDDEN __GLXDRIdrawable
*
75 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
77 struct glx_display
*priv
= __glXInitialize(dpy
);
78 __GLXDRIdrawable
*pdraw
;
83 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
91 _X_HIDDEN
struct glx_drawable
*
92 GetGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
94 struct glx_display
*priv
= __glXInitialize(dpy
);
95 struct glx_drawable
*glxDraw
;
100 if (__glxHashLookup(priv
->glXDrawHash
, drawable
, (void *) &glxDraw
) == 0)
107 InitGLXDrawable(Display
*dpy
, struct glx_drawable
*glxDraw
, XID xDrawable
,
108 GLXDrawable drawable
)
110 struct glx_display
*priv
= __glXInitialize(dpy
);
115 glxDraw
->xDrawable
= xDrawable
;
116 glxDraw
->drawable
= drawable
;
117 glxDraw
->lastEventSbc
= 0;
118 glxDraw
->eventSbcWrap
= 0;
120 return __glxHashInsert(priv
->glXDrawHash
, drawable
, glxDraw
);
124 DestroyGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
126 struct glx_display
*priv
= __glXInitialize(dpy
);
127 struct glx_drawable
*glxDraw
;
132 glxDraw
= GetGLXDrawable(dpy
, drawable
);
133 __glxHashDelete(priv
->glXDrawHash
, drawable
);
138 * Get the GLX per-screen data structure associated with a GLX context.
140 * \param dpy Display for which the GLX per-screen information is to be
142 * \param scrn Screen on \c dpy for which the GLX per-screen information is
144 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
145 * specify a valid GLX screen, or NULL otherwise.
147 * \todo Should this function validate that \c scrn is within the screen
148 * number range for \c dpy?
151 _X_HIDDEN
struct glx_screen
*
152 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
154 struct glx_display
*const priv
= __glXInitialize(dpy
);
158 NULL
) ? priv
->screens
[scrn
] : NULL
;
163 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
164 struct glx_screen
** ppsc
)
166 /* Initialize the extension, if needed . This has the added value
167 * of initializing/allocating the display private
171 return GLX_NO_EXTENSION
;
174 *ppriv
= __glXInitialize(dpy
);
175 if (*ppriv
== NULL
) {
176 return GLX_NO_EXTENSION
;
179 /* Check screen number to see if its valid */
180 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
181 return GLX_BAD_SCREEN
;
184 /* Check to see if the GL is supported on this screen */
185 *ppsc
= (*ppriv
)->screens
[scrn
];
186 if ((*ppsc
)->configs
== NULL
&& (*ppsc
)->visuals
== NULL
) {
187 /* No support for GL on this screen regardless of visual */
188 return GLX_BAD_VISUAL
;
196 * Determine if a \c GLXFBConfig supplied by the application is valid.
198 * \param dpy Application supplied \c Display pointer.
199 * \param config Application supplied \c GLXFBConfig.
201 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
202 * \c struct glx_config structure is returned. Otherwise, \c NULL
205 static struct glx_config
*
206 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
208 struct glx_display
*const priv
= __glXInitialize(dpy
);
209 int num_screens
= ScreenCount(dpy
);
211 struct glx_config
*config
;
214 for (i
= 0; i
< num_screens
; i
++) {
215 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
216 config
= config
->next
) {
217 if (config
== (struct glx_config
*) fbconfig
) {
228 * Verifies context's GLX_RENDER_TYPE value with config.
230 * \param config GLX FBConfig which will support the returned renderType.
231 * \param renderType The context render type to be verified.
232 * \return True if the value of context renderType was approved, or 0 if no
233 * valid value was found.
236 validate_renderType_against_config(const struct glx_config
*config
,
239 switch (renderType
) {
241 return (config
->renderType
& GLX_RGBA_BIT
) != 0;
242 case GLX_COLOR_INDEX_TYPE
:
243 return (config
->renderType
& GLX_COLOR_INDEX_BIT
) != 0;
244 case GLX_RGBA_FLOAT_TYPE_ARB
:
245 return (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) != 0;
246 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
:
247 return (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) != 0;
255 glx_context_init(struct glx_context
*gc
,
256 struct glx_screen
*psc
, struct glx_config
*config
)
258 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
259 if (!gc
->majorOpcode
)
262 gc
->screen
= psc
->scr
;
265 gc
->isDirect
= GL_TRUE
;
266 gc
->currentContextTag
= -1;
273 * Create a new context.
275 * \param renderType For FBConfigs, what is the rendering type?
279 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
280 GLXContext shareList_user
, Bool allowDirect
,
281 unsigned code
, int renderType
, int screen
)
283 struct glx_context
*gc
;
284 struct glx_screen
*psc
;
285 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
289 psc
= GetGLXScreenConfigs(dpy
, screen
);
293 if (generic_id
== None
)
297 #ifdef GLX_USE_APPLEGL
298 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
300 if (allowDirect
&& psc
->vtable
->create_context
)
301 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
303 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
310 case X_GLXCreateContext
: {
311 xGLXCreateContextReq
*req
;
313 /* Send the glXCreateContext request */
314 GetReq(GLXCreateContext
, req
);
315 req
->reqType
= gc
->majorOpcode
;
316 req
->glxCode
= X_GLXCreateContext
;
317 req
->context
= gc
->xid
= XAllocID(dpy
);
318 req
->visual
= generic_id
;
319 req
->screen
= screen
;
320 req
->shareList
= shareList
? shareList
->xid
: None
;
321 req
->isDirect
= gc
->isDirect
;
325 case X_GLXCreateNewContext
: {
326 xGLXCreateNewContextReq
*req
;
328 /* Send the glXCreateNewContext request */
329 GetReq(GLXCreateNewContext
, req
);
330 req
->reqType
= gc
->majorOpcode
;
331 req
->glxCode
= X_GLXCreateNewContext
;
332 req
->context
= gc
->xid
= XAllocID(dpy
);
333 req
->fbconfig
= generic_id
;
334 req
->screen
= screen
;
335 req
->renderType
= renderType
;
336 req
->shareList
= shareList
? shareList
->xid
: None
;
337 req
->isDirect
= gc
->isDirect
;
341 case X_GLXvop_CreateContextWithConfigSGIX
: {
342 xGLXVendorPrivateWithReplyReq
*vpreq
;
343 xGLXCreateContextWithConfigSGIXReq
*req
;
345 /* Send the glXCreateNewContext request */
346 GetReqExtra(GLXVendorPrivateWithReply
,
347 sz_xGLXCreateContextWithConfigSGIXReq
-
348 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
349 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
350 req
->reqType
= gc
->majorOpcode
;
351 req
->glxCode
= X_GLXVendorPrivateWithReply
;
352 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
353 req
->context
= gc
->xid
= XAllocID(dpy
);
354 req
->fbconfig
= generic_id
;
355 req
->screen
= screen
;
356 req
->renderType
= renderType
;
357 req
->shareList
= shareList
? shareList
->xid
: None
;
358 req
->isDirect
= gc
->isDirect
;
363 /* What to do here? This case is the sign of an internal error. It
364 * should never be reachable.
372 gc
->share_xid
= shareList
? shareList
->xid
: None
;
373 gc
->imported
= GL_FALSE
;
375 return (GLXContext
) gc
;
379 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
380 GLXContext shareList
, Bool allowDirect
)
382 struct glx_config
*config
= NULL
;
383 int renderType
= GLX_RGBA_TYPE
;
385 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
386 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
389 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
391 if (config
== NULL
) {
394 error
.errorCode
= BadValue
;
395 error
.resourceID
= vis
->visualid
;
396 error
.sequenceNumber
= dpy
->request
;
397 error
.type
= X_Error
;
398 error
.majorCode
= __glXSetupForCommand(dpy
);
399 error
.minorCode
= X_GLXCreateContext
;
400 _XError(dpy
, &error
);
404 /* Choose the context render type based on DRI config values. It is
405 * unusual to set this type from config, but we have no other choice, as
406 * this old API does not provide renderType parameter.
408 if (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) {
409 renderType
= GLX_RGBA_FLOAT_TYPE_ARB
;
410 } else if (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) {
411 renderType
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
412 } else if (config
->renderType
& GLX_RGBA_BIT
) {
413 renderType
= GLX_RGBA_TYPE
;
414 } else if (config
->renderType
& GLX_COLOR_INDEX_BIT
) {
415 renderType
= GLX_COLOR_INDEX_TYPE
;
416 } else if (config
->rgbMode
) {
417 /* If we're here, then renderType is not set correctly. Let's use a
418 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
419 * default value is needed by old DRI drivers, which didn't set
420 * renderType correctly as the value was just ignored.
422 renderType
= GLX_RGBA_TYPE
;
424 /* Safeguard - only one option left, all non-RGB modes are indexed
425 * modes. Again, this allows drivers with invalid renderType to work
428 renderType
= GLX_COLOR_INDEX_TYPE
;
432 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
433 X_GLXCreateContext
, renderType
, vis
->screen
);
437 glx_send_destroy_context(Display
*dpy
, XID xid
)
439 CARD8 opcode
= __glXSetupForCommand(dpy
);
440 xGLXDestroyContextReq
*req
;
443 GetReq(GLXDestroyContext
, req
);
444 req
->reqType
= opcode
;
445 req
->glxCode
= X_GLXDestroyContext
;
452 ** Destroy the named context
456 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
458 struct glx_context
*gc
= (struct glx_context
*) ctx
;
460 if (gc
== NULL
|| gc
->xid
== None
)
465 glx_send_destroy_context(dpy
, gc
->xid
);
467 if (gc
->currentDpy
) {
468 /* This context is bound to some thread. According to the man page,
469 * we should not actually delete the context until it's unbound.
470 * Note that we set gc->xid = None above. In MakeContextCurrent()
471 * we check for that and delete the context there.
475 gc
->vtable
->destroy(gc
);
481 ** Return the major and minor version #s for the GLX extension
484 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
486 struct glx_display
*priv
;
488 /* Init the extension. This fetches the major and minor version. */
489 priv
= __glXInitialize(dpy
);
494 *major
= priv
->majorVersion
;
496 *minor
= priv
->minorVersion
;
501 ** Query the existance of the GLX extension
504 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
506 int major_op
, erb
, evb
;
509 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
520 ** Put a barrier in the token stream that forces the GL to finish its
521 ** work before X can proceed.
526 struct glx_context
*gc
= __glXGetCurrentContext();
528 if (gc
&& gc
->vtable
->wait_gl
)
529 gc
->vtable
->wait_gl(gc
);
533 ** Put a barrier in the token stream that forces X to finish its
534 ** work before GL can proceed.
539 struct glx_context
*gc
= __glXGetCurrentContext();
541 if (gc
&& gc
->vtable
->wait_x
)
542 gc
->vtable
->wait_x(gc
);
546 glXUseXFont(Font font
, int first
, int count
, int listBase
)
548 struct glx_context
*gc
= __glXGetCurrentContext();
550 if (gc
&& gc
->vtable
->use_x_font
)
551 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
554 /************************************************************************/
557 ** Copy the source context to the destination context using the
561 glXCopyContext(Display
* dpy
, GLXContext source_user
,
562 GLXContext dest_user
, unsigned long mask
)
564 struct glx_context
*source
= (struct glx_context
*) source_user
;
565 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
566 #ifdef GLX_USE_APPLEGL
567 struct glx_context
*gc
= __glXGetCurrentContext();
571 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
572 mask
, &errorcode
, &x11error
)) {
573 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
577 xGLXCopyContextReq
*req
;
578 struct glx_context
*gc
= __glXGetCurrentContext();
582 opcode
= __glXSetupForCommand(dpy
);
587 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
589 /* NOT_DONE: This does not work yet */
594 ** If the source is the current context, send its tag so that the context
595 ** can be flushed before the copy.
597 if (source
== gc
&& dpy
== gc
->currentDpy
) {
598 tag
= gc
->currentContextTag
;
604 /* Send the glXCopyContext request */
606 GetReq(GLXCopyContext
, req
);
607 req
->reqType
= opcode
;
608 req
->glxCode
= X_GLXCopyContext
;
609 req
->source
= source
? source
->xid
: None
;
610 req
->dest
= dest
? dest
->xid
: None
;
612 req
->contextTag
= tag
;
615 #endif /* GLX_USE_APPLEGL */
620 * Determine if a context uses direct rendering.
622 * \param dpy Display where the context was created.
623 * \param contextID ID of the context to be tested.
625 * \returns \c True if the context is direct rendering or not.
628 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
632 xcb_generic_error_t
*err
;
633 xcb_glx_is_direct_reply_t
*reply
;
636 opcode
= __glXSetupForCommand(dpy
);
641 c
= XGetXCBConnection(dpy
);
642 reply
= xcb_glx_is_direct_reply(c
, xcb_glx_is_direct(c
, contextID
), &err
);
643 is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
646 __glXSendErrorForXcb(dpy
, err
);
657 * Shouldn't this function \b always return \c False when
658 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
659 * the GLX protocol here at all?
662 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
664 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
669 else if (gc
->isDirect
) {
672 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
675 return __glXIsDirect(dpy
, gc
->xid
);
680 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
682 #ifdef GLX_USE_APPLEGL
683 int screen
= vis
->screen
;
684 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
685 const struct glx_config
*config
;
687 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
689 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
694 xGLXCreateGLXPixmapReq
*req
;
695 struct glx_drawable
*glxDraw
;
699 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
700 struct glx_display
*const priv
= __glXInitialize(dpy
);
706 opcode
= __glXSetupForCommand(dpy
);
711 glxDraw
= malloc(sizeof(*glxDraw
));
715 /* Send the glXCreateGLXPixmap request */
717 GetReq(GLXCreateGLXPixmap
, req
);
718 req
->reqType
= opcode
;
719 req
->glxCode
= X_GLXCreateGLXPixmap
;
720 req
->screen
= vis
->screen
;
721 req
->visual
= vis
->visualid
;
722 req
->pixmap
= pixmap
;
723 req
->glxpixmap
= xid
= XAllocID(dpy
);
727 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
732 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
734 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
735 * is actually bound to a context... */
737 __GLXDRIdrawable
*pdraw
;
738 struct glx_screen
*psc
;
739 struct glx_config
*config
;
741 psc
= priv
->screens
[vis
->screen
];
742 if (psc
->driScreen
== NULL
)
745 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
746 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
748 fprintf(stderr
, "failed to create pixmap\n");
753 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
754 (*pdraw
->destroyDrawable
) (pdraw
);
761 xGLXDestroyGLXPixmapReq
*dreq
;
763 GetReq(GLXDestroyGLXPixmap
, dreq
);
764 dreq
->reqType
= opcode
;
765 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
766 dreq
->glxpixmap
= xid
;
777 ** Destroy the named pixmap
780 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
782 #ifdef GLX_USE_APPLEGL
783 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
784 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
786 xGLXDestroyGLXPixmapReq
*req
;
789 opcode
= __glXSetupForCommand(dpy
);
794 /* Send the glXDestroyGLXPixmap request */
796 GetReq(GLXDestroyGLXPixmap
, req
);
797 req
->reqType
= opcode
;
798 req
->glxCode
= X_GLXDestroyGLXPixmap
;
799 req
->glxpixmap
= glxpixmap
;
803 DestroyGLXDrawable(dpy
, glxpixmap
);
805 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
807 struct glx_display
*const priv
= __glXInitialize(dpy
);
808 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
810 if (priv
!= NULL
&& pdraw
!= NULL
) {
811 (*pdraw
->destroyDrawable
) (pdraw
);
812 __glxHashDelete(priv
->drawHash
, glxpixmap
);
816 #endif /* GLX_USE_APPLEGL */
820 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
822 #ifdef GLX_USE_APPLEGL
823 struct glx_context
* gc
= __glXGetCurrentContext();
824 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
825 apple_glx_swap_buffers(gc
->driContext
);
827 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
830 struct glx_context
*gc
;
835 gc
= __glXGetCurrentContext();
837 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
839 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
842 Bool flush
= gc
&& drawable
== gc
->currentDrawable
;
844 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0, flush
);
850 opcode
= __glXSetupForCommand(dpy
);
856 ** The calling thread may or may not have a current context. If it
857 ** does, send the context tag so the server can do a flush.
859 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
860 ((drawable
== gc
->currentDrawable
)
861 || (drawable
== gc
->currentReadable
))) {
862 tag
= gc
->currentContextTag
;
868 c
= XGetXCBConnection(dpy
);
869 xcb_glx_swap_buffers(c
, tag
, drawable
);
871 #endif /* GLX_USE_APPLEGL */
876 ** Return configuration information for the given display, screen and
877 ** visual combination.
880 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
883 struct glx_display
*priv
;
884 struct glx_screen
*psc
;
885 struct glx_config
*config
;
888 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
889 if (status
== Success
) {
890 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
892 /* Lookup attribute after first finding a match on the visual */
893 if (config
!= NULL
) {
894 return glx_config_get(config
, attribute
, value_return
);
897 status
= GLX_BAD_VISUAL
;
901 ** If we can't find the config for this visual, this visual is not
902 ** supported by the OpenGL implementation on the server.
904 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
905 *value_return
= False
;
912 /************************************************************************/
915 init_fbconfig_for_chooser(struct glx_config
* config
,
916 GLboolean fbconfig_style_tags
)
918 memset(config
, 0, sizeof(struct glx_config
));
919 config
->visualID
= (XID
) GLX_DONT_CARE
;
920 config
->visualType
= GLX_DONT_CARE
;
922 /* glXChooseFBConfig specifies different defaults for these properties than
925 if (fbconfig_style_tags
) {
926 config
->rgbMode
= GL_TRUE
;
927 config
->doubleBufferMode
= GLX_DONT_CARE
;
928 config
->renderType
= GLX_RGBA_BIT
;
931 config
->drawableType
= GLX_WINDOW_BIT
;
932 config
->visualRating
= GLX_DONT_CARE
;
933 config
->transparentPixel
= GLX_NONE
;
934 config
->transparentRed
= GLX_DONT_CARE
;
935 config
->transparentGreen
= GLX_DONT_CARE
;
936 config
->transparentBlue
= GLX_DONT_CARE
;
937 config
->transparentAlpha
= GLX_DONT_CARE
;
938 config
->transparentIndex
= GLX_DONT_CARE
;
940 config
->xRenderable
= GLX_DONT_CARE
;
941 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
943 config
->swapMethod
= GLX_DONT_CARE
;
946 #define MATCH_DONT_CARE( param ) \
948 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
949 && (a-> param != b-> param) ) { \
954 #define MATCH_MINIMUM( param ) \
956 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
957 && (a-> param > b-> param) ) { \
962 #define MATCH_EXACT( param ) \
964 if ( a-> param != b-> param) { \
969 /* Test that all bits from a are contained in b */
970 #define MATCH_MASK(param) \
972 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
973 && ((a->param & ~b->param) != 0) ) { \
979 * Determine if two GLXFBConfigs are compatible.
981 * \param a Application specified config to test.
982 * \param b Server specified config to test against \c a.
985 fbconfigs_compatible(const struct glx_config
* const a
,
986 const struct glx_config
* const b
)
988 MATCH_DONT_CARE(doubleBufferMode
);
989 MATCH_DONT_CARE(visualType
);
990 MATCH_DONT_CARE(visualRating
);
991 MATCH_DONT_CARE(xRenderable
);
992 MATCH_DONT_CARE(fbconfigID
);
993 MATCH_DONT_CARE(swapMethod
);
995 MATCH_MINIMUM(rgbBits
);
996 MATCH_MINIMUM(numAuxBuffers
);
997 MATCH_MINIMUM(redBits
);
998 MATCH_MINIMUM(greenBits
);
999 MATCH_MINIMUM(blueBits
);
1000 MATCH_MINIMUM(alphaBits
);
1001 MATCH_MINIMUM(depthBits
);
1002 MATCH_MINIMUM(stencilBits
);
1003 MATCH_MINIMUM(accumRedBits
);
1004 MATCH_MINIMUM(accumGreenBits
);
1005 MATCH_MINIMUM(accumBlueBits
);
1006 MATCH_MINIMUM(accumAlphaBits
);
1007 MATCH_MINIMUM(sampleBuffers
);
1008 MATCH_MINIMUM(maxPbufferWidth
);
1009 MATCH_MINIMUM(maxPbufferHeight
);
1010 MATCH_MINIMUM(maxPbufferPixels
);
1011 MATCH_MINIMUM(samples
);
1013 MATCH_DONT_CARE(stereoMode
);
1016 MATCH_MASK(drawableType
);
1017 MATCH_MASK(renderType
);
1019 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1020 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1021 * Technically speaking, it is a bug in the DDX driver, but there is
1022 * enough of an installed base to work around the problem here. In any
1023 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1024 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1025 * 0 from the server to be a match to maintain backward compatibility with
1026 * the (broken) drivers.
1029 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1030 if (a
->transparentPixel
== GLX_NONE
) {
1031 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1035 MATCH_EXACT(transparentPixel
);
1038 switch (a
->transparentPixel
) {
1039 case GLX_TRANSPARENT_RGB
:
1040 MATCH_DONT_CARE(transparentRed
);
1041 MATCH_DONT_CARE(transparentGreen
);
1042 MATCH_DONT_CARE(transparentBlue
);
1043 MATCH_DONT_CARE(transparentAlpha
);
1046 case GLX_TRANSPARENT_INDEX
:
1047 MATCH_DONT_CARE(transparentIndex
);
1059 /* There's some trickly language in the GLX spec about how this is supposed
1060 * to work. Basically, if a given component size is either not specified
1061 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1062 * Well, that's really hard to do with the code as-is. This behavior is
1063 * closer to correct, but still not technically right.
1065 #define PREFER_LARGER_OR_ZERO(comp) \
1067 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1068 if ( ((*a)-> comp) == 0 ) { \
1071 else if ( ((*b)-> comp) == 0 ) { \
1075 return ((*b)-> comp) - ((*a)-> comp) ; \
1080 #define PREFER_LARGER(comp) \
1082 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1083 return ((*b)-> comp) - ((*a)-> comp) ; \
1087 #define PREFER_SMALLER(comp) \
1089 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1090 return ((*a)-> comp) - ((*b)-> comp) ; \
1095 * Compare two GLXFBConfigs. This function is intended to be used as the
1096 * compare function passed in to qsort.
1098 * \returns If \c a is a "better" config, according to the specification of
1099 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1100 * better, then a number greater than zero is return. If both are
1101 * equal, zero is returned.
1102 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1105 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1107 /* The order of these comparisons must NOT change. It is defined by
1108 * the GLX 1.3 spec and ARB_multisample.
1111 PREFER_SMALLER(visualSelectGroup
);
1113 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1114 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1115 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1117 PREFER_SMALLER(visualRating
);
1119 /* This isn't quite right. It is supposed to compare the sum of the
1120 * components the user specifically set minimums for.
1122 PREFER_LARGER_OR_ZERO(redBits
);
1123 PREFER_LARGER_OR_ZERO(greenBits
);
1124 PREFER_LARGER_OR_ZERO(blueBits
);
1125 PREFER_LARGER_OR_ZERO(alphaBits
);
1127 PREFER_SMALLER(rgbBits
);
1129 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1130 /* Prefer single-buffer.
1132 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1135 PREFER_SMALLER(numAuxBuffers
);
1137 PREFER_LARGER_OR_ZERO(depthBits
);
1138 PREFER_SMALLER(stencilBits
);
1140 /* This isn't quite right. It is supposed to compare the sum of the
1141 * components the user specifically set minimums for.
1143 PREFER_LARGER_OR_ZERO(accumRedBits
);
1144 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1145 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1146 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1148 PREFER_SMALLER(visualType
);
1150 /* None of the multisample specs say where this comparison should happen,
1151 * so I put it near the end.
1153 PREFER_SMALLER(sampleBuffers
);
1154 PREFER_SMALLER(samples
);
1156 /* None of the pbuffer or fbconfig specs say that this comparison needs
1157 * to happen at all, but it seems like it should.
1159 PREFER_LARGER(maxPbufferWidth
);
1160 PREFER_LARGER(maxPbufferHeight
);
1161 PREFER_LARGER(maxPbufferPixels
);
1168 * Selects and sorts a subset of the supplied configs based on the attributes.
1169 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1170 * and \c glXChooseFBConfigSGIX.
1172 * \param configs Array of pointers to possible configs. The elements of
1173 * this array that do not meet the criteria will be set to
1174 * NULL. The remaining elements will be sorted according to
1175 * the various visual / FBConfig selection rules.
1176 * \param num_configs Number of elements in the \c configs array.
1177 * \param attribList Attributes used select from \c configs. This array is
1178 * terminated by a \c None tag. The array can either take
1179 * the form expected by \c glXChooseVisual (where boolean
1180 * tags do not have a value) or by \c glXChooseFBConfig
1181 * (where every tag has a value).
1182 * \param fbconfig_style_tags Selects whether \c attribList is in
1183 * \c glXChooseVisual style or
1184 * \c glXChooseFBConfig style.
1185 * \returns The number of valid elements left in \c configs.
1187 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1190 choose_visual(struct glx_config
** configs
, int num_configs
,
1191 const int *attribList
, GLboolean fbconfig_style_tags
)
1193 struct glx_config test_config
;
1197 /* This is a fairly direct implementation of the selection method
1198 * described by GLX_SGIX_fbconfig. Start by culling out all the
1199 * configs that are not compatible with the selected parameter
1203 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1204 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1205 (const INT32
*) attribList
,
1206 GL_TRUE
, fbconfig_style_tags
);
1209 for (i
= 0; i
< num_configs
; i
++) {
1210 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1211 configs
[base
] = configs
[i
];
1220 if (base
< num_configs
) {
1221 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1224 /* After the incompatible configs are removed, the resulting
1225 * list is sorted according to the rules set out in the various
1229 qsort(configs
, base
, sizeof(struct glx_config
*),
1230 (int (*)(const void *, const void *)) fbconfig_compare
);
1238 ** Return the visual that best matches the template. Return None if no
1239 ** visual matches the template.
1241 _X_EXPORT XVisualInfo
*
1242 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1244 XVisualInfo
*visualList
= NULL
;
1245 struct glx_display
*priv
;
1246 struct glx_screen
*psc
;
1247 struct glx_config test_config
;
1248 struct glx_config
*config
;
1249 struct glx_config
*best_config
= NULL
;
1252 ** Get a list of all visuals, return if list is empty
1254 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1260 ** Build a template from the defaults and the attribute list
1261 ** Free visual list and return if an unexpected token is encountered
1263 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1264 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1265 (const INT32
*) attribList
,
1269 ** Eliminate visuals that don't meet minimum requirements
1270 ** Compute a score for those that do
1271 ** Remember which visual, if any, got the highest score
1272 ** If no visual is acceptable, return None
1273 ** Otherwise, create an XVisualInfo list with just the selected X visual
1276 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1277 if (fbconfigs_compatible(&test_config
, config
)
1278 && ((best_config
== NULL
) ||
1279 (fbconfig_compare (&config
, &best_config
) < 0))) {
1280 XVisualInfo visualTemplate
;
1281 XVisualInfo
*newList
;
1284 visualTemplate
.screen
= screen
;
1285 visualTemplate
.visualid
= config
->visualID
;
1286 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1287 &visualTemplate
, &i
);
1291 visualList
= newList
;
1292 best_config
= config
;
1297 #ifdef GLX_USE_APPLEGL
1298 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1299 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1307 _X_EXPORT
const char *
1308 glXQueryExtensionsString(Display
* dpy
, int screen
)
1310 struct glx_screen
*psc
;
1311 struct glx_display
*priv
;
1313 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1317 if (!psc
->effectiveGLXexts
) {
1318 if (!psc
->serverGLXexts
) {
1319 psc
->serverGLXexts
=
1320 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1324 __glXCalculateUsableExtensions(psc
,
1325 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1326 (psc
->driScreen
!= NULL
),
1330 priv
->minorVersion
);
1333 return psc
->effectiveGLXexts
;
1336 _X_EXPORT
const char *
1337 glXGetClientString(Display
* dpy
, int name
)
1343 return (__glXGLXClientVendorName
);
1345 return (__glXGLXClientVersion
);
1346 case GLX_EXTENSIONS
:
1347 return (__glXGetClientExtensions());
1353 _X_EXPORT
const char *
1354 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1356 struct glx_screen
*psc
;
1357 struct glx_display
*priv
;
1361 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1367 str
= &priv
->serverGLXvendor
;
1370 str
= &priv
->serverGLXversion
;
1372 case GLX_EXTENSIONS
:
1373 str
= &psc
->serverGLXexts
;
1380 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1387 __glXClientInfo(Display
* dpy
, int opcode
)
1389 char *ext_str
= __glXGetClientGLExtensionString();
1390 int size
= strlen(ext_str
) + 1;
1392 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1393 xcb_glx_client_info(c
,
1394 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1401 ** EXT_import_context
1405 glXGetCurrentDisplay(void)
1407 struct glx_context
*gc
= __glXGetCurrentContext();
1410 return gc
->currentDpy
;
1414 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1415 glXGetCurrentDisplay
)
1417 #ifndef GLX_USE_APPLEGL
1418 _X_EXPORT GLXContext
1419 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1421 struct glx_display
*priv
= __glXInitialize(dpy
);
1422 struct glx_screen
*psc
= NULL
;
1423 xGLXQueryContextReply reply
;
1425 struct glx_context
*ctx
;
1427 /* This GLX implementation knows about 5 different properties, so
1428 * allow the server to send us one of each.
1430 int propList
[5 * 2], *pProp
, nPropListBytes
;
1434 struct glx_config
*mode
;
1435 uint32_t fbconfigID
= 0;
1436 uint32_t visualID
= 0;
1437 uint32_t screen
= 0;
1438 Bool got_screen
= False
;
1443 /* The GLX_EXT_import_context spec says:
1445 * "If <contextID> does not refer to a valid context, then a BadContext
1446 * error is generated; if <contextID> refers to direct rendering
1447 * context then no error is generated but glXImportContextEXT returns
1450 * If contextID is None, generate BadContext on the client-side. Other
1451 * sorts of invalid contexts will be detected by the server in the
1452 * __glXIsDirect call.
1454 if (contextID
== None
) {
1455 __glXSendError(dpy
, GLXBadContext
, contextID
, X_GLXIsDirect
, false);
1459 if (__glXIsDirect(dpy
, contextID
))
1462 opcode
= __glXSetupForCommand(dpy
);
1466 /* Send the glXQueryContextInfoEXT request */
1469 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1470 xGLXQueryContextReq
*req
;
1472 GetReq(GLXQueryContext
, req
);
1474 req
->reqType
= opcode
;
1475 req
->glxCode
= X_GLXQueryContext
;
1476 req
->context
= contextID
;
1479 xGLXVendorPrivateReq
*vpreq
;
1480 xGLXQueryContextInfoEXTReq
*req
;
1482 GetReqExtra(GLXVendorPrivate
,
1483 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1485 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1486 req
->reqType
= opcode
;
1487 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1488 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1489 req
->context
= contextID
;
1492 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1494 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1495 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1498 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1502 numProps
= nPropListBytes
/ (2 * sizeof(propList
[0]));
1505 renderType
= GLX_RGBA_TYPE
; /* By default, assume RGBA context */
1508 for (i
= 0, pProp
= propList
; i
< numProps
; i
++, pProp
+= 2)
1514 case GLX_SHARE_CONTEXT_EXT
:
1517 case GLX_VISUAL_ID_EXT
:
1518 visualID
= pProp
[1];
1520 case GLX_FBCONFIG_ID
:
1521 fbconfigID
= pProp
[1];
1523 case GLX_RENDER_TYPE
:
1524 renderType
= pProp
[1];
1531 psc
= GetGLXScreenConfigs(dpy
, screen
);
1535 if (fbconfigID
!= 0) {
1536 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1537 } else if (visualID
!= 0) {
1538 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1544 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1548 ctx
->xid
= contextID
;
1549 ctx
->imported
= GL_TRUE
;
1550 ctx
->share_xid
= share
;
1552 return (GLXContext
) ctx
;
1558 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1560 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1562 switch (attribute
) {
1563 case GLX_SHARE_CONTEXT_EXT
:
1564 *value
= ctx
->share_xid
;
1566 case GLX_VISUAL_ID_EXT
:
1567 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1570 *value
= ctx
->screen
;
1572 case GLX_FBCONFIG_ID
:
1573 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1575 case GLX_RENDER_TYPE
:
1576 *value
= ctx
->renderType
;
1579 return GLX_BAD_ATTRIBUTE
;
1585 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1586 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1587 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1589 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1591 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1593 return (ctx
== NULL
) ? None
: ctx
->xid
;
1597 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1599 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1601 if (gc
== NULL
|| gc
->xid
== None
)
1604 /* The GLX_EXT_import_context spec says:
1606 * "glXFreeContext does not free the server-side context information or
1607 * the XID associated with the server-side context."
1609 * Don't send any protocol. Just destroy the client-side tracking of the
1610 * context. Also, only release the context structure if it's not current.
1613 if (gc
->currentDpy
) {
1616 gc
->vtable
->destroy(gc
);
1621 _X_EXPORT GLXFBConfig
*
1622 glXChooseFBConfig(Display
* dpy
, int screen
,
1623 const int *attribList
, int *nitems
)
1625 struct glx_config
**config_list
;
1629 config_list
= (struct glx_config
**)
1630 glXGetFBConfigs(dpy
, screen
, &list_size
);
1632 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1633 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1634 if (list_size
== 0) {
1640 *nitems
= list_size
;
1641 return (GLXFBConfig
*) config_list
;
1645 _X_EXPORT GLXContext
1646 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1647 int renderType
, GLXContext shareList
, Bool allowDirect
)
1649 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1651 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1652 allowDirect
, X_GLXCreateNewContext
, renderType
,
1657 _X_EXPORT GLXDrawable
1658 glXGetCurrentReadDrawable(void)
1660 struct glx_context
*gc
= __glXGetCurrentContext();
1662 return gc
->currentReadable
;
1666 _X_EXPORT GLXFBConfig
*
1667 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1669 struct glx_display
*priv
= __glXInitialize(dpy
);
1670 struct glx_config
**config_list
= NULL
;
1671 struct glx_config
*config
;
1672 unsigned num_configs
= 0;
1676 if (priv
&& (priv
->screens
!= NULL
)
1677 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1678 && (priv
->screens
[screen
]->configs
!= NULL
)
1679 && (priv
->screens
[screen
]->configs
->fbconfigID
1680 != (int) GLX_DONT_CARE
)) {
1682 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1683 config
= config
->next
) {
1684 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1689 config_list
= malloc(num_configs
* sizeof *config_list
);
1690 if (config_list
!= NULL
) {
1691 *nelements
= num_configs
;
1693 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1694 config
= config
->next
) {
1695 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1696 config_list
[i
] = config
;
1703 return (GLXFBConfig
*) config_list
;
1708 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1709 int attribute
, int *value
)
1711 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1714 return GLXBadFBConfig
;
1716 return glx_config_get(config
, attribute
, value
);
1720 _X_EXPORT XVisualInfo
*
1721 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1723 XVisualInfo visualTemplate
;
1724 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1728 ** Get a list of all visuals, return if list is empty
1730 visualTemplate
.visualid
= config
->visualID
;
1731 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1734 #ifndef GLX_USE_APPLEGL
1736 ** GLX_SGI_swap_control
1739 __glXSwapIntervalSGI(int interval
)
1741 xGLXVendorPrivateReq
*req
;
1742 struct glx_context
*gc
= __glXGetCurrentContext();
1743 struct glx_screen
*psc
;
1745 CARD32
*interval_ptr
;
1749 return GLX_BAD_CONTEXT
;
1752 if (interval
<= 0) {
1753 return GLX_BAD_VALUE
;
1756 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1758 #ifdef GLX_DIRECT_RENDERING
1759 if (gc
->isDirect
&& psc
&& psc
->driScreen
&&
1760 psc
->driScreen
->setSwapInterval
) {
1761 __GLXDRIdrawable
*pdraw
=
1762 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1763 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1768 dpy
= gc
->currentDpy
;
1769 opcode
= __glXSetupForCommand(dpy
);
1774 /* Send the glXSwapIntervalSGI request */
1776 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1777 req
->reqType
= opcode
;
1778 req
->glxCode
= X_GLXVendorPrivate
;
1779 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1780 req
->contextTag
= gc
->currentContextTag
;
1782 interval_ptr
= (CARD32
*) (req
+ 1);
1783 *interval_ptr
= interval
;
1794 ** GLX_MESA_swap_control
1797 __glXSwapIntervalMESA(unsigned int interval
)
1799 #ifdef GLX_DIRECT_RENDERING
1800 struct glx_context
*gc
= __glXGetCurrentContext();
1802 if (gc
!= NULL
&& gc
->isDirect
) {
1803 struct glx_screen
*psc
;
1805 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1806 if (psc
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1807 __GLXDRIdrawable
*pdraw
=
1808 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1809 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1814 return GLX_BAD_CONTEXT
;
1819 __glXGetSwapIntervalMESA(void)
1821 #ifdef GLX_DIRECT_RENDERING
1822 struct glx_context
*gc
= __glXGetCurrentContext();
1824 if (gc
!= NULL
&& gc
->isDirect
) {
1825 struct glx_screen
*psc
;
1827 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1828 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1829 __GLXDRIdrawable
*pdraw
=
1830 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1831 return psc
->driScreen
->getSwapInterval(pdraw
);
1841 ** GLX_SGI_video_sync
1844 __glXGetVideoSyncSGI(unsigned int *count
)
1846 int64_t ust
, msc
, sbc
;
1848 struct glx_context
*gc
= __glXGetCurrentContext();
1849 struct glx_screen
*psc
;
1850 #ifdef GLX_DIRECT_RENDERING
1851 __GLXDRIdrawable
*pdraw
;
1855 return GLX_BAD_CONTEXT
;
1857 #ifdef GLX_DIRECT_RENDERING
1859 return GLX_BAD_CONTEXT
;
1862 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1863 #ifdef GLX_DIRECT_RENDERING
1864 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1867 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1868 * FIXME: there should be a GLX encoding for this call. I can find no
1869 * FIXME: documentation for the GLX encoding.
1871 #ifdef GLX_DIRECT_RENDERING
1872 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1873 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1874 *count
= (unsigned) msc
;
1875 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1879 return GLX_BAD_CONTEXT
;
1883 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1885 struct glx_context
*gc
= __glXGetCurrentContext();
1886 struct glx_screen
*psc
;
1887 #ifdef GLX_DIRECT_RENDERING
1888 __GLXDRIdrawable
*pdraw
;
1890 int64_t ust
, msc
, sbc
;
1893 if (divisor
<= 0 || remainder
< 0)
1894 return GLX_BAD_VALUE
;
1897 return GLX_BAD_CONTEXT
;
1899 #ifdef GLX_DIRECT_RENDERING
1901 return GLX_BAD_CONTEXT
;
1904 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1905 #ifdef GLX_DIRECT_RENDERING
1906 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1909 #ifdef GLX_DIRECT_RENDERING
1910 if (psc
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1911 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1913 *count
= (unsigned) msc
;
1914 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1918 return GLX_BAD_CONTEXT
;
1921 #endif /* GLX_USE_APPLEGL */
1924 ** GLX_SGIX_fbconfig
1925 ** Many of these functions are aliased to GLX 1.3 entry points in the
1926 ** GLX_functions table.
1930 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1931 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1932 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1934 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1935 (Display
* dpy
, int screen
, int *attrib_list
,
1936 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1939 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1940 (Display
* dpy
, GLXFBConfigSGIX config
),
1941 (dpy
, config
), glXGetVisualFromFBConfig
)
1944 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1945 GLXFBConfigSGIX fbconfig
,
1948 #ifndef GLX_USE_APPLEGL
1949 xGLXVendorPrivateWithReplyReq
*vpreq
;
1950 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1951 GLXPixmap xid
= None
;
1953 struct glx_screen
*psc
;
1955 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1958 if ((dpy
== NULL
) || (config
== NULL
)) {
1961 #ifdef GLX_USE_APPLEGL
1962 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1967 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1969 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1970 opcode
= __glXSetupForCommand(dpy
);
1975 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1977 GetReqExtra(GLXVendorPrivateWithReply
,
1978 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1979 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1980 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1981 req
->reqType
= opcode
;
1982 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1983 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1984 req
->screen
= config
->screen
;
1985 req
->fbconfig
= config
->fbconfigID
;
1986 req
->pixmap
= pixmap
;
1987 req
->glxpixmap
= xid
= XAllocID(dpy
);
1996 _X_EXPORT GLXContext
1997 glXCreateContextWithConfigSGIX(Display
* dpy
,
1998 GLXFBConfigSGIX fbconfig
, int renderType
,
1999 GLXContext shareList
, Bool allowDirect
)
2001 GLXContext gc
= NULL
;
2002 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2003 struct glx_screen
*psc
;
2006 if ((dpy
== NULL
) || (config
== NULL
)) {
2010 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2012 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2013 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2015 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2023 _X_EXPORT GLXFBConfigSGIX
2024 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2026 struct glx_display
*priv
;
2027 struct glx_screen
*psc
= NULL
;
2029 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2030 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2031 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2032 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2039 #ifndef GLX_USE_APPLEGL
2041 ** GLX_SGIX_swap_group
2044 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2054 ** GLX_SGIX_swap_barrier
2057 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2065 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2075 ** GLX_OML_sync_control
2078 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2079 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2081 struct glx_display
* const priv
= __glXInitialize(dpy
);
2083 #ifdef GLX_DIRECT_RENDERING
2084 __GLXDRIdrawable
*pdraw
;
2086 struct glx_screen
*psc
;
2091 #ifdef GLX_DIRECT_RENDERING
2092 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2093 psc
= pdraw
? pdraw
->psc
: NULL
;
2094 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2095 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2103 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2105 __glxGetMscRate(struct glx_screen
*psc
,
2106 int32_t * numerator
, int32_t * denominator
)
2109 XF86VidModeModeLine mode_line
;
2113 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2114 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2115 unsigned n
= dot_clock
* 1000;
2116 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2118 # define V_INTERLACE 0x010
2119 # define V_DBLSCAN 0x020
2121 if (mode_line
.flags
& V_INTERLACE
)
2123 else if (mode_line
.flags
& V_DBLSCAN
)
2126 /* The OML_sync_control spec requires that if the refresh rate is a
2127 * whole number, that the returned numerator be equal to the refresh
2128 * rate and the denominator be 1.
2136 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2138 /* This is a poor man's way to reduce a fraction. It's far from
2139 * perfect, but it will work well enough for this situation.
2142 for (i
= 0; f
[i
] != 0; i
++) {
2143 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2163 * Determine the refresh rate of the specified drawable and display.
2165 * \param dpy Display whose refresh rate is to be determined.
2166 * \param drawable Drawable whose refresh rate is to be determined.
2167 * \param numerator Numerator of the refresh rate.
2168 * \param demoninator Denominator of the refresh rate.
2169 * \return If the refresh rate for the specified display and drawable could
2170 * be calculated, True is returned. Otherwise False is returned.
2172 * \note This function is implemented entirely client-side. A lot of other
2173 * functionality is required to export GLX_OML_sync_control, so on
2174 * XFree86 this function can be called for direct-rendering contexts
2175 * when GLX_OML_sync_control appears in the client extension string.
2179 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2180 int32_t * numerator
, int32_t * denominator
)
2182 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2183 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2188 return __glxGetMscRate(draw
->psc
, numerator
, denominator
);
2200 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2201 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2203 struct glx_context
*gc
= __glXGetCurrentContext();
2204 #ifdef GLX_DIRECT_RENDERING
2205 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2206 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2209 if (!gc
) /* no GLX for this */
2212 #ifdef GLX_DIRECT_RENDERING
2213 if (!pdraw
|| !gc
->isDirect
)
2217 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2218 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2219 * of -1 if the function failed because of errors detected in the input
2222 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2224 if (divisor
> 0 && remainder
>= divisor
)
2227 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2230 #ifdef GLX_DIRECT_RENDERING
2231 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2232 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2241 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2242 int64_t target_msc
, int64_t divisor
,
2243 int64_t remainder
, int64_t * ust
,
2244 int64_t * msc
, int64_t * sbc
)
2246 #ifdef GLX_DIRECT_RENDERING
2247 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2248 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2253 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2254 * error", but the return type in the spec is Bool.
2256 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2258 if (divisor
> 0 && remainder
>= divisor
)
2261 #ifdef GLX_DIRECT_RENDERING
2262 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2263 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2274 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2275 int64_t target_sbc
, int64_t * ust
,
2276 int64_t * msc
, int64_t * sbc
)
2278 #ifdef GLX_DIRECT_RENDERING
2279 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2280 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2284 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2285 * error", but the return type in the spec is Bool.
2290 #ifdef GLX_DIRECT_RENDERING
2291 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2292 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2304 * Mesa extension stubs. These will help reduce portability problems.
2309 * Release all buffers associated with the specified GLX drawable.
2312 * This function was intended for stand-alone Mesa. The issue there is that
2313 * the library doesn't get any notification when a window is closed. In
2314 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2315 * supported, there are 3 different functions to destroy a drawable. It
2316 * should be possible to create GLX protocol (or have it determine which
2317 * protocol to use based on the type of the drawable) to have one function
2318 * do the work of 3. For the direct-rendering case, this function could
2319 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2320 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2321 * would need to be used. This really should be done as part of the new DRI
2324 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2325 * __driGarbageCollectDrawables
2326 * glXDestroyGLXPixmap
2327 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2328 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2331 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2340 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2341 Pixmap pixmap
, Colormap cmap
)
2354 * GLX_MESA_copy_sub_buffer
2356 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2358 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2359 int x
, int y
, int width
, int height
)
2361 xGLXVendorPrivateReq
*req
;
2362 struct glx_context
*gc
;
2364 CARD32
*drawable_ptr
;
2365 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2368 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2369 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2370 if (pdraw
!= NULL
) {
2371 struct glx_screen
*psc
= pdraw
->psc
;
2372 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2373 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
, True
);
2380 opcode
= __glXSetupForCommand(dpy
);
2385 ** The calling thread may or may not have a current context. If it
2386 ** does, send the context tag so the server can do a flush.
2388 gc
= __glXGetCurrentContext();
2389 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2390 ((drawable
== gc
->currentDrawable
) ||
2391 (drawable
== gc
->currentReadable
))) {
2392 tag
= gc
->currentContextTag
;
2399 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2400 req
->reqType
= opcode
;
2401 req
->glxCode
= X_GLXVendorPrivate
;
2402 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2403 req
->contextTag
= tag
;
2405 drawable_ptr
= (CARD32
*) (req
+ 1);
2406 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2407 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2408 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2409 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2411 *drawable_ptr
= drawable
;
2423 __glXBindTexImageEXT(Display
* dpy
,
2424 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2426 struct glx_context
*gc
= __glXGetCurrentContext();
2428 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2431 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2435 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2437 struct glx_context
*gc
= __glXGetCurrentContext();
2439 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2442 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2447 #endif /* GLX_USE_APPLEGL */
2450 * \c strdup is actually not a standard ANSI C or POSIX routine.
2451 * Irix will not define it if ANSI mode is in effect.
2456 __glXstrdup(const char *str
)
2459 copy
= malloc(strlen(str
) + 1);
2467 ** glXGetProcAddress support
2470 struct name_address_pair
2476 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2477 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2479 static const struct name_address_pair GLX_functions
[] = {
2480 /*** GLX_VERSION_1_0 ***/
2481 GLX_FUNCTION(glXChooseVisual
),
2482 GLX_FUNCTION(glXCopyContext
),
2483 GLX_FUNCTION(glXCreateContext
),
2484 GLX_FUNCTION(glXCreateGLXPixmap
),
2485 GLX_FUNCTION(glXDestroyContext
),
2486 GLX_FUNCTION(glXDestroyGLXPixmap
),
2487 GLX_FUNCTION(glXGetConfig
),
2488 GLX_FUNCTION(glXGetCurrentContext
),
2489 GLX_FUNCTION(glXGetCurrentDrawable
),
2490 GLX_FUNCTION(glXIsDirect
),
2491 GLX_FUNCTION(glXMakeCurrent
),
2492 GLX_FUNCTION(glXQueryExtension
),
2493 GLX_FUNCTION(glXQueryVersion
),
2494 GLX_FUNCTION(glXSwapBuffers
),
2495 GLX_FUNCTION(glXUseXFont
),
2496 GLX_FUNCTION(glXWaitGL
),
2497 GLX_FUNCTION(glXWaitX
),
2499 /*** GLX_VERSION_1_1 ***/
2500 GLX_FUNCTION(glXGetClientString
),
2501 GLX_FUNCTION(glXQueryExtensionsString
),
2502 GLX_FUNCTION(glXQueryServerString
),
2504 /*** GLX_VERSION_1_2 ***/
2505 GLX_FUNCTION(glXGetCurrentDisplay
),
2507 /*** GLX_VERSION_1_3 ***/
2508 GLX_FUNCTION(glXChooseFBConfig
),
2509 GLX_FUNCTION(glXCreateNewContext
),
2510 GLX_FUNCTION(glXCreatePbuffer
),
2511 GLX_FUNCTION(glXCreatePixmap
),
2512 GLX_FUNCTION(glXCreateWindow
),
2513 GLX_FUNCTION(glXDestroyPbuffer
),
2514 GLX_FUNCTION(glXDestroyPixmap
),
2515 GLX_FUNCTION(glXDestroyWindow
),
2516 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2517 GLX_FUNCTION(glXGetFBConfigAttrib
),
2518 GLX_FUNCTION(glXGetFBConfigs
),
2519 GLX_FUNCTION(glXGetSelectedEvent
),
2520 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2521 GLX_FUNCTION(glXMakeContextCurrent
),
2522 GLX_FUNCTION(glXQueryContext
),
2523 GLX_FUNCTION(glXQueryDrawable
),
2524 GLX_FUNCTION(glXSelectEvent
),
2526 #ifndef GLX_USE_APPLEGL
2527 /*** GLX_SGI_swap_control ***/
2528 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2530 /*** GLX_SGI_video_sync ***/
2531 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2532 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2534 /*** GLX_SGI_make_current_read ***/
2535 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2536 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2538 /*** GLX_EXT_import_context ***/
2539 GLX_FUNCTION(glXFreeContextEXT
),
2540 GLX_FUNCTION(glXGetContextIDEXT
),
2541 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2542 GLX_FUNCTION(glXImportContextEXT
),
2543 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2546 /*** GLX_SGIX_fbconfig ***/
2547 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2548 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2549 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2550 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2551 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2552 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2554 #ifndef GLX_USE_APPLEGL
2555 /*** GLX_SGIX_pbuffer ***/
2556 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2557 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2558 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2559 GLX_FUNCTION(glXSelectEventSGIX
),
2560 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2562 /*** GLX_SGIX_swap_group ***/
2563 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2565 /*** GLX_SGIX_swap_barrier ***/
2566 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2567 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2569 /*** GLX_MESA_copy_sub_buffer ***/
2570 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2572 /*** GLX_MESA_pixmap_colormap ***/
2573 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2575 /*** GLX_MESA_release_buffers ***/
2576 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2578 /*** GLX_MESA_swap_control ***/
2579 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2580 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2583 /*** GLX_ARB_get_proc_address ***/
2584 GLX_FUNCTION(glXGetProcAddressARB
),
2587 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2589 #ifndef GLX_USE_APPLEGL
2590 /*** GLX_OML_sync_control ***/
2591 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2592 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2593 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2594 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2595 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2597 /*** GLX_EXT_texture_from_pixmap ***/
2598 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2599 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2602 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2603 /*** DRI configuration ***/
2604 GLX_FUNCTION(glXGetScreenDriver
),
2605 GLX_FUNCTION(glXGetDriverConfig
),
2608 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2609 GLX_FUNCTION(glXCreateContextAttribsARB
),
2611 /*** GLX_MESA_query_renderer ***/
2612 GLX_FUNCTION(glXQueryRendererIntegerMESA
),
2613 GLX_FUNCTION(glXQueryRendererStringMESA
),
2614 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA
),
2615 GLX_FUNCTION(glXQueryCurrentRendererStringMESA
),
2617 {NULL
, NULL
} /* end of list */
2620 static const GLvoid
*
2621 get_glx_proc_address(const char *funcName
)
2625 /* try static functions */
2626 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2627 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2628 return GLX_functions
[i
].Address
;
2635 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2636 * \c glXGetProcAddress.
2638 * \param procName Name of a GL or GLX function.
2639 * \returns A pointer to the named function
2641 * \sa glXGetProcAddress
2643 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2645 typedef void (*gl_function
) (void);
2649 /* Search the table of GLX and internal functions first. If that
2650 * fails and the supplied name could be a valid core GL name, try
2651 * searching the core GL function table. This check is done to prevent
2652 * DRI based drivers from searching the core GL function table for
2653 * internal API functions.
2655 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2656 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2657 && (procName
[2] != 'X')) {
2658 #ifdef GLX_SHARED_GLAPI
2659 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2662 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2664 struct glx_context
*gc
= __glXGetCurrentContext();
2666 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2667 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2674 * Get the address of a named GL function. This is the GLX 1.4 name for
2675 * \c glXGetProcAddressARB.
2677 * \param procName Name of a GL or GLX function.
2678 * \returns A pointer to the named function
2680 * \sa glXGetProcAddressARB
2682 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2683 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2684 __attribute__ ((alias("glXGetProcAddressARB")));
2687 return glXGetProcAddressARB(procName
);
2689 #endif /* __GNUC__ */
2692 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2694 * Get the unadjusted system time (UST). Currently, the UST is measured in
2695 * microseconds since Epoc. The actual resolution of the UST may vary from
2696 * system to system, and the units may vary from release to release.
2697 * Drivers should not call this function directly. They should instead use
2698 * \c glXGetProcAddress to obtain a pointer to the function.
2700 * \param ust Location to store the 64-bit UST
2701 * \returns Zero on success or a negative errno value on failure.
2703 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2705 * \since Internal API version 20030317.
2708 __glXGetUST(int64_t * ust
)
2716 if (gettimeofday(&tv
, NULL
) == 0) {
2717 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2724 #endif /* GLX_DIRECT_RENDERING */