Merge remote branch 'origin/gallium-0.2' into gallium-0.2
[mesa.git] / src / glx / x11 / glxcmds.c
index 1437ea54425ba03a4db4a4ed3435fd2522be790b..cac39a59048a665876e6d9a4a85f0fd691149be1 100644 (file)
@@ -1,60 +1,48 @@
-/* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */
 /*
-** License Applicability. Except to the extent portions of this file are
-** made subject to an alternative license as permitted in the SGI Free
-** Software License B, Version 1.1 (the "License"), the contents of this
-** file are subject only to the provisions of the License. You may not use
-** this file except in compliance with the License. You may obtain a copy
-** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
-** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
-** 
-** http://oss.sgi.com/projects/FreeB
-** 
-** Note that, as provided in the License, the Software is distributed on an
-** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
-** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
-** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
-** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
-** 
-** 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.
-** 
-** Additional Notice Provisions: The application programming interfaces
-** established by SGI in conjunction with the Original Code are The
-** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
-** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
-** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
-** Window System(R) (Version 1.3), released October 19, 1998. This software
-** was created using the OpenGL(R) version 1.2.1 Sample Implementation
-** published by SGI, but has not been independently verified as being
-** compliant with the OpenGL(R) version 1.2.1 Specification.
-**
-*/
+ * 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.
+ */
 
 /**
  * \file glxcmds.c
  * Client-side GLX interface.
  */
 
-#include <inttypes.h>
 #include "glxclient.h"
-#include <X11/extensions/extutil.h>
-#include <X11/extensions/Xext.h>
-#include <assert.h>
-#include <string.h>
 #include "glapi.h"
+#include "glxextensions.h"
+#include "glcontextmodes.h"
+
 #ifdef GLX_DIRECT_RENDERING
-#include "indirect_init.h"
+#include <sys/time.h>
 #include <X11/extensions/xf86vmode.h>
 #include "xf86dri.h"
 #endif
-#include "glxextensions.h"
-#include "glcontextmodes.h"
-#include "glheader.h"
-#include <sys/time.h>
 
 static const char __glXGLXClientVendorName[] = "SGI";
 static const char __glXGLXClientVersion[] = "1.4";
@@ -99,10 +87,8 @@ static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
            if (!windowExistsFlag) {
                /* Destroy the local drawable data, if the drawable no
                   longer exists in the Xserver */
-               (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable);
-               XF86DRIDestroyDrawable(dpy, sc->scr, draw);
+               (*pdraw->destroyDrawable)(pdraw);
                 __glxHashDelete(sc->drawHash, draw);
-               Xfree(pdraw);
            }
        } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1);
     }
@@ -111,6 +97,9 @@ static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
     XSetErrorHandler(oldXErrorHandler);
 }
 
+extern __GLXDRIdrawable *
+GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num);
+
 /**
  * Get the __DRIdrawable for the drawable associated with a GLXContext
  * 
@@ -120,24 +109,27 @@ static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
  * \returns  A pointer to the context's __DRIdrawable on success, or NULL if
  *           the drawable is not associated with a direct-rendering context.
  */
