piping everything through. Almost done
This commit is contained in:
@@ -20,17 +20,17 @@ 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::{CanvasFont, CanvasFontHandle};
|
||||
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasText};
|
||||
use crate::util::vertex_3d::Vertex3D;
|
||||
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasFont};
|
||||
use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
|
||||
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;
|
||||
use std::borrow::Borrow;
|
||||
use crate::canvas::shader::text_shader::GlyphInstance;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId};
|
||||
/// 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
|
||||
/// Provides Image and Texture handles for drawing
|
||||
@@ -225,43 +225,6 @@ 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.font_buffers.len() as u32 });
|
||||
//
|
||||
// let text = CanvasText {
|
||||
// handle: handle.clone(),
|
||||
// buffer: 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().0,
|
||||
// size: dimensions,
|
||||
// };
|
||||
//
|
||||
// let text_cache = CanvasTextCache {
|
||||
// handle: handle.clone(),
|
||||
// buffer: CpuAccessibleBuffer::<[u8]>::from_iter(
|
||||
// self.device.clone(),
|
||||
// BufferUsage::all(),
|
||||
// cache_pixel_buffer.iter().cloned()
|
||||
// ).unwrap(),
|
||||
// size: dimensions,
|
||||
// };
|
||||
//
|
||||
// self.text_buffers.push(Arc::new((text, text_cache)));
|
||||
//
|
||||
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 });
|
||||
@@ -372,6 +335,48 @@ impl CanvasState {
|
||||
Some(handle)
|
||||
}
|
||||
|
||||
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
||||
pub fn load_font(&mut self, name: String) -> Arc<CanvasFontHandle> {
|
||||
let handle = Arc::new(CanvasFontHandle { handle: self.font_buffers.len() as u32 });
|
||||
|
||||
self.font_buffers.push(Arc::new({
|
||||
let font = Font::from_bytes({
|
||||
let mut f = File::open("resources/fonts/sansation.ttf").expect("Font file not found");
|
||||
let mut font_data = Vec::new();
|
||||
f.read_to_end(&mut font_data).expect("Dont know");
|
||||
font_data
|
||||
}).unwrap();
|
||||
|
||||
let mut current_x = 0;
|
||||
let mut current_y = 0;
|
||||
|
||||
let mut accumulator = Vec::new();
|
||||
|
||||
for i in (0..255) {
|
||||
let glyph = font.glyph(GlyphId { 0: 40 });
|
||||
|
||||
let glyph_data = glyph.get_data().unwrap();
|
||||
|
||||
for vertex in glyph_data.clone().shape.clone().unwrap() {
|
||||
accumulator.push(TextVertex3D {
|
||||
position: [vertex.x as f32, vertex.y as f32, 0.0],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
CanvasFont {
|
||||
handle: handle.clone(),
|
||||
font: font.clone(),
|
||||
name: name,
|
||||
buffer: ImmutableBuffer::from_iter(
|
||||
accumulator.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(), self.queue.clone()).unwrap().0,
|
||||
}
|
||||
}));
|
||||
|
||||
handle
|
||||
}
|
||||
|
||||
/// Using the texture name, iterates through the stored textures and matches by the name
|
||||
pub fn get_texture_handle(&self, texture_name: String)
|
||||
-> Option<Arc<CanvasTextureHandle>> {
|
||||
@@ -383,7 +388,7 @@ impl CanvasState {
|
||||
None
|
||||
}
|
||||
|
||||
/// Using the shader name, iterates through the stored textures and matches by the name
|
||||
/// Using the shader name, iterates through the stored shaders and matches by the name
|
||||
pub fn get_shader_handle(&self, shader_name: String)
|
||||
-> Option<Arc<CompiledGraphicsPipelineHandle>> {
|
||||
for shader in self.shader_buffers.clone() {
|
||||
@@ -394,6 +399,16 @@ impl CanvasState {
|
||||
None
|
||||
}
|
||||
|
||||
/// Using the font name, iterates through the stored fonts and matches by the name
|
||||
pub fn get_font_handle(&self, font_name: String) -> Option<Arc<CanvasFontHandle>> {
|
||||
for font in self.font_buffers.clone() {
|
||||
if font.name == font_name {
|
||||
return Some(font.handle.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Using the texture handle, grab the stored texture and return the buffer
|
||||
pub fn get_texture(&self, texture_handle: Arc<CanvasTextureHandle>)
|
||||
-> Arc<ImmutableImage<Format>> {
|
||||
@@ -588,22 +603,22 @@ impl CanvasState {
|
||||
.unwrap().clone().handle as usize
|
||||
).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![font.get_vertex_buffer().clone(), instance_buffer.clone()],
|
||||
(), (),
|
||||
).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 = CanvasFont::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![font.get_vertex_buffer().clone(), instance_buffer.clone()],
|
||||
// (), (),
|
||||
// ).unwrap();
|
||||
// }
|
||||
// }
|
||||
|
||||
command_buffer
|
||||
.end_render_pass()
|
||||
|
||||
Reference in New Issue
Block a user