Sorta want this type of API, but, CanvasFrame would be tied to a single type...
This commit is contained in:
@@ -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<V, H, In> where H: Handle{
|
||||
pub trait DrawableTest<V, H> where H: Handle{
|
||||
fn get_vertices(&self) -> Vec<V>;
|
||||
fn get_instances(&self) -> Vec<In>;
|
||||
fn get_handle(&self) -> H;
|
||||
}
|
||||
|
||||
|
||||
pub struct DrawableTestee {
|
||||
pub vertices: Vec<u32>,
|
||||
pub instances: Vec<u32>,
|
||||
pub vertices: Vec<ImplVertexData>,
|
||||
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> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn get_instances(&self) -> Vec<In> {
|
||||
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<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 {
|
||||
|
||||
@@ -62,10 +79,15 @@ pub trait Drawable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
pub trait VertexDefinitionAndData {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub struct CanvasFrame {
|
||||
pub colored_drawables: 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>) {
|
||||
// let h = drawable.get_handle();
|
||||
//
|
||||
|
||||
@@ -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<Arc<CompiledShaderHandle>>
|
||||
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<RuntimeVertexDef>, 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<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
|
||||
/// image number to be passed in as they are taken care of by the vkprocessor
|
||||
pub fn draw_commands(&mut self,
|
||||
|
||||
18
src/main.rs
18
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<ImplVertexData, CanvasTextureHandle>= 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user