Browse Source

Add enough functionality for simple tri demo

pull/18/head
Ian Chamberlain 3 years ago
parent
commit
c648c93493
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 2
      citro3d-sys/Cargo.toml
  2. 6
      citro3d-sys/src/lib.rs
  3. 10
      citro3d-sys/src/renderqueue.rs
  4. 55
      citro3d-sys/src/texenv.rs

2
citro3d-sys/Cargo.toml

@ -6,4 +6,4 @@ edition = "2021"
[dependencies] [dependencies]
libc = "0.2.116" libc = "0.2.116"
ctru-sys = { path = "../../ctru-rs/ctru-sys" } ctru-sys = { git = "https://github.com/Meziu/ctru-rs.git" }

6
citro3d-sys/src/lib.rs

@ -3,6 +3,7 @@
#![feature(untagged_unions)] // used for [`C3D_Mtx`] #![feature(untagged_unions)] // used for [`C3D_Mtx`]
pub mod base; pub mod base;
pub mod renderqueue;
pub mod texenv; pub mod texenv;
pub mod uniforms; pub mod uniforms;
@ -15,7 +16,6 @@ mod bindings;
pub use base::*; pub use base::*;
pub use bindings::*; pub use bindings::*;
pub use uniforms::*; pub use renderqueue::*;
#[cfg(todo = "gpu_tev_macros")]
pub use texenv::*; pub use texenv::*;
pub use uniforms::*;

10
citro3d-sys/src/renderqueue.rs

@ -0,0 +1,10 @@
//! `<c3d/renderqueue.h>`
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);
}

55
citro3d-sys/src/texenv.rs

@ -1,11 +1,45 @@
#![cfg(todo = "gpu_tev_macros")] //! Definitions for `<c3d/texenv.h>`.
//! `<c3d/texenv.h>` //! 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 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<T>(a: T, b: T, c: T) -> T
where
T: BitOr<Output = T> + Shl<u8, Output = T>,
{
a | b << 4 | c << 8
}
/// Creates a texture combiner operand parameter from three operands.
fn gpu_tevoperands<T>(a: T, b: T, c: T) -> T
where
T: BitOr<Output = T> + Shl<u8, Output = T>,
{
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) { 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 { if mode & C3D_RGB as i32 != 0 {
(*env).srcRgb = param as u16; (*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) { 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 { 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 { if mode & C3D_Alpha as i32 != 0 {
(*env).opAlpha = param as u16; (*env)
.__bindgen_anon_1
.__bindgen_anon_1
.set_opAlpha(param as u32);
} }
} }

Loading…
Cancel
Save