55//! configured to render to a specific surface (either a window or an offscreen image).
66use bevy:: {
77 camera:: {
8- CameraMainTextureUsages , CameraOutputMode , CameraProjection , ClearColorConfig ,
8+ CameraMainTextureUsages , CameraOutputMode , CameraProjection , ClearColorConfig , Hdr ,
99 ImageRenderTarget , MsaaWriteback , Projection , RenderTarget , visibility:: RenderLayers ,
1010 } ,
1111 core_pipeline:: tonemapping:: Tonemapping ,
1212 ecs:: { entity:: EntityHashMap , query:: QueryEntityError } ,
1313 math:: { Mat4 , Vec3A } ,
1414 prelude:: * ,
1515 render:: {
16- Render , RenderSystems ,
16+ Render ,
1717 render_resource:: {
1818 CommandEncoderDescriptor , Extent3d , MapMode , Origin3d , PollType , TexelCopyBufferInfo ,
1919 TexelCopyBufferLayout , TexelCopyTextureInfo , TextureFormat , TextureUsages ,
2020 } ,
2121 renderer:: { RenderDevice , RenderQueue } ,
2222 sync_world:: MainEntity ,
23- view:: { Hdr , ViewTarget , prepare_view_targets} ,
23+ view:: { ViewTarget , prepare_view_targets} ,
2424 } ,
2525 window:: WindowRef ,
2626} ;
@@ -48,12 +48,7 @@ impl Plugin for GraphicsPlugin {
4848
4949 let render_app = app. sub_app_mut ( bevy:: render:: RenderApp ) ;
5050 render_app
51- . add_systems (
52- Render ,
53- send_view_targets
54- . in_set ( RenderSystems :: ManageViews )
55- . after ( prepare_view_targets) ,
56- )
51+ . add_systems ( Render , send_view_targets. after ( prepare_view_targets) )
5752 . insert_resource ( GraphicsTargetSender ( tx) ) ;
5853 }
5954}
@@ -219,14 +214,14 @@ pub fn create(
219214 . spawn ( (
220215 Camera3d :: default ( ) ,
221216 Camera {
222- target,
223217 // always load the previous frame (provides sketch like behavior)
224218 clear_color : ClearColorConfig :: None ,
225219 // TODO: toggle this conditionally based on whether we need to write back MSAA
226220 // when doing manual pixel udpates
227221 msaa_writeback : MsaaWriteback :: Always ,
228222 ..default ( )
229223 } ,
224+ target,
230225 // default to floating point texture format
231226 Hdr ,
232227 // tonemapping prevents color accurate readback, so we disable it
@@ -293,6 +288,10 @@ pub fn mode_3d(
293288 let near = camera_z / 10.0 ;
294289 let far = camera_z * 10.0 ;
295290
291+ // TODO: Setting this as a default, but we need to think about API around
292+ // a user defined value
293+ let near_clip_plane = vec4 ( 0.0 , 0.0 , -1.0 , -near) ;
294+
296295 let mut projection = projections
297296 . get_mut ( entity)
298297 . map_err ( |_| ProcessingError :: GraphicsNotFound ) ?;
@@ -302,6 +301,7 @@ pub fn mode_3d(
302301 aspect_ratio : aspect,
303302 near,
304303 far,
304+ near_clip_plane,
305305 } ) ;
306306
307307 let mut transform = transforms
@@ -351,6 +351,7 @@ pub fn perspective(
351351 aspect_ratio,
352352 near,
353353 far,
354+ near_clip_plane,
354355 } ,
355356 ) ) : In < ( Entity , PerspectiveProjection ) > ,
356357 mut projections : Query < & mut Projection > ,
@@ -364,6 +365,7 @@ pub fn perspective(
364365 aspect_ratio,
365366 near,
366367 far,
368+ near_clip_plane,
367369 } ) ;
368370
369371 Ok ( ( ) )
@@ -526,7 +528,8 @@ pub fn readback(
526528 } ) ;
527529
528530 render_device
529- . poll ( PollType :: Wait )
531+ // TODO: should this have a timeout?
532+ . poll ( PollType :: wait_indefinitely ( ) )
530533 . expect ( "Failed to poll device for map async" ) ;
531534
532535 r. recv ( ) . expect ( "Failed to receive the map_async message" ) ;
0 commit comments