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

Eric Anholt eric at anholt.net
Mon Aug 15 11:54:01 PDT 2011


From: Brian Paul <brianp at vmware.com>

---
 src/mesa/main/texgetimage.c            |  103 ++++++++++++++++++--------------
 src/mesa/state_tracker/st_cb_texture.c |   38 ------------
 2 files changed, 57 insertions(+), 84 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 36a3f42..4d97c88 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -41,7 +41,6 @@
 #include "pack.h"
 #include "pbo.h"
 #include "texgetimage.h"
-#include "texfetch.h"
 #include "teximage.h"
 #include "drivers/common/meta.h"
 
@@ -272,16 +271,8 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
     * The only possible exception is component clamping to [0,1].
     */
    GLbitfield transferOps = 0x0;
-   GLint img, row;
-   GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
-   const GLboolean is_sampler_srgb_decode =
-       _mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB &&
-       texImage->TexObject->Sampler.sRGBDecode == GL_DECODE_EXT;
-
-   if (!rgba) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
-      return;
-   }
+   GLint img;
+   gl_format texFormat;
 
    /* Clamping does not apply to GetTexImage (final conversion)?
     * Looks like we need clamp though when going from format
@@ -296,13 +287,10 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
       transferOps |= IMAGE_CLAMP_BIT;
    }
 
-   /* glGetTexImage always returns sRGB data for sRGB textures. Make sure the
-    * fetch functions return sRGB data without linearizing it.
+   /* glGetTexImage always returns sRGB data for sRGB textures. Make sure we
+    * get sRGB data without linearizing it.
     */
-   if (is_sampler_srgb_decode) {
-      texImage->TexObject->Sampler.sRGBDecode = GL_SKIP_DECODE_EXT;
-      _mesa_set_fetch_functions(texImage, dimensions);
-   }
+   texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat);
 
    for (img = 0; img < depth; img++) {
       if (_mesa_is_format_compressed(texImage->TexFormat)) {
@@ -311,49 +299,72 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
                                              format, type, pixels,
                                              ctx->Pack.RowLength);
          _mesa_lock_texture(ctx, texImage->TexObject);
-	 continue;
       }
+      else {
+         GLfloat (*rgba)[4];
+         GLubyte *srcMap;
+         GLint srcRowStride;
+         GLint row;
+
+         rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+         if (!rgba) {
+            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
+            return;
+         }
 
-      for (row = 0; row < height; row++) {
-         void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
-                                          width, height, format, type,
-                                          img, row, 0);
-         GLint col;
+         /* 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);
+            GLint i;
+
+            _mesa_unpack_rgba_row(texFormat, width, srcMap, rgba);
+            srcMap += srcRowStride;
 
-         for (col = 0; col < width; col++) {
-            texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
             if (texImage->_BaseFormat == GL_ALPHA) {
-               rgba[col][RCOMP] = 0.0F;
-               rgba[col][GCOMP] = 0.0F;
-               rgba[col][BCOMP] = 0.0F;
+               for (i = 0; i < width; i++) {
+                  rgba[i][RCOMP] = 0.0F;
+                  rgba[i][GCOMP] = 0.0F;
+                  rgba[i][BCOMP] = 0.0F;
+               }
             }
             else if (texImage->_BaseFormat == GL_LUMINANCE) {
-               rgba[col][GCOMP] = 0.0F;
-               rgba[col][BCOMP] = 0.0F;
-               rgba[col][ACOMP] = 1.0F;
+               for (i = 0; i < width; i++) {
+                  rgba[i][GCOMP] = 0.0F;
+                  rgba[i][BCOMP] = 0.0F;
+                  rgba[i][ACOMP] = 1.0F;
+               }
             }
             else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
-               rgba[col][GCOMP] = 0.0F;
-               rgba[col][BCOMP] = 0.0F;
+               for (i = 0; i < width; i++) {
+                  rgba[i][GCOMP] = 0.0F;
+                  rgba[i][BCOMP] = 0.0F;
+               }
             }
             else if (texImage->_BaseFormat == GL_INTENSITY) {
-               rgba[col][GCOMP] = 0.0F;
-               rgba[col][BCOMP] = 0.0F;
-               rgba[col][ACOMP] = 1.0F;
+               for (i = 0; i < width; i++) {
+                  rgba[i][GCOMP] = 0.0F;
+                  rgba[i][BCOMP] = 0.0F;
+                  rgba[i][ACOMP] = 1.0F;
+               }
             }
+
+            _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
+                                       format, type, dest,
+                                       &ctx->Pack, transferOps);
          }
-         _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
-                                    format, type, dest,
-                                    &ctx->Pack, transferOps);
-      }
-   }
 
-   if (is_sampler_srgb_decode) {
-      texImage->TexObject->Sampler.sRGBDecode = GL_DECODE_EXT;
-      _mesa_set_fetch_functions(texImage, dimensions);
-   }
+         /* Unmap the src texture buffer */
+         ctx->Driver.UnmapTextureImage(ctx, texImage, img);
 
-   free(rgba);
+         free(rgba);
+      }
+   }
 }
 
 
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index feb4691..7134fb6 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -931,7 +931,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.
@@ -943,37 +942,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;
 
@@ -998,12 +966,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