@@ -11,15 +11,14 @@ use bevy::{
1111 prelude:: * ,
1212} ;
1313use command:: { CommandBuffer , DrawCommand } ;
14- use material:: { MaterialKey , MaterialSource } ;
14+ use material:: MaterialKey ;
1515use primitive:: { TessellationMode , empty_mesh} ;
1616use transform:: TransformStack ;
1717
1818use 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
4140struct 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
342340fn 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
377371fn 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