mesa: add glTextureParameteri/iv/f/fvEXT
[mesa.git] / src / mesa / main / texstore.c
index b54e03337493a990c909a0975d60dd77808d6e07..2913d4bc06718b7128be93e82d503b8ba7fe8917 100644 (file)
@@ -51,6 +51,7 @@
  */
 
 
+#include "errors.h"
 #include "glheader.h"
 #include "bufferobj.h"
 #include "format_pack.h"
 #include "enums.h"
 #include "glformats.h"
 #include "pixeltransfer.h"
-#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
-#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+#include "util/format_rgb9e5.h"
+#include "util/format_r11g11b10f.h"
 
 
 enum {
-   ZERO = 4, 
+   ZERO = 4,
    ONE = 5
 };
 
@@ -430,47 +431,47 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS)
    for (img = 0; img < srcDepth; img++) {
       GLuint *dstRow = (GLuint *) dstSlices[img];
       const GLubyte *src
-        = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
-                                               srcWidth, srcHeight,
-                                               srcFormat, srcType,
-                                               img, 0, 0);
+         = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
+                                                srcWidth, srcHeight,
+                                                srcFormat, srcType,
+                                                img, 0, 0);
       for (row = 0; row < srcHeight; row++) {
-        GLint i;
-        GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
-        
-        if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
-           keepstencil = GL_TRUE;
-        }
+         GLint i;
+         GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
+
+         if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
+            keepstencil = GL_TRUE;
+         }
          else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
-           keepdepth = GL_TRUE;
-        }
-
-        if (keepdepth == GL_FALSE)
-           /* the 24 depth bits will be in the low position: */
-           _mesa_unpack_depth_span(ctx, srcWidth,
-                                   GL_UNSIGNED_INT, /* dst type */
-                                   keepstencil ? depth : dstRow, /* dst addr */
-                                   depthScale,
-                                   srcType, src, srcPacking);   
-
-        if (keepstencil == GL_FALSE)
-           /* get the 8-bit stencil values */
-           _mesa_unpack_stencil_span(ctx, srcWidth,
-                                     GL_UNSIGNED_BYTE, /* dst type */
-                                     stencil, /* dst addr */
-                                     srcType, src, srcPacking,
-                                     ctx->_ImageTransferState);
-
-        /* merge stencil values into depth values */
-        for (i = 0; i < srcWidth; i++) {
-           if (keepstencil)
-              dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
-           else
-              dstRow[i] = (dstRow[i] & 0xFFFFFF) | (stencil[i] << 24);
-
-        }
-        src += srcRowStride;
-        dstRow += dstRowStride / sizeof(GLuint);
+            keepdepth = GL_TRUE;
+         }
+
+         if (keepdepth == GL_FALSE)
+            /* the 24 depth bits will be in the low position: */
+            _mesa_unpack_depth_span(ctx, srcWidth,
+                                    GL_UNSIGNED_INT, /* dst type */
+                                    keepstencil ? depth : dstRow, /* dst addr */
+                                    depthScale,
+                                    srcType, src, srcPacking);
+
+         if (keepstencil == GL_FALSE)
+            /* get the 8-bit stencil values */
+            _mesa_unpack_stencil_span(ctx, srcWidth,
+                                      GL_UNSIGNED_BYTE, /* dst type */
+                                      stencil, /* dst addr */
+                                      srcType, src, srcPacking,
+                                      ctx->_ImageTransferState);
+
+         /* merge stencil values into depth values */
+         for (i = 0; i < srcWidth; i++) {
+            if (keepstencil)
+               dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
+            else
+               dstRow[i] = (dstRow[i] & 0xFFFFFF) | (stencil[i] << 24);
+
+         }
+         src += srcRowStride;
+         dstRow += dstRowStride / sizeof(GLuint);
       }
    }
 