-static __DRIdrawable *
-GetDRIDrawable( Display *dpy, GLXDrawable drawable, int * const scrn_num )
+_X_HIDDEN __GLXDRIdrawable *
+GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num)
 {
-    __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
-    __GLXDRIdrawable * const pdraw;
+    __GLXdisplayPrivate *priv = __glXInitialize(dpy);
+    __GLXDRIdrawable *pdraw;
     const unsigned  screen_count = ScreenCount(dpy);
     unsigned   i;
-    __GLXscreenConfigs *sc;
+    __GLXscreenConfigs *psc;
 
-    if (priv == NULL || priv->driDisplay == NULL)
+    if (priv == NULL)
        return NULL;
     
     for (i = 0; i < screen_count; i++) {
-       sc = &priv->screenConfigs[i];
-       if (__glxHashLookup(sc->drawHash, drawable, (void *) &pdraw) == 0) {
+       psc = &priv->screenConfigs[i];
+       if (psc->drawHash == NULL)
+           continue;
+
+       if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) {
            if (scrn_num != NULL)
                *scrn_num = i;
-           return &pdraw->driDrawable;
+           return pdraw;
        }
     }
 
@@ -315,6 +307,7 @@ GLXContext AllocateGLXContext( Display *dpy )
     gc->fillImage = __glFillImage;
     gc->pc = gc->buf;
     gc->bufEnd = gc->buf + bufSize;
+    gc->isDirect = GL_FALSE;
     if (__glXDebug) {
        /*
        ** Set limit register so that there will be one command per packet
@@ -406,6 +399,7 @@ CreateContext(Display *dpy, XVisualInfo *vis,
                gc->screen = mode->screen;
                gc->psc = psc;
                gc->mode = mode;
+               gc->isDirect = GL_TRUE;
            }
        }
 #endif
@@ -422,7 +416,11 @@ CreateContext(Display *dpy, XVisualInfo *vis,
            req->visual = vis->visualid;
            req->screen = vis->screen;
            req->shareList = shareList ? shareList->xid : None;
+#ifdef GLX_DIRECT_RENDERING
            req->isDirect = gc->driContext != NULL;
+#else
+           req->isDirect = 0;
+#endif
        }
        else if ( use_glx_1_3 ) {
            xGLXCreateNewContextReq *req;
@@ -436,7 +434,11 @@ CreateContext(Display *dpy, XVisualInfo *vis,
            req->screen = fbconfig->screen;
            req->renderType = renderType;
            req->shareList = shareList ? shareList->xid : None;
+#ifdef GLX_DIRECT_RENDERING
            req->isDirect = gc->driContext != NULL;
+#else
+           req->isDirect = 0;
+#endif
        }
        else {
            xGLXVendorPrivateWithReplyReq *vpreq;
@@ -454,7 +456,11 @@ CreateContext(Display *dpy, XVisualInfo *vis,
            req->screen = fbconfig->screen;
            req->renderType = renderType;
            req->shareList = shareList ? shareList->xid : None;
+#ifdef GLX_DIRECT_RENDERING
            req->isDirect = gc->driContext != NULL;
+#else
+           req->isDirect = 0;
+#endif
        }
 
        UnlockDisplay(dpy);
@@ -519,6 +525,8 @@ DestroyContext(Display *dpy, GLXContext gc)
     }
 #endif
 
+    __glXFreeVertexArrayState(gc);
+
     if (gc->currentDpy) {
        /* Have to free later cuz it's in use now */
        __glXUnlock();
@@ -837,10 +845,11 @@ PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
     GLXContextTag tag;
     CARD8 opcode;
 #ifdef GLX_DIRECT_RENDERING
-    __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, NULL );
+    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
 
-    if ( pdraw != NULL ) {
-       (*pdraw->swapBuffers)(pdraw);
+    if (pdraw != NULL) {
+       glFlush();          
+       (*pdraw->psc->driScreen->swapBuffers)(pdraw);
        return;
     }
 #endif
@@ -1524,7 +1533,11 @@ glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value)
     int retVal;
 
     /* get the information from the server if we don't have it already */
+#ifdef GLX_DIRECT_RENDERING
     if (!ctx->driContext && (ctx->mode == NULL)) {
+#else
+    if (ctx->mode == NULL) {
+#endif
        retVal = __glXQueryContextInfo(dpy, ctx);
        if (Success != retVal) return retVal;
     }
@@ -1721,11 +1734,11 @@ static int __glXSwapIntervalSGI(int interval)
    if (gc->driContext) {
        __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
                                                             gc->screen );
-       __DRIdrawable * const pdraw = GetDRIDrawable( gc->currentDpy,
-                                                    gc->currentDrawable,
-                                                    NULL );
+       __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy,
+                                                  gc->currentDrawable,
+                                                  NULL);
        if (psc->swapControl != NULL && pdraw != NULL) {
-          psc->swapControl->setSwapInterval(pdraw, interval);
+          psc->swapControl->setSwapInterval(pdraw->driDrawable, interval);
           return 0;
        }
        else {
@@ -1775,10 +1788,10 @@ static int __glXSwapIntervalMESA(unsigned int interval)
                                                            gc->screen );
       
       if ( (psc != NULL) && (psc->driScreen != NULL) ) {
-        __DRIdrawable * const pdraw = 
-            GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
+        __GLXDRIdrawable *pdraw = 
+            GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
         if (psc->swapControl != NULL && pdraw != NULL) {
-           psc->swapControl->setSwapInterval(pdraw, interval);
+           psc->swapControl->setSwapInterval(pdraw->driDrawable, interval);
            return 0;
         }
       }
@@ -1801,10 +1814,10 @@ static int __glXGetSwapIntervalMESA(void)
                                                            gc->screen );
       
       if ( (psc != NULL) && (psc->driScreen != NULL) ) {
-        __DRIdrawable * const pdraw = 
-            GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
+        __GLXDRIdrawable *pdraw = 
+            GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
         if (psc->swapControl != NULL && pdraw != NULL) {
-           return psc->swapControl->getSwapInterval(pdraw);
+           return psc->swapControl->getSwapInterval(pdraw->driDrawable);
         }
       }
    }
