fix some float/ubyte mistakes (Daniel Borca)
[mesa.git] / src / mesa / drivers / glide / fxdd.c
index a5541eceb1dc39510cdf9b277289b81bda3e8f26..fd099e7e1153c25896cb9067a38808b42353b13c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: fxdd.c,v 1.86 2002/06/13 04:28:30 brianp Exp $ */
+/* $Id: fxdd.c,v 1.95 2003/01/08 21:32:36 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -45,6 +45,7 @@
 #include "fxdrv.h"
 #include "enums.h"
 #include "extensions.h"
+#include "mmath.h"
 #include "texstore.h"
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -125,19 +126,23 @@ fxDDBufferSize(GLframebuffer *buffer, GLuint * width, GLuint * height)
 
 /* Implements glClearColor() */
 static void
-fxDDClearColor(GLcontext * ctx, const GLchan color[4])
+fxDDClearColor(GLcontext * ctx, const GLfloat color[4])
 {
    fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
    GLubyte col[4];
 
    if (MESA_VERBOSE & VERBOSE_DRIVER) {
-      fprintf(stderr, "fxmesa: fxDDClearColor(%d,%d,%d,%d)\n",
+      fprintf(stderr, "fxmesa: fxDDClearColor(%f,%f,%f,%f)\n",
              color[0], color[1], color[2], color[3]);
    }
 
-   ASSIGN_4V(col, color[0], color[1], color[2], 255);
+   CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
+   CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
+   CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
+   CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]);
+
    fxMesa->clearC = FXCOLOR4(col);
-   fxMesa->clearA = color[3];
+   fxMesa->clearA = col[3];
 }
 
 
@@ -245,7 +250,7 @@ fxDDClear(GLcontext * ctx, GLbitfield mask, GLboolean all,
       FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
       FX_grColorMask(FXTRUE, ctx->Color.ColorMask[ACOMP]
                     && fxMesa->haveAlphaBuffer);
-      if (ctx->Color.DrawDestMask & FRONT_LEFT_BIT)
+      if (ctx->Color._DrawDestMask & FRONT_LEFT_BIT)
         FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER);
       if (!ctx->Depth.Test || !ctx->Depth.Mask)
         FX_grDepthMask(FXFALSE);
@@ -264,7 +269,7 @@ fxDDClear(GLcontext * ctx, GLbitfield mask, GLboolean all,
 
 /* Set the buffer used for drawing */
 /* XXX support for separate read/draw buffers hasn't been tested */
-static GLboolean
+static void
 fxDDSetDrawBuffer(GLcontext * ctx, GLenum mode)
 {
    fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
@@ -276,20 +281,21 @@ fxDDSetDrawBuffer(GLcontext * ctx, GLenum mode)
    if (mode == GL_FRONT_LEFT) {
       fxMesa->currentFB = GR_BUFFER_FRONTBUFFER;
       FX_grRenderBuffer(fxMesa->currentFB);
-      return GL_TRUE;
    }
    else if (mode == GL_BACK_LEFT) {
       fxMesa->currentFB = GR_BUFFER_BACKBUFFER;
       FX_grRenderBuffer(fxMesa->currentFB);
-      return GL_TRUE;
    }
    else if (mode == GL_NONE) {
       FX_grColorMask(FXFALSE, FXFALSE);
-      return GL_TRUE;
    }
    else {
-      return GL_FALSE;
+      /* we'll need a software fallback */
+      /* XXX not implemented */
    }
+
+   /* update s/w fallback state */
+   _swrast_DrawBuffer(ctx, mode);
 }
 
 
@@ -317,7 +323,9 @@ fxDDDrawBitmap(GLcontext * ctx, GLint px, GLint py,
        ctx->Stencil.Enabled ||
        ctx->Scissor.Enabled ||
        (ctx->DrawBuffer->UseSoftwareAlphaBuffers &&
-       ctx->Color.ColorMask[ACOMP]) || ctx->Color.MultiDrawBuffer) {
+       ctx->Color.ColorMask[ACOMP]) ||
+       (ctx->Color._DrawDestMask != FRONT_LEFT_BIT &&
+        ctx->Color._DrawDestMask != BACK_LEFT_BIT)) {
       _swrast_Bitmap(ctx, px, py, width, height, unpack, bitmap);
       return;
    }
@@ -691,7 +699,7 @@ fxDDInitFxMesaContext(fxMesaContext fxMesa)
 
    fxMesa->unitsState.alphaTestEnabled = GL_FALSE;
    fxMesa->unitsState.alphaTestFunc = GR_CMP_ALWAYS;
-   fxMesa->unitsState.alphaTestRefValue = 0;
+   fxMesa->unitsState.alphaTestRefValue = 0.0;
 
    fxMesa->unitsState.blendEnabled = GL_FALSE;
    fxMesa->unitsState.blendSrcFuncRGB = GR_BLEND_ONE;
@@ -714,7 +722,7 @@ fxDDInitFxMesaContext(fxMesaContext fxMesa)
    }
 
    fxMesa->state = malloc(FX_grGetInteger(FX_GLIDE_STATE_SIZE));
