Minor tweaks to help out at a driver level.
[mesa.git] / src / mesa / main / texstore.c
index d144d8095f22a053baa7dbe46d8211eb5e2befd6..899201e6c4ab80c278cab04401b8f969be63ae3e 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: texstore.c,v 1.46 2002/10/28 23:01:24 kschultz Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  5.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  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"),
@@ -159,7 +157,7 @@ components_in_intformat( GLint format )
  * apply pixel transfer ops into a temporary image buffer.  Then,
  * convert the temporary image into the special hardware format.
  *
- * Input:
+ * \param
  *   dimensions - 1, 2, or 3
  *   texDestFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA,
  *                   GL_RGB or GL_RGBA (the destination format)
@@ -193,11 +191,13 @@ transfer_teximage(GLcontext *ctx, GLuint dimensions,
           texDestFormat == GL_LUMINANCE_ALPHA ||
           texDestFormat == GL_ALPHA ||
           texDestFormat == GL_RGB ||
-          texDestFormat == GL_RGBA);
+          texDestFormat == GL_RGBA ||
+          texDestFormat == GL_COLOR_INDEX ||
+          texDestFormat == GL_DEPTH_COMPONENT);
    ASSERT(texDestAddr);
-   ASSERT(srcWidth >= 1);
-   ASSERT(srcHeight >= 1);
-   ASSERT(srcDepth >= 1);
+   ASSERT(srcWidth >= 0);
+   ASSERT(srcHeight >= 0);
+   ASSERT(srcDepth >= 0);
    ASSERT(dstXoffset >= 0);
    ASSERT(dstYoffset >= 0);
    ASSERT(dstZoffset >= 0);
@@ -295,7 +295,6 @@ transfer_teximage(GLcontext *ctx, GLuint dimensions,
                      + dstYoffset * (dstRowStride / sizeof(GLushort))
                      + dstXoffset * texComponents;
       ASSERT(ctx->Extensions.MESA_ycbcr_texture);
-      printf("copy ycbcr\n");
       for (img = 0; img < srcDepth; img++) {
          GLushort *destRow = dest;
          for (row = 0; row < srcHeight; row++) {
@@ -436,7 +435,7 @@ transfer_teximage(GLcontext *ctx, GLuint dimensions,
  * Transfer a texture image from user space to <destAddr> applying all
  * needed image transfer operations and storing the result in the format
  * specified by <dstFormat>.  <dstFormat> may be any format from texformat.h.
- * Input:
+ * \param
  *   dimensions - 1, 2 or 3
  *   baseInternalFormat - base format of the internal texture format
  *       specified by the user.  This is very important, see below.
@@ -446,7 +445,7 @@ transfer_teximage(GLcontext *ctx, GLuint dimensions,
  *   dstX/Y/Zoffset - as specified by glTexSubImage
  *   dstRowStride - stride between dest rows in bytes
  *   dstImageStride - stride between dest images in bytes
- *   srcFormat, srcType - incoming image format and datatype
+ *   srcFormat, srcType - incoming image format and data type
  *   srcAddr - source image address
  *   srcPacking - packing params of source image
  *
@@ -480,7 +479,10 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
           baseInternalFormat == GL_LUMINANCE_ALPHA ||
           baseInternalFormat == GL_ALPHA ||
           baseInternalFormat == GL_RGB ||
-          baseInternalFormat == GL_RGBA);
+          baseInternalFormat == GL_RGBA ||
+          baseInternalFormat == GL_YCBCR_MESA ||
+          baseInternalFormat == GL_COLOR_INDEX ||
+          baseInternalFormat == GL_DEPTH_COMPONENT);
 
    if (transferOps & IMAGE_CONVOLUTION_BIT) {
       _mesa_adjust_image_for_convolution(ctx, dimensions, &postConvWidth,
@@ -625,6 +627,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
                                          srcPacking, srcAddr,
                                          dstAddr);
          assert(b);
+         (void) b;
       }
       else if (dimensions == 2) {
          GLboolean b;
@@ -636,6 +639,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
                                          srcPacking, srcAddr,
                                          dstAddr);
          assert(b);
+         (void) b;
       }
       else {
          GLboolean b;
@@ -646,6 +650,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
                                       srcFormat, srcType,
                                       srcPacking, srcAddr, dstAddr);
          assert(b);
+         (void) b;
       }
    }
    else {
@@ -979,7 +984,7 @@ _mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
       GLubyte *dest = _mesa_compressed_image_address(xoffset, 0, 0,
                                                      texImage->IntFormat,
                                                      texImage->Width,
-                                                     texImage->Data);
+                                          (GLubyte*) texImage->Data);
       transfer_compressed_teximage(ctx, 1,             /* dimensions */
                                    width, 1, 1,        /* size to replace */
                                    format, type,       /* source format/type */
@@ -1028,7 +1033,7 @@ _mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level,
       GLubyte *dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
                                                      texImage->IntFormat,
                                                      texImage->Width,
-                                                     texImage->Data);
+                                          (GLubyte*) texImage->Data);
       transfer_compressed_teximage(ctx, 2,             /* dimensions */
                                    width, height, 1,   /* size to replace */
                                    format, type,       /* source format/type */
@@ -1076,7 +1081,7 @@ _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level,
       GLubyte *dest = _mesa_compressed_image_address(xoffset, yoffset, zoffset,
                                                      texImage->IntFormat,
                                                      texImage->Width,
-                                                     texImage->Data);
+                                          (GLubyte*) texImage->Data);
       transfer_compressed_teximage(ctx, 3,              /* dimensions */
                                    width, height, depth,/* size to replace */
                                    format, type,       /* source format/type */
@@ -1091,7 +1096,7 @@ _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level,
                            texImage->Format,
                            texImage->TexFormat, texImage->Data,
                            width, height, depth, /* src size */
-                           xoffset, yoffset, xoffset, /* dest offsets */
+                           xoffset, yoffset, zoffset, /* dest offsets */
                            texImage->Width * texelBytes,  /* dst row stride */
                            texImage->Width * texImage->Height * texelBytes,
                            format, type, pixels, packing);
