diff --git a/src/Config.cpp b/src/Config.cpp index c8ad24d2..7e292f49 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,8 +37,12 @@ void Config::resetToDefaults() generalEmulation.correctTexrectCoords = tcDisable; generalEmulation.enableNativeResTexrects = 0; generalEmulation.enableLegacyBlending = 0; - generalEmulation.enableFragmentDepthWrite = 1; generalEmulation.hacks = 0; +#ifdef GLES2 + generalEmulation.enableFragmentDepthWrite = 0; +#else + generalEmulation.enableFragmentDepthWrite = 1; +#endif #ifdef ANDROID generalEmulation.forcePolygonOffset = 0; generalEmulation.polygonOffsetFactor = 0.0f; diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 00b91df8..68af999a 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -384,7 +384,8 @@ CachedTexture * FrameBuffer::getTexture(u32 _t) { const bool getDepthTexture = m_isDepthBuffer && gDP.colorImage.address == gDP.depthImageAddress && - m_pDepthBuffer != nullptr; + m_pDepthBuffer != nullptr && + (config.generalEmulation.hacks & hack_ZeldaMM) != 0; CachedTexture *pTexture = getDepthTexture ? m_pDepthBuffer->m_pDepthBufferTexture : m_pTexture; const u32 shift = (gSP.textureTile[_t]->imageAddress - m_startAddress) >> (m_size - 1); diff --git a/src/OGL3X/GLSLCombiner_ogl3x.cpp b/src/OGL3X/GLSLCombiner_ogl3x.cpp index c231beeb..5899890f 100644 --- a/src/OGL3X/GLSLCombiner_ogl3x.cpp +++ b/src/OGL3X/GLSLCombiner_ogl3x.cpp @@ -590,13 +590,14 @@ void ShaderCombiner::updateRenderState(bool _bForce) void ShaderCombiner::updateRenderTarget(bool _bForce) { + if (config.generalEmulation.enableFragmentDepthWrite == 0) + return; + int renderTarget = 0; if (gDP.colorImage.address == gDP.depthImageAddress && (config.generalEmulation.hacks & hack_ZeldaMM) == 0 ) { - FrameBuffer * pCurBuf = frameBufferList().getCurrent(); - if (pCurBuf != nullptr && pCurBuf->m_pDepthBuffer != nullptr) - renderTarget = gDP.otherMode.depthCompare + 1; + renderTarget = gDP.otherMode.depthCompare + 1; } m_uniforms.uRenderTarget.set(renderTarget, _bForce); } diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index 106de598..4c6edf4a 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -1175,11 +1175,16 @@ void OGLRender::_updateStates(RENDER_STATE _renderState) const #ifndef GLES2 if (gDP.colorImage.address == gDP.depthImageAddress && + config.generalEmulation.enableFragmentDepthWrite != 0 && (config.generalEmulation.hacks & hack_ZeldaMM) == 0 ) { - FrameBuffer * pCurBuf = frameBufferList().getCurrent(); - if (pCurBuf != nullptr && pCurBuf->m_pDepthBuffer != nullptr) { - if (gDP.otherMode.depthCompare != 0) { + // Current render target is depth buffer. + // Shader will set gl_FragDepth to shader color, see ShaderCombiner ctor + // Here we enable depth buffer write. + if (gDP.otherMode.depthCompare != 0) { + // Render to depth buffer with depth compare. Need to get copy of current depth buffer. + FrameBuffer * pCurBuf = frameBufferList().getCurrent(); + if (pCurBuf != nullptr && pCurBuf->m_pDepthBuffer != nullptr) { CachedTexture * pDepthTexture = pCurBuf->m_pDepthBuffer->copyDepthBufferTexture(pCurBuf); if (pDepthTexture == nullptr) return; @@ -1189,11 +1194,11 @@ void OGLRender::_updateStates(RENDER_STATE _renderState) const glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - glDepthMask(TRUE); - gDP.changed |= CHANGED_RENDERMODE; } + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + glDepthMask(TRUE); + gDP.changed |= CHANGED_RENDERMODE; } #endif } diff --git a/src/gDP.cpp b/src/gDP.cpp index 92c8895d..406b88e0 100644 --- a/src/gDP.cpp +++ b/src/gDP.cpp @@ -770,7 +770,8 @@ void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry ) // Game may use depth texture as auxilary color texture. Example: Mario Tennis // If color is not depth clear color, that is most likely the case if (gDP.fillColor.color == DepthClearColor) { - if ((ulx == 0) && (uly == 0) && (lrx == gDP.scissor.lrx) && (lry == gDP.scissor.lry)) { + if (config.generalEmulation.enableFragmentDepthWrite == 0 || + (ulx == 0 && uly == 0 && lrx == gDP.scissor.lrx && lry == gDP.scissor.lry)) { gDPFillRDRAM(gDP.colorImage.address, ulx, uly, lrx, lry, gDP.colorImage.width, gDP.colorImage.size, gDP.fillColor.color); render.clearDepthBuffer(uly, lry); bBufferCleared = true; @@ -778,9 +779,12 @@ void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry ) } } else if (gDP.fillColor.color == DepthClearColor && gDP.otherMode.cycleType == G_CYC_FILL) { depthBufferList().saveBuffer(gDP.colorImage.address); - gDPFillRDRAM(gDP.colorImage.address, ulx, uly, lrx, lry, gDP.colorImage.width, gDP.colorImage.size, gDP.fillColor.color); - render.clearDepthBuffer(uly, lry); - bBufferCleared = true; + if (config.generalEmulation.enableFragmentDepthWrite == 0 || + (ulx == 0 && uly == 0 && lrx == gDP.scissor.lrx && lry == gDP.scissor.lry)) { + gDPFillRDRAM(gDP.colorImage.address, ulx, uly, lrx, lry, gDP.colorImage.width, gDP.colorImage.size, gDP.fillColor.color); + render.clearDepthBuffer(uly, lry); + bBufferCleared = true; + } } if (!bBufferCleared) {