|
|
@ -1,6 +1,6 @@
|
|
|
|
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
|
|
|
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer, CpuBufferPool};
|
|
|
|
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use vulkano::format::{ClearValue, Format, R8Unorm, ClearValuesTuple};
|
|
|
|
use vulkano::format::{ClearValue, Format, R8Unorm, ClearValuesTuple};
|
|
|
|
use vulkano::framebuffer::{FramebufferAbstract, Framebuffer, RenderPass, RenderPassAbstract};
|
|
|
|
use vulkano::framebuffer::{FramebufferAbstract, Framebuffer, RenderPass, RenderPassAbstract};
|
|
|
@ -28,8 +28,8 @@ use std::io::Read;
|
|
|
|
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment};
|
|
|
|
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment};
|
|
|
|
use vulkano::pipeline::vertex::{VertexDefinition, Vertex};
|
|
|
|
use vulkano::pipeline::vertex::{VertexDefinition, Vertex};
|
|
|
|
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
|
|
|
|
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
|
|
|
|
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle, DrawableHandle, CanvasUniformHandle};
|
|
|
|
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle, DrawableHandle};
|
|
|
|
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont, CanvasUniform};
|
|
|
|
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
|
|
|
|
use crate::canvas::managed::shader::shader_common::CompiledShader;
|
|
|
|
use crate::canvas::managed::shader::shader_common::CompiledShader;
|
|
|
|
use crate::canvas::managed::shader::generic_shader::GenericShader;
|
|
|
|
use crate::canvas::managed::shader::generic_shader::GenericShader;
|
|
|
|
use crate::VertexTypes;
|
|
|
|
use crate::VertexTypes;
|
|
|
@ -50,7 +50,6 @@ pub struct CanvasState {
|
|
|
|
image_buffers: Vec<Arc<CanvasImage>>,
|
|
|
|
image_buffers: Vec<Arc<CanvasImage>>,
|
|
|
|
texture_buffers: Vec<Arc<CanvasTexture>>,
|
|
|
|
texture_buffers: Vec<Arc<CanvasTexture>>,
|
|
|
|
font_buffers: Vec<Arc<CanvasFont>>,
|
|
|
|
font_buffers: Vec<Arc<CanvasFont>>,
|
|
|
|
uniform_buffers: Vec<Arc<CanvasUniform>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Compiled Graphics pipelines have a handle which self describe their position in this vector
|
|
|
|
/// Compiled Graphics pipelines have a handle which self describe their position in this vector
|
|
|
|
shader_buffers: Vec<Arc<Box<dyn CompiledShader>>>,
|
|
|
|
shader_buffers: Vec<Arc<Box<dyn CompiledShader>>>,
|
|
|
@ -162,8 +161,6 @@ impl CanvasState {
|
|
|
|
shader_buffers: vec![],
|
|
|
|
shader_buffers: vec![],
|
|
|
|
font_buffers: vec![],
|
|
|
|
font_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
uniform_buffer: CpuBufferPool::new(device.clone(), BufferUsage::all()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queue: queue.clone(),
|
|
|
|
queue: queue.clone(),
|
|
|
|
device: device.clone(),
|
|
|
|
device: device.clone(),
|
|
|
|
render_pass: render_pass.clone(),
|
|
|
|
render_pass: render_pass.clone(),
|
|
|
@ -255,24 +252,6 @@ impl CanvasState {
|
|
|
|
Some(handle)
|
|
|
|
Some(handle)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Load a texture using it's filename from a file. Returns the handle of the loaded texture
|
|
|
|
|
|
|
|
pub fn load_buffer_pool(&mut self) -> Option<Arc<CanvasTextureHandle>> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CanvasUniformHandle {
|
|
|
|
|
|
|
|
handle: self.uniform_buffers.len() as u32
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let texture = Arc::new(CanvasUniform {
|
|
|
|
|
|
|
|
handle: handle.clone(),
|
|
|
|
|
|
|
|
buffer: self.get_texture_from_file(filename.clone()),
|
|
|
|
|
|
|
|
name: filename.clone(),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.texture_buffers.push(texture);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Some(handle)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Load and Compile a shader with the filename at resources/shaders
|
|
|
|
/// Load and Compile a shader with the filename at resources/shaders
|
|
|
|
/// Takes physical and capabilities as we don't store that in Canvas
|
|
|
|
/// Takes physical and capabilities as we don't store that in Canvas
|
|
|
|
pub fn load_shader<T: 'static, V>(&mut self,
|
|
|
|
pub fn load_shader<T: 'static, V>(&mut self,
|
|
|
@ -563,11 +542,58 @@ impl CanvasState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Text
|
|
|
|
// Text
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
self.get_shader_handle(String::from("simple_text"))
|
|
|
|
self.get_shader_handle(String::from("simple_text"))
|
|
|
|
.unwrap().clone().get_handle() as usize
|
|
|
|
.unwrap().clone().get_handle() as usize
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// self.dynamic_state = DynamicState {
|
|
|
|
|
|
|
|
// line_width: None,
|
|
|
|
|
|
|
|
// viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
|
|
|
|
// scissors: None,
|
|
|
|
|
|
|
|
// compare_mask: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
// face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
// value: 0x00,
|
|
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// write_mask: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
// face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
// value: 0xFF,
|
|
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// reference: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
// face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
// value: 0x00,
|
|
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if !allocated_buffers.text_vertex_buffer.is_empty() {
|
|
|
|
|
|
|
|
// command_buffer = command_buffer.draw(
|
|
|
|
|
|
|
|
// shader.get_pipeline().clone(),
|
|
|
|
|
|
|
|
// &self.dynamic_state.clone(),
|
|
|
|
|
|
|
|
// allocated_buffers.text_vertex_buffer.clone(),
|
|
|
|
|
|
|
|
// (), (),
|
|
|
|
|
|
|
|
// ).unwrap();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// self.dynamic_state = DynamicState {
|
|
|
|
|
|
|
|
// line_width: None,
|
|
|
|
|
|
|
|
// viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
|
|
|
|
// scissors: None,
|
|
|
|
|
|
|
|
// compare_mask: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
// face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
// value: 0xFF,
|
|
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// write_mask: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
// face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
// value: 0x00,
|
|
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// reference: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
// face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
// value: 0x00,
|
|
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
if !allocated_buffers.text_vertex_buffer.is_empty() {
|
|
|
|
if !allocated_buffers.text_vertex_buffer.is_empty() {
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
@ -578,35 +604,6 @@ impl CanvasState {
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// So I need a uniform buffer which is the transformation matrix for the camera I think...
|
|
|
|
|
|
|
|
// I also need two buffers, one for normals, one for vertices. These can be piped through the
|
|
|
|
|
|
|
|
// current interfaces by just adding another type to VertexTypes
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 3D
|
|
|
|
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
|
|
|
|
self.get_shader_handle(String::from("simple_3d"))
|
|
|
|
|
|
|
|
.unwrap().clone().get_handle() as usize
|
|
|
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The other modules get the descriptor set like this
|
|
|
|
|
|
|
|
// let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
|
|
|
|
|
|
|
// .get_descriptor_set(shader.get_pipeline(), self.sampler.clone());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// let set = Arc::new(
|
|
|
|
|
|
|
|
// PersistentDescriptorSet::start(layout.clone()) //
|
|
|
|
|
|
|
|
// .add_buffer(uniform_buffer_subbuffer).unwrap()
|
|
|
|
|
|
|
|
// .build().unwrap()
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if !allocated_buffers.text_vertex_buffer.is_empty() {
|
|
|
|
|
|
|
|
// command_buffer = command_buffer.draw_indexed(
|
|
|
|
|
|
|
|
// shader.get_pipeline().clone(),
|
|
|
|
|
|
|
|
// &self.dynamic_state.clone(),
|
|
|
|
|
|
|
|
// vec!(vertex_buffer.clone(), normals_buffer.clone()),
|
|
|
|
|
|
|
|
// index_buffer.clone(), set.clone(), ()
|
|
|
|
|
|
|
|
// ).unwrap();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer
|
|
|
|
command_buffer
|
|
|
|
.end_render_pass()
|
|
|
|
.end_render_pass()
|
|
|
|