stencil buffer is added, but not working for invert

This commit is contained in:
2019-09-18 18:53:45 -07:00
parent 038eedeb97
commit 54fff9a4e9
4 changed files with 104 additions and 19 deletions

View File

@@ -121,16 +121,97 @@ impl Drawable for Sprite {
}
}
/*
let vertex_buffer = {
#[derive(Debug, Clone)]
pub struct Poly {
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 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.))
}
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
(-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
}
}