2022-12-05 14:48:57 +11:00
|
|
|
//! Binding types for the librashader C API.
|
2022-12-04 10:32:10 +11:00
|
|
|
use crate::error::LibrashaderError;
|
2024-02-09 18:07:02 +11:00
|
|
|
use librashader::presets::context::{Orientation, VideoDriver, WildcardContext};
|
2022-12-05 16:06:37 +11:00
|
|
|
use librashader::presets::ShaderPreset;
|
2023-02-10 15:36:09 +11:00
|
|
|
use std::mem::MaybeUninit;
|
2022-12-05 16:06:37 +11:00
|
|
|
use std::ptr::NonNull;
|
2022-12-04 10:32:10 +11:00
|
|
|
|
2023-01-14 10:10:09 +11:00
|
|
|
/// A handle to a shader preset object.
|
2022-12-04 11:55:27 +11:00
|
|
|
pub type libra_shader_preset_t = Option<NonNull<ShaderPreset>>;
|
2023-01-14 10:10:09 +11:00
|
|
|
|
2024-02-09 18:07:02 +11:00
|
|
|
/// A handle to a preset wildcard context object.
|
|
|
|
pub type libra_preset_ctx_t = Option<NonNull<WildcardContext>>;
|
|
|
|
|
2023-01-14 10:10:09 +11:00
|
|
|
/// A handle to a librashader error object.
|
2022-12-05 14:37:03 +11:00
|
|
|
pub type libra_error_t = Option<NonNull<LibrashaderError>>;
|
2022-12-04 10:32:10 +11:00
|
|
|
|
2024-02-09 18:07:02 +11:00
|
|
|
/// An enum representing orientation for use in preset contexts.
|
|
|
|
#[repr(u32)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub enum LIBRA_PRESET_CTX_ORIENTATION {
|
|
|
|
Vertical = 0,
|
|
|
|
Horizontal,
|
|
|
|
}
|
|
|
|
impl From<LIBRA_PRESET_CTX_ORIENTATION> for Orientation {
|
|
|
|
fn from(value: LIBRA_PRESET_CTX_ORIENTATION) -> Self {
|
|
|
|
match value {
|
|
|
|
LIBRA_PRESET_CTX_ORIENTATION::Vertical => Orientation::Vertical,
|
|
|
|
LIBRA_PRESET_CTX_ORIENTATION::Horizontal => Orientation::Horizontal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// An enum representing graphics runtimes (video drivers) for use in preset contexts.
|
|
|
|
#[repr(u32)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub enum LIBRA_PRESET_CTX_RUNTIME {
|
|
|
|
None = 0,
|
|
|
|
GlCore,
|
|
|
|
Vulkan,
|
|
|
|
D3D11,
|
|
|
|
D3D12,
|
|
|
|
Metal,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<LIBRA_PRESET_CTX_RUNTIME> for VideoDriver {
|
|
|
|
fn from(value: LIBRA_PRESET_CTX_RUNTIME) -> Self {
|
|
|
|
match value {
|
|
|
|
LIBRA_PRESET_CTX_RUNTIME::None => VideoDriver::None,
|
|
|
|
LIBRA_PRESET_CTX_RUNTIME::GlCore => VideoDriver::GlCore,
|
|
|
|
LIBRA_PRESET_CTX_RUNTIME::Vulkan => VideoDriver::Vulkan,
|
|
|
|
LIBRA_PRESET_CTX_RUNTIME::D3D11 => VideoDriver::Direct3D11,
|
|
|
|
LIBRA_PRESET_CTX_RUNTIME::D3D12 => VideoDriver::Direct3D12,
|
|
|
|
LIBRA_PRESET_CTX_RUNTIME::Metal => VideoDriver::Metal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 09:48:20 +11:00
|
|
|
#[cfg(feature = "runtime-opengl")]
|
|
|
|
use librashader::runtime::gl::FilterChain as FilterChainGL;
|
|
|
|
|
2023-01-14 10:10:09 +11:00
|
|
|
/// A handle to a OpenGL filter chain.
|
2022-12-05 14:37:03 +11:00
|
|
|
#[cfg(feature = "runtime-opengl")]
|
2023-01-21 17:54:06 +11:00
|
|
|
#[doc(cfg(feature = "runtime-opengl"))]
|
2024-02-10 09:48:20 +11:00
|
|
|
pub type libra_gl_filter_chain_t = Option<NonNull<FilterChainGL>>;
|
|
|
|
|
|
|
|
/// A handle to a Direct3D 11 filter chain.
|
|
|
|
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
|
|
|
|
use librashader::runtime::d3d11::FilterChain as FilterChainD3D11;
|
2022-12-04 10:56:57 +11:00
|
|
|
|
2023-02-06 18:17:30 +11:00
|
|
|
/// A handle to a Direct3D 11 filter chain.
|
2023-01-21 17:54:06 +11:00
|
|
|
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
|
|
|
|
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d11")))]
|
2024-02-11 10:54:57 +11:00
|
|
|
pub type libra_d3d11_filter_chain_t = Option<NonNull<FilterChainD3D11>>;
|
2022-12-05 14:48:57 +11:00
|
|
|
|
2024-02-10 09:48:20 +11:00
|
|
|
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
|
|
|
|
use librashader::runtime::d3d12::FilterChain as FilterChainD3D12;
|
2023-02-06 18:17:30 +11: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")))]
|
2024-02-11 10:54:57 +11:00
|
|
|
pub type libra_d3d12_filter_chain_t = Option<NonNull<FilterChainD3D12>>;
|
2023-02-06 18:17:30 +11:00
|
|
|
|
2024-02-10 09:48:20 +11:00
|
|
|
#[cfg(feature = "runtime-vulkan")]
|
|
|
|
use librashader::runtime::vk::FilterChain as FilterChainVulkan;
|
2023-01-14 10:10:09 +11:00
|
|
|
/// A handle to a Vulkan filter chain.
|
2023-01-14 09:59:22 +11:00
|
|
|
#[cfg(feature = "runtime-vulkan")]
|
2023-01-21 17:54:06 +11:00
|
|
|
#[doc(cfg(feature = "runtime-vulkan"))]
|
2024-02-11 10:54:57 +11:00
|
|
|
pub type libra_vk_filter_chain_t = Option<NonNull<FilterChainVulkan>>;
|
2023-01-14 09:59:22 +11:00
|
|
|
|
2023-01-14 10:10:09 +11:00
|
|
|
/// Defines the output viewport for a rendered frame.
|
2022-12-04 10:56:57 +11:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct libra_viewport_t {
|
2023-01-14 10:10:09 +11:00
|
|
|
/// The x offset in the viewport framebuffer to begin rendering from.
|
2022-12-04 10:56:57 +11:00
|
|
|
pub x: f32,
|
2023-01-14 10:10:09 +11:00
|
|
|
/// The y offset in the viewport framebuffer to begin rendering from.
|
2022-12-04 10:56:57 +11:00
|
|
|
pub y: f32,
|
2023-01-21 16:31:29 +11:00
|
|
|
/// The width of the viewport framebuffer.
|
|
|
|
pub width: u32,
|
2023-01-28 10:17:35 +11:00
|
|
|
/// The height of the viewport framebuffer.
|
|
|
|
pub height: u32,
|
2022-12-05 16:06:37 +11:00
|
|
|
}
|
2023-02-10 15:36:09 +11:00
|
|
|
|
|
|
|
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;
|
2024-02-10 09:48:20 +11:00
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[deny(deprecated)]
|
|
|
|
#[deprecated = "Forward declarations for cbindgen, do not use."]
|
|
|
|
mod __cbindgen_opaque_forward_declarations {
|
|
|
|
macro_rules! typedef_struct {
|
|
|
|
($($(#[$($attrss:tt)*])* $name:ident;)*) => {
|
|
|
|
$($(#[$($attrss)*])*
|
|
|
|
#[allow(unused)]
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[deny(deprecated)]
|
|
|
|
#[deprecated]
|
|
|
|
pub struct $name;
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef_struct! {
|
|
|
|
/// Opaque struct for a preset context.
|
|
|
|
WildcardContext;
|
|
|
|
/// Opaque struct for a shader preset.
|
|
|
|
ShaderPreset;
|
|
|
|
/// Opaque struct for an OpenGL filter chain.
|
|
|
|
FilterChainGL;
|
|
|
|
/// Opaque struct for a Direct3D 11 filter chain.
|
|
|
|
FilterChainD3D11;
|
|
|
|
/// Opaque struct for a Direct3D 12 filter chain.
|
|
|
|
FilterChainD3D12;
|
|
|
|
/// Opaque struct for a Vulkan filter chain.
|
|
|
|
FilterChainVulkan;
|
|
|
|
}
|
2024-02-11 10:54:57 +11:00
|
|
|
}
|