Skip to content

Commit

Permalink
WIP use FindSmallestFramebufferAtPtr again
Browse files Browse the repository at this point in the history
Tenkaichi 2 uses CLUT pointers which don't align perfectly with the framebuffer
  • Loading branch information
kernle32dll committed Jun 7, 2021
1 parent d9c9be9 commit 871f747
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions Source/gs/GSH_OpenGL/GSH_OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,13 +1358,36 @@ CGSH_OpenGL::BitmapPtr CGSH_OpenGL::FindOrCreateBitmap(const FramebufferPtr& fra
return sharedPtr;
}

CGSH_OpenGL::FramebufferPtr CGSH_OpenGL::FindFramebufferAtPtr(uint32 ptr, uint32 psm) const
CGSH_OpenGL::FramebufferPtr CGSH_OpenGL::FindSmallestFramebufferAtPtr(uint32 ptr, uint32 psm) const
{
auto framebufferIterator = std::find_if(m_framebuffers.begin(), m_framebuffers.end(),
[ptr, psm](const FramebufferPtr& framebuffer) {
return framebuffer->m_psm == psm && framebuffer->m_basePtr == ptr;
});
return (framebufferIterator != std::end(m_framebuffers)) ? *(framebufferIterator) : FramebufferPtr();
uint32 smallestSize = 0;
FramebufferPtr framebufferPtr = nullptr;

for(const auto& framebuffer : m_framebuffers)
{
if(framebuffer->m_psm != psm)
{
continue;
}

// If its a exact match, we can be sure its the right framebuffer
if(framebuffer->m_basePtr == ptr)
{
return framebuffer;
}

if(framebuffer->m_basePtr <= ptr && (framebuffer->m_basePtr + 0x6200) >= ptr)
{
uint32 size = framebuffer->m_width * framebuffer->m_height;
if(size < smallestSize || smallestSize == 0)
{
smallestSize = size;
framebufferPtr = framebuffer;
}
}
}

return framebufferPtr;
}

/////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1927,7 +1950,7 @@ void CGSH_OpenGL::SyncCLUT(const TEX0& tex0)
{
const uint32 ptr = tex0.GetCLUTPtr();

FramebufferPtr framebuffer = FindFramebufferAtPtr(ptr, PSMCT32);
FramebufferPtr framebuffer = FindSmallestFramebufferAtPtr(ptr, PSMCT32);
if(framebuffer)
{
WriteFramebufferToMemory(framebuffer, true);
Expand Down
2 changes: 1 addition & 1 deletion Source/gs/GSH_OpenGL/GSH_OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class CGSH_OpenGL : public CGSHandler
FramebufferPtr FindFramebuffer(const FRAME&) const;
DepthbufferPtr FindDepthbuffer(const ZBUF&, const FRAME&) const;
BitmapPtr FindOrCreateBitmap(const FramebufferPtr&, uint32);
FramebufferPtr FindFramebufferAtPtr(uint32, uint32) const;
FramebufferPtr FindSmallestFramebufferAtPtr(uint32 ptr, uint32 psm) const;
void WriteFramebufferToMemory(const FramebufferPtr&, bool);

void DumpTexture(unsigned int, unsigned int, uint32);
Expand Down

0 comments on commit 871f747

Please sign in to comment.