moved over to the enum method of drawing. Not flexible, but type safe

master
mitchellhansen 5 years ago
parent 80c0d323be
commit 659cd98a1f

@ -8,13 +8,13 @@ Creation-Date: 2020-02-03T22:11:42-08:00
Main Systems: Main Systems:
[[~/source/Trac3r-rust/doc/sfml_rust/sprite/index.html|Spri]][[~/source/Trac3r-rust/doc/sfml_rust/sprite/index.html|te]] [[~/source/Trac3r-rust/doc/sfml_rust/sprite/index.html|Spri]][[~/source/Trac3r-rust/doc/sfml_rust/sprite/index.html|te]]
[[CanvasContainerClasses]] [[VKProcessor:CanvasContainerClasses]]
Docs Docs
[[VkProcessor]] [[~/source/Trac3r-rust/doc/sfml_rust/vkprocessor/struct.VkProcessor.html|===========]] [[VkProcessor]] [[~/source/Trac3r-rust/doc/sfml_rust/vkprocessor/struct.VkProcessor.html|===========]]
[[CanvasState]] [[~/source/Trac3r-rust/doc/sfml_rust/canvas/canvas_state/index.html|===========]] [[VKProcessor:CanvasState]] [[~/source/Trac3r-rust/doc/sfml_rust/canvas/canvas_state/index.html|===========]]
[[DynamicVertex]] [[VKProcessor:DynamicVertex]]
[[CompuState]] [[~/source/Trac3r-rust/doc/sfml_rust/compute/compu_state/struct.CompuState.html|===========]] [[VKProcessor:CompuState]] [[~/source/Trac3r-rust/doc/sfml_rust/compute/compu_state/struct.CompuState.html|===========]]
-------------------- --------------------

@ -26,13 +26,13 @@ Vk Processors is a do_all class for interaction with the render window, vulkan s
queue queue
**Owns:** **Owns:**
[[CanvasState]] [[+CanvasState]]
[[CompuState]] [[+CompuState]]
-------------------- --------------------
===== CanvasState ===== ===== CanvasState =====
<[[CanvasState]]>:[[~/source/Trac3r-rust/doc/sfml_rust/canvas/canvas_state/index.html|docs]] <[[+CanvasState]]>:[[~/source/Trac3r-rust/doc/sfml_rust/canvas/canvas_state/index.html|docs]]
* Is used for storage of texture and image buffers in addition to vertex buffers * Is used for storage of texture and image buffers in addition to vertex buffers
* Also contains logic for writing the stored buffers to the command_buffer * Also contains logic for writing the stored buffers to the command_buffer

