-/* $Id: fakeglx.c,v 1.49 2001/04/27 21:18:25 brianp Exp $ */
+/* $Id: fakeglx.c,v 1.50 2001/05/24 19:06:21 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "context.h"
#include "config.h"
#include "macros.h"
+#include "mem.h"
#include "mmath.h"
#include "mtypes.h"
#include "xfonts.h"
}
+/*
+ * Our fake GLX context will contain a "real" GLX context and an XMesa context.
+ *
+ * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
+ * and vice versa.
+ *
+ * We really just need this structure in order to make the libGL functions
+ * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
+ * work correctly.
+ */
+struct fake_glx_context {
+ __GLXcontext glxContext; /* this MUST be first! */
+ XMesaContext xmesaContext;
+};
-#define DONT_CARE -1
+/**********************************************************************/
+/*** GLX Visual Code ***/
+/**********************************************************************/
+
+#define DONT_CARE -1
+
#define MAX_VISUALS 100
static XMesaVisual VisualTable[MAX_VISUALS];
static int NumVisuals = 0;
-
/*
* This struct and some code fragments borrowed
* from Mark Kilgard's GLUT library.
}
+/**********************************************************************/
+/*** Begin Fake GLX API Functions ***/
+/**********************************************************************/
+
static XVisualInfo *
Fake_glXChooseVisual( Display *dpy, int screen, int *list )
GLXContext share_list, Bool direct )
{
XMesaVisual glxvis;
- XMesaContext xmctx;
+ struct fake_glx_context *glxCtx;
+
+ glxCtx = CALLOC_STRUCT(fake_glx_context);
+ if (!glxCtx)
+ return 0;
/* deallocate unused windows/buffers */
XMesaGarbageCollect();
glxvis = create_glx_visual( dpy, visinfo );
if (!glxvis) {
/* unusable visual */
+ FREE(glxCtx);
return NULL;
}
}
- xmctx = XMesaCreateContext( glxvis, (XMesaContext) share_list );
- if (xmctx) {
- /* set the direct/indirect flag */
- xmctx->direct = direct;
+ glxCtx->xmesaContext = XMesaCreateContext(glxvis,
+ (XMesaContext) share_list);
+ if (!glxCtx->xmesaContext) {
+ FREE(glxCtx);
+ return NULL;
}
- return (GLXContext) xmctx;
+
+ glxCtx->xmesaContext->direct = GL_FALSE;
+ glxCtx->glxContext.isDirect = GL_FALSE;
+ glxCtx->glxContext.currentDpy = dpy;
+ glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
+
+ assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
+
+ return (GLXContext) glxCtx;
}
+/* XXX these may have to be removed due to thread-safety issues. */
static GLXContext MakeCurrent_PrevContext = 0;
static GLXDrawable MakeCurrent_PrevDrawable = 0;
static GLXDrawable MakeCurrent_PrevReadable = 0;
static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
+
/* GLX 1.3 and later */
static Bool
Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
GLXDrawable read, GLXContext ctx )
{
+ struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
+
if (ctx && draw && read) {
XMesaBuffer drawBuffer, readBuffer;
- XMesaContext xmctx = (XMesaContext) ctx;
+ XMesaContext xmctx = glxCtx->xmesaContext;
/* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
if (ctx == MakeCurrent_PrevContext
}
if (!drawBuffer) {
/* drawable must be a new window! */
- drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, (XMesaContext) ctx );
+ drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, xmctx);
if (!drawBuffer) {
/* Out of memory, or context/drawable depth mismatch */
return False;
}
if (!readBuffer) {
/* drawable must be a new window! */
- readBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, read, (XMesaContext) ctx );
+ readBuffer = XMesaCreateWindowBuffer2(glxCtx->xmesaContext->xm_visual,
+ read, xmctx);
if (!readBuffer) {
/* Out of memory, or context/drawable depth mismatch */
return False;
MakeCurrent_PrevReadBuffer = readBuffer;
/* Now make current! */
- return (Bool) XMesaMakeCurrent2((XMesaContext) ctx, drawBuffer, readBuffer);
+ if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
+ ctx->currentDpy = dpy;
+ ctx->currentDrawable = draw;
+ ctx->currentReadable = read;
+#ifdef GLX_BUILD_IN_XLIB_MESA
+ __glXSetCurrentContext(ctx);
+#endif
+ return True;
+ }
+ else {
+ return False;
+ }
}
else if (!ctx && !draw && !read) {
/* release current context w/out assigning new one. */
static void
Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
{
+ struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
(void) dpy;
MakeCurrent_PrevContext = 0;
MakeCurrent_PrevDrawable = 0;
MakeCurrent_PrevReadable = 0;
MakeCurrent_PrevDrawBuffer = 0;
MakeCurrent_PrevReadBuffer = 0;
- XMesaDestroyContext( (XMesaContext) ctx );
+ XMesaDestroyContext( glxCtx->xmesaContext );
XMesaGarbageCollect();
}
static Bool
Fake_glXIsDirect( Display *dpy, GLXContext ctx )
{
+ struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
(void) dpy;
- return ((XMesaContext) ctx)->direct;
+ return glxCtx->xmesaContext->direct;
}
return False;
}
+/* not used
static GLXDrawable
-Fake_glXGetCurrentReadDrawableSGI(void)
+make_glXGetCurrentReadDrawableSGI(void)
{
return 0;
}
-
+*/
#endif
return 0;
}
-static Display *
-Fake_glXGetCurrentDisplayEXT(void)
-{
- return glXGetCurrentDisplay();
-}
-
static GLXContext
Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
{
#ifdef GLX_SGI_make_current_read
glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
- glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;
+ /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
#endif
#if defined(_VL_H) && defined(GLX_SGIX_video_source)
#ifdef GLX_EXT_import_context
glx.FreeContextEXT = Fake_glXFreeContextEXT;
glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
- glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;
+ /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
glx.ImportContextEXT = Fake_glXImportContextEXT;
glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
#endif
-/* $Id: glxapi.c,v 1.21 2001/05/24 00:00:57 brianp Exp $ */
+/* $Id: glxapi.c,v 1.22 2001/05/24 19:06:21 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.5
*
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2001 Brian Paul 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"),
/* Set by glXMakeCurrent() and glXMakeContextCurrent() only */
-static Display *CurrentDisplay = NULL;
+#ifndef GLX_BUILD_IN_XLIB_MESA
static GLXContext CurrentContext = 0;
-static GLXDrawable CurrentDrawable = 0;
-static GLXDrawable CurrentReadDrawable = 0;
-
+#define __glXGetCurrentContext() CurrentContext;
+#endif
/*
}
+#ifdef GLX_BUILD_IN_XLIB_MESA
+/* Use real libGL's glXGetCurrentContext() function */
+#else
+/* stand-alone Mesa */
GLXContext glXGetCurrentContext(void)
{
return CurrentContext;
}
+#endif
GLXDrawable glXGetCurrentDrawable(void)
{
- return CurrentDrawable;
+ GLXContext gc = glXGetCurrentContext();
+ return gc ? gc->currentDrawable : 0;
}
if (!t)
return False;
b = (*t->MakeCurrent)(dpy, drawable, ctx);
+#ifndef GLX_BUILD_IN_XLIB_MESA
if (b) {
- CurrentDisplay = dpy;
CurrentContext = ctx;
- CurrentDrawable = drawable;
- CurrentReadDrawable = drawable;
}
+#endif
return b;
}
void glXUseXFont(Font font, int first, int count, int listBase)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return;
(t->UseXFont)(font, first, count, listBase);
void glXWaitGL(void)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return;
(t->WaitGL)();
void glXWaitX(void)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return;
(t->WaitX)();
#ifdef GLX_VERSION_1_2
Display *glXGetCurrentDisplay(void)
{
- return CurrentDisplay;
+ /* Same code as in libGL's glxext.c */
+ GLXContext gc = __glXGetCurrentContext();
+ if (NULL == gc) return NULL;
+ return gc->currentDpy;
}
#endif
GLXDrawable glXGetCurrentReadDrawable(void)
{
- return CurrentReadDrawable;
+ GLXContext gc = glXGetCurrentContext();
+ return gc ? gc->currentReadable : 0;
}
if (!t)
return False;
b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
+#ifndef GLX_BUILD_IN_XLIB_MESA
if (b) {
- CurrentDisplay = dpy;
CurrentContext = ctx;
- CurrentDrawable = draw;
- CurrentReadDrawable = read;
}
+#endif
return b;
}
int glXSwapIntervalSGI(int interval)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return 0;
return (t->SwapIntervalSGI)(interval);
int glXGetVideoSyncSGI(unsigned int *count)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return 0;
return (t->GetVideoSyncSGI)(count);
int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return 0;
return (t->WaitVideoSyncSGI)(divisor, remainder, count);
GLXDrawable glXGetCurrentReadDrawableSGI(void)
{
- struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
- if (!t)
- return 0;
- return (t->GetCurrentReadDrawableSGI)();
+ return glXGetCurrentReadDrawable();
}
-
#endif
(t->FreeContextEXT)(dpy, context);
}
+#ifdef GLX_BUILD_IN_XLIB_MESA
+/* Use real libGL's glXGetContextIDEXT() function */
+#else
+/* stand-alone Mesa */
GLXContextID glXGetContextIDEXT(const GLXContext context)
{
- /* XXX is this function right? */
- struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
- if (!t)
- return 0;
- return (t->GetContextIDEXT)(context);
+ return context->xid;
}
+#endif
Display *glXGetCurrentDisplayEXT(void)
{
- return CurrentDisplay;
+ return glXGetCurrentDisplay();
}
GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID)
Bool glXSet3DfxModeMESA(int mode)
{
struct _glxapi_table *t;
- GET_DISPATCH(CurrentDisplay, t);
+ Display *dpy = glXGetCurrentDisplay();
+ GET_DISPATCH(dpy, t);
if (!t)
return False;
return (t->Set3DfxModeMESA)(mode);
-/* $Id: glxapi.h,v 1.8 2000/12/15 04:02:50 brianp Exp $ */
+/* $Id: glxapi.h,v 1.9 2001/05/24 19:06:21 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.5
*
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2001 Brian Paul 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"),
#include "GL/glx.h"
+#ifdef GLX_BUILD_IN_XLIB_MESA
+/* The GLX API dispatcher is being built into XFree86's libGL */
+#include "glxclient.h"
+#else
+/* The GLX API dispatcher is being built into stand-alone Mesa */
+typedef struct __GLXcontextRec {
+ Display *currentDpy;
+ GLboolean isDirect;
+ GLXDrawable currentDrawable;
+ GLXDrawable currentReadable;
+ XID xid;
+} __GLXcontext;
+#endif
+
+
/*
* Almost all the GLX API functions get routed through this dispatch table.
* The exceptions are the glXGetCurrentXXX() functions.
#ifdef GLX_SGI_make_current_read
Bool (*MakeCurrentReadSGI)(Display *, GLXDrawable, GLXDrawable, GLXContext);
- GLXDrawable (*GetCurrentReadDrawableSGI)(void);
+ /*GLXDrawable (*GetCurrentReadDrawableSGI)(void);*/
#endif
#if defined(_VL_H) && defined(GLX_SGIX_video_source)
#ifdef GLX_EXT_import_context
void (*FreeContextEXT)(Display *dpy, GLXContext context);
GLXContextID (*GetContextIDEXT)(const GLXContext context);
- Display *(*GetCurrentDisplayEXT)(void);
+ /*Display *(*GetCurrentDisplayEXT)(void);*/
GLXContext (*ImportContextEXT)(Display *dpy, GLXContextID contextID);
int (*QueryContextInfoEXT)(Display *dpy, GLXContext context, int attribute,int *value);
#endif