From d7780c42b0d19117f5dcc26d9ed8eb6b69529021 Mon Sep 17 00:00:00 2001 From: charlotte Date: Sun, 22 Mar 2026 19:35:59 -0700 Subject: [PATCH] Fix projection transform that was leading to ~100 max draws. --- crates/processing_render/src/graphics.rs | 29 +++++++--------------- crates/processing_render/src/render/mod.rs | 8 +++--- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index 2dda6ee..48567b1 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -29,7 +29,7 @@ use crate::{ Flush, image::{Image, create_readback_buffer, pixel_size, pixels_to_bytes}, render::{ - RenderState, + BATCH_INDEX_STEP, RenderState, command::{CommandBuffer, DrawCommand}, }, surface::Surface, @@ -112,7 +112,6 @@ pub struct SurfaceSize(pub u32, pub u32); /// Custom orthographic projection for Processing's coordinate system. /// Origin at top-left, Y-axis down, in pixel units (aka screen space). #[derive(Debug, Clone, Reflect)] -#[reflect(Default)] pub struct ProcessingProjection { pub width: f32, pub height: f32, @@ -120,11 +119,11 @@ pub struct ProcessingProjection { pub far: f32, } -impl Default for ProcessingProjection { - fn default() -> Self { +impl ProcessingProjection { + pub fn new(width: f32, height: f32) -> Self { Self { - width: 1.0, - height: 1.0, + width, + height, near: 0.0, far: 1000.0, } @@ -234,14 +233,9 @@ pub fn create( Tonemapping::None, // we need to be able to write to the texture CameraMainTextureUsages::default().with(TextureUsages::COPY_DST), - Projection::custom(ProcessingProjection { - width: width as f32, - height: height as f32, - near: 0.0, - far: 1000.0, - }), + Projection::custom(ProcessingProjection::new(width as f32, height as f32)), Msaa::Off, - Transform::from_xyz(0.0, 0.0, 999.9), + Transform::from_xyz(0.0, 0.0, BATCH_INDEX_STEP), render_layer, CommandBuffer::new(), RenderState::default(), @@ -340,18 +334,13 @@ pub fn mode_2d( .get_mut(entity) .map_err(|_| ProcessingError::GraphicsNotFound)?; - *projection = Projection::custom(ProcessingProjection { - width: *width as f32, - height: *height as f32, - near: 0.0, - far: 1000.0, - }); + *projection = Projection::custom(ProcessingProjection::new(*width as f32, *height as f32)); let mut transform = transforms .get_mut(entity) .map_err(|_| ProcessingError::GraphicsNotFound)?; - *transform = Transform::from_xyz(0.0, 0.0, 999.9); + *transform = Transform::from_xyz(0.0, 0.0, BATCH_INDEX_STEP); Ok(()) } diff --git a/crates/processing_render/src/render/mod.rs b/crates/processing_render/src/render/mod.rs index fe10a0b..8f41965 100644 --- a/crates/processing_render/src/render/mod.rs +++ b/crates/processing_render/src/render/mod.rs @@ -23,6 +23,8 @@ use crate::{ render::{material::UntypedMaterial, primitive::rect}, }; +pub(crate) const BATCH_INDEX_STEP: f32 = 0.001; + #[derive(Component)] #[relationship(relationship_target = TransientMeshes)] pub struct BelongsToGraphics(pub Entity); @@ -350,7 +352,7 @@ pub fn flush_draw_commands( flush_batch(&mut res, &mut batch, &p_material_handles); - let z_offset = -(batch.draw_index as f32 * 0.001); + let z_offset = -(batch.draw_index as f32 * BATCH_INDEX_STEP); let mut transform = state.transform.to_bevy_transform(); // if the "source" geometry was parented in a gltf scene, we need to make sure that @@ -565,7 +567,7 @@ fn flush_batch( material_handles: &Query<&UntypedMaterial>, ) { if let Some(mesh) = batch.current_mesh.take() { - let z_offset = -(batch.draw_index as f32 * 0.001); + let z_offset = -(batch.draw_index as f32 * BATCH_INDEX_STEP); spawn_mesh(res, batch, mesh, z_offset, material_handles); batch.draw_index += 1; } @@ -616,7 +618,7 @@ fn add_shape3d( } }; - let z_offset = -(batch.draw_index as f32 * 0.001); + let z_offset = -(batch.draw_index as f32 * BATCH_INDEX_STEP); let mut transform = state.transform.to_bevy_transform(); transform.translation.z += z_offset;