From 31ba049666bdc794475e55ba550b5dbf3eab36dc Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sun, 28 Apr 2024 19:52:02 +0200 Subject: [PATCH] Short enums --- citro3d-sys/build.rs | 1 + citro3d-sys/src/gx.rs | 6 +++--- citro3d/src/attrib.rs | 11 +++++++++-- citro3d/src/buffer.rs | 2 +- citro3d/src/lib.rs | 2 +- citro3d/src/math.rs | 1 + citro3d/src/render.rs | 6 +++--- citro3d/src/render/transfer.rs | 2 +- citro3d/src/shader.rs | 6 +++--- citro3d/src/texenv.rs | 4 ++-- 10 files changed, 25 insertions(+), 16 deletions(-) diff --git a/citro3d-sys/build.rs b/citro3d-sys/build.rs index c429ee9..ac7b8df 100644 --- a/citro3d-sys/build.rs +++ b/citro3d-sys/build.rs @@ -93,6 +93,7 @@ fn main() { "-DARM11 ", "-D_3DS ", "-D__3DS__ ", + "-fshort-enums", ]) .parse_callbacks(Box::new(CustomCallbacks)) .generate() diff --git a/citro3d-sys/src/gx.rs b/citro3d-sys/src/gx.rs index c2cfb98..c2c7cb3 100644 --- a/citro3d-sys/src/gx.rs +++ b/citro3d-sys/src/gx.rs @@ -20,15 +20,15 @@ pub fn GX_TRANSFER_RAW_COPY(raw_copy: bool) -> u32 { #[inline] pub fn GX_TRANSFER_IN_FORMAT(format: GX_TRANSFER_FORMAT) -> u32 { - format << 8 + (format as u32) << 8 } #[inline] pub fn GX_TRANSFER_OUT_FORMAT(format: GX_TRANSFER_FORMAT) -> u32 { - format << 12 + (format as u32) << 12 } #[inline] pub fn GX_TRANSFER_SCALING(scale: GX_TRANSFER_SCALE) -> u32 { - scale << 24 + (scale as u32) << 24 } diff --git a/citro3d/src/attrib.rs b/citro3d/src/attrib.rs index f96ed44..035dc7d 100644 --- a/citro3d/src/attrib.rs +++ b/citro3d/src/attrib.rs @@ -38,11 +38,12 @@ impl Register { /// An attribute index. This is the attribute's actual index in the input buffer, /// and may correspond to any [`Register`] (or multiple) as input in the shader /// program. +#[allow(dead_code)] #[derive(Debug, Clone, Copy)] pub struct Index(u8); /// The data format of an attribute. -#[repr(u32)] +#[repr(u8)] #[derive(Debug, Clone, Copy)] #[doc(alias = "GPU_FORMATS")] pub enum Format { @@ -56,6 +57,12 @@ pub enum Format { Short = ctru_sys::GPU_SHORT, } +impl From for u8 { + fn from(value: Format) -> Self { + value as u8 + } +} + // SAFETY: the RWLock ensures unique access when mutating the global struct, and // we trust citro3d to Do The Right Thing™ and not mutate it otherwise. unsafe impl Sync for Info {} @@ -117,7 +124,7 @@ impl Info { // SAFETY: the &mut self.0 reference is only used to access fields in // the attribute info, not stored somewhere for later use let ret = unsafe { - citro3d_sys::AttrInfo_AddLoader(&mut self.0, register.0, format as u32, count.into()) + citro3d_sys::AttrInfo_AddLoader(&mut self.0, register.0, format.into(), count.into()) }; let Ok(idx) = ret.try_into() else { diff --git a/citro3d/src/buffer.rs b/citro3d/src/buffer.rs index b959f83..0a19ff3 100644 --- a/citro3d/src/buffer.rs +++ b/citro3d/src/buffer.rs @@ -49,7 +49,7 @@ impl Slice<'_> { } /// The geometric primitive to draw (i.e. what shapes the buffer data describes). -#[repr(u32)] +#[repr(u16)] #[derive(Debug, Clone, Copy)] #[doc(alias = "GPU_Primitive_t")] pub enum Primitive { diff --git a/citro3d/src/lib.rs b/citro3d/src/lib.rs index ba93984..5f4929d 100644 --- a/citro3d/src/lib.rs +++ b/citro3d/src/lib.rs @@ -141,7 +141,7 @@ impl Instance { unsafe { citro3d_sys::C3D_FrameBegin( // TODO: begin + end flags should be configurable - citro3d_sys::C3D_FRAME_SYNCDRAW.try_into().unwrap(), + citro3d_sys::C3D_FRAME_SYNCDRAW, ); } diff --git a/citro3d/src/math.rs b/citro3d/src/math.rs index ec2ebfb..a97e266 100644 --- a/citro3d/src/math.rs +++ b/citro3d/src/math.rs @@ -46,6 +46,7 @@ impl IVec { } /// A quaternion, internally represented the same way as [`FVec`]. +#[allow(dead_code)] #[doc(alias = "C3D_FQuat")] pub struct FQuat(citro3d_sys::C3D_FQuat); diff --git a/citro3d/src/render.rs b/citro3d/src/render.rs index 4960447..467139a 100644 --- a/citro3d/src/render.rs +++ b/citro3d/src/render.rs @@ -100,7 +100,7 @@ impl<'screen> Target<'screen> { bitflags::bitflags! { /// Indicate whether color, depth buffer, or both values should be cleared. #[doc(alias = "C3D_ClearBits")] - pub struct ClearFlags: u32 { + pub struct ClearFlags: u8 { /// Clear the color of the render target. const COLOR = citro3d_sys::C3D_CLEAR_COLOR; /// Clear the depth buffer value of the render target. @@ -111,7 +111,7 @@ bitflags::bitflags! { } /// The color format to use when rendering on the GPU. -#[repr(u32)] +#[repr(u8)] #[derive(Clone, Copy, Debug)] #[doc(alias = "GPU_COLORBUF")] pub enum ColorFormat { @@ -141,7 +141,7 @@ impl From for ColorFormat { } /// The depth buffer format to use when rendering. -#[repr(u32)] +#[repr(u8)] #[derive(Clone, Copy, Debug)] #[doc(alias = "GPU_DEPTHBUF")] #[doc(alias = "C3D_DEPTHTYPE")] diff --git a/citro3d/src/render/transfer.rs b/citro3d/src/render/transfer.rs index c2d9dc7..e17ec49 100644 --- a/citro3d/src/render/transfer.rs +++ b/citro3d/src/render/transfer.rs @@ -31,7 +31,7 @@ impl Flags { /// NOTE: this a distinct type from [`ColorFormat`] because they are not implicitly /// convertible to one another. Use [`From::from`] to get the [`Format`] corresponding /// to a given [`ColorFormat`]. -#[repr(u32)] +#[repr(u8)] #[doc(alias = "GX_TRANSFER_FORMAT")] pub enum Format { /// 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha. diff --git a/citro3d/src/shader.rs b/citro3d/src/shader.rs index 512022b..129cb4d 100644 --- a/citro3d/src/shader.rs +++ b/citro3d/src/shader.rs @@ -115,7 +115,7 @@ impl Drop for Program { } /// The type of a shader. -#[repr(u32)] +#[repr(u8)] #[derive(Clone, Copy)] pub enum Type { /// A vertex shader. @@ -124,9 +124,9 @@ pub enum Type { Geometry = ctru_sys::GPU_GEOMETRY_SHADER, } -impl From for u32 { +impl From for u8 { fn from(value: Type) -> Self { - value as u32 + value as u8 } } diff --git a/citro3d/src/texenv.rs b/citro3d/src/texenv.rs index 055366d..4758b0b 100644 --- a/citro3d/src/texenv.rs +++ b/citro3d/src/texenv.rs @@ -85,7 +85,7 @@ bitflags! { #[doc(alias = "GPU_TEVSRC")] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)] -#[repr(u32)] +#[repr(u8)] #[non_exhaustive] pub enum Source { PrimaryColor = ctru_sys::GPU_PRIMARY_COLOR, @@ -104,7 +104,7 @@ pub enum Source { #[doc(alias = "GPU_COMBINEFUNC")] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)] -#[repr(u32)] +#[repr(u8)] #[non_exhaustive] pub enum CombineFunc { Replace = ctru_sys::GPU_REPLACE,