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/apple_glx_context.h"
45 #include "apple/apple_glx.h"
46 #include "util/debug.h"
49 #include <X11/extensions/xf86vmode.h>
53 #include <X11/Xlib-xcb.h>
56 #include "GL/mesa_glinterop.h"
58 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
59 static const char __glXGLXClientVersion
[] = "1.4";
61 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
64 * Get the __DRIdrawable for the drawable associated with a GLXContext
66 * \param dpy The display associated with \c drawable.
67 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
68 * \param scrn_num If non-NULL, the drawables screen is stored there
69 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
70 * the drawable is not associated with a direct-rendering context.
72 _X_HIDDEN __GLXDRIdrawable
*
73 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
75 struct glx_display
*priv
= __glXInitialize(dpy
);
76 __GLXDRIdrawable
*pdraw
;
81 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
89 _X_HIDDEN
struct glx_drawable
*
90 GetGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
92 struct glx_display
*priv
= __glXInitialize(dpy
);
93 struct glx_drawable
*glxDraw
;
98 if (__glxHashLookup(priv
->glXDrawHash
, drawable
, (void *) &glxDraw
) == 0)
105 InitGLXDrawable(Display
*dpy
, struct glx_drawable
*glxDraw
, XID xDrawable
,
106 GLXDrawable drawable
)
108 struct glx_display
*priv
= __glXInitialize(dpy
);
113 glxDraw
->xDrawable
= xDrawable
;
114 glxDraw
->drawable
= drawable
;
115 glxDraw
->lastEventSbc
= 0;
116 glxDraw
->eventSbcWrap
= 0;
118 return __glxHashInsert(priv
->glXDrawHash
, drawable
, glxDraw
);
122 DestroyGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
124 struct glx_display
*priv
= __glXInitialize(dpy
);
125 struct glx_drawable
*glxDraw
;
130 glxDraw
= GetGLXDrawable(dpy
, drawable
);
131 __glxHashDelete(priv
->glXDrawHash
, drawable
);
136 * Get the GLX per-screen data structure associated with a GLX context.
138 * \param dpy Display for which the GLX per-screen information is to be
140 * \param scrn Screen on \c dpy for which the GLX per-screen information is
142 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
143 * specify a valid GLX screen, or NULL otherwise.
145 * \todo Should this function validate that \c scrn is within the screen
146 * number range for \c dpy?
149 _X_HIDDEN
struct glx_screen
*
150 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
152 struct glx_display
*const priv
= __glXInitialize(dpy
);
156 NULL
) ? priv
->screens
[scrn
] : NULL
;
161 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
162 struct glx_screen
** ppsc
)
164 /* Initialize the extension, if needed . This has the added value
165 * of initializing/allocating the display private
169 return GLX_NO_EXTENSION
;
172 *ppriv
= __glXInitialize(dpy
);
173 if (*ppriv
== NULL
) {
174 return GLX_NO_EXTENSION
;
177 /* Check screen number to see if its valid */
178 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
179 return GLX_BAD_SCREEN
;
182 /* Check to see if the GL is supported on this screen */
183 *ppsc
= (*ppriv
)->screens
[scrn
];
184 if ((*ppsc
)->configs
== NULL
&& (*ppsc
)->visuals
== NULL
) {
185 /* No support for GL on this screen regardless of visual */
186 return GLX_BAD_VISUAL
;
194 * Determine if a \c GLXFBConfig supplied by the application is valid.
196 * \param dpy Application supplied \c Display pointer.
197 * \param config Application supplied \c GLXFBConfig.
199 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
200 * \c struct glx_config structure is returned. Otherwise, \c NULL
203 static struct glx_config
*
204 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
206 struct glx_display
*const priv
= __glXInitialize(dpy
);
207 int num_screens
= ScreenCount(dpy
);
209 struct glx_config
*config
;
212 for (i
= 0; i
< num_screens
; i
++) {
213 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
214 config
= config
->next
) {
215 if (config
== (struct glx_config
*) fbconfig
) {
226 * Verifies context's GLX_RENDER_TYPE value with config.
228 * \param config GLX FBConfig which will support the returned renderType.
229 * \param renderType The context render type to be verified.
230 * \return True if the value of context renderType was approved, or 0 if no
231 * valid value was found.
234 validate_renderType_against_config(const struct glx_config
*config
,
237 /* GLX_EXT_no_config_context supports any render type */
241 switch (renderType
) {
243 return (config
->renderType
& GLX_RGBA_BIT
) != 0;
244 case GLX_COLOR_INDEX_TYPE
:
245 return (config
->renderType
& GLX_COLOR_INDEX_BIT
) != 0;
246 case GLX_RGBA_FLOAT_TYPE_ARB
:
247 return (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) != 0;
248 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
:
249 return (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) != 0;
257 glx_context_init(struct glx_context
*gc
,
258 struct glx_screen
*psc
, struct glx_config
*config
)
260 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
261 if (!gc
->majorOpcode
)
264 gc
->screen
= psc
->scr
;
267 gc
->isDirect
= GL_TRUE
;
268 gc
->currentContextTag
= -1;
274 * Determine if a context uses direct rendering.
276 * \param dpy Display where the context was created.
277 * \param contextID ID of the context to be tested.
278 * \param error Out parameter, set to True on error if not NULL
280 * \returns \c True if the context is direct rendering or not.
283 __glXIsDirect(Display
* dpy
, GLXContextID contextID
, Bool
*error
)
287 xcb_generic_error_t
*err
;
288 xcb_glx_is_direct_reply_t
*reply
;
291 opcode
= __glXSetupForCommand(dpy
);
296 c
= XGetXCBConnection(dpy
);
297 reply
= xcb_glx_is_direct_reply(c
, xcb_glx_is_direct(c
, contextID
), &err
);
298 is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
303 __glXSendErrorForXcb(dpy
, err
);
313 * Create a new context.
315 * \param renderType For FBConfigs, what is the rendering type?
319 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
320 GLXContext shareList_user
, Bool allowDirect
,
321 unsigned code
, int renderType
, int screen
)
323 struct glx_context
*gc
;
324 struct glx_screen
*psc
;
325 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
329 psc
= GetGLXScreenConfigs(dpy
, screen
);
333 if (generic_id
== None
)
337 #ifdef GLX_USE_APPLEGL
338 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
340 if (allowDirect
&& psc
->vtable
->create_context
)
341 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
343 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
350 case X_GLXCreateContext
: {
351 xGLXCreateContextReq
*req
;
353 /* Send the glXCreateContext request */
354 GetReq(GLXCreateContext
, req
);
355 req
->reqType
= gc
->majorOpcode
;
356 req
->glxCode
= X_GLXCreateContext
;
357 req
->context
= gc
->xid
= XAllocID(dpy
);
358 req
->visual
= generic_id
;
359 req
->screen
= screen
;
360 req
->shareList
= shareList
? shareList
->xid
: None
;
361 req
->isDirect
= gc
->isDirect
;
365 case X_GLXCreateNewContext
: {
366 xGLXCreateNewContextReq
*req
;
368 /* Send the glXCreateNewContext request */
369 GetReq(GLXCreateNewContext
, req
);
370 req
->reqType
= gc
->majorOpcode
;
371 req
->glxCode
= X_GLXCreateNewContext
;
372 req
->context
= gc
->xid
= XAllocID(dpy
);
373 req
->fbconfig
= generic_id
;
374 req
->screen
= screen
;
375 req
->renderType
= renderType
;
376 req
->shareList
= shareList
? shareList
->xid
: None
;
377 req
->isDirect
= gc
->isDirect
;
381 case X_GLXvop_CreateContextWithConfigSGIX
: {
382 xGLXVendorPrivateWithReplyReq
*vpreq
;
383 xGLXCreateContextWithConfigSGIXReq
*req
;
385 /* Send the glXCreateNewContext request */
386 GetReqExtra(GLXVendorPrivateWithReply
,
387 sz_xGLXCreateContextWithConfigSGIXReq
-
388 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
389 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
390 req
->reqType
= gc
->majorOpcode
;
391 req
->glxCode
= X_GLXVendorPrivateWithReply
;
392 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
393 req
->context
= gc
->xid
= XAllocID(dpy
);
394 req
->fbconfig
= generic_id
;
395 req
->screen
= screen
;
396 req
->renderType
= renderType
;
397 req
->shareList
= shareList
? shareList
->xid
: None
;
398 req
->isDirect
= gc
->isDirect
;
403 /* What to do here? This case is the sign of an internal error. It
404 * should never be reachable.
412 gc
->share_xid
= shareList
? shareList
->xid
: None
;
413 gc
->imported
= GL_FALSE
;
415 /* Unlike most X resource creation requests, we're about to return a handle
416 * with client-side state, not just an XID. To simplify error handling
417 * elsewhere in libGL, force a round-trip here to ensure the CreateContext
418 * request above succeeded.
422 int isDirect
= __glXIsDirect(dpy
, gc
->xid
, &error
);
424 if (error
!= False
|| isDirect
!= gc
->isDirect
) {
425 gc
->vtable
->destroy(gc
);
430 return (GLXContext
) gc
;
433 _GLX_PUBLIC GLXContext
434 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
435 GLXContext shareList
, Bool allowDirect
)
437 struct glx_config
*config
= NULL
;
438 int renderType
= GLX_RGBA_TYPE
;
440 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
441 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
444 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
446 if (config
== NULL
) {
447 __glXSendError(dpy
, BadValue
, vis
->visualid
, X_GLXCreateContext
, True
);
451 /* Choose the context render type based on DRI config values. It is
452 * unusual to set this type from config, but we have no other choice, as
453 * this old API does not provide renderType parameter.
455 if (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) {
456 renderType
= GLX_RGBA_FLOAT_TYPE_ARB
;
457 } else if (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) {
458 renderType
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
459 } else if (config
->renderType
& GLX_RGBA_BIT
) {
460 renderType
= GLX_RGBA_TYPE
;
461 } else if (config
->renderType
& GLX_COLOR_INDEX_BIT
) {
462 renderType
= GLX_COLOR_INDEX_TYPE
;
463 } else if (config
->rgbMode
) {
464 /* If we're here, then renderType is not set correctly. Let's use a
465 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
466 * default value is needed by old DRI drivers, which didn't set
467 * renderType correctly as the value was just ignored.
469 renderType
= GLX_RGBA_TYPE
;
471 /* Safeguard - only one option left, all non-RGB modes are indexed
472 * modes. Again, this allows drivers with invalid renderType to work
475 renderType
= GLX_COLOR_INDEX_TYPE
;
479 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
480 X_GLXCreateContext
, renderType
, vis
->screen
);
484 glx_send_destroy_context(Display
*dpy
, XID xid
)
486 CARD8 opcode
= __glXSetupForCommand(dpy
);
487 xGLXDestroyContextReq
*req
;
490 GetReq(GLXDestroyContext
, req
);
491 req
->reqType
= opcode
;
492 req
->glxCode
= X_GLXDestroyContext
;
499 ** Destroy the named context
503 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
505 struct glx_context
*gc
= (struct glx_context
*) ctx
;
507 if (gc
== NULL
|| gc
->xid
== None
)
512 glx_send_destroy_context(dpy
, gc
->xid
);
514 if (gc
->currentDpy
) {
515 /* This context is bound to some thread. According to the man page,
516 * we should not actually delete the context until it's unbound.
517 * Note that we set gc->xid = None above. In MakeContextCurrent()
518 * we check for that and delete the context there.
522 gc
->vtable
->destroy(gc
);
528 ** Return the major and minor version #s for the GLX extension
531 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
533 struct glx_display
*priv
;
535 /* Init the extension. This fetches the major and minor version. */
536 priv
= __glXInitialize(dpy
);
541 *major
= priv
->majorVersion
;
543 *minor
= priv
->minorVersion
;
548 ** Query the existence of the GLX extension
551 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
553 int major_op
, erb
, evb
;
556 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
567 ** Put a barrier in the token stream that forces the GL to finish its
568 ** work before X can proceed.
573 struct glx_context
*gc
= __glXGetCurrentContext();
575 if (gc
->vtable
->wait_gl
)
576 gc
->vtable
->wait_gl(gc
);
580 ** Put a barrier in the token stream that forces X to finish its
581 ** work before GL can proceed.
586 struct glx_context
*gc
= __glXGetCurrentContext();
588 if (gc
->vtable
->wait_x
)
589 gc
->vtable
->wait_x(gc
);
593 glXUseXFont(Font font
, int first
, int count
, int listBase
)
595 struct glx_context
*gc
= __glXGetCurrentContext();
597 if (gc
->vtable
->use_x_font
)
598 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
601 /************************************************************************/
604 ** Copy the source context to the destination context using the
608 glXCopyContext(Display
* dpy
, GLXContext source_user
,
609 GLXContext dest_user
, unsigned long mask
)
611 struct glx_context
*source
= (struct glx_context
*) source_user
;
612 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
613 #ifdef GLX_USE_APPLEGL
614 struct glx_context
*gc
= __glXGetCurrentContext();
618 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
619 mask
, &errorcode
, &x11error
)) {
620 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
624 xGLXCopyContextReq
*req
;
625 struct glx_context
*gc
= __glXGetCurrentContext();
629 opcode
= __glXSetupForCommand(dpy
);
634 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
636 /* NOT_DONE: This does not work yet */
641 ** If the source is the current context, send its tag so that the context
642 ** can be flushed before the copy.
644 if (source
== gc
&& dpy
== gc
->currentDpy
) {
645 tag
= gc
->currentContextTag
;
651 /* Send the glXCopyContext request */
653 GetReq(GLXCopyContext
, req
);
654 req
->reqType
= opcode
;
655 req
->glxCode
= X_GLXCopyContext
;
656 req
->source
= source
? source
->xid
: None
;
657 req
->dest
= dest
? dest
->xid
: None
;
659 req
->contextTag
= tag
;
662 #endif /* GLX_USE_APPLEGL */
668 * Shouldn't this function \b always return \c False when
669 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
670 * the GLX protocol here at all?
673 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
675 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
680 else if (gc
->isDirect
) {
683 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
686 return __glXIsDirect(dpy
, gc
->xid
, NULL
);
690 _GLX_PUBLIC GLXPixmap
691 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
693 #ifdef GLX_USE_APPLEGL
694 int screen
= vis
->screen
;
695 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
696 const struct glx_config
*config
;
698 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
700 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
705 xGLXCreateGLXPixmapReq
*req
;
706 struct glx_drawable
*glxDraw
;
710 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
711 struct glx_display
*const priv
= __glXInitialize(dpy
);
717 opcode
= __glXSetupForCommand(dpy
);
722 glxDraw
= malloc(sizeof(*glxDraw
));
726 /* Send the glXCreateGLXPixmap request */
728 GetReq(GLXCreateGLXPixmap
, req
);
729 req
->reqType
= opcode
;
730 req
->glxCode
= X_GLXCreateGLXPixmap
;
731 req
->screen
= vis
->screen
;
732 req
->visual
= vis
->visualid
;
733 req
->pixmap
= pixmap
;
734 req
->glxpixmap
= xid
= XAllocID(dpy
);
738 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
743 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
745 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
746 * is actually bound to a context... */
748 __GLXDRIdrawable
*pdraw
;
749 struct glx_screen
*psc
;
750 struct glx_config
*config
;
752 psc
= priv
->screens
[vis
->screen
];
753 if (psc
->driScreen
== NULL
)
756 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
757 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
759 fprintf(stderr
, "failed to create pixmap\n");
764 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
765 (*pdraw
->destroyDrawable
) (pdraw
);
772 xGLXDestroyGLXPixmapReq
*dreq
;
774 GetReq(GLXDestroyGLXPixmap
, dreq
);
775 dreq
->reqType
= opcode
;
776 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
777 dreq
->glxpixmap
= xid
;
788 ** Destroy the named pixmap
791 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
793 #ifdef GLX_USE_APPLEGL
794 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
795 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
797 xGLXDestroyGLXPixmapReq
*req
;
800 opcode
= __glXSetupForCommand(dpy
);
805 /* Send the glXDestroyGLXPixmap request */
807 GetReq(GLXDestroyGLXPixmap
, req
);
808 req
->reqType
= opcode
;
809 req
->glxCode
= X_GLXDestroyGLXPixmap
;
810 req
->glxpixmap
= glxpixmap
;
814 DestroyGLXDrawable(dpy
, glxpixmap
);
816 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
818 struct glx_display
*const priv
= __glXInitialize(dpy
);
819 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
821 if (priv
!= NULL
&& pdraw
!= NULL
) {
822 (*pdraw
->destroyDrawable
) (pdraw
);
823 __glxHashDelete(priv
->drawHash
, glxpixmap
);
827 #endif /* GLX_USE_APPLEGL */
831 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
833 #ifdef GLX_USE_APPLEGL
834 struct glx_context
* gc
= __glXGetCurrentContext();
835 if(gc
!= &dummyContext
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
836 apple_glx_swap_buffers(gc
->driContext
);
838 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
841 struct glx_context
*gc
;
846 gc
= __glXGetCurrentContext();
848 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
850 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
853 Bool flush
= gc
!= &dummyContext
&& drawable
== gc
->currentDrawable
;
855 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0, flush
);
861 opcode
= __glXSetupForCommand(dpy
);
867 ** The calling thread may or may not have a current context. If it
868 ** does, send the context tag so the server can do a flush.
870 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
871 ((drawable
== gc
->currentDrawable
)
872 || (drawable
== gc
->currentReadable
))) {
873 tag
= gc
->currentContextTag
;
879 c
= XGetXCBConnection(dpy
);
880 xcb_glx_swap_buffers(c
, tag
, drawable
);
882 #endif /* GLX_USE_APPLEGL */
887 ** Return configuration information for the given display, screen and
888 ** visual combination.
891 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
894 struct glx_display
*priv
;
895 struct glx_screen
*psc
;
896 struct glx_config
*config
;
899 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
900 if (status
== Success
) {
901 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
903 /* Lookup attribute after first finding a match on the visual */
904 if (config
!= NULL
) {
905 return glx_config_get(config
, attribute
, value_return
);
908 status
= GLX_BAD_VISUAL
;
912 ** If we can't find the config for this visual, this visual is not
913 ** supported by the OpenGL implementation on the server.
915 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
916 *value_return
= False
;
923 /************************************************************************/
926 init_fbconfig_for_chooser(struct glx_config
* config
,
927 GLboolean fbconfig_style_tags
)
929 memset(config
, 0, sizeof(struct glx_config
));
930 config
->visualID
= (XID
) GLX_DONT_CARE
;
931 config
->visualType
= GLX_DONT_CARE
;
933 /* glXChooseFBConfig specifies different defaults for these properties than
936 if (fbconfig_style_tags
) {
937 config
->rgbMode
= GL_TRUE
;
938 config
->doubleBufferMode
= GLX_DONT_CARE
;
939 config
->renderType
= GLX_RGBA_BIT
;
942 config
->drawableType
= GLX_WINDOW_BIT
;
943 config
->visualRating
= GLX_DONT_CARE
;
944 config
->transparentPixel
= GLX_NONE
;
945 config
->transparentRed
= GLX_DONT_CARE
;
946 config
->transparentGreen
= GLX_DONT_CARE
;
947 config
->transparentBlue
= GLX_DONT_CARE
;
948 config
->transparentAlpha
= GLX_DONT_CARE
;
949 config
->transparentIndex
= GLX_DONT_CARE
;
951 config
->xRenderable
= GLX_DONT_CARE
;
952 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
954 config
->swapMethod
= GLX_DONT_CARE
;
955 config
->sRGBCapable
= GLX_DONT_CARE
;
958 #define MATCH_DONT_CARE( param ) \
960 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
961 && (a-> param != b-> param) ) { \
966 #define MATCH_MINIMUM( param ) \
968 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
969 && (a-> param > b-> param) ) { \
974 #define MATCH_EXACT( param ) \
976 if ( a-> param != b-> param) { \
981 /* Test that all bits from a are contained in b */
982 #define MATCH_MASK(param) \
984 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
985 && ((a->param & ~b->param) != 0) ) { \
991 * Determine if two GLXFBConfigs are compatible.
993 * \param a Application specified config to test.
994 * \param b Server specified config to test against \c a.
997 fbconfigs_compatible(const struct glx_config
* const a
,
998 const struct glx_config
* const b
)
1000 MATCH_DONT_CARE(doubleBufferMode
);
1001 MATCH_DONT_CARE(visualType
);
1002 MATCH_DONT_CARE(visualRating
);
1003 MATCH_DONT_CARE(xRenderable
);
1004 MATCH_DONT_CARE(fbconfigID
);
1005 MATCH_DONT_CARE(swapMethod
);
1007 MATCH_MINIMUM(rgbBits
);
1008 MATCH_MINIMUM(numAuxBuffers
);
1009 MATCH_MINIMUM(redBits
);
1010 MATCH_MINIMUM(greenBits
);
1011 MATCH_MINIMUM(blueBits
);
1012 MATCH_MINIMUM(alphaBits
);
1013 MATCH_MINIMUM(depthBits
);
1014 MATCH_MINIMUM(stencilBits
);
1015 MATCH_MINIMUM(accumRedBits
);
1016 MATCH_MINIMUM(accumGreenBits
);
1017 MATCH_MINIMUM(accumBlueBits
);
1018 MATCH_MINIMUM(accumAlphaBits
);
1019 MATCH_MINIMUM(sampleBuffers
);
1020 MATCH_MINIMUM(maxPbufferWidth
);
1021 MATCH_MINIMUM(maxPbufferHeight
);
1022 MATCH_MINIMUM(maxPbufferPixels
);
1023 MATCH_MINIMUM(samples
);
1025 MATCH_DONT_CARE(stereoMode
);
1028 MATCH_MASK(drawableType
);
1029 MATCH_MASK(renderType
);
1030 MATCH_DONT_CARE(sRGBCapable
);
1032 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1033 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1034 * Technically speaking, it is a bug in the DDX driver, but there is
1035 * enough of an installed base to work around the problem here. In any
1036 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1037 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1038 * 0 from the server to be a match to maintain backward compatibility with
1039 * the (broken) drivers.
1042 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1043 if (a
->transparentPixel
== GLX_NONE
) {
1044 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1048 MATCH_EXACT(transparentPixel
);
1051 switch (a
->transparentPixel
) {
1052 case GLX_TRANSPARENT_RGB
:
1053 MATCH_DONT_CARE(transparentRed
);
1054 MATCH_DONT_CARE(transparentGreen
);
1055 MATCH_DONT_CARE(transparentBlue
);
1056 MATCH_DONT_CARE(transparentAlpha
);
1059 case GLX_TRANSPARENT_INDEX
:
1060 MATCH_DONT_CARE(transparentIndex
);
1072 /* There's some trickly language in the GLX spec about how this is supposed
1073 * to work. Basically, if a given component size is either not specified
1074 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1075 * Well, that's really hard to do with the code as-is. This behavior is
1076 * closer to correct, but still not technically right.
1078 #define PREFER_LARGER_OR_ZERO(comp) \
1080 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1081 if ( ((*a)-> comp) == 0 ) { \
1084 else if ( ((*b)-> comp) == 0 ) { \
1088 return ((*b)-> comp) - ((*a)-> comp) ; \
1093 #define PREFER_LARGER(comp) \
1095 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1096 return ((*b)-> comp) - ((*a)-> comp) ; \
1100 #define PREFER_SMALLER(comp) \
1102 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1103 return ((*a)-> comp) - ((*b)-> comp) ; \
1108 * Compare two GLXFBConfigs. This function is intended to be used as the
1109 * compare function passed in to qsort.
1111 * \returns If \c a is a "better" config, according to the specification of
1112 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1113 * better, then a number greater than zero is return. If both are
1114 * equal, zero is returned.
1115 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1118 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1120 /* The order of these comparisons must NOT change. It is defined by
1121 * the GLX 1.4 specification.
1124 PREFER_SMALLER(visualSelectGroup
);
1126 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1127 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1128 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1130 PREFER_SMALLER(visualRating
);
1132 /* This isn't quite right. It is supposed to compare the sum of the
1133 * components the user specifically set minimums for.
1135 PREFER_LARGER_OR_ZERO(redBits
);
1136 PREFER_LARGER_OR_ZERO(greenBits
);
1137 PREFER_LARGER_OR_ZERO(blueBits
);
1138 PREFER_LARGER_OR_ZERO(alphaBits
);
1140 PREFER_SMALLER(rgbBits
);
1142 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1143 /* Prefer single-buffer.
1145 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1148 PREFER_SMALLER(numAuxBuffers
);
1150 PREFER_SMALLER(sampleBuffers
);
1151 PREFER_SMALLER(samples
);
1153 PREFER_LARGER_OR_ZERO(depthBits
);
1154 PREFER_SMALLER(stencilBits
);
1156 /* This isn't quite right. It is supposed to compare the sum of the
1157 * components the user specifically set minimums for.
1159 PREFER_LARGER_OR_ZERO(accumRedBits
);
1160 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1161 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1162 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1164 PREFER_SMALLER(visualType
);
1166 /* None of the pbuffer or fbconfig specs say that this comparison needs
1167 * to happen at all, but it seems like it should.
1169 PREFER_LARGER(maxPbufferWidth
);
1170 PREFER_LARGER(maxPbufferHeight
);
1171 PREFER_LARGER(maxPbufferPixels
);
1178 * Selects and sorts a subset of the supplied configs based on the attributes.
1179 * This function forms to basis of \c glXChooseFBConfig and
1180 * \c glXChooseFBConfigSGIX.
1182 * \param configs Array of pointers to possible configs. The elements of
1183 * this array that do not meet the criteria will be set to
1184 * NULL. The remaining elements will be sorted according to
1185 * the various visual / FBConfig selection rules.
1186 * \param num_configs Number of elements in the \c configs array.
1187 * \param attribList Attributes used select from \c configs. This array is
1188 * terminated by a \c None tag. The array is of the form
1189 * expected by \c glXChooseFBConfig (where every tag has a
1191 * \returns The number of valid elements left in \c configs.
1193 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
1196 choose_fbconfig(struct glx_config
** configs
, int num_configs
,
1197 const int *attribList
)
1199 struct glx_config test_config
;
1203 /* This is a fairly direct implementation of the selection method
1204 * described by GLX_SGIX_fbconfig. Start by culling out all the
1205 * configs that are not compatible with the selected parameter
1209 init_fbconfig_for_chooser(&test_config
, GL_TRUE
);
1210 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1211 (const INT32
*) attribList
,
1215 for (i
= 0; i
< num_configs
; i
++) {
1216 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1217 configs
[base
] = configs
[i
];
1226 if (base
< num_configs
) {
1227 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1230 /* After the incompatible configs are removed, the resulting
1231 * list is sorted according to the rules set out in the various
1235 qsort(configs
, base
, sizeof(struct glx_config
*),
1236 (int (*)(const void *, const void *)) fbconfig_compare
);
1244 ** Return the visual that best matches the template. Return None if no
1245 ** visual matches the template.
1247 _GLX_PUBLIC XVisualInfo
*
1248 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1250 XVisualInfo
*visualList
= NULL
;
1251 struct glx_display
*priv
;
1252 struct glx_screen
*psc
;
1253 struct glx_config test_config
;
1254 struct glx_config
*config
;
1255 struct glx_config
*best_config
= NULL
;
1258 ** Get a list of all visuals, return if list is empty
1260 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1266 ** Build a template from the defaults and the attribute list
1267 ** Free visual list and return if an unexpected token is encountered
1269 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1270 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1271 (const INT32
*) attribList
,
1275 ** Eliminate visuals that don't meet minimum requirements
1276 ** Compute a score for those that do
1277 ** Remember which visual, if any, got the highest score
1278 ** If no visual is acceptable, return None
1279 ** Otherwise, create an XVisualInfo list with just the selected X visual
1282 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1283 if (fbconfigs_compatible(&test_config
, config
)
1284 && ((best_config
== NULL
) ||
1285 (fbconfig_compare (&config
, &best_config
) < 0))) {
1286 XVisualInfo visualTemplate
;
1287 XVisualInfo
*newList
;
1290 visualTemplate
.screen
= screen
;
1291 visualTemplate
.visualid
= config
->visualID
;
1292 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1293 &visualTemplate
, &i
);
1297 visualList
= newList
;
1298 best_config
= config
;
1303 #ifdef GLX_USE_APPLEGL
1304 if(visualList
&& env_var_as_boolean("LIBGL_DUMP_VISUALID", false)) {
1305 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1313 _GLX_PUBLIC
const char *
1314 glXQueryExtensionsString(Display
* dpy
, int screen
)
1316 struct glx_screen
*psc
;
1317 struct glx_display
*priv
;
1319 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1323 if (!psc
->effectiveGLXexts
) {
1324 if (!psc
->serverGLXexts
) {
1325 psc
->serverGLXexts
=
1326 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1330 __glXCalculateUsableExtensions(psc
,
1331 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1332 (psc
->driScreen
!= NULL
),
1336 priv
->minorVersion
);
1339 return psc
->effectiveGLXexts
;
1342 _GLX_PUBLIC
const char *
1343 glXGetClientString(Display
* dpy
, int name
)
1349 return (__glXGLXClientVendorName
);
1351 return (__glXGLXClientVersion
);
1352 case GLX_EXTENSIONS
:
1353 return (__glXGetClientExtensions());
1359 _GLX_PUBLIC
const char *
1360 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1362 struct glx_screen
*psc
;
1363 struct glx_display
*priv
;
1367 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1373 str
= &priv
->serverGLXvendor
;
1376 str
= &priv
->serverGLXversion
;
1378 case GLX_EXTENSIONS
:
1379 str
= &psc
->serverGLXexts
;
1386 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1394 ** EXT_import_context
1397 _GLX_PUBLIC Display
*
1398 glXGetCurrentDisplay(void)
1400 struct glx_context
*gc
= __glXGetCurrentContext();
1401 if (gc
== &dummyContext
)
1403 return gc
->currentDpy
;
1407 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1408 glXGetCurrentDisplay
)
1410 #ifndef GLX_USE_APPLEGL
1411 _GLX_PUBLIC GLXContext
1412 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1414 struct glx_display
*priv
= __glXInitialize(dpy
);
1415 struct glx_screen
*psc
= NULL
;
1416 xGLXQueryContextReply reply
;
1418 struct glx_context
*ctx
;
1419 int i
, renderType
= GLX_RGBA_TYPE
; /* By default, assume RGBA context */
1421 struct glx_config
*mode
= NULL
;
1422 uint32_t fbconfigID
= 0;
1423 uint32_t visualID
= 0;
1424 uint32_t screen
= 0;
1425 Bool got_screen
= False
;
1430 /* The GLX_EXT_import_context spec says:
1432 * "If <contextID> does not refer to a valid context, then a BadContext
1433 * error is generated; if <contextID> refers to direct rendering
1434 * context then no error is generated but glXImportContextEXT returns
1437 * If contextID is None, generate BadContext on the client-side. Other
1438 * sorts of invalid contexts will be detected by the server in the
1439 * __glXIsDirect call.
1441 if (contextID
== None
) {
1442 __glXSendError(dpy
, GLXBadContext
, contextID
, X_GLXIsDirect
, false);
1446 if (__glXIsDirect(dpy
, contextID
, NULL
))
1449 opcode
= __glXSetupForCommand(dpy
);
1453 /* Send the glXQueryContextInfoEXT request */
1456 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1457 xGLXQueryContextReq
*req
;
1459 GetReq(GLXQueryContext
, req
);
1461 req
->reqType
= opcode
;
1462 req
->glxCode
= X_GLXQueryContext
;
1463 req
->context
= contextID
;
1466 xGLXVendorPrivateReq
*vpreq
;
1467 xGLXQueryContextInfoEXTReq
*req
;
1469 GetReqExtra(GLXVendorPrivate
,
1470 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1472 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1473 req
->reqType
= opcode
;
1474 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1475 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1476 req
->context
= contextID
;
1479 if (_XReply(dpy
, (xReply
*) & reply
, 0, False
) &&
1480 reply
.n
< (INT32_MAX
/ 2)) {
1482 for (i
= 0; i
< reply
.n
; i
++) {
1485 _XRead(dpy
, (char *)prop
, sizeof(prop
));
1491 case GLX_SHARE_CONTEXT_EXT
:
1494 case GLX_VISUAL_ID_EXT
:
1497 case GLX_FBCONFIG_ID
:
1498 fbconfigID
= prop
[1];
1500 case GLX_RENDER_TYPE
:
1501 renderType
= prop
[1];
1512 psc
= GetGLXScreenConfigs(dpy
, screen
);
1516 if (fbconfigID
!= 0) {
1517 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1518 } else if (visualID
!= 0) {
1519 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1525 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1529 ctx
->xid
= contextID
;
1530 ctx
->imported
= GL_TRUE
;
1531 ctx
->share_xid
= share
;
1533 return (GLXContext
) ctx
;
1539 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1541 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1543 switch (attribute
) {
1544 case GLX_SHARE_CONTEXT_EXT
:
1545 *value
= ctx
->share_xid
;
1547 case GLX_VISUAL_ID_EXT
:
1548 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1551 *value
= ctx
->screen
;
1553 case GLX_FBCONFIG_ID
:
1554 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1556 case GLX_RENDER_TYPE
:
1557 *value
= ctx
->renderType
;
1560 return GLX_BAD_ATTRIBUTE
;
1566 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1567 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1568 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1570 _GLX_PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1572 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1574 return (ctx
== NULL
) ? None
: ctx
->xid
;
1578 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1580 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1582 if (gc
== NULL
|| gc
->xid
== None
)
1585 /* The GLX_EXT_import_context spec says:
1587 * "glXFreeContext does not free the server-side context information or
1588 * the XID associated with the server-side context."
1590 * Don't send any protocol. Just destroy the client-side tracking of the
1591 * context. Also, only release the context structure if it's not current.
1594 if (gc
->currentDpy
) {
1597 gc
->vtable
->destroy(gc
);
1602 _GLX_PUBLIC GLXFBConfig
*
1603 glXChooseFBConfig(Display
* dpy
, int screen
,
1604 const int *attribList
, int *nitems
)
1606 struct glx_config
**config_list
;
1610 config_list
= (struct glx_config
**)
1611 glXGetFBConfigs(dpy
, screen
, &list_size
);
1613 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1614 list_size
= choose_fbconfig(config_list
, list_size
, attribList
);
1615 if (list_size
== 0) {
1621 *nitems
= list_size
;
1622 return (GLXFBConfig
*) config_list
;
1626 _GLX_PUBLIC GLXContext
1627 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1628 int renderType
, GLXContext shareList
, Bool allowDirect
)
1630 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1631 struct glx_config
**config_list
;
1636 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1640 config_list
= (struct glx_config
**)
1641 glXGetFBConfigs(dpy
, config
->screen
, &list_size
);
1643 for (i
= 0; i
< list_size
; i
++) {
1644 if (config_list
[i
] == config
)
1649 if (i
== list_size
) {
1650 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1654 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1655 allowDirect
, X_GLXCreateNewContext
, renderType
,
1660 _GLX_PUBLIC GLXDrawable
1661 glXGetCurrentReadDrawable(void)
1663 struct glx_context
*gc
= __glXGetCurrentContext();
1665 return gc
->currentReadable
;
1669 _GLX_PUBLIC GLXFBConfig
*
1670 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1672 struct glx_display
*priv
= __glXInitialize(dpy
);
1673 struct glx_config
**config_list
= NULL
;
1674 struct glx_config
*config
;
1675 unsigned num_configs
= 0;
1679 if (priv
&& (priv
->screens
!= NULL
)
1680 && (screen
>= 0) && (screen
< ScreenCount(dpy
))
1681 && (priv
->screens
[screen
]->configs
!= NULL
)
1682 && (priv
->screens
[screen
]->configs
->fbconfigID
1683 != (int) GLX_DONT_CARE
)) {
1685 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1686 config
= config
->next
) {
1687 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1692 config_list
= malloc(num_configs
* sizeof *config_list
);
1693 if (config_list
!= NULL
) {
1694 *nelements
= num_configs
;
1696 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1697 config
= config
->next
) {
1698 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1699 config_list
[i
] = config
;
1706 return (GLXFBConfig
*) config_list
;
1711 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1712 int attribute
, int *value
)
1714 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1717 return GLXBadFBConfig
;
1719 return glx_config_get(config
, attribute
, value
);
1723 _GLX_PUBLIC XVisualInfo
*
1724 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1726 XVisualInfo visualTemplate
;
1727 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1731 ** Get a list of all visuals, return if list is empty
1733 visualTemplate
.visualid
= config
->visualID
;
1734 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1737 #ifndef GLX_USE_APPLEGL
1739 ** GLX_SGI_swap_control
1742 __glXSwapIntervalSGI(int interval
)
1744 xGLXVendorPrivateReq
*req
;
1745 struct glx_context
*gc
= __glXGetCurrentContext();
1746 struct glx_screen
*psc
;
1748 CARD32
*interval_ptr
;
1751 if (gc
== &dummyContext
) {
1752 return GLX_BAD_CONTEXT
;
1755 if (interval
<= 0) {
1756 return GLX_BAD_VALUE
;
1759 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1761 #ifdef GLX_DIRECT_RENDERING
1762 if (gc
->isDirect
&& psc
&& psc
->driScreen
&&
1763 psc
->driScreen
->setSwapInterval
) {
1764 __GLXDRIdrawable
*pdraw
=
1765 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1766 /* Simply ignore the command if the GLX drawable has been destroyed but
1767 * the context is still bound.
1770 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1775 dpy
= gc
->currentDpy
;
1776 opcode
= __glXSetupForCommand(dpy
);
1781 /* Send the glXSwapIntervalSGI request */
1783 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1784 req
->reqType
= opcode
;
1785 req
->glxCode
= X_GLXVendorPrivate
;
1786 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1787 req
->contextTag
= gc
->currentContextTag
;
1789 interval_ptr
= (CARD32
*) (req
+ 1);
1790 *interval_ptr
= interval
;
1801 ** GLX_MESA_swap_control
1804 __glXSwapIntervalMESA(unsigned int interval
)
1806 #ifdef GLX_DIRECT_RENDERING
1807 struct glx_context
*gc
= __glXGetCurrentContext();
1809 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1810 struct glx_screen
*psc
;
1812 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1813 if (psc
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1814 __GLXDRIdrawable
*pdraw
=
1815 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1817 /* Simply ignore the command if the GLX drawable has been destroyed but
1818 * the context is still bound.
1823 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1828 return GLX_BAD_CONTEXT
;
1833 __glXGetSwapIntervalMESA(void)
1835 #ifdef GLX_DIRECT_RENDERING
1836 struct glx_context
*gc
= __glXGetCurrentContext();
1838 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1839 struct glx_screen
*psc
;
1841 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1842 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1843 __GLXDRIdrawable
*pdraw
=
1844 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1846 return psc
->driScreen
->getSwapInterval(pdraw
);
1856 ** GLX_SGI_video_sync
1859 __glXGetVideoSyncSGI(unsigned int *count
)
1861 int64_t ust
, msc
, sbc
;
1863 struct glx_context
*gc
= __glXGetCurrentContext();
1864 struct glx_screen
*psc
;
1865 #ifdef GLX_DIRECT_RENDERING
1866 __GLXDRIdrawable
*pdraw
;
1869 if (gc
== &dummyContext
)
1870 return GLX_BAD_CONTEXT
;
1872 #ifdef GLX_DIRECT_RENDERING
1874 return GLX_BAD_CONTEXT
;
1877 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1878 #ifdef GLX_DIRECT_RENDERING
1879 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1882 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1883 * FIXME: there should be a GLX encoding for this call. I can find no
1884 * FIXME: documentation for the GLX encoding.
1886 #ifdef GLX_DIRECT_RENDERING
1887 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1888 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1889 *count
= (unsigned) msc
;
1890 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1894 return GLX_BAD_CONTEXT
;
1898 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1900 struct glx_context
*gc
= __glXGetCurrentContext();
1901 struct glx_screen
*psc
;
1902 #ifdef GLX_DIRECT_RENDERING
1903 __GLXDRIdrawable
*pdraw
;
1905 int64_t ust
, msc
, sbc
;
1908 if (divisor
<= 0 || remainder
< 0)
1909 return GLX_BAD_VALUE
;
1911 if (gc
== &dummyContext
)
1912 return GLX_BAD_CONTEXT
;
1914 #ifdef GLX_DIRECT_RENDERING
1916 return GLX_BAD_CONTEXT
;
1919 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1920 #ifdef GLX_DIRECT_RENDERING
1921 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1924 #ifdef GLX_DIRECT_RENDERING
1925 if (psc
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1926 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1928 *count
= (unsigned) msc
;
1929 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1933 return GLX_BAD_CONTEXT
;
1936 #endif /* GLX_USE_APPLEGL */
1939 ** GLX_SGIX_fbconfig
1940 ** Many of these functions are aliased to GLX 1.3 entry points in the
1941 ** GLX_functions table.
1945 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1946 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1947 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1949 _GLX_PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1950 (Display
* dpy
, int screen
, int *attrib_list
,
1951 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1954 _GLX_PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1955 (Display
* dpy
, GLXFBConfigSGIX config
),
1956 (dpy
, config
), glXGetVisualFromFBConfig
)
1958 _GLX_PUBLIC GLXPixmap
1959 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1960 GLXFBConfigSGIX fbconfig
,
1963 #ifndef GLX_USE_APPLEGL
1964 xGLXVendorPrivateWithReplyReq
*vpreq
;
1965 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1966 GLXPixmap xid
= None
;
1968 struct glx_screen
*psc
;
1970 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1973 if ((dpy
== NULL
) || (config
== NULL
)) {
1976 #ifdef GLX_USE_APPLEGL
1977 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1982 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1984 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1985 opcode
= __glXSetupForCommand(dpy
);
1990 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1992 GetReqExtra(GLXVendorPrivateWithReply
,
1993 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1994 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1995 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1996 req
->reqType
= opcode
;
1997 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1998 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1999 req
->screen
= config
->screen
;
2000 req
->fbconfig
= config
->fbconfigID
;
2001 req
->pixmap
= pixmap
;
2002 req
->glxpixmap
= xid
= XAllocID(dpy
);
2011 _GLX_PUBLIC GLXContext
2012 glXCreateContextWithConfigSGIX(Display
* dpy
,
2013 GLXFBConfigSGIX fbconfig
, int renderType
,
2014 GLXContext shareList
, Bool allowDirect
)
2016 GLXContext gc
= NULL
;
2017 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2018 struct glx_screen
*psc
;
2021 if ((dpy
== NULL
) || (config
== NULL
)) {
2025 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2027 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2028 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2030 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2038 _GLX_PUBLIC GLXFBConfigSGIX
2039 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2041 struct glx_display
*priv
;
2042 struct glx_screen
*psc
= NULL
;
2044 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2045 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2046 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2047 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2054 #ifndef GLX_USE_APPLEGL
2056 ** GLX_OML_sync_control
2059 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2060 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2062 struct glx_display
* const priv
= __glXInitialize(dpy
);
2064 #ifdef GLX_DIRECT_RENDERING
2065 __GLXDRIdrawable
*pdraw
;
2067 struct glx_screen
*psc
;
2072 #ifdef GLX_DIRECT_RENDERING
2073 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2074 psc
= pdraw
? pdraw
->psc
: NULL
;
2075 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2076 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2084 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2086 __glxGetMscRate(struct glx_screen
*psc
,
2087 int32_t * numerator
, int32_t * denominator
)
2089 XF86VidModeModeLine mode_line
;
2093 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2094 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2095 unsigned n
= dot_clock
* 1000;
2096 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2098 # define V_INTERLACE 0x010
2099 # define V_DBLSCAN 0x020
2101 if (mode_line
.flags
& V_INTERLACE
)
2103 else if (mode_line
.flags
& V_DBLSCAN
)
2106 /* The OML_sync_control spec requires that if the refresh rate is a
2107 * whole number, that the returned numerator be equal to the refresh
2108 * rate and the denominator be 1.
2116 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2118 /* This is a poor man's way to reduce a fraction. It's far from
2119 * perfect, but it will work well enough for this situation.
2122 for (i
= 0; f
[i
] != 0; i
++) {
2123 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2141 * Determine the refresh rate of the specified drawable and display.
2143 * \param dpy Display whose refresh rate is to be determined.
2144 * \param drawable Drawable whose refresh rate is to be determined.
2145 * \param numerator Numerator of the refresh rate.
2146 * \param demoninator Denominator of the refresh rate.
2147 * \return If the refresh rate for the specified display and drawable could
2148 * be calculated, True is returned. Otherwise False is returned.
2150 * \note This function is implemented entirely client-side. A lot of other
2151 * functionality is required to export GLX_OML_sync_control, so on
2152 * XFree86 this function can be called for direct-rendering contexts
2153 * when GLX_OML_sync_control appears in the client extension string.
2157 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2158 int32_t * numerator
, int32_t * denominator
)
2160 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2161 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2166 return __glxGetMscRate(draw
->psc
, numerator
, denominator
);
2178 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2179 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2181 struct glx_context
*gc
= __glXGetCurrentContext();
2182 #ifdef GLX_DIRECT_RENDERING
2183 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2184 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2187 if (gc
== &dummyContext
) /* no GLX for this */
2190 #ifdef GLX_DIRECT_RENDERING
2191 if (!pdraw
|| !gc
->isDirect
)
2195 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2196 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2197 * of -1 if the function failed because of errors detected in the input
2200 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2202 if (divisor
> 0 && remainder
>= divisor
)
2205 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2208 #ifdef GLX_DIRECT_RENDERING
2209 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2210 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2219 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2220 int64_t target_msc
, int64_t divisor
,
2221 int64_t remainder
, int64_t * ust
,
2222 int64_t * msc
, int64_t * sbc
)
2224 #ifdef GLX_DIRECT_RENDERING
2225 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2226 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2231 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2232 * error", but the return type in the spec is Bool.
2234 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2236 if (divisor
> 0 && remainder
>= divisor
)
2239 #ifdef GLX_DIRECT_RENDERING
2240 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2241 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2252 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2253 int64_t target_sbc
, int64_t * ust
,
2254 int64_t * msc
, int64_t * sbc
)
2256 #ifdef GLX_DIRECT_RENDERING
2257 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2258 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2262 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2263 * error", but the return type in the spec is Bool.
2268 #ifdef GLX_DIRECT_RENDERING
2269 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2270 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2282 * Mesa extension stubs. These will help reduce portability problems.
2287 * Release all buffers associated with the specified GLX drawable.
2290 * This function was intended for stand-alone Mesa. The issue there is that
2291 * the library doesn't get any notification when a window is closed. In
2292 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2293 * supported, there are 3 different functions to destroy a drawable. It
2294 * should be possible to create GLX protocol (or have it determine which
2295 * protocol to use based on the type of the drawable) to have one function
2296 * do the work of 3. For the direct-rendering case, this function could
2297 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2298 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2299 * would need to be used. This really should be done as part of the new DRI
2302 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2303 * __driGarbageCollectDrawables
2304 * glXDestroyGLXPixmap
2305 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2306 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2309 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2317 _GLX_PUBLIC GLXPixmap
2318 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2319 Pixmap pixmap
, Colormap cmap
)
2332 * GLX_MESA_copy_sub_buffer
2334 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2336 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2337 int x
, int y
, int width
, int height
)
2339 xGLXVendorPrivateReq
*req
;
2340 struct glx_context
*gc
;
2342 CARD32
*drawable_ptr
;
2343 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2346 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2347 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2348 if (pdraw
!= NULL
) {
2349 struct glx_screen
*psc
= pdraw
->psc
;
2350 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2351 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
, True
);
2358 opcode
= __glXSetupForCommand(dpy
);
2363 ** The calling thread may or may not have a current context. If it
2364 ** does, send the context tag so the server can do a flush.
2366 gc
= __glXGetCurrentContext();
2367 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
2368 ((drawable
== gc
->currentDrawable
) ||
2369 (drawable
== gc
->currentReadable
))) {
2370 tag
= gc
->currentContextTag
;
2377 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2378 req
->reqType
= opcode
;
2379 req
->glxCode
= X_GLXVendorPrivate
;
2380 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2381 req
->contextTag
= tag
;
2383 drawable_ptr
= (CARD32
*) (req
+ 1);
2384 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2385 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2386 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2387 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2389 *drawable_ptr
= drawable
;
2401 __glXBindTexImageEXT(Display
* dpy
,
2402 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2404 struct glx_context
*gc
= __glXGetCurrentContext();
2406 if (gc
->vtable
->bind_tex_image
== NULL
)
2409 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2413 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2415 struct glx_context
*gc
= __glXGetCurrentContext();
2417 if (gc
->vtable
->release_tex_image
== NULL
)
2420 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2425 #endif /* GLX_USE_APPLEGL */
2428 ** glXGetProcAddress support
2431 struct name_address_pair
2437 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2438 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2440 static const struct name_address_pair GLX_functions
[] = {
2441 /*** GLX_VERSION_1_0 ***/
2442 GLX_FUNCTION(glXChooseVisual
),
2443 GLX_FUNCTION(glXCopyContext
),
2444 GLX_FUNCTION(glXCreateContext
),
2445 GLX_FUNCTION(glXCreateGLXPixmap
),
2446 GLX_FUNCTION(glXDestroyContext
),
2447 GLX_FUNCTION(glXDestroyGLXPixmap
),
2448 GLX_FUNCTION(glXGetConfig
),
2449 GLX_FUNCTION(glXGetCurrentContext
),
2450 GLX_FUNCTION(glXGetCurrentDrawable
),
2451 GLX_FUNCTION(glXIsDirect
),
2452 GLX_FUNCTION(glXMakeCurrent
),
2453 GLX_FUNCTION(glXQueryExtension
),
2454 GLX_FUNCTION(glXQueryVersion
),
2455 GLX_FUNCTION(glXSwapBuffers
),
2456 GLX_FUNCTION(glXUseXFont
),
2457 GLX_FUNCTION(glXWaitGL
),
2458 GLX_FUNCTION(glXWaitX
),
2460 /*** GLX_VERSION_1_1 ***/
2461 GLX_FUNCTION(glXGetClientString
),
2462 GLX_FUNCTION(glXQueryExtensionsString
),
2463 GLX_FUNCTION(glXQueryServerString
),
2465 /*** GLX_VERSION_1_2 ***/
2466 GLX_FUNCTION(glXGetCurrentDisplay
),
2468 /*** GLX_VERSION_1_3 ***/
2469 GLX_FUNCTION(glXChooseFBConfig
),
2470 GLX_FUNCTION(glXCreateNewContext
),
2471 GLX_FUNCTION(glXCreatePbuffer
),
2472 GLX_FUNCTION(glXCreatePixmap
),
2473 GLX_FUNCTION(glXCreateWindow
),
2474 GLX_FUNCTION(glXDestroyPbuffer
),
2475 GLX_FUNCTION(glXDestroyPixmap
),
2476 GLX_FUNCTION(glXDestroyWindow
),
2477 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2478 GLX_FUNCTION(glXGetFBConfigAttrib
),
2479 GLX_FUNCTION(glXGetFBConfigs
),
2480 GLX_FUNCTION(glXGetSelectedEvent
),
2481 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2482 GLX_FUNCTION(glXMakeContextCurrent
),
2483 GLX_FUNCTION(glXQueryContext
),
2484 GLX_FUNCTION(glXQueryDrawable
),
2485 GLX_FUNCTION(glXSelectEvent
),
2487 #ifndef GLX_USE_APPLEGL
2488 /*** GLX_SGI_swap_control ***/
2489 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2491 /*** GLX_SGI_video_sync ***/
2492 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2493 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2495 /*** GLX_SGI_make_current_read ***/
2496 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2497 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2499 /*** GLX_EXT_import_context ***/
2500 GLX_FUNCTION(glXFreeContextEXT
),
2501 GLX_FUNCTION(glXGetContextIDEXT
),
2502 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2503 GLX_FUNCTION(glXImportContextEXT
),
2504 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2507 /*** GLX_SGIX_fbconfig ***/
2508 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2509 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2510 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2511 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2512 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2513 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2515 #ifndef GLX_USE_APPLEGL
2516 /*** GLX_SGIX_pbuffer ***/
2517 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2518 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2519 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2520 GLX_FUNCTION(glXSelectEventSGIX
),
2521 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2523 /*** GLX_MESA_copy_sub_buffer ***/
2524 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2526 /*** GLX_MESA_pixmap_colormap ***/
2527 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2529 /*** GLX_MESA_release_buffers ***/
2530 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2532 /*** GLX_MESA_swap_control ***/
2533 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2534 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2537 /*** GLX_ARB_get_proc_address ***/
2538 GLX_FUNCTION(glXGetProcAddressARB
),
2541 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2543 #ifndef GLX_USE_APPLEGL
2544 /*** GLX_OML_sync_control ***/
2545 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2546 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2547 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2548 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2549 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2551 /*** GLX_EXT_texture_from_pixmap ***/
2552 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2553 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2556 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
2557 /*** DRI configuration ***/
2558 GLX_FUNCTION(glXGetScreenDriver
),
2559 GLX_FUNCTION(glXGetDriverConfig
),
2562 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2563 GLX_FUNCTION(glXCreateContextAttribsARB
),
2565 /*** GLX_MESA_query_renderer ***/
2566 GLX_FUNCTION(glXQueryRendererIntegerMESA
),
2567 GLX_FUNCTION(glXQueryRendererStringMESA
),
2568 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA
),
2569 GLX_FUNCTION(glXQueryCurrentRendererStringMESA
),
2571 {NULL
, NULL
} /* end of list */
2574 static const GLvoid
*
2575 get_glx_proc_address(const char *funcName
)
2579 /* try static functions */
2580 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2581 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2582 return GLX_functions
[i
].Address
;
2589 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2590 * \c glXGetProcAddress.
2592 * \param procName Name of a GL or GLX function.
2593 * \returns A pointer to the named function
2595 * \sa glXGetProcAddress
2597 _GLX_PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2599 typedef void (*gl_function
) (void);
2603 /* Search the table of GLX and internal functions first. If that
2604 * fails and the supplied name could be a valid core GL name, try
2605 * searching the core GL function table. This check is done to prevent
2606 * DRI based drivers from searching the core GL function table for
2607 * internal API functions.
2609 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2610 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2611 && (procName
[2] != 'X')) {
2612 #ifdef GLX_INDIRECT_RENDERING
2613 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2616 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2618 struct glx_context
*gc
= __glXGetCurrentContext();
2620 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2621 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2628 * Get the address of a named GL function. This is the GLX 1.4 name for
2629 * \c glXGetProcAddressARB.
2631 * \param procName Name of a GL or GLX function.
2632 * \returns A pointer to the named function
2634 * \sa glXGetProcAddressARB
2637 GLX_ALIAS(__GLXextFuncPtr
, glXGetProcAddress
,
2638 (const GLubyte
* procName
),
2639 (procName
), glXGetProcAddressARB
)
2641 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2643 * Get the unadjusted system time (UST). Currently, the UST is measured in
2644 * microseconds since Epoc. The actual resolution of the UST may vary from
2645 * system to system, and the units may vary from release to release.
2646 * Drivers should not call this function directly. They should instead use
2647 * \c glXGetProcAddress to obtain a pointer to the function.
2649 * \param ust Location to store the 64-bit UST
2650 * \returns Zero on success or a negative errno value on failure.
2652 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2654 * \since Internal API version 20030317.
2657 __glXGetUST(int64_t * ust
)
2665 if (gettimeofday(&tv
, NULL
) == 0) {
2666 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2673 #endif /* GLX_DIRECT_RENDERING */
2675 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2678 MesaGLInteropGLXQueryDeviceInfo(Display
*dpy
, GLXContext context
,
2679 struct mesa_glinterop_device_info
*out
)
2681 struct glx_context
*gc
= (struct glx_context
*)context
;
2686 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2688 return MESA_GLINTEROP_INVALID_CONTEXT
;
2691 if (!gc
->vtable
->interop_query_device_info
) {
2693 return MESA_GLINTEROP_UNSUPPORTED
;
2696 ret
= gc
->vtable
->interop_query_device_info(gc
, out
);
2702 MesaGLInteropGLXExportObject(Display
*dpy
, GLXContext context
,
2703 struct mesa_glinterop_export_in
*in
,
2704 struct mesa_glinterop_export_out
*out
)
2706 struct glx_context
*gc
= (struct glx_context
*)context
;
2711 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2713 return MESA_GLINTEROP_INVALID_CONTEXT
;
2716 if (!gc
->vtable
->interop_export_object
) {
2718 return MESA_GLINTEROP_UNSUPPORTED
;
2721 ret
= gc
->vtable
->interop_export_object(gc
, in
, out
);
2726 #endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */