Content-Type: text/x-zim-wiki Wiki-Format: zim 0.4 Creation-Date: 2020-02-04T23:22:14-08:00 ====== DynamicVertex ====== [[/doc/sfml_rust/canvas/managed/shader/dynamic_vertex/index.html|Documentation]] [[https://vulkan-tutorial.com/Vertex_buffers/Vertex_input_description|Vulkan C++ binding equivilent]] ===== Details ===== So, the **pipeline** we create over in the **shader** needs to know about the vertex data it will be using. This lines up pretty well because the Shader is precisely the mechanism which would know about this data. -------------------- ===== Data ===== **Borrowed:** **Owns:** -------------------- {{{code: lang="rust" linenumbers="True" #[derive(Default, Debug, Clone)] pub struct RuntimeVertexDef { buffers: Vec<(u32, usize, InputRate)>, // (attribute id, stride, Vertex or Instance data) vertex_buffer_ids: Vec<(usize, usize)>,// attributes: Vec<(String, u32, AttributeInfo)>, num_vertices: u32, } impl RuntimeVertexDef { /// primitive is an input value or struct which can then describe /// these damn values that are required for inputting them into vulkan pub fn from_primitive(primitive: u32) -> RuntimeVertexDef { } /// Returns the indices of the buffers to bind as vertex buffers and the byte offset, when /// drawing the primitive. pub fn vertex_buffer_ids(&self) -> &[(usize, usize)] { &self.vertex_buffer_ids } } unsafe impl VertexDefinition for RuntimeVertexDef where I: ShaderInterfaceDef /// Iterator that returns the offset, the stride (in bytes) and input rate of each buffer. type BuffersIter = VecIntoIter<(u32, usize, InputRate)>; /// Iterator that returns the attribute location, buffer id, and infos. type AttribsIter = VecIntoIter<(u32, u32, AttributeInfo)>; fn definition(&self, interface: &I) -> <(Self::BuffersIter, Self::AttribsIter), IncompatibleVertexDefinitionError>{ let buffers = vec![ (0, mem::size_of::(), InputRate::Vertex), (1, mem::size_of::(), InputRate::Instance), ]_iter(); } } unsafe impl VertexSource>> for RuntimeVertexDef { fn decode(&self, bufs: Vec>) -> (Vec>, usize, usize) { ( bufs.into_iter().map(|b| Box::new(b) as Box<_>).collect(), // Box up the buffers self.num_vertices as usize, // Number of vertices 1 // Number of instances ) } } }}}