Content-Type: text/x-zim-wiki Wiki-Format: zim 0.4 Creation-Date: 2020-01-22T18:39:43-08:00 ====== Dynamic Vertex ====== {{{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(); } } /// I don't know what the fuck is going on here... It just repackages the buffs /// Needs the num vertices 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 ) } } }}}