@@ -1160,7 +1165,7 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
    }
 
    /* copy the data */
-   ASSERT(texImage->CompressedSize == imageSize);
+   ASSERT(texImage->CompressedSize == (GLuint) imageSize);
    MEMCPY(texImage->Data, data, imageSize);
 }
 
@@ -1230,7 +1235,8 @@ _mesa_store_compressed_texsubimage2d(GLcontext *ctx, GLenum target,
                                                texImage->Width);
    dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
                                          texImage->IntFormat,
-                                         texImage->Width, texImage->Data);
+                                         texImage->Width,
+                              (GLubyte*) texImage->Data);
 
    bytesPerRow = srcRowStride;
    rows = height / 4;
@@ -1260,44 +1266,6 @@ _mesa_store_compressed_texsubimage3d(GLcontext *ctx, GLenum target,
 }
 
 
-
-
-
-/*
- * This is the fallback for Driver.TestProxyTexImage().
- */
-GLboolean
-_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
-                          GLint internalFormat, GLenum format, GLenum type,
-                          GLint width, GLint height, GLint depth, GLint border)
-{
-   struct gl_texture_unit *texUnit;
-   struct gl_texture_object *texObj;
-   struct gl_texture_image *texImage;
-
-   (void) format;
-   (void) type;
-
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-   texObj = _mesa_select_tex_object(ctx, texUnit, target);
-   texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
-
-   /* We always pass.
-    * The core Mesa code will have already tested the image size, etc.
-    * If a driver has more stringent texture limits to enforce it will
-    * have to override this function.
-    */
-   /* choose the texture format */
-   assert(ctx->Driver.ChooseTextureFormat);
-   texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
-                                          internalFormat, format, type);
-   assert(texImage->TexFormat);
-
-   return GL_TRUE;
-}
-
-
-
 /*
  * Average together two rows of a source image to produce a single new
  * row in the dest image.  It's legal for the two source rows to point
@@ -1312,7 +1280,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:
@@ -1895,8 +1865,8 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
 {
    const struct gl_texture_image *srcImage;
    const struct gl_texture_format *convertFormat;
-   const GLubyte *srcData;
-   GLubyte *dstData;
+   const GLubyte *srcData = NULL;
+   GLubyte *dstData = NULL;
    GLint level, maxLevels;
 
    ASSERT(texObj);
@@ -1932,12 +1902,12 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
       size = _mesa_bytes_per_pixel(srcImage->Format, CHAN_TYPE)
          * srcImage->Width * srcImage->Height * srcImage->Depth + 20;
       /* 20 extra bytes, just be safe when calling last FetchTexel */
-      srcData = MALLOC(size);
+      srcData = (GLubyte *) MALLOC(size);
       if (!srcData) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
          return;
       }
-      dstData = MALLOC(size / 2);  /* 1/4 would probably be OK */
+      dstData = (GLubyte *) MALLOC(size / 2);  /* 1/4 would probably be OK */
       if (!dstData) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
          FREE((void *) srcData);
@@ -1969,7 +1939,7 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
       GLint border, bytesPerTexel;
 
       /* get src image parameters */
-      srcImage = texObj->Image[level];
+      srcImage = _mesa_select_tex_image(ctx, texUnit, target, level);
       ASSERT(srcImage);
       srcWidth = srcImage->Width;
       srcHeight = srcImage->Height;
@@ -2008,14 +1978,10 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
       }
 
       /* get dest gl_texture_image */
-      dstImage = _mesa_select_tex_image(ctx, texUnit, target, level+1);
+      dstImage = _mesa_get_tex_image(ctx, texUnit, target, level + 1);
       if (!dstImage) {
-         dstImage = _mesa_alloc_texture_image();
-         if (!dstImage) {
-            _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
-            return;
-         }
-         _mesa_set_tex_image(texObj, target, level + 1, dstImage);
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
+         return;
       }
 
       /* Free old image data */
@@ -2101,10 +2067,10 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
          _mesa_compress_teximage(ctx,
                                  dstWidth, dstHeight, /* size */
                                  srcFormat,           /* source format */
-                                 dstData,             /* source buffer */
+                (const GLchan *) dstData,             /* source buffer */
                                  dstWidth,            /* source row stride */
                                  dstImage->TexFormat, /* dest format */
-                                 dstImage->Data,      /* dest buffer */
+                      (GLubyte*) dstImage->Data,      /* dest buffer */
                                  dstRowStride );      /* dest row stride */
 
          /* swap src and dest pointers */