1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copied from `scripts/static/`

use std::fmt::*;
use std::mem;
use utils::vk_traits::*;
use utils::vk_convert::*;
use vulkan::vk::*;

#[doc(hidden)]
#[repr(C)]
#[derive(Copy, Clone)]
pub union RawVkClearValue {
    pub color: RawVkClearColorValue,
    pub depth_stencil: RawVkClearDepthStencilValue
}

/// Wrapper for [VkClearValue](https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkClearValue.html)
#[derive(Debug, Clone)]
pub enum VkClearValue {
    Color(VkClearColorValue),
    DepthStencil(VkClearDepthStencilValue)
}

impl Debug for RawVkClearValue {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "{:?}", unsafe { self.color })
    }
}

impl VkWrappedType<RawVkClearValue> for VkClearValue {
    fn vk_to_raw(value: &VkClearValue, dst: &mut RawVkClearValue) {
        match *value {
            VkClearValue::Color(ref color_value) => {
                *dst = RawVkClearValue { color: vk_to_raw_value(color_value) };
            },
            VkClearValue::DepthStencil(ref depth_stencil_value) => {
                *dst = RawVkClearValue { depth_stencil: vk_to_raw_value(depth_stencil_value) };
            }
        }
    }
}

impl Default for VkClearValue {
    fn default() -> VkClearValue {
        VkClearValue::Color(VkClearColorValue::U([0; 4]))
    }
}