Skip to content

Commit 1b34a50

Browse files
committed
Refactor rendering crate to clarify primary Processing API.
1 parent 060cd70 commit 1b34a50

File tree

14 files changed

+1687
-654
lines changed

14 files changed

+1687
-654
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ path = "examples/rectangle.rs"
4242
name = "background_image"
4343
path = "examples/background_image.rs"
4444

45+
[[example]]
46+
name = "update_pixels"
47+
path = "examples/update_pixels.rs"
48+
4549
[profile.wasm-release]
4650
inherits = "release"
4751
opt-level = "z"

crates/processing_ffi/src/lib.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ pub extern "C" fn processing_surface_resize(window_id: u64, width: u32, height:
7676
pub extern "C" fn processing_background_color(window_id: u64, color: Color) {
7777
error::clear_error();
7878
let window_entity = Entity::from_bits(window_id);
79-
error::check(|| record_command(window_entity, DrawCommand::BackgroundColor(color.into())));
79+
error::check(|| {
80+
graphics_record_command(window_entity, DrawCommand::BackgroundColor(color.into()))
81+
});
8082
}
8183

8284
/// Set the background image for the given window.
@@ -90,7 +92,9 @@ pub extern "C" fn processing_background_image(window_id: u64, image_id: u64) {
9092
error::clear_error();
9193
let window_entity = Entity::from_bits(window_id);
9294
let image_entity = Entity::from_bits(image_id);
93-
error::check(|| record_command(window_entity, DrawCommand::BackgroundImage(image_entity)));
95+
error::check(|| {
96+
graphics_record_command(window_entity, DrawCommand::BackgroundImage(image_entity))
97+
});
9498
}
9599

96100
/// Begins the draw for the given window.
@@ -102,7 +106,7 @@ pub extern "C" fn processing_background_image(window_id: u64, image_id: u64) {
102106
pub extern "C" fn processing_begin_draw(window_id: u64) {
103107
error::clear_error();
104108
let window_entity = Entity::from_bits(window_id);
105-
error::check(|| begin_draw(window_entity));
109+
error::check(|| graphics_begin_draw(window_entity));
106110
}
107111

108112
/// Flushes recorded draw commands for the given window.
@@ -114,7 +118,7 @@ pub extern "C" fn processing_begin_draw(window_id: u64) {
114118
pub extern "C" fn processing_flush(window_id: u64) {
115119
error::clear_error();
116120
let window_entity = Entity::from_bits(window_id);
117-
error::check(|| flush(window_entity));
121+
error::check(|| graphics_flush(window_entity));
118122
}
119123

120124
/// Ends the draw for the given window and presents the frame.
@@ -126,7 +130,7 @@ pub extern "C" fn processing_flush(window_id: u64) {
126130
pub extern "C" fn processing_end_draw(window_id: u64) {
127131
error::clear_error();
128132
let window_entity = Entity::from_bits(window_id);
129-
error::check(|| end_draw(window_entity));
133+
error::check(|| graphics_end_draw(window_entity));
130134
}
131135

132136
/// Shuts down internal resources with given exit code, but does *not* terminate the process.
@@ -151,7 +155,7 @@ pub extern "C" fn processing_set_fill(window_id: u64, r: f32, g: f32, b: f32, a:
151155
error::clear_error();
152156
let window_entity = Entity::from_bits(window_id);
153157
let color = bevy::color::Color::srgba(r, g, b, a);
154-
error::check(|| record_command(window_entity, DrawCommand::Fill(color)));
158+
error::check(|| graphics_record_command(window_entity, DrawCommand::Fill(color)));
155159
}
156160

157161
/// Set the stroke color.
@@ -165,7 +169,7 @@ pub extern "C" fn processing_set_stroke_color(window_id: u64, r: f32, g: f32, b:
165169
error::clear_error();
166170
let window_entity = Entity::from_bits(window_id);
167171
let color = bevy::color::Color::srgba(r, g, b, a);
168-
error::check(|| record_command(window_entity, DrawCommand::StrokeColor(color)));
172+
error::check(|| graphics_record_command(window_entity, DrawCommand::StrokeColor(color)));
169173
}
170174

171175
/// Set the stroke weight.
@@ -178,7 +182,7 @@ pub extern "C" fn processing_set_stroke_color(window_id: u64, r: f32, g: f32, b:
178182
pub extern "C" fn processing_set_stroke_weight(window_id: u64, weight: f32) {
179183
error::clear_error();
180184
let window_entity = Entity::from_bits(window_id);
181-
error::check(|| record_command(window_entity, DrawCommand::StrokeWeight(weight)));
185+
error::check(|| graphics_record_command(window_entity, DrawCommand::StrokeWeight(weight)));
182186
}
183187

184188
/// Disable fill for subsequent shapes.
@@ -191,7 +195,7 @@ pub extern "C" fn processing_set_stroke_weight(window_id: u64, weight: f32) {
191195
pub extern "C" fn processing_no_fill(window_id: u64) {
192196
error::clear_error();
193197
let window_entity = Entity::from_bits(window_id);
194-
error::check(|| record_command(window_entity, DrawCommand::NoFill));
198+
error::check(|| graphics_record_command(window_entity, DrawCommand::NoFill));
195199
}
196200

197201
/// Disable stroke for subsequent shapes.
@@ -204,7 +208,7 @@ pub extern "C" fn processing_no_fill(window_id: u64) {
204208
pub extern "C" fn processing_no_stroke(window_id: u64) {
205209
error::clear_error();
206210
let window_entity = Entity::from_bits(window_id);
207-
error::check(|| record_command(window_entity, DrawCommand::NoStroke));
211+
error::check(|| graphics_record_command(window_entity, DrawCommand::NoStroke));
208212
}
209213

210214
/// Draw a rectangle.
@@ -228,7 +232,7 @@ pub extern "C" fn processing_rect(
228232
error::clear_error();
229233
let window_entity = Entity::from_bits(window_id);
230234
error::check(|| {
231-
record_command(
235+
graphics_record_command(
232236
window_entity,
233237
DrawCommand::Rect {
234238
x,
@@ -318,15 +322,15 @@ pub extern "C" fn processing_image_resize(image_id: u64, new_width: u32, new_hei
318322
/// - buffer_len must equal width * height of the image.
319323
/// - This is called from the same thread as init.
320324
#[unsafe(no_mangle)]
321-
pub unsafe extern "C" fn processing_image_load_pixels(
325+
pub unsafe extern "C" fn processing_image_readback(
322326
image_id: u64,
323327
buffer: *mut Color,
324328
buffer_len: usize,
325329
) {
326330
error::clear_error();
327331
let image_entity = Entity::from_bits(image_id);
328332
error::check(|| {
329-
let colors = image_load_pixels(image_entity)?;
333+
let colors = image_readback(image_entity)?;
330334

331335
// Validate buffer size
332336
if colors.len() != buffer_len {

crates/processing_pyo3/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use pyo3::prelude::*;
33

44
#[pymodule]
55
mod processing {
6-
use crate::glfw::GlfwContext;
76
use processing::prelude::*;
87
use pyo3::prelude::*;
98

9+
use crate::glfw::GlfwContext;
10+
1011
/// create surface
1112
#[pyfunction]
1213
fn size(width: u32, height: u32) -> PyResult<String> {

crates/processing_render/src/error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub enum ProcessingError {
88
AppAccess,
99
#[error("Error initializing tracing: {0}")]
1010
Tracing(#[from] tracing::subscriber::SetGlobalDefaultError),
11-
#[error("Window not found")]
12-
WindowNotFound,
11+
#[error("Surface not found")]
12+
SurfaceNotFound,
1313
#[error("Handle error: {0}")]
1414
HandleError(#[from] raw_window_handle::HandleError),
1515
#[error("Invalid window handle provided")]
@@ -20,4 +20,8 @@ pub enum ProcessingError {
2020
UnsupportedTextureFormat,
2121
#[error("Invalid argument: {0}")]
2222
InvalidArgument(String),
23+
#[error("Graphics not found")]
24+
GraphicsNotFound,
25+
#[error("Invalid entity")]
26+
InvalidEntity,
2327
}

0 commit comments

Comments
 (0)