OpenGL: add support for changing BG0HOFS midframe. fixes #2072

This commit is contained in:
Arisotura 2024-06-18 13:11:42 +02:00
parent 626d2379bc
commit e234385c20
4 changed files with 9 additions and 11 deletions

View File

@ -254,7 +254,11 @@ void SoftRenderer::DrawScanline(u32 line, Unit* unit)
if (GPU.GPU3D.IsRendererAccelerated()) if (GPU.GPU3D.IsRendererAccelerated())
{ {
dst[256*3] = masterBrightness | (CurUnit->DispCnt & 0x30000); u32 xpos = GPU.GPU3D.GetRenderXPos();
dst[256*3] = masterBrightness |
(CurUnit->DispCnt & 0x30000) |
(xpos << 24) | ((xpos & 0x100) << 15);
return; return;
} }

View File

@ -51,7 +51,6 @@ std::optional<GLCompositor> GLCompositor::New() noexcept
GLCompositor::GLCompositor(GLuint compShader) noexcept : CompShader(compShader) GLCompositor::GLCompositor(GLuint compShader) noexcept : CompShader(compShader)
{ {
CompScaleLoc = glGetUniformLocation(CompShader, "u3DScale"); CompScaleLoc = glGetUniformLocation(CompShader, "u3DScale");
Comp3DXPosLoc = glGetUniformLocation(CompShader, "u3DXPos");
glUseProgram(CompShader); glUseProgram(CompShader);
GLuint screenTextureUniform = glGetUniformLocation(CompShader, "ScreenTex"); GLuint screenTextureUniform = glGetUniformLocation(CompShader, "ScreenTex");
@ -140,7 +139,6 @@ GLCompositor::GLCompositor(GLCompositor&& other) noexcept :
ScreenH(other.ScreenH), ScreenH(other.ScreenH),
ScreenW(other.ScreenW), ScreenW(other.ScreenW),
CompScaleLoc(other.CompScaleLoc), CompScaleLoc(other.CompScaleLoc),
Comp3DXPosLoc(other.Comp3DXPosLoc),
CompVertices(other.CompVertices), CompVertices(other.CompVertices),
CompShader(other.CompShader), CompShader(other.CompShader),
CompVertexBufferID(other.CompVertexBufferID), CompVertexBufferID(other.CompVertexBufferID),
@ -165,7 +163,6 @@ GLCompositor& GLCompositor::operator=(GLCompositor&& other) noexcept
ScreenH = other.ScreenH; ScreenH = other.ScreenH;
ScreenW = other.ScreenW; ScreenW = other.ScreenW;
CompScaleLoc = other.CompScaleLoc; CompScaleLoc = other.CompScaleLoc;
Comp3DXPosLoc = other.Comp3DXPosLoc;
CompVertices = other.CompVertices; CompVertices = other.CompVertices;
// Clean up these resources before overwriting them // Clean up these resources before overwriting them
@ -258,9 +255,6 @@ void GLCompositor::RenderFrame(const GPU& gpu, Renderer3D& renderer) noexcept
glUseProgram(CompShader); glUseProgram(CompShader);
glUniform1ui(CompScaleLoc, Scale); glUniform1ui(CompScaleLoc, Scale);
// TODO: support setting this midframe, if ever needed
glUniform1i(Comp3DXPosLoc, ((int)gpu.GPU3D.GetRenderXPos() << 23) >> 23);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, CompScreenInputTex); glBindTexture(GL_TEXTURE_2D, CompScreenInputTex);

View File

@ -52,7 +52,6 @@ private:
GLuint CompShader {}; GLuint CompShader {};
GLuint CompScaleLoc = 0; GLuint CompScaleLoc = 0;
GLuint Comp3DXPosLoc = 0;
GLuint CompVertexBufferID = 0; GLuint CompVertexBufferID = 0;
GLuint CompVertexArrayID = 0; GLuint CompVertexArrayID = 0;

View File

@ -43,7 +43,6 @@ void main()
const char* kCompositorFS_Nearest = R"(#version 140 const char* kCompositorFS_Nearest = R"(#version 140
uniform uint u3DScale; uniform uint u3DScale;
uniform int u3DXPos;
uniform usampler2D ScreenTex; uniform usampler2D ScreenTex;
uniform sampler2D _3DTex; uniform sampler2D _3DTex;
@ -56,11 +55,13 @@ void main()
{ {
ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0));
float _3dxpos = float(u3DXPos);
ivec4 mbright = ivec4(texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0)); ivec4 mbright = ivec4(texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0));
int dispmode = mbright.b & 0x3; int dispmode = mbright.b & 0x3;
// mbright.a == HOFS bit0..7
// mbright.b bit7 == HOFS bit8 (sign)
float _3dxpos = float(mbright.a - ((mbright.b & 0x80) * 2));
if (dispmode == 1) if (dispmode == 1)
{ {
ivec4 val1 = pixel; ivec4 val1 = pixel;