ark_api_ffi/entrypoints/render.rs
1//! Render module entrypoints
2//! Render modules only get an entry point, so not much needed here
3//! other than necessary type definitions.
4
5use bytemuck::Pod;
6use bytemuck::Zeroable;
7
8/// `ark_render_frame` - Render a frame with a set of instances to draw
9///
10/// # Example
11///
12/// ```no_run
13/// pub use ark_api_ffi::entrypoints::render::{RenderFrameInfo, RenderDrawInfo};
14/// #[no_mangle]
15/// pub unsafe fn ark_render_frame(frame_info_ptr: *const RenderFrameInfo, draw_info_ptr: *const RenderDrawInfo, draw_info_len: u32) {
16/// }
17pub type RenderFrameFn = fn(
18 frame_info_ptr: *const RenderFrameInfo,
19 draw_info_ptr: *const RenderDrawInfo,
20 draw_info_len: u32,
21);
22pub const RENDER_FRAME: &str = "ark_render_frame";
23
24bitflags! {
25 #[repr(C)]
26 #[derive(Pod, Zeroable)]
27 pub struct RenderDrawFlags : u32 {
28 const REMOVED = 0b0000_0001;
29 }
30}
31
32/// Raw struct, abstracted away by the impl macro so not accessed directly by user code.
33#[derive(Copy, Clone, Pod, Zeroable)]
34#[repr(C)]
35pub struct RenderDrawInfo {
36 pub object_to_world: [f32; 16],
37 pub static_data_ptr: u32,
38 pub static_data_len: u32,
39 /// Stable instance ID for identifying an instance across frames.
40 pub cache_id: u64,
41
42 pub flags: RenderDrawFlags,
43
44 pub dynamic_data_ptr: u32,
45 pub dynamic_data_len: u32,
46
47 // Unlike in RenderFrameInfo, we need to reserve space here for any future expantion
48 // because we pass as slice `RenderDrawInfo` to the module so the size is fixed.
49 // Running out of reserved space already...
50 pub reserved: u32,
51}
52
53/// General information about the current frame.
54///
55/// `view_to_world` is useful for making camera aligned things in world space,
56/// such as particles.
57/// Use `game_time_s` and `frame_delta_times_s` to drive animations, as appropriate.
58/// Will be approximately in sync with the simulated game time on the server,
59/// but will have higher resolution in time if you are running on a high refresh rate monitor.
60#[derive(Copy, Clone, Pod, Zeroable)]
61#[repr(C)]
62pub struct RenderFrameInfo {
63 pub view_to_world: [f32; 16],
64 pub game_time_s: f64,
65 pub frame_delta_time_s: f32,
66 pub display_width: u16,
67 pub display_height: u16,
68 pub dpi_factor: f32,
69 pub _pad: u32,
70 // Can safely be (strictly) expanded without breaking ABI
71}