Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
32 changes: 22 additions & 10 deletions crates/processing_render/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -445,16 +447,6 @@ pub fn begin_draw(In(entity): In<Entity>, 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::<CommandBuffer>()
.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::<Flush>();
Expand Down Expand Up @@ -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>,
Expand Down
10 changes: 7 additions & 3 deletions crates/processing_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,17 @@ pub fn graphics_create(
height: u32,
texture_format: TextureFormat,
) -> error::Result<Entity> {
app_mut(|app| {
app.world_mut()
app_mut(|app| -> error::Result<Entity> {
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)
})
}

Expand Down
Loading