@@ -36,6 +36,8 @@ use crate::{
3636} ;
3737use processing_core:: error:: { ProcessingError , Result } ;
3838
39+ pub const DEFAULT_CLEAR_COLOR : Color = Color :: srgba_u8 ( 208 , 208 , 208 , 255 ) ;
40+
3941pub struct GraphicsPlugin ;
4042
4143impl Plugin for GraphicsPlugin {
@@ -445,16 +447,6 @@ pub fn begin_draw(In(entity): In<Entity>, mut state_query: Query<&mut RenderStat
445447}
446448
447449pub fn flush ( app : & mut App , entity : Entity ) -> Result < ( ) > {
448- // f there's nothing to render, skip the whole render pass. this avoids some issues on
449- // macos with msaa resolve where nothing is rendered
450- let is_empty = graphics_mut ! ( app, entity)
451- . get :: < CommandBuffer > ( )
452- . map ( |c| c. commands . is_empty ( ) )
453- . unwrap_or ( true ) ;
454- if is_empty {
455- return Ok ( ( ) ) ;
456- }
457-
458450 graphics_mut ! ( app, entity) . insert ( Flush ) ;
459451 app. update ( ) ;
460452 graphics_mut ! ( app, entity) . remove :: < Flush > ( ) ;
@@ -483,6 +475,26 @@ pub fn end_draw(app: &mut App, entity: Entity) -> Result<()> {
483475 present ( app, entity)
484476}
485477
478+ /// Do some work on the GPU to ensure that the render target texture is initialized and can be read
479+ /// from/written to.
480+ ///
481+ /// This is necessary on some platforms (notably macOS) to avoid issues with the first few frames of
482+ /// rendering being corrupted or not appearing at all.
483+ ///
484+ // TODO: why is metal particularly affected by this? can we remove this?
485+ pub fn warmup ( app : & mut App , entity : Entity ) -> Result < ( ) > {
486+ for _ in 0 ..3 {
487+ app. world_mut ( )
488+ . run_system_cached_with (
489+ record_command,
490+ ( entity, DrawCommand :: BackgroundColor ( DEFAULT_CLEAR_COLOR ) ) ,
491+ )
492+ . unwrap ( ) ?;
493+ flush ( app, entity) ?;
494+ }
495+ Ok ( ( ) )
496+ }
497+
486498pub fn record_command (
487499 In ( ( graphics_entity, cmd) ) : In < ( Entity , DrawCommand ) > ,
488500 mut graphics_query : Query < & mut CommandBuffer > ,
0 commit comments