Browse Source

Init

pull/18/head
panicbit 7 years ago
commit
a5cd55250b
  1. 2
      .gitignore
  2. 8
      Cargo.toml
  3. 48
      bindgen.sh
  4. 10
      src/base.rs
  5. 267
      src/bindgen.rs
  6. 33
      src/lib.rs
  7. 39
      src/texenv.rs
  8. 35
      src/uniforms.rs

2
.gitignore vendored

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
target
Cargo.lock

8
Cargo.toml

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
[package]
name = "citro3d-sys"
version = "0.1.0"
authors = ["panicbit <panicbit.dev@gmail.com>"]
[dependencies]
libc = "0.2.26"
ctru-sys = { git = "https://github.com/rust3ds/ctru-rs" }

48
bindgen.sh

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
#!/usr/bin/env bash
clang_version=$1
if [ -z "$clang_version" ]; then
echo " usage: ./bindgen.sh <clang_version>"
echo "example: ./bindgen.sh 5.0.0"
echo "Check your current version with \`clang -v\`."
exit 1
fi
set -euxo pipefail
bindgen "$DEVKITPRO/libctru/include/citro3d.h" \
--rust-target 1.21 \
--use-core \
--distrust-clang-mangling \
--no-doc-comments \
--no-derive-debug \
--no-layout-tests \
--no-rustfmt-bindings \
--ctypes-prefix "::libc" \
--no-prepend-enum-name \
--generate "functions,types,vars" \
--blacklist-type "u(8|16|32|64)" \
--blacklist-type "__builtin_va_list" \
--blacklist-type "__va_list" \
--no-recursive-whitelist \
--whitelist-type "C3D_.*" \
--whitelist-function "C3D_.*" \
--whitelist-var "C3D_.*" \
--whitelist-function 'AttrInfo_(Init|AddLoader|AddFixed)' \
--whitelist-function 'BufInfo_(Init|Add)' \
--whitelist-function 'Mtx_.*' \
--raw-line "use libctru::*;" \
-- \
--target=arm-none-eabi \
--sysroot=$DEVKITARM/arm-none-eabi \
-isystem$DEVKITARM/arm-none-eabi/include \
-isystem/usr/lib/clang/$clang_version/include \
-I$DEVKITPRO/libctru/include \
-mfloat-abi=hard \
-march=armv6k \
-mtune=mpcore \
-mfpu=vfp \
-DARM11 \
-D_3DS \
> src/bindgen.rs

10
src/base.rs

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
#![allow(non_snake_case)]
// c3d/base.h
use libc::c_int;
use super::*;
pub unsafe fn C3D_FixedAttribSet(id: c_int, x: f32, y: f32, z: f32, w: f32) {
let mut ptr = C3D_FixedAttribGetWritePtr(id);
*(*ptr).c.as_mut() = [x, y, z, w];
}

267
src/bindgen.rs

File diff suppressed because one or more lines are too long

33
src/lib.rs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
extern crate libc;
extern crate core;
#[macro_use] extern crate ctru_sys as libctru;
#[allow(warnings)]
mod bindgen;
pub mod base;
pub mod texenv;
pub mod uniforms;
pub use bindgen::*;
pub use base::*;
pub use texenv::*;
pub use uniforms::*;
#[link(name="citro3d")]
#[link(name="ctru")]
extern {}
impl Copy for C3D_FVec {}
impl Clone for C3D_FVec {
fn clone(&self) -> Self {
*self
}
}
impl From<libctru::GPU_DEPTHBUF> for C3D_DEPTHTYPE {
fn from(fmt: libctru::GPU_DEPTHBUF) -> Self {
Self {
__e: fmt,
}
}
}

39
src/texenv.rs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
#![allow(non_snake_case)]
// c3d/texenv.h
use libc::c_int;
use super::*;
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);
if mode & C3D_RGB as i32 != 0 {
(*env).srcRgb = param as u16;
}
if mode & C3D_Alpha as i32 != 0 {
(*env).srcAlpha = param as u16;
}
}
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);
if mode & C3D_RGB as i32 != 0 {
(*env).opRgb = param as u16;
}
if mode & C3D_Alpha as i32 != 0 {
(*env).opAlpha = param as u16;
}
}
pub unsafe fn C3D_TexEnvFunc(env: *mut C3D_TexEnv, mode: c_int, param: c_int) {
if mode & C3D_RGB as i32 != 0 {
(*env).funcRgb = param as u16;
}
if mode & C3D_Alpha as i32 != 0 {
(*env).funcAlpha = param as u16;
}
}

35
src/uniforms.rs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
#![allow(non_snake_case)]
// c3d/uniforms.h
use libc::c_int;
use super::*;
use libctru::GPU_SHADER_TYPE;
#[inline]
pub unsafe fn C3D_FVUnifWritePtr(type_: GPU_SHADER_TYPE, id: c_int, size: 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: c_int, mtx: *const C3D_Mtx, num: 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: 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) {
let ptr = C3D_FVUnifWritePtr(type_, id, 1);
*(*ptr).c.as_mut() = [x, y, z, w];
}
Loading…
Cancel
Save