diff --git a/build/vcpkg/test/vcpkg-configuration.json b/build/vcpkg/test/vcpkg-configuration.json index 3a5ba01..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": "dbd74247203195bfbc94b20c519c68ec6d2492f6", + "baseline": "9fda5016dcd22857de5dd20702428ac8d1652a99", "reference": "main", "packages": [ "myci", diff --git a/src/ruis/render/vulkan/context.cpp b/src/ruis/render/vulkan/context.cpp index 00dce02..aeaf416 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,14 +760,10 @@ 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. - 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()}; + // the viewport is stored in top-left origin coordinates (x right, y down), + // 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)