@@ -1823,11 +1836,11 @@ static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
    int   status = GLX_BAD_CONTEXT;
 #ifdef __DRI_FRAME_TRACKING
    int screen;
-   __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
+   __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
 
    if (pdraw != NULL && psc->frameTracking != NULL)
-       status = psc->frameTracking->frameTracking(pdraw, GL_TRUE);
+       status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE);
 #else
    (void) dpy;
    (void) drawable;
@@ -1841,11 +1854,12 @@ static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
    int   status = GLX_BAD_CONTEXT;
 #ifdef __DRI_FRAME_TRACKING
    int screen;
-   __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
-   __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
+   __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
+   __GLXscreenConfigs *psc = GetGLXScreenConfigs(dpy, screen);
 
    if (pdraw != NULL && psc->frameTracking != NULL)
-       status = psc->frameTracking->frameTracking(pdraw, GL_FALSE);
+       status = psc->frameTracking->frameTracking(pdraw->driDrawable,
+                                                 GL_FALSE);
 #else
    (void) dpy;
    (void) drawable;
@@ -1860,14 +1874,15 @@ static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable,
    int   status = GLX_BAD_CONTEXT;
 #ifdef __DRI_FRAME_TRACKING
    int screen;
-   __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
+   __GLXDRIdrawable * const pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
 
    if (pdraw != NULL && psc->frameTracking != NULL) {
        int64_t sbc, missedFrames;
        float   lastMissedUsage;
 
-       status = psc->frameTracking->queryFrameTracking(pdraw, &sbc,
+       status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable,
+                                                      &sbc,
                                                       &missedFrames,
                                                       &lastMissedUsage,
                                                       usage);
@@ -1888,13 +1903,14 @@ static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable,
    int   status = GLX_BAD_CONTEXT;
 #ifdef __DRI_FRAME_TRACKING
    int screen;
-   __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
+   __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
 
    if (pdraw != NULL && psc->frameTracking != NULL) {
       float   usage;
 
-      status = psc->frameTracking->queryFrameTracking(pdraw, sbc, missedFrames,
+      status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable,
+                                                     sbc, missedFrames,
                                                      lastMissedUsage, &usage);
    }
 #else
@@ -1925,12 +1941,13 @@ static int __glXGetVideoSyncSGI(unsigned int *count)
       __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
                                                            gc->screen );
       if ( psc->msc && psc->driScreen ) {
-          __DRIdrawable * const pdraw = 
-              GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
+          __GLXDRIdrawable *pdraw = 
+              GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
          int64_t temp; 
          int ret;
  
-         ret = (*psc->msc->getDrawableMSC)(&psc->__driScreen, pdraw, &temp);
+         ret = (*psc->msc->getDrawableMSC)(psc->__driScreen,
+                                           pdraw->driDrawable, &temp);
          *count = (unsigned) temp;
 
          return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
@@ -1954,14 +1971,14 @@ static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count
       __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
                                                            gc->screen );
       if (psc->msc != NULL && psc->driScreen ) {
-        __DRIdrawable * const pdraw = 
-            GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
+        __GLXDRIdrawable *pdraw = 
+            GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
         int       ret;
         int64_t   msc;
         int64_t   sbc;
 
-        ret = (*psc->msc->waitForMSC)(pdraw, 0, divisor, remainder, &msc,
-                                      &sbc);
+        ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0,
+                                      divisor, remainder, &msc, &sbc);
         *count = (unsigned) msc;
         return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
       }
@@ -2120,13 +2137,13 @@ static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
 
     if ( priv != NULL ) {
        int   i;
-       __DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i );
+       __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i);
        __GLXscreenConfigs * const psc = &priv->screenConfigs[i];
 
        assert( (pdraw == NULL) || (i != -1) );
        return ( (pdraw && psc->sbc && psc->msc)
-                && ((*psc->msc->getMSC)(&psc->driScreen, msc) == 0)
-                && ((*psc->sbc->getSBC)(pdraw, sbc) == 0)
+                && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0)
+                && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0)
                 && (__glXGetUST(ust) == 0) );
     }
 #else
@@ -2141,16 +2158,16 @@ static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
 
 #ifdef GLX_DIRECT_RENDERING
 _X_HIDDEN GLboolean
