Skip to content

Commit

Permalink
Export shader keys for materials
Browse files Browse the repository at this point in the history
  • Loading branch information
redstrate committed Apr 27, 2024
1 parent 6a0c00b commit 60df89b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/mtrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use physis::mtrl::Material;
use std::os::raw::c_char;
use std::ptr::{null, null_mut};
use std::{mem, slice};
use physis::mtrl::ShaderKey;

#[repr(C)]
#[derive(Clone, Copy)]
Expand All @@ -14,6 +15,8 @@ pub struct physis_Material {
shpk_name: *const c_char,
num_textures: u32,
textures: *mut *const c_char,
num_shader_keys: u32,
shader_keys: *mut ShaderKey
}

impl Default for physis_Material {
Expand All @@ -22,6 +25,8 @@ impl Default for physis_Material {
shpk_name: null(),
num_textures: 0,
textures: null_mut(),
num_shader_keys: 0,
shader_keys: null_mut()
}
}
}
Expand All @@ -38,13 +43,18 @@ pub extern "C" fn physis_material_parse(buffer: physis_Buffer) -> physis_Materia
c_strings.push(ffi_to_c_string(tex));
}

let mut shader_keys = material.shader_keys.clone();

let mat = physis_Material {
shpk_name: ffi_to_c_string(&material.shader_package_name),
num_textures: c_strings.len() as u32,
textures: c_strings.as_mut_ptr(),
num_shader_keys: shader_keys.len() as u32,
shader_keys: shader_keys.as_mut_ptr(),
};

mem::forget(c_strings);
mem::forget(shader_keys);

mat
} else {
Expand Down

0 comments on commit 60df89b

Please sign in to comment.