Fix glXCopyContext bug
[mesa.git] / src / mesa / drivers / x11 / fakeglx.c
index af94222b767c56210a951cfce77741a898932fa3..e7d98dd2a3da9fd302f32fbbae03c7eb66d8114a 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: fakeglx.c,v 1.60 2002/03/15 18:24:53 brianp Exp $ */
+/* $Id: fakeglx.c,v 1.66 2002/06/16 03:56:11 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  4.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"),
@@ -269,8 +269,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
             ximageFlag = GL_TRUE;
          }
          else {
-            fprintf(stderr, "Mesa: invalid value for MESA_BACK_BUFFER ");
-            fprintf(stderr, "environment variable, using an XImage.\n");
+            _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
          }
       }
    }
@@ -308,8 +307,8 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
 
    /* Create a new visual and add it to the list. */
 
-   if (NumVisuals>=MAX_VISUALS) {
-      fprintf( stderr, "GLX Error: maximum number of visuals exceeded\n");
+   if (NumVisuals >= MAX_VISUALS) {
+      _mesa_problem(NULL, "GLX Error: maximum number of visuals exceeded");
       return NULL;
    }
 
@@ -392,7 +391,7 @@ create_glx_visual( Display *dpy, XVisualInfo *visinfo )
       }
    }
    else {
-      fprintf(stderr,"Mesa: error in glXCreateContext: bad visual\n");
+      _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
       return NULL;
    }
 }
@@ -578,8 +577,13 @@ static XVisualInfo *get_env_visual(Display *dpy, int scr, const char *varname)
       }
    }
 
-   fprintf( stderr, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
-           type, depth );
+   {
+      char s[1000];
+      sprintf(s, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
+              type, depth );
+      _mesa_warning(NULL, s);
+   }
+
    return NULL;
 }
 
@@ -1133,6 +1137,10 @@ Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
    XMesaVisual glxvis;
    struct fake_glx_context *glxCtx;
    struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
+
+   if (!dpy || !visinfo)
+      return 0;
+
    glxCtx = CALLOC_STRUCT(fake_glx_context);
    if (!glxCtx)
       return 0;
@@ -1233,8 +1241,9 @@ Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
       if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
          ((__GLXcontext *) ctx)->currentDpy = dpy;
          ((__GLXcontext *) ctx)->currentDrawable = draw;
+#ifndef GLX_BUILT_IN_XMESA
          ((__GLXcontext *) ctx)->currentReadable = read;
-#ifdef GLX_BUILT_IN_XMESA
+#else
          __glXSetCurrentContext(ctx);
 #endif
          return True;
@@ -1331,7 +1340,7 @@ Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
       XMesaDestroyBuffer(b);
    }
    else if (getenv("MESA_DEBUG")) {
-      fprintf( stderr, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
+      _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
    }
 }
 
@@ -1341,8 +1350,10 @@ static void
 Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
                      unsigned long mask )
 {
-   XMesaContext xm_src = (XMesaContext) src;
-   XMesaContext xm_dst = (XMesaContext) dst;
+   struct fake_glx_context *fakeSrc = (struct fake_glx_context *) src;
+   struct fake_glx_context *fakeDst = (struct fake_glx_context *) dst;
+   XMesaContext xm_src = fakeSrc->xmesaContext;
+   XMesaContext xm_dst = fakeDst->xmesaContext;
    (void) dpy;
    _mesa_copy_context( xm_src->gl_ctx, xm_dst->gl_ctx, (GLuint) mask );
 }
@@ -1403,7 +1414,7 @@ Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
       XMesaSwapBuffers(buffer);
    }
    else if (getenv("MESA_DEBUG")) {
-      fprintf(stderr, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
+      _mesa_warning(NULL, "Mesa: glXSwapBuffers: invalid drawable\n");
    }
 }
 
@@ -1420,7 +1431,7 @@ Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
       XMesaCopySubBuffer(buffer, x, y, width, height);
    }
    else if (getenv("MESA_DEBUG")) {
-      fprintf(stderr, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
+      _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
    }
 }
 
@@ -1459,7 +1470,6 @@ Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
            return 0;
         }
         else {
-           /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
            return GLX_BAD_VISUAL;
         }
       }
@@ -1704,6 +1714,7 @@ extern XMesaBuffer XMesaCreatePBuffer( XMesaVisual v, XMesaColormap cmap,
 
 
 
+/* PBUFFER */
 static GLXFBConfig *
 Fake_glXChooseFBConfig( Display *dpy, int screen,
                         const int *attribList, int *nitems )
@@ -1716,6 +1727,7 @@ Fake_glXChooseFBConfig( Display *dpy, int screen,
 }
 
 
+/* PBUFFER */
 static int
 Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
                            int attribute, int *value )
@@ -1790,7 +1802,11 @@ Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
          *value = False; /* XXX ??? */
          break;
       case GLX_X_VISUAL_TYPE:
+#if defined(__cplusplus) || defined(c_plusplus)
+         switch (v->vishandle->c_class) {
+#else
          switch (v->vishandle->class) {
+#endif
             case GrayScale:
                *value = GLX_GRAY_SCALE;
                break;
@@ -1871,16 +1887,19 @@ Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
 }
 
 
+/* PBUFFER */
 static GLXFBConfig *
 Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
 {
+   /* Get list of all X visuals, create FBconfigs from them */
    (void) dpy;
    (void) screen;
-   (void) nelements;
+   nelements = 0;
    return 0;
 }
 
 
+/* PBUFFER */
 static XVisualInfo *
 Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
 {
@@ -1894,6 +1913,7 @@ Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
 }
 
 
+/* PBUFFER */
 static GLXWindow
 Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
                       const int *attribList )
@@ -1964,6 +1984,7 @@ Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
 }
 
 
+/* PBUFFER */
 static GLXPbuffer
 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
                        const int *attribList )
@@ -2002,6 +2023,7 @@ Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
 }
 
 
+/* PBUFFER */
 static void
 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
 {
@@ -2010,6 +2032,7 @@ Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
 }
 
 
+/* PBUFFER */
 static void
 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
                        unsigned int *value )
@@ -2045,6 +2068,7 @@ Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
 }
 
 
+/* PBUFFER */
 static int
 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
 {
@@ -2063,6 +2087,7 @@ Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
 }
 
 
+/* PBUFFER */
 static void
 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
 {
@@ -2072,6 +2097,7 @@ Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
 }
 
 
+/* PBUFFER */
 static void
 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
                           unsigned long *mask )
@@ -2119,11 +2145,7 @@ Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
 static Bool
 Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
 {
-   (void) dpy;
-   (void) draw;
-   (void) read;
-   (void) ctx;
-   return False;
+   return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
 }
 
 /* not used