|
|
|
@ -20,7 +20,7 @@ use vulkano::pipeline::viewport::Viewport;
|
|
|
|
|
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
|
|
|
|
use crate::canvas::canvas_frame::CanvasFrame;
|
|
|
|
|
use std::hash::Hash;
|
|
|
|
|
use crate::canvas::canvas_text::{CanvasText, CanvasTextHandle};
|
|
|
|
|
use crate::canvas::canvas_text::{CanvasText, CanvasFontHandle};
|
|
|
|
|
|
|
|
|
|
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
|
|
|
|
use crate::util::vertex_3d::Vertex3D;
|
|
|
|
@ -28,6 +28,7 @@ use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
|
|
|
|
use crate::canvas::shader::common::{CompiledGraphicsPipeline, CompiledGraphicsPipelineHandle};
|
|
|
|
|
use crate::canvas::shader::generic_shader::GenericShader;
|
|
|
|
|
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
|
|
|
|
use rusttype::Glyph;
|
|
|
|
|
|
|
|
|
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
|
|
|
|
/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color
|
|
|
|
@ -92,6 +93,11 @@ pub struct CanvasState {
|
|
|
|
|
image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<Vertex3D>>>,
|
|
|
|
|
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
// So what exactly is this going to hold?
|
|
|
|
|
// Its going to be untextured. Colored. Lists of vertices.
|
|
|
|
|
text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<(Vertex3D)>>,
|
|
|
|
|
text_vertex_buffer: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
|
|
queue: Arc<Queue>,
|
|
|
|
|
device: Arc<Device>,
|
|
|
|
@ -170,6 +176,8 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CanvasState {
|
|
|
|
|
|
|
|
|
|
// TODO: Might need to move this
|
|
|
|
|
dynamic_state: DynamicState {
|
|
|
|
|
line_width: None,
|
|
|
|
|
viewports: None,
|
|
|
|
@ -195,14 +203,16 @@ impl CanvasState {
|
|
|
|
|
image_buffers: vec![],
|
|
|
|
|
texture_buffers: vec![],
|
|
|
|
|
shader_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
text_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
colored_drawables: vec![],
|
|
|
|
|
colored_vertex_buffer: vec![],
|
|
|
|
|
textured_drawables: HashMap::default(),
|
|
|
|
|
textured_vertex_buffer: Default::default(),
|
|
|
|
|
image_drawables: Default::default(),
|
|
|
|
|
image_vertex_buffer: Default::default(),
|
|
|
|
|
text_drawables: HashMap::default(),
|
|
|
|
|
text_vertex_buffer: Default::default(),
|
|
|
|
|
|
|
|
|
|
queue: queue.clone(),
|
|
|
|
|
device: device.clone(),
|
|
|
|
@ -211,8 +221,8 @@ impl CanvasState {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
|
|
|
|
pub fn create_text_buffers(&mut self, dimensions: (u32, u32)) -> Arc<CanvasTextHandle> {
|
|
|
|
|
let handle = Arc::new(CanvasTextHandle { handle: self.text_buffers.len() as u32 });
|
|
|
|
|
pub fn create_text_buffers(&mut self, dimensions: (u32, u32)) -> Arc<CanvasFontHandle> {
|
|
|
|
|
let handle = Arc::new(CanvasFontHandle { handle: self.text_buffers.len() as u32 });
|
|
|
|
|
//
|
|
|
|
|
// let text = CanvasText {
|
|
|
|
|
// handle: handle.clone(),
|
|
|
|
@ -338,20 +348,19 @@ impl CanvasState {
|
|
|
|
|
/// Load and Compile a shader with the filename at resources/shaders
|
|
|
|
|
/// Takes physical and capabilities as we don't store that in Canvas
|
|
|
|
|
pub fn load_shader<T: 'static>(&mut self,
|
|
|
|
|
filename: String,
|
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
|
|
|
|
|
filename: String,
|
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
|
|
|
|
|
where T: CompiledGraphicsPipeline {
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CompiledGraphicsPipelineHandle {
|
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let shader : Box<dyn CompiledGraphicsPipeline> = Box::new(T::new(
|
|
|
|
|
let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new(
|
|
|
|
|
filename.clone(),
|
|
|
|
|
self.device.clone(),
|
|
|
|
|
handle.clone(),
|
|
|
|
|
self.render_pass.clone()
|
|
|
|
|
self.render_pass.clone(),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
self.shader_buffers.push(Arc::new(shader));
|
|
|
|
@ -482,12 +491,14 @@ impl CanvasState {
|
|
|
|
|
ClearValue::DepthStencil((1.0, 0x00)),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// self.dynamic_state = DynamicState {
|
|
|
|
|
// line_width: None,
|
|
|
|
|
// viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
|
// scissors: None,
|
|
|
|
|
// compare_mask: Some(StencilMask{ face: StencilFaceFlags::StencilFaceFrontBit, mask: 0xFF }),
|
|
|
|
|
// };
|
|
|
|
|
self.dynamic_state = DynamicState {
|
|
|
|
|
line_width: None,
|
|
|
|
|
viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
|
scissors: None,
|
|
|
|
|
compare_mask: None,
|
|
|
|
|
write_mask: None,
|
|
|
|
|
reference: None,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
|
|
|
@ -553,6 +564,27 @@ impl CanvasState {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Text
|
|
|
|
|
let mut shader = self.text_buffers.get(
|
|
|
|
|
self.get_shader_handle(String::from("simple_text"))
|
|
|
|
|
.unwrap().clone().handle as usize
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
if !self.text_vertex_buffer.is_empty() {
|
|
|
|
|
for (text_handle, vertex_buffer) in self.text_vertex_buffer.clone() {
|
|
|
|
|
let handle = texture_handle.clone().handle as usize;
|
|
|
|
|
let descriptor_set = self.text_buffers.get(handle).clone().unwrap().clone()
|
|
|
|
|
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone());
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command_buffer
|
|
|
|
|
.end_render_pass()
|
|
|
|
|
.unwrap()
|
|
|
|
|