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 #ifdef GLX_DIRECT_RENDERING
41 #ifdef GLX_USE_APPLEGL
42 #include "apple_glx_context.h"
43 #include "apple_glx.h"
44 #include "glx_error.h"
45 #define GC_IS_DIRECT(gc) ((gc)->isDirect)
48 #include <X11/extensions/xf86vmode.h>
50 #define GC_IS_DIRECT(gc) ((gc)->driContext != NULL)
53 #define GC_IS_DIRECT(gc) (0)
57 #include <X11/Xlib-xcb.h>
62 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
63 static const char __glXGLXClientVersion
[] = "1.4";
64 static const struct glx_context_vtable indirect_context_vtable
;
66 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
68 static Bool windowExistsFlag
;
70 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
74 if (xerr
->error_code
== BadWindow
) {
75 windowExistsFlag
= GL_FALSE
;
81 * Find drawables in the local hash that have been destroyed on the
84 * \param dpy Display to destroy drawables for
85 * \param screen Screen number to destroy drawables for
88 GarbageCollectDRIDrawables(struct glx_screen
* sc
)
91 __GLXDRIdrawable
*pdraw
;
92 __GLXdisplayPrivate
*priv
= sc
->display
;
93 XWindowAttributes xwa
;
94 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
96 /* Set no-op error handler so Xlib doesn't bail out if the windows
97 * has alreay been destroyed on the server. */
98 XSync(priv
->dpy
, GL_FALSE
);
99 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
101 if (__glxHashFirst(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
103 windowExistsFlag
= GL_TRUE
;
104 XGetWindowAttributes(priv
->dpy
, draw
, &xwa
); /* dummy request */
105 if (!windowExistsFlag
) {
106 /* Destroy the local drawable data, if the drawable no
107 longer exists in the Xserver */
108 (*pdraw
->destroyDrawable
) (pdraw
);
109 __glxHashDelete(priv
->drawHash
, draw
);
111 } while (__glxHashNext(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1);
114 XSync(priv
->dpy
, GL_FALSE
);
115 XSetErrorHandler(oldXErrorHandler
);
119 * Get the __DRIdrawable for the drawable associated with a GLXContext
121 * \param dpy The display associated with \c drawable.
122 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
123 * \param scrn_num If non-NULL, the drawables screen is stored there
124 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
125 * the drawable is not associated with a direct-rendering context.
127 _X_HIDDEN __GLXDRIdrawable
*
128 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
130 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
131 __GLXDRIdrawable
*pdraw
;
136 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
146 * Get the GLX per-screen data structure associated with a GLX context.
148 * \param dpy Display for which the GLX per-screen information is to be
150 * \param scrn Screen on \c dpy for which the GLX per-screen information is
152 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
153 * specify a valid GLX screen, or NULL otherwise.
155 * \todo Should this function validate that \c scrn is within the screen
156 * number range for \c dpy?
159 static struct glx_screen
*
160 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
162 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
166 NULL
) ? priv
->screens
[scrn
] : NULL
;
171 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
172 struct glx_screen
** ppsc
)
174 /* Initialize the extension, if needed . This has the added value
175 * of initializing/allocating the display private
179 return GLX_NO_EXTENSION
;
182 *ppriv
= __glXInitialize(dpy
);
183 if (*ppriv
== NULL
) {
184 return GLX_NO_EXTENSION
;
187 /* Check screen number to see if its valid */
188 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
189 return GLX_BAD_SCREEN
;
192 /* Check to see if the GL is supported on this screen */
193 *ppsc
= (*ppriv
)->screens
[scrn
];
194 if ((*ppsc
)->configs
== NULL
) {
195 /* No support for GL on this screen regardless of visual */
196 return GLX_BAD_VISUAL
;
204 * Determine if a \c GLXFBConfig supplied by the application is valid.
206 * \param dpy Application supplied \c Display pointer.
207 * \param config Application supplied \c GLXFBConfig.
209 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
210 * \c struct glx_config structure is returned. Otherwise, \c NULL
213 static struct glx_config
*
214 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
216 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
217 int num_screens
= ScreenCount(dpy
);
219 struct glx_config
*config
;
222 for (i
= 0; i
< num_screens
; i
++) {
223 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
224 config
= config
->next
) {
225 if (config
== (struct glx_config
*) fbconfig
) {
235 #ifdef GLX_USE_APPLEGL
237 static const struct glx_context_vtable applegl_context_vtable
;
240 applegl_create_context(struct glx_screen
*psc
,
241 struct glx_config
*mode
,
242 GLXContext shareList
, int renderType
)
248 /* TODO: Integrate this with apple_glx_create_context and make
249 * struct apple_glx_context inherit from __GLXcontext. */
251 gc
= Xmalloc(sizeof *gc
);
255 memset(gc
, 0, sizeof *gc
);
256 if (!glx_context_init(&gc
->base
, &psc
->base
, mode
)) {
261 gc
->vtable
= &applegl_context_vtable
;
262 gc
->driContext
= NULL
;
263 gc
->do_destroy
= False
;
265 /* TODO: darwin: Integrate with above to do indirect */
266 if(apple_glx_create_context(&gc
->driContext
, dpy
, screen
, fbconfig
,
267 shareList
? shareList
->driContext
: NULL
,
268 &errorcode
, &x11error
)) {
269 __glXSendError(dpy
, errorcode
, 0, X_GLXCreateContext
, x11error
);
270 gc
->vtable
->destroy(gc
);
274 gc
->currentContextTag
= -1;
276 gc
->isDirect
= allowDirect
;
277 gc
->xid
= 1; /* Just something not None, so we know when to destroy
278 * it in MakeContextCurrent. */
286 * \todo It should be possible to move the allocate of \c client_state_private
287 * later in the function for direct-rendering contexts. Direct-rendering
288 * contexts don't need to track client state, so they don't need that memory
291 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
292 * function called \c __glXAllocateClientState that allocates the memory and
293 * does all the initialization (including the pixel pack / unpack).
296 indirect_create_context(struct glx_screen
*psc
,
297 struct glx_config
*mode
,
298 GLXContext shareList
, int renderType
)
303 __GLXattribute
*state
;
305 opcode
= __glXSetupForCommand(psc
->dpy
);
310 /* Allocate our context record */
311 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
316 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
318 glx_context_init(gc
, psc
, mode
);
319 gc
->isDirect
= GL_FALSE
;
320 gc
->vtable
= &indirect_context_vtable
;
321 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
327 gc
->client_state_private
= state
;
328 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
329 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
332 ** Create a temporary buffer to hold GLX rendering commands. The size
333 ** of the buffer is selected so that the maximum number of GLX rendering
334 ** commands can fit in a single X packet and still have room in the X
335 ** packet for the GLXRenderReq header.
338 bufSize
= (XMaxRequestSize(psc
->dpy
) * 4) - sz_xGLXRenderReq
;
339 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
341 Xfree(gc
->client_state_private
);
345 gc
->bufSize
= bufSize
;
347 /* Fill in the new context */
348 gc
->renderMode
= GL_RENDER
;
350 state
->storePack
.alignment
= 4;
351 state
->storeUnpack
.alignment
= 4;
353 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
356 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
357 ** Other code uses the fastImageUnpack bit, but it is never set
360 gc
->fastImageUnpack
= GL_FALSE
;
361 gc
->fillImage
= __glFillImage
;
363 gc
->bufEnd
= gc
->buf
+ bufSize
;
364 gc
->isDirect
= GL_FALSE
;
367 ** Set limit register so that there will be one command per packet
372 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
374 gc
->majorOpcode
= opcode
;
377 ** Constrain the maximum drawing command size allowed to be
378 ** transfered using the X_GLXRender protocol request. First
379 ** constrain by a software limit, then constrain by the protocl
382 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
383 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
385 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
386 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
388 gc
->maxSmallRenderCommandSize
= bufSize
;
394 struct glx_screen_vtable indirect_screen_vtable
= {
395 indirect_create_context
398 _X_HIDDEN
struct glx_screen
*
399 indirect_create_screen(int screen
, __GLXdisplayPrivate
* priv
)
401 struct glx_screen
*psc
;
403 psc
= Xmalloc(sizeof *psc
);
407 memset(psc
, 0, sizeof *psc
);
408 glx_screen_init(psc
, screen
, priv
);
409 psc
->vtable
= &indirect_screen_vtable
;
416 glx_context_init(__GLXcontext
*gc
,
417 struct glx_screen
*psc
, struct glx_config
*config
)
419 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
420 if (!gc
->majorOpcode
)
423 gc
->screen
= psc
->scr
;
426 gc
->isDirect
= GL_TRUE
;
433 * Create a new context. Exactly one of \c vis and \c fbconfig should be
436 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
437 * SGIX_fbconfig protocol be used?
438 * \param renderType For FBConfigs, what is the rendering type?
442 CreateContext(Display
* dpy
, int generic_id
,
443 struct glx_config
*config
,
444 GLXContext shareList
,
446 unsigned code
, int renderType
, int screen
)
448 GLXContext gc
= NULL
;
449 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
454 if (generic_id
== None
)
458 if (allowDirect
&& psc
->vtable
->create_context
)
459 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
461 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
467 case X_GLXCreateContext
: {
468 xGLXCreateContextReq
*req
;
470 /* Send the glXCreateContext request */
471 GetReq(GLXCreateContext
, req
);
472 req
->reqType
= gc
->majorOpcode
;
473 req
->glxCode
= X_GLXCreateContext
;
474 req
->context
= gc
->xid
= XAllocID(dpy
);
475 req
->visual
= generic_id
;
476 req
->screen
= screen
;
477 req
->shareList
= shareList
? shareList
->xid
: None
;
478 req
->isDirect
= GC_IS_DIRECT(gc
);
482 case X_GLXCreateNewContext
: {
483 xGLXCreateNewContextReq
*req
;
485 /* Send the glXCreateNewContext request */
486 GetReq(GLXCreateNewContext
, req
);
487 req
->reqType
= gc
->majorOpcode
;
488 req
->glxCode
= X_GLXCreateNewContext
;
489 req
->context
= gc
->xid
= XAllocID(dpy
);
490 req
->fbconfig
= generic_id
;
491 req
->screen
= screen
;
492 req
->renderType
= renderType
;
493 req
->shareList
= shareList
? shareList
->xid
: None
;
494 req
->isDirect
= GC_IS_DIRECT(gc
);
498 case X_GLXvop_CreateContextWithConfigSGIX
: {
499 xGLXVendorPrivateWithReplyReq
*vpreq
;
500 xGLXCreateContextWithConfigSGIXReq
*req
;
502 /* Send the glXCreateNewContext request */
503 GetReqExtra(GLXVendorPrivateWithReply
,
504 sz_xGLXCreateContextWithConfigSGIXReq
-
505 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
506 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
507 req
->reqType
= gc
->majorOpcode
;
508 req
->glxCode
= X_GLXVendorPrivateWithReply
;
509 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
510 req
->context
= gc
->xid
= XAllocID(dpy
);
511 req
->fbconfig
= generic_id
;
512 req
->screen
= screen
;
513 req
->renderType
= renderType
;
514 req
->shareList
= shareList
? shareList
->xid
: None
;
515 req
->isDirect
= GC_IS_DIRECT(gc
);
520 /* What to do here? This case is the sign of an internal error. It
521 * should never be reachable.
529 gc
->imported
= GL_FALSE
;
530 gc
->renderType
= renderType
;
536 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
537 GLXContext shareList
, Bool allowDirect
)
539 struct glx_config
*config
= NULL
;
542 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
543 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
545 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
546 if (config
== NULL
) {
549 error
.errorCode
= BadValue
;
550 error
.resourceID
= vis
->visualid
;
551 error
.sequenceNumber
= dpy
->request
;
552 error
.type
= X_Error
;
553 error
.majorCode
= __glXSetupForCommand(dpy
);
554 error
.minorCode
= X_GLXCreateContext
;
555 _XError(dpy
, &error
);
559 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
562 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
563 X_GLXCreateContext
, renderType
, vis
->screen
);
567 glx_send_destroy_context(Display
*dpy
, XID xid
)
569 CARD8 opcode
= __glXSetupForCommand(dpy
);
570 xGLXDestroyContextReq
*req
;
573 GetReq(GLXDestroyContext
, req
);
574 req
->reqType
= opcode
;
575 req
->glxCode
= X_GLXDestroyContext
;
582 indirect_destroy_context(__GLXcontext
*gc
)
584 if (!gc
->imported
&& gc
->xid
)
585 glx_send_destroy_context(gc
->psc
->dpy
, gc
->xid
);
587 __glXFreeVertexArrayState(gc
);
590 XFree((char *) gc
->vendor
);
592 XFree((char *) gc
->renderer
);
594 XFree((char *) gc
->version
);
596 XFree((char *) gc
->extensions
);
597 __glFreeAttributeState(gc
);
598 XFree((char *) gc
->buf
);
599 Xfree((char *) gc
->client_state_private
);
604 ** Destroy the named context
607 DestroyContext(Display
* dpy
, GLXContext gc
)
613 if (gc
->currentDpy
) {
614 /* This context is bound to some thread. According to the man page,
615 * we should not actually delete the context until it's unbound.
616 * Note that we set gc->xid = None above. In MakeContextCurrent()
617 * we check for that and delete the context there.
620 glx_send_destroy_context(dpy
, gc
->xid
);
627 if (gc
->vtable
->destroy
)
628 gc
->vtable
->destroy(gc
);
632 glXDestroyContext(Display
* dpy
, GLXContext gc
)
634 DestroyContext(dpy
, gc
);
638 ** Return the major and minor version #s for the GLX extension
641 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
643 __GLXdisplayPrivate
*priv
;
645 /* Init the extension. This fetches the major and minor version. */
646 priv
= __glXInitialize(dpy
);
651 *major
= priv
->majorVersion
;
653 *minor
= priv
->minorVersion
;
658 ** Query the existance of the GLX extension
661 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
663 int major_op
, erb
, evb
;
666 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
677 indirect_wait_gl(__GLXcontext
*gc
)
680 Display
*dpy
= gc
->currentDpy
;
682 /* Flush any pending commands out */
683 __glXFlushRenderBuffer(gc
, gc
->pc
);
685 /* Send the glXWaitGL request */
687 GetReq(GLXWaitGL
, req
);
688 req
->reqType
= gc
->majorOpcode
;
689 req
->glxCode
= X_GLXWaitGL
;
690 req
->contextTag
= gc
->currentContextTag
;
696 ** Put a barrier in the token stream that forces the GL to finish its
697 ** work before X can proceed.
702 GLXContext gc
= __glXGetCurrentContext();
704 if (gc
&& gc
->vtable
->use_x_font
)
705 gc
->vtable
->wait_gl(gc
);
709 indirect_wait_x(__GLXcontext
*gc
)
712 Display
*dpy
= gc
->currentDpy
;
714 /* Flush any pending commands out */
715 __glXFlushRenderBuffer(gc
, gc
->pc
);
718 GetReq(GLXWaitX
, req
);
719 req
->reqType
= gc
->majorOpcode
;
720 req
->glxCode
= X_GLXWaitX
;
721 req
->contextTag
= gc
->currentContextTag
;
727 ** Put a barrier in the token stream that forces X to finish its
728 ** work before GL can proceed.
733 GLXContext gc
= __glXGetCurrentContext();
735 if (gc
&& gc
->vtable
->use_x_font
)
736 gc
->vtable
->wait_x(gc
);
740 indirect_use_x_font(__GLXcontext
*gc
,
741 Font font
, int first
, int count
, int listBase
)
743 xGLXUseXFontReq
*req
;
744 Display
*dpy
= gc
->currentDpy
;
746 /* Flush any pending commands out */
747 __glXFlushRenderBuffer(gc
, gc
->pc
);
749 /* Send the glXUseFont request */
751 GetReq(GLXUseXFont
, req
);
752 req
->reqType
= gc
->majorOpcode
;
753 req
->glxCode
= X_GLXUseXFont
;
754 req
->contextTag
= gc
->currentContextTag
;
758 req
->listBase
= listBase
;
763 #ifdef GLX_USE_APPLEGL
766 applegl_destroy_context(__GLXcontext
*gc
)
768 apple_glx_destroy_context(&gc
->driContext
, gc
->currentDpy
);
772 applegl_wait_gl(__GLXcontext
*gc
)
778 applegl_wait_x(__GLXcontext
*gc
)
780 apple_glx_waitx(gc
->dpy
, gc
->driContext
);
783 static const struct glx_context_vtable applegl_context_vtable
= {
784 applegl_destroy_context
,
788 NULL
, /* bind_tex_image, */
789 NULL
, /* release_tex_image, */
795 glXUseXFont(Font font
, int first
, int count
, int listBase
)
797 GLXContext gc
= __glXGetCurrentContext();
799 if (gc
&& gc
->vtable
->use_x_font
)
800 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
803 /************************************************************************/
806 ** Copy the source context to the destination context using the
810 glXCopyContext(Display
* dpy
, GLXContext source
,
811 GLXContext dest
, unsigned long mask
)
813 #ifdef GLX_USE_APPLEGL
814 GLXContext gc
= __glXGetCurrentContext();
818 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
819 mask
, &errorcode
, &x11error
)) {
820 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
824 xGLXCopyContextReq
*req
;
825 GLXContext gc
= __glXGetCurrentContext();
829 opcode
= __glXSetupForCommand(dpy
);
834 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
835 if (gc
->driContext
) {
836 /* NOT_DONE: This does not work yet */
841 ** If the source is the current context, send its tag so that the context
842 ** can be flushed before the copy.
844 if (source
== gc
&& dpy
== gc
->currentDpy
) {
845 tag
= gc
->currentContextTag
;
851 /* Send the glXCopyContext request */
853 GetReq(GLXCopyContext
, req
);
854 req
->reqType
= opcode
;
855 req
->glxCode
= X_GLXCopyContext
;
856 req
->source
= source
? source
->xid
: None
;
857 req
->dest
= dest
? dest
->xid
: None
;
859 req
->contextTag
= tag
;
862 #endif /* GLX_USE_APPLEGL */
867 * Determine if a context uses direct rendering.
869 * \param dpy Display where the context was created.
870 * \param contextID ID of the context to be tested.
872 * \returns \c GL_TRUE if the context is direct rendering or not.
875 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
877 #if !defined(USE_XCB)
878 xGLXIsDirectReq
*req
;
879 xGLXIsDirectReply reply
;
883 opcode
= __glXSetupForCommand(dpy
);
889 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
890 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
895 const Bool is_direct
= reply
->is_direct
? True
: False
;
900 /* Send the glXIsDirect request */
902 GetReq(GLXIsDirect
, req
);
903 req
->reqType
= opcode
;
904 req
->glxCode
= X_GLXIsDirect
;
905 req
->context
= contextID
;
906 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
910 return reply
.isDirect
;
916 * Shouldn't this function \b always return \c GL_FALSE when
917 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
918 * the GLX protocol here at all?
921 glXIsDirect(Display
* dpy
, GLXContext gc
)
926 else if (GC_IS_DIRECT(gc
)) {
929 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
932 return __glXIsDirect(dpy
, gc
->xid
);
937 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
939 #ifdef GLX_USE_APPLEGL
940 int screen
= vis
->screen
;
941 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
942 const struct glx_config
*config
;
944 config
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
946 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
951 xGLXCreateGLXPixmapReq
*req
;
955 opcode
= __glXSetupForCommand(dpy
);
960 /* Send the glXCreateGLXPixmap request */
962 GetReq(GLXCreateGLXPixmap
, req
);
963 req
->reqType
= opcode
;
964 req
->glxCode
= X_GLXCreateGLXPixmap
;
965 req
->screen
= vis
->screen
;
966 req
->visual
= vis
->visualid
;
967 req
->pixmap
= pixmap
;
968 req
->glxpixmap
= xid
= XAllocID(dpy
);
972 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
974 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
975 * is actually bound to a context... */
977 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
978 __GLXDRIdrawable
*pdraw
;
979 struct glx_screen
*psc
;
980 struct glx_config
*config
;
982 psc
= priv
->screens
[vis
->screen
];
983 if (psc
->driScreen
== NULL
)
985 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
986 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, config
);
988 fprintf(stderr
, "failed to create pixmap\n");
992 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
993 (*pdraw
->destroyDrawable
) (pdraw
);
994 return None
; /* FIXME: Check what we're supposed to do here... */
1004 ** Destroy the named pixmap
1007 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
1009 #ifdef GLX_USE_APPLEGL
1010 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
1011 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
1013 xGLXDestroyGLXPixmapReq
*req
;
1016 opcode
= __glXSetupForCommand(dpy
);
1021 /* Send the glXDestroyGLXPixmap request */
1023 GetReq(GLXDestroyGLXPixmap
, req
);
1024 req
->reqType
= opcode
;
1025 req
->glxCode
= X_GLXDestroyGLXPixmap
;
1026 req
->glxpixmap
= glxpixmap
;
1030 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1032 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
1033 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
1035 if (pdraw
!= NULL
) {
1036 (*pdraw
->destroyDrawable
) (pdraw
);
1037 __glxHashDelete(priv
->drawHash
, glxpixmap
);
1041 #endif /* GLX_USE_APPLEGL */
1045 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
1047 #ifdef GLX_USE_APPLEGL
1048 GLXContext gc
= glXGetCurrentContext();
1049 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
1050 apple_glx_swap_buffers(gc
->driContext
);
1052 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
1059 xcb_connection_t
*c
;
1061 xGLXSwapBuffersReq
*req
;
1064 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1065 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1067 if (pdraw
!= NULL
) {
1069 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
1074 opcode
= __glXSetupForCommand(dpy
);
1080 ** The calling thread may or may not have a current context. If it
1081 ** does, send the context tag so the server can do a flush.
1083 gc
= __glXGetCurrentContext();
1084 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1085 ((drawable
== gc
->currentDrawable
)
1086 || (drawable
== gc
->currentReadable
))) {
1087 tag
= gc
->currentContextTag
;
1094 c
= XGetXCBConnection(dpy
);
1095 xcb_glx_swap_buffers(c
, tag
, drawable
);
1098 /* Send the glXSwapBuffers request */
1100 GetReq(GLXSwapBuffers
, req
);
1101 req
->reqType
= opcode
;
1102 req
->glxCode
= X_GLXSwapBuffers
;
1103 req
->drawable
= drawable
;
1104 req
->contextTag
= tag
;
1108 #endif /* USE_XCB */
1109 #endif /* GLX_USE_APPLEGL */
1114 ** Return configuration information for the given display, screen and
1115 ** visual combination.
1118 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1121 __GLXdisplayPrivate
*priv
;
1122 struct glx_screen
*psc
;
1123 struct glx_config
*config
;
1126 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1127 if (status
== Success
) {
1128 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
1130 /* Lookup attribute after first finding a match on the visual */
1131 if (config
!= NULL
) {
1132 return glx_config_get(config
, attribute
, value_return
);
1135 status
= GLX_BAD_VISUAL
;
1139 ** If we can't find the config for this visual, this visual is not
1140 ** supported by the OpenGL implementation on the server.
1142 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1143 *value_return
= GL_FALSE
;
1150 /************************************************************************/
1153 init_fbconfig_for_chooser(struct glx_config
* config
,
1154 GLboolean fbconfig_style_tags
)
1156 memset(config
, 0, sizeof(struct glx_config
));
1157 config
->visualID
= (XID
) GLX_DONT_CARE
;
1158 config
->visualType
= GLX_DONT_CARE
;
1160 /* glXChooseFBConfig specifies different defaults for these two than
1163 if (fbconfig_style_tags
) {
1164 config
->rgbMode
= GL_TRUE
;
1165 config
->doubleBufferMode
= GLX_DONT_CARE
;
1168 config
->visualRating
= GLX_DONT_CARE
;
1169 config
->transparentPixel
= GLX_NONE
;
1170 config
->transparentRed
= GLX_DONT_CARE
;
1171 config
->transparentGreen
= GLX_DONT_CARE
;
1172 config
->transparentBlue
= GLX_DONT_CARE
;
1173 config
->transparentAlpha
= GLX_DONT_CARE
;
1174 config
->transparentIndex
= GLX_DONT_CARE
;
1176 config
->drawableType
= GLX_WINDOW_BIT
;
1177 config
->renderType
=
1178 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1179 config
->xRenderable
= GLX_DONT_CARE
;
1180 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1182 config
->swapMethod
= GLX_DONT_CARE
;
1185 #define MATCH_DONT_CARE( param ) \
1187 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1188 && (a-> param != b-> param) ) { \
1193 #define MATCH_MINIMUM( param ) \
1195 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1196 && (a-> param > b-> param) ) { \
1201 #define MATCH_EXACT( param ) \
1203 if ( a-> param != b-> param) { \
1208 /* Test that all bits from a are contained in b */
1209 #define MATCH_MASK(param) \
1211 if ((a->param & ~b->param) != 0) \
1216 * Determine if two GLXFBConfigs are compatible.
1218 * \param a Application specified config to test.
1219 * \param b Server specified config to test against \c a.
1222 fbconfigs_compatible(const struct glx_config
* const a
,
1223 const struct glx_config
* const b
)
1225 MATCH_DONT_CARE(doubleBufferMode
);
1226 MATCH_DONT_CARE(visualType
);
1227 MATCH_DONT_CARE(visualRating
);
1228 MATCH_DONT_CARE(xRenderable
);
1229 MATCH_DONT_CARE(fbconfigID
);
1230 MATCH_DONT_CARE(swapMethod
);
1232 MATCH_MINIMUM(rgbBits
);
1233 MATCH_MINIMUM(numAuxBuffers
);
1234 MATCH_MINIMUM(redBits
);
1235 MATCH_MINIMUM(greenBits
);
1236 MATCH_MINIMUM(blueBits
);
1237 MATCH_MINIMUM(alphaBits
);
1238 MATCH_MINIMUM(depthBits
);
1239 MATCH_MINIMUM(stencilBits
);
1240 MATCH_MINIMUM(accumRedBits
);
1241 MATCH_MINIMUM(accumGreenBits
);
1242 MATCH_MINIMUM(accumBlueBits
);
1243 MATCH_MINIMUM(accumAlphaBits
);
1244 MATCH_MINIMUM(sampleBuffers
);
1245 MATCH_MINIMUM(maxPbufferWidth
);
1246 MATCH_MINIMUM(maxPbufferHeight
);
1247 MATCH_MINIMUM(maxPbufferPixels
);
1248 MATCH_MINIMUM(samples
);
1250 MATCH_DONT_CARE(stereoMode
);
1253 MATCH_MASK(drawableType
);
1254 MATCH_MASK(renderType
);
1256 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1257 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1258 * Technically speaking, it is a bug in the DDX driver, but there is
1259 * enough of an installed base to work around the problem here. In any
1260 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1261 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1262 * 0 from the server to be a match to maintain backward compatibility with
1263 * the (broken) drivers.
1266 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1267 if (a
->transparentPixel
== GLX_NONE
) {
1268 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1272 MATCH_EXACT(transparentPixel
);
1275 switch (a
->transparentPixel
) {
1276 case GLX_TRANSPARENT_RGB
:
1277 MATCH_DONT_CARE(transparentRed
);
1278 MATCH_DONT_CARE(transparentGreen
);
1279 MATCH_DONT_CARE(transparentBlue
);
1280 MATCH_DONT_CARE(transparentAlpha
);
1283 case GLX_TRANSPARENT_INDEX
:
1284 MATCH_DONT_CARE(transparentIndex
);
1296 /* There's some trickly language in the GLX spec about how this is supposed
1297 * to work. Basically, if a given component size is either not specified
1298 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1299 * Well, that's really hard to do with the code as-is. This behavior is
1300 * closer to correct, but still not technically right.
1302 #define PREFER_LARGER_OR_ZERO(comp) \
1304 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1305 if ( ((*a)-> comp) == 0 ) { \
1308 else if ( ((*b)-> comp) == 0 ) { \
1312 return ((*b)-> comp) - ((*a)-> comp) ; \
1317 #define PREFER_LARGER(comp) \
1319 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1320 return ((*b)-> comp) - ((*a)-> comp) ; \
1324 #define PREFER_SMALLER(comp) \
1326 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1327 return ((*a)-> comp) - ((*b)-> comp) ; \
1332 * Compare two GLXFBConfigs. This function is intended to be used as the
1333 * compare function passed in to qsort.
1335 * \returns If \c a is a "better" config, according to the specification of
1336 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1337 * better, then a number greater than zero is return. If both are
1338 * equal, zero is returned.
1339 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1342 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1344 /* The order of these comparisons must NOT change. It is defined by
1345 * the GLX 1.3 spec and ARB_multisample.
1348 PREFER_SMALLER(visualSelectGroup
);
1350 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1351 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1352 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1354 PREFER_SMALLER(visualRating
);
1356 /* This isn't quite right. It is supposed to compare the sum of the
1357 * components the user specifically set minimums for.
1359 PREFER_LARGER_OR_ZERO(redBits
);
1360 PREFER_LARGER_OR_ZERO(greenBits
);
1361 PREFER_LARGER_OR_ZERO(blueBits
);
1362 PREFER_LARGER_OR_ZERO(alphaBits
);
1364 PREFER_SMALLER(rgbBits
);
1366 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1367 /* Prefer single-buffer.
1369 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1372 PREFER_SMALLER(numAuxBuffers
);
1374 PREFER_LARGER_OR_ZERO(depthBits
);
1375 PREFER_SMALLER(stencilBits
);
1377 /* This isn't quite right. It is supposed to compare the sum of the
1378 * components the user specifically set minimums for.
1380 PREFER_LARGER_OR_ZERO(accumRedBits
);
1381 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1382 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1383 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1385 PREFER_SMALLER(visualType
);
1387 /* None of the multisample specs say where this comparison should happen,
1388 * so I put it near the end.
1390 PREFER_SMALLER(sampleBuffers
);
1391 PREFER_SMALLER(samples
);
1393 /* None of the pbuffer or fbconfig specs say that this comparison needs
1394 * to happen at all, but it seems like it should.
1396 PREFER_LARGER(maxPbufferWidth
);
1397 PREFER_LARGER(maxPbufferHeight
);
1398 PREFER_LARGER(maxPbufferPixels
);
1405 * Selects and sorts a subset of the supplied configs based on the attributes.
1406 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1407 * and \c glXChooseFBConfigSGIX.
1409 * \param configs Array of pointers to possible configs. The elements of
1410 * this array that do not meet the criteria will be set to
1411 * NULL. The remaining elements will be sorted according to
1412 * the various visual / FBConfig selection rules.
1413 * \param num_configs Number of elements in the \c configs array.
1414 * \param attribList Attributes used select from \c configs. This array is
1415 * terminated by a \c None tag. The array can either take
1416 * the form expected by \c glXChooseVisual (where boolean
1417 * tags do not have a value) or by \c glXChooseFBConfig
1418 * (where every tag has a value).
1419 * \param fbconfig_style_tags Selects whether \c attribList is in
1420 * \c glXChooseVisual style or
1421 * \c glXChooseFBConfig style.
1422 * \returns The number of valid elements left in \c configs.
1424 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1427 choose_visual(struct glx_config
** configs
, int num_configs
,
1428 const int *attribList
, GLboolean fbconfig_style_tags
)
1430 struct glx_config test_config
;
1434 /* This is a fairly direct implementation of the selection method
1435 * described by GLX_SGIX_fbconfig. Start by culling out all the
1436 * configs that are not compatible with the selected parameter
1440 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1441 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1442 (const INT32
*) attribList
,
1443 GL_TRUE
, fbconfig_style_tags
);
1446 for (i
= 0; i
< num_configs
; i
++) {
1447 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1448 configs
[base
] = configs
[i
];
1457 if (base
< num_configs
) {
1458 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1461 /* After the incompatible configs are removed, the resulting
1462 * list is sorted according to the rules set out in the various
1466 qsort(configs
, base
, sizeof(struct glx_config
*),
1467 (int (*)(const void *, const void *)) fbconfig_compare
);
1475 ** Return the visual that best matches the template. Return None if no
1476 ** visual matches the template.
1478 _X_EXPORT XVisualInfo
*
1479 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1481 XVisualInfo
*visualList
= NULL
;
1482 __GLXdisplayPrivate
*priv
;
1483 struct glx_screen
*psc
;
1484 struct glx_config test_config
;
1485 struct glx_config
*config
;
1486 struct glx_config
*best_config
= NULL
;
1489 ** Get a list of all visuals, return if list is empty
1491 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1497 ** Build a template from the defaults and the attribute list
1498 ** Free visual list and return if an unexpected token is encountered
1500 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1501 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1502 (const INT32
*) attribList
,
1506 ** Eliminate visuals that don't meet minimum requirements
1507 ** Compute a score for those that do
1508 ** Remember which visual, if any, got the highest score
1509 ** If no visual is acceptable, return None
1510 ** Otherwise, create an XVisualInfo list with just the selected X visual
1513 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1514 if (fbconfigs_compatible(&test_config
, config
)
1515 && ((best_config
== NULL
) ||
1516 (fbconfig_compare (&config
, &best_config
) < 0))) {
1517 XVisualInfo visualTemplate
;
1518 XVisualInfo
*newList
;
1521 visualTemplate
.screen
= screen
;
1522 visualTemplate
.visualid
= config
->visualID
;
1523 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1524 &visualTemplate
, &i
);
1528 visualList
= newList
;
1529 best_config
= config
;
1534 #ifdef GLX_USE_APPLEGL
1535 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1536 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1544 _X_EXPORT
const char *
1545 glXQueryExtensionsString(Display
* dpy
, int screen
)
1547 struct glx_screen
*psc
;
1548 __GLXdisplayPrivate
*priv
;
1550 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1554 if (!psc
->effectiveGLXexts
) {
1555 if (!psc
->serverGLXexts
) {
1556 psc
->serverGLXexts
=
1557 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1561 __glXCalculateUsableExtensions(psc
,
1562 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1563 (psc
->driScreen
!= NULL
),
1567 priv
->minorVersion
);
1570 return psc
->effectiveGLXexts
;
1573 _X_EXPORT
const char *
1574 glXGetClientString(Display
* dpy
, int name
)
1580 return (__glXGLXClientVendorName
);
1582 return (__glXGLXClientVersion
);
1583 case GLX_EXTENSIONS
:
1584 return (__glXGetClientExtensions());
1590 _X_EXPORT
const char *
1591 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1593 struct glx_screen
*psc
;
1594 __GLXdisplayPrivate
*priv
;
1598 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1604 str
= &priv
->serverGLXvendor
;
1607 str
= &priv
->serverGLXversion
;
1609 case GLX_EXTENSIONS
:
1610 str
= &psc
->serverGLXexts
;
1617 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1624 __glXClientInfo(Display
* dpy
, int opcode
)
1626 char *ext_str
= __glXGetClientGLExtensionString();
1627 int size
= strlen(ext_str
) + 1;
1630 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1631 xcb_glx_client_info(c
,
1632 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1634 xGLXClientInfoReq
*req
;
1636 /* Send the glXClientInfo request */
1638 GetReq(GLXClientInfo
, req
);
1639 req
->reqType
= opcode
;
1640 req
->glxCode
= X_GLXClientInfo
;
1641 req
->major
= GLX_MAJOR_VERSION
;
1642 req
->minor
= GLX_MINOR_VERSION
;
1644 req
->length
+= (size
+ 3) >> 2;
1645 req
->numbytes
= size
;
1646 Data(dpy
, ext_str
, size
);
1650 #endif /* USE_XCB */
1657 ** EXT_import_context
1661 glXGetCurrentDisplay(void)
1663 GLXContext gc
= __glXGetCurrentContext();
1666 return gc
->currentDpy
;
1670 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1671 glXGetCurrentDisplay
)
1673 #ifndef GLX_USE_APPLEGL
1674 _X_EXPORT GLXContext
1675 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1677 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1678 struct glx_screen
*psc
;
1679 xGLXQueryContextReply reply
;
1682 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1685 struct glx_config
*mode
;
1687 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1690 opcode
= __glXSetupForCommand(dpy
);
1694 /* Send the glXQueryContextInfoEXT request */
1697 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1698 xGLXQueryContextReq
*req
;
1700 GetReq(GLXQueryContext
, req
);
1702 req
->reqType
= opcode
;
1703 req
->glxCode
= X_GLXQueryContext
;
1704 req
->context
= contextID
;
1707 xGLXVendorPrivateReq
*vpreq
;
1708 xGLXQueryContextInfoEXTReq
*req
;
1710 GetReqExtra(GLXVendorPrivate
,
1711 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1713 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1714 req
->reqType
= opcode
;
1715 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1716 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1717 req
->context
= contextID
;
1720 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1722 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1723 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1726 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1730 /* Look up screen first so we can look up visuals/fbconfigs later */
1732 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1733 if (pProp
[0] == GLX_SCREEN
)
1734 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1743 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1745 case GLX_SHARE_CONTEXT_EXT
:
1748 case GLX_VISUAL_ID_EXT
:
1749 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1751 case GLX_FBCONFIG_ID
:
1752 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1754 case GLX_RENDER_TYPE
:
1755 renderType
= pProp
[1];
1762 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1766 ctx
->xid
= contextID
;
1767 ctx
->imported
= GL_TRUE
;
1768 ctx
->share_xid
= share
;
1776 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1778 switch (attribute
) {
1779 case GLX_SHARE_CONTEXT_EXT
:
1780 *value
= ctx
->share_xid
;
1782 case GLX_VISUAL_ID_EXT
:
1783 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1786 *value
= ctx
->screen
;
1788 case GLX_FBCONFIG_ID
:
1789 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1791 case GLX_RENDER_TYPE
:
1792 *value
= ctx
->renderType
;
1795 return GLX_BAD_ATTRIBUTE
;
1801 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1802 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1803 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1805 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1811 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1813 DestroyContext(dpy
, ctx
);
1817 _X_EXPORT GLXFBConfig
*
1818 glXChooseFBConfig(Display
* dpy
, int screen
,
1819 const int *attribList
, int *nitems
)
1821 struct glx_config
**config_list
;
1825 config_list
= (struct glx_config
**)
1826 glXGetFBConfigs(dpy
, screen
, &list_size
);
1828 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1829 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1830 if (list_size
== 0) {
1836 *nitems
= list_size
;
1837 return (GLXFBConfig
*) config_list
;
1841 _X_EXPORT GLXContext
1842 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1843 int renderType
, GLXContext shareList
, Bool allowDirect
)
1845 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1847 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1848 allowDirect
, X_GLXCreateNewContext
, renderType
,
1853 _X_EXPORT GLXDrawable
1854 glXGetCurrentReadDrawable(void)
1856 GLXContext gc
= __glXGetCurrentContext();
1857 return gc
->currentReadable
;
1861 _X_EXPORT GLXFBConfig
*
1862 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1864 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1865 struct glx_config
**config_list
= NULL
;
1866 struct glx_config
*config
;
1867 unsigned num_configs
= 0;
1871 if (priv
&& (priv
->screens
!= NULL
)
1872 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1873 && (priv
->screens
[screen
]->configs
!= NULL
)
1874 && (priv
->screens
[screen
]->configs
->fbconfigID
1875 != (int) GLX_DONT_CARE
)) {
1877 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1878 config
= config
->next
) {
1879 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1884 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1885 if (config_list
!= NULL
) {
1886 *nelements
= num_configs
;
1888 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1889 config
= config
->next
) {
1890 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1891 config_list
[i
] = config
;
1898 return (GLXFBConfig
*) config_list
;
1903 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1904 int attribute
, int *value
)
1906 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1909 return GLXBadFBConfig
;
1911 return glx_config_get(config
, attribute
, value
);
1915 _X_EXPORT XVisualInfo
*
1916 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1918 XVisualInfo visualTemplate
;
1919 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1923 ** Get a list of all visuals, return if list is empty
1925 visualTemplate
.visualid
= config
->visualID
;
1926 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1929 #ifndef GLX_USE_APPLEGL
1931 ** GLX_SGI_swap_control
1934 __glXSwapIntervalSGI(int interval
)
1936 xGLXVendorPrivateReq
*req
;
1937 GLXContext gc
= __glXGetCurrentContext();
1938 struct glx_screen
*psc
;
1940 CARD32
*interval_ptr
;
1944 return GLX_BAD_CONTEXT
;
1947 if (interval
<= 0) {
1948 return GLX_BAD_VALUE
;
1951 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1953 #ifdef GLX_DIRECT_RENDERING
1954 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1955 __GLXDRIdrawable
*pdraw
=
1956 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1957 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1962 dpy
= gc
->currentDpy
;
1963 opcode
= __glXSetupForCommand(dpy
);
1968 /* Send the glXSwapIntervalSGI request */
1970 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1971 req
->reqType
= opcode
;
1972 req
->glxCode
= X_GLXVendorPrivate
;
1973 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1974 req
->contextTag
= gc
->currentContextTag
;
1976 interval_ptr
= (CARD32
*) (req
+ 1);
1977 *interval_ptr
= interval
;
1988 ** GLX_MESA_swap_control
1991 __glXSwapIntervalMESA(unsigned int interval
)
1993 #ifdef GLX_DIRECT_RENDERING
1994 GLXContext gc
= __glXGetCurrentContext();
1996 if (gc
!= NULL
&& gc
->driContext
) {
1997 struct glx_screen
*psc
;
1999 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2000 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2001 __GLXDRIdrawable
*pdraw
=
2002 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2003 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2008 return GLX_BAD_CONTEXT
;
2013 __glXGetSwapIntervalMESA(void)
2015 #ifdef GLX_DIRECT_RENDERING
2016 GLXContext gc
= __glXGetCurrentContext();
2018 if (gc
!= NULL
&& gc
->driContext
) {
2019 struct glx_screen
*psc
;
2021 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2022 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2023 __GLXDRIdrawable
*pdraw
=
2024 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2025 return psc
->driScreen
->getSwapInterval(pdraw
);
2035 ** GLX_SGI_video_sync
2038 __glXGetVideoSyncSGI(unsigned int *count
)
2040 int64_t ust
, msc
, sbc
;
2042 GLXContext gc
= __glXGetCurrentContext();
2043 struct glx_screen
*psc
;
2044 #ifdef GLX_DIRECT_RENDERING
2045 __GLXDRIdrawable
*pdraw
;
2049 return GLX_BAD_CONTEXT
;
2051 #ifdef GLX_DIRECT_RENDERING
2052 if (!gc
->driContext
)
2053 return GLX_BAD_CONTEXT
;
2056 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2057 #ifdef GLX_DIRECT_RENDERING
2058 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2061 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2062 * FIXME: there should be a GLX encoding for this call. I can find no
2063 * FIXME: documentation for the GLX encoding.
2065 #ifdef GLX_DIRECT_RENDERING
2066 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2067 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2068 *count
= (unsigned) msc
;
2069 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2073 return GLX_BAD_CONTEXT
;
2077 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2079 GLXContext gc
= __glXGetCurrentContext();
2080 struct glx_screen
*psc
;
2081 #ifdef GLX_DIRECT_RENDERING
2082 __GLXDRIdrawable
*pdraw
;
2084 int64_t ust
, msc
, sbc
;
2087 if (divisor
<= 0 || remainder
< 0)
2088 return GLX_BAD_VALUE
;
2091 return GLX_BAD_CONTEXT
;
2093 #ifdef GLX_DIRECT_RENDERING
2094 if (!gc
->driContext
)
2095 return GLX_BAD_CONTEXT
;
2098 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2099 #ifdef GLX_DIRECT_RENDERING
2100 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2103 #ifdef GLX_DIRECT_RENDERING
2104 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2105 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2107 *count
= (unsigned) msc
;
2108 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2112 return GLX_BAD_CONTEXT
;
2115 #endif /* GLX_USE_APPLEGL */
2118 ** GLX_SGIX_fbconfig
2119 ** Many of these functions are aliased to GLX 1.3 entry points in the
2120 ** GLX_functions table.
2124 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2125 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2126 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2128 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2129 (Display
* dpy
, int screen
, int *attrib_list
,
2130 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2133 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2134 (Display
* dpy
, GLXFBConfigSGIX config
),
2135 (dpy
, config
), glXGetVisualFromFBConfig
)
2138 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2139 GLXFBConfigSGIX fbconfig
,
2142 #ifndef GLX_USE_APPLEGL
2143 xGLXVendorPrivateWithReplyReq
*vpreq
;
2144 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2145 GLXPixmap xid
= None
;
2147 struct glx_screen
*psc
;
2149 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2152 if ((dpy
== NULL
) || (config
== NULL
)) {
2155 #ifdef GLX_USE_APPLEGL
2156 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
2161 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2163 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2164 opcode
= __glXSetupForCommand(dpy
);
2169 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2171 GetReqExtra(GLXVendorPrivateWithReply
,
2172 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2173 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2174 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2175 req
->reqType
= opcode
;
2176 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2177 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2178 req
->screen
= config
->screen
;
2179 req
->fbconfig
= config
->fbconfigID
;
2180 req
->pixmap
= pixmap
;
2181 req
->glxpixmap
= xid
= XAllocID(dpy
);
2190 _X_EXPORT GLXContext
2191 glXCreateContextWithConfigSGIX(Display
* dpy
,
2192 GLXFBConfigSGIX fbconfig
, int renderType
,
2193 GLXContext shareList
, Bool allowDirect
)
2195 GLXContext gc
= NULL
;
2196 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2197 struct glx_screen
*psc
;
2200 if ((dpy
== NULL
) || (config
== NULL
)) {
2204 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2206 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2207 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2209 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2217 _X_EXPORT GLXFBConfigSGIX
2218 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2220 __GLXdisplayPrivate
*priv
;
2221 struct glx_screen
*psc
= NULL
;
2223 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2224 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2225 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2226 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2233 #ifndef GLX_USE_APPLEGL
2235 ** GLX_SGIX_swap_group
2238 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2248 ** GLX_SGIX_swap_barrier
2251 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2259 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2269 ** GLX_OML_sync_control
2272 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2273 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2275 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2277 #ifdef GLX_DIRECT_RENDERING
2278 __GLXDRIdrawable
*pdraw
;
2280 struct glx_screen
*psc
;
2285 #ifdef GLX_DIRECT_RENDERING
2286 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2287 psc
= pdraw
? pdraw
->psc
: NULL
;
2288 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2289 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2297 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2299 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2300 int32_t * numerator
, int32_t * denominator
)
2303 struct glx_screen
*psc
;
2304 XF86VidModeModeLine mode_line
;
2309 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2310 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2311 unsigned n
= dot_clock
* 1000;
2312 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2314 # define V_INTERLACE 0x010
2315 # define V_DBLSCAN 0x020
2317 if (mode_line
.flags
& V_INTERLACE
)
2319 else if (mode_line
.flags
& V_DBLSCAN
)
2322 /* The OML_sync_control spec requires that if the refresh rate is a
2323 * whole number, that the returned numerator be equal to the refresh
2324 * rate and the denominator be 1.
2332 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2334 /* This is a poor man's way to reduce a fraction. It's far from
2335 * perfect, but it will work well enough for this situation.
2338 for (i
= 0; f
[i
] != 0; i
++) {
2339 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2365 * Determine the refresh rate of the specified drawable and display.
2367 * \param dpy Display whose refresh rate is to be determined.
2368 * \param drawable Drawable whose refresh rate is to be determined.
2369 * \param numerator Numerator of the refresh rate.
2370 * \param demoninator Denominator of the refresh rate.
2371 * \return If the refresh rate for the specified display and drawable could
2372 * be calculated, True is returned. Otherwise False is returned.
2374 * \note This function is implemented entirely client-side. A lot of other
2375 * functionality is required to export GLX_OML_sync_control, so on
2376 * XFree86 this function can be called for direct-rendering contexts
2377 * when GLX_OML_sync_control appears in the client extension string.
2381 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2382 int32_t * numerator
, int32_t * denominator
)
2384 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2385 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2390 return __glxGetMscRate(draw
, numerator
, denominator
);
2402 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2403 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2405 GLXContext gc
= __glXGetCurrentContext();
2406 #ifdef GLX_DIRECT_RENDERING
2407 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2408 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2411 if (!gc
) /* no GLX for this */
2414 #ifdef GLX_DIRECT_RENDERING
2415 if (!pdraw
|| !gc
->driContext
)
2419 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2420 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2421 * of -1 if the function failed because of errors detected in the input
2424 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2426 if (divisor
> 0 && remainder
>= divisor
)
2429 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2432 #ifdef GLX_DIRECT_RENDERING
2433 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2434 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2443 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2444 int64_t target_msc
, int64_t divisor
,
2445 int64_t remainder
, int64_t * ust
,
2446 int64_t * msc
, int64_t * sbc
)
2448 #ifdef GLX_DIRECT_RENDERING
2449 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2451 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2455 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2456 * error", but the return type in the spec is Bool.
2458 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2460 if (divisor
> 0 && remainder
>= divisor
)
2463 #ifdef GLX_DIRECT_RENDERING
2464 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2465 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2476 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2477 int64_t target_sbc
, int64_t * ust
,
2478 int64_t * msc
, int64_t * sbc
)
2480 #ifdef GLX_DIRECT_RENDERING
2481 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2483 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2486 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2487 * error", but the return type in the spec is Bool.
2492 #ifdef GLX_DIRECT_RENDERING
2493 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2494 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2506 * Mesa extension stubs. These will help reduce portability problems.
2511 * Release all buffers associated with the specified GLX drawable.
2514 * This function was intended for stand-alone Mesa. The issue there is that
2515 * the library doesn't get any notification when a window is closed. In
2516 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2517 * supported, there are 3 different functions to destroy a drawable. It
2518 * should be possible to create GLX protocol (or have it determine which
2519 * protocol to use based on the type of the drawable) to have one function
2520 * do the work of 3. For the direct-rendering case, this function could
2521 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2522 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2523 * would need to be used. This really should be done as part of the new DRI
2526 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2527 * __driGarbageCollectDrawables
2528 * glXDestroyGLXPixmap
2529 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2530 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2533 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2542 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2543 Pixmap pixmap
, Colormap cmap
)
2556 * GLX_MESA_copy_sub_buffer
2558 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2560 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2561 int x
, int y
, int width
, int height
)
2563 xGLXVendorPrivateReq
*req
;
2566 CARD32
*drawable_ptr
;
2567 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2570 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2571 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2572 if (pdraw
!= NULL
) {
2573 struct glx_screen
*psc
= pdraw
->psc
;
2574 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2576 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2583 opcode
= __glXSetupForCommand(dpy
);
2588 ** The calling thread may or may not have a current context. If it
2589 ** does, send the context tag so the server can do a flush.
2591 gc
= __glXGetCurrentContext();
2592 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2593 ((drawable
== gc
->currentDrawable
) ||
2594 (drawable
== gc
->currentReadable
))) {
2595 tag
= gc
->currentContextTag
;
2602 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2603 req
->reqType
= opcode
;
2604 req
->glxCode
= X_GLXVendorPrivate
;
2605 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2606 req
->contextTag
= tag
;
2608 drawable_ptr
= (CARD32
*) (req
+ 1);
2609 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2610 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2611 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2612 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2614 *drawable_ptr
= drawable
;
2626 * GLX_EXT_texture_from_pixmap
2629 indirect_bind_tex_image(Display
* dpy
,
2630 GLXDrawable drawable
,
2631 int buffer
, const int *attrib_list
)
2633 xGLXVendorPrivateReq
*req
;
2634 GLXContext gc
= __glXGetCurrentContext();
2635 CARD32
*drawable_ptr
;
2637 CARD32
*num_attrib_ptr
;
2644 while (attrib_list
[i
* 2] != None
)
2648 opcode
= __glXSetupForCommand(dpy
);
2653 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2654 req
->reqType
= opcode
;
2655 req
->glxCode
= X_GLXVendorPrivate
;
2656 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2657 req
->contextTag
= gc
->currentContextTag
;
2659 drawable_ptr
= (CARD32
*) (req
+ 1);
2660 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2661 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2662 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2664 *drawable_ptr
= drawable
;
2665 *buffer_ptr
= buffer
;
2666 *num_attrib_ptr
= (CARD32
) i
;
2670 while (attrib_list
[i
* 2] != None
) {
2671 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2672 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2682 indirect_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2684 xGLXVendorPrivateReq
*req
;
2685 GLXContext gc
= __glXGetCurrentContext();
2686 CARD32
*drawable_ptr
;
2690 opcode
= __glXSetupForCommand(dpy
);
2695 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2696 req
->reqType
= opcode
;
2697 req
->glxCode
= X_GLXVendorPrivate
;
2698 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2699 req
->contextTag
= gc
->currentContextTag
;
2701 drawable_ptr
= (CARD32
*) (req
+ 1);
2702 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2704 *drawable_ptr
= drawable
;
2705 *buffer_ptr
= buffer
;
2711 static const struct glx_context_vtable indirect_context_vtable
= {
2712 indirect_destroy_context
,
2715 indirect_use_x_font
,
2716 indirect_bind_tex_image
,
2717 indirect_release_tex_image
,
2722 __glXBindTexImageEXT(Display
* dpy
,
2723 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2725 GLXContext gc
= __glXGetCurrentContext();
2727 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2730 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2734 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2736 GLXContext gc
= __glXGetCurrentContext();
2738 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2741 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2746 #endif /* GLX_USE_APPLEGL */
2749 * \c strdup is actually not a standard ANSI C or POSIX routine.
2750 * Irix will not define it if ANSI mode is in effect.
2755 __glXstrdup(const char *str
)
2758 copy
= (char *) Xmalloc(strlen(str
) + 1);
2766 ** glXGetProcAddress support
2769 struct name_address_pair
2775 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2776 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2778 static const struct name_address_pair GLX_functions
[] = {
2779 /*** GLX_VERSION_1_0 ***/
2780 GLX_FUNCTION(glXChooseVisual
),
2781 GLX_FUNCTION(glXCopyContext
),
2782 GLX_FUNCTION(glXCreateContext
),
2783 GLX_FUNCTION(glXCreateGLXPixmap
),
2784 GLX_FUNCTION(glXDestroyContext
),
2785 GLX_FUNCTION(glXDestroyGLXPixmap
),
2786 GLX_FUNCTION(glXGetConfig
),
2787 GLX_FUNCTION(glXGetCurrentContext
),
2788 GLX_FUNCTION(glXGetCurrentDrawable
),
2789 GLX_FUNCTION(glXIsDirect
),
2790 GLX_FUNCTION(glXMakeCurrent
),
2791 GLX_FUNCTION(glXQueryExtension
),
2792 GLX_FUNCTION(glXQueryVersion
),
2793 GLX_FUNCTION(glXSwapBuffers
),
2794 GLX_FUNCTION(glXUseXFont
),
2795 GLX_FUNCTION(glXWaitGL
),
2796 GLX_FUNCTION(glXWaitX
),
2798 /*** GLX_VERSION_1_1 ***/
2799 GLX_FUNCTION(glXGetClientString
),
2800 GLX_FUNCTION(glXQueryExtensionsString
),
2801 GLX_FUNCTION(glXQueryServerString
),
2803 /*** GLX_VERSION_1_2 ***/
2804 GLX_FUNCTION(glXGetCurrentDisplay
),
2806 /*** GLX_VERSION_1_3 ***/
2807 GLX_FUNCTION(glXChooseFBConfig
),
2808 GLX_FUNCTION(glXCreateNewContext
),
2809 GLX_FUNCTION(glXCreatePbuffer
),
2810 GLX_FUNCTION(glXCreatePixmap
),
2811 GLX_FUNCTION(glXCreateWindow
),
2812 GLX_FUNCTION(glXDestroyPbuffer
),
2813 GLX_FUNCTION(glXDestroyPixmap
),
2814 GLX_FUNCTION(glXDestroyWindow
),
2815 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2816 GLX_FUNCTION(glXGetFBConfigAttrib
),
2817 GLX_FUNCTION(glXGetFBConfigs
),
2818 GLX_FUNCTION(glXGetSelectedEvent
),
2819 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2820 GLX_FUNCTION(glXMakeContextCurrent
),
2821 GLX_FUNCTION(glXQueryContext
),
2822 GLX_FUNCTION(glXQueryDrawable
),
2823 GLX_FUNCTION(glXSelectEvent
),
2825 #ifndef GLX_USE_APPLEGL
2826 /*** GLX_SGI_swap_control ***/
2827 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2829 /*** GLX_SGI_video_sync ***/
2830 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2831 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2833 /*** GLX_SGI_make_current_read ***/
2834 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2835 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2837 /*** GLX_EXT_import_context ***/
2838 GLX_FUNCTION(glXFreeContextEXT
),
2839 GLX_FUNCTION(glXGetContextIDEXT
),
2840 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2841 GLX_FUNCTION(glXImportContextEXT
),
2842 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2845 /*** GLX_SGIX_fbconfig ***/
2846 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2847 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2848 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2849 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2850 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2851 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2853 #ifndef GLX_USE_APPLEGL
2854 /*** GLX_SGIX_pbuffer ***/
2855 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2856 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2857 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2858 GLX_FUNCTION(glXSelectEventSGIX
),
2859 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2861 /*** GLX_SGIX_swap_group ***/
2862 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2864 /*** GLX_SGIX_swap_barrier ***/
2865 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2866 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2868 /*** GLX_MESA_copy_sub_buffer ***/
2869 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2871 /*** GLX_MESA_pixmap_colormap ***/
2872 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2874 /*** GLX_MESA_release_buffers ***/
2875 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2877 /*** GLX_MESA_swap_control ***/
2878 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2879 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2882 /*** GLX_ARB_get_proc_address ***/
2883 GLX_FUNCTION(glXGetProcAddressARB
),
2886 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2888 #ifndef GLX_USE_APPLEGL
2889 /*** GLX_OML_sync_control ***/
2890 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2891 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2892 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2893 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2894 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2896 /*** GLX_EXT_texture_from_pixmap ***/
2897 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2898 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2901 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2902 /*** DRI configuration ***/
2903 GLX_FUNCTION(glXGetScreenDriver
),
2904 GLX_FUNCTION(glXGetDriverConfig
),
2907 {NULL
, NULL
} /* end of list */
2910 #ifndef GLX_USE_APPLEGL
2911 static const GLvoid
*
2912 get_glx_proc_address(const char *funcName
)
2916 /* try static functions */
2917 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2918 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2919 return GLX_functions
[i
].Address
;
2927 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2928 * \c glXGetProcAddress.
2930 * \param procName Name of a GL or GLX function.
2931 * \returns A pointer to the named function
2933 * \sa glXGetProcAddress
2935 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2937 typedef void (*gl_function
) (void);
2941 /* Search the table of GLX and internal functions first. If that
2942 * fails and the supplied name could be a valid core GL name, try
2943 * searching the core GL function table. This check is done to prevent
2944 * DRI based drivers from searching the core GL function table for
2945 * internal API functions.
2947 #ifdef GLX_USE_APPLEGL
2948 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2950 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2951 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2952 && (procName
[2] != 'X')) {
2953 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2960 * Get the address of a named GL function. This is the GLX 1.4 name for
2961 * \c glXGetProcAddressARB.
2963 * \param procName Name of a GL or GLX function.
2964 * \returns A pointer to the named function
2966 * \sa glXGetProcAddressARB
2968 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2969 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2970 __attribute__ ((alias("glXGetProcAddressARB")));
2973 return glXGetProcAddressARB(procName
);
2975 #endif /* __GNUC__ */
2978 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2980 * Get the unadjusted system time (UST). Currently, the UST is measured in
2981 * microseconds since Epoc. The actual resolution of the UST may vary from
2982 * system to system, and the units may vary from release to release.
2983 * Drivers should not call this function directly. They should instead use
2984 * \c glXGetProcAddress to obtain a pointer to the function.
2986 * \param ust Location to store the 64-bit UST
2987 * \returns Zero on success or a negative errno value on failure.
2989 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2991 * \since Internal API version 20030317.
2994 __glXGetUST(int64_t * ust
)
3002 if (gettimeofday(&tv
, NULL
) == 0) {
3003 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3010 #endif /* GLX_DIRECT_RENDERING */