piping everything through. Almost done

master
mitchellhansen 5 years ago
parent e5ba27c353
commit 1551a53d1e

@ -1,4 +1,4 @@
use crate::canvas::canvas_state::{CanvasTextureHandle, CanvasImageHandle}; use crate::canvas::canvas_state::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle};
use vulkano::image::{ImmutableImage, AttachmentImage}; use vulkano::image::{ImmutableImage, AttachmentImage};
use std::sync::Arc; use std::sync::Arc;
use vulkano::format::{Format, R8Unorm}; use vulkano::format::{Format, R8Unorm};
@ -7,7 +7,6 @@ use vulkano::descriptor::DescriptorSet;
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess}; use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess};
use vulkano::pipeline::GraphicsPipelineAbstract; use vulkano::pipeline::GraphicsPipelineAbstract;
use crate::canvas::canvas_text::CanvasFontHandle;
use rusttype::Font; use rusttype::Font;
#[derive(Clone)] #[derive(Clone)]
@ -54,7 +53,7 @@ impl CanvasImage {
#[derive(Clone)] #[derive(Clone)]
pub struct CanvasFont { pub struct CanvasFont {
pub(crate) handle: Arc<CanvasImageHandle>, pub(crate) handle: Arc<CanvasFontHandle>,
pub(crate) buffer: Arc<(dyn BufferAccess + Send + Sync)>, // Font atlas pub(crate) buffer: Arc<(dyn BufferAccess + Send + Sync)>, // Font atlas
pub(crate) font: Font<'static>, pub(crate) font: Font<'static>,
pub(crate) name: String, pub(crate) name: String,

@ -1,8 +1,7 @@
use crate::util::vertex_3d::{Vertex3D}; use crate::util::vertex_3d::{Vertex3D};
use std::sync::Arc; use std::sync::Arc;
use std::collections::HashMap; use std::collections::HashMap;
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle}; use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle};
use crate::canvas::canvas_text::CanvasFontHandle;
use crate::canvas::shader::text_shader::GlyphInstance; use crate::canvas::shader::text_shader::GlyphInstance;
/// ///
@ -13,6 +12,10 @@ pub struct CanvasFrame {
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>> pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
} }
pub struct GenericCanvasFrame<V, H, Im, In, T> {
frame_data: HashMap<Arc<H>, Vec<(V, Im, In, T)>>
}
impl CanvasFrame { impl CanvasFrame {
/// Creates a bare canvas frame with empty accumulators /// Creates a bare canvas frame with empty accumulators

@ -20,17 +20,17 @@ 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::{CanvasFont, CanvasFontHandle}; use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasFont};
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasText}; use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
use crate::util::vertex_3d::Vertex3D;
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue}; 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;
use std::borrow::Borrow; use std::borrow::Borrow;
use crate::canvas::shader::text_shader::GlyphInstance; 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 /// 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
/// Provides Image and Texture handles for drawing /// 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 /// 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> { 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 }); let handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 });
@ -372,6 +335,48 @@ impl CanvasState {
Some(handle) 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 /// Using the texture name, iterates through the stored textures and matches by the name
pub fn get_texture_handle(&self, texture_name: String) pub fn get_texture_handle(&self, texture_name: String)
-> Option<Arc<CanvasTextureHandle>> { -> Option<Arc<CanvasTextureHandle>> {
@ -383,7 +388,7 @@ impl CanvasState {
None 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) pub fn get_shader_handle(&self, shader_name: String)
-> Option<Arc<CompiledGraphicsPipelineHandle>> { -> Option<Arc<CompiledGraphicsPipelineHandle>> {
for shader in self.shader_buffers.clone() { for shader in self.shader_buffers.clone() {
@ -394,6 +399,16 @@ impl CanvasState {
None 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 /// Using the texture handle, grab the stored texture and return the buffer
pub fn get_texture(&self, texture_handle: Arc<CanvasTextureHandle>) pub fn get_texture(&self, texture_handle: Arc<CanvasTextureHandle>)
-> Arc<ImmutableImage<Format>> { -> Arc<ImmutableImage<Format>> {
@ -588,22 +603,22 @@ impl CanvasState {
.unwrap().clone().handle as usize .unwrap().clone().handle as usize
).unwrap(); ).unwrap();
//
if !self.text_instances.is_empty() { // if !self.text_instances.is_empty() {
for (font_handle, instance_buffer) in self.text_instances.clone() { // for (font_handle, instance_buffer) in self.text_instances.clone() {
let handle = font_handle.clone().handle as usize; // let handle = font_handle.clone().handle as usize;
let font = self.font_buffers.get(handle).clone().unwrap().clone(); // let font = self.font_buffers.get(handle).clone().unwrap().clone();
let descriptor_set = CanvasText::get_descriptor_set(shader.get_pipeline()); // let descriptor_set = CanvasFont::get_descriptor_set(shader.get_pipeline());
//
command_buffer = command_buffer.draw( // command_buffer = command_buffer.draw(
shader.get_pipeline().clone(), // shader.get_pipeline().clone(),
// Multiple vertex buffers must have their definition in the pipeline! // // Multiple vertex buffers must have their definition in the pipeline!
&self.dynamic_state.clone(), // &self.dynamic_state.clone(),
vec![font.get_vertex_buffer().clone(), instance_buffer.clone()], // vec![font.get_vertex_buffer().clone(), instance_buffer.clone()],
(), (), // (), (),
).unwrap(); // ).unwrap();
} // }
} // }
command_buffer command_buffer
.end_render_pass() .end_render_pass()

@ -12,90 +12,65 @@ use std::fs::File;
use std::io::Read; use std::io::Read;
use crate::canvas::shader::text_shader::GlyphInstance; use crate::canvas::shader::text_shader::GlyphInstance;
use crate::util::vertex_3d::{Vertex3D, TextVertex3D}; use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
use crate::canvas::canvas_buffer::CanvasFont;
/*
//pub struct Glyph {}
So I think this thing is going to build text vertex buffers to send to the GPU. //
I assume I will just lay them out in ASCII for now along with a list of ///// So currently, I'm using these as container classes which vkprocessor owns
transformation matrices ///// I then use a CanvasFrame which accumulates lists of handles and vertices.
//pub struct CanvasFonto {
Glpyh: // font: Font<'static>,
index: 0-255, // font_name: String,
scale: 0.0 - 99.99 // allocated_font_atlas: Arc<(dyn BufferAccess + Send + Sync)>,
transform: (0.0, 0.0) - (1.0, 1.0) //}
//
I'm not sure if I want to send a new transformation matrix for each frame. But I suppose //impl CanvasFonto {
that can come when I look at caching the sprites //
// pub fn parse_to_vertex_buffer(font: Font) -> Vec<TextVertex3D> {
//
// let mut current_x = 0;
// let mut current_y = 0;
//
*/ // let mut accumulator = Vec::new();
//
pub struct Glyph {} // for i in (0..255) {
//
/// Typed wrapper for a u32 shader handle (index id) // let glyph = font.glyph(GlyphId{ 0: 40 });
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] //
pub struct CanvasFontHandle { // let glyph_data = glyph.get_data().unwrap();
pub handle: u32 //
} // for vertex in glyph_data.clone().shape.clone().unwrap() {
// accumulator.push(TextVertex3D {
/// So currently, I'm using these as container classes which vkprocessor owns // position: [vertex.x as f32, vertex.y as f32, 0.0],
/// I then use a CanvasFrame which accumulates lists of handles and vertices. // });
pub struct CanvasFont { // }
font: Font<'static>, // }
font_name: String, //
allocated_font_atlas: Arc<(dyn BufferAccess + Send + Sync)>, // accumulator
} // }
// /// Load the font
impl CanvasFont { // pub fn new(device: Arc<Device>, queue: Arc<Queue>, font_name: String) -> CanvasFonto {
//
fn parse_to_vertex_buffer(font: Font) -> Vec<TextVertex3D> { // let font = Font::from_bytes({
// let mut f = File::open("resources/fonts/sansation.ttf").expect("Font file not found");
let mut current_x = 0; // let mut font_data = Vec::new();
let mut current_y = 0; // f.read_to_end(&mut font_data).expect("Dont know");
// font_data
let mut accumulator = Vec::new(); // }).unwrap();
//
for i in (0..255) { // CanvasFont {
// font: font.clone(),
let glyph = font.glyph(GlyphId{ 0: 40 }); // font_name: font_name,
// allocated_font_atlas: ImmutableBuffer::from_iter(
let glyph_data = glyph.get_data().unwrap(); // CanvasFont::parse_to_vertex_buffer(font.clone()).iter().cloned(),
// BufferUsage::vertex_buffer(), queue).unwrap().0,
for vertex in glyph_data.clone().shape.clone().unwrap() { // }
accumulator.push(TextVertex3D { // }
position: [vertex.x as f32, vertex.y as f32, 0.0], //
}); // /// Generate a vertex buffer from the font
} // pub fn get_vertex_buffer(&self) -> Arc<(dyn BufferAccess + Send + Sync)> {
} // return self.allocated_font_atlas.clone();
// }
accumulator //
} //}
/// Load the font
pub fn new(device: Arc<Device>, queue: Arc<Queue>, font_name: String) -> CanvasFont {
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();
CanvasFont {
font: font.clone(),
font_name: font_name,
allocated_font_atlas: ImmutableBuffer::from_iter(
CanvasFont::parse_to_vertex_buffer(font.clone()).iter().cloned(),
BufferUsage::vertex_buffer(), queue).unwrap().0,
}
}
/// Generate a vertex buffer from the font
pub fn get_vertex_buffer(&self) -> Arc<(dyn BufferAccess + Send + Sync)> {
return self.allocated_font_atlas.clone();
}
}

@ -18,10 +18,10 @@ use shade_runner as sr;
#[derive(Default, Debug, Clone, Copy)] #[derive(Default, Debug, Clone, Copy)]
pub struct GlyphInstance { pub struct GlyphInstance {
screen_position: (f32, f32), pub screen_position: (f32, f32),
atlas_position: (f32, f32), pub atlas_position: (f32, f32),
atlas_size: (f32, f32), pub atlas_size: (f32, f32),
scale: f32, pub scale: f32,
} }
vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size, scale); vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size, scale);

@ -22,7 +22,7 @@ use sprite::Sprite;
use crate::util::load_raw; use crate::util::load_raw;
use crate::sprite::Poly; use crate::sprite::{Poly, Text};
use vulkano::instance::debug::DebugCallback; use vulkano::instance::debug::DebugCallback;
use crate::compute::compu_sprite::CompuSprite; use crate::compute::compu_sprite::CompuSprite;
use crate::compute::compu_frame::CompuFrame; use crate::compute::compu_frame::CompuFrame;
@ -66,6 +66,7 @@ pub fn main() {
processor.preload_kernels(); processor.preload_kernels();
processor.preload_shaders(); processor.preload_shaders();
processor.preload_textures(); processor.preload_textures();
processor.preload_fonts();
} }
let q2 = hprof::enter("Game Objects"); let q2 = hprof::enter("Game Objects");
@ -93,15 +94,11 @@ pub fn main() {
let funky_handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap(); let funky_handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap(); let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap();
let font_handle = processor.get_font_handle(String::from("sansation.ttf")).unwrap();
let funky_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone()); let funky_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
let sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone()); let sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
let text_sprite = Text::new((-0.1,-0.1), (10.0, 10.0), font_handle.clone());
// ========================
// Creating a new text... This is just something to interface with the
// canvas_frame. So it can be mutable
let text_sprite = TextSprite::new();
let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0)); let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));

