librashader_capi/
ctypes.rs1use crate::error::LibrashaderError;
3use librashader::presets::context::{Orientation, VideoDriver, WildcardContext};
4use librashader::presets::ShaderPreset;
5use std::mem::MaybeUninit;
6use std::ptr::NonNull;
7
8pub type libra_shader_preset_t = Option<NonNull<ShaderPreset>>;
10
11pub type libra_preset_ctx_t = Option<NonNull<WildcardContext>>;
13
14pub type libra_error_t = Option<NonNull<LibrashaderError>>;
16
17#[repr(u32)]
19#[derive(Debug, Copy, Clone)]
20pub enum LIBRA_PRESET_CTX_ORIENTATION {
21 Vertical = 0,
23 Horizontal,
25}
26impl From<LIBRA_PRESET_CTX_ORIENTATION> for Orientation {
27 fn from(value: LIBRA_PRESET_CTX_ORIENTATION) -> Self {
28 match value {
29 LIBRA_PRESET_CTX_ORIENTATION::Vertical => Orientation::Vertical,
30 LIBRA_PRESET_CTX_ORIENTATION::Horizontal => Orientation::Horizontal,
31 }
32 }
33}
34
35#[repr(u32)]
37#[derive(Debug, Copy, Clone)]
38pub enum LIBRA_PRESET_CTX_RUNTIME {
39 None = 0,
41 GlCore,
43 Vulkan,
45 D3D11,
47 D3D12,
49 Metal,
51 D3D9_HLSL,
53}
54
55impl From<LIBRA_PRESET_CTX_RUNTIME> for VideoDriver {
56 fn from(value: LIBRA_PRESET_CTX_RUNTIME) -> Self {
57 match value {
58 LIBRA_PRESET_CTX_RUNTIME::None => VideoDriver::None,
59 LIBRA_PRESET_CTX_RUNTIME::GlCore => VideoDriver::GlCore,
60 LIBRA_PRESET_CTX_RUNTIME::Vulkan => VideoDriver::Vulkan,
61 LIBRA_PRESET_CTX_RUNTIME::D3D11 => VideoDriver::Direct3D11,
62 LIBRA_PRESET_CTX_RUNTIME::D3D12 => VideoDriver::Direct3D12,
63 LIBRA_PRESET_CTX_RUNTIME::Metal => VideoDriver::Metal,
64 LIBRA_PRESET_CTX_RUNTIME::D3D9_HLSL => VideoDriver::Direct3D9Hlsl,
65 }
66 }
67}
68
69#[cfg(feature = "runtime-opengl")]
70use librashader::runtime::gl::FilterChain as FilterChainGL;
71
72#[cfg(feature = "runtime-opengl")]
74#[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-opengl")))]
75pub type libra_gl_filter_chain_t = Option<NonNull<FilterChainGL>>;
76
77#[cfg(any(
79 feature = "__cbindgen_internal",
80 all(target_os = "windows", feature = "runtime-d3d11")
81))]
82use librashader::runtime::d3d11::FilterChain as FilterChainD3D11;
83
84#[cfg_attr(
86 feature = "docsrs",
87 doc(cfg(all(target_os = "windows", feature = "runtime-d3d11")))
88)]
89#[cfg(any(
90 feature = "__cbindgen_internal",
91 all(target_os = "windows", feature = "runtime-d3d11")
92))]
93pub type libra_d3d11_filter_chain_t = Option<NonNull<FilterChainD3D11>>;
94
95#[cfg(any(
96 feature = "__cbindgen_internal",
97 all(target_os = "windows", feature = "runtime-d3d12")
98))]
99use librashader::runtime::d3d12::FilterChain as FilterChainD3D12;
100#[cfg(any(
102 feature = "__cbindgen_internal",
103 all(target_os = "windows", feature = "runtime-d3d12")
104))]
105pub type libra_d3d12_filter_chain_t = Option<NonNull<FilterChainD3D12>>;
106
107#[cfg(any(
109 feature = "__cbindgen_internal",
110 all(target_os = "windows", feature = "runtime-d3d9")
111))]
112use librashader::runtime::d3d9::FilterChain as FilterChainD3D9;
113
114#[cfg_attr(
116 feature = "docsrs",
117 doc(cfg(all(target_os = "windows", feature = "runtime-d3d9")))
118)]
119#[cfg(any(
120 feature = "__cbindgen_internal",
121 all(target_os = "windows", feature = "runtime-d3d9")
122))]
123pub type libra_d3d9_filter_chain_t = Option<NonNull<FilterChainD3D9>>;
124
125#[cfg(feature = "runtime-vulkan")]
126use librashader::runtime::vk::FilterChain as FilterChainVulkan;
127#[cfg(feature = "runtime-vulkan")]
129#[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-vulkan")))]
130pub type libra_vk_filter_chain_t = Option<NonNull<FilterChainVulkan>>;
131
132#[cfg(all(target_os = "macos", feature = "runtime-metal"))]
133use librashader::runtime::mtl::FilterChain as FilterChainMetal;
134
135#[cfg_attr(
137 feature = "docsrs",
138 doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))
139)]
140#[cfg(any(
141 feature = "__cbindgen_internal",
142 all(
143 target_vendor = "apple",
144 feature = "runtime-metal",
145 feature = "__cbindgen_internal_objc"
146 )
147))]
148pub type libra_mtl_filter_chain_t = Option<NonNull<FilterChainMetal>>;
149
150#[repr(C)]
152pub struct libra_viewport_t {
153 pub x: f32,
155 pub y: f32,
157 pub width: u32,
160 pub height: u32,
163}
164
165pub(crate) trait FromUninit<T>
166where
167 Self: Sized,
168{
169 fn from_uninit(value: MaybeUninit<Self>) -> T;
170}
171
172macro_rules! config_set_field {
173 (@POINTER $options:ident.$field:ident <- $ptr:ident) => {
174 $options.$field = unsafe { ::std::ptr::addr_of!((*$ptr).$field).read() };
175 };
176 (@POINTER @NEGATIVE $options:ident.$field:ident <- $ptr:ident) => {
177 $options.$field = unsafe { !::std::ptr::addr_of!((*$ptr).$field).read() };
178 };
179 (@LITERAL $options:ident.$field:ident <- $value:literal) => {
180 $options.$field = $value;
181 };
182}
183
184macro_rules! config_version_set {
185 (@ROOT $realver:ident $version:literal => [$($field:ident),+ $(,)?] ($options:ident <- $ptr:ident)) => {
187 #[allow(unused_comparisons)]
188 if $realver >= $version {
189 $($crate::ctypes::config_set_field!(@POINTER $options.$field <- $ptr);)+
190 }
191 };
192
193 (@ROOT $realver:ident $version:literal => [$($field:tt),+ $(,)?] ($options:ident <- $ptr:ident)) => {
195 $(crate::ctypes::config_version_set!(@SINGLE $realver $version => [$field] ($options <- $ptr));)+
196 };
197
198 (@SINGLE $realver:ident $version:literal => [($field:ident: $value:literal)] ($options:ident <- $ptr:ident)) => {
200 #[allow(unused_comparisons)]
201 if $realver >= $version {
202 $crate::ctypes::config_set_field!(@LITERAL $options.$field <- $value);
203 }
204 };
205
206 (@SINGLE $realver:ident $version:literal => [(!$field:ident)] ($options:ident <- $ptr:ident)) => {
208 #[allow(unused_comparisons)]
209 if $realver >= $version {
210 $crate::ctypes::config_set_field!(@POINTER @NEGATIVE $options.$field <- $ptr);
211 }
212 };
213
214 (@SINGLE $realver:ident $version:literal => [$field:ident] ($options:ident <- $ptr:ident)) => {
215 #[allow(unused_comparisons)]
216 if $realver >= $version {
217 $crate::ctypes::config_set_field!(@POINTER $options.$field <- $ptr);
218 }
219 };
220}
221
222macro_rules! config_struct {
243 (impl $rust:ty => $capi:ty {$($version:literal => [$($field:tt),+]);+ $(;)?}) => {
244 impl $crate::ctypes::FromUninit<$rust> for $capi {
245 fn from_uninit(value: ::std::mem::MaybeUninit<Self>) -> $rust {
246 let ptr = value.as_ptr();
247 let version = unsafe { ::std::ptr::addr_of!((*ptr).version).read() };
248
249 let mut options = <$rust>::default();
250 $(
251 $crate::ctypes::config_version_set!(@ROOT version $version => [$($field),+] (options <- ptr));
252 )+
253 options
254 }
255 }
256 }
257}
258
259pub(crate) use config_set_field;
260pub(crate) use config_struct;
261pub(crate) use config_version_set;
262
263#[doc(hidden)]
264#[deny(deprecated)]
265#[deprecated = "Forward declarations for cbindgen, do not use."]
266mod __cbindgen_opaque_forward_declarations {
267 macro_rules! typedef_struct {
268 ($($(#[$($attrss:tt)*])* $name:ident;)*) => {
269 $($(#[$($attrss)*])*
270 #[allow(unused)]
271 #[doc(hidden)]
272 #[deny(deprecated)]
273 #[deprecated]
274 pub struct $name;
275 )*
276 };
277 }
278
279 typedef_struct! {
280 WildcardContext;
282 ShaderPreset;
284 FilterChainGL;
286 FilterChainD3D11;
288 FilterChainD3D12;
290 FilterChainD3D9;
292 FilterChainVulkan;
294 FilterChainMetal;
296 }
297}