Skip to main content

optic_core/
enums.rs

1/// Polygon rasterization mode.
2#[derive(Copy, Clone, Debug, PartialEq)]
3pub enum PolyMode {
4    Points,
5    WireFrame,
6    Filled,
7}
8
9/// Face culling direction.
10#[derive(Copy, Clone, Debug, PartialEq)]
11pub enum Cull {
12    Clock,
13    AntiClock,
14}
15
16/// Primitive topology for draw calls.
17#[derive(Copy, Clone, Debug, Default, PartialEq)]
18pub enum DrawMode {
19    Points,
20    Lines,
21    #[default]
22    Triangles,
23    Strip,
24}
25
26/// Texture image format, encoding channel count and bit depth.
27///
28/// Each variant carries the per-channel bit depth (e.g. `RGBA(8)` = 4×8-bit).
29#[derive(Copy, Clone, Debug, PartialEq)]
30pub enum ImgFormat {
31    R(u8),
32    RG(u8),
33    RGB(u8),
34    RGBA(u8),
35}
36
37impl ImgFormat {
38    /// Number of color channels (1–4).
39    pub fn channels(&self) -> u8 {
40        match self {
41            ImgFormat::R(_) => 1,
42            ImgFormat::RG(_) => 2,
43            ImgFormat::RGB(_) => 3,
44            ImgFormat::RGBA(_) => 4,
45        }
46    }
47    /// Bits per channel.
48    pub fn bit_depth(&self) -> u8 {
49        *match self {
50            ImgFormat::R(bd) => bd,
51            ImgFormat::RG(bd) => bd,
52            ImgFormat::RGB(bd) => bd,
53            ImgFormat::RGBA(bd) => bd,
54        }
55    }
56    /// Total bytes per pixel (channels × bit_depth / 8).
57    pub fn pixel_size(&self) -> u8 {
58        self.channels() * self.bit_depth() / 8
59    }
60    /// Construct from channel count and bit depth.
61    ///
62    /// Channels ≥ 4 produce `RGBA`. Unknown channels default to `RGBA`.
63    pub fn from(channels: u8, bit_depth: u8) -> ImgFormat {
64        match channels {
65            1 => ImgFormat::R(bit_depth),
66            2 => ImgFormat::RG(bit_depth),
67            3 => ImgFormat::RGB(bit_depth),
68            _ => ImgFormat::RGBA(bit_depth),
69        }
70    }
71}
72
73/// Texture filter (minification/magnification) mode.
74#[derive(Debug, Clone, Copy, PartialEq)]
75pub enum ImgFilter {
76    Closest,
77    Linear,
78}
79
80/// Texture wrap (addressing) mode.
81#[derive(Debug, Clone, Copy, PartialEq)]
82pub enum ImgWrap {
83    Repeat,
84    Extend,
85    Clip,
86}
87
88/// Vertex attribute data type.
89#[derive(Clone, Debug, PartialEq)]
90pub enum ATTRType {
91    U8,
92    I8,
93    U16,
94    I16,
95    U32,
96    I32,
97    F32,
98    F64,
99}