automake: add -Wl,--no-undefined to all libraries
[mesa.git] / src / mesa / drivers / x11 / glxapi.c
index 8f7f5745da220cc26b3beb8be03ed483d242aad8..a870e94ed4a06e9968d81cca74e85d304f176764 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
  * 
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  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"),
  * 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
- * BRIAN PAUL 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.
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
  */
 
 
 /*
- * This is the GLX API dispatcher.  Calls to the glX* functions are
- * either routed to the real GLX encoders or to Mesa's pseudo-GLX functions.
- * See the glxapi.h file for more details.
+ * This is the GLX API dispatcher.  It uses a dispatch table but that's
+ * not really needed anymore since the table always points to the "fake"
+ * GLX functions.
  */
 
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "glheader.h"
-#include "glapi.h"
+#include "main/glheader.h"
+#include "main/compiler.h"
+#include "glapi/glapi.h"
 #include "glxapi.h"
 
 
-extern struct _glxapi_table *_real_GetGLXDispatchTable(void);
 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
 
 
@@ -49,6 +49,36 @@ struct display_dispatch {
    struct display_dispatch *Next;
 };
 
+
+/**
+ * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in
+ * libglapi.a.  We need to define them here.
+ */
+#ifdef GLX_INDIRECT_RENDERING
+
+#include "glapi/glapitable.h"
+
+#define KEYWORD1 PUBLIC
+
+#if defined(USE_MGL_NAMESPACE)
+#define NAME(func)  mgl##func
+#else
+#define NAME(func)  gl##func
+#endif
+
+#define DISPATCH(FUNC, ARGS, MESSAGE)          \
+   GET_DISPATCH()->FUNC ARGS
+
+#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE)   \
+   return GET_DISPATCH()->FUNC ARGS
+
+/* skip normal ones */
+#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS
+#include "glapi/glapitemp.h"
+
+#endif /* GLX_INDIRECT_RENDERING */
+
+
 static struct display_dispatch *DispatchList = NULL;
 
 
@@ -76,39 +106,13 @@ get_dispatch(Display *dpy)
       }
    }
 
-   /* A new display, determine if we should use real GLX
-    * or Mesa's pseudo-GLX.
-    */
+   /* Setup the dispatch table */
    {
-      struct _glxapi_table *t = NULL;
-
-#ifdef GLX_BUILT_IN_XMESA
-      if (!getenv("LIBGL_FORCE_XMESA")) {
-         int ignore;
-         if (XQueryExtension( dpy, "GLX", &ignore, &ignore, &ignore )) {
-            /* the X server has the GLX extension */
-            t = _real_GetGLXDispatchTable();
-         }
-      }
-#endif
-
-      if (!t) {
-         /* Fallback to Mesa with Xlib driver */
-#ifdef GLX_BUILT_IN_XMESA
-         if (getenv("LIBGL_DEBUG")) {
-            fprintf(stderr,
-                    "libGL: server %s lacks the GLX extension.",
-                    dpy->display_name);
-            fprintf(stderr, " Using Mesa Xlib renderer.\n");
-         }
-#endif
-         t = _mesa_GetGLXDispatchTable();
-         assert(t);  /* this has to work */
-      }
+      struct _glxapi_table *t = _mesa_GetGLXDispatchTable();
 
       if (t) {
          struct display_dispatch *d;
-         d = (struct display_dispatch *) malloc(sizeof(struct display_dispatch));
+         d = malloc(sizeof(struct display_dispatch));
          if (d) {
             d->Dpy = dpy;
             d->Table = t;
@@ -123,14 +127,13 @@ get_dispatch(Display *dpy)
       }
    }
 
-   /* If we get here that means we can't use real GLX on this display
-    * and the Mesa pseudo-GLX software renderer wasn't compiled in.
-    * Or, we ran out of memory!
-    */
    return NULL;
 }
 
 
+/* Don't use the GET_DISPATCH macro */
+#undef GET_DISPATCH
+
 #define GET_DISPATCH(DPY, TABLE)       \
    if (DPY == prevDisplay) {           \
       TABLE = prevTable;               \
@@ -143,15 +146,6 @@ get_dispatch(Display *dpy)
    }
 
    
-
-
-/* Set by glXMakeCurrent() and glXMakeContextCurrent() only */
-#ifndef GLX_BUILT_IN_XMESA
-static GLXContext CurrentContext = 0;
-#define __glXGetCurrentContext() CurrentContext;
-#endif
-
-
 /*
  * GLX API entrypoints
  */
