doing some hardcore storming on this dynamic vertex situation

master
mitchellhansen 5 years ago
parent c4b20bcd79
commit ffa04d0bb1

@ -0,0 +1 @@
<mxfile host="Electron" modified="2019-10-17T05:29:15.668Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/12.1.0 Chrome/76.0.3809.139 Electron/6.0.7 Safari/537.36" etag="Jx9s5H1g1OmlROooa6iA" version="12.1.0" type="device" pages="1"><diagram id="207_h35IBA5InrABCH76" name="Page-1">7Vtdb+I4FP01SDMPVPkiwGOBdmelzk41VDPbp5WbmMRbE0eOKTC/fq8ThxAcCt2SJoyQKjW+dkxyzr33XNvQscfz1R8cxeFX5mPasQx/1bEnHcuyDXsA/6RlnVnMQd/NLAEnvrIVhin5hZXRUNYF8XFSGigYo4LEZaPHogh7omRDnLNlediM0fKnxijAmmHqIapbfxJfhMo6tIyi4wsmQZh/tGWonjnKRytDEiKfLbdM9k3HHnPGRHY1X40xlfDlwGT33e7p3TwZx5E45oaf9uPDX9Nn+y6cXn/DS/dltoi6io0XRBfqjR/wSqgHFuschmRJ5hRF0BrNWCSmqseENqIkiODag8fAHAwvmAsCCF6rDsFisHohof4dWrOFfNhEIO85b41CxskvmBZRNSd0c6GcwXJLI6byTjAbYOU4gTH3OQLmjukrWpUG3qFEKIPHKEVxQp42rzFHPCDRiAnB5mqQggZeB6/2Ym5umIQgwGyOBV/DEHXDUHGv3N/O3Xq55UuusoVbbjRQvCDlvsFm5oJguFAcv4HvvsZ3xxrJwCBYRsa1jK91jDUHENIrJDGcPeMxowyYnkQs8whC6Y4pdwqKZ2KvSyQx8kgU3KVjJk5h+a6AkCYG985oGjch8X0cSTqZQAJl3EmiYkYikSLVG8Ef4Dk2rnqdHjz4GNpm0YY/OZyLMYvgXRBJacTgGEssneM4zvdHku4IinnLPY54qy7iBxXE73BMScpdxnGe7cz/RfAcqKK4YPRBEj7pmhrrts66XcEwRU+Y3rOECMLk/Dwbu8N8U+T2rCOjuiZu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3RJtQY6oY/vak/C91elJlAgUwQKi+b3rrmkNW7d57VQUzYVonmM0fKRiQrP4nWxWxxS/N7Zv/gM=</diagram></mxfile>

@ -13,6 +13,70 @@ pub struct CanvasFrame {
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>> pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
} }
/*
This is sort of the beginning of our interface with the user definable sprites.
Will be taking in multiple type of items
TEXT
FontHandle
VertexDefintion
color
position
instances (string)
Textured
TextureHandle
VertexDefintion
position
coords
size
Vertex definition is directly correlated to the compiled code. How do I bucket these
I guess I could store them and set handles like I do textures
The only ent that can create these vertex handles is the vkprocessor.
So Text can only get a vertex definition by going like shader.get_definition()
Text
FontHandle
VertexHandle
Drawable must include
shader_handle (but how to I get this to the text? this is runtime)
Okay, no. Maybe a default shader type of setup. With a shader handle override????
Type: Text
Textured
Img
Color
frame.draw(text) {
text.type == TEXT { // When it matches to default text shader
text_shader.get_definition()
text_shader.get_pipeline()
}
...
else { // When the user passes in a shader
text.shader_handle.get_definition()
text.shader_handle.get_pipeline()
}
}
// Has default shader
let text = Text::new("asdoif");
let frame = CanvasFrame::new();
frame.draw(text);
vkprocessor.run(frame);
*/
impl CanvasFrame { impl CanvasFrame {
/// Creates a bare canvas frame with empty accumulators /// Creates a bare canvas frame with empty accumulators
@ -53,30 +117,6 @@ impl CanvasFrame {
} }
} }
struct Pair<T> {
x: T,
y: T,
}
impl Pair<Vertex3D> {
fn new(x: Vertex3D, y: Vertex3D) -> Self {
Self {
x,
y,
}
}
}
impl Pair<GlyphInstance> {
fn new(x: GlyphInstance, y: GlyphInstance) -> Self {
Self {
x,
y,
}
}
}
pub struct GenericCanvasFrame<H, V, In> { pub struct GenericCanvasFrame<H, V, In> {
frame_data: HashMap<H, Vec<(Vec<V>, Vec<In>)>> frame_data: HashMap<H, Vec<(Vec<V>, Vec<In>)>>
} }

