diff --git a/Cargo.toml b/Cargo.toml index 3f4577f..5919779 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,10 +63,6 @@ rand = "0.10.0" [target.'cfg(target_os = "linux")'.dev-dependencies] processing_glfw = { workspace = true, features = ["wayland"] } -[[example]] -name = "test" -path = "examples/test.rs" - [patch."https://github.com/bevyengine/bevy"] bevy = { git = "https://github.com/processing/bevy", branch = "main" } diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index ffbc56c..f885750 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -36,6 +36,8 @@ use crate::{ }; use processing_core::error::{ProcessingError, Result}; +pub const DEFAULT_CLEAR_COLOR: Color = Color::srgba_u8(208, 208, 208, 255); + pub struct GraphicsPlugin; impl Plugin for GraphicsPlugin { @@ -445,16 +447,6 @@ pub fn begin_draw(In(entity): In, mut state_query: Query<&mut RenderStat } pub fn flush(app: &mut App, entity: Entity) -> Result<()> { - // f there's nothing to render, skip the whole render pass. this avoids some issues on - // macos with msaa resolve where nothing is rendered - let is_empty = graphics_mut!(app, entity) - .get::() - .map(|c| c.commands.is_empty()) - .unwrap_or(true); - if is_empty { - return Ok(()); - } - graphics_mut!(app, entity).insert(Flush); app.update(); graphics_mut!(app, entity).remove::(); @@ -483,6 +475,26 @@ pub fn end_draw(app: &mut App, entity: Entity) -> Result<()> { present(app, entity) } +/// Do some work on the GPU to ensure that the render target texture is initialized and can be read +/// from/written to. +/// +/// This is necessary on some platforms (notably macOS) to avoid issues with the first few frames of +/// rendering being corrupted or not appearing at all. +/// +// TODO: why is metal particularly affected by this? can we remove this? +pub fn warmup(app: &mut App, entity: Entity) -> Result<()> { + for _ in 0..3 { + app.world_mut() + .run_system_cached_with( + record_command, + (entity, DrawCommand::BackgroundColor(DEFAULT_CLEAR_COLOR)), + ) + .unwrap()?; + flush(app, entity)?; + } + Ok(()) +} + pub fn record_command( In((graphics_entity, cmd)): In<(Entity, DrawCommand)>, mut graphics_query: Query<&mut CommandBuffer>, diff --git a/crates/processing_render/src/lib.rs b/crates/processing_render/src/lib.rs index 27636dd..8d40662 100644 --- a/crates/processing_render/src/lib.rs +++ b/crates/processing_render/src/lib.rs @@ -254,13 +254,17 @@ pub fn graphics_create( height: u32, texture_format: TextureFormat, ) -> error::Result { - app_mut(|app| { - app.world_mut() + app_mut(|app| -> error::Result { + let entity = app + .world_mut() .run_system_cached_with( graphics::create, (width, height, surface_entity, texture_format), ) - .unwrap() + .unwrap()?; + + graphics::warmup(app, entity)?; + Ok(entity) }) }