Removed all RCS / CVS tags (Id, Header, Date, etc.) from everything.
[mesa.git] / src / mesa / drivers / x11 / glxapi.c
index 007579250a8f788524965332e52c0e2cbc10b0b0..4680994310ef2d97b6719b86e5569b80d8f6de39 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: glxapi.c,v 1.25 2001/05/29 16:23:26 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  5.1
  * 
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2002  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"),
@@ -28,6 +27,7 @@
 /*
  * 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.
  */
 
 
@@ -35,7 +35,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-/*#include <dlfcn.h>*/ /* XXX not portable? */
 #include "glapi.h"
 #include "glxapi.h"
 
@@ -83,7 +82,7 @@ get_dispatch(Display *dpy)
    {
       struct _glxapi_table *t = NULL;
 
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
       if (!getenv("LIBGL_FORCE_XMESA")) {
          int ignore;
          if (XQueryExtension( dpy, "GLX", &ignore, &ignore, &ignore )) {
@@ -95,10 +94,12 @@ get_dispatch(Display *dpy)
 
       if (!t) {
          /* Fallback to Mesa with Xlib driver */
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
          if (getenv("LIBGL_DEBUG")) {
             fprintf(stderr,
-               "libGL: server lacks GLX extension. Using Mesa Xlib renderer.");
+                    "libGL: server %s lacks the GLX extension.",
+                    dpy->display_name);
+            fprintf(stderr, " Using Mesa Xlib renderer.\n");
          }
 #endif
          t = _mesa_GetGLXDispatchTable();
@@ -145,7 +146,7 @@ get_dispatch(Display *dpy)
 
 
 /* Set by glXMakeCurrent() and glXMakeContextCurrent() only */
-#ifndef GLX_BUILD_IN_XLIB_MESA
+#ifndef GLX_BUILT_IN_XMESA
 static GLXContext CurrentContext = 0;
 #define __glXGetCurrentContext() CurrentContext;
 #endif
@@ -227,7 +228,7 @@ int glXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value)
 }
 
 
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
 /* Use real libGL's glXGetCurrentContext() function */
 #else
 /* stand-alone Mesa */
@@ -238,7 +239,7 @@ GLXContext glXGetCurrentContext(void)
 #endif
 
 
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
 /* Use real libGL's glXGetCurrentContext() function */
 #else
 /* stand-alone Mesa */
@@ -265,10 +266,11 @@ Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
    Bool b;
    struct _glxapi_table *t;
    GET_DISPATCH(dpy, t);
-   if (!t)
+   if (!t) {
       return False;
+   }
    b = (*t->MakeCurrent)(dpy, drawable, ctx);
-#ifndef  GLX_BUILD_IN_XLIB_MESA
+#ifndef  GLX_BUILT_IN_XMESA
    if (b) {
       CurrentContext = ctx;
    }
@@ -375,7 +377,7 @@ const char *glXQueryServerString(Display *dpy, int screen, int name)
 
 /*** GLX_VERSION_1_2 ***/
 
-#if !defined(GLX_BUILD_IN_XLIB_MESA)
+#if !defined(GLX_BUILT_IN_XMESA)
 Display *glXGetCurrentDisplay(void)
 {
    /* Same code as in libGL's glxext.c */
@@ -469,7 +471,7 @@ void glXDestroyWindow(Display *dpy, GLXWindow window)
 }
 
 
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
 /* Use the glXGetCurrentReadDrawable() function from libGL */
 #else
 GLXDrawable glXGetCurrentReadDrawable(void)
@@ -527,7 +529,7 @@ Bool glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLX
    if (!t)
       return False;
    b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
-#ifndef GLX_BUILD_IN_XLIB_MESA
+#ifndef GLX_BUILT_IN_XMESA
    if (b) {
       CurrentContext = ctx;
    }
@@ -617,7 +619,7 @@ Bool glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLX
    return (t->MakeCurrentReadSGI)(dpy, draw, read, ctx);
 }
 
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
 /* Use glXGetCurrentReadDrawableSGI() from libGL */
 #else
 /* stand-alone Mesa */