@ -319,17 +319,17 @@ impl CanvasState {
/// Load and Compile a shader with the filename at resources/shaders /// Load and Compile a shader with the filename at resources/shaders
/// Takes physical and capabilities as we don't store that in Canvas /// Takes physical and capabilities as we don't store that in Canvas
pub fn load_shader<T: 'static, V>(&mut self, pub fn load_shader<T: 'static>(&mut self,
filename: String, filename: String,
physical: PhysicalDevice, physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>> capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
where T: CompiledGraphicsPipeline, V: VertexDefinition { where T: CompiledGraphicsPipeline {
let handle = Arc::new(CompiledGraphicsPipelineHandle { let handle = Arc::new(CompiledGraphicsPipelineHandle {
handle: self.shader_buffers.len() as u32 handle: self.shader_buffers.len() as u32
}); });
let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new::<V>( let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new(
filename.clone(), filename.clone(),
self.device.clone(), self.device.clone(),
handle.clone(), handle.clone(),

@ -103,7 +103,7 @@ pub struct CompiledGraphicsPipelineHandle {
} }
pub trait CompiledGraphicsPipeline { pub trait CompiledGraphicsPipeline {
fn new<T>(filename: String, fn new(filename: String,
device: Arc<Device>, device: Arc<Device>,
handle: Arc<CompiledGraphicsPipelineHandle>, handle: Arc<CompiledGraphicsPipelineHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized; render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized;

@ -1,3 +1,10 @@
use vulkano::pipeline::vertex::{VertexDefinition, InputRate, AttributeInfo, IncompatibleVertexDefinitionError, VertexSource};
use vulkano::pipeline::shader::ShaderInterfaceDef;
use vulkano::buffer::BufferAccess;
use std::sync::Arc;
use cgmath::num_traits::real::Real;
use std::vec::IntoIter as VecIntoIter;
pub struct RuntimeVertexDef { pub struct RuntimeVertexDef {
buffers: Vec<(u32, usize, InputRate)>, buffers: Vec<(u32, usize, InputRate)>,
vertex_buffer_ids: Vec<(usize, usize)>, vertex_buffer_ids: Vec<(usize, usize)>,
@ -6,50 +13,50 @@ pub struct RuntimeVertexDef {
} }
impl RuntimeVertexDef { impl RuntimeVertexDef {
pub fn from_primitive(primitive: gltf::Primitive) -> RuntimeVertexDef { pub fn from_primitive(primitive: u32) -> RuntimeVertexDef {
use gltf::mesh::Attribute; // use gltf::mesh::Attribute;
use gltf::accessor::{DataType, Dimensions}; // use gltf::accessor::{DataType, Dimensions};
//
let mut buffers = Vec::new(); let mut buffers = Vec::new();
let mut vertex_buffer_ids = Vec::new(); let mut vertex_buffer_ids = Vec::new();
let mut attributes = Vec::new(); let mut attributes = Vec::new();
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),
Attribute::Normals(accessor) => ("i_normal".to_owned(), accessor), // Attribute::Normals(accessor) => ("i_normal".to_owned(), accessor),
Attribute::Tangents(accessor) => ("i_tangent".to_owned(), accessor), // Attribute::Tangents(accessor) => ("i_tangent".to_owned(), accessor),
Attribute::Colors(0, accessor) => ("i_color_0".to_owned(), accessor), // Attribute::Colors(0, accessor) => ("i_color_0".to_owned(), accessor),
Attribute::TexCoords(0, accessor) => ("i_texcoord_0".to_owned(), accessor), // Attribute::TexCoords(0, accessor) => ("i_texcoord_0".to_owned(), accessor),
Attribute::TexCoords(1, accessor) => ("i_texcoord_1".to_owned(), accessor), // Attribute::TexCoords(1, accessor) => ("i_texcoord_1".to_owned(), accessor),
Attribute::Joints(0, accessor) => ("i_joints_0".to_owned(), accessor), // Attribute::Joints(0, accessor) => ("i_joints_0".to_owned(), accessor),
Attribute::Weights(0, accessor) => ("i_weights_0".to_owned(), accessor), // Attribute::Weights(0, accessor) => ("i_weights_0".to_owned(), accessor),
_ => unimplemented!(), // _ => unimplemented!(),
}; // };
//
if (accessor.count() as u32) < num_vertices { // if (accessor.count() as u32) < num_vertices {
num_vertices = accessor.count() as u32; // num_vertices = accessor.count() as u32;
} // }
//
let infos = AttributeInfo { // let infos = AttributeInfo {
offset: 0, // offset: 0,
format: match (accessor.data_type(), accessor.dimensions()) { // format: match (accessor.data_type(), accessor.dimensions()) {
(DataType::I8, Dimensions::Scalar) => Format::R8Snorm, // (DataType::I8, Dimensions::Scalar) => Format::R8Snorm,
(DataType::U8, Dimensions::Scalar) => Format::R8Unorm, // (DataType::U8, Dimensions::Scalar) => Format::R8Unorm,
(DataType::F32, Dimensions::Vec2) => Format::R32G32Sfloat, // (DataType::F32, Dimensions::Vec2) => Format::R32G32Sfloat,
(DataType::F32, Dimensions::Vec3) => Format::R32G32B32Sfloat, // (DataType::F32, Dimensions::Vec3) => Format::R32G32B32Sfloat,
(DataType::F32, Dimensions::Vec4) => Format::R32G32B32A32Sfloat, // (DataType::F32, Dimensions::Vec4) => Format::R32G32B32A32Sfloat,
_ => unimplemented!() // _ => unimplemented!()
}, // },
}; // };
//
let view = accessor.view(); // let view = accessor.view();
buffers.push((attribute_id as u32, view.stride().unwrap_or(accessor.size()), InputRate::Vertex)); // buffers.push((attribute_id as u32, view.stride().unwrap_or(accessor.size()), InputRate::Vertex));
attributes.push((name, attribute_id as u32, infos)); // attributes.push((name, attribute_id as u32, infos));
vertex_buffer_ids.push((view.buffer().index(), view.offset() + accessor.offset())); // vertex_buffer_ids.push((view.buffer().index(), view.offset() + accessor.offset()));
} // }
RuntimeVertexDef { RuntimeVertexDef {
buffers: buffers, buffers: buffers,
@ -100,9 +107,9 @@ unsafe impl<I> VertexDefinition<I> for RuntimeVertexDef
} }
} }
unsafe impl VertexSource<Vec<Arc<BufferAccess + Send + Sync>>> for RuntimeVertexDef { unsafe impl VertexSource<Vec<Arc<dyn BufferAccess + Send + Sync>>> for RuntimeVertexDef {
fn decode(&self, bufs: Vec<Arc<BufferAccess + Send + Sync>>) fn decode(&self, bufs: Vec<Arc<dyn BufferAccess + Send + Sync>>)
-> (Vec<Box<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(), self.num_vertices as usize, 1)
} }

@ -40,7 +40,7 @@ impl CompiledGraphicsPipelineResources for GenericShader {}
impl CompiledGraphicsPipeline for GenericShader { impl CompiledGraphicsPipeline for GenericShader {
/// This will explode when the shader does not want to compile /// This will explode when the shader does not want to compile
fn new<T: VertexDefinition>(filename: String, fn new(filename: String,
device: Arc<Device>, device: Arc<Device>,
handle: Arc<CompiledGraphicsPipelineHandle>, handle: Arc<CompiledGraphicsPipelineHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader { render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {

@ -3,7 +3,7 @@ use crate::canvas::shader::common::CompiledGraphicsPipeline;
pub mod common; pub mod common;
pub mod generic_shader; pub mod generic_shader;
pub mod text_shader; pub mod text_shader;
use mod dynamic_vertex; pub mod dynamic_vertex;
use crate::canvas::shader::common::*; use crate::canvas::shader::common::*;
use crate::canvas::shader::generic_shader::*; use crate::canvas::shader::generic_shader::*;

Loading…
Cancel
Save