|
|
@ -1,4 +1,3 @@
|
|
|
|
use crate::vertex_2d::Vertex2D;
|
|
|
|
|
|
|
|
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
|
|
|
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
|
|
|
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
|
|
@ -23,21 +22,28 @@ use crate::canvas_frame::CanvasFrame;
|
|
|
|
use std::hash::Hash;
|
|
|
|
use std::hash::Hash;
|
|
|
|
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
|
|
|
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
|
|
|
use crate::canvas_buffer::{CanvasImage, CanvasTexture};
|
|
|
|
use crate::canvas_buffer::{CanvasImage, CanvasTexture};
|
|
|
|
|
|
|
|
use crate::vertex_3d::Vertex3D;
|
|
|
|
|
|
|
|
|
|
|
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
|
|
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
|
|
|
/// Allows Texture or Image drawing via their handles
|
|
|
|
/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color
|
|
|
|
|
|
|
|
/// Provides Image and Texture handles for drawing
|
|
|
|
|
|
|
|
/// Split out to two drawables?
|
|
|
|
|
|
|
|
///
|
|
|
|
pub trait Drawable {
|
|
|
|
pub trait Drawable {
|
|
|
|
|
|
|
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32)>;
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32)>;
|
|
|
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
|
|
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
|
|
|
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
|
|
|
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
|
|
|
|
|
|
|
|
|
|
|
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
|
|
|
|
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
|
|
|
|
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
|
|
|
|
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
|
|
|
|
|
|
|
|
// fn get_text_handle(&self) -> Option<Arc<CanvasTextHandle>>;
|
|
|
|
|
|
|
|
|
|
|
|
fn collect(&self) -> Vec<Vertex2D> {
|
|
|
|
fn collect(&self) -> Vec<Vertex3D> {
|
|
|
|
let color = self.get_color();
|
|
|
|
let color = self.get_color();
|
|
|
|
self.get_vertices().iter().zip(self.get_ti_coords().iter()).map(|(a, b)|
|
|
|
|
self.get_vertices().iter().zip(self.get_ti_coords().iter()).map(|(a, b)|
|
|
|
|
Vertex2D {
|
|
|
|
Vertex3D {
|
|
|
|
v_position: [a.0, a.1],
|
|
|
|
v_position: [a.0, a.1, 0.0],
|
|
|
|
color: [color.0, color.1, color.2, color.3],
|
|
|
|
color: [color.0, color.1, color.2, color.3],
|
|
|
|
ti_position: [b.0, b.1],
|
|
|
|
ti_position: [b.0, b.1],
|
|
|
|
}).collect()
|
|
|
|
}).collect()
|
|
|
@ -80,13 +86,13 @@ pub struct CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
// Hold onto the vertices we get from the Compu and Canvas Frames
|
|
|
|
// Hold onto the vertices we get from the Compu and Canvas Frames
|
|
|
|
// When the run comes around, push the vertices to the GPU
|
|
|
|
// When the run comes around, push the vertices to the GPU
|
|
|
|
colored_drawables: Vec<Vertex2D>,
|
|
|
|
colored_drawables: Vec<Vertex3D>,
|
|
|
|
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
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<Vertex3D>>>,
|
|
|
|
textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
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<Vertex3D>>>,
|
|
|
|
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
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
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
@ -109,10 +115,14 @@ impl CanvasState {
|
|
|
|
depth_range: 0.0..1.0,
|
|
|
|
depth_range: 0.0..1.0,
|
|
|
|
}]);
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dimensions = [dimensions.width(), dimensions.height()];
|
|
|
|
|
|
|
|
let depth_buffer = AttachmentImage::transient(self.device.clone(), dimensions, Format::D16Unorm).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
images.iter().map(|image| {
|
|
|
|
images.iter().map(|image| {
|
|
|
|
Arc::new(
|
|
|
|
Arc::new(
|
|
|
|
Framebuffer::start(self.render_pass.clone())
|
|
|
|
Framebuffer::start(self.render_pass.clone())
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
|
|
|
|
.add(depth_buffer.clone()).unwrap()
|
|
|
|
.build().unwrap()
|
|
|
|
.build().unwrap()
|
|
|
|
) as Arc<dyn FramebufferAbstract + Send + Sync>
|
|
|
|
) as Arc<dyn FramebufferAbstract + Send + Sync>
|
|
|
|
}).collect::<Vec<_>>()
|
|
|
|
}).collect::<Vec<_>>()
|
|
|
@ -143,16 +153,21 @@ impl CanvasState {
|
|
|
|
// of your structs that implements the `FormatDesc` trait). Here we use the
|
|
|
|
// of your structs that implements the `FormatDesc` trait). Here we use the
|
|
|
|
// same format as the swapchain.
|
|
|
|
// same format as the swapchain.
|
|
|
|
format: format,
|
|
|
|
format: format,
|
|
|
|
// TODO:
|
|
|
|
samples: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// `color` is a custom name we give to the first and only attachment.
|
|
|
|
|
|
|
|
depth: {
|
|
|
|
|
|
|
|
load: Clear,
|
|
|
|
|
|
|
|
store: DontCare,
|
|
|
|
|
|
|
|
format: Format::D16Unorm,
|
|
|
|
samples: 1,
|
|
|
|
samples: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pass: {
|
|
|
|
pass: {
|
|
|
|
// We use the attachment named `color` as the one and only color attachment.
|
|
|
|
// We use the attachment named `color` as the one and only color attachment.
|
|
|
|
color: [color],
|
|
|
|
color: [color],
|
|
|
|
//color: [],
|
|
|
|
|
|
|
|
// No depth-stencil attachment is indicated with empty brackets.
|
|
|
|
// No depth-stencil attachment is indicated with empty brackets.
|
|
|
|
depth_stencil: {}
|
|
|
|
depth_stencil: {depth}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).unwrap());
|
|
|
|
).unwrap());
|
|
|
|
|
|
|
|
|
|
|
@ -372,7 +387,7 @@ impl CanvasState {
|
|
|
|
let g = hprof::enter("Textured Vertex Buffer");
|
|
|
|
let g = hprof::enter("Textured Vertex Buffer");
|
|
|
|
for (k, v) in self.textured_drawables.drain() {
|
|
|
|
for (k, v) in self.textured_drawables.drain() {
|
|
|
|
let vertex_buffer = v.clone().iter()
|
|
|
|
let vertex_buffer = v.clone().iter()
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex3D>, b| {
|
|
|
|
a.extend(b);
|
|
|
|
a.extend(b);
|
|
|
|
a
|
|
|
|
a
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -393,7 +408,7 @@ impl CanvasState {
|
|
|
|
let g = hprof::enter("Image Vertex Buffer");
|
|
|
|
let g = hprof::enter("Image Vertex Buffer");
|
|
|
|
for (k, v) in self.image_drawables.drain() {
|
|
|
|
for (k, v) in self.image_drawables.drain() {
|
|
|
|
let vertex_buffer = v.clone().iter()
|
|
|
|
let vertex_buffer = v.clone().iter()
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex3D>, b| {
|
|
|
|
a.extend(b);
|
|
|
|
a.extend(b);
|
|
|
|
a
|
|
|
|
a
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -427,7 +442,10 @@ impl CanvasState {
|
|
|
|
image_num: usize) -> AutoCommandBufferBuilder {
|
|
|
|
image_num: usize) -> 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!(ClearValue::Float([0.0, 0.0, 1.0, 1.0]));
|
|
|
|
let clear_values = vec!(
|
|
|
|
|
|
|
|
ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
|
|
|
|
|
|
|
|
1f32.into()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
|
|
|