diff --git a/citro3d-sys/Cargo.toml b/citro3d-sys/Cargo.toml index c1f1ee0..b0bd4ab 100644 --- a/citro3d-sys/Cargo.toml +++ b/citro3d-sys/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" [dependencies] libc = "0.2.116" -ctru-sys = { path = "../../ctru-rs/ctru-sys" } +ctru-sys = { git = "https://github.com/Meziu/ctru-rs.git" } diff --git a/citro3d-sys/src/lib.rs b/citro3d-sys/src/lib.rs index 1b58163..6a5b301 100644 --- a/citro3d-sys/src/lib.rs +++ b/citro3d-sys/src/lib.rs @@ -3,6 +3,7 @@ #![feature(untagged_unions)] // used for [`C3D_Mtx`] pub mod base; +pub mod renderqueue; pub mod texenv; pub mod uniforms; @@ -15,7 +16,6 @@ mod bindings; pub use base::*; pub use bindings::*; -pub use uniforms::*; - -#[cfg(todo = "gpu_tev_macros")] +pub use renderqueue::*; pub use texenv::*; +pub use uniforms::*; diff --git a/citro3d-sys/src/renderqueue.rs b/citro3d-sys/src/renderqueue.rs new file mode 100644 index 0000000..3385cfa --- /dev/null +++ b/citro3d-sys/src/renderqueue.rs @@ -0,0 +1,10 @@ +//! `` + +pub unsafe fn C3D_RenderTargetClear( + target: *mut crate::C3D_RenderTarget, + clearBits: crate::C3D_ClearBits, + clearColor: u32, + clearDepth: u32, +) { + crate::C3D_FrameBufClear(&mut (*target).frameBuf, clearBits, clearColor, clearDepth); +} diff --git a/citro3d-sys/src/texenv.rs b/citro3d-sys/src/texenv.rs index d296f60..5679987 100644 --- a/citro3d-sys/src/texenv.rs +++ b/citro3d-sys/src/texenv.rs @@ -1,11 +1,45 @@ -#![cfg(todo = "gpu_tev_macros")] -//! `` +//! Definitions for ``. +//! Most of these functions are `static inline` so they don't get generated by `bindgen`. + +use core::ops::{BitOr, Shl}; -use super::*; use libc::c_int; +use super::*; + +// TODO: why are these two different macros in C? + +/// Creates a texture combiner source parameter from three sources. +fn gpu_tevsources(a: T, b: T, c: T) -> T +where + T: BitOr + Shl, +{ + a | b << 4 | c << 8 +} + +/// Creates a texture combiner operand parameter from three operands. +fn gpu_tevoperands(a: T, b: T, c: T) -> T +where + T: BitOr + Shl, +{ + a | b << 4 | c << 8 +} + +pub unsafe fn C3D_TexEnvInit(env: *mut C3D_TexEnv) { + (*env).srcRgb = gpu_tevsources(ctru_sys::GPU_PREVIOUS, 0, 0) as u16; + (*env).srcAlpha = (*env).srcRgb; + (*env).__bindgen_anon_1.opAll = 0; + (*env).funcRgb = ctru_sys::GPU_REPLACE as u16; + (*env).funcAlpha = (*env).funcRgb; + (*env).color = 0xFFFFFFFF; + (*env).scaleRgb = ctru_sys::GPU_TEVSCALE_1 as u16; + (*env).scaleAlpha = ctru_sys::GPU_TEVSCALE_1 as u16; +} + +// TODO: maybe + pub unsafe fn C3D_TexEnvSrc(env: *mut C3D_TexEnv, mode: c_int, s1: c_int, s2: c_int, s3: c_int) { - let param = gpu_tevsources!(s1, s2, s3); + let param = gpu_tevsources(s1, s2, s3); if mode & C3D_RGB as i32 != 0 { (*env).srcRgb = param as u16; @@ -17,14 +51,21 @@ pub unsafe fn C3D_TexEnvSrc(env: *mut C3D_TexEnv, mode: c_int, s1: c_int, s2: c_ } pub unsafe fn C3D_TexEnvOp(env: *mut C3D_TexEnv, mode: c_int, o1: c_int, o2: c_int, o3: c_int) { - let param = gpu_tevoperands!(o1, o2, o3); + let param = gpu_tevoperands(o1, o2, o3); if mode & C3D_RGB as i32 != 0 { - (*env).opRgb = param as u16; + // (*env).opRgb = param as u16; + (*env) + .__bindgen_anon_1 + .__bindgen_anon_1 + .set_opRgb(param as u32); } if mode & C3D_Alpha as i32 != 0 { - (*env).opAlpha = param as u16; + (*env) + .__bindgen_anon_1 + .__bindgen_anon_1 + .set_opAlpha(param as u32); } }