@@ -29,7 +29,7 @@ use crate::{
2929 Flush ,
3030 image:: { Image , create_readback_buffer, pixel_size, pixels_to_bytes} ,
3131 render:: {
32- RenderState ,
32+ BATCH_INDEX_STEP , RenderState ,
3333 command:: { CommandBuffer , DrawCommand } ,
3434 } ,
3535 surface:: Surface ,
@@ -112,19 +112,18 @@ pub struct SurfaceSize(pub u32, pub u32);
112112/// Custom orthographic projection for Processing's coordinate system.
113113/// Origin at top-left, Y-axis down, in pixel units (aka screen space).
114114#[ derive( Debug , Clone , Reflect ) ]
115- #[ reflect( Default ) ]
116115pub struct ProcessingProjection {
117116 pub width : f32 ,
118117 pub height : f32 ,
119118 pub near : f32 ,
120119 pub far : f32 ,
121120}
122121
123- impl Default for ProcessingProjection {
124- fn default ( ) -> Self {
122+ impl ProcessingProjection {
123+ pub fn new ( width : f32 , height : f32 ) -> Self {
125124 Self {
126- width : 1.0 ,
127- height : 1.0 ,
125+ width,
126+ height,
128127 near : 0.0 ,
129128 far : 1000.0 ,
130129 }
@@ -234,14 +233,9 @@ pub fn create(
234233 Tonemapping :: None ,
235234 // we need to be able to write to the texture
236235 CameraMainTextureUsages :: default ( ) . with ( TextureUsages :: COPY_DST ) ,
237- Projection :: custom ( ProcessingProjection {
238- width : width as f32 ,
239- height : height as f32 ,
240- near : 0.0 ,
241- far : 1000.0 ,
242- } ) ,
236+ Projection :: custom ( ProcessingProjection :: new ( width as f32 , height as f32 ) ) ,
243237 Msaa :: Off ,
244- Transform :: from_xyz ( 0.0 , 0.0 , 999.9 ) ,
238+ Transform :: from_xyz ( 0.0 , 0.0 , BATCH_INDEX_STEP ) ,
245239 render_layer,
246240 CommandBuffer :: new ( ) ,
247241 RenderState :: default ( ) ,
@@ -340,18 +334,13 @@ pub fn mode_2d(
340334 . get_mut ( entity)
341335 . map_err ( |_| ProcessingError :: GraphicsNotFound ) ?;
342336
343- * projection = Projection :: custom ( ProcessingProjection {
344- width : * width as f32 ,
345- height : * height as f32 ,
346- near : 0.0 ,
347- far : 1000.0 ,
348- } ) ;
337+ * projection = Projection :: custom ( ProcessingProjection :: new ( * width as f32 , * height as f32 ) ) ;
349338
350339 let mut transform = transforms
351340 . get_mut ( entity)
352341 . map_err ( |_| ProcessingError :: GraphicsNotFound ) ?;
353342
354- * transform = Transform :: from_xyz ( 0.0 , 0.0 , 999.9 ) ;
343+ * transform = Transform :: from_xyz ( 0.0 , 0.0 , BATCH_INDEX_STEP ) ;
355344
356345 Ok ( ( ) )
357346}
0 commit comments