Skip to content
Merged
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
19 changes: 11 additions & 8 deletions src/ruis/render/vulkan/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "context.hpp"

#include <algorithm>
#include <cstring>
#include <limits>

Expand All @@ -43,7 +44,7 @@ using namespace ruis::render::vulkan;
namespace {

// maps NDC (-1 .. 1) to the unit range (0 .. 1)
constexpr float ndc_to_unit_scale = 0.5f;
constexpr ruis::real ndc_to_unit_scale = ruis::real(0.5);

// number of bits per blend factor in the packed blend key (15 values fit in 4,
// use 5 for simplicity)
Expand Down Expand Up @@ -722,13 +723,15 @@ 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 p = r4::vector2<float>(point.x(), point.y());
const auto w = this->window_dims.x();
const auto h = this->window_dims.y();
r4::vector2<uint32_t> result;
result.x() = static_cast<uint32_t>((p.x() + 1.0f) * ndc_to_unit_scale * static_cast<float>(w));
result.y() = static_cast<uint32_t>((p.y() + 1.0f) * ndc_to_unit_scale * static_cast<float>(h));
return result;
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
// 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>();
}

bool context::is_scissor_enabled() const noexcept
Expand Down
Loading