Skip to main content

gcrecomp_runtime/texture/
mapper.rs

1// Texture mapping
2use anyhow::Result;
3
4pub struct TextureMapper {
5    // Handles texture coordinate mapping and UV transformations
6}
7
8impl TextureMapper {
9    pub fn new() -> Self {
10        Self {}
11    }
12
13    pub fn map_coordinates(&self, u: f32, v: f32, wrap_mode: WrapMode) -> (f32, f32) {
14        match wrap_mode {
15            WrapMode::Clamp => (u.clamp(0.0, 1.0), v.clamp(0.0, 1.0)),
16            WrapMode::Repeat => (u.fract(), v.fract()),
17            WrapMode::Mirror => {
18                let u_mirror = if (u as i32) % 2 == 0 {
19                    u.fract()
20                } else {
21                    1.0 - u.fract()
22                };
23                let v_mirror = if (v as i32) % 2 == 0 {
24                    v.fract()
25                } else {
26                    1.0 - v.fract()
27                };
28                (u_mirror, v_mirror)
29            }
30        }
31    }
32}
33
34#[derive(Debug, Clone, Copy)]
35pub enum WrapMode {
36    Clamp,
37    Repeat,
38    Mirror,
39}