mesa: add new helper _mesa_get_texobj_by_target_and_texunit
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tue, 30 Apr 2019 11:37:12 +0000 (13:37 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 6 Aug 2019 21:03:06 +0000 (17:03 -0400)
Based on the 'static get_texobj_by_target' function from texparam.c,
but extended to also take the texunit as a parameter.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/texobj.c
src/mesa/main/texobj.h
src/mesa/main/texparam.c

index 5d49ce7924c1968ac0bdcf47f748608b14943343..5c57266d361cd44a0c95dbbcc9af94564c7f1ace 100644 (file)
@@ -218,6 +218,42 @@ _mesa_get_current_tex_object(struct gl_context *ctx, GLenum target)
 }
 
 
+/**
+ * Get the texture object for given target and texunit
+ * Proxy targets are accepted only allowProxyTarget is true.
+ * Return NULL if any error (and record the error).
+ */
+struct gl_texture_object *
+_mesa_get_texobj_by_target_and_texunit(struct gl_context *ctx, GLenum target,
+                                       GLuint texunit, bool allowProxyTarget,
+                                       const char* caller)
+{
+   struct gl_texture_unit *texUnit;
+   int targetIndex;
+
+   if (_mesa_is_proxy_texture(target) && allowProxyTarget) {
+      return _mesa_get_current_tex_object(ctx, target);
+   }
+
+   if (texunit >= ctx->Const.MaxCombinedTextureImageUnits) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(texunit=%d)", caller, texunit);
+      return NULL;
+   }
+
+   texUnit = _mesa_get_tex_unit(ctx, texunit);
+
+   targetIndex = _mesa_tex_target_to_index(ctx, target);
+   if (targetIndex < 0 || targetIndex == TEXTURE_BUFFER_INDEX) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", caller);
+      return NULL;
+   }
+   assert(targetIndex < NUM_TEXTURE_TARGETS);
+
+   return texUnit->CurrentTex[targetIndex];
+}
+
+
 /**
  * Allocate and initialize a new texture object.  But don't put it into the
  * texture object hash table.
index 54399af538196cc5c25258020044f609d8b6d668..19f715159a294184714f7c1938f0dc6bd8145dda 100644 (file)
@@ -58,6 +58,12 @@ _mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id);
 extern struct gl_texture_object *
 _mesa_get_current_tex_object(struct gl_context *ctx, GLenum target);
 
+extern struct gl_texture_object *
+_mesa_get_texobj_by_target_and_texunit(struct gl_context *ctx, GLenum target,
+                                       GLuint texunit,
+                                       bool allowProxyTargets,
+                                       const char* caller);
+
 extern struct gl_texture_object *
 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
 
index f3a01ae65e56daac50514f8a1c1d7cd4235e9006..78888b660fa3ac686e36c5696bb02d5da8c80c15 100644 (file)
@@ -114,39 +114,6 @@ validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
 }
 
 
-/**
- * Get current texture object for given target.
- * Return NULL if any error (and record the error).
- * Note that this is different from _mesa_get_current_tex_object() in that
- * proxy targets are not accepted.
- * Only the glGetTexLevelParameter() functions accept proxy targets.
- */
-static struct gl_texture_object *
-get_texobj_by_target(struct gl_context *ctx, GLenum target, GLboolean get)
-{
-   struct gl_texture_unit *texUnit;
-   int targetIndex;
-
-   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "gl%sTexParameter(current unit)", get ? "Get" : "");
-      return NULL;
-   }
-
-   texUnit = _mesa_get_current_tex_unit(ctx);
-
-   targetIndex = _mesa_tex_target_to_index(ctx, target);
-   if (targetIndex < 0 || targetIndex == TEXTURE_BUFFER_INDEX) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "gl%sTexParameter(target)", get ? "Get" : "");
-      return NULL;
-   }
-   assert(targetIndex < NUM_TEXTURE_TARGETS);
-
-   return texUnit->CurrentTex[targetIndex];
-}
-
-
 static bool
 is_texparameteri_target_valid(GLenum target)
 {
@@ -1096,7 +1063,10 @@ _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_FALSE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                   ctx->Texture.CurrentUnit,
+                                                   false,
+                                                   "glTexParameterf");
    if (!texObj)
       return;
 
@@ -1109,7 +1079,10 @@ _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_FALSE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                   ctx->Texture.CurrentUnit,
+                                                   false,
+                                                   "glTexParameterfv");
    if (!texObj)
       return;
 
@@ -1122,7 +1095,10 @@ _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_FALSE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                   ctx->Texture.CurrentUnit,
+                                                   false,
+                                                   "glTexParameteri");
    if (!texObj)
       return;
 
@@ -1135,7 +1111,10 @@ _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_FALSE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                   ctx->Texture.CurrentUnit,
+                                                   false,
+                                                   "glTexParameteriv");
    if (!texObj)
       return;
 
@@ -1153,7 +1132,10 @@ _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_FALSE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                   ctx->Texture.CurrentUnit,
+                                                   false,
+                                                   "glTexParameterIiv");
    if (!texObj)
       return;
 
@@ -1171,7 +1153,10 @@ _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_FALSE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                   ctx->Texture.CurrentUnit,
+                                                   false,
+                                                   "glTexParameterIuiv");
    if (!texObj)
       return;
 
@@ -2445,7 +2430,10 @@ _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
    struct gl_texture_object *obj;
    GET_CURRENT_CONTEXT(ctx);
 
-   obj = get_texobj_by_target(ctx, target, GL_TRUE);
+   obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                ctx->Texture.CurrentUnit,
+                                                false,
+                                                "glGetTexParameterfv");
    if (!obj)
       return;
 
@@ -2458,7 +2446,10 @@ _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
    struct gl_texture_object *obj;
    GET_CURRENT_CONTEXT(ctx);
 
-   obj = get_texobj_by_target(ctx, target, GL_TRUE);
+   obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                ctx->Texture.CurrentUnit,
+                                                false,
+                                                "glGetTexParameteriv");
    if (!obj)
       return;
 
@@ -2472,7 +2463,10 @@ _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_TRUE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                ctx->Texture.CurrentUnit,
+                                                false,
+                                                "glGetTexParameterIiv");
    if (!texObj)
       return;
 
@@ -2487,7 +2481,10 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_target(ctx, target, GL_TRUE);
+   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
+                                                ctx->Texture.CurrentUnit,
+                                                false,
+                                                "glGetTexParameterIuiv");
    if (!texObj)
       return;