diff --git a/notes/CanvasFrame.txt b/notes/CanvasFrame.txt index 1a4f182a..cb0acb3a 100644 --- a/notes/CanvasFrame.txt +++ b/notes/CanvasFrame.txt @@ -40,6 +40,11 @@ Drawable needs a few things: (vertices will be character data for text) Instances? +The handle is queiried and then turned into a descriptor set in the draw_commands. + + + + -------------------- ===== Data ===== diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index 70050252..4a215dea 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -6,37 +6,54 @@ use crate::canvas::*; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle}; use crate::canvas::managed::shader::text_shader::GlyphInstance; +use vulkano::pipeline::vertex::Vertex; // I don't think this is going to work without getting into Box'ing -pub trait DrawableTest where H: Handle{ +pub trait DrawableTest where H: Handle{ fn get_vertices(&self) -> Vec; - fn get_instances(&self) -> Vec; fn get_handle(&self) -> H; } pub struct DrawableTestee { - pub vertices: Vec, - pub instances: Vec, + pub vertices: Vec, pub handle: Arc } -impl DrawableTest for DrawableTestee { +impl DrawableTest for DrawableTestee { fn get_vertices(&self) -> Vec { unimplemented!() } - fn get_instances(&self) -> Vec { - unimplemented!() - } - fn get_handle(&self) -> H { unimplemented!() } } +pub struct ImplVertexData { + pub x: i32, + pub y: i32, +} +impl VertexData for ImplVertexData { + +} + +pub trait VertexData : Sized { + +} + +// CanvasFrameTest will be drawn to by objects implementing DrawableTest +pub struct CanvasFrameTest { + pub map: HashMap>, +} +impl CanvasFrameTest { + pub fn draw(&mut self, drawable: &dyn DrawableTest) { + drawable.get_vertices(); + self.map.insert(drawable.get_handle(), drawable.get_vertices()); + } +} pub trait Drawable { @@ -62,10 +79,15 @@ pub trait Drawable { } } + + + pub trait VertexDefinitionAndData { } + + pub struct CanvasFrame { pub colored_drawables: Vec, pub textured_drawables: HashMap, Vec>>, @@ -85,7 +107,6 @@ impl CanvasFrame { } } - // // pub fn draw_test(&mut self, drawable: &dyn DrawableTest) { // let h = drawable.get_handle(); // diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index 47b69a45..910e7e47 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -18,7 +18,7 @@ use vulkano::swapchain::Capabilities; use winit::Window; use vulkano::pipeline::viewport::Viewport; use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer; -use crate::canvas::canvas_frame::CanvasFrame; +use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest, VertexData}; use std::hash::Hash; use crate::util::vertex_3d::{Vertex3D, TextVertex3D}; use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue}; @@ -35,8 +35,6 @@ use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline; use crate::canvas::managed::shader::generic_shader::GenericShader; - - /// Canvas state is used for storage of texture and image buffers in addition to vertex buffers /// Canvas state also contains logic for writing the stored buffers to the command_buffer #[derive(Clone)] @@ -276,7 +274,6 @@ impl CanvasState { physical: PhysicalDevice, capabilities: Capabilities) -> Option> where T: CompiledGraphicsPipeline { - let handle = Arc::new(CompiledShaderHandle { handle: self.shader_buffers.len() as u32 }); @@ -314,7 +311,7 @@ impl CanvasState { for i in (0..255) { let glyph = font.glyph('d'); - let s = glyph.scaled(Scale{ x: 1.0, y: 1.0 }); + let s = glyph.scaled(Scale { x: 1.0, y: 1.0 }); let shape = s.shape().unwrap(); @@ -325,7 +322,7 @@ impl CanvasState { accumulator.push(TextVertex3D { position: [l.p[0].x as f32, l.p[0].y as f32, 0.0], }); - }, + } Segment::Curve(c) => { accumulator.push(TextVertex3D { position: [c.p[0].x as f32, c.p[0].y as f32, 0.0], @@ -421,7 +418,7 @@ impl CanvasState { let g = hprof::enter("Textured Vertex Buffer"); for (k, v) in textured_drawables.drain() { let vertex_buffer = v.clone().get(0).unwrap().clone(); - // TODO + // TODO // v.clone().iter() // .fold(Vec::new(), |mut a: Vec, b| { // a.extend(b); @@ -487,6 +484,27 @@ impl CanvasState { o } + // This is taking in a canvas frame, which should be some sort of matrix of vertices of generic + // types and handles + pub fn draw_commands_test + (&mut self, + mut command_buffer: AutoCommandBufferBuilder, + framebuffers: Vec>, + image_num: usize, + canvas_frame: CanvasFrameTest) -> AutoCommandBufferBuilder { + + let v = Vec::::new(); + + let x = ImmutableBuffer::from_iter( + v.iter().cloned(), + BufferUsage::all(), + self.queue.clone(), + ).unwrap().0; + + command_buffer + + } + /// Pushes the draw commands to the command buffer. Requires the framebuffers and /// image number to be passed in as they are taken care of by the vkprocessor pub fn draw_commands(&mut self, diff --git a/src/main.rs b/src/main.rs index 7aa05c8a..00178eb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,9 +25,10 @@ use crate::util::load_raw; use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance}; use vulkano::instance::debug::DebugCallback; use crate::compute::compu_frame::CompuFrame; -use crate::canvas::canvas_frame::{CanvasFrame, DrawableTestee}; +use crate::canvas::canvas_frame::{CanvasFrame, DrawableTestee, CanvasFrameTest, ImplVertexData}; use crate::compute::managed::compu_sprite::CompuSprite; use std::sync::Arc; +use crate::canvas::managed::handles::CanvasTextureHandle; pub mod util; @@ -87,15 +88,7 @@ pub fn main() { processor.preload_fonts(); } - let mut v = vec![]; - let d = DrawableTestee { - vertices: vec![], - instances: vec![], - handle: Arc::new(Default::default()) - }; - - v.push(d); let q2 = hprof::enter("Game Objects"); @@ -189,6 +182,13 @@ pub fn main() { break; } + let dt = DrawableTestee{ + vertices: vec![ImplVertexData{ x: 0, y: 0 }], + handle: Arc::new(Default::default()) + }; + let mut cft :CanvasFrameTest= CanvasFrameTest{ map: Default::default() }; + cft.draw(&dt); + let mut compu_frame = CompuFrame::new(); // compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); // compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 1953b6bd..26076842 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -265,9 +265,9 @@ impl<'a> VkProcessor<'a> { drop(g); { - let g = hprof::enter("Canvas creates GPU buffers"); // take the canvas frame and create the vertex buffers // TODO: This performs gpu buffer creation. Shouldn't be in hotpath?? + let g = hprof::enter("Canvas creates GPU buffers"); self.canvas_state.draw(canvas_frame); }