diff --git a/src/canvas/canvas_buffer.rs b/src/canvas/canvas_buffer.rs index 2ae89990..cd256326 100644 --- a/src/canvas/canvas_buffer.rs +++ b/src/canvas/canvas_buffer.rs @@ -9,6 +9,8 @@ use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess}; use vulkano::pipeline::GraphicsPipelineAbstract; use rusttype::Font; + +/// Canvas buffer which represents an allocated Texture with a key and dimensions #[derive(Clone)] pub struct CanvasTexture { pub(crate) handle: Arc, @@ -31,6 +33,7 @@ impl CanvasTexture { } } +/// Canvas buffer which represents an allocated image and dimension #[derive(Clone)] pub struct CanvasImage { pub(crate) handle: Arc, diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index 0a6f1edc..9767ea9a 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -16,7 +16,6 @@ pub struct CanvasFrame { /* This is sort of the beginning of our interface with the user definable sprites. - Will be taking in multiple type of items TEXT diff --git a/src/canvas/shader/dynamic_vertex.rs b/src/canvas/shader/dynamic_vertex.rs index 9348c89d..12db11a7 100644 --- a/src/canvas/shader/dynamic_vertex.rs +++ b/src/canvas/shader/dynamic_vertex.rs @@ -5,14 +5,18 @@ use std::sync::Arc; use cgmath::num_traits::real::Real; use std::vec::IntoIter as VecIntoIter; +/// Runtime Vertex def is just a generic holder of "dynamic vertex definitions" pub struct RuntimeVertexDef { - buffers: Vec<(u32, usize, InputRate)>, - vertex_buffer_ids: Vec<(usize, usize)>, + 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 + /// pub fn from_primitive(primitive: u32) -> RuntimeVertexDef { let mut buffers = Vec::new(); @@ -21,6 +25,7 @@ impl RuntimeVertexDef { let mut num_vertices = u32::max_value(); + // for (attribute_id, attribute) in primitive.attributes().enumerate() { // let (name, accessor) = match attribute.clone() { // Attribute::Positions(accessor) => ("i_position".to_owned(), accessor), @@ -70,16 +75,29 @@ impl RuntimeVertexDef { &self.vertex_buffer_ids } } - +/// Implementing VertexDefinition 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)>; + /// Builds the vertex definition to use to link this definition to a vertex shader's input + /// interface. + /// + /// At this point I need to have enough information from the implementing type to + /// describe its elements + /// + /// Needs: + /// buffers + /// attributes + /// fn definition(&self, interface: &I) -> Result<(Self::BuffersIter, Self::AttribsIter), IncompatibleVertexDefinitionError> { + let buffers_iter = self.buffers.clone().into_iter(); let mut attribs_iter = self.attributes.iter().map(|&(ref name, buffer_id, ref infos)| { @@ -92,6 +110,7 @@ unsafe impl VertexDefinition for RuntimeVertexDef }).collect::>(); // Add dummy attributes. + // Binding is for binding in interface.elements() { if attribs_iter.iter().any(|a| a.0 == binding.location.start) { continue; @@ -105,10 +124,15 @@ unsafe impl VertexDefinition for RuntimeVertexDef } } +/// I don't know what the fuck is going on here... It just repackages the buffs unsafe impl VertexSource>> for RuntimeVertexDef { fn decode(&self, bufs: Vec>) -> (Vec>, usize, usize) { - (bufs.into_iter().map(|b| Box::new(b) as Box<_>).collect(), self.num_vertices as usize, 1) + ( + 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 + ) } } \ No newline at end of file