Mesa (master): mesa: refactor bind_texture

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jun 28 19:41:53 UTC 2019


Module: Mesa
Branch: master
Commit: 274104ec381ebb1505e0e078959f94724b51ec58
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=274104ec381ebb1505e0e078959f94724b51ec58

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Tue Jun 25 16:53:49 2019 +0200

mesa: refactor bind_texture

Splits texture lookup and binding actions.

The new _mesa_lookup_or_create_texture will be useful to implement the EXT_direct_state_access extension.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Signed-off-by: Marek Olšák <marek.olsak at amd.com>

---

 src/mesa/main/texobj.c | 47 ++++++++++++++++++++++++++++++-----------------
 src/mesa/main/texobj.h |  6 ++++++
 2 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index fa8a4d88dcb..6dbe56fa19c 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1703,17 +1703,10 @@ _mesa_bind_texture(struct gl_context *ctx, GLenum target,
    bind_texture_object(ctx, ctx->Texture.CurrentUnit, tex_obj);
 }
 
-/**
- * Implement glBindTexture().  Do error checking, look-up or create a new
- * texture object, then bind it in the current texture unit.
- *
- * \param target texture target.
- * \param texName texture name.
- * \param texunit texture unit.
- */
-static ALWAYS_INLINE void
-bind_texture(struct gl_context *ctx, GLenum target, GLuint texName,
-             GLenum texunit, bool no_error, const char *caller)
+struct gl_texture_object *
+_mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
+                               GLuint texName, bool no_error,
+                               const char *caller)
 {
    struct gl_texture_object *newTexObj = NULL;
    int targetIndex;
@@ -1722,7 +1715,7 @@ bind_texture(struct gl_context *ctx, GLenum target, GLuint texName,
    if (!no_error && targetIndex < 0) {
       _mesa_error(ctx, GL_INVALID_ENUM, "%s(target = %s)", caller,
                   _mesa_enum_to_string(target));
-      return;
+      return NULL;
    }
    assert(targetIndex < NUM_TEXTURE_TARGETS);
 
@@ -1744,24 +1737,23 @@ bind_texture(struct gl_context *ctx, GLenum target, GLuint texName,
              */
             _mesa_error(ctx, GL_INVALID_OPERATION,
                         "%s(target mismatch)", caller);
-            return;
+            return NULL;
          }
          if (newTexObj->Target == 0) {
             finish_texture_init(ctx, target, newTexObj, targetIndex);
          }
-      }
-      else {
+      } else {
          if (!no_error && ctx->API == API_OPENGL_CORE) {
             _mesa_error(ctx, GL_INVALID_OPERATION,
                         "%s(non-gen name)", caller);
-            return;
+            return NULL;
          }
 
          /* if this is a new texture id, allocate a texture object now */
          newTexObj = ctx->Driver.NewTextureObject(ctx, texName, target);
          if (!newTexObj) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
-            return;
+            return NULL;
          }
 
          /* and insert it into hash table */
@@ -1772,6 +1764,27 @@ bind_texture(struct gl_context *ctx, GLenum target, GLuint texName,
    assert(newTexObj->Target == target);
    assert(newTexObj->TargetIndex == targetIndex);
 
+   return newTexObj;
+}
+
+/**
+ * Implement glBindTexture().  Do error checking, look-up or create a new
+ * texture object, then bind it in the current texture unit.
+ *
+ * \param target texture target.
+ * \param texName texture name.
+ * \param texunit texture unit.
+ */
+static ALWAYS_INLINE void
+bind_texture(struct gl_context *ctx, GLenum target, GLuint texName,
+             GLenum texunit, bool no_error, const char *caller)
+{
+   struct gl_texture_object *newTexObj =
+      _mesa_lookup_or_create_texture(ctx, target, texName, no_error,
+                                     "glBindTexture");
+   if (!newTexObj)
+      return;
+
    bind_texture_object(ctx, texunit, newTexObj);
 }
 
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 80e95d1f91a..3ebfa6715db 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -176,6 +176,12 @@ _mesa_delete_nameless_texture(struct gl_context *ctx,
 extern void
 _mesa_bind_texture(struct gl_context *ctx, GLenum target,
                    struct gl_texture_object *tex_obj);
+
+extern struct gl_texture_object *
+_mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
+                               GLuint texName, bool no_error,
+                               const char *name);
+
 /*@}*/
 
 /**




More information about the mesa-commit mailing list