diff --git a/citro3d/src/error.rs b/citro3d/src/error.rs index 29acd73..9a99089 100644 --- a/citro3d/src/error.rs +++ b/citro3d/src/error.rs @@ -1,5 +1,6 @@ //! General-purpose error and result types returned by public APIs of this crate. +use std::ffi::NulError; use std::num::TryFromIntError; use std::sync::TryLockError; @@ -31,6 +32,10 @@ pub enum Error { /// The given memory could not be converted to a physical address for sharing /// with the GPU. Data should be allocated with [`ctru::linear`]. InvalidMemoryLocation, + /// The given name was not valid for the requested purpose. + InvalidName, + /// The requested resource could not be found. + NotFound, } impl From for Error { @@ -44,3 +49,9 @@ impl From> for Error { Self::LockHeld } } + +impl From for Error { + fn from(_: NulError) -> Self { + Self::InvalidName + } +} diff --git a/citro3d/src/math.rs b/citro3d/src/math.rs index 0ee26f1..2ce9dd6 100644 --- a/citro3d/src/math.rs +++ b/citro3d/src/math.rs @@ -4,16 +4,16 @@ use std::mem::MaybeUninit; use crate::AspectRatio; -/// A 4-vector of [`u8`]s. +/// A 4-vector of `u8`s. pub struct IntVec(citro3d_sys::C3D_IVec); -/// A 4-vector of [`f32`]s. +/// A 4-vector of `f32`s. pub struct FloatVec(citro3d_sys::C3D_FVec); -/// A quaternion, internally represented the same way as [`FVec`]. +/// A quaternion, internally represented the same way as [`FloatVec`]. pub struct Quaternion(citro3d_sys::C3D_FQuat); -/// A 4x4 row-major matrix of [`f32`]s. +/// A 4x4 row-major matrix of `f32`s. pub struct Matrix(citro3d_sys::C3D_Mtx); /// Whether to use left-handed or right-handed coordinates for calculations. diff --git a/citro3d/src/shader.rs b/citro3d/src/shader.rs index 8500e2d..158fbb5 100644 --- a/citro3d/src/shader.rs +++ b/citro3d/src/shader.rs @@ -67,20 +67,26 @@ impl Program { } } - // TODO: newtype for index? + /// Get the index of a uniform by name. + /// + /// # Errors + /// + /// * If the given `name` contains a null byte + /// * If a uniform with the given `name` could not be found pub fn get_uniform_location(&self, name: &str) -> crate::Result { let vertex_instance = unsafe { (*self.as_raw()).vertexShader }; - if vertex_instance.is_null() { - return Err(todo!()); - } + assert!( + !vertex_instance.is_null(), + "vertex shader should never be null!" + ); - let name = CString::new(name).map_err(|e| -> crate::Error { todo!() })?; + let name = CString::new(name)?; let idx = unsafe { ctru_sys::shaderInstanceGetUniformLocation(vertex_instance, name.as_ptr()) }; if idx < 0 { - Err(todo!()) + Err(crate::Error::NotFound) } else { Ok(idx) }