• 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 use super::VertexBufferDescription;
11 use crate::{
12     pipeline::graphics::vertex_input::{
13         IncompatibleVertexDefinitionError, Vertex, VertexDefinition, VertexInputState,
14     },
15     shader::ShaderInterface,
16 };
17 
18 /// A vertex definition for any number of vertex and instance buffers.
19 #[deprecated(
20     since = "0.33.0",
21     note = "Use `VertexBufferDescription` directly instead as returned by `Vertex::per_vertex` or `Vertex::per_instance`"
22 )]
23 #[derive(Clone, Debug, Default)]
24 pub struct BuffersDefinition(Vec<VertexBufferDescription>);
25 
26 #[allow(deprecated)]
27 impl BuffersDefinition {
28     /// Constructs a new definition.
29     #[inline]
new() -> Self30     pub fn new() -> Self {
31         BuffersDefinition(Vec::new())
32     }
33 
34     /// Adds a new vertex buffer containing elements of type `V` to the definition.
vertex<V: Vertex>(mut self) -> Self35     pub fn vertex<V: Vertex>(mut self) -> Self {
36         self.0.push(V::per_vertex());
37         self
38     }
39 
40     /// Adds a new instance buffer containing elements of type `V` to the definition.
instance<V: Vertex>(mut self) -> Self41     pub fn instance<V: Vertex>(mut self) -> Self {
42         self.0.push(V::per_instance());
43         self
44     }
45 
46     /// Adds a new instance buffer containing elements of type `V` to the definition, with the
47     /// specified input rate divisor.
48     ///
49     /// This requires the [`vertex_attribute_instance_rate_divisor`] feature has been enabled on
50     /// the device, unless `divisor` is 1.
51     ///
52     /// `divisor` can be 0 if the [`vertex_attribute_instance_rate_zero_divisor`] feature is also
53     /// enabled. This means that every vertex will use the same vertex and instance data.
54     ///
55     /// [`vertex_attribute_instance_rate_divisor`]: crate::device::Features::vertex_attribute_instance_rate_divisor
56     /// [`vertex_attribute_instance_rate_zero_divisor`]: crate::device::Features::vertex_attribute_instance_rate_zero_divisor
instance_with_divisor<V: Vertex>(mut self, divisor: u32) -> Self57     pub fn instance_with_divisor<V: Vertex>(mut self, divisor: u32) -> Self {
58         self.0.push(V::per_instance_with_divisor(divisor));
59         self
60     }
61 }
62 
63 #[allow(deprecated)]
64 unsafe impl VertexDefinition for BuffersDefinition {
65     #[inline]
definition( &self, interface: &ShaderInterface, ) -> Result<VertexInputState, IncompatibleVertexDefinitionError>66     fn definition(
67         &self,
68         interface: &ShaderInterface,
69     ) -> Result<VertexInputState, IncompatibleVertexDefinitionError> {
70         self.0.definition(interface)
71     }
72 }
73