diff --git a/citro3d-sys/src/base.rs b/citro3d-sys/src/base.rs index 7ca1ada..16463dc 100644 --- a/citro3d-sys/src/base.rs +++ b/citro3d-sys/src/base.rs @@ -1,9 +1,9 @@ -//! `` +//! Definitions from `` -use super::*; -use libc::c_int; +use crate::C3D_FixedAttribGetWritePtr; -pub unsafe fn C3D_FixedAttribSet(id: c_int, x: f32, y: f32, z: f32, w: f32) { +#[inline] +pub unsafe fn C3D_FixedAttribSet(id: libc::c_int, x: f32, y: f32, z: f32, w: f32) { let ptr = C3D_FixedAttribGetWritePtr(id); (*ptr).c.copy_from_slice(&[x, y, z, w]); } diff --git a/citro3d-sys/src/gx.rs b/citro3d-sys/src/gx.rs new file mode 100644 index 0000000..9be28ed --- /dev/null +++ b/citro3d-sys/src/gx.rs @@ -0,0 +1,33 @@ +//! Helper functions based on `<3ds/gpu/gx.h>`. + +use crate::{GX_TRANSFER_FORMAT, GX_TRANSFER_SCALE}; + +#[inline] +pub fn GX_TRANSFER_FLIP_VERT(flip: bool) -> u32 { + flip as u32 +} + +#[inline] +pub fn GX_TRANSFER_OUT_TILED(tiled: bool) -> u32 { + (tiled as u32) << 1 +} + +#[inline] +pub fn GX_TRANSFER_RAW_COPY(raw_copy: bool) -> u32 { + (raw_copy as u32) << 3 +} + +#[inline] +pub fn GX_TRANSFER_IN_FORMAT(format: GX_TRANSFER_FORMAT) -> u32 { + format << 8 +} + +#[inline] +pub fn GX_TRANSFER_OUT_FORMAT(format: GX_TRANSFER_FORMAT) -> u32 { + format << 12 +} + +#[inline] +pub fn GX_TRANSFER_SCALING(scale: GX_TRANSFER_SCALE) -> u32 { + scale << 24 +} diff --git a/citro3d-sys/src/lib.rs b/citro3d-sys/src/lib.rs index 8e17aae..3426e83 100644 --- a/citro3d-sys/src/lib.rs +++ b/citro3d-sys/src/lib.rs @@ -6,6 +6,7 @@ #![allow(clippy::all)] pub mod base; +pub mod gx; pub mod renderqueue; pub mod texenv; pub mod uniforms; @@ -14,6 +15,7 @@ mod bindings; pub use base::*; pub use bindings::*; +pub use gx::*; pub use renderqueue::*; pub use texenv::*; pub use uniforms::*; diff --git a/citro3d-sys/src/renderqueue.rs b/citro3d-sys/src/renderqueue.rs index 3385cfa..cb7050f 100644 --- a/citro3d-sys/src/renderqueue.rs +++ b/citro3d-sys/src/renderqueue.rs @@ -1,5 +1,6 @@ -//! `` +//! Definitions from `` +#[inline] pub unsafe fn C3D_RenderTargetClear( target: *mut crate::C3D_RenderTarget, clearBits: crate::C3D_ClearBits, diff --git a/citro3d-sys/src/texenv.rs b/citro3d-sys/src/texenv.rs index f7ef661..f52ffac 100644 --- a/citro3d-sys/src/texenv.rs +++ b/citro3d-sys/src/texenv.rs @@ -1,9 +1,8 @@ -//! Definitions for ``. +//! Definitions from ``. +//! //! Most of these functions are `static inline` so they don't get generated by `bindgen`. //! See . -// TODO: probably should mark these all as #[inline] for parity with the C code - use core::ops::{BitOr, Shl}; use libc::c_int; @@ -13,6 +12,7 @@ use super::*; // TODO: why are these two different macros in C? /// Creates a texture combiner source parameter from three sources. +#[inline] fn GPU_TEVSOURCES(a: T, b: T, c: T) -> T where T: BitOr + Shl, @@ -21,6 +21,7 @@ where } /// Creates a texture combiner operand parameter from three operands. +#[inline] fn GPU_TEVOPERANDS(a: T, b: T, c: T) -> T where T: BitOr + Shl, @@ -28,6 +29,7 @@ where a | b << 4 | c << 8 } +#[inline] pub unsafe fn C3D_TexEnvInit(env: *mut C3D_TexEnv) { (*env).srcRgb = GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0) as u16; (*env).srcAlpha = (*env).srcRgb; @@ -39,6 +41,7 @@ pub unsafe fn C3D_TexEnvInit(env: *mut C3D_TexEnv) { (*env).scaleAlpha = GPU_TEVSCALE_1 as u16; } +#[inline] pub unsafe fn C3D_TexEnvSrc( env: *mut C3D_TexEnv, mode: C3D_TexEnvMode, @@ -58,6 +61,7 @@ pub unsafe fn C3D_TexEnvSrc( } // TODO: match API of texenv.h +#[inline] pub unsafe fn C3D_TexEnvOp( env: *mut C3D_TexEnv, mode: C3D_TexEnvMode, @@ -83,6 +87,7 @@ pub unsafe fn C3D_TexEnvOp( } } +#[inline] pub unsafe fn C3D_TexEnvFunc(env: *mut C3D_TexEnv, mode: C3D_TexEnvMode, param: GPU_COMBINEFUNC) { if mode & C3D_RGB != 0 { (*env).funcRgb = param as u16; diff --git a/citro3d-sys/src/uniforms.rs b/citro3d-sys/src/uniforms.rs index c2b0290..b2df616 100644 --- a/citro3d-sys/src/uniforms.rs +++ b/citro3d-sys/src/uniforms.rs @@ -1,11 +1,13 @@ -//! `` +//! Definitions from`` -use super::*; - -use libc::c_int; +use super::{C3D_FVUnif, C3D_FVUnifDirty, C3D_FVec, C3D_Mtx, GPU_SHADER_TYPE}; #[inline] -pub unsafe fn C3D_FVUnifWritePtr(type_: GPU_SHADER_TYPE, id: c_int, size: c_int) -> *mut C3D_FVec { +pub unsafe fn C3D_FVUnifWritePtr( + type_: GPU_SHADER_TYPE, + id: libc::c_int, + size: libc::c_int, +) -> *mut C3D_FVec { for i in 0..size { C3D_FVUnifDirty[type_ as usize][(id + i) as usize] = true; } @@ -14,7 +16,12 @@ pub unsafe fn C3D_FVUnifWritePtr(type_: GPU_SHADER_TYPE, id: c_int, size: c_int) } #[inline] -pub unsafe fn C3D_FVUnifMtxNx4(type_: GPU_SHADER_TYPE, id: c_int, mtx: *const C3D_Mtx, num: c_int) { +pub unsafe fn C3D_FVUnifMtxNx4( + type_: GPU_SHADER_TYPE, + id: libc::c_int, + mtx: *const C3D_Mtx, + num: libc::c_int, +) { let ptr = C3D_FVUnifWritePtr(type_, id, num); for i in 0..num { @@ -23,12 +30,19 @@ pub unsafe fn C3D_FVUnifMtxNx4(type_: GPU_SHADER_TYPE, id: c_int, mtx: *const C3 } #[inline] -pub unsafe fn C3D_FVUnifMtx4x4(type_: GPU_SHADER_TYPE, id: c_int, mtx: *const C3D_Mtx) { +pub unsafe fn C3D_FVUnifMtx4x4(type_: GPU_SHADER_TYPE, id: libc::c_int, mtx: *const C3D_Mtx) { C3D_FVUnifMtxNx4(type_, id, mtx, 4); } #[inline] -pub unsafe fn C3D_FVUnifSet(type_: GPU_SHADER_TYPE, id: c_int, x: f32, y: f32, z: f32, w: f32) { +pub unsafe fn C3D_FVUnifSet( + type_: GPU_SHADER_TYPE, + id: libc::c_int, + x: f32, + y: f32, + z: f32, + w: f32, +) { let ptr = C3D_FVUnifWritePtr(type_, id, 1); (*ptr).c.copy_from_slice(&[x, y, z, w]); }