Skip to content

Commit c99ef4f

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

File tree

8 files changed

+52
-30
lines changed

8 files changed

+52
-30
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
@@ -26,6 +26,7 @@ processing = { path = "." }
2626
processing_pyo3 = { path = "crates/processing_pyo3" }
2727
processing_render = { path = "crates/processing_render" }
2828
processing_midi = { path = "crates/processing_midi" }
29+
processing_utils = { path = "crates/processing_utils" }
2930

3031
[dependencies]
3132
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: 6 additions & 7 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,8 +241,8 @@ pub fn create(
242241
}),
243242
Transform::from_xyz(0.0, 0.0, 999.9),
244243
render_layer,
245-
CommandBuffer::new(),
246-
RenderState::new(),
244+
CommandBuffer::<DrawCommand>::new(),
245+
RenderState::default(),
247246
SurfaceSize(width, height),
248247
Graphics {
249248
readback_buffer,
@@ -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
@@ -53,24 +53,3 @@ pub enum DrawCommand {
5353
stacks: u32,
5454
},
5555
}
56-
57-
#[derive(Debug, Default, Component)]
58-
pub struct CommandBuffer {
59-
pub commands: Vec<DrawCommand>,
60-
}
61-
62-
impl CommandBuffer {
63-
pub fn new() -> Self {
64-
Self {
65-
commands: Vec::new(),
66-
}
67-
}
68-
69-
pub fn push(&mut self, cmd: DrawCommand) {
70-
self.commands.push(cmd);
71-
}
72-
73-
pub fn clear(&mut self) {
74-
self.commands.clear();
75-
}
76-
}

crates/processing_render/src/render/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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, box_mesh, empty_mesh, sphere_mesh};
1616
use transform::TransformStack;
@@ -22,6 +22,8 @@ use crate::{
2222
render::{material::UntypedMaterial, primitive::rect},
2323
};
2424

25+
use processing_utils::CommandBuffer;
26+
2527
#[derive(Component)]
2628
#[relationship(relationship_target = TransientMeshes)]
2729
pub struct BelongsToGraphics(pub Entity);
@@ -113,7 +115,7 @@ pub fn flush_draw_commands(
113115
mut graphics: Query<
114116
(
115117
Entity,
116-
&mut CommandBuffer,
118+
&mut CommandBuffer<DrawCommand>,
117119
&mut RenderState,
118120
&RenderLayers,
119121
&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)