• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 The vulkano developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
6 // at your option. All files in the project carrying such
7 // notice may not be copied, modified, or distributed except
8 // according to those terms.
9 
10 //! A test to discard pixels that would be written to certain areas of a framebuffer.
11 //!
12 //! The discard rectangle test is similar to, but separate from the scissor test.
13 
14 use crate::{
15     macros::vulkan_enum,
16     pipeline::{graphics::viewport::Scissor, PartialStateMode},
17 };
18 
19 /// The state in a graphics pipeline describing how the discard rectangle test should behave.
20 #[derive(Clone, Debug)]
21 pub struct DiscardRectangleState {
22     /// Sets whether the discard rectangle test operates inclusively or exclusively.
23     pub mode: DiscardRectangleMode,
24 
25     /// Specifies the discard rectangles. If set to `Dynamic`, it specifies only the number of
26     /// rectangles used from the dynamic state.
27     ///
28     /// If set to `Dynamic` or to `Fixed` with a non-empty list, the
29     /// [`ext_discard_rectangles`](crate::device::DeviceExtensions::ext_discard_rectangles)
30     /// extension must be enabled on the device.
31     pub rectangles: PartialStateMode<Vec<Scissor>, u32>,
32 }
33 
34 impl DiscardRectangleState {
35     /// Creates a `DiscardRectangleState` in exclusive mode with zero rectangles.
36     #[inline]
new() -> Self37     pub fn new() -> Self {
38         Self {
39             mode: DiscardRectangleMode::Exclusive,
40             rectangles: PartialStateMode::Fixed(Vec::new()),
41         }
42     }
43 }
44 
45 impl Default for DiscardRectangleState {
46     /// Returns [`DiscardRectangleState::new`].
47     #[inline]
default() -> Self48     fn default() -> Self {
49         Self::new()
50     }
51 }
52 
53 vulkan_enum! {
54     #[non_exhaustive]
55 
56     /// The mode in which the discard rectangle test operates.
57     DiscardRectangleMode = DiscardRectangleModeEXT(i32);
58 
59     /// Samples that are inside a rectangle are kept, samples that are outside all rectangles
60     /// are discarded.
61     Inclusive = INCLUSIVE,
62 
63     /// Samples that are inside a rectangle are discarded, samples that are outside all rectangles
64     /// are kept.
65     Exclusive = EXCLUSIVE,
66 }
67