From dcc0df955ec7a8bcfa372d64be2272415d59ec94 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Wed, 22 Jan 2020 21:45:59 -0800 Subject: [PATCH] . --- notes/Dynamic_Vertex.txt | 65 +++++++++++++++++++++++++++++ src/canvas/shader/dynamic_vertex.rs | 2 +- src/main.rs | 4 +- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 notes/Dynamic_Vertex.txt diff --git a/notes/Dynamic_Vertex.txt b/notes/Dynamic_Vertex.txt new file mode 100644 index 00000000..ce942b12 --- /dev/null +++ b/notes/Dynamic_Vertex.txt @@ -0,0 +1,65 @@ +Content-Type: text/x-zim-wiki +Wiki-Format: zim 0.4 +Creation-Date: 2020-01-22T18:39:43-08:00 + +====== Dynamic Vertex ====== +Created Wednesday 22 January 2020 + + + + +#[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 + ) + } +} + diff --git a/src/canvas/shader/dynamic_vertex.rs b/src/canvas/shader/dynamic_vertex.rs index ea67bfdc..1a3e119e 100644 --- a/src/canvas/shader/dynamic_vertex.rs +++ b/src/canvas/shader/dynamic_vertex.rs @@ -1,4 +1,4 @@ -use vulkano::pipeline::vertex::{VertexDefinition, InputRate, AttributeInfo, IncompatibleVertexDefinitionError, VertexSource}; +use vulkano::pipeline::vertex::{VertexDefinition, InputRate, AttributeInfo, IncompatibleVertexDefinitionError, VertexSource, VertexMemberInfo, VertexMemberTy}; use vulkano::pipeline::shader::ShaderInterfaceDef; use vulkano::buffer::BufferAccess; use std::sync::Arc; diff --git a/src/main.rs b/src/main.rs index b6686a7c..caddc85e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,8 +183,8 @@ pub fn main() { // compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); // let mut canvas = CanvasFrame::new(); -// canvas.draw(&funky_sprite); -// canvas.draw(&test_polygon); + canvas.draw(&funky_sprite); + canvas.draw(&test_polygon); { let g = hprof::enter("Run");