From 4b2e04b862ef0e5166f1c855148a44bc7c88f381 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 6 May 2015 21:31:05 +0200 Subject: OGL: Change the depth buffer type to GL_FLOAT. --- Source/Core/VideoBackends/OGL/Render.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index a1f63c6d32..638192df44 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -914,7 +914,7 @@ void ClearEFBCache() } } -void Renderer::UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const u32* data) +void Renderer::UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const void* data) { u32 cacheType = (type == PEEK_Z ? 0 : 1); @@ -936,7 +936,18 @@ void Renderer::UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRec u32 xEFB = efbPixelRc.left + xCache; u32 xPixel = (EFBToScaledX(xEFB) + EFBToScaledX(xEFB + 1)) / 2; u32 xData = xPixel - targetPixelRc.left; - s_efbCache[cacheType][cacheRectIdx][yCache * EFB_CACHE_RECT_SIZE + xCache] = data[yData * targetPixelRcWidth + xData]; + u32 value; + if (type == PEEK_Z) + { + float* ptr = (float*)data; + value = (u32)(ptr[yData * targetPixelRcWidth + xData] * 16777216.0f); + } + else + { + u32* ptr = (u32*)data; + value = ptr[yData * targetPixelRcWidth + xData]; + } + s_efbCache[cacheType][cacheRectIdx][yCache * EFB_CACHE_RECT_SIZE + xCache] = value; } } @@ -1005,10 +1016,10 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) g_renderer->RestoreAPIState(); } - u32* depthMap = new u32[targetPixelRcWidth * targetPixelRcHeight]; + float* depthMap = new float[targetPixelRcWidth * targetPixelRcHeight]; glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight, - GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, depthMap); + GL_DEPTH_COMPONENT, GL_FLOAT, depthMap); UpdateEFBCache(type, cacheRectIdx, efbPixelRc, targetPixelRc, depthMap); @@ -1019,18 +1030,10 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) u32 yRect = y % EFB_CACHE_RECT_SIZE; z = s_efbCache[0][cacheRectIdx][yRect * EFB_CACHE_RECT_SIZE + xRect]; - // Scale the 32-bit value returned by glReadPixels to a 24-bit - // value (GC uses a 24-bit Z-buffer). - // TODO: in RE0 this value is often off by one, which causes lighting to disappear + // if Z is in 16 bit format you must return a 16 bit integer if (bpmem.zcontrol.pixel_format == PEControl::RGB565_Z16) - { - // if Z is in 16 bit format you must return a 16 bit integer - z = z >> 16; - } - else - { z = z >> 8; - } + return z; } -- cgit v1.2.3 From 1a409a2e16b46d88e3dbd6e0b01eb2145050383b Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 7 May 2015 00:37:58 +0200 Subject: VideoBackends: Clamp Z peek values. --- Source/Core/VideoBackends/OGL/Render.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 638192df44..50a166e2da 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -12,6 +12,7 @@ #include "Common/Atomic.h" #include "Common/CommonPaths.h" #include "Common/FileUtil.h" +#include "Common/MathUtil.h" #include "Common/StringUtil.h" #include "Common/Thread.h" #include "Common/Timer.h" @@ -940,7 +941,7 @@ void Renderer::UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRec if (type == PEEK_Z) { float* ptr = (float*)data; - value = (u32)(ptr[yData * targetPixelRcWidth + xData] * 16777216.0f); + value = MathUtil::Clamp((u32)(ptr[yData * targetPixelRcWidth + xData] * 16777216.0f), 0, 0xFFFFFF); } else { -- cgit v1.2.3 From 84a5f4abb07d01fdc32ff6cf96e2a4d682b07e06 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 7 May 2015 23:29:16 +0200 Subject: VideoBackends: Use the new divisor when clearing the depth buffer. --- Source/Core/VideoBackends/OGL/Render.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 50a166e2da..1c0e3df4c2 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1139,7 +1139,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) ResetAPIState(); glDepthMask(GL_TRUE); - glClearDepthf(float(poke_data & 0xFFFFFF) / float(0xFFFFFF)); + glClearDepthf(float(poke_data & 0xFFFFFF) / 16777216.0f); glEnable(GL_SCISSOR_TEST); glScissor(targetPixelRc.left, targetPixelRc.bottom, targetPixelRc.GetWidth(), targetPixelRc.GetHeight()); @@ -1273,7 +1273,7 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE // depth glDepthMask(zEnable ? GL_TRUE : GL_FALSE); - glClearDepthf(float(z & 0xFFFFFF) / float(0xFFFFFF)); + glClearDepthf(float(z & 0xFFFFFF) / 16777216.0f); // Update rect for clearing the picture glEnable(GL_SCISSOR_TEST); -- cgit v1.2.3