[Mesa-dev] [PATCH] mesa: implement glTexImage as glTexSubImage when possible

Brian Paul brianp at vmware.com
Fri Jun 8 22:31:52 CEST 2012


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



More information about the mesa-dev mailing list