|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
use crate::vertex_2d::{Vertex2D};
|
|
|
|
|
use crate::vertex_2d::Vertex2D;
|
|
|
|
|
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
|
|
|
@ -35,8 +35,8 @@ pub trait Drawable {
|
|
|
|
|
|
|
|
|
|
fn collect(&self) -> Vec<Vertex2D> {
|
|
|
|
|
let color = self.get_color();
|
|
|
|
|
self.get_vertices().iter().zip(self.get_ti_coords().iter()).map(|(a,b)|
|
|
|
|
|
Vertex2D{
|
|
|
|
|
self.get_vertices().iter().zip(self.get_ti_coords().iter()).map(|(a, b)|
|
|
|
|
|
Vertex2D {
|
|
|
|
|
v_position: [a.0, a.1],
|
|
|
|
|
color: [color.0, color.1, color.2, color.3],
|
|
|
|
|
ti_position: [b.0, b.1],
|
|
|
|
@ -68,7 +68,6 @@ pub struct CanvasImageHandle {
|
|
|
|
|
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct CanvasState {
|
|
|
|
|
|
|
|
|
|
/// Generated during new()
|
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
|
/// Generated during new()
|
|
|
|
@ -98,11 +97,9 @@ pub struct CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl CanvasState {
|
|
|
|
|
|
|
|
|
|
/// 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>>])
|
|
|
|
|
-> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
|
|
|
|
|
|
|
|
|
let dimensions = images[0].dimensions();
|
|
|
|
|
|
|
|
|
|
self.dynamic_state.viewports =
|
|
|
|
@ -126,8 +123,6 @@ 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!(
|
|
|
|
@ -188,7 +183,6 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
|
|
|
|
pub fn create_image(&mut self, dimensions: (u32, u32), usage: ImageUsage) -> Arc<CanvasImageHandle> {
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 });
|
|
|
|
|
|
|
|
|
|
let image = CanvasImage {
|
|
|
|
@ -281,7 +275,6 @@ impl CanvasState {
|
|
|
|
|
shader_type: ShaderType,
|
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CanvasShaderHandle {
|
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
|
});
|
|
|
|
@ -378,10 +371,16 @@ impl CanvasState {
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("Textured Vertex Buffer");
|
|
|
|
|
for (k, v) in self.textured_drawables.drain() {
|
|
|
|
|
let vertex_buffer = v.clone().iter()
|
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
|
|
|
|
a.extend(b);
|
|
|
|
|
a
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.textured_vertex_buffer.insert(
|
|
|
|
|
k.clone(),
|
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
|
v.first().unwrap().iter().cloned(), // I don't think doing a first is the right thing
|
|
|
|
|
vertex_buffer.iter().cloned(),
|
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
|
self.queue.clone(),
|
|
|
|
|
).unwrap().0,
|
|
|
|
@ -393,11 +392,16 @@ impl CanvasState {
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("Image Vertex Buffer");
|
|
|
|
|
for (k, v) in self.image_drawables.drain() {
|
|
|
|
|
let vertex_buffer = v.clone().iter()
|
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
|
|
|
|
a.extend(b);
|
|
|
|
|
a
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.image_vertex_buffer.insert(
|
|
|
|
|
k.clone(),
|
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
|
v.iter().fold(Vec::new(), |mut acc, x| [acc.as_slice(), x.as_slice()].concat()).iter(),
|
|
|
|
|
//v.first().unwrap().iter().cloned(),
|
|
|
|
|
vertex_buffer.iter().cloned(),
|
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
|
self.queue.clone(),
|
|
|
|
|
).unwrap().0,
|
|
|
|
@ -460,6 +464,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
|
// Multiple vertex buffers must have their definition in the pipeline!
|
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
|
).unwrap();
|
|
|
|
@ -480,6 +485,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
|
// Multiple vertex buffers must have their definition in the pipeline!
|
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
|
).unwrap();
|
|
|
|
|