@ -1,10 +1,11 @@
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest}; use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest, CanvasFontHandle};
use std::sync::Arc; use std::sync::Arc;
use crate::canvas::shader::text_shader::GlyphInstance; use crate::canvas::shader::text_shader::GlyphInstance;
use crate::canvas::canvas_buffer::CanvasFont;
use crate::util::vertex_3d::Vertex3D;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Sprite { pub struct Sprite {
pub vertices: [(f32, f32, f32); 6], pub vertices: [(f32, f32, f32); 6],
pub ti_position: [(f32, f32); 6], pub ti_position: [(f32, f32); 6],
@ -20,7 +21,6 @@ pub struct Sprite {
/// Container class which implements drawable. /// Container class which implements drawable.
impl Sprite { impl Sprite {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite { pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite {
Sprite::new_with_color(position, size, 0, (0., 0., 0., 0.)) Sprite::new_with_color(position, size, 0, (0., 0., 0., 0.))
} }
@ -29,7 +29,6 @@ impl Sprite {
size: (f32, f32), size: (f32, f32),
depth: u32, depth: u32,
color: (f32, f32, f32, f32)) -> Sprite { color: (f32, f32, f32, f32)) -> Sprite {
let normalized_depth = (depth as f32 / 255.0); let normalized_depth = (depth as f32 / 255.0);
Sprite { Sprite {
@ -59,8 +58,8 @@ impl Sprite {
screen_position: (0.0, 0.0), screen_position: (0.0, 0.0),
atlas_position: (0.0, 0.0), atlas_position: (0.0, 0.0),
atlas_size: (0.0, 0.0), atlas_size: (0.0, 0.0),
scale: 0.0 scale: 0.0,
} },
} }
} }
@ -69,7 +68,6 @@ impl Sprite {
size: (f32, f32), size: (f32, f32),
depth: u32, depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite { texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0); let normalized_depth = (depth as f32 / 255.0);
Sprite { Sprite {
@ -93,17 +91,15 @@ impl Sprite {
size: size, size: size,
color: (1.0, 0.0, 0.0, 1.0), color: (1.0, 0.0, 0.0, 1.0),
textured: true, textured: true,
texture_handle: Some(texture_handle.clone()) texture_handle: Some(texture_handle.clone()),
value: Default::default(),
} }
} }
} }
impl<V, H> DrawableTest<V, H> for Sprite { impl<V, H> DrawableTest<V, H> for Sprite {
fn get_vertices(&self) -> Vec<V> { fn get_vertices(&self) -> Vec<V> {
unimplemented!()
} }
fn get_handle(&self) -> Vec<H> { fn get_handle(&self) -> Vec<H> {
@ -112,7 +108,6 @@ impl<V, H> DrawableTest<V, H> for Sprite {
} }
impl Drawable for Sprite { impl Drawable for Sprite {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> { fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec() self.vertices.to_vec()
} }
@ -129,7 +124,7 @@ impl Drawable for Sprite {
match self.textured { match self.textured {
true => { true => {
self.texture_handle.clone() self.texture_handle.clone()
}, }
false => None, false => None,
} }
} }
@ -142,7 +137,6 @@ impl Drawable for Sprite {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Poly { pub struct Poly {
pub vertices: Vec<(f32, f32, f32)>, pub vertices: Vec<(f32, f32, f32)>,
pub ti_position: Vec<(f32, f32)>, pub ti_position: Vec<(f32, f32)>,
@ -154,13 +148,10 @@ pub struct Poly {
texture_handle: Option<Arc<CanvasTextureHandle>>, texture_handle: Option<Arc<CanvasTextureHandle>>,
// ================================== // ==================================
} }
/// Container class which implements drawable. /// Container class which implements drawable.
impl Poly { impl Poly {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly { pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
Poly::new_with_color(position, size, 0, (0., 0., 0., 0.)) Poly::new_with_color(position, size, 0, (0., 0., 0., 0.))
} }
@ -169,7 +160,6 @@ impl Poly {
size: (f32, f32), size: (f32, f32),
depth: u32, depth: u32,
color: (f32, f32, f32, f32)) -> Poly { color: (f32, f32, f32, f32)) -> Poly {
let normalized_depth = (depth as f32 / 255.0); let normalized_depth = (depth as f32 / 255.0);
Poly { Poly {
@ -177,31 +167,24 @@ impl Poly {
(-0.5, -0.5, normalized_depth), (-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(-0.25, 0.0, normalized_depth), (-0.25, 0.0, normalized_depth),
(-0.25, 0.0, normalized_depth), (-0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth), (0.0, 0.5, normalized_depth),
(0.25, 0.0, normalized_depth), (0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth), (0.0, 0.5, normalized_depth),
(0.5, -0.5, normalized_depth), (0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(0.25, 0.0, normalized_depth), (0.25, 0.0, normalized_depth),
(0.25, -0.5, normalized_depth), (0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(0.5, -0.5, normalized_depth), (0.5, -0.5, normalized_depth),
(0.25, -0.5, normalized_depth), (0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth), (0.0, -0.1, normalized_depth),
(-0.25, -0.5, normalized_depth), (-0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth), (0.0, -0.1, normalized_depth),
(-0.5, -0.5, normalized_depth), (-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth), (-1.0, 1.0, normalized_depth),
(-0.25, -0.5, normalized_depth), (-0.25, -0.5, normalized_depth),
@ -237,13 +220,12 @@ impl Poly {
size: size, size: size,
color: color, color: color,
textured: false, textured: false,
texture_handle: None texture_handle: None,
} }
} }
} }
impl Drawable for Poly { impl Drawable for Poly {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> { fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec() self.vertices.to_vec()
} }
@ -260,7 +242,7 @@ impl Drawable for Poly {
match self.textured { match self.textured {
true => { true => {
self.texture_handle.clone() self.texture_handle.clone()
}, }
false => None, false => None,
} }
} }
@ -272,74 +254,43 @@ impl Drawable for Poly {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Poly { pub struct Text {
position: (f32, f32, f32),
pub vertices: Vec<(f32, f32, f32)>, scale: f32,
pub ti_position: Vec<(f32, f32)>,
position: (f32, f32),
size: (f32, f32),
color: (f32, f32, f32, f32), color: (f32, f32, f32, f32),
textured: bool, text_handle: Arc<CanvasFontHandle>,
texture_handle: Option<Arc<CanvasTextureHandle>>,
// ==================================
} }
/// Container class which implements drawable. /// Container class which implements drawable.
impl Poly { impl Text {
pub fn new(position: (f32, f32), size: (f32, f32), font_handle: Arc<CanvasFontHandle>) -> Text {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly { Text::new_with_color(position, size, 0, (0., 0., 0., 0.), font_handle)
Poly::new_with_color(position, size, 0, (0.,0.,0.,0.))
} }
pub fn new_with_color(position: (f32, f32), pub fn new_with_color(position: (f32, f32),
size: (f32, f32), size: (f32, f32),
depth: u32, depth: u32,
color: (f32, f32, f32, f32)) -> Poly { color: (f32, f32, f32, f32),
handle: Arc<CanvasFontHandle>) -> Text {
let normalized_depth = (depth as f32 / 255.0); let normalized_depth = (depth as f32 / 255.0);
Poly { Text {
vertices: vec![], position: (position.0, position.1, normalized_depth),
scale: 0.0,
position: position, color,
ti_position: vec![], text_handle: handle,
size: size,
color: color,
textured: false,
texture_handle: None
} }
} }
} }
impl Drawable for Poly { impl<V, H> DrawableTest<V, H> for Text {
fn get_vertices(&self) -> Vec<V> {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> { unimplemented!()
self.vertices.to_vec()
}
fn get_color(&self) -> (f32, f32, f32, f32) {
self.color.clone()
}
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
self.ti_position.to_vec()
}
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
match self.textured {
true => {
self.texture_handle.clone()
},
false => None,
}
} }
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> { fn get_handle(&self) -> Vec<H> {
None unimplemented!()
} }
} }

@ -7,6 +7,7 @@ pub struct Vertex3D {
pub ti_position: [f32; 2], pub ti_position: [f32; 2],
} }
vulkano::impl_vertex!(Vertex3D, v_position, color, ti_position); vulkano::impl_vertex!(Vertex3D, v_position, color, ti_position);
/// Text vertex 3d with vertex position /// Text vertex 3d with vertex position

@ -11,7 +11,7 @@ use winit::Window;
use crate::compute::compu_state::CompuState; use crate::compute::compu_state::CompuState;
use vulkano::image::ImageUsage; use vulkano::image::ImageUsage;
use crate::compute::compu_frame::CompuFrame; use crate::compute::compu_frame::CompuFrame;
use crate::canvas::canvas_state::{CanvasState, CanvasTextureHandle, CanvasImageHandle}; use crate::canvas::canvas_state::{CanvasState, CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle};
use crate::canvas::canvas_frame::CanvasFrame; use crate::canvas::canvas_frame::CanvasFrame;
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle}; use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle}; use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
@ -163,6 +163,11 @@ impl<'a> VkProcessor<'a> {
self.canvas_state.load_shader::<TextShader>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone()); self.canvas_state.load_shader::<TextShader>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
} }
/// A hardcoded list of shaders which can be proloaded from this function
pub fn preload_fonts(&mut self) {
self.canvas_state.load_font(String::from("sansation.ttf"));
}
/// O(n) Lookup for the matching texture string /// O(n) Lookup for the matching texture string
pub fn get_texture_handle(&self, texture_name: String) -> Option<Arc<CanvasTextureHandle>> { pub fn get_texture_handle(&self, texture_name: String) -> Option<Arc<CanvasTextureHandle>> {
self.canvas_state.get_texture_handle(texture_name) self.canvas_state.get_texture_handle(texture_name)
@ -178,6 +183,10 @@ impl<'a> VkProcessor<'a> {
self.canvas_state.get_shader_handle(shader_name) self.canvas_state.get_shader_handle(shader_name)
} }
pub fn get_font_handle(&self, font_name: String) -> Option<Arc<CanvasFontHandle>> {
self.canvas_state.get_font_handle(font_name)
}
/// Create a new image which has the transfer usage /// Create a new image which has the transfer usage
pub fn new_swap_image(&mut self, dimensions: (u32, u32)) -> Arc<CanvasImageHandle> { pub fn new_swap_image(&mut self, dimensions: (u32, u32)) -> Arc<CanvasImageHandle> {
let mut usage = ImageUsage::none(); let mut usage = ImageUsage::none();

Loading…
Cancel
Save