stencil buffer is added, but not working for invert

master
mitchellhansen 5 years ago
parent 038eedeb97
commit 54fff9a4e9

@ -118,7 +118,7 @@ impl CanvasState {
}]); }]);
let dimensions = [dimensions.width(), dimensions.height()]; 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| { images.iter().map(|image| {
Arc::new( Arc::new(
@ -157,11 +157,11 @@ impl CanvasState {
format: format, format: format,
samples: 1, samples: 1,
}, },
// `color` is a custom name we give to the first and only attachment.
depth: { depth: {
load: Clear, load: Clear,
store: DontCare, store: DontCare,
format: Format::D16Unorm, format: Format::D32Sfloat_S8Uint,
samples: 1, samples: 1,
} }
}, },
@ -486,7 +486,7 @@ impl CanvasState {
// Specify the color to clear the framebuffer with i.e. blue // Specify the color to clear the framebuffer with i.e. blue
let clear_values = vec!( let clear_values = vec!(
ClearValue::Float([0.0, 0.0, 1.0, 1.0]), 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( let mut command_buffer = command_buffer.begin_render_pass(

@ -118,10 +118,10 @@ impl CanvasShader {
depth_write: true, depth_write: true,
depth_bounds_test: DepthBounds::Disabled, depth_bounds_test: DepthBounds::Disabled,
stencil_front: Stencil { stencil_front: Stencil {
compare: Compare::Never, compare: Compare::Always,
pass_op: StencilOp::Invert, pass_op: StencilOp::Invert,
fail_op: StencilOp::Keep, fail_op: StencilOp::Invert,
depth_fail_op: StencilOp::Keep, depth_fail_op: StencilOp::Invert,
compare_mask: Some(u32::max_value()), compare_mask: Some(u32::max_value()),
write_mask: Some(u32::max_value()), write_mask: Some(u32::max_value()),
reference: Some(u32::max_value()), reference: Some(u32::max_value()),

@ -24,6 +24,7 @@ use crate::compu_kernel::CompuKernel;
use crate::compu_buffer::CompuBuffers; 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;
use crate::sprite::Poly;
pub mod util; pub mod util;
@ -101,7 +102,9 @@ pub fn main() {
let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap(); 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 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); drop(q2);
@ -111,7 +114,6 @@ pub fn main() {
let mut exit = false; let mut exit = false;
let mut count = 0; let mut count = 0;
while let Some(p) = window.get_position() { while let Some(p) = window.get_position() {
@ -172,6 +174,8 @@ pub fn main() {
canvas.draw(&sfml_sprite); canvas.draw(&sfml_sprite);
canvas.draw(&compu_sprite1); canvas.draw(&compu_sprite1);
canvas.draw(&test_polygon);
{ {
let g = hprof::enter("Run"); let g = hprof::enter("Run");
processor.run(&surface, processor.run(&surface,

@ -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<Arc<CanvasTextureHandle>>,
}
/// 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(), [ pub fn new_with_color(position: (f32, f32),
ColoredVertex2D { position: [ 1.0, 1.0 ], color }, size: (f32, f32),
ColoredVertex2D { position: [ 1.0, 0.5 ], color }, depth: u32,
ColoredVertex2D { position: [ 0.5, 0.5 ], color }, color: (f32, f32, f32, f32)) -> Poly {
ColoredVertex2D { position: [ 0.5, 1.0 ], color },
].iter().cloned()).unwrap() 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
*/ (-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<Arc<CanvasTextureHandle>> {
match self.textured {
true => {
self.texture_handle.clone()
},
false => None,
}
}
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
None
}
}

Loading…
Cancel
Save