Piping just the vertex glyph representation first to test the stencil buffer
This commit is contained in:
@@ -18,7 +18,7 @@ use vulkano::swapchain::Capabilities;
|
||||
use winit::Window;
|
||||
use vulkano::pipeline::viewport::Viewport;
|
||||
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
||||
use crate::canvas::canvas_frame::{CanvasFrame};
|
||||
use crate::canvas::canvas_frame::CanvasFrame;
|
||||
use std::hash::Hash;
|
||||
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
||||
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
||||
@@ -236,7 +236,6 @@ impl CanvasState {
|
||||
|
||||
/// Load a texture using it's filename from a file. Returns the handle of the loaded texture
|
||||
pub fn load_texture(&mut self, filename: String) -> Option<Arc<CanvasTextureHandle>> {
|
||||
|
||||
let handle = Arc::new(CanvasTextureHandle {
|
||||
handle: self.texture_buffers.len() as u32
|
||||
});
|
||||
@@ -256,11 +255,10 @@ impl CanvasState {
|
||||
/// Load and Compile a shader with the filename at resources/shaders
|
||||
/// Takes physical and capabilities as we don't store that in Canvas
|
||||
pub fn load_shader<T: 'static, V>(&mut self,
|
||||
filename: String,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
|
||||
filename: String,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
|
||||
where T: CompiledShader, V: Vertex {
|
||||
|
||||
let handle = Arc::new(CompiledShaderHandle {
|
||||
handle: self.shader_buffers.len() as u32
|
||||
});
|
||||
@@ -277,13 +275,14 @@ 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 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
|
||||
@@ -388,12 +387,13 @@ impl CanvasState {
|
||||
|
||||
/// Consume and allocate the canvas frame data to the GPU
|
||||
pub fn allocate(&mut self, canvas_frame: CanvasFrame) -> CanvasFrameAllocation {
|
||||
|
||||
let mut colored_vertex_buffer: Vec<ColorVertex3D> = Vec::default();
|
||||
let mut textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Vec<TextureVertex3D>> = HashMap::new();
|
||||
let mut image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Vec<ImageVertex3D>> = HashMap::new();
|
||||
let mut text_instances: HashMap<Arc<CanvasFontHandle>, Vec<TextVertex3D>> = HashMap::new();
|
||||
|
||||
let mut text_vertex_buffer: Vec<TextVertex3D> = Vec::new();
|
||||
|
||||
for value in canvas_frame.map {
|
||||
match value {
|
||||
VertexTypes::TextureType(vertices, handle) => {
|
||||
@@ -405,7 +405,12 @@ impl CanvasState {
|
||||
VertexTypes::ColorType(vertices) => {
|
||||
colored_vertex_buffer.extend(vertices);
|
||||
}
|
||||
VertexTypes::ThreeDType(vertices) => {}
|
||||
VertexTypes::ThreeDType(vertices) => {
|
||||
|
||||
}
|
||||
VertexTypes::TextType(vertices) => {
|
||||
text_vertex_buffer.extend(vertices);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -418,25 +423,35 @@ impl CanvasState {
|
||||
).unwrap().0);
|
||||
}
|
||||
|
||||
let mut allocated_text_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>> = Vec::new();
|
||||
if !text_vertex_buffer.is_empty() {
|
||||
allocated_text_buffer.push(ImmutableBuffer::from_iter(
|
||||
text_vertex_buffer.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0);
|
||||
}
|
||||
|
||||
CanvasFrameAllocation {
|
||||
colored_vertex_buffer: allocated_colored_buffer,
|
||||
textured_vertex_buffer: textured_vertex_buffer.into_iter().map(|(k, v)| {
|
||||
(k,
|
||||
ImmutableBuffer::from_iter(
|
||||
v.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
||||
ImmutableBuffer::from_iter(
|
||||
v.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
||||
}).collect(),
|
||||
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
|
||||
(k,
|
||||
ImmutableBuffer::from_iter(
|
||||
v.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
||||
ImmutableBuffer::from_iter(
|
||||
v.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
||||
}).collect(),
|
||||
text_instances: Default::default(),
|
||||
text_vertex_buffer: allocated_text_buffer,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,28 +542,38 @@ impl CanvasState {
|
||||
}
|
||||
}
|
||||
|
||||
// Text
|
||||
// let mut shader = self.shader_buffers.get(
|
||||
// self.get_shader_handle(String::from("simple_text"))
|
||||
// .unwrap().clone().get_handle() as usize
|
||||
// ).unwrap();
|
||||
self.dynamic_state = DynamicState {
|
||||
line_width: None,
|
||||
viewports: self.dynamic_state.viewports.clone(),
|
||||
scissors: None,
|
||||
compare_mask: Some(DynamicStencilValue {
|
||||
face: StencilFaceFlags::StencilFrontAndBack,
|
||||
value: 0xFF,
|
||||
}),
|
||||
write_mask: Some(DynamicStencilValue {
|
||||
face: StencilFaceFlags::StencilFrontAndBack,
|
||||
value: 0xFF,
|
||||
}),
|
||||
reference: Some(DynamicStencilValue {
|
||||
face: StencilFaceFlags::StencilFrontAndBack,
|
||||
value: 0xFF,
|
||||
}),
|
||||
};
|
||||
|
||||
//
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
// Text
|
||||
let mut shader = self.shader_buffers.get(
|
||||
self.get_shader_handle(String::from("simple_text"))
|
||||
.unwrap().clone().get_handle() as usize
|
||||
).unwrap();
|
||||
|
||||
if !allocated_buffers.text_vertex_buffer.is_empty() {
|
||||
command_buffer = command_buffer.draw(
|
||||
shader.get_pipeline().clone(),
|
||||
&self.dynamic_state.clone(),
|
||||
allocated_buffers.text_vertex_buffer.clone(),
|
||||
(), (),
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
command_buffer
|
||||
.end_render_pass()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod polygon;
|
||||
pub mod sprite;
|
||||
pub mod rect;
|
||||
pub mod compu_sprite;
|
||||
pub mod compu_sprite;
|
||||
pub mod text;
|
||||
133
src/drawables/text.rs
Normal file
133
src/drawables/text.rs
Normal file
@@ -0,0 +1,133 @@
|
||||
use crate::canvas::canvas_frame::Drawable;
|
||||
use crate::util::vertex::{VertexTypes, ColorVertex3D};
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Text {
|
||||
pub verts: VertexTypes,
|
||||
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
}
|
||||
|
||||
/// Container class which implements drawable.
|
||||
impl Text {
|
||||
///
|
||||
pub fn new(position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
depth: u32) -> Text {
|
||||
let normalized_depth = (depth as f32 / 255.0);
|
||||
|
||||
let verts = {
|
||||
vec![
|
||||
ColorVertex3D {
|
||||
v_position: [-0.5, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, 0.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, 0.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, 0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, 0.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, 0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.5, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, 0.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.5, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, -0.1, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, -0.1, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.5, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
}]
|
||||
};
|
||||
|
||||
Text {
|
||||
verts: VertexTypes::ColorType(verts),
|
||||
position: position,
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Text {
|
||||
fn get(&self) -> VertexTypes {
|
||||
self.verts.clone()
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
|
||||
use crate::drawables::sprite::Sprite;
|
||||
use crate::drawables::rect::Rect;
|
||||
use crate::drawables::compu_sprite::CompuSprite;
|
||||
use crate::drawables::text::Text;
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
@@ -111,7 +112,7 @@ pub fn main() {
|
||||
|
||||
|
||||
//let sfml_sprite = Sprite::new((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());
|
||||
let text_sprite = Text::new((-0.1,-0.1), (10.0, 10.0), 1);
|
||||
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
||||
|
||||
drop(q2);
|
||||
@@ -173,7 +174,7 @@ pub fn main() {
|
||||
|
||||
let mut canvas_frame = CanvasFrame::default();
|
||||
canvas_frame.draw(&funky_sprite);
|
||||
canvas_frame.draw(&compu_sprite1);
|
||||
canvas_frame.draw(&text_sprite);
|
||||
// canvas_frame.draw(&rect);
|
||||
|
||||
let mut compu_frame = CompuFrame::new();
|
||||
|
||||
@@ -56,6 +56,7 @@ pub enum VertexTypes {
|
||||
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
|
||||
ColorType(Vec<ColorVertex3D>),
|
||||
ThreeDType(Vec<Vertex3D>),
|
||||
TextType(Vec<TextVertex3D>),
|
||||
|
||||
}
|
||||
|
||||
@@ -65,6 +66,8 @@ pub struct CanvasFrameAllocation {
|
||||
pub textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
pub image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
pub text_instances: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
|
||||
pub text_vertex_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ impl<'a> VkProcessor<'a> {
|
||||
self.canvas_state.load_shader::<GenericShader, ColorVertex3D>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader, TextureVertex3D>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader, ImageVertex3D>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone());
|
||||
// self.canvas_state.load_shader::<TextShader, TextVertex3D>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<TextShader, ColorVertex3D>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
|
||||
}
|
||||
|
||||
/// A hardcoded list of shaders which can be proloaded from this function
|
||||
|
||||
Reference in New Issue
Block a user