|
|
|
@ -95,6 +95,52 @@ pub enum ShaderType {
|
|
|
|
|
COMPUTE = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct CanvasFrame {
|
|
|
|
|
colored_drawables : Vec<ColoredVertex2D>,
|
|
|
|
|
textured_drawables: HashMap<String, Vec<Vertex2D>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl CanvasFrame {
|
|
|
|
|
|
|
|
|
|
pub fn new() -> CanvasFrame {
|
|
|
|
|
CanvasFrame {
|
|
|
|
|
colored_drawables: vec![],
|
|
|
|
|
textured_drawables: Default::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// After done using this, need to call allocated vertex buffers
|
|
|
|
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
|
|
|
|
|
|
|
|
|
match drawable.get_texture_id() {
|
|
|
|
|
Some(id) => {
|
|
|
|
|
self.textured_drawables
|
|
|
|
|
.entry(id)
|
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
|
.extend(drawable.get_vertices().iter().map(|n|
|
|
|
|
|
Vertex2D {
|
|
|
|
|
position: [n.0, n.1],
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
None => {
|
|
|
|
|
let colors = drawable.get_color();
|
|
|
|
|
|
|
|
|
|
self.colored_drawables.extend(
|
|
|
|
|
drawable.get_vertices().iter().map(|n|
|
|
|
|
|
ColoredVertex2D {
|
|
|
|
|
position: [n.0, n.1],
|
|
|
|
|
color: [colors.0, colors.1, colors.2, colors.3]
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct Canvas {
|
|
|
|
|
|
|
|
|
@ -108,6 +154,8 @@ pub struct Canvas {
|
|
|
|
|
|
|
|
|
|
texture_store: HashMap<String, Arc<ImmutableImage<Format>>>,
|
|
|
|
|
|
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
|
|
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
|
|
queue: Arc<Queue>,
|
|
|
|
|
sampler: Arc<Sampler>
|
|
|
|
@ -139,6 +187,8 @@ impl Canvas {
|
|
|
|
|
shader_kernels: shader_kernels,
|
|
|
|
|
texture_store: Default::default(),
|
|
|
|
|
|
|
|
|
|
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
|
|
|
|
|
|
|
|
|
queue: queue.clone(),
|
|
|
|
|
sampler: Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
|
|
|
|
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
|
|
|
@ -200,37 +250,12 @@ impl Canvas {
|
|
|
|
|
self.texture_store.insert(filename, texture.clone());
|
|
|
|
|
texture
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// After done using this, need to call allocated vertex buffers
|
|
|
|
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
|
|
|
|
|
|
|
|
|
match drawable.get_texture_id() {
|
|
|
|
|
Some(id) => {
|
|
|
|
|
self.textured_drawables
|
|
|
|
|
.entry(id)
|
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
|
.extend(drawable.get_vertices().iter().map(|n|
|
|
|
|
|
Vertex2D {
|
|
|
|
|
position: [n.0, n.1],
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
None => {
|
|
|
|
|
let colors = drawable.get_color();
|
|
|
|
|
|
|
|
|
|
self.colored_drawables.extend(
|
|
|
|
|
drawable.get_vertices().iter().map(|n|
|
|
|
|
|
ColoredVertex2D {
|
|
|
|
|
position: [n.0, n.1],
|
|
|
|
|
color: [colors.0, colors.1, colors.2, colors.3]
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
|
|
|
|
|
self.textured_drawables = canvas_frame.textured_drawables;
|
|
|
|
|
self.colored_drawables = canvas_frame.colored_drawables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -313,6 +338,7 @@ impl Canvas {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
pub fn draw_commands(&self,
|
|
|
|
|
mut command_buffer: AutoCommandBufferBuilder,
|
|
|
|
@ -322,8 +348,6 @@ impl Canvas {
|
|
|
|
|
// 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]));
|
|
|
|
|
|
|
|
|
|
let dynamic_state = DynamicState { line_width: None, viewports: None, scissors: None };
|
|
|
|
|
|
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone()
|
|
|
|
|
).unwrap();
|
|
|
|
@ -334,8 +358,9 @@ impl Canvas {
|
|
|
|
|
ShaderType::SOLID => {
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
|
kernel.clone().get_pipeline().clone(),
|
|
|
|
|
&dynamic_state.clone(), self.colored_vertex_buffer.clone(),
|
|
|
|
|
vec![self.get_solid_color_descriptor_set()], ()
|
|
|
|
|
&self.dynamic_state.clone(),
|
|
|
|
|
self.colored_vertex_buffer.clone(),
|
|
|
|
|
(), ()
|
|
|
|
|
).unwrap();
|
|
|
|
|
},
|
|
|
|
|
ShaderType::TEXTURED => {
|
|
|
|
@ -355,21 +380,18 @@ impl Canvas {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This method is called once during initialization, then again whenever the window is resized
|
|
|
|
|
pub fn window_size_dependent_setup(&self,
|
|
|
|
|
pub fn window_size_dependent_setup(&mut self,
|
|
|
|
|
images: &[Arc<SwapchainImage<Window>>],
|
|
|
|
|
) -> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
|
|
|
|
|
|
|
|
|
let dimensions = images[0].dimensions();
|
|
|
|
|
|
|
|
|
|
let mut dynamic_state = DynamicState {
|
|
|
|
|
line_width: None,
|
|
|
|
|
viewports: Some(vec![Viewport {
|
|
|
|
|
self.dynamic_state.viewports =
|
|
|
|
|
Some(vec![Viewport {
|
|
|
|
|
origin: [0.0, 0.0],
|
|
|
|
|
dimensions: [dimensions.width() as f32, dimensions.height() as f32],
|
|
|
|
|
depth_range: 0.0..1.0,
|
|
|
|
|
}]),
|
|
|
|
|
scissors: None
|
|
|
|
|
};
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
images.iter().map(|image| {
|
|
|
|
|
Arc::new(
|
|
|
|
|