diff --git a/Cargo.toml b/Cargo.toml index b41d139a..8fd201d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ authors = ["MitchellHansen "] edition = "2018" [dependencies] -sfml = "0.14.0" cgmath = "0.17.0" simple-stopwatch="0.1.4" nalgebra = "0.18.0" @@ -22,4 +21,4 @@ shade_runner = {path = "../shade_runner"} winit = "0.19.1" #criterion = "0.3.0" hprof = "0.1.3" -rusttype = { version = "0.7", features = ["gpu_cache"] } \ No newline at end of file +rusttype = { version = "0.7.0", features = ["gpu_cache"] } \ No newline at end of file diff --git a/diagram.drawio b/diagram.drawio new file mode 100644 index 00000000..e2b9f148 --- /dev/null +++ b/diagram.drawio @@ -0,0 +1 @@ +7Vtbc5s4FP41ntl9SMdC4MtjbafdTtOZzHhnmz4qIGM1gDxCxHZ//R7ZAgwyDmkdC3fXL0FHAsH3nZt0lB6expuPgqyWX3hAo57TDzY9POs5DvLcPvxRkq2W4PFoLwkFC7SsFMzZD6qF+sYwYwFNKwMl55Fkq6rQ50lCfVmRESH4ujpswaPqrCsS6hn7pWDuk4gaw76yQC7zt4Nf2fMXZeFSGl0xycdrQbokAV8fiPBtD08F53J/FW+mNFIA5tDs7/vQ0Fu8m6CJbHODM4nZEGfjLERPaXj3/e7jbHODvP1jnkmU6Y+eZIsFFSCb8kQSllCR9pxBBHNMHkE8CNXV7yLZESO3OeGCZ0lAFWB96F4vmaTzFfFV7xp0HGRLGUfQQnAZkUca3fOUScYTkPlABACHJ89USAZadFcbELMgUDNNSMTCo3e81x3FSM0OdNNNI++o0CYwRcpjKsUWhugb8EgroLbCG6zb61KlnbGWLQ+U2clVmWgzCotnl2oGF1rTXqN1yNC6KUmeSfo33chM0F/j5RyYjauYOSZkyDkC2eDNEHMaEPsUKx/WNbxQ3zpg+ISKTYm/tA9aER87o2TuCcy6Ypp11DqgaoMG2OYQ8VUkrYedP3wer1gEmY3KZ9TXsxWNINL+aR1dI1gg61rpmJb8hSTg9VIDLRpA+qabXMglD3lCottSOqniWY6543ylUfxOpdzqXJRkwA+eAHhi+6D7d41v6gnvvLw52+gn7ltb3TK4US94mhn4Hp4Jn7bI2SQRIZWnBg6Pcy1oRCR7rr7J+XlzL8bPAc50w+RDTgZcHxAFrZIn1dgekvZQZfRbhdDj9J6T08FVcIqHrW0RfJCsUiNoyn6Qx90ABd+Ks0Tu3tCb9LzZq/LiXe49If5TuNOYKY+42M2LF7vfKW+oV4v6TXoHi7+StxMa3eg7b0B9+iPtrVrzoR93r8A4GMIXixQUoU5YMevPc5jHzyuyy5rbdV7yu+c0zGFLw8Rjm4aJTMPc5yDWMwrkvrz8PJpQoPGbZRSOVQsotL6IMa+OTOiCBjC6isiUv6ZhAB8Eie2vWupWUKTL9tJqcw/GhlWcU1PHbTV1ZDWHMjX1ve9ncQaT/0fyqNO2AgEe5TuE28qM3U2qct07IHUmyFphYz8Eu51zPtjczjxlA1eWn14wPc1Zezk97R9XkQvtBfTN6MzjVSY7YiC17eshsm4gZl3u0pteZzOOd31IDasG4rovmMiudU8FAzhVBDu73bTdQ8PYqt38X5797cuzw6rvcYem77lwedZpKmh0pQZUr1J49osUTfsvHanP1gAbWC+aOU3r9Q7VZ3HntMxcZXSwQIu7pmt4cHVJk739Ptx6RWE1M8INK4pubPc5XucWFEeOXCm8PlORqGOb13RGoZYxFcHNHrjmwZlrXa3ZK4HnGtpxx+Oiq+MUVuCQblVW4K5newWOcVu6rRZW8ZFzhMpvziWR9uMMqsUZt60rRKM384VmjvrP073gPk1TLqwjdoPqR1XbhmZv4L0aMmiWB/z3tYbyXyXw7b8= \ No newline at end of file diff --git a/src/canvas.rs b/src/canvas.rs index d0fd346e..0c8f8782 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -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 diff --git a/src/canvas_shader.rs b/src/canvas_shader.rs index 42ab85d5..c5ff8928 100644 --- a/src/canvas_shader.rs +++ b/src/canvas_shader.rs @@ -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 diff --git a/src/canvas_text.rs b/src/canvas_text.rs index f1b0a59a..cadedb6b 100644 --- a/src/canvas_text.rs +++ b/src/canvas_text.rs @@ -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 = text.glyphs.iter().flat_map(|g| { + let vertices: Vec = 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 { diff --git a/src/input.rs b/src/input.rs index 18e3adfd..5dc764ee 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,5 +1,4 @@ use std::collections::HashSet; -use sfml::window::{Key, Event, mouse::Button}; pub struct Input { held_keys: HashSet, diff --git a/src/main.rs b/src/main.rs index c7642a3e..d9433627 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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);