From 5d9f949d5a6b6e178d4519e45a5d640df3cf8f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moon=20Dav=C3=A9?= Date: Sun, 15 Feb 2026 23:08:45 -0500 Subject: [PATCH] Generic CommandBuffer, and processing_utils crate --- Cargo.lock | 8 +++++++ Cargo.toml | 1 + crates/processing_render/Cargo.toml | 1 + crates/processing_render/src/graphics.rs | 11 +++++----- .../processing_render/src/render/command.rs | 21 ------------------ crates/processing_render/src/render/mod.rs | 6 +++-- crates/processing_utils/Cargo.toml | 10 +++++++++ crates/processing_utils/src/lib.rs | 22 +++++++++++++++++++ 8 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 crates/processing_utils/Cargo.toml create mode 100644 crates/processing_utils/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 5e14b7b..816e13e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4432,6 +4432,7 @@ dependencies = [ "lyon", "objc2 0.6.3", "objc2-app-kit 0.3.2", + "processing_utils", "raw-window-handle", "thiserror 2.0.17", "tracing", @@ -4442,6 +4443,13 @@ dependencies = [ "windows 0.58.0", ] +[[package]] +name = "processing_utils" +version = "0.1.0" +dependencies = [ + "bevy", +] + [[package]] name = "processing_wasm" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e63a2d8..2574439 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ bevy = { git = "https://github.com/bevyengine/bevy", branch = "main" } processing = { path = "." } processing_pyo3 = { path = "crates/processing_pyo3" } processing_render = { path = "crates/processing_render" } +processing_utils = { path = "crates/processing_utils" } [dependencies] bevy = { workspace = true } diff --git a/crates/processing_render/Cargo.toml b/crates/processing_render/Cargo.toml index 91c34d8..7c62997 100644 --- a/crates/processing_render/Cargo.toml +++ b/crates/processing_render/Cargo.toml @@ -13,6 +13,7 @@ x11 = ["bevy/x11"] [dependencies] bevy = { workspace = true } +processing_utils = { workspace = true } lyon = "1.0" raw-window-handle = "0.6" thiserror = "2" diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index b6b5b80..adaf52d 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -29,13 +29,12 @@ use crate::{ Flush, error::{ProcessingError, Result}, image::{Image, bytes_to_pixels, create_readback_buffer, pixel_size, pixels_to_bytes}, - render::{ - RenderState, - command::{CommandBuffer, DrawCommand}, - }, + render::{RenderState, command::DrawCommand}, surface::Surface, }; +use processing_utils::CommandBuffer; + pub struct GraphicsPlugin; impl Plugin for GraphicsPlugin { @@ -242,7 +241,7 @@ pub fn create( }), Transform::from_xyz(0.0, 0.0, 999.9), render_layer, - CommandBuffer::new(), + CommandBuffer::::new(), RenderState::default(), SurfaceSize(width, height), Graphics { @@ -465,7 +464,7 @@ pub fn end_draw(app: &mut App, entity: Entity) -> Result<()> { pub fn record_command( In((graphics_entity, cmd)): In<(Entity, DrawCommand)>, - mut graphics_query: Query<&mut CommandBuffer>, + mut graphics_query: Query<&mut CommandBuffer>, ) -> Result<()> { let mut command_buffer = graphics_query .get_mut(graphics_entity) diff --git a/crates/processing_render/src/render/command.rs b/crates/processing_render/src/render/command.rs index f800a23..3591aa7 100644 --- a/crates/processing_render/src/render/command.rs +++ b/crates/processing_render/src/render/command.rs @@ -38,24 +38,3 @@ pub enum DrawCommand { }, Geometry(Entity), } - -#[derive(Debug, Default, Component)] -pub struct CommandBuffer { - pub commands: Vec, -} - -impl CommandBuffer { - pub fn new() -> Self { - Self { - commands: Vec::new(), - } - } - - pub fn push(&mut self, cmd: DrawCommand) { - self.commands.push(cmd); - } - - pub fn clear(&mut self) { - self.commands.clear(); - } -} diff --git a/crates/processing_render/src/render/mod.rs b/crates/processing_render/src/render/mod.rs index e19188c..6072e6a 100644 --- a/crates/processing_render/src/render/mod.rs +++ b/crates/processing_render/src/render/mod.rs @@ -10,7 +10,7 @@ use bevy::{ math::{Affine3A, Mat4, Vec4}, prelude::*, }; -use command::{CommandBuffer, DrawCommand}; +use command::DrawCommand; use material::MaterialKey; use primitive::{TessellationMode, empty_mesh}; use transform::TransformStack; @@ -18,6 +18,8 @@ use transform::TransformStack; use crate::render::material::UntypedMaterial; use crate::{Flush, geometry::Geometry, image::Image, render::primitive::rect}; +use processing_utils::CommandBuffer; + #[derive(Component)] #[relationship(relationship_target = TransientMeshes)] pub struct BelongsToGraphics(pub Entity); @@ -93,7 +95,7 @@ pub fn flush_draw_commands( mut graphics: Query< ( Entity, - &mut CommandBuffer, + &mut CommandBuffer, &mut RenderState, &RenderLayers, &Projection, diff --git a/crates/processing_utils/Cargo.toml b/crates/processing_utils/Cargo.toml new file mode 100644 index 0000000..e2199e2 --- /dev/null +++ b/crates/processing_utils/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "processing_utils" +version = "0.1.0" +edition = "2024" + +[dependencies] +bevy = { workspace = true } + +[lints] +workspace = true diff --git a/crates/processing_utils/src/lib.rs b/crates/processing_utils/src/lib.rs new file mode 100644 index 0000000..759ebbd --- /dev/null +++ b/crates/processing_utils/src/lib.rs @@ -0,0 +1,22 @@ +use bevy::prelude::*; + +#[derive(Debug, Default, Component)] +pub struct CommandBuffer { + pub commands: Vec, +} + +impl CommandBuffer { + pub fn new() -> Self { + Self { + commands: Vec::new(), + } + } + + pub fn push(&mut self, cmd: T) { + self.commands.push(cmd); + } + + pub fn clear(&mut self) { + self.commands.clear(); + } +}