TextureCacheBase: Simplify texture cache entry initialization

This commit is contained in:
NeoBrainX 2011-12-26 18:05:01 +01:00 committed by NeoBrainX
parent c5008fe9de
commit 94a8536b8c
2 changed files with 46 additions and 35 deletions

View File

@ -135,7 +135,7 @@ void TextureCache::MakeRangeDynamic(u32 start_address, u32 size)
const int rangePosition = iter->second->IntersectsMemoryRange(start_address, size);
if (0 == rangePosition)
{
iter->second->hash = 0;
iter->second->SetHashes(TEXHASH_INVALID);
}
}
}
@ -190,8 +190,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
const unsigned int nativeH = height;
bool isPow2;
u64 hash_value = 0;
u64 texHash = 0;
u64 hash_value = TEXHASH_INVALID;
u64 texHash = TEXHASH_INVALID;
u32 texID = address;
u32 full_format = texformat;
const u32 texture_size = TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, texformat);
@ -252,7 +252,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
}
else
{
hash_value = 0;
hash_value = TEXHASH_INVALID;
}
}
else
@ -262,7 +262,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
}
else if ((entry->isRenderTarget || entry->isDynamic) && g_ActiveConfig.bCopyEFBToTexture)
{
hash_value = 0;
hash_value = TEXHASH_INVALID;
}
if (((entry->isRenderTarget || entry->isDynamic) && hash_value == entry->hash && address == entry->addr)
@ -332,24 +332,15 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
// Sometimes, we can get around recreating a texture if only the number of mip levels gets changes
// e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states
// Thus, we don't update this member for every Load, but just whenever the texture gets recreated
entry->num_mipmaps = maxlevel;
entry->num_mipmaps = maxlevel; // TODO: Does this actually work? We can't really adjust mipmap settings per-stage...
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
}
entry->addr = address;
entry->format = full_format;
entry->size_in_bytes = texture_size;
entry->native_width = nativeW;
entry->native_height = nativeH;
entry->virtual_width = width;
entry->virtual_height = height;
entry->isRenderTarget = false;
entry->SetGeneralParameters(address, texture_size, full_format, entry->num_mipmaps);
entry->SetDimensions(nativeW, nativeH, width, height);
entry->SetEFBCopyParameters(false, texture_is_dynamic);
entry->isNonPow2 = false;
entry->isDynamic = texture_is_dynamic;
entry->oldpixel = *(u32*)ptr;
@ -657,21 +648,12 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
// create the texture
textures[dstAddr] = entry = g_texture_cache->CreateRenderTargetTexture(scaled_tex_w, scaled_tex_h);
entry->addr = dstAddr;
entry->hash = 0;
entry->native_width = tex_w;
entry->native_height = tex_h;
entry->virtual_width = scaled_tex_w;
entry->virtual_height = scaled_tex_h;
entry->format = dstFormat;
entry->num_mipmaps = 0;
entry->isRenderTarget = true;
// TODO: Using the wrong dstFormat, dumb...
entry->SetGeneralParameters(dstAddr, 0, dstFormat, 0);
entry->SetDimensions(tex_w, tex_h, scaled_tex_w, scaled_tex_h);
entry->SetEFBCopyParameters(true, false);
entry->SetHashes(TEXHASH_INVALID);
entry->isNonPow2 = true;
entry->isDynamic = false;
}
entry->frameCount = frameCount;

View File

@ -16,6 +16,8 @@ class TextureCache
public:
struct TCacheEntryBase
{
#define TEXHASH_INVALID 0
// common members
u32 addr;
u32 size_in_bytes;
@ -29,6 +31,33 @@ public:
unsigned int native_width, native_height; // Texture dimensions from the GameCube's point of view
unsigned int virtual_width, virtual_height; // Texture dimensions from OUR point of view - for hires textures or scaled EFB copies
void SetGeneralParameters(u32 addr, u32 size, u32 format, unsigned int num_mipmaps)
{
this->addr = addr;
this->size_in_bytes = size;
this->format = format;
this->num_mipmaps = num_mipmaps;
}
void SetDimensions(unsigned int native_width, unsigned int native_height, unsigned int virtual_width, unsigned int virtual_height)
{
this->native_width = native_width;
this->native_height = native_height;
this->virtual_width = virtual_width;
this->virtual_height = virtual_height;
}
void SetHashes(u64 hash/*, u32 pal_hash*/)
{
this->hash = hash;
//this->pal_hash = pal_hash;
}
void SetEFBCopyParameters(bool is_efb_copy, bool is_dynamic)
{
isRenderTarget = is_efb_copy;
isDynamic = is_dynamic;
}
// EFB copies
bool isRenderTarget; // copied from EFB