|
|
@ -20,7 +20,7 @@ use vulkano::pipeline::viewport::Viewport;
|
|
|
|
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
|
|
|
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
|
|
|
use crate::canvas::canvas_frame::CanvasFrame;
|
|
|
|
use crate::canvas::canvas_frame::CanvasFrame;
|
|
|
|
use std::hash::Hash;
|
|
|
|
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::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
|
|
|
use crate::util::vertex_3d::Vertex3D;
|
|
|
|
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::common::{CompiledGraphicsPipeline, CompiledGraphicsPipelineHandle};
|
|
|
|
use crate::canvas::shader::generic_shader::GenericShader;
|
|
|
|
use crate::canvas::shader::generic_shader::GenericShader;
|
|
|
|
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
|
|
|
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
|
|
|
|
|
|
|
use rusttype::Glyph;
|
|
|
|
|
|
|
|
|
|
|
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
|
|
|
/// 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
|
|
|
|
/// 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_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<Vertex3D>>>,
|
|
|
|
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
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
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
|
queue: Arc<Queue>,
|
|
|
|
queue: Arc<Queue>,
|
|
|
|
device: Arc<Device>,
|
|
|
|
device: Arc<Device>,
|
|
|
@ -170,6 +176,8 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CanvasState {
|
|
|
|
CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Might need to move this
|
|
|
|
dynamic_state: DynamicState {
|
|
|
|
dynamic_state: DynamicState {
|
|
|
|
line_width: None,
|
|
|
|
line_width: None,
|
|
|
|
viewports: None,
|
|
|
|
viewports: None,
|
|
|
@ -195,14 +203,16 @@ impl CanvasState {
|
|
|
|
image_buffers: vec![],
|
|
|
|
image_buffers: vec![],
|
|
|
|
texture_buffers: vec![],
|
|
|
|
texture_buffers: vec![],
|
|
|
|
shader_buffers: vec![],
|
|
|
|
shader_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
text_buffers: vec![],
|
|
|
|
text_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
colored_drawables: vec![],
|
|
|
|
colored_drawables: vec![],
|
|
|
|
colored_vertex_buffer: vec![],
|
|
|
|
colored_vertex_buffer: vec![],
|
|
|
|
textured_drawables: HashMap::default(),
|
|
|
|
textured_drawables: HashMap::default(),
|
|
|
|
textured_vertex_buffer: Default::default(),
|
|
|
|
textured_vertex_buffer: Default::default(),
|
|
|
|
image_drawables: Default::default(),
|
|
|
|
image_drawables: Default::default(),
|
|
|
|
image_vertex_buffer: Default::default(),
|
|
|
|
image_vertex_buffer: Default::default(),
|
|
|
|
|
|
|
|
text_drawables: HashMap::default(),
|
|
|
|
|
|
|
|
text_vertex_buffer: Default::default(),
|
|
|
|
|
|
|
|
|
|
|
|
queue: queue.clone(),
|
|
|
|
queue: queue.clone(),
|
|
|
|
device: device.clone(),
|
|
|
|
device: device.clone(),
|
|
|
@ -211,8 +221,8 @@ 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_text_buffers(&mut self, dimensions: (u32, u32)) -> Arc<CanvasTextHandle> {
|
|
|
|
pub fn create_text_buffers(&mut self, dimensions: (u32, u32)) -> Arc<CanvasFontHandle> {
|
|
|
|
let handle = Arc::new(CanvasTextHandle { handle: self.text_buffers.len() as u32 });
|
|
|
|
let handle = Arc::new(CanvasFontHandle { handle: self.text_buffers.len() as u32 });
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// let text = CanvasText {
|
|
|
|
// let text = CanvasText {
|
|
|
|
// handle: handle.clone(),
|
|
|
|
// handle: handle.clone(),
|
|
|
@ -342,16 +352,15 @@ impl CanvasState {
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
|
|
|
|
where T: CompiledGraphicsPipeline {
|
|
|
|
where T: CompiledGraphicsPipeline {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CompiledGraphicsPipelineHandle {
|
|
|
|
let handle = Arc::new(CompiledGraphicsPipelineHandle {
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
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(),
|
|
|
|
filename.clone(),
|
|
|
|
self.device.clone(),
|
|
|
|
self.device.clone(),
|
|
|
|
handle.clone(),
|
|
|
|
handle.clone(),
|
|
|
|
self.render_pass.clone()
|
|
|
|
self.render_pass.clone(),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
self.shader_buffers.push(Arc::new(shader));
|
|
|
|
self.shader_buffers.push(Arc::new(shader));
|
|
|
@ -482,12 +491,14 @@ impl CanvasState {
|
|
|
|
ClearValue::DepthStencil((1.0, 0x00)),
|
|
|
|
ClearValue::DepthStencil((1.0, 0x00)),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// self.dynamic_state = DynamicState {
|
|
|
|
self.dynamic_state = DynamicState {
|
|
|
|
// line_width: None,
|
|
|
|
line_width: None,
|
|
|
|
// viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
// scissors: None,
|
|
|
|
scissors: None,
|
|
|
|
// compare_mask: Some(StencilMask{ face: StencilFaceFlags::StencilFaceFrontBit, mask: 0xFF }),
|
|
|
|
compare_mask: None,
|
|
|
|
// };
|
|
|
|
write_mask: None,
|
|
|
|
|
|
|
|
reference: None,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
|
|
|
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
|
|
|
|
command_buffer
|
|
|
|
.end_render_pass()
|
|
|
|
.end_render_pass()
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|