use core::mem::{align_of, size_of};
use std::os::raw::{c_char, c_void};
use crate::render_device::device::TextureBinding;
use crate::render_device::types::DeviceCaps;
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct TextureBindingFfi {
pub handle: u64,
pub width: u32,
pub height: u32,
pub has_mipmaps: bool,
pub inverted: bool,
pub has_alpha: bool,
pub pad: u8,
}
impl From<TextureBinding> for TextureBindingFfi {
fn from(b: TextureBinding) -> Self {
Self {
handle: b.handle.0.get(),
width: b.width,
height: b.height,
has_mipmaps: b.has_mipmaps,
inverted: b.inverted,
has_alpha: b.has_alpha,
pad: 0,
}
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct RenderTargetBindingFfi {
pub handle: u64,
pub resolve_texture: TextureBindingFfi,
}
const _: () = assert!(size_of::<TextureBindingFfi>() == 24);
const _: () = assert!(align_of::<TextureBindingFfi>() == 8);
const _: () = assert!(size_of::<RenderTargetBindingFfi>() == 32);
const _: () = assert!(align_of::<RenderTargetBindingFfi>() == 8);
#[repr(C)]
pub struct RenderDeviceVTable {
pub get_caps: unsafe extern "C" fn(userdata: *mut c_void, out_caps: *mut DeviceCaps),
pub create_texture: unsafe extern "C" fn(
userdata: *mut c_void,
label: *const c_char,
width: u32,
height: u32,
num_levels: u32,
format: u32,
data: *const *const c_void,
out: *mut TextureBindingFfi,
),
pub update_texture: unsafe extern "C" fn(
userdata: *mut c_void,
handle: u64,
level: u32,
x: u32,
y: u32,
width: u32,
height: u32,
format: u32,
data: *const c_void,
),
pub end_updating_textures:
unsafe extern "C" fn(userdata: *mut c_void, handles: *const u64, count: u32),
pub drop_texture: unsafe extern "C" fn(userdata: *mut c_void, handle: u64),
pub create_render_target: unsafe extern "C" fn(
userdata: *mut c_void,
label: *const c_char,
width: u32,
height: u32,
sample_count: u32,
needs_stencil: bool,
out: *mut RenderTargetBindingFfi,
),
pub clone_render_target: unsafe extern "C" fn(
userdata: *mut c_void,
label: *const c_char,
src_handle: u64,
out: *mut RenderTargetBindingFfi,
),
pub drop_render_target: unsafe extern "C" fn(userdata: *mut c_void, handle: u64),
pub begin_offscreen_render: unsafe extern "C" fn(userdata: *mut c_void),
pub end_offscreen_render: unsafe extern "C" fn(userdata: *mut c_void),
pub begin_onscreen_render: unsafe extern "C" fn(userdata: *mut c_void),
pub end_onscreen_render: unsafe extern "C" fn(userdata: *mut c_void),
pub set_render_target: unsafe extern "C" fn(userdata: *mut c_void, handle: u64),
pub begin_tile: unsafe extern "C" fn(
userdata: *mut c_void,
handle: u64,
tile: *const crate::render_device::types::Tile,
),
pub end_tile: unsafe extern "C" fn(userdata: *mut c_void, handle: u64),
pub resolve_render_target: unsafe extern "C" fn(
userdata: *mut c_void,
handle: u64,
tiles: *const crate::render_device::types::Tile,
count: u32,
),
pub map_vertices: unsafe extern "C" fn(userdata: *mut c_void, bytes: u32) -> *mut c_void,
pub unmap_vertices: unsafe extern "C" fn(userdata: *mut c_void),
pub map_indices: unsafe extern "C" fn(userdata: *mut c_void, bytes: u32) -> *mut c_void,
pub unmap_indices: unsafe extern "C" fn(userdata: *mut c_void),
pub draw_batch: unsafe extern "C" fn(
userdata: *mut c_void,
batch: *const crate::render_device::types::Batch,
),
pub drop_userdata: unsafe extern "C" fn(userdata: *mut c_void),
}
unsafe extern "C" {
pub fn noesis_render_device_create(
vtable: *const RenderDeviceVTable,
userdata: *mut c_void,
) -> *mut c_void;
pub fn noesis_render_device_destroy(device: *mut c_void);
pub fn noesis_texture_get_handle(texture: *const c_void) -> u64;
pub fn noesis_render_device_set_offscreen_width(device: *mut c_void, width: u32);
pub fn noesis_render_device_set_offscreen_height(device: *mut c_void, height: u32);
pub fn noesis_render_device_set_offscreen_sample_count(device: *mut c_void, count: u32);
pub fn noesis_render_device_set_offscreen_default_num_surfaces(device: *mut c_void, num: u32);
pub fn noesis_render_device_set_offscreen_max_num_surfaces(device: *mut c_void, num: u32);
pub fn noesis_render_device_set_glyph_cache_width(device: *mut c_void, width: u32);
pub fn noesis_render_device_set_glyph_cache_height(device: *mut c_void, height: u32);
pub fn noesis_render_device_get_offscreen_width(device: *const c_void) -> u32;
pub fn noesis_render_device_get_offscreen_height(device: *const c_void) -> u32;
pub fn noesis_render_device_get_offscreen_sample_count(device: *const c_void) -> u32;
pub fn noesis_render_device_get_offscreen_default_num_surfaces(device: *const c_void) -> u32;
pub fn noesis_render_device_get_offscreen_max_num_surfaces(device: *const c_void) -> u32;
pub fn noesis_render_device_get_glyph_cache_width(device: *const c_void) -> u32;
pub fn noesis_render_device_get_glyph_cache_height(device: *const c_void) -> u32;
}
#[cfg(feature = "test-utils")]
unsafe extern "C" {
pub fn noesis_test_run_frame_scenario(device: *mut c_void);
}