diff --git a/src/canvas.rs b/src/canvas.rs index 695b6e0b..51c17752 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -118,7 +118,7 @@ impl CanvasState { }]); let dimensions = [dimensions.width(), dimensions.height()]; - let depth_buffer = AttachmentImage::transient(self.device.clone(), dimensions, Format::D16Unorm).unwrap(); + let depth_buffer = AttachmentImage::transient(self.device.clone(), dimensions, Format::D32Sfloat_S8Uint).unwrap(); images.iter().map(|image| { Arc::new( @@ -157,11 +157,11 @@ impl CanvasState { format: format, samples: 1, }, - // `color` is a custom name we give to the first and only attachment. + depth: { load: Clear, store: DontCare, - format: Format::D16Unorm, + format: Format::D32Sfloat_S8Uint, samples: 1, } }, @@ -486,7 +486,7 @@ impl CanvasState { // Specify the color to clear the framebuffer with i.e. blue let clear_values = vec!( ClearValue::Float([0.0, 0.0, 1.0, 1.0]), - 1f32.into() + ClearValue::DepthStencil((1.0, 1)), ); let mut command_buffer = command_buffer.begin_render_pass( diff --git a/src/canvas_shader.rs b/src/canvas_shader.rs index 78d3eceb..1d9d8c75 100644 --- a/src/canvas_shader.rs +++ b/src/canvas_shader.rs @@ -118,10 +118,10 @@ impl CanvasShader { depth_write: true, depth_bounds_test: DepthBounds::Disabled, stencil_front: Stencil { - compare: Compare::Never, + compare: Compare::Always, pass_op: StencilOp::Invert, - fail_op: StencilOp::Keep, - depth_fail_op: StencilOp::Keep, + fail_op: StencilOp::Invert, + depth_fail_op: StencilOp::Invert, compare_mask: Some(u32::max_value()), write_mask: Some(u32::max_value()), reference: Some(u32::max_value()), diff --git a/src/main.rs b/src/main.rs index d9433627..042cd3ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use crate::compu_kernel::CompuKernel; use crate::compu_buffer::CompuBuffers; use crate::util::load_raw; use crate::canvas_frame::CanvasFrame; +use crate::sprite::Poly; pub mod util; @@ -101,7 +102,9 @@ pub fn main() { let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap(); let funky_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone()); - let sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 0, sfml_handle.clone()); + let sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone()); + + 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); @@ -111,7 +114,6 @@ pub fn main() { let mut exit = false; - let mut count = 0; while let Some(p) = window.get_position() { @@ -172,6 +174,8 @@ pub fn main() { canvas.draw(&sfml_sprite); canvas.draw(&compu_sprite1); + canvas.draw(&test_polygon); + { let g = hprof::enter("Run"); processor.run(&surface, diff --git a/src/sprite.rs b/src/sprite.rs index 62ef5b3c..d3be69c5 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -121,16 +121,97 @@ impl Drawable for Sprite { } } -/* - let vertex_buffer = { +#[derive(Debug, Clone)] +pub struct Poly { + + pub vertices: Vec<(f32, f32, f32)>, + pub ti_position: Vec<(f32, f32)>, + + position: (f32, f32), + size: (f32, f32), + color: (f32, f32, f32, f32), + + textured: bool, + texture_handle: Option>, + +} + +/// Container class which implements drawable. +impl Poly { + + pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly { + Poly::new_with_color(position, size, 0, (0.,0.,0.,0.)) + } - CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), [ - ColoredVertex2D { position: [ 1.0, 1.0 ], color }, - ColoredVertex2D { position: [ 1.0, 0.5 ], color }, - ColoredVertex2D { position: [ 0.5, 0.5 ], color }, - ColoredVertex2D { position: [ 0.5, 1.0 ], color }, - ].iter().cloned()).unwrap() - }; + pub fn new_with_color(position: (f32, f32), + size: (f32, f32), + depth: u32, + color: (f32, f32, f32, f32)) -> Poly { + + let normalized_depth = (depth as f32 / 255.0); + + Poly { + vertices: vec![ + (position.0, position.1 , normalized_depth), // top left + (position.0, position.1 + size.1 , normalized_depth), // bottom left + (position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right + + (position.0, position.1 , normalized_depth), // top left + (position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right + (position.0 + size.0, position.1 , normalized_depth), // top right + + (position.0 - 0.1, position.1 , normalized_depth), // top left + (position.0 - 0.1 + size.0, position.1 + size.1, normalized_depth), // bottom right + (position.0 - 0.1 + size.0, position.1 , normalized_depth), // top right + ], + + position: position, + ti_position: vec![ + (-0.0, -0.0), // top left + (-0.0, 1.0), // bottom left + ( 1.0, 1.0), // bottom right + + (-0.0, -0.0), // top left + ( 1.0, 1.0), // bottom right + ( 1.0, -0.0), // top right -*/ \ No newline at end of file + (-0.0, -0.0), // top left + ( 1.0, 1.0), // bottom right + ( 1.0, -0.0), // top right + ], + size: size, + color: color, + textured: false, + texture_handle: None + } + } +} + +impl Drawable for Poly { + + fn get_vertices(&self) -> Vec<(f32,f32,f32)> { + self.vertices.to_vec() + } + + fn get_color(&self) -> (f32, f32, f32, f32) { + self.color.clone() + } + + fn get_ti_coords(&self) -> Vec<(f32, f32)> { + self.ti_position.to_vec() + } + + fn get_texture_handle(&self) -> Option> { + match self.textured { + true => { + self.texture_handle.clone() + }, + false => None, + } + } + + fn get_image_handle(&self) -> Option> { + None + } +}