From 431313156a80592216a7bed2ec17988fa0495987 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 5 Oct 2019 14:36:48 +1000 Subject: [PATCH] GPU: Fix invalid rectangle passed to glScissor --- src/core/gpu_hw.cpp | 8 ++++---- src/core/gpu_hw_opengl.cpp | 27 +++++++++++++++++---------- src/core/gpu_hw_opengl.h | 1 + src/duckstation/sdl_interface.cpp | 6 ++++-- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 80cd5ecdc..1d563d5f1 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -141,10 +141,10 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices) void GPU_HW::CalcScissorRect(int* left, int* top, int* right, int* bottom) { - *left = m_drawing_area.left * s32(m_resolution_scale); - *right = (m_drawing_area.right + 1) * s32(m_resolution_scale); - *top = m_drawing_area.top * s32(m_resolution_scale); - *bottom = (m_drawing_area.bottom + 1) * s32(m_resolution_scale); + *left = m_drawing_area.left * m_resolution_scale; + *right = std::max((m_drawing_area.right + 1) * m_resolution_scale, *left + 1); + *top = m_drawing_area.top * m_resolution_scale; + *bottom = std::max((m_drawing_area.bottom + 1) * m_resolution_scale, *top + 1); } static void DefineMacro(std::stringstream& ss, const char* name, bool enabled) diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index c0e4cbc0f..675cbdae3 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -396,20 +396,27 @@ void GPU_HW_OpenGL::SetDrawState() glBlendFuncSeparate(GL_ONE, GL_SRC_ALPHA, GL_ONE, GL_ZERO); } } + + if (m_drawing_area_changed) + { + m_drawing_area_changed = false; + + 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 = m_vram_texture->GetHeight() - bottom; + + Log_DebugPrintf("SetScissor: (%d-%d, %d-%d)", x, x + width, y, y + height); + glScissor(x, y, width, height); + } } void GPU_HW_OpenGL::UpdateDrawingArea() { - 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 = m_vram_texture->GetHeight() - bottom; - - Log_DebugPrintf("SetScissor: (%d-%d, %d-%d)", x, x + width, y, y + height); - glScissor(x, y, width, height); + m_drawing_area_changed = true; } void GPU_HW_OpenGL::UpdateDisplay() diff --git a/src/core/gpu_hw_opengl.h b/src/core/gpu_hw_opengl.h index 0dec54cdd..a3fb9bd95 100644 --- a/src/core/gpu_hw_opengl.h +++ b/src/core/gpu_hw_opengl.h @@ -73,6 +73,7 @@ private: bool m_vram_read_texture_dirty = true; bool m_last_transparency_enable = false; TransparencyMode m_last_transparency_mode = TransparencyMode::BackgroundMinusForeground; + bool m_drawing_area_changed = true; std::array, 3>, 2>, 2> m_render_programs; GL::Program m_reinterpret_rgb8_program; diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index 015b33462..02b6e8978 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -98,12 +98,14 @@ bool SDLInterface::CreateGLContext() return false; } +#if 0 if (GLAD_GL_KHR_debug) { glad_glDebugMessageCallbackKHR(GLDebugCallback, nullptr); - // glEnable(GL_DEBUG_OUTPUT); - // glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); } +#endif SDL_GL_SetSwapInterval(0); return true;