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()
|
||||
|
||||
Reference in New Issue
Block a user