mirror of
https://github.com/lisk77/comet.git
synced 2025-12-15 18:18:50 +00:00
refactor(renderer): completely overhauled the comet_renderer crate
This commit is contained in:
parent
fafc7d22a4
commit
1f983fb2ad
7 changed files with 705 additions and 72 deletions
|
|
@ -1,9 +1,10 @@
|
|||
use std::collections::HashMap;
|
||||
use comet_log::error;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
pub struct RenderResources {
|
||||
bind_groups: HashMap<String, Vec<wgpu::BindGroup>>,
|
||||
bind_group_layouts: HashMap<String, Vec<wgpu::BindGroupLayout>>,
|
||||
buffers: HashMap<String, Vec<wgpu::Buffer>>,
|
||||
bind_groups: HashMap<String, Vec<Arc<wgpu::BindGroup>>>,
|
||||
bind_group_layouts: HashMap<String, Vec<Arc<wgpu::BindGroupLayout>>>,
|
||||
buffers: HashMap<String, Vec<Arc<wgpu::Buffer>>>,
|
||||
samplers: HashMap<String, wgpu::Sampler>,
|
||||
}
|
||||
|
||||
|
|
@ -17,11 +18,23 @@ impl RenderResources {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_bindgroups(&self, label: String) -> Option<&Vec<wgpu::BindGroup>> {
|
||||
self.bind_groups.get(&label)
|
||||
pub fn get_bind_groups(&self, label: &str) -> Option<&Vec<Arc<wgpu::BindGroup>>> {
|
||||
self.bind_groups.get(label)
|
||||
}
|
||||
|
||||
pub fn insert_bindgroup(&mut self, label: String, bind_group: wgpu::BindGroup) {
|
||||
pub fn get_bind_group_layout(&self, label: &str) -> Option<&Vec<Arc<wgpu::BindGroupLayout>>> {
|
||||
self.bind_group_layouts.get(label)
|
||||
}
|
||||
|
||||
pub fn get_buffer(&self, label: &str) -> Option<&Vec<Arc<wgpu::Buffer>>> {
|
||||
self.buffers.get(label)
|
||||
}
|
||||
|
||||
pub fn get_sampler(&self, label: &str) -> Option<&wgpu::Sampler> {
|
||||
self.samplers.get(label)
|
||||
}
|
||||
|
||||
pub fn insert_bind_group(&mut self, label: String, bind_group: Arc<wgpu::BindGroup>) {
|
||||
match self.bind_groups.get_mut(&label) {
|
||||
None => {
|
||||
self.bind_groups.insert(label, vec![bind_group]);
|
||||
|
|
@ -30,11 +43,31 @@ impl RenderResources {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn get_bind_group_layout(&self, label: String) -> Option<&Vec<wgpu::BindGroupLayout>> {
|
||||
self.bind_group_layouts.get(&label)
|
||||
pub fn replace_bind_group(
|
||||
&mut self,
|
||||
label: String,
|
||||
pos: usize,
|
||||
bind_group: Arc<wgpu::BindGroup>,
|
||||
) {
|
||||
match self.bind_groups.get_mut(&label) {
|
||||
None => {
|
||||
error!("Render pass {} does not exist", label);
|
||||
return;
|
||||
}
|
||||
Some(v) => {
|
||||
if v.len() <= pos {
|
||||
error!(
|
||||
"Position {} is out of bounds for the bind groups of render pass {}",
|
||||
pos, label
|
||||
);
|
||||
return;
|
||||
}
|
||||
v[pos] = bind_group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_bind_group_layout(&mut self, label: String, layout: wgpu::BindGroupLayout) {
|
||||
pub fn insert_bind_group_layout(&mut self, label: String, layout: Arc<wgpu::BindGroupLayout>) {
|
||||
match self.bind_group_layouts.get_mut(&label) {
|
||||
None => {
|
||||
self.bind_group_layouts.insert(label, vec![layout]);
|
||||
|
|
@ -42,12 +75,7 @@ impl RenderResources {
|
|||
Some(v) => v.push(layout),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_buffer(&self, label: String) -> Option<&Vec<wgpu::Buffer>> {
|
||||
self.buffers.get(&label)
|
||||
}
|
||||
|
||||
pub fn insert_buffer(&mut self, label: String, buffer: wgpu::Buffer) {
|
||||
pub fn insert_buffer(&mut self, label: String, buffer: Arc<wgpu::Buffer>) {
|
||||
match self.buffers.get_mut(&label) {
|
||||
None => {
|
||||
self.buffers.insert(label, vec![buffer]);
|
||||
|
|
@ -56,8 +84,23 @@ impl RenderResources {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_sampler(&self, label: String) -> Option<&wgpu::Sampler> {
|
||||
self.samplers.get(&label)
|
||||
pub fn replace_buffer(&mut self, label: String, pos: usize, buffer: Arc<wgpu::Buffer>) {
|
||||
match self.buffers.get_mut(&label) {
|
||||
None => {
|
||||
error!("Render pass {} does not exist", label);
|
||||
return;
|
||||
}
|
||||
Some(v) => {
|
||||
if v.len() <= pos {
|
||||
error!(
|
||||
"Position {} is out of bounds for the buffers of render pass {}",
|
||||
pos, label
|
||||
);
|
||||
return;
|
||||
}
|
||||
v[pos] = buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_sampler(&mut self, label: String, sampler: wgpu::Sampler) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue