[Mesa-dev] [PATCH 1/2] gallium: Avoid a if () only used for convenience for gen_mipmap

Vincent Lejeune vljn at ovi.com
Sun Jan 8 14:15:33 PST 2012


---
 src/mesa/state_tracker/st_cb_texture.c |   67 ++++++++++++++++++++-----------
 src/mesa/state_tracker/st_cb_texture.h |    5 ++
 src/mesa/state_tracker/st_gen_mipmap.c |    4 +-
 3 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index ad4f23c..3cd1b2b 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -1197,39 +1197,34 @@ copy_image_data_to_texture(struct st_context *st,
    pipe_resource_reference(&stImage->pt, stObj->pt);
 }
 
+static void inline
+set_mipmap_level(struct st_texture_object *stObj)
+{
+   /* The texture is complete and we know exactly how many mipmap levels
+    * are present/needed.  This is conditional because we may be called
+    * from the st_generate_mipmap() function when the texture object is
+    * incomplete.  In that case, we'll have set stObj->lastLevel before
+    * we get here.
+    */
+   if (stObj->base.Sampler.MinFilter == GL_LINEAR ||
+       stObj->base.Sampler.MinFilter == GL_NEAREST)
+      stObj->lastLevel = stObj->base.BaseLevel;
+   else
+      stObj->lastLevel = stObj->base._MaxLevel;
+}
 
-/**
- * Called during state validation.  When this function is finished,
- * the texture object should be ready for rendering.
- * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
- */
-GLboolean
-st_finalize_texture(struct gl_context *ctx,
-		    struct pipe_context *pipe,
-		    struct gl_texture_object *tObj)
+static GLboolean inline
+st_finalize_texture_body(struct gl_context *ctx,
+                struct pipe_context *pipe,
+               struct st_texture_object *stObj)
 {
    struct st_context *st = st_context(ctx);
-   struct st_texture_object *stObj = st_texture_object(tObj);
    const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
    GLuint face;
    struct st_texture_image *firstImage;
    enum pipe_format firstImageFormat;
    GLuint ptWidth, ptHeight, ptDepth, ptLayers;
 
-   if (stObj->base._Complete) {
-      /* The texture is complete and we know exactly how many mipmap levels
-       * are present/needed.  This is conditional because we may be called
-       * from the st_generate_mipmap() function when the texture object is
-       * incomplete.  In that case, we'll have set stObj->lastLevel before
-       * we get here.
-       */
-      if (stObj->base.Sampler.MinFilter == GL_LINEAR ||
-          stObj->base.Sampler.MinFilter == GL_NEAREST)
-         stObj->lastLevel = stObj->base.BaseLevel;
-      else
-         stObj->lastLevel = stObj->base._MaxLevel;
-   }
-
    firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
    assert(firstImage);
 
@@ -1333,6 +1328,30 @@ st_finalize_texture(struct gl_context *ctx,
    return GL_TRUE;
 }
 
+GLboolean
+st_finalize_texture_mip_map(struct gl_context *ctx,
+                struct pipe_context *pipe,
+                struct gl_texture_object *tObj)
+{
+   return st_finalize_texture_body(ctx, pipe, st_texture_object(tObj));
+}
+
+/**
+ * Called during state validation.  When this function is finished,
+ * the texture object should be ready for rendering.
+ * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
+ */
+GLboolean
+st_finalize_texture(struct gl_context *ctx,
+		    struct pipe_context *pipe,
+		    struct gl_texture_object *tObj)
+{
+   struct st_texture_object *stObj = st_texture_object(tObj);
+
+   set_mipmap_level(stObj);
+   return st_finalize_texture_body(ctx, pipe, stObj);
+}
+
 
 /**
  * Returns pointer to a default/dummy texture.
diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h
index f1502bd..0724aba 100644
--- a/src/mesa/state_tracker/st_cb_texture.h
+++ b/src/mesa/state_tracker/st_cb_texture.h
@@ -39,6 +39,11 @@ struct pipe_context;
 struct st_context;
 
 extern GLboolean
+st_finalize_texture_mip_map(struct gl_context *ctx,
+                struct pipe_context *pipe,
+                struct gl_texture_object *tObj);
+
+extern GLboolean
 st_finalize_texture(struct gl_context *ctx,
 		    struct pipe_context *pipe, 
 		    struct gl_texture_object *tObj);
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index d817a9c..6b4ebe5 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -196,7 +196,7 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
       /* This will copy the old texture's base image into the new texture
        * which we just allocated.
        */
-      st_finalize_texture(ctx, st->pipe, texObj);
+      st_finalize_texture_mip_map(ctx, st->pipe, texObj);
 
       /* release the old tex (will likely be freed too) */
       pipe_resource_reference(&oldTex, NULL);
@@ -206,7 +206,7 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
       /* Make sure that the base texture image data is present in the
        * texture buffer.
        */
-      st_finalize_texture(ctx, st->pipe, texObj);
+      st_finalize_texture_mip_map(ctx, st->pipe, texObj);
    }
 
    pt = stObj->pt;
-- 
1.7.7



More information about the mesa-dev mailing list