Browse Source

Minor docs and error handling cleanup

pull/27/head
Ian Chamberlain 1 year ago
parent
commit
7084a22764
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 11
      citro3d/src/error.rs
  2. 8
      citro3d/src/math.rs
  3. 18
      citro3d/src/shader.rs

11
citro3d/src/error.rs

@ -1,5 +1,6 @@
//! General-purpose error and result types returned by public APIs of this crate. //! General-purpose error and result types returned by public APIs of this crate.
use std::ffi::NulError;
use std::num::TryFromIntError; use std::num::TryFromIntError;
use std::sync::TryLockError; use std::sync::TryLockError;
@ -31,6 +32,10 @@ pub enum Error {
/// The given memory could not be converted to a physical address for sharing /// The given memory could not be converted to a physical address for sharing
/// with the GPU. Data should be allocated with [`ctru::linear`]. /// with the GPU. Data should be allocated with [`ctru::linear`].
InvalidMemoryLocation, InvalidMemoryLocation,
/// The given name was not valid for the requested purpose.
InvalidName,
/// The requested resource could not be found.
NotFound,
} }
impl From<TryFromIntError> for Error { impl From<TryFromIntError> for Error {
@ -44,3 +49,9 @@ impl<T> From<TryLockError<T>> for Error {
Self::LockHeld Self::LockHeld
} }
} }
impl From<NulError> for Error {
fn from(_: NulError) -> Self {
Self::InvalidName
}
}

8
citro3d/src/math.rs

@ -4,16 +4,16 @@ use std::mem::MaybeUninit;
use crate::AspectRatio; use crate::AspectRatio;
/// A 4-vector of [`u8`]s. /// A 4-vector of `u8`s.
pub struct IntVec(citro3d_sys::C3D_IVec); 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); 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); 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); pub struct Matrix(citro3d_sys::C3D_Mtx);
/// Whether to use left-handed or right-handed coordinates for calculations. /// Whether to use left-handed or right-handed coordinates for calculations.

18
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<i8> { pub fn get_uniform_location(&self, name: &str) -> crate::Result<i8> {
let vertex_instance = unsafe { (*self.as_raw()).vertexShader }; let vertex_instance = unsafe { (*self.as_raw()).vertexShader };
if vertex_instance.is_null() { assert!(
return Err(todo!()); !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 = let idx =
unsafe { ctru_sys::shaderInstanceGetUniformLocation(vertex_instance, name.as_ptr()) }; unsafe { ctru_sys::shaderInstanceGetUniformLocation(vertex_instance, name.as_ptr()) };
if idx < 0 { if idx < 0 {
Err(todo!()) Err(crate::Error::NotFound)
} else { } else {
Ok(idx) Ok(idx)
} }

Loading…
Cancel
Save