@@ -235,29 +229,22 @@ glXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value)
 }
 
 
-#ifdef GLX_BUILT_IN_XMESA
-/* Use real libGL's glXGetCurrentContext() function */
-#else
-/* stand-alone Mesa */
+/* declare here to avoid including xmesa.h */
+extern void *XMesaGetCurrentContext(void);
+
 GLXContext PUBLIC
 glXGetCurrentContext(void)
 {
-   return CurrentContext;
+   return (GLXContext) XMesaGetCurrentContext();
 }
-#endif
 
 
-#ifdef GLX_BUILT_IN_XMESA
-/* Use real libGL's glXGetCurrentContext() function */
-#else
-/* stand-alone Mesa */
 GLXDrawable PUBLIC
 glXGetCurrentDrawable(void)
 {
    __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
    return gc ? gc->currentDrawable : 0;
 }
-#endif
 
 
 Bool PUBLIC
@@ -281,11 +268,6 @@ glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
       return False;
    }
    b = (*t->MakeCurrent)(dpy, drawable, ctx);
-#ifndef  GLX_BUILT_IN_XMESA
-   if (b) {
-      CurrentContext = ctx;
-   }
-#endif
    return b;
 }
 
@@ -397,7 +379,6 @@ glXQueryServerString(Display *dpy, int screen, int name)
 
 /*** GLX_VERSION_1_2 ***/
 
-#if !defined(GLX_BUILT_IN_XMESA)
 Display PUBLIC *
 glXGetCurrentDisplay(void)
 {
@@ -406,7 +387,6 @@ glXGetCurrentDisplay(void)
    if (NULL == gc) return NULL;
    return gc->currentDpy;
 }
-#endif
 
 
 
@@ -500,16 +480,12 @@ glXDestroyWindow(Display *dpy, GLXWindow window)
 }
 
 
-#ifdef GLX_BUILT_IN_XMESA
-/* Use the glXGetCurrentReadDrawable() function from libGL */
-#else
 GLXDrawable PUBLIC
 glXGetCurrentReadDrawable(void)
 {
    __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
    return gc ? gc->currentReadable : 0;
 }
-#endif
 
 
 int PUBLIC
@@ -564,11 +540,6 @@ glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXConte
    if (!t)
       return False;
    b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
-#ifndef GLX_BUILT_IN_XMESA
-   if (b) {
-      CurrentContext = ctx;
-   }
-#endif
    return b;
 }
 
@@ -631,8 +602,8 @@ glXGetVideoSyncSGI(unsigned int *count)
    struct _glxapi_table *t;
    Display *dpy = glXGetCurrentDisplay();
    GET_DISPATCH(dpy, t);
-   if (!t)
-      return 0;
+   if (!t || !glXGetCurrentContext())
+      return GLX_BAD_CONTEXT;
    return (t->GetVideoSyncSGI)(count);
 }
 
@@ -642,8 +613,8 @@ glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
    struct _glxapi_table *t;
    Display *dpy = glXGetCurrentDisplay();
    GET_DISPATCH(dpy, t);
-   if (!t)
-      return 0;
+   if (!t || !glXGetCurrentContext())
+      return GLX_BAD_CONTEXT;
    return (t->WaitVideoSyncSGI)(divisor, remainder, count);
 }
 
@@ -657,20 +628,15 @@ glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXConte
    struct _glxapi_table *t;
    GET_DISPATCH(dpy, t);
    if (!t)
-      return 0;
+      return False;
    return (t->MakeCurrentReadSGI)(dpy, draw, read, ctx);
 }
 
-#ifdef GLX_BUILT_IN_XMESA
-/* Use glXGetCurrentReadDrawableSGI() from libGL */
-#else
-/* stand-alone Mesa */
 GLXDrawable PUBLIC
 glXGetCurrentReadDrawableSGI(void)
 {
    return glXGetCurrentReadDrawable();
 }
-#endif
 
 
 #if defined(_VL_H)
@@ -710,27 +676,17 @@ glXFreeContextEXT(Display *dpy, GLXContext context)
    (t->FreeContextEXT)(dpy, context);
 }
 
-#ifdef GLX_BUILT_IN_XMESA
-/* Use real libGL's glXGetContextIDEXT() function */
-#else
-/* stand-alone Mesa */
 GLXContextID PUBLIC
 glXGetContextIDEXT(const GLXContext context)
 {
    return ((__GLXcontext *) context)->xid;
 }
