From 554e8d551e46180d304e18ef08321c96db9c6446 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Tue, 15 Oct 2019 00:08:43 -0700 Subject: [PATCH] Got the vertex definition into the load function. Which is something --- notes/vkprocessor.drawio | 1 + src/canvas/canvas_frame.rs | 30 ++++++++++++++++++++++++++--- src/canvas/canvas_state.rs | 5 +++-- src/canvas/shader/common.rs | 2 +- src/canvas/shader/generic_shader.rs | 5 +++-- src/canvas/shader/text_shader.rs | 6 +++--- src/main.rs | 4 ++-- src/sprite.rs | 6 +++--- src/vkprocessor.rs | 12 +++++++----- 9 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 notes/vkprocessor.drawio diff --git a/notes/vkprocessor.drawio b/notes/vkprocessor.drawio new file mode 100644 index 00000000..e025c387 --- /dev/null +++ b/notes/vkprocessor.drawio @@ -0,0 +1 @@ +7V3bkps4EP2aqdp9sAskro9zycxkd1I1tZPKJo8aLNskGLlAzCVfv5JBNiDZxjZYsIkfJiAkDKe7j1rdLecCXi/e7hK0nH8iExxdAGPydgFvLgAwPc9j//CW96IFGDBvmSXhpGjbNDyFP3HRaBStWTjBaaUjJSSi4bLaGJA4xgGttKEkIa/VblMSVb91iWbFNxqbhqcARVjq9m84oXPxdOyzuXKPw9mcSpcWSPQvGtI5mpDXUhP8cAGvE0JofrR4u8YRB1BAk4+73XJ1/WwJjmmTAeBqEbow87OZ+SOdPXx/uLt5G5nFbV5QlBUvfY3iF5R+xm80S/AFcCJ296vnhB3N+JHulhWU9F2IKCFZPMH8FQ12+XUeUvy0RAG/+sq0krXN6SJiZ+Z6dBky8fo4ofit1FRAeIfJAtPknXUprlpCvoVOj0wI8obXkoZ4Rad5WTesohEVWjlb33wjNXZQCO4QIYItQvy44Ar+W4RVEdp+XYTCRMsi9M8rQrhFhLeEvedvCVYl6EoSNI2xrd0MHVmGZLEMI7yaH8MgfQyXOApjhUn+EcYUJ1OOGZ+nEo5Q0flP7XBDtwq3CYAKbUuBttMZ2O4Wg9GO1h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hhHdrr53f/cIjf/gwL88B8= \ No newline at end of file diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index e1dded8b..0c9938a8 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -53,20 +53,44 @@ impl CanvasFrame { } } + +struct Pair { + x: T, + y: T, +} + +impl Pair { + fn new(x: Vertex3D, y: Vertex3D) -> Self { + Self { + x, + y, + } + } +} + +impl Pair { + fn new(x: GlyphInstance, y: GlyphInstance) -> Self { + Self { + x, + y, + } + } +} + pub struct GenericCanvasFrame { frame_data: HashMap, Vec)>> } -impl GenericCanvasFrame { +impl GenericCanvasFrame { /// Creates a bare canvas frame with empty accumulators - pub fn new() -> GenericCanvasFrame where H: Eq + Hash { + pub fn new() -> GenericCanvasFrame { GenericCanvasFrame { frame_data: Default::default() } } - pub fn draw(&mut self, drawable: &dyn DrawableTest) where H: Eq + Hash + Clone { + pub fn draw(&mut self, drawable: &dyn DrawableTest) { self.frame_data .entry(drawable.get_handle().clone()) .or_insert(Vec::new()) diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index ff19f64e..ebb9d7cf 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -318,16 +318,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(&mut self, + pub fn load_shader(&mut self, filename: String, physical: PhysicalDevice, capabilities: Capabilities) -> Option> where T: CompiledGraphicsPipeline { + let handle = Arc::new(CompiledGraphicsPipelineHandle { handle: self.shader_buffers.len() as u32 }); - let shader: Box = Box::new(T::new( + let shader: Box = Box::new(T::new::( filename.clone(), self.device.clone(), handle.clone(), diff --git a/src/canvas/shader/common.rs b/src/canvas/shader/common.rs index 8085e05c..7562a3bf 100644 --- a/src/canvas/shader/common.rs +++ b/src/canvas/shader/common.rs @@ -103,7 +103,7 @@ pub struct CompiledGraphicsPipelineHandle { } pub trait CompiledGraphicsPipeline { - fn new(filename: String, + fn new(filename: String, device: Arc, handle: Arc, render_pass: Arc) -> Self where Self: Sized; diff --git a/src/canvas/shader/generic_shader.rs b/src/canvas/shader/generic_shader.rs index d84fe7e4..cbf677fb 100644 --- a/src/canvas/shader/generic_shader.rs +++ b/src/canvas/shader/generic_shader.rs @@ -39,7 +39,7 @@ impl CompiledGraphicsPipelineResources for GenericShader {} impl CompiledGraphicsPipeline for GenericShader { /// This will explode when the shader does not want to compile - fn new(filename: String, + fn new(filename: String, device: Arc, handle: Arc, render_pass: Arc) -> GenericShader { @@ -78,7 +78,8 @@ impl CompiledGraphicsPipeline for GenericShader { graphics_pipeline: Some(Arc::new(GraphicsPipeline::start() - .vertex_input(SingleBufferDefinition::::new()) + //SingleBufferDefinition:: + .vertex_input(T::new()) .vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants { first_constant: 0, diff --git a/src/canvas/shader/text_shader.rs b/src/canvas/shader/text_shader.rs index cf3584bc..b0bcc20f 100644 --- a/src/canvas/shader/text_shader.rs +++ b/src/canvas/shader/text_shader.rs @@ -45,7 +45,7 @@ impl CompiledGraphicsPipelineResources for TextShader {} impl CompiledGraphicsPipeline for TextShader { /// This will explode when the shader does not want to compile - fn new(filename: String, + fn new(filename: String, device: Arc, handle: Arc, render_pass: Arc) -> TextShader { @@ -107,8 +107,8 @@ impl CompiledGraphicsPipeline for TextShader { TextShader { graphics_pipeline: Some(Arc::new(GraphicsPipeline::start() - - .vertex_input(OneVertexOneInstanceDefinition::::new()) +//OneVertexOneInstanceDefinition:: + .vertex_input(T::new()) .vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants { first_constant: 0, diff --git a/src/main.rs b/src/main.rs index dd6e4962..81d2df49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -169,8 +169,8 @@ pub fn main() { canvas.draw(&funky_sprite); canvas.draw(&test_polygon); - let mut gencanvas = GenericCanvasFrame::new(); - gencanvas.draw(&text_sprite); +// let mut gencanvas = GenericCanvasFrame::new(); +// gencanvas.draw(&text_sprite); { diff --git a/src/sprite.rs b/src/sprite.rs index 5d4f4213..99deeaeb 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -97,8 +97,8 @@ impl Sprite { } } -impl DrawableTest for Sprite { - fn get_vertices(&self) -> Vec { +impl DrawableTest for Sprite { + fn get_vertices(&self) -> Vec { unimplemented!() } @@ -301,7 +301,7 @@ pub trait TextVertex { fn get_vertices() -> Vec<(u32, u32, u32)>; } -impl DrawableTest for Text { +impl DrawableTest for Text { fn get_vertices(&self) -> Vec { unimplemented!() } diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index a36b1914..9002d8b4 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -19,7 +19,9 @@ use std::time::Duration; use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags}; use crate::canvas::shader::common::CompiledGraphicsPipelineHandle; use crate::canvas::shader::generic_shader::GenericShader; -use crate::canvas::shader::text_shader::TextShader; +use crate::canvas::shader::text_shader::{TextShader, GlyphInstance}; +use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition}; +use crate::util::vertex_3d::Vertex3D; /// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states /// @@ -157,10 +159,10 @@ impl<'a> VkProcessor<'a> { /// A hardcoded list of shaders which can be proloaded from this function pub fn preload_shaders(&mut self) { - self.canvas_state.load_shader::(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone()); - self.canvas_state.load_shader::(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone()); - self.canvas_state.load_shader::(String::from("simple_image"), self.physical.clone(), self.capabilities.clone()); - self.canvas_state.load_shader::(String::from("simple_text"), self.physical.clone(), self.capabilities.clone()); + self.canvas_state.load_shader::>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone()); + self.canvas_state.load_shader::>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone()); + self.canvas_state.load_shader::>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone()); + self.canvas_state.load_shader::>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone()); } /// A hardcoded list of shaders which can be proloaded from this function