Commit d0e18550 authored by Marek Olšák's avatar Marek Olšák Committed by Marge Bot

mesa: optimize saving/restoring bound textures for glPush/PopAttrib

Reviewed-by: Pierre-Eric Pelloux-Prayer's avatarPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <!6946>
parent 9a8b5428
......@@ -241,8 +241,13 @@ _mesa_PushAttrib(GLbitfield mask)
/* copy state/contents of the currently bound texture objects */
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
_mesa_copy_texture_object(&head->Texture.SavedObj[u][tex],
ctx->Texture.Unit[u].CurrentTex[tex]);
struct gl_texture_object *dst = &head->Texture.SavedObj[u][tex];
struct gl_texture_object *src = ctx->Texture.Unit[u].CurrentTex[tex];
dst->Target = src->Target;
dst->Name = src->Name;
memcpy(&dst->Sampler.Attrib, &src->Sampler.Attrib, sizeof(src->Sampler.Attrib));
memcpy(&dst->Attrib, &src->Attrib, sizeof(src->Attrib));
}
}
......@@ -563,70 +568,20 @@ pop_texture_group(struct gl_context *ctx, struct gl_texture_attrib_node *texstat
/* Restore texture object state for each target */
for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
const struct gl_texture_object *obj = NULL;
const struct gl_sampler_object *samp;
GLenum target;
obj = &texstate->SavedObj[u][tgt];
/* don't restore state for unsupported targets to prevent
* raising GL errors.
*/
if (obj->Target == GL_TEXTURE_CUBE_MAP &&
!ctx->Extensions.ARB_texture_cube_map) {
continue;
}
else if (obj->Target == GL_TEXTURE_RECTANGLE_NV &&
!ctx->Extensions.NV_texture_rectangle) {
continue;
const struct gl_texture_object *savedObj = &texstate->SavedObj[u][tgt];
struct gl_texture_object *texObj =
texObj = _mesa_get_tex_unit(ctx, u)->CurrentTex[tgt];
if (texObj->Name != savedObj->Name) {
/* We don't need to check whether the texture target is supported,
* because we wouldn't get in this conditional block if it wasn't.
*/
_mesa_BindTexture_no_error(savedObj->Target, savedObj->Name);
}
else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT ||
obj->Target == GL_TEXTURE_2D_ARRAY_EXT) &&
!ctx->Extensions.EXT_texture_array) {
continue;
}
else if (obj->Target == GL_TEXTURE_CUBE_MAP_ARRAY &&
!ctx->Extensions.ARB_texture_cube_map_array) {
continue;
} else if (obj->Target == GL_TEXTURE_BUFFER)
continue;
else if (obj->Target == GL_TEXTURE_EXTERNAL_OES)
continue;
else if (obj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
obj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
continue;
target = obj->Target;
_mesa_BindTexture(target, obj->Name);
samp = &obj->Sampler;
_mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, samp->Attrib.BorderColor.f);
_mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, samp->Attrib.WrapS);
_mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, samp->Attrib.WrapT);
_mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, samp->Attrib.WrapR);
_mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, samp->Attrib.MinFilter);
_mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, samp->Attrib.MagFilter);
_mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, samp->Attrib.MinLod);
_mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, samp->Attrib.MaxLod);
_mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, samp->Attrib.LodBias);
_mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Attrib.Priority);
_mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->Attrib.BaseLevel);
if (target != GL_TEXTURE_RECTANGLE_ARB)
_mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->Attrib.MaxLevel);
if (ctx->Extensions.EXT_texture_filter_anisotropic) {
_mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
samp->Attrib.MaxAnisotropy);
}
if (ctx->Extensions.ARB_shadow) {
_mesa_TexParameteri(target, GL_TEXTURE_COMPARE_MODE,
samp->Attrib.CompareMode);
_mesa_TexParameteri(target, GL_TEXTURE_COMPARE_FUNC,
samp->Attrib.CompareFunc);
}
if (ctx->Extensions.ARB_depth_texture)
_mesa_TexParameteri(target, GL_DEPTH_TEXTURE_MODE, obj->Attrib.DepthMode);
memcpy(&texObj->Sampler.Attrib, &savedObj->Sampler.Attrib,
sizeof(savedObj->Sampler.Attrib));
memcpy(&texObj->Attrib, &savedObj->Attrib, sizeof(savedObj->Attrib));
}
/* remove saved references to the texture objects */
......
......@@ -459,56 +459,6 @@ _mesa_delete_texture_object(struct gl_context *ctx,
}
/**
* Copy texture object state from one texture object to another.
* Use for glPush/PopAttrib.
*
* \param dest destination texture object.
* \param src source texture object.
*/
void
_mesa_copy_texture_object( struct gl_texture_object *dest,
const struct gl_texture_object *src )
{
dest->Target = src->Target;
dest->TargetIndex = src->TargetIndex;
dest->Name = src->Name;
dest->Attrib.Priority = src->Attrib.Priority;
dest->Sampler.Attrib.BorderColor.f[0] = src->Sampler.Attrib.BorderColor.f[0];
dest->Sampler.Attrib.BorderColor.f[1] = src->Sampler.Attrib.BorderColor.f[1];
dest->Sampler.Attrib.BorderColor.f[2] = src->Sampler.Attrib.BorderColor.f[2];
dest->Sampler.Attrib.BorderColor.f[3] = src->Sampler.Attrib.BorderColor.f[3];
dest->Sampler.Attrib.WrapS = src->Sampler.Attrib.WrapS;
dest->Sampler.Attrib.WrapT = src->Sampler.Attrib.WrapT;
dest->Sampler.Attrib.WrapR = src->Sampler.Attrib.WrapR;
dest->Sampler.Attrib.MinFilter = src->Sampler.Attrib.MinFilter;
dest->Sampler.Attrib.MagFilter = src->Sampler.Attrib.MagFilter;
dest->Sampler.Attrib.MinLod = src->Sampler.Attrib.MinLod;
dest->Sampler.Attrib.MaxLod = src->Sampler.Attrib.MaxLod;
dest->Sampler.Attrib.LodBias = src->Sampler.Attrib.LodBias;
dest->Attrib.BaseLevel = src->Attrib.BaseLevel;
dest->Attrib.MaxLevel = src->Attrib.MaxLevel;
dest->Sampler.Attrib.MaxAnisotropy = src->Sampler.Attrib.MaxAnisotropy;
dest->Sampler.Attrib.CompareMode = src->Sampler.Attrib.CompareMode;
dest->Sampler.Attrib.CompareFunc = src->Sampler.Attrib.CompareFunc;
dest->Sampler.Attrib.CubeMapSeamless = src->Sampler.Attrib.CubeMapSeamless;
dest->Attrib.DepthMode = src->Attrib.DepthMode;
dest->Attrib.StencilSampling = src->Attrib.StencilSampling;
dest->Sampler.Attrib.sRGBDecode = src->Sampler.Attrib.sRGBDecode;
dest->_MaxLevel = src->_MaxLevel;
dest->_MaxLambda = src->_MaxLambda;
dest->Attrib.GenerateMipmap = src->Attrib.GenerateMipmap;
dest->_BaseComplete = src->_BaseComplete;
dest->_MipmapComplete = src->_MipmapComplete;
COPY_4V(dest->Attrib.Swizzle, src->Attrib.Swizzle);
dest->Attrib._Swizzle = src->Attrib._Swizzle;
dest->_IsHalfFloat = src->_IsHalfFloat;
dest->_IsFloat = src->_IsFloat;
dest->RequiredTextureImageUnits = src->RequiredTextureImageUnits;
}
/**
* Free all texture images of the given texture objectm, except for
* \p retainTexImage.
......
......@@ -79,10 +79,6 @@ extern void
_mesa_delete_texture_object( struct gl_context *ctx,
struct gl_texture_object *obj );
extern void
_mesa_copy_texture_object( struct gl_texture_object *dest,
const struct gl_texture_object *src );
extern void
_mesa_clear_texture_object(struct gl_context *ctx,
struct gl_texture_object *obj,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment