Refactor to generalize pipeline drawing sequence

This commit is contained in:
Keavon Chambers
2020-05-23 12:36:47 -07:00
parent 9a60ba54fe
commit a9859b4bb4
18 changed files with 628 additions and 337 deletions
+10
View File
@@ -1,5 +1,6 @@
use std::fs;
use image::GenericImageView;
use crate::resource_cache::ResourceCache;
pub struct Texture {
pub texture: wgpu::Texture,
@@ -8,6 +9,15 @@ pub struct Texture {
}
impl Texture {
pub fn cached_load<'a>(device: &wgpu::Device, queue: &mut wgpu::Queue, path: &str, texture_cache: &'a mut ResourceCache<Texture>) -> &'a Texture {
// If uncached, construct a texture loaded from the image file
if texture_cache.get(path).is_none() {
let texture = Texture::from_filepath(device, queue, path).unwrap();
texture_cache.set(path, texture);
}
texture_cache.get(path).unwrap()
}
pub fn from_filepath(device: &wgpu::Device, queue: &mut wgpu::Queue, path: &str) -> Result<Self, failure::Error> {
// Read the raw bytes from the specified file
let bytes = fs::read(path)?;