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 std::sync::Arc;
use vulkano::format::{Format, R8Unorm};
@ -7,7 +7,6 @@ use vulkano::descriptor::DescriptorSet;
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess};
use vulkano::pipeline::GraphicsPipelineAbstract;
use crate::canvas::canvas_text::CanvasFontHandle;
use rusttype::Font;
#[derive(Clone)]
@ -54,7 +53,7 @@ impl CanvasImage {
#[derive(Clone)]
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) font: Font<'static>,
pub(crate) name: String,

@ -1,8 +1,7 @@
use crate::util::vertex_3d::{Vertex3D};
use std::sync::Arc;
use std::collections::HashMap;
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle};
use crate::canvas::canvas_text::CanvasFontHandle;
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle};
use crate::canvas::shader::text_shader::GlyphInstance;
///
@ -13,6 +12,10 @@ pub struct CanvasFrame {
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 {
/// Creates a bare canvas frame with empty accumulators

@ -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()

@ -12,90 +12,65 @@ use std::fs::File;
use std::io::Read;
use crate::canvas::shader::text_shader::GlyphInstance;
use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
/*
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
transformation matrices
Glpyh:
index: 0-255,
scale: 0.0 - 99.99
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
that can come when I look at caching the sprites
*/
pub struct Glyph {}
/// Typed wrapper for a u32 shader handle (index id)
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CanvasFontHandle {
pub handle: u32
}
/// So currently, I'm using these as container classes which vkprocessor owns
/// 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)>,
}
impl CanvasFont {
fn parse_to_vertex_buffer(font: Font) -> Vec<TextVertex3D> {
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],
});
}
}
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();
}
}
use crate::canvas::canvas_buffer::CanvasFont;
//pub struct Glyph {}
//
///// So currently, I'm using these as container classes which vkprocessor owns
///// I then use a CanvasFrame which accumulates lists of handles and vertices.
//pub struct CanvasFonto {
// font: Font<'static>,
// font_name: String,
// allocated_font_atlas: Arc<(dyn BufferAccess + Send + Sync)>,
//}
//
//impl CanvasFonto {
//
// 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();
//
// 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],
// });
// }
// }
//
// accumulator
// }
// /// Load the font
// pub fn new(device: Arc<Device>, queue: Arc<Queue>, font_name: String) -> CanvasFonto {
//
// 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)]
pub struct GlyphInstance {
screen_position: (f32, f32),
atlas_position: (f32, f32),
atlas_size: (f32, f32),
scale: f32,
pub screen_position: (f32, f32),
pub atlas_position: (f32, f32),
pub atlas_size: (f32, f32),
pub scale: f32,
}
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::sprite::Poly;
use crate::sprite::{Poly, Text};
use vulkano::instance::debug::DebugCallback;
use crate::compute::compu_sprite::CompuSprite;
use crate::compute::compu_frame::CompuFrame;
@ -66,6 +66,7 @@ pub fn main() {
processor.preload_kernels();
processor.preload_shaders();
processor.preload_textures();
processor.preload_fonts();
}
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 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 sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 1, sfml_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 text_sprite = Text::new((-0.1,-0.1), (10.0, 10.0), font_handle.clone());
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 crate::canvas::shader::text_shader::GlyphInstance;
use crate::canvas::canvas_buffer::CanvasFont;
use crate::util::vertex_3d::Vertex3D;
#[derive(Debug, Clone)]
pub struct Sprite {
pub vertices: [(f32, f32, f32); 6],
pub ti_position: [(f32, f32); 6],
@ -20,36 +21,34 @@ pub struct Sprite {
/// Container class which implements drawable.
impl 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.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1 + size.1 , normalized_depth), // bottom left
(position.0, position.1, normalized_depth), // top left
(position.0, position.1 + size.1, normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1, normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1 , normalized_depth), // top right
(position.0 + size.0, position.1, normalized_depth), // top right
],
position: position,
ti_position: [
(-0.0, -0.0), // top left
(-0.0, 1.0), // bottom left
( 1.0, 1.0), // bottom right
(-0.0, 1.0), // bottom left
(1.0, 1.0), // bottom right
(-0.0, -0.0), // top left
( 1.0, 1.0), // bottom right
( 1.0, -0.0), // top right
(1.0, 1.0), // bottom right
(1.0, -0.0), // top right
],
size: size,
color: color,
@ -59,8 +58,8 @@ impl Sprite {
screen_position: (0.0, 0.0),
atlas_position: (0.0, 0.0),
atlas_size: (0.0, 0.0),
scale: 0.0
}
scale: 0.0,
},
}
}
@ -69,41 +68,38 @@ impl Sprite {
size: (f32, f32),
depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1 + size.1 , normalized_depth), // bottom left
(position.0, position.1, normalized_depth), // top left
(position.0, position.1 + size.1, normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1, normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1 , normalized_depth), // top right
(position.0 + size.0, position.1, normalized_depth), // top right
],
position: position,
ti_position: [
(-0.0, -0.0), // top left
(-0.0, 1.0), // bottom left
( 1.0, 1.0), // bottom right
(-0.0, 1.0), // bottom left
(1.0, 1.0), // bottom right
(-0.0, -0.0), // top left
( 1.0, 1.0), // bottom right
( 1.0, -0.0), // top right
(1.0, 1.0), // bottom right
(1.0, -0.0), // top right
],
size: size,
color: (1.0, 0.0, 0.0, 1.0),
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 {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_handle(&self) -> Vec<H> {
@ -112,8 +108,7 @@ impl<V, H> DrawableTest<V, H> 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()
}
@ -129,7 +124,7 @@ impl Drawable for Sprite {
match self.textured {
true => {
self.texture_handle.clone()
},
}
false => None,
}
}
@ -142,7 +137,6 @@ impl Drawable for Sprite {
#[derive(Debug, Clone)]
pub struct Poly {
pub vertices: Vec<(f32, f32, f32)>,
pub ti_position: Vec<(f32, f32)>,
@ -154,97 +148,85 @@ pub struct Poly {
texture_handle: Option<Arc<CanvasTextureHandle>>,
// ==================================
}
/// Container class which implements drawable.
impl 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.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Poly {
let normalized_depth = (depth as f32 / 255.0);
Poly {
vertices: vec![
(-0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(-0.25 , 0.0 , normalized_depth),
(-0.25 , 0.0 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , 0.5 , normalized_depth),
(0.25 , 0.0 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , 0.5 , normalized_depth),
(0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.25 , 0.0 , normalized_depth),
(0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.5 , -0.5 , normalized_depth),
(0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , -0.1 , normalized_depth),
(-0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , -0.1 , normalized_depth),
(-0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(-0.25 , -0.5 , normalized_depth),
(-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(-0.25, 0.0, normalized_depth),
(-0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth),
(0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth),
(0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.25, 0.0, normalized_depth),
(0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.5, -0.5, normalized_depth),
(0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth),
(-0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth),
(-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(-0.25, -0.5, normalized_depth),
],
position: position,
ti_position: vec![
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
],
size: size,
color: color,
textured: false,
texture_handle: None
texture_handle: None,
}
}
}
impl Drawable for Poly {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec()
}
@ -260,7 +242,7 @@ impl Drawable for Poly {
match self.textured {
true => {
self.texture_handle.clone()
},
}
false => None,
}
}
@ -272,74 +254,43 @@ impl Drawable for Poly {
#[derive(Debug, Clone)]
pub struct Poly {
pub vertices: Vec<(f32, f32, f32)>,
pub ti_position: Vec<(f32, f32)>,
position: (f32, f32),
size: (f32, f32),
pub struct Text {
position: (f32, f32, f32),
scale: f32,
color: (f32, f32, f32, f32),
textured: bool,
texture_handle: Option<Arc<CanvasTextureHandle>>,
// ==================================
text_handle: Arc<CanvasFontHandle>,
}
/// Container class which implements drawable.
impl Poly {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
Poly::new_with_color(position, size, 0, (0.,0.,0.,0.))
impl Text {
pub fn new(position: (f32, f32), size: (f32, f32), font_handle: Arc<CanvasFontHandle>) -> Text {
Text::new_with_color(position, size, 0, (0., 0., 0., 0.), font_handle)
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
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);
Poly {
vertices: vec![],
position: position,
ti_position: vec![],
size: size,
color: color,
textured: false,
texture_handle: None
Text {
position: (position.0, position.1, normalized_depth),
scale: 0.0,
color,
text_handle: handle,
}
}
}
impl Drawable for Poly {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
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,
}
impl<V, H> DrawableTest<V, H> for Text {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
None
fn get_handle(&self) -> Vec<H> {
unimplemented!()
}
}
}

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

@ -11,7 +11,7 @@ use winit::Window;
use crate::compute::compu_state::CompuState;
use vulkano::image::ImageUsage;
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::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
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());
}
/// 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
pub fn get_texture_handle(&self, texture_name: String) -> Option<Arc<CanvasTextureHandle>> {
self.canvas_state.get_texture_handle(texture_name)
@ -178,6 +183,10 @@ impl<'a> VkProcessor<'a> {
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
pub fn new_swap_image(&mut self, dimensions: (u32, u32)) -> Arc<CanvasImageHandle> {
let mut usage = ImageUsage::none();

Loading…
Cancel
Save