15 #include <vsg/maths/color.h>
22 constexpr T clamp_to_edge(T value)
24 return value <= T(0.0) ? T(0.0) : value >= T(1.0) ? T(1.0)
30 constexpr T repeat(T value)
32 T result = value - std::floor(value);
33 if (result != T(0.0))
return result;
34 return (value > T(0.0)) ? T(1.0) : T(0.0);
39 constexpr T mirror_repeat(T value)
41 T half_value = (std::abs(value) * T(0.5));
42 T v_fract = half_value - std::floor(half_value);
43 return T(1.0) - std::abs(T(1.0) - v_fract * T(2.0));
47 inline bool clamp(VkSamplerAddressMode mode,
float& coord)
51 case (VK_SAMPLER_ADDRESS_MODE_REPEAT):
52 coord = repeat(coord);
54 case (VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT):
55 coord = mirror_repeat(coord);
57 case (VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE):
58 coord = clamp_to_edge(coord);
60 case (VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER):
61 if (coord < 0.0f)
return false;
62 if (coord > 1.0f)
return false;
66 coord = clamp_to_edge(coord);