working on dynamic v's

master
mitchellhansen 5 years ago
parent 8a83a1f12a
commit 11701542e2

@ -9,6 +9,8 @@ use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess};
use vulkano::pipeline::GraphicsPipelineAbstract; use vulkano::pipeline::GraphicsPipelineAbstract;
use rusttype::Font; use rusttype::Font;
/// Canvas buffer which represents an allocated Texture with a key and dimensions
#[derive(Clone)] #[derive(Clone)]
pub struct CanvasTexture { pub struct CanvasTexture {
pub(crate) handle: Arc<CanvasTextureHandle>, pub(crate) handle: Arc<CanvasTextureHandle>,
@ -31,6 +33,7 @@ impl CanvasTexture {
} }
} }
/// Canvas buffer which represents an allocated image and dimension
#[derive(Clone)] #[derive(Clone)]
pub struct CanvasImage { pub struct CanvasImage {
pub(crate) handle: Arc<CanvasImageHandle>, pub(crate) handle: Arc<CanvasImageHandle>,

@ -16,7 +16,6 @@ pub struct CanvasFrame {
/* /*
This is sort of the beginning of our interface with the user definable sprites. This is sort of the beginning of our interface with the user definable sprites.
Will be taking in multiple type of items Will be taking in multiple type of items
TEXT TEXT

@ -5,14 +5,18 @@ use std::sync::Arc;
use cgmath::num_traits::real::Real; use cgmath::num_traits::real::Real;
use std::vec::IntoIter as VecIntoIter; use std::vec::IntoIter as VecIntoIter;
/// Runtime Vertex def is just a generic holder of "dynamic vertex definitions"
pub struct RuntimeVertexDef { pub struct RuntimeVertexDef {
buffers: Vec<(u32, usize, InputRate)>, buffers: Vec<(u32, usize, InputRate)>, // (attribute id, stride, Vertex or Instance data)
vertex_buffer_ids: Vec<(usize, usize)>, vertex_buffer_ids: Vec<(usize, usize)>,//
attributes: Vec<(String, u32, AttributeInfo)>, attributes: Vec<(String, u32, AttributeInfo)>,
num_vertices: u32, num_vertices: u32,
} }
impl RuntimeVertexDef { impl RuntimeVertexDef {
/// primitive is an input value or struct which can then describe
///
pub fn from_primitive(primitive: u32) -> RuntimeVertexDef { pub fn from_primitive(primitive: u32) -> RuntimeVertexDef {
let mut buffers = Vec::new(); let mut buffers = Vec::new();
@ -21,6 +25,7 @@ impl RuntimeVertexDef {
let mut num_vertices = u32::max_value(); let mut num_vertices = u32::max_value();
// for (attribute_id, attribute) in primitive.attributes().enumerate() { // for (attribute_id, attribute) in primitive.attributes().enumerate() {
// let (name, accessor) = match attribute.clone() { // let (name, accessor) = match attribute.clone() {
// Attribute::Positions(accessor) => ("i_position".to_owned(), accessor), // Attribute::Positions(accessor) => ("i_position".to_owned(), accessor),
@ -70,16 +75,29 @@ impl RuntimeVertexDef {
&self.vertex_buffer_ids &self.vertex_buffer_ids
} }
} }
/// Implementing VertexDefinition
unsafe impl<I> VertexDefinition<I> for RuntimeVertexDef unsafe impl<I> VertexDefinition<I> for RuntimeVertexDef
where I: ShaderInterfaceDef where I: ShaderInterfaceDef
{ {
/// Iterator that returns the offset, the stride (in bytes) and input rate of each buffer.
type BuffersIter = VecIntoIter<(u32, usize, InputRate)>; type BuffersIter = VecIntoIter<(u32, usize, InputRate)>;
/// Iterator that returns the attribute location, buffer id, and infos.
type AttribsIter = VecIntoIter<(u32, u32, AttributeInfo)>; 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) fn definition(&self, interface: &I)
-> Result<(Self::BuffersIter, Self::AttribsIter), IncompatibleVertexDefinitionError> -> Result<(Self::BuffersIter, Self::AttribsIter), IncompatibleVertexDefinitionError>
{ {
let buffers_iter = self.buffers.clone().into_iter(); let buffers_iter = self.buffers.clone().into_iter();
let mut attribs_iter = self.attributes.iter().map(|&(ref name, buffer_id, ref infos)| { let mut attribs_iter = self.attributes.iter().map(|&(ref name, buffer_id, ref infos)| {
@ -92,6 +110,7 @@ unsafe impl<I> VertexDefinition<I> for RuntimeVertexDef
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
// Add dummy attributes. // Add dummy attributes.
// Binding is
for binding in interface.elements() { for binding in interface.elements() {
if attribs_iter.iter().any(|a| a.0 == binding.location.start) { if attribs_iter.iter().any(|a| a.0 == binding.location.start) {
continue; continue;
@ -105,10 +124,15 @@ unsafe impl<I> VertexDefinition<I> for RuntimeVertexDef
} }
} }
/// I don't know what the fuck is going on here... It just repackages the buffs
unsafe impl VertexSource<Vec<Arc<dyn BufferAccess + Send + Sync>>> for RuntimeVertexDef { unsafe impl VertexSource<Vec<Arc<dyn BufferAccess + Send + Sync>>> for RuntimeVertexDef {
fn decode(&self, bufs: Vec<Arc<dyn BufferAccess + Send + Sync>>) fn decode(&self, bufs: Vec<Arc<dyn BufferAccess + Send + Sync>>)
-> (Vec<Box<dyn BufferAccess + Send + Sync>>, usize, usize) -> (Vec<Box<dyn BufferAccess + Send + Sync>>, 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
)
} }
} }
Loading…
Cancel
Save