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"
49 #include <X11/extensions/xf86vmode.h>
54 #include <X11/Xlib-xcb.h>
57 #include "GL/mesa_glinterop.h"
59 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
60 static const char __glXGLXClientVersion
[] = "1.4";
62 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
65 * Get the __DRIdrawable for the drawable associated with a GLXContext
67 * \param dpy The display associated with \c drawable.
68 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
69 * \param scrn_num If non-NULL, the drawables screen is stored there
70 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
71 * the drawable is not associated with a direct-rendering context.
73 _X_HIDDEN __GLXDRIdrawable
*
74 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
76 struct glx_display
*priv
= __glXInitialize(dpy
);
77 __GLXDRIdrawable
*pdraw
;
82 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
90 _X_HIDDEN
struct glx_drawable
*
91 GetGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
93 struct glx_display
*priv
= __glXInitialize(dpy
);
94 struct glx_drawable
*glxDraw
;
99 if (__glxHashLookup(priv
->glXDrawHash
, drawable
, (void *) &glxDraw
) == 0)
106 InitGLXDrawable(Display
*dpy
, struct glx_drawable
*glxDraw
, XID xDrawable
,
107 GLXDrawable drawable
)
109 struct glx_display
*priv
= __glXInitialize(dpy
);
114 glxDraw
->xDrawable
= xDrawable
;
115 glxDraw
->drawable
= drawable
;
116 glxDraw
->lastEventSbc
= 0;
117 glxDraw
->eventSbcWrap
= 0;
119 return __glxHashInsert(priv
->glXDrawHash
, drawable
, glxDraw
);
123 DestroyGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
125 struct glx_display
*priv
= __glXInitialize(dpy
);
126 struct glx_drawable
*glxDraw
;
131 glxDraw
= GetGLXDrawable(dpy
, drawable
);
132 __glxHashDelete(priv
->glXDrawHash
, drawable
);
137 * Get the GLX per-screen data structure associated with a GLX context.
139 * \param dpy Display for which the GLX per-screen information is to be
141 * \param scrn Screen on \c dpy for which the GLX per-screen information is
143 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
144 * specify a valid GLX screen, or NULL otherwise.
146 * \todo Should this function validate that \c scrn is within the screen
147 * number range for \c dpy?
150 _X_HIDDEN
struct glx_screen
*
151 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
153 struct glx_display
*const priv
= __glXInitialize(dpy
);
157 NULL
) ? priv
->screens
[scrn
] : NULL
;
162 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
163 struct glx_screen
** ppsc
)
165 /* Initialize the extension, if needed . This has the added value
166 * of initializing/allocating the display private
170 return GLX_NO_EXTENSION
;
173 *ppriv
= __glXInitialize(dpy
);
174 if (*ppriv
== NULL
) {
175 return GLX_NO_EXTENSION
;
178 /* Check screen number to see if its valid */
179 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
180 return GLX_BAD_SCREEN
;
183 /* Check to see if the GL is supported on this screen */
184 *ppsc
= (*ppriv
)->screens
[scrn
];
185 if ((*ppsc
)->configs
== NULL
&& (*ppsc
)->visuals
== NULL
) {
186 /* No support for GL on this screen regardless of visual */
187 return GLX_BAD_VISUAL
;
195 * Determine if a \c GLXFBConfig supplied by the application is valid.
197 * \param dpy Application supplied \c Display pointer.
198 * \param config Application supplied \c GLXFBConfig.
200 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
201 * \c struct glx_config structure is returned. Otherwise, \c NULL
204 static struct glx_config
*
205 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
207 struct glx_display
*const priv
= __glXInitialize(dpy
);
208 int num_screens
= ScreenCount(dpy
);
210 struct glx_config
*config
;
213 for (i
= 0; i
< num_screens
; i
++) {
214 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
215 config
= config
->next
) {
216 if (config
== (struct glx_config
*) fbconfig
) {
227 * Verifies context's GLX_RENDER_TYPE value with config.
229 * \param config GLX FBConfig which will support the returned renderType.
230 * \param renderType The context render type to be verified.
231 * \return True if the value of context renderType was approved, or 0 if no
232 * valid value was found.
235 validate_renderType_against_config(const struct glx_config
*config
,
238 switch (renderType
) {
240 return (config
->renderType
& GLX_RGBA_BIT
) != 0;
241 case GLX_COLOR_INDEX_TYPE
:
242 return (config
->renderType
& GLX_COLOR_INDEX_BIT
) != 0;
243 case GLX_RGBA_FLOAT_TYPE_ARB
:
244 return (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) != 0;
245 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
:
246 return (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) != 0;
254 glx_context_init(struct glx_context
*gc
,
255 struct glx_screen
*psc
, struct glx_config
*config
)
257 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
258 if (!gc
->majorOpcode
)
261 gc
->screen
= psc
->scr
;
264 gc
->isDirect
= GL_TRUE
;
265 gc
->currentContextTag
= -1;
272 * Create a new context.
274 * \param renderType For FBConfigs, what is the rendering type?
278 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
279 GLXContext shareList_user
, Bool allowDirect
,
280 unsigned code
, int renderType
, int screen
)
282 struct glx_context
*gc
;
283 struct glx_screen
*psc
;
284 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
288 psc
= GetGLXScreenConfigs(dpy
, screen
);
292 if (generic_id
== None
)
296 #ifdef GLX_USE_APPLEGL
297 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
299 if (allowDirect
&& psc
->vtable
->create_context
)
300 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
302 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
309 case X_GLXCreateContext
: {
310 xGLXCreateContextReq
*req
;
312 /* Send the glXCreateContext request */
313 GetReq(GLXCreateContext
, req
);
314 req
->reqType
= gc
->majorOpcode
;
315 req
->glxCode
= X_GLXCreateContext
;
316 req
->context
= gc
->xid
= XAllocID(dpy
);
317 req
->visual
= generic_id
;
318 req
->screen
= screen
;
319 req
->shareList
= shareList
? shareList
->xid
: None
;
320 req
->isDirect
= gc
->isDirect
;
324 case X_GLXCreateNewContext
: {
325 xGLXCreateNewContextReq
*req
;
327 /* Send the glXCreateNewContext request */
328 GetReq(GLXCreateNewContext
, req
);
329 req
->reqType
= gc
->majorOpcode
;
330 req
->glxCode
= X_GLXCreateNewContext
;
331 req
->context
= gc
->xid
= XAllocID(dpy
);
332 req
->fbconfig
= generic_id
;
333 req
->screen
= screen
;
334 req
->renderType
= renderType
;
335 req
->shareList
= shareList
? shareList
->xid
: None
;
336 req
->isDirect
= gc
->isDirect
;
340 case X_GLXvop_CreateContextWithConfigSGIX
: {
341 xGLXVendorPrivateWithReplyReq
*vpreq
;
342 xGLXCreateContextWithConfigSGIXReq
*req
;
344 /* Send the glXCreateNewContext request */
345 GetReqExtra(GLXVendorPrivateWithReply
,
346 sz_xGLXCreateContextWithConfigSGIXReq
-
347 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
348 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
349 req
->reqType
= gc
->majorOpcode
;
350 req
->glxCode
= X_GLXVendorPrivateWithReply
;
351 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
352 req
->context
= gc
->xid
= XAllocID(dpy
);
353 req
->fbconfig
= generic_id
;
354 req
->screen
= screen
;
355 req
->renderType
= renderType
;
356 req
->shareList
= shareList
? shareList
->xid
: None
;
357 req
->isDirect
= gc
->isDirect
;
362 /* What to do here? This case is the sign of an internal error. It
363 * should never be reachable.
371 gc
->share_xid
= shareList
? shareList
->xid
: None
;
372 gc
->imported
= GL_FALSE
;
374 return (GLXContext
) gc
;
377 _GLX_PUBLIC GLXContext
378 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
379 GLXContext shareList
, Bool allowDirect
)
381 struct glx_config
*config
= NULL
;
382 int renderType
= GLX_RGBA_TYPE
;
384 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
385 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
388 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
390 if (config
== NULL
) {
393 error
.errorCode
= BadValue
;
394 error
.resourceID
= vis
->visualid
;
395 error
.sequenceNumber
= dpy
->request
;
396 error
.type
= X_Error
;
397 error
.majorCode
= __glXSetupForCommand(dpy
);
398 error
.minorCode
= X_GLXCreateContext
;
399 _XError(dpy
, &error
);
403 /* Choose the context render type based on DRI config values. It is
404 * unusual to set this type from config, but we have no other choice, as
405 * this old API does not provide renderType parameter.
407 if (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) {
408 renderType
= GLX_RGBA_FLOAT_TYPE_ARB
;
409 } else if (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) {
410 renderType
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
411 } else if (config
->renderType
& GLX_RGBA_BIT
) {
412 renderType
= GLX_RGBA_TYPE
;
413 } else if (config
->renderType
& GLX_COLOR_INDEX_BIT
) {
414 renderType
= GLX_COLOR_INDEX_TYPE
;
415 } else if (config
->rgbMode
) {
416 /* If we're here, then renderType is not set correctly. Let's use a
417 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
418 * default value is needed by old DRI drivers, which didn't set
419 * renderType correctly as the value was just ignored.
421 renderType
= GLX_RGBA_TYPE
;
423 /* Safeguard - only one option left, all non-RGB modes are indexed
424 * modes. Again, this allows drivers with invalid renderType to work
427 renderType
= GLX_COLOR_INDEX_TYPE
;
431 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
432 X_GLXCreateContext
, renderType
, vis
->screen
);
436 glx_send_destroy_context(Display
*dpy
, XID xid
)
438 CARD8 opcode
= __glXSetupForCommand(dpy
);
439 xGLXDestroyContextReq
*req
;
442 GetReq(GLXDestroyContext
, req
);
443 req
->reqType
= opcode
;
444 req
->glxCode
= X_GLXDestroyContext
;
451 ** Destroy the named context
455 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
457 struct glx_context
*gc
= (struct glx_context
*) ctx
;
459 if (gc
== NULL
|| gc
->xid
== None
)
464 glx_send_destroy_context(dpy
, gc
->xid
);
466 if (gc
->currentDpy
) {
467 /* This context is bound to some thread. According to the man page,
468 * we should not actually delete the context until it's unbound.
469 * Note that we set gc->xid = None above. In MakeContextCurrent()
470 * we check for that and delete the context there.
474 gc
->vtable
->destroy(gc
);
480 ** Return the major and minor version #s for the GLX extension
483 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
485 struct glx_display
*priv
;
487 /* Init the extension. This fetches the major and minor version. */
488 priv
= __glXInitialize(dpy
);
493 *major
= priv
->majorVersion
;
495 *minor
= priv
->minorVersion
;
500 ** Query the existence of the GLX extension
503 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
505 int major_op
, erb
, evb
;
508 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
519 ** Put a barrier in the token stream that forces the GL to finish its
520 ** work before X can proceed.
525 struct glx_context
*gc
= __glXGetCurrentContext();
527 if (gc
!= &dummyContext
&& gc
->vtable
->wait_gl
)
528 gc
->vtable
->wait_gl(gc
);
532 ** Put a barrier in the token stream that forces X to finish its
533 ** work before GL can proceed.
538 struct glx_context
*gc
= __glXGetCurrentContext();
540 if (gc
!= &dummyContext
&& gc
->vtable
->wait_x
)
541 gc
->vtable
->wait_x(gc
);
545 glXUseXFont(Font font
, int first
, int count
, int listBase
)
547 struct glx_context
*gc
= __glXGetCurrentContext();
549 if (gc
!= &dummyContext
&& gc
->vtable
->use_x_font
)
550 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
553 /************************************************************************/
556 ** Copy the source context to the destination context using the
560 glXCopyContext(Display
* dpy
, GLXContext source_user
,
561 GLXContext dest_user
, unsigned long mask
)
563 struct glx_context
*source
= (struct glx_context
*) source_user
;
564 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
565 #ifdef GLX_USE_APPLEGL
566 struct glx_context
*gc
= __glXGetCurrentContext();
570 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
571 mask
, &errorcode
, &x11error
)) {
572 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
576 xGLXCopyContextReq
*req
;
577 struct glx_context
*gc
= __glXGetCurrentContext();
581 opcode
= __glXSetupForCommand(dpy
);
586 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
588 /* NOT_DONE: This does not work yet */
593 ** If the source is the current context, send its tag so that the context
594 ** can be flushed before the copy.
596 if (source
== gc
&& dpy
== gc
->currentDpy
) {
597 tag
= gc
->currentContextTag
;
603 /* Send the glXCopyContext request */
605 GetReq(GLXCopyContext
, req
);
606 req
->reqType
= opcode
;
607 req
->glxCode
= X_GLXCopyContext
;
608 req
->source
= source
? source
->xid
: None
;
609 req
->dest
= dest
? dest
->xid
: None
;
611 req
->contextTag
= tag
;
614 #endif /* GLX_USE_APPLEGL */
619 * Determine if a context uses direct rendering.
621 * \param dpy Display where the context was created.
622 * \param contextID ID of the context to be tested.
624 * \returns \c True if the context is direct rendering or not.
627 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
631 xcb_generic_error_t
*err
;
632 xcb_glx_is_direct_reply_t
*reply
;
635 opcode
= __glXSetupForCommand(dpy
);
640 c
= XGetXCBConnection(dpy
);
641 reply
= xcb_glx_is_direct_reply(c
, xcb_glx_is_direct(c
, contextID
), &err
);
642 is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
645 __glXSendErrorForXcb(dpy
, err
);
656 * Shouldn't this function \b always return \c False when
657 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
658 * the GLX protocol here at all?
661 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
663 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
668 else if (gc
->isDirect
) {
671 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
674 return __glXIsDirect(dpy
, gc
->xid
);
678 _GLX_PUBLIC GLXPixmap
679 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
681 #ifdef GLX_USE_APPLEGL
682 int screen
= vis
->screen
;
683 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
684 const struct glx_config
*config
;
686 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
688 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
693 xGLXCreateGLXPixmapReq
*req
;
694 struct glx_drawable
*glxDraw
;
698 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
699 struct glx_display
*const priv
= __glXInitialize(dpy
);
705 opcode
= __glXSetupForCommand(dpy
);
710 glxDraw
= malloc(sizeof(*glxDraw
));
714 /* Send the glXCreateGLXPixmap request */
716 GetReq(GLXCreateGLXPixmap
, req
);
717 req
->reqType
= opcode
;
718 req
->glxCode
= X_GLXCreateGLXPixmap
;
719 req
->screen
= vis
->screen
;
720 req
->visual
= vis
->visualid
;
721 req
->pixmap
= pixmap
;
722 req
->glxpixmap
= xid
= XAllocID(dpy
);
726 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
731 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
733 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
734 * is actually bound to a context... */
736 __GLXDRIdrawable
*pdraw
;
737 struct glx_screen
*psc
;
738 struct glx_config
*config
;
740 psc
= priv
->screens
[vis
->screen
];
741 if (psc
->driScreen
== NULL
)
744 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
745 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
747 fprintf(stderr
, "failed to create pixmap\n");
752 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
753 (*pdraw
->destroyDrawable
) (pdraw
);
760 xGLXDestroyGLXPixmapReq
*dreq
;
762 GetReq(GLXDestroyGLXPixmap
, dreq
);
763 dreq
->reqType
= opcode
;
764 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
765 dreq
->glxpixmap
= xid
;
776 ** Destroy the named pixmap
779 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
781 #ifdef GLX_USE_APPLEGL
782 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
783 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
785 xGLXDestroyGLXPixmapReq
*req
;
788 opcode
= __glXSetupForCommand(dpy
);
793 /* Send the glXDestroyGLXPixmap request */
795 GetReq(GLXDestroyGLXPixmap
, req
);
796 req
->reqType
= opcode
;
797 req
->glxCode
= X_GLXDestroyGLXPixmap
;
798 req
->glxpixmap
= glxpixmap
;
802 DestroyGLXDrawable(dpy
, glxpixmap
);
804 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
806 struct glx_display
*const priv
= __glXInitialize(dpy
);
807 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
809 if (priv
!= NULL
&& pdraw
!= NULL
) {
810 (*pdraw
->destroyDrawable
) (pdraw
);
811 __glxHashDelete(priv
->drawHash
, glxpixmap
);
815 #endif /* GLX_USE_APPLEGL */
819 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
821 #ifdef GLX_USE_APPLEGL
822 struct glx_context
* gc
= __glXGetCurrentContext();
823 if(gc
!= &DummyContext
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
824 apple_glx_swap_buffers(gc
->driContext
);
826 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
829 struct glx_context
*gc
;
834 gc
= __glXGetCurrentContext();
836 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
838 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
841 Bool flush
= gc
!= &dummyContext
&& drawable
== gc
->currentDrawable
;
843 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0, flush
);
849 opcode
= __glXSetupForCommand(dpy
);
855 ** The calling thread may or may not have a current context. If it
856 ** does, send the context tag so the server can do a flush.
858 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
859 ((drawable
== gc
->currentDrawable
)
860 || (drawable
== gc
->currentReadable
))) {
861 tag
= gc
->currentContextTag
;
867 c
= XGetXCBConnection(dpy
);
868 xcb_glx_swap_buffers(c
, tag
, drawable
);
870 #endif /* GLX_USE_APPLEGL */
875 ** Return configuration information for the given display, screen and
876 ** visual combination.
879 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
882 struct glx_display
*priv
;
883 struct glx_screen
*psc
;
884 struct glx_config
*config
;
887 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
888 if (status
== Success
) {
889 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
891 /* Lookup attribute after first finding a match on the visual */
892 if (config
!= NULL
) {
893 return glx_config_get(config
, attribute
, value_return
);
896 status
= GLX_BAD_VISUAL
;
900 ** If we can't find the config for this visual, this visual is not
901 ** supported by the OpenGL implementation on the server.
903 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
904 *value_return
= False
;
911 /************************************************************************/
914 init_fbconfig_for_chooser(struct glx_config
* config
,
915 GLboolean fbconfig_style_tags
)
917 memset(config
, 0, sizeof(struct glx_config
));
918 config
->visualID
= (XID
) GLX_DONT_CARE
;
919 config
->visualType
= GLX_DONT_CARE
;
921 /* glXChooseFBConfig specifies different defaults for these properties than
924 if (fbconfig_style_tags
) {
925 config
->rgbMode
= GL_TRUE
;
926 config
->doubleBufferMode
= GLX_DONT_CARE
;
927 config
->renderType
= GLX_RGBA_BIT
;
930 config
->drawableType
= GLX_WINDOW_BIT
;
931 config
->visualRating
= GLX_DONT_CARE
;
932 config
->transparentPixel
= GLX_NONE
;
933 config
->transparentRed
= GLX_DONT_CARE
;
934 config
->transparentGreen
= GLX_DONT_CARE
;
935 config
->transparentBlue
= GLX_DONT_CARE
;
936 config
->transparentAlpha
= GLX_DONT_CARE
;
937 config
->transparentIndex
= GLX_DONT_CARE
;
939 config
->xRenderable
= GLX_DONT_CARE
;
940 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
942 config
->swapMethod
= GLX_DONT_CARE
;
945 #define MATCH_DONT_CARE( param ) \
947 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
948 && (a-> param != b-> param) ) { \
953 #define MATCH_MINIMUM( param ) \
955 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
956 && (a-> param > b-> param) ) { \
961 #define MATCH_EXACT( param ) \
963 if ( a-> param != b-> param) { \
968 /* Test that all bits from a are contained in b */
969 #define MATCH_MASK(param) \
971 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
972 && ((a->param & ~b->param) != 0) ) { \
978 * Determine if two GLXFBConfigs are compatible.
980 * \param a Application specified config to test.
981 * \param b Server specified config to test against \c a.
984 fbconfigs_compatible(const struct glx_config
* const a
,
985 const struct glx_config
* const b
)
987 MATCH_DONT_CARE(doubleBufferMode
);
988 MATCH_DONT_CARE(visualType
);
989 MATCH_DONT_CARE(visualRating
);
990 MATCH_DONT_CARE(xRenderable
);
991 MATCH_DONT_CARE(fbconfigID
);
992 MATCH_DONT_CARE(swapMethod
);
994 MATCH_MINIMUM(rgbBits
);
995 MATCH_MINIMUM(numAuxBuffers
);
996 MATCH_MINIMUM(redBits
);
997 MATCH_MINIMUM(greenBits
);
998 MATCH_MINIMUM(blueBits
);
999 MATCH_MINIMUM(alphaBits
);
1000 MATCH_MINIMUM(depthBits
);
1001 MATCH_MINIMUM(stencilBits
);
1002 MATCH_MINIMUM(accumRedBits
);
1003 MATCH_MINIMUM(accumGreenBits
);
1004 MATCH_MINIMUM(accumBlueBits
);
1005 MATCH_MINIMUM(accumAlphaBits
);
1006 MATCH_MINIMUM(sampleBuffers
);
1007 MATCH_MINIMUM(maxPbufferWidth
);
1008 MATCH_MINIMUM(maxPbufferHeight
);
1009 MATCH_MINIMUM(maxPbufferPixels
);
1010 MATCH_MINIMUM(samples
);
1012 MATCH_DONT_CARE(stereoMode
);
1015 MATCH_MASK(drawableType
);
1016 MATCH_MASK(renderType
);
1017 MATCH_DONT_CARE(sRGBCapable
);
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.4 specification.
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_SMALLER(sampleBuffers
);
1138 PREFER_SMALLER(samples
);
1140 PREFER_LARGER_OR_ZERO(depthBits
);
1141 PREFER_SMALLER(stencilBits
);
1143 /* This isn't quite right. It is supposed to compare the sum of the
1144 * components the user specifically set minimums for.
1146 PREFER_LARGER_OR_ZERO(accumRedBits
);
1147 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1148 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1149 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1151 PREFER_SMALLER(visualType
);
1153 /* None of the pbuffer or fbconfig specs say that this comparison needs
1154 * to happen at all, but it seems like it should.
1156 PREFER_LARGER(maxPbufferWidth
);
1157 PREFER_LARGER(maxPbufferHeight
);
1158 PREFER_LARGER(maxPbufferPixels
);
1165 * Selects and sorts a subset of the supplied configs based on the attributes.
1166 * This function forms to basis of \c glXChooseFBConfig and
1167 * \c glXChooseFBConfigSGIX.
1169 * \param configs Array of pointers to possible configs. The elements of
1170 * this array that do not meet the criteria will be set to
1171 * NULL. The remaining elements will be sorted according to
1172 * the various visual / FBConfig selection rules.
1173 * \param num_configs Number of elements in the \c configs array.
1174 * \param attribList Attributes used select from \c configs. This array is
1175 * terminated by a \c None tag. The array is of the form
1176 * expected by \c glXChooseFBConfig (where every tag has a
1178 * \returns The number of valid elements left in \c configs.
1180 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
1183 choose_fbconfig(struct glx_config
** configs
, int num_configs
,
1184 const int *attribList
)
1186 struct glx_config test_config
;
1190 /* This is a fairly direct implementation of the selection method
1191 * described by GLX_SGIX_fbconfig. Start by culling out all the
1192 * configs that are not compatible with the selected parameter
1196 init_fbconfig_for_chooser(&test_config
, GL_TRUE
);
1197 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1198 (const INT32
*) attribList
,
1202 for (i
= 0; i
< num_configs
; i
++) {
1203 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1204 configs
[base
] = configs
[i
];
1213 if (base
< num_configs
) {
1214 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1217 /* After the incompatible configs are removed, the resulting
1218 * list is sorted according to the rules set out in the various
1222 qsort(configs
, base
, sizeof(struct glx_config
*),
1223 (int (*)(const void *, const void *)) fbconfig_compare
);
1231 ** Return the visual that best matches the template. Return None if no
1232 ** visual matches the template.
1234 _GLX_PUBLIC XVisualInfo
*
1235 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1237 XVisualInfo
*visualList
= NULL
;
1238 struct glx_display
*priv
;
1239 struct glx_screen
*psc
;
1240 struct glx_config test_config
;
1241 struct glx_config
*config
;
1242 struct glx_config
*best_config
= NULL
;
1245 ** Get a list of all visuals, return if list is empty
1247 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1253 ** Build a template from the defaults and the attribute list
1254 ** Free visual list and return if an unexpected token is encountered
1256 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1257 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1258 (const INT32
*) attribList
,
1262 ** Eliminate visuals that don't meet minimum requirements
1263 ** Compute a score for those that do
1264 ** Remember which visual, if any, got the highest score
1265 ** If no visual is acceptable, return None
1266 ** Otherwise, create an XVisualInfo list with just the selected X visual
1269 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1270 if (fbconfigs_compatible(&test_config
, config
)
1271 && ((best_config
== NULL
) ||
1272 (fbconfig_compare (&config
, &best_config
) < 0))) {
1273 XVisualInfo visualTemplate
;
1274 XVisualInfo
*newList
;
1277 visualTemplate
.screen
= screen
;
1278 visualTemplate
.visualid
= config
->visualID
;
1279 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1280 &visualTemplate
, &i
);
1284 visualList
= newList
;
1285 best_config
= config
;
1290 #ifdef GLX_USE_APPLEGL
1291 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1292 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1300 _GLX_PUBLIC
const char *
1301 glXQueryExtensionsString(Display
* dpy
, int screen
)
1303 struct glx_screen
*psc
;
1304 struct glx_display
*priv
;
1306 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1310 if (!psc
->effectiveGLXexts
) {
1311 if (!psc
->serverGLXexts
) {
1312 psc
->serverGLXexts
=
1313 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1317 __glXCalculateUsableExtensions(psc
,
1318 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1319 (psc
->driScreen
!= NULL
),
1323 priv
->minorVersion
);
1326 return psc
->effectiveGLXexts
;
1329 _GLX_PUBLIC
const char *
1330 glXGetClientString(Display
* dpy
, int name
)
1336 return (__glXGLXClientVendorName
);
1338 return (__glXGLXClientVersion
);
1339 case GLX_EXTENSIONS
:
1340 return (__glXGetClientExtensions());
1346 _GLX_PUBLIC
const char *
1347 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1349 struct glx_screen
*psc
;
1350 struct glx_display
*priv
;
1354 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1360 str
= &priv
->serverGLXvendor
;
1363 str
= &priv
->serverGLXversion
;
1365 case GLX_EXTENSIONS
:
1366 str
= &psc
->serverGLXexts
;
1373 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1381 ** EXT_import_context
1384 _GLX_PUBLIC Display
*
1385 glXGetCurrentDisplay(void)
1387 struct glx_context
*gc
= __glXGetCurrentContext();
1388 if (gc
== &dummyContext
)
1390 return gc
->currentDpy
;
1394 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1395 glXGetCurrentDisplay
)
1397 #ifndef GLX_USE_APPLEGL
1398 _GLX_PUBLIC GLXContext
1399 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1401 struct glx_display
*priv
= __glXInitialize(dpy
);
1402 struct glx_screen
*psc
= NULL
;
1403 xGLXQueryContextReply reply
;
1405 struct glx_context
*ctx
;
1407 /* This GLX implementation knows about 5 different properties, so
1408 * allow the server to send us one of each.
1410 int propList
[5 * 2], *pProp
, nPropListBytes
;
1414 struct glx_config
*mode
;
1415 uint32_t fbconfigID
= 0;
1416 uint32_t visualID
= 0;
1417 uint32_t screen
= 0;
1418 Bool got_screen
= False
;
1423 /* The GLX_EXT_import_context spec says:
1425 * "If <contextID> does not refer to a valid context, then a BadContext
1426 * error is generated; if <contextID> refers to direct rendering
1427 * context then no error is generated but glXImportContextEXT returns
1430 * If contextID is None, generate BadContext on the client-side. Other
1431 * sorts of invalid contexts will be detected by the server in the
1432 * __glXIsDirect call.
1434 if (contextID
== None
) {
1435 __glXSendError(dpy
, GLXBadContext
, contextID
, X_GLXIsDirect
, false);
1439 if (__glXIsDirect(dpy
, contextID
))
1442 opcode
= __glXSetupForCommand(dpy
);
1446 /* Send the glXQueryContextInfoEXT request */
1449 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1450 xGLXQueryContextReq
*req
;
1452 GetReq(GLXQueryContext
, req
);
1454 req
->reqType
= opcode
;
1455 req
->glxCode
= X_GLXQueryContext
;
1456 req
->context
= contextID
;
1459 xGLXVendorPrivateReq
*vpreq
;
1460 xGLXQueryContextInfoEXTReq
*req
;
1462 GetReqExtra(GLXVendorPrivate
,
1463 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1465 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1466 req
->reqType
= opcode
;
1467 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1468 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1469 req
->context
= contextID
;
1472 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1474 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1475 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1478 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1482 numProps
= nPropListBytes
/ (2 * sizeof(propList
[0]));
1485 renderType
= GLX_RGBA_TYPE
; /* By default, assume RGBA context */
1488 for (i
= 0, pProp
= propList
; i
< numProps
; i
++, pProp
+= 2)
1494 case GLX_SHARE_CONTEXT_EXT
:
1497 case GLX_VISUAL_ID_EXT
:
1498 visualID
= pProp
[1];
1500 case GLX_FBCONFIG_ID
:
1501 fbconfigID
= pProp
[1];
1503 case GLX_RENDER_TYPE
:
1504 renderType
= pProp
[1];
1511 psc
= GetGLXScreenConfigs(dpy
, screen
);
1515 if (fbconfigID
!= 0) {
1516 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1517 } else if (visualID
!= 0) {
1518 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1524 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1528 ctx
->xid
= contextID
;
1529 ctx
->imported
= GL_TRUE
;
1530 ctx
->share_xid
= share
;
1532 return (GLXContext
) ctx
;
1538 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1540 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1542 switch (attribute
) {
1543 case GLX_SHARE_CONTEXT_EXT
:
1544 *value
= ctx
->share_xid
;
1546 case GLX_VISUAL_ID_EXT
:
1547 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1550 *value
= ctx
->screen
;
1552 case GLX_FBCONFIG_ID
:
1553 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1555 case GLX_RENDER_TYPE
:
1556 *value
= ctx
->renderType
;
1559 return GLX_BAD_ATTRIBUTE
;
1565 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1566 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1567 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1569 _GLX_PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1571 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1573 return (ctx
== NULL
) ? None
: ctx
->xid
;
1577 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1579 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1581 if (gc
== NULL
|| gc
->xid
== None
)
1584 /* The GLX_EXT_import_context spec says:
1586 * "glXFreeContext does not free the server-side context information or
1587 * the XID associated with the server-side context."
1589 * Don't send any protocol. Just destroy the client-side tracking of the
1590 * context. Also, only release the context structure if it's not current.
1593 if (gc
->currentDpy
) {
1596 gc
->vtable
->destroy(gc
);
1601 _GLX_PUBLIC GLXFBConfig
*
1602 glXChooseFBConfig(Display
* dpy
, int screen
,
1603 const int *attribList
, int *nitems
)
1605 struct glx_config
**config_list
;
1609 config_list
= (struct glx_config
**)
1610 glXGetFBConfigs(dpy
, screen
, &list_size
);
1612 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1613 list_size
= choose_fbconfig(config_list
, list_size
, attribList
);
1614 if (list_size
== 0) {
1620 *nitems
= list_size
;
1621 return (GLXFBConfig
*) config_list
;
1625 _GLX_PUBLIC GLXContext
1626 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1627 int renderType
, GLXContext shareList
, Bool allowDirect
)
1629 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1630 struct glx_config
**config_list
;
1635 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1639 config_list
= (struct glx_config
**)
1640 glXGetFBConfigs(dpy
, config
->screen
, &list_size
);
1642 for (i
= 0; i
< list_size
; i
++) {
1643 if (config_list
[i
] == config
)
1648 if (i
== list_size
) {
1649 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1653 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1654 allowDirect
, X_GLXCreateNewContext
, renderType
,
1659 _GLX_PUBLIC GLXDrawable
1660 glXGetCurrentReadDrawable(void)
1662 struct glx_context
*gc
= __glXGetCurrentContext();
1664 return gc
->currentReadable
;
1668 _GLX_PUBLIC GLXFBConfig
*
1669 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1671 struct glx_display
*priv
= __glXInitialize(dpy
);
1672 struct glx_config
**config_list
= NULL
;
1673 struct glx_config
*config
;
1674 unsigned num_configs
= 0;
1678 if (priv
&& (priv
->screens
!= NULL
)
1679 && (screen
>= 0) && (screen
< ScreenCount(dpy
))
1680 && (priv
->screens
[screen
]->configs
!= NULL
)
1681 && (priv
->screens
[screen
]->configs
->fbconfigID
1682 != (int) GLX_DONT_CARE
)) {
1684 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1685 config
= config
->next
) {
1686 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1691 config_list
= malloc(num_configs
* sizeof *config_list
);
1692 if (config_list
!= NULL
) {
1693 *nelements
= num_configs
;
1695 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1696 config
= config
->next
) {
1697 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1698 config_list
[i
] = config
;
1705 return (GLXFBConfig
*) config_list
;
1710 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1711 int attribute
, int *value
)
1713 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1716 return GLXBadFBConfig
;
1718 return glx_config_get(config
, attribute
, value
);
1722 _GLX_PUBLIC XVisualInfo
*
1723 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1725 XVisualInfo visualTemplate
;
1726 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1730 ** Get a list of all visuals, return if list is empty
1732 visualTemplate
.visualid
= config
->visualID
;
1733 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1736 #ifndef GLX_USE_APPLEGL
1738 ** GLX_SGI_swap_control
1741 __glXSwapIntervalSGI(int interval
)
1743 xGLXVendorPrivateReq
*req
;
1744 struct glx_context
*gc
= __glXGetCurrentContext();
1745 struct glx_screen
*psc
;
1747 CARD32
*interval_ptr
;
1750 if (gc
== &dummyContext
) {
1751 return GLX_BAD_CONTEXT
;
1754 if (interval
<= 0) {
1755 return GLX_BAD_VALUE
;
1758 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1760 #ifdef GLX_DIRECT_RENDERING
1761 if (gc
->isDirect
&& psc
&& psc
->driScreen
&&
1762 psc
->driScreen
->setSwapInterval
) {
1763 __GLXDRIdrawable
*pdraw
=
1764 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1765 /* Simply ignore the command if the GLX drawable has been destroyed but
1766 * the context is still bound.
1769 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1774 dpy
= gc
->currentDpy
;
1775 opcode
= __glXSetupForCommand(dpy
);
1780 /* Send the glXSwapIntervalSGI request */
1782 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1783 req
->reqType
= opcode
;
1784 req
->glxCode
= X_GLXVendorPrivate
;
1785 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1786 req
->contextTag
= gc
->currentContextTag
;
1788 interval_ptr
= (CARD32
*) (req
+ 1);
1789 *interval_ptr
= interval
;
1800 ** GLX_MESA_swap_control
1803 __glXSwapIntervalMESA(unsigned int interval
)
1805 #ifdef GLX_DIRECT_RENDERING
1806 struct glx_context
*gc
= __glXGetCurrentContext();
1808 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1809 struct glx_screen
*psc
;
1811 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1812 if (psc
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1813 __GLXDRIdrawable
*pdraw
=
1814 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1816 /* Simply ignore the command if the GLX drawable has been destroyed but
1817 * the context is still bound.
1822 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1827 return GLX_BAD_CONTEXT
;
1832 __glXGetSwapIntervalMESA(void)
1834 #ifdef GLX_DIRECT_RENDERING
1835 struct glx_context
*gc
= __glXGetCurrentContext();
1837 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1838 struct glx_screen
*psc
;
1840 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1841 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1842 __GLXDRIdrawable
*pdraw
=
1843 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1845 return psc
->driScreen
->getSwapInterval(pdraw
);
1855 ** GLX_SGI_video_sync
1858 __glXGetVideoSyncSGI(unsigned int *count
)
1860 int64_t ust
, msc
, sbc
;
1862 struct glx_context
*gc
= __glXGetCurrentContext();
1863 struct glx_screen
*psc
;
1864 #ifdef GLX_DIRECT_RENDERING
1865 __GLXDRIdrawable
*pdraw
;
1868 if (gc
== &dummyContext
)
1869 return GLX_BAD_CONTEXT
;
1871 #ifdef GLX_DIRECT_RENDERING
1873 return GLX_BAD_CONTEXT
;
1876 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1877 #ifdef GLX_DIRECT_RENDERING
1878 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1881 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1882 * FIXME: there should be a GLX encoding for this call. I can find no
1883 * FIXME: documentation for the GLX encoding.
1885 #ifdef GLX_DIRECT_RENDERING
1886 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1887 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1888 *count
= (unsigned) msc
;
1889 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1893 return GLX_BAD_CONTEXT
;
1897 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1899 struct glx_context
*gc
= __glXGetCurrentContext();
1900 struct glx_screen
*psc
;
1901 #ifdef GLX_DIRECT_RENDERING
1902 __GLXDRIdrawable
*pdraw
;
1904 int64_t ust
, msc
, sbc
;
1907 if (divisor
<= 0 || remainder
< 0)
1908 return GLX_BAD_VALUE
;
1910 if (gc
== &dummyContext
)
1911 return GLX_BAD_CONTEXT
;
1913 #ifdef GLX_DIRECT_RENDERING
1915 return GLX_BAD_CONTEXT
;
1918 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1919 #ifdef GLX_DIRECT_RENDERING
1920 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1923 #ifdef GLX_DIRECT_RENDERING
1924 if (psc
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1925 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1927 *count
= (unsigned) msc
;
1928 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1932 return GLX_BAD_CONTEXT
;
1935 #endif /* GLX_USE_APPLEGL */
1938 ** GLX_SGIX_fbconfig
1939 ** Many of these functions are aliased to GLX 1.3 entry points in the
1940 ** GLX_functions table.
1944 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1945 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1946 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1948 _GLX_PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1949 (Display
* dpy
, int screen
, int *attrib_list
,
1950 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1953 _GLX_PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1954 (Display
* dpy
, GLXFBConfigSGIX config
),
1955 (dpy
, config
), glXGetVisualFromFBConfig
)
1957 _GLX_PUBLIC GLXPixmap
1958 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1959 GLXFBConfigSGIX fbconfig
,
1962 #ifndef GLX_USE_APPLEGL
1963 xGLXVendorPrivateWithReplyReq
*vpreq
;
1964 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1965 GLXPixmap xid
= None
;
1967 struct glx_screen
*psc
;
1969 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1972 if ((dpy
== NULL
) || (config
== NULL
)) {
1975 #ifdef GLX_USE_APPLEGL
1976 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1981 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1983 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1984 opcode
= __glXSetupForCommand(dpy
);
1989 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1991 GetReqExtra(GLXVendorPrivateWithReply
,
1992 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1993 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1994 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1995 req
->reqType
= opcode
;
1996 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1997 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1998 req
->screen
= config
->screen
;
1999 req
->fbconfig
= config
->fbconfigID
;
2000 req
->pixmap
= pixmap
;
2001 req
->glxpixmap
= xid
= XAllocID(dpy
);
2010 _GLX_PUBLIC GLXContext
2011 glXCreateContextWithConfigSGIX(Display
* dpy
,
2012 GLXFBConfigSGIX fbconfig
, int renderType
,
2013 GLXContext shareList
, Bool allowDirect
)
2015 GLXContext gc
= NULL
;
2016 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2017 struct glx_screen
*psc
;
2020 if ((dpy
== NULL
) || (config
== NULL
)) {
2024 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2026 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2027 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2029 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2037 _GLX_PUBLIC GLXFBConfigSGIX
2038 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2040 struct glx_display
*priv
;
2041 struct glx_screen
*psc
= NULL
;
2043 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2044 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2045 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2046 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2053 #ifndef GLX_USE_APPLEGL
2055 ** GLX_SGIX_swap_group
2058 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2068 ** GLX_SGIX_swap_barrier
2071 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2079 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2089 ** GLX_OML_sync_control
2092 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2093 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2095 struct glx_display
* const priv
= __glXInitialize(dpy
);
2097 #ifdef GLX_DIRECT_RENDERING
2098 __GLXDRIdrawable
*pdraw
;
2100 struct glx_screen
*psc
;
2105 #ifdef GLX_DIRECT_RENDERING
2106 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2107 psc
= pdraw
? pdraw
->psc
: NULL
;
2108 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2109 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2117 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2119 __glxGetMscRate(struct glx_screen
*psc
,
2120 int32_t * numerator
, int32_t * denominator
)
2123 XF86VidModeModeLine mode_line
;
2127 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2128 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2129 unsigned n
= dot_clock
* 1000;
2130 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2132 # define V_INTERLACE 0x010
2133 # define V_DBLSCAN 0x020
2135 if (mode_line
.flags
& V_INTERLACE
)
2137 else if (mode_line
.flags
& V_DBLSCAN
)
2140 /* The OML_sync_control spec requires that if the refresh rate is a
2141 * whole number, that the returned numerator be equal to the refresh
2142 * rate and the denominator be 1.
2150 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2152 /* This is a poor man's way to reduce a fraction. It's far from
2153 * perfect, but it will work well enough for this situation.
2156 for (i
= 0; f
[i
] != 0; i
++) {
2157 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2177 * Determine the refresh rate of the specified drawable and display.
2179 * \param dpy Display whose refresh rate is to be determined.
2180 * \param drawable Drawable whose refresh rate is to be determined.
2181 * \param numerator Numerator of the refresh rate.
2182 * \param demoninator Denominator of the refresh rate.
2183 * \return If the refresh rate for the specified display and drawable could
2184 * be calculated, True is returned. Otherwise False is returned.
2186 * \note This function is implemented entirely client-side. A lot of other
2187 * functionality is required to export GLX_OML_sync_control, so on
2188 * XFree86 this function can be called for direct-rendering contexts
2189 * when GLX_OML_sync_control appears in the client extension string.
2193 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2194 int32_t * numerator
, int32_t * denominator
)
2196 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2197 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2202 return __glxGetMscRate(draw
->psc
, numerator
, denominator
);
2214 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2215 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2217 struct glx_context
*gc
= __glXGetCurrentContext();
2218 #ifdef GLX_DIRECT_RENDERING
2219 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2220 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2223 if (gc
== &dummyContext
) /* no GLX for this */
2226 #ifdef GLX_DIRECT_RENDERING
2227 if (!pdraw
|| !gc
->isDirect
)
2231 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2232 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2233 * of -1 if the function failed because of errors detected in the input
2236 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2238 if (divisor
> 0 && remainder
>= divisor
)
2241 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2244 #ifdef GLX_DIRECT_RENDERING
2245 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2246 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2255 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2256 int64_t target_msc
, int64_t divisor
,
2257 int64_t remainder
, int64_t * ust
,
2258 int64_t * msc
, int64_t * sbc
)
2260 #ifdef GLX_DIRECT_RENDERING
2261 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2262 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2267 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2268 * error", but the return type in the spec is Bool.
2270 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2272 if (divisor
> 0 && remainder
>= divisor
)
2275 #ifdef GLX_DIRECT_RENDERING
2276 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2277 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2288 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2289 int64_t target_sbc
, int64_t * ust
,
2290 int64_t * msc
, int64_t * sbc
)
2292 #ifdef GLX_DIRECT_RENDERING
2293 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2294 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2298 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2299 * error", but the return type in the spec is Bool.
2304 #ifdef GLX_DIRECT_RENDERING
2305 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2306 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2318 * Mesa extension stubs. These will help reduce portability problems.
2323 * Release all buffers associated with the specified GLX drawable.
2326 * This function was intended for stand-alone Mesa. The issue there is that
2327 * the library doesn't get any notification when a window is closed. In
2328 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2329 * supported, there are 3 different functions to destroy a drawable. It
2330 * should be possible to create GLX protocol (or have it determine which
2331 * protocol to use based on the type of the drawable) to have one function
2332 * do the work of 3. For the direct-rendering case, this function could
2333 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2334 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2335 * would need to be used. This really should be done as part of the new DRI
2338 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2339 * __driGarbageCollectDrawables
2340 * glXDestroyGLXPixmap
2341 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2342 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2345 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2353 _GLX_PUBLIC GLXPixmap
2354 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2355 Pixmap pixmap
, Colormap cmap
)
2368 * GLX_MESA_copy_sub_buffer
2370 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2372 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2373 int x
, int y
, int width
, int height
)
2375 xGLXVendorPrivateReq
*req
;
2376 struct glx_context
*gc
;
2378 CARD32
*drawable_ptr
;
2379 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2382 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2383 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2384 if (pdraw
!= NULL
) {
2385 struct glx_screen
*psc
= pdraw
->psc
;
2386 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2387 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
, True
);
2394 opcode
= __glXSetupForCommand(dpy
);
2399 ** The calling thread may or may not have a current context. If it
2400 ** does, send the context tag so the server can do a flush.
2402 gc
= __glXGetCurrentContext();
2403 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
2404 ((drawable
== gc
->currentDrawable
) ||
2405 (drawable
== gc
->currentReadable
))) {
2406 tag
= gc
->currentContextTag
;
2413 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2414 req
->reqType
= opcode
;
2415 req
->glxCode
= X_GLXVendorPrivate
;
2416 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2417 req
->contextTag
= tag
;
2419 drawable_ptr
= (CARD32
*) (req
+ 1);
2420 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2421 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2422 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2423 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2425 *drawable_ptr
= drawable
;
2437 __glXBindTexImageEXT(Display
* dpy
,
2438 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2440 struct glx_context
*gc
= __glXGetCurrentContext();
2442 if (gc
== &dummyContext
|| gc
->vtable
->bind_tex_image
== NULL
)
2445 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2449 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2451 struct glx_context
*gc
= __glXGetCurrentContext();
2453 if (gc
== &dummyContext
|| gc
->vtable
->release_tex_image
== NULL
)
2456 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2461 #endif /* GLX_USE_APPLEGL */
2464 ** glXGetProcAddress support
2467 struct name_address_pair
2473 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2474 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2476 static const struct name_address_pair GLX_functions
[] = {
2477 /*** GLX_VERSION_1_0 ***/
2478 GLX_FUNCTION(glXChooseVisual
),
2479 GLX_FUNCTION(glXCopyContext
),
2480 GLX_FUNCTION(glXCreateContext
),
2481 GLX_FUNCTION(glXCreateGLXPixmap
),
2482 GLX_FUNCTION(glXDestroyContext
),
2483 GLX_FUNCTION(glXDestroyGLXPixmap
),
2484 GLX_FUNCTION(glXGetConfig
),
2485 GLX_FUNCTION(glXGetCurrentContext
),
2486 GLX_FUNCTION(glXGetCurrentDrawable
),
2487 GLX_FUNCTION(glXIsDirect
),
2488 GLX_FUNCTION(glXMakeCurrent
),
2489 GLX_FUNCTION(glXQueryExtension
),
2490 GLX_FUNCTION(glXQueryVersion
),
2491 GLX_FUNCTION(glXSwapBuffers
),
2492 GLX_FUNCTION(glXUseXFont
),
2493 GLX_FUNCTION(glXWaitGL
),
2494 GLX_FUNCTION(glXWaitX
),
2496 /*** GLX_VERSION_1_1 ***/
2497 GLX_FUNCTION(glXGetClientString
),
2498 GLX_FUNCTION(glXQueryExtensionsString
),
2499 GLX_FUNCTION(glXQueryServerString
),
2501 /*** GLX_VERSION_1_2 ***/
2502 GLX_FUNCTION(glXGetCurrentDisplay
),
2504 /*** GLX_VERSION_1_3 ***/
2505 GLX_FUNCTION(glXChooseFBConfig
),
2506 GLX_FUNCTION(glXCreateNewContext
),
2507 GLX_FUNCTION(glXCreatePbuffer
),
2508 GLX_FUNCTION(glXCreatePixmap
),
2509 GLX_FUNCTION(glXCreateWindow
),
2510 GLX_FUNCTION(glXDestroyPbuffer
),
2511 GLX_FUNCTION(glXDestroyPixmap
),
2512 GLX_FUNCTION(glXDestroyWindow
),
2513 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2514 GLX_FUNCTION(glXGetFBConfigAttrib
),
2515 GLX_FUNCTION(glXGetFBConfigs
),
2516 GLX_FUNCTION(glXGetSelectedEvent
),
2517 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2518 GLX_FUNCTION(glXMakeContextCurrent
),
2519 GLX_FUNCTION(glXQueryContext
),
2520 GLX_FUNCTION(glXQueryDrawable
),
2521 GLX_FUNCTION(glXSelectEvent
),
2523 #ifndef GLX_USE_APPLEGL
2524 /*** GLX_SGI_swap_control ***/
2525 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2527 /*** GLX_SGI_video_sync ***/
2528 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2529 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2531 /*** GLX_SGI_make_current_read ***/
2532 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2533 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2535 /*** GLX_EXT_import_context ***/
2536 GLX_FUNCTION(glXFreeContextEXT
),
2537 GLX_FUNCTION(glXGetContextIDEXT
),
2538 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2539 GLX_FUNCTION(glXImportContextEXT
),
2540 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2543 /*** GLX_SGIX_fbconfig ***/
2544 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2545 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2546 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2547 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2548 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2549 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2551 #ifndef GLX_USE_APPLEGL
2552 /*** GLX_SGIX_pbuffer ***/
2553 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2554 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2555 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2556 GLX_FUNCTION(glXSelectEventSGIX
),
2557 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2559 /*** GLX_SGIX_swap_group ***/
2560 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2562 /*** GLX_SGIX_swap_barrier ***/
2563 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2564 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2566 /*** GLX_MESA_copy_sub_buffer ***/
2567 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2569 /*** GLX_MESA_pixmap_colormap ***/
2570 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2572 /*** GLX_MESA_release_buffers ***/
2573 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2575 /*** GLX_MESA_swap_control ***/
2576 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2577 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2580 /*** GLX_ARB_get_proc_address ***/
2581 GLX_FUNCTION(glXGetProcAddressARB
),
2584 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2586 #ifndef GLX_USE_APPLEGL
2587 /*** GLX_OML_sync_control ***/
2588 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2589 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2590 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2591 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2592 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2594 /*** GLX_EXT_texture_from_pixmap ***/
2595 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2596 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2599 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
2600 /*** DRI configuration ***/
2601 GLX_FUNCTION(glXGetScreenDriver
),
2602 GLX_FUNCTION(glXGetDriverConfig
),
2605 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2606 GLX_FUNCTION(glXCreateContextAttribsARB
),
2608 /*** GLX_MESA_query_renderer ***/
2609 GLX_FUNCTION(glXQueryRendererIntegerMESA
),
2610 GLX_FUNCTION(glXQueryRendererStringMESA
),
2611 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA
),
2612 GLX_FUNCTION(glXQueryCurrentRendererStringMESA
),
2614 {NULL
, NULL
} /* end of list */
2617 static const GLvoid
*
2618 get_glx_proc_address(const char *funcName
)
2622 /* try static functions */
2623 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2624 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2625 return GLX_functions
[i
].Address
;
2632 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2633 * \c glXGetProcAddress.
2635 * \param procName Name of a GL or GLX function.
2636 * \returns A pointer to the named function
2638 * \sa glXGetProcAddress
2640 _GLX_PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2642 typedef void (*gl_function
) (void);
2646 /* Search the table of GLX and internal functions first. If that
2647 * fails and the supplied name could be a valid core GL name, try
2648 * searching the core GL function table. This check is done to prevent
2649 * DRI based drivers from searching the core GL function table for
2650 * internal API functions.
2652 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2653 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2654 && (procName
[2] != 'X')) {
2655 #ifdef GLX_INDIRECT_RENDERING
2656 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2659 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2661 struct glx_context
*gc
= __glXGetCurrentContext();
2663 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2664 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2671 * Get the address of a named GL function. This is the GLX 1.4 name for
2672 * \c glXGetProcAddressARB.
2674 * \param procName Name of a GL or GLX function.
2675 * \returns A pointer to the named function
2677 * \sa glXGetProcAddressARB
2680 GLX_ALIAS(__GLXextFuncPtr
, glXGetProcAddress
,
2681 (const GLubyte
* procName
),
2682 (procName
), glXGetProcAddressARB
)
2684 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2686 * Get the unadjusted system time (UST). Currently, the UST is measured in
2687 * microseconds since Epoc. The actual resolution of the UST may vary from
2688 * system to system, and the units may vary from release to release.
2689 * Drivers should not call this function directly. They should instead use
2690 * \c glXGetProcAddress to obtain a pointer to the function.
2692 * \param ust Location to store the 64-bit UST
2693 * \returns Zero on success or a negative errno value on failure.
2695 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2697 * \since Internal API version 20030317.
2700 __glXGetUST(int64_t * ust
)
2708 if (gettimeofday(&tv
, NULL
) == 0) {
2709 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2716 #endif /* GLX_DIRECT_RENDERING */
2718 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2721 MesaGLInteropGLXQueryDeviceInfo(Display
*dpy
, GLXContext context
,
2722 struct mesa_glinterop_device_info
*out
)
2724 struct glx_context
*gc
= (struct glx_context
*)context
;
2729 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2731 return MESA_GLINTEROP_INVALID_CONTEXT
;
2734 if (!gc
->vtable
->interop_query_device_info
) {
2736 return MESA_GLINTEROP_UNSUPPORTED
;
2739 ret
= gc
->vtable
->interop_query_device_info(gc
, out
);
2745 MesaGLInteropGLXExportObject(Display
*dpy
, GLXContext context
,
2746 struct mesa_glinterop_export_in
*in
,
2747 struct mesa_glinterop_export_out
*out
)
2749 struct glx_context
*gc
= (struct glx_context
*)context
;
2754 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2756 return MESA_GLINTEROP_INVALID_CONTEXT
;
2759 if (!gc
->vtable
->interop_export_object
) {
2761 return MESA_GLINTEROP_UNSUPPORTED
;
2764 ret
= gc
->vtable
->interop_export_object(gc
, in
, out
);
2769 #endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */