• 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 //! Assembling vertices into primitives.
11 //!
12 //! The input assembly is the stage where lists of vertices are turned into primitives.
13 //!
14 
15 /// How the input assembly stage should behave.
16 #[derive(Copy, Clone, Debug)]
17 #[deprecated]
18 pub struct InputAssembly {
19     /// The type of primitives.
20     ///
21     /// Note that some topologies don't support primitive restart.
22     pub topology: PrimitiveTopology,
23 
24     /// If true, then the special index value `0xffff` or `0xffffffff` will tell the GPU that it is
25     /// the end of the current primitive. A new primitive will restart at the next index.
26     ///
27     /// Note that some topologies don't support primitive restart.
28     pub primitive_restart_enable: bool,
29 }
30 
31 impl InputAssembly {
32     /// Builds an `InputAssembly` struct with the `TriangleList` topology.
33     #[inline]
triangle_list() -> InputAssembly34     pub fn triangle_list() -> InputAssembly {
35         InputAssembly {
36             topology: PrimitiveTopology::TriangleList,
37             primitive_restart_enable: false,
38         }
39     }
40 }
41 
42 /// Describes how vertices must be grouped together to form primitives.
43 ///
44 /// Note that some topologies don't support primitive restart.
45 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
46 pub enum PrimitiveTopology {
47     PointList,
48     LineList,
49     LineStrip,
50     TriangleList,
51     TriangleStrip,
52     TriangleFan,
53     LineListWithAdjacency,
54     LineStripWithAdjacency,
55     TriangleListWithAdjacency,
56     TriangleStripWithAdjacency,
57     PatchList { vertices_per_patch: u32 },
58 }
59 
60 impl From<PrimitiveTopology> for ash::vk::PrimitiveTopology {
61     #[inline]
from(val: PrimitiveTopology) -> ash::vk::PrimitiveTopology62     fn from(val: PrimitiveTopology) -> ash::vk::PrimitiveTopology {
63         match val {
64             PrimitiveTopology::PointList => ash::vk::PrimitiveTopology::POINT_LIST,
65             PrimitiveTopology::LineList => ash::vk::PrimitiveTopology::LINE_LIST,
66             PrimitiveTopology::LineStrip => ash::vk::PrimitiveTopology::LINE_STRIP,
67             PrimitiveTopology::TriangleList => ash::vk::PrimitiveTopology::TRIANGLE_LIST,
68             PrimitiveTopology::TriangleStrip => ash::vk::PrimitiveTopology::TRIANGLE_STRIP,
69             PrimitiveTopology::TriangleFan => ash::vk::PrimitiveTopology::TRIANGLE_FAN,
70             PrimitiveTopology::LineListWithAdjacency => {
71                 ash::vk::PrimitiveTopology::LINE_LIST_WITH_ADJACENCY
72             }
73             PrimitiveTopology::LineStripWithAdjacency => {
74                 ash::vk::PrimitiveTopology::LINE_STRIP_WITH_ADJACENCY
75             }
76             PrimitiveTopology::TriangleListWithAdjacency => {
77                 ash::vk::PrimitiveTopology::TRIANGLE_LIST_WITH_ADJACENCY
78             }
79             PrimitiveTopology::TriangleStripWithAdjacency => {
80                 ash::vk::PrimitiveTopology::TRIANGLE_STRIP_WITH_ADJACENCY
81             }
82             PrimitiveTopology::PatchList { .. } => ash::vk::PrimitiveTopology::PATCH_LIST,
83         }
84     }
85 }
86 
87 impl PrimitiveTopology {
88     /// Returns true if this primitive topology supports using primitives restart.
89     #[inline]
supports_primitive_restart(&self) -> bool90     pub fn supports_primitive_restart(&self) -> bool {
91         match *self {
92             PrimitiveTopology::LineStrip => true,
93             PrimitiveTopology::TriangleStrip => true,
94             PrimitiveTopology::TriangleFan => true,
95             PrimitiveTopology::LineStripWithAdjacency => true,
96             PrimitiveTopology::TriangleStripWithAdjacency => true,
97             _ => false,
98         }
99     }
100 }
101 
102 /// Trait for types that can be used as indices by the GPU.
103 pub unsafe trait Index {
104     /// Returns the type of data.
ty() -> IndexType105     fn ty() -> IndexType;
106 }
107 
108 unsafe impl Index for u16 {
109     #[inline(always)]
ty() -> IndexType110     fn ty() -> IndexType {
111         IndexType::U16
112     }
113 }
114 
115 unsafe impl Index for u32 {
116     #[inline(always)]
ty() -> IndexType117     fn ty() -> IndexType {
118         IndexType::U32
119     }
120 }
121 
122 /// An enumeration of all valid index types.
123 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
124 #[allow(missing_docs)]
125 #[repr(i32)]
126 pub enum IndexType {
127     U16 = ash::vk::IndexType::UINT16.as_raw(),
128     U32 = ash::vk::IndexType::UINT32.as_raw(),
129 }
130 
131 impl From<IndexType> for ash::vk::IndexType {
132     #[inline]
from(val: IndexType) -> Self133     fn from(val: IndexType) -> Self {
134         Self::from_raw(val as i32)
135     }
136 }
137