2008-04-18 15:28:34 +01:00
|
|
|
/*
|
Update to SGI FreeB 2.0.
Under the terms of version 1.1, "once Covered Code has been published
under a particular version of the License, Recipient may, for the
duration of the License, continue to use it under the terms of that
version, or choose to use such Covered Code under the terms of any
subsequent version published by SGI."
FreeB 2.0 license refers to "dates of first publication". They are here
taken to be 1991-2000, as noted in the original license text:
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
Official FreeB 2.0 text:
http://oss.sgi.com/projects/FreeB/SGIFreeSWLicB.2.0.pdf
As always, this code has not been tested for conformance with the OpenGL
specification. OpenGL conformance testing is available from
http://khronos.org/ and is required for use of the OpenGL logo in
product advertising and promotion.
2008-09-19 22:16:53 +01:00
|
|
|
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
|
|
|
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice including the dates of first publication and
|
|
|
|
* either this permission notice or a reference to
|
|
|
|
* http://oss.sgi.com/projects/FreeB/
|
|
|
|
* shall be included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name of Silicon Graphics, Inc.
|
|
|
|
* shall not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
* other dealings in this Software without prior written authorization from
|
|
|
|
* Silicon Graphics, Inc.
|
|
|
|
*/
|
2008-04-18 15:28:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file glxcurrent.c
|
|
|
|
* Client-side GLX interface for current context management.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glxclient.h"
|
|
|
|
#include "glapi.h"
|
|
|
|
#include "indirect_init.h"
|
|
|
|
|
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
|
|
|
#include "xf86dri.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
** We setup some dummy structures here so that the API can be used
|
|
|
|
** even if no context is current.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GLubyte dummyBuffer[__GLX_BUFFER_LIMIT_SIZE];
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Dummy context used by small commands when there is no current context.
|
|
|
|
** All the
|
|
|
|
** gl and glx entry points are designed to operate as nop's when using
|
|
|
|
** the dummy context structure.
|
|
|
|
*/
|
|
|
|
static __GLXcontext dummyContext = {
|
2008-10-13 13:07:07 +01:00
|
|
|
&dummyBuffer[0],
|
|
|
|
&dummyBuffer[0],
|
|
|
|
&dummyBuffer[0],
|
|
|
|
&dummyBuffer[__GLX_BUFFER_LIMIT_SIZE],
|
|
|
|
sizeof(dummyBuffer),
|
2008-04-18 15:28:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** All indirect rendering contexts will share the same indirect dispatch table.
|
|
|
|
*/
|
|
|
|
static __GLapi *IndirectAPI = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Current context management and locking
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined( USE_XTHREADS )
|
|
|
|
|
|
|
|
/* thread safe */
|
|
|
|
static GLboolean TSDinitialized = GL_FALSE;
|
|
|
|
static xthread_key_t ContextTSD;
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_X_HIDDEN __GLXcontext *
|
|
|
|
__glXGetCurrentContext(void)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
|
|
|
if (!TSDinitialized) {
|
|
|
|
xthread_key_create(&ContextTSD, NULL);
|
|
|
|
TSDinitialized = GL_TRUE;
|
|
|
|
return &dummyContext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
void *p;
|
|
|
|
xthread_get_specific(ContextTSD, &p);
|
|
|
|
if (!p)
|
|
|
|
return &dummyContext;
|
|
|
|
else
|
|
|
|
return (__GLXcontext *) p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_X_HIDDEN void
|
|
|
|
__glXSetCurrentContext(__GLXcontext * c)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
|
|
|
if (!TSDinitialized) {
|
|
|
|
xthread_key_create(&ContextTSD, NULL);
|
|
|
|
TSDinitialized = GL_TRUE;
|
|
|
|
}
|
|
|
|
xthread_set_specific(ContextTSD, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Used by the __glXLock() and __glXUnlock() macros */
|
|
|
|
_X_HIDDEN xmutex_rec __glXmutex;
|
|
|
|
|
|
|
|
#elif defined( PTHREADS )
|
|
|
|
|
|
|
|
_X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
# if defined( GLX_USE_TLS )
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Per-thread GLX context pointer.
|
|
|
|
*
|
|
|
|
* \c __glXSetCurrentContext is written is such a way that this pointer can
|
|
|
|
* \b never be \c NULL. This is important! Because of this
|
|
|
|
* \c __glXGetCurrentContext can be implemented as trivial macro.
|
|
|
|
*/
|
2008-10-13 13:07:07 +01:00
|
|
|
__thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
|
|
|
|
= &dummyContext;
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_X_HIDDEN void
|
|
|
|
__glXSetCurrentContext(__GLXcontext * c)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
__glX_tls_Context = (c != NULL) ? c : &dummyContext;
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Per-thread data key.
|
|
|
|
*
|
|
|
|
* Once \c init_thread_data has been called, the per-thread data key will
|
|
|
|
* take a value of \c NULL. As each new thread is created the default
|
|
|
|
* value, in that thread, will be \c NULL.
|
|
|
|
*/
|
|
|
|
static pthread_key_t ContextTSD;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the per-thread data key.
|
|
|
|
*
|
|
|
|
* This function is called \b exactly once per-process (not per-thread!) to
|
|
|
|
* initialize the per-thread data key. This is ideally done using the
|
|
|
|
* \c pthread_once mechanism.
|
|
|
|
*/
|
2008-10-13 13:07:07 +01:00
|
|
|
static void
|
|
|
|
init_thread_data(void)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
if (pthread_key_create(&ContextTSD, NULL) != 0) {
|
|
|
|
perror("pthread_key_create");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_X_HIDDEN void
|
|
|
|
__glXSetCurrentContext(__GLXcontext * c)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
pthread_once(&once_control, init_thread_data);
|
|
|
|
pthread_setspecific(ContextTSD, c);
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_X_HIDDEN __GLXcontext *
|
|
|
|
__glXGetCurrentContext(void)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
void *v;
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
pthread_once(&once_control, init_thread_data);
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
v = pthread_getspecific(ContextTSD);
|
|
|
|
return (v == NULL) ? &dummyContext : (__GLXcontext *) v;
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# endif /* defined( GLX_USE_TLS ) */
|
|
|
|
|
|
|
|
#elif defined( THREADS )
|
|
|
|
|
|
|
|
#error Unknown threading method specified.
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* not thread safe */
|
|
|
|
_X_HIDDEN __GLXcontext *__glXcurrentContext = &dummyContext;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_X_HIDDEN void
|
|
|
|
__glXSetCurrentContextNull(void)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
__glXSetCurrentContext(&dummyContext);
|
2008-04-18 15:28:34 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2008-10-13 13:07:07 +01:00
|
|
|
_glapi_set_dispatch(NULL); /* no-op functions */
|
2008-04-18 15:28:34 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
PUBLIC GLXContext
|
|
|
|
glXGetCurrentContext(void)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
GLXContext cx = __glXGetCurrentContext();
|
|
|
|
|
|
|
|
if (cx == &dummyContext) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return cx;
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
PUBLIC GLXDrawable
|
|
|
|
glXGetCurrentDrawable(void)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
GLXContext gc = __glXGetCurrentContext();
|
|
|
|
return gc->currentDrawable;
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a GLX protocol message to the specified display to make the context
|
|
|
|
* and the drawables current.
|
|
|
|
*
|
|
|
|
* \param dpy Display to send the message to.
|
|
|
|
* \param opcode Major opcode value for the display.
|
|
|
|
* \param gc_id Context tag for the context to be made current.
|
|
|
|
* \param draw Drawable ID for the "draw" drawable.
|
|
|
|
* \param read Drawable ID for the "read" drawable.
|
|
|
|
* \param reply Space to store the X-server's reply.
|
|
|
|
*
|
|
|
|
* \warning
|
|
|
|
* This function assumes that \c dpy is locked with \c LockDisplay on entry.
|
|
|
|
*/
|
2008-10-13 13:07:07 +01:00
|
|
|
static Bool
|
|
|
|
SendMakeCurrentRequest(Display * dpy, CARD8 opcode,
|
|
|
|
GLXContextID gc_id, GLXContextTag gc_tag,
|
|
|
|
GLXDrawable draw, GLXDrawable read,
|
|
|
|
xGLXMakeCurrentReply * reply)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
Bool ret;
|
|
|
|
|
|
|
|
|
|
|
|
LockDisplay(dpy);
|
|
|
|
|
|
|
|
if (draw == read) {
|
|
|
|
xGLXMakeCurrentReq *req;
|
|
|
|
|
|
|
|
GetReq(GLXMakeCurrent, req);
|
|
|
|
req->reqType = opcode;
|
|
|
|
req->glxCode = X_GLXMakeCurrent;
|
|
|
|
req->drawable = draw;
|
|
|
|
req->context = gc_id;
|
|
|
|
req->oldContextTag = gc_tag;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
__GLXdisplayPrivate *priv = __glXInitialize(dpy);
|
|
|
|
|
|
|
|
/* If the server can support the GLX 1.3 version, we should
|
|
|
|
* perfer that. Not only that, some servers support GLX 1.3 but
|
|
|
|
* not the SGI extension.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
|
|
|
|
xGLXMakeContextCurrentReq *req;
|
|
|
|
|
|
|
|
GetReq(GLXMakeContextCurrent, req);
|
|
|
|
req->reqType = opcode;
|
|
|
|
req->glxCode = X_GLXMakeContextCurrent;
|
|
|
|
req->drawable = draw;
|
|
|
|
req->readdrawable = read;
|
|
|
|
req->context = gc_id;
|
|
|
|
req->oldContextTag = gc_tag;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xGLXVendorPrivateWithReplyReq *vpreq;
|
|
|
|
xGLXMakeCurrentReadSGIReq *req;
|
|
|
|
|
|
|
|
GetReqExtra(GLXVendorPrivateWithReply,
|
|
|
|
sz_xGLXMakeCurrentReadSGIReq -
|
|
|
|
sz_xGLXVendorPrivateWithReplyReq, vpreq);
|
|
|
|
req = (xGLXMakeCurrentReadSGIReq *) vpreq;
|
|
|
|
req->reqType = opcode;
|
|
|
|
req->glxCode = X_GLXVendorPrivateWithReply;
|
|
|
|
req->vendorCode = X_GLXvop_MakeCurrentReadSGI;
|
|
|
|
req->drawable = draw;
|
|
|
|
req->readable = read;
|
|
|
|
req->context = gc_id;
|
|
|
|
req->oldContextTag = gc_tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _XReply(dpy, (xReply *) reply, 0, False);
|
|
|
|
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
|
|
|
|
|
|
|
return ret;
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
|
|
|
static __GLXDRIdrawable *
|
2008-10-13 13:07:07 +01:00
|
|
|
FetchDRIDrawable(Display * dpy,
|
|
|
|
GLXDrawable glxDrawable, GLXContext gc, Bool pre13)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
__GLXdisplayPrivate *const priv = __glXInitialize(dpy);
|
|
|
|
__GLXDRIdrawable *pdraw;
|
|
|
|
__GLXscreenConfigs *psc;
|
|
|
|
XID drawable;
|
|
|
|
|
|
|
|
if (priv == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
psc = &priv->screenConfigs[gc->screen];
|
|
|
|
if (psc->drawHash == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (__glxHashLookup(psc->drawHash, glxDrawable, (void *) &pdraw) == 0)
|
|
|
|
return pdraw;
|
|
|
|
|
|
|
|
/* If this is glXMakeCurrent (pre GLX 1.3) we allow creating the
|
|
|
|
* GLX drawable on the fly. Otherwise we pass None as the X
|
|
|
|
* drawable */
|
|
|
|
if (pre13)
|
|
|
|
drawable = glxDrawable;
|
|
|
|
else
|
|
|
|
drawable = None;
|
|
|
|
|
|
|
|
pdraw = psc->driScreen->createDrawable(psc, drawable,
|
|
|
|
glxDrawable, gc->mode);
|
|
|
|
if (__glxHashInsert(psc->drawHash, glxDrawable, pdraw)) {
|
|
|
|
(*pdraw->destroyDrawable) (pdraw);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pdraw;
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
#endif /* GLX_DIRECT_RENDERING */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a particular context current.
|
|
|
|
*
|
|
|
|
* \note This is in this file so that it can access dummyContext.
|
|
|
|
*/
|
2008-10-13 13:07:07 +01:00
|
|
|
static Bool
|
|
|
|
MakeContextCurrent(Display * dpy, GLXDrawable draw,
|
|
|
|
GLXDrawable read, GLXContext gc, Bool pre13)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
xGLXMakeCurrentReply reply;
|
|
|
|
const GLXContext oldGC = __glXGetCurrentContext();
|
|
|
|
const CARD8 opcode = __glXSetupForCommand(dpy);
|
|
|
|
const CARD8 oldOpcode = ((gc == oldGC) || (oldGC == &dummyContext))
|
2008-04-18 15:28:34 +01:00
|
|
|
? opcode : __glXSetupForCommand(oldGC->currentDpy);
|
2008-10-13 13:07:07 +01:00
|
|
|
Bool bindReturnValue;
|
2008-04-18 15:28:34 +01:00
|
|
|
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
if (!opcode || !oldOpcode) {
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
/* Make sure that the new context has a nonzero ID. In the request,
|
|
|
|
* a zero context ID is used only to mean that we bind to no current
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
if ((gc != NULL) && (gc->xid == None)) {
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
_glapi_check_multithread();
|
2008-04-18 15:28:34 +01:00
|
|
|
|
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2008-10-13 13:07:07 +01:00
|
|
|
/* Bind the direct rendering context to the drawable */
|
|
|
|
if (gc && gc->driContext) {
|
|
|
|
__GLXDRIdrawable *pdraw = FetchDRIDrawable(dpy, draw, gc, pre13);
|
|
|
|
__GLXDRIdrawable *pread = FetchDRIDrawable(dpy, read, gc, pre13);
|
|
|
|
|
|
|
|
bindReturnValue =
|
|
|
|
(gc->driContext->bindContext) (gc->driContext, pdraw, pread);
|
|
|
|
}
|
|
|
|
else
|
2008-04-18 15:28:34 +01:00
|
|
|
#endif
|
2008-10-13 13:07:07 +01:00
|
|
|
{
|
|
|
|
/* Send a glXMakeCurrent request to bind the new context. */
|
|
|
|
bindReturnValue =
|
|
|
|
SendMakeCurrentRequest(dpy, opcode, gc ? gc->xid : None,
|
|
|
|
((dpy != oldGC->currentDpy)
|
|
|
|
|| oldGC->isDirect)
|
|
|
|
? None : oldGC->currentContextTag, draw, read,
|
|
|
|
&reply);
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
if (!bindReturnValue) {
|
|
|
|
return False;
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-08-08 10:52:10 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2008-10-13 13:07:07 +01:00
|
|
|
if ((dpy != oldGC->currentDpy || (gc && gc->driContext)) &&
|
|
|
|
!oldGC->isDirect && oldGC != &dummyContext) {
|
2008-08-08 10:52:10 +01:00
|
|
|
#else
|
2008-10-13 13:07:07 +01:00
|
|
|
if ((dpy != oldGC->currentDpy) && oldGC != &dummyContext) {
|
2008-08-08 10:52:10 +01:00
|
|
|
#endif
|
2008-10-13 13:07:07 +01:00
|
|
|
xGLXMakeCurrentReply dummy_reply;
|
|
|
|
|
|
|
|
/* We are either switching from one dpy to another and have to
|
|
|
|
* send a request to the previous dpy to unbind the previous
|
|
|
|
* context, or we are switching away from a indirect context to
|
|
|
|
* a direct context and have to send a request to the dpy to
|
|
|
|
* unbind the previous context.
|
|
|
|
*/
|
|
|
|
(void) SendMakeCurrentRequest(oldGC->currentDpy, oldOpcode, None,
|
|
|
|
oldGC->currentContextTag, None, None,
|
|
|
|
&dummy_reply);
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2008-10-13 13:07:07 +01:00
|
|
|
else if (oldGC->driContext) {
|
|
|
|
oldGC->driContext->unbindContext(oldGC->driContext);
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
/* Update our notion of what is current */
|
|
|
|
__glXLock();
|
|
|
|
if (gc == oldGC) {
|
|
|
|
/* Even though the contexts are the same the drawable might have
|
|
|
|
* changed. Note that gc cannot be the dummy, and that oldGC
|
|
|
|
* cannot be NULL, therefore if they are the same, gc is not
|
|
|
|
* NULL and not the dummy.
|
|
|
|
*/
|
|
|
|
gc->currentDrawable = draw;
|
|
|
|
gc->currentReadable = read;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (oldGC != &dummyContext) {
|
|
|
|
/* Old current context is no longer current to anybody */
|
|
|
|
oldGC->currentDpy = 0;
|
|
|
|
oldGC->currentDrawable = None;
|
|
|
|
oldGC->currentReadable = None;
|
|
|
|
oldGC->currentContextTag = 0;
|
|
|
|
|
|
|
|
if (oldGC->xid == None) {
|
|
|
|
/* We are switching away from a context that was
|
|
|
|
* previously destroyed, so we need to free the memory
|
|
|
|
* for the old handle.
|
|
|
|
*/
|
2008-04-18 15:28:34 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2008-10-13 13:07:07 +01:00
|
|
|
/* Destroy the old direct rendering context */
|
|
|
|
if (oldGC->driContext) {
|
|
|
|
oldGC->driContext->destroyContext(oldGC->driContext,
|
|
|
|
oldGC->psc,
|
|
|
|
oldGC->createDpy);
|
|
|
|
oldGC->driContext = NULL;
|
|
|
|
}
|
2008-04-18 15:28:34 +01:00
|
|
|
#endif
|
2008-10-13 13:07:07 +01:00
|
|
|
__glXFreeContext(oldGC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gc) {
|
|
|
|
__glXSetCurrentContext(gc);
|
|
|
|
|
|
|
|
gc->currentDpy = dpy;
|
|
|
|
gc->currentDrawable = draw;
|
|
|
|
gc->currentReadable = read;
|
|
|
|
|
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
|
|
|
if (!gc->driContext) {
|
2008-08-08 10:52:10 +01:00
|
|
|
#endif
|
2008-10-13 13:07:07 +01:00
|
|
|
if (!IndirectAPI)
|
|
|
|
IndirectAPI = __glXNewIndirectAPI();
|
|
|
|
_glapi_set_dispatch(IndirectAPI);
|
2008-04-18 15:28:34 +01:00
|
|
|
|
|
|
|
#ifdef GLX_USE_APPLEGL
|
2008-10-13 13:07:07 +01:00
|
|
|
do {
|
|
|
|
extern void XAppleDRIUseIndirectDispatch(void);
|
|
|
|
XAppleDRIUseIndirectDispatch();
|
|
|
|
} while (0);
|
2008-04-18 15:28:34 +01:00
|
|
|
#endif
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
__GLXattribute *state =
|
|
|
|
(__GLXattribute *) (gc->client_state_private);
|
|
|
|
|
|
|
|
gc->currentContextTag = reply.contextTag;
|
|
|
|
if (state->array_state == NULL) {
|
|
|
|
(void) glGetString(GL_EXTENSIONS);
|
|
|
|
(void) glGetString(GL_VERSION);
|
|
|
|
__glXInitVertexArrayState(gc);
|
|
|
|
}
|
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc->currentContextTag = -1;
|
|
|
|
}
|
2008-08-08 10:52:10 +01:00
|
|
|
#endif
|
2008-10-13 13:07:07 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
__glXSetCurrentContextNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__glXUnlock();
|
|
|
|
return GL_TRUE;
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
PUBLIC Bool
|
|
|
|
glXMakeCurrent(Display * dpy, GLXDrawable draw, GLXContext gc)
|
2008-04-18 15:28:34 +01:00
|
|
|
{
|
2008-10-13 13:07:07 +01:00
|
|
|
return MakeContextCurrent(dpy, draw, draw, gc, True);
|
2008-04-18 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
PUBLIC
|
|
|
|
GLX_ALIAS(Bool, glXMakeCurrentReadSGI,
|
|
|
|
(Display * dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx),
|
|
|
|
(dpy, d, r, ctx, False), MakeContextCurrent)
|
2008-04-18 15:28:34 +01:00
|
|
|
|
2008-10-13 13:07:07 +01:00
|
|
|
PUBLIC GLX_ALIAS(Bool, glXMakeContextCurrent,
|
|
|
|
(Display * dpy, GLXDrawable d, GLXDrawable r,
|
|
|
|
GLXContext ctx), (dpy, d, r, ctx, False),
|
|
|
|
MakeContextCurrent)
|