From 811cfb059eb968e0b6fb6a64597863cc667ca682 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Sat, 6 Feb 2010 16:05:48 +0000 Subject: [PATCH] D3D and Opengl: reverted a tiny leftover of my safe texture cache commit D3D renamed the SSAA modes to use samples as MSAA now they are 2,25x and 4x. OpenGL: fixed a nasty logical bug introduced in 4984 that causes efb corruption when efb to texture is used re enabled shader caching as it was not producing errors. fixed efb misalignment caused by integer rounding still a bit misaligned but many games will look better now git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5020 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp | 4 ++-- Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp | 2 +- .../Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp | 10 ++++++---- .../Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp | 8 ++++---- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 4 ++-- Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp | 9 ++++++--- .../Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp | 9 ++++----- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp index f1db382ce5..c82b1d9a0b 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp @@ -163,8 +163,8 @@ void Enumerate() // Add SuperSamples modes a.aa_levels.push_back(AALevel("None", D3DMULTISAMPLE_NONE, 0)); - a.aa_levels.push_back(AALevel("1.5x SSAA", D3DMULTISAMPLE_NONE, 0)); - a.aa_levels.push_back(AALevel("2x SSAA", D3DMULTISAMPLE_NONE, 0)); + a.aa_levels.push_back(AALevel("2.25x SSAA", D3DMULTISAMPLE_NONE, 0)); + a.aa_levels.push_back(AALevel("4x SSAA", D3DMULTISAMPLE_NONE, 0)); //Add multisample modes DWORD qlevels = 0; if (D3DERR_NOTAVAILABLE != D3D::D3D->CheckDeviceMultiSampleType( diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp index 3c7ba3d8d3..660edd3b75 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp @@ -166,7 +166,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width, // each other stored in a single texture, and uses the palette to make different characters // visible or invisible. Thus, unless we want to recreate the textures for every drawn character, // we must make sure that texture with different tluts get different IDs. - u64 tlutHash = TexDecoder_GetTlutHash(&texMem[tlutaddr], TexDecoder_GetPaletteSize(tex_format)); + u64 tlutHash = TexDecoder_GetTlutHash(&texMem[tlutaddr], (tex_format == GX_TF_C4) ? 32 : 128); texHash ^= tlutHash; if (g_ActiveConfig.bSafeTextureCache) texID ^= tlutHash; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 527f0e9359..0e206b2f50 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -265,10 +265,12 @@ GLuint FramebufferManager::GetEFBDepthTexture(const EFBRectangle& sourceRc) cons TargetRectangle FramebufferManager::ConvertEFBRectangle(const EFBRectangle& rc) const { TargetRectangle result; - result.left = rc.left * Renderer::GetTargetWidth() / EFB_WIDTH; - result.top = Renderer::GetTargetHeight() - (rc.top * Renderer::GetTargetHeight() / EFB_HEIGHT); - result.right = rc.right * Renderer::GetTargetWidth() / EFB_WIDTH ; - result.bottom = Renderer::GetTargetHeight() - (rc.bottom * Renderer::GetTargetHeight() / EFB_HEIGHT); + float XScale = Renderer::GetTargetScaleX(); + float YScale = Renderer::GetTargetScaleY(); + result.left = rc.left * XScale; + result.top = Renderer::GetTargetHeight() - (rc.top * YScale); + result.right = rc.right * XScale ; + result.bottom = Renderer::GetTargetHeight() - (rc.bottom * YScale); return result; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 159691cc6e..9603fccf79 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -298,7 +298,7 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr void PixelShaderCache::DisableShader() { CurrentShader = 0; - //if(ShaderEnabled) + if(ShaderEnabled) { glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); glDisable(GL_FRAGMENT_PROGRAM_ARB); @@ -311,7 +311,7 @@ void PixelShaderCache::DisableShader() void PixelShaderCache::SetCurrentShader(GLuint Shader) { //The caching here breakes Super Mario Sunshine i'm still trying to figure out wy - //if(ShaderEnabled /*&& CurrentShader != Shader*/) + if(ShaderEnabled /*&& CurrentShader != Shader*/) { CurrentShader = Shader; glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); @@ -321,13 +321,13 @@ void PixelShaderCache::SetCurrentShader(GLuint Shader) //Enable Fragment program and bind initial program void PixelShaderCache::EnableShader(GLuint Shader) { - //if(!ShaderEnabled) + if(!ShaderEnabled) { glEnable(GL_FRAGMENT_PROGRAM_ARB); ShaderEnabled = true; CurrentShader = 0; } - //if(CurrentShader != Shader) + if(CurrentShader != Shader) { CurrentShader = Shader; glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index e0de796645..550c0373e1 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -172,7 +172,7 @@ void SetDefaultRectTexParams() if (glGetError() != GL_NO_ERROR) { glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); - GL_REPORT_ERROR(); + GL_REPORT_ERRORD(); } glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -1083,7 +1083,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) bool last_copy_efb_to_ram = !g_ActiveConfig.bCopyEFBToTexture; UpdateActiveConfig(); - if (last_copy_efb_to_ram != g_ActiveConfig.bCopyEFBToTexture) + if (last_copy_efb_to_ram != (!g_ActiveConfig.bCopyEFBToTexture)) TextureMngr::ClearRenderTargets(); // For testing zbuffer targets. diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp index 75a4526877..3460d69b0b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp @@ -275,7 +275,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width // each other stored in a single texture, and uses the palette to make different characters // visible or invisible. Thus, unless we want to recreate the textures for every drawn character, // we must make sure that texture with different tluts get different IDs. - u64 tlutHash = TexDecoder_GetTlutHash(&texMem[tlutaddr], TexDecoder_GetPaletteSize(tex_format)); + u64 tlutHash = TexDecoder_GetTlutHash(&texMem[tlutaddr], (tex_format == GX_TF_C4) ? 32 : 128); texHash ^= tlutHash; if (g_ActiveConfig.bSafeTextureCache) texID ^= tlutHash; @@ -301,6 +301,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width glEnable(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D); // entry.isRectangle ? TextureMngr::EnableTex2D(texstage) : TextureMngr::EnableTexRECT(texstage); glBindTexture(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D, entry.texture); + GL_REPORT_ERRORD(); if (entry.mode.hex != tm0.hex) entry.SetTextureParameters(tm0); //DebugLog("%cC addr: %08x | fmt: %i | e.hash: %08x | w:%04i h:%04i", g_ActiveConfig.bSafeTextureCache ? 'S' : 'U' @@ -315,6 +316,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width if (width == entry.w && height == entry.h && FullFormat == entry.fmt) { glBindTexture(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D, entry.texture); + GL_REPORT_ERRORD(); if (entry.mode.hex != tm0.hex) entry.SetTextureParameters(tm0); skip_texture_create = true; @@ -634,19 +636,20 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool { glGenTextures(1, (GLuint *)&entry.texture); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture); + GL_REPORT_ERRORD(); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, gl_iformat, w, h, 0, gl_format, gl_type, NULL); GL_REPORT_ERRORD(); } else { _assert_(entry.texture); - GL_REPORT_ERROR(); + GL_REPORT_ERRORD(); if (entry.w == w && entry.h == h && entry.isRectangle && entry.fmt == copyfmt) { glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture); // for some reason mario sunshine errors here... // Beyond Good and Evil does too, occasionally. - GL_REPORT_ERROR(); + GL_REPORT_ERRORD(); } else { // Delete existing texture. glDeleteTextures(1,(GLuint *)&entry.texture); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index d26e29777e..4cfe2caabf 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -246,7 +246,7 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr void VertexShaderCache::DisableShader() { - //if (ShaderEnabled) + if (ShaderEnabled) { CurrentShader = 0; glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); @@ -255,11 +255,10 @@ void VertexShaderCache::DisableShader() } } -// TODO: Why are these if statements commented out? void VertexShaderCache::SetCurrentShader(GLuint Shader) { - //if (ShaderEnabled && CurrentShader != Shader) + if (ShaderEnabled && CurrentShader != Shader) { CurrentShader = Shader; glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); @@ -268,13 +267,13 @@ void VertexShaderCache::SetCurrentShader(GLuint Shader) void VertexShaderCache::EnableShader(GLuint Shader) { - //if (!ShaderEnabled) + if (!ShaderEnabled) { glEnable(GL_VERTEX_PROGRAM_ARB); ShaderEnabled= true; CurrentShader = 0; } - //if (CurrentShader != Shader) + if (CurrentShader != Shader) { CurrentShader = Shader; glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);