gfx_hal/command/
clear.rs

1use crate::pso;
2use std::fmt;
3
4/// A clear color union, which can be either `f32`, `i32`, or `u32`.
5#[repr(C)]
6#[derive(Clone, Copy)]
7pub union ClearColor {
8    /// `f32` variant
9    pub float32: [f32; 4],
10    /// `i32` variant
11    pub sint32: [i32; 4],
12    /// `u32` variant
13    pub uint32: [u32; 4],
14}
15
16impl fmt::Debug for ClearColor {
17    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18        writeln![f, "ClearColor"]
19    }
20}
21
22/// A combination of depth and stencil clear values.
23#[repr(C)]
24#[derive(Clone, Copy, Debug)]
25#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26pub struct ClearDepthStencil {
27    /// Depth value
28    pub depth: f32,
29    /// Stencil value
30    pub stencil: u32,
31}
32
33/// A set of clear values for a single attachment.
34///
35/// These are passed to a command buffer by
36/// [beginning a render pass][crate::command::CommandBuffer::begin_render_pass].
37#[repr(C)]
38#[derive(Clone, Copy)]
39pub union ClearValue {
40    /// Clear color
41    pub color: ClearColor,
42    /// Clear depth and stencil
43    pub depth_stencil: ClearDepthStencil,
44    _align: [u32; 4],
45}
46
47impl fmt::Debug for ClearValue {
48    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49        f.debug_struct("ClearValue")
50            .field("color", unsafe { &self.color.uint32 })
51            .field("depth_stencil", unsafe { &self.depth_stencil })
52            .finish()
53    }
54}
55
56impl Default for ClearValue {
57    fn default() -> Self {
58        ClearValue { _align: [0; 4] }
59    }
60}
61
62/// Attachment clear description for the current subpass.
63#[derive(Clone, Copy, Debug)]
64pub enum AttachmentClear {
65    /// Clear color attachment.
66    Color {
67        /// Index inside the `SubpassDesc::colors` array.
68        index: usize,
69        /// Value to clear with.
70        value: ClearColor,
71    },
72    /// Clear depth-stencil attachment.
73    DepthStencil {
74        /// Depth value to clear with.
75        depth: Option<pso::DepthValue>,
76        /// Stencil value to clear with.
77        stencil: Option<pso::StencilValue>,
78    },
79}