@ -18,6 +18,7 @@ All buffers will have a coupled handle type stored in the [[/src/canvas/mod.rs|c
===== CanvasTexture ===== ===== CanvasTexture =====
===== CanvasFont ===== ===== CanvasFont =====

@ -37,7 +37,7 @@ Creation-Date: 2020-02-03T23:30:41-08:00
**Owns:** **Owns:**
render_pass render_pass
[[CanvasImage]] [[CanvasImage]]
[[CanvasTexture]] [[VKProcessor:CanvasTexture]]
[[CanvasFont]] [[CanvasFont]]
CompiledGraphicsPipeline CompiledGraphicsPipeline
colored_vertex_buffer colored_vertex_buffer

@ -1,4 +1,3 @@
use crate::util::vertex_3d::Vertex3D;
use std::sync::Arc; use std::sync::Arc;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
@ -10,11 +9,7 @@ use vulkano::pipeline::vertex::Vertex;
use std::any::Any; use std::any::Any;
// I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<VTypes: Into<VertexTypes>, H: Handle + DynHash> {
fn get_vertices(&self) -> VTypes;
fn get_handle(&self) -> H;
}
pub mod dynhash { pub mod dynhash {
use std::any::Any; use std::any::Any;
@ -74,14 +69,19 @@ use crate::canvas::canvas_frame::dynhash::DynHash;
use crate::VertexTypes; use crate::VertexTypes;
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
pub struct CanvasFrameTest<VTypes> { pub trait DrawableTest {
pub map: HashMap<Box<dyn DynHash>, VTypes>, fn get(&self) -> VertexTypes;
}
#[derive(Default)]
pub struct CanvasFrameTest {
pub map: Vec<VertexTypes>,
} }
impl<VTypes> CanvasFrameTest<VTypes> { impl CanvasFrameTest {
pub fn draw(&mut self, drawable: VTypes) { pub fn draw(&mut self, drawable: &dyn DrawableTest) {
self.map.insert(Box::new(10), drawable); self.map.push(drawable.get());
} }
} }

@ -20,7 +20,6 @@ use vulkano::pipeline::viewport::Viewport;
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer; use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest}; use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
use std::hash::Hash; use std::hash::Hash;
use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue}; use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic; use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
use std::borrow::Borrow; use std::borrow::Borrow;
@ -29,11 +28,12 @@ use std::io::Read;
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment}; use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment};
use vulkano::pipeline::vertex::VertexDefinition; use vulkano::pipeline::vertex::VertexDefinition;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle, DrawableHandle};
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont}; use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline; use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline;
use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::VertexTypes; use crate::VertexTypes;
use crate::util::vertex::{TextVertex3D, TextureVertex2D, ImageVertex2D, ColorVertex2D, CanvasFrameAllocation};
/// 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
@ -53,16 +53,6 @@ pub struct CanvasState {
// Compiled Graphics pipelines have a handle which self describe their position in this vector // Compiled Graphics pipelines have a handle which self describe their position in this vector
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>, shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
// Hold onto the vertices we get from the Compu and Canvas Frames
// When the run comes around, push the vertices to the GPU
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>>,
textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
text_instances: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
// Looks like we gotta hold onto the queue for managing textures // Looks like we gotta hold onto the queue for managing textures
queue: Arc<Queue>, queue: Arc<Queue>,
device: Arc<Device>, device: Arc<Device>,
@ -70,7 +60,6 @@ pub struct CanvasState {
} }
impl CanvasState { impl CanvasState {
/// This method is called once during initialization, then again whenever the window is resized /// This method is called once during initialization, then again whenever the window is resized
pub fn window_size_dependent_setup(&mut self, images: &[Arc<SwapchainImage<Window>>]) pub fn window_size_dependent_setup(&mut self, images: &[Arc<SwapchainImage<Window>>])
@ -102,7 +91,6 @@ impl CanvasState {
device: Arc<Device>, device: Arc<Device>,
physical: PhysicalDevice, physical: PhysicalDevice,
capabilities: Capabilities) -> CanvasState { capabilities: Capabilities) -> CanvasState {
let format = capabilities.supported_formats[0].0; let format = capabilities.supported_formats[0].0;
let render_pass = Arc::new(vulkano::single_pass_renderpass!( let render_pass = Arc::new(vulkano::single_pass_renderpass!(
@ -172,11 +160,6 @@ impl CanvasState {
shader_buffers: vec![], shader_buffers: vec![],
font_buffers: vec![], font_buffers: vec![],
colored_vertex_buffer: vec![],
textured_vertex_buffer: Default::default(),
image_vertex_buffer: Default::default(),
text_instances: HashMap::default(),
queue: queue.clone(), queue: queue.clone(),
device: device.clone(), device: device.clone(),
render_pass: render_pass.clone(), render_pass: render_pass.clone(),
@ -393,91 +376,6 @@ impl CanvasState {
} }
} }
/// Scrape all the values from the CanvasFrame and then allocate the vertex buffers
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
// Consume the canvas frame
let mut textured_drawables = canvas_frame.textured_drawables;
let mut colored_drawables = canvas_frame.colored_drawables;
let mut image_drawables = canvas_frame.image_drawables;
let mut text_drawables = canvas_frame.text_drawables;
// Walk through the consumed items and allocate them to GPU buffers
self.colored_vertex_buffer.clear();
{
let g = hprof::enter("Colored Vertex Buffer");
self.colored_vertex_buffer.push(
ImmutableBuffer::from_iter(
colored_drawables.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0
);
}
self.textured_vertex_buffer.clear();
{
let g = hprof::enter("Textured Vertex Buffer");
for (k, v) in textured_drawables.drain() {
let vertex_buffer = v.clone().get(0).unwrap().clone();
// TODO
// v.clone().iter()
// .fold(Vec::new(), |mut a: Vec<RuntimeVertexDef>, b| {
// a.extend(b);
// a
// });
self.textured_vertex_buffer.insert(
k.clone(),
ImmutableBuffer::from_iter(
vertex_buffer.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0,
);
}
}
self.image_vertex_buffer.clear();
{
let g = hprof::enter("Image Vertex Buffer");
for (k, v) in image_drawables.drain() {
let vertex_buffer = v.clone().get(0).unwrap().clone();
// TODO
// v.clone().iter()
// .fold(Vec::new(), |mut a: Vec<&RuntimeVertexDef>, b| {
// a.extend(b);
// a
// });
self.image_vertex_buffer.insert(
k.clone(),
ImmutableBuffer::from_iter(
vertex_buffer.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0,
);
}
}
self.text_instances.clear();
{
let g = hprof::enter("Text Instance Vertex Buffer");
for (k, v) in text_drawables.drain() {
self.text_instances.insert(
k.clone(),
ImmutableBuffer::from_iter(
v.iter().cloned(),
BufferUsage::all(),
self.queue.clone(),
).unwrap().0,
);
}
}
}
/// Builds the descriptor set for solid colors using the input kernel (needs to support solid colors) /// Builds the descriptor set for solid colors using the input kernel (needs to support solid colors)
fn get_solid_color_descriptor_set(&self, kernel: Arc<GenericShader>) -> Box<dyn DescriptorSet + Send + Sync> { fn get_solid_color_descriptor_set(&self, kernel: Arc<GenericShader>) -> Box<dyn DescriptorSet + Send + Sync> {
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new( let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
@ -487,79 +385,58 @@ impl CanvasState {
o o
} }
/// Consume and allocated the canvas frame data to the GPU
pub fn allocate(&mut self, canvas_frame: CanvasFrameTest) -> CanvasFrameAllocation {
// This is taking in a canvas frame, which should be some sort of matrix of vertices of generic let mut colored_vertex_buffer: Vec<ColorVertex2D> = Vec::default();
// types and handles let mut textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Vec<TextureVertex2D>> = HashMap::new();
pub fn draw_commands_test<VTypes: Into<VertexTypes>>(&mut self, let mut image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Vec<ImageVertex2D>> = HashMap::new();
mut command_buffer: AutoCommandBufferBuilder, let mut text_instances: HashMap<Arc<CanvasFontHandle>, Vec<TextVertex3D>> = HashMap::new();
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
image_num: usize,
canvas_frame: CanvasFrameTest<VTypes>) -> AutoCommandBufferBuilder {
// Specify the color to clear the framebuffer with i.e. blue
let clear_values = vec!(
ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
ClearValue::DepthStencil((1.0, 0x00)),
);
self.dynamic_state = DynamicState { for value in canvas_frame.map {
line_width: None, match value {
viewports: self.dynamic_state.viewports.clone(), VertexTypes::TextureType(vertices, handle) => {
scissors: None, textured_vertex_buffer.entry(handle).or_insert(vertices.clone()).extend(vertices);
compare_mask: None, }
write_mask: None, VertexTypes::ImageType(vertices, handle) => {
reference: None, image_vertex_buffer.entry(handle).or_insert(vertices.clone()).extend(vertices);
}
VertexTypes::ColorType(vertices) => {
colored_vertex_buffer.extend(vertices);
}
VertexTypes::ThreeDType(vertices) => {}
};
}; };
let mut command_buffer = command_buffer.begin_render_pass( let mut allocated_colored_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>> = Vec::new();
framebuffers[image_num].clone(), false, clear_values.clone(), if !colored_vertex_buffer.is_empty() {
).unwrap(); allocated_colored_buffer.push(ImmutableBuffer::from_iter(
colored_vertex_buffer.iter().cloned(),
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();
let buffer = ImmutableBuffer::from_iter(
vertices.iter().cloned(),
BufferUsage::vertex_buffer(), BufferUsage::vertex_buffer(),
self.queue.clone(), self.queue.clone(),
).unwrap().0; ).unwrap().0);
if !self.colored_vertex_buffer.is_empty() {
command_buffer = command_buffer.draw(
shader.get_pipeline().clone(),
&self.dynamic_state.clone(),
vec![buffer.clone()],
(), (),
).unwrap();
} }
buffer CanvasFrameAllocation {
}, colored_vertex_buffer: allocated_colored_buffer,
VertexTypes::VType2(vertices) => { textured_vertex_buffer: textured_vertex_buffer.into_iter().map(|(k, v)| {
(k,
ImmutableBuffer::from_iter( ImmutableBuffer::from_iter(
vertices.iter().cloned(), v.iter().cloned(),
BufferUsage::vertex_buffer(), BufferUsage::vertex_buffer(),
self.queue.clone(), self.queue.clone(),
).unwrap().0 ).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
} }).collect(),
}; image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
(k,
ImmutableBuffer::from_iter(
v.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
}).collect(),
text_instances: Default::default(),
} }
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
@ -567,7 +444,8 @@ impl CanvasState {
pub fn draw_commands(&mut self, pub fn draw_commands(&mut self,
mut command_buffer: AutoCommandBufferBuilder, mut command_buffer: AutoCommandBufferBuilder,
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>, framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
image_num: usize) -> AutoCommandBufferBuilder { image_num: usize,
allocated_buffers: CanvasFrameAllocation) -> AutoCommandBufferBuilder {
// Specify the color to clear the framebuffer with i.e. blue // Specify the color to clear the framebuffer with i.e. blue
let clear_values = vec!( let clear_values = vec!(
@ -597,11 +475,11 @@ impl CanvasState {
// This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs. // This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs.
// But we can pass in multiple vertex buffers // But we can pass in multiple vertex buffers
if !self.colored_vertex_buffer.is_empty() { if allocated_buffers.colored_vertex_buffer.is_empty() {
command_buffer = command_buffer.draw( command_buffer = command_buffer.draw(
shader.get_pipeline().clone(), shader.get_pipeline().clone(),
&self.dynamic_state.clone(), &self.dynamic_state.clone(),
self.colored_vertex_buffer.clone(), allocated_buffers.colored_vertex_buffer.clone(),
(), (), (), (),
).unwrap(); ).unwrap();
} }
@ -612,8 +490,8 @@ impl CanvasState {
.unwrap().clone().get_handle() as usize .unwrap().clone().get_handle() as usize
).unwrap(); ).unwrap();
if !self.image_vertex_buffer.is_empty() { if !allocated_buffers.image_vertex_buffer.is_empty() {
for (image_handle, vertex_buffer) in self.image_vertex_buffer.clone() { for (image_handle, vertex_buffer) in allocated_buffers.image_vertex_buffer.clone() {
let handle = image_handle.clone().get_handle() as usize; let handle = image_handle.clone().get_handle() as usize;
let descriptor_set = self.image_buffers.get(handle).clone().unwrap().clone() let descriptor_set = self.image_buffers.get(handle).clone().unwrap().clone()
.get_descriptor_set(shader.get_pipeline().clone()); .get_descriptor_set(shader.get_pipeline().clone());
@ -633,8 +511,8 @@ impl CanvasState {
.unwrap().clone().get_handle() as usize .unwrap().clone().get_handle() as usize
).unwrap(); ).unwrap();
if !self.textured_vertex_buffer.is_empty() { if !allocated_buffers.textured_vertex_buffer.is_empty() {
for (texture_handle, vertex_buffer) in self.textured_vertex_buffer.clone() { for (texture_handle, vertex_buffer) in allocated_buffers.textured_vertex_buffer.clone() {
let handle = texture_handle.clone().get_handle() as usize; let handle = texture_handle.clone().get_handle() as usize;
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone() let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone()); .get_descriptor_set(shader.get_pipeline(), self.sampler.clone());

@ -10,7 +10,6 @@ use vulkano::format::ClearValue;
use vulkano::format::Format::R8Unorm; use vulkano::format::Format::R8Unorm;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
//pub struct Glyph {} //pub struct Glyph {}

@ -3,6 +3,15 @@ pub trait Handle {
fn get_handle(&self) -> u32; fn get_handle(&self) -> u32;
} }
pub enum DrawableHandle {
Texture(CanvasTextureHandle),
Image(CanvasImageHandle),
Font(CanvasFontHandle),
}
/// Typed wrapper for a u32 handle /// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CanvasFontHandle { pub struct CanvasFontHandle {

@ -11,7 +11,6 @@ use std::ffi::CStr;
use std::marker::PhantomData; use std::marker::PhantomData;
use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp}; use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp};
use vulkano::pipeline::vertex::{SingleBufferDefinition, VertexDefinition}; use vulkano::pipeline::vertex::{SingleBufferDefinition, VertexDefinition};
use crate::util::vertex_3d::Vertex3D;
use shade_runner as sr; use shade_runner as sr;
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic; use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
use vulkano::SafeDeref; use vulkano::SafeDeref;

@ -10,7 +10,6 @@ use std::ffi::CStr;
use std::marker::PhantomData; use std::marker::PhantomData;
use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp}; use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp};
use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefinition}; use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefinition};
use crate::util::vertex_3d::Vertex3D;
use shade_runner as sr; use shade_runner as sr;
use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphicsPipelineResources, CompiledGraphicsPipeline}; use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphicsPipelineResources, CompiledGraphicsPipeline};
use crate::canvas::managed::handles::CompiledShaderHandle; use crate::canvas::managed::handles::CompiledShaderHandle;

@ -22,7 +22,6 @@ use sprite::Sprite;
use crate::util::load_raw; use crate::util::load_raw;
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, CanvasFrameTest, DrawableTest}; use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest, DrawableTest};
@ -30,6 +29,7 @@ use crate::compute::managed::compu_sprite::CompuSprite;
use std::sync::Arc; use std::sync::Arc;
use crate::canvas::managed::handles::{CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::dynhash::DynHash; use crate::canvas::canvas_frame::dynhash::DynHash;
use crate::util::vertex::{VertexTypes, TextureVertex2D};
pub mod util; pub mod util;
@ -57,48 +57,6 @@ pub mod compute;
*/ */
#[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 DrawableTestee {
vertices: VertexTypes,
handle: Arc<CanvasTextureHandle>,
}
impl<VTypes: Into<VertexTypes>, H: Handle + DynHash> DrawableTest<VTypes, H> for DrawableTestee {
fn get_vertices(&self) -> VTypes {
unimplemented!()
}
fn get_handle(&self) -> H {
unimplemented!()
}
}
pub fn main() { pub fn main() {
hprof::start_frame(); hprof::start_frame();
@ -162,12 +120,12 @@ pub fn main() {
let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap(); let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap();
let font_handle = processor.get_font_handle(String::from("sansation.ttf")).unwrap(); let font_handle = processor.get_font_handle(String::from("sansation.ttf")).unwrap();
let funky_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone()); let funky_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
let sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone()); let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
let text_sprite = Text::new((-0.1,-0.1), (10.0, 10.0), font_handle.clone()); //let text_sprite = Text::new((-0.1,-0.1), (10.0, 10.0), font_handle.clone());
let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0)); //let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
drop(q2); drop(q2);
drop(q1); drop(q1);
@ -226,17 +184,12 @@ pub fn main() {
break; break;
} }
let sprite = Sprite::new((0.0,0.0), (0.0,0.0));
let dt = DrawableTestee { let funky_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
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() };
canvas_frame.draw(dt.vertices); let mut canvas_frame = CanvasFrameTest::default();
canvas_frame.draw(sprite.get_vertices()); canvas_frame.draw(&funky_sprite);
canvas_frame.draw(&sfml_sprite);
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());

@ -1,306 +1,45 @@
use std::sync::Arc; use std::sync::Arc;
use crate::util::vertex_3d::Vertex3D;
use crate::canvas::*; use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance; use crate::canvas::managed::shader::text_shader::GlyphInstance;
use crate::canvas::canvas_frame::{DrawableTest, Drawable}; use crate::canvas::canvas_frame::{DrawableTest, Drawable};
use crate::{VertexTypes, ImplVertexData1};
use crate::canvas::canvas_frame::dynhash::DynHash; use crate::canvas::canvas_frame::dynhash::DynHash;
use crate::util::vertex::{VertexTypes, TextureVertex2D, Vertex3D};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Sprite { pub struct Sprite {
pub verts: VertexTypes::TexturedType(vec![]), pub verts: VertexTypes,
pub vertices: [(f32, f32, f32); 6],
pub ti_position: [(f32, f32); 6],
position: (f32, f32), position: (f32, f32),
size: (f32, f32), size: (f32, f32),
color: (f32, f32, f32, f32),
textured: bool,
texture_handle: Option<Arc<CanvasTextureHandle>>,
value: GlyphInstance,
} }
/// Container class which implements drawable. /// Container class which implements drawable.
impl Sprite { impl Sprite {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite {
Sprite::new_with_color(position, size, 0, (0., 0., 0., 0.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1, normalized_depth), // top left
(position.0, position.1 + size.1, normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1, normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1, normalized_depth), // top right
],
position: position,
ti_position: [
(-0.0, -0.0), // top left
(-0.0, 1.0), // bottom left
(1.0, 1.0), // bottom right
(-0.0, -0.0), // top left
(1.0, 1.0), // bottom right
(1.0, -0.0), // top right
],
size: size,
color: color,
textured: false,
texture_handle: None,
value: GlyphInstance {
screen_position: (0.0, 0.0),
atlas_position: (0.0, 0.0),
atlas_size: (0.0, 0.0),
scale: 0.0,
},
}
}
/// ///
pub fn new_with_texture(position: (f32, f32), pub fn new(position: (f32, f32),
size: (f32, f32), size: (f32, f32),
depth: u32, depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite { texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1, normalized_depth), // top left
(position.0, position.1 + size.1, normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1, normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1, normalized_depth), // top right
],
position: position,
ti_position: [
(-0.0, -0.0), // top left
(-0.0, 1.0), // bottom left
(1.0, 1.0), // bottom right
(-0.0, -0.0), // top left
(1.0, 1.0), // bottom right
(1.0, -0.0), // top right
],
size: size,
color: (1.0, 0.0, 0.0, 1.0),
textured: true,
texture_handle: Some(texture_handle.clone()),
value: Default::default(),
}
}
}
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()
}
fn get_color(&self) -> (f32, f32, f32, f32) {
self.color.clone()
}
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
self.ti_position.to_vec()
}
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
match self.textured {
true => {
self.texture_handle.clone()
}
false => None,
}
}
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
None
}
}
#[derive(Debug, Clone)]
pub struct Poly {
pub vertices: Vec<(f32, f32, f32)>,
pub ti_position: Vec<(f32, f32)>,
position: (f32, f32),
size: (f32, f32),
color: (f32, f32, f32, f32),
textured: bool,
texture_handle: Option<Arc<CanvasTextureHandle>>,
// ==================================
}
/// Container class which implements drawable.
impl Poly {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
Poly::new_with_color(position, size, 0, (0., 0., 0., 0.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Poly {
let normalized_depth = (depth as f32 / 255.0); let normalized_depth = (depth as f32 / 255.0);
Poly { Sprite {
vertices: vec![ verts: VertexTypes::TextureType(Vec::new(), texture_handle),
(-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(-0.25, 0.0, normalized_depth),
(-0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth),
(0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth),
(0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.25, 0.0, normalized_depth),
(0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.5, -0.5, normalized_depth),
(0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth),
(-0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth),
(-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(-0.25, -0.5, normalized_depth),
],
position: position, position: position,
ti_position: vec![
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
],
size: size, size: size,
color: color,
textured: false,
texture_handle: None,
}
}
}
impl Drawable for Poly {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec()
}
fn get_color(&self) -> (f32, f32, f32, f32) {
self.color.clone()
}
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
self.ti_position.to_vec()
}
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
match self.textured {
true => {
self.texture_handle.clone()
}
false => None,
} }
} }
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
None
}
}
#[derive(Debug, Clone)]
pub struct Text {
position: (f32, f32, f32),
scale: f32,
color: (f32, f32, f32, f32),
text_handle: Arc<CanvasFontHandle>,
} }
impl DrawableTest for Sprite{
/// Container class which implements drawable. fn get(&self) -> VertexTypes {
impl Text { self.verts.clone()
pub fn new(position: (f32, f32), size: (f32, f32), font_handle: Arc<CanvasFontHandle>) -> Text {
Text::new_with_color(position, size, 0, (0., 0., 0., 0.), font_handle)
} }
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32),
handle: Arc<CanvasFontHandle>) -> Text {
let normalized_depth = (depth as f32 / 255.0);
Text {
position: (position.0, position.1, normalized_depth),
scale: 0.0,
color,
text_handle: handle,
}
}
} }
pub trait TextHandle {
fn do_nothing() -> u32;
}
pub trait TextInstance {
fn get_thing() -> Vec<(u32, u32, u32)>;
}
pub trait TextVertex {
fn get_vertices() -> Vec<(u32, u32, u32)>;
}

