mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / texgetimage.c
index 7299a4b23e9f5b549059e9552d227bad38ec257b..1ac707d134c8180cc5521e41d67e48df7c41b05f 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.7
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (c) 2009 VMware, Inc.
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
@@ -37,7 +37,6 @@
 #include "format_unpack.h"
 #include "glformats.h"
 #include "image.h"
-#include "mfeatures.h"
 #include "mtypes.h"
 #include "pack.h"
 #include "pbo.h"
@@ -131,6 +130,10 @@ get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
    const GLint depth = texImage->Depth;
    GLint img, row;
 
+   assert(format == GL_DEPTH_STENCIL);
+   assert(type == GL_UNSIGNED_INT_24_8 ||
+          type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
+
    for (img = 0; img < depth; img++) {
       GLubyte *srcMap;
       GLint rowstride;
@@ -146,8 +149,10 @@ get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
             void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
                                              width, height, format, type,
                                              img, row, 0);
-            /* XXX Z24_S8 vs. S8_Z24??? */
-            memcpy(dest, src, width * sizeof(GLuint));
+            _mesa_unpack_depth_stencil_row(texImage->TexFormat,
+                                           width,
+                                           (const GLuint *) src,
+                                           type, dest);
             if (ctx->Pack.SwapBytes) {
                _mesa_swap4((GLuint *) dest, width);
             }
@@ -226,7 +231,7 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
                         GLbitfield transferOps)
 {
    /* don't want to apply sRGB -> RGB conversion here so override the format */
-   const gl_format texFormat =
+   const mesa_format texFormat =
       _mesa_get_srgb_format_linear(texImage->TexFormat);
    const GLenum baseFormat = _mesa_get_format_base_format(texFormat);
    const GLenum destBaseFormat = _mesa_base_tex_format(ctx, format);
@@ -234,8 +239,8 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
    const GLuint width = texImage->Width;
    const GLuint height = texImage->Height;
    const GLuint depth = texImage->Depth;
-   GLfloat *tempImage, *srcRow;
-   GLuint row;
+   GLfloat *tempImage, *tempSlice, *srcRow;
+   GLuint row, slice;
 
    /* Decompress into temp float buffer, then pack into user buffer */
    tempImage = malloc(width * height * depth
@@ -245,20 +250,22 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
       return;
    }
 
-   /* Decompress the texture image - results in 'tempImage' */
-   {
+   /* Decompress the texture image slices - results in 'tempImage' */
+   for (slice = 0; slice < depth; slice++) {
       GLubyte *srcMap;
       GLint srcRowStride;
 
-      ctx->Driver.MapTextureImage(ctx, texImage, 0,
+      tempSlice = tempImage + slice * 4 * width * height;
+
+      ctx->Driver.MapTextureImage(ctx, texImage, slice,
                                   0, 0, width, height,
                                   GL_MAP_READ_BIT,
                                   &srcMap, &srcRowStride);
       if (srcMap) {
          _mesa_decompress_image(texFormat, width, height,
-                                srcMap, srcRowStride, tempImage);
+                                srcMap, srcRowStride, tempSlice);
 
-         ctx->Driver.UnmapTextureImage(ctx, texImage, 0);
+         ctx->Driver.UnmapTextureImage(ctx, texImage, slice);
       }
       else {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
@@ -295,15 +302,19 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
                               rebaseFormat);
    }
 
-   srcRow = tempImage;
-   for (row = 0; row < height; row++) {
-      void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
-                                       width, height, format, type,
-                                       0, row, 0);
-
-      _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow,
-                                 format, type, dest, &ctx->Pack, transferOps);
-      srcRow += width * 4;
+   tempSlice = tempImage;
+   for (slice = 0; slice < depth; slice++) {
+      srcRow = tempSlice;
+      for (row = 0; row < height; row++) {
+         void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+                                          width, height, format, type,
+                                          slice, row, 0);
+
+         _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow,
+                                    format, type, dest, &ctx->Pack, transferOps);
+         srcRow += 4 * width;
+      }
+      tempSlice += 4 * width * height;
    }
 
    free(tempImage);
@@ -314,7 +325,7 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
  * Return a base GL format given the user-requested format
  * for glGetTexImage().
  */
