Skip to content

Commit

Permalink
Add clear color option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciubix8513 committed Jul 25, 2024
1 parent c6cd4ca commit e41691d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
10 changes: 10 additions & 0 deletions examples/blahaj/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ impl Component for Spiny {
fn init(state: &mut MyState) {
log::info!("Initializing scene");

state.extension = Base::new_with_color(
0,
wgpu::Color {
r: 0.96,
g: 0.65,
b: 0.72,
a: 1.0,
},
);

state.frame = 0;
let mesh = state
.assset_store
Expand Down
36 changes: 29 additions & 7 deletions src/rendering/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ impl std::cmp::Ord for dyn RenderingExtension {
///}
///```
pub struct Base {
priority: u32,
///Priority of the extension
pub priority: u32,
///Clear color used for rendering
pub clear_color: wgpu::Color,
//Stores vector of (mesh_id, material_id) for caching
identifier: Vec<(u128, u128)>,
v_buffers: Vec<wgpu::Buffer>,
Expand All @@ -96,6 +99,30 @@ impl Base {
pub const fn new(order: u32) -> Self {
Self {
priority: order,
clear_color: wgpu::Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
},
identifier: Vec::new(),
v_buffers: Vec::new(),
mesh_materials: Vec::new(),
num_instances: Vec::new(),
mesh_refs: Vec::new(),
}
}

///Creates a new [`Base`] with a pre defined clear color
///
///The clear color is the color that is used as a background
///
///Everything rendered with this extension will have that color in the parts not occupied by a mesh.
#[must_use]
pub fn new_with_color(order: u32, color: wgpu::Color) -> Self {
Self {
priority: order,
clear_color: color,
identifier: Vec::new(),
v_buffers: Vec::new(),
mesh_materials: Vec::new(),
Expand Down Expand Up @@ -360,12 +387,7 @@ impl RenderingExtension for Base {
view: &attachments.color,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
}),
load: wgpu::LoadOp::Clear(self.clear_color),
store: wgpu::StoreOp::Store,
},
})],
Expand Down

0 comments on commit e41691d

Please sign in to comment.