Sorta want this type of API, but, CanvasFrame would be tied to a single type...

master
mitchellhansen 5 years ago
parent 0c1f513225
commit 1597f0e380

@ -40,6 +40,11 @@ Drawable needs a few things:
(vertices will be character data for text) (vertices will be character data for text)
Instances? Instances?
The handle is queiried and then turned into a descriptor set in the draw_commands.
-------------------- --------------------
===== Data ===== ===== Data =====

@ -6,37 +6,54 @@ use crate::canvas::*;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance; 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 // I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<V, H, In> where H: Handle{ pub trait DrawableTest<V, H> where H: Handle{
fn get_vertices(&self) -> Vec<V>; fn get_vertices(&self) -> Vec<V>;
fn get_instances(&self) -> Vec<In>;
fn get_handle(&self) -> H; fn get_handle(&self) -> H;
} }
pub struct DrawableTestee { pub struct DrawableTestee {
pub vertices: Vec<u32>, pub vertices: Vec<ImplVertexData>,
pub instances: Vec<u32>,
pub handle: Arc<CanvasTextureHandle> pub handle: Arc<CanvasTextureHandle>
} }
impl<V, H: Handle, In> DrawableTest<V, H, In> for DrawableTestee { impl<V, H: Handle> DrawableTest<V, H> for DrawableTestee {
fn get_vertices(&self) -> Vec<V> { fn get_vertices(&self) -> Vec<V> {
unimplemented!() unimplemented!()
} }
fn get_instances(&self) -> Vec<In> {
unimplemented!()
}
fn get_handle(&self) -> H { fn get_handle(&self) -> H {
unimplemented!() 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<V: VertexData + Sized, H: Handle + Sized> {
pub map: HashMap<H, Vec<V>>,
}
impl<V: VertexData + Sized, H: Handle + Sized + Eq + Hash> CanvasFrameTest<V, H> {
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, H>) {
drawable.get_vertices();
self.map.insert(drawable.get_handle(), drawable.get_vertices());
}
}
pub trait Drawable { pub trait Drawable {
@ -62,10 +79,15 @@ pub trait Drawable {
} }
} }
pub trait VertexDefinitionAndData { pub trait VertexDefinitionAndData {
} }
pub struct CanvasFrame { pub struct CanvasFrame {
pub colored_drawables: Vec<RuntimeVertexDef>, pub colored_drawables: Vec<RuntimeVertexDef>,
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>, pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
@ -85,7 +107,6 @@ impl CanvasFrame {
} }
} }
//
// pub fn draw_test<V : VertexDefinitionAndData, H: Handle, In>(&mut self, drawable: &dyn DrawableTest<V, H, In>) { // pub fn draw_test<V : VertexDefinitionAndData, H: Handle, In>(&mut self, drawable: &dyn DrawableTest<V, H, In>) {
// let h = drawable.get_handle(); // let h = drawable.get_handle();
// //

@ -18,7 +18,7 @@ use vulkano::swapchain::Capabilities;
use winit::Window; use winit::Window;
use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::viewport::Viewport;
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer; 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 std::hash::Hash;
use crate::util::vertex_3d::{Vertex3D, TextVertex3D}; use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue}; 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; 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 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 /// Canvas state also contains logic for writing the stored buffers to the command_buffer
#[derive(Clone)] #[derive(Clone)]
@ -276,7 +274,6 @@ impl CanvasState {
physical: PhysicalDevice, physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>> capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
where T: CompiledGraphicsPipeline { where T: CompiledGraphicsPipeline {
let handle = Arc::new(CompiledShaderHandle { let handle = Arc::new(CompiledShaderHandle {
handle: self.shader_buffers.len() as u32 handle: self.shader_buffers.len() as u32
}); });
@ -314,7 +311,7 @@ impl CanvasState {
for i in (0..255) { for i in (0..255) {
let glyph = font.glyph('d'); 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(); let shape = s.shape().unwrap();
@ -325,7 +322,7 @@ impl CanvasState {
accumulator.push(TextVertex3D { accumulator.push(TextVertex3D {
position: [l.p[0].x as f32, l.p[0].y as f32, 0.0], position: [l.p[0].x as f32, l.p[0].y as f32, 0.0],
}); });
}, }
Segment::Curve(c) => { Segment::Curve(c) => {
accumulator.push(TextVertex3D { accumulator.push(TextVertex3D {
position: [c.p[0].x as f32, c.p[0].y as f32, 0.0], position: [c.p[0].x as f32, c.p[0].y as f32, 0.0],
@ -487,6 +484,27 @@ impl CanvasState {
o 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<V: 'static + VertexData + Sized + Clone + Send + Sync, H: Handle + Sized>
(&mut self,
mut command_buffer: AutoCommandBufferBuilder,
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
image_num: usize,
canvas_frame: CanvasFrameTest<V, H>) -> AutoCommandBufferBuilder {
let v = Vec::<V>::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 /// 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 /// image number to be passed in as they are taken care of by the vkprocessor
pub fn draw_commands(&mut self, pub fn draw_commands(&mut self,

@ -25,9 +25,10 @@ use crate::util::load_raw;
use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance}; use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance};
use vulkano::instance::debug::DebugCallback; use vulkano::instance::debug::DebugCallback;
use crate::compute::compu_frame::CompuFrame; 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 crate::compute::managed::compu_sprite::CompuSprite;
use std::sync::Arc; use std::sync::Arc;
use crate::canvas::managed::handles::CanvasTextureHandle;
pub mod util; pub mod util;
@ -87,15 +88,7 @@ pub fn main() {
processor.preload_fonts(); 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"); let q2 = hprof::enter("Game Objects");
@ -189,6 +182,13 @@ pub fn main() {
break; break;
} }
let dt = DrawableTestee{
vertices: vec![ImplVertexData{ x: 0, y: 0 }],
handle: Arc::new(Default::default())
};
let mut cft :CanvasFrameTest<ImplVertexData, CanvasTextureHandle>= CanvasFrameTest{ map: Default::default() };
cft.draw(&dt);
let mut compu_frame = CompuFrame::new(); let mut compu_frame = CompuFrame::new();
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); // compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); // compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);

@ -265,9 +265,9 @@ impl<'a> VkProcessor<'a> {
drop(g); drop(g);
{ {
let g = hprof::enter("Canvas creates GPU buffers");
// take the canvas frame and create the vertex buffers // take the canvas frame and create the vertex buffers
// TODO: This performs gpu buffer creation. Shouldn't be in hotpath?? // 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); self.canvas_state.draw(canvas_frame);
} }

Loading…
Cancel
Save