some mishmash brainstorming on adding text rendering. Going to use inverted stencil buffer + glyph path method

This commit is contained in:
2019-09-17 20:10:16 -07:00
parent b13a834475
commit 89fc974d3c
7 changed files with 76 additions and 45 deletions

View File

@@ -20,8 +20,9 @@ use vulkano::pipeline::viewport::Viewport;
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
use crate::canvas_frame::CanvasFrame;
use std::hash::Hash;
use crate::canvas_text::{CanvasText};
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasText, CanvasTextCache};
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
use crate::vertex_3d::Vertex3D;
/// A drawable object can be passed into a CanvasFrame to be rendered

View File

@@ -11,6 +11,8 @@ use vulkano::swapchain::Capabilities;
use crate::vertex_2d::Vertex2D;
use vulkano::pipeline::vertex::SingleBufferDefinition;
use crate::vertex_3d::Vertex3D;
use vulkano::pipeline::depth_stencil::{DepthStencil, Stencil, StencilOp, Compare, DepthBounds};
/// Typed wrapper for a u32 shader handle (index id)
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
@@ -111,6 +113,22 @@ impl CanvasShader {
GraphicsShaderType::Vertex))
};
let stencil = DepthStencil {
depth_compare: Compare::Less,
depth_write: true,
depth_bounds_test: DepthBounds::Disabled,
stencil_front: Stencil {
compare: Compare::Never,
pass_op: StencilOp::Invert,
fail_op: StencilOp::Keep,
depth_fail_op: StencilOp::Keep,
compare_mask: Some(u32::MAX),
write_mask: Some(u32::MAX),
reference: Some(u32::MAX),
},
stencil_back: Default::default()
};
CanvasShader {
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
@@ -132,6 +150,7 @@ impl CanvasShader {
third_constant: 0.0,
})
.depth_stencil(stencil)
.depth_stencil_simple_depth()
// We have to indicate which subpass of which render pass this pipeline is going to be used

View File

@@ -1,10 +1,24 @@
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use rusttype::{Font, PositionedGlyph, Scale, Rect, point};
use rusttype::gpu_cache::Cache;
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
use vulkano::device::{Device, Queue};
use std::sync::Arc;
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
use vulkano::image::{ImmutableImage, ImageUsage, ImageLayout, Dimensions};
use vulkano::format::ClearValue;
use crate::vertex_2d::Vertex2D;
use vulkano::format::Format::R8Unorm;
const CACHE_WIDTH: usize = 1000;
const CACHE_HEIGHT: usize = 1000;
/// Typed wrapper for a u32 shader handle (index id)
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CanvasShaderHandle {
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 CanvasText {
@@ -24,13 +38,13 @@ impl CanvasText {
let cache_pixel_buffer = vec!(0; CACHE_WIDTH * CACHE_HEIGHT);
let font_data = include_bytes!("DejaVuSans.ttf");
let font = Font::from_bytes(font_data as &[u8]).unwrap();
// let font_data = include_bytes!("DejaVuSans.ttf");
// let font = Font::from_bytes(font_data as &[u8]).unwrap();
CanvasText {
device: (),
queue: (),
font: font,
font: (),
cache: (),
cache_pixel_buffer: (),
texts: ()
@@ -116,7 +130,7 @@ impl CanvasText {
// draw
for text in &mut self.texts.drain(..) {
let vertices: Vec<Vertex> = text.glyphs.iter().flat_map(|g| {
let vertices: Vec<Vertex2D> = text.glyphs.iter().flat_map(|g| {
if let Ok(Some((uv_rect, screen_rect))) = cache.rect_for(0, g) {
let gl_rect = Rect {
min: point(
@@ -129,37 +143,37 @@ impl CanvasText {
)
};
vec!(
Vertex {
position: [gl_rect.min.x, gl_rect.max.y],
tex_position: [uv_rect.min.x, uv_rect.max.y],
color: text.color,
},
Vertex {
position: [gl_rect.min.x, gl_rect.min.y],
tex_position: [uv_rect.min.x, uv_rect.min.y],
color: text.color,
},
Vertex {
position: [gl_rect.max.x, gl_rect.min.y],
tex_position: [uv_rect.max.x, uv_rect.min.y],
color: text.color,
},
Vertex {
position: [gl_rect.max.x, gl_rect.min.y],
tex_position: [uv_rect.max.x, uv_rect.min.y],
color: text.color,
},
Vertex {
position: [gl_rect.max.x, gl_rect.max.y],
tex_position: [uv_rect.max.x, uv_rect.max.y],
color: text.color,
},
Vertex {
position: [gl_rect.min.x, gl_rect.max.y],
tex_position: [uv_rect.min.x, uv_rect.max.y],
color: text.color,
},
// Vertex {
// position: [gl_rect.min.x, gl_rect.max.y],
// tex_position: [uv_rect.min.x, uv_rect.max.y],
// color: text.color,
// },
// Vertex {
// position: [gl_rect.min.x, gl_rect.min.y],
// tex_position: [uv_rect.min.x, uv_rect.min.y],
// color: text.color,
// },
// Vertex {
// position: [gl_rect.max.x, gl_rect.min.y],
// tex_position: [uv_rect.max.x, uv_rect.min.y],
// color: text.color,
// },
//
// Vertex {
// position: [gl_rect.max.x, gl_rect.min.y],
// tex_position: [uv_rect.max.x, uv_rect.min.y],
// color: text.color,
// },
// Vertex {
// position: [gl_rect.max.x, gl_rect.max.y],
// tex_position: [uv_rect.max.x, uv_rect.max.y],
// color: text.color,
// },
// Vertex {
// position: [gl_rect.min.x, gl_rect.max.y],
// tex_position: [uv_rect.min.x, uv_rect.max.y],
// color: text.color,
// },
).into_iter()
}
else {

View File

@@ -1,5 +1,4 @@
use std::collections::HashSet;
use sfml::window::{Key, Event, mouse::Button};
pub struct Input {
held_keys: HashSet<Key>,

View File

@@ -6,11 +6,9 @@ extern crate cgmath;
extern crate image;
extern crate nalgebra as na;
extern crate rand;
extern crate sfml;
extern crate time;
extern crate hprof;
use sfml::system::*;
use vulkano::sync;
use crate::timer::Timer;
use vulkano::instance::Instance;
@@ -27,9 +25,10 @@ use crate::compu_buffer::CompuBuffers;
use crate::util::load_raw;
use crate::canvas_frame::CanvasFrame;
pub mod util;
pub mod timer;
pub mod input;
//pub mod input;
pub mod vkprocessor;
pub mod vertex_2d;
pub mod vertex_3d;
@@ -39,6 +38,7 @@ pub mod canvas;
pub mod canvas_frame;
pub mod canvas_shader;
pub mod canvas_buffer;
pub mod canvas_text;
pub mod compu_state;
pub mod compu_frame;
@@ -84,8 +84,6 @@ pub fn main() {
let mut accumulator_time: f32 = 0.0;
let mut current_time: f32 = timer.elap_time();
let mut mouse_xy = Vector2i::new(0, 0);
let image_data = load_raw(String::from("funky-bird.jpg"));
let image_dimensions_f = ((image_data.1).0 as f32, (image_data.1).1 as f32);