• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 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 crate::buffer::BufferAccess;
11 use crate::pipeline::shader::ShaderInterface;
12 use crate::pipeline::vertex::IncompatibleVertexDefinitionError;
13 use crate::pipeline::vertex::VertexDefinition;
14 use crate::pipeline::vertex::VertexInput;
15 use crate::pipeline::vertex::VertexSource;
16 
17 /// Implementation of `VertexDefinition` for drawing with no buffers at all.
18 ///
19 /// This is only useful if your shaders come up with vertex data on their own, e.g. by inspecting
20 /// `gl_VertexIndex`
21 #[derive(Copy, Clone)]
22 pub struct BufferlessDefinition;
23 
24 /// Value to be passed as the vertex source for bufferless draw commands.
25 ///
26 /// Note that the concrete type of the graphics pipeline using `BufferlessDefinition` must be
27 /// visible to the command buffer builder for this to be usable.
28 #[derive(Copy, Clone)]
29 pub struct BufferlessVertices {
30     pub vertices: usize,
31     pub instances: usize,
32 }
33 
34 unsafe impl VertexSource<BufferlessVertices> for BufferlessDefinition {
decode( &self, n: BufferlessVertices, ) -> ( Vec<Box<dyn BufferAccess + Sync + Send + 'static>>, usize, usize, )35     fn decode(
36         &self,
37         n: BufferlessVertices,
38     ) -> (
39         Vec<Box<dyn BufferAccess + Sync + Send + 'static>>,
40         usize,
41         usize,
42     ) {
43         (Vec::new(), n.vertices, n.instances)
44     }
45 }
46 
47 unsafe impl<T> VertexSource<Vec<T>> for BufferlessDefinition {
decode<'l>( &self, _: Vec<T>, ) -> ( Vec<Box<dyn BufferAccess + Sync + Send + 'static>>, usize, usize, )48     fn decode<'l>(
49         &self,
50         _: Vec<T>,
51     ) -> (
52         Vec<Box<dyn BufferAccess + Sync + Send + 'static>>,
53         usize,
54         usize,
55     ) {
56         panic!("bufferless drawing should not be supplied with buffers")
57     }
58 }
59 
60 unsafe impl VertexDefinition for BufferlessDefinition {
definition( &self, _: &ShaderInterface, ) -> Result<VertexInput, IncompatibleVertexDefinitionError>61     fn definition(
62         &self,
63         _: &ShaderInterface,
64     ) -> Result<VertexInput, IncompatibleVertexDefinitionError> {
65         Ok(VertexInput::empty())
66     }
67 }
68