working through the pipeline I have going on for the text stuff
This commit is contained in:
@@ -20,9 +20,8 @@ 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, CanvasFontHandle};
|
||||
|
||||
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
||||
use crate::canvas::canvas_text::{CanvasFont, CanvasFontHandle};
|
||||
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasText};
|
||||
use crate::util::vertex_3d::Vertex3D;
|
||||
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
||||
use crate::canvas::shader::common::{CompiledGraphicsPipeline, CompiledGraphicsPipelineHandle};
|
||||
@@ -30,6 +29,7 @@ use crate::canvas::shader::generic_shader::GenericShader;
|
||||
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
||||
use rusttype::Glyph;
|
||||
use std::borrow::Borrow;
|
||||
use crate::canvas::shader::text_shader::GlyphInstance;
|
||||
|
||||
/// 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
|
||||
@@ -82,21 +82,18 @@ pub struct CanvasState {
|
||||
texture_buffers: Vec<Arc<CanvasTexture>>,
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
|
||||
//
|
||||
text_buffers: Vec<Arc<CanvasText>>,
|
||||
// Individually hold onto the Fonts
|
||||
font_buffers: Vec<Arc<CanvasFont>>,
|
||||
|
||||
// Hold onto the vertices we get from the Compu and Canvas Frames
|
||||
// When the run comes around, push the vertices to the GPU
|
||||
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
|
||||
textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
|
||||
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
|
||||
// So what exactly is this going to hold?
|
||||
// Its going to be untextured. Colored. Lists of vertices.
|
||||
text_instances: HashMap<Arc<CanvasFontHandle>, Vec<(Vertex3D, )>>,
|
||||
text_atlas_buffer: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
text_instances: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
|
||||
// Looks like we gotta hold onto the queue for managing textures
|
||||
queue: Arc<Queue>,
|
||||
@@ -203,16 +200,12 @@ impl CanvasState {
|
||||
image_buffers: vec![],
|
||||
texture_buffers: vec![],
|
||||
shader_buffers: vec![],
|
||||
text_buffers: vec![],
|
||||
font_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_instances: HashMap::default(),
|
||||
text_atlas_buffer: Default::default(),
|
||||
|
||||
queue: queue.clone(),
|
||||
device: device.clone(),
|
||||
@@ -222,7 +215,7 @@ 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<CanvasFontHandle> {
|
||||
let handle = Arc::new(CanvasFontHandle { handle: self.text_buffers.len() as u32 });
|
||||
let handle = Arc::new(CanvasFontHandle { handle: self.font_buffers.len() as u32 });
|
||||
//
|
||||
// let text = CanvasText {
|
||||
// handle: handle.clone(),
|
||||
@@ -403,10 +396,14 @@ impl CanvasState {
|
||||
|
||||
/// Scrape all the values from the CanvasFrame and then allocate the vertex buffers
|
||||
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
|
||||
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;
|
||||
|
||||
// Consume the canvas frame
|
||||
let mut textured_drawables = canvas_frame.textured_drawables;
|
||||
let mut colored_drawables = canvas_frame.colored_drawables;
|
||||
let mut image_drawables = canvas_frame.image_drawables;
|
||||
let mut text_drawables = canvas_frame.text_drawables;
|
||||
|
||||
// Walk through the consumed items and allocate them to GPU buffers
|
||||
|
||||
self.colored_vertex_buffer.clear();
|
||||
{
|
||||
@@ -423,7 +420,7 @@ impl CanvasState {
|
||||
self.textured_vertex_buffer.clear();
|
||||
{
|
||||
let g = hprof::enter("Textured Vertex Buffer");
|
||||
for (k, v) in self.textured_drawables.drain() {
|
||||
for (k, v) in textured_drawables.drain() {
|
||||
let vertex_buffer = v.clone().iter()
|
||||
.fold(Vec::new(), |mut a: Vec<Vertex3D>, b| {
|
||||
a.extend(b);
|
||||
@@ -444,7 +441,7 @@ impl CanvasState {
|
||||
self.image_vertex_buffer.clear();
|
||||
{
|
||||
let g = hprof::enter("Image Vertex Buffer");
|
||||
for (k, v) in self.image_drawables.drain() {
|
||||
for (k, v) in image_drawables.drain() {
|
||||
let vertex_buffer = v.clone().iter()
|
||||
.fold(Vec::new(), |mut a: Vec<Vertex3D>, b| {
|
||||
a.extend(b);
|
||||
@@ -465,18 +462,12 @@ 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(
|
||||
for (k, v) in text_drawables.drain() {
|
||||
self.text_instances.insert(
|
||||
k.clone(),
|
||||
ImmutableBuffer::from_iter(
|
||||
vertex_buffer.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
v.iter().cloned(),
|
||||
BufferUsage::all(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0,
|
||||
);
|
||||
@@ -580,27 +571,24 @@ impl CanvasState {
|
||||
}
|
||||
|
||||
// Text
|
||||
let mut shader = self.text_buffers.get(
|
||||
let mut shader = self.shader_buffers.get(
|
||||
self.get_shader_handle(String::from("simple_text"))
|
||||
.unwrap().clone().handle as usize
|
||||
).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();
|
||||
if !self.text_instances.is_empty() {
|
||||
for (font_handle, instance_buffer) in self.text_instances.clone() {
|
||||
let handle = font_handle.clone().handle as usize;
|
||||
let font = self.font_buffers.get(handle).clone().unwrap().clone();
|
||||
let descriptor_set = CanvasText::get_descriptor_set(shader.get_pipeline());
|
||||
|
||||
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], (),
|
||||
vec![font.get_vertex_buffer().clone(), instance_buffer.clone()],
|
||||
(), (),
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user