Skip to content

Commit 844d534

Browse files
committed
Remove material source vestige
1 parent 8ef4d9d commit 844d534

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

crates/processing_pyo3/examples/materials.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ def setup():
77
size(800, 600)
88
mode_3d()
99

10-
# Add lighting
1110
dir_light = create_directional_light(1.0, 0.98, 0.95, 1500.0)
1211
point_light = create_point_light(1.0, 1.0, 1.0, 100000.0, 800.0, 0.0)
1312
point_light.position(200.0, 200.0, 400.0)
1413

15-
# Create a PBR material
1614
mat = Material()
1715
mat.set_float("roughness", 0.3)
1816
mat.set_float("metallic", 0.8)

crates/processing_render/src/render/material.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ use std::ops::Deref;
77
#[derive(Component, Deref)]
88
pub struct UntypedMaterial(pub UntypedHandle);
99

10-
#[derive(Clone, PartialEq, Debug)]
11-
pub enum MaterialSource {
12-
Immediate(MaterialKey),
13-
Explicit(Entity),
14-
}
15-
1610
/// Defines the current material for a batch, which can be used to determine when to flush the
1711
/// current batch and start a new one.
1812
#[derive(Clone, PartialEq, Eq, Hash, Debug)]

crates/processing_render/src/render/mod.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ use bevy::{
1111
prelude::*,
1212
};
1313
use command::{CommandBuffer, DrawCommand};
14-
use material::{MaterialKey, MaterialSource};
14+
use material::MaterialKey;
1515
use primitive::{TessellationMode, empty_mesh};
1616
use transform::TransformStack;
1717

1818
use crate::{
1919
Flush,
2020
geometry::Geometry,
2121
image::Image,
22-
material::DefaultMaterial,
2322
render::{material::UntypedMaterial, primitive::rect},
2423
};
2524

@@ -40,7 +39,7 @@ pub struct RenderResources<'w, 's> {
4039

4140
struct BatchState {
4241
current_mesh: Option<Mesh>,
43-
material_source: Option<MaterialSource>,
42+
material_key: Option<MaterialKey>,
4443
active_material: Entity,
4544
transform: Affine3A,
4645
draw_index: u32,
@@ -52,7 +51,7 @@ impl BatchState {
5251
fn new(graphics_entity: Entity, render_layers: RenderLayers, active_material: Entity) -> Self {
5352
Self {
5453
current_mesh: None,
55-
material_source: None,
54+
material_key: None,
5655
active_material,
5756
transform: Affine3A::IDENTITY,
5857
draw_index: 0,
@@ -124,7 +123,6 @@ pub fn flush_draw_commands(
124123
p_images: Query<&Image>,
125124
p_geometries: Query<&Geometry>,
126125
p_material_handles: Query<&UntypedMaterial>,
127-
#[allow(unused)] default_material: Res<DefaultMaterial>,
128126
) {
129127
for (
130128
graphics_entity,
@@ -340,7 +338,7 @@ pub fn clear_transient_meshes(
340338
}
341339

342340
fn spawn_mesh(res: &mut RenderResources, batch: &mut BatchState, mesh: Mesh, z_offset: f32) {
343-
let Some(material_source) = &batch.material_source else {
341+
let Some(key) = &batch.material_key else {
344342
return;
345343
};
346344

@@ -353,10 +351,7 @@ fn spawn_mesh(res: &mut RenderResources, batch: &mut BatchState, mesh: Mesh, z_o
353351
scale,
354352
};
355353

356-
let material_handle = match material_source {
357-
MaterialSource::Immediate(key) => key.to_material(&mut res.materials),
358-
MaterialSource::Explicit(_) => return,
359-
};
354+
let material_handle = key.to_material(&mut res.materials);
360355

361356
res.commands.spawn((
362357
Mesh3d(mesh_handle),
@@ -367,21 +362,20 @@ fn spawn_mesh(res: &mut RenderResources, batch: &mut BatchState, mesh: Mesh, z_o
367362
));
368363
}
369364

370-
fn needs_new_batch(batch: &BatchState, state: &RenderState, new_source: &MaterialSource) -> bool {
371-
let current_transform = state.transform.current();
372-
let material_changed = batch.material_source.as_ref() != Some(new_source);
373-
let transform_changed = batch.transform != current_transform;
365+
fn needs_batch(batch: &BatchState, state: &RenderState, material_key: &MaterialKey) -> bool {
366+
let material_changed = batch.material_key.as_ref() != Some(material_key);
367+
let transform_changed = batch.transform != state.transform.current();
374368
material_changed || transform_changed
375369
}
376370

377371
fn start_batch(
378372
res: &mut RenderResources,
379373
batch: &mut BatchState,
380374
state: &RenderState,
381-
material_source: MaterialSource,
375+
material_key: MaterialKey,
382376
) {
383377
flush_batch(res, batch);
384-
batch.material_source = Some(material_source);
378+
batch.material_key = Some(material_key);
385379
batch.transform = state.transform.current();
386380
batch.current_mesh = Some(empty_mesh());
387381
}
@@ -415,10 +409,9 @@ fn add_fill(
415409
return;
416410
};
417411
let material_key = material_key_with_color(&state.material_key, color);
418-
let material_source = MaterialSource::Immediate(material_key);
419412

420-
if needs_new_batch(batch, state, &material_source) {
421-
start_batch(res, batch, state, material_source);
413+
if needs_batch(batch, state, &material_key) {
414+
start_batch(res, batch, state, material_key);
422415
}
423416

424417
if let Some(ref mut mesh) = batch.current_mesh {
@@ -437,10 +430,9 @@ fn add_stroke(
437430
};
438431
let stroke_weight = state.stroke_weight;
439432
let material_key = material_key_with_color(&state.material_key, color);
440-
let material_source = MaterialSource::Immediate(material_key);
441433

442-
if needs_new_batch(batch, state, &material_source) {
443-
start_batch(res, batch, state, material_source);
434+
if needs_batch(batch, state, &material_key) {
435+
start_batch(res, batch, state, material_key);
444436
}
445437

446438
if let Some(ref mut mesh) = batch.current_mesh {
@@ -454,7 +446,7 @@ fn flush_batch(res: &mut RenderResources, batch: &mut BatchState) {
454446
spawn_mesh(res, batch, mesh, z_offset);
455447
batch.draw_index += 1;
456448
}
457-
batch.material_source = None;
449+
batch.material_key = None;
458450
}
459451

460452
/// Creates a fullscreen quad by transforming NDC fullscreen by inverse of the clip-from-world matrix

0 commit comments

Comments
 (0)