some mishmash brainstorming on adding text rendering. Going to use inverted stencil buffer + glyph path method
This commit is contained in:
@@ -5,7 +5,6 @@ authors = ["MitchellHansen <mitchellhansen0@gmail.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sfml = "0.14.0"
|
|
||||||
cgmath = "0.17.0"
|
cgmath = "0.17.0"
|
||||||
simple-stopwatch="0.1.4"
|
simple-stopwatch="0.1.4"
|
||||||
nalgebra = "0.18.0"
|
nalgebra = "0.18.0"
|
||||||
@@ -22,4 +21,4 @@ shade_runner = {path = "../shade_runner"}
|
|||||||
winit = "0.19.1"
|
winit = "0.19.1"
|
||||||
#criterion = "0.3.0"
|
#criterion = "0.3.0"
|
||||||
hprof = "0.1.3"
|
hprof = "0.1.3"
|
||||||
rusttype = { version = "0.7", features = ["gpu_cache"] }
|
rusttype = { version = "0.7.0", features = ["gpu_cache"] }
|
||||||
1
diagram.drawio
Normal file
1
diagram.drawio
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<mxfile modified="2019-09-17T05:36:48.980Z" host="www.draw.io" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/76.0.3809.100 Chrome/76.0.3809.100 Safari/537.36" etag="BK448PY-Hn1syjU6_G00" version="11.2.8" type="device" pages="1"><diagram id="eBoc7Yustm6TUbQq-vnT" name="Page-1">7Vtbc5s4FP41ntl9SMdC4MtjbafdTtOZzHhnmz4qIGM1gDxCxHZ//R7ZAgwyDmkdC3fXL0FHAsH3nZt0lB6expuPgqyWX3hAo57TDzY9POs5DvLcPvxRkq2W4PFoLwkFC7SsFMzZD6qF+sYwYwFNKwMl55Fkq6rQ50lCfVmRESH4ujpswaPqrCsS6hn7pWDuk4gaw76yQC7zt4Nf2fMXZeFSGl0xycdrQbokAV8fiPBtD08F53J/FW+mNFIA5tDs7/vQ0Fu8m6CJbHODM4nZEGfjLERPaXj3/e7jbHODvP1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Cm8PlORqGOb13RGoZYxFcHNHrjmwZlrXa3ZK4HnGtpxx+Oiq+MUVuCQblVW4K5newWOcVu6rRZW8ZFzhMpvziWR9uMMqsUZt60rRKM384VmjvrP073gPk1TLqwjdoPqR1XbhmZv4L0aMmiWB/z3tYbyXyXw7b8=</diagram></mxfile>
|
||||||
@@ -20,8 +20,9 @@ use vulkano::pipeline::viewport::Viewport;
|
|||||||
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
||||||
use crate::canvas_frame::CanvasFrame;
|
use crate::canvas_frame::CanvasFrame;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use crate::canvas_text::{CanvasText};
|
||||||
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
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;
|
use crate::vertex_3d::Vertex3D;
|
||||||
|
|
||||||
/// A drawable object can be passed into a CanvasFrame to be rendered
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use vulkano::swapchain::Capabilities;
|
|||||||
use crate::vertex_2d::Vertex2D;
|
use crate::vertex_2d::Vertex2D;
|
||||||
use vulkano::pipeline::vertex::SingleBufferDefinition;
|
use vulkano::pipeline::vertex::SingleBufferDefinition;
|
||||||
use crate::vertex_3d::Vertex3D;
|
use crate::vertex_3d::Vertex3D;
|
||||||
|
use vulkano::pipeline::depth_stencil::{DepthStencil, Stencil, StencilOp, Compare, DepthBounds};
|
||||||
|
|
||||||
|
|
||||||
/// Typed wrapper for a u32 shader handle (index id)
|
/// Typed wrapper for a u32 shader handle (index id)
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
@@ -111,6 +113,22 @@ impl CanvasShader {
|
|||||||
GraphicsShaderType::Vertex))
|
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 {
|
CanvasShader {
|
||||||
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
||||||
|
|
||||||
@@ -132,6 +150,7 @@ impl CanvasShader {
|
|||||||
third_constant: 0.0,
|
third_constant: 0.0,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.depth_stencil(stencil)
|
||||||
.depth_stencil_simple_depth()
|
.depth_stencil_simple_depth()
|
||||||
|
|
||||||
// We have to indicate which subpass of which render pass this pipeline is going to be used
|
// We have to indicate which subpass of which render pass this pipeline is going to be used
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
|
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
|
||||||
use rusttype::{Font, PositionedGlyph, Scale, Rect, point};
|
use rusttype::{Font, PositionedGlyph, Scale, Rect, point};
|
||||||
use rusttype::gpu_cache::Cache;
|
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_WIDTH: usize = 1000;
|
||||||
const CACHE_HEIGHT: 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
|
/// So currently, I'm using these as container classes which vkprocessor owns
|
||||||
/// I then use a CanvasFrame which accumulates lists of handles and vertices.
|
/// I then use a CanvasFrame which accumulates lists of handles and vertices.
|
||||||
pub struct CanvasText {
|
pub struct CanvasText {
|
||||||
@@ -24,13 +38,13 @@ impl CanvasText {
|
|||||||
let cache_pixel_buffer = vec!(0; CACHE_WIDTH * CACHE_HEIGHT);
|
let cache_pixel_buffer = vec!(0; CACHE_WIDTH * CACHE_HEIGHT);
|
||||||
|
|
||||||
|
|
||||||
let font_data = include_bytes!("DejaVuSans.ttf");
|
// let font_data = include_bytes!("DejaVuSans.ttf");
|
||||||
let font = Font::from_bytes(font_data as &[u8]).unwrap();
|
// let font = Font::from_bytes(font_data as &[u8]).unwrap();
|
||||||
|
|
||||||
CanvasText {
|
CanvasText {
|
||||||
device: (),
|
device: (),
|
||||||
queue: (),
|
queue: (),
|
||||||
font: font,
|
font: (),
|
||||||
cache: (),
|
cache: (),
|
||||||
cache_pixel_buffer: (),
|
cache_pixel_buffer: (),
|
||||||
texts: ()
|
texts: ()
|
||||||
@@ -116,7 +130,7 @@ impl CanvasText {
|
|||||||
|
|
||||||
// draw
|
// draw
|
||||||
for text in &mut self.texts.drain(..) {
|
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) {
|
if let Ok(Some((uv_rect, screen_rect))) = cache.rect_for(0, g) {
|
||||||
let gl_rect = Rect {
|
let gl_rect = Rect {
|
||||||
min: point(
|
min: point(
|
||||||
@@ -129,37 +143,37 @@ impl CanvasText {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
vec!(
|
vec!(
|
||||||
Vertex {
|
// Vertex {
|
||||||
position: [gl_rect.min.x, gl_rect.max.y],
|
// position: [gl_rect.min.x, gl_rect.max.y],
|
||||||
tex_position: [uv_rect.min.x, uv_rect.max.y],
|
// tex_position: [uv_rect.min.x, uv_rect.max.y],
|
||||||
color: text.color,
|
// color: text.color,
|
||||||
},
|
// },
|
||||||
Vertex {
|
// Vertex {
|
||||||
position: [gl_rect.min.x, gl_rect.min.y],
|
// position: [gl_rect.min.x, gl_rect.min.y],
|
||||||
tex_position: [uv_rect.min.x, uv_rect.min.y],
|
// tex_position: [uv_rect.min.x, uv_rect.min.y],
|
||||||
color: text.color,
|
// color: text.color,
|
||||||
},
|
// },
|
||||||
Vertex {
|
// Vertex {
|
||||||
position: [gl_rect.max.x, gl_rect.min.y],
|
// position: [gl_rect.max.x, gl_rect.min.y],
|
||||||
tex_position: [uv_rect.max.x, uv_rect.min.y],
|
// tex_position: [uv_rect.max.x, uv_rect.min.y],
|
||||||
color: text.color,
|
// color: text.color,
|
||||||
},
|
// },
|
||||||
|
//
|
||||||
Vertex {
|
// Vertex {
|
||||||
position: [gl_rect.max.x, gl_rect.min.y],
|
// position: [gl_rect.max.x, gl_rect.min.y],
|
||||||
tex_position: [uv_rect.max.x, uv_rect.min.y],
|
// tex_position: [uv_rect.max.x, uv_rect.min.y],
|
||||||
color: text.color,
|
// color: text.color,
|
||||||
},
|
// },
|
||||||
Vertex {
|
// Vertex {
|
||||||
position: [gl_rect.max.x, gl_rect.max.y],
|
// position: [gl_rect.max.x, gl_rect.max.y],
|
||||||
tex_position: [uv_rect.max.x, uv_rect.max.y],
|
// tex_position: [uv_rect.max.x, uv_rect.max.y],
|
||||||
color: text.color,
|
// color: text.color,
|
||||||
},
|
// },
|
||||||
Vertex {
|
// Vertex {
|
||||||
position: [gl_rect.min.x, gl_rect.max.y],
|
// position: [gl_rect.min.x, gl_rect.max.y],
|
||||||
tex_position: [uv_rect.min.x, uv_rect.max.y],
|
// tex_position: [uv_rect.min.x, uv_rect.max.y],
|
||||||
color: text.color,
|
// color: text.color,
|
||||||
},
|
// },
|
||||||
).into_iter()
|
).into_iter()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use sfml::window::{Key, Event, mouse::Button};
|
|
||||||
|
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
held_keys: HashSet<Key>,
|
held_keys: HashSet<Key>,
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ extern crate cgmath;
|
|||||||
extern crate image;
|
extern crate image;
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate sfml;
|
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate hprof;
|
extern crate hprof;
|
||||||
|
|
||||||
use sfml::system::*;
|
|
||||||
use vulkano::sync;
|
use vulkano::sync;
|
||||||
use crate::timer::Timer;
|
use crate::timer::Timer;
|
||||||
use vulkano::instance::Instance;
|
use vulkano::instance::Instance;
|
||||||
@@ -27,9 +25,10 @@ use crate::compu_buffer::CompuBuffers;
|
|||||||
use crate::util::load_raw;
|
use crate::util::load_raw;
|
||||||
use crate::canvas_frame::CanvasFrame;
|
use crate::canvas_frame::CanvasFrame;
|
||||||
|
|
||||||
|
|
||||||
pub mod util;
|
pub mod util;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
pub mod input;
|
//pub mod input;
|
||||||
pub mod vkprocessor;
|
pub mod vkprocessor;
|
||||||
pub mod vertex_2d;
|
pub mod vertex_2d;
|
||||||
pub mod vertex_3d;
|
pub mod vertex_3d;
|
||||||
@@ -39,6 +38,7 @@ pub mod canvas;
|
|||||||
pub mod canvas_frame;
|
pub mod canvas_frame;
|
||||||
pub mod canvas_shader;
|
pub mod canvas_shader;
|
||||||
pub mod canvas_buffer;
|
pub mod canvas_buffer;
|
||||||
|
pub mod canvas_text;
|
||||||
|
|
||||||
pub mod compu_state;
|
pub mod compu_state;
|
||||||
pub mod compu_frame;
|
pub mod compu_frame;
|
||||||
@@ -84,8 +84,6 @@ pub fn main() {
|
|||||||
let mut accumulator_time: f32 = 0.0;
|
let mut accumulator_time: f32 = 0.0;
|
||||||
let mut current_time: f32 = timer.elap_time();
|
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_data = load_raw(String::from("funky-bird.jpg"));
|
||||||
let image_dimensions_f = ((image_data.1).0 as f32, (image_data.1).1 as f32);
|
let image_dimensions_f = ((image_data.1).0 as f32, (image_data.1).1 as f32);
|
||||||
|
|||||||
Reference in New Issue
Block a user