Remvoe old cache implementations
This commit is contained in:
parent
f4900dd919
commit
d64d4d881a
|
|
@ -3,9 +3,6 @@ mod gui_rect;
|
||||||
mod pipeline;
|
mod pipeline;
|
||||||
mod texture;
|
mod texture;
|
||||||
mod color_palette;
|
mod color_palette;
|
||||||
mod shader_cache;
|
|
||||||
mod pipeline_cache;
|
|
||||||
mod texture_cache;
|
|
||||||
mod resource_cache;
|
mod resource_cache;
|
||||||
mod shader_stage;
|
mod shader_stage;
|
||||||
mod draw_command;
|
mod draw_command;
|
||||||
|
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
use super::pipeline::Pipeline;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
||||||
struct CacheID {
|
|
||||||
index: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CacheID {
|
|
||||||
fn new(index: usize) -> Self {
|
|
||||||
Self { index }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PipelineCache {
|
|
||||||
pub pipelines: Vec<Pipeline>,
|
|
||||||
name_to_id: HashMap<String, CacheID>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PipelineCache {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let pipelines = Vec::new();
|
|
||||||
let name_to_id = HashMap::new();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
pipelines,
|
|
||||||
name_to_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get(&self, name: &str) -> Option<&Pipeline> {
|
|
||||||
match self.name_to_id.get(name) {
|
|
||||||
Some(id) => self.pipelines.get(id.index),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn set(&mut self, name: &str, pipeline: Pipeline) {
|
|
||||||
match self.name_to_id.get(name) {
|
|
||||||
Some(id) => {
|
|
||||||
self.pipelines[id.index] = pipeline;
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
let last_index = self.name_to_id.len();
|
|
||||||
let id = CacheID::new(last_index);
|
|
||||||
self.name_to_id.insert(String::from(name), id);
|
|
||||||
self.pipelines.push(pipeline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn load(&mut self, device: &wgpu::Device, name: &str, vertex_shader: &wgpu::ShaderModule, fragment_shader: &wgpu::ShaderModule) {
|
|
||||||
let pipeline = Pipeline::new(device, vertex_shader, fragment_shader);
|
|
||||||
self.set(name, pipeline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
||||||
struct CacheID {
|
|
||||||
index: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CacheID {
|
|
||||||
fn new(index: usize) -> Self {
|
|
||||||
Self { index }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ShaderCache {
|
|
||||||
pub shaders: Vec<wgpu::ShaderModule>,
|
|
||||||
name_to_id: HashMap<String, CacheID>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ShaderCache {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let shaders = Vec::new();
|
|
||||||
let name_to_id = HashMap::new();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
shaders,
|
|
||||||
name_to_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get(&self, name: &str) -> Option<&wgpu::ShaderModule> {
|
|
||||||
match self.name_to_id.get(name) {
|
|
||||||
Some(id) => self.shaders.get(id.index),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn set(&mut self, name: &str, shader: wgpu::ShaderModule) {
|
|
||||||
match self.name_to_id.get(name) {
|
|
||||||
Some(id) => {
|
|
||||||
self.shaders[id.index] = shader;
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
let last_index = self.name_to_id.len();
|
|
||||||
let id = CacheID::new(last_index);
|
|
||||||
self.name_to_id.insert(String::from(name), id);
|
|
||||||
self.shaders.push(shader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn load(&mut self, device: &wgpu::Device, path: &str, shader_type: glsl_to_spirv::ShaderType) -> std::io::Result<()> {
|
|
||||||
if self.name_to_id.get(path).is_none() {
|
|
||||||
let source = std::fs::read_to_string(path)?;
|
|
||||||
let spirv = match glsl_to_spirv::compile(&source[..], shader_type) {
|
|
||||||
Ok(spirv_output) => spirv_output,
|
|
||||||
Err(message) => {
|
|
||||||
println!("Error compiling GLSL to SPIRV shader: {}", message);
|
|
||||||
panic!("{}", message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let compiled = wgpu::read_spirv(spirv)?;
|
|
||||||
let shader = device.create_shader_module(&compiled);
|
|
||||||
|
|
||||||
let last_index = self.name_to_id.len();
|
|
||||||
self.name_to_id.insert(String::from(path), CacheID::new(last_index));
|
|
||||||
self.shaders.push(shader);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
use super::texture::Texture;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
||||||
struct CacheID {
|
|
||||||
index: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CacheID {
|
|
||||||
fn new(index: usize) -> Self {
|
|
||||||
Self { index }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TextureCache {
|
|
||||||
pub textures: Vec<Texture>,
|
|
||||||
name_to_id: HashMap<String, CacheID>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TextureCache {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let textures = Vec::new();
|
|
||||||
let name_to_id = HashMap::new();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
textures,
|
|
||||||
name_to_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get(&self, name: &str) -> Option<&Texture> {
|
|
||||||
match self.name_to_id.get(name) {
|
|
||||||
Some(id) => self.textures.get(id.index),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn set(&mut self, name: &str, texture: Texture) {
|
|
||||||
match self.name_to_id.get(name) {
|
|
||||||
Some(id) => {
|
|
||||||
self.textures[id.index] = texture;
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
let last_index = self.name_to_id.len();
|
|
||||||
let id = CacheID::new(last_index);
|
|
||||||
self.name_to_id.insert(String::from(name), id);
|
|
||||||
self.textures.push(texture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn load(&mut self, device: &wgpu::Device, queue: &mut wgpu::Queue, path: &str) -> std::io::Result<()> {
|
|
||||||
if self.name_to_id.get(path).is_none() {
|
|
||||||
let texture = Texture::from_filepath(device, queue, "textures/grid.png").unwrap();
|
|
||||||
|
|
||||||
let length = self.name_to_id.len();
|
|
||||||
self.name_to_id.insert(String::from(path), CacheID::new(length));
|
|
||||||
self.textures.push(texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue