diff options
author | Pierre-Eric Pelloux-Prayer <[email protected]> | 2019-04-30 13:37:12 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-08-06 17:03:06 -0400 |
commit | 0e595326c4d728f17abc7c72f9a263965ff65da9 (patch) | |
tree | 4ef8581dd85d9010d7acb9993965f9531f21ceee /src/mesa/main | |
parent | 58030d2b3ded667585f4f5e7bc459008f7ba7e8f (diff) |
mesa: add new helper _mesa_get_texobj_by_target_and_texunit
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 <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/texobj.c | 36 | ||||
-rw-r--r-- | src/mesa/main/texobj.h | 6 | ||||
-rw-r--r-- | src/mesa/main/texparam.c | 83 |
3 files changed, 82 insertions, 43 deletions
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index 5d49ce7924c..5c57266d361 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -219,6 +219,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. * diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h index 54399af5381..19f715159a2 100644 --- a/src/mesa/main/texobj.h +++ b/src/mesa/main/texobj.h @@ -59,6 +59,12 @@ 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 ); extern void diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index f3a01ae65e5..78888b660fa 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -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; |