librashader/librashader-capi/src/ctypes.rs

90 lines
3 KiB
Rust
Raw Normal View History

2022-12-04 22:48:57 -05:00
//! Binding types for the librashader C API.
2022-12-03 18:32:10 -05:00
use crate::error::LibrashaderError;
use librashader::presets::ShaderPreset;
use std::mem::MaybeUninit;
use std::ptr::NonNull;
2022-12-03 18:32:10 -05:00
2023-01-13 18:10:09 -05:00
/// A handle to a shader preset object.
pub type libra_shader_preset_t = Option<NonNull<ShaderPreset>>;
2023-01-13 18:10:09 -05:00
/// A handle to a librashader error object.
2022-12-04 22:37:03 -05:00
pub type libra_error_t = Option<NonNull<LibrashaderError>>;
2022-12-03 18:32:10 -05:00
2023-01-13 18:10:09 -05:00
/// A handle to a OpenGL filter chain.
2022-12-04 22:37:03 -05:00
#[cfg(feature = "runtime-opengl")]
#[doc(cfg(feature = "runtime-opengl"))]
pub type libra_gl_filter_chain_t = Option<NonNull<librashader::runtime::gl::capi::FilterChainGL>>;
2022-12-03 18:56:57 -05:00
2023-02-06 02:17:30 -05:00
/// A handle to a Direct3D 11 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d11")))]
pub type libra_d3d11_filter_chain_t =
Option<NonNull<librashader::runtime::d3d11::capi::FilterChainD3D11>>;
2022-12-04 22:48:57 -05:00
2023-02-06 02:17:30 -05:00
/// A handle to a Direct3D 12 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))]
pub type libra_d3d12_filter_chain_t =
2023-02-06 21:56:30 -05:00
Option<NonNull<librashader::runtime::d3d12::capi::FilterChainD3D12>>;
2023-02-06 02:17:30 -05:00
2023-01-13 18:10:09 -05:00
/// A handle to a Vulkan filter chain.
2023-01-13 17:59:22 -05:00
#[cfg(feature = "runtime-vulkan")]
#[doc(cfg(feature = "runtime-vulkan"))]
2023-01-13 17:59:22 -05:00
pub type libra_vk_filter_chain_t =
2023-01-15 03:06:09 -05:00
Option<NonNull<librashader::runtime::vk::capi::FilterChainVulkan>>;
2023-01-13 17:59:22 -05:00
2023-01-13 18:10:09 -05:00
/// Defines the output viewport for a rendered frame.
2022-12-03 18:56:57 -05:00
#[repr(C)]
pub struct libra_viewport_t {
2023-01-13 18:10:09 -05:00
/// The x offset in the viewport framebuffer to begin rendering from.
2022-12-03 18:56:57 -05:00
pub x: f32,
2023-01-13 18:10:09 -05:00
/// The y offset in the viewport framebuffer to begin rendering from.
2022-12-03 18:56:57 -05:00
pub y: f32,
2023-01-21 00:31:29 -05:00
/// The width of the viewport framebuffer.
pub width: u32,
2023-01-27 18:17:35 -05:00
/// The height of the viewport framebuffer.
pub height: u32,
}
pub(crate) trait FromUninit<T>
where
Self: Sized,
{
fn from_uninit(value: MaybeUninit<Self>) -> T;
}
macro_rules! config_set_field {
($options:ident.$field:ident <- $ptr:ident) => {
$options.$field = unsafe { ::std::ptr::addr_of!((*$ptr).$field).read() };
};
}
macro_rules! config_version_set {
($version:literal => [$($field:ident),+ $(,)?] ($options:ident <- $ptr:ident)) => {
let version = unsafe { ::std::ptr::addr_of!((*$ptr).version).read() };
#[allow(unused_comparisons)]
if version >= $version {
$($crate::ctypes::config_set_field!($options.$field <- $ptr);)+
}
}
}
macro_rules! config_struct {
(impl $rust:ty => $capi:ty {$($version:literal => [$($field:ident),+ $(,)?]);+ $(;)?}) => {
impl $crate::ctypes::FromUninit<$rust> for $capi {
fn from_uninit(value: ::std::mem::MaybeUninit<Self>) -> $rust {
let ptr = value.as_ptr();
let mut options = <$rust>::default();
$(
$crate::ctypes::config_version_set!($version => [$($field),+] (options <- ptr));
)+
options
}
}
}
}
pub(crate) use config_set_field;
pub(crate) use config_struct;
pub(crate) use config_version_set;