@@ -662,7 +664,7 @@ void glXFreeContextEXT(Display *dpy, GLXContext context)
    (t->FreeContextEXT)(dpy, context);
 }
 
-#ifdef GLX_BUILD_IN_XLIB_MESA
+#ifdef GLX_BUILT_IN_XMESA
 /* Use real libGL's glXGetContextIDEXT() function */
 #else
 /* stand-alone Mesa */
@@ -672,10 +674,15 @@ GLXContextID glXGetContextIDEXT(const GLXContext context)
 }
 #endif
 
+#ifdef GLX_BUILT_IN_XMESA
+/* Use real libGL's glXGetCurrentDisplayEXT() function */
+#else
+/* stand-alone Mesa */
 Display *glXGetCurrentDisplayEXT(void)
 {
    return glXGetCurrentDisplay();
 }
+#endif
 
 GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID)
 {
@@ -980,6 +987,84 @@ Bool glXSet3DfxModeMESA(int mode)
 
 
 
+/*** GLX_NV_vertex_array_range ***/
+
+void *
+glXAllocateMemoryNV( GLsizei size,
+                     GLfloat readFrequency,
+                     GLfloat writeFrequency,
+                     GLfloat priority )
+{
+   struct _glxapi_table *t;
+   Display *dpy = glXGetCurrentDisplay();
+   GET_DISPATCH(dpy, t);
+   if (!t)
+      return NULL;
+   return (t->AllocateMemoryNV)(size, readFrequency, writeFrequency, priority);
+}
+
+
+void 
+glXFreeMemoryNV( GLvoid *pointer )
+{
+   struct _glxapi_table *t;
+   Display *dpy = glXGetCurrentDisplay();
+   GET_DISPATCH(dpy, t);
+   if (!t)
+      return;
+   (t->FreeMemoryNV)(pointer);
+}
+
+
+/*** GLX_MESA_agp_offset */
+
+GLuint
+glXGetAGPOffsetMESA( const GLvoid *pointer )
+{
+   struct _glxapi_table *t;
+   Display *dpy = glXGetCurrentDisplay();
+   GET_DISPATCH(dpy, t);
+   if (!t)
+      return ~0;
+   return (t->GetAGPOffsetMESA)(pointer);
+}
+
+
+/*** GLX_ARB_render_Texture ***/
+
+Bool
+glXBindTexImageARB( Display *dpy, GLXPbuffer pbuffer, int buffer )
+{
+   struct _glxapi_table *t;
+   GET_DISPATCH(dpy, t);
+   if (!t)
+      return False;
+   return (t->BindTexImageARB)(dpy, pbuffer, buffer);
+}
+
+
+Bool
+glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer )
+{
+   struct _glxapi_table *t;
+   GET_DISPATCH(dpy, t);
+   if (!t)
+      return False;
+   return (t->ReleaseTexImageARB)(dpy, pbuffer, buffer);
+}
+
+
+Bool
+glXDrawableAttribARB( Display *dpy, GLXDrawable draw, const int *attribList )
+{
+   struct _glxapi_table *t;
+   GET_DISPATCH(dpy, t);
+   if (!t)
+      return False;
+   return (t->DrawableAttribARB)(dpy, draw, attribList);
+}
+
+
 
 /**********************************************************************/
 /* GLX API management functions                                       */
@@ -1017,6 +1102,15 @@ _glxapi_get_extensions(void)
 #endif
 #ifdef GLX_MESA_set_3dfx_mode
       "GLX_MESA_set_3dfx_mode",
+#endif
+#ifdef GLX_SGIX_fbconfig
+      "GLX_SGIX_fbconfig",
+#endif
+#ifdef GLX_SGIX_pbuffer
+      "GLX_SGIX_pbuffer",
+#endif
+#ifdef GLX_ARB_render_texture
+      "GLX_ARB_render_texture",
 #endif
       NULL
    };
@@ -1056,143 +1150,6 @@ _glxapi_set_no_op_table(struct _glxapi_table *t)
 }
 
 
