Skip to content

Commit d2fecc0

Browse files
committed
Fixup other crates.
1 parent 1b34a50 commit d2fecc0

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

crates/processing_pyo3/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ mod processing {
1919
let surface = surface_create(window_handle, display_handle, width, height, 1.0).unwrap();
2020

2121
while glfw_ctx.poll_events() {
22-
begin_draw(surface).unwrap();
22+
graphics_begin_draw(surface).unwrap();
2323

24-
record_command(
24+
graphics_record_command(
2525
surface,
2626
DrawCommand::Rect {
2727
x: 10.0,
@@ -33,7 +33,7 @@ mod processing {
3333
)
3434
.unwrap();
3535

36-
end_draw(surface).unwrap();
36+
graphics_end_draw(surface).unwrap();
3737
}
3838

3939
Ok("OK".to_string())

crates/processing_render/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ pub mod image;
44
pub mod render;
55
mod surface;
66

7-
#[cfg(any(target_os = "linux", target_arch = "wasm32"))]
8-
use std::ffi::c_void;
97
use std::{cell::RefCell, num::NonZero, path::PathBuf, sync::OnceLock};
108

119
use bevy::{
1210
app::{App, AppExit},
1311
asset::AssetEventSystems,
14-
log::tracing_subscriber,
1512
prelude::*,
1613
render::render_resource::{Extent3d, TextureFormat},
1714
};
15+
#[cfg(not(target_arch = "wasm32"))]
16+
use bevy::log::tracing_subscriber;
1817
use render::{activate_cameras, clear_transient_meshes, flush_draw_commands};
1918
use tracing::debug;
2019

crates/processing_render/src/surface.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//!
77
//! In Bevy, we can consider a surface to be a [`RenderTarget`], which is either a window or a
88
//! texture.
9+
#[cfg(any(target_os = "linux", target_arch = "wasm32"))]
10+
use std::ffi::c_void;
911
use std::ptr::NonNull;
1012

1113
use bevy::{
@@ -191,6 +193,24 @@ pub fn create(
191193
)
192194
};
193195

196+
#[cfg(target_arch = "wasm32")]
197+
let (raw_window_handle, raw_display_handle) = {
198+
use raw_window_handle::{WebCanvasWindowHandle, WebDisplayHandle};
199+
200+
// For WASM, window_handle is a pointer to an HtmlCanvasElement
201+
if window_handle == 0 {
202+
return Err(error::ProcessingError::InvalidWindowHandle);
203+
}
204+
let canvas_ptr = NonNull::new(window_handle as *mut c_void).unwrap();
205+
let window = WebCanvasWindowHandle::new(canvas_ptr.cast());
206+
let display = WebDisplayHandle::new();
207+
208+
(
209+
RawWindowHandle::WebCanvas(window),
210+
RawDisplayHandle::Web(display),
211+
)
212+
};
213+
194214
let glfw_window = GlfwWindow {
195215
window_handle: raw_window_handle,
196216
display_handle: raw_display_handle,

crates/processing_wasm/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use bevy::prelude::Entity;
22
use processing_render::{
3-
begin_draw, end_draw, exit, flush, image_create, image_destroy, image_load, image_load_pixels,
4-
image_resize, init, record_command, render::command::DrawCommand, surface_create_from_canvas,
5-
surface_destroy, surface_resize,
3+
exit, graphics_begin_draw, graphics_end_draw, graphics_flush, graphics_record_command,
4+
image_create, image_destroy, image_load, image_readback, image_resize, init,
5+
render::command::DrawCommand, surface_create_from_canvas, surface_destroy, surface_resize,
66
};
77
use wasm_bindgen::prelude::*;
88

@@ -38,33 +38,33 @@ pub fn js_surface_resize(surface_id: u64, width: u32, height: u32) -> Result<(),
3838
#[wasm_bindgen(js_name = "background")]
3939
pub fn js_background_color(surface_id: u64, r: f32, g: f32, b: f32, a: f32) -> Result<(), JsValue> {
4040
let color = bevy::color::Color::srgba(r, g, b, a);
41-
check(record_command(
41+
check(graphics_record_command(
4242
Entity::from_bits(surface_id),
4343
DrawCommand::BackgroundColor(color),
4444
))
4545
}
4646

4747
#[wasm_bindgen(js_name = "backgroundImage")]
4848
pub fn js_background_image(surface_id: u64, image_id: u64) -> Result<(), JsValue> {
49-
check(record_command(
49+
check(graphics_record_command(
5050
Entity::from_bits(surface_id),
5151
DrawCommand::BackgroundImage(Entity::from_bits(image_id)),
5252
))
5353
}
5454

5555
#[wasm_bindgen(js_name = "beginDraw")]
5656
pub fn js_begin_draw(surface_id: u64) -> Result<(), JsValue> {
57-
check(begin_draw(Entity::from_bits(surface_id)))
57+
check(graphics_begin_draw(Entity::from_bits(surface_id)))
5858
}
5959

6060
#[wasm_bindgen(js_name = "flush")]
6161
pub fn js_flush(surface_id: u64) -> Result<(), JsValue> {
62-
check(flush(Entity::from_bits(surface_id)))
62+
check(graphics_flush(Entity::from_bits(surface_id)))
6363
}
6464

6565
#[wasm_bindgen(js_name = "endDraw")]
6666
pub fn js_end_draw(surface_id: u64) -> Result<(), JsValue> {
67-
check(end_draw(Entity::from_bits(surface_id)))
67+
check(graphics_end_draw(Entity::from_bits(surface_id)))
6868
}
6969

7070
#[wasm_bindgen(js_name = "exit")]
@@ -75,7 +75,7 @@ pub fn js_exit(exit_code: u8) -> Result<(), JsValue> {
7575
#[wasm_bindgen(js_name = "fill")]
7676
pub fn js_fill(surface_id: u64, r: f32, g: f32, b: f32, a: f32) -> Result<(), JsValue> {
7777
let color = bevy::color::Color::srgba(r, g, b, a);
78-
check(record_command(
78+
check(graphics_record_command(
7979
Entity::from_bits(surface_id),
8080
DrawCommand::Fill(color),
8181
))
@@ -84,31 +84,31 @@ pub fn js_fill(surface_id: u64, r: f32, g: f32, b: f32, a: f32) -> Result<(), Js
8484
#[wasm_bindgen(js_name = "stroke")]
8585
pub fn js_stroke(surface_id: u64, r: f32, g: f32, b: f32, a: f32) -> Result<(), JsValue> {
8686
let color = bevy::color::Color::srgba(r, g, b, a);
87-
check(record_command(
87+
check(graphics_record_command(
8888
Entity::from_bits(surface_id),
8989
DrawCommand::StrokeColor(color),
9090
))
9191
}
9292

9393
#[wasm_bindgen(js_name = "strokeWeight")]
9494
pub fn js_stroke_weight(surface_id: u64, weight: f32) -> Result<(), JsValue> {
95-
check(record_command(
95+
check(graphics_record_command(
9696
Entity::from_bits(surface_id),
9797
DrawCommand::StrokeWeight(weight),
9898
))
9999
}
100100

101101
#[wasm_bindgen(js_name = "noFill")]
102102
pub fn js_no_fill(surface_id: u64) -> Result<(), JsValue> {
103-
check(record_command(
103+
check(graphics_record_command(
104104
Entity::from_bits(surface_id),
105105
DrawCommand::NoFill,
106106
))
107107
}
108108

109109
#[wasm_bindgen(js_name = "noStroke")]
110110
pub fn js_no_stroke(surface_id: u64) -> Result<(), JsValue> {
111-
check(record_command(
111+
check(graphics_record_command(
112112
Entity::from_bits(surface_id),
113113
DrawCommand::NoStroke,
114114
))
@@ -126,7 +126,7 @@ pub fn js_rect(
126126
br: f32,
127127
bl: f32,
128128
) -> Result<(), JsValue> {
129-
check(record_command(
129+
check(graphics_record_command(
130130
Entity::from_bits(surface_id),
131131
DrawCommand::Rect {
132132
x,
@@ -168,8 +168,8 @@ pub fn js_image_resize(image_id: u64, new_width: u32, new_height: u32) -> Result
168168
}
169169

170170
#[wasm_bindgen(js_name = "loadPixels")]
171-
pub fn js_image_load_pixels(image_id: u64) -> Result<Vec<f32>, JsValue> {
172-
let colors = check(image_load_pixels(Entity::from_bits(image_id)))?;
171+
pub fn js_image_readback(image_id: u64) -> Result<Vec<f32>, JsValue> {
172+
let colors = check(image_readback(Entity::from_bits(image_id)))?;
173173

174174
let mut result = Vec::with_capacity(colors.len() * 4);
175175
for color in colors {

0 commit comments

Comments
 (0)