From 3239c301710f1652116d08b1ef96cd2a266c1c51 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Sun, 29 Nov 2026 23:23:31 +0200 Subject: [PATCH 1/4] to_window_coords, get_viewport: top-left origin window coordinates Window coordinates are always top-left origin (x right, y down): - to_window_coords() computes the result in the viewport's coordinate frame (clamped) and adds the viewport offset - get_viewport() returns the viewport stored by set_viewport() (top-left origin), falling back to the effective target's dimensions until set_viewport() has been called --- src/ruis/render/vulkan/context.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ruis/render/vulkan/context.cpp b/src/ruis/render/vulkan/context.cpp index 00dce02..81ae37e 100644 --- a/src/ruis/render/vulkan/context.cpp +++ b/src/ruis/render/vulkan/context.cpp @@ -722,16 +722,20 @@ void context::clear_framebuffer_stencil() r4::vector2 context::to_window_coords(const ruis::vec2& point) const { - // NDC -> window space using the swapchain (physical) dimensions - const auto dims = this->window_dims.to(); - // clamp the result to the window bounds (same as the GL variant): without the - // clamp a point outside the window would produce a negative value which, when + // NDC -> window space. The window coordinate system is top-left origin + // (x right, y down): framework top-left (NDC y = -1) maps to (0, 0). + // The rect is computed in the viewport's coordinate frame. + const auto& vp = this->get_viewport(); + const auto dims = vp.d.to(); + // clamp the result to the viewport bounds (same as the GL variant): without the + // clamp a point outside the viewport would produce a negative value which, when // cast to uint32_t, wraps around to a huge number and corrupts the scissor // rectangle (the widget's contents would disappear instead of being clipped) auto res = (point + ruis::vec2(1, 1)) * ndc_to_unit_scale; res.comp_multiply(dims); res = min(dims, max(res, ruis::vec2(0, 0))); - return round(res).to(); + res = round(res) + vp.p.to(); + return res.to(); } bool context::is_scissor_enabled() const noexcept @@ -756,13 +760,17 @@ void context::set_scissor(const r4::rectangle& r) r4::rectangle context::get_viewport() const { - // when rendering into a framebuffer (e.g. render-to-texture / get_render), - // the viewport is the framebuffer's dimensions, not the window's viewport. + // the viewport is stored in top-left origin coordinates (x right, y down), + // exactly as set_viewport() accepts. Until set_viewport() is called, fall + // back to the effective target's dimensions (framebuffer when rendering to + // a framebuffer, otherwise the swapchain). + if (this->viewport.d.x() != 0 || this->viewport.d.y() != 0) { + return this->viewport; + } if (this->current_fb != nullptr) { const auto d = this->current_fb->dims(); return {0, 0, d.x(), d.y()}; } - // when rendering to the screen, use the swapchain (physical) dimensions return {0, 0, this->window_dims.x(), this->window_dims.y()}; } From e7e256cfe0fca4fd969e6414624d310131dd1281 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Mon, 30 Nov 2026 17:45:26 +0200 Subject: [PATCH 2/4] chore: bump vcpkg baseline to latest cppfw vcpkg-repo commit --- build/vcpkg/test/vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/vcpkg/test/vcpkg-configuration.json b/build/vcpkg/test/vcpkg-configuration.json index 3a5ba01..a311080 100644 --- a/build/vcpkg/test/vcpkg-configuration.json +++ b/build/vcpkg/test/vcpkg-configuration.json @@ -8,7 +8,7 @@ { "kind": "git", "repository": "https://github.com/cppfw/vcpkg-repo/", - "baseline": "dbd74247203195bfbc94b20c519c68ec6d2492f6", + "baseline": "92dfac49fed12783e0c6b28ebd5da07136d88aa3", "reference": "main", "packages": [ "myci", From f9aaf157d19216a3f045ee83dc694b41e347a1aa Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Tue, 1 Dec 2026 01:03:24 +0200 Subject: [PATCH 3/4] chore: bump vcpkg baseline to latest cppfw vcpkg-repo commit --- build/vcpkg/test/vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/vcpkg/test/vcpkg-configuration.json b/build/vcpkg/test/vcpkg-configuration.json index a311080..ae36887 100644 --- a/build/vcpkg/test/vcpkg-configuration.json +++ b/build/vcpkg/test/vcpkg-configuration.json @@ -8,7 +8,7 @@ { "kind": "git", "repository": "https://github.com/cppfw/vcpkg-repo/", - "baseline": "92dfac49fed12783e0c6b28ebd5da07136d88aa3", + "baseline": "9fda5016dcd22857de5dd20702428ac8d1652a99", "reference": "main", "packages": [ "myci", From 88e5034bb5863df362e399740ff76d03c21e8ed1 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Tue, 1 Dec 2026 01:27:12 +0200 Subject: [PATCH 4/4] get_viewport: return the stored rect as-is, no fallback Until set_viewport() is called the stored rect is zero-sized by default, so the framebuffer/window-dimensions fallback was unnecessary and could misrepresent the state (it also made the pre-set state ambiguous with a genuine viewport). --- src/ruis/render/vulkan/context.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/ruis/render/vulkan/context.cpp b/src/ruis/render/vulkan/context.cpp index 81ae37e..aeaf416 100644 --- a/src/ruis/render/vulkan/context.cpp +++ b/src/ruis/render/vulkan/context.cpp @@ -761,17 +761,9 @@ void context::set_scissor(const r4::rectangle& r) r4::rectangle context::get_viewport() const { // the viewport is stored in top-left origin coordinates (x right, y down), - // exactly as set_viewport() accepts. Until set_viewport() is called, fall - // back to the effective target's dimensions (framebuffer when rendering to - // a framebuffer, otherwise the swapchain). - if (this->viewport.d.x() != 0 || this->viewport.d.y() != 0) { - return this->viewport; - } - if (this->current_fb != nullptr) { - const auto d = this->current_fb->dims(); - return {0, 0, d.x(), d.y()}; - } - return {0, 0, this->window_dims.x(), this->window_dims.y()}; + // exactly as set_viewport() accepts. Until set_viewport() is called it is + // zero-sized by default. + return this->viewport; } void context::set_viewport(const r4::rectangle& r)