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 struct glx_display
*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 struct glx_display
*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 struct glx_display
*const priv
= __glXInitialize(dpy
);
166 NULL
) ? priv
->screens
[scrn
] : NULL
;
171 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** 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 struct glx_display
*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
;
239 static struct glx_context
*
240 applegl_create_context(struct glx_screen
*psc
,
241 struct glx_config
*mode
,
242 struct glx_context
*shareList
, int renderType
)
244 struct glx_context
*gc
;
248 /* TODO: Integrate this with apple_glx_create_context and make
249 * struct apple_glx_context inherit from struct glx_context. */
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).
295 static struct glx_context
*
296 indirect_create_context(struct glx_screen
*psc
,
297 struct glx_config
*mode
,
298 struct glx_context
*shareList
, int renderType
)
300 struct glx_context
*gc
;
303 __GLXattribute
*state
;
305 opcode
= __glXSetupForCommand(psc
->dpy
);
310 /* Allocate our context record */
311 gc
= Xmalloc(sizeof *gc
);
316 memset(gc
, 0, sizeof *gc
);
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
, struct glx_display
* 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(struct glx_context
*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_user
,
446 unsigned code
, int renderType
, int screen
)
448 struct glx_context
*gc
= NULL
;
449 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
450 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
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
;
532 return (GLXContext
) gc
;
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(struct glx_context
*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 ctx
)
609 struct glx_context
*gc
= (struct glx_context
*) ctx
;
615 if (gc
->currentDpy
) {
616 /* This context is bound to some thread. According to the man page,
617 * we should not actually delete the context until it's unbound.
618 * Note that we set gc->xid = None above. In MakeContextCurrent()
619 * we check for that and delete the context there.
622 glx_send_destroy_context(dpy
, gc
->xid
);
629 if (gc
->vtable
->destroy
)
630 gc
->vtable
->destroy(gc
);
634 glXDestroyContext(Display
* dpy
, GLXContext gc
)
636 DestroyContext(dpy
, gc
);
640 ** Return the major and minor version #s for the GLX extension
643 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
645 struct glx_display
*priv
;
647 /* Init the extension. This fetches the major and minor version. */
648 priv
= __glXInitialize(dpy
);
653 *major
= priv
->majorVersion
;
655 *minor
= priv
->minorVersion
;
660 ** Query the existance of the GLX extension
663 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
665 int major_op
, erb
, evb
;
668 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
679 indirect_wait_gl(struct glx_context
*gc
)
682 Display
*dpy
= gc
->currentDpy
;
684 /* Flush any pending commands out */
685 __glXFlushRenderBuffer(gc
, gc
->pc
);
687 /* Send the glXWaitGL request */
689 GetReq(GLXWaitGL
, req
);
690 req
->reqType
= gc
->majorOpcode
;
691 req
->glxCode
= X_GLXWaitGL
;
692 req
->contextTag
= gc
->currentContextTag
;
698 ** Put a barrier in the token stream that forces the GL to finish its
699 ** work before X can proceed.
704 struct glx_context
*gc
= __glXGetCurrentContext();
706 if (gc
&& gc
->vtable
->use_x_font
)
707 gc
->vtable
->wait_gl(gc
);
711 indirect_wait_x(struct glx_context
*gc
)
714 Display
*dpy
= gc
->currentDpy
;
716 /* Flush any pending commands out */
717 __glXFlushRenderBuffer(gc
, gc
->pc
);
720 GetReq(GLXWaitX
, req
);
721 req
->reqType
= gc
->majorOpcode
;
722 req
->glxCode
= X_GLXWaitX
;
723 req
->contextTag
= gc
->currentContextTag
;
729 ** Put a barrier in the token stream that forces X to finish its
730 ** work before GL can proceed.
735 struct glx_context
*gc
= __glXGetCurrentContext();
737 if (gc
&& gc
->vtable
->use_x_font
)
738 gc
->vtable
->wait_x(gc
);
742 indirect_use_x_font(struct glx_context
*gc
,
743 Font font
, int first
, int count
, int listBase
)
745 xGLXUseXFontReq
*req
;
746 Display
*dpy
= gc
->currentDpy
;
748 /* Flush any pending commands out */
749 __glXFlushRenderBuffer(gc
, gc
->pc
);
751 /* Send the glXUseFont request */
753 GetReq(GLXUseXFont
, req
);
754 req
->reqType
= gc
->majorOpcode
;
755 req
->glxCode
= X_GLXUseXFont
;
756 req
->contextTag
= gc
->currentContextTag
;
760 req
->listBase
= listBase
;
765 #ifdef GLX_USE_APPLEGL
768 applegl_destroy_context(struct glx_context
*gc
)
770 apple_glx_destroy_context(&gc
->driContext
, gc
->currentDpy
);
774 applegl_wait_gl(struct glx_context
*gc
)
780 applegl_wait_x(struct glx_context
*gc
)
782 apple_glx_waitx(gc
->dpy
, gc
->driContext
);
785 static const struct glx_context_vtable applegl_context_vtable
= {
786 applegl_destroy_context
,
790 NULL
, /* bind_tex_image, */
791 NULL
, /* release_tex_image, */
797 glXUseXFont(Font font
, int first
, int count
, int listBase
)
799 struct glx_context
*gc
= __glXGetCurrentContext();
801 if (gc
&& gc
->vtable
->use_x_font
)
802 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
805 /************************************************************************/
808 ** Copy the source context to the destination context using the
812 glXCopyContext(Display
* dpy
, GLXContext source_user
,
813 GLXContext dest_user
, unsigned long mask
)
815 struct glx_context
*source
= (struct glx_context
*) source_user
;
816 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
817 #ifdef GLX_USE_APPLEGL
818 struct glx_context
*gc
= __glXGetCurrentContext();
822 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
823 mask
, &errorcode
, &x11error
)) {
824 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
828 xGLXCopyContextReq
*req
;
829 struct glx_context
*gc
= __glXGetCurrentContext();
833 opcode
= __glXSetupForCommand(dpy
);
838 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
839 if (gc
->driContext
) {
840 /* NOT_DONE: This does not work yet */
845 ** If the source is the current context, send its tag so that the context
846 ** can be flushed before the copy.
848 if (source
== gc
&& dpy
== gc
->currentDpy
) {
849 tag
= gc
->currentContextTag
;
855 /* Send the glXCopyContext request */
857 GetReq(GLXCopyContext
, req
);
858 req
->reqType
= opcode
;
859 req
->glxCode
= X_GLXCopyContext
;
860 req
->source
= source
? source
->xid
: None
;
861 req
->dest
= dest
? dest
->xid
: None
;
863 req
->contextTag
= tag
;
866 #endif /* GLX_USE_APPLEGL */
871 * Determine if a context uses direct rendering.
873 * \param dpy Display where the context was created.
874 * \param contextID ID of the context to be tested.
876 * \returns \c GL_TRUE if the context is direct rendering or not.
879 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
881 #if !defined(USE_XCB)
882 xGLXIsDirectReq
*req
;
883 xGLXIsDirectReply reply
;
887 opcode
= __glXSetupForCommand(dpy
);
893 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
894 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
899 const Bool is_direct
= reply
->is_direct
? True
: False
;
904 /* Send the glXIsDirect request */
906 GetReq(GLXIsDirect
, req
);
907 req
->reqType
= opcode
;
908 req
->glxCode
= X_GLXIsDirect
;
909 req
->context
= contextID
;
910 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
914 return reply
.isDirect
;
920 * Shouldn't this function \b always return \c GL_FALSE when
921 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
922 * the GLX protocol here at all?
925 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
927 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
932 else if (GC_IS_DIRECT(gc
)) {
935 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
938 return __glXIsDirect(dpy
, gc
->xid
);
943 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
945 #ifdef GLX_USE_APPLEGL
946 int screen
= vis
->screen
;
947 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
948 const struct glx_config
*config
;
950 config
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
952 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
957 xGLXCreateGLXPixmapReq
*req
;
961 opcode
= __glXSetupForCommand(dpy
);
966 /* Send the glXCreateGLXPixmap request */
968 GetReq(GLXCreateGLXPixmap
, req
);
969 req
->reqType
= opcode
;
970 req
->glxCode
= X_GLXCreateGLXPixmap
;
971 req
->screen
= vis
->screen
;
972 req
->visual
= vis
->visualid
;
973 req
->pixmap
= pixmap
;
974 req
->glxpixmap
= xid
= XAllocID(dpy
);
978 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
980 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
981 * is actually bound to a context... */
983 struct glx_display
*const priv
= __glXInitialize(dpy
);
984 __GLXDRIdrawable
*pdraw
;
985 struct glx_screen
*psc
;
986 struct glx_config
*config
;
988 psc
= priv
->screens
[vis
->screen
];
989 if (psc
->driScreen
== NULL
)
991 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
992 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, config
);
994 fprintf(stderr
, "failed to create pixmap\n");
998 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
999 (*pdraw
->destroyDrawable
) (pdraw
);
1000 return None
; /* FIXME: Check what we're supposed to do here... */
1010 ** Destroy the named pixmap
1013 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
1015 #ifdef GLX_USE_APPLEGL
1016 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
1017 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
1019 xGLXDestroyGLXPixmapReq
*req
;
1022 opcode
= __glXSetupForCommand(dpy
);
1027 /* Send the glXDestroyGLXPixmap request */
1029 GetReq(GLXDestroyGLXPixmap
, req
);
1030 req
->reqType
= opcode
;
1031 req
->glxCode
= X_GLXDestroyGLXPixmap
;
1032 req
->glxpixmap
= glxpixmap
;
1036 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1038 struct glx_display
*const priv
= __glXInitialize(dpy
);
1039 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
1041 if (pdraw
!= NULL
) {
1042 (*pdraw
->destroyDrawable
) (pdraw
);
1043 __glxHashDelete(priv
->drawHash
, glxpixmap
);
1047 #endif /* GLX_USE_APPLEGL */
1051 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
1053 #ifdef GLX_USE_APPLEGL
1054 GLXContext gc
= glXGetCurrentContext();
1055 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
1056 apple_glx_swap_buffers(gc
->driContext
);
1058 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
1061 struct glx_context
*gc
;
1065 xcb_connection_t
*c
;
1067 xGLXSwapBuffersReq
*req
;
1070 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1071 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1073 if (pdraw
!= NULL
) {
1075 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
1080 opcode
= __glXSetupForCommand(dpy
);
1086 ** The calling thread may or may not have a current context. If it
1087 ** does, send the context tag so the server can do a flush.
1089 gc
= __glXGetCurrentContext();
1090 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1091 ((drawable
== gc
->currentDrawable
)
1092 || (drawable
== gc
->currentReadable
))) {
1093 tag
= gc
->currentContextTag
;
1100 c
= XGetXCBConnection(dpy
);
1101 xcb_glx_swap_buffers(c
, tag
, drawable
);
1104 /* Send the glXSwapBuffers request */
1106 GetReq(GLXSwapBuffers
, req
);
1107 req
->reqType
= opcode
;
1108 req
->glxCode
= X_GLXSwapBuffers
;
1109 req
->drawable
= drawable
;
1110 req
->contextTag
= tag
;
1114 #endif /* USE_XCB */
1115 #endif /* GLX_USE_APPLEGL */
1120 ** Return configuration information for the given display, screen and
1121 ** visual combination.
1124 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1127 struct glx_display
*priv
;
1128 struct glx_screen
*psc
;
1129 struct glx_config
*config
;
1132 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1133 if (status
== Success
) {
1134 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
1136 /* Lookup attribute after first finding a match on the visual */
1137 if (config
!= NULL
) {
1138 return glx_config_get(config
, attribute
, value_return
);
1141 status
= GLX_BAD_VISUAL
;
1145 ** If we can't find the config for this visual, this visual is not
1146 ** supported by the OpenGL implementation on the server.
1148 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1149 *value_return
= GL_FALSE
;
1156 /************************************************************************/
1159 init_fbconfig_for_chooser(struct glx_config
* config
,
1160 GLboolean fbconfig_style_tags
)
1162 memset(config
, 0, sizeof(struct glx_config
));
1163 config
->visualID
= (XID
) GLX_DONT_CARE
;
1164 config
->visualType
= GLX_DONT_CARE
;
1166 /* glXChooseFBConfig specifies different defaults for these two than
1169 if (fbconfig_style_tags
) {
1170 config
->rgbMode
= GL_TRUE
;
1171 config
->doubleBufferMode
= GLX_DONT_CARE
;
1174 config
->visualRating
= GLX_DONT_CARE
;
1175 config
->transparentPixel
= GLX_NONE
;
1176 config
->transparentRed
= GLX_DONT_CARE
;
1177 config
->transparentGreen
= GLX_DONT_CARE
;
1178 config
->transparentBlue
= GLX_DONT_CARE
;
1179 config
->transparentAlpha
= GLX_DONT_CARE
;
1180 config
->transparentIndex
= GLX_DONT_CARE
;
1182 config
->drawableType
= GLX_WINDOW_BIT
;
1183 config
->renderType
=
1184 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1185 config
->xRenderable
= GLX_DONT_CARE
;
1186 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1188 config
->swapMethod
= GLX_DONT_CARE
;
1191 #define MATCH_DONT_CARE( param ) \
1193 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1194 && (a-> param != b-> param) ) { \
1199 #define MATCH_MINIMUM( param ) \
1201 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1202 && (a-> param > b-> param) ) { \
1207 #define MATCH_EXACT( param ) \
1209 if ( a-> param != b-> param) { \
1214 /* Test that all bits from a are contained in b */
1215 #define MATCH_MASK(param) \
1217 if ((a->param & ~b->param) != 0) \
1222 * Determine if two GLXFBConfigs are compatible.
1224 * \param a Application specified config to test.
1225 * \param b Server specified config to test against \c a.
1228 fbconfigs_compatible(const struct glx_config
* const a
,
1229 const struct glx_config
* const b
)
1231 MATCH_DONT_CARE(doubleBufferMode
);
1232 MATCH_DONT_CARE(visualType
);
1233 MATCH_DONT_CARE(visualRating
);
1234 MATCH_DONT_CARE(xRenderable
);
1235 MATCH_DONT_CARE(fbconfigID
);
1236 MATCH_DONT_CARE(swapMethod
);
1238 MATCH_MINIMUM(rgbBits
);
1239 MATCH_MINIMUM(numAuxBuffers
);
1240 MATCH_MINIMUM(redBits
);
1241 MATCH_MINIMUM(greenBits
);
1242 MATCH_MINIMUM(blueBits
);
1243 MATCH_MINIMUM(alphaBits
);
1244 MATCH_MINIMUM(depthBits
);
1245 MATCH_MINIMUM(stencilBits
);
1246 MATCH_MINIMUM(accumRedBits
);
1247 MATCH_MINIMUM(accumGreenBits
);
1248 MATCH_MINIMUM(accumBlueBits
);
1249 MATCH_MINIMUM(accumAlphaBits
);
1250 MATCH_MINIMUM(sampleBuffers
);
1251 MATCH_MINIMUM(maxPbufferWidth
);
1252 MATCH_MINIMUM(maxPbufferHeight
);
1253 MATCH_MINIMUM(maxPbufferPixels
);
1254 MATCH_MINIMUM(samples
);
1256 MATCH_DONT_CARE(stereoMode
);
1259 MATCH_MASK(drawableType
);
1260 MATCH_MASK(renderType
);
1262 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1263 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1264 * Technically speaking, it is a bug in the DDX driver, but there is
1265 * enough of an installed base to work around the problem here. In any
1266 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1267 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1268 * 0 from the server to be a match to maintain backward compatibility with
1269 * the (broken) drivers.
1272 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1273 if (a
->transparentPixel
== GLX_NONE
) {
1274 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1278 MATCH_EXACT(transparentPixel
);
1281 switch (a
->transparentPixel
) {
1282 case GLX_TRANSPARENT_RGB
:
1283 MATCH_DONT_CARE(transparentRed
);
1284 MATCH_DONT_CARE(transparentGreen
);
1285 MATCH_DONT_CARE(transparentBlue
);
1286 MATCH_DONT_CARE(transparentAlpha
);
1289 case GLX_TRANSPARENT_INDEX
:
1290 MATCH_DONT_CARE(transparentIndex
);
1302 /* There's some trickly language in the GLX spec about how this is supposed
1303 * to work. Basically, if a given component size is either not specified
1304 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1305 * Well, that's really hard to do with the code as-is. This behavior is
1306 * closer to correct, but still not technically right.
1308 #define PREFER_LARGER_OR_ZERO(comp) \
1310 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1311 if ( ((*a)-> comp) == 0 ) { \
1314 else if ( ((*b)-> comp) == 0 ) { \
1318 return ((*b)-> comp) - ((*a)-> comp) ; \
1323 #define PREFER_LARGER(comp) \
1325 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1326 return ((*b)-> comp) - ((*a)-> comp) ; \
1330 #define PREFER_SMALLER(comp) \
1332 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1333 return ((*a)-> comp) - ((*b)-> comp) ; \
1338 * Compare two GLXFBConfigs. This function is intended to be used as the
1339 * compare function passed in to qsort.
1341 * \returns If \c a is a "better" config, according to the specification of
1342 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1343 * better, then a number greater than zero is return. If both are
1344 * equal, zero is returned.
1345 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1348 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1350 /* The order of these comparisons must NOT change. It is defined by
1351 * the GLX 1.3 spec and ARB_multisample.
1354 PREFER_SMALLER(visualSelectGroup
);
1356 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1357 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1358 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1360 PREFER_SMALLER(visualRating
);
1362 /* This isn't quite right. It is supposed to compare the sum of the
1363 * components the user specifically set minimums for.
1365 PREFER_LARGER_OR_ZERO(redBits
);
1366 PREFER_LARGER_OR_ZERO(greenBits
);
1367 PREFER_LARGER_OR_ZERO(blueBits
);
1368 PREFER_LARGER_OR_ZERO(alphaBits
);
1370 PREFER_SMALLER(rgbBits
);
1372 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1373 /* Prefer single-buffer.
1375 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1378 PREFER_SMALLER(numAuxBuffers
);
1380 PREFER_LARGER_OR_ZERO(depthBits
);
1381 PREFER_SMALLER(stencilBits
);
1383 /* This isn't quite right. It is supposed to compare the sum of the
1384 * components the user specifically set minimums for.
1386 PREFER_LARGER_OR_ZERO(accumRedBits
);
1387 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1388 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1389 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1391 PREFER_SMALLER(visualType
);
1393 /* None of the multisample specs say where this comparison should happen,
1394 * so I put it near the end.
1396 PREFER_SMALLER(sampleBuffers
);
1397 PREFER_SMALLER(samples
);
1399 /* None of the pbuffer or fbconfig specs say that this comparison needs
1400 * to happen at all, but it seems like it should.
1402 PREFER_LARGER(maxPbufferWidth
);
1403 PREFER_LARGER(maxPbufferHeight
);
1404 PREFER_LARGER(maxPbufferPixels
);
1411 * Selects and sorts a subset of the supplied configs based on the attributes.
1412 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1413 * and \c glXChooseFBConfigSGIX.
1415 * \param configs Array of pointers to possible configs. The elements of
1416 * this array that do not meet the criteria will be set to
1417 * NULL. The remaining elements will be sorted according to
1418 * the various visual / FBConfig selection rules.
1419 * \param num_configs Number of elements in the \c configs array.
1420 * \param attribList Attributes used select from \c configs. This array is
1421 * terminated by a \c None tag. The array can either take
1422 * the form expected by \c glXChooseVisual (where boolean
1423 * tags do not have a value) or by \c glXChooseFBConfig
1424 * (where every tag has a value).
1425 * \param fbconfig_style_tags Selects whether \c attribList is in
1426 * \c glXChooseVisual style or
1427 * \c glXChooseFBConfig style.
1428 * \returns The number of valid elements left in \c configs.
1430 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1433 choose_visual(struct glx_config
** configs
, int num_configs
,
1434 const int *attribList
, GLboolean fbconfig_style_tags
)
1436 struct glx_config test_config
;
1440 /* This is a fairly direct implementation of the selection method
1441 * described by GLX_SGIX_fbconfig. Start by culling out all the
1442 * configs that are not compatible with the selected parameter
1446 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1447 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1448 (const INT32
*) attribList
,
1449 GL_TRUE
, fbconfig_style_tags
);
1452 for (i
= 0; i
< num_configs
; i
++) {
1453 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1454 configs
[base
] = configs
[i
];
1463 if (base
< num_configs
) {
1464 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1467 /* After the incompatible configs are removed, the resulting
1468 * list is sorted according to the rules set out in the various
1472 qsort(configs
, base
, sizeof(struct glx_config
*),
1473 (int (*)(const void *, const void *)) fbconfig_compare
);
1481 ** Return the visual that best matches the template. Return None if no
1482 ** visual matches the template.
1484 _X_EXPORT XVisualInfo
*
1485 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1487 XVisualInfo
*visualList
= NULL
;
1488 struct glx_display
*priv
;
1489 struct glx_screen
*psc
;
1490 struct glx_config test_config
;
1491 struct glx_config
*config
;
1492 struct glx_config
*best_config
= NULL
;
1495 ** Get a list of all visuals, return if list is empty
1497 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1503 ** Build a template from the defaults and the attribute list
1504 ** Free visual list and return if an unexpected token is encountered
1506 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1507 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1508 (const INT32
*) attribList
,
1512 ** Eliminate visuals that don't meet minimum requirements
1513 ** Compute a score for those that do
1514 ** Remember which visual, if any, got the highest score
1515 ** If no visual is acceptable, return None
1516 ** Otherwise, create an XVisualInfo list with just the selected X visual
1519 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1520 if (fbconfigs_compatible(&test_config
, config
)
1521 && ((best_config
== NULL
) ||
1522 (fbconfig_compare (&config
, &best_config
) < 0))) {
1523 XVisualInfo visualTemplate
;
1524 XVisualInfo
*newList
;
1527 visualTemplate
.screen
= screen
;
1528 visualTemplate
.visualid
= config
->visualID
;
1529 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1530 &visualTemplate
, &i
);
1534 visualList
= newList
;
1535 best_config
= config
;
1540 #ifdef GLX_USE_APPLEGL
1541 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1542 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1550 _X_EXPORT
const char *
1551 glXQueryExtensionsString(Display
* dpy
, int screen
)
1553 struct glx_screen
*psc
;
1554 struct glx_display
*priv
;
1556 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1560 if (!psc
->effectiveGLXexts
) {
1561 if (!psc
->serverGLXexts
) {
1562 psc
->serverGLXexts
=
1563 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1567 __glXCalculateUsableExtensions(psc
,
1568 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1569 (psc
->driScreen
!= NULL
),
1573 priv
->minorVersion
);
1576 return psc
->effectiveGLXexts
;
1579 _X_EXPORT
const char *
1580 glXGetClientString(Display
* dpy
, int name
)
1586 return (__glXGLXClientVendorName
);
1588 return (__glXGLXClientVersion
);
1589 case GLX_EXTENSIONS
:
1590 return (__glXGetClientExtensions());
1596 _X_EXPORT
const char *
1597 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1599 struct glx_screen
*psc
;
1600 struct glx_display
*priv
;
1604 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1610 str
= &priv
->serverGLXvendor
;
1613 str
= &priv
->serverGLXversion
;
1615 case GLX_EXTENSIONS
:
1616 str
= &psc
->serverGLXexts
;
1623 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1630 __glXClientInfo(Display
* dpy
, int opcode
)
1632 char *ext_str
= __glXGetClientGLExtensionString();
1633 int size
= strlen(ext_str
) + 1;
1636 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1637 xcb_glx_client_info(c
,
1638 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1640 xGLXClientInfoReq
*req
;
1642 /* Send the glXClientInfo request */
1644 GetReq(GLXClientInfo
, req
);
1645 req
->reqType
= opcode
;
1646 req
->glxCode
= X_GLXClientInfo
;
1647 req
->major
= GLX_MAJOR_VERSION
;
1648 req
->minor
= GLX_MINOR_VERSION
;
1650 req
->length
+= (size
+ 3) >> 2;
1651 req
->numbytes
= size
;
1652 Data(dpy
, ext_str
, size
);
1656 #endif /* USE_XCB */
1663 ** EXT_import_context
1667 glXGetCurrentDisplay(void)
1669 struct glx_context
*gc
= __glXGetCurrentContext();
1672 return gc
->currentDpy
;
1676 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1677 glXGetCurrentDisplay
)
1679 #ifndef GLX_USE_APPLEGL
1680 _X_EXPORT GLXContext
1681 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1683 struct glx_display
*priv
= __glXInitialize(dpy
);
1684 struct glx_screen
*psc
;
1685 xGLXQueryContextReply reply
;
1687 struct glx_context
*ctx
;
1688 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1691 struct glx_config
*mode
;
1693 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1696 opcode
= __glXSetupForCommand(dpy
);
1700 /* Send the glXQueryContextInfoEXT request */
1703 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1704 xGLXQueryContextReq
*req
;
1706 GetReq(GLXQueryContext
, req
);
1708 req
->reqType
= opcode
;
1709 req
->glxCode
= X_GLXQueryContext
;
1710 req
->context
= contextID
;
1713 xGLXVendorPrivateReq
*vpreq
;
1714 xGLXQueryContextInfoEXTReq
*req
;
1716 GetReqExtra(GLXVendorPrivate
,
1717 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1719 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1720 req
->reqType
= opcode
;
1721 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1722 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1723 req
->context
= contextID
;
1726 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1728 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1729 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1732 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1736 /* Look up screen first so we can look up visuals/fbconfigs later */
1738 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1739 if (pProp
[0] == GLX_SCREEN
)
1740 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1749 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1751 case GLX_SHARE_CONTEXT_EXT
:
1754 case GLX_VISUAL_ID_EXT
:
1755 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1757 case GLX_FBCONFIG_ID
:
1758 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1760 case GLX_RENDER_TYPE
:
1761 renderType
= pProp
[1];
1768 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1772 ctx
->xid
= contextID
;
1773 ctx
->imported
= GL_TRUE
;
1774 ctx
->share_xid
= share
;
1776 return (GLXContext
) ctx
;
1782 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1784 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1786 switch (attribute
) {
1787 case GLX_SHARE_CONTEXT_EXT
:
1788 *value
= ctx
->share_xid
;
1790 case GLX_VISUAL_ID_EXT
:
1791 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1794 *value
= ctx
->screen
;
1796 case GLX_FBCONFIG_ID
:
1797 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1799 case GLX_RENDER_TYPE
:
1800 *value
= ctx
->renderType
;
1803 return GLX_BAD_ATTRIBUTE
;
1809 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1810 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1811 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1813 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1815 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1821 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1823 DestroyContext(dpy
, ctx
);
1827 _X_EXPORT GLXFBConfig
*
1828 glXChooseFBConfig(Display
* dpy
, int screen
,
1829 const int *attribList
, int *nitems
)
1831 struct glx_config
**config_list
;
1835 config_list
= (struct glx_config
**)
1836 glXGetFBConfigs(dpy
, screen
, &list_size
);
1838 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1839 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1840 if (list_size
== 0) {
1846 *nitems
= list_size
;
1847 return (GLXFBConfig
*) config_list
;
1851 _X_EXPORT GLXContext
1852 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1853 int renderType
, GLXContext shareList
, Bool allowDirect
)
1855 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1857 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1858 allowDirect
, X_GLXCreateNewContext
, renderType
,
1863 _X_EXPORT GLXDrawable
1864 glXGetCurrentReadDrawable(void)
1866 struct glx_context
*gc
= __glXGetCurrentContext();
1868 return gc
->currentReadable
;
1872 _X_EXPORT GLXFBConfig
*
1873 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1875 struct glx_display
*priv
= __glXInitialize(dpy
);
1876 struct glx_config
**config_list
= NULL
;
1877 struct glx_config
*config
;
1878 unsigned num_configs
= 0;
1882 if (priv
&& (priv
->screens
!= NULL
)
1883 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1884 && (priv
->screens
[screen
]->configs
!= NULL
)
1885 && (priv
->screens
[screen
]->configs
->fbconfigID
1886 != (int) GLX_DONT_CARE
)) {
1888 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1889 config
= config
->next
) {
1890 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1895 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1896 if (config_list
!= NULL
) {
1897 *nelements
= num_configs
;
1899 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1900 config
= config
->next
) {
1901 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1902 config_list
[i
] = config
;
1909 return (GLXFBConfig
*) config_list
;
1914 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1915 int attribute
, int *value
)
1917 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1920 return GLXBadFBConfig
;
1922 return glx_config_get(config
, attribute
, value
);
1926 _X_EXPORT XVisualInfo
*
1927 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1929 XVisualInfo visualTemplate
;
1930 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1934 ** Get a list of all visuals, return if list is empty
1936 visualTemplate
.visualid
= config
->visualID
;
1937 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1940 #ifndef GLX_USE_APPLEGL
1942 ** GLX_SGI_swap_control
1945 __glXSwapIntervalSGI(int interval
)
1947 xGLXVendorPrivateReq
*req
;
1948 struct glx_context
*gc
= __glXGetCurrentContext();
1949 struct glx_screen
*psc
;
1951 CARD32
*interval_ptr
;
1955 return GLX_BAD_CONTEXT
;
1958 if (interval
<= 0) {
1959 return GLX_BAD_VALUE
;
1962 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1964 #ifdef GLX_DIRECT_RENDERING
1965 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1966 __GLXDRIdrawable
*pdraw
=
1967 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1968 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1973 dpy
= gc
->currentDpy
;
1974 opcode
= __glXSetupForCommand(dpy
);
1979 /* Send the glXSwapIntervalSGI request */
1981 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1982 req
->reqType
= opcode
;
1983 req
->glxCode
= X_GLXVendorPrivate
;
1984 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1985 req
->contextTag
= gc
->currentContextTag
;
1987 interval_ptr
= (CARD32
*) (req
+ 1);
1988 *interval_ptr
= interval
;
1999 ** GLX_MESA_swap_control
2002 __glXSwapIntervalMESA(unsigned int interval
)
2004 #ifdef GLX_DIRECT_RENDERING
2005 struct glx_context
*gc
= __glXGetCurrentContext();
2007 if (gc
!= NULL
&& gc
->driContext
) {
2008 struct glx_screen
*psc
;
2010 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2011 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2012 __GLXDRIdrawable
*pdraw
=
2013 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2014 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2019 return GLX_BAD_CONTEXT
;
2024 __glXGetSwapIntervalMESA(void)
2026 #ifdef GLX_DIRECT_RENDERING
2027 struct glx_context
*gc
= __glXGetCurrentContext();
2029 if (gc
!= NULL
&& gc
->driContext
) {
2030 struct glx_screen
*psc
;
2032 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2033 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2034 __GLXDRIdrawable
*pdraw
=
2035 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2036 return psc
->driScreen
->getSwapInterval(pdraw
);
2046 ** GLX_SGI_video_sync
2049 __glXGetVideoSyncSGI(unsigned int *count
)
2051 int64_t ust
, msc
, sbc
;
2053 struct glx_context
*gc
= __glXGetCurrentContext();
2054 struct glx_screen
*psc
;
2055 #ifdef GLX_DIRECT_RENDERING
2056 __GLXDRIdrawable
*pdraw
;
2060 return GLX_BAD_CONTEXT
;
2062 #ifdef GLX_DIRECT_RENDERING
2063 if (!gc
->driContext
)
2064 return GLX_BAD_CONTEXT
;
2067 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2068 #ifdef GLX_DIRECT_RENDERING
2069 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2072 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2073 * FIXME: there should be a GLX encoding for this call. I can find no
2074 * FIXME: documentation for the GLX encoding.
2076 #ifdef GLX_DIRECT_RENDERING
2077 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2078 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2079 *count
= (unsigned) msc
;
2080 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2084 return GLX_BAD_CONTEXT
;
2088 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2090 struct glx_context
*gc
= __glXGetCurrentContext();
2091 struct glx_screen
*psc
;
2092 #ifdef GLX_DIRECT_RENDERING
2093 __GLXDRIdrawable
*pdraw
;
2095 int64_t ust
, msc
, sbc
;
2098 if (divisor
<= 0 || remainder
< 0)
2099 return GLX_BAD_VALUE
;
2102 return GLX_BAD_CONTEXT
;
2104 #ifdef GLX_DIRECT_RENDERING
2105 if (!gc
->driContext
)
2106 return GLX_BAD_CONTEXT
;
2109 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2110 #ifdef GLX_DIRECT_RENDERING
2111 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2114 #ifdef GLX_DIRECT_RENDERING
2115 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2116 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2118 *count
= (unsigned) msc
;
2119 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2123 return GLX_BAD_CONTEXT
;
2126 #endif /* GLX_USE_APPLEGL */
2129 ** GLX_SGIX_fbconfig
2130 ** Many of these functions are aliased to GLX 1.3 entry points in the
2131 ** GLX_functions table.
2135 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2136 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2137 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2139 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2140 (Display
* dpy
, int screen
, int *attrib_list
,
2141 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2144 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2145 (Display
* dpy
, GLXFBConfigSGIX config
),
2146 (dpy
, config
), glXGetVisualFromFBConfig
)
2149 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2150 GLXFBConfigSGIX fbconfig
,
2153 #ifndef GLX_USE_APPLEGL
2154 xGLXVendorPrivateWithReplyReq
*vpreq
;
2155 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2156 GLXPixmap xid
= None
;
2158 struct glx_screen
*psc
;
2160 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2163 if ((dpy
== NULL
) || (config
== NULL
)) {
2166 #ifdef GLX_USE_APPLEGL
2167 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
2172 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2174 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2175 opcode
= __glXSetupForCommand(dpy
);
2180 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2182 GetReqExtra(GLXVendorPrivateWithReply
,
2183 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2184 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2185 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2186 req
->reqType
= opcode
;
2187 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2188 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2189 req
->screen
= config
->screen
;
2190 req
->fbconfig
= config
->fbconfigID
;
2191 req
->pixmap
= pixmap
;
2192 req
->glxpixmap
= xid
= XAllocID(dpy
);
2201 _X_EXPORT GLXContext
2202 glXCreateContextWithConfigSGIX(Display
* dpy
,
2203 GLXFBConfigSGIX fbconfig
, int renderType
,
2204 GLXContext shareList
, Bool allowDirect
)
2206 GLXContext gc
= NULL
;
2207 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2208 struct glx_screen
*psc
;
2211 if ((dpy
== NULL
) || (config
== NULL
)) {
2215 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2217 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2218 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2220 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2228 _X_EXPORT GLXFBConfigSGIX
2229 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2231 struct glx_display
*priv
;
2232 struct glx_screen
*psc
= NULL
;
2234 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2235 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2236 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2237 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2244 #ifndef GLX_USE_APPLEGL
2246 ** GLX_SGIX_swap_group
2249 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2259 ** GLX_SGIX_swap_barrier
2262 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2270 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2280 ** GLX_OML_sync_control
2283 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2284 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2286 struct glx_display
* const priv
= __glXInitialize(dpy
);
2288 #ifdef GLX_DIRECT_RENDERING
2289 __GLXDRIdrawable
*pdraw
;
2291 struct glx_screen
*psc
;
2296 #ifdef GLX_DIRECT_RENDERING
2297 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2298 psc
= pdraw
? pdraw
->psc
: NULL
;
2299 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2300 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2308 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2310 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2311 int32_t * numerator
, int32_t * denominator
)
2314 struct glx_screen
*psc
;
2315 XF86VidModeModeLine mode_line
;
2320 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2321 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2322 unsigned n
= dot_clock
* 1000;
2323 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2325 # define V_INTERLACE 0x010
2326 # define V_DBLSCAN 0x020
2328 if (mode_line
.flags
& V_INTERLACE
)
2330 else if (mode_line
.flags
& V_DBLSCAN
)
2333 /* The OML_sync_control spec requires that if the refresh rate is a
2334 * whole number, that the returned numerator be equal to the refresh
2335 * rate and the denominator be 1.
2343 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2345 /* This is a poor man's way to reduce a fraction. It's far from
2346 * perfect, but it will work well enough for this situation.
2349 for (i
= 0; f
[i
] != 0; i
++) {
2350 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2376 * Determine the refresh rate of the specified drawable and display.
2378 * \param dpy Display whose refresh rate is to be determined.
2379 * \param drawable Drawable whose refresh rate is to be determined.
2380 * \param numerator Numerator of the refresh rate.
2381 * \param demoninator Denominator of the refresh rate.
2382 * \return If the refresh rate for the specified display and drawable could
2383 * be calculated, True is returned. Otherwise False is returned.
2385 * \note This function is implemented entirely client-side. A lot of other
2386 * functionality is required to export GLX_OML_sync_control, so on
2387 * XFree86 this function can be called for direct-rendering contexts
2388 * when GLX_OML_sync_control appears in the client extension string.
2392 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2393 int32_t * numerator
, int32_t * denominator
)
2395 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2396 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2401 return __glxGetMscRate(draw
, numerator
, denominator
);
2413 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2414 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2416 struct glx_context
*gc
= __glXGetCurrentContext();
2417 #ifdef GLX_DIRECT_RENDERING
2418 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2419 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2422 if (!gc
) /* no GLX for this */
2425 #ifdef GLX_DIRECT_RENDERING
2426 if (!pdraw
|| !gc
->driContext
)
2430 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2431 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2432 * of -1 if the function failed because of errors detected in the input
2435 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2437 if (divisor
> 0 && remainder
>= divisor
)
2440 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2443 #ifdef GLX_DIRECT_RENDERING
2444 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2445 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2454 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2455 int64_t target_msc
, int64_t divisor
,
2456 int64_t remainder
, int64_t * ust
,
2457 int64_t * msc
, int64_t * sbc
)
2459 #ifdef GLX_DIRECT_RENDERING
2460 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2462 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2466 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2467 * error", but the return type in the spec is Bool.
2469 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2471 if (divisor
> 0 && remainder
>= divisor
)
2474 #ifdef GLX_DIRECT_RENDERING
2475 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2476 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2487 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2488 int64_t target_sbc
, int64_t * ust
,
2489 int64_t * msc
, int64_t * sbc
)
2491 #ifdef GLX_DIRECT_RENDERING
2492 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2494 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2497 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2498 * error", but the return type in the spec is Bool.
2503 #ifdef GLX_DIRECT_RENDERING
2504 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2505 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2517 * Mesa extension stubs. These will help reduce portability problems.
2522 * Release all buffers associated with the specified GLX drawable.
2525 * This function was intended for stand-alone Mesa. The issue there is that
2526 * the library doesn't get any notification when a window is closed. In
2527 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2528 * supported, there are 3 different functions to destroy a drawable. It
2529 * should be possible to create GLX protocol (or have it determine which
2530 * protocol to use based on the type of the drawable) to have one function
2531 * do the work of 3. For the direct-rendering case, this function could
2532 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2533 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2534 * would need to be used. This really should be done as part of the new DRI
2537 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2538 * __driGarbageCollectDrawables
2539 * glXDestroyGLXPixmap
2540 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2541 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2544 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2553 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2554 Pixmap pixmap
, Colormap cmap
)
2567 * GLX_MESA_copy_sub_buffer
2569 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2571 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2572 int x
, int y
, int width
, int height
)
2574 xGLXVendorPrivateReq
*req
;
2575 struct glx_context
*gc
;
2577 CARD32
*drawable_ptr
;
2578 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2581 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2582 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2583 if (pdraw
!= NULL
) {
2584 struct glx_screen
*psc
= pdraw
->psc
;
2585 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2587 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2594 opcode
= __glXSetupForCommand(dpy
);
2599 ** The calling thread may or may not have a current context. If it
2600 ** does, send the context tag so the server can do a flush.
2602 gc
= __glXGetCurrentContext();
2603 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2604 ((drawable
== gc
->currentDrawable
) ||
2605 (drawable
== gc
->currentReadable
))) {
2606 tag
= gc
->currentContextTag
;
2613 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2614 req
->reqType
= opcode
;
2615 req
->glxCode
= X_GLXVendorPrivate
;
2616 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2617 req
->contextTag
= tag
;
2619 drawable_ptr
= (CARD32
*) (req
+ 1);
2620 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2621 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2622 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2623 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2625 *drawable_ptr
= drawable
;
2637 * GLX_EXT_texture_from_pixmap
2640 indirect_bind_tex_image(Display
* dpy
,
2641 GLXDrawable drawable
,
2642 int buffer
, const int *attrib_list
)
2644 xGLXVendorPrivateReq
*req
;
2645 struct glx_context
*gc
= __glXGetCurrentContext();
2646 CARD32
*drawable_ptr
;
2648 CARD32
*num_attrib_ptr
;
2655 while (attrib_list
[i
* 2] != None
)
2659 opcode
= __glXSetupForCommand(dpy
);
2664 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2665 req
->reqType
= opcode
;
2666 req
->glxCode
= X_GLXVendorPrivate
;
2667 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2668 req
->contextTag
= gc
->currentContextTag
;
2670 drawable_ptr
= (CARD32
*) (req
+ 1);
2671 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2672 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2673 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2675 *drawable_ptr
= drawable
;
2676 *buffer_ptr
= buffer
;
2677 *num_attrib_ptr
= (CARD32
) i
;
2681 while (attrib_list
[i
* 2] != None
) {
2682 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2683 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2693 indirect_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2695 xGLXVendorPrivateReq
*req
;
2696 struct glx_context
*gc
= __glXGetCurrentContext();
2697 CARD32
*drawable_ptr
;
2701 opcode
= __glXSetupForCommand(dpy
);
2706 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2707 req
->reqType
= opcode
;
2708 req
->glxCode
= X_GLXVendorPrivate
;
2709 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2710 req
->contextTag
= gc
->currentContextTag
;
2712 drawable_ptr
= (CARD32
*) (req
+ 1);
2713 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2715 *drawable_ptr
= drawable
;
2716 *buffer_ptr
= buffer
;
2722 static const struct glx_context_vtable indirect_context_vtable
= {
2723 indirect_destroy_context
,
2726 indirect_use_x_font
,
2727 indirect_bind_tex_image
,
2728 indirect_release_tex_image
,
2733 __glXBindTexImageEXT(Display
* dpy
,
2734 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2736 struct glx_context
*gc
= __glXGetCurrentContext();
2738 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2741 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2745 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2747 struct glx_context
*gc
= __glXGetCurrentContext();
2749 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2752 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2757 #endif /* GLX_USE_APPLEGL */
2760 * \c strdup is actually not a standard ANSI C or POSIX routine.
2761 * Irix will not define it if ANSI mode is in effect.
2766 __glXstrdup(const char *str
)
2769 copy
= (char *) Xmalloc(strlen(str
) + 1);
2777 ** glXGetProcAddress support
2780 struct name_address_pair
2786 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2787 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2789 static const struct name_address_pair GLX_functions
[] = {
2790 /*** GLX_VERSION_1_0 ***/
2791 GLX_FUNCTION(glXChooseVisual
),
2792 GLX_FUNCTION(glXCopyContext
),
2793 GLX_FUNCTION(glXCreateContext
),
2794 GLX_FUNCTION(glXCreateGLXPixmap
),
2795 GLX_FUNCTION(glXDestroyContext
),
2796 GLX_FUNCTION(glXDestroyGLXPixmap
),
2797 GLX_FUNCTION(glXGetConfig
),
2798 GLX_FUNCTION(glXGetCurrentContext
),
2799 GLX_FUNCTION(glXGetCurrentDrawable
),
2800 GLX_FUNCTION(glXIsDirect
),
2801 GLX_FUNCTION(glXMakeCurrent
),
2802 GLX_FUNCTION(glXQueryExtension
),
2803 GLX_FUNCTION(glXQueryVersion
),
2804 GLX_FUNCTION(glXSwapBuffers
),
2805 GLX_FUNCTION(glXUseXFont
),
2806 GLX_FUNCTION(glXWaitGL
),
2807 GLX_FUNCTION(glXWaitX
),
2809 /*** GLX_VERSION_1_1 ***/
2810 GLX_FUNCTION(glXGetClientString
),
2811 GLX_FUNCTION(glXQueryExtensionsString
),
2812 GLX_FUNCTION(glXQueryServerString
),
2814 /*** GLX_VERSION_1_2 ***/
2815 GLX_FUNCTION(glXGetCurrentDisplay
),
2817 /*** GLX_VERSION_1_3 ***/
2818 GLX_FUNCTION(glXChooseFBConfig
),
2819 GLX_FUNCTION(glXCreateNewContext
),
2820 GLX_FUNCTION(glXCreatePbuffer
),
2821 GLX_FUNCTION(glXCreatePixmap
),
2822 GLX_FUNCTION(glXCreateWindow
),
2823 GLX_FUNCTION(glXDestroyPbuffer
),
2824 GLX_FUNCTION(glXDestroyPixmap
),
2825 GLX_FUNCTION(glXDestroyWindow
),
2826 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2827 GLX_FUNCTION(glXGetFBConfigAttrib
),
2828 GLX_FUNCTION(glXGetFBConfigs
),
2829 GLX_FUNCTION(glXGetSelectedEvent
),
2830 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2831 GLX_FUNCTION(glXMakeContextCurrent
),
2832 GLX_FUNCTION(glXQueryContext
),
2833 GLX_FUNCTION(glXQueryDrawable
),
2834 GLX_FUNCTION(glXSelectEvent
),
2836 #ifndef GLX_USE_APPLEGL
2837 /*** GLX_SGI_swap_control ***/
2838 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2840 /*** GLX_SGI_video_sync ***/
2841 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2842 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2844 /*** GLX_SGI_make_current_read ***/
2845 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2846 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2848 /*** GLX_EXT_import_context ***/
2849 GLX_FUNCTION(glXFreeContextEXT
),
2850 GLX_FUNCTION(glXGetContextIDEXT
),
2851 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2852 GLX_FUNCTION(glXImportContextEXT
),
2853 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2856 /*** GLX_SGIX_fbconfig ***/
2857 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2858 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2859 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2860 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2861 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2862 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2864 #ifndef GLX_USE_APPLEGL
2865 /*** GLX_SGIX_pbuffer ***/
2866 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2867 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2868 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2869 GLX_FUNCTION(glXSelectEventSGIX
),
2870 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2872 /*** GLX_SGIX_swap_group ***/
2873 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2875 /*** GLX_SGIX_swap_barrier ***/
2876 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2877 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2879 /*** GLX_MESA_copy_sub_buffer ***/
2880 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2882 /*** GLX_MESA_pixmap_colormap ***/
2883 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2885 /*** GLX_MESA_release_buffers ***/
2886 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2888 /*** GLX_MESA_swap_control ***/
2889 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2890 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2893 /*** GLX_ARB_get_proc_address ***/
2894 GLX_FUNCTION(glXGetProcAddressARB
),
2897 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2899 #ifndef GLX_USE_APPLEGL
2900 /*** GLX_OML_sync_control ***/
2901 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2902 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2903 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2904 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2905 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2907 /*** GLX_EXT_texture_from_pixmap ***/
2908 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2909 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2912 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2913 /*** DRI configuration ***/
2914 GLX_FUNCTION(glXGetScreenDriver
),
2915 GLX_FUNCTION(glXGetDriverConfig
),
2918 {NULL
, NULL
} /* end of list */
2921 #ifndef GLX_USE_APPLEGL
2922 static const GLvoid
*
2923 get_glx_proc_address(const char *funcName
)
2927 /* try static functions */
2928 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2929 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2930 return GLX_functions
[i
].Address
;
2938 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2939 * \c glXGetProcAddress.
2941 * \param procName Name of a GL or GLX function.
2942 * \returns A pointer to the named function
2944 * \sa glXGetProcAddress
2946 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2948 typedef void (*gl_function
) (void);
2952 /* Search the table of GLX and internal functions first. If that
2953 * fails and the supplied name could be a valid core GL name, try
2954 * searching the core GL function table. This check is done to prevent
2955 * DRI based drivers from searching the core GL function table for
2956 * internal API functions.
2958 #ifdef GLX_USE_APPLEGL
2959 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2961 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2962 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2963 && (procName
[2] != 'X')) {
2964 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2971 * Get the address of a named GL function. This is the GLX 1.4 name for
2972 * \c glXGetProcAddressARB.
2974 * \param procName Name of a GL or GLX function.
2975 * \returns A pointer to the named function
2977 * \sa glXGetProcAddressARB
2979 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2980 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2981 __attribute__ ((alias("glXGetProcAddressARB")));
2984 return glXGetProcAddressARB(procName
);
2986 #endif /* __GNUC__ */
2989 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2991 * Get the unadjusted system time (UST). Currently, the UST is measured in
2992 * microseconds since Epoc. The actual resolution of the UST may vary from
2993 * system to system, and the units may vary from release to release.
2994 * Drivers should not call this function directly. They should instead use
2995 * \c glXGetProcAddress to obtain a pointer to the function.
2997 * \param ust Location to store the 64-bit UST
2998 * \returns Zero on success or a negative errno value on failure.
3000 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3002 * \since Internal API version 20030317.
3005 __glXGetUST(int64_t * ust
)
3013 if (gettimeofday(&tv
, NULL
) == 0) {
3014 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3021 #endif /* GLX_DIRECT_RENDERING */