I've now seen a couple apps that replace a whole texture image with a
glTexImage() call instead of glTexSubImage().  The later is better
because we can skip freeing/allocating texture memory.

This patch checks if the new glTexImage's format and size matches the
current image.  If so, use the TexSubImage path.
---
 src/mesa/main/teximage.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index b16baaf..867487a 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -2591,6 +2591,19 @@ teximage(struct gl_context *ctx, GLuint dims,
         if (!texImage) {
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
         }
+         else if (texImage->InternalFormat == internalFormat &&
+                  texImage->Width == width &&
+                  texImage->Height == height &&
+                  texImage->Depth == depth &&
+                  texImage->Border == border) {
+            /* The current tex image and the new tex image are the same
+             * size and format so we can skip memory allocation, etc.
+             */
+            ctx->Driver.TexSubImage(ctx, dims, texImage,
+                                    0, 0, 0, width, height, depth,
+                                    format, type, pixels, unpack);
+            check_gen_mipmap(ctx, target, texObj, level);
+         }
          else {
             gl_format texFormat;
 
-- 
1.7.3.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to