-static GLenum
+GLenum
 _mesa_base_pack_format(GLenum format)
 {
    switch (format) {
@@ -355,7 +366,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
                           GLbitfield transferOps)
 {
    /* don't want to apply sRGB -> RGB conversion here so override the format */
-   const gl_format texFormat =
+   const mesa_format texFormat =
       _mesa_get_srgb_format_linear(texImage->TexFormat);
    const GLuint width = texImage->Width;
    GLenum destBaseFormat = _mesa_base_pack_format(format);
@@ -518,6 +529,7 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
    if (type_needs_clamping(type)) {
       /* the returned image type can't have negative values */
       if (dataType == GL_FLOAT ||
+          dataType == GL_HALF_FLOAT ||
           dataType == GL_SIGNED_NORMALIZED ||
           format == GL_LUMINANCE ||
           format == GL_LUMINANCE_ALPHA) {
@@ -616,18 +628,8 @@ _mesa_get_teximage(struct gl_context *ctx,
                    GLenum format, GLenum type, GLvoid *pixels,
                    struct gl_texture_image *texImage)
 {
-   GLuint dimensions;
-
-   switch (texImage->TexObject->Target) {
-   case GL_TEXTURE_1D:
-      dimensions = 1;
-      break;
-   case GL_TEXTURE_3D:
-      dimensions = 3;
-      break;
-   default:
-      dimensions = 2;
-   }
+   const GLuint dimensions =
+      _mesa_get_texture_dimensions(texImage->TexObject->Target);
 
    /* map dest buffer, if PBO */
    if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
@@ -639,7 +641,8 @@ _mesa_get_teximage(struct gl_context *ctx,
        */
       GLubyte *buf = (GLubyte *)
          ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size,
-                                   GL_MAP_WRITE_BIT, ctx->Pack.BufferObj);
+                                   GL_MAP_WRITE_BIT, ctx->Pack.BufferObj,
+                                    MAP_INTERNAL);
       if (!buf) {
          /* out of memory or other unexpected error */
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)");
@@ -668,7 +671,7 @@ _mesa_get_teximage(struct gl_context *ctx,
    }
 
    if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
-      ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj);
+      ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL);
    }
 }
 
@@ -693,7 +696,8 @@ _mesa_get_compressed_teximage(struct gl_context *ctx,
       /* pack texture image into a PBO */
       GLubyte *buf = (GLubyte *)
          ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size,
-                                   GL_MAP_WRITE_BIT, ctx->Pack.BufferObj);
+                                   GL_MAP_WRITE_BIT, ctx->Pack.BufferObj,
+                                    MAP_INTERNAL);
       if (!buf) {
          /* out of memory or other unexpected error */
          _mesa_error(ctx, GL_OUT_OF_MEMORY,
@@ -735,7 +739,7 @@ _mesa_get_compressed_teximage(struct gl_context *ctx,
    }
 
    if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
-      ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj);
+      ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL);
    }
 }
 
@@ -763,8 +767,7 @@ legal_getteximage_target(struct gl_context *ctx, GLenum target)
       return ctx->Extensions.NV_texture_rectangle;
    case GL_TEXTURE_1D_ARRAY_EXT:
    case GL_TEXTURE_2D_ARRAY_EXT:
-      return (ctx->Extensions.MESA_texture_array ||
-              ctx->Extensions.EXT_texture_array);
+      return ctx->Extensions.EXT_texture_array;
    case GL_TEXTURE_CUBE_MAP_ARRAY:
       return ctx->Extensions.ARB_texture_cube_map_array;
    default:
@@ -834,6 +837,11 @@ getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level,
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
       return GL_TRUE;
    }
+   else if (_mesa_is_stencil_format(format)
+            && !ctx->Extensions.ARB_texture_stencil8) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format=GL_STENCIL_INDEX)");
+      return GL_TRUE;
+   }
    else if (_mesa_is_ycbcr_format(format)
             && !_mesa_is_ycbcr_format(baseFormat)) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
@@ -849,6 +857,11 @@ getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level,
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
       return GL_TRUE;
    }
+   else if (_mesa_is_enum_format_integer(format) !=
+            _mesa_is_format_integer(texImage->TexFormat)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+      return GL_TRUE;
+   }
 
    if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width,
                                   texImage->Height, texImage->Depth,
@@ -866,7 +879,7 @@ getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level,
 
    if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
       /* PBO should not be mapped */
-      if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
+      if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glGetTexImage(PBO is mapped)");
          return GL_TRUE;
@@ -1009,7 +1022,7 @@ getcompressedteximage_error_check(struct gl_context *ctx, GLenum target,
       }
 
       /* make sure PBO is not mapped */
-      if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
+      if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glGetCompressedTexImage(PBO is mapped)");
          return GL_TRUE;