@@ -4,7 +4,9 @@ pub mod mesh_builder;
44pub mod primitive;
55pub mod transform;
66
7- use bevy:: { camera:: visibility:: RenderLayers , ecs:: system:: SystemParam , math:: Affine3A , prelude:: * } ;
7+ use bevy:: {
8+ camera:: visibility:: RenderLayers , ecs:: system:: SystemParam , math:: Affine3A , prelude:: * ,
9+ } ;
810use command:: { CommandBuffer , DrawCommand } ;
911use material:: MaterialKey ;
1012use primitive:: { TessellationMode , empty_mesh} ;
@@ -261,20 +263,18 @@ fn spawn_mesh(ctx: &mut RenderContext, mesh: Mesh, z_offset: f32) {
261263 ) ) ;
262264}
263265
264- fn maybe_start_batch ( ctx : & mut RenderContext , material_key : MaterialKey ) -> bool {
266+ fn needs_batch ( ctx : & RenderContext , material_key : & MaterialKey ) -> bool {
265267 let current_transform = ctx. state . transform . current ( ) ;
266- let material_changed = ctx. batch . material_key . as_ref ( ) != Some ( & material_key) ;
268+ let material_changed = ctx. batch . material_key . as_ref ( ) != Some ( material_key) ;
267269 let transform_changed = ctx. batch . transform != current_transform;
270+ material_changed || transform_changed
271+ }
268272
269- if material_changed || transform_changed {
270- flush_batch ( ctx) ;
271- ctx. batch . material_key = Some ( material_key) ;
272- ctx. batch . transform = current_transform;
273- ctx. batch . current_mesh = Some ( empty_mesh ( ) ) ;
274- true
275- } else {
276- false
277- }
273+ fn start_batch ( ctx : & mut RenderContext , material_key : MaterialKey ) {
274+ flush_batch ( ctx) ;
275+ ctx. batch . material_key = Some ( material_key) ;
276+ ctx. batch . transform = ctx. state . transform . current ( ) ;
277+ ctx. batch . current_mesh = Some ( empty_mesh ( ) ) ;
278278}
279279
280280fn add_fill ( ctx : & mut RenderContext , tessellate : impl FnOnce ( & mut Mesh , Color ) ) {
@@ -286,9 +286,10 @@ fn add_fill(ctx: &mut RenderContext, tessellate: impl FnOnce(&mut Mesh, Color))
286286 background_image : None ,
287287 } ;
288288
289- maybe_start_batch ( ctx, material_key) ;
289+ if needs_batch ( ctx, & material_key) {
290+ start_batch ( ctx, material_key) ;
291+ }
290292
291- // accumulate geometry into the current mega mesh
292293 if let Some ( ref mut mesh) = ctx. batch . current_mesh {
293294 tessellate ( mesh, color) ;
294295 }
@@ -304,9 +305,10 @@ fn add_stroke(ctx: &mut RenderContext, tessellate: impl FnOnce(&mut Mesh, Color,
304305 background_image : None ,
305306 } ;
306307
307- maybe_start_batch ( ctx, material_key) ;
308+ if needs_batch ( ctx, & material_key) {
309+ start_batch ( ctx, material_key) ;
310+ }
308311
309- // accumulate geometry into the current mega mesh
310312 if let Some ( ref mut mesh) = ctx. batch . current_mesh {
311313 tessellate ( mesh, color, stroke_weight) ;
312314 }
0 commit comments