mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Clarify texture cache code. Previously, there were THREE sets of texture dimensions, and it was hard to tell which set was for what purpose.
Now, there are two: Real dimensions: Width and height of the original GameCube texture Virtual dimensions: Width and height of the texture used by dolphin-emu's renderer git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6291 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -263,8 +263,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
|
|||||||
|
|
||||||
// TODO: Is the mipLevels check needed?
|
// TODO: Is the mipLevels check needed?
|
||||||
if (!entry->isRenderTarget &&
|
if (!entry->isRenderTarget &&
|
||||||
((!entry->isDynamic && width == entry->w && height == entry->h && full_format == entry->format && entry->mipLevels == maxlevel)
|
((!entry->isDynamic && width == entry->realW && height == entry->realH && full_format == entry->format && entry->mipLevels == maxlevel)
|
||||||
|| (entry->isDynamic && entry->w == width && entry->h == height)))
|
|| (entry->isDynamic && entry->realW == width && entry->realH == height)))
|
||||||
{
|
{
|
||||||
// reuse the texture
|
// reuse the texture
|
||||||
}
|
}
|
||||||
@ -319,11 +319,11 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
|
|||||||
entry->mipLevels = maxlevel;
|
entry->mipLevels = maxlevel;
|
||||||
entry->size_in_bytes = texture_size;
|
entry->size_in_bytes = texture_size;
|
||||||
|
|
||||||
entry->scaledW = entry->w = width;
|
entry->virtualW = width;
|
||||||
entry->scaledH = entry->h = height;
|
entry->virtualH = height;
|
||||||
|
|
||||||
entry->nativeH = nativeH;
|
entry->realW = nativeW;
|
||||||
entry->nativeW = nativeW;
|
entry->realH = nativeH;
|
||||||
|
|
||||||
entry->isRenderTarget = false;
|
entry->isRenderTarget = false;
|
||||||
entry->isNonPow2 = false;
|
entry->isNonPow2 = false;
|
||||||
@ -608,8 +608,8 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer,
|
|||||||
TCacheEntryBase *entry = textures[address];
|
TCacheEntryBase *entry = textures[address];
|
||||||
if (entry)
|
if (entry)
|
||||||
{
|
{
|
||||||
if ((entry->isRenderTarget && entry->scaledW == scaled_tex_w && entry->scaledH == scaled_tex_h)
|
if ((entry->isRenderTarget && entry->virtualW == scaled_tex_w && entry->virtualH == scaled_tex_h)
|
||||||
|| (entry->isDynamic && entry->w == tex_w && entry->h == tex_h))
|
|| (entry->isDynamic && entry->realW == tex_w && entry->realH == tex_h))
|
||||||
{
|
{
|
||||||
texture_is_dynamic = entry->isDynamic;
|
texture_is_dynamic = entry->isDynamic;
|
||||||
}
|
}
|
||||||
@ -635,11 +635,11 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer,
|
|||||||
entry->addr = address;
|
entry->addr = address;
|
||||||
entry->hash = 0;
|
entry->hash = 0;
|
||||||
|
|
||||||
entry->w = entry->nativeW = tex_w;
|
entry->realW = tex_w;
|
||||||
entry->h = entry->nativeH = tex_h;
|
entry->realH = tex_h;
|
||||||
|
|
||||||
entry->scaledW = scaled_tex_w;
|
entry->virtualW = scaled_tex_w;
|
||||||
entry->scaledH = scaled_tex_h;
|
entry->virtualH = scaled_tex_h;
|
||||||
|
|
||||||
entry->format = copyfmt;
|
entry->format = copyfmt;
|
||||||
entry->mipLevels = 0;
|
entry->mipLevels = 0;
|
||||||
|
@ -24,9 +24,15 @@ public:
|
|||||||
u32 format;
|
u32 format;
|
||||||
|
|
||||||
int frameCount;
|
int frameCount;
|
||||||
unsigned int w, h, mipLevels;
|
|
||||||
// TODO: it looks like scaledW/H can be removed and w/h can be used in their place
|
unsigned int realW, realH; // Texture dimensions from the GameCube's point of view
|
||||||
unsigned int scaledW, scaledH, nativeW, nativeH;
|
unsigned int virtualW, virtualH; // Texture dimensions from OUR point of view
|
||||||
|
// Real and virtual dimensions are usually the same, but may be
|
||||||
|
// different if e.g. we use high-res textures. Then, realW,realH will
|
||||||
|
// be the dimensions of the original GameCube texture and
|
||||||
|
// virtualW,virtualH will be the dimensions of the high-res texture.
|
||||||
|
|
||||||
|
unsigned int mipLevels;
|
||||||
|
|
||||||
bool isRenderTarget;
|
bool isRenderTarget;
|
||||||
bool isDynamic; // mofified from cpu
|
bool isDynamic; // mofified from cpu
|
||||||
|
@ -121,7 +121,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
|||||||
bool bIsIntensityFmt, u32 copyfmt)
|
bool bIsIntensityFmt, u32 copyfmt)
|
||||||
{
|
{
|
||||||
// stretch picture with increased internal resolution
|
// stretch picture with increased internal resolution
|
||||||
const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)scaledW, (float)scaledH);
|
const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)virtualW, (float)virtualH);
|
||||||
D3D::context->RSSetViewports(1, &vp);
|
D3D::context->RSSetViewports(1, &vp);
|
||||||
|
|
||||||
// set transformation
|
// set transformation
|
||||||
|
@ -225,7 +225,7 @@ void VertexManager::vFlush()
|
|||||||
if (tentry)
|
if (tentry)
|
||||||
{
|
{
|
||||||
// 0s are probably for no manual wrapping needed.
|
// 0s are probably for no manual wrapping needed.
|
||||||
PixelShaderManager::SetTexDims(i, tentry->nativeW, tentry->nativeH, 0, 0);
|
PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ERROR_LOG(VIDEO, "error loading texture");
|
ERROR_LOG(VIDEO, "error loading texture");
|
||||||
|
@ -89,15 +89,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
|||||||
// Stretch picture with increased internal resolution
|
// Stretch picture with increased internal resolution
|
||||||
vp.X = 0;
|
vp.X = 0;
|
||||||
vp.Y = 0;
|
vp.Y = 0;
|
||||||
vp.Width = scaledW;
|
vp.Width = virtualW;
|
||||||
vp.Height = scaledH;
|
vp.Height = virtualH;
|
||||||
vp.MinZ = 0.0f;
|
vp.MinZ = 0.0f;
|
||||||
vp.MaxZ = 1.0f;
|
vp.MaxZ = 1.0f;
|
||||||
D3D::dev->SetViewport(&vp);
|
D3D::dev->SetViewport(&vp);
|
||||||
RECT destrect;
|
RECT destrect;
|
||||||
destrect.bottom = scaledH;
|
destrect.bottom = virtualH;
|
||||||
destrect.left = 0;
|
destrect.left = 0;
|
||||||
destrect.right = scaledW;
|
destrect.right = virtualW;
|
||||||
destrect.top = 0;
|
destrect.top = 0;
|
||||||
|
|
||||||
const float* const fConstAdd = colmat + 16; // fConstAdd is the last 4 floats of colmat
|
const float* const fConstAdd = colmat + 16; // fConstAdd is the last 4 floats of colmat
|
||||||
@ -133,7 +133,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
|||||||
|
|
||||||
D3D::drawShadedTexQuad(read_texture, &sourcerect,
|
D3D::drawShadedTexQuad(read_texture, &sourcerect,
|
||||||
Renderer::GetFullTargetWidth(), Renderer::GetFullTargetHeight(),
|
Renderer::GetFullTargetWidth(), Renderer::GetFullTargetHeight(),
|
||||||
scaledW, scaledH,
|
virtualW, virtualH,
|
||||||
((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer) ?
|
((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer) ?
|
||||||
PixelShaderCache::GetDepthMatrixProgram(SSAAMode) :
|
PixelShaderCache::GetDepthMatrixProgram(SSAAMode) :
|
||||||
PixelShaderCache::GetColorMatrixProgram(SSAAMode),
|
PixelShaderCache::GetColorMatrixProgram(SSAAMode),
|
||||||
|
@ -144,7 +144,7 @@ void VertexManager::vFlush()
|
|||||||
if (tentry)
|
if (tentry)
|
||||||
{
|
{
|
||||||
// 0s are probably for no manual wrapping needed.
|
// 0s are probably for no manual wrapping needed.
|
||||||
PixelShaderManager::SetTexDims(i, tentry->nativeW, tentry->nativeH, 0, 0);
|
PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ERROR_LOG(VIDEO, "error loading texture");
|
ERROR_LOG(VIDEO, "error loading texture");
|
||||||
|
@ -125,7 +125,7 @@ bool TextureCache::TCacheEntry::Save(const char filename[])
|
|||||||
std::string tga_filename(filename);
|
std::string tga_filename(filename);
|
||||||
tga_filename.replace(tga_filename.size() - 3, 3, "tga");
|
tga_filename.replace(tga_filename.size() - 3, 3, "tga");
|
||||||
|
|
||||||
return SaveTexture(tga_filename.c_str(), GL_TEXTURE_2D, texture, w, h);
|
return SaveTexture(tga_filename.c_str(), GL_TEXTURE_2D, texture, realW, realH);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
||||||
@ -298,7 +298,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
|||||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
||||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture);
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture);
|
||||||
|
|
||||||
glViewport(0, 0, scaledW, scaledH);
|
glViewport(0, 0, virtualW, virtualH);
|
||||||
|
|
||||||
PixelShaderCache::SetCurrentShader(bFromZBuffer ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
|
PixelShaderCache::SetCurrentShader(bFromZBuffer ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
|
||||||
const float* const fConstAdd = colmat + 16; // fConstAdd is the last 4 floats of colmat
|
const float* const fConstAdd = colmat + 16; // fConstAdd is the last 4 floats of colmat
|
||||||
@ -344,7 +344,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
|||||||
{
|
{
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
SaveTexture(StringFromFormat("%sefb_frame_%i.tga", File::GetUserPath(D_DUMPTEXTURES_IDX),
|
SaveTexture(StringFromFormat("%sefb_frame_%i.tga", File::GetUserPath(D_DUMPTEXTURES_IDX),
|
||||||
count++).c_str(), GL_TEXTURE_2D, texture, w, h);
|
count++).c_str(), GL_TEXTURE_2D, texture, realW, realH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ void VertexManager::vFlush()
|
|||||||
if (tentry)
|
if (tentry)
|
||||||
{
|
{
|
||||||
// 0s are probably for no manual wrapping needed.
|
// 0s are probably for no manual wrapping needed.
|
||||||
PixelShaderManager::SetTexDims(i, tentry->nativeW, tentry->nativeH, 0, 0);
|
PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
|
||||||
|
|
||||||
if (g_ActiveConfig.iLog & CONF_SAVETEXTURES)
|
if (g_ActiveConfig.iLog & CONF_SAVETEXTURES)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user