25 Texture2D(
AImageView texture,
ImageRendering imageRendering)
noexcept: mTexture(texture), mImageRendering(imageRendering) {}
26 Texture2D(
AImageView texture)
noexcept: Texture2D(texture, ImageRendering::PIXELATED) {}
28 glm::vec4 operator[](glm::vec2 uv)
const {
29 switch (mImageRendering) {
30 case ImageRendering::PIXELATED:
31 return clamped(glm::ivec2(uv * glm::vec2(mTexture.size())));
32 case ImageRendering::SMOOTH: {
33 const auto pos = glm::ivec2(uv * glm::vec2(mTexture.size()));
34 const auto texelSize = glm::vec2(1.f) / glm::vec2(mTexture.size());
35 const auto topLeft = clamped(pos);
36 const auto topRight = clamped(pos + glm::ivec2(1, 0));
37 const auto bottomLeft = clamped(pos + glm::ivec2(0, 1));
38 const auto bottomRight = clamped(pos + glm::ivec2(1, 1));
39 const auto texelSpaceUv = glm::mod(uv, texelSize) / texelSize;
41 const auto top = glm::mix(topLeft, topRight, texelSpaceUv.x);
42 const auto bottom = glm::mix(bottomLeft, bottomRight, texelSpaceUv.x);
43 return glm::mix(top, bottom, texelSpaceUv.y);
50 glm::vec4 clamped(glm::ivec2 pos)
const noexcept {
51 return mTexture.get(glm::clamp(pos, glm::ivec2(0), glm::ivec2(mTexture.size()) - 1));