Skip to main content

vulkano/pipeline/graphics/vertex_input/
buffers.rs

1use super::{definition::VertexDefinition, VertexBufferDescription};
2use crate::{
3    pipeline::graphics::vertex_input::{Vertex, VertexInputState},
4    shader::EntryPoint,
5    ValidationError,
6};
7
8/// A vertex definition for any number of vertex and instance buffers.
9#[deprecated(
10    since = "0.33.0",
11    note = "use `VertexBufferDescription` directly instead as returned by `Vertex::per_vertex` or `Vertex::per_instance`"
12)]
13#[derive(Clone, Debug, Default)]
14pub struct BuffersDefinition(Vec<VertexBufferDescription>);
15
16#[allow(deprecated)]
17impl BuffersDefinition {
18    /// Constructs a new definition.
19    #[inline]
20    pub fn new() -> Self {
21        BuffersDefinition(Vec::new())
22    }
23
24    /// Adds a new vertex buffer containing elements of type `V` to the definition.
25    pub fn vertex<V: Vertex>(mut self) -> Self {
26        self.0.push(V::per_vertex());
27        self
28    }
29
30    /// Adds a new instance buffer containing elements of type `V` to the definition.
31    pub fn instance<V: Vertex>(mut self) -> Self {
32        self.0.push(V::per_instance());
33        self
34    }
35
36    /// Adds a new instance buffer containing elements of type `V` to the definition, with the
37    /// specified input rate divisor.
38    ///
39    /// This requires the [`vertex_attribute_instance_rate_divisor`] feature has been enabled on
40    /// the device, unless `divisor` is 1.
41    ///
42    /// `divisor` can be 0 if the [`vertex_attribute_instance_rate_zero_divisor`] feature is also
43    /// enabled. This means that every vertex will use the same vertex and instance data.
44    ///
45    /// [`vertex_attribute_instance_rate_divisor`]: crate::device::DeviceFeatures::vertex_attribute_instance_rate_divisor
46    /// [`vertex_attribute_instance_rate_zero_divisor`]: crate::device::DeviceFeatures::vertex_attribute_instance_rate_zero_divisor
47    pub fn instance_with_divisor<V: Vertex>(mut self, divisor: u32) -> Self {
48        self.0.push(V::per_instance_with_divisor(divisor));
49        self
50    }
51}
52
53#[allow(deprecated)]
54unsafe impl VertexDefinition for BuffersDefinition {
55    #[inline]
56    fn definition(
57        &self,
58        entry_point: &EntryPoint,
59    ) -> Result<VertexInputState, Box<ValidationError>> {
60        self.0.definition(entry_point)
61    }
62}