[Mesa-dev] [PATCH 03/18] mesa: Optimize unbind_texobj_from_texunits()

Fredrik Höglund fredrik at kde.org
Tue Jan 21 15:35:41 PST 2014


The texture can only be bound to the index that corresponds to its
target, so there is no need to loop over all possible indices
for every unit and checking if the texture is bound to it.
---
 src/mesa/main/texobj.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index fbbc577..5a3cfb2 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1084,19 +1084,19 @@ static void
 unbind_texobj_from_texunits(struct gl_context *ctx,
                             struct gl_texture_object *texObj)
 {
-   GLuint u, tex;
+   const GLuint index = texObj->TargetIndex;
+   GLuint u;
 
    for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
       struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
-      for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
-         if (texObj == unit->CurrentTex[tex]) {
-            _mesa_reference_texobj(&unit->CurrentTex[tex],
-                                   ctx->Shared->DefaultTex[tex]);
-            ASSERT(unit->CurrentTex[tex]);
-            unit->_BoundTextures ^= (1 << tex);
-            break;
-         }
-      }
+
+      if (texObj != unit->CurrentTex[index])
+         continue;
+
+      _mesa_reference_texobj(&unit->CurrentTex[index],
+                             ctx->Shared->DefaultTex[index]);
+      ASSERT(unit->CurrentTex[index]);
+      unit->_BoundTextures ^= (1 << index);
    }
 }
 
-- 
1.7.10.4



More information about the mesa-dev mailing list