|
|
@ -1,4 +1,4 @@
|
|
|
|
use crate::vertex_2d::{Vertex2D};
|
|
|
|
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};
|
|
|
@ -68,7 +68,6 @@ pub struct CanvasImageHandle {
|
|
|
|
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
|
|
|
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct CanvasState {
|
|
|
|
pub struct CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
/// Generated during new()
|
|
|
|
/// Generated during new()
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
/// Generated during new()
|
|
|
|
/// Generated during new()
|
|
|
@ -98,11 +97,9 @@ 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>>])
|
|
|
|
-> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
|
|
|
-> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
|
|
|
|
|
|
|
|
|
|
|
let dimensions = images[0].dimensions();
|
|
|
|
let dimensions = images[0].dimensions();
|
|
|
|
|
|
|
|
|
|
|
|
self.dynamic_state.viewports =
|
|
|
|
self.dynamic_state.viewports =
|
|
|
@ -126,8 +123,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!(
|
|
|
@ -188,7 +183,6 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
|
|
|
/// 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> {
|
|
|
|
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 handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 });
|
|
|
|
|
|
|
|
|
|
|
|
let image = CanvasImage {
|
|
|
|
let image = CanvasImage {
|
|
|
@ -281,7 +275,6 @@ impl CanvasState {
|
|
|
|
shader_type: ShaderType,
|
|
|
|
shader_type: ShaderType,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CanvasShaderHandle {
|
|
|
|
let handle = Arc::new(CanvasShaderHandle {
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -378,10 +371,16 @@ 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()
|
|
|
|
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
|
|
|
|
|
|
|
a.extend(b);
|
|
|
|
|
|
|
|
a
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.textured_vertex_buffer.insert(
|
|
|
|
self.textured_vertex_buffer.insert(
|
|
|
|
k.clone(),
|
|
|
|
k.clone(),
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
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(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone(),
|
|
|
|
).unwrap().0,
|
|
|
|
).unwrap().0,
|
|
|
@ -393,11 +392,16 @@ 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()
|
|
|
|
|
|
|
|
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
|
|
|
|
|
|
|
a.extend(b);
|
|
|
|
|
|
|
|
a
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.image_vertex_buffer.insert(
|
|
|
|
self.image_vertex_buffer.insert(
|
|
|
|
k.clone(),
|
|
|
|
k.clone(),
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
v.iter().fold(Vec::new(), |mut acc, x| [acc.as_slice(), x.as_slice()].concat()).iter(),
|
|
|
|
vertex_buffer.iter().cloned(),
|
|
|
|
//v.first().unwrap().iter().cloned(),
|
|
|
|
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone(),
|
|
|
|
).unwrap().0,
|
|
|
|
).unwrap().0,
|
|
|
@ -460,6 +464,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
|
|
|
|
// Multiple vertex buffers must have their definition in the pipeline!
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
@ -480,6 +485,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
|
|
|
|
// Multiple vertex buffers must have their definition in the pipeline!
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|