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