[Mesa-dev] [PATCH 07/10] mesa: Finally, convert RGBA glGetTexImage() to using MapTextureImage().

Eric Anholt eric at anholt.net
Thu Sep 22 17:14:45 PDT 2011


From: Brian Paul <brianp at vmware.com>

---
 src/mesa/main/texgetimage.c            |   16 ++++++++++---
 src/mesa/state_tracker/st_cb_texture.c |   38 --------------------------------
 2 files changed, 12 insertions(+), 42 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 11494e5..7d7960b 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -270,7 +270,6 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
    }
    else {
       /* No decompression needed */
-      const GLint texelSize = _mesa_get_format_bytes(texFormat);
       GLuint img, row;
       GLfloat (*rgba)[4];
 
@@ -281,13 +280,19 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
       }
 
       for (img = 0; img < depth; img++) {
+	 GLubyte *srcMap;
+	 GLint rowstride;
+
+         /* map src texture buffer */
+         ctx->Driver.MapTextureImage(ctx, texImage, img,
+                                     0, 0, width, height, GL_MAP_READ_BIT,
+                                     &srcMap, &rowstride);
+
          for (row = 0; row < height; row++) {
+	    const GLubyte *src = srcMap + row * rowstride;
             void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
                                              width, height, format, type,
                                              img, row, 0);
-            const GLubyte *src = (const GLubyte *) texImage->Data +
-               (texImage->ImageOffsets[img] +
-                texImage->RowStride * row) * texelSize;
 
             _mesa_unpack_rgba_row(texFormat, width, src, rgba);
 
@@ -327,6 +332,9 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
                                        format, type, dest,
                                        &ctx->Pack, transferOps);
          }
+
+         /* Unmap the src texture buffer */
+         ctx->Driver.UnmapTextureImage(ctx, texImage, img);
       }
 
       free(rgba);
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index ee215f7..24fde55 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -940,7 +940,6 @@ 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.
@@ -952,37 +951,6 @@ st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
       return;
    }
 
-   if (format == GL_DEPTH_STENCIL ||
-       format == GL_DEPTH_COMPONENT) {
-      do_map = GL_FALSE;
-   }
-
-   /* Map */
-   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.
-       */
-      texImage->Data = st_texture_image_map(st, stImage, 0,
-                                            PIPE_TRANSFER_READ, 0, 0,
-                                            stImage->base.Width,
-                                            stImage->base.Height);
-      /* compute stride in texels from stride in bytes */
-      texImage->RowStride = stImage->transfer->stride
-         * util_format_get_blockwidth(stImage->pt->format)
-         / util_format_get_blocksize(stImage->pt->format);
-   }
-   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
-       * texImage->Data - storage for texture images in main memory
-       * and access (ie mappings) of images.  In other words, we'd
-       * create a new texImage->Map field and leave Data simply for
-       * storage.
-       */
-      assert(texImage->Data);
-   }
-
    depth = texImage->Depth;
    texImage->Depth = 1;
 
@@ -1005,12 +973,6 @@ st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
    }
 
    texImage->Depth = depth;
-
-   /* Unmap */
-   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