#![deny(unsafe_op_in_unsafe_fn)]
use crate::metal::context::MtlContext;
use crate::metal::texture::{upload_texture, upload_texture_image};
impl MtlContext {
pub(crate) fn update_texture_slot(
&mut self,
slot: usize,
image: &concinnity_core::bake::texture::TextureImage,
) -> Result<(), String> {
if slot >= self.textures.len() {
return Err(format!(
"update_texture_slot: slot {} out of range (pool size {})",
slot,
self.textures.len()
));
}
self.textures[slot] = upload_texture_image(&self.allocator, image)?;
Ok(())
}
pub(crate) fn evict_texture_slot(&mut self, slot: usize) -> Result<(), String> {
if slot >= self.textures.len() {
return Err(format!(
"evict_texture_slot: slot {} out of range (pool size {})",
slot,
self.textures.len()
));
}
self.textures[slot] = upload_texture(&self.allocator, 1, 1, &[128, 128, 128, 255])?;
Ok(())
}
pub(crate) fn update_color_lut(&mut self, size: u32, data: &[u8]) -> Result<(), String> {
let tex = crate::metal::texture::upload_color_lut(&self.allocator, size, data)?;
self.color_lut = tex;
Ok(())
}
pub(crate) fn update_environment_map(&mut self, payload: &[u8]) -> Result<(), String> {
let view = crate::bake::environment_map::deserialise(payload)
.map_err(|e| format!("envmap hot-reload payload malformed: {}", e))?;
let new_env = crate::metal::texture::upload_environment_map(
&self.allocator,
view.irradiance_face,
view.irradiance_bytes,
view.prefilter_face,
&view.prefilter_mip_bytes,
)?;
self.env_map = new_env;
Ok(())
}
}