79 lines
1.9 KiB
Rust
79 lines
1.9 KiB
Rust
use std::{path::PathBuf, sync::Arc};
|
|
|
|
use anyhow::Result;
|
|
use context::prelude::*;
|
|
use ecs::*;
|
|
|
|
pub struct SkyBoxImages {
|
|
left: PathBuf,
|
|
right: PathBuf,
|
|
front: PathBuf,
|
|
back: PathBuf,
|
|
top: PathBuf,
|
|
bottom: PathBuf,
|
|
}
|
|
|
|
impl<T: ExactSizeIterator<Item = PathBuf>> From<T> for SkyBoxImages {
|
|
fn from(mut paths: T) -> Self {
|
|
debug_assert_eq!(paths.len(), 6);
|
|
|
|
Self {
|
|
left: paths.next().unwrap(),
|
|
right: paths.next().unwrap(),
|
|
front: paths.next().unwrap(),
|
|
back: paths.next().unwrap(),
|
|
top: paths.next().unwrap(),
|
|
bottom: paths.next().unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct SkyBox {
|
|
cube_map: Arc<Image>,
|
|
}
|
|
|
|
impl SkyBox {
|
|
pub fn new(world: &mut WorldBuilder, images: impl Into<SkyBoxImages>) -> Result<()> {
|
|
let images = images.into();
|
|
let context = world.resources.get_mut::<Context>();
|
|
context.render_core_mut().add_render_routine::<Self>(1);
|
|
|
|
let cube_map = Image::cube_map([
|
|
images.left.try_into()?,
|
|
images.right.try_into()?,
|
|
images.front.try_into()?,
|
|
images.back.try_into()?,
|
|
images.top.try_into()?,
|
|
images.bottom.try_into()?,
|
|
])?
|
|
.max_mip_map_levels()
|
|
.attach_pretty_sampler(context.device())?
|
|
.build(context.device(), context.queue())?;
|
|
|
|
let me = Self { cube_map };
|
|
world.resources.insert(me);
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl TScene for SkyBox {
|
|
fn process(
|
|
&mut self,
|
|
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
|
images: &TargetMode<Vec<Arc<Image>>>,
|
|
indices: &TargetMode<usize>,
|
|
world: &World,
|
|
) -> Result<()> {
|
|
todo!()
|
|
}
|
|
|
|
fn resize(
|
|
&mut self,
|
|
window_width: f32,
|
|
window_height: f32,
|
|
images: &TargetMode<Vec<Arc<Image>>>,
|
|
) -> Result<()> {
|
|
todo!()
|
|
}
|
|
}
|