diagramming out what I want to do here. CanvasFont will live with the buffers. Need to figure out how and where I'm going to query the font data for rendering
This commit is contained in:
@@ -5,9 +5,10 @@ use vulkano::format::{Format, R8Unorm};
|
||||
use vulkano::sampler::Sampler;
|
||||
use vulkano::descriptor::DescriptorSet;
|
||||
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
|
||||
use vulkano::buffer::CpuAccessibleBuffer;
|
||||
use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess};
|
||||
use vulkano::pipeline::GraphicsPipelineAbstract;
|
||||
use crate::canvas::canvas_text::CanvasFontHandle;
|
||||
use rusttype::Font;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CanvasTexture {
|
||||
@@ -52,10 +53,15 @@ impl CanvasImage {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CanvasText {
|
||||
pub struct CanvasFont {
|
||||
pub(crate) handle: Arc<CanvasImageHandle>,
|
||||
pub(crate) buffer: Arc<(dyn BufferAccess + Send + Sync)>, // Font atlas
|
||||
pub(crate) font: Font<'static>,
|
||||
pub(crate) name: String,
|
||||
|
||||
}
|
||||
|
||||
impl CanvasText {
|
||||
impl CanvasFont {
|
||||
pub fn get_descriptor_set(pipeline: Arc<dyn GraphicsPipelineAbstract + Sync + Send>)
|
||||
-> Box<dyn DescriptorSet + Send + Sync> {
|
||||
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
||||
|
||||
@@ -36,6 +36,13 @@ use crate::canvas::shader::text_shader::GlyphInstance;
|
||||
/// Provides Image and Texture handles for drawing
|
||||
/// Split out to two drawables?
|
||||
///
|
||||
|
||||
//
|
||||
pub trait DrawableTest<V, H> {
|
||||
fn get_vertices(&self) -> Vec<V>;
|
||||
fn get_handle(&self) -> Vec<H>;
|
||||
}
|
||||
|
||||
pub trait Drawable {
|
||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
||||
fn get_color(&self) -> (f32, f32, f32, f32);
|
||||
@@ -68,6 +75,12 @@ pub struct CanvasImageHandle {
|
||||
pub handle: u32
|
||||
}
|
||||
|
||||
/// Typed wrapper for a u32 font handle (index id)
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CanvasFontHandle {
|
||||
pub handle: u32
|
||||
}
|
||||
|
||||
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
||||
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
||||
#[derive(Clone)]
|
||||
@@ -77,14 +90,13 @@ pub struct CanvasState {
|
||||
/// Generated during new()
|
||||
sampler: Arc<Sampler>,
|
||||
|
||||
// hold the image, texture, and shader buffers the same was as we do CompuState
|
||||
// hold the image, texture, and Fonts the same was as we do CompuState
|
||||
image_buffers: Vec<Arc<CanvasImage>>,
|
||||
texture_buffers: Vec<Arc<CanvasTexture>>,
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
|
||||
// Individually hold onto the Fonts
|
||||
font_buffers: Vec<Arc<CanvasFont>>,
|
||||
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
|
||||
// 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 + Send + Sync)>>,
|
||||
|
||||
@@ -98,140 +98,4 @@ impl CanvasFont {
|
||||
return self.allocated_font_atlas.clone();
|
||||
}
|
||||
|
||||
/// postpone this until caching
|
||||
pub fn queue_text(&mut self,
|
||||
x: f32, y: f32,
|
||||
size: f32, color: [f32; 4],
|
||||
text: &str) {
|
||||
let glyphs: Vec<PositionedGlyph> = self.font.layout(text, Scale::uniform(size), point(x, y)).map(|x| x.standalone()).collect();
|
||||
// for glyph in &glyphs {
|
||||
// self.cache.queue_glyph(0, glyph.clone());
|
||||
// }
|
||||
// self.texts.push(TextData {
|
||||
// glyphs: glyphs.clone(),
|
||||
// color: color,
|
||||
// });
|
||||
}
|
||||
|
||||
pub fn draw_text(&mut self,
|
||||
command_buffer: AutoCommandBufferBuilder,
|
||||
image_num: usize,
|
||||
) -> AutoCommandBufferBuilder {
|
||||
|
||||
// let screen_width = 0;
|
||||
// let screen_height = 0;
|
||||
//
|
||||
// let cache_pixel_buffer = &mut self.cache_pixel_buffer;
|
||||
// let cache = &mut self.cache;
|
||||
//
|
||||
// // update texture cache
|
||||
// cache.cache_queued(
|
||||
// |rect, src_data| {
|
||||
// let width = (rect.max.x - rect.min.x) as usize;
|
||||
// let height = (rect.max.y - rect.min.y) as usize;
|
||||
// let mut dst_index = rect.min.y as usize * CACHE_WIDTH + rect.min.x as usize;
|
||||
// let mut src_index = 0;
|
||||
//
|
||||
// for _ in 0..height {
|
||||
// let dst_slice = &mut cache_pixel_buffer[dst_index..dst_index+width];
|
||||
// let src_slice = &src_data[src_index..src_index+width];
|
||||
// dst_slice.copy_from_slice(src_slice);
|
||||
//
|
||||
// dst_index += CACHE_WIDTH;
|
||||
// src_index += width;
|
||||
// }
|
||||
// }
|
||||
// ).unwrap();
|
||||
//
|
||||
// // need to get a hold of the cache buffer handle after I create it
|
||||
// // will then get swapped into this texture buffer
|
||||
// // Hmmm so this uninit call returns the texture and then a handle for whatever fills it up
|
||||
// let (cache_texture, cache_texture_write) = ImmutableImage::uninitialized(
|
||||
// self.device.clone(),
|
||||
// Dimensions::Dim2d { width: CACHE_WIDTH as u32, height: CACHE_HEIGHT as u32 },
|
||||
// R8Unorm,
|
||||
// 1,
|
||||
// ImageUsage {
|
||||
// sampled: true,
|
||||
// transfer_destination: true,
|
||||
// .. ImageUsage::none()
|
||||
// },
|
||||
// ImageLayout::General,
|
||||
// Some(self.queue.family())
|
||||
// ).unwrap();
|
||||
//
|
||||
//
|
||||
//
|
||||
// let set = Arc::new(
|
||||
// PersistentDescriptorSet::start(self.pipeline.clone(), 0)
|
||||
// .add_sampled_image(cache_texture.clone(), sampler).unwrap()
|
||||
// .build().unwrap()
|
||||
// );
|
||||
//
|
||||
// let mut command_buffer = command_buffer
|
||||
// .copy_buffer_to_image(
|
||||
// buffer.clone(),
|
||||
// cache_texture_write,
|
||||
// ).unwrap()
|
||||
// .begin_render_pass(self.framebuffers[image_num].clone(), false, vec!(ClearValue::None)).unwrap();
|
||||
//
|
||||
// // draw
|
||||
// for text in &mut self.texts.drain(..) {
|
||||
// let vertices: Vec<Vertex2D> = text.glyphs.iter().flat_map(|g| {
|
||||
// if let Ok(Some((uv_rect, screen_rect))) = cache.rect_for(0, g) {
|
||||
// let gl_rect = Rect {
|
||||
// min: point(
|
||||
// (screen_rect.min.x as f32 / screen_width as f32 - 0.5) * 2.0,
|
||||
// (screen_rect.min.y as f32 / screen_height as f32 - 0.5) * 2.0
|
||||
// ),
|
||||
// max: point(
|
||||
// (screen_rect.max.x as f32 / screen_width as f32 - 0.5) * 2.0,
|
||||
// (screen_rect.max.y as f32 / screen_height as f32 - 0.5) * 2.0
|
||||
// )
|
||||
// };
|
||||
// vec!(
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.min.x, gl_rect.max.y],
|
||||
//// tex_position: [uv_rect.min.x, uv_rect.max.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.min.x, gl_rect.min.y],
|
||||
//// tex_position: [uv_rect.min.x, uv_rect.min.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.max.x, gl_rect.min.y],
|
||||
//// tex_position: [uv_rect.max.x, uv_rect.min.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
////
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.max.x, gl_rect.min.y],
|
||||
//// tex_position: [uv_rect.max.x, uv_rect.min.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.max.x, gl_rect.max.y],
|
||||
//// tex_position: [uv_rect.max.x, uv_rect.max.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.min.x, gl_rect.max.y],
|
||||
//// tex_position: [uv_rect.min.x, uv_rect.max.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
// ).into_iter()
|
||||
// }
|
||||
// else {
|
||||
// vec!().into_iter()
|
||||
// }
|
||||
// }).collect();
|
||||
//
|
||||
// let vertex_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), vertices.into_iter()).unwrap();
|
||||
// command_buffer = command_buffer.draw(self.pipeline.clone(), &DynamicState::none(), vertex_buffer.clone(), set.clone(), ()).unwrap();
|
||||
// }
|
||||
|
||||
command_buffer//.end_render_pass().unwrap()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user