You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
6 years ago
|
use crate::util::vertex_3d::{Vertex3D};
|
||
6 years ago
|
use std::sync::Arc;
|
||
|
use std::collections::HashMap;
|
||
6 years ago
|
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle};
|
||
6 years ago
|
|
||
6 years ago
|
///
|
||
6 years ago
|
pub struct CanvasFrame {
|
||
6 years ago
|
pub colored_drawables: Vec<Vertex3D>,
|
||
|
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<Vertex3D>>>,
|
||
|
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<Vertex3D>>>,
|
||
6 years ago
|
}
|
||
|
|
||
|
impl CanvasFrame {
|
||
6 years ago
|
|
||
|
/// Creates a bare canvas frame with empty accumulators
|
||
6 years ago
|
pub fn new() -> CanvasFrame {
|
||
|
CanvasFrame {
|
||
|
colored_drawables: vec![],
|
||
|
textured_drawables: Default::default(),
|
||
|
image_drawables: Default::default(),
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
/// Accumulates the drawables collected Vertex2D's
|
||
6 years ago
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
||
|
match drawable.get_texture_handle() {
|
||
|
Some(handle) => {
|
||
|
self.textured_drawables
|
||
|
.entry(handle.clone())
|
||
|
.or_insert(Vec::new())
|
||
6 years ago
|
.push(drawable.collect());
|
||
6 years ago
|
}
|
||
|
None => {
|
||
|
match drawable.get_image_handle() {
|
||
|
Some(handle) => {
|
||
|
self.image_drawables
|
||
|
.entry(handle.clone())
|
||
|
.or_insert(Vec::new())
|
||
6 years ago
|
.push(drawable.collect());
|
||
6 years ago
|
}
|
||
|
None => {
|
||
6 years ago
|
self.colored_drawables.extend(drawable.collect());
|
||
6 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|