Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_render.c
index 3ce91b9257b78c27b8e0325aee4ecfc21f3e4fa5..979bcd4514091c76a00de00d7242242bd10f11c5 100644 (file)
@@ -23,7 +23,6 @@
  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.c,v 1.4 2002/02/22 21:45:03 dawes Exp $ */
 
 /*
  * New fixes:
 
 /* Clear the color and/or depth buffers.
  */
-static void tdfxClear( GLcontext *ctx,
-                        GLbitfield mask, GLboolean all,
-                        GLint x, GLint y, GLint width, GLint height )
+static void tdfxClear( GLcontext *ctx, GLbitfield mask )
 {
    tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
-   GLbitfield softwareMask = mask & (DD_ACCUM_BIT);
+   GLbitfield softwareMask = mask & (BUFFER_BIT_ACCUM);
    const GLuint stencil_size =
       fxMesa->haveHwStencil ? fxMesa->glCtx->Visual.stencilBits : 0;
 
    if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) {
-      fprintf( stderr, "%s( %d, %d, %d, %d )\n",
-              __FUNCTION__, (int) x, (int) y, (int) width, (int) height );
+      fprintf( stderr, "tdfxClear(0x%x)\n", mask);
    }
 
    /* Need this check to respond to glScissor and clipping updates */
@@ -67,23 +63,23 @@ static void tdfxClear( GLcontext *ctx,
    }
 
    /* we can't clear accum buffers */
-   mask &= ~(DD_ACCUM_BIT);
+   mask &= ~(BUFFER_BIT_ACCUM);
 
-   if (mask & DD_STENCIL_BIT) {
-      if (!fxMesa->haveHwStencil || ctx->Stencil.WriteMask[0] != 0xff) {
+   if (mask & BUFFER_BIT_STENCIL) {
+      if (!fxMesa->haveHwStencil || (ctx->Stencil.WriteMask[0] & 0xff) != 0xff) {
          /* Napalm seems to have trouble with stencil write masks != 0xff */
          /* do stencil clear in software */
-         mask &= ~(DD_STENCIL_BIT);
-         softwareMask |= DD_STENCIL_BIT;
+         mask &= ~(BUFFER_BIT_STENCIL);
+         softwareMask |= BUFFER_BIT_STENCIL;
       }
    }
 
    if (fxMesa->glCtx->Visual.redBits != 8) {
       /* can only do color masking if running in 24/32bpp on Napalm */
-      if (ctx->Color.ColorMask[RCOMP] != ctx->Color.ColorMask[GCOMP] ||
-          ctx->Color.ColorMask[GCOMP] != ctx->Color.ColorMask[BCOMP]) {
-         softwareMask |= (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
-         mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
+      if (ctx->Color.ColorMask[0][RCOMP] != ctx->Color.ColorMask[0][GCOMP] ||
+          ctx->Color.ColorMask[0][GCOMP] != ctx->Color.ColorMask[0][BCOMP]) {
+         softwareMask |= (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT));
+         mask &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT);
       }
    }
 
@@ -94,11 +90,11 @@ static void tdfxClear( GLcontext *ctx,
        * in the OGL state.
        */
       LOCK_HARDWARE(fxMesa);
-      if (mask & DD_STENCIL_BIT) {
+      if (mask & BUFFER_BIT_STENCIL) {
         fxMesa->Glide.grStencilMask(/*ctx->Stencil.WriteMask*/ 0xff);
         /* set stencil ref value = desired clear value */
         fxMesa->Glide.grStencilFunc(GR_CMP_ALWAYS,
-                                     fxMesa->Stencil.Clear, 0xff);
+                                     (fxMesa->Stencil.Clear & 0xff), 0xff);
         fxMesa->Glide.grStencilOp(GR_STENCILOP_REPLACE,
                                    GR_STENCILOP_REPLACE, GR_STENCILOP_REPLACE);
         fxMesa->Glide.grEnable(GR_STENCIL_MODE_EXT);
@@ -119,8 +115,8 @@ static void tdfxClear( GLcontext *ctx,
        * This could probably be done fancier but doing each possible case
        * explicitly is less error prone.
        */
-      switch (mask & ~DD_STENCIL_BIT) {
-      case DD_BACK_LEFT_BIT | DD_DEPTH_BIT:
+      switch (mask & ~BUFFER_BIT_STENCIL) {
+      case BUFFER_BIT_BACK_LEFT | BUFFER_BIT_DEPTH:
         /* back buffer & depth */
         FX_grColorMaskv_NoLock(ctx, true4); /* work around Voodoo3 bug */
         fxMesa->Glide.grDepthMask(FXTRUE);
@@ -129,7 +125,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
          }
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
@@ -139,7 +135,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grDepthMask(FXFALSE);
         }
         break;
-      case DD_FRONT_LEFT_BIT | DD_DEPTH_BIT:
+      case BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_DEPTH:
         /* XXX it appears that the depth buffer isn't cleared when
          * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
          * This is a work-around/
@@ -152,11 +148,11 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
-                                        fxMesa->Depth.Clear);
+                                        fxMesa->Depth.Clear & 0xff);
         /* clear front */
         FX_grColorMaskv_NoLock(ctx, true4);
         fxMesa->Glide.grRenderBuffer(GR_BUFFER_FRONTBUFFER);
@@ -164,7 +160,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -173,7 +169,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grDepthMask(FXFALSE);
         }
         break;
-      case DD_BACK_LEFT_BIT:
+      case BUFFER_BIT_BACK_LEFT:
         /* back buffer only */
         fxMesa->Glide.grDepthMask(FXFALSE);
         fxMesa->Glide.grRenderBuffer(GR_BUFFER_BACKBUFFER);
@@ -181,7 +177,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -190,7 +186,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grDepthMask(FXTRUE);
         }
         break;
-      case DD_FRONT_LEFT_BIT:
+      case BUFFER_BIT_FRONT_LEFT:
         /* front buffer only */
         fxMesa->Glide.grDepthMask(FXFALSE);
         fxMesa->Glide.grRenderBuffer(GR_BUFFER_FRONTBUFFER);
@@ -198,7 +194,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -207,7 +203,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grDepthMask(FXTRUE);
         }
         break;
-      case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT:
+      case BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT:
         /* front and back */
         fxMesa->Glide.grDepthMask(FXFALSE);
         fxMesa->Glide.grRenderBuffer(GR_BUFFER_BACKBUFFER);
@@ -215,7 +211,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -225,7 +221,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -234,7 +230,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grDepthMask(FXTRUE);
         }
         break;
-      case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT:
+      case BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT | BUFFER_BIT_DEPTH:
         /* clear front */
         fxMesa->Glide.grDepthMask(FXFALSE);
         fxMesa->Glide.grRenderBuffer(GR_BUFFER_FRONTBUFFER);
@@ -242,7 +238,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -254,7 +250,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
@@ -263,7 +259,7 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grDepthMask(FXFALSE);
         }
         break;
