From 9780f333b411b34704aec51d40fec657b8776c70 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Sun, 19 Mar 2017 01:33:45 +0000 Subject: [PATCH] The model3 has this weird issue where the 2d and 3d planes are misaligned by 2 pixels. Originally I made a quick hack that shifted subviewports 2 pixels. But apparently that wasn't enough, as the issue effects everything. Thanks to HarryTuttle for pointing this out, and making a patch :) --- Src/Graphics/New3D/New3D.cpp | 8 -------- Src/Graphics/Render2D.cpp | 14 +++----------- Src/Graphics/Render2D.h | 1 + Src/Model3/Real3D.cpp | 2 +- Src/OSD/SDL/Main.cpp | 10 ++++++++-- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 573a46f..f0b7b11 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -703,14 +703,6 @@ void CNew3D::RenderViewport(UINT32 addr) uint32_t matrixBase = vpnode[0x16] & 0xFFFFFF; // matrix base address - if (vp->vpX) { - vp->vpX += 2; - } - - if (vp->vpY) { - vp->vpY += 2; - } - LODBlendTable* tableTest = (LODBlendTable*)TranslateCullingAddress(vpnode[0x17]); vp->angle_left = -atan2(*(float *)&vpnode[12], *(float *)&vpnode[13]); diff --git a/Src/Graphics/Render2D.cpp b/Src/Graphics/Render2D.cpp index 4269b2b..2c3b10f 100644 --- a/Src/Graphics/Render2D.cpp +++ b/Src/Graphics/Render2D.cpp @@ -536,24 +536,15 @@ void CRender2D::Setup2D(bool isBottom, bool clearAll) glUseProgram(m_shaderProgram); // Clear everything if requested or just overscan areas for wide screen mode - if (clearAll) + if (clearAll || isBottom) { glClearColor(0.0, 0.0, 0.0, 0.0); glViewport(0, 0, m_totalXPixels, m_totalYPixels); glClear(GL_COLOR_BUFFER_BIT); } - else if (isBottom && g_Config.wideScreen) - { - // For now, clear w/ black (may want to use color 0 later) - glClearColor(0.0, 0.0, 0.0, 0.0); - glViewport(0, 0, m_xOffset, m_totalYPixels); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(m_xOffset + m_xPixels, 0, m_totalXPixels, m_totalYPixels); - glClear(GL_COLOR_BUFFER_BIT); - } // Set up the viewport and orthogonal projection - glViewport(m_xOffset, m_yOffset, m_xPixels, m_yPixels); + glViewport(m_xOffset - m_correction, m_yOffset + m_correction, m_xPixels, m_yPixels); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 1.0, 0.0, 1.0, -1.0); @@ -672,6 +663,7 @@ bool CRender2D::Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned m_yOffset = yOffset; m_totalXPixels = totalXRes; m_totalYPixels = totalYRes; + m_correction = (UINT32)(((yRes / 384.f) * 2) + 0.5f); // for some reason the 2d layer is 2 pixels off the 3D // Create textures glActiveTexture(GL_TEXTURE0); // texture unit 0 diff --git a/Src/Graphics/Render2D.h b/Src/Graphics/Render2D.h index 7ec021b..7715211 100644 --- a/Src/Graphics/Render2D.h +++ b/Src/Graphics/Render2D.h @@ -186,6 +186,7 @@ private: unsigned m_yOffset = 0; unsigned m_totalXPixels; // total display surface resolution unsigned m_totalYPixels; + unsigned m_correction = 0; // Shader programs and input data locations GLuint m_shaderProgram; // shader program object diff --git a/Src/Model3/Real3D.cpp b/Src/Model3/Real3D.cpp index 4034a23..5fa11ce 100644 --- a/Src/Model3/Real3D.cpp +++ b/Src/Model3/Real3D.cpp @@ -1076,7 +1076,7 @@ CReal3D::CReal3D(void) CReal3D::~CReal3D(void) { // Dump memory -#if 0 +#if 1 FILE *fp; fp = fopen("8c000000", "wb"); if (NULL != fp) diff --git a/Src/OSD/SDL/Main.cpp b/Src/OSD/SDL/Main.cpp index c880955..1fba8d9 100644 --- a/Src/OSD/SDL/Main.cpp +++ b/Src/OSD/SDL/Main.cpp @@ -135,16 +135,22 @@ static bool SetGLGeometry(unsigned *xOffsetPtr, unsigned *yOffsetPtr, unsigned * // Write back resolution parameters *xResPtr = (unsigned) xRes; *yResPtr = (unsigned) yRes; + + UINT32 correction = (UINT32)(((yRes / 384.f) * 2) + 0.5f); + + glEnable(GL_SCISSOR_TEST); // Scissor box (to clip visible area) if (!g_Config.wideScreen) { if (VideoInfo->current_w > int(*xResPtr) || VideoInfo->current_h > int(*yResPtr)) { - glEnable(GL_SCISSOR_TEST); - glScissor(*xOffsetPtr, *yOffsetPtr, *xResPtr, *yResPtr); + glScissor(*xOffsetPtr + correction, *yOffsetPtr + correction, *xResPtr - (correction*2), *yResPtr - (correction*2)); } } + else { + glScissor(0, correction, *totalXResPtr, *totalYResPtr - (correction * 2)); + } return OKAY; }