From b712e8a68f77ed0c0dab4bddf709b9a21921255f Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sat, 30 Sep 2023 22:51:47 -0400 Subject: [PATCH 1/3] Generate bindings with build.rs at compile time Effectively: - Move the previous bindgen script into build.rs - In lib.rs, include the file generated at build time - Compile inline statics with devkitARM toolchain - Remove now-unneeded reimplementations of inline statics - Use doxygen_rs to clean up the docs of the generated bindings. Nice! This cleans up the repo a lot and also ensures we are using the canonical implementations of those inline functions, which should help prevent mistakes as well. --- Cargo.toml | 7 +- bindgen-citro3d/Cargo.toml | 9 - bindgen-citro3d/src/main.rs | 92 -- citro3d-sys/Cargo.toml | 5 + citro3d-sys/build.rs | 132 ++- citro3d-sys/src/base.rs | 9 - citro3d-sys/src/bindings.rs | 1740 -------------------------------- citro3d-sys/src/gx.rs | 3 +- citro3d-sys/src/lib.rs | 16 +- citro3d-sys/src/os.rs | 13 - citro3d-sys/src/renderqueue.rs | 18 - citro3d-sys/src/texenv.rs | 100 -- citro3d-sys/src/uniforms.rs | 50 - citro3d/examples/triangle.rs | 2 +- 14 files changed, 142 insertions(+), 2054 deletions(-) delete mode 100644 bindgen-citro3d/Cargo.toml delete mode 100644 bindgen-citro3d/src/main.rs delete mode 100644 citro3d-sys/src/base.rs delete mode 100644 citro3d-sys/src/bindings.rs delete mode 100644 citro3d-sys/src/os.rs delete mode 100644 citro3d-sys/src/renderqueue.rs delete mode 100644 citro3d-sys/src/texenv.rs delete mode 100644 citro3d-sys/src/uniforms.rs diff --git a/Cargo.toml b/Cargo.toml index c2c3e84..31f011c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,8 @@ [workspace] members = [ - "bindgen-citro3d", - "citro3d-macros", - "citro3d-sys", "citro3d", + "citro3d-sys", + "citro3d-macros", ] default-members = [ "citro3d", @@ -13,4 +12,6 @@ default-members = [ resolver = "2" [patch."https://github.com/rust3ds/citro3d-rs.git"] +citro3d = { path = "citro3d" } citro3d-sys = { path = "citro3d-sys" } +citro3d-macros = { path = "citro3d-macros" } diff --git a/bindgen-citro3d/Cargo.toml b/bindgen-citro3d/Cargo.toml deleted file mode 100644 index 28137fb..0000000 --- a/bindgen-citro3d/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "bindgen-citro3d" -version = "0.1.0" -edition = "2021" -description = "Helper tool to generate citro3d-sys bindings." -publish = false - -[dependencies] -bindgen = "0.62.0" diff --git a/bindgen-citro3d/src/main.rs b/bindgen-citro3d/src/main.rs deleted file mode 100644 index ea12c12..0000000 --- a/bindgen-citro3d/src/main.rs +++ /dev/null @@ -1,92 +0,0 @@ -//! This is meant to be run as a "script" to generate bindings to `citro3d`. -//! We use this instead of `bindgen-cli` to enable the use of [`CustomCallbacks`] -//! with [`bindgen`] as a library for finer grained control of the bindings. - -use std::iter::FromIterator; -use std::path::PathBuf; - -use bindgen::callbacks::{DeriveTrait, ImplementsTrait, ParseCallbacks}; -use bindgen::{Builder, RustTarget}; - -fn main() { - let devkitpro = std::env::var("DEVKITPRO").expect("DEVKITPRO not set in environment"); - let devkitarm = std::env::var("DEVKITARM").expect("DEVKITARM not set in environment"); - - let include_path = PathBuf::from_iter([devkitpro.as_str(), "libctru", "include"]); - let header = include_path.join("tex3ds.h"); - - let sysroot = PathBuf::from(devkitarm).join("arm-none-eabi"); - let system_include = sysroot.join("include"); - - let bindings = Builder::default() - .header(header.to_str().unwrap()) - .rust_target(RustTarget::Nightly) - .use_core() - .trust_clang_mangling(false) - .layout_tests(false) - .ctypes_prefix("::libc") - .prepend_enum_name(false) - .fit_macro_constants(true) - .raw_line("use ctru_sys::*;") - .must_use_type("Result") - .blocklist_type("u(8|16|32|64)") - .opaque_type("(GPU|GFX)_.*") - .opaque_type("float24Uniform_s") - .allowlist_file(".*/c3d/.*[.]h") - .allowlist_file(".*/tex3ds[.]h") - .blocklist_file(".*/3ds/.*[.]h") - .blocklist_file(".*/sys/.*[.]h") - .clang_args([ - "--target=arm-none-eabi", - "--sysroot", - sysroot.to_str().unwrap(), - "-isystem", - system_include.to_str().unwrap(), - "-I", - include_path.to_str().unwrap(), - "-mfloat-abi=hard", - "-march=armv6k", - "-mtune=mpcore", - "-mfpu=vfp", - "-DARM11 ", - "-D_3DS ", - "-D__3DS__ ", - ]) - .parse_callbacks(Box::new(CustomCallbacks)) - .generate() - .expect("Unable to generate bindings"); - - bindings - .write(Box::new(std::io::stdout())) - .expect("failed to write bindings"); -} - -/// Custom callback struct to allow us to mark some "known good types" as -/// [`Copy`], which in turn allows using Rust `union` instead of bindgen union -/// types. See -/// -/// for more info. -/// -/// We do the same for [`Debug`] just for the convenience of derived Debug impls -/// on some `citro3d` types. -#[derive(Debug)] -struct CustomCallbacks; - -impl ParseCallbacks for CustomCallbacks { - fn blocklisted_type_implements_trait( - &self, - name: &str, - derive_trait: DeriveTrait, - ) -> Option { - if let DeriveTrait::Copy | DeriveTrait::Debug = derive_trait { - match name { - "u64_" | "u32_" | "u16_" | "u8_" | "u64" | "u32" | "u16" | "u8" | "gfxScreen_t" - | "gfx3dSide_t" => Some(ImplementsTrait::Yes), - _ if name.starts_with("GPU_") => Some(ImplementsTrait::Yes), - _ => None, - } - } else { - None - } - } -} diff --git a/citro3d-sys/Cargo.toml b/citro3d-sys/Cargo.toml index 3e03c41..9c55a60 100644 --- a/citro3d-sys/Cargo.toml +++ b/citro3d-sys/Cargo.toml @@ -8,3 +8,8 @@ license = "Zlib" [dependencies] libc = "0.2.116" ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" } + +[build-dependencies] +bindgen = { version = "0.68.1", features = ["experimental"] } +cc = "1.0.83" +doxygen-rs = "0.4.2" diff --git a/citro3d-sys/build.rs b/citro3d-sys/build.rs index e865214..1210f08 100644 --- a/citro3d-sys/build.rs +++ b/citro3d-sys/build.rs @@ -1,19 +1,143 @@ +//! This build script generates bindings from `citro3d` on the fly at compilation +//! time into `OUT_DIR`, from which they can be included into `lib.rs`. + use std::env; +use std::iter::FromIterator; +use std::path::{Path, PathBuf}; + +use bindgen::callbacks::{DeriveTrait, ImplementsTrait, ParseCallbacks}; +use bindgen::{Builder, RustTarget}; fn main() { - let dkp_path = env::var("DEVKITPRO").unwrap(); + let devkitpro = env::var("DEVKITPRO").expect("DEVKITPRO not set in environment"); + println!("cargo:rerun-if-env-changed=DEVKITPRO"); + + let devkitarm = std::env::var("DEVKITARM").expect("DEVKITARM not set in environment"); + println!("cargo:rerun-if-env-changed=DEVKITARM"); + let debug_symbols = env::var("DEBUG").unwrap(); + println!("cargo:rerun-if-env-changed=DEBUG"); + + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + println!("cargo:rerun-if-env-changed=OUT_DIR"); println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rerun-if-env-changed=DEVKITPRO"); - println!("cargo:rustc-link-search=native={dkp_path}/libctru/lib"); + println!("cargo:rustc-link-search=native={devkitpro}/libctru/lib"); println!( "cargo:rustc-link-lib=static={}", match debug_symbols.as_str() { // Based on valid values described in // https://doc.rust-lang.org/cargo/reference/profiles.html#debug - "0" | "false" => "citro3d", + "0" | "false" | "none" => "citro3d", _ => "citro3dd", } ); + + let include_path = PathBuf::from_iter([devkitpro.as_str(), "libctru", "include"]); + let tex3ds_h = include_path.join("tex3ds.h"); + let citro3d_h = include_path.join("citro3d.h"); + let three_ds_h = include_path.join("3ds.h"); + + let sysroot = Path::new(devkitarm.as_str()).join("arm-none-eabi"); + let system_include = sysroot.join("include"); + let static_fns_path = Path::new("citro3d_statics_wrapper"); + + let bindings = Builder::default() + .header(three_ds_h.to_str().unwrap()) + .header(citro3d_h.to_str().unwrap()) + .header(tex3ds_h.to_str().unwrap()) + .rust_target(RustTarget::Nightly) + .use_core() + .trust_clang_mangling(false) + .layout_tests(false) + .ctypes_prefix("::libc") + .prepend_enum_name(false) + .fit_macro_constants(true) + .raw_line("use ctru_sys::*;") + .must_use_type("Result") + .blocklist_type("u(8|16|32|64)") + .opaque_type("(GPU|GFX)_.*") + .opaque_type("float24Uniform_s") + .allowlist_file(".*/c3d/.*[.]h") + .allowlist_file(".*/tex3ds[.]h") + .blocklist_file(".*/3ds/.*[.]h") + .blocklist_file(".*/sys/.*[.]h") + .wrap_static_fns(true) + .wrap_static_fns_path(out_dir.join(static_fns_path)) + .clang_args([ + "--target=arm-none-eabi", + "--sysroot", + sysroot.to_str().unwrap(), + "-isystem", + system_include.to_str().unwrap(), + "-I", + include_path.to_str().unwrap(), + "-mfloat-abi=hard", + "-march=armv6k", + "-mtune=mpcore", + "-mfpu=vfp", + "-DARM11 ", + "-D_3DS ", + "-D__3DS__ ", + ]) + .parse_callbacks(Box::new(CustomCallbacks)) + .generate() + .expect("Unable to generate bindings"); + + bindings + .write_to_file(out_dir.join("bindings.rs")) + .expect("failed to write bindings"); + + // Compile static inline fns wrapper + let cc = Path::new(devkitarm.as_str()).join("bin/arm-none-eabi-gcc"); + let ar = Path::new(devkitarm.as_str()).join("bin/arm-none-eabi-ar"); + + cc::Build::new() + .compiler(cc) + .archiver(ar) + .include(&include_path) + .file(out_dir.join(static_fns_path.with_extension("c"))) + .flag("-march=armv6k") + .flag("-mtune=mpcore") + .flag("-mfloat-abi=hard") + .flag("-mfpu=vfp") + .flag("-mtp=soft") + .flag("-Wno-deprecated-declarations") + .compile("citro3d_statics_wrapper"); +} + +/// Custom callback struct to allow us to mark some "known good types" as +/// [`Copy`], which in turn allows using Rust `union` instead of bindgen union types. See +/// +/// for more info. +/// +/// We do the same for [`Debug`] just for the convenience of derived Debug impls +/// on some `citro3d` types. +/// +/// Finally, we use [`doxygen_rs`] to transform the doc comments into something +/// easier to read in the generated documentation / hover documentation. +#[derive(Debug)] +struct CustomCallbacks; + +impl ParseCallbacks for CustomCallbacks { + fn process_comment(&self, comment: &str) -> Option { + Some(doxygen_rs::transform(comment)) + } + + fn blocklisted_type_implements_trait( + &self, + name: &str, + derive_trait: DeriveTrait, + ) -> Option { + if let DeriveTrait::Copy | DeriveTrait::Debug = derive_trait { + match name { + "u64_" | "u32_" | "u16_" | "u8_" | "u64" | "u32" | "u16" | "u8" | "gfxScreen_t" + | "gfx3dSide_t" => Some(ImplementsTrait::Yes), + _ if name.starts_with("GPU_") => Some(ImplementsTrait::Yes), + _ => None, + } + } else { + None + } + } } diff --git a/citro3d-sys/src/base.rs b/citro3d-sys/src/base.rs deleted file mode 100644 index 16463dc..0000000 --- a/citro3d-sys/src/base.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! Definitions from `` - -use crate::C3D_FixedAttribGetWritePtr; - -#[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/bindings.rs b/citro3d-sys/src/bindings.rs deleted file mode 100644 index ecda601..0000000 --- a/citro3d-sys/src/bindings.rs +++ /dev/null @@ -1,1740 +0,0 @@ -/* automatically generated by rust-bindgen 0.64.0 */ - -use ctru_sys::*; - -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub const fn new(storage: Storage) -> Self { - Self { storage } - } -} -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ - #[inline] - pub fn get_bit(&self, index: usize) -> bool { - debug_assert!(index / 8 < self.storage.as_ref().len()); - let byte_index = index / 8; - let byte = self.storage.as_ref()[byte_index]; - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - let mask = 1 << bit_index; - byte & mask == mask - } - #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { - debug_assert!(index / 8 < self.storage.as_ref().len()); - let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - let mask = 1 << bit_index; - if val { - *byte |= mask; - } else { - *byte &= !mask; - } - } - #[inline] - pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { - if self.get_bit(i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] - pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - self.set_bit(index + bit_offset, val_bit_is_set); - } - } -} -pub const M_TAU: f64 = 6.283185307179586; -pub const C3D_AspectRatioTop: f64 = 1.6666666666666667; -pub const C3D_AspectRatioBot: f64 = 1.3333333333333333; -pub const C3D_MTXSTACK_SIZE: u8 = 8; -pub const C3D_FVUNIF_COUNT: u8 = 96; -pub const C3D_IVUNIF_COUNT: u8 = 4; -pub const C3D_DEFAULT_CMDBUF_SIZE: u32 = 262144; -pub const C3DF_LightEnv_IsCP_Any: u32 = 66846720; -pub const C3DF_LightEnv_LutDirtyAll: u32 = 4227858432; -pub type __int64_t = ::libc::c_longlong; -pub type _off_t = __int64_t; -pub type _fpos_t = __int64_t; -pub type wint_t = ::libc::c_int; -pub type C3D_IVec = u32_; -#[doc = " @struct C3D_FVec\n @brief Float vector\n\n Matches PICA layout"] -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_FVec { - pub __bindgen_anon_1: C3D_FVec__bindgen_ty_1, - pub __bindgen_anon_2: C3D_FVec__bindgen_ty_2, - #[doc = " @brief Raw access"] - pub c: [f32; 4usize], -} -#[doc = " @brief Vector access"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_FVec__bindgen_ty_1 { - #[doc = "< W-component"] - pub w: f32, - #[doc = "< Z-component"] - pub z: f32, - #[doc = "< Y-component"] - pub y: f32, - #[doc = "< X-component"] - pub x: f32, -} -#[doc = " @brief Quaternion access"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_FVec__bindgen_ty_2 { - #[doc = "< Real component"] - pub r: f32, - #[doc = "< K-component"] - pub k: f32, - #[doc = "< J-component"] - pub j: f32, - #[doc = "< I-component"] - pub i: f32, -} -#[doc = " @struct C3D_FVec\n @brief Float vector\n\n Matches PICA layout"] -pub type C3D_FQuat = C3D_FVec; -#[doc = " @struct C3D_Mtx\n @brief Row-major 4x4 matrix"] -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_Mtx { - #[doc = "< Rows are vectors"] - pub r: [C3D_FVec; 4usize], - #[doc = "< Raw access"] - pub m: [f32; 16usize], -} -extern "C" { - #[doc = "@brief Transposes the matrix. Row => Column, and vice versa.\n@param[in,out] out Output matrix."] - pub fn Mtx_Transpose(out: *mut C3D_Mtx); -} -extern "C" { - #[doc = " @brief Multiply two matrices\n @param[out] out Output matrix\n @param[in] a Multiplicand\n @param[in] b Multiplier"] - pub fn Mtx_Multiply(out: *mut C3D_Mtx, a: *const C3D_Mtx, b: *const C3D_Mtx); -} -extern "C" { - #[doc = " @brief Inverse a matrix\n @param[in,out] out Matrix to inverse\n @retval 0.0f Degenerate matrix (no inverse)\n @return determinant"] - pub fn Mtx_Inverse(out: *mut C3D_Mtx) -> f32; -} -extern "C" { - #[doc = " @brief Multiply 3x3 matrix by a FVec3\n @param[in] mtx Matrix\n @param[in] v Vector\n @return mtx*v (product)"] - pub fn Mtx_MultiplyFVec3(mtx: *const C3D_Mtx, v: C3D_FVec) -> C3D_FVec; -} -extern "C" { - #[doc = " @brief Multiply 4x4 matrix by a FVec4\n @param[in] mtx Matrix\n @param[in] v Vector\n @return mtx*v (product)"] - pub fn Mtx_MultiplyFVec4(mtx: *const C3D_Mtx, v: C3D_FVec) -> C3D_FVec; -} -extern "C" { - #[doc = " @brief Get 4x4 matrix equivalent to Quaternion\n @param[out] m Output matrix\n @param[in] q Input Quaternion"] - pub fn Mtx_FromQuat(m: *mut C3D_Mtx, q: C3D_FQuat); -} -extern "C" { - #[doc = " @brief 3D translation\n @param[in,out] mtx Matrix to translate\n @param[in] x X component to translate\n @param[in] y Y component to translate\n @param[in] z Z component to translate\n @param[in] bRightSide Whether to transform from the right side"] - pub fn Mtx_Translate(mtx: *mut C3D_Mtx, x: f32, y: f32, z: f32, bRightSide: bool); -} -extern "C" { - #[doc = " @brief 3D Scale\n @param[in,out] mtx Matrix to scale\n @param[in] x X component to scale\n @param[in] y Y component to scale\n @param[in] z Z component to scale"] - pub fn Mtx_Scale(mtx: *mut C3D_Mtx, x: f32, y: f32, z: f32); -} -extern "C" { - #[doc = " @brief 3D Rotation\n @param[in,out] mtx Matrix to rotate\n @param[in] axis Axis about which to rotate\n @param[in] angle Radians to rotate\n @param[in] bRightSide Whether to transform from the right side"] - pub fn Mtx_Rotate(mtx: *mut C3D_Mtx, axis: C3D_FVec, angle: f32, bRightSide: bool); -} -extern "C" { - #[doc = " @brief 3D Rotation about the X axis\n @param[in,out] mtx Matrix to rotate\n @param[in] angle Radians to rotate\n @param[in] bRightSide Whether to transform from the right side"] - pub fn Mtx_RotateX(mtx: *mut C3D_Mtx, angle: f32, bRightSide: bool); -} -extern "C" { - #[doc = " @brief 3D Rotation about the Y axis\n @param[in,out] mtx Matrix to rotate\n @param[in] angle Radians to rotate\n @param[in] bRightSide Whether to transform from the right side"] - pub fn Mtx_RotateY(mtx: *mut C3D_Mtx, angle: f32, bRightSide: bool); -} -extern "C" { - #[doc = " @brief 3D Rotation about the Z axis\n @param[in,out] mtx Matrix to rotate\n @param[in] angle Radians to rotate\n @param[in] bRightSide Whether to transform from the right side"] - pub fn Mtx_RotateZ(mtx: *mut C3D_Mtx, angle: f32, bRightSide: bool); -} -extern "C" { - #[doc = " @brief Orthogonal projection\n @param[out] mtx Output matrix\n @param[in] left Left clip plane (X=left)\n @param[in] right Right clip plane (X=right)\n @param[in] bottom Bottom clip plane (Y=bottom)\n @param[in] top Top clip plane (Y=top)\n @param[in] near Near clip plane (Z=near)\n @param[in] far Far clip plane (Z=far)\n @param[in] isLeftHanded Whether to build a LH projection\n @sa Mtx_OrthoTilt"] - pub fn Mtx_Ortho( - mtx: *mut C3D_Mtx, - left: f32, - right: f32, - bottom: f32, - top: f32, - near: f32, - far: f32, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Perspective projection\n @param[out] mtx Output matrix\n @param[in] fovy Vertical field of view in radians\n @param[in] aspect Aspect ration of projection plane (width/height)\n @param[in] near Near clip plane (Z=near)\n @param[in] far Far clip plane (Z=far)\n @param[in] isLeftHanded Whether to build a LH projection\n @sa Mtx_PerspTilt\n @sa Mtx_PerspStereo\n @sa Mtx_PerspStereoTilt"] - pub fn Mtx_Persp( - mtx: *mut C3D_Mtx, - fovy: f32, - aspect: f32, - near: f32, - far: f32, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Stereo perspective projection\n @note Typically you will use iod to mean the distance between the eyes. Plug\n in -iod for the left eye and iod for the right eye.\n @note The focal length is defined by screen. If objects are further than this,\n they will appear to be inside the screen. If objects are closer than this,\n they will appear to pop out of the screen. Objects at this distance appear\n to be at the screen.\n @param[out] mtx Output matrix\n @param[in] fovy Vertical field of view in radians\n @param[in] aspect Aspect ration of projection plane (width/height)\n @param[in] near Near clip plane (Z=near)\n @param[in] far Far clip plane (Z=far)\n @param[in] iod Interocular distance\n @param[in] screen Focal length\n @param[in] isLeftHanded Whether to build a LH projection\n @sa Mtx_Persp\n @sa Mtx_PerspTilt\n @sa Mtx_PerspStereoTilt"] - pub fn Mtx_PerspStereo( - mtx: *mut C3D_Mtx, - fovy: f32, - aspect: f32, - near: f32, - far: f32, - iod: f32, - screen: f32, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Orthogonal projection, tilted to account for the 3DS screen rotation\n @param[out] mtx Output matrix\n @param[in] left Left clip plane (X=left)\n @param[in] right Right clip plane (X=right)\n @param[in] bottom Bottom clip plane (Y=bottom)\n @param[in] top Top clip plane (Y=top)\n @param[in] near Near clip plane (Z=near)\n @param[in] far Far clip plane (Z=far)\n @param[in] isLeftHanded Whether to build a LH projection\n @sa Mtx_Ortho"] - pub fn Mtx_OrthoTilt( - mtx: *mut C3D_Mtx, - left: f32, - right: f32, - bottom: f32, - top: f32, - near: f32, - far: f32, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Perspective projection, tilted to account for the 3DS screen rotation\n @param[out] mtx Output matrix\n @param[in] fovy Vertical field of view in radians\n @param[in] aspect Aspect ration of projection plane (width/height)\n @param[in] near Near clip plane (Z=near)\n @param[in] far Far clip plane (Z=far)\n @param[in] isLeftHanded Whether to build a LH projection\n @sa Mtx_Persp\n @sa Mtx_PerspStereo\n @sa Mtx_PerspStereoTilt"] - pub fn Mtx_PerspTilt( - mtx: *mut C3D_Mtx, - fovy: f32, - aspect: f32, - near: f32, - far: f32, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Stereo perspective projection, tilted to account for the 3DS screen rotation\n @note See the notes for @ref Mtx_PerspStereo\n @param[out] mtx Output matrix\n @param[in] fovy Vertical field of view in radians\n @param[in] aspect Aspect ration of projection plane (width/height)\n @param[in] near Near clip plane (Z=near)\n @param[in] far Far clip plane (Z=far)\n @param[in] iod Interocular distance\n @param[in] screen Focal length\n @param[in] isLeftHanded Whether to build a LH projection\n @sa Mtx_Persp\n @sa Mtx_PerspTilt\n @sa Mtx_PerspStereo"] - pub fn Mtx_PerspStereoTilt( - mtx: *mut C3D_Mtx, - fovy: f32, - aspect: f32, - near: f32, - far: f32, - iod: f32, - screen: f32, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Look-At matrix, based on DirectX implementation\n @note See https://msdn.microsoft.com/en-us/library/windows/desktop/bb205342\n @param[out] out Output matrix.\n @param[in] cameraPosition Position of the intended camera in 3D space.\n @param[in] cameraTarget Position of the intended target the camera is supposed to face in 3D space.\n @param[in] cameraUpVector The vector that points straight up depending on the camera's \"Up\" direction.\n @param[in] isLeftHanded Whether to build a LH projection"] - pub fn Mtx_LookAt( - out: *mut C3D_Mtx, - cameraPosition: C3D_FVec, - cameraTarget: C3D_FVec, - cameraUpVector: C3D_FVec, - isLeftHanded: bool, - ); -} -extern "C" { - #[doc = " @brief Multiply two Quaternions\n @param[in] lhs Multiplicand\n @param[in] rhs Multiplier\n @return lhs*rhs"] - pub fn Quat_Multiply(lhs: C3D_FQuat, rhs: C3D_FQuat) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief Raise Quaternion to a power\n @note If p is 0, this returns the identity Quaternion.\n If p is 1, this returns q.\n @param[in] q Base Quaternion\n @param[in] p Power\n @return qp"] - pub fn Quat_Pow(q: C3D_FQuat, p: f32) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief Cross product of Quaternion and FVec3\n @param[in] q Base Quaternion\n @param[in] v Vector to cross\n @return q×v"] - pub fn Quat_CrossFVec3(q: C3D_FQuat, v: C3D_FVec) -> C3D_FVec; -} -extern "C" { - #[doc = " @brief 3D Rotation\n @param[in] q Quaternion to rotate\n @param[in] axis Axis about which to rotate\n @param[in] r Radians to rotate\n @param[in] bRightSide Whether to transform from the right side\n @return Rotated Quaternion"] - pub fn Quat_Rotate(q: C3D_FQuat, axis: C3D_FVec, r: f32, bRightSide: bool) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief 3D Rotation about the X axis\n @param[in] q Quaternion to rotate\n @param[in] r Radians to rotate\n @param[in] bRightSide Whether to transform from the right side\n @return Rotated Quaternion"] - pub fn Quat_RotateX(q: C3D_FQuat, r: f32, bRightSide: bool) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief 3D Rotation about the Y axis\n @param[in] q Quaternion to rotate\n @param[in] r Radians to rotate\n @param[in] bRightSide Whether to transform from the right side\n @return Rotated Quaternion"] - pub fn Quat_RotateY(q: C3D_FQuat, r: f32, bRightSide: bool) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief 3D Rotation about the Z axis\n @param[in] q Quaternion to rotate\n @param[in] r Radians to rotate\n @param[in] bRightSide Whether to transform from the right side\n @return Rotated Quaternion"] - pub fn Quat_RotateZ(q: C3D_FQuat, r: f32, bRightSide: bool) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief Get Quaternion equivalent to 4x4 matrix\n @note If the matrix is orthogonal or special orthogonal, where determinant(matrix) = +1.0f, then the matrix can be converted.\n @param[in] m Input Matrix\n @return Generated Quaternion"] - pub fn Quat_FromMtx(m: *const C3D_Mtx) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief Converting Pitch, Yaw, and Roll to Quaternion equivalent\n @param[in] pitch The pitch angle in radians.\n @param[in] yaw The yaw angle in radians.\n @param[in] roll The roll angle in radians.\n @param[in] bRightSide Whether to transform from the right side\n @return C3D_FQuat The Quaternion equivalent with the pitch, yaw, and roll (in that order) orientations applied."] - pub fn Quat_FromPitchYawRoll(pitch: f32, yaw: f32, roll: f32, bRightSide: bool) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief Quaternion Look-At\n @param[in] source C3D_FVec Starting position. Origin of rotation.\n @param[in] target C3D_FVec Target position to orient towards.\n @param[in] forwardVector C3D_FVec The Up vector.\n @param[in] upVector C3D_FVec The Up vector.\n @return Quaternion rotation."] - pub fn Quat_LookAt( - source: C3D_FVec, - target: C3D_FVec, - forwardVector: C3D_FVec, - upVector: C3D_FVec, - ) -> C3D_FQuat; -} -extern "C" { - #[doc = " @brief Quaternion, created from a given axis and angle in radians.\n @param[in] axis C3D_FVec The axis to rotate around at.\n @param[in] angle float The angle to rotate. Unit: Radians\n @return Quaternion rotation based on the axis and angle. Axis doesn't have to be orthogonal."] - pub fn Quat_FromAxisAngle(axis: C3D_FVec, angle: f32) -> C3D_FQuat; -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct C3D_MtxStack { - pub m: [C3D_Mtx; 8usize], - pub pos: ::libc::c_int, - pub unifType: u8_, - pub unifPos: u8_, - pub unifLen: u8_, - pub isDirty: bool, -} -extern "C" { - pub fn MtxStack_Init(stk: *mut C3D_MtxStack); -} -extern "C" { - pub fn MtxStack_Bind( - stk: *mut C3D_MtxStack, - unifType: GPU_SHADER_TYPE, - unifPos: ::libc::c_int, - unifLen: ::libc::c_int, - ); -} -extern "C" { - pub fn MtxStack_Push(stk: *mut C3D_MtxStack) -> *mut C3D_Mtx; -} -extern "C" { - pub fn MtxStack_Pop(stk: *mut C3D_MtxStack) -> *mut C3D_Mtx; -} -extern "C" { - pub fn MtxStack_Update(stk: *mut C3D_MtxStack); -} -extern "C" { - pub static mut C3D_FVUnif: [[C3D_FVec; 96usize]; 2usize]; -} -extern "C" { - pub static mut C3D_IVUnif: [[C3D_IVec; 4usize]; 2usize]; -} -extern "C" { - pub static mut C3D_BoolUnifs: [u16_; 2usize]; -} -extern "C" { - pub static mut C3D_FVUnifDirty: [[bool; 96usize]; 2usize]; -} -extern "C" { - pub static mut C3D_IVUnifDirty: [[bool; 4usize]; 2usize]; -} -extern "C" { - pub static mut C3D_BoolUnifsDirty: [bool; 2usize]; -} -extern "C" { - pub fn C3D_UpdateUniforms(type_: GPU_SHADER_TYPE); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_AttrInfo { - pub flags: [u32_; 2usize], - pub permutation: u64_, - pub attrCount: ::libc::c_int, -} -extern "C" { - pub fn AttrInfo_Init(info: *mut C3D_AttrInfo); -} -extern "C" { - pub fn AttrInfo_AddLoader( - info: *mut C3D_AttrInfo, - regId: ::libc::c_int, - format: GPU_FORMATS, - count: ::libc::c_int, - ) -> ::libc::c_int; -} -extern "C" { - pub fn AttrInfo_AddFixed(info: *mut C3D_AttrInfo, regId: ::libc::c_int) -> ::libc::c_int; -} -extern "C" { - pub fn C3D_GetAttrInfo() -> *mut C3D_AttrInfo; -} -extern "C" { - pub fn C3D_SetAttrInfo(info: *mut C3D_AttrInfo); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_BufCfg { - pub offset: u32_, - pub flags: [u32_; 2usize], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_BufInfo { - pub base_paddr: u32_, - pub bufCount: ::libc::c_int, - pub buffers: [C3D_BufCfg; 12usize], -} -extern "C" { - pub fn BufInfo_Init(info: *mut C3D_BufInfo); -} -extern "C" { - pub fn BufInfo_Add( - info: *mut C3D_BufInfo, - data: *const ::libc::c_void, - stride: isize, - attribCount: ::libc::c_int, - permutation: u64_, - ) -> ::libc::c_int; -} -extern "C" { - pub fn C3D_GetBufInfo() -> *mut C3D_BufInfo; -} -extern "C" { - pub fn C3D_SetBufInfo(info: *mut C3D_BufInfo); -} -pub const C3D_UNSIGNED_BYTE: _bindgen_ty_38 = 0; -pub const C3D_UNSIGNED_SHORT: _bindgen_ty_38 = 1; -pub type _bindgen_ty_38 = ::libc::c_uint; -extern "C" { - pub fn C3D_Init(cmdBufSize: usize) -> bool; -} -extern "C" { - pub fn C3D_Fini(); -} -extern "C" { - pub fn C3D_GetCmdBufUsage() -> f32; -} -extern "C" { - pub fn C3D_BindProgram(program: *mut shaderProgram_s); -} -extern "C" { - pub fn C3D_SetViewport(x: u32_, y: u32_, w: u32_, h: u32_); -} -extern "C" { - pub fn C3D_SetScissor(mode: GPU_SCISSORMODE, left: u32_, top: u32_, right: u32_, bottom: u32_); -} -extern "C" { - pub fn C3D_DrawArrays(primitive: GPU_Primitive_t, first: ::libc::c_int, size: ::libc::c_int); -} -extern "C" { - pub fn C3D_DrawElements( - primitive: GPU_Primitive_t, - count: ::libc::c_int, - type_: ::libc::c_int, - indices: *const ::libc::c_void, - ); -} -extern "C" { - pub fn C3D_ImmDrawBegin(primitive: GPU_Primitive_t); -} -extern "C" { - pub fn C3D_ImmSendAttrib(x: f32, y: f32, z: f32, w: f32); -} -extern "C" { - pub fn C3D_ImmDrawEnd(); -} -extern "C" { - pub fn C3D_FixedAttribGetWritePtr(id: ::libc::c_int) -> *mut C3D_FVec; -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct C3D_TexEnv { - pub srcRgb: u16_, - pub srcAlpha: u16_, - pub __bindgen_anon_1: C3D_TexEnv__bindgen_ty_1, - pub funcRgb: u16_, - pub funcAlpha: u16_, - pub color: u32_, - pub scaleRgb: u16_, - pub scaleAlpha: u16_, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_TexEnv__bindgen_ty_1 { - pub opAll: u32_, - pub __bindgen_anon_1: C3D_TexEnv__bindgen_ty_1__bindgen_ty_1, -} -#[repr(C)] -#[repr(align(4))] -#[derive(Debug, Copy, Clone)] -pub struct C3D_TexEnv__bindgen_ty_1__bindgen_ty_1 { - pub _bitfield_align_1: [u16; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, -} -impl C3D_TexEnv__bindgen_ty_1__bindgen_ty_1 { - #[inline] - pub fn opRgb(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 12u8) as u32) } - } - #[inline] - pub fn set_opRgb(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 12u8, val as u64) - } - } - #[inline] - pub fn opAlpha(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(12usize, 12u8) as u32) } - } - #[inline] - pub fn set_opAlpha(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(12usize, 12u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1(opRgb: u32_, opAlpha: u32_) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 12u8, { - let opRgb: u32 = unsafe { ::core::mem::transmute(opRgb) }; - opRgb as u64 - }); - __bindgen_bitfield_unit.set(12usize, 12u8, { - let opAlpha: u32 = unsafe { ::core::mem::transmute(opAlpha) }; - opAlpha as u64 - }); - __bindgen_bitfield_unit - } -} -pub const C3D_RGB: C3D_TexEnvMode = 1; -pub const C3D_Alpha: C3D_TexEnvMode = 2; -pub const C3D_Both: C3D_TexEnvMode = 3; -pub type C3D_TexEnvMode = ::libc::c_uint; -extern "C" { - pub fn C3D_GetTexEnv(id: ::libc::c_int) -> *mut C3D_TexEnv; -} -extern "C" { - pub fn C3D_SetTexEnv(id: ::libc::c_int, env: *mut C3D_TexEnv); -} -extern "C" { - pub fn C3D_DirtyTexEnv(env: *mut C3D_TexEnv); -} -extern "C" { - pub fn C3D_TexEnvBufUpdate(mode: ::libc::c_int, mask: ::libc::c_int); -} -extern "C" { - pub fn C3D_TexEnvBufColor(color: u32_); -} -extern "C" { - pub fn C3D_DepthMap(bIsZBuffer: bool, zScale: f32, zOffset: f32); -} -extern "C" { - pub fn C3D_CullFace(mode: GPU_CULLMODE); -} -extern "C" { - pub fn C3D_StencilTest( - enable: bool, - function: GPU_TESTFUNC, - ref_: ::libc::c_int, - inputMask: ::libc::c_int, - writeMask: ::libc::c_int, - ); -} -extern "C" { - pub fn C3D_StencilOp(sfail: GPU_STENCILOP, dfail: GPU_STENCILOP, pass: GPU_STENCILOP); -} -extern "C" { - pub fn C3D_BlendingColor(color: u32_); -} -extern "C" { - pub fn C3D_EarlyDepthTest(enable: bool, function: GPU_EARLYDEPTHFUNC, ref_: u32_); -} -extern "C" { - pub fn C3D_DepthTest(enable: bool, function: GPU_TESTFUNC, writemask: GPU_WRITEMASK); -} -extern "C" { - pub fn C3D_AlphaTest(enable: bool, function: GPU_TESTFUNC, ref_: ::libc::c_int); -} -extern "C" { - pub fn C3D_AlphaBlend( - colorEq: GPU_BLENDEQUATION, - alphaEq: GPU_BLENDEQUATION, - srcClr: GPU_BLENDFACTOR, - dstClr: GPU_BLENDFACTOR, - srcAlpha: GPU_BLENDFACTOR, - dstAlpha: GPU_BLENDFACTOR, - ); -} -extern "C" { - pub fn C3D_ColorLogicOp(op: GPU_LOGICOP); -} -extern "C" { - pub fn C3D_FragOpMode(mode: GPU_FRAGOPMODE); -} -extern "C" { - pub fn C3D_FragOpShadow(scale: f32, bias: f32); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_TexCube { - pub data: [*mut ::libc::c_void; 6usize], -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct C3D_Tex { - pub __bindgen_anon_1: C3D_Tex__bindgen_ty_1, - pub _bitfield_align_1: [u32; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, - pub __bindgen_anon_2: C3D_Tex__bindgen_ty_2, - pub param: u32_, - pub border: u32_, - pub __bindgen_anon_3: C3D_Tex__bindgen_ty_3, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_Tex__bindgen_ty_1 { - pub data: *mut ::libc::c_void, - pub cube: *mut C3D_TexCube, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_Tex__bindgen_ty_2 { - pub dim: u32_, - pub __bindgen_anon_1: C3D_Tex__bindgen_ty_2__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_Tex__bindgen_ty_2__bindgen_ty_1 { - pub height: u16_, - pub width: u16_, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_Tex__bindgen_ty_3 { - pub lodParam: u32_, - pub __bindgen_anon_1: C3D_Tex__bindgen_ty_3__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_Tex__bindgen_ty_3__bindgen_ty_1 { - pub lodBias: u16_, - pub maxLevel: u8_, - pub minLevel: u8_, -} -impl C3D_Tex { - #[inline] - pub fn fmt(&self) -> GPU_TEXCOLOR { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } - } - #[inline] - pub fn set_fmt(&mut self, val: GPU_TEXCOLOR) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 4u8, val as u64) - } - } - #[inline] - pub fn size(&self) -> usize { - unsafe { ::core::mem::transmute(self._bitfield_1.get(4usize, 28u8) as u32) } - } - #[inline] - pub fn set_size(&mut self, val: usize) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(4usize, 28u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1(fmt: GPU_TEXCOLOR, size: usize) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let fmt: u32 = unsafe { ::core::mem::transmute(fmt) }; - fmt as u64 - }); - __bindgen_bitfield_unit.set(4usize, 28u8, { - let size: u32 = unsafe { ::core::mem::transmute(size) }; - size as u64 - }); - __bindgen_bitfield_unit - } -} -#[repr(C)] -#[repr(align(8))] -#[derive(Debug, Copy, Clone)] -pub struct C3D_TexInitParams { - pub width: u16_, - pub height: u16_, - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, - pub __bindgen_padding_0: u16, -} -impl C3D_TexInitParams { - #[inline] - pub fn maxLevel(&self) -> u8_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u8) } - } - #[inline] - pub fn set_maxLevel(&mut self, val: u8_) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 4u8, val as u64) - } - } - #[inline] - pub fn format(&self) -> GPU_TEXCOLOR { - unsafe { ::core::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } - } - #[inline] - pub fn set_format(&mut self, val: GPU_TEXCOLOR) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(4usize, 4u8, val as u64) - } - } - #[inline] - pub fn type_(&self) -> GPU_TEXTURE_MODE_PARAM { - unsafe { ::core::mem::transmute(self._bitfield_1.get(8usize, 3u8) as u32) } - } - #[inline] - pub fn set_type(&mut self, val: GPU_TEXTURE_MODE_PARAM) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(8usize, 3u8, val as u64) - } - } - #[inline] - pub fn onVram(&self) -> bool { - unsafe { ::core::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u8) } - } - #[inline] - pub fn set_onVram(&mut self, val: bool) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - self._bitfield_1.set(11usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - maxLevel: u8_, - format: GPU_TEXCOLOR, - type_: GPU_TEXTURE_MODE_PARAM, - onVram: bool, - ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let maxLevel: u8 = unsafe { ::core::mem::transmute(maxLevel) }; - maxLevel as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let format: u32 = unsafe { ::core::mem::transmute(format) }; - format as u64 - }); - __bindgen_bitfield_unit.set(8usize, 3u8, { - let type_: u32 = unsafe { ::core::mem::transmute(type_) }; - type_ as u64 - }); - __bindgen_bitfield_unit.set(11usize, 1u8, { - let onVram: u8 = unsafe { ::core::mem::transmute(onVram) }; - onVram as u64 - }); - __bindgen_bitfield_unit - } -} -extern "C" { - pub fn C3D_TexInitWithParams( - tex: *mut C3D_Tex, - cube: *mut C3D_TexCube, - p: C3D_TexInitParams, - ) -> bool; -} -extern "C" { - pub fn C3D_TexLoadImage( - tex: *mut C3D_Tex, - data: *const ::libc::c_void, - face: GPU_TEXFACE, - level: ::libc::c_int, - ); -} -extern "C" { - pub fn C3D_TexGenerateMipmap(tex: *mut C3D_Tex, face: GPU_TEXFACE); -} -extern "C" { - pub fn C3D_TexBind(unitId: ::libc::c_int, tex: *mut C3D_Tex); -} -extern "C" { - pub fn C3D_TexFlush(tex: *mut C3D_Tex); -} -extern "C" { - pub fn C3D_TexDelete(tex: *mut C3D_Tex); -} -extern "C" { - pub fn C3D_TexShadowParams(perspective: bool, bias: f32); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTexColorLut { - pub color: [u32_; 256usize], - pub diff: [u32_; 256usize], -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct C3D_ProcTex { - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_1, - pub __bindgen_anon_2: C3D_ProcTex__bindgen_ty_2, - pub __bindgen_anon_3: C3D_ProcTex__bindgen_ty_3, - pub __bindgen_anon_4: C3D_ProcTex__bindgen_ty_4, - pub __bindgen_anon_5: C3D_ProcTex__bindgen_ty_5, - pub __bindgen_anon_6: C3D_ProcTex__bindgen_ty_6, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_ProcTex__bindgen_ty_1 { - pub proctex0: u32_, - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_1__bindgen_ty_1, -} -#[repr(C)] -#[repr(align(4))] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTex__bindgen_ty_1__bindgen_ty_1 { - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, -} -impl C3D_ProcTex__bindgen_ty_1__bindgen_ty_1 { - #[inline] - pub fn uClamp(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u32) } - } - #[inline] - pub fn set_uClamp(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 3u8, val as u64) - } - } - #[inline] - pub fn vClamp(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(3usize, 3u8) as u32) } - } - #[inline] - pub fn set_vClamp(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(3usize, 3u8, val as u64) - } - } - #[inline] - pub fn rgbFunc(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(6usize, 4u8) as u32) } - } - #[inline] - pub fn set_rgbFunc(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(6usize, 4u8, val as u64) - } - } - #[inline] - pub fn alphaFunc(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(10usize, 4u8) as u32) } - } - #[inline] - pub fn set_alphaFunc(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(10usize, 4u8, val as u64) - } - } - #[inline] - pub fn alphaSeparate(&self) -> bool { - unsafe { ::core::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u8) } - } - #[inline] - pub fn set_alphaSeparate(&mut self, val: bool) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - self._bitfield_1.set(14usize, 1u8, val as u64) - } - } - #[inline] - pub fn enableNoise(&self) -> bool { - unsafe { ::core::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u8) } - } - #[inline] - pub fn set_enableNoise(&mut self, val: bool) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - self._bitfield_1.set(15usize, 1u8, val as u64) - } - } - #[inline] - pub fn uShift(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(16usize, 2u8) as u32) } - } - #[inline] - pub fn set_uShift(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(16usize, 2u8, val as u64) - } - } - #[inline] - pub fn vShift(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(18usize, 2u8) as u32) } - } - #[inline] - pub fn set_vShift(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(18usize, 2u8, val as u64) - } - } - #[inline] - pub fn lodBiasLow(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(20usize, 8u8) as u32) } - } - #[inline] - pub fn set_lodBiasLow(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(20usize, 8u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - uClamp: u32_, - vClamp: u32_, - rgbFunc: u32_, - alphaFunc: u32_, - alphaSeparate: bool, - enableNoise: bool, - uShift: u32_, - vShift: u32_, - lodBiasLow: u32_, - ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let uClamp: u32 = unsafe { ::core::mem::transmute(uClamp) }; - uClamp as u64 - }); - __bindgen_bitfield_unit.set(3usize, 3u8, { - let vClamp: u32 = unsafe { ::core::mem::transmute(vClamp) }; - vClamp as u64 - }); - __bindgen_bitfield_unit.set(6usize, 4u8, { - let rgbFunc: u32 = unsafe { ::core::mem::transmute(rgbFunc) }; - rgbFunc as u64 - }); - __bindgen_bitfield_unit.set(10usize, 4u8, { - let alphaFunc: u32 = unsafe { ::core::mem::transmute(alphaFunc) }; - alphaFunc as u64 - }); - __bindgen_bitfield_unit.set(14usize, 1u8, { - let alphaSeparate: u8 = unsafe { ::core::mem::transmute(alphaSeparate) }; - alphaSeparate as u64 - }); - __bindgen_bitfield_unit.set(15usize, 1u8, { - let enableNoise: u8 = unsafe { ::core::mem::transmute(enableNoise) }; - enableNoise as u64 - }); - __bindgen_bitfield_unit.set(16usize, 2u8, { - let uShift: u32 = unsafe { ::core::mem::transmute(uShift) }; - uShift as u64 - }); - __bindgen_bitfield_unit.set(18usize, 2u8, { - let vShift: u32 = unsafe { ::core::mem::transmute(vShift) }; - vShift as u64 - }); - __bindgen_bitfield_unit.set(20usize, 8u8, { - let lodBiasLow: u32 = unsafe { ::core::mem::transmute(lodBiasLow) }; - lodBiasLow as u64 - }); - __bindgen_bitfield_unit - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_ProcTex__bindgen_ty_2 { - pub proctex1: u32_, - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_2__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTex__bindgen_ty_2__bindgen_ty_1 { - pub uNoiseAmpl: u16_, - pub uNoisePhase: u16_, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_ProcTex__bindgen_ty_3 { - pub proctex2: u32_, - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_3__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTex__bindgen_ty_3__bindgen_ty_1 { - pub vNoiseAmpl: u16_, - pub vNoisePhase: u16_, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_ProcTex__bindgen_ty_4 { - pub proctex3: u32_, - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_4__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTex__bindgen_ty_4__bindgen_ty_1 { - pub uNoiseFreq: u16_, - pub vNoiseFreq: u16_, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_ProcTex__bindgen_ty_5 { - pub proctex4: u32_, - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_5__bindgen_ty_1, -} -#[repr(C)] -#[repr(align(4))] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTex__bindgen_ty_5__bindgen_ty_1 { - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, -} -impl C3D_ProcTex__bindgen_ty_5__bindgen_ty_1 { - #[inline] - pub fn minFilter(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u32) } - } - #[inline] - pub fn set_minFilter(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 3u8, val as u64) - } - } - #[inline] - pub fn unknown1(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(3usize, 8u8) as u32) } - } - #[inline] - pub fn set_unknown1(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(3usize, 8u8, val as u64) - } - } - #[inline] - pub fn width(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(11usize, 8u8) as u32) } - } - #[inline] - pub fn set_width(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(11usize, 8u8, val as u64) - } - } - #[inline] - pub fn lodBiasHigh(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(19usize, 8u8) as u32) } - } - #[inline] - pub fn set_lodBiasHigh(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(19usize, 8u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - minFilter: u32_, - unknown1: u32_, - width: u32_, - lodBiasHigh: u32_, - ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let minFilter: u32 = unsafe { ::core::mem::transmute(minFilter) }; - minFilter as u64 - }); - __bindgen_bitfield_unit.set(3usize, 8u8, { - let unknown1: u32 = unsafe { ::core::mem::transmute(unknown1) }; - unknown1 as u64 - }); - __bindgen_bitfield_unit.set(11usize, 8u8, { - let width: u32 = unsafe { ::core::mem::transmute(width) }; - width as u64 - }); - __bindgen_bitfield_unit.set(19usize, 8u8, { - let lodBiasHigh: u32 = unsafe { ::core::mem::transmute(lodBiasHigh) }; - lodBiasHigh as u64 - }); - __bindgen_bitfield_unit - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_ProcTex__bindgen_ty_6 { - pub proctex5: u32_, - pub __bindgen_anon_1: C3D_ProcTex__bindgen_ty_6__bindgen_ty_1, -} -#[repr(C)] -#[repr(align(4))] -#[derive(Debug, Copy, Clone)] -pub struct C3D_ProcTex__bindgen_ty_6__bindgen_ty_1 { - pub _bitfield_align_1: [u32; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, -} -impl C3D_ProcTex__bindgen_ty_6__bindgen_ty_1 { - #[inline] - pub fn offset(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 8u8) as u32) } - } - #[inline] - pub fn set_offset(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 8u8, val as u64) - } - } - #[inline] - pub fn unknown2(&self) -> u32_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(8usize, 24u8) as u32) } - } - #[inline] - pub fn set_unknown2(&mut self, val: u32_) { - unsafe { - let val: u32 = ::core::mem::transmute(val); - self._bitfield_1.set(8usize, 24u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1(offset: u32_, unknown2: u32_) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 8u8, { - let offset: u32 = unsafe { ::core::mem::transmute(offset) }; - offset as u64 - }); - __bindgen_bitfield_unit.set(8usize, 24u8, { - let unknown2: u32 = unsafe { ::core::mem::transmute(unknown2) }; - unknown2 as u64 - }); - __bindgen_bitfield_unit - } -} -pub const C3D_ProcTex_U: _bindgen_ty_39 = 1; -pub const C3D_ProcTex_V: _bindgen_ty_39 = 2; -pub const C3D_ProcTex_UV: _bindgen_ty_39 = 3; -pub type _bindgen_ty_39 = ::libc::c_uint; -extern "C" { - pub fn C3D_ProcTexInit(pt: *mut C3D_ProcTex, offset: ::libc::c_int, length: ::libc::c_int); -} -extern "C" { - pub fn C3D_ProcTexNoiseCoefs( - pt: *mut C3D_ProcTex, - mode: ::libc::c_int, - amplitude: f32, - frequency: f32, - phase: f32, - ); -} -extern "C" { - pub fn C3D_ProcTexLodBias(pt: *mut C3D_ProcTex, bias: f32); -} -extern "C" { - pub fn C3D_ProcTexBind(texCoordId: ::libc::c_int, pt: *mut C3D_ProcTex); -} -pub type C3D_ProcTexLut = [u32_; 128usize]; -extern "C" { - pub fn C3D_ProcTexLutBind(id: GPU_PROCTEX_LUTID, lut: *mut C3D_ProcTexLut); -} -extern "C" { - pub fn ProcTexLut_FromArray(lut: *mut C3D_ProcTexLut, in_: *const f32); -} -extern "C" { - pub fn C3D_ProcTexColorLutBind(lut: *mut C3D_ProcTexColorLut); -} -extern "C" { - pub fn ProcTexColorLut_Write( - out: *mut C3D_ProcTexColorLut, - in_: *const u32_, - offset: ::libc::c_int, - length: ::libc::c_int, - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightLut { - pub data: [u32_; 256usize], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightLutDA { - pub lut: C3D_LightLut, - pub bias: f32, - pub scale: f32, -} -pub type C3D_LightLutFunc = ::core::option::Option f32>; -pub type C3D_LightLutFuncDA = - ::core::option::Option f32>; -extern "C" { - pub fn LightLut_FromArray(lut: *mut C3D_LightLut, data: *mut f32); -} -extern "C" { - pub fn LightLut_FromFunc( - lut: *mut C3D_LightLut, - func: C3D_LightLutFunc, - param: f32, - negative: bool, - ); -} -extern "C" { - pub fn LightLutDA_Create( - lut: *mut C3D_LightLutDA, - func: C3D_LightLutFuncDA, - from: f32, - to: f32, - arg0: f32, - arg1: f32, - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_Material { - pub ambient: [f32; 3usize], - pub diffuse: [f32; 3usize], - pub specular0: [f32; 3usize], - pub specular1: [f32; 3usize], - pub emission: [f32; 3usize], -} -pub type C3D_Light = C3D_Light_t; -pub type C3D_LightEnv = C3D_LightEnv_t; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightLutInputConf { - pub abs: u32_, - pub select: u32_, - pub scale: u32_, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightEnvConf { - pub ambient: u32_, - pub numLights: u32_, - pub config: [u32_; 2usize], - pub lutInput: C3D_LightLutInputConf, - pub permutation: u32_, -} -pub const C3DF_LightEnv_Dirty: _bindgen_ty_40 = 1; -pub const C3DF_LightEnv_MtlDirty: _bindgen_ty_40 = 2; -pub const C3DF_LightEnv_LCDirty: _bindgen_ty_40 = 4; -pub type _bindgen_ty_40 = ::libc::c_uint; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightEnv_t { - pub flags: u32_, - pub luts: [*mut C3D_LightLut; 6usize], - pub ambient: [f32; 3usize], - pub lights: [*mut C3D_Light; 8usize], - pub conf: C3D_LightEnvConf, - pub material: C3D_Material, -} -extern "C" { - pub fn C3D_LightEnvInit(env: *mut C3D_LightEnv); -} -extern "C" { - pub fn C3D_LightEnvBind(env: *mut C3D_LightEnv); -} -extern "C" { - pub fn C3D_LightEnvMaterial(env: *mut C3D_LightEnv, mtl: *const C3D_Material); -} -extern "C" { - pub fn C3D_LightEnvAmbient(env: *mut C3D_LightEnv, r: f32, g: f32, b: f32); -} -extern "C" { - pub fn C3D_LightEnvLut( - env: *mut C3D_LightEnv, - lutId: GPU_LIGHTLUTID, - input: GPU_LIGHTLUTINPUT, - negative: bool, - lut: *mut C3D_LightLut, - ); -} -pub const GPU_SHADOW_PRIMARY: _bindgen_ty_41 = 65536; -pub const GPU_SHADOW_SECONDARY: _bindgen_ty_41 = 131072; -pub const GPU_INVERT_SHADOW: _bindgen_ty_41 = 262144; -pub const GPU_SHADOW_ALPHA: _bindgen_ty_41 = 524288; -pub type _bindgen_ty_41 = ::libc::c_uint; -extern "C" { - pub fn C3D_LightEnvFresnel(env: *mut C3D_LightEnv, selector: GPU_FRESNELSEL); -} -extern "C" { - pub fn C3D_LightEnvBumpMode(env: *mut C3D_LightEnv, mode: GPU_BUMPMODE); -} -extern "C" { - pub fn C3D_LightEnvBumpSel(env: *mut C3D_LightEnv, texUnit: ::libc::c_int); -} -extern "C" { - pub fn C3D_LightEnvShadowMode(env: *mut C3D_LightEnv, mode: u32_); -} -extern "C" { - pub fn C3D_LightEnvShadowSel(env: *mut C3D_LightEnv, texUnit: ::libc::c_int); -} -extern "C" { - pub fn C3D_LightEnvClampHighlights(env: *mut C3D_LightEnv, clamp: bool); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightMatConf { - pub specular0: u32_, - pub specular1: u32_, - pub diffuse: u32_, - pub ambient: u32_, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_LightConf { - pub material: C3D_LightMatConf, - pub position: [u16_; 3usize], - pub padding0: u16_, - pub spotDir: [u16_; 3usize], - pub padding1: u16_, - pub padding2: u32_, - pub config: u32_, - pub distAttnBias: u32_, - pub distAttnScale: u32_, -} -pub const C3DF_Light_Enabled: _bindgen_ty_42 = 1; -pub const C3DF_Light_Dirty: _bindgen_ty_42 = 2; -pub const C3DF_Light_MatDirty: _bindgen_ty_42 = 4; -pub const C3DF_Light_SPDirty: _bindgen_ty_42 = 16384; -pub const C3DF_Light_DADirty: _bindgen_ty_42 = 32768; -pub type _bindgen_ty_42 = ::libc::c_uint; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_Light_t { - pub flags: u16_, - pub id: u16_, - pub parent: *mut C3D_LightEnv, - pub lut_SP: *mut C3D_LightLut, - pub lut_DA: *mut C3D_LightLut, - pub ambient: [f32; 3usize], - pub diffuse: [f32; 3usize], - pub specular0: [f32; 3usize], - pub specular1: [f32; 3usize], - pub conf: C3D_LightConf, -} -extern "C" { - pub fn C3D_LightInit(light: *mut C3D_Light, env: *mut C3D_LightEnv) -> ::libc::c_int; -} -extern "C" { - pub fn C3D_LightEnable(light: *mut C3D_Light, enable: bool); -} -extern "C" { - pub fn C3D_LightTwoSideDiffuse(light: *mut C3D_Light, enable: bool); -} -extern "C" { - pub fn C3D_LightGeoFactor(light: *mut C3D_Light, id: ::libc::c_int, enable: bool); -} -extern "C" { - pub fn C3D_LightAmbient(light: *mut C3D_Light, r: f32, g: f32, b: f32); -} -extern "C" { - pub fn C3D_LightDiffuse(light: *mut C3D_Light, r: f32, g: f32, b: f32); -} -extern "C" { - pub fn C3D_LightSpecular0(light: *mut C3D_Light, r: f32, g: f32, b: f32); -} -extern "C" { - pub fn C3D_LightSpecular1(light: *mut C3D_Light, r: f32, g: f32, b: f32); -} -extern "C" { - pub fn C3D_LightPosition(light: *mut C3D_Light, pos: *mut C3D_FVec); -} -extern "C" { - pub fn C3D_LightShadowEnable(light: *mut C3D_Light, enable: bool); -} -extern "C" { - pub fn C3D_LightSpotEnable(light: *mut C3D_Light, enable: bool); -} -extern "C" { - pub fn C3D_LightSpotDir(light: *mut C3D_Light, x: f32, y: f32, z: f32); -} -extern "C" { - pub fn C3D_LightSpotLut(light: *mut C3D_Light, lut: *mut C3D_LightLut); -} -extern "C" { - pub fn C3D_LightDistAttnEnable(light: *mut C3D_Light, enable: bool); -} -extern "C" { - pub fn C3D_LightDistAttn(light: *mut C3D_Light, lut: *mut C3D_LightLutDA); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_FogLut { - pub data: [u32_; 128usize], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_GasLut { - pub diff: [u32_; 8usize], - pub color: [u32_; 8usize], -} -extern "C" { - pub fn FogLut_FromArray(lut: *mut C3D_FogLut, data: *const f32); -} -extern "C" { - pub fn FogLut_Exp(lut: *mut C3D_FogLut, density: f32, gradient: f32, near: f32, far: f32); -} -extern "C" { - pub fn C3D_FogGasMode(fogMode: GPU_FOGMODE, gasMode: GPU_GASMODE, zFlip: bool); -} -extern "C" { - pub fn C3D_FogColor(color: u32_); -} -extern "C" { - pub fn C3D_FogLutBind(lut: *mut C3D_FogLut); -} -extern "C" { - pub fn GasLut_FromArray(lut: *mut C3D_GasLut, data: *const u32_); -} -extern "C" { - pub fn C3D_GasBeginAcc(); -} -extern "C" { - pub fn C3D_GasDeltaZ(value: f32); -} -extern "C" { - pub fn C3D_GasAccMax(value: f32); -} -extern "C" { - pub fn C3D_GasAttn(value: f32); -} -extern "C" { - pub fn C3D_GasLightPlanar(min: f32, max: f32, attn: f32); -} -extern "C" { - pub fn C3D_GasLightView(min: f32, max: f32, attn: f32); -} -extern "C" { - pub fn C3D_GasLightDirection(dotp: f32); -} -extern "C" { - pub fn C3D_GasLutInput(input: GPU_GASLUTINPUT); -} -extern "C" { - pub fn C3D_GasLutBind(lut: *mut C3D_GasLut); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_FrameBuf { - pub colorBuf: *mut ::libc::c_void, - pub depthBuf: *mut ::libc::c_void, - pub width: u16_, - pub height: u16_, - pub colorFmt: GPU_COLORBUF, - pub depthFmt: GPU_DEPTHBUF, - pub block32: bool, - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - pub __bindgen_padding_0: u16, -} -impl C3D_FrameBuf { - #[inline] - pub fn colorMask(&self) -> u8_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u8) } - } - #[inline] - pub fn set_colorMask(&mut self, val: u8_) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - self._bitfield_1.set(0usize, 4u8, val as u64) - } - } - #[inline] - pub fn depthMask(&self) -> u8_ { - unsafe { ::core::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u8) } - } - #[inline] - pub fn set_depthMask(&mut self, val: u8_) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - self._bitfield_1.set(4usize, 4u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1(colorMask: u8_, depthMask: u8_) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let colorMask: u8 = unsafe { ::core::mem::transmute(colorMask) }; - colorMask as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let depthMask: u8 = unsafe { ::core::mem::transmute(depthMask) }; - depthMask as u64 - }); - __bindgen_bitfield_unit - } -} -pub const C3D_CLEAR_COLOR: C3D_ClearBits = 1; -pub const C3D_CLEAR_DEPTH: C3D_ClearBits = 2; -pub const C3D_CLEAR_ALL: C3D_ClearBits = 3; -pub type C3D_ClearBits = ::libc::c_uint; -extern "C" { - pub fn C3D_CalcColorBufSize(width: u32_, height: u32_, fmt: GPU_COLORBUF) -> u32_; -} -extern "C" { - pub fn C3D_CalcDepthBufSize(width: u32_, height: u32_, fmt: GPU_DEPTHBUF) -> u32_; -} -extern "C" { - pub fn C3D_GetFrameBuf() -> *mut C3D_FrameBuf; -} -extern "C" { - pub fn C3D_SetFrameBuf(fb: *mut C3D_FrameBuf); -} -extern "C" { - pub fn C3D_FrameBufTex( - fb: *mut C3D_FrameBuf, - tex: *mut C3D_Tex, - face: GPU_TEXFACE, - level: ::libc::c_int, - ); -} -extern "C" { - pub fn C3D_FrameBufClear( - fb: *mut C3D_FrameBuf, - clearBits: C3D_ClearBits, - clearColor: u32_, - clearDepth: u32_, - ); -} -extern "C" { - pub fn C3D_FrameBufTransfer( - fb: *mut C3D_FrameBuf, - screen: gfxScreen_t, - side: gfx3dSide_t, - transferFlags: u32_, - ); -} -pub type C3D_RenderTarget = C3D_RenderTarget_tag; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct C3D_RenderTarget_tag { - pub next: *mut C3D_RenderTarget, - pub prev: *mut C3D_RenderTarget, - pub frameBuf: C3D_FrameBuf, - pub used: bool, - pub ownsColor: bool, - pub ownsDepth: bool, - pub linked: bool, - pub screen: gfxScreen_t, - pub side: gfx3dSide_t, - pub transferFlags: u32_, -} -pub const C3D_FRAME_SYNCDRAW: _bindgen_ty_43 = 1; -pub const C3D_FRAME_NONBLOCK: _bindgen_ty_43 = 2; -pub type _bindgen_ty_43 = ::libc::c_uint; -extern "C" { - pub fn C3D_FrameRate(fps: f32) -> f32; -} -extern "C" { - pub fn C3D_FrameSync(); -} -extern "C" { - pub fn C3D_FrameCounter(id: ::libc::c_int) -> u32_; -} -extern "C" { - pub fn C3D_FrameBegin(flags: u8_) -> bool; -} -extern "C" { - pub fn C3D_FrameDrawOn(target: *mut C3D_RenderTarget) -> bool; -} -extern "C" { - pub fn C3D_FrameSplit(flags: u8_); -} -extern "C" { - pub fn C3D_FrameEnd(flags: u8_); -} -extern "C" { - pub fn C3D_FrameEndHook( - hook: ::core::option::Option, - param: *mut ::libc::c_void, - ); -} -extern "C" { - pub fn C3D_GetDrawingTime() -> f32; -} -extern "C" { - pub fn C3D_GetProcessingTime() -> f32; -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union C3D_DEPTHTYPE { - pub __i: ::libc::c_int, - pub __e: GPU_DEPTHBUF, -} -extern "C" { - pub fn C3D_RenderTargetCreate( - width: ::libc::c_int, - height: ::libc::c_int, - colorFmt: GPU_COLORBUF, - depthFmt: C3D_DEPTHTYPE, - ) -> *mut C3D_RenderTarget; -} -extern "C" { - pub fn C3D_RenderTargetCreateFromTex( - tex: *mut C3D_Tex, - face: GPU_TEXFACE, - level: ::libc::c_int, - depthFmt: C3D_DEPTHTYPE, - ) -> *mut C3D_RenderTarget; -} -extern "C" { - pub fn C3D_RenderTargetDelete(target: *mut C3D_RenderTarget); -} -extern "C" { - pub fn C3D_RenderTargetSetOutput( - target: *mut C3D_RenderTarget, - screen: gfxScreen_t, - side: gfx3dSide_t, - transferFlags: u32_, - ); -} -extern "C" { - pub fn C3D_SyncDisplayTransfer( - inadr: *mut u32_, - indim: u32_, - outadr: *mut u32_, - outdim: u32_, - flags: u32_, - ); -} -extern "C" { - pub fn C3D_SyncTextureCopy( - inadr: *mut u32_, - indim: u32_, - outadr: *mut u32_, - outdim: u32_, - size: u32_, - flags: u32_, - ); -} -extern "C" { - pub fn C3D_SyncMemoryFill( - buf0a: *mut u32_, - buf0v: u32_, - buf0e: *mut u32_, - control0: u16_, - buf1a: *mut u32_, - buf1v: u32_, - buf1e: *mut u32_, - control1: u16_, - ); -} -pub type FILE = __FILE; -#[doc = " @brief Subtexture\n @note If top > bottom, the subtexture is rotated 1/4 revolution counter-clockwise"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Tex3DS_SubTexture { - #[doc = "< Sub-texture width (pixels)"] - pub width: u16_, - #[doc = "< Sub-texture height (pixels)"] - pub height: u16_, - #[doc = "< Left u-coordinate"] - pub left: f32, - #[doc = "< Top v-coordinate"] - pub top: f32, - #[doc = "< Right u-coordinate"] - pub right: f32, - #[doc = "< Bottom v-coordinate"] - pub bottom: f32, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Tex3DS_Texture_s { - _unused: [u8; 0], -} -#[doc = " @brief Texture"] -pub type Tex3DS_Texture = *mut Tex3DS_Texture_s; -extern "C" { - #[doc = " @brief Import Tex3DS texture\n @param[in] input Input data\n @param[in] insize Size of the input data\n @param[out] tex citro3d texture\n @param[out] texcube citro3d texcube\n @param[in] vram Whether to store textures in VRAM\n @returns Tex3DS texture"] - pub fn Tex3DS_TextureImport( - input: *const ::libc::c_void, - insize: usize, - tex: *mut C3D_Tex, - texcube: *mut C3D_TexCube, - vram: bool, - ) -> Tex3DS_Texture; -} -extern "C" { - #[doc = " @brief Import Tex3DS texture\n\n @description\n For example, use this if you want to import from a large file without\n pulling the entire file into memory.\n\n @param[out] tex citro3d texture\n @param[out] texcube citro3d texcube\n @param[in] vram Whether to store textures in VRAM\n @param[in] callback Data callback\n @param[in] userdata User data passed to callback\n @returns Tex3DS texture"] - pub fn Tex3DS_TextureImportCallback( - tex: *mut C3D_Tex, - texcube: *mut C3D_TexCube, - vram: bool, - callback: decompressCallback, - userdata: *mut ::libc::c_void, - ) -> Tex3DS_Texture; -} -extern "C" { - #[doc = " @brief Import Tex3DS texture\n\n Starts reading at the current file descriptor's offset. The file\n descriptor's position is left at the end of the decoded data. On error, the\n file descriptor's position is indeterminate.\n\n @param[in] fd Open file descriptor\n @param[out] tex citro3d texture\n @param[out] texcube citro3d texcube\n @param[in] vram Whether to store textures in VRAM\n @returns Tex3DS texture"] - pub fn Tex3DS_TextureImportFD( - fd: ::libc::c_int, - tex: *mut C3D_Tex, - texcube: *mut C3D_TexCube, - vram: bool, - ) -> Tex3DS_Texture; -} -extern "C" { - #[doc = " @brief Import Tex3DS texture\n\n Starts reading at the current file stream's offset. The file stream's\n position is left at the end of the decoded data. On error, the file\n stream's position is indeterminate.\n\n @param[in] fp Open file stream\n @param[out] tex citro3d texture\n @param[out] texcube citro3d texcube\n @param[in] vram Whether to store textures in VRAM\n @returns Tex3DS texture"] - pub fn Tex3DS_TextureImportStdio( - fp: *mut FILE, - tex: *mut C3D_Tex, - texcube: *mut C3D_TexCube, - vram: bool, - ) -> Tex3DS_Texture; -} -extern "C" { - #[doc = " @brief Get number of subtextures\n @param[in] texture Tex3DS texture\n @returns Number of subtextures"] - pub fn Tex3DS_GetNumSubTextures(texture: Tex3DS_Texture) -> usize; -} -extern "C" { - #[doc = " @brief Get subtexture\n @param[in] texture Tex3DS texture\n @param[in] index Subtexture index\n @returns Subtexture info"] - pub fn Tex3DS_GetSubTexture(texture: Tex3DS_Texture, index: usize) -> *const Tex3DS_SubTexture; -} -extern "C" { - #[doc = " @brief Free Tex3DS texture\n @param[in] texture Tex3DS texture to free"] - pub fn Tex3DS_TextureFree(texture: Tex3DS_Texture); -} diff --git a/citro3d-sys/src/gx.rs b/citro3d-sys/src/gx.rs index 2630208..c2cfb98 100644 --- a/citro3d-sys/src/gx.rs +++ b/citro3d-sys/src/gx.rs @@ -1,4 +1,5 @@ -//! Helper functions based on `<3ds/gpu/gx.h>`. +//! Helper functions based on `<3ds/gpu/gx.h>`. Bindgen doesn't work on these +//! function-like macros so we just reimplement them as `#[inline]` here. use ctru_sys::{GX_TRANSFER_FORMAT, GX_TRANSFER_SCALE}; diff --git a/citro3d-sys/src/lib.rs b/citro3d-sys/src/lib.rs index 48a46ec..ed84f5e 100644 --- a/citro3d-sys/src/lib.rs +++ b/citro3d-sys/src/lib.rs @@ -5,19 +5,7 @@ #![allow(non_camel_case_types)] #![allow(clippy::all)] -pub mod base; -pub mod gx; -pub mod os; -pub mod renderqueue; -pub mod texenv; -pub mod uniforms; - -mod bindings; +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -pub use base::*; -pub use bindings::*; +pub mod gx; pub use gx::*; -pub use os::*; -pub use renderqueue::*; -pub use texenv::*; -pub use uniforms::*; diff --git a/citro3d-sys/src/os.rs b/citro3d-sys/src/os.rs deleted file mode 100644 index ed04411..0000000 --- a/citro3d-sys/src/os.rs +++ /dev/null @@ -1,13 +0,0 @@ -// TODO: move this to ctru-sys, maybe? -// would probably be auto-generated via https://github.com/rust3ds/ctru-rs/issues/123 - -use ctru_sys::{osSharedConfig_s, OS_SHAREDCFG_VADDR}; - -fn OS_SharedConfig() -> *mut osSharedConfig_s { - OS_SHAREDCFG_VADDR as _ -} - -/// Gets the state of the 3D slider as a value from 0.0 to 1.0 -pub unsafe fn osGet3DSliderState() -> f32 { - (*OS_SharedConfig()).slider_3d -} diff --git a/citro3d-sys/src/renderqueue.rs b/citro3d-sys/src/renderqueue.rs deleted file mode 100644 index 95a239a..0000000 --- a/citro3d-sys/src/renderqueue.rs +++ /dev/null @@ -1,18 +0,0 @@ -//! Definitions from `` - -use crate::*; - -#[inline] -pub unsafe fn C3D_RenderTargetDetachOutput(target: *mut C3D_RenderTarget) { - C3D_RenderTargetSetOutput(core::ptr::null_mut(), (*target).screen, (*target).side, 0); -} - -#[inline] -pub unsafe fn C3D_RenderTargetClear( - target: *mut C3D_RenderTarget, - clearBits: C3D_ClearBits, - clearColor: u32, - clearDepth: u32, -) { - C3D_FrameBufClear(&mut (*target).frameBuf, clearBits, clearColor, clearDepth); -} diff --git a/citro3d-sys/src/texenv.rs b/citro3d-sys/src/texenv.rs deleted file mode 100644 index bcc599c..0000000 --- a/citro3d-sys/src/texenv.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! Definitions from ``. -//! -//! Most of these functions are `static inline` so they don't get generated by `bindgen`. -//! See . - -use core::ops::{BitOr, Shl}; - -use ctru_sys::{GPU_COMBINEFUNC, GPU_PREVIOUS, GPU_REPLACE, GPU_TEVSCALE_1, GPU_TEVSRC}; -use libc::c_int; - -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, -{ - a | b << 4 | c << 8 -} - -/// Creates a texture combiner operand parameter from three operands. -#[inline] -fn GPU_TEVOPERANDS(a: T, b: T, c: T) -> T -where - T: BitOr + Shl, -{ - 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; - (*env).__bindgen_anon_1.opAll = 0; - (*env).funcRgb = GPU_REPLACE as u16; - (*env).funcAlpha = (*env).funcRgb; - (*env).color = 0xFFFFFFFF; - (*env).scaleRgb = GPU_TEVSCALE_1 as u16; - (*env).scaleAlpha = GPU_TEVSCALE_1 as u16; -} - -#[inline] -pub unsafe fn C3D_TexEnvSrc( - env: *mut C3D_TexEnv, - mode: C3D_TexEnvMode, - s1: GPU_TEVSRC, - s2: GPU_TEVSRC, // default GPU_PRIMARY_COLOR - s3: GPU_TEVSRC, // default GPU_PRIMARY_COLOR -) { - let param = GPU_TEVSOURCES(s1, s2, s3); - - if mode & C3D_RGB != 0 { - (*env).srcRgb = param as u16; - } - - if mode & C3D_Alpha != 0 { - (*env).srcAlpha = param as u16; - } -} - -// TODO: match API of texenv.h -#[inline] -pub unsafe fn C3D_TexEnvOp( - env: *mut C3D_TexEnv, - mode: C3D_TexEnvMode, - o1: c_int, - o2: c_int, - o3: c_int, -) { - let param = GPU_TEVOPERANDS(o1, o2, o3); - - if mode & C3D_RGB != 0 { - // (*env).opRgb = param as u16; - (*env) - .__bindgen_anon_1 - .__bindgen_anon_1 - .set_opRgb(param as u32); - } - - if mode & C3D_Alpha != 0 { - (*env) - .__bindgen_anon_1 - .__bindgen_anon_1 - .set_opAlpha(param as u32); - } -} - -#[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; - } - - if mode & C3D_Alpha != 0 { - (*env).funcAlpha = param as u16; - } -} diff --git a/citro3d-sys/src/uniforms.rs b/citro3d-sys/src/uniforms.rs deleted file mode 100644 index bfd6d83..0000000 --- a/citro3d-sys/src/uniforms.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Definitions from`` - -use ctru_sys::GPU_SHADER_TYPE; - -use super::{C3D_FVUnif, C3D_FVUnifDirty, C3D_FVec, C3D_Mtx}; - -#[inline] -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; - } - - return &mut C3D_FVUnif[type_ as usize][id as usize]; -} - -#[inline] -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 { - *ptr.offset(i as isize) = (*mtx).r.as_ref()[i as usize]; - } -} - -#[inline] -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: 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]); -} diff --git a/citro3d/examples/triangle.rs b/citro3d/examples/triangle.rs index 426a95a..8f3522f 100644 --- a/citro3d/examples/triangle.rs +++ b/citro3d/examples/triangle.rs @@ -177,7 +177,7 @@ fn calculate_projections() -> Projections { // TODO: it would be cool to allow playing around with these parameters on // the fly with D-pad, etc. - let slider_val = unsafe { citro3d_sys::osGet3DSliderState() }; + let slider_val = unsafe { ctru_sys::osGet3DSliderState() }; let iod = slider_val / 4.0; let near = 0.01; From a06dc14a8655aedf9048ec925cfbdcbdf228ec80 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sat, 30 Sep 2023 22:58:36 -0400 Subject: [PATCH 2/3] Actually use test_runner::run_gdb (I forgor) --- citro3d/Cargo.toml | 3 +++ citro3d/src/lib.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/citro3d/Cargo.toml b/citro3d/Cargo.toml index 99b340c..306b2d2 100644 --- a/citro3d/Cargo.toml +++ b/citro3d/Cargo.toml @@ -13,3 +13,6 @@ citro3d-sys = { git = "https://github.com/rust3ds/citro3d-rs.git" } ctru-rs = { git = "https://github.com/rust3ds/ctru-rs.git" } ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" } libc = "0.2.125" + +[dev-dependencies] +test-runner = { git = "https://github.com/rust3ds/test-runner.git" } diff --git a/citro3d/src/lib.rs b/citro3d/src/lib.rs index 5176de6..c7dbe0e 100644 --- a/citro3d/src/lib.rs +++ b/citro3d/src/lib.rs @@ -1,4 +1,6 @@ //! Safe Rust bindings to `citro3d`. +#![feature(custom_test_frameworks)] +#![test_runner(test_runner::run_gdb)] pub mod attrib; pub mod buffer; From 97f4835c17dafdae4ad9bd49d14062cc52ffb8a7 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sun, 1 Oct 2023 00:33:44 -0400 Subject: [PATCH 3/3] Include gcc libdir when building Assume devkitARM ships with only a single version, so then find the first entry matching `${DEVKITARM}/lib/gcc/arm-none-eabi/*/include` and add it to the -isystem includes. --- citro3d-sys/Cargo.toml | 3 ++- citro3d-sys/build.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/citro3d-sys/Cargo.toml b/citro3d-sys/Cargo.toml index 9c55a60..62b31d8 100644 --- a/citro3d-sys/Cargo.toml +++ b/citro3d-sys/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "citro3d-sys" version = "0.1.0" -authors = [ "Rust3DS Org", "panicbit " ] +authors = ["Rust3DS Org", "panicbit "] edition = "2021" license = "Zlib" +links = "citro3d" [dependencies] libc = "0.2.116" diff --git a/citro3d-sys/build.rs b/citro3d-sys/build.rs index 1210f08..c429ee9 100644 --- a/citro3d-sys/build.rs +++ b/citro3d-sys/build.rs @@ -42,6 +42,18 @@ fn main() { let system_include = sysroot.join("include"); let static_fns_path = Path::new("citro3d_statics_wrapper"); + let gcc_dir = PathBuf::from_iter([devkitarm.as_str(), "lib", "gcc", "arm-none-eabi"]); + + let gcc_include = gcc_dir + .read_dir() + .unwrap() + // Assuming that there is only one gcc version of libs under the devkitARM dir + .next() + .unwrap() + .unwrap() + .path() + .join("include"); + let bindings = Builder::default() .header(three_ds_h.to_str().unwrap()) .header(citro3d_h.to_str().unwrap()) @@ -70,6 +82,8 @@ fn main() { sysroot.to_str().unwrap(), "-isystem", system_include.to_str().unwrap(), + "-isystem", + gcc_include.to_str().unwrap(), "-I", include_path.to_str().unwrap(), "-mfloat-abi=hard",