lava/vulkan/vk/
vk_command_buffer_usage_flags.rs

1// Generated by `scripts/generate.js`
2
3use utils::vk_traits::*;
4
5/// Wrapper for [VkCommandBufferUsageFlags](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkCommandBufferUsageFlags.html).
6///
7/// Use the macro `VkCommandBufferUsageFlags!` as an alternative method to create a structure. For example, these two snippets return the same value:
8/// ```
9/// VkCommandBufferUsageFlags!(one_time_submit, render_pass_continue)
10/// ```
11/// ```
12/// VkCommandBufferUsageFlags {
13///     one_time_submit: true,
14///     render_pass_continue: true,
15///     ..VkCommandBufferUsageFlags::none()
16/// }
17/// ```
18#[derive(Debug, Clone)]
19pub struct VkCommandBufferUsageFlags {
20    pub one_time_submit: bool,
21    pub render_pass_continue: bool,
22    pub simultaneous_use: bool,
23}
24
25#[doc(hidden)]
26pub type RawVkCommandBufferUsageFlags = u32;
27
28impl VkWrappedType<RawVkCommandBufferUsageFlags> for VkCommandBufferUsageFlags {
29    fn vk_to_raw(src: &VkCommandBufferUsageFlags, dst: &mut RawVkCommandBufferUsageFlags) {
30        *dst = 0;
31        if src.one_time_submit { *dst |= 0x00000001; }
32        if src.render_pass_continue { *dst |= 0x00000002; }
33        if src.simultaneous_use { *dst |= 0x00000004; }
34    }
35}
36
37impl VkRawType<VkCommandBufferUsageFlags> for RawVkCommandBufferUsageFlags {
38    fn vk_to_wrapped(src: &RawVkCommandBufferUsageFlags) -> VkCommandBufferUsageFlags {
39        VkCommandBufferUsageFlags {
40            one_time_submit: (src & 0x00000001) != 0,
41            render_pass_continue: (src & 0x00000002) != 0,
42            simultaneous_use: (src & 0x00000004) != 0,
43        }
44    }
45}
46
47impl Default for VkCommandBufferUsageFlags {
48    fn default() -> VkCommandBufferUsageFlags {
49        VkCommandBufferUsageFlags {
50            one_time_submit: false,
51            render_pass_continue: false,
52            simultaneous_use: false,
53        }
54    }
55}
56
57impl VkCommandBufferUsageFlags {
58    
59    /// Return a structure with all flags to `false`.
60    pub fn none() -> Self {
61        VkCommandBufferUsageFlags {
62            one_time_submit: false,
63            render_pass_continue: false,
64            simultaneous_use: false,
65        }
66    }
67    
68    /// Return a structure with all flags to `true`.
69    pub fn all() -> Self {
70        VkCommandBufferUsageFlags {
71            one_time_submit: true,
72            render_pass_continue: true,
73            simultaneous_use: true,
74        }
75    }
76    
77    /// Return the numerical bit flags corresponding to the structure (as described in the Vulkan specs).
78    pub fn to_u32(&self) -> u32 {
79        0
80        + if self.one_time_submit { 0x00000001 } else { 0 }
81        + if self.render_pass_continue { 0x00000002 } else { 0 }
82        + if self.simultaneous_use { 0x00000004 } else { 0 }
83    }
84    
85    /// Create a structure corresponding to the specified numerical bit flags.
86    pub fn from_u32(value: u32) -> Self {
87        VkCommandBufferUsageFlags {
88            one_time_submit: value & 0x00000001 > 0,
89            render_pass_continue: value & 0x00000002 > 0,
90            simultaneous_use: value & 0x00000004 > 0,
91        }
92    }
93}
94
95#[doc(hidden)]
96#[macro_export]
97macro_rules! VkCommandBufferUsageFlags {
98    ( $( $x:ident ),* ) => {
99        VkCommandBufferUsageFlags {
100            $($x: true,)*
101            ..VkCommandBufferUsageFlags::none()
102        }
103    }
104}