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 /* GLX_EXT_no_config_context supports any render type */
242 switch (renderType
) {
244 return (config
->renderType
& GLX_RGBA_BIT
) != 0;
245 case GLX_COLOR_INDEX_TYPE
:
246 return (config
->renderType
& GLX_COLOR_INDEX_BIT
) != 0;
247 case GLX_RGBA_FLOAT_TYPE_ARB
:
248 return (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) != 0;
249 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
:
250 return (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) != 0;
258 glx_context_init(struct glx_context
*gc
,
259 struct glx_screen
*psc
, struct glx_config
*config
)
261 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
262 if (!gc
->majorOpcode
)
265 gc
->screen
= psc
->scr
;
268 gc
->isDirect
= GL_TRUE
;
269 gc
->currentContextTag
= -1;
276 * Create a new context.
278 * \param renderType For FBConfigs, what is the rendering type?
282 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
283 GLXContext shareList_user
, Bool allowDirect
,
284 unsigned code
, int renderType
, int screen
)
286 struct glx_context
*gc
;
287 struct glx_screen
*psc
;
288 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
292 psc
= GetGLXScreenConfigs(dpy
, screen
);
296 if (generic_id
== None
)
300 #ifdef GLX_USE_APPLEGL
301 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
303 if (allowDirect
&& psc
->vtable
->create_context
)
304 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
306 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
313 case X_GLXCreateContext
: {
314 xGLXCreateContextReq
*req
;
316 /* Send the glXCreateContext request */
317 GetReq(GLXCreateContext
, req
);
318 req
->reqType
= gc
->majorOpcode
;
319 req
->glxCode
= X_GLXCreateContext
;
320 req
->context
= gc
->xid
= XAllocID(dpy
);
321 req
->visual
= generic_id
;
322 req
->screen
= screen
;
323 req
->shareList
= shareList
? shareList
->xid
: None
;
324 req
->isDirect
= gc
->isDirect
;
328 case X_GLXCreateNewContext
: {
329 xGLXCreateNewContextReq
*req
;
331 /* Send the glXCreateNewContext request */
332 GetReq(GLXCreateNewContext
, req
);
333 req
->reqType
= gc
->majorOpcode
;
334 req
->glxCode
= X_GLXCreateNewContext
;
335 req
->context
= gc
->xid
= XAllocID(dpy
);
336 req
->fbconfig
= generic_id
;
337 req
->screen
= screen
;
338 req
->renderType
= renderType
;
339 req
->shareList
= shareList
? shareList
->xid
: None
;
340 req
->isDirect
= gc
->isDirect
;
344 case X_GLXvop_CreateContextWithConfigSGIX
: {
345 xGLXVendorPrivateWithReplyReq
*vpreq
;
346 xGLXCreateContextWithConfigSGIXReq
*req
;
348 /* Send the glXCreateNewContext request */
349 GetReqExtra(GLXVendorPrivateWithReply
,
350 sz_xGLXCreateContextWithConfigSGIXReq
-
351 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
352 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
353 req
->reqType
= gc
->majorOpcode
;
354 req
->glxCode
= X_GLXVendorPrivateWithReply
;
355 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
356 req
->context
= gc
->xid
= XAllocID(dpy
);
357 req
->fbconfig
= generic_id
;
358 req
->screen
= screen
;
359 req
->renderType
= renderType
;
360 req
->shareList
= shareList
? shareList
->xid
: None
;
361 req
->isDirect
= gc
->isDirect
;
366 /* What to do here? This case is the sign of an internal error. It
367 * should never be reachable.
375 gc
->share_xid
= shareList
? shareList
->xid
: None
;
376 gc
->imported
= GL_FALSE
;
378 return (GLXContext
) gc
;
381 _GLX_PUBLIC GLXContext
382 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
383 GLXContext shareList
, Bool allowDirect
)
385 struct glx_config
*config
= NULL
;
386 int renderType
= GLX_RGBA_TYPE
;
388 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
389 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
392 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
394 if (config
== NULL
) {
395 __glXSendError(dpy
, BadValue
, vis
->visualid
, X_GLXCreateContext
, True
);
399 /* Choose the context render type based on DRI config values. It is
400 * unusual to set this type from config, but we have no other choice, as
401 * this old API does not provide renderType parameter.
403 if (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) {
404 renderType
= GLX_RGBA_FLOAT_TYPE_ARB
;
405 } else if (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) {
406 renderType
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
407 } else if (config
->renderType
& GLX_RGBA_BIT
) {
408 renderType
= GLX_RGBA_TYPE
;
409 } else if (config
->renderType
& GLX_COLOR_INDEX_BIT
) {
410 renderType
= GLX_COLOR_INDEX_TYPE
;
411 } else if (config
->rgbMode
) {
412 /* If we're here, then renderType is not set correctly. Let's use a
413 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
414 * default value is needed by old DRI drivers, which didn't set
415 * renderType correctly as the value was just ignored.
417 renderType
= GLX_RGBA_TYPE
;
419 /* Safeguard - only one option left, all non-RGB modes are indexed
420 * modes. Again, this allows drivers with invalid renderType to work
423 renderType
= GLX_COLOR_INDEX_TYPE
;
427 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
428 X_GLXCreateContext
, renderType
, vis
->screen
);
432 glx_send_destroy_context(Display
*dpy
, XID xid
)
434 CARD8 opcode
= __glXSetupForCommand(dpy
);
435 xGLXDestroyContextReq
*req
;
438 GetReq(GLXDestroyContext
, req
);
439 req
->reqType
= opcode
;
440 req
->glxCode
= X_GLXDestroyContext
;
447 ** Destroy the named context
451 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
453 struct glx_context
*gc
= (struct glx_context
*) ctx
;
455 if (gc
== NULL
|| gc
->xid
== None
)
460 glx_send_destroy_context(dpy
, gc
->xid
);
462 if (gc
->currentDpy
) {
463 /* This context is bound to some thread. According to the man page,
464 * we should not actually delete the context until it's unbound.
465 * Note that we set gc->xid = None above. In MakeContextCurrent()
466 * we check for that and delete the context there.
470 gc
->vtable
->destroy(gc
);
476 ** Return the major and minor version #s for the GLX extension
479 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
481 struct glx_display
*priv
;
483 /* Init the extension. This fetches the major and minor version. */
484 priv
= __glXInitialize(dpy
);
489 *major
= priv
->majorVersion
;
491 *minor
= priv
->minorVersion
;
496 ** Query the existence of the GLX extension
499 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
501 int major_op
, erb
, evb
;
504 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
515 ** Put a barrier in the token stream that forces the GL to finish its
516 ** work before X can proceed.
521 struct glx_context
*gc
= __glXGetCurrentContext();
523 if (gc
->vtable
->wait_gl
)
524 gc
->vtable
->wait_gl(gc
);
528 ** Put a barrier in the token stream that forces X to finish its
529 ** work before GL can proceed.
534 struct glx_context
*gc
= __glXGetCurrentContext();
536 if (gc
->vtable
->wait_x
)
537 gc
->vtable
->wait_x(gc
);
541 glXUseXFont(Font font
, int first
, int count
, int listBase
)
543 struct glx_context
*gc
= __glXGetCurrentContext();
545 if (gc
->vtable
->use_x_font
)
546 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
549 /************************************************************************/
552 ** Copy the source context to the destination context using the
556 glXCopyContext(Display
* dpy
, GLXContext source_user
,
557 GLXContext dest_user
, unsigned long mask
)
559 struct glx_context
*source
= (struct glx_context
*) source_user
;
560 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
561 #ifdef GLX_USE_APPLEGL
562 struct glx_context
*gc
= __glXGetCurrentContext();
566 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
567 mask
, &errorcode
, &x11error
)) {
568 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
572 xGLXCopyContextReq
*req
;
573 struct glx_context
*gc
= __glXGetCurrentContext();
577 opcode
= __glXSetupForCommand(dpy
);
582 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
584 /* NOT_DONE: This does not work yet */
589 ** If the source is the current context, send its tag so that the context
590 ** can be flushed before the copy.
592 if (source
== gc
&& dpy
== gc
->currentDpy
) {
593 tag
= gc
->currentContextTag
;
599 /* Send the glXCopyContext request */
601 GetReq(GLXCopyContext
, req
);
602 req
->reqType
= opcode
;
603 req
->glxCode
= X_GLXCopyContext
;
604 req
->source
= source
? source
->xid
: None
;
605 req
->dest
= dest
? dest
->xid
: None
;
607 req
->contextTag
= tag
;
610 #endif /* GLX_USE_APPLEGL */
615 * Determine if a context uses direct rendering.
617 * \param dpy Display where the context was created.
618 * \param contextID ID of the context to be tested.
620 * \returns \c True if the context is direct rendering or not.
623 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
627 xcb_generic_error_t
*err
;
628 xcb_glx_is_direct_reply_t
*reply
;
631 opcode
= __glXSetupForCommand(dpy
);
636 c
= XGetXCBConnection(dpy
);
637 reply
= xcb_glx_is_direct_reply(c
, xcb_glx_is_direct(c
, contextID
), &err
);
638 is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
641 __glXSendErrorForXcb(dpy
, err
);
652 * Shouldn't this function \b always return \c False when
653 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
654 * the GLX protocol here at all?
657 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
659 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
664 else if (gc
->isDirect
) {
667 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
670 return __glXIsDirect(dpy
, gc
->xid
);
674 _GLX_PUBLIC GLXPixmap
675 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
677 #ifdef GLX_USE_APPLEGL
678 int screen
= vis
->screen
;
679 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
680 const struct glx_config
*config
;
682 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
684 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
689 xGLXCreateGLXPixmapReq
*req
;
690 struct glx_drawable
*glxDraw
;
694 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
695 struct glx_display
*const priv
= __glXInitialize(dpy
);
701 opcode
= __glXSetupForCommand(dpy
);
706 glxDraw
= malloc(sizeof(*glxDraw
));
710 /* Send the glXCreateGLXPixmap request */
712 GetReq(GLXCreateGLXPixmap
, req
);
713 req
->reqType
= opcode
;
714 req
->glxCode
= X_GLXCreateGLXPixmap
;
715 req
->screen
= vis
->screen
;
716 req
->visual
= vis
->visualid
;
717 req
->pixmap
= pixmap
;
718 req
->glxpixmap
= xid
= XAllocID(dpy
);
722 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
727 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
729 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
730 * is actually bound to a context... */
732 __GLXDRIdrawable
*pdraw
;
733 struct glx_screen
*psc
;
734 struct glx_config
*config
;
736 psc
= priv
->screens
[vis
->screen
];
737 if (psc
->driScreen
== NULL
)
740 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
741 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
743 fprintf(stderr
, "failed to create pixmap\n");
748 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
749 (*pdraw
->destroyDrawable
) (pdraw
);
756 xGLXDestroyGLXPixmapReq
*dreq
;
758 GetReq(GLXDestroyGLXPixmap
, dreq
);
759 dreq
->reqType
= opcode
;
760 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
761 dreq
->glxpixmap
= xid
;
772 ** Destroy the named pixmap
775 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
777 #ifdef GLX_USE_APPLEGL
778 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
779 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
781 xGLXDestroyGLXPixmapReq
*req
;
784 opcode
= __glXSetupForCommand(dpy
);
789 /* Send the glXDestroyGLXPixmap request */
791 GetReq(GLXDestroyGLXPixmap
, req
);
792 req
->reqType
= opcode
;
793 req
->glxCode
= X_GLXDestroyGLXPixmap
;
794 req
->glxpixmap
= glxpixmap
;
798 DestroyGLXDrawable(dpy
, glxpixmap
);
800 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
802 struct glx_display
*const priv
= __glXInitialize(dpy
);
803 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
805 if (priv
!= NULL
&& pdraw
!= NULL
) {
806 (*pdraw
->destroyDrawable
) (pdraw
);
807 __glxHashDelete(priv
->drawHash
, glxpixmap
);
811 #endif /* GLX_USE_APPLEGL */
815 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
817 #ifdef GLX_USE_APPLEGL
818 struct glx_context
* gc
= __glXGetCurrentContext();
819 if(gc
!= &dummyContext
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
820 apple_glx_swap_buffers(gc
->driContext
);
822 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
825 struct glx_context
*gc
;
830 gc
= __glXGetCurrentContext();
832 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
834 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
837 Bool flush
= gc
!= &dummyContext
&& drawable
== gc
->currentDrawable
;
839 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0, flush
);
845 opcode
= __glXSetupForCommand(dpy
);
851 ** The calling thread may or may not have a current context. If it
852 ** does, send the context tag so the server can do a flush.
854 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
855 ((drawable
== gc
->currentDrawable
)
856 || (drawable
== gc
->currentReadable
))) {
857 tag
= gc
->currentContextTag
;
863 c
= XGetXCBConnection(dpy
);
864 xcb_glx_swap_buffers(c
, tag
, drawable
);
866 #endif /* GLX_USE_APPLEGL */
871 ** Return configuration information for the given display, screen and
872 ** visual combination.
875 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
878 struct glx_display
*priv
;
879 struct glx_screen
*psc
;
880 struct glx_config
*config
;
883 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
884 if (status
== Success
) {
885 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
887 /* Lookup attribute after first finding a match on the visual */
888 if (config
!= NULL
) {
889 return glx_config_get(config
, attribute
, value_return
);
892 status
= GLX_BAD_VISUAL
;
896 ** If we can't find the config for this visual, this visual is not
897 ** supported by the OpenGL implementation on the server.
899 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
900 *value_return
= False
;
907 /************************************************************************/
910 init_fbconfig_for_chooser(struct glx_config
* config
,
911 GLboolean fbconfig_style_tags
)
913 memset(config
, 0, sizeof(struct glx_config
));
914 config
->visualID
= (XID
) GLX_DONT_CARE
;
915 config
->visualType
= GLX_DONT_CARE
;
917 /* glXChooseFBConfig specifies different defaults for these properties than
920 if (fbconfig_style_tags
) {
921 config
->rgbMode
= GL_TRUE
;
922 config
->doubleBufferMode
= GLX_DONT_CARE
;
923 config
->renderType
= GLX_RGBA_BIT
;
926 config
->drawableType
= GLX_WINDOW_BIT
;
927 config
->visualRating
= GLX_DONT_CARE
;
928 config
->transparentPixel
= GLX_NONE
;
929 config
->transparentRed
= GLX_DONT_CARE
;
930 config
->transparentGreen
= GLX_DONT_CARE
;
931 config
->transparentBlue
= GLX_DONT_CARE
;
932 config
->transparentAlpha
= GLX_DONT_CARE
;
933 config
->transparentIndex
= GLX_DONT_CARE
;
935 config
->xRenderable
= GLX_DONT_CARE
;
936 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
938 config
->swapMethod
= GLX_DONT_CARE
;
941 #define MATCH_DONT_CARE( param ) \
943 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
944 && (a-> param != b-> param) ) { \
949 #define MATCH_MINIMUM( param ) \
951 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
952 && (a-> param > b-> param) ) { \
957 #define MATCH_EXACT( param ) \
959 if ( a-> param != b-> param) { \
964 /* Test that all bits from a are contained in b */
965 #define MATCH_MASK(param) \
967 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
968 && ((a->param & ~b->param) != 0) ) { \
974 * Determine if two GLXFBConfigs are compatible.
976 * \param a Application specified config to test.
977 * \param b Server specified config to test against \c a.
980 fbconfigs_compatible(const struct glx_config
* const a
,
981 const struct glx_config
* const b
)
983 MATCH_DONT_CARE(doubleBufferMode
);
984 MATCH_DONT_CARE(visualType
);
985 MATCH_DONT_CARE(visualRating
);
986 MATCH_DONT_CARE(xRenderable
);
987 MATCH_DONT_CARE(fbconfigID
);
988 MATCH_DONT_CARE(swapMethod
);
990 MATCH_MINIMUM(rgbBits
);
991 MATCH_MINIMUM(numAuxBuffers
);
992 MATCH_MINIMUM(redBits
);
993 MATCH_MINIMUM(greenBits
);
994 MATCH_MINIMUM(blueBits
);
995 MATCH_MINIMUM(alphaBits
);
996 MATCH_MINIMUM(depthBits
);
997 MATCH_MINIMUM(stencilBits
);
998 MATCH_MINIMUM(accumRedBits
);
999 MATCH_MINIMUM(accumGreenBits
);
1000 MATCH_MINIMUM(accumBlueBits
);
1001 MATCH_MINIMUM(accumAlphaBits
);
1002 MATCH_MINIMUM(sampleBuffers
);
1003 MATCH_MINIMUM(maxPbufferWidth
);
1004 MATCH_MINIMUM(maxPbufferHeight
);
1005 MATCH_MINIMUM(maxPbufferPixels
);
1006 MATCH_MINIMUM(samples
);
1008 MATCH_DONT_CARE(stereoMode
);
1011 MATCH_MASK(drawableType
);
1012 MATCH_MASK(renderType
);
1013 MATCH_DONT_CARE(sRGBCapable
);
1015 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1016 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1017 * Technically speaking, it is a bug in the DDX driver, but there is
1018 * enough of an installed base to work around the problem here. In any
1019 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1020 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1021 * 0 from the server to be a match to maintain backward compatibility with
1022 * the (broken) drivers.
1025 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1026 if (a
->transparentPixel
== GLX_NONE
) {
1027 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1031 MATCH_EXACT(transparentPixel
);
1034 switch (a
->transparentPixel
) {
1035 case GLX_TRANSPARENT_RGB
:
1036 MATCH_DONT_CARE(transparentRed
);
1037 MATCH_DONT_CARE(transparentGreen
);
1038 MATCH_DONT_CARE(transparentBlue
);
1039 MATCH_DONT_CARE(transparentAlpha
);
1042 case GLX_TRANSPARENT_INDEX
:
1043 MATCH_DONT_CARE(transparentIndex
);
1055 /* There's some trickly language in the GLX spec about how this is supposed
1056 * to work. Basically, if a given component size is either not specified
1057 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1058 * Well, that's really hard to do with the code as-is. This behavior is
1059 * closer to correct, but still not technically right.
1061 #define PREFER_LARGER_OR_ZERO(comp) \
1063 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1064 if ( ((*a)-> comp) == 0 ) { \
1067 else if ( ((*b)-> comp) == 0 ) { \
1071 return ((*b)-> comp) - ((*a)-> comp) ; \
1076 #define PREFER_LARGER(comp) \
1078 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1079 return ((*b)-> comp) - ((*a)-> comp) ; \
1083 #define PREFER_SMALLER(comp) \
1085 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1086 return ((*a)-> comp) - ((*b)-> comp) ; \
1091 * Compare two GLXFBConfigs. This function is intended to be used as the
1092 * compare function passed in to qsort.
1094 * \returns If \c a is a "better" config, according to the specification of
1095 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1096 * better, then a number greater than zero is return. If both are
1097 * equal, zero is returned.
1098 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1101 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1103 /* The order of these comparisons must NOT change. It is defined by
1104 * the GLX 1.4 specification.
1107 PREFER_SMALLER(visualSelectGroup
);
1109 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1110 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1111 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1113 PREFER_SMALLER(visualRating
);
1115 /* This isn't quite right. It is supposed to compare the sum of the
1116 * components the user specifically set minimums for.
1118 PREFER_LARGER_OR_ZERO(redBits
);
1119 PREFER_LARGER_OR_ZERO(greenBits
);
1120 PREFER_LARGER_OR_ZERO(blueBits
);
1121 PREFER_LARGER_OR_ZERO(alphaBits
);
1123 PREFER_SMALLER(rgbBits
);
1125 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1126 /* Prefer single-buffer.
1128 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1131 PREFER_SMALLER(numAuxBuffers
);
1133 PREFER_SMALLER(sampleBuffers
);
1134 PREFER_SMALLER(samples
);
1136 PREFER_LARGER_OR_ZERO(depthBits
);
1137 PREFER_SMALLER(stencilBits
);
1139 /* This isn't quite right. It is supposed to compare the sum of the
1140 * components the user specifically set minimums for.
1142 PREFER_LARGER_OR_ZERO(accumRedBits
);
1143 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1144 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1145 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1147 PREFER_SMALLER(visualType
);
1149 /* None of the pbuffer or fbconfig specs say that this comparison needs
1150 * to happen at all, but it seems like it should.
1152 PREFER_LARGER(maxPbufferWidth
);
1153 PREFER_LARGER(maxPbufferHeight
);
1154 PREFER_LARGER(maxPbufferPixels
);
1161 * Selects and sorts a subset of the supplied configs based on the attributes.
1162 * This function forms to basis of \c glXChooseFBConfig and
1163 * \c glXChooseFBConfigSGIX.
1165 * \param configs Array of pointers to possible configs. The elements of
1166 * this array that do not meet the criteria will be set to
1167 * NULL. The remaining elements will be sorted according to
1168 * the various visual / FBConfig selection rules.
1169 * \param num_configs Number of elements in the \c configs array.
1170 * \param attribList Attributes used select from \c configs. This array is
1171 * terminated by a \c None tag. The array is of the form
1172 * expected by \c glXChooseFBConfig (where every tag has a
1174 * \returns The number of valid elements left in \c configs.
1176 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
1179 choose_fbconfig(struct glx_config
** configs
, int num_configs
,
1180 const int *attribList
)
1182 struct glx_config test_config
;
1186 /* This is a fairly direct implementation of the selection method
1187 * described by GLX_SGIX_fbconfig. Start by culling out all the
1188 * configs that are not compatible with the selected parameter
1192 init_fbconfig_for_chooser(&test_config
, GL_TRUE
);
1193 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1194 (const INT32
*) attribList
,
1198 for (i
= 0; i
< num_configs
; i
++) {
1199 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1200 configs
[base
] = configs
[i
];
1209 if (base
< num_configs
) {
1210 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1213 /* After the incompatible configs are removed, the resulting
1214 * list is sorted according to the rules set out in the various
1218 qsort(configs
, base
, sizeof(struct glx_config
*),
1219 (int (*)(const void *, const void *)) fbconfig_compare
);
1227 ** Return the visual that best matches the template. Return None if no
1228 ** visual matches the template.
1230 _GLX_PUBLIC XVisualInfo
*
1231 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1233 XVisualInfo
*visualList
= NULL
;
1234 struct glx_display
*priv
;
1235 struct glx_screen
*psc
;
1236 struct glx_config test_config
;
1237 struct glx_config
*config
;
1238 struct glx_config
*best_config
= NULL
;
1241 ** Get a list of all visuals, return if list is empty
1243 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1249 ** Build a template from the defaults and the attribute list
1250 ** Free visual list and return if an unexpected token is encountered
1252 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1253 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1254 (const INT32
*) attribList
,
1258 ** Eliminate visuals that don't meet minimum requirements
1259 ** Compute a score for those that do
1260 ** Remember which visual, if any, got the highest score
1261 ** If no visual is acceptable, return None
1262 ** Otherwise, create an XVisualInfo list with just the selected X visual
1265 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1266 if (fbconfigs_compatible(&test_config
, config
)
1267 && ((best_config
== NULL
) ||
1268 (fbconfig_compare (&config
, &best_config
) < 0))) {
1269 XVisualInfo visualTemplate
;
1270 XVisualInfo
*newList
;
1273 visualTemplate
.screen
= screen
;
1274 visualTemplate
.visualid
= config
->visualID
;
1275 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1276 &visualTemplate
, &i
);
1280 visualList
= newList
;
1281 best_config
= config
;
1286 #ifdef GLX_USE_APPLEGL
1287 if(visualList
&& env_var_as_boolean("LIBGL_DUMP_VISUALID", false)) {
1288 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1296 _GLX_PUBLIC
const char *
1297 glXQueryExtensionsString(Display
* dpy
, int screen
)
1299 struct glx_screen
*psc
;
1300 struct glx_display
*priv
;
1302 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1306 if (!psc
->effectiveGLXexts
) {
1307 if (!psc
->serverGLXexts
) {
1308 psc
->serverGLXexts
=
1309 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1313 __glXCalculateUsableExtensions(psc
,
1314 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1315 (psc
->driScreen
!= NULL
),
1319 priv
->minorVersion
);
1322 return psc
->effectiveGLXexts
;
1325 _GLX_PUBLIC
const char *
1326 glXGetClientString(Display
* dpy
, int name
)
1332 return (__glXGLXClientVendorName
);
1334 return (__glXGLXClientVersion
);
1335 case GLX_EXTENSIONS
:
1336 return (__glXGetClientExtensions());
1342 _GLX_PUBLIC
const char *
1343 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1345 struct glx_screen
*psc
;
1346 struct glx_display
*priv
;
1350 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1356 str
= &priv
->serverGLXvendor
;
1359 str
= &priv
->serverGLXversion
;
1361 case GLX_EXTENSIONS
:
1362 str
= &psc
->serverGLXexts
;
1369 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1377 ** EXT_import_context
1380 _GLX_PUBLIC Display
*
1381 glXGetCurrentDisplay(void)
1383 struct glx_context
*gc
= __glXGetCurrentContext();
1384 if (gc
== &dummyContext
)
1386 return gc
->currentDpy
;
1390 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1391 glXGetCurrentDisplay
)
1393 #ifndef GLX_USE_APPLEGL
1394 _GLX_PUBLIC GLXContext
1395 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1397 struct glx_display
*priv
= __glXInitialize(dpy
);
1398 struct glx_screen
*psc
= NULL
;
1399 xGLXQueryContextReply reply
;
1401 struct glx_context
*ctx
;
1402 int i
, renderType
= GLX_RGBA_TYPE
; /* By default, assume RGBA context */
1404 struct glx_config
*mode
= NULL
;
1405 uint32_t fbconfigID
= 0;
1406 uint32_t visualID
= 0;
1407 uint32_t screen
= 0;
1408 Bool got_screen
= False
;
1413 /* The GLX_EXT_import_context spec says:
1415 * "If <contextID> does not refer to a valid context, then a BadContext
1416 * error is generated; if <contextID> refers to direct rendering
1417 * context then no error is generated but glXImportContextEXT returns
1420 * If contextID is None, generate BadContext on the client-side. Other
1421 * sorts of invalid contexts will be detected by the server in the
1422 * __glXIsDirect call.
1424 if (contextID
== None
) {
1425 __glXSendError(dpy
, GLXBadContext
, contextID
, X_GLXIsDirect
, false);
1429 if (__glXIsDirect(dpy
, contextID
))
1432 opcode
= __glXSetupForCommand(dpy
);
1436 /* Send the glXQueryContextInfoEXT request */
1439 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1440 xGLXQueryContextReq
*req
;
1442 GetReq(GLXQueryContext
, req
);
1444 req
->reqType
= opcode
;
1445 req
->glxCode
= X_GLXQueryContext
;
1446 req
->context
= contextID
;
1449 xGLXVendorPrivateReq
*vpreq
;
1450 xGLXQueryContextInfoEXTReq
*req
;
1452 GetReqExtra(GLXVendorPrivate
,
1453 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1455 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1456 req
->reqType
= opcode
;
1457 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1458 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1459 req
->context
= contextID
;
1462 if (_XReply(dpy
, (xReply
*) & reply
, 0, False
) &&
1463 reply
.n
< (INT32_MAX
/ 2)) {
1465 for (i
= 0; i
< reply
.n
* 2; i
++) {
1468 _XRead(dpy
, (char *)prop
, sizeof(prop
));
1474 case GLX_SHARE_CONTEXT_EXT
:
1477 case GLX_VISUAL_ID_EXT
:
1480 case GLX_FBCONFIG_ID
:
1481 fbconfigID
= prop
[1];
1483 case GLX_RENDER_TYPE
:
1484 renderType
= prop
[1];
1495 psc
= GetGLXScreenConfigs(dpy
, screen
);
1499 if (fbconfigID
!= 0) {
1500 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1501 } else if (visualID
!= 0) {
1502 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1508 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1512 ctx
->xid
= contextID
;
1513 ctx
->imported
= GL_TRUE
;
1514 ctx
->share_xid
= share
;
1516 return (GLXContext
) ctx
;
1522 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1524 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1526 switch (attribute
) {
1527 case GLX_SHARE_CONTEXT_EXT
:
1528 *value
= ctx
->share_xid
;
1530 case GLX_VISUAL_ID_EXT
:
1531 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1534 *value
= ctx
->screen
;
1536 case GLX_FBCONFIG_ID
:
1537 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1539 case GLX_RENDER_TYPE
:
1540 *value
= ctx
->renderType
;
1543 return GLX_BAD_ATTRIBUTE
;
1549 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1550 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1551 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1553 _GLX_PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1555 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1557 return (ctx
== NULL
) ? None
: ctx
->xid
;
1561 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1563 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1565 if (gc
== NULL
|| gc
->xid
== None
)
1568 /* The GLX_EXT_import_context spec says:
1570 * "glXFreeContext does not free the server-side context information or
1571 * the XID associated with the server-side context."
1573 * Don't send any protocol. Just destroy the client-side tracking of the
1574 * context. Also, only release the context structure if it's not current.
1577 if (gc
->currentDpy
) {
1580 gc
->vtable
->destroy(gc
);
1585 _GLX_PUBLIC GLXFBConfig
*
1586 glXChooseFBConfig(Display
* dpy
, int screen
,
1587 const int *attribList
, int *nitems
)
1589 struct glx_config
**config_list
;
1593 config_list
= (struct glx_config
**)
1594 glXGetFBConfigs(dpy
, screen
, &list_size
);
1596 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1597 list_size
= choose_fbconfig(config_list
, list_size
, attribList
);
1598 if (list_size
== 0) {
1604 *nitems
= list_size
;
1605 return (GLXFBConfig
*) config_list
;
1609 _GLX_PUBLIC GLXContext
1610 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1611 int renderType
, GLXContext shareList
, Bool allowDirect
)
1613 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1614 struct glx_config
**config_list
;
1619 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1623 config_list
= (struct glx_config
**)
1624 glXGetFBConfigs(dpy
, config
->screen
, &list_size
);
1626 for (i
= 0; i
< list_size
; i
++) {
1627 if (config_list
[i
] == config
)
1632 if (i
== list_size
) {
1633 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1637 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1638 allowDirect
, X_GLXCreateNewContext
, renderType
,
1643 _GLX_PUBLIC GLXDrawable
1644 glXGetCurrentReadDrawable(void)
1646 struct glx_context
*gc
= __glXGetCurrentContext();
1648 return gc
->currentReadable
;
1652 _GLX_PUBLIC GLXFBConfig
*
1653 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1655 struct glx_display
*priv
= __glXInitialize(dpy
);
1656 struct glx_config
**config_list
= NULL
;
1657 struct glx_config
*config
;
1658 unsigned num_configs
= 0;
1662 if (priv
&& (priv
->screens
!= NULL
)
1663 && (screen
>= 0) && (screen
< ScreenCount(dpy
))
1664 && (priv
->screens
[screen
]->configs
!= NULL
)
1665 && (priv
->screens
[screen
]->configs
->fbconfigID
1666 != (int) GLX_DONT_CARE
)) {
1668 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1669 config
= config
->next
) {
1670 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1675 config_list
= malloc(num_configs
* sizeof *config_list
);
1676 if (config_list
!= NULL
) {
1677 *nelements
= num_configs
;
1679 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1680 config
= config
->next
) {
1681 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1682 config_list
[i
] = config
;
1689 return (GLXFBConfig
*) config_list
;
1694 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1695 int attribute
, int *value
)
1697 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1700 return GLXBadFBConfig
;
1702 return glx_config_get(config
, attribute
, value
);
1706 _GLX_PUBLIC XVisualInfo
*
1707 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1709 XVisualInfo visualTemplate
;
1710 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1714 ** Get a list of all visuals, return if list is empty
1716 visualTemplate
.visualid
= config
->visualID
;
1717 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1720 #ifndef GLX_USE_APPLEGL
1722 ** GLX_SGI_swap_control
1725 __glXSwapIntervalSGI(int interval
)
1727 xGLXVendorPrivateReq
*req
;
1728 struct glx_context
*gc
= __glXGetCurrentContext();
1729 struct glx_screen
*psc
;
1731 CARD32
*interval_ptr
;
1734 if (gc
== &dummyContext
) {
1735 return GLX_BAD_CONTEXT
;
1738 if (interval
<= 0) {
1739 return GLX_BAD_VALUE
;
1742 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1744 #ifdef GLX_DIRECT_RENDERING
1745 if (gc
->isDirect
&& psc
&& psc
->driScreen
&&
1746 psc
->driScreen
->setSwapInterval
) {
1747 __GLXDRIdrawable
*pdraw
=
1748 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1749 /* Simply ignore the command if the GLX drawable has been destroyed but
1750 * the context is still bound.
1753 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1758 dpy
= gc
->currentDpy
;
1759 opcode
= __glXSetupForCommand(dpy
);
1764 /* Send the glXSwapIntervalSGI request */
1766 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1767 req
->reqType
= opcode
;
1768 req
->glxCode
= X_GLXVendorPrivate
;
1769 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1770 req
->contextTag
= gc
->currentContextTag
;
1772 interval_ptr
= (CARD32
*) (req
+ 1);
1773 *interval_ptr
= interval
;
1784 ** GLX_MESA_swap_control
1787 __glXSwapIntervalMESA(unsigned int interval
)
1789 #ifdef GLX_DIRECT_RENDERING
1790 struct glx_context
*gc
= __glXGetCurrentContext();
1792 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1793 struct glx_screen
*psc
;
1795 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1796 if (psc
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1797 __GLXDRIdrawable
*pdraw
=
1798 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1800 /* Simply ignore the command if the GLX drawable has been destroyed but
1801 * the context is still bound.
1806 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1811 return GLX_BAD_CONTEXT
;
1816 __glXGetSwapIntervalMESA(void)
1818 #ifdef GLX_DIRECT_RENDERING
1819 struct glx_context
*gc
= __glXGetCurrentContext();
1821 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1822 struct glx_screen
*psc
;
1824 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1825 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1826 __GLXDRIdrawable
*pdraw
=
1827 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1829 return psc
->driScreen
->getSwapInterval(pdraw
);
1839 ** GLX_SGI_video_sync
1842 __glXGetVideoSyncSGI(unsigned int *count
)
1844 int64_t ust
, msc
, sbc
;
1846 struct glx_context
*gc
= __glXGetCurrentContext();
1847 struct glx_screen
*psc
;
1848 #ifdef GLX_DIRECT_RENDERING
1849 __GLXDRIdrawable
*pdraw
;
1852 if (gc
== &dummyContext
)
1853 return GLX_BAD_CONTEXT
;
1855 #ifdef GLX_DIRECT_RENDERING
1857 return GLX_BAD_CONTEXT
;
1860 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1861 #ifdef GLX_DIRECT_RENDERING
1862 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1865 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1866 * FIXME: there should be a GLX encoding for this call. I can find no
1867 * FIXME: documentation for the GLX encoding.
1869 #ifdef GLX_DIRECT_RENDERING
1870 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1871 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1872 *count
= (unsigned) msc
;
1873 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1877 return GLX_BAD_CONTEXT
;
1881 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1883 struct glx_context
*gc
= __glXGetCurrentContext();
1884 struct glx_screen
*psc
;
1885 #ifdef GLX_DIRECT_RENDERING
1886 __GLXDRIdrawable
*pdraw
;
1888 int64_t ust
, msc
, sbc
;
1891 if (divisor
<= 0 || remainder
< 0)
1892 return GLX_BAD_VALUE
;
1894 if (gc
== &dummyContext
)
1895 return GLX_BAD_CONTEXT
;
1897 #ifdef GLX_DIRECT_RENDERING
1899 return GLX_BAD_CONTEXT
;
1902 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1903 #ifdef GLX_DIRECT_RENDERING
1904 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1907 #ifdef GLX_DIRECT_RENDERING
1908 if (psc
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1909 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1911 *count
= (unsigned) msc
;
1912 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1916 return GLX_BAD_CONTEXT
;
1919 #endif /* GLX_USE_APPLEGL */
1922 ** GLX_SGIX_fbconfig
1923 ** Many of these functions are aliased to GLX 1.3 entry points in the
1924 ** GLX_functions table.
1928 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1929 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1930 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1932 _GLX_PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1933 (Display
* dpy
, int screen
, int *attrib_list
,
1934 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1937 _GLX_PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1938 (Display
* dpy
, GLXFBConfigSGIX config
),
1939 (dpy
, config
), glXGetVisualFromFBConfig
)
1941 _GLX_PUBLIC GLXPixmap
1942 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1943 GLXFBConfigSGIX fbconfig
,
1946 #ifndef GLX_USE_APPLEGL
1947 xGLXVendorPrivateWithReplyReq
*vpreq
;
1948 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1949 GLXPixmap xid
= None
;
1951 struct glx_screen
*psc
;
1953 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1956 if ((dpy
== NULL
) || (config
== NULL
)) {
1959 #ifdef GLX_USE_APPLEGL
1960 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1965 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1967 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1968 opcode
= __glXSetupForCommand(dpy
);
1973 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1975 GetReqExtra(GLXVendorPrivateWithReply
,
1976 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1977 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1978 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1979 req
->reqType
= opcode
;
1980 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1981 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1982 req
->screen
= config
->screen
;
1983 req
->fbconfig
= config
->fbconfigID
;
1984 req
->pixmap
= pixmap
;
1985 req
->glxpixmap
= xid
= XAllocID(dpy
);
1994 _GLX_PUBLIC GLXContext
1995 glXCreateContextWithConfigSGIX(Display
* dpy
,
1996 GLXFBConfigSGIX fbconfig
, int renderType
,
1997 GLXContext shareList
, Bool allowDirect
)
1999 GLXContext gc
= NULL
;
2000 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2001 struct glx_screen
*psc
;
2004 if ((dpy
== NULL
) || (config
== NULL
)) {
2008 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2010 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2011 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2013 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2021 _GLX_PUBLIC GLXFBConfigSGIX
2022 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2024 struct glx_display
*priv
;
2025 struct glx_screen
*psc
= NULL
;
2027 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2028 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2029 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2030 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2037 #ifndef GLX_USE_APPLEGL
2039 ** GLX_SGIX_swap_group
2042 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2052 ** GLX_SGIX_swap_barrier
2055 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2063 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2073 ** GLX_OML_sync_control
2076 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2077 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2079 struct glx_display
* const priv
= __glXInitialize(dpy
);
2081 #ifdef GLX_DIRECT_RENDERING
2082 __GLXDRIdrawable
*pdraw
;
2084 struct glx_screen
*psc
;
2089 #ifdef GLX_DIRECT_RENDERING
2090 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2091 psc
= pdraw
? pdraw
->psc
: NULL
;
2092 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2093 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2101 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2103 __glxGetMscRate(struct glx_screen
*psc
,
2104 int32_t * numerator
, int32_t * denominator
)
2107 XF86VidModeModeLine mode_line
;
2111 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2112 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2113 unsigned n
= dot_clock
* 1000;
2114 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2116 # define V_INTERLACE 0x010
2117 # define V_DBLSCAN 0x020
2119 if (mode_line
.flags
& V_INTERLACE
)
2121 else if (mode_line
.flags
& V_DBLSCAN
)
2124 /* The OML_sync_control spec requires that if the refresh rate is a
2125 * whole number, that the returned numerator be equal to the refresh
2126 * rate and the denominator be 1.
2134 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2136 /* This is a poor man's way to reduce a fraction. It's far from
2137 * perfect, but it will work well enough for this situation.
2140 for (i
= 0; f
[i
] != 0; i
++) {
2141 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2161 * Determine the refresh rate of the specified drawable and display.
2163 * \param dpy Display whose refresh rate is to be determined.
2164 * \param drawable Drawable whose refresh rate is to be determined.
2165 * \param numerator Numerator of the refresh rate.
2166 * \param demoninator Denominator of the refresh rate.
2167 * \return If the refresh rate for the specified display and drawable could
2168 * be calculated, True is returned. Otherwise False is returned.
2170 * \note This function is implemented entirely client-side. A lot of other
2171 * functionality is required to export GLX_OML_sync_control, so on
2172 * XFree86 this function can be called for direct-rendering contexts
2173 * when GLX_OML_sync_control appears in the client extension string.
2177 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2178 int32_t * numerator
, int32_t * denominator
)
2180 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2181 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2186 return __glxGetMscRate(draw
->psc
, numerator
, denominator
);
2198 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2199 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2201 struct glx_context
*gc
= __glXGetCurrentContext();
2202 #ifdef GLX_DIRECT_RENDERING
2203 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2204 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2207 if (gc
== &dummyContext
) /* no GLX for this */
2210 #ifdef GLX_DIRECT_RENDERING
2211 if (!pdraw
|| !gc
->isDirect
)
2215 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2216 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2217 * of -1 if the function failed because of errors detected in the input
2220 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2222 if (divisor
> 0 && remainder
>= divisor
)
2225 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2228 #ifdef GLX_DIRECT_RENDERING
2229 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2230 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2239 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2240 int64_t target_msc
, int64_t divisor
,
2241 int64_t remainder
, int64_t * ust
,
2242 int64_t * msc
, int64_t * sbc
)
2244 #ifdef GLX_DIRECT_RENDERING
2245 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2246 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2251 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2252 * error", but the return type in the spec is Bool.
2254 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2256 if (divisor
> 0 && remainder
>= divisor
)
2259 #ifdef GLX_DIRECT_RENDERING
2260 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2261 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2272 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2273 int64_t target_sbc
, int64_t * ust
,
2274 int64_t * msc
, int64_t * sbc
)
2276 #ifdef GLX_DIRECT_RENDERING
2277 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2278 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2282 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2283 * error", but the return type in the spec is Bool.
2288 #ifdef GLX_DIRECT_RENDERING
2289 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2290 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2302 * Mesa extension stubs. These will help reduce portability problems.
2307 * Release all buffers associated with the specified GLX drawable.
2310 * This function was intended for stand-alone Mesa. The issue there is that
2311 * the library doesn't get any notification when a window is closed. In
2312 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2313 * supported, there are 3 different functions to destroy a drawable. It
2314 * should be possible to create GLX protocol (or have it determine which
2315 * protocol to use based on the type of the drawable) to have one function
2316 * do the work of 3. For the direct-rendering case, this function could
2317 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2318 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2319 * would need to be used. This really should be done as part of the new DRI
2322 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2323 * __driGarbageCollectDrawables
2324 * glXDestroyGLXPixmap
2325 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2326 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2329 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2337 _GLX_PUBLIC GLXPixmap
2338 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2339 Pixmap pixmap
, Colormap cmap
)
2352 * GLX_MESA_copy_sub_buffer
2354 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2356 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2357 int x
, int y
, int width
, int height
)
2359 xGLXVendorPrivateReq
*req
;
2360 struct glx_context
*gc
;
2362 CARD32
*drawable_ptr
;
2363 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2366 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2367 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2368 if (pdraw
!= NULL
) {
2369 struct glx_screen
*psc
= pdraw
->psc
;
2370 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2371 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
, True
);
2378 opcode
= __glXSetupForCommand(dpy
);
2383 ** The calling thread may or may not have a current context. If it
2384 ** does, send the context tag so the server can do a flush.
2386 gc
= __glXGetCurrentContext();
2387 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
2388 ((drawable
== gc
->currentDrawable
) ||
2389 (drawable
== gc
->currentReadable
))) {
2390 tag
= gc
->currentContextTag
;
2397 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2398 req
->reqType
= opcode
;
2399 req
->glxCode
= X_GLXVendorPrivate
;
2400 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2401 req
->contextTag
= tag
;
2403 drawable_ptr
= (CARD32
*) (req
+ 1);
2404 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2405 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2406 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2407 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2409 *drawable_ptr
= drawable
;
2421 __glXBindTexImageEXT(Display
* dpy
,
2422 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2424 struct glx_context
*gc
= __glXGetCurrentContext();
2426 if (gc
->vtable
->bind_tex_image
== NULL
)
2429 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2433 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2435 struct glx_context
*gc
= __glXGetCurrentContext();
2437 if (gc
->vtable
->release_tex_image
== NULL
)
2440 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2445 #endif /* GLX_USE_APPLEGL */
2448 ** glXGetProcAddress support
2451 struct name_address_pair
2457 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2458 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2460 static const struct name_address_pair GLX_functions
[] = {
2461 /*** GLX_VERSION_1_0 ***/
2462 GLX_FUNCTION(glXChooseVisual
),
2463 GLX_FUNCTION(glXCopyContext
),
2464 GLX_FUNCTION(glXCreateContext
),
2465 GLX_FUNCTION(glXCreateGLXPixmap
),
2466 GLX_FUNCTION(glXDestroyContext
),
2467 GLX_FUNCTION(glXDestroyGLXPixmap
),
2468 GLX_FUNCTION(glXGetConfig
),
2469 GLX_FUNCTION(glXGetCurrentContext
),
2470 GLX_FUNCTION(glXGetCurrentDrawable
),
2471 GLX_FUNCTION(glXIsDirect
),
2472 GLX_FUNCTION(glXMakeCurrent
),
2473 GLX_FUNCTION(glXQueryExtension
),
2474 GLX_FUNCTION(glXQueryVersion
),
2475 GLX_FUNCTION(glXSwapBuffers
),
2476 GLX_FUNCTION(glXUseXFont
),
2477 GLX_FUNCTION(glXWaitGL
),
2478 GLX_FUNCTION(glXWaitX
),
2480 /*** GLX_VERSION_1_1 ***/
2481 GLX_FUNCTION(glXGetClientString
),
2482 GLX_FUNCTION(glXQueryExtensionsString
),
2483 GLX_FUNCTION(glXQueryServerString
),
2485 /*** GLX_VERSION_1_2 ***/
2486 GLX_FUNCTION(glXGetCurrentDisplay
),
2488 /*** GLX_VERSION_1_3 ***/
2489 GLX_FUNCTION(glXChooseFBConfig
),
2490 GLX_FUNCTION(glXCreateNewContext
),
2491 GLX_FUNCTION(glXCreatePbuffer
),
2492 GLX_FUNCTION(glXCreatePixmap
),
2493 GLX_FUNCTION(glXCreateWindow
),
2494 GLX_FUNCTION(glXDestroyPbuffer
),
2495 GLX_FUNCTION(glXDestroyPixmap
),
2496 GLX_FUNCTION(glXDestroyWindow
),
2497 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2498 GLX_FUNCTION(glXGetFBConfigAttrib
),
2499 GLX_FUNCTION(glXGetFBConfigs
),
2500 GLX_FUNCTION(glXGetSelectedEvent
),
2501 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2502 GLX_FUNCTION(glXMakeContextCurrent
),
2503 GLX_FUNCTION(glXQueryContext
),
2504 GLX_FUNCTION(glXQueryDrawable
),
2505 GLX_FUNCTION(glXSelectEvent
),
2507 #ifndef GLX_USE_APPLEGL
2508 /*** GLX_SGI_swap_control ***/
2509 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2511 /*** GLX_SGI_video_sync ***/
2512 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2513 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2515 /*** GLX_SGI_make_current_read ***/
2516 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2517 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2519 /*** GLX_EXT_import_context ***/
2520 GLX_FUNCTION(glXFreeContextEXT
),
2521 GLX_FUNCTION(glXGetContextIDEXT
),
2522 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2523 GLX_FUNCTION(glXImportContextEXT
),
2524 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2527 /*** GLX_SGIX_fbconfig ***/
2528 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2529 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2530 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2531 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2532 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2533 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2535 #ifndef GLX_USE_APPLEGL
2536 /*** GLX_SGIX_pbuffer ***/
2537 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2538 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2539 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2540 GLX_FUNCTION(glXSelectEventSGIX
),
2541 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2543 /*** GLX_SGIX_swap_group ***/
2544 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2546 /*** GLX_SGIX_swap_barrier ***/
2547 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2548 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2550 /*** GLX_MESA_copy_sub_buffer ***/
2551 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2553 /*** GLX_MESA_pixmap_colormap ***/
2554 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2556 /*** GLX_MESA_release_buffers ***/
2557 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2559 /*** GLX_MESA_swap_control ***/
2560 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2561 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2564 /*** GLX_ARB_get_proc_address ***/
2565 GLX_FUNCTION(glXGetProcAddressARB
),
2568 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2570 #ifndef GLX_USE_APPLEGL
2571 /*** GLX_OML_sync_control ***/
2572 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2573 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2574 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2575 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2576 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2578 /*** GLX_EXT_texture_from_pixmap ***/
2579 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2580 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2583 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
2584 /*** DRI configuration ***/
2585 GLX_FUNCTION(glXGetScreenDriver
),
2586 GLX_FUNCTION(glXGetDriverConfig
),
2589 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2590 GLX_FUNCTION(glXCreateContextAttribsARB
),
2592 /*** GLX_MESA_query_renderer ***/
2593 GLX_FUNCTION(glXQueryRendererIntegerMESA
),
2594 GLX_FUNCTION(glXQueryRendererStringMESA
),
2595 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA
),
2596 GLX_FUNCTION(glXQueryCurrentRendererStringMESA
),
2598 {NULL
, NULL
} /* end of list */
2601 static const GLvoid
*
2602 get_glx_proc_address(const char *funcName
)
2606 /* try static functions */
2607 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2608 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2609 return GLX_functions
[i
].Address
;
2616 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2617 * \c glXGetProcAddress.
2619 * \param procName Name of a GL or GLX function.
2620 * \returns A pointer to the named function
2622 * \sa glXGetProcAddress
2624 _GLX_PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2626 typedef void (*gl_function
) (void);
2630 /* Search the table of GLX and internal functions first. If that
2631 * fails and the supplied name could be a valid core GL name, try
2632 * searching the core GL function table. This check is done to prevent
2633 * DRI based drivers from searching the core GL function table for
2634 * internal API functions.
2636 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2637 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2638 && (procName
[2] != 'X')) {
2639 #ifdef GLX_INDIRECT_RENDERING
2640 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2643 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2645 struct glx_context
*gc
= __glXGetCurrentContext();
2647 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2648 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2655 * Get the address of a named GL function. This is the GLX 1.4 name for
2656 * \c glXGetProcAddressARB.
2658 * \param procName Name of a GL or GLX function.
2659 * \returns A pointer to the named function
2661 * \sa glXGetProcAddressARB
2664 GLX_ALIAS(__GLXextFuncPtr
, glXGetProcAddress
,
2665 (const GLubyte
* procName
),
2666 (procName
), glXGetProcAddressARB
)
2668 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2670 * Get the unadjusted system time (UST). Currently, the UST is measured in
2671 * microseconds since Epoc. The actual resolution of the UST may vary from
2672 * system to system, and the units may vary from release to release.
2673 * Drivers should not call this function directly. They should instead use
2674 * \c glXGetProcAddress to obtain a pointer to the function.
2676 * \param ust Location to store the 64-bit UST
2677 * \returns Zero on success or a negative errno value on failure.
2679 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2681 * \since Internal API version 20030317.
2684 __glXGetUST(int64_t * ust
)
2692 if (gettimeofday(&tv
, NULL
) == 0) {
2693 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2700 #endif /* GLX_DIRECT_RENDERING */
2702 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2705 MesaGLInteropGLXQueryDeviceInfo(Display
*dpy
, GLXContext context
,
2706 struct mesa_glinterop_device_info
*out
)
2708 struct glx_context
*gc
= (struct glx_context
*)context
;
2713 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2715 return MESA_GLINTEROP_INVALID_CONTEXT
;
2718 if (!gc
->vtable
->interop_query_device_info
) {
2720 return MESA_GLINTEROP_UNSUPPORTED
;
2723 ret
= gc
->vtable
->interop_query_device_info(gc
, out
);
2729 MesaGLInteropGLXExportObject(Display
*dpy
, GLXContext context
,
2730 struct mesa_glinterop_export_in
*in
,
2731 struct mesa_glinterop_export_out
*out
)
2733 struct glx_context
*gc
= (struct glx_context
*)context
;
2738 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2740 return MESA_GLINTEROP_INVALID_CONTEXT
;
2743 if (!gc
->vtable
->interop_export_object
) {
2745 return MESA_GLINTEROP_UNSUPPORTED
;
2748 ret
= gc
->vtable
->interop_export_object(gc
, in
, out
);
2753 #endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */