Going to just normalize to a single hardcoded enum of vertex definitions. Seems like quite a backpeddle....
This commit is contained in:
@@ -39,8 +39,18 @@ In Shader lie the shader compilers, pipelines, and supporting data.
|
||||
I need to put them where I create them. The actual shader doesn't.
|
||||
|
||||
|
||||
=== canvas frame ===
|
||||
The current workflow:
|
||||
|
||||
enum of vertex types
|
||||
sprite holds vertex::type1
|
||||
poly holds vertex::type2
|
||||
|
||||
canvasframe holds <enumType>
|
||||
|
||||
canvasState.run takes canvasFrame<enumType>
|
||||
|
||||
canvasState.draw_commands_test(command_buffer, framebuffers, image_num, canvas_frame);
|
||||
|
||||
|
||||
|
||||
@@ -48,13 +58,35 @@ In Shader lie the shader compilers, pipelines, and supporting data.
|
||||
--------------------
|
||||
|
||||
|
||||
===== Links =====
|
||||
|
||||
Dynamic Keys in HashMap
|
||||
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=b4630cf98afa88fc0fbffdb0112af1c1
|
||||
|
||||
VertexDefinition
|
||||
https://github.com/tomaka/vulkano-examples/blob/81f5a4eb3c5f3fcc6a194d3c41e53b2bc66f7add/gltf/gltf_system.rs#L687-L795
|
||||
|
||||
|
||||
pub enum Content {
|
||||
Text(String),
|
||||
Number(u32),
|
||||
}
|
||||
|
||||
impl From for String {
|
||||
fn wrap(self) {
|
||||
Content::Text(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl From for u32 {
|
||||
fn wrap(self) {
|
||||
Content::Number(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn any_content<T>(value : T) where T : IntoContent {
|
||||
let content : Content = value.wrap();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,14 +11,12 @@ use std::any::Any;
|
||||
|
||||
|
||||
// I don't think this is going to work without getting into Box'ing
|
||||
pub trait DrawableTest<V, H> where H: Handle {
|
||||
fn get_vertices(&self) -> Vec<V>;
|
||||
pub trait DrawableTest<VTypes: Into<VertexTypes>, H: Handle + DynHash> {
|
||||
fn get_vertices(&self) -> VTypes;
|
||||
fn get_handle(&self) -> H;
|
||||
}
|
||||
|
||||
|
||||
|
||||
mod dynhash {
|
||||
pub mod dynhash {
|
||||
use std::any::Any;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
@@ -73,17 +71,16 @@ mod dynhash {
|
||||
}
|
||||
}
|
||||
use crate::canvas::canvas_frame::dynhash::DynHash;
|
||||
|
||||
|
||||
use crate::VertexTypes;
|
||||
|
||||
|
||||
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
|
||||
pub struct CanvasFrameTest<VTypes> {
|
||||
pub map: HashMap<Box<dyn DynHash>, Vec<VTypes>>,
|
||||
pub map: HashMap<Box<dyn DynHash>, VTypes>,
|
||||
}
|
||||
|
||||
impl<VTypes> CanvasFrameTest<VTypes> {
|
||||
pub fn draw(&mut self, drawable: Vec<VTypes>) {
|
||||
pub fn draw(&mut self, drawable: VTypes) {
|
||||
self.map.insert(Box::new(10), drawable);
|
||||
}
|
||||
}
|
||||
@@ -133,18 +130,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();
|
||||
//
|
||||
// let v = drawable.get_vertices();
|
||||
//
|
||||
// let v = v.get(0).unwrap();
|
||||
//
|
||||
// // need to fill up the drawables....
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
// TODO: Fix this for text and fonts
|
||||
/// Accumulates the drawables collected Vertex2D's
|
||||
|
||||
@@ -2,7 +2,7 @@ use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
||||
use std::sync::Arc;
|
||||
use vulkano::format::{ClearValue, Format, R8Unorm};
|
||||
use vulkano::format::{ClearValue, Format, R8Unorm, ClearValuesTuple};
|
||||
use vulkano::framebuffer::{FramebufferAbstract, Framebuffer, RenderPass, RenderPassAbstract};
|
||||
use vulkano::device::{Device, Queue};
|
||||
use vulkano::instance::PhysicalDevice;
|
||||
@@ -33,6 +33,7 @@ use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, Ca
|
||||
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
|
||||
use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline;
|
||||
use crate::canvas::managed::shader::generic_shader::GenericShader;
|
||||
use crate::VertexTypes;
|
||||
|
||||
|
||||
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
||||
@@ -101,6 +102,7 @@ impl CanvasState {
|
||||
device: Arc<Device>,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> CanvasState {
|
||||
|
||||
let format = capabilities.supported_formats[0].0;
|
||||
|
||||
let render_pass = Arc::new(vulkano::single_pass_renderpass!(
|
||||
@@ -488,11 +490,11 @@ impl CanvasState {
|
||||
|
||||
// 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<T: 'static + Send + Sync + Clone>(&mut self,
|
||||
pub fn draw_commands_test<VTypes: Into<VertexTypes>>(&mut self,
|
||||
mut command_buffer: AutoCommandBufferBuilder,
|
||||
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
||||
image_num: usize,
|
||||
canvas_frame: CanvasFrameTest<T>) -> AutoCommandBufferBuilder {
|
||||
canvas_frame: CanvasFrameTest<VTypes>) -> AutoCommandBufferBuilder {
|
||||
|
||||
// Specify the color to clear the framebuffer with i.e. blue
|
||||
let clear_values = vec!(
|
||||
@@ -513,20 +515,22 @@ impl CanvasState {
|
||||
framebuffers[image_num].clone(), false, clear_values.clone(),
|
||||
).unwrap();
|
||||
|
||||
|
||||
|
||||
for (k,v) in canvas_frame.map {
|
||||
|
||||
let buffer: Arc<(dyn BufferAccess + Send + Sync)> = match v.into() {
|
||||
|
||||
VertexTypes::TexturedType(vertices) => {
|
||||
|
||||
// Solid colors
|
||||
let mut shader = self.shader_buffers.get(
|
||||
self.get_shader_handle(String::from("color-passthrough"))
|
||||
.unwrap().clone().get_handle() as usize
|
||||
).unwrap();
|
||||
|
||||
|
||||
|
||||
for (k,v) in canvas_frame.map {
|
||||
|
||||
let value : Vec<T> = v.iter().map(|v| v.clone()).collect();
|
||||
|
||||
let buffer : Arc<(dyn BufferAccess + Send + Sync)> = ImmutableBuffer::from_iter(
|
||||
value.iter().cloned(),
|
||||
let buffer = ImmutableBuffer::from_iter(
|
||||
vertices.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0;
|
||||
@@ -539,6 +543,19 @@ impl CanvasState {
|
||||
(), (),
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
buffer
|
||||
},
|
||||
VertexTypes::VType2(vertices) => {
|
||||
ImmutableBuffer::from_iter(
|
||||
vertices.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
command_buffer
|
||||
|
||||
@@ -18,7 +18,7 @@ impl Handle for CanvasFontHandle {
|
||||
/// Typed wrapper for a u32 handle
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CanvasTextureHandle {
|
||||
pub(in crate::canvas) handle: u32
|
||||
pub/*(in crate::canvas)*/ handle: u32
|
||||
}
|
||||
|
||||
impl Handle for CanvasTextureHandle {
|
||||
|
||||
76
src/main.rs
76
src/main.rs
@@ -25,10 +25,11 @@ 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, CanvasFrameTest};
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest, DrawableTest};
|
||||
use crate::compute::managed::compu_sprite::CompuSprite;
|
||||
use std::sync::Arc;
|
||||
use crate::canvas::managed::handles::CanvasTextureHandle;
|
||||
use crate::canvas::managed::handles::{CanvasTextureHandle, Handle};
|
||||
use crate::canvas::canvas_frame::dynhash::DynHash;
|
||||
|
||||
|
||||
pub mod util;
|
||||
@@ -55,22 +56,48 @@ pub mod compute;
|
||||
|
||||
|
||||
*/
|
||||
pub struct ImplVertexData1 {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TextureVertex2D {
|
||||
pub v_position: [f32; 2],
|
||||
pub ti_position: [f32; 2],
|
||||
}
|
||||
vulkano::impl_vertex!(TextureVertex2D, v_position, ti_position);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ColorVertex2D {
|
||||
pub v_position: [f32; 2],
|
||||
pub color: [f32; 4],
|
||||
}
|
||||
vulkano::impl_vertex!(ColorVertex2D, v_position, color);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImageVertex2D {
|
||||
pub v_position: [f32; 2],
|
||||
pub color: [f32; 4],
|
||||
}
|
||||
vulkano::impl_vertex!(ImageVertex2D, v_position, color);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum VertexTypes {
|
||||
TextureType(Vec<TextureVertex2D>),
|
||||
ColorType(Vec<ColorVertex2D>),
|
||||
ImageType(Vec<ImageVertex2D>),
|
||||
}
|
||||
|
||||
pub struct ImplVertexData2 {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub struct DrawableTestee {
|
||||
vertices: VertexTypes,
|
||||
handle: Arc<CanvasTextureHandle>,
|
||||
}
|
||||
|
||||
impl ImplVertexData1 {}
|
||||
impl ImplVertexData2 {}
|
||||
impl<VTypes: Into<VertexTypes>, H: Handle + DynHash> DrawableTest<VTypes, H> for DrawableTestee {
|
||||
fn get_vertices(&self) -> VTypes {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
enum VertexTypes {
|
||||
VType1(ImplVertexData1),
|
||||
VType2(ImplVertexData2),
|
||||
fn get_handle(&self) -> H {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
@@ -199,27 +226,30 @@ pub fn main() {
|
||||
break;
|
||||
}
|
||||
|
||||
// let dt = DrawableTestee{
|
||||
// vertices: vec![ImplVertexData{ x: 0, y: 0 }],
|
||||
// handle: Arc::new(CanvasTextureHandle{ handle: 0 })
|
||||
// };
|
||||
let mut cft : CanvasFrameTest<VertexTypes> =
|
||||
let sprite = Sprite::new((0.0,0.0), (0.0,0.0));
|
||||
|
||||
let dt = DrawableTestee {
|
||||
vertices: VertexTypes::TexturedType(vec![ImplVertexData1 {x:0,y:0}]),
|
||||
handle: Arc::new(CanvasTextureHandle{ handle: 0 })
|
||||
};
|
||||
let mut canvas_frame : CanvasFrameTest<VertexTypes> =
|
||||
CanvasFrameTest{ map: Default::default() };
|
||||
|
||||
// cft.draw(&dt);
|
||||
canvas_frame.draw(dt.vertices);
|
||||
canvas_frame.draw(sprite.get_vertices());
|
||||
|
||||
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);
|
||||
//
|
||||
let mut canvas = CanvasFrame::new();
|
||||
canvas.draw(&funky_sprite);
|
||||
canvas.draw(&test_polygon);
|
||||
// let mut canvas = CanvasFrame::new();
|
||||
// canvas.draw(&funky_sprite);
|
||||
// canvas.draw(&test_polygon);
|
||||
|
||||
{
|
||||
let g = hprof::enter("Run");
|
||||
processor.run(&surface,
|
||||
canvas,
|
||||
canvas_frame,
|
||||
compu_frame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
use std::sync::Arc;
|
||||
use crate::util::vertex_3d::Vertex3D;
|
||||
use crate::canvas::*;
|
||||
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle};
|
||||
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
|
||||
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
||||
use crate::canvas::canvas_frame::{DrawableTest, Drawable};
|
||||
use crate::{VertexTypes, ImplVertexData1};
|
||||
use crate::canvas::canvas_frame::dynhash::DynHash;
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
|
||||
pub verts: VertexTypes::TexturedType(vec![]),
|
||||
|
||||
pub vertices: [(f32, f32, f32); 6],
|
||||
pub ti_position: [(f32, f32); 6],
|
||||
|
||||
@@ -98,6 +103,18 @@ impl Sprite {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Into<VertexTypes>, H: Handle + DynHash> DrawableTest<V, H> for Sprite{
|
||||
|
||||
fn get_vertices(&self) -> V {
|
||||
VertexTypes::TexturedType(vec![ImplVertexData1{ x: 0, y: 0 }])
|
||||
}
|
||||
|
||||
fn get_handle(&self) -> H {
|
||||
self.texture_handle.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Sprite {
|
||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
|
||||
self.vertices.to_vec()
|
||||
|
||||
@@ -11,7 +11,7 @@ use winit::Window;
|
||||
use crate::compute::compu_state::CompuState;
|
||||
use vulkano::image::ImageUsage;
|
||||
use crate::compute::compu_frame::CompuFrame;
|
||||
use crate::canvas::canvas_frame::CanvasFrame;
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
|
||||
use std::time::Duration;
|
||||
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
|
||||
use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition};
|
||||
@@ -21,6 +21,7 @@ use crate::canvas::managed::shader::generic_shader::GenericShader;
|
||||
use crate::canvas::managed::shader::text_shader::TextShader;
|
||||
use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle};
|
||||
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
|
||||
use crate::{ImplVertexData1, VertexTypes};
|
||||
|
||||
|
||||
/// VKProcessor holds the vulkan instance information, the swapchain,
|
||||
@@ -223,9 +224,10 @@ impl<'a> VkProcessor<'a> {
|
||||
}
|
||||
|
||||
///
|
||||
pub fn run(&mut self,
|
||||
pub fn run<VTypes: Into<VertexTypes>>(&mut self,
|
||||
surface: &'a Arc<Surface<Window>>,
|
||||
canvas_frame: CanvasFrame,
|
||||
//canvas_frame: CanvasFrame,
|
||||
canvas_frame: CanvasFrameTest<VTypes>,
|
||||
compute_frame: CompuFrame,
|
||||
) {
|
||||
|
||||
@@ -268,7 +270,8 @@ impl<'a> VkProcessor<'a> {
|
||||
// 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);
|
||||
//self.canvas_state.draw(canvas_frame);
|
||||
|
||||
}
|
||||
|
||||
let mut command_buffer =
|
||||
@@ -282,7 +285,9 @@ impl<'a> VkProcessor<'a> {
|
||||
let g = hprof::enter("Push draw commands to command buffer");
|
||||
|
||||
// Add the draw commands
|
||||
let mut command_buffer = self.canvas_state.draw_commands(command_buffer, framebuffers, image_num);
|
||||
//let mut command_buffer = self.canvas_state.draw_commands(command_buffer, framebuffers, image_num);
|
||||
let mut command_buffer =
|
||||
self.canvas_state.draw_commands_test(command_buffer, framebuffers, image_num, canvas_frame);
|
||||
|
||||
// And build
|
||||
let command_buffer = command_buffer.build().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user