-   fxMesa->fogTable = malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES) *
+   fxMesa->fogTable = (GrFog_t *) malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES) *
                             sizeof(GrFog_t));
 
    if (!fxMesa->state || !fxMesa->fogTable) {
@@ -826,7 +834,8 @@ fx_check_IsInHardware(GLcontext * ctx)
       return GL_FALSE;
 
    if (ctx->Stencil.Enabled ||
-       ctx->Color.MultiDrawBuffer ||
+       (ctx->Color._DrawDestMask != FRONT_LEFT_BIT &&
+        ctx->Color._DrawDestMask != BACK_LEFT_BIT) ||
        ((ctx->Color.BlendEnabled)
        && (ctx->Color.BlendEquation != GL_FUNC_ADD_EXT))
        || ((ctx->Color.ColorLogicOpEnabled)
@@ -843,14 +852,15 @@ fx_check_IsInHardware(GLcontext * ctx)
    /* Unsupported texture/multitexture cases */
 
    if (fxMesa->haveTwoTMUs) {
-      if (ctx->Texture._ReallyEnabled & (TEXTURE0_3D | TEXTURE1_3D))
-        return GL_FALSE;       /* can't do 3D textures */
-      if (ctx->Texture._ReallyEnabled & (TEXTURE0_1D | TEXTURE1_1D))
-        return GL_FALSE;       /* can't do 1D textures */
+      /* we can only do 2D textures */
+      if (ctx->Texture.Unit[0]._ReallyEnabled & ~TEXTURE_2D_BIT)
+        return GL_FALSE;
+      if (ctx->Texture.Unit[1]._ReallyEnabled & ~TEXTURE_2D_BIT)
+        return GL_FALSE;
 
-      if (ctx->Texture._ReallyEnabled & TEXTURE0_2D) {
+      if (ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_2D_BIT) {
         if (ctx->Texture.Unit[0].EnvMode == GL_BLEND &&
-            (ctx->Texture._ReallyEnabled & TEXTURE1_2D ||
+            (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_2D_BIT ||
              ctx->Texture.Unit[0].EnvColor[0] != 0 ||
              ctx->Texture.Unit[0].EnvColor[1] != 0 ||
              ctx->Texture.Unit[0].EnvColor[2] != 0 ||
@@ -861,7 +871,7 @@ fx_check_IsInHardware(GLcontext * ctx)
            return GL_FALSE;
       }
 
-      if (ctx->Texture._ReallyEnabled & TEXTURE1_2D) {
+      if (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_2D_BIT) {
         if (ctx->Texture.Unit[1].EnvMode == GL_BLEND)
            return GL_FALSE;
         if (ctx->Texture.Unit[1]._Current->Image[0]->Border > 0)
@@ -875,9 +885,10 @@ fx_check_IsInHardware(GLcontext * ctx)
 
       /* KW: This was wrong (I think) and I changed it... which doesn't mean
        * it is now correct...
+       * BP: The old condition just seemed to test if both texture units
+       * were enabled.  That's easy!
        */
-      if ((ctx->Texture._ReallyEnabled & (TEXTURE0_1D | TEXTURE0_2D | TEXTURE0_3D)) &&
-         (ctx->Texture._ReallyEnabled & (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D))) {
+      if (ctx->Texture._EnabledUnits == 0x3) {
         /* Can't use multipass to blend a multitextured triangle - fall
          * back to software.
          */
@@ -895,16 +906,12 @@ fx_check_IsInHardware(GLcontext * ctx)
       }
    }
    else {
-      if ((ctx->Texture._ReallyEnabled & (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D)) ||
-         /* Not very well written ... */
-         ((ctx->Texture._ReallyEnabled & TEXTURE0_1D) &&
-           (!(ctx->Texture._ReallyEnabled & TEXTURE0_2D)))
-        ) {
+      /* we have just one texture unit */
+      if (ctx->Texture._EnabledUnits > 0x1) {
         return GL_FALSE;
       }
 
-
-      if ((ctx->Texture._ReallyEnabled & TEXTURE0_2D) &&
+      if ((ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_2D_BIT) &&
          (ctx->Texture.Unit[0].EnvMode == GL_BLEND)) {
         return GL_FALSE;
       }
@@ -995,7 +1002,7 @@ fxSetupDDPointers(GLcontext * ctx)
    ctx->Driver.ClearIndex = NULL;
    ctx->Driver.ClearColor = fxDDClearColor;
    ctx->Driver.Clear = fxDDClear;
-   ctx->Driver.SetDrawBuffer = fxDDSetDrawBuffer;
+   ctx->Driver.DrawBuffer = fxDDSetDrawBuffer;
    ctx->Driver.GetBufferSize = fxDDBufferSize;
    ctx->Driver.Accum = _swrast_Accum;
    ctx->Driver.Bitmap = fxDDDrawBitmap;
@@ -1012,6 +1019,12 @@ fxSetupDDPointers(GLcontext * ctx)
    ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
    ctx->Driver.TexSubImage2D = fxDDTexSubImage2D;
    ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
+   ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
+   ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
+   ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
+   ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
+   ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
+   ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
    ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
    ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
    ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;