From e40393fec46a18cdfb7eb32c2eef9f143707397e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 14 Sep 2019 21:54:58 +1000 Subject: [PATCH] GPU: Use scissor test for drawing area --- src/pse/gpu_hw.cpp | 10 ++-------- src/pse/gpu_hw_opengl.cpp | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/pse/gpu_hw.cpp b/src/pse/gpu_hw.cpp index e89d50210..a1599df6a 100644 --- a/src/pse/gpu_hw.cpp +++ b/src/pse/gpu_hw.cpp @@ -31,12 +31,6 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices) hw_vert.x = vp.x(); hw_vert.y = vp.y(); - // excluding lower-right coordinates - if ((i & UINT32_C(1)) != 0) - hw_vert.x--; - if ((i & UINT32_C(2)) != 0) - hw_vert.y--; - if (textured) hw_vert.texcoord = Truncate16(m_GP0_command[buffer_pos++]); else @@ -113,9 +107,9 @@ void GPU_HW::CalcViewport(int* x, int* y, int* width, int* height) void GPU_HW::CalcScissorRect(int* left, int* top, int* right, int* bottom) { *left = m_drawing_area.top_left_x; - *right = m_drawing_area.bottom_right_x; + *right = m_drawing_area.bottom_right_x + 1; *top = m_drawing_area.top_left_y; - *bottom = m_drawing_area.bottom_right_y; + *bottom = m_drawing_area.bottom_right_y + 1; } static void DefineMacro(std::stringstream& ss, const char* name, bool enabled) diff --git a/src/pse/gpu_hw_opengl.cpp b/src/pse/gpu_hw_opengl.cpp index a8a91ae22..ea4c1d206 100644 --- a/src/pse/gpu_hw_opengl.cpp +++ b/src/pse/gpu_hw_opengl.cpp @@ -175,7 +175,19 @@ void GPU_HW_OpenGL::SetViewport() glViewport(x, y, width, height); } -void GPU_HW_OpenGL::SetScissor() {} +void GPU_HW_OpenGL::SetScissor() +{ + int left, top, right, bottom; + CalcScissorRect(&left, &top, &right, &bottom); + + const int width = right - left; + const int height = bottom - top; + const int x = left; + const int y = VRAM_HEIGHT - bottom; + + Log_DebugPrintf("SetScissor: (%d-%d, %d-%d)", x, x + width, y, y + height); + glScissor(x, y, width, height); +} inline u32 ConvertRGBA5551ToRGBA8888(u16 color) { @@ -252,7 +264,6 @@ void GPU_HW_OpenGL::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) const auto [r, g, b, a] = RGBA8ToFloat(color); glClearColor(r, g, b, a); glClear(GL_COLOR_BUFFER_BIT); - glDisable(GL_SCISSOR_TEST); } void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data) @@ -293,6 +304,7 @@ void GPU_HW_OpenGL::UpdateTexturePageTexture() m_framebuffer_texture->Bind(); glDisable(GL_BLEND); + glDisable(GL_SCISSOR_TEST); glViewport(0, 0, TEXTURE_PAGE_WIDTH, TEXTURE_PAGE_HEIGHT); glBindVertexArray(m_attributeless_vao_id); @@ -321,8 +333,13 @@ void GPU_HW_OpenGL::FlushRender() if (m_batch_vertices.empty()) return; + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glDepthMask(GL_FALSE); SetProgram(m_batch_command.texture_enable, m_batch_command.texture_blending_raw); SetViewport(); + SetScissor(); if (m_batch_command.texture_enable) m_texture_page_texture->Bind();