Visitar URL original
Fixes. · processing/libprocessing@bbb935d · GitHub
Skip to content

Commit bbb935d

Browse files
committed
Fixes.
1 parent 6864a86 commit bbb935d

11 files changed

Lines changed: 2189 additions & 2149 deletions

File tree

‎Cargo.lock‎

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

‎crates/processing_ffi/Cargo.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ name = "processing"
1111
crate-type = ["cdylib", "staticlib"]
1212

1313
[features]
14-
default = []
14+
default = ["video"]
1515
wayland = ["processing/wayland"]
1616
x11 = ["processing/x11"]
1717
webcam = ["processing/webcam"]
1818
cuda = ["processing/cuda"]
19+
video = ["processing/video", "dep:processing_video"]
1920

2021
[dependencies]
2122
processing = { workspace = true }
23+
processing_video = { workspace = true, optional = true }
2224
bevy = { workspace = true }
2325
half = "2.7"
2426

‎crates/processing_ffi/src/lib.rs‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ use crate::color::Color;
99

1010
mod color;
1111
mod error;
12+
#[cfg(feature = "video")]
13+
mod video;
1214

13-
unsafe fn cstr_to_str<'a>(ptr: *const std::ffi::c_char) -> Result<&'a str, ProcessingError> {
15+
pub(crate) unsafe fn cstr_to_str<'a>(
16+
ptr: *const std::ffi::c_char,
17+
) -> Result<&'a str, ProcessingError> {
1418
unsafe { std::ffi::CStr::from_ptr(ptr) }
1519
.to_str()
1620
.map_err(|_| ProcessingError::InvalidArgument("non-UTF8 C string".to_string()))
@@ -311,6 +315,8 @@ pub extern "C" fn processing_end_draw(graphics_id: u64) {
311315
#[unsafe(no_mangle)]
312316
pub extern "C" fn processing_exit(exit_code: u8) {
313317
error::clear_error();
318+
#[cfg(feature = "video")]
319+
video::finish_on_exit();
314320
error::check(|| exit(exit_code));
315321
}
316322

@@ -1975,6 +1981,27 @@ pub extern "C" fn processing_ortho(
19751981
error::check(|| graphics_ortho(graphics_entity, left, right, bottom, top, near, far));
19761982
}
19771983

1984+
/// Set a glFrustum-style asymmetric (off-axis) perspective projection.
1985+
/// `left`/`right`/`bottom`/`top` bound the view volume on the NEAR plane,
1986+
/// matching classic Processing/OpenGL `frustum()`. Requires 0 < near < far.
1987+
///
1988+
/// SAFETY:
1989+
/// - graphics_id is a valid ID returned from graphics_create.
1990+
#[unsafe(no_mangle)]
1991+
pub extern "C" fn processing_frustum(
1992+
graphics_id: u64,
1993+
left: f32,
1994+
right: f32,
1995+
bottom: f32,
1996+
top: f32,
1997+
near: f32,
1998+
far: f32,
1999+
) {
2000+
error::clear_error();
2001+
let graphics_entity = Entity::from_bits(graphics_id);
2002+
error::check(|| graphics_frustum(graphics_entity, left, right, bottom, top, near, far));
2003+
}
2004+
19782005
#[unsafe(no_mangle)]
19792006
pub extern "C" fn processing_transform_set_position(entity_id: u64, x: f32, y: f32, z: f32) {
19802007
error::clear_error();
@@ -2786,6 +2813,31 @@ pub extern "C" fn processing_geometry_sphere(radius: f32, sectors: u32, stacks:
27862813
.unwrap_or(0)
27872814
}
27882815

2816+
/// Tessellate and extrude `text` into a 3D geometry, honoring the graphics
2817+
/// context's current text font, size, and style. `x`/`y` position the
2818+
/// baseline as in text(); `depth` is the extrusion depth. Returns the
2819+
/// geometry entity, or 0 on error.
2820+
///
2821+
/// SAFETY:
2822+
/// - graphics_id is a valid ID returned from graphics_create.
2823+
/// - text is a valid, NUL-terminated C string.
2824+
#[unsafe(no_mangle)]
2825+
pub unsafe extern "C" fn processing_graphics_text_to_geometry(
2826+
graphics_id: u64,
2827+
text: *const std::ffi::c_char,
2828+
x: f32,
2829+
y: f32,
2830+
depth: f32,
2831+
) -> u64 {
2832+
error::clear_error();
2833+
error::check(|| {
2834+
let text = unsafe { cstr_to_str(text) }?;
2835+
let mesh = graphics_text_to_model(Entity::from_bits(graphics_id), text, x, y, depth)?;
2836+
Ok(geometry_create_from_mesh(mesh)?.to_bits())
2837+
})
2838+
.unwrap_or(0)
2839+
}
2840+
27892841
#[unsafe(no_mangle)]
27902842
pub extern "C" fn processing_light_create_directional(
27912843
graphics_id: u64,

0 commit comments

Comments
 (0)