citro3d/render/
transfer.rs

1use citro3d_sys::{GX_TRANSFER_IN_FORMAT, GX_TRANSFER_OUT_FORMAT};
2use ctru_sys::GX_TRANSFER_FORMAT;
3
4use super::ColorFormat;
5
6/// Control flags for a GX data transfer.
7#[derive(Default, Clone, Copy)]
8pub struct Flags(u32);
9
10impl Flags {
11    /// Set the input format of the data transfer.
12    #[must_use]
13    pub fn in_format(self, fmt: Format) -> Self {
14        Self(self.0 | GX_TRANSFER_IN_FORMAT(fmt as GX_TRANSFER_FORMAT))
15    }
16
17    /// Set the output format of the data transfer.
18    #[must_use]
19    pub fn out_format(self, fmt: Format) -> Self {
20        Self(self.0 | GX_TRANSFER_OUT_FORMAT(fmt as GX_TRANSFER_FORMAT))
21    }
22
23    #[must_use]
24    pub fn bits(self) -> u32 {
25        self.0
26    }
27}
28
29/// The color format to use when transferring data to/from the GPU.
30///
31/// NOTE: this a distinct type from [`ColorFormat`] because they are not implicitly
32/// convertible to one another. Use [`From::from`] to get the [`Format`] corresponding
33/// to a given [`ColorFormat`].
34#[repr(u8)]
35#[doc(alias = "GX_TRANSFER_FORMAT")]
36pub enum Format {
37    /// 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha.
38    RGBA8 = ctru_sys::GX_TRANSFER_FMT_RGBA8,
39    /// 8-bit Red + 8-bit Green + 8-bit Blue.
40    RGB8 = ctru_sys::GX_TRANSFER_FMT_RGB8,
41    /// 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha.
42    RGB565 = ctru_sys::GX_TRANSFER_FMT_RGB565,
43    /// 5-bit Red + 6-bit Green + 5-bit Blue.
44    RGB5A1 = ctru_sys::GX_TRANSFER_FMT_RGB5A1,
45    /// 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha.
46    RGBA4 = ctru_sys::GX_TRANSFER_FMT_RGBA4,
47}
48
49impl From<ColorFormat> for Format {
50    fn from(color_fmt: ColorFormat) -> Self {
51        match color_fmt {
52            ColorFormat::RGBA8 => Self::RGBA8,
53            ColorFormat::RGB8 => Self::RGB8,
54            ColorFormat::RGBA5551 => Self::RGB5A1,
55            ColorFormat::RGB565 => Self::RGB565,
56            ColorFormat::RGBA4 => Self::RGBA4,
57        }
58    }
59}