-#if 00
-/*
- * Open the named library and use dlsym() to populate the given dispatch
- * table with GLX function pointers.
- * Return: true = all OK
- *         false = can't open libName or can't get required GLX function
- */
-GLboolean
-_glxapi_load_library_table(const char *libName, struct _glxapi_table *t)
-{
-   void *libHandle;
-   void **entry;   /* used to avoid a lot of cast/type warnings */
-
-   libHandle = dlopen(libName, 0);
-   if (!libHandle) {
-      return GL_FALSE;
-   }
-
-#define GET_REQ_FUNCTION(ENTRY, NAME)                                  \
-   entry = (void **) &(t->ENTRY);                                      \
-   *entry = dlsym(libHandle, NAME);                                    \
-   if (!*entry) {                                                      \
-      fprintf(stderr, "libGL Error: couldn't load %s from %s\n",       \
-              NAME, libName);                                          \
-      dlclose(libHandle);                                              \
-      return GL_FALSE;                                                 \
-   }
-
-   /* 1.0 and 1.1 functions */
-   GET_REQ_FUNCTION(ChooseVisual, "glXChooseVisual");
-   GET_REQ_FUNCTION(CopyContext, "glXCopyContext");
-   GET_REQ_FUNCTION(CreateContext, "glXCreateContext");
-   GET_REQ_FUNCTION(CreateGLXPixmap, "glXCreateGLXPixmap");
-   GET_REQ_FUNCTION(DestroyContext, "glXDestroyContext");
-   GET_REQ_FUNCTION(GetConfig, "glXGetConfig");
-   GET_REQ_FUNCTION(IsDirect, "glXIsDirect");
-   GET_REQ_FUNCTION(MakeCurrent, "glXMakeCurrent");
-   GET_REQ_FUNCTION(QueryExtension, "glXQueryExtension");
-   GET_REQ_FUNCTION(QueryVersion, "glXQueryVersion");
-   GET_REQ_FUNCTION(SwapBuffers, "glXSwapBuffers");
-   GET_REQ_FUNCTION(UseXFont, "glXUseXFont");
-   GET_REQ_FUNCTION(WaitGL, "glXWaitGL");
-   GET_REQ_FUNCTION(WaitX, "glXWaitX");
-   GET_REQ_FUNCTION(GetClientString, "glXGetClientString");
-   GET_REQ_FUNCTION(QueryExtensionsString, "glXQueryExtensionsString");
-   GET_REQ_FUNCTION(QueryServerString, "glXQueryServerString");
-
-#define GET_OPT_FUNCTION(ENTRY, NAME)                                  \
-   entry = (void **) &(t->ENTRY);                                      \
-   *entry = dlsym(libHandle, NAME);                                    \
-   if (!*entry) {                                                      \
-      *entry = (void *) generic_no_op_func;                            \
-   }
-
-   /* 1.2, 1.3 and extensions */
-   GET_OPT_FUNCTION(ChooseFBConfig, "glXChooseFBConfig");
-   GET_OPT_FUNCTION(CreateNewContext, "glXCreateNewContext");
-   GET_OPT_FUNCTION(CreatePbuffer, "glXCreatePbuffer");
-   GET_OPT_FUNCTION(CreatePixmap, "glXCreatePixmap");
-   GET_OPT_FUNCTION(CreateWindow, "glXCreateWindow");
-   GET_OPT_FUNCTION(DestroyPbuffer, "glXDestroyPbuffer");
-   GET_OPT_FUNCTION(DestroyPixmap, "glXDestroyPixmap");
-   GET_OPT_FUNCTION(DestroyWindow, "glXDestroyWindow");
-   GET_OPT_FUNCTION(GetFBConfigAttrib, "glXGetFBConfigAttrib");
-   GET_OPT_FUNCTION(GetFBConfigs, "glXGetFBConfigs");
-   GET_OPT_FUNCTION(GetSelectedEvent, "glXGetSelectedEvent");
-   GET_OPT_FUNCTION(GetVisualFromFBConfig, "glXGetVisualFromFBConfig");
-   GET_OPT_FUNCTION(MakeContextCurrent, "glXMakeContextCurrent");
-   GET_OPT_FUNCTION(QueryContext, "glXQueryContext");
-   GET_OPT_FUNCTION(QueryDrawable, "glXQueryDrawable");
-   GET_OPT_FUNCTION(SelectEvent, "glXSelectEvent");
-   /*** GLX_SGI_swap_control ***/
-   GET_OPT_FUNCTION(SwapIntervalSGI, "glXSwapIntervalSGI");
-   /*** GLX_SGI_video_sync ***/
-   GET_OPT_FUNCTION(GetVideoSyncSGI, "glXGetVideoSyncSGI");
-   GET_OPT_FUNCTION(WaitVideoSyncSGI, "glXWaitVideoSyncSGI");
-   /*** GLX_SGI_make_current_read ***/
-   GET_OPT_FUNCTION(MakeCurrentReadSGI, "glXMakeCurrentReadSGI");
-   GET_OPT_FUNCTION(GetCurrentReadDrawableSGI, "glXGetCurrentReadDrawableSGI");
-   /*** GLX_SGIX_video_source ***/
-#if defined(_VL_H)
-   GET_OPT_FUNCTION(CreateGLXVideoSourceSGIX, "glXCreateGLXVideoSourceSGIX");
-   GET_OPT_FUNCTION(DestroyGLXVideoSourceSGIX, "glXDestroyGLXVideoSourceSGIX");
-#endif
-   /*** GLX_EXT_import_context ***/
-   GET_OPT_FUNCTION(FreeContextEXT, "glXFreeContextEXT");
-   GET_OPT_FUNCTION(GetContextIDEXT, "glXGetContextIDEXT");
-   GET_OPT_FUNCTION(GetCurrentDisplayEXT, "glXGetCurrentDisplayEXT");
-   GET_OPT_FUNCTION(ImportContextEXT, "glXImportContextEXT");
-   GET_OPT_FUNCTION(QueryContextInfoEXT, "glXQueryContextInfoEXT");
-   /*** GLX_SGIX_fbconfig ***/
-   GET_OPT_FUNCTION(GetFBConfigAttribSGIX, "glXGetFBConfigAttribSGIX");
-   GET_OPT_FUNCTION(ChooseFBConfigSGIX, "glXChooseFBConfigSGIX");
-   GET_OPT_FUNCTION(CreateGLXPixmapWithConfigSGIX, "glXCreateGLXPixmapWithConfigSGIX");
-   GET_OPT_FUNCTION(CreateContextWithConfigSGIX, "glXCreateContextWithConfigSGIX");
-   GET_OPT_FUNCTION(GetVisualFromFBConfigSGIX, "glXGetVisualFromFBConfigSGIX");
-   GET_OPT_FUNCTION(GetFBConfigFromVisualSGIX, "glXGetFBConfigFromVisualSGIX");
-   /*** GLX_SGIX_pbuffer ***/
-   GET_OPT_FUNCTION(CreateGLXPbufferSGIX, "glXCreateGLXPbufferSGIX");
-   GET_OPT_FUNCTION(DestroyGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX");
-   GET_OPT_FUNCTION(QueryGLXPbufferSGIX, "glXQueryGLXPbufferSGIX");
-   GET_OPT_FUNCTION(SelectEventSGIX, "glXSelectEventSGIX");
-   GET_OPT_FUNCTION(GetSelectedEventSGIX, "glXGetSelectedEventSGIX");
-   /*** GLX_SGI_cushion ***/
-   GET_OPT_FUNCTION(CushionSGI, "glXCushionSGI");
-   /*** GLX_SGIX_video_resize ***/
-   GET_OPT_FUNCTION(BindChannelToWindowSGIX, "glXBindChannelToWindowSGIX");
-   GET_OPT_FUNCTION(ChannelRectSGIX, "glXChannelRectSGIX");
-   GET_OPT_FUNCTION(QueryChannelRectSGIX, "glXQueryChannelRectSGIX");
-   GET_OPT_FUNCTION(QueryChannelDeltasSGIX, "glXQueryChannelDeltasSGIX");
-   GET_OPT_FUNCTION(ChannelRectSyncSGIX, "glXChannelRectSyncSGIX");
-   /*** GLX_SGIX_dmbuffer ***/
-#if defined (_DM_BUFFER_H_)
-   GET_OPT_FUNCTION(AssociateDMPbufferSGIX, "glXAssociateDMPbufferSGIX");
-#endif
-   /*** GLX_SGIX_swap_group ***/
-   GET_OPT_FUNCTION(JoinSwapGroupSGIX, "glXJoinSwapGroupSGIX");
-   /*** GLX_SGIX_swap_barrier ***/
-   GET_OPT_FUNCTION(BindSwapBarrierSGIX, "glXBindSwapBarrierSGIX");
-   GET_OPT_FUNCTION(QueryMaxSwapBarriersSGIX, "glXQueryMaxSwapBarriersSGIX");
-   /*** GLX_SUN_get_transparent_index ***/
-   GET_OPT_FUNCTION(GetTransparentIndexSUN, "glXGetTransparentIndexSUN");
-   /*** GLX_MESA_copy_sub_buffer ***/
-   GET_OPT_FUNCTION(CopySubBufferMESA, "glXCopySubBufferMESA");
-   /*** GLX_MESA_release_buffers ***/
-   GET_OPT_FUNCTION(ReleaseBuffersMESA, "glXReleaseBuffersMESA");
-   /*** GLX_MESA_pixmap_colormap ***/
-   GET_OPT_FUNCTION(CreateGLXPixmapMESA, "glXCreateGLXPixmapMESA");
-   /*** GLX_MESA_set_3dfx_mode ***/
-   GET_OPT_FUNCTION(Set3DfxModeMESA, "glXSet3DfxModeMESA");
-
-   return GL_TRUE;
-}
-#endif
-
-
-
 struct name_address_pair {
    const char *Name;
    GLvoid *Address;
@@ -1245,6 +1202,9 @@ static struct name_address_pair GLX_functions[] = {
    { "glXQueryDrawable", (GLvoid *) glXQueryDrawable },
    { "glXSelectEvent", (GLvoid *) glXSelectEvent },
 
+   /*** GLX_VERSION_1_4 ***/
+   { "glXGetProcAddress", (GLvoid *) glXGetProcAddress },
+
    /*** GLX_SGI_swap_control ***/
    { "glXSwapIntervalSGI", (GLvoid *) glXSwapIntervalSGI },
 
@@ -1324,6 +1284,18 @@ static struct name_address_pair GLX_functions[] = {
    /*** GLX_ARB_get_proc_address ***/
    { "glXGetProcAddressARB", (GLvoid *) glXGetProcAddressARB },
 
+   /*** GLX_NV_vertex_array_range ***/
+   { "glXAllocateMemoryNV", (GLvoid *) glXAllocateMemoryNV },
+   { "glXFreeMemoryNV", (GLvoid *) glXFreeMemoryNV },
+
+   /*** GLX_MESA_agp_offset ***/
+   { "glXGetAGPOffsetMESA", (GLvoid *) glXGetAGPOffsetMESA },
+
+   /*** GLX_ARB_render_texture ***/
+   { "glXBindTexImageARB", (GLvoid *) glXBindTexImageARB },
+   { "glXReleaseTexImageARB", (GLvoid *) glXReleaseTexImageARB },
+   { "glXDrawableAttribARB", (GLvoid *) glXDrawableAttribARB },
+
    { NULL, NULL }   /* end of list */
 };
 
@@ -1362,3 +1334,10 @@ void (*glXGetProcAddressARB(const GLubyte *procName))()
    f = (gl_function) _glapi_get_proc_address((const char *) procName);
    return f;
 }
+
+
+/* GLX 1.4 */
+void (*glXGetProcAddress(const GLubyte *procName))()
+{
+   return glXGetProcAddressARB(procName);
+}