Skip to content

Commit 871f747

Browse files
committed
WIP use FindSmallestFramebufferAtPtr again
Tenkaichi 2 uses CLUT pointers which don't align perfectly with the framebuffer
1 parent d9c9be9 commit 871f747

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

Source/gs/GSH_OpenGL/GSH_OpenGL.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,13 +1358,36 @@ CGSH_OpenGL::BitmapPtr CGSH_OpenGL::FindOrCreateBitmap(const FramebufferPtr& fra
13581358
return sharedPtr;
13591359
}
13601360

1361-
CGSH_OpenGL::FramebufferPtr CGSH_OpenGL::FindFramebufferAtPtr(uint32 ptr, uint32 psm) const
1361+
CGSH_OpenGL::FramebufferPtr CGSH_OpenGL::FindSmallestFramebufferAtPtr(uint32 ptr, uint32 psm) const
13621362
{
1363-
auto framebufferIterator = std::find_if(m_framebuffers.begin(), m_framebuffers.end(),
1364-
[ptr, psm](const FramebufferPtr& framebuffer) {
1365-
return framebuffer->m_psm == psm && framebuffer->m_basePtr == ptr;
1366-
});
1367-
return (framebufferIterator != std::end(m_framebuffers)) ? *(framebufferIterator) : FramebufferPtr();
1363+
uint32 smallestSize = 0;
1364+
FramebufferPtr framebufferPtr = nullptr;
1365+
1366+
for(const auto& framebuffer : m_framebuffers)
1367+
{
1368+
if(framebuffer->m_psm != psm)
1369+
{
1370+
continue;
1371+
}
1372+
1373+
// If its a exact match, we can be sure its the right framebuffer
1374+
if(framebuffer->m_basePtr == ptr)
1375+
{
1376+
return framebuffer;
1377+
}
1378+
1379+
if(framebuffer->m_basePtr <= ptr && (framebuffer->m_basePtr + 0x6200) >= ptr)
1380+
{
1381+
uint32 size = framebuffer->m_width * framebuffer->m_height;
1382+
if(size < smallestSize || smallestSize == 0)
1383+
{
1384+
smallestSize = size;
1385+
framebufferPtr = framebuffer;
1386+
}
1387+
}
1388+
}
1389+
1390+
return framebufferPtr;
13681391
}
13691392

13701393
/////////////////////////////////////////////////////////////
@@ -1927,7 +1950,7 @@ void CGSH_OpenGL::SyncCLUT(const TEX0& tex0)
19271950
{
19281951
const uint32 ptr = tex0.GetCLUTPtr();
19291952

1930-
FramebufferPtr framebuffer = FindFramebufferAtPtr(ptr, PSMCT32);
1953+
FramebufferPtr framebuffer = FindSmallestFramebufferAtPtr(ptr, PSMCT32);
19311954
if(framebuffer)
19321955
{
19331956
WriteFramebufferToMemory(framebuffer, true);

Source/gs/GSH_OpenGL/GSH_OpenGL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class CGSH_OpenGL : public CGSHandler
376376
FramebufferPtr FindFramebuffer(const FRAME&) const;
377377
DepthbufferPtr FindDepthbuffer(const ZBUF&, const FRAME&) const;
378378
BitmapPtr FindOrCreateBitmap(const FramebufferPtr&, uint32);
379-
FramebufferPtr FindFramebufferAtPtr(uint32, uint32) const;
379+
FramebufferPtr FindSmallestFramebufferAtPtr(uint32 ptr, uint32 psm) const;
380380
void WriteFramebufferToMemory(const FramebufferPtr&, bool);
381381

382382
void DumpTexture(unsigned int, unsigned int, uint32);

0 commit comments

Comments
 (0)