|
|
|
@ -21,6 +21,11 @@ use vulkano::pipeline::viewport::Viewport;
|
|
|
|
|
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
|
|
|
|
use crate::canvas::canvas_frame::CanvasFrame;
|
|
|
|
|
use std::hash::Hash;
|
|
|
|
|
use crate::canvas::shader::generic_shader::GenericShader;
|
|
|
|
|
use crate::canvas::shader::common::CompiledGraphicsPipeline;
|
|
|
|
|
use shade_runner::CompiledShader;
|
|
|
|
|
use crate::canvas::{CanvasTextureHandle, CanvasImageHandle};
|
|
|
|
|
use crate::canvas::shader::dynamic_vertex::RuntimeVertexDef;
|
|
|
|
|
|
|
|
|
|
// Canvas is the accumulator of Sprites for drawing
|
|
|
|
|
|
|
|
|
@ -61,15 +66,6 @@ pub trait Vertex {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Vertex for ColoredVertex2D {
|
|
|
|
|
fn position(&self) -> (f32, f32) {
|
|
|
|
|
(0.0, 0.0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
|
|
|
|
Some((0., 0., 0., 0.))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait Drawable {
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32)>;
|
|
|
|
@ -87,20 +83,7 @@ pub enum ShaderType {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
|
|
|
|
pub struct CanvasTextureHandle {
|
|
|
|
|
pub handle: u32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
|
|
|
|
pub struct CanvasImageHandle {
|
|
|
|
|
pub handle: u32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
|
|
|
|
pub struct CanvasShaderHandle {
|
|
|
|
|
pub handle: u32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct CanvasTexture {
|
|
|
|
@ -112,7 +95,7 @@ pub struct CanvasTexture {
|
|
|
|
|
|
|
|
|
|
impl CanvasTexture {
|
|
|
|
|
fn get_descriptor_set(&self,
|
|
|
|
|
shader: Arc<CanvasShader>,
|
|
|
|
|
shader: Arc<CompiledGraphicsPipeline>,
|
|
|
|
|
sampler: Arc<Sampler>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
@ -132,7 +115,7 @@ pub struct CanvasImage {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl CanvasImage {
|
|
|
|
|
fn get_descriptor_set(&mut self, shader: Arc<CanvasShader>)
|
|
|
|
|
fn get_descriptor_set(&mut self, shader: Arc<CompiledGraphicsPipeline>)
|
|
|
|
|
-> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
@ -152,17 +135,17 @@ pub struct CanvasState {
|
|
|
|
|
// hold the image, texture, and shader buffers the same was as we do CompuState
|
|
|
|
|
image_buffers: Vec<Arc<CanvasImage>>,
|
|
|
|
|
texture_buffers: Vec<Arc<CanvasTexture>>,
|
|
|
|
|
shader_buffers: HashMap<String, Arc<CanvasShader>>,
|
|
|
|
|
shader_buffers: HashMap<String, Arc<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_drawables: Vec<ColoredVertex2D>,
|
|
|
|
|
colored_drawables: Vec<RuntimeVertexDef>,
|
|
|
|
|
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<Vertex2D>>>,
|
|
|
|
|
textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
|
|
|
|
textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<Vertex2D>>>,
|
|
|
|
|
image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
|
|
|
|
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
|
@ -186,7 +169,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
images.iter().map(|image| {
|
|
|
|
|
Arc::new(
|
|
|
|
|
Framebuffer::start(self.shader_buffers.get("color-passthrough").unwrap().render_pass.clone())
|
|
|
|
|
Framebuffer::start(self.shader_buffers.get("color-passthrough").unwrap().get_renderpass().clone())
|
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
|
.build().unwrap()
|
|
|
|
|
) as Arc<dyn FramebufferAbstract + Send + Sync>
|
|
|
|
@ -210,18 +193,25 @@ impl CanvasState {
|
|
|
|
|
image_buffers: vec![],
|
|
|
|
|
texture_buffers: vec![],
|
|
|
|
|
shader_buffers: HashMap::from_iter(vec![
|
|
|
|
|
(solid_color_kernel.clone(), Arc::new(CanvasShader::new_colored(solid_color_kernel.clone(),
|
|
|
|
|
capabilities.clone(),
|
|
|
|
|
queue.clone(),
|
|
|
|
|
physical.clone(),
|
|
|
|
|
device.clone()))
|
|
|
|
|
),
|
|
|
|
|
(texture_kernel.clone(), Arc::new(CanvasShader::new_textured(texture_kernel.clone(),
|
|
|
|
|
capabilities.clone(),
|
|
|
|
|
queue.clone(),
|
|
|
|
|
physical.clone(),
|
|
|
|
|
device.clone()))
|
|
|
|
|
),
|
|
|
|
|
// (solid_color_kernel.clone(), Arc::new(GenericShader::new(solid_color_kernel.clone(),
|
|
|
|
|
// device.clone(),
|
|
|
|
|
//
|
|
|
|
|
// capabilities.clone(),
|
|
|
|
|
// queue.clone(),
|
|
|
|
|
// physical.clone(),
|
|
|
|
|
// ))),
|
|
|
|
|
// (solid_color_kernel.clone(), Arc::new(CanvasShader::new_colored(solid_color_kernel.clone(),
|
|
|
|
|
// capabilities.clone(),
|
|
|
|
|
// queue.clone(),
|
|
|
|
|
// physical.clone(),
|
|
|
|
|
// device.clone()))
|
|
|
|
|
// ),
|
|
|
|
|
// (texture_kernel.clone(), Arc::new(CanvasShader::new_textured(texture_kernel.clone(),
|
|
|
|
|
// capabilities.clone(),
|
|
|
|
|
// queue.clone(),
|
|
|
|
|
// physical.clone(),
|
|
|
|
|
// device.clone()))
|
|
|
|
|
// ),
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
|
|
colored_drawables: vec![],
|
|
|
|
@ -389,7 +379,7 @@ impl CanvasState {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_solid_color_descriptor_set(&self, kernel: Arc<CanvasShader>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
fn get_solid_color_descriptor_set(&self, kernel: Arc<CompiledGraphicsPipeline>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|