-      case DD_DEPTH_BIT:
+      case BUFFER_BIT_DEPTH:
         /* just the depth buffer */
         fxMesa->Glide.grRenderBuffer(GR_BUFFER_BACKBUFFER);
         FX_grColorMaskv_NoLock(ctx, false4);
@@ -272,20 +268,20 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
         else
             fxMesa->Glide.grBufferClear(fxMesa->Color.ClearColor,
                                         fxMesa->Color.ClearAlpha,
                                         fxMesa->Depth.Clear);
         FX_grColorMaskv_NoLock(ctx, true4);
-        if (ctx->Color._DrawDestMask[0] & DD_FRONT_LEFT_BIT)
+        if (ctx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT)
             fxMesa->Glide.grRenderBuffer(GR_BUFFER_FRONTBUFFER);
         if (!ctx->Depth.Test || !ctx->Depth.Mask)
            fxMesa->Glide.grDepthMask(FXFALSE);
         break;
       default:
          /* clear no color buffers or depth buffer but might clear stencil */
-        if (stencil_size > 0 && (mask & DD_STENCIL_BIT)) {
+        if (stencil_size > 0 && (mask & BUFFER_BIT_STENCIL)) {
             /* XXX need this RenderBuffer call to work around Glide bug */
             fxMesa->Glide.grRenderBuffer(GR_BUFFER_BACKBUFFER);
             fxMesa->Glide.grDepthMask(FXFALSE);
@@ -293,19 +289,19 @@ static void tdfxClear( GLcontext *ctx,
             fxMesa->Glide.grBufferClearExt(fxMesa->Color.ClearColor,
                                            fxMesa->Color.ClearAlpha,
                                            fxMesa->Depth.Clear,
-                                           (FxU32) ctx->Stencil.Clear);
+                                           (FxU32) (ctx->Stencil.Clear & 0xff));
             if (ctx->Depth.Mask && ctx->Depth.Test) {
                fxMesa->Glide.grDepthMask(FXTRUE);
             }
             FX_grColorMaskv_NoLock(ctx, true4);
-            if (ctx->Color._DrawDestMask[0] & DD_FRONT_LEFT_BIT)
+            if (ctx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT)
                fxMesa->Glide.grRenderBuffer(GR_BUFFER_FRONTBUFFER);
          }
       }
    }
    END_CLIP_LOOP(fxMesa);
 
-   if (fxMesa->haveHwStencil && (mask & DD_STENCIL_BIT)) {
+   if (fxMesa->haveHwStencil && (mask & BUFFER_BIT_STENCIL)) {
       /* We changed the stencil state above.  Signal that we need to
        * upload it again.
        */
@@ -313,7 +309,7 @@ static void tdfxClear( GLcontext *ctx,
    }
 
    if (softwareMask)
-      _swrast_Clear( ctx, softwareMask, all, x, y, width, height );
+      _swrast_Clear(ctx, softwareMask);
 }
 
 
@@ -560,7 +556,7 @@ static void uploadTextureImages( tdfxContextPtr fxMesa )
  */
 void tdfxUploadClipping( tdfxContextPtr fxMesa )
 {
-   __DRIdrawablePrivate *dPriv = fxMesa->driDrawable;
+   __DRIdrawable *dPriv = fxMesa->driDrawable;
 
    assert(dPriv);
 
@@ -725,7 +721,7 @@ void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa )
         fxMesa->Glide.grColorMask( fxMesa->Color.ColorMask[RCOMP] ||
                                     fxMesa->Color.ColorMask[GCOMP] ||
                                     fxMesa->Color.ColorMask[BCOMP],
-                                    /*fxMesa->Color.ColorMask[ACOMP]*/GL_FALSE/*[dBorca] no-no*/ );
+                                    /*fxMesa->Color.ColorMask[0][ACOMP]*/GL_FALSE/*[dBorca] no-no*/ );
       }
       fxMesa->dirty &= ~TDFX_UPLOAD_COLOR_MASK;
    }
@@ -744,7 +740,7 @@ void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa )
    }
 
    if ( fxMesa->dirty & TDFX_UPLOAD_STENCIL ) {
-      if (fxMesa->glCtx->Stencil.Enabled) {
+      if (fxMesa->glCtx->Stencil._Enabled) {
          fxMesa->Glide.grEnable(GR_STENCIL_MODE_EXT);
          fxMesa->Glide.grStencilOp(fxMesa->Stencil.FailFunc,
                                    fxMesa->Stencil.ZFailFunc,