@ -4,8 +4,7 @@ use std::ffi::CStr;
use std::path::PathBuf; use std::path::PathBuf;
pub mod timer; pub mod timer;
pub mod vertex_2d; pub mod vertex;
pub mod vertex_3d;
pub fn load_raw(filename: String) -> (Vec<u8>, (u32,u32)) { pub fn load_raw(filename: String) -> (Vec<u8>, (u32,u32)) {

@ -0,0 +1,78 @@
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle};
use std::sync::Arc;
use vulkano::buffer::BufferAccess;
use std::collections::HashMap;
#[derive(Default, Debug, Clone, Copy)]
pub struct TextureVertex2D {
pub v_position: [f32; 2],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(TextureVertex2D, v_position, ti_position);
#[derive(Default, Debug, Clone, Copy)]
pub struct ColorVertex2D {
pub v_position: [f32; 2],
pub color: [f32; 4],
}
vulkano::impl_vertex!(ColorVertex2D, v_position, color);
#[derive(Default, Debug, Clone, Copy)]
pub struct ImageVertex2D {
pub v_position: [f32; 2],
pub color: [f32; 4],
}
vulkano::impl_vertex!(ImageVertex2D, v_position, color);
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex3D {
pub v_position: [f32; 3],
pub color : [f32; 4],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(Vertex3D, v_position, color, ti_position);
/// Text vertex 3d with vertex position
#[derive(Default, Debug, Clone, Copy)]
pub struct TextVertex3D {
pub position: [f32; 3],
}
vulkano::impl_vertex!(TextVertex3D, position);
// ==============================================================================
#[derive(Debug, Clone)]
pub enum VertexTypes {
TextureType(Vec<TextureVertex2D>, Arc<CanvasTextureHandle>),
ImageType(Vec<ImageVertex2D>, Arc<CanvasImageHandle>),
ColorType(Vec<ColorVertex2D>),
ThreeDType(Vec<Vertex3D>),
}
#[derive(Clone)]
pub struct CanvasFrameAllocation {
pub colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>>,
pub textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
pub image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
pub text_instances: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
}

@ -1,10 +0,0 @@
/// Generic vertex 2d with vertex position, texture position and a 32bit color
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex2D {
pub v_position: [f32; 2],
pub color : [f32; 4],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(Vertex2D, v_position, color, ti_position);

@ -1,20 +0,0 @@
/// Generic vertex 3d with vertex position, texture position and a 32bit color
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex3D {
pub v_position: [f32; 3],
pub color : [f32; 4],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(Vertex3D, v_position, color, ti_position);
/// Text vertex 3d with vertex position
#[derive(Default, Debug, Clone, Copy)]
pub struct TextVertex3D {
pub position: [f32; 3],
}
vulkano::impl_vertex!(TextVertex3D, position);

@ -15,13 +15,12 @@ use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
use std::time::Duration; use std::time::Duration;
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags}; use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition}; use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition};
use crate::util::vertex_3d::Vertex3D;
use crate::canvas::canvas_state::CanvasState; use crate::canvas::canvas_state::CanvasState;
use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::text_shader::TextShader; use crate::canvas::managed::shader::text_shader::TextShader;
use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::{ImplVertexData1, VertexTypes}; use crate::util::vertex::VertexTypes;
/// VKProcessor holds the vulkan instance information, the swapchain, /// VKProcessor holds the vulkan instance information, the swapchain,
@ -224,10 +223,10 @@ impl<'a> VkProcessor<'a> {
} }
/// ///
pub fn run<VTypes: Into<VertexTypes>>(&mut self, pub fn run(&mut self,
surface: &'a Arc<Surface<Window>>, surface: &'a Arc<Surface<Window>>,
//canvas_frame: CanvasFrame, //canvas_frame: CanvasFrame,
canvas_frame: CanvasFrameTest<VTypes>, canvas_frame: CanvasFrameTest,
compute_frame: CompuFrame, compute_frame: CompuFrame,
) { ) {
@ -266,13 +265,12 @@ impl<'a> VkProcessor<'a> {
drop(g); drop(g);
{ let allocated_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"); let g = hprof::enter("Canvas creates GPU buffers");
//self.canvas_state.draw(canvas_frame); self.canvas_state.allocate(canvas_frame)
};
}
let mut command_buffer = let mut command_buffer =
AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap(); AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap();
@ -287,7 +285,7 @@ impl<'a> VkProcessor<'a> {
// Add the draw commands // 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 = let mut command_buffer =
self.canvas_state.draw_commands_test(command_buffer, framebuffers, image_num, canvas_frame); self.canvas_state.draw_commands(command_buffer, framebuffers, image_num, allocated_buffers);
// And build // And build
let command_buffer = command_buffer.build().unwrap(); let command_buffer = command_buffer.build().unwrap();

Loading…
Cancel
Save