Skip to content

Commit cd9cc35

Browse files
authored
Merge pull request #76 from rust3ds/feature/map_gpu_enums
Map gpu enums
2 parents 19cf482 + c8d2cef commit cd9cc35

File tree

6 files changed

+1423
-1
lines changed

6 files changed

+1423
-1
lines changed

citro3d/src/fog.rs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//! Fog/Gas unit configuration.
2+
3+
/// Fog modes.
4+
#[repr(u8)]
5+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6+
#[doc(alias = "GPU_FOGMODE")]
7+
pub enum FogMode {
8+
/// Fog/Gas unit disabled.
9+
#[doc(alias = "GPU_NO_FOG")]
10+
NoFog = ctru_sys::GPU_NO_FOG,
11+
12+
/// Fog/Gas unit configured in Fog mode.
13+
#[doc(alias = "GPU_FOG")]
14+
Fog = ctru_sys::GPU_FOG,
15+
16+
/// Fog/Gas unit configured in Gas mode.
17+
#[doc(alias = "GPU_GAS")]
18+
Gas = ctru_sys::GPU_GAS,
19+
}
20+
21+
impl TryFrom<u8> for FogMode {
22+
type Error = String;
23+
fn try_from(value: u8) -> Result<Self, Self::Error> {
24+
match value {
25+
ctru_sys::GPU_NO_FOG => Ok(FogMode::NoFog),
26+
ctru_sys::GPU_FOG => Ok(FogMode::Fog),
27+
ctru_sys::GPU_GAS => Ok(FogMode::Gas),
28+
_ => Err("invalid value for FogMode".to_string()),
29+
}
30+
}
31+
}
32+
33+
/// Gas shading density source values.
34+
#[repr(u8)]
35+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36+
#[doc(alias = "GPU_GASMODE")]
37+
pub enum GasMode {
38+
/// Plain density.
39+
#[doc(alias = "GPU_PLAIN_DENSITY")]
40+
PlainDensity = ctru_sys::GPU_PLAIN_DENSITY,
41+
42+
/// Depth density.
43+
#[doc(alias = "GPU_DEPTH_DENSITY")]
44+
DepthDensity = ctru_sys::GPU_DEPTH_DENSITY,
45+
}
46+
47+
impl TryFrom<u8> for GasMode {
48+
type Error = String;
49+
fn try_from(value: u8) -> Result<Self, Self::Error> {
50+
match value {
51+
ctru_sys::GPU_PLAIN_DENSITY => Ok(GasMode::PlainDensity),
52+
ctru_sys::GPU_DEPTH_DENSITY => Ok(GasMode::DepthDensity),
53+
_ => Err("invalid value for GasMode".to_string()),
54+
}
55+
}
56+
}
57+
58+
/// Gas color LUT inputs.
59+
#[repr(u8)]
60+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
61+
#[doc(alias = "GPU_GASLUTINPUT")]
62+
pub enum GasLutInput {
63+
/// Gas density used as input.
64+
#[doc(alias = "GPU_GAS_DENSITY")]
65+
Density = ctru_sys::GPU_GAS_DENSITY,
66+
67+
/// Light factor used as input.
68+
#[doc(alias = "GPU_GAS_LIGHT_FACTOR")]
69+
LightFactor = ctru_sys::GPU_GAS_LIGHT_FACTOR,
70+
}
71+
72+
impl TryFrom<u8> for GasLutInput {
73+
type Error = String;
74+
fn try_from(value: u8) -> Result<Self, Self::Error> {
75+
match value {
76+
ctru_sys::GPU_GAS_DENSITY => Ok(GasLutInput::Density),
77+
ctru_sys::GPU_GAS_LIGHT_FACTOR => Ok(GasLutInput::LightFactor),
78+
_ => Err("invalid value for GasLutInput".to_string()),
79+
}
80+
}
81+
}
82+
83+
/// Gas depth functions.
84+
#[repr(u8)]
85+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
86+
#[doc(alias = "GPU_GASDEPTHFUNC")]
87+
pub enum GasDepthFunction {
88+
/// Never pass (0).
89+
#[doc(alias = "GPU_GAS_NEVER")]
90+
Never = ctru_sys::GPU_GAS_NEVER,
91+
92+
/// Always pass (1).
93+
#[doc(alias = "GPU_GAS_ALWAYS")]
94+
Always = ctru_sys::GPU_GAS_ALWAYS,
95+
96+
/// Pass if greater than (1-X).
97+
#[doc(alias = "GPU_GAS_GREATER")]
98+
Greater = ctru_sys::GPU_GAS_GREATER,
99+
100+
/// Pass if less than (X).
101+
#[doc(alias = "GPU_GAS_LESS")]
102+
Less = ctru_sys::GPU_GAS_LESS,
103+
}
104+
105+
impl TryFrom<u8> for GasDepthFunction {
106+
type Error = String;
107+
108+
fn try_from(value: u8) -> Result<Self, Self::Error> {
109+
match value {
110+
ctru_sys::GPU_GAS_NEVER => Ok(GasDepthFunction::Never),
111+
ctru_sys::GPU_GAS_ALWAYS => Ok(GasDepthFunction::Always),
112+
ctru_sys::GPU_GAS_GREATER => Ok(GasDepthFunction::Greater),
113+
ctru_sys::GPU_GAS_LESS => Ok(GasDepthFunction::Less),
114+
_ => Err("invalid value for GasDepthFunction".to_string()),
115+
}
116+
}
117+
}

