rust3ds / citro3d-rs

Rust bindings and safe wrappers for citro3d
https://rust3ds.github.io/citro3d-rs
14 stars 11 forks source link

Safe `Mtx_PerspStereoTilt` API and proper stereo 3D example #21

Closed ian-h-chamberlain closed 1 year ago

ian-h-chamberlain commented 1 year ago

citro3d provides a dedicated Mtx_PerspStereoTilt for creating a tilted perspective matrix, and we should use ctru_sys::osGetSliderValue to adjust the strength of the tilt

Originally posted by @Firepal in https://github.com/rust3ds/citro3d-rs/issues/19#issuecomment-1523345502

Firepal commented 1 year ago

The way we safely expose Citro3D matrices depends a whole lot on how we're gonna let developers safely pass matrices as uniforms for vertex shaders... Uniforms are their whole can of worms...

ian-h-chamberlain commented 1 year ago

Yeah, this will definitely take some thought. Ideally, I would love to use an existing Rust library for handling matrix math etc., but I'm sure there would be some runtime cost converting back and forth which would not be ideal (maybe could be a Cargo feature, for convenience at the cost of performance?).

Probably there would be similar concerns with some other Citro3D "math types" although there aren't too many of them.

Regarding uniforms, we might just be able to limit to the fairly small set of types defined by citro3d, and write wrappers just for those. I think it's probably out of scope to allow arbitrary writes to the uniform buffer (with C3D_FVUnifWritePtr), so it maybe could even be a trait like

trait Uniform {}

impl Uniform for bool {}
impl Uniform for (i32, i32, i32, i32) {} // ivec4
impl<const N: usize> Uniform for SafeMatrix4Wrapper<N> {} // or whatever matrix type we use
ian-h-chamberlain commented 1 year ago

Mostly done in #27 although there may be some room for improvement on the uniform handling. I think I'll close this for now, and track any further changes in separate issues as they come up.