From 1825a809534dc2ba9054930f9d3dfcc6d6226876 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 7 Apr 2025 20:12:31 -0600 Subject: [PATCH] Clamp scissor to framebuffer size --- lib/gfx/common.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/gfx/common.cpp b/lib/gfx/common.cpp index b627300..968b90a 100644 --- a/lib/gfx/common.cpp +++ b/lib/gfx/common.cpp @@ -517,7 +517,7 @@ void begin_frame() { g_instance.ProcessEvents(); } size_t bufferOffset = 0; - auto& stagingBuf = g_stagingBuffers[currentStagingBuffer]; + const auto& stagingBuf = g_stagingBuffers[currentStagingBuffer]; const auto mapBuffer = [&](ByteBuffer& buf, uint64_t size) { if (size <= 0) { return; @@ -684,7 +684,12 @@ void render_pass(const wgpu::RenderPassEncoder& pass, u32 idx) { } break; case CommandType::SetScissor: { const auto& sc = cmd.data.setScissor; - pass.SetScissorRect(sc.x, sc.y, sc.w, sc.h); + const auto& size = webgpu::g_frameBuffer.size; + const auto x = std::clamp(sc.x, 0u, size.width); + const auto y = std::clamp(sc.y, 0u, size.height); + const auto w = std::clamp(sc.w, 0u, size.width - x); + const auto h = std::clamp(sc.h, 0u, size.height - y); + pass.SetScissorRect(x, y, w, h); } break; case CommandType::Draw: { const auto& draw = cmd.data.draw;