|
|
|
@ -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,32 +515,47 @@ impl CanvasState {
|
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
// 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)> = 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(),
|
|
|
|
|
self.queue.clone(),
|
|
|
|
|
).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
|
|
|
|
|
},
|
|
|
|
|
VertexTypes::VType2(vertices) => {
|
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
|
vertices.iter().cloned(),
|
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
|
self.queue.clone(),
|
|
|
|
|
).unwrap().0
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let buffer : Arc<(dyn BufferAccess + Send + Sync)> = ImmutableBuffer::from_iter(
|
|
|
|
|
value.iter().cloned(),
|
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
|
self.queue.clone(),
|
|
|
|
|
).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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command_buffer
|
|
|
|
|