-__driGetMscRateOML(__DRIdrawable *draw, int32_t *numerator, int32_t *denominator)
+__driGetMscRateOML(__DRIdrawable *draw,
+                  int32_t *numerator, int32_t *denominator, void *private)
 {
 #ifdef XF86VIDMODE
     __GLXscreenConfigs *psc;
     XF86VidModeModeLine   mode_line;
     int   dot_clock;
     int   i;
-    __GLXDRIdrawable *glxDraw;
+    __GLXDRIdrawable *glxDraw = private;
 
-    glxDraw = containerOf(draw, __GLXDRIdrawable, driDrawable);
     psc = glxDraw->psc;
     if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
        XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) {
@@ -2223,12 +2240,12 @@ _X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
                                       int32_t * denominator)
 {
 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
-    __DRIdrawable *driDraw = GetDRIDrawable(dpy, drawable, NULL);
+    __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL);
 
-    if (driDraw == NULL)
+    if (draw == NULL)
        return False;
 
-    return __driGetMscRateOML(driDraw, numerator, denominator);
+    return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw);
 #else
    (void) dpy;
    (void) drawable;
@@ -2245,7 +2262,7 @@ static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
 {
 #ifdef __DRI_SWAP_BUFFER_COUNTER
    int screen;
-   __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
+   __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
 
    /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
@@ -2259,7 +2276,7 @@ static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
       return -1;
 
    if (pdraw != NULL && psc->counters != NULL)
-      return (*psc->sbc->swapBuffersMSC)(pdraw, target_msc,
+      return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc,
                                         divisor, remainder);
 
 #else
@@ -2280,7 +2297,7 @@ static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
 {
 #ifdef __DRI_MEDIA_STREAM_COUNTER
    int screen;
-   __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
+   __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
    int  ret;
 
@@ -2293,7 +2310,7 @@ static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
       return False;
 
    if (pdraw != NULL && psc->msc != NULL) {
-      ret = (*psc->msc->waitForMSC)(pdraw, target_msc,
+      ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, target_msc,
                                    divisor, remainder, msc, sbc);
 
       /* __glXGetUST returns zero on success and non-zero on failure.
@@ -2321,7 +2338,7 @@ static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
 {
 #ifdef __DRI_SWAP_BUFFER_COUNTER
    int screen;
-   __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
+   __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
    int  ret;
 
@@ -2332,7 +2349,7 @@ static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
       return False;
 
    if (pdraw != NULL && psc->sbc != NULL) {
-      ret = (*psc->sbc->waitForSBC)(pdraw, target_sbc, msc, sbc);
+      ret = (*psc->sbc->waitForSBC)(pdraw->driDrawable, target_sbc, msc, sbc);
 
       /* __glXGetUST returns zero on success and non-zero on failure.
        * This function returns True on success and False on failure.
@@ -2364,9 +2381,8 @@ PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn,
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
 
    if (psc && psc->allocate)
-       return (*psc->allocate->allocateMemory)( &psc->__driScreen, size,
-                                               readFreq, writeFreq,
-                                               priority );
+       return (*psc->allocate->allocateMemory)(psc->__driScreen, size,
+                                              readFreq, writeFreq, priority);
 
 #else
    (void) dpy;
@@ -2387,7 +2403,7 @@ PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
 
    if (psc && psc->allocate)
-        (*psc->allocate->freeMemory)( &psc->__driScreen, pointer );
+        (*psc->allocate->freeMemory)(psc->__driScreen, pointer);
 
 #else
    (void) dpy;
@@ -2404,7 +2420,7 @@ PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
 
    if (psc && psc->allocate)
-       return (*psc->allocate->memoryOffset)( &psc->__driScreen, pointer );
+       return (*psc->allocate->memoryOffset)(psc->__driScreen, pointer);
 
 #else
    (void) dpy;
@@ -2480,11 +2496,12 @@ static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
 
 #ifdef __DRI_COPY_SUB_BUFFER
     int screen;
-    __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
+    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
     if ( pdraw != NULL ) {
        __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
        if (psc->copySubBuffer != NULL) {
-           (*psc->copySubBuffer->copySubBuffer)(pdraw, x, y, width, height);
+           (*psc->copySubBuffer->copySubBuffer)(pdraw->driDrawable,
+                                                x, y, width, height);
        }
 
        return;
@@ -2560,8 +2577,16 @@ static void __glXBindTexImageEXT(Display *dpy,
     }
  
 #ifdef GLX_DIRECT_RENDERING
-    if (gc->driContext)
+    if (gc->driContext) {
+       __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
+
+       if (pdraw != NULL)
+           (*pdraw->psc->texBuffer->setTexBuffer)(gc->__driContext,
+                                                  pdraw->textureTarget,
+                                                  pdraw->driDrawable);
+
        return;
+    }
 #endif
 
     opcode = __glXSetupForCommand(dpy);