Browse Source

Initial attempt at build script compilation

pull/18/head
Ian Chamberlain 3 years ago
parent
commit
5743da3d56
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 39
      citro3d/build.rs
  2. 2
      citro3d/examples/assets/vshader.pica
  3. 21
      citro3d/examples/triangle.rs

39
citro3d/build.rs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
use std::ffi::OsStr;
use std::path::PathBuf;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=examples/assets");
let mut asset_dir = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());
asset_dir.push("examples");
asset_dir.push("assets");
println!("Checking dir {:?}", asset_dir.display());
for entry in asset_dir.read_dir().unwrap().flatten() {
println!("Checking {:?}", entry.path().display());
if let Some("pica") = entry.path().extension().and_then(OsStr::to_str) {
println!("cargo:rerun-if-changed={}", entry.path().display());
let mut out_path = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
out_path.push("examples");
out_path.push("assets");
out_path.push(entry.path().with_extension("shbin").file_name().unwrap());
std::fs::create_dir_all(out_path.parent().unwrap()).unwrap();
println!("Compiling {:?}", out_path.display());
let mut cmd = Command::new("picasso");
cmd.arg(entry.path()).arg("--out").arg(out_path);
let status = cmd.spawn().unwrap().wait().unwrap();
assert!(
status.success(),
"Command {cmd:#?} failed with code {status:?}"
);
}
}
}

2
citro3d/examples/assets/vshader.pica

@ -5,8 +5,6 @@ @@ -5,8 +5,6 @@
; Constants
.constf myconst(0.0, 1.0, -1.0, 0.1)
.constf myconst2(0.3, 0.0, 0.0, 0.0)
.alias zeros myconst.xxxx ; Vector full of zeros
.alias ones myconst.yyyy ; Vector full of ones
; Outputs

21
citro3d/examples/triangle.rs

@ -91,25 +91,18 @@ impl Vertex { @@ -91,25 +91,18 @@ impl Vertex {
}
}
static SHBIN_BYTES: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/examples/assets/vshader.shbin"));
fn scene_init() -> (shaderProgram_s, i8, C3D_Mtx, *mut libc::c_void, *mut DVLB_s) {
// Load the vertex shader, create a shader program and bind it
unsafe {
// To compile the shader:
// ```sh
// picasso assets/vshader.v.pica -o assets/vshader.shbin
// ```
// TODO: can we do this in a build script?
// boo, this way we have to specify the length. Alternative seems to be allocating a
// slice first, then copying into it with a transmute...
const SHBIN_BYTES: &[u8; 280] = include_bytes!("assets/vshader.shbin");
// Assume the data is aligned properly...
let mut shbin_data: [u32; SHBIN_BYTES.len() / 4] = std::mem::transmute_copy(SHBIN_BYTES);
let mut shader_bytes = SHBIN_BYTES.to_owned();
// Assume the data is aligned properly...
let vshader_dvlb = citro3d_sys::DVLB_ParseFile(
shbin_data.as_mut_ptr(),
shbin_data
.len()
shader_bytes.as_mut_ptr() as _,
(shader_bytes.len() / 4)
.try_into()
.expect("shader len fits in a u32"),
);

Loading…
Cancel
Save