@@ -492,7 +493,7 @@ _mesa_texstore_s8(TEXSTORE_PARAMS)
 
    {
       const GLint srcRowStride
-        = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+         = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
       GLint img, row;
       GLubyte *stencil = malloc(srcWidth * sizeof(GLubyte));
 
@@ -672,12 +673,10 @@ texstore_compressed(TEXSTORE_PARAMS)
 static GLboolean
 texstore_rgba(TEXSTORE_PARAMS)
 {
-   void *tempImage = NULL, *tempRGBA = NULL;
-   int srcRowStride, img;
+   void *tempImage = NULL;
+   int img;
    GLubyte *src, *dst;
-   uint32_t srcMesaFormat;
    uint8_t rebaseSwizzle[4];
-   bool needRebase;
    bool transferOpsDone = false;
 
    /* We have to handle MESA_FORMAT_YCBCR manually because it is a special case
@@ -724,7 +723,9 @@ texstore_rgba(TEXSTORE_PARAMS)
        */
       GLint swapSize = _mesa_sizeof_packed_type(srcType);
       if (swapSize == 2 || swapSize == 4) {
-         int imageStride = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat, srcType);
+         int imageStride = _mesa_image_image_stride(srcPacking, srcWidth,
+                                                    srcHeight, srcFormat,
+                                                    srcType);
          int bufferSize = imageStride * srcDepth;
          int layer;
          const uint8_t *src;
@@ -747,15 +748,18 @@ texstore_rgba(TEXSTORE_PARAMS)
       }
    }
 
-   srcRowStride =
+   int srcRowStride =
       _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
 
-   srcMesaFormat = _mesa_format_from_format_and_type(srcFormat, srcType);
+   uint32_t srcMesaFormat =
+      _mesa_format_from_format_and_type(srcFormat, srcType);
+
    dstFormat = _mesa_get_srgb_format_linear(dstFormat);
 
    /* If we have transferOps then we need to convert to RGBA float first,
       then apply transferOps, then do the conversion to dst
     */
+   void *tempRGBA = NULL;
    if (!transferOpsDone &&
        _mesa_texstore_needs_transfer_ops(ctx, baseInternalFormat, dstFormat)) {
       /* Allocate RGBA float image */
@@ -763,7 +767,6 @@ texstore_rgba(TEXSTORE_PARAMS)
       tempRGBA = malloc(4 * elementCount * sizeof(float));
       if (!tempRGBA) {
          free(tempImage);
-         free(tempRGBA);
          return GL_FALSE;
       }
 
@@ -797,6 +800,7 @@ texstore_rgba(TEXSTORE_PARAMS)
       _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
                           srcFormat, srcType, 0, 0, 0);
 
+   bool needRebase;
    if (_mesa_get_format_base_format(dstFormat) != baseInternalFormat) {
       needRebase =
          _mesa_compute_rgba2base2rgba_component_mapping(baseInternalFormat,
@@ -1053,7 +1057,8 @@ store_texsubimage(struct gl_context *ctx,
                                                 format, type);
       break;
    default:
-      _mesa_warning(ctx, "Unexpected target 0x%x in store_texsubimage()", target);
+      _mesa_warning(ctx, "Unexpected target 0x%x in store_texsubimage()",
+                    target);
       return;
    }
 
@@ -1288,7 +1293,8 @@ _mesa_compute_compressed_pixelstore(GLuint dims, mesa_format texFormat,
             ((packing->RowLength + bw - 1) / bw);
       }
 
-      store->SkipBytes += packing->SkipPixels * packing->CompressedBlockSize / bw;
+      store->SkipBytes +=
+         packing->SkipPixels * packing->CompressedBlockSize / bw;
    }
 
    if (dims > 1 && packing->CompressedBlockHeight &&
@@ -1360,16 +1366,24 @@ _mesa_store_compressed_texsubimage(struct gl_context *ctx, GLuint dims,
       if (dstMap) {
 
          /* copy rows of blocks */
-         for (i = 0; i < store.CopyRowsPerSlice; i++) {
-            memcpy(dstMap, src, store.CopyBytesPerRow);
-            dstMap += dstRowStride;
-            src += store.TotalBytesPerRow;
+         if (dstRowStride == store.TotalBytesPerRow &&
+             dstRowStride == store.CopyBytesPerRow) {
+            memcpy(dstMap, src, store.CopyBytesPerRow * store.CopyRowsPerSlice);
+            src += store.CopyBytesPerRow * store.CopyRowsPerSlice;
+         }
+         else {
+            for (i = 0; i < store.CopyRowsPerSlice; i++) {
+               memcpy(dstMap, src, store.CopyBytesPerRow);
+               dstMap += dstRowStride;
+               src += store.TotalBytesPerRow;
+            }
          }
 
          ctx->Driver.UnmapTextureImage(ctx, texImage, slice + zoffset);
 
          /* advance to next slice */
-         src += store.TotalBytesPerRow * (store.TotalRowsPerSlice - store.CopyRowsPerSlice);
+         src += store.TotalBytesPerRow * (store.TotalRowsPerSlice
+                                          - store.CopyRowsPerSlice);
       }
       else {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage%uD",