2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
40 #include "glx_error.h"
42 #ifdef GLX_DIRECT_RENDERING
43 #ifdef GLX_USE_APPLEGL
44 #include "apple/apple_glx_context.h"
45 #include "apple/apple_glx.h"
46 #include "util/debug.h"
50 #include <X11/extensions/xf86vmode.h>
55 #include <X11/Xlib-xcb.h>
58 #include "GL/mesa_glinterop.h"
60 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
61 static const char __glXGLXClientVersion
[] = "1.4";
63 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
66 * Get the __DRIdrawable for the drawable associated with a GLXContext
68 * \param dpy The display associated with \c drawable.
69 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
70 * \param scrn_num If non-NULL, the drawables screen is stored there
71 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
72 * the drawable is not associated with a direct-rendering context.
74 _X_HIDDEN __GLXDRIdrawable
*
75 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
77 struct glx_display
*priv
= __glXInitialize(dpy
);
78 __GLXDRIdrawable
*pdraw
;
83 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
91 _X_HIDDEN
struct glx_drawable
*
92 GetGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
94 struct glx_display
*priv
= __glXInitialize(dpy
);
95 struct glx_drawable
*glxDraw
;
100 if (__glxHashLookup(priv
->glXDrawHash
, drawable
, (void *) &glxDraw
) == 0)
107 InitGLXDrawable(Display
*dpy
, struct glx_drawable
*glxDraw
, XID xDrawable
,
108 GLXDrawable drawable
)
110 struct glx_display
*priv
= __glXInitialize(dpy
);
115 glxDraw
->xDrawable
= xDrawable
;
116 glxDraw
->drawable
= drawable
;
117 glxDraw
->lastEventSbc
= 0;
118 glxDraw
->eventSbcWrap
= 0;
120 return __glxHashInsert(priv
->glXDrawHash
, drawable
, glxDraw
);
124 DestroyGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
126 struct glx_display
*priv
= __glXInitialize(dpy
);
127 struct glx_drawable
*glxDraw
;
132 glxDraw
= GetGLXDrawable(dpy
, drawable
);
133 __glxHashDelete(priv
->glXDrawHash
, drawable
);
138 * Get the GLX per-screen data structure associated with a GLX context.
140 * \param dpy Display for which the GLX per-screen information is to be
142 * \param scrn Screen on \c dpy for which the GLX per-screen information is
144 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
145 * specify a valid GLX screen, or NULL otherwise.
147 * \todo Should this function validate that \c scrn is within the screen
148 * number range for \c dpy?
151 _X_HIDDEN
struct glx_screen
*
152 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
154 struct glx_display
*const priv
= __glXInitialize(dpy
);
158 NULL
) ? priv
->screens
[scrn
] : NULL
;
163 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
164 struct glx_screen
** ppsc
)
166 /* Initialize the extension, if needed . This has the added value
167 * of initializing/allocating the display private
171 return GLX_NO_EXTENSION
;
174 *ppriv
= __glXInitialize(dpy
);
175 if (*ppriv
== NULL
) {
176 return GLX_NO_EXTENSION
;
179 /* Check screen number to see if its valid */
180 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
181 return GLX_BAD_SCREEN
;
184 /* Check to see if the GL is supported on this screen */
185 *ppsc
= (*ppriv
)->screens
[scrn
];
186 if ((*ppsc
)->configs
== NULL
&& (*ppsc
)->visuals
== NULL
) {
187 /* No support for GL on this screen regardless of visual */
188 return GLX_BAD_VISUAL
;
196 * Determine if a \c GLXFBConfig supplied by the application is valid.
198 * \param dpy Application supplied \c Display pointer.
199 * \param config Application supplied \c GLXFBConfig.
201 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
202 * \c struct glx_config structure is returned. Otherwise, \c NULL
205 static struct glx_config
*
206 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
208 struct glx_display
*const priv
= __glXInitialize(dpy
);
209 int num_screens
= ScreenCount(dpy
);
211 struct glx_config
*config
;
214 for (i
= 0; i
< num_screens
; i
++) {
215 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
216 config
= config
->next
) {
217 if (config
== (struct glx_config
*) fbconfig
) {
228 * Verifies context's GLX_RENDER_TYPE value with config.
230 * \param config GLX FBConfig which will support the returned renderType.
231 * \param renderType The context render type to be verified.
232 * \return True if the value of context renderType was approved, or 0 if no
233 * valid value was found.
236 validate_renderType_against_config(const struct glx_config
*config
,
239 /* GLX_EXT_no_config_context supports any render type */
243 switch (renderType
) {
245 return (config
->renderType
& GLX_RGBA_BIT
) != 0;
246 case GLX_COLOR_INDEX_TYPE
:
247 return (config
->renderType
& GLX_COLOR_INDEX_BIT
) != 0;
248 case GLX_RGBA_FLOAT_TYPE_ARB
:
249 return (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) != 0;
250 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
:
251 return (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) != 0;
259 glx_context_init(struct glx_context
*gc
,
260 struct glx_screen
*psc
, struct glx_config
*config
)
262 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
263 if (!gc
->majorOpcode
)
266 gc
->screen
= psc
->scr
;
269 gc
->isDirect
= GL_TRUE
;
270 gc
->currentContextTag
= -1;
277 * Create a new context.
279 * \param renderType For FBConfigs, what is the rendering type?
283 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
284 GLXContext shareList_user
, Bool allowDirect
,
285 unsigned code
, int renderType
, int screen
)
287 struct glx_context
*gc
;
288 struct glx_screen
*psc
;
289 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
293 psc
= GetGLXScreenConfigs(dpy
, screen
);
297 if (generic_id
== None
)
301 #ifdef GLX_USE_APPLEGL
302 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
304 if (allowDirect
&& psc
->vtable
->create_context
)
305 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
307 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
314 case X_GLXCreateContext
: {
315 xGLXCreateContextReq
*req
;
317 /* Send the glXCreateContext request */
318 GetReq(GLXCreateContext
, req
);
319 req
->reqType
= gc
->majorOpcode
;
320 req
->glxCode
= X_GLXCreateContext
;
321 req
->context
= gc
->xid
= XAllocID(dpy
);
322 req
->visual
= generic_id
;
323 req
->screen
= screen
;
324 req
->shareList
= shareList
? shareList
->xid
: None
;
325 req
->isDirect
= gc
->isDirect
;
329 case X_GLXCreateNewContext
: {
330 xGLXCreateNewContextReq
*req
;
332 /* Send the glXCreateNewContext request */
333 GetReq(GLXCreateNewContext
, req
);
334 req
->reqType
= gc
->majorOpcode
;
335 req
->glxCode
= X_GLXCreateNewContext
;
336 req
->context
= gc
->xid
= XAllocID(dpy
);
337 req
->fbconfig
= generic_id
;
338 req
->screen
= screen
;
339 req
->renderType
= renderType
;
340 req
->shareList
= shareList
? shareList
->xid
: None
;
341 req
->isDirect
= gc
->isDirect
;
345 case X_GLXvop_CreateContextWithConfigSGIX
: {
346 xGLXVendorPrivateWithReplyReq
*vpreq
;
347 xGLXCreateContextWithConfigSGIXReq
*req
;
349 /* Send the glXCreateNewContext request */
350 GetReqExtra(GLXVendorPrivateWithReply
,
351 sz_xGLXCreateContextWithConfigSGIXReq
-
352 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
353 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
354 req
->reqType
= gc
->majorOpcode
;
355 req
->glxCode
= X_GLXVendorPrivateWithReply
;
356 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
357 req
->context
= gc
->xid
= XAllocID(dpy
);
358 req
->fbconfig
= generic_id
;
359 req
->screen
= screen
;
360 req
->renderType
= renderType
;
361 req
->shareList
= shareList
? shareList
->xid
: None
;
362 req
->isDirect
= gc
->isDirect
;
367 /* What to do here? This case is the sign of an internal error. It
368 * should never be reachable.
376 gc
->share_xid
= shareList
? shareList
->xid
: None
;
377 gc
->imported
= GL_FALSE
;
379 return (GLXContext
) gc
;
382 _GLX_PUBLIC GLXContext
383 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
384 GLXContext shareList
, Bool allowDirect
)
386 struct glx_config
*config
= NULL
;
387 int renderType
= GLX_RGBA_TYPE
;
389 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
390 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
393 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
395 if (config
== NULL
) {
396 __glXSendError(dpy
, BadValue
, vis
->visualid
, X_GLXCreateContext
, True
);
400 /* Choose the context render type based on DRI config values. It is
401 * unusual to set this type from config, but we have no other choice, as
402 * this old API does not provide renderType parameter.
404 if (config
->renderType
& GLX_RGBA_FLOAT_BIT_ARB
) {
405 renderType
= GLX_RGBA_FLOAT_TYPE_ARB
;
406 } else if (config
->renderType
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) {
407 renderType
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
408 } else if (config
->renderType
& GLX_RGBA_BIT
) {
409 renderType
= GLX_RGBA_TYPE
;
410 } else if (config
->renderType
& GLX_COLOR_INDEX_BIT
) {
411 renderType
= GLX_COLOR_INDEX_TYPE
;
412 } else if (config
->rgbMode
) {
413 /* If we're here, then renderType is not set correctly. Let's use a
414 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
415 * default value is needed by old DRI drivers, which didn't set
416 * renderType correctly as the value was just ignored.
418 renderType
= GLX_RGBA_TYPE
;
420 /* Safeguard - only one option left, all non-RGB modes are indexed
421 * modes. Again, this allows drivers with invalid renderType to work
424 renderType
= GLX_COLOR_INDEX_TYPE
;
428 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
429 X_GLXCreateContext
, renderType
, vis
->screen
);
433 glx_send_destroy_context(Display
*dpy
, XID xid
)
435 CARD8 opcode
= __glXSetupForCommand(dpy
);
436 xGLXDestroyContextReq
*req
;
439 GetReq(GLXDestroyContext
, req
);
440 req
->reqType
= opcode
;
441 req
->glxCode
= X_GLXDestroyContext
;
448 ** Destroy the named context
452 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
454 struct glx_context
*gc
= (struct glx_context
*) ctx
;
456 if (gc
== NULL
|| gc
->xid
== None
)
461 glx_send_destroy_context(dpy
, gc
->xid
);
463 if (gc
->currentDpy
) {
464 /* This context is bound to some thread. According to the man page,
465 * we should not actually delete the context until it's unbound.
466 * Note that we set gc->xid = None above. In MakeContextCurrent()
467 * we check for that and delete the context there.
471 gc
->vtable
->destroy(gc
);
477 ** Return the major and minor version #s for the GLX extension
480 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
482 struct glx_display
*priv
;
484 /* Init the extension. This fetches the major and minor version. */
485 priv
= __glXInitialize(dpy
);
490 *major
= priv
->majorVersion
;
492 *minor
= priv
->minorVersion
;
497 ** Query the existence of the GLX extension
500 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
502 int major_op
, erb
, evb
;
505 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
516 ** Put a barrier in the token stream that forces the GL to finish its
517 ** work before X can proceed.
522 struct glx_context
*gc
= __glXGetCurrentContext();
524 if (gc
->vtable
->wait_gl
)
525 gc
->vtable
->wait_gl(gc
);
529 ** Put a barrier in the token stream that forces X to finish its
530 ** work before GL can proceed.
535 struct glx_context
*gc
= __glXGetCurrentContext();
537 if (gc
->vtable
->wait_x
)
538 gc
->vtable
->wait_x(gc
);
542 glXUseXFont(Font font
, int first
, int count
, int listBase
)
544 struct glx_context
*gc
= __glXGetCurrentContext();
546 if (gc
->vtable
->use_x_font
)
547 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
550 /************************************************************************/
553 ** Copy the source context to the destination context using the
557 glXCopyContext(Display
* dpy
, GLXContext source_user
,
558 GLXContext dest_user
, unsigned long mask
)
560 struct glx_context
*source
= (struct glx_context
*) source_user
;
561 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
562 #ifdef GLX_USE_APPLEGL
563 struct glx_context
*gc
= __glXGetCurrentContext();
567 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
568 mask
, &errorcode
, &x11error
)) {
569 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
573 xGLXCopyContextReq
*req
;
574 struct glx_context
*gc
= __glXGetCurrentContext();
578 opcode
= __glXSetupForCommand(dpy
);
583 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
585 /* NOT_DONE: This does not work yet */
590 ** If the source is the current context, send its tag so that the context
591 ** can be flushed before the copy.
593 if (source
== gc
&& dpy
== gc
->currentDpy
) {
594 tag
= gc
->currentContextTag
;
600 /* Send the glXCopyContext request */
602 GetReq(GLXCopyContext
, req
);
603 req
->reqType
= opcode
;
604 req
->glxCode
= X_GLXCopyContext
;
605 req
->source
= source
? source
->xid
: None
;
606 req
->dest
= dest
? dest
->xid
: None
;
608 req
->contextTag
= tag
;
611 #endif /* GLX_USE_APPLEGL */
616 * Determine if a context uses direct rendering.
618 * \param dpy Display where the context was created.
619 * \param contextID ID of the context to be tested.
621 * \returns \c True if the context is direct rendering or not.
624 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
628 xcb_generic_error_t
*err
;
629 xcb_glx_is_direct_reply_t
*reply
;
632 opcode
= __glXSetupForCommand(dpy
);
637 c
= XGetXCBConnection(dpy
);
638 reply
= xcb_glx_is_direct_reply(c
, xcb_glx_is_direct(c
, contextID
), &err
);
639 is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
642 __glXSendErrorForXcb(dpy
, err
);
653 * Shouldn't this function \b always return \c False when
654 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
655 * the GLX protocol here at all?
658 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
660 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
665 else if (gc
->isDirect
) {
668 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
671 return __glXIsDirect(dpy
, gc
->xid
);
675 _GLX_PUBLIC GLXPixmap
676 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
678 #ifdef GLX_USE_APPLEGL
679 int screen
= vis
->screen
;
680 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
681 const struct glx_config
*config
;
683 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
685 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
690 xGLXCreateGLXPixmapReq
*req
;
691 struct glx_drawable
*glxDraw
;
695 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
696 struct glx_display
*const priv
= __glXInitialize(dpy
);
702 opcode
= __glXSetupForCommand(dpy
);
707 glxDraw
= malloc(sizeof(*glxDraw
));
711 /* Send the glXCreateGLXPixmap request */
713 GetReq(GLXCreateGLXPixmap
, req
);
714 req
->reqType
= opcode
;
715 req
->glxCode
= X_GLXCreateGLXPixmap
;
716 req
->screen
= vis
->screen
;
717 req
->visual
= vis
->visualid
;
718 req
->pixmap
= pixmap
;
719 req
->glxpixmap
= xid
= XAllocID(dpy
);
723 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
728 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
730 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
731 * is actually bound to a context... */
733 __GLXDRIdrawable
*pdraw
;
734 struct glx_screen
*psc
;
735 struct glx_config
*config
;
737 psc
= priv
->screens
[vis
->screen
];
738 if (psc
->driScreen
== NULL
)
741 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
742 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
744 fprintf(stderr
, "failed to create pixmap\n");
749 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
750 (*pdraw
->destroyDrawable
) (pdraw
);
757 xGLXDestroyGLXPixmapReq
*dreq
;
759 GetReq(GLXDestroyGLXPixmap
, dreq
);
760 dreq
->reqType
= opcode
;
761 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
762 dreq
->glxpixmap
= xid
;
773 ** Destroy the named pixmap
776 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
778 #ifdef GLX_USE_APPLEGL
779 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
780 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
782 xGLXDestroyGLXPixmapReq
*req
;
785 opcode
= __glXSetupForCommand(dpy
);
790 /* Send the glXDestroyGLXPixmap request */
792 GetReq(GLXDestroyGLXPixmap
, req
);
793 req
->reqType
= opcode
;
794 req
->glxCode
= X_GLXDestroyGLXPixmap
;
795 req
->glxpixmap
= glxpixmap
;
799 DestroyGLXDrawable(dpy
, glxpixmap
);
801 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
803 struct glx_display
*const priv
= __glXInitialize(dpy
);
804 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
806 if (priv
!= NULL
&& pdraw
!= NULL
) {
807 (*pdraw
->destroyDrawable
) (pdraw
);
808 __glxHashDelete(priv
->drawHash
, glxpixmap
);
812 #endif /* GLX_USE_APPLEGL */
816 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
818 #ifdef GLX_USE_APPLEGL
819 struct glx_context
* gc
= __glXGetCurrentContext();
820 if(gc
!= &dummyContext
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
821 apple_glx_swap_buffers(gc
->driContext
);
823 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
826 struct glx_context
*gc
;
831 gc
= __glXGetCurrentContext();
833 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
835 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
838 Bool flush
= gc
!= &dummyContext
&& drawable
== gc
->currentDrawable
;
840 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0, flush
);
846 opcode
= __glXSetupForCommand(dpy
);
852 ** The calling thread may or may not have a current context. If it
853 ** does, send the context tag so the server can do a flush.
855 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
856 ((drawable
== gc
->currentDrawable
)
857 || (drawable
== gc
->currentReadable
))) {
858 tag
= gc
->currentContextTag
;
864 c
= XGetXCBConnection(dpy
);
865 xcb_glx_swap_buffers(c
, tag
, drawable
);
867 #endif /* GLX_USE_APPLEGL */
872 ** Return configuration information for the given display, screen and
873 ** visual combination.
876 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
879 struct glx_display
*priv
;
880 struct glx_screen
*psc
;
881 struct glx_config
*config
;
884 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
885 if (status
== Success
) {
886 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
888 /* Lookup attribute after first finding a match on the visual */
889 if (config
!= NULL
) {
890 return glx_config_get(config
, attribute
, value_return
);
893 status
= GLX_BAD_VISUAL
;
897 ** If we can't find the config for this visual, this visual is not
898 ** supported by the OpenGL implementation on the server.
900 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
901 *value_return
= False
;
908 /************************************************************************/
911 init_fbconfig_for_chooser(struct glx_config
* config
,
912 GLboolean fbconfig_style_tags
)
914 memset(config
, 0, sizeof(struct glx_config
));
915 config
->visualID
= (XID
) GLX_DONT_CARE
;
916 config
->visualType
= GLX_DONT_CARE
;
918 /* glXChooseFBConfig specifies different defaults for these properties than
921 if (fbconfig_style_tags
) {
922 config
->rgbMode
= GL_TRUE
;
923 config
->doubleBufferMode
= GLX_DONT_CARE
;
924 config
->renderType
= GLX_RGBA_BIT
;
927 config
->drawableType
= GLX_WINDOW_BIT
;
928 config
->visualRating
= GLX_DONT_CARE
;
929 config
->transparentPixel
= GLX_NONE
;
930 config
->transparentRed
= GLX_DONT_CARE
;
931 config
->transparentGreen
= GLX_DONT_CARE
;
932 config
->transparentBlue
= GLX_DONT_CARE
;
933 config
->transparentAlpha
= GLX_DONT_CARE
;
934 config
->transparentIndex
= GLX_DONT_CARE
;
936 config
->xRenderable
= GLX_DONT_CARE
;
937 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
939 config
->swapMethod
= GLX_DONT_CARE
;
940 config
->sRGBCapable
= GLX_DONT_CARE
;
943 #define MATCH_DONT_CARE( param ) \
945 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
946 && (a-> param != b-> param) ) { \
951 #define MATCH_MINIMUM( param ) \
953 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
954 && (a-> param > b-> param) ) { \
959 #define MATCH_EXACT( param ) \
961 if ( a-> param != b-> param) { \
966 /* Test that all bits from a are contained in b */
967 #define MATCH_MASK(param) \
969 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
970 && ((a->param & ~b->param) != 0) ) { \
976 * Determine if two GLXFBConfigs are compatible.
978 * \param a Application specified config to test.
979 * \param b Server specified config to test against \c a.
982 fbconfigs_compatible(const struct glx_config
* const a
,
983 const struct glx_config
* const b
)
985 MATCH_DONT_CARE(doubleBufferMode
);
986 MATCH_DONT_CARE(visualType
);
987 MATCH_DONT_CARE(visualRating
);
988 MATCH_DONT_CARE(xRenderable
);
989 MATCH_DONT_CARE(fbconfigID
);
990 MATCH_DONT_CARE(swapMethod
);
992 MATCH_MINIMUM(rgbBits
);
993 MATCH_MINIMUM(numAuxBuffers
);
994 MATCH_MINIMUM(redBits
);
995 MATCH_MINIMUM(greenBits
);
996 MATCH_MINIMUM(blueBits
);
997 MATCH_MINIMUM(alphaBits
);
998 MATCH_MINIMUM(depthBits
);
999 MATCH_MINIMUM(stencilBits
);
1000 MATCH_MINIMUM(accumRedBits
);
1001 MATCH_MINIMUM(accumGreenBits
);
1002 MATCH_MINIMUM(accumBlueBits
);
1003 MATCH_MINIMUM(accumAlphaBits
);
1004 MATCH_MINIMUM(sampleBuffers
);
1005 MATCH_MINIMUM(maxPbufferWidth
);
1006 MATCH_MINIMUM(maxPbufferHeight
);
1007 MATCH_MINIMUM(maxPbufferPixels
);
1008 MATCH_MINIMUM(samples
);
1010 MATCH_DONT_CARE(stereoMode
);
1013 MATCH_MASK(drawableType
);
1014 MATCH_MASK(renderType
);
1015 MATCH_DONT_CARE(sRGBCapable
);
1017 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1018 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1019 * Technically speaking, it is a bug in the DDX driver, but there is
1020 * enough of an installed base to work around the problem here. In any
1021 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1022 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1023 * 0 from the server to be a match to maintain backward compatibility with
1024 * the (broken) drivers.
1027 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1028 if (a
->transparentPixel
== GLX_NONE
) {
1029 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1033 MATCH_EXACT(transparentPixel
);
1036 switch (a
->transparentPixel
) {
1037 case GLX_TRANSPARENT_RGB
:
1038 MATCH_DONT_CARE(transparentRed
);
1039 MATCH_DONT_CARE(transparentGreen
);
1040 MATCH_DONT_CARE(transparentBlue
);
1041 MATCH_DONT_CARE(transparentAlpha
);
1044 case GLX_TRANSPARENT_INDEX
:
1045 MATCH_DONT_CARE(transparentIndex
);
1057 /* There's some trickly language in the GLX spec about how this is supposed
1058 * to work. Basically, if a given component size is either not specified
1059 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1060 * Well, that's really hard to do with the code as-is. This behavior is
1061 * closer to correct, but still not technically right.
1063 #define PREFER_LARGER_OR_ZERO(comp) \
1065 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1066 if ( ((*a)-> comp) == 0 ) { \
1069 else if ( ((*b)-> comp) == 0 ) { \
1073 return ((*b)-> comp) - ((*a)-> comp) ; \
1078 #define PREFER_LARGER(comp) \
1080 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1081 return ((*b)-> comp) - ((*a)-> comp) ; \
1085 #define PREFER_SMALLER(comp) \
1087 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1088 return ((*a)-> comp) - ((*b)-> comp) ; \
1093 * Compare two GLXFBConfigs. This function is intended to be used as the
1094 * compare function passed in to qsort.
1096 * \returns If \c a is a "better" config, according to the specification of
1097 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1098 * better, then a number greater than zero is return. If both are
1099 * equal, zero is returned.
1100 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1103 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1105 /* The order of these comparisons must NOT change. It is defined by
1106 * the GLX 1.4 specification.
1109 PREFER_SMALLER(visualSelectGroup
);
1111 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1112 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1113 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1115 PREFER_SMALLER(visualRating
);
1117 /* This isn't quite right. It is supposed to compare the sum of the
1118 * components the user specifically set minimums for.
1120 PREFER_LARGER_OR_ZERO(redBits
);
1121 PREFER_LARGER_OR_ZERO(greenBits
);
1122 PREFER_LARGER_OR_ZERO(blueBits
);
1123 PREFER_LARGER_OR_ZERO(alphaBits
);
1125 PREFER_SMALLER(rgbBits
);
1127 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1128 /* Prefer single-buffer.
1130 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1133 PREFER_SMALLER(numAuxBuffers
);
1135 PREFER_SMALLER(sampleBuffers
);
1136 PREFER_SMALLER(samples
);
1138 PREFER_LARGER_OR_ZERO(depthBits
);
1139 PREFER_SMALLER(stencilBits
);
1141 /* This isn't quite right. It is supposed to compare the sum of the
1142 * components the user specifically set minimums for.
1144 PREFER_LARGER_OR_ZERO(accumRedBits
);
1145 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1146 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1147 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1149 PREFER_SMALLER(visualType
);
1151 /* None of the pbuffer or fbconfig specs say that this comparison needs
1152 * to happen at all, but it seems like it should.
1154 PREFER_LARGER(maxPbufferWidth
);
1155 PREFER_LARGER(maxPbufferHeight
);
1156 PREFER_LARGER(maxPbufferPixels
);
1163 * Selects and sorts a subset of the supplied configs based on the attributes.
1164 * This function forms to basis of \c glXChooseFBConfig and
1165 * \c glXChooseFBConfigSGIX.
1167 * \param configs Array of pointers to possible configs. The elements of
1168 * this array that do not meet the criteria will be set to
1169 * NULL. The remaining elements will be sorted according to
1170 * the various visual / FBConfig selection rules.
1171 * \param num_configs Number of elements in the \c configs array.
1172 * \param attribList Attributes used select from \c configs. This array is
1173 * terminated by a \c None tag. The array is of the form
1174 * expected by \c glXChooseFBConfig (where every tag has a
1176 * \returns The number of valid elements left in \c configs.
1178 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
1181 choose_fbconfig(struct glx_config
** configs
, int num_configs
,
1182 const int *attribList
)
1184 struct glx_config test_config
;
1188 /* This is a fairly direct implementation of the selection method
1189 * described by GLX_SGIX_fbconfig. Start by culling out all the
1190 * configs that are not compatible with the selected parameter
1194 init_fbconfig_for_chooser(&test_config
, GL_TRUE
);
1195 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1196 (const INT32
*) attribList
,
1200 for (i
= 0; i
< num_configs
; i
++) {
1201 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1202 configs
[base
] = configs
[i
];
1211 if (base
< num_configs
) {
1212 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1215 /* After the incompatible configs are removed, the resulting
1216 * list is sorted according to the rules set out in the various
1220 qsort(configs
, base
, sizeof(struct glx_config
*),
1221 (int (*)(const void *, const void *)) fbconfig_compare
);
1229 ** Return the visual that best matches the template. Return None if no
1230 ** visual matches the template.
1232 _GLX_PUBLIC XVisualInfo
*
1233 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1235 XVisualInfo
*visualList
= NULL
;
1236 struct glx_display
*priv
;
1237 struct glx_screen
*psc
;
1238 struct glx_config test_config
;
1239 struct glx_config
*config
;
1240 struct glx_config
*best_config
= NULL
;
1243 ** Get a list of all visuals, return if list is empty
1245 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1251 ** Build a template from the defaults and the attribute list
1252 ** Free visual list and return if an unexpected token is encountered
1254 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1255 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1256 (const INT32
*) attribList
,
1260 ** Eliminate visuals that don't meet minimum requirements
1261 ** Compute a score for those that do
1262 ** Remember which visual, if any, got the highest score
1263 ** If no visual is acceptable, return None
1264 ** Otherwise, create an XVisualInfo list with just the selected X visual
1267 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1268 if (fbconfigs_compatible(&test_config
, config
)
1269 && ((best_config
== NULL
) ||
1270 (fbconfig_compare (&config
, &best_config
) < 0))) {
1271 XVisualInfo visualTemplate
;
1272 XVisualInfo
*newList
;
1275 visualTemplate
.screen
= screen
;
1276 visualTemplate
.visualid
= config
->visualID
;
1277 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1278 &visualTemplate
, &i
);
1282 visualList
= newList
;
1283 best_config
= config
;
1288 #ifdef GLX_USE_APPLEGL
1289 if(visualList
&& env_var_as_boolean("LIBGL_DUMP_VISUALID", false)) {
1290 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1298 _GLX_PUBLIC
const char *
1299 glXQueryExtensionsString(Display
* dpy
, int screen
)
1301 struct glx_screen
*psc
;
1302 struct glx_display
*priv
;
1304 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1308 if (!psc
->effectiveGLXexts
) {
1309 if (!psc
->serverGLXexts
) {
1310 psc
->serverGLXexts
=
1311 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1315 __glXCalculateUsableExtensions(psc
,
1316 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1317 (psc
->driScreen
!= NULL
),
1321 priv
->minorVersion
);
1324 return psc
->effectiveGLXexts
;
1327 _GLX_PUBLIC
const char *
1328 glXGetClientString(Display
* dpy
, int name
)
1334 return (__glXGLXClientVendorName
);
1336 return (__glXGLXClientVersion
);
1337 case GLX_EXTENSIONS
:
1338 return (__glXGetClientExtensions());
1344 _GLX_PUBLIC
const char *
1345 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1347 struct glx_screen
*psc
;
1348 struct glx_display
*priv
;
1352 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1358 str
= &priv
->serverGLXvendor
;
1361 str
= &priv
->serverGLXversion
;
1363 case GLX_EXTENSIONS
:
1364 str
= &psc
->serverGLXexts
;
1371 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1379 ** EXT_import_context
1382 _GLX_PUBLIC Display
*
1383 glXGetCurrentDisplay(void)
1385 struct glx_context
*gc
= __glXGetCurrentContext();
1386 if (gc
== &dummyContext
)
1388 return gc
->currentDpy
;
1392 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1393 glXGetCurrentDisplay
)
1395 #ifndef GLX_USE_APPLEGL
1396 _GLX_PUBLIC GLXContext
1397 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1399 struct glx_display
*priv
= __glXInitialize(dpy
);
1400 struct glx_screen
*psc
= NULL
;
1401 xGLXQueryContextReply reply
;
1403 struct glx_context
*ctx
;
1404 int i
, renderType
= GLX_RGBA_TYPE
; /* By default, assume RGBA context */
1406 struct glx_config
*mode
= NULL
;
1407 uint32_t fbconfigID
= 0;
1408 uint32_t visualID
= 0;
1409 uint32_t screen
= 0;
1410 Bool got_screen
= False
;
1415 /* The GLX_EXT_import_context spec says:
1417 * "If <contextID> does not refer to a valid context, then a BadContext
1418 * error is generated; if <contextID> refers to direct rendering
1419 * context then no error is generated but glXImportContextEXT returns
1422 * If contextID is None, generate BadContext on the client-side. Other
1423 * sorts of invalid contexts will be detected by the server in the
1424 * __glXIsDirect call.
1426 if (contextID
== None
) {
1427 __glXSendError(dpy
, GLXBadContext
, contextID
, X_GLXIsDirect
, false);
1431 if (__glXIsDirect(dpy
, contextID
))
1434 opcode
= __glXSetupForCommand(dpy
);
1438 /* Send the glXQueryContextInfoEXT request */
1441 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1442 xGLXQueryContextReq
*req
;
1444 GetReq(GLXQueryContext
, req
);
1446 req
->reqType
= opcode
;
1447 req
->glxCode
= X_GLXQueryContext
;
1448 req
->context
= contextID
;
1451 xGLXVendorPrivateReq
*vpreq
;
1452 xGLXQueryContextInfoEXTReq
*req
;
1454 GetReqExtra(GLXVendorPrivate
,
1455 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1457 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1458 req
->reqType
= opcode
;
1459 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1460 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1461 req
->context
= contextID
;
1464 if (_XReply(dpy
, (xReply
*) & reply
, 0, False
) &&
1465 reply
.n
< (INT32_MAX
/ 2)) {
1467 for (i
= 0; i
< reply
.n
; i
++) {
1470 _XRead(dpy
, (char *)prop
, sizeof(prop
));
1476 case GLX_SHARE_CONTEXT_EXT
:
1479 case GLX_VISUAL_ID_EXT
:
1482 case GLX_FBCONFIG_ID
:
1483 fbconfigID
= prop
[1];
1485 case GLX_RENDER_TYPE
:
1486 renderType
= prop
[1];
1497 psc
= GetGLXScreenConfigs(dpy
, screen
);
1501 if (fbconfigID
!= 0) {
1502 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1503 } else if (visualID
!= 0) {
1504 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1510 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1514 ctx
->xid
= contextID
;
1515 ctx
->imported
= GL_TRUE
;
1516 ctx
->share_xid
= share
;
1518 return (GLXContext
) ctx
;
1524 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1526 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1528 switch (attribute
) {
1529 case GLX_SHARE_CONTEXT_EXT
:
1530 *value
= ctx
->share_xid
;
1532 case GLX_VISUAL_ID_EXT
:
1533 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1536 *value
= ctx
->screen
;
1538 case GLX_FBCONFIG_ID
:
1539 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1541 case GLX_RENDER_TYPE
:
1542 *value
= ctx
->renderType
;
1545 return GLX_BAD_ATTRIBUTE
;
1551 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1552 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1553 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1555 _GLX_PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1557 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1559 return (ctx
== NULL
) ? None
: ctx
->xid
;
1563 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1565 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1567 if (gc
== NULL
|| gc
->xid
== None
)
1570 /* The GLX_EXT_import_context spec says:
1572 * "glXFreeContext does not free the server-side context information or
1573 * the XID associated with the server-side context."
1575 * Don't send any protocol. Just destroy the client-side tracking of the
1576 * context. Also, only release the context structure if it's not current.
1579 if (gc
->currentDpy
) {
1582 gc
->vtable
->destroy(gc
);
1587 _GLX_PUBLIC GLXFBConfig
*
1588 glXChooseFBConfig(Display
* dpy
, int screen
,
1589 const int *attribList
, int *nitems
)
1591 struct glx_config
**config_list
;
1595 config_list
= (struct glx_config
**)
1596 glXGetFBConfigs(dpy
, screen
, &list_size
);
1598 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1599 list_size
= choose_fbconfig(config_list
, list_size
, attribList
);
1600 if (list_size
== 0) {
1606 *nitems
= list_size
;
1607 return (GLXFBConfig
*) config_list
;
1611 _GLX_PUBLIC GLXContext
1612 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1613 int renderType
, GLXContext shareList
, Bool allowDirect
)
1615 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1616 struct glx_config
**config_list
;
1621 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1625 config_list
= (struct glx_config
**)
1626 glXGetFBConfigs(dpy
, config
->screen
, &list_size
);
1628 for (i
= 0; i
< list_size
; i
++) {
1629 if (config_list
[i
] == config
)
1634 if (i
== list_size
) {
1635 __glXSendError(dpy
, GLXBadFBConfig
, 0, X_GLXCreateNewContext
, false);
1639 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1640 allowDirect
, X_GLXCreateNewContext
, renderType
,
1645 _GLX_PUBLIC GLXDrawable
1646 glXGetCurrentReadDrawable(void)
1648 struct glx_context
*gc
= __glXGetCurrentContext();
1650 return gc
->currentReadable
;
1654 _GLX_PUBLIC GLXFBConfig
*
1655 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1657 struct glx_display
*priv
= __glXInitialize(dpy
);
1658 struct glx_config
**config_list
= NULL
;
1659 struct glx_config
*config
;
1660 unsigned num_configs
= 0;
1664 if (priv
&& (priv
->screens
!= NULL
)
1665 && (screen
>= 0) && (screen
< ScreenCount(dpy
))
1666 && (priv
->screens
[screen
]->configs
!= NULL
)
1667 && (priv
->screens
[screen
]->configs
->fbconfigID
1668 != (int) GLX_DONT_CARE
)) {
1670 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1671 config
= config
->next
) {
1672 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1677 config_list
= malloc(num_configs
* sizeof *config_list
);
1678 if (config_list
!= NULL
) {
1679 *nelements
= num_configs
;
1681 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1682 config
= config
->next
) {
1683 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1684 config_list
[i
] = config
;
1691 return (GLXFBConfig
*) config_list
;
1696 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1697 int attribute
, int *value
)
1699 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1702 return GLXBadFBConfig
;
1704 return glx_config_get(config
, attribute
, value
);
1708 _GLX_PUBLIC XVisualInfo
*
1709 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1711 XVisualInfo visualTemplate
;
1712 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1716 ** Get a list of all visuals, return if list is empty
1718 visualTemplate
.visualid
= config
->visualID
;
1719 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1722 #ifndef GLX_USE_APPLEGL
1724 ** GLX_SGI_swap_control
1727 __glXSwapIntervalSGI(int interval
)
1729 xGLXVendorPrivateReq
*req
;
1730 struct glx_context
*gc
= __glXGetCurrentContext();
1731 struct glx_screen
*psc
;
1733 CARD32
*interval_ptr
;
1736 if (gc
== &dummyContext
) {
1737 return GLX_BAD_CONTEXT
;
1740 if (interval
<= 0) {
1741 return GLX_BAD_VALUE
;
1744 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1746 #ifdef GLX_DIRECT_RENDERING
1747 if (gc
->isDirect
&& psc
&& psc
->driScreen
&&
1748 psc
->driScreen
->setSwapInterval
) {
1749 __GLXDRIdrawable
*pdraw
=
1750 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1751 /* Simply ignore the command if the GLX drawable has been destroyed but
1752 * the context is still bound.
1755 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1760 dpy
= gc
->currentDpy
;
1761 opcode
= __glXSetupForCommand(dpy
);
1766 /* Send the glXSwapIntervalSGI request */
1768 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1769 req
->reqType
= opcode
;
1770 req
->glxCode
= X_GLXVendorPrivate
;
1771 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1772 req
->contextTag
= gc
->currentContextTag
;
1774 interval_ptr
= (CARD32
*) (req
+ 1);
1775 *interval_ptr
= interval
;
1786 ** GLX_MESA_swap_control
1789 __glXSwapIntervalMESA(unsigned int interval
)
1791 #ifdef GLX_DIRECT_RENDERING
1792 struct glx_context
*gc
= __glXGetCurrentContext();
1794 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1795 struct glx_screen
*psc
;
1797 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1798 if (psc
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1799 __GLXDRIdrawable
*pdraw
=
1800 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1802 /* Simply ignore the command if the GLX drawable has been destroyed but
1803 * the context is still bound.
1808 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1813 return GLX_BAD_CONTEXT
;
1818 __glXGetSwapIntervalMESA(void)
1820 #ifdef GLX_DIRECT_RENDERING
1821 struct glx_context
*gc
= __glXGetCurrentContext();
1823 if (gc
!= &dummyContext
&& gc
->isDirect
) {
1824 struct glx_screen
*psc
;
1826 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1827 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1828 __GLXDRIdrawable
*pdraw
=
1829 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1831 return psc
->driScreen
->getSwapInterval(pdraw
);
1841 ** GLX_SGI_video_sync
1844 __glXGetVideoSyncSGI(unsigned int *count
)
1846 int64_t ust
, msc
, sbc
;
1848 struct glx_context
*gc
= __glXGetCurrentContext();
1849 struct glx_screen
*psc
;
1850 #ifdef GLX_DIRECT_RENDERING
1851 __GLXDRIdrawable
*pdraw
;
1854 if (gc
== &dummyContext
)
1855 return GLX_BAD_CONTEXT
;
1857 #ifdef GLX_DIRECT_RENDERING
1859 return GLX_BAD_CONTEXT
;
1862 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1863 #ifdef GLX_DIRECT_RENDERING
1864 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1867 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1868 * FIXME: there should be a GLX encoding for this call. I can find no
1869 * FIXME: documentation for the GLX encoding.
1871 #ifdef GLX_DIRECT_RENDERING
1872 if (psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1873 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1874 *count
= (unsigned) msc
;
1875 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1879 return GLX_BAD_CONTEXT
;
1883 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1885 struct glx_context
*gc
= __glXGetCurrentContext();
1886 struct glx_screen
*psc
;
1887 #ifdef GLX_DIRECT_RENDERING
1888 __GLXDRIdrawable
*pdraw
;
1890 int64_t ust
, msc
, sbc
;
1893 if (divisor
<= 0 || remainder
< 0)
1894 return GLX_BAD_VALUE
;
1896 if (gc
== &dummyContext
)
1897 return GLX_BAD_CONTEXT
;
1899 #ifdef GLX_DIRECT_RENDERING
1901 return GLX_BAD_CONTEXT
;
1904 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1905 #ifdef GLX_DIRECT_RENDERING
1906 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1909 #ifdef GLX_DIRECT_RENDERING
1910 if (psc
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1911 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1913 *count
= (unsigned) msc
;
1914 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1918 return GLX_BAD_CONTEXT
;
1921 #endif /* GLX_USE_APPLEGL */
1924 ** GLX_SGIX_fbconfig
1925 ** Many of these functions are aliased to GLX 1.3 entry points in the
1926 ** GLX_functions table.
1930 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1931 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1932 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1934 _GLX_PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1935 (Display
* dpy
, int screen
, int *attrib_list
,
1936 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1939 _GLX_PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1940 (Display
* dpy
, GLXFBConfigSGIX config
),
1941 (dpy
, config
), glXGetVisualFromFBConfig
)
1943 _GLX_PUBLIC GLXPixmap
1944 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1945 GLXFBConfigSGIX fbconfig
,
1948 #ifndef GLX_USE_APPLEGL
1949 xGLXVendorPrivateWithReplyReq
*vpreq
;
1950 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1951 GLXPixmap xid
= None
;
1953 struct glx_screen
*psc
;
1955 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1958 if ((dpy
== NULL
) || (config
== NULL
)) {
1961 #ifdef GLX_USE_APPLEGL
1962 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1967 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1969 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1970 opcode
= __glXSetupForCommand(dpy
);
1975 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1977 GetReqExtra(GLXVendorPrivateWithReply
,
1978 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1979 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1980 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1981 req
->reqType
= opcode
;
1982 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1983 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1984 req
->screen
= config
->screen
;
1985 req
->fbconfig
= config
->fbconfigID
;
1986 req
->pixmap
= pixmap
;
1987 req
->glxpixmap
= xid
= XAllocID(dpy
);
1996 _GLX_PUBLIC GLXContext
1997 glXCreateContextWithConfigSGIX(Display
* dpy
,
1998 GLXFBConfigSGIX fbconfig
, int renderType
,
1999 GLXContext shareList
, Bool allowDirect
)
2001 GLXContext gc
= NULL
;
2002 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2003 struct glx_screen
*psc
;
2006 if ((dpy
== NULL
) || (config
== NULL
)) {
2010 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2012 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2013 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2015 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2023 _GLX_PUBLIC GLXFBConfigSGIX
2024 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2026 struct glx_display
*priv
;
2027 struct glx_screen
*psc
= NULL
;
2029 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2030 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2031 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2032 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2039 #ifndef GLX_USE_APPLEGL
2041 ** GLX_OML_sync_control
2044 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2045 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2047 struct glx_display
* const priv
= __glXInitialize(dpy
);
2049 #ifdef GLX_DIRECT_RENDERING
2050 __GLXDRIdrawable
*pdraw
;
2052 struct glx_screen
*psc
;
2057 #ifdef GLX_DIRECT_RENDERING
2058 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2059 psc
= pdraw
? pdraw
->psc
: NULL
;
2060 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2061 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2069 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2071 __glxGetMscRate(struct glx_screen
*psc
,
2072 int32_t * numerator
, int32_t * denominator
)
2075 XF86VidModeModeLine mode_line
;
2079 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2080 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2081 unsigned n
= dot_clock
* 1000;
2082 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2084 # define V_INTERLACE 0x010
2085 # define V_DBLSCAN 0x020
2087 if (mode_line
.flags
& V_INTERLACE
)
2089 else if (mode_line
.flags
& V_DBLSCAN
)
2092 /* The OML_sync_control spec requires that if the refresh rate is a
2093 * whole number, that the returned numerator be equal to the refresh
2094 * rate and the denominator be 1.
2102 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2104 /* This is a poor man's way to reduce a fraction. It's far from
2105 * perfect, but it will work well enough for this situation.
2108 for (i
= 0; f
[i
] != 0; i
++) {
2109 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2129 * Determine the refresh rate of the specified drawable and display.
2131 * \param dpy Display whose refresh rate is to be determined.
2132 * \param drawable Drawable whose refresh rate is to be determined.
2133 * \param numerator Numerator of the refresh rate.
2134 * \param demoninator Denominator of the refresh rate.
2135 * \return If the refresh rate for the specified display and drawable could
2136 * be calculated, True is returned. Otherwise False is returned.
2138 * \note This function is implemented entirely client-side. A lot of other
2139 * functionality is required to export GLX_OML_sync_control, so on
2140 * XFree86 this function can be called for direct-rendering contexts
2141 * when GLX_OML_sync_control appears in the client extension string.
2145 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2146 int32_t * numerator
, int32_t * denominator
)
2148 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2149 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2154 return __glxGetMscRate(draw
->psc
, numerator
, denominator
);
2166 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2167 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2169 struct glx_context
*gc
= __glXGetCurrentContext();
2170 #ifdef GLX_DIRECT_RENDERING
2171 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2172 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2175 if (gc
== &dummyContext
) /* no GLX for this */
2178 #ifdef GLX_DIRECT_RENDERING
2179 if (!pdraw
|| !gc
->isDirect
)
2183 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2184 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2185 * of -1 if the function failed because of errors detected in the input
2188 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2190 if (divisor
> 0 && remainder
>= divisor
)
2193 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2196 #ifdef GLX_DIRECT_RENDERING
2197 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2198 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2207 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2208 int64_t target_msc
, int64_t divisor
,
2209 int64_t remainder
, int64_t * ust
,
2210 int64_t * msc
, int64_t * sbc
)
2212 #ifdef GLX_DIRECT_RENDERING
2213 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2214 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2219 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2220 * error", but the return type in the spec is Bool.
2222 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2224 if (divisor
> 0 && remainder
>= divisor
)
2227 #ifdef GLX_DIRECT_RENDERING
2228 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2229 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2240 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2241 int64_t target_sbc
, 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
;
2250 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2251 * error", but the return type in the spec is Bool.
2256 #ifdef GLX_DIRECT_RENDERING
2257 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2258 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2270 * Mesa extension stubs. These will help reduce portability problems.
2275 * Release all buffers associated with the specified GLX drawable.
2278 * This function was intended for stand-alone Mesa. The issue there is that
2279 * the library doesn't get any notification when a window is closed. In
2280 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2281 * supported, there are 3 different functions to destroy a drawable. It
2282 * should be possible to create GLX protocol (or have it determine which
2283 * protocol to use based on the type of the drawable) to have one function
2284 * do the work of 3. For the direct-rendering case, this function could
2285 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2286 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2287 * would need to be used. This really should be done as part of the new DRI
2290 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2291 * __driGarbageCollectDrawables
2292 * glXDestroyGLXPixmap
2293 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2294 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2297 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2305 _GLX_PUBLIC GLXPixmap
2306 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2307 Pixmap pixmap
, Colormap cmap
)
2320 * GLX_MESA_copy_sub_buffer
2322 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2324 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2325 int x
, int y
, int width
, int height
)
2327 xGLXVendorPrivateReq
*req
;
2328 struct glx_context
*gc
;
2330 CARD32
*drawable_ptr
;
2331 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2334 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2335 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2336 if (pdraw
!= NULL
) {
2337 struct glx_screen
*psc
= pdraw
->psc
;
2338 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2339 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
, True
);
2346 opcode
= __glXSetupForCommand(dpy
);
2351 ** The calling thread may or may not have a current context. If it
2352 ** does, send the context tag so the server can do a flush.
2354 gc
= __glXGetCurrentContext();
2355 if ((gc
!= &dummyContext
) && (dpy
== gc
->currentDpy
) &&
2356 ((drawable
== gc
->currentDrawable
) ||
2357 (drawable
== gc
->currentReadable
))) {
2358 tag
= gc
->currentContextTag
;
2365 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2366 req
->reqType
= opcode
;
2367 req
->glxCode
= X_GLXVendorPrivate
;
2368 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2369 req
->contextTag
= tag
;
2371 drawable_ptr
= (CARD32
*) (req
+ 1);
2372 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2373 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2374 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2375 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2377 *drawable_ptr
= drawable
;
2389 __glXBindTexImageEXT(Display
* dpy
,
2390 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2392 struct glx_context
*gc
= __glXGetCurrentContext();
2394 if (gc
->vtable
->bind_tex_image
== NULL
)
2397 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2401 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2403 struct glx_context
*gc
= __glXGetCurrentContext();
2405 if (gc
->vtable
->release_tex_image
== NULL
)
2408 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2413 #endif /* GLX_USE_APPLEGL */
2416 ** glXGetProcAddress support
2419 struct name_address_pair
2425 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2426 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2428 static const struct name_address_pair GLX_functions
[] = {
2429 /*** GLX_VERSION_1_0 ***/
2430 GLX_FUNCTION(glXChooseVisual
),
2431 GLX_FUNCTION(glXCopyContext
),
2432 GLX_FUNCTION(glXCreateContext
),
2433 GLX_FUNCTION(glXCreateGLXPixmap
),
2434 GLX_FUNCTION(glXDestroyContext
),
2435 GLX_FUNCTION(glXDestroyGLXPixmap
),
2436 GLX_FUNCTION(glXGetConfig
),
2437 GLX_FUNCTION(glXGetCurrentContext
),
2438 GLX_FUNCTION(glXGetCurrentDrawable
),
2439 GLX_FUNCTION(glXIsDirect
),
2440 GLX_FUNCTION(glXMakeCurrent
),
2441 GLX_FUNCTION(glXQueryExtension
),
2442 GLX_FUNCTION(glXQueryVersion
),
2443 GLX_FUNCTION(glXSwapBuffers
),
2444 GLX_FUNCTION(glXUseXFont
),
2445 GLX_FUNCTION(glXWaitGL
),
2446 GLX_FUNCTION(glXWaitX
),
2448 /*** GLX_VERSION_1_1 ***/
2449 GLX_FUNCTION(glXGetClientString
),
2450 GLX_FUNCTION(glXQueryExtensionsString
),
2451 GLX_FUNCTION(glXQueryServerString
),
2453 /*** GLX_VERSION_1_2 ***/
2454 GLX_FUNCTION(glXGetCurrentDisplay
),
2456 /*** GLX_VERSION_1_3 ***/
2457 GLX_FUNCTION(glXChooseFBConfig
),
2458 GLX_FUNCTION(glXCreateNewContext
),
2459 GLX_FUNCTION(glXCreatePbuffer
),
2460 GLX_FUNCTION(glXCreatePixmap
),
2461 GLX_FUNCTION(glXCreateWindow
),
2462 GLX_FUNCTION(glXDestroyPbuffer
),
2463 GLX_FUNCTION(glXDestroyPixmap
),
2464 GLX_FUNCTION(glXDestroyWindow
),
2465 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2466 GLX_FUNCTION(glXGetFBConfigAttrib
),
2467 GLX_FUNCTION(glXGetFBConfigs
),
2468 GLX_FUNCTION(glXGetSelectedEvent
),
2469 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2470 GLX_FUNCTION(glXMakeContextCurrent
),
2471 GLX_FUNCTION(glXQueryContext
),
2472 GLX_FUNCTION(glXQueryDrawable
),
2473 GLX_FUNCTION(glXSelectEvent
),
2475 #ifndef GLX_USE_APPLEGL
2476 /*** GLX_SGI_swap_control ***/
2477 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2479 /*** GLX_SGI_video_sync ***/
2480 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2481 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2483 /*** GLX_SGI_make_current_read ***/
2484 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2485 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2487 /*** GLX_EXT_import_context ***/
2488 GLX_FUNCTION(glXFreeContextEXT
),
2489 GLX_FUNCTION(glXGetContextIDEXT
),
2490 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2491 GLX_FUNCTION(glXImportContextEXT
),
2492 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2495 /*** GLX_SGIX_fbconfig ***/
2496 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2497 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2498 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2499 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2500 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2501 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2503 #ifndef GLX_USE_APPLEGL
2504 /*** GLX_SGIX_pbuffer ***/
2505 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2506 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2507 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2508 GLX_FUNCTION(glXSelectEventSGIX
),
2509 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2511 /*** GLX_MESA_copy_sub_buffer ***/
2512 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2514 /*** GLX_MESA_pixmap_colormap ***/
2515 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2517 /*** GLX_MESA_release_buffers ***/
2518 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2520 /*** GLX_MESA_swap_control ***/
2521 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2522 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2525 /*** GLX_ARB_get_proc_address ***/
2526 GLX_FUNCTION(glXGetProcAddressARB
),
2529 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2531 #ifndef GLX_USE_APPLEGL
2532 /*** GLX_OML_sync_control ***/
2533 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2534 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2535 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2536 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2537 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2539 /*** GLX_EXT_texture_from_pixmap ***/
2540 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2541 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2544 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
2545 /*** DRI configuration ***/
2546 GLX_FUNCTION(glXGetScreenDriver
),
2547 GLX_FUNCTION(glXGetDriverConfig
),
2550 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2551 GLX_FUNCTION(glXCreateContextAttribsARB
),
2553 /*** GLX_MESA_query_renderer ***/
2554 GLX_FUNCTION(glXQueryRendererIntegerMESA
),
2555 GLX_FUNCTION(glXQueryRendererStringMESA
),
2556 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA
),
2557 GLX_FUNCTION(glXQueryCurrentRendererStringMESA
),
2559 {NULL
, NULL
} /* end of list */
2562 static const GLvoid
*
2563 get_glx_proc_address(const char *funcName
)
2567 /* try static functions */
2568 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2569 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2570 return GLX_functions
[i
].Address
;
2577 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2578 * \c glXGetProcAddress.
2580 * \param procName Name of a GL or GLX function.
2581 * \returns A pointer to the named function
2583 * \sa glXGetProcAddress
2585 _GLX_PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2587 typedef void (*gl_function
) (void);
2591 /* Search the table of GLX and internal functions first. If that
2592 * fails and the supplied name could be a valid core GL name, try
2593 * searching the core GL function table. This check is done to prevent
2594 * DRI based drivers from searching the core GL function table for
2595 * internal API functions.
2597 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2598 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2599 && (procName
[2] != 'X')) {
2600 #ifdef GLX_INDIRECT_RENDERING
2601 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2604 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2606 struct glx_context
*gc
= __glXGetCurrentContext();
2608 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2609 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2616 * Get the address of a named GL function. This is the GLX 1.4 name for
2617 * \c glXGetProcAddressARB.
2619 * \param procName Name of a GL or GLX function.
2620 * \returns A pointer to the named function
2622 * \sa glXGetProcAddressARB
2625 GLX_ALIAS(__GLXextFuncPtr
, glXGetProcAddress
,
2626 (const GLubyte
* procName
),
2627 (procName
), glXGetProcAddressARB
)
2629 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2631 * Get the unadjusted system time (UST). Currently, the UST is measured in
2632 * microseconds since Epoc. The actual resolution of the UST may vary from
2633 * system to system, and the units may vary from release to release.
2634 * Drivers should not call this function directly. They should instead use
2635 * \c glXGetProcAddress to obtain a pointer to the function.
2637 * \param ust Location to store the 64-bit UST
2638 * \returns Zero on success or a negative errno value on failure.
2640 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2642 * \since Internal API version 20030317.
2645 __glXGetUST(int64_t * ust
)
2653 if (gettimeofday(&tv
, NULL
) == 0) {
2654 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2661 #endif /* GLX_DIRECT_RENDERING */
2663 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2666 MesaGLInteropGLXQueryDeviceInfo(Display
*dpy
, GLXContext context
,
2667 struct mesa_glinterop_device_info
*out
)
2669 struct glx_context
*gc
= (struct glx_context
*)context
;
2674 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2676 return MESA_GLINTEROP_INVALID_CONTEXT
;
2679 if (!gc
->vtable
->interop_query_device_info
) {
2681 return MESA_GLINTEROP_UNSUPPORTED
;
2684 ret
= gc
->vtable
->interop_query_device_info(gc
, out
);
2690 MesaGLInteropGLXExportObject(Display
*dpy
, GLXContext context
,
2691 struct mesa_glinterop_export_in
*in
,
2692 struct mesa_glinterop_export_out
*out
)
2694 struct glx_context
*gc
= (struct glx_context
*)context
;
2699 if (!gc
|| gc
->xid
== None
|| !gc
->isDirect
) {
2701 return MESA_GLINTEROP_INVALID_CONTEXT
;
2704 if (!gc
->vtable
->interop_export_object
) {
2706 return MESA_GLINTEROP_UNSUPPORTED
;
2709 ret
= gc
->vtable
->interop_export_object(gc
, in
, out
);
2714 #endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */