[Mesa-dev] [PATCH 26/37] mesa: Convert depth/stencil glGetTexImage() to using MapTextureImage().

Eric Anholt eric at anholt.net
Mon Aug 15 11:53:56 PDT 2011


From: Brian Paul <brianp at vmware.com>

Note that the implementation before and after appears to be broken in
its handling of Z24_S8 vs S8_Z24.
---
 src/mesa/main/texgetimage.c            |   19 ++++++++++++++-----
 src/mesa/state_tracker/st_cb_texture.c |   11 ++++++++---
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index aeff0da..9f64b26 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -165,27 +165,36 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions,
 static void
 get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
                       GLenum format, GLenum type, GLvoid *pixels,
-                      const struct gl_texture_image *texImage)
+                      struct gl_texture_image *texImage)
 {
    const GLint width = texImage->Width;
    const GLint height = texImage->Height;
    const GLint depth = texImage->Depth;
-   const GLint rowstride = texImage->RowStride;
-   const GLuint *src = (const GLuint *) texImage->Data;
    GLint img, row;
 
    for (img = 0; img < depth; img++) {
+      GLubyte *srcMap;
+      GLint srcRowStride;
+
+      /* map src texture buffer */
+      ctx->Driver.MapTextureImage(ctx, texImage, img,
+                                  0, 0, width, height, GL_MAP_READ_BIT,
+                                  &srcMap, &srcRowStride);
+
       for (row = 0; row < height; row++) {
          void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
                                           width, height, format, type,
                                           img, row, 0);
-         memcpy(dest, src, width * sizeof(GLuint));
+         /* XXX Z24_S8 vs. S8_Z24??? */
+         memcpy(dest, srcMap, width * sizeof(GLuint));
          if (ctx->Pack.SwapBytes) {
             _mesa_swap4((GLuint *) dest, width);
          }
 
-         src += rowstride;
+         srcMap += srcRowStride;
       }
+
+      ctx->Driver.UnmapTextureImage(ctx, texImage, img);
    }
 }
 
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index ec81a89..bdd90c7 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -931,6 +931,7 @@ st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
                                format, type);
    GLuint depth, i;
    GLubyte *dest;
+   GLboolean do_map = GL_TRUE;
 
    if (stImage->pt && util_format_is_s3tc(stImage->pt->format)) {
       /* Need to decompress the texture.
@@ -942,8 +943,12 @@ st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
       return;
    }
 
+   if (format == GL_DEPTH_STENCIL_EXT) {
+      do_map = GL_FALSE;
+   }
+
    /* Map */
-   if (stImage->pt) {
+   if (do_map && stImage->pt) {
       /* Image is stored in hardware format in a buffer managed by the
        * kernel.  Need to explicitly map and unmap it.
        */
@@ -956,7 +961,7 @@ st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
          * util_format_get_blockwidth(stImage->pt->format)
          / util_format_get_blocksize(stImage->pt->format);
    }
-   else {
+   else if (do_map) {
       /* Otherwise, the image should actually be stored in
        * texImage->Data.  This is pretty confusing for
        * everybody, I'd much prefer to separate the two functions of
@@ -994,7 +999,7 @@ st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
    texImage->Depth = depth;
 
    /* Unmap */
-   if (stImage->pt) {
+   if (do_map && stImage->pt) {
       st_texture_image_unmap(st, stImage);
       texImage->Data = NULL;
    }
-- 
1.7.5.4



More information about the mesa-dev mailing list