diff --git a/DepthBuffer.cpp b/DepthBuffer.cpp index 9c8c1d7b..d39cafd5 100644 --- a/DepthBuffer.cpp +++ b/DepthBuffer.cpp @@ -143,12 +143,12 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture glBindTexture(GL_TEXTURE_2D, 0); } -void DepthBuffer::setDepthAttachment() +void DepthBuffer::setDepthAttachment(GLenum _target) { if (config.video.multisampling != 0) - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, m_pDepthBufferTexture->glName, 0); + glFramebufferTexture2D(_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, m_pDepthBufferTexture->glName, 0); else - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pDepthBufferTexture->glName, 0); + glFramebufferTexture2D(_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pDepthBufferTexture->glName, 0); m_resolved = false; } diff --git a/DepthBuffer.h b/DepthBuffer.h index 408941c6..e5eccbe0 100644 --- a/DepthBuffer.h +++ b/DepthBuffer.h @@ -13,7 +13,7 @@ struct DepthBuffer void initDepthBufferTexture(FrameBuffer * _pBuffer); CachedTexture * resolveDepthBufferTexture(FrameBuffer * _pBuffer); - void setDepthAttachment(); + void setDepthAttachment(GLenum _target); void activateDepthBufferTexture(FrameBuffer * _pBuffer); void bindDepthImageTexture(); diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 09b748bf..0452a601 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -457,7 +457,7 @@ void FrameBufferList::attachDepthBuffer() pDepthBuffer->initDepthImageTexture(m_pCurrent); pDepthBuffer->initDepthBufferTexture(m_pCurrent); m_pCurrent->m_pDepthBuffer = pDepthBuffer; - pDepthBuffer->setDepthAttachment(); + pDepthBuffer->setDepthAttachment(GL_DRAW_FRAMEBUFFER); if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0) pDepthBuffer->bindDepthImageTexture(); } else diff --git a/gSP.cpp b/gSP.cpp index 7504a855..31c9451a 100644 --- a/gSP.cpp +++ b/gSP.cpp @@ -2100,7 +2100,7 @@ void gSPObjRectangleR(u32 sp) gSPDrawObjRect(objCoords); } -#ifdef GL_IMAGE_TEXTURES_SUPPORT +#ifndef GLES2 static void _copyDepthBuffer() { @@ -2115,14 +2115,11 @@ void _copyDepthBuffer() FrameBuffer * pTmpBuffer = frameBufferList().findTmpBuffer(frameBufferList().getCurrent()->m_startAddress); if (pTmpBuffer == NULL) return; - DepthBuffer * pTmpBufferDepth = pTmpBuffer->m_pDepthBuffer; - pTmpBuffer->m_pDepthBuffer = depthBufferList().findBuffer(gSP.bgImage.address); - if (pTmpBufferDepth == NULL || pTmpBuffer->m_pDepthBuffer == NULL) + DepthBuffer * pCopyBufferDepth = depthBufferList().findBuffer(gSP.bgImage.address); + if (pCopyBufferDepth == NULL) return; glBindFramebuffer(GL_READ_FRAMEBUFFER, pTmpBuffer->m_FBO); - pTmpBuffer->m_pDepthBuffer->setDepthAttachment(); - GLuint attachment = GL_COLOR_ATTACHMENT0; - glDrawBuffers(1, &attachment); + pCopyBufferDepth->setDepthAttachment(GL_READ_FRAMEBUFFER); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO); OGLVideo & ogl = video(); glBlitFramebuffer( @@ -2131,12 +2128,13 @@ void _copyDepthBuffer() GL_DEPTH_BUFFER_BIT, GL_NEAREST ); // Restore objects - pTmpBufferDepth->setDepthAttachment(); + if (pTmpBuffer->m_pDepthBuffer != NULL) + pTmpBuffer->m_pDepthBuffer->setDepthAttachment(GL_READ_FRAMEBUFFER); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); // Set back current depth buffer depthBufferList().saveBuffer(gDP.depthImageAddress); } -#endif // GL_IMAGE_TEXTURES_SUPPORT +#endif // GLES2 static void _loadBGImage(const uObjScaleBg * _bgInfo, bool _loadScale)