Skip to content

Commit 8ef4d9d

Browse files
committed
Clean up.
1 parent 1bfa613 commit 8ef4d9d

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

crates/processing_render/src/render/material.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use bevy::{prelude::*, render::alpha::AlphaMode};
22
use std::ops::Deref;
33

4+
/// A component that holds an untyped handle to a material. This allows the main render loop
5+
/// to be agnostic of the specific material types being used, and allows for dynamic material
6+
/// creation based on the `MaterialKey`.
47
#[derive(Component, Deref)]
58
pub struct UntypedMaterial(pub UntypedHandle);
69

@@ -10,6 +13,8 @@ pub enum MaterialSource {
1013
Explicit(Entity),
1114
}
1215

16+
/// Defines the current material for a batch, which can be used to determine when to flush the
17+
/// current batch and start a new one.
1318
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
1419
pub enum MaterialKey {
1520
Color {
@@ -26,20 +31,6 @@ pub enum MaterialKey {
2631
}
2732

2833
impl MaterialKey {
29-
pub fn simple_2d(transparent: bool) -> Self {
30-
Self::Color {
31-
transparent,
32-
background_image: None,
33-
}
34-
}
35-
36-
pub fn with_image(image: Handle<Image>, transparent: bool) -> Self {
37-
Self::Color {
38-
transparent,
39-
background_image: Some(image),
40-
}
41-
}
42-
4334
pub fn to_material(&self, materials: &mut ResMut<Assets<StandardMaterial>>) -> UntypedHandle {
4435
match self {
4536
MaterialKey::Color {
@@ -95,6 +86,8 @@ impl MaterialKey {
9586
}
9687
}
9788

89+
/// A system that adds a `MeshMaterial3d` component to any entity with an `UntypedMaterial` that can
90+
/// be typed as a `StandardMaterial`.
9891
pub fn add_standard_materials(
9992
mut commands: Commands,
10093
meshes: Query<(Entity, &UntypedMaterial)>,

crates/processing_render/src/render/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ pub fn flush_draw_commands(
232232
let mesh = create_ndc_background_quad(world_from_clip, color, false);
233233
let mesh_handle = res.meshes.add(mesh);
234234

235-
let material_key = MaterialKey::simple_2d(color.alpha() < 1.0);
235+
let material_key = MaterialKey::Color {
236+
transparent: color.alpha() < 1.0,
237+
background_image: None,
238+
};
236239
let material_handle = material_key.to_material(&mut res.materials);
237240

238241
res.commands.spawn((
@@ -256,7 +259,10 @@ pub fn flush_draw_commands(
256259
let mesh = create_ndc_background_quad(world_from_clip, Color::WHITE, true);
257260
let mesh_handle = res.meshes.add(mesh);
258261

259-
let material_key = MaterialKey::with_image(p_image.handle.clone(), false);
262+
let material_key = MaterialKey::Color {
263+
transparent: false,
264+
background_image: Some(p_image.handle.clone()),
265+
};
260266
let material_handle = material_key.to_material(&mut res.materials);
261267

262268
res.commands.spawn((

0 commit comments

Comments
 (0)