Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/vcpkg/test/vcpkg-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"kind": "git",
"repository": "https://github.com/cppfw/vcpkg-repo/",
"baseline": "dbd74247203195bfbc94b20c519c68ec6d2492f6",
"baseline": "9fda5016dcd22857de5dd20702428ac8d1652a99",
"reference": "main",
"packages": [
"myci",
Expand Down
26 changes: 13 additions & 13 deletions src/ruis/render/vulkan/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,20 @@ void context::clear_framebuffer_stencil()

r4::vector2<uint32_t> context::to_window_coords(const ruis::vec2& point) const
{
// NDC -> window space using the swapchain (physical) dimensions
const auto dims = this->window_dims.to<ruis::real>();
// 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<ruis::real>();
// 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<uint32_t>();
res = round(res) + vp.p.to<ruis::real>();
return res.to<uint32_t>();
}

bool context::is_scissor_enabled() const noexcept
Expand All @@ -756,14 +760,10 @@ void context::set_scissor(const r4::rectangle<uint32_t>& r)

r4::rectangle<uint32_t> 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),
Comment thread
igagis marked this conversation as resolved.
Resolved
// 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<uint32_t>& r)
Expand Down
Loading