citro3d/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ pub mod attrib;
2121
pub mod buffer;
2222
pub mod color;
2323
pub mod error;
24+
pub mod fog;
2425
pub mod light;
2526
pub mod math;
2627
pub mod render;
2728
pub mod shader;
2829
pub mod texenv;
30+
pub mod texture;
2931
pub mod uniform;
3032

3133
use std::cell::{OnceCell, RefMut};

citro3d/src/light.rs

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl Light {
430430
}
431431
}
432432

433-
/// Sets the spotlight direction of the light (relatively to the light's source [position](set_position)).
433+
/// Sets the spotlight direction of the light (relatively to the light's source [position](Light::set_position)).
434434
#[doc(alias = "C3D_LightSpotDir")]
435435
pub fn set_spotlight_direction(self: Pin<&mut Self>, direction: FVec3) {
436436
unsafe {
@@ -636,6 +636,21 @@ pub enum LutInput {
636636
ViewHalf = ctru_sys::GPU_LUTINPUT_VH,
637637
}
638638

639+
impl TryFrom<u8> for LutInput {
640+
type Error = String;
641+
fn try_from(value: u8) -> Result<Self, Self::Error> {
642+
match value {
643+
ctru_sys::GPU_LUTINPUT_NH => Ok(Self::NormalHalf),
644+
ctru_sys::GPU_LUTINPUT_VH => Ok(Self::ViewHalf),
645+
ctru_sys::GPU_LUTINPUT_NV => Ok(Self::NormalView),
646+
ctru_sys::GPU_LUTINPUT_LN => Ok(Self::LightNormal),
647+
ctru_sys::GPU_LUTINPUT_SP => Ok(Self::LightSpotLight),
648+
ctru_sys::GPU_LUTINPUT_CP => Ok(Self::CosPhi),
649+
_ => Err("invalid value for LutInput".to_string()),
650+
}
651+
}
652+
}
653+
639654
/// Identifier/index for the various LUTs associated to a [`LightEnv`].
640655
///
641656
/// # Notes
@@ -664,6 +679,23 @@ pub enum LutId {
664679
DistanceAttenuation = ctru_sys::GPU_LUT_DA,
665680
}
666681

682+
impl TryFrom<u8> for LutId {
683+
type Error = String;
684+
fn try_from(value: u8) -> Result<Self, Self::Error> {
685+
match value {
686+
ctru_sys::GPU_LUT_D0 => Ok(Self::D0),
687+
ctru_sys::GPU_LUT_D1 => Ok(Self::D1),
688+
ctru_sys::GPU_LUT_SP => Ok(Self::Spotlight),
689+
ctru_sys::GPU_LUT_FR => Ok(Self::Fresnel),
690+
ctru_sys::GPU_LUT_RB => Ok(Self::ReflectBlue),
691+
ctru_sys::GPU_LUT_RG => Ok(Self::ReflectGreen),
692+
ctru_sys::GPU_LUT_RR => Ok(Self::ReflectRed),
693+
ctru_sys::GPU_LUT_DA => Ok(Self::DistanceAttenuation),
694+
_ => Err("invalid value for LutId".to_string()),
695+
}
696+
}
697+
}
698+
667699
#[doc(alias = "GPU_FRESNELSEL")]
668700
#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]
669701
#[repr(u8)]
@@ -678,6 +710,94 @@ pub enum FresnelSelector {
678710
Both = ctru_sys::GPU_PRI_SEC_ALPHA_FRESNEL,
679711
}
680712

713+
impl TryFrom<u8> for FresnelSelector {
714+
type Error = String;
715+
fn try_from(value: u8) -> Result<Self, Self::Error> {
716+
match value {
717+
ctru_sys::GPU_NO_FRESNEL => Ok(Self::None),
718+
ctru_sys::GPU_PRI_ALPHA_FRESNEL => Ok(Self::PrimaryAlpha),
719+
ctru_sys::GPU_SEC_ALPHA_FRESNEL => Ok(Self::SecondaryAlpha),
720+
ctru_sys::GPU_PRI_SEC_ALPHA_FRESNEL => Ok(Self::Both),
721+
_ => Err("invalid value for FresnelSelector".to_string()),
722+
}
723+
}
724+
}
725+
726+
/// LUT scaling factors.
727+
#[repr(u8)]
728+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
729+
#[doc(alias = "GPU_LIGHTLUTSCALER")]
730+
pub enum LutScale {
731+
/// 1x scale.
732+
#[doc(alias = "GPU_LUTSCALER_1x")]
733+
OneX = ctru_sys::GPU_LUTSCALER_1x,
734+
735+
/// 2x scale.
736+
#[doc(alias = "GPU_LUTSCALER_2x")]
737+
TwoX = ctru_sys::GPU_LUTSCALER_2x,
738+
739+
/// 4x scale.
740+
#[doc(alias = "GPU_LUTSCALER_4x")]
741+
FourX = ctru_sys::GPU_LUTSCALER_4x,
742+
743+
/// 8x scale.
744+
#[doc(alias = "GPU_LUTSCALER_8x")]
745+
EightX = ctru_sys::GPU_LUTSCALER_8x,
746+
747+
/// 0.25x scale.
748+
#[doc(alias = "GPU_LUTSCALER_0_25x")]
749+
QuarterX = ctru_sys::GPU_LUTSCALER_0_25x,
750+
751+
/// 0.5x scale.
752+
#[doc(alias = "GPU_LUTSCALER_0_5x")]
753+
HalfX = ctru_sys::GPU_LUTSCALER_0_5x,
754+
}
755+
756+
impl TryFrom<u8> for LutScale {
757+
type Error = String;
758+
fn try_from(value: u8) -> Result<Self, Self::Error> {
759+
match value {
760+
ctru_sys::GPU_LUTSCALER_1x => Ok(Self::OneX),
761+
ctru_sys::GPU_LUTSCALER_2x => Ok(Self::TwoX),
762+
ctru_sys::GPU_LUTSCALER_4x => Ok(Self::FourX),
763+
ctru_sys::GPU_LUTSCALER_8x => Ok(Self::EightX),
764+
ctru_sys::GPU_LUTSCALER_0_25x => Ok(Self::QuarterX),
765+
ctru_sys::GPU_LUTSCALER_0_5x => Ok(Self::HalfX),
766+
_ => Err("invalid value for LutScale".to_string()),
767+
}
768+
}
769+
}
770+
771+
/// Bump map modes.
772+
#[repr(u8)]
773+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
774+
#[doc(alias = "GPU_BUMPMODE")]
775+
pub enum BumpMappingMode {
776+
/// Disabled.
777+
#[doc(alias = "GPU_BUMP_NOT_USED")]
778+
NotUsed = ctru_sys::GPU_BUMP_NOT_USED,
779+
780+
/// Bump as bump mapping.
781+
#[doc(alias = "GPU_BUMP_AS_BUMP")]
782+
AsBump = ctru_sys::GPU_BUMP_AS_BUMP,
783+
784+
/// Bump as tangent/normal mapping.
785+
#[doc(alias = "GPU_BUMP_AS_TANG")]
786+
AsTangent = ctru_sys::GPU_BUMP_AS_TANG,
787+
}
788+
789+
impl TryFrom<u8> for BumpMappingMode {
790+
type Error = String;
791+
fn try_from(value: u8) -> Result<Self, Self::Error> {
792+
match value {
793+
ctru_sys::GPU_BUMP_NOT_USED => Ok(BumpMappingMode::NotUsed),
794+
ctru_sys::GPU_BUMP_AS_BUMP => Ok(BumpMappingMode::AsBump),
795+
ctru_sys::GPU_BUMP_AS_TANG => Ok(BumpMappingMode::AsTangent),
796+
_ => Err("invalid value for BumpMappingMode".to_string()),
797+
}
798+
}
799+
}
800+
681801
#[cfg(test)]
682802
mod tests {
683803
use super::Lut;

citro3d/src/render.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use ctru_sys::{GPU_COLORBUF, GPU_DEPTHBUF};
1313

1414
use crate::{Error, RenderQueue, Result};
1515

16+
pub mod effect;
1617
mod transfer;
1718

1819
/// A render target for `citro3d`. Frame data will be written to this target

0 commit comments

Comments
 (0)