mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-22 00:08:09 +02:00
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 <marek.olsak@amd.com>
This commit is contained in:
parent
58030d2b3d
commit
0e595326c4
3 changed files with 82 additions and 43 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue