Skip to content

Commit 5d9f949

Browse files
committed
Generic CommandBuffer<T>, and processing_utils crate
1 parent f411d2d commit 5d9f949

File tree

8 files changed

+51
-29
lines changed

8 files changed

+51
-29
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ bevy = { git = "https://github.com/bevyengine/bevy", branch = "main" }
2525
processing = { path = "." }
2626
processing_pyo3 = { path = "crates/processing_pyo3" }
2727
processing_render = { path = "crates/processing_render" }
28+
processing_utils = { path = "crates/processing_utils" }
2829

2930
[dependencies]
3031
bevy = { workspace = true }

crates/processing_render/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ x11 = ["bevy/x11"]
1313

1414
[dependencies]
1515
bevy = { workspace = true }
16+
processing_utils = { workspace = true }
1617
lyon = "1.0"
1718
raw-window-handle = "0.6"
1819
thiserror = "2"

crates/processing_render/src/graphics.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ use crate::{
2929
Flush,
3030
error::{ProcessingError, Result},
3131
image::{Image, bytes_to_pixels, create_readback_buffer, pixel_size, pixels_to_bytes},
32-
render::{
33-
RenderState,
34-
command::{CommandBuffer, DrawCommand},
35-
},
32+
render::{RenderState, command::DrawCommand},
3633
surface::Surface,
3734
};
3835

36+
use processing_utils::CommandBuffer;
37+
3938
pub struct GraphicsPlugin;
4039

4140
impl Plugin for GraphicsPlugin {
@@ -242,7 +241,7 @@ pub fn create(
242241
}),
243242
Transform::from_xyz(0.0, 0.0, 999.9),
244243
render_layer,
245-
CommandBuffer::new(),
244+
CommandBuffer::<DrawCommand>::new(),
246245
RenderState::default(),
247246
SurfaceSize(width, height),
248247
Graphics {
@@ -465,7 +464,7 @@ pub fn end_draw(app: &mut App, entity: Entity) -> Result<()> {
465464

466465
pub fn record_command(
467466
In((graphics_entity, cmd)): In<(Entity, DrawCommand)>,
468-
mut graphics_query: Query<&mut CommandBuffer>,
467+
mut graphics_query: Query<&mut CommandBuffer<DrawCommand>>,
469468
) -> Result<()> {
470469
let mut command_buffer = graphics_query
471470
.get_mut(graphics_entity)

crates/processing_render/src/render/command.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,3 @@ pub enum DrawCommand {
3838
},
3939
Geometry(Entity),
4040
}
41-
42-
#[derive(Debug, Default, Component)]
43-
pub struct CommandBuffer {
44-
pub commands: Vec<DrawCommand>,
45-
}
46-
47-
impl CommandBuffer {
48-
pub fn new() -> Self {
49-
Self {
50-
commands: Vec::new(),
51-
}
52-
}
53-
54-
pub fn push(&mut self, cmd: DrawCommand) {
55-
self.commands.push(cmd);
56-
}
57-
58-
pub fn clear(&mut self) {
59-
self.commands.clear();
60-
}
61-
}

crates/processing_render/src/render/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ use bevy::{
1010
math::{Affine3A, Mat4, Vec4},
1111
prelude::*,
1212
};
13-
use command::{CommandBuffer, DrawCommand};
13+
use command::DrawCommand;
1414
use material::MaterialKey;
1515
use primitive::{TessellationMode, empty_mesh};
1616
use transform::TransformStack;
1717

1818
use crate::render::material::UntypedMaterial;
1919
use crate::{Flush, geometry::Geometry, image::Image, render::primitive::rect};
2020

21+
use processing_utils::CommandBuffer;
22+
2123
#[derive(Component)]
2224
#[relationship(relationship_target = TransientMeshes)]
2325
pub struct BelongsToGraphics(pub Entity);
@@ -93,7 +95,7 @@ pub fn flush_draw_commands(
9395
mut graphics: Query<
9496
(
9597
Entity,
96-
&mut CommandBuffer,
98+
&mut CommandBuffer<DrawCommand>,
9799
&mut RenderState,
98100
&RenderLayers,
99101
&Projection,

crates/processing_utils/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "processing_utils"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
bevy = { workspace = true }
8+
9+
[lints]
10+
workspace = true

crates/processing_utils/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use bevy::prelude::*;
2+
3+
#[derive(Debug, Default, Component)]
4+
pub struct CommandBuffer<T> {
5+
pub commands: Vec<T>,
6+
}
7+
8+
impl<T> CommandBuffer<T> {
9+
pub fn new() -> Self {
10+
Self {
11+
commands: Vec::new(),
12+
}
13+
}
14+
15+
pub fn push(&mut self, cmd: T) {
16+
self.commands.push(cmd);
17+
}
18+
19+
pub fn clear(&mut self) {
20+
self.commands.clear();
21+
}
22+
}

0 commit comments

Comments
 (0)