From 33521936321fe1b4ce0735ccb2cc1f703a0014e1 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Mon, 8 Sep 2014 18:00:13 +0700 Subject: [PATCH] Depth buffer refactor --- DepthBuffer.cpp | 295 +++++++++++++++++++---------------------------- DepthBuffer.h | 36 +++--- FrameBuffer.cpp | 61 ++-------- FrameBuffer.h | 2 - GLSLCombiner.cpp | 4 +- OpenGL.cpp | 2 +- gDP.cpp | 4 +- gSP.cpp | 14 +-- 8 files changed, 160 insertions(+), 258 deletions(-) diff --git a/DepthBuffer.cpp b/DepthBuffer.cpp index ed7982a7..bae87b4b 100644 --- a/DepthBuffer.cpp +++ b/DepthBuffer.cpp @@ -12,195 +12,141 @@ const GLuint ZlutImageUnit = 0; const GLuint TlutImageUnit = 1; const GLuint depthImageUnit = 2; -void DepthBuffer_Init() +DepthBuffer::DepthBuffer() : m_address(0), m_width(0), m_renderbuf(0), m_FBO(0), m_pDepthTexture(NULL) { - DepthBufferList & dbList = depthBufferList(); - dbList.current = NULL; - dbList.top = NULL; - dbList.bottom = NULL; - dbList.numBuffers = 0; + glGenRenderbuffers(1, &m_renderbuf); + glGenFramebuffers(1, &m_FBO); } -void DepthBuffer_RemoveBottom() +DepthBuffer::DepthBuffer(DepthBuffer && _other) : + m_address(_other.m_address), m_width(_other.m_width), + m_renderbuf(_other.m_renderbuf), m_FBO(_other.m_FBO), m_pDepthTexture(_other.m_pDepthTexture) { - DepthBufferList & dbList = depthBufferList(); - DepthBuffer *newBottom = dbList.bottom->higher; - - if (dbList.bottom == dbList.top) - dbList.top = NULL; - - if (dbList.bottom->renderbuf != 0) - glDeleteRenderbuffers(1, &dbList.bottom->renderbuf); - if (dbList.bottom->depth_texture != NULL) - textureCache().removeFrameBufferTexture(dbList.bottom->depth_texture); - free( dbList.bottom ); - - dbList.bottom = newBottom; - - if (dbList.bottom != NULL) - dbList.bottom->lower = NULL; - - dbList.numBuffers--; + _other.m_renderbuf = 0; + _other.m_FBO = 0; + _other.m_pDepthTexture = NULL; } -void DepthBuffer_Remove( DepthBuffer *buffer ) +DepthBuffer::~DepthBuffer() { - DepthBufferList & dbList = depthBufferList(); - if ((buffer == dbList.bottom) && - (buffer == dbList.top)) - { - dbList.top = NULL; - dbList.bottom = NULL; - } - else if (buffer == dbList.bottom) - { - dbList.bottom = buffer->higher; - - if (dbList.bottom) - dbList.bottom->lower = NULL; - } - else if (buffer == dbList.top) - { - dbList.top = buffer->lower; - - if (dbList.top) - dbList.top->higher = NULL; - } - else - { - buffer->higher->lower = buffer->lower; - buffer->lower->higher = buffer->higher; - } - - if (buffer->renderbuf != 0) - glDeleteRenderbuffers(1, &buffer->renderbuf); - if (buffer->fbo != 0) - glDeleteFramebuffers(1, &buffer->fbo); - if (buffer->depth_texture != NULL) - textureCache().removeFrameBufferTexture(buffer->depth_texture); - free( buffer ); - - dbList.numBuffers--; + if (m_renderbuf != 0) + glDeleteRenderbuffers(1, &m_renderbuf); + if (m_FBO != 0) + glDeleteFramebuffers(1, &m_FBO); + if (m_pDepthTexture != NULL) + textureCache().removeFrameBufferTexture(m_pDepthTexture); } -void DepthBuffer_RemoveBuffer( u32 address ) +void DepthBuffer::initDepthTexture(FrameBuffer * _pBuffer) { - DepthBuffer *current = depthBufferList().bottom; +#ifndef GLES2 + if (m_pDepthTexture != NULL) + textureCache().removeFrameBufferTexture(m_pDepthTexture); + m_pDepthTexture = textureCache().addFrameBufferTexture(); - while (current != NULL) - { - if (current->address == address) - { - DepthBuffer_Remove( current ); + m_pDepthTexture->width = (u32)(_pBuffer->m_pTexture->width); + m_pDepthTexture->height = (u32)(_pBuffer->m_pTexture->height); + m_pDepthTexture->format = 0; + m_pDepthTexture->size = 2; + m_pDepthTexture->clampS = 1; + m_pDepthTexture->clampT = 1; + m_pDepthTexture->address = _pBuffer->m_startAddress; + m_pDepthTexture->clampWidth = _pBuffer->m_width; + m_pDepthTexture->clampHeight = _pBuffer->m_height; + m_pDepthTexture->frameBufferTexture = TRUE; + m_pDepthTexture->maskS = 0; + m_pDepthTexture->maskT = 0; + m_pDepthTexture->mirrorS = 0; + m_pDepthTexture->mirrorT = 0; + m_pDepthTexture->realWidth = (u32)pow2( m_pDepthTexture->width ); + m_pDepthTexture->realHeight = (u32)pow2( m_pDepthTexture->height ); + m_pDepthTexture->textureBytes = m_pDepthTexture->realWidth * m_pDepthTexture->realHeight * 4 * 4; // Width*Height*RGBA*sizeof(GL_RGBA32F) + textureCache().addFrameBufferTextureSize(m_pDepthTexture->textureBytes); + + glBindTexture( GL_TEXTURE_2D, m_pDepthTexture->glName ); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_pDepthTexture->realWidth, m_pDepthTexture->realHeight, 0, GL_RGBA, GL_FLOAT, NULL); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glBindTexture( GL_TEXTURE_2D, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pDepthTexture->glName, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_FBO); + _pBuffer->m_pDepthBuffer = this; + depthBufferList().clearBuffer(); +#else + depth_texture = NULL; +#endif // GLES2 +} + +void DepthBufferList::init() +{ + m_pCurrent = NULL; +} + +void DepthBufferList::destroy() +{ + m_pCurrent = NULL; + m_list.clear(); +} + +DepthBuffer * DepthBufferList::findBuffer(u32 _address) +{ + for (DepthBuffers::iterator iter = m_list.begin(); iter != m_list.end(); ++iter) + if (iter->m_address == _address) + return &(*iter); + return NULL; +} + +void DepthBufferList::removeBuffer(u32 _address ) +{ + for (DepthBuffers::iterator iter = m_list.begin(); iter != m_list.end(); ++iter) + if (iter->m_address == _address) { + m_list.erase(iter); return; } - current = current->higher; - } } -DepthBuffer *DepthBuffer_AddTop() +void DepthBufferList::saveBuffer(u32 _address) { - DepthBufferList & dbList = depthBufferList(); - DepthBuffer *newtop = (DepthBuffer*)malloc( sizeof( DepthBuffer ) ); - - newtop->lower = dbList.top; - newtop->higher = NULL; - newtop->renderbuf = 0; - newtop->fbo = 0; - - if (dbList.top) - dbList.top->higher = newtop; - - if (!dbList.bottom) - dbList.bottom = newtop; - - dbList.top = newtop; - - dbList.numBuffers++; - - return newtop; -} - -void DepthBuffer_MoveToTop( DepthBuffer *newtop ) -{ - DepthBufferList & dbList = depthBufferList(); - if (newtop == dbList.top) + if (!config.frameBufferEmulation.enable) return; - if (newtop == dbList.bottom) - { - dbList.bottom = newtop->higher; - dbList.bottom->lower = NULL; - } - else - { - newtop->higher->lower = newtop->lower; - newtop->lower->higher = newtop->higher; - } - - newtop->higher = NULL; - newtop->lower = dbList.top; - dbList.top->higher = newtop; - dbList.top = newtop; -} - -void DepthBuffer_Destroy() -{ - DepthBufferList & dbList = depthBufferList(); - while (dbList.bottom) - DepthBuffer_RemoveBottom(); - - dbList.top = dbList.bottom = dbList.current = NULL; -} - -void DepthBuffer_SetBuffer( u32 address ) -{ - DepthBufferList & dbList = depthBufferList(); - FrameBuffer * pFrameBuffer = frameBufferList().findBuffer(address); + FrameBuffer * pFrameBuffer = frameBufferList().findBuffer(_address); if (pFrameBuffer == NULL) pFrameBuffer = frameBufferList().getCurrent(); - DepthBuffer *current = dbList.top; + if (m_pCurrent == NULL || m_pCurrent->m_address != _address) + m_pCurrent = findBuffer(_address); - // Search through saved depth buffers - while (current != NULL) - { - if (current->address == address) - { - if (pFrameBuffer != NULL && current->width != pFrameBuffer->m_width) { - DepthBuffer_Remove( current ); - current = NULL; - break; - } - DepthBuffer_MoveToTop( current ); - break; - } - current = current->lower; + if (m_pCurrent != NULL && pFrameBuffer != NULL && m_pCurrent->m_width != pFrameBuffer->m_width) { + removeBuffer(_address); + m_pCurrent = NULL; } - if (current == NULL) { - current = DepthBuffer_AddTop(); + if (m_pCurrent == NULL) { + m_list.emplace_front(); + DepthBuffer & buffer = m_list.front(); - current->address = address; - current->width = pFrameBuffer != NULL ? pFrameBuffer->m_width : VI.width; - current->depth_texture = NULL; - if (config.frameBufferEmulation.enable) { - glGenRenderbuffers(1, ¤t->renderbuf); - glBindRenderbuffer(GL_RENDERBUFFER, current->renderbuf); + buffer.m_address = _address; + buffer.m_width = pFrameBuffer != NULL ? pFrameBuffer->m_width : VI.width; + buffer.m_pDepthTexture = NULL; + glBindRenderbuffer(GL_RENDERBUFFER, buffer.m_renderbuf); #ifndef GLES2 const GLenum format = GL_DEPTH_COMPONENT; #else const GLenum format = GL_DEPTH_COMPONENT24_OES; #endif - if (pFrameBuffer != NULL) - glRenderbufferStorage(GL_RENDERBUFFER, format, pFrameBuffer->m_pTexture->realWidth, pFrameBuffer->m_pTexture->realHeight); - else - glRenderbufferStorage(GL_RENDERBUFFER, format, (u32)pow2(OGL.width), (u32)pow2(OGL.height)); - } + if (pFrameBuffer != NULL) + glRenderbufferStorage(GL_RENDERBUFFER, format, pFrameBuffer->m_pTexture->realWidth, pFrameBuffer->m_pTexture->realHeight); + else + glRenderbufferStorage(GL_RENDERBUFFER, format, (u32)pow2(OGL.width), (u32)pow2(OGL.height)); + + m_pCurrent = &buffer; } - if (config.frameBufferEmulation.enable) { - frameBufferList().attachDepthBuffer(); + frameBufferList().attachDepthBuffer(); #ifdef DEBUG DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "DepthBuffer_SetBuffer( 0x%08X ); color buffer is 0x%08X\n", @@ -208,37 +154,30 @@ void DepthBuffer_SetBuffer( u32 address ) ); #endif - } - dbList.current = current; } -DepthBuffer *DepthBuffer_FindBuffer( u32 address ) +void DepthBufferList::clearBuffer() { - DepthBufferList & dbList = depthBufferList(); - DepthBuffer *current = dbList.top; - - while (current) - { - if (current->address == address) - return current; - current = current->lower; - } - - return NULL; -} - -void DepthBuffer_ClearBuffer() { #ifndef GLES2 if (!OGL.bImageTexture) return; - DepthBuffer *current = depthBufferList().top; - if (current == NULL || current->fbo == 0) + if (m_pCurrent == NULL || m_pCurrent->m_FBO == 0) return; float color[4] = {1.0f, 1.0f, 0.0f, 1.0f}; glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current->fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_FBO); OGL_DrawRect(0,0,VI.width, VI.height, color); - glBindImageTexture(depthImageUnit, current->depth_texture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); + glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO); #endif // GLES2 } + +void DepthBuffer_Init() +{ + depthBufferList().init(); +} + +void DepthBuffer_Destroy() +{ + depthBufferList().destroy(); +} diff --git a/DepthBuffer.h b/DepthBuffer.h index a11113d6..a0c3f31c 100644 --- a/DepthBuffer.h +++ b/DepthBuffer.h @@ -6,18 +6,27 @@ struct DepthBuffer { - DepthBuffer *higher, *lower; + DepthBuffer(); + DepthBuffer(DepthBuffer && _other); + ~DepthBuffer(); + void initDepthTexture(FrameBuffer * _pBuffer); - u32 address, width; - GLuint renderbuf; - CachedTexture *depth_texture; - GLuint fbo; + u32 m_address, m_width; + GLuint m_renderbuf; + GLuint m_FBO; + CachedTexture *m_pDepthTexture; }; -struct DepthBufferList +class DepthBufferList { - DepthBuffer *top, *bottom, *current; - int numBuffers; +public: + void init(); + void destroy(); + void saveBuffer(u32 _address); + void removeBuffer(u32 _address); + void clearBuffer(); + DepthBuffer *findBuffer(u32 _address); + DepthBuffer * getCurrent() const {return m_pCurrent;} static DepthBufferList & get() { @@ -26,8 +35,12 @@ struct DepthBufferList } private: - DepthBufferList() : current(NULL) {} + DepthBufferList() : m_pCurrent(NULL) {} DepthBufferList(const FrameBufferList &); + + typedef std::list DepthBuffers; + DepthBuffers m_list; + DepthBuffer *m_pCurrent; }; inline @@ -42,9 +55,4 @@ extern const GLuint depthImageUnit; void DepthBuffer_Init(); void DepthBuffer_Destroy(); -void DepthBuffer_SetBuffer( u32 address ); -void DepthBuffer_RemoveBuffer( u32 address ); -void DepthBuffer_ClearBuffer(); -DepthBuffer *DepthBuffer_FindBuffer( u32 address ); - #endif diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 2332876f..be87342c 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -273,61 +273,18 @@ void FrameBufferList::removeBuffer(u32 _address ) } } -void FrameBufferList::_initDepthTexture() -{ -#ifndef GLES2 - DepthBufferList & dbList = depthBufferList(); - dbList.top->depth_texture = textureCache().addFrameBufferTexture(); - - dbList.top->depth_texture->width = (u32)(m_pCurrent->m_width * OGL.scaleX); - dbList.top->depth_texture->height = (u32)(m_pCurrent->m_height * OGL.scaleY); - dbList.top->depth_texture->format = 0; - dbList.top->depth_texture->size = 2; - dbList.top->depth_texture->clampS = 1; - dbList.top->depth_texture->clampT = 1; - dbList.top->depth_texture->address = m_pCurrent->m_startAddress; - dbList.top->depth_texture->clampWidth = m_pCurrent->m_width; - dbList.top->depth_texture->clampHeight = m_pCurrent->m_height; - dbList.top->depth_texture->frameBufferTexture = TRUE; - dbList.top->depth_texture->maskS = 0; - dbList.top->depth_texture->maskT = 0; - dbList.top->depth_texture->mirrorS = 0; - dbList.top->depth_texture->mirrorT = 0; - dbList.top->depth_texture->realWidth = (u32)pow2( dbList.top->depth_texture->width ); - dbList.top->depth_texture->realHeight = (u32)pow2( dbList.top->depth_texture->height ); - dbList.top->depth_texture->textureBytes = dbList.top->depth_texture->realWidth * dbList.top->depth_texture->realHeight * 2; - textureCache().addFrameBufferTextureSize(dbList.top->depth_texture->textureBytes); - - glBindTexture( GL_TEXTURE_2D, dbList.top->depth_texture->glName ); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, dbList.top->depth_texture->realWidth, dbList.top->depth_texture->realHeight, 0, GL_RGBA, GL_FLOAT, NULL); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - glBindTexture( GL_TEXTURE_2D, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glGenFramebuffers(1, &dbList.top->fbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dbList.top->fbo); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dbList.top->depth_texture->glName, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_FBO); - m_pCurrent->m_pDepthBuffer = dbList.top; - DepthBuffer_ClearBuffer(); -#else - dbList.top->depth_texture = NULL; -#endif // GLES2 -} - void FrameBufferList::attachDepthBuffer() { - DepthBufferList & dbList = depthBufferList(); - if (m_pCurrent != NULL && m_pCurrent->m_FBO > 0 && dbList.top != NULL && dbList.top->renderbuf > 0) { - if (dbList.top->depth_texture == NULL) - _initDepthTexture(); - m_pCurrent->m_pDepthBuffer = dbList.top; - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, dbList.top->renderbuf); + DepthBuffer * pDepthBuffer = depthBufferList().getCurrent(); + if (m_pCurrent != NULL && m_pCurrent->m_FBO > 0 && pDepthBuffer != NULL && pDepthBuffer->m_renderbuf > 0) { + if (pDepthBuffer->m_pDepthTexture == NULL || pDepthBuffer->m_pDepthTexture->width != m_pCurrent->m_pTexture->width) + pDepthBuffer->initDepthTexture(m_pCurrent); + m_pCurrent->m_pDepthBuffer = pDepthBuffer; + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pDepthBuffer->m_renderbuf); #ifndef GLES2 GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT }; glDrawBuffers(2, attachments); - glBindImageTexture(depthImageUnit, dbList.top->depth_texture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); + glBindImageTexture(depthImageUnit, pDepthBuffer->m_pDepthTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); #endif assert(checkFBO()); } else if (m_pCurrent != NULL) { @@ -709,8 +666,8 @@ void DepthBufferToRDRAM::CopyToRDRAM( u32 address) { return; DepthBuffer * pDepthBuffer = pBuffer->m_pDepthBuffer; - address = pDepthBuffer->address; - glBindFramebuffer(GL_READ_FRAMEBUFFER, pDepthBuffer->fbo); + address = pDepthBuffer->m_address; + glBindFramebuffer(GL_READ_FRAMEBUFFER, pDepthBuffer->m_FBO); glReadBuffer(GL_COLOR_ATTACHMENT0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO); GLuint attachment = GL_COLOR_ATTACHMENT0; diff --git a/FrameBuffer.h b/FrameBuffer.h index dac24cba..9b4546b9 100644 --- a/FrameBuffer.h +++ b/FrameBuffer.h @@ -49,8 +49,6 @@ private: FrameBufferList() : m_pCurrent(NULL), m_drawBuffer(GL_BACK) {} FrameBufferList(const FrameBufferList &); - void _initDepthTexture(); - typedef std::list FrameBuffers; FrameBuffers m_list; FrameBuffer * m_pCurrent; diff --git a/GLSLCombiner.cpp b/GLSLCombiner.cpp index 8b2636e8..7ed1842d 100644 --- a/GLSLCombiner.cpp +++ b/GLSLCombiner.cpp @@ -748,7 +748,7 @@ void GLSL_RenderDepth() { glPushAttrib( GL_ENABLE_BIT | GL_VIEWPORT_BIT ); glActiveTexture( GL_TEXTURE0 ); - glBindTexture(GL_TEXTURE_2D, pBuffer->m_pDepthBuffer->depth_texture->glName); + glBindTexture(GL_TEXTURE_2D, pBuffer->m_pDepthBuffer->m_pDepthTexture->glName); // glBindTexture(GL_TEXTURE_2D, g_zlut_tex); CombinerInfo::get().setCombine( EncodeCombineMode( 0, 0, 0, TEXEL0, 0, 0, 0, 1, 0, 0, 0, TEXEL0, 0, 0, 0, 1 ) ); @@ -795,7 +795,7 @@ void GLSL_RenderDepth() { OGL_SwapBuffers(); #endif glBindFramebuffer(GL_DRAW_FRAMEBUFFER, pBuffer->m_FBO); - glBindImageTexture(depthImageUnit, pBuffer->m_pDepthBuffer->depth_texture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); + glBindImageTexture(depthImageUnit, pBuffer->m_pDepthBuffer->m_pDepthTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); glLoadIdentity(); diff --git a/OpenGL.cpp b/OpenGL.cpp index 095953ec..5a26bc47 100644 --- a/OpenGL.cpp +++ b/OpenGL.cpp @@ -1213,7 +1213,7 @@ void OGL_ClearDepthBuffer() if (config.frameBufferEmulation.enable && frameBufferList().getCurrent() == NULL) return; - DepthBuffer_ClearBuffer(); + depthBufferList().clearBuffer(); OGL_UpdateStates(); glDisable( GL_SCISSOR_TEST ); diff --git a/gDP.cpp b/gDP.cpp index 53cb8ad1..1db7c426 100644 --- a/gDP.cpp +++ b/gDP.cpp @@ -325,7 +325,7 @@ void gDPSetTextureImage( u32 format, u32 size, u32 width, u32 address ) void gDPSetDepthImage( u32 address ) { address = RSP_SegmentToPhysical( address ); - DepthBuffer_SetBuffer( address ); + depthBufferList().saveBuffer(address); gDP.depthImageAddress = address; #ifdef DEBUG @@ -790,7 +790,7 @@ void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry ) return; } } else if (gDP.fillColor.color == DEPTH_CLEAR_COLOR) { - DepthBuffer_SetBuffer( gDP.colorImage.address ); + depthBufferList().saveBuffer(gDP.colorImage.address); gDPFillRDRAM(gDP.colorImage.address, ulx, uly, lrx, lry, gDP.colorImage.width, gDP.colorImage.size, gDP.fillColor.color); OGL_ClearDepthBuffer(); return; diff --git a/gSP.cpp b/gSP.cpp index ff001e5e..6cd18524 100644 --- a/gSP.cpp +++ b/gSP.cpp @@ -1682,13 +1682,13 @@ void _copyDepthBuffer() // OpenGL has different format for color and depth buffers, so this trick can't be performed directly // To do that, depth buffer with address of current color buffer created and attached to the current FBO // It will be copy depth buffer - DepthBuffer_SetBuffer(gDP.colorImage.address); + depthBufferList().saveBuffer(gDP.colorImage.address); // Take any frame buffer and attach source depth buffer to it, to blit it into copy depth buffer FrameBuffer * pTmpBuffer = frameBufferList().findTmpBuffer(frameBufferList().getCurrent()->m_startAddress); DepthBuffer * pTmpBufferDepth = pTmpBuffer->m_pDepthBuffer; - pTmpBuffer->m_pDepthBuffer = DepthBuffer_FindBuffer(gSP.bgImage.address); + pTmpBuffer->m_pDepthBuffer = depthBufferList().findBuffer(gSP.bgImage.address); glBindFramebuffer(GL_READ_FRAMEBUFFER, pTmpBuffer->m_FBO); - glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pTmpBuffer->m_pDepthBuffer->renderbuf); + glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pTmpBuffer->m_pDepthBuffer->m_renderbuf); GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT }; glDrawBuffers(2, attachments); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO); @@ -1698,10 +1698,10 @@ void _copyDepthBuffer() GL_DEPTH_BUFFER_BIT, GL_NEAREST ); // Restore objects - glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pTmpBufferDepth->renderbuf); + glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pTmpBufferDepth->m_renderbuf); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); // Set back current depth buffer - DepthBuffer_SetBuffer(gDP.depthImageAddress); + depthBufferList().saveBuffer(gDP.depthImageAddress); } #endif // GLES2 @@ -1745,7 +1745,7 @@ void gSPBgRect1Cyc( u32 bg ) loadBGImage(objScaleBg, true); #ifndef GLES2 - if (gSP.bgImage.address == gDP.depthImageAddress || DepthBuffer_FindBuffer(gSP.bgImage.address) != NULL) { + if (gSP.bgImage.address == gDP.depthImageAddress || depthBufferList().findBuffer(gSP.bgImage.address) != NULL) { _copyDepthBuffer(); return; } @@ -1830,7 +1830,7 @@ void gSPBgRectCopy( u32 bg ) loadBGImage(objBg, false); #ifndef GLES2 - if (gSP.bgImage.address == gDP.depthImageAddress || DepthBuffer_FindBuffer(gSP.bgImage.address) != NULL) { + if (gSP.bgImage.address == gDP.depthImageAddress || depthBufferList().findBuffer(gSP.bgImage.address) != NULL) { _copyDepthBuffer(); return; }