-#endif
 
-#ifdef GLX_BUILT_IN_XMESA
-/* Use real libGL's glXGetCurrentDisplayEXT() function */
-#else
-/* stand-alone Mesa */
 Display PUBLIC *
 glXGetCurrentDisplayEXT(void)
 {
    return glXGetCurrentDisplay();
 }
-#endif
 
 GLXContext PUBLIC
 glXImportContextEXT(Display *dpy, GLXContextID contextID)
@@ -1108,32 +1064,28 @@ glXGetAGPOffsetMESA( const GLvoid *pointer )
 }
 
 
-/*** GLX_MESA_allocate_memory */
-
-void *
-glXAllocateMemoryMESA(Display *dpy, int scrn, size_t size,
-                      float readfreq, float writefreq, float priority)
-{
-   /* dummy */
-   return NULL;
-}
+/*** GLX_EXT_texture_from_pixmap */
 
-void
-glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
+void PUBLIC
+glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
+                   const int *attrib_list)
 {
-   /* dummy */
+   struct _glxapi_table *t;
+   GET_DISPATCH(dpy, t);
+   if (t)
+      t->BindTexImageEXT(dpy, drawable, buffer, attrib_list);
 }
 
-
-GLuint
-glXGetMemoryOffsetMESA(Display *dpy, int scrn, const void *pointer)
+void PUBLIC
+glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
 {
-   /* dummy */
-   return 0;
+   struct _glxapi_table *t;
+   GET_DISPATCH(dpy, t);
+   if (t)
+      t->ReleaseTexImageEXT(dpy, drawable, buffer);
 }
 
 
-
 /**********************************************************************/
 /* GLX API management functions                                       */
 /**********************************************************************/
@@ -1176,6 +1128,12 @@ _glxapi_get_extensions(void)
 #endif
 #ifdef GLX_SGIX_pbuffer
       "GLX_SGIX_pbuffer",
+#endif
+#ifdef GLX_EXT_texture_from_pixmap
+      "GLX_EXT_texture_from_pixmap",
+#endif
+#ifdef GLX_INTEL_swap_event
+      "GLX_INTEL_swap_event",
 #endif
       NULL
    };
@@ -1357,10 +1315,9 @@ static struct name_address_pair GLX_functions[] = {
    /*** GLX_MESA_agp_offset ***/
    { "glXGetAGPOffsetMESA", (__GLXextFuncPtr) glXGetAGPOffsetMESA },
 
-   /*** GLX_MESA_allocate_memory ***/
-   { "glXAllocateMemoryMESA", (__GLXextFuncPtr) glXAllocateMemoryMESA },
-   { "glXFreeMemoryMESA", (__GLXextFuncPtr) glXFreeMemoryMESA },
-   { "glXGetMemoryOffsetMESA", (__GLXextFuncPtr) glXGetMemoryOffsetMESA },
+   /*** GLX_EXT_texture_from_pixmap ***/
+   { "glXBindTexImageEXT", (__GLXextFuncPtr) glXBindTexImageEXT },
+   { "glXReleaseTexImageEXT", (__GLXextFuncPtr) glXReleaseTexImageEXT },
 
    { NULL, NULL }   /* end of list */
 };
@@ -1375,7 +1332,12 @@ _glxapi_get_proc_address(const char *funcName)
 {
    GLuint i;
    for (i = 0; GLX_functions[i].Name; i++) {
+#ifdef MANGLE
+      /* skip the "m" prefix on the name */
+      if (strcmp(GLX_functions[i].Name, funcName+1) == 0)
+#else
       if (strcmp(GLX_functions[i].Name, funcName) == 0)
+#endif
          return GLX_functions[i].Address;
    }
    return NULL;
@@ -1387,7 +1349,7 @@ _glxapi_get_proc_address(const char *funcName)
  * This function does not get dispatched through the dispatch table
  * since it's really a "meta" function.
  */
-__GLXextFuncPtr
+__GLXextFuncPtr PUBLIC
 glXGetProcAddressARB(const GLubyte *procName)
 {
    __GLXextFuncPtr f;
@@ -1403,7 +1365,8 @@ glXGetProcAddressARB(const GLubyte *procName)
 
 
 /* GLX 1.4 */
-void (*glXGetProcAddress(const GLubyte *procName))()
+void PUBLIC
+(*glXGetProcAddress(const GLubyte *procName))()
 {
    return glXGetProcAddressARB(procName);
 }