getting the canvasframe set up for text
This commit is contained in:
@@ -29,6 +29,7 @@ use crate::canvas::shader::common::{CompiledGraphicsPipeline, CompiledGraphicsPi
|
||||
use crate::canvas::shader::generic_shader::GenericShader;
|
||||
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
||||
use rusttype::Glyph;
|
||||
use std::borrow::Borrow;
|
||||
|
||||
/// 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
|
||||
@@ -80,23 +81,22 @@ pub struct CanvasState {
|
||||
image_buffers: Vec<Arc<CanvasImage>>,
|
||||
texture_buffers: Vec<Arc<CanvasTexture>>,
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
text_buffers: Vec<Arc<(CanvasText, CanvasTextCache)>>,
|
||||
|
||||
//
|
||||
text_buffers: Vec<Arc<CanvasText>>,
|
||||
|
||||
// Hold onto the vertices we get from the Compu and Canvas Frames
|
||||
// When the run comes around, push the vertices to the GPU
|
||||
colored_drawables: Vec<Vertex3D>,
|
||||
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
|
||||
textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<Vertex3D>>>,
|
||||
textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
|
||||
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)>>,
|
||||
text_instances: HashMap<Arc<CanvasFontHandle>, Vec<(Vertex3D, )>>,
|
||||
text_atlas_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>,
|
||||
@@ -211,8 +211,8 @@ impl CanvasState {
|
||||
textured_vertex_buffer: Default::default(),
|
||||
image_drawables: Default::default(),
|
||||
image_vertex_buffer: Default::default(),
|
||||
text_drawables: HashMap::default(),
|
||||
text_vertex_buffer: Default::default(),
|
||||
text_instances: HashMap::default(),
|
||||
text_atlas_buffer: Default::default(),
|
||||
|
||||
queue: queue.clone(),
|
||||
device: device.clone(),
|
||||
@@ -257,7 +257,6 @@ impl CanvasState {
|
||||
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> {
|
||||
let handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 });
|
||||
@@ -404,22 +403,17 @@ impl CanvasState {
|
||||
|
||||
/// Scrape all the values from the CanvasFrame and then allocate the vertex buffers
|
||||
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
|
||||
self.textured_drawables = canvas_frame.textured_drawables;
|
||||
self.colored_drawables = canvas_frame.colored_drawables;
|
||||
self.image_drawables = canvas_frame.image_drawables;
|
||||
let textured_drawables = canvas_frame.textured_drawables;
|
||||
let colored_drawables = canvas_frame.colored_drawables;
|
||||
let image_drawables = canvas_frame.image_drawables;
|
||||
let text_drawables = canvas_frame.text_drawables;
|
||||
|
||||
self.allocate_vertex_buffers();
|
||||
}
|
||||
|
||||
/// draw(canvas_fame) stored all the intermediate information, this function
|
||||
/// allocates the vertex buffers using that information
|
||||
fn allocate_vertex_buffers(&mut self) {
|
||||
self.colored_vertex_buffer.clear();
|
||||
{
|
||||
let g = hprof::enter("Colored Vertex Buffer");
|
||||
self.colored_vertex_buffer.push(
|
||||
ImmutableBuffer::from_iter(
|
||||
self.colored_drawables.iter().cloned(),
|
||||
colored_drawables.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0
|
||||
@@ -467,6 +461,27 @@ impl CanvasState {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
self.text_instances.clear();
|
||||
{
|
||||
let g = hprof::enter("Text Instance Vertex Buffer");
|
||||
for (k, v) in self.text_.drain() {
|
||||
let vertex_buffer = v.clone().iter()
|
||||
.fold(Vec::new(), |mut a: Vec<Vertex3D>, b| {
|
||||
a.extend(b);
|
||||
a
|
||||
});
|
||||
|
||||
self.image_vertex_buffer.insert(
|
||||
k.clone(),
|
||||
ImmutableBuffer::from_iter(
|
||||
vertex_buffer.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the descriptor set for solid colors using the input kernel (needs to support solid colors)
|
||||
@@ -565,25 +580,30 @@ impl CanvasState {
|
||||
}
|
||||
|
||||
// Text
|
||||
// let mut shader = self.text_buffers.get(
|
||||
// self.get_shader_handle(String::from("simple_text"))
|
||||
// .unwrap().clone().handle as usize
|
||||
// ).unwrap();
|
||||
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 = text_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();
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
|
||||
if !self.text_atlas_buffer.is_empty() {
|
||||
for (text_handle, vertex_buffer) in self.text_atlas_buffer.clone() {
|
||||
let handle = text_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());
|
||||
let instance_data = self.text_instances.get(text_handle.borrow()).unwrap();
|
||||
|
||||
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![]),
|
||||
vec![descriptor_set], (),
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
command_buffer
|
||||
.end_render_pass()
|
||||
|
||||
Reference in New Issue
Block a user