doing some hardcore storming on this dynamic vertex situation
This commit is contained in:
@@ -13,6 +13,70 @@ pub struct CanvasFrame {
|
||||
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 {
|
||||
|
||||
/// 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> {
|
||||
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
|
||||
/// 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,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
|
||||
where T: CompiledGraphicsPipeline, V: VertexDefinition {
|
||||
where T: CompiledGraphicsPipeline {
|
||||
|
||||
let handle = Arc::new(CompiledGraphicsPipelineHandle {
|
||||
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(),
|
||||
self.device.clone(),
|
||||
handle.clone(),
|
||||
|
||||
@@ -103,7 +103,7 @@ pub struct CompiledGraphicsPipelineHandle {
|
||||
}
|
||||
|
||||
pub trait CompiledGraphicsPipeline {
|
||||
fn new<T>(filename: String,
|
||||
fn new(filename: String,
|
||||
device: Arc<Device>,
|
||||
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||
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 {
|
||||
buffers: Vec<(u32, usize, InputRate)>,
|
||||
vertex_buffer_ids: Vec<(usize, usize)>,
|
||||
@@ -6,50 +13,50 @@ pub struct RuntimeVertexDef {
|
||||
}
|
||||
|
||||
impl RuntimeVertexDef {
|
||||
pub fn from_primitive(primitive: gltf::Primitive) -> RuntimeVertexDef {
|
||||
use gltf::mesh::Attribute;
|
||||
use gltf::accessor::{DataType, Dimensions};
|
||||
|
||||
pub fn from_primitive(primitive: u32) -> RuntimeVertexDef {
|
||||
// use gltf::mesh::Attribute;
|
||||
// use gltf::accessor::{DataType, Dimensions};
|
||||
//
|
||||
let mut buffers = Vec::new();
|
||||
let mut vertex_buffer_ids = Vec::new();
|
||||
let mut attributes = Vec::new();
|
||||
|
||||
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),
|
||||
Attribute::Normals(accessor) => ("i_normal".to_owned(), accessor),
|
||||
Attribute::Tangents(accessor) => ("i_tangent".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(1, accessor) => ("i_texcoord_1".to_owned(), accessor),
|
||||
Attribute::Joints(0, accessor) => ("i_joints_0".to_owned(), accessor),
|
||||
Attribute::Weights(0, accessor) => ("i_weights_0".to_owned(), accessor),
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
if (accessor.count() as u32) < num_vertices {
|
||||
num_vertices = accessor.count() as u32;
|
||||
}
|
||||
|
||||
let infos = AttributeInfo {
|
||||
offset: 0,
|
||||
format: match (accessor.data_type(), accessor.dimensions()) {
|
||||
(DataType::I8, Dimensions::Scalar) => Format::R8Snorm,
|
||||
(DataType::U8, Dimensions::Scalar) => Format::R8Unorm,
|
||||
(DataType::F32, Dimensions::Vec2) => Format::R32G32Sfloat,
|
||||
(DataType::F32, Dimensions::Vec3) => Format::R32G32B32Sfloat,
|
||||
(DataType::F32, Dimensions::Vec4) => Format::R32G32B32A32Sfloat,
|
||||
_ => unimplemented!()
|
||||
},
|
||||
};
|
||||
|
||||
let view = accessor.view();
|
||||
buffers.push((attribute_id as u32, view.stride().unwrap_or(accessor.size()), InputRate::Vertex));
|
||||
attributes.push((name, attribute_id as u32, infos));
|
||||
vertex_buffer_ids.push((view.buffer().index(), view.offset() + accessor.offset()));
|
||||
}
|
||||
//
|
||||
// for (attribute_id, attribute) in primitive.attributes().enumerate() {
|
||||
// let (name, accessor) = match attribute.clone() {
|
||||
// Attribute::Positions(accessor) => ("i_position".to_owned(), accessor),
|
||||
// Attribute::Normals(accessor) => ("i_normal".to_owned(), accessor),
|
||||
// Attribute::Tangents(accessor) => ("i_tangent".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(1, accessor) => ("i_texcoord_1".to_owned(), accessor),
|
||||
// Attribute::Joints(0, accessor) => ("i_joints_0".to_owned(), accessor),
|
||||
// Attribute::Weights(0, accessor) => ("i_weights_0".to_owned(), accessor),
|
||||
// _ => unimplemented!(),
|
||||
// };
|
||||
//
|
||||
// if (accessor.count() as u32) < num_vertices {
|
||||
// num_vertices = accessor.count() as u32;
|
||||
// }
|
||||
//
|
||||
// let infos = AttributeInfo {
|
||||
// offset: 0,
|
||||
// format: match (accessor.data_type(), accessor.dimensions()) {
|
||||
// (DataType::I8, Dimensions::Scalar) => Format::R8Snorm,
|
||||
// (DataType::U8, Dimensions::Scalar) => Format::R8Unorm,
|
||||
// (DataType::F32, Dimensions::Vec2) => Format::R32G32Sfloat,
|
||||
// (DataType::F32, Dimensions::Vec3) => Format::R32G32B32Sfloat,
|
||||
// (DataType::F32, Dimensions::Vec4) => Format::R32G32B32A32Sfloat,
|
||||
// _ => unimplemented!()
|
||||
// },
|
||||
// };
|
||||
//
|
||||
// let view = accessor.view();
|
||||
// buffers.push((attribute_id as u32, view.stride().unwrap_or(accessor.size()), InputRate::Vertex));
|
||||
// attributes.push((name, attribute_id as u32, infos));
|
||||
// vertex_buffer_ids.push((view.buffer().index(), view.offset() + accessor.offset()));
|
||||
// }
|
||||
|
||||
RuntimeVertexDef {
|
||||
buffers: buffers,
|
||||
@@ -100,9 +107,9 @@ unsafe impl<I> VertexDefinition<I> for RuntimeVertexDef
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl VertexSource<Vec<Arc<BufferAccess + Send + Sync>>> for RuntimeVertexDef {
|
||||
fn decode(&self, bufs: Vec<Arc<BufferAccess + Send + Sync>>)
|
||||
-> (Vec<Box<BufferAccess + Send + Sync>>, usize, usize)
|
||||
unsafe impl VertexSource<Vec<Arc<dyn BufferAccess + Send + Sync>>> for RuntimeVertexDef {
|
||||
fn decode(&self, bufs: Vec<Arc<dyn BufferAccess + Send + Sync>>)
|
||||
-> (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)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ impl CompiledGraphicsPipelineResources for GenericShader {}
|
||||
impl CompiledGraphicsPipeline for GenericShader {
|
||||
|
||||
/// This will explode when the shader does not want to compile
|
||||
fn new<T: VertexDefinition>(filename: String,
|
||||
fn new(filename: String,
|
||||
device: Arc<Device>,
|
||||
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::canvas::shader::common::CompiledGraphicsPipeline;
|
||||
pub mod common;
|
||||
pub mod generic_shader;
|
||||
pub mod text_shader;
|
||||
use mod dynamic_vertex;
|
||||
pub mod dynamic_vertex;
|
||||
|
||||
use crate::canvas::shader::common::*;
|
||||
use crate::canvas::shader::generic_shader::*;
|
||||
|
||||
Reference in New Issue
Block a user