diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 0636e9de..443bfed3 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -150,12 +150,33 @@ void FrameBufferList::destroy() { m_drawBuffer = GL_BACK; } -FrameBuffer * FrameBufferList::findBuffer(u32 _startAddress, u32 _endAddress) +FrameBuffer * FrameBufferList::findBuffer(u32 _startAddress) { for (FrameBuffers::iterator iter = m_list.begin(); iter != m_list.end(); ++iter) - if ((iter->m_startAddress <= _startAddress && iter->m_endAddress >= _startAddress) || - (_startAddress < iter->m_startAddress && _endAddress > iter->m_startAddress)) - return &(*iter); + if (iter->m_startAddress <= _startAddress && iter->m_endAddress >= _startAddress) // [ { ] + return &(*iter); + return NULL; +} + +FrameBuffer * FrameBufferList::_findBuffer(u32 _startAddress, u32 _endAddress, u32 _width) +{ + if (m_list.empty()) + return NULL; + + FrameBuffers::iterator iter = m_list.end(); + do { + --iter; + if ((iter->m_startAddress <= _startAddress && iter->m_endAddress >= _startAddress) || // [ { ] + (_startAddress <= iter->m_startAddress && _endAddress >= iter->m_startAddress)) { // { [ } + + if (_startAddress != iter->m_startAddress || _width != iter->m_width) { + m_list.erase(iter); + return _findBuffer(_startAddress, _endAddress, _width); + } + + return &(*iter); + } + } while (iter != m_list.begin()); return NULL; } @@ -180,8 +201,8 @@ void FrameBufferList::saveBuffer(u32 _address, u16 _format, u16 _size, u16 _widt } const u32 endAddress = _address + ((_width * _height << _size >> 1) - 1); - if (m_pCurrent == NULL || m_pCurrent->m_startAddress != _address) - m_pCurrent = findBuffer(_address, endAddress); + if (m_pCurrent == NULL || m_pCurrent->m_startAddress != _address || m_pCurrent->m_width != _width) + m_pCurrent = _findBuffer(_address, endAddress, _width); if (m_pCurrent != NULL) { if ((m_pCurrent->m_startAddress != _address) || (m_pCurrent->m_width != _width) || @@ -334,7 +355,7 @@ void FrameBufferList::renderBuffer(u32 _address) if (VI.width == 0) // H width is zero. Don't draw return; - FrameBuffer *pBuffer = findBuffer(_address, 0); + FrameBuffer *pBuffer = findBuffer(_address); if (pBuffer == NULL) return; diff --git a/FrameBuffer.h b/FrameBuffer.h index 6beacf2c..e98ded93 100644 --- a/FrameBuffer.h +++ b/FrameBuffer.h @@ -34,7 +34,7 @@ public: void saveBuffer(u32 _address, u16 _format, u16 _size, u16 _width, u16 _height, bool _cfb); void removeBuffer(u32 _address); void attachDepthBuffer(); - FrameBuffer * findBuffer(u32 _startAddress, u32 _endAddress = 0); + FrameBuffer * findBuffer(u32 _startAddress); FrameBuffer * findTmpBuffer(u32 _address); FrameBuffer * getCurrent() const {return m_pCurrent;} void renderBuffer(u32 _address); @@ -50,6 +50,8 @@ private: FrameBufferList() : m_pCurrent(NULL), m_drawBuffer(GL_BACK) {} FrameBufferList(const FrameBufferList &); + FrameBuffer * _findBuffer(u32 _startAddress, u32 _endAddress, u32 _width); + typedef std::list FrameBuffers; FrameBuffers m_list; FrameBuffer * m_pCurrent; diff --git a/gDP.cpp b/gDP.cpp index 10036c2e..0fa104b3 100644 --- a/gDP.cpp +++ b/gDP.cpp @@ -686,6 +686,7 @@ void gDPLoadBlock( u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt ) } else UnswapCopy( src, dest, bytes ); + //gDP.textureImage.address += bytes; #ifdef DEBUG DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPLoadBlock( %i, %i, %i, %i, %i );\n", tile, uls, ult, lrs, dxt );