in the midst of a very messy refactor of the way i build the command buffer
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
use crate::vertex_2d::ColoredVertex2D;
|
||||
use crate::canvas::Drawable;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
vertices: [ColoredVertex2D; 6],
|
||||
color: [f32; 4],
|
||||
pub vertices: [(f32, f32); 6],
|
||||
|
||||
position: (f32, f32),
|
||||
size: (u32, u32),
|
||||
color: (f32, f32, f32, f32),
|
||||
|
||||
textured: bool,
|
||||
texture_id: i32,
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
@@ -14,21 +23,80 @@ impl Sprite {
|
||||
|
||||
pub fn new_with_color(position: (f32, f32), size: (u32, u32), color: (f32, f32, f32, f32)) -> Sprite {
|
||||
|
||||
let size = (size.0 as f32, size.1 as f32);
|
||||
|
||||
let color = [color.0, color.1, color.2, color.3];
|
||||
let fsize = (size.0 as f32, size.1 as f32);
|
||||
|
||||
Sprite {
|
||||
vertices: [
|
||||
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
|
||||
ColoredVertex2D { position: [ position.0, position.1 + size.1], color }, // bottom left
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
|
||||
|
||||
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 ], color }, // top right
|
||||
(position.0, position.1 ), // top left
|
||||
(position.0, position.1 + fsize.1), // bottom left
|
||||
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
|
||||
(position.0, position.1 ), // top left
|
||||
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
|
||||
(position.0 + fsize.0, position.1 ), // top right
|
||||
],
|
||||
|
||||
position: position,
|
||||
size: size,
|
||||
color: color,
|
||||
textured: false,
|
||||
texture_id: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_texture(position: (f32, f32), size: (u32, u32), texture_id: i32) -> Sprite {
|
||||
|
||||
let fsize = (size.0 as f32, size.1 as f32);
|
||||
|
||||
Sprite {
|
||||
vertices: [
|
||||
(position.0, position.1 ), // top left
|
||||
(position.0, position.1 + fsize.1), // bottom left
|
||||
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
|
||||
(position.0, position.1 ), // top left
|
||||
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
|
||||
(position.0 + fsize.0, position.1 ), // top right
|
||||
],
|
||||
position,
|
||||
size,
|
||||
color: (0.0, 0.0, 0.0, 0.0),
|
||||
textured: false,
|
||||
texture_id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl Drawable for Sprite {
|
||||
fn get_vertices(&self) -> Vec<(f32,f32)> {
|
||||
self.vertices.to_vec()
|
||||
}
|
||||
|
||||
fn get_color(&self) -> (f32, f32, f32, f32) {
|
||||
self.color.clone()
|
||||
}
|
||||
|
||||
fn get_texture_id(&self) -> Option<i32> {
|
||||
match self.textured {
|
||||
true => {
|
||||
Some(self.texture_id.clone())
|
||||
},
|
||||
false => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
let vertex_buffer = {
|
||||
|
||||
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()
|
||||
};
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user