init secondary color to (0,0,0,1). remove some redundant initializations.
[mesa.git] / src / mesa / main / texstore.c
index f4b864cfb3eebfb84c030bf8014690beb41f59f0..97040487f646ff0a9b7bbb9204c3040335b7fb8e 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  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"),
@@ -480,6 +480,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
           baseInternalFormat == GL_ALPHA ||
           baseInternalFormat == GL_RGB ||
           baseInternalFormat == GL_RGBA ||
+          baseInternalFormat == GL_YCBCR_MESA ||
           baseInternalFormat == GL_COLOR_INDEX ||
           baseInternalFormat == GL_DEPTH_COMPONENT);
 
@@ -626,6 +627,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
                                          srcPacking, srcAddr,
                                          dstAddr);
          assert(b);
+         (void) b;
       }
       else if (dimensions == 2) {
          GLboolean b;
@@ -637,6 +639,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
                                          srcPacking, srcAddr,
                                          dstAddr);
          assert(b);
+         (void) b;
       }
       else {
          GLboolean b;
@@ -647,6 +650,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
                                       srcFormat, srcType,
                                       srcPacking, srcAddr, dstAddr);
          assert(b);
+         (void) b;
       }
    }
    else {
@@ -766,7 +770,8 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
    texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
                                           internalFormat, format, type);
    assert(texImage->TexFormat);
-   texImage->FetchTexel = texImage->TexFormat->FetchTexel1D;
+   texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D;
+   texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df;
 
    texelBytes = texImage->TexFormat->TexelBytes;
 
@@ -842,7 +847,8 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
    texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
                                           internalFormat, format, type);
    assert(texImage->TexFormat);
-   texImage->FetchTexel = texImage->TexFormat->FetchTexel2D;
+   texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D;
+   texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df;
 
    texelBytes = texImage->TexFormat->TexelBytes;
 
@@ -913,7 +919,8 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
    texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
                                           internalFormat, format, type);
    assert(texImage->TexFormat);
-   texImage->FetchTexel = texImage->TexFormat->FetchTexel3D;
+   texImage->FetchTexelc = texImage->TexFormat->FetchTexel3D;
+   texImage->FetchTexelf = texImage->TexFormat->FetchTexel3Df;
 
    texelBytes = texImage->TexFormat->TexelBytes;
 
@@ -1151,7 +1158,8 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
    texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
                                           internalFormat, 0, 0);
    assert(texImage->TexFormat);
-   texImage->FetchTexel = texImage->TexFormat->FetchTexel2D;
+   texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D;
+   texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df;
 
    /* allocate storage */
    texImage->Data = MESA_PBUFFER_ALLOC(imageSize);
@@ -1276,7 +1284,9 @@ do_row(const struct gl_texture_format *format, GLint srcWidth,
    const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1;
    const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2;
 
+   /* This assertion is no longer valid with non-power-of-2 textures
    assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
+   */
 
    switch (format->MesaFormat) {
    case MESA_FORMAT_RGBA:
@@ -1415,9 +1425,9 @@ do_row(const struct gl_texture_format *format, GLint srcWidth,
             const GLint rowAb1 = (rowA[k] >> 11) & 0x1f;
             const GLint rowBb0 = (rowB[j] >> 11) & 0x1f;
             const GLint rowBb1 = (rowB[k] >> 11) & 0x1f;
-            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4;
-            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4;
-            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4;
+            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
             dst[i] = (blue << 11) | (green << 5) | red;
          }
       }
@@ -1446,10 +1456,10 @@ do_row(const struct gl_texture_format *format, GLint srcWidth,
             const GLint rowAa1 = (rowA[k] >> 12) & 0xf;
             const GLint rowBa0 = (rowB[j] >> 12) & 0xf;
             const GLint rowBa1 = (rowB[k] >> 12) & 0xf;
-            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4;
-            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4;
-            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4;
-            const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 4;
+            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+            const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
             dst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red;
          }
       }
@@ -1478,10 +1488,10 @@ do_row(const struct gl_texture_format *format, GLint srcWidth,
             const GLint rowAa1 = (rowA[k] >> 15) & 0x1;
             const GLint rowBa0 = (rowB[j] >> 15) & 0x1;
             const GLint rowBa1 = (rowB[k] >> 15) & 0x1;
-            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4;
-            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4;
-            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4;
-            const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 4;
+            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+            const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
             dst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red;
          }
       }
@@ -1521,9 +1531,9 @@ do_row(const struct gl_texture_format *format, GLint srcWidth,
             const GLint rowAb1 = (rowA[k] >> 5) & 0x7;
             const GLint rowBb0 = (rowB[j] >> 5) & 0x7;
             const GLint rowBb1 = (rowB[k] >> 5) & 0x7;
-            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4;
-            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4;
-            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4;
+            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
             dst[i] = (blue << 5) | (green << 2) | red;
          }
       }
@@ -1864,7 +1874,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
    GLint level, maxLevels;
 
    ASSERT(texObj);
-   srcImage = texObj->Image[texObj->BaseLevel];
+   srcImage = texObj->Image[0][texObj->BaseLevel];
    ASSERT(srcImage);
 
    maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
@@ -1913,7 +1923,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
       for (row = 0; row < srcImage->Height; row++) {
          GLuint col;
          for (col = 0; col < srcImage->Width; col++) {
-            (*srcImage->FetchTexel)(srcImage, col, row, 0, (GLvoid *) dst);
+            srcImage->FetchTexelc(srcImage, col, row, 0, dst);
             dst += components;
          }
       }
@@ -1987,9 +1997,11 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
                                  dstDepth, border, srcImage->IntFormat);
       dstImage->DriverData = NULL;
       dstImage->TexFormat = srcImage->TexFormat;
-      dstImage->FetchTexel = srcImage->FetchTexel;
+      dstImage->FetchTexelc = srcImage->FetchTexelc;
+      dstImage->FetchTexelf = srcImage->FetchTexelf;
       ASSERT(dstImage->TexFormat);
-      ASSERT(dstImage->FetchTexel);
+      ASSERT(dstImage->FetchTexelc);
+      ASSERT(dstImage->FetchTexelf);
 
       /* Alloc new teximage data buffer.
        * Setup src and dest data pointers.