-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement BuffersDefinition leveraging VertexBufferInfo
- Loading branch information
Showing
3 changed files
with
96 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2016 The vulkano developers | ||
// Licensed under the Apache License, Version 2.0 | ||
// <LICENSE-APACHE or | ||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT | ||
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, | ||
// at your option. All files in the project carrying such | ||
// notice may not be copied, modified, or distributed except | ||
// according to those terms. | ||
|
||
use super::VertexBufferInfo; | ||
use crate::{ | ||
pipeline::graphics::vertex_input::{ | ||
IncompatibleVertexDefinitionError, Vertex, VertexDefinition, VertexInputState, | ||
}, | ||
shader::ShaderInterface, | ||
}; | ||
|
||
/// A vertex definition for any number of vertex and instance buffers. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct BuffersDefinition(Vec<VertexBufferInfo>); | ||
|
||
impl BuffersDefinition { | ||
/// Constructs a new definition. | ||
#[inline] | ||
pub fn new() -> Self { | ||
BuffersDefinition(Vec::new()) | ||
} | ||
|
||
/// Adds a new vertex buffer containing elements of type `V` to the definition. | ||
pub fn vertex<V: Vertex>(mut self) -> Self { | ||
self.0.push(V::info().per_vertex()); | ||
self | ||
} | ||
|
||
/// Adds a new instance buffer containing elements of type `V` to the definition. | ||
pub fn instance<V: Vertex>(mut self) -> Self { | ||
self.0.push(V::info().per_instance()); | ||
self | ||
} | ||
|
||
/// Adds a new instance buffer containing elements of type `V` to the definition, with the | ||
/// specified input rate divisor. | ||
/// | ||
/// This requires the [`vertex_attribute_instance_rate_divisor`] feature has been enabled on | ||
/// the device, unless `divisor` is 1. | ||
/// | ||
/// `divisor` can be 0 if the [`vertex_attribute_instance_rate_zero_divisor`] feature is also | ||
/// enabled. This means that every vertex will use the same vertex and instance data. | ||
/// | ||
/// [`vertex_attribute_instance_rate_divisor`]: crate::device::Features::vertex_attribute_instance_rate_divisor | ||
/// [`vertex_attribute_instance_rate_zero_divisor`]: crate::device::Features::vertex_attribute_instance_rate_zero_divisor | ||
pub fn instance_with_divisor<V: Vertex>(mut self, divisor: u32) -> Self { | ||
self.0.push(V::info().per_instance_with_divisor(divisor)); | ||
self | ||
} | ||
} | ||
|
||
unsafe impl VertexDefinition for BuffersDefinition { | ||
#[inline] | ||
fn definition( | ||
&self, | ||
interface: &ShaderInterface, | ||
) -> Result<VertexInputState, IncompatibleVertexDefinitionError> { | ||
self.0.definition(interface) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters