Browse Source

Inline citro3d-sys functions where needed

Add gx.h bindings for some helper macros there.
pull/18/head
Ian Chamberlain 3 years ago
parent
commit
395aa29bc1
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 8
      citro3d-sys/src/base.rs
  2. 33
      citro3d-sys/src/gx.rs
  3. 2
      citro3d-sys/src/lib.rs
  4. 3
      citro3d-sys/src/renderqueue.rs
  5. 11
      citro3d-sys/src/texenv.rs
  6. 30
      citro3d-sys/src/uniforms.rs

8
citro3d-sys/src/base.rs

@ -1,9 +1,9 @@
//! `<c3d/base.h>` //! Definitions from `<c3d/base.h>`
use super::*; use crate::C3D_FixedAttribGetWritePtr;
use libc::c_int;
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); let ptr = C3D_FixedAttribGetWritePtr(id);
(*ptr).c.copy_from_slice(&[x, y, z, w]); (*ptr).c.copy_from_slice(&[x, y, z, w]);
} }

33
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
}

2
citro3d-sys/src/lib.rs

@ -6,6 +6,7 @@
#![allow(clippy::all)] #![allow(clippy::all)]
pub mod base; pub mod base;
pub mod gx;
pub mod renderqueue; pub mod renderqueue;
pub mod texenv; pub mod texenv;
pub mod uniforms; pub mod uniforms;
@ -14,6 +15,7 @@ mod bindings;
pub use base::*; pub use base::*;
pub use bindings::*; pub use bindings::*;
pub use gx::*;
pub use renderqueue::*; pub use renderqueue::*;
pub use texenv::*; pub use texenv::*;
pub use uniforms::*; pub use uniforms::*;

3
citro3d-sys/src/renderqueue.rs

@ -1,5 +1,6 @@
//! `<c3d/renderqueue.h>` //! Definitions from `<c3d/renderqueue.h>`
#[inline]
pub unsafe fn C3D_RenderTargetClear( pub unsafe fn C3D_RenderTargetClear(
target: *mut crate::C3D_RenderTarget, target: *mut crate::C3D_RenderTarget,
clearBits: crate::C3D_ClearBits, clearBits: crate::C3D_ClearBits,

11
citro3d-sys/src/texenv.rs

@ -1,9 +1,8 @@
//! Definitions for `<c3d/texenv.h>`. //! Definitions from `<c3d/texenv.h>`.
//!
//! Most of these functions are `static inline` so they don't get generated by `bindgen`. //! Most of these functions are `static inline` so they don't get generated by `bindgen`.
//! See <https://github.com/rust-lang/rust-bindgen/issues/1090>. //! See <https://github.com/rust-lang/rust-bindgen/issues/1090>.
// TODO: probably should mark these all as #[inline] for parity with the C code
use core::ops::{BitOr, Shl}; use core::ops::{BitOr, Shl};
use libc::c_int; use libc::c_int;
@ -13,6 +12,7 @@ use super::*;
// TODO: why are these two different macros in C? // TODO: why are these two different macros in C?
/// Creates a texture combiner source parameter from three sources. /// Creates a texture combiner source parameter from three sources.
#[inline]
fn GPU_TEVSOURCES<T>(a: T, b: T, c: T) -> T fn GPU_TEVSOURCES<T>(a: T, b: T, c: T) -> T
where where
T: BitOr<Output = T> + Shl<u8, Output = T>, T: BitOr<Output = T> + Shl<u8, Output = T>,
@ -21,6 +21,7 @@ where
} }
/// Creates a texture combiner operand parameter from three operands. /// Creates a texture combiner operand parameter from three operands.
#[inline]
fn GPU_TEVOPERANDS<T>(a: T, b: T, c: T) -> T fn GPU_TEVOPERANDS<T>(a: T, b: T, c: T) -> T
where where
T: BitOr<Output = T> + Shl<u8, Output = T>, T: BitOr<Output = T> + Shl<u8, Output = T>,
@ -28,6 +29,7 @@ where
a | b << 4 | c << 8 a | b << 4 | c << 8
} }
#[inline]
pub unsafe fn C3D_TexEnvInit(env: *mut C3D_TexEnv) { pub unsafe fn C3D_TexEnvInit(env: *mut C3D_TexEnv) {
(*env).srcRgb = GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0) as u16; (*env).srcRgb = GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0) as u16;
(*env).srcAlpha = (*env).srcRgb; (*env).srcAlpha = (*env).srcRgb;
@ -39,6 +41,7 @@ pub unsafe fn C3D_TexEnvInit(env: *mut C3D_TexEnv) {
(*env).scaleAlpha = GPU_TEVSCALE_1 as u16; (*env).scaleAlpha = GPU_TEVSCALE_1 as u16;
} }
#[inline]
pub unsafe fn C3D_TexEnvSrc( pub unsafe fn C3D_TexEnvSrc(
env: *mut C3D_TexEnv, env: *mut C3D_TexEnv,
mode: C3D_TexEnvMode, mode: C3D_TexEnvMode,
@ -58,6 +61,7 @@ pub unsafe fn C3D_TexEnvSrc(
} }
// TODO: match API of texenv.h // TODO: match API of texenv.h
#[inline]
pub unsafe fn C3D_TexEnvOp( pub unsafe fn C3D_TexEnvOp(
env: *mut C3D_TexEnv, env: *mut C3D_TexEnv,
mode: C3D_TexEnvMode, 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) { pub unsafe fn C3D_TexEnvFunc(env: *mut C3D_TexEnv, mode: C3D_TexEnvMode, param: GPU_COMBINEFUNC) {
if mode & C3D_RGB != 0 { if mode & C3D_RGB != 0 {
(*env).funcRgb = param as u16; (*env).funcRgb = param as u16;

30
citro3d-sys/src/uniforms.rs

@ -1,11 +1,13 @@
//! `<c3d/uniforms.h>` //! Definitions from`<c3d/uniforms.h>`
use super::*; use super::{C3D_FVUnif, C3D_FVUnifDirty, C3D_FVec, C3D_Mtx, GPU_SHADER_TYPE};
use libc::c_int;
#[inline] #[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 { for i in 0..size {
C3D_FVUnifDirty[type_ as usize][(id + i) as usize] = true; 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] #[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); let ptr = C3D_FVUnifWritePtr(type_, id, num);
for i in 0..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] #[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); C3D_FVUnifMtxNx4(type_, id, mtx, 4);
} }
#[inline] #[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); let ptr = C3D_FVUnifWritePtr(type_, id, 1);
(*ptr).c.copy_from_slice(&[x, y, z, w]); (*ptr).c.copy_from_slice(&[x, y, z, w]);
} }

Loading…
Cancel
Save