67 {
68 u = repeat_horizontal ? u - std::floor(u) : std::clamp(u, 0.0f, 1.0f);
69 v = std::clamp(v, 0.0f, 1.0f);
70 const float texture_x = u *
static_cast<float>(repeat_horizontal ?
width :
width - 1);
71 const float texture_y = v *
static_cast<float>(
height - 1);
72 const int first_x = static_cast<int>(std::floor(texture_x));
73 const int first_y = static_cast<int>(std::floor(texture_y));
74 const int second_x = repeat_horizontal ? (first_x + 1) %
width : std::min(first_x + 1,
width - 1);
75 const int second_y = std::min(first_y + 1,
height - 1);
76 const float x_fraction = texture_x - static_cast<float>(first_x);
77 const float y_fraction = texture_y - static_cast<float>(first_y);
78 const auto texel = [
this](
int x,
int y) {
return pixels[
static_cast<std::size_t
>(y) *
static_cast<std::size_t
>(
width) +
static_cast<std::size_t
>(x)]; };
82 }
mxvk::MXCOLOR interpolate_color(mxvk::MXCOLOR first, mxvk::MXCOLOR second, float fraction)
std::uint32_t MXCOLOR
Packed 32-bit color in ARGB byte order.
std::vector< mxvk::MXCOLOR > pixels