55 lines
1.3 KiB
Rust
55 lines
1.3 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<Self> {
|
||
|
let images = images.into();
|
||
|
let context = world.resources.get::<Context>();
|
||
|
|
||
|
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())?;
|
||
|
|
||
|
Ok(Self { cube_map })
|
||
|
}
|
||
|
}
|