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"
41 #ifdef GLX_DIRECT_RENDERING
42 #ifdef GLX_USE_APPLEGL
43 #include "apple_glx_context.h"
44 #include "apple_glx.h"
45 #include "glx_error.h"
49 #include <X11/extensions/xf86vmode.h>
57 #include <X11/Xlib-xcb.h>
62 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
63 static const char __glXGLXClientVersion
[] = "1.4";
65 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
68 * Get the __DRIdrawable for the drawable associated with a GLXContext
70 * \param dpy The display associated with \c drawable.
71 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
72 * \param scrn_num If non-NULL, the drawables screen is stored there
73 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
74 * the drawable is not associated with a direct-rendering context.
76 _X_HIDDEN __GLXDRIdrawable
*
77 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
79 struct glx_display
*priv
= __glXInitialize(dpy
);
80 __GLXDRIdrawable
*pdraw
;
85 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
93 _X_HIDDEN
struct glx_drawable
*
94 GetGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
96 struct glx_display
*priv
= __glXInitialize(dpy
);
97 struct glx_drawable
*glxDraw
;
102 if (__glxHashLookup(priv
->glXDrawHash
, drawable
, (void *) &glxDraw
) == 0)
109 InitGLXDrawable(Display
*dpy
, struct glx_drawable
*glxDraw
, XID xDrawable
,
110 GLXDrawable drawable
)
112 struct glx_display
*priv
= __glXInitialize(dpy
);
117 glxDraw
->xDrawable
= xDrawable
;
118 glxDraw
->drawable
= drawable
;
119 glxDraw
->lastEventSbc
= 0;
120 glxDraw
->eventSbcWrap
= 0;
122 return __glxHashInsert(priv
->glXDrawHash
, drawable
, glxDraw
);
126 DestroyGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
128 struct glx_display
*priv
= __glXInitialize(dpy
);
129 struct glx_drawable
*glxDraw
;
134 glxDraw
= GetGLXDrawable(dpy
, drawable
);
135 __glxHashDelete(priv
->glXDrawHash
, drawable
);
140 * Get the GLX per-screen data structure associated with a GLX context.
142 * \param dpy Display for which the GLX per-screen information is to be
144 * \param scrn Screen on \c dpy for which the GLX per-screen information is
146 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
147 * specify a valid GLX screen, or NULL otherwise.
149 * \todo Should this function validate that \c scrn is within the screen
150 * number range for \c dpy?
153 static struct glx_screen
*
154 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
156 struct glx_display
*const priv
= __glXInitialize(dpy
);
160 NULL
) ? priv
->screens
[scrn
] : NULL
;
165 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
166 struct glx_screen
** ppsc
)
168 /* Initialize the extension, if needed . This has the added value
169 * of initializing/allocating the display private
173 return GLX_NO_EXTENSION
;
176 *ppriv
= __glXInitialize(dpy
);
177 if (*ppriv
== NULL
) {
178 return GLX_NO_EXTENSION
;
181 /* Check screen number to see if its valid */
182 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
183 return GLX_BAD_SCREEN
;
186 /* Check to see if the GL is supported on this screen */
187 *ppsc
= (*ppriv
)->screens
[scrn
];
188 if ((*ppsc
)->configs
== NULL
) {
189 /* No support for GL on this screen regardless of visual */
190 return GLX_BAD_VISUAL
;
198 * Determine if a \c GLXFBConfig supplied by the application is valid.
200 * \param dpy Application supplied \c Display pointer.
201 * \param config Application supplied \c GLXFBConfig.
203 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
204 * \c struct glx_config structure is returned. Otherwise, \c NULL
207 static struct glx_config
*
208 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
210 struct glx_display
*const priv
= __glXInitialize(dpy
);
211 int num_screens
= ScreenCount(dpy
);
213 struct glx_config
*config
;
216 for (i
= 0; i
< num_screens
; i
++) {
217 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
218 config
= config
->next
) {
219 if (config
== (struct glx_config
*) fbconfig
) {
230 glx_context_init(struct glx_context
*gc
,
231 struct glx_screen
*psc
, struct glx_config
*config
)
233 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
234 if (!gc
->majorOpcode
)
237 gc
->screen
= psc
->scr
;
240 gc
->isDirect
= GL_TRUE
;
241 gc
->currentContextTag
= -1;
248 * Create a new context.
250 * \param renderType For FBConfigs, what is the rendering type?
254 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
255 GLXContext shareList_user
, Bool allowDirect
,
256 unsigned code
, int renderType
, int screen
)
258 struct glx_context
*gc
;
259 struct glx_screen
*psc
;
260 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
264 psc
= GetGLXScreenConfigs(dpy
, screen
);
268 if (generic_id
== None
)
272 #ifdef GLX_USE_APPLEGL
273 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
275 if (allowDirect
&& psc
->vtable
->create_context
)
276 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
278 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
285 case X_GLXCreateContext
: {
286 xGLXCreateContextReq
*req
;
288 /* Send the glXCreateContext request */
289 GetReq(GLXCreateContext
, req
);
290 req
->reqType
= gc
->majorOpcode
;
291 req
->glxCode
= X_GLXCreateContext
;
292 req
->context
= gc
->xid
= XAllocID(dpy
);
293 req
->visual
= generic_id
;
294 req
->screen
= screen
;
295 req
->shareList
= shareList
? shareList
->xid
: None
;
296 req
->isDirect
= gc
->isDirect
;
300 case X_GLXCreateNewContext
: {
301 xGLXCreateNewContextReq
*req
;
303 /* Send the glXCreateNewContext request */
304 GetReq(GLXCreateNewContext
, req
);
305 req
->reqType
= gc
->majorOpcode
;
306 req
->glxCode
= X_GLXCreateNewContext
;
307 req
->context
= gc
->xid
= XAllocID(dpy
);
308 req
->fbconfig
= generic_id
;
309 req
->screen
= screen
;
310 req
->renderType
= renderType
;
311 req
->shareList
= shareList
? shareList
->xid
: None
;
312 req
->isDirect
= gc
->isDirect
;
316 case X_GLXvop_CreateContextWithConfigSGIX
: {
317 xGLXVendorPrivateWithReplyReq
*vpreq
;
318 xGLXCreateContextWithConfigSGIXReq
*req
;
320 /* Send the glXCreateNewContext request */
321 GetReqExtra(GLXVendorPrivateWithReply
,
322 sz_xGLXCreateContextWithConfigSGIXReq
-
323 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
324 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
325 req
->reqType
= gc
->majorOpcode
;
326 req
->glxCode
= X_GLXVendorPrivateWithReply
;
327 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
328 req
->context
= gc
->xid
= XAllocID(dpy
);
329 req
->fbconfig
= generic_id
;
330 req
->screen
= screen
;
331 req
->renderType
= renderType
;
332 req
->shareList
= shareList
? shareList
->xid
: None
;
333 req
->isDirect
= gc
->isDirect
;
338 /* What to do here? This case is the sign of an internal error. It
339 * should never be reachable.
347 gc
->imported
= GL_FALSE
;
348 gc
->renderType
= renderType
;
350 return (GLXContext
) gc
;
354 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
355 GLXContext shareList
, Bool allowDirect
)
357 struct glx_config
*config
= NULL
;
360 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
361 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
363 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
364 if (config
== NULL
) {
367 error
.errorCode
= BadValue
;
368 error
.resourceID
= vis
->visualid
;
369 error
.sequenceNumber
= dpy
->request
;
370 error
.type
= X_Error
;
371 error
.majorCode
= __glXSetupForCommand(dpy
);
372 error
.minorCode
= X_GLXCreateContext
;
373 _XError(dpy
, &error
);
377 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
380 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
381 X_GLXCreateContext
, renderType
, vis
->screen
);
385 glx_send_destroy_context(Display
*dpy
, XID xid
)
387 CARD8 opcode
= __glXSetupForCommand(dpy
);
388 xGLXDestroyContextReq
*req
;
391 GetReq(GLXDestroyContext
, req
);
392 req
->reqType
= opcode
;
393 req
->glxCode
= X_GLXDestroyContext
;
400 ** Destroy the named context
404 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
406 struct glx_context
*gc
= (struct glx_context
*) ctx
;
412 if (gc
->currentDpy
) {
413 /* This context is bound to some thread. According to the man page,
414 * we should not actually delete the context until it's unbound.
415 * Note that we set gc->xid = None above. In MakeContextCurrent()
416 * we check for that and delete the context there.
419 glx_send_destroy_context(dpy
, gc
->xid
);
426 gc
->vtable
->destroy(gc
);
430 ** Return the major and minor version #s for the GLX extension
433 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
435 struct glx_display
*priv
;
437 /* Init the extension. This fetches the major and minor version. */
438 priv
= __glXInitialize(dpy
);
443 *major
= priv
->majorVersion
;
445 *minor
= priv
->minorVersion
;
450 ** Query the existance of the GLX extension
453 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
455 int major_op
, erb
, evb
;
458 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
469 ** Put a barrier in the token stream that forces the GL to finish its
470 ** work before X can proceed.
475 struct glx_context
*gc
= __glXGetCurrentContext();
477 if (gc
&& gc
->vtable
->wait_gl
)
478 gc
->vtable
->wait_gl(gc
);
482 ** Put a barrier in the token stream that forces X to finish its
483 ** work before GL can proceed.
488 struct glx_context
*gc
= __glXGetCurrentContext();
490 if (gc
&& gc
->vtable
->wait_x
)
491 gc
->vtable
->wait_x(gc
);
495 glXUseXFont(Font font
, int first
, int count
, int listBase
)
497 struct glx_context
*gc
= __glXGetCurrentContext();
499 if (gc
&& gc
->vtable
->use_x_font
)
500 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
503 /************************************************************************/
506 ** Copy the source context to the destination context using the
510 glXCopyContext(Display
* dpy
, GLXContext source_user
,
511 GLXContext dest_user
, unsigned long mask
)
513 struct glx_context
*source
= (struct glx_context
*) source_user
;
514 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
515 #ifdef GLX_USE_APPLEGL
516 struct glx_context
*gc
= __glXGetCurrentContext();
520 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
521 mask
, &errorcode
, &x11error
)) {
522 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
526 xGLXCopyContextReq
*req
;
527 struct glx_context
*gc
= __glXGetCurrentContext();
531 opcode
= __glXSetupForCommand(dpy
);
536 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
538 /* NOT_DONE: This does not work yet */
543 ** If the source is the current context, send its tag so that the context
544 ** can be flushed before the copy.
546 if (source
== gc
&& dpy
== gc
->currentDpy
) {
547 tag
= gc
->currentContextTag
;
553 /* Send the glXCopyContext request */
555 GetReq(GLXCopyContext
, req
);
556 req
->reqType
= opcode
;
557 req
->glxCode
= X_GLXCopyContext
;
558 req
->source
= source
? source
->xid
: None
;
559 req
->dest
= dest
? dest
->xid
: None
;
561 req
->contextTag
= tag
;
564 #endif /* GLX_USE_APPLEGL */
569 * Determine if a context uses direct rendering.
571 * \param dpy Display where the context was created.
572 * \param contextID ID of the context to be tested.
574 * \returns \c GL_TRUE if the context is direct rendering or not.
577 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
579 #if !defined(USE_XCB)
580 xGLXIsDirectReq
*req
;
581 xGLXIsDirectReply reply
;
585 opcode
= __glXSetupForCommand(dpy
);
591 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
592 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
597 const Bool is_direct
= reply
->is_direct
? True
: False
;
602 /* Send the glXIsDirect request */
604 GetReq(GLXIsDirect
, req
);
605 req
->reqType
= opcode
;
606 req
->glxCode
= X_GLXIsDirect
;
607 req
->context
= contextID
;
608 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
612 return reply
.isDirect
;
618 * Shouldn't this function \b always return \c GL_FALSE when
619 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
620 * the GLX protocol here at all?
623 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
625 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
630 else if (gc
->isDirect
) {
633 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
636 return __glXIsDirect(dpy
, gc
->xid
);
641 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
643 #ifdef GLX_USE_APPLEGL
644 int screen
= vis
->screen
;
645 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
646 const struct glx_config
*config
;
648 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
650 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
655 xGLXCreateGLXPixmapReq
*req
;
656 struct glx_drawable
*glxDraw
;
660 opcode
= __glXSetupForCommand(dpy
);
665 glxDraw
= Xmalloc(sizeof(*glxDraw
));
669 /* Send the glXCreateGLXPixmap request */
671 GetReq(GLXCreateGLXPixmap
, req
);
672 req
->reqType
= opcode
;
673 req
->glxCode
= X_GLXCreateGLXPixmap
;
674 req
->screen
= vis
->screen
;
675 req
->visual
= vis
->visualid
;
676 req
->pixmap
= pixmap
;
677 req
->glxpixmap
= xid
= XAllocID(dpy
);
681 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
686 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
688 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
689 * is actually bound to a context... */
691 struct glx_display
*const priv
= __glXInitialize(dpy
);
692 __GLXDRIdrawable
*pdraw
;
693 struct glx_screen
*psc
;
694 struct glx_config
*config
;
696 psc
= priv
->screens
[vis
->screen
];
697 if (psc
->driScreen
== NULL
)
700 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
701 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
703 fprintf(stderr
, "failed to create pixmap\n");
708 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
709 (*pdraw
->destroyDrawable
) (pdraw
);
716 xGLXDestroyGLXPixmapReq
*dreq
;
718 GetReq(GLXDestroyGLXPixmap
, dreq
);
719 dreq
->reqType
= opcode
;
720 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
721 dreq
->glxpixmap
= xid
;
732 ** Destroy the named pixmap
735 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
737 #ifdef GLX_USE_APPLEGL
738 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
739 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
741 xGLXDestroyGLXPixmapReq
*req
;
744 opcode
= __glXSetupForCommand(dpy
);
749 /* Send the glXDestroyGLXPixmap request */
751 GetReq(GLXDestroyGLXPixmap
, req
);
752 req
->reqType
= opcode
;
753 req
->glxCode
= X_GLXDestroyGLXPixmap
;
754 req
->glxpixmap
= glxpixmap
;
758 DestroyGLXDrawable(dpy
, glxpixmap
);
760 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
762 struct glx_display
*const priv
= __glXInitialize(dpy
);
763 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
766 (*pdraw
->destroyDrawable
) (pdraw
);
767 __glxHashDelete(priv
->drawHash
, glxpixmap
);
771 #endif /* GLX_USE_APPLEGL */
775 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
777 #ifdef GLX_USE_APPLEGL
778 struct glx_context
* gc
= __glXGetCurrentContext();
779 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
780 apple_glx_swap_buffers(gc
->driContext
);
782 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
785 struct glx_context
*gc
;
791 xGLXSwapBuffersReq
*req
;
794 gc
= __glXGetCurrentContext();
796 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
798 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
801 if (gc
&& drawable
== gc
->currentDrawable
) {
805 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
811 opcode
= __glXSetupForCommand(dpy
);
817 ** The calling thread may or may not have a current context. If it
818 ** does, send the context tag so the server can do a flush.
820 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
821 ((drawable
== gc
->currentDrawable
)
822 || (drawable
== gc
->currentReadable
))) {
823 tag
= gc
->currentContextTag
;
830 c
= XGetXCBConnection(dpy
);
831 xcb_glx_swap_buffers(c
, tag
, drawable
);
834 /* Send the glXSwapBuffers request */
836 GetReq(GLXSwapBuffers
, req
);
837 req
->reqType
= opcode
;
838 req
->glxCode
= X_GLXSwapBuffers
;
839 req
->drawable
= drawable
;
840 req
->contextTag
= tag
;
845 #endif /* GLX_USE_APPLEGL */
850 ** Return configuration information for the given display, screen and
851 ** visual combination.
854 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
857 struct glx_display
*priv
;
858 struct glx_screen
*psc
;
859 struct glx_config
*config
;
862 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
863 if (status
== Success
) {
864 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
866 /* Lookup attribute after first finding a match on the visual */
867 if (config
!= NULL
) {
868 return glx_config_get(config
, attribute
, value_return
);
871 status
= GLX_BAD_VISUAL
;
875 ** If we can't find the config for this visual, this visual is not
876 ** supported by the OpenGL implementation on the server.
878 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
879 *value_return
= GL_FALSE
;
886 /************************************************************************/
889 init_fbconfig_for_chooser(struct glx_config
* config
,
890 GLboolean fbconfig_style_tags
)
892 memset(config
, 0, sizeof(struct glx_config
));
893 config
->visualID
= (XID
) GLX_DONT_CARE
;
894 config
->visualType
= GLX_DONT_CARE
;
896 /* glXChooseFBConfig specifies different defaults for these two than
899 if (fbconfig_style_tags
) {
900 config
->rgbMode
= GL_TRUE
;
901 config
->doubleBufferMode
= GLX_DONT_CARE
;
904 config
->visualRating
= GLX_DONT_CARE
;
905 config
->transparentPixel
= GLX_NONE
;
906 config
->transparentRed
= GLX_DONT_CARE
;
907 config
->transparentGreen
= GLX_DONT_CARE
;
908 config
->transparentBlue
= GLX_DONT_CARE
;
909 config
->transparentAlpha
= GLX_DONT_CARE
;
910 config
->transparentIndex
= GLX_DONT_CARE
;
912 config
->drawableType
= GLX_WINDOW_BIT
;
914 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
915 config
->xRenderable
= GLX_DONT_CARE
;
916 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
918 config
->swapMethod
= GLX_DONT_CARE
;
921 #define MATCH_DONT_CARE( param ) \
923 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
924 && (a-> param != b-> param) ) { \
929 #define MATCH_MINIMUM( param ) \
931 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
932 && (a-> param > b-> param) ) { \
937 #define MATCH_EXACT( param ) \
939 if ( a-> param != b-> param) { \
944 /* Test that all bits from a are contained in b */
945 #define MATCH_MASK(param) \
947 if ((a->param & ~b->param) != 0) \
952 * Determine if two GLXFBConfigs are compatible.
954 * \param a Application specified config to test.
955 * \param b Server specified config to test against \c a.
958 fbconfigs_compatible(const struct glx_config
* const a
,
959 const struct glx_config
* const b
)
961 MATCH_DONT_CARE(doubleBufferMode
);
962 MATCH_DONT_CARE(visualType
);
963 MATCH_DONT_CARE(visualRating
);
964 MATCH_DONT_CARE(xRenderable
);
965 MATCH_DONT_CARE(fbconfigID
);
966 MATCH_DONT_CARE(swapMethod
);
968 MATCH_MINIMUM(rgbBits
);
969 MATCH_MINIMUM(numAuxBuffers
);
970 MATCH_MINIMUM(redBits
);
971 MATCH_MINIMUM(greenBits
);
972 MATCH_MINIMUM(blueBits
);
973 MATCH_MINIMUM(alphaBits
);
974 MATCH_MINIMUM(depthBits
);
975 MATCH_MINIMUM(stencilBits
);
976 MATCH_MINIMUM(accumRedBits
);
977 MATCH_MINIMUM(accumGreenBits
);
978 MATCH_MINIMUM(accumBlueBits
);
979 MATCH_MINIMUM(accumAlphaBits
);
980 MATCH_MINIMUM(sampleBuffers
);
981 MATCH_MINIMUM(maxPbufferWidth
);
982 MATCH_MINIMUM(maxPbufferHeight
);
983 MATCH_MINIMUM(maxPbufferPixels
);
984 MATCH_MINIMUM(samples
);
986 MATCH_DONT_CARE(stereoMode
);
989 MATCH_MASK(drawableType
);
990 MATCH_MASK(renderType
);
992 /* There is a bug in a few of the XFree86 DDX drivers. They contain
993 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
994 * Technically speaking, it is a bug in the DDX driver, but there is
995 * enough of an installed base to work around the problem here. In any
996 * case, 0 is not a valid value of the transparent type, so we'll treat 0
997 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
998 * 0 from the server to be a match to maintain backward compatibility with
999 * the (broken) drivers.
1002 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1003 if (a
->transparentPixel
== GLX_NONE
) {
1004 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1008 MATCH_EXACT(transparentPixel
);
1011 switch (a
->transparentPixel
) {
1012 case GLX_TRANSPARENT_RGB
:
1013 MATCH_DONT_CARE(transparentRed
);
1014 MATCH_DONT_CARE(transparentGreen
);
1015 MATCH_DONT_CARE(transparentBlue
);
1016 MATCH_DONT_CARE(transparentAlpha
);
1019 case GLX_TRANSPARENT_INDEX
:
1020 MATCH_DONT_CARE(transparentIndex
);
1032 /* There's some trickly language in the GLX spec about how this is supposed
1033 * to work. Basically, if a given component size is either not specified
1034 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1035 * Well, that's really hard to do with the code as-is. This behavior is
1036 * closer to correct, but still not technically right.
1038 #define PREFER_LARGER_OR_ZERO(comp) \
1040 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1041 if ( ((*a)-> comp) == 0 ) { \
1044 else if ( ((*b)-> comp) == 0 ) { \
1048 return ((*b)-> comp) - ((*a)-> comp) ; \
1053 #define PREFER_LARGER(comp) \
1055 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1056 return ((*b)-> comp) - ((*a)-> comp) ; \
1060 #define PREFER_SMALLER(comp) \
1062 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1063 return ((*a)-> comp) - ((*b)-> comp) ; \
1068 * Compare two GLXFBConfigs. This function is intended to be used as the
1069 * compare function passed in to qsort.
1071 * \returns If \c a is a "better" config, according to the specification of
1072 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1073 * better, then a number greater than zero is return. If both are
1074 * equal, zero is returned.
1075 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1078 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1080 /* The order of these comparisons must NOT change. It is defined by
1081 * the GLX 1.3 spec and ARB_multisample.
1084 PREFER_SMALLER(visualSelectGroup
);
1086 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1087 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1088 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1090 PREFER_SMALLER(visualRating
);
1092 /* This isn't quite right. It is supposed to compare the sum of the
1093 * components the user specifically set minimums for.
1095 PREFER_LARGER_OR_ZERO(redBits
);
1096 PREFER_LARGER_OR_ZERO(greenBits
);
1097 PREFER_LARGER_OR_ZERO(blueBits
);
1098 PREFER_LARGER_OR_ZERO(alphaBits
);
1100 PREFER_SMALLER(rgbBits
);
1102 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1103 /* Prefer single-buffer.
1105 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1108 PREFER_SMALLER(numAuxBuffers
);
1110 PREFER_LARGER_OR_ZERO(depthBits
);
1111 PREFER_SMALLER(stencilBits
);
1113 /* This isn't quite right. It is supposed to compare the sum of the
1114 * components the user specifically set minimums for.
1116 PREFER_LARGER_OR_ZERO(accumRedBits
);
1117 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1118 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1119 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1121 PREFER_SMALLER(visualType
);
1123 /* None of the multisample specs say where this comparison should happen,
1124 * so I put it near the end.
1126 PREFER_SMALLER(sampleBuffers
);
1127 PREFER_SMALLER(samples
);
1129 /* None of the pbuffer or fbconfig specs say that this comparison needs
1130 * to happen at all, but it seems like it should.
1132 PREFER_LARGER(maxPbufferWidth
);
1133 PREFER_LARGER(maxPbufferHeight
);
1134 PREFER_LARGER(maxPbufferPixels
);
1141 * Selects and sorts a subset of the supplied configs based on the attributes.
1142 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1143 * and \c glXChooseFBConfigSGIX.
1145 * \param configs Array of pointers to possible configs. The elements of
1146 * this array that do not meet the criteria will be set to
1147 * NULL. The remaining elements will be sorted according to
1148 * the various visual / FBConfig selection rules.
1149 * \param num_configs Number of elements in the \c configs array.
1150 * \param attribList Attributes used select from \c configs. This array is
1151 * terminated by a \c None tag. The array can either take
1152 * the form expected by \c glXChooseVisual (where boolean
1153 * tags do not have a value) or by \c glXChooseFBConfig
1154 * (where every tag has a value).
1155 * \param fbconfig_style_tags Selects whether \c attribList is in
1156 * \c glXChooseVisual style or
1157 * \c glXChooseFBConfig style.
1158 * \returns The number of valid elements left in \c configs.
1160 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1163 choose_visual(struct glx_config
** configs
, int num_configs
,
1164 const int *attribList
, GLboolean fbconfig_style_tags
)
1166 struct glx_config test_config
;
1170 /* This is a fairly direct implementation of the selection method
1171 * described by GLX_SGIX_fbconfig. Start by culling out all the
1172 * configs that are not compatible with the selected parameter
1176 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1177 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1178 (const INT32
*) attribList
,
1179 GL_TRUE
, fbconfig_style_tags
);
1182 for (i
= 0; i
< num_configs
; i
++) {
1183 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1184 configs
[base
] = configs
[i
];
1193 if (base
< num_configs
) {
1194 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1197 /* After the incompatible configs are removed, the resulting
1198 * list is sorted according to the rules set out in the various
1202 qsort(configs
, base
, sizeof(struct glx_config
*),
1203 (int (*)(const void *, const void *)) fbconfig_compare
);
1211 ** Return the visual that best matches the template. Return None if no
1212 ** visual matches the template.
1214 _X_EXPORT XVisualInfo
*
1215 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1217 XVisualInfo
*visualList
= NULL
;
1218 struct glx_display
*priv
;
1219 struct glx_screen
*psc
;
1220 struct glx_config test_config
;
1221 struct glx_config
*config
;
1222 struct glx_config
*best_config
= NULL
;
1225 ** Get a list of all visuals, return if list is empty
1227 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1233 ** Build a template from the defaults and the attribute list
1234 ** Free visual list and return if an unexpected token is encountered
1236 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1237 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1238 (const INT32
*) attribList
,
1242 ** Eliminate visuals that don't meet minimum requirements
1243 ** Compute a score for those that do
1244 ** Remember which visual, if any, got the highest score
1245 ** If no visual is acceptable, return None
1246 ** Otherwise, create an XVisualInfo list with just the selected X visual
1249 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1250 if (fbconfigs_compatible(&test_config
, config
)
1251 && ((best_config
== NULL
) ||
1252 (fbconfig_compare (&config
, &best_config
) < 0))) {
1253 XVisualInfo visualTemplate
;
1254 XVisualInfo
*newList
;
1257 visualTemplate
.screen
= screen
;
1258 visualTemplate
.visualid
= config
->visualID
;
1259 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1260 &visualTemplate
, &i
);
1264 visualList
= newList
;
1265 best_config
= config
;
1270 #ifdef GLX_USE_APPLEGL
1271 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1272 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1280 _X_EXPORT
const char *
1281 glXQueryExtensionsString(Display
* dpy
, int screen
)
1283 struct glx_screen
*psc
;
1284 struct glx_display
*priv
;
1286 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1290 if (!psc
->effectiveGLXexts
) {
1291 if (!psc
->serverGLXexts
) {
1292 psc
->serverGLXexts
=
1293 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1297 __glXCalculateUsableExtensions(psc
,
1298 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1299 (psc
->driScreen
!= NULL
),
1303 priv
->minorVersion
);
1306 return psc
->effectiveGLXexts
;
1309 _X_EXPORT
const char *
1310 glXGetClientString(Display
* dpy
, int name
)
1316 return (__glXGLXClientVendorName
);
1318 return (__glXGLXClientVersion
);
1319 case GLX_EXTENSIONS
:
1320 return (__glXGetClientExtensions());
1326 _X_EXPORT
const char *
1327 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1329 struct glx_screen
*psc
;
1330 struct glx_display
*priv
;
1334 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1340 str
= &priv
->serverGLXvendor
;
1343 str
= &priv
->serverGLXversion
;
1345 case GLX_EXTENSIONS
:
1346 str
= &psc
->serverGLXexts
;
1353 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1360 __glXClientInfo(Display
* dpy
, int opcode
)
1362 char *ext_str
= __glXGetClientGLExtensionString();
1363 int size
= strlen(ext_str
) + 1;
1366 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1367 xcb_glx_client_info(c
,
1368 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1370 xGLXClientInfoReq
*req
;
1372 /* Send the glXClientInfo request */
1374 GetReq(GLXClientInfo
, req
);
1375 req
->reqType
= opcode
;
1376 req
->glxCode
= X_GLXClientInfo
;
1377 req
->major
= GLX_MAJOR_VERSION
;
1378 req
->minor
= GLX_MINOR_VERSION
;
1380 req
->length
+= (size
+ 3) >> 2;
1381 req
->numbytes
= size
;
1382 Data(dpy
, ext_str
, size
);
1386 #endif /* USE_XCB */
1393 ** EXT_import_context
1397 glXGetCurrentDisplay(void)
1399 struct glx_context
*gc
= __glXGetCurrentContext();
1402 return gc
->currentDpy
;
1406 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1407 glXGetCurrentDisplay
)
1409 #ifndef GLX_USE_APPLEGL
1410 _X_EXPORT GLXContext
1411 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1413 struct glx_display
*priv
= __glXInitialize(dpy
);
1414 struct glx_screen
*psc
;
1415 xGLXQueryContextReply reply
;
1417 struct glx_context
*ctx
;
1418 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1421 struct glx_config
*mode
;
1423 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1426 opcode
= __glXSetupForCommand(dpy
);
1430 /* Send the glXQueryContextInfoEXT request */
1433 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1434 xGLXQueryContextReq
*req
;
1436 GetReq(GLXQueryContext
, req
);
1438 req
->reqType
= opcode
;
1439 req
->glxCode
= X_GLXQueryContext
;
1440 req
->context
= contextID
;
1443 xGLXVendorPrivateReq
*vpreq
;
1444 xGLXQueryContextInfoEXTReq
*req
;
1446 GetReqExtra(GLXVendorPrivate
,
1447 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1449 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1450 req
->reqType
= opcode
;
1451 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1452 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1453 req
->context
= contextID
;
1456 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1458 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1459 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1462 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1466 /* Look up screen first so we can look up visuals/fbconfigs later */
1468 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1469 if (pProp
[0] == GLX_SCREEN
)
1470 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1479 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1481 case GLX_SHARE_CONTEXT_EXT
:
1484 case GLX_VISUAL_ID_EXT
:
1485 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1487 case GLX_FBCONFIG_ID
:
1488 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1490 case GLX_RENDER_TYPE
:
1491 renderType
= pProp
[1];
1498 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1502 ctx
->xid
= contextID
;
1503 ctx
->imported
= GL_TRUE
;
1504 ctx
->share_xid
= share
;
1506 return (GLXContext
) ctx
;
1512 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1514 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1516 switch (attribute
) {
1517 case GLX_SHARE_CONTEXT_EXT
:
1518 *value
= ctx
->share_xid
;
1520 case GLX_VISUAL_ID_EXT
:
1521 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1524 *value
= ctx
->screen
;
1526 case GLX_FBCONFIG_ID
:
1527 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1529 case GLX_RENDER_TYPE
:
1530 *value
= ctx
->renderType
;
1533 return GLX_BAD_ATTRIBUTE
;
1539 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1540 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1541 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1543 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1545 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1551 GLX_ALIAS_VOID(glXFreeContextEXT
, (Display
*dpy
, GLXContext ctx
), (dpy
, ctx
),
1554 _X_EXPORT GLXFBConfig
*
1555 glXChooseFBConfig(Display
* dpy
, int screen
,
1556 const int *attribList
, int *nitems
)
1558 struct glx_config
**config_list
;
1562 config_list
= (struct glx_config
**)
1563 glXGetFBConfigs(dpy
, screen
, &list_size
);
1565 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1566 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1567 if (list_size
== 0) {
1573 *nitems
= list_size
;
1574 return (GLXFBConfig
*) config_list
;
1578 _X_EXPORT GLXContext
1579 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1580 int renderType
, GLXContext shareList
, Bool allowDirect
)
1582 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1584 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1585 allowDirect
, X_GLXCreateNewContext
, renderType
,
1590 _X_EXPORT GLXDrawable
1591 glXGetCurrentReadDrawable(void)
1593 struct glx_context
*gc
= __glXGetCurrentContext();
1595 return gc
->currentReadable
;
1599 _X_EXPORT GLXFBConfig
*
1600 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1602 struct glx_display
*priv
= __glXInitialize(dpy
);
1603 struct glx_config
**config_list
= NULL
;
1604 struct glx_config
*config
;
1605 unsigned num_configs
= 0;
1609 if (priv
&& (priv
->screens
!= NULL
)
1610 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1611 && (priv
->screens
[screen
]->configs
!= NULL
)
1612 && (priv
->screens
[screen
]->configs
->fbconfigID
1613 != (int) GLX_DONT_CARE
)) {
1615 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1616 config
= config
->next
) {
1617 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1622 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1623 if (config_list
!= NULL
) {
1624 *nelements
= num_configs
;
1626 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1627 config
= config
->next
) {
1628 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1629 config_list
[i
] = config
;
1636 return (GLXFBConfig
*) config_list
;
1641 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1642 int attribute
, int *value
)
1644 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1647 return GLXBadFBConfig
;
1649 return glx_config_get(config
, attribute
, value
);
1653 _X_EXPORT XVisualInfo
*
1654 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1656 XVisualInfo visualTemplate
;
1657 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1661 ** Get a list of all visuals, return if list is empty
1663 visualTemplate
.visualid
= config
->visualID
;
1664 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1667 #ifndef GLX_USE_APPLEGL
1669 ** GLX_SGI_swap_control
1672 __glXSwapIntervalSGI(int interval
)
1674 xGLXVendorPrivateReq
*req
;
1675 struct glx_context
*gc
= __glXGetCurrentContext();
1676 struct glx_screen
*psc
;
1678 CARD32
*interval_ptr
;
1682 return GLX_BAD_CONTEXT
;
1685 if (interval
<= 0) {
1686 return GLX_BAD_VALUE
;
1689 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1691 #ifdef GLX_DIRECT_RENDERING
1692 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1693 __GLXDRIdrawable
*pdraw
=
1694 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1695 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1700 dpy
= gc
->currentDpy
;
1701 opcode
= __glXSetupForCommand(dpy
);
1706 /* Send the glXSwapIntervalSGI request */
1708 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1709 req
->reqType
= opcode
;
1710 req
->glxCode
= X_GLXVendorPrivate
;
1711 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1712 req
->contextTag
= gc
->currentContextTag
;
1714 interval_ptr
= (CARD32
*) (req
+ 1);
1715 *interval_ptr
= interval
;
1726 ** GLX_MESA_swap_control
1729 __glXSwapIntervalMESA(unsigned int interval
)
1731 #ifdef GLX_DIRECT_RENDERING
1732 struct glx_context
*gc
= __glXGetCurrentContext();
1734 if (gc
!= NULL
&& gc
->isDirect
) {
1735 struct glx_screen
*psc
;
1737 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1738 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1739 __GLXDRIdrawable
*pdraw
=
1740 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1741 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1746 return GLX_BAD_CONTEXT
;
1751 __glXGetSwapIntervalMESA(void)
1753 #ifdef GLX_DIRECT_RENDERING
1754 struct glx_context
*gc
= __glXGetCurrentContext();
1756 if (gc
!= NULL
&& gc
->isDirect
) {
1757 struct glx_screen
*psc
;
1759 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1760 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1761 __GLXDRIdrawable
*pdraw
=
1762 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1763 return psc
->driScreen
->getSwapInterval(pdraw
);
1773 ** GLX_SGI_video_sync
1776 __glXGetVideoSyncSGI(unsigned int *count
)
1778 int64_t ust
, msc
, sbc
;
1780 struct glx_context
*gc
= __glXGetCurrentContext();
1781 struct glx_screen
*psc
;
1782 #ifdef GLX_DIRECT_RENDERING
1783 __GLXDRIdrawable
*pdraw
;
1787 return GLX_BAD_CONTEXT
;
1789 #ifdef GLX_DIRECT_RENDERING
1791 return GLX_BAD_CONTEXT
;
1794 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1795 #ifdef GLX_DIRECT_RENDERING
1796 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1799 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1800 * FIXME: there should be a GLX encoding for this call. I can find no
1801 * FIXME: documentation for the GLX encoding.
1803 #ifdef GLX_DIRECT_RENDERING
1804 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1805 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1806 *count
= (unsigned) msc
;
1807 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1811 return GLX_BAD_CONTEXT
;
1815 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1817 struct glx_context
*gc
= __glXGetCurrentContext();
1818 struct glx_screen
*psc
;
1819 #ifdef GLX_DIRECT_RENDERING
1820 __GLXDRIdrawable
*pdraw
;
1822 int64_t ust
, msc
, sbc
;
1825 if (divisor
<= 0 || remainder
< 0)
1826 return GLX_BAD_VALUE
;
1829 return GLX_BAD_CONTEXT
;
1831 #ifdef GLX_DIRECT_RENDERING
1833 return GLX_BAD_CONTEXT
;
1836 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1837 #ifdef GLX_DIRECT_RENDERING
1838 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1841 #ifdef GLX_DIRECT_RENDERING
1842 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1843 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1845 *count
= (unsigned) msc
;
1846 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1850 return GLX_BAD_CONTEXT
;
1853 #endif /* GLX_USE_APPLEGL */
1856 ** GLX_SGIX_fbconfig
1857 ** Many of these functions are aliased to GLX 1.3 entry points in the
1858 ** GLX_functions table.
1862 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1863 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1864 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1866 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1867 (Display
* dpy
, int screen
, int *attrib_list
,
1868 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1871 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1872 (Display
* dpy
, GLXFBConfigSGIX config
),
1873 (dpy
, config
), glXGetVisualFromFBConfig
)
1876 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1877 GLXFBConfigSGIX fbconfig
,
1880 #ifndef GLX_USE_APPLEGL
1881 xGLXVendorPrivateWithReplyReq
*vpreq
;
1882 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1883 GLXPixmap xid
= None
;
1885 struct glx_screen
*psc
;
1887 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1890 if ((dpy
== NULL
) || (config
== NULL
)) {
1893 #ifdef GLX_USE_APPLEGL
1894 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1899 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1901 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1902 opcode
= __glXSetupForCommand(dpy
);
1907 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1909 GetReqExtra(GLXVendorPrivateWithReply
,
1910 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1911 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1912 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1913 req
->reqType
= opcode
;
1914 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1915 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1916 req
->screen
= config
->screen
;
1917 req
->fbconfig
= config
->fbconfigID
;
1918 req
->pixmap
= pixmap
;
1919 req
->glxpixmap
= xid
= XAllocID(dpy
);
1928 _X_EXPORT GLXContext
1929 glXCreateContextWithConfigSGIX(Display
* dpy
,
1930 GLXFBConfigSGIX fbconfig
, int renderType
,
1931 GLXContext shareList
, Bool allowDirect
)
1933 GLXContext gc
= NULL
;
1934 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1935 struct glx_screen
*psc
;
1938 if ((dpy
== NULL
) || (config
== NULL
)) {
1942 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1944 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1945 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1947 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1955 _X_EXPORT GLXFBConfigSGIX
1956 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1958 struct glx_display
*priv
;
1959 struct glx_screen
*psc
= NULL
;
1961 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
1962 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1963 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1964 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1971 #ifndef GLX_USE_APPLEGL
1973 ** GLX_SGIX_swap_group
1976 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1986 ** GLX_SGIX_swap_barrier
1989 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1997 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2007 ** GLX_OML_sync_control
2010 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2011 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2013 struct glx_display
* const priv
= __glXInitialize(dpy
);
2015 #ifdef GLX_DIRECT_RENDERING
2016 __GLXDRIdrawable
*pdraw
;
2018 struct glx_screen
*psc
;
2023 #ifdef GLX_DIRECT_RENDERING
2024 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2025 psc
= pdraw
? pdraw
->psc
: NULL
;
2026 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2027 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2035 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2037 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2038 int32_t * numerator
, int32_t * denominator
)
2041 struct glx_screen
*psc
;
2042 XF86VidModeModeLine mode_line
;
2047 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2048 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2049 unsigned n
= dot_clock
* 1000;
2050 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2052 # define V_INTERLACE 0x010
2053 # define V_DBLSCAN 0x020
2055 if (mode_line
.flags
& V_INTERLACE
)
2057 else if (mode_line
.flags
& V_DBLSCAN
)
2060 /* The OML_sync_control spec requires that if the refresh rate is a
2061 * whole number, that the returned numerator be equal to the refresh
2062 * rate and the denominator be 1.
2070 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2072 /* This is a poor man's way to reduce a fraction. It's far from
2073 * perfect, but it will work well enough for this situation.
2076 for (i
= 0; f
[i
] != 0; i
++) {
2077 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2097 * Determine the refresh rate of the specified drawable and display.
2099 * \param dpy Display whose refresh rate is to be determined.
2100 * \param drawable Drawable whose refresh rate is to be determined.
2101 * \param numerator Numerator of the refresh rate.
2102 * \param demoninator Denominator of the refresh rate.
2103 * \return If the refresh rate for the specified display and drawable could
2104 * be calculated, True is returned. Otherwise False is returned.
2106 * \note This function is implemented entirely client-side. A lot of other
2107 * functionality is required to export GLX_OML_sync_control, so on
2108 * XFree86 this function can be called for direct-rendering contexts
2109 * when GLX_OML_sync_control appears in the client extension string.
2113 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2114 int32_t * numerator
, int32_t * denominator
)
2116 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2117 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2122 return __glxGetMscRate(draw
, numerator
, denominator
);
2134 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2135 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2137 struct glx_context
*gc
= __glXGetCurrentContext();
2138 #ifdef GLX_DIRECT_RENDERING
2139 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2140 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2143 if (!gc
) /* no GLX for this */
2146 #ifdef GLX_DIRECT_RENDERING
2147 if (!pdraw
|| !gc
->isDirect
)
2151 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2152 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2153 * of -1 if the function failed because of errors detected in the input
2156 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2158 if (divisor
> 0 && remainder
>= divisor
)
2161 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2164 #ifdef GLX_DIRECT_RENDERING
2165 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2166 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2175 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2176 int64_t target_msc
, int64_t divisor
,
2177 int64_t remainder
, int64_t * ust
,
2178 int64_t * msc
, int64_t * sbc
)
2180 #ifdef GLX_DIRECT_RENDERING
2181 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2182 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2187 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2188 * error", but the return type in the spec is Bool.
2190 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2192 if (divisor
> 0 && remainder
>= divisor
)
2195 #ifdef GLX_DIRECT_RENDERING
2196 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2197 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2208 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2209 int64_t target_sbc
, 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
;
2218 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2219 * error", but the return type in the spec is Bool.
2224 #ifdef GLX_DIRECT_RENDERING
2225 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2226 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2238 * Mesa extension stubs. These will help reduce portability problems.
2243 * Release all buffers associated with the specified GLX drawable.
2246 * This function was intended for stand-alone Mesa. The issue there is that
2247 * the library doesn't get any notification when a window is closed. In
2248 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2249 * supported, there are 3 different functions to destroy a drawable. It
2250 * should be possible to create GLX protocol (or have it determine which
2251 * protocol to use based on the type of the drawable) to have one function
2252 * do the work of 3. For the direct-rendering case, this function could
2253 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2254 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2255 * would need to be used. This really should be done as part of the new DRI
2258 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2259 * __driGarbageCollectDrawables
2260 * glXDestroyGLXPixmap
2261 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2262 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2265 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2274 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2275 Pixmap pixmap
, Colormap cmap
)
2288 * GLX_MESA_copy_sub_buffer
2290 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2292 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2293 int x
, int y
, int width
, int height
)
2295 xGLXVendorPrivateReq
*req
;
2296 struct glx_context
*gc
;
2298 CARD32
*drawable_ptr
;
2299 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2302 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2303 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2304 if (pdraw
!= NULL
) {
2305 struct glx_screen
*psc
= pdraw
->psc
;
2306 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2308 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2315 opcode
= __glXSetupForCommand(dpy
);
2320 ** The calling thread may or may not have a current context. If it
2321 ** does, send the context tag so the server can do a flush.
2323 gc
= __glXGetCurrentContext();
2324 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2325 ((drawable
== gc
->currentDrawable
) ||
2326 (drawable
== gc
->currentReadable
))) {
2327 tag
= gc
->currentContextTag
;
2334 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2335 req
->reqType
= opcode
;
2336 req
->glxCode
= X_GLXVendorPrivate
;
2337 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2338 req
->contextTag
= tag
;
2340 drawable_ptr
= (CARD32
*) (req
+ 1);
2341 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2342 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2343 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2344 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2346 *drawable_ptr
= drawable
;
2358 __glXBindTexImageEXT(Display
* dpy
,
2359 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2361 struct glx_context
*gc
= __glXGetCurrentContext();
2363 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2366 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2370 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2372 struct glx_context
*gc
= __glXGetCurrentContext();
2374 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2377 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2382 #endif /* GLX_USE_APPLEGL */
2385 * \c strdup is actually not a standard ANSI C or POSIX routine.
2386 * Irix will not define it if ANSI mode is in effect.
2391 __glXstrdup(const char *str
)
2394 copy
= (char *) Xmalloc(strlen(str
) + 1);
2402 ** glXGetProcAddress support
2405 struct name_address_pair
2411 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2412 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2414 static const struct name_address_pair GLX_functions
[] = {
2415 /*** GLX_VERSION_1_0 ***/
2416 GLX_FUNCTION(glXChooseVisual
),
2417 GLX_FUNCTION(glXCopyContext
),
2418 GLX_FUNCTION(glXCreateContext
),
2419 GLX_FUNCTION(glXCreateGLXPixmap
),
2420 GLX_FUNCTION(glXDestroyContext
),
2421 GLX_FUNCTION(glXDestroyGLXPixmap
),
2422 GLX_FUNCTION(glXGetConfig
),
2423 GLX_FUNCTION(glXGetCurrentContext
),
2424 GLX_FUNCTION(glXGetCurrentDrawable
),
2425 GLX_FUNCTION(glXIsDirect
),
2426 GLX_FUNCTION(glXMakeCurrent
),
2427 GLX_FUNCTION(glXQueryExtension
),
2428 GLX_FUNCTION(glXQueryVersion
),
2429 GLX_FUNCTION(glXSwapBuffers
),
2430 GLX_FUNCTION(glXUseXFont
),
2431 GLX_FUNCTION(glXWaitGL
),
2432 GLX_FUNCTION(glXWaitX
),
2434 /*** GLX_VERSION_1_1 ***/
2435 GLX_FUNCTION(glXGetClientString
),
2436 GLX_FUNCTION(glXQueryExtensionsString
),
2437 GLX_FUNCTION(glXQueryServerString
),
2439 /*** GLX_VERSION_1_2 ***/
2440 GLX_FUNCTION(glXGetCurrentDisplay
),
2442 /*** GLX_VERSION_1_3 ***/
2443 GLX_FUNCTION(glXChooseFBConfig
),
2444 GLX_FUNCTION(glXCreateNewContext
),
2445 GLX_FUNCTION(glXCreatePbuffer
),
2446 GLX_FUNCTION(glXCreatePixmap
),
2447 GLX_FUNCTION(glXCreateWindow
),
2448 GLX_FUNCTION(glXDestroyPbuffer
),
2449 GLX_FUNCTION(glXDestroyPixmap
),
2450 GLX_FUNCTION(glXDestroyWindow
),
2451 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2452 GLX_FUNCTION(glXGetFBConfigAttrib
),
2453 GLX_FUNCTION(glXGetFBConfigs
),
2454 GLX_FUNCTION(glXGetSelectedEvent
),
2455 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2456 GLX_FUNCTION(glXMakeContextCurrent
),
2457 GLX_FUNCTION(glXQueryContext
),
2458 GLX_FUNCTION(glXQueryDrawable
),
2459 GLX_FUNCTION(glXSelectEvent
),
2461 #ifndef GLX_USE_APPLEGL
2462 /*** GLX_SGI_swap_control ***/
2463 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2465 /*** GLX_SGI_video_sync ***/
2466 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2467 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2469 /*** GLX_SGI_make_current_read ***/
2470 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2471 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2473 /*** GLX_EXT_import_context ***/
2474 GLX_FUNCTION(glXFreeContextEXT
),
2475 GLX_FUNCTION(glXGetContextIDEXT
),
2476 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2477 GLX_FUNCTION(glXImportContextEXT
),
2478 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2481 /*** GLX_SGIX_fbconfig ***/
2482 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2483 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2484 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2485 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2486 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2487 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2489 #ifndef GLX_USE_APPLEGL
2490 /*** GLX_SGIX_pbuffer ***/
2491 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2492 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2493 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2494 GLX_FUNCTION(glXSelectEventSGIX
),
2495 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2497 /*** GLX_SGIX_swap_group ***/
2498 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2500 /*** GLX_SGIX_swap_barrier ***/
2501 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2502 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2504 /*** GLX_MESA_copy_sub_buffer ***/
2505 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2507 /*** GLX_MESA_pixmap_colormap ***/
2508 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2510 /*** GLX_MESA_release_buffers ***/
2511 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2513 /*** GLX_MESA_swap_control ***/
2514 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2515 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2518 /*** GLX_ARB_get_proc_address ***/
2519 GLX_FUNCTION(glXGetProcAddressARB
),
2522 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2524 #ifndef GLX_USE_APPLEGL
2525 /*** GLX_OML_sync_control ***/
2526 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2527 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2528 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2529 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2530 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2532 /*** GLX_EXT_texture_from_pixmap ***/
2533 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2534 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2537 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2538 /*** DRI configuration ***/
2539 GLX_FUNCTION(glXGetScreenDriver
),
2540 GLX_FUNCTION(glXGetDriverConfig
),
2543 {NULL
, NULL
} /* end of list */
2546 static const GLvoid
*
2547 get_glx_proc_address(const char *funcName
)
2551 /* try static functions */
2552 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2553 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2554 return GLX_functions
[i
].Address
;
2561 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2562 * \c glXGetProcAddress.
2564 * \param procName Name of a GL or GLX function.
2565 * \returns A pointer to the named function
2567 * \sa glXGetProcAddress
2569 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2571 typedef void (*gl_function
) (void);
2575 /* Search the table of GLX and internal functions first. If that
2576 * fails and the supplied name could be a valid core GL name, try
2577 * searching the core GL function table. This check is done to prevent
2578 * DRI based drivers from searching the core GL function table for
2579 * internal API functions.
2581 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2582 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2583 && (procName
[2] != 'X')) {
2584 #ifdef GLX_SHARED_GLAPI
2585 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2588 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2590 struct glx_context
*gc
= __glXGetCurrentContext();
2592 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2593 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2600 * Get the address of a named GL function. This is the GLX 1.4 name for
2601 * \c glXGetProcAddressARB.
2603 * \param procName Name of a GL or GLX function.
2604 * \returns A pointer to the named function
2606 * \sa glXGetProcAddressARB
2608 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2609 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2610 __attribute__ ((alias("glXGetProcAddressARB")));
2613 return glXGetProcAddressARB(procName
);
2615 #endif /* __GNUC__ */
2618 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2620 * Get the unadjusted system time (UST). Currently, the UST is measured in
2621 * microseconds since Epoc. The actual resolution of the UST may vary from
2622 * system to system, and the units may vary from release to release.
2623 * Drivers should not call this function directly. They should instead use
2624 * \c glXGetProcAddress to obtain a pointer to the function.
2626 * \param ust Location to store the 64-bit UST
2627 * \returns Zero on success or a negative errno value on failure.
2629 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2631 * \since Internal API version 20030317.
2634 __glXGetUST(int64_t * ust
)
2642 if (gettimeofday(&tv
, NULL
) == 0) {
2643 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2650 #endif /* GLX_DIRECT_RENDERING */