|
|
@ -51,31 +51,22 @@ it appears that renderpass is tied to the individual shader
|
|
|
|
|
|
|
|
|
|
|
|
pub trait Vertex {
|
|
|
|
pub trait Vertex {
|
|
|
|
fn position(&self) -> (f32, f32) {
|
|
|
|
fn position(&self) -> (f32, f32) {
|
|
|
|
(0.0,0.0)
|
|
|
|
(0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
|
|
|
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
|
|
|
Some((0.,0.,0.,0.))
|
|
|
|
Some((0., 0., 0., 0.))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn textured(&self) -> bool {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Vertex for ColoredVertex2D {
|
|
|
|
impl Vertex for ColoredVertex2D {
|
|
|
|
|
|
|
|
|
|
|
|
fn position(&self) -> (f32, f32) {
|
|
|
|
fn position(&self) -> (f32, f32) {
|
|
|
|
(0.0,0.0)
|
|
|
|
(0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
|
|
|
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
|
|
|
Some((0.,0.,0.,0.))
|
|
|
|
Some((0., 0., 0., 0.))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn textured(&self) -> bool {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -86,17 +77,18 @@ pub trait Drawable {
|
|
|
|
fn get_image_handle(&self) -> Option<Arc<u32>>;
|
|
|
|
fn get_image_handle(&self) -> Option<Arc<u32>>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Need three types of shaders. Solid, Textured, Compute
|
|
|
|
// Need three types of shaders. Solid, Textured, Image
|
|
|
|
#[derive(PartialEq, Eq, Hash, Clone)]
|
|
|
|
#[derive(PartialEq, Eq, Hash, Clone)]
|
|
|
|
pub enum ShaderType {
|
|
|
|
pub enum ShaderType {
|
|
|
|
SOLID = 0,
|
|
|
|
SOLID = 0,
|
|
|
|
TEXTURED = 1,
|
|
|
|
TEXTURED = 1,
|
|
|
|
COMPUTE = 2
|
|
|
|
IMAGE = 2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct CanvasFrame {
|
|
|
|
pub struct CanvasFrame {
|
|
|
|
colored_drawables : Vec<ColoredVertex2D>,
|
|
|
|
colored_drawables: Vec<ColoredVertex2D>,
|
|
|
|
textured_drawables: HashMap<Arc<u32>, Vec<Vertex2D>>,
|
|
|
|
textured_drawables: HashMap<Arc<u32>, Vec<Vec<Vertex2D>>>,
|
|
|
|
|
|
|
|
image_drawables: HashMap<Arc<u32>, Vec<Vec<Vertex2D>>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CanvasFrame {
|
|
|
|
impl CanvasFrame {
|
|
|
@ -104,36 +96,52 @@ impl CanvasFrame {
|
|
|
|
pub fn new() -> CanvasFrame {
|
|
|
|
pub fn new() -> CanvasFrame {
|
|
|
|
CanvasFrame {
|
|
|
|
CanvasFrame {
|
|
|
|
colored_drawables: vec![],
|
|
|
|
colored_drawables: vec![],
|
|
|
|
textured_drawables: Default::default()
|
|
|
|
textured_drawables: Default::default(),
|
|
|
|
|
|
|
|
image_drawables: Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// After done using this, need to call allocated vertex buffers
|
|
|
|
// Accumulates the drawables vertices and colors
|
|
|
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
|
|
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
|
|
|
|
|
|
|
|
|
|
|
match drawable.get_texture_handle() {
|
|
|
|
match drawable.get_texture_handle() {
|
|
|
|
Some(id) => {
|
|
|
|
Some(handle) => {
|
|
|
|
self.textured_drawables
|
|
|
|
self.textured_drawables
|
|
|
|
.entry(id.clone())
|
|
|
|
.entry(handle.clone())
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
.extend(drawable.get_vertices().iter().map(|n|
|
|
|
|
.push(drawable.get_vertices().iter().map(|n|
|
|
|
|
Vertex2D {
|
|
|
|
Vertex2D {
|
|
|
|
position: [n.0, n.1],
|
|
|
|
position: [n.0, n.1],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
|
|
|
).collect::<Vec<Vertex2D>>());
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
let colors = drawable.get_color();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.colored_drawables.extend(
|
|
|
|
match drawable.get_image_handle() {
|
|
|
|
drawable.get_vertices().iter().map(|n|
|
|
|
|
|
|
|
|
ColoredVertex2D {
|
|
|
|
Some(handle) => {
|
|
|
|
position: [n.0, n.1],
|
|
|
|
self.image_drawables
|
|
|
|
color: [colors.0, colors.1, colors.2, colors.3]
|
|
|
|
.entry(handle.clone())
|
|
|
|
}
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
)
|
|
|
|
.push(drawable.get_vertices().iter().map(|n|
|
|
|
|
);
|
|
|
|
Vertex2D {
|
|
|
|
|
|
|
|
position: [n.0, n.1],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
).collect());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -142,31 +150,63 @@ impl CanvasFrame {
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Canvas {
|
|
|
|
pub struct Canvas {
|
|
|
|
|
|
|
|
|
|
|
|
colored_drawables : Vec<ColoredVertex2D>,
|
|
|
|
|
|
|
|
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textured_drawables: HashMap<Arc<u32>, Vec<Vertex2D>>,
|
|
|
|
|
|
|
|
textured_vertex_buffer: HashMap<Arc<u32>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shader_kernels: HashMap<ShaderType, ShaderKernels>,
|
|
|
|
shader_kernels: HashMap<ShaderType, ShaderKernels>,
|
|
|
|
|
|
|
|
|
|
|
|
texture_store: HashMap<String, Arc<ImmutableImage<Format>>>,
|
|
|
|
texture_store: HashMap<String, Arc<ImmutableImage<Format>>>,
|
|
|
|
|
|
|
|
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
|
|
|
|
sampler: Arc<Sampler>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// hold the image, texture, and shader buffers the same was as we do CompuState
|
|
|
|
image_buffers: Vec<std::sync::Arc<vulkano::image::attachment::AttachmentImage>>,
|
|
|
|
image_buffers: Vec<std::sync::Arc<vulkano::image::attachment::AttachmentImage>>,
|
|
|
|
image_buffer_handles: Vec<Arc<u32>>,
|
|
|
|
image_buffer_handles: Vec<Arc<u32>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
texture_buffers: Vec<Arc<ImmutableImage<Format>>>,
|
|
|
|
|
|
|
|
texture_buffer_handles: Vec<Arc<u32>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shader_buffers: HashMap<ShaderType, ShaderKernels>,
|
|
|
|
|
|
|
|
shader_buffer_handles: Vec<Arc<u32>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Hold onto the vertices we get from the Compu and Canvas Frames
|
|
|
|
|
|
|
|
// When the run comes around, push the vertices to the GPU
|
|
|
|
|
|
|
|
colored_drawables: Vec<ColoredVertex2D>,
|
|
|
|
|
|
|
|
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textured_drawables: HashMap<Arc<u32>, Vec<Vec<Vertex2D>>>,
|
|
|
|
|
|
|
|
textured_vertex_buffer: HashMap<Arc<u32>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image_drawables: HashMap<Arc<u32>, Vec<Vec<Vertex2D>>>,
|
|
|
|
|
|
|
|
image_vertex_buffer: HashMap<Arc<u32>, Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
|
|
|
|
|
|
|
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
|
// Looks like we gotta hold onto the queue for managing textures
|
|
|
|
queue: Arc<Queue>,
|
|
|
|
queue: Arc<Queue>,
|
|
|
|
sampler: Arc<Sampler>,
|
|
|
|
|
|
|
|
device: Arc<Device>,
|
|
|
|
device: Arc<Device>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Canvas {
|
|
|
|
impl Canvas {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This method is called once during initialization, then again whenever the window is resized
|
|
|
|
|
|
|
|
pub fn window_size_dependent_setup(&mut self, images: &[Arc<SwapchainImage<Window>>])
|
|
|
|
|
|
|
|
-> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
|
|
|
|
|
|
|
let dimensions = images[0].dimensions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
images.iter().map(|image| {
|
|
|
|
|
|
|
|
Arc::new(
|
|
|
|
|
|
|
|
Framebuffer::start(self.shader_kernels.get(&ShaderType::SOLID).unwrap().render_pass.clone())
|
|
|
|
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
|
|
|
|
.build().unwrap()
|
|
|
|
|
|
|
|
) as Arc<dyn FramebufferAbstract + Send + Sync>
|
|
|
|
|
|
|
|
}).collect::<Vec<_>>()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// needs to take in the texture list
|
|
|
|
// needs to take in the texture list
|
|
|
|
pub fn new(queue: Arc<Queue>,
|
|
|
|
pub fn new(queue: Arc<Queue>,
|
|
|
|
device: Arc<Device>,
|
|
|
|
device: Arc<Device>,
|
|
|
@ -176,33 +216,36 @@ impl Canvas {
|
|
|
|
let solid_color_kernel = String::from("color-passthrough");
|
|
|
|
let solid_color_kernel = String::from("color-passthrough");
|
|
|
|
let texture_kernel = String::from("simple_texture");
|
|
|
|
let texture_kernel = String::from("simple_texture");
|
|
|
|
|
|
|
|
|
|
|
|
let shader_kernels = HashMap::from_iter(vec![
|
|
|
|
let shader_kernels : HashMap<ShaderType, ShaderKernels> = HashMap::from_iter(vec![
|
|
|
|
(ShaderType::SOLID, ShaderKernels::new(solid_color_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone())),
|
|
|
|
(ShaderType::SOLID, ShaderKernels::new(solid_color_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone())),
|
|
|
|
//(ShaderType::TEXTURED, ShaderKernels::new(texture_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone()))
|
|
|
|
(ShaderType::TEXTURED, ShaderKernels::new(texture_kernel, capabilities.clone(), queue.clone(), physical.clone(), device.clone()))
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Canvas {
|
|
|
|
Canvas {
|
|
|
|
|
|
|
|
shader_kernels: Default::default(),
|
|
|
|
|
|
|
|
texture_store: Default::default(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
|
|
|
|
|
|
|
sampler: Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
|
|
|
|
|
|
|
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
|
|
|
|
|
|
|
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(),
|
|
|
|
|
|
|
|
image_buffers: vec![],
|
|
|
|
|
|
|
|
image_buffer_handles: vec![],
|
|
|
|
|
|
|
|
texture_buffers: vec![],
|
|
|
|
|
|
|
|
texture_buffer_handles: vec![],
|
|
|
|
|
|
|
|
shader_buffers: Default::default(),
|
|
|
|
|
|
|
|
shader_buffer_handles: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
colored_drawables: vec![],
|
|
|
|
colored_drawables: vec![],
|
|
|
|
colored_vertex_buffer: vec![],
|
|
|
|
colored_vertex_buffer: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
textured_drawables: Default::default(),
|
|
|
|
textured_drawables: Default::default(),
|
|
|
|
textured_vertex_buffer: Default::default(),
|
|
|
|
textured_vertex_buffer: Default::default(),
|
|
|
|
|
|
|
|
image_drawables: Default::default(),
|
|
|
|
|
|
|
|
image_vertex_buffer: Default::default(),
|
|
|
|
|
|
|
|
|
|
|
|
shader_kernels: shader_kernels,
|
|
|
|
|
|
|
|
texture_store: Default::default(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image_buffers: Vec::new(),
|
|
|
|
|
|
|
|
image_buffer_handles: Vec::new(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device: device.clone(),
|
|
|
|
|
|
|
|
queue: queue.clone(),
|
|
|
|
queue: queue.clone(),
|
|
|
|
sampler: Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
|
|
|
device: device.clone(),
|
|
|
|
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
|
|
|
|
|
|
|
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -220,7 +263,6 @@ impl Canvas {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO Handle file not found gracefully
|
|
|
|
// TODO Handle file not found gracefully
|
|
|
|
fn get_texture_from_file(&self, image_filename: String) -> Arc<ImmutableImage<Format>> {
|
|
|
|
fn get_texture_from_file(&self, image_filename: String) -> Arc<ImmutableImage<Format>> {
|
|
|
|
|
|
|
|
|
|
|
|
let project_root =
|
|
|
|
let project_root =
|
|
|
|
std::env::current_dir()
|
|
|
|
std::env::current_dir()
|
|
|
|
.expect("failed to get root directory");
|
|
|
|
.expect("failed to get root directory");
|
|
|
@ -255,14 +297,13 @@ impl Canvas {
|
|
|
|
image_buffer.iter().cloned(),
|
|
|
|
image_buffer.iter().cloned(),
|
|
|
|
Dimensions::Dim2d { width: xy.0, height: xy.1 },
|
|
|
|
Dimensions::Dim2d { width: xy.0, height: xy.1 },
|
|
|
|
Format::R8G8B8A8Srgb,
|
|
|
|
Format::R8G8B8A8Srgb,
|
|
|
|
self.queue.clone()
|
|
|
|
self.queue.clone(),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
texture
|
|
|
|
texture
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn load_texture_from_filename(&mut self, filename: String) -> Arc<ImmutableImage<Format>> {
|
|
|
|
pub fn load_texture_from_filename(&mut self, filename: String) -> Arc<ImmutableImage<Format>> {
|
|
|
|
|
|
|
|
|
|
|
|
if self.texture_store.contains_key(&filename.clone()) {
|
|
|
|
if self.texture_store.contains_key(&filename.clone()) {
|
|
|
|
println!("{} Already exists, not going to replace it.", filename.clone());
|
|
|
|
println!("{} Already exists, not going to replace it.", filename.clone());
|
|
|
|
self.texture_store.get(&filename.clone()).unwrap().clone()
|
|
|
|
self.texture_store.get(&filename.clone()).unwrap().clone()
|
|
|
@ -273,15 +314,25 @@ impl Canvas {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn load_texture(&mut self, filename: String) -> Option<Arc<u32>> {
|
|
|
|
|
|
|
|
let texture_buffer = self.get_texture_from_file(filename.clone());
|
|
|
|
|
|
|
|
self.texture_buffers.push(texture_buffer.clone());
|
|
|
|
|
|
|
|
let id = Arc::new(self.texture_buffers.len() as u32);
|
|
|
|
|
|
|
|
self.texture_buffer_handles.push(id.clone());
|
|
|
|
|
|
|
|
Some(id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// After done using this, need to call allocated vertex buffers
|
|
|
|
// After done using this, need to call allocated vertex buffers
|
|
|
|
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
|
|
|
|
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
|
|
|
|
self.textured_drawables = canvas_frame.textured_drawables;
|
|
|
|
self.textured_drawables = canvas_frame.textured_drawables;
|
|
|
|
self.colored_drawables = canvas_frame.colored_drawables;
|
|
|
|
self.colored_drawables = canvas_frame.colored_drawables;
|
|
|
|
}
|
|
|
|
self.image_drawables = canvas_frame.image_drawables;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.allocate_vertex_buffers(self.device.clone());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_texture(&self, texture_id: String) -> Arc<ImmutableImage<Format>> {
|
|
|
|
fn get_texture(&self, texture_id: String) -> Arc<ImmutableImage<Format>> {
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(i) = self.texture_store.get(&texture_id) {
|
|
|
|
if let Some(i) = self.texture_store.get(&texture_id) {
|
|
|
|
return i.clone();
|
|
|
|
return i.clone();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -290,9 +341,9 @@ impl Canvas {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn allocate_vertex_buffers(&mut self, device: Arc<Device>) {
|
|
|
|
pub fn allocate_vertex_buffers(&mut self, device: Arc<Device>) {
|
|
|
|
|
|
|
|
|
|
|
|
self.colored_vertex_buffer.clear();
|
|
|
|
self.colored_vertex_buffer.clear();
|
|
|
|
self.textured_vertex_buffer.clear();
|
|
|
|
self.textured_vertex_buffer.clear();
|
|
|
|
|
|
|
|
self.image_vertex_buffer.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO should probably use cpu accessible buffer instead of recreating immutes each frame
|
|
|
|
//TODO should probably use cpu accessible buffer instead of recreating immutes each frame
|
|
|
@ -317,28 +368,26 @@ impl Canvas {
|
|
|
|
v.iter().cloned(),
|
|
|
|
v.iter().cloned(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone(),
|
|
|
|
).unwrap().0
|
|
|
|
).unwrap().0,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_solid_color_descriptor_set(&self) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
fn get_solid_color_descriptor_set(&self) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
|
|
println!("{}", self.shader_kernels.get(&ShaderType::SOLID).unwrap().clone().get_pipeline().clone().num_sets());
|
|
|
|
println!("{}", self.shader_kernels.get(&ShaderType::SOLID).unwrap().clone().get_pipeline().clone().num_sets());
|
|
|
|
|
|
|
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
self.shader_kernels.get(&ShaderType::SOLID).unwrap().clone().get_pipeline().clone(), 0
|
|
|
|
self.shader_kernels.get(&ShaderType::SOLID).unwrap().clone().get_pipeline().clone(), 0,
|
|
|
|
).build().unwrap());
|
|
|
|
).build().unwrap());
|
|
|
|
o
|
|
|
|
o
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_textured_descriptor_set(&self, texture_id: String)
|
|
|
|
fn get_textured_descriptor_set(&self, texture_id: String)
|
|
|
|
-> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
-> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
self.shader_kernels.get(&ShaderType::TEXTURED).unwrap().clone().get_pipeline().clone(), 0
|
|
|
|
self.shader_kernels.get(&ShaderType::TEXTURED).unwrap().clone().get_pipeline().clone(), 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_sampled_image(self.get_texture(texture_id), self.sampler.clone()).unwrap()
|
|
|
|
.add_sampled_image(self.get_texture(texture_id), self.sampler.clone()).unwrap()
|
|
|
|
.build().unwrap());
|
|
|
|
.build().unwrap());
|
|
|
@ -351,24 +400,19 @@ impl Canvas {
|
|
|
|
fn get_compute_swap_descriptor_set(&mut self,
|
|
|
|
fn get_compute_swap_descriptor_set(&mut self,
|
|
|
|
device: Arc<Device>,
|
|
|
|
device: Arc<Device>,
|
|
|
|
compute_image: &ComputeImage) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
compute_image: &ComputeImage) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
|
|
let sampler = Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
|
|
|
let sampler = Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
|
|
|
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
|
|
|
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
|
|
|
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
|
|
|
|
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let o : Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
self.shader_kernels.get(&ShaderType::COMPUTE).clone().unwrap().clone().get_pipeline(), 0
|
|
|
|
self.shader_kernels.get(&ShaderType::IMAGE).clone().unwrap().clone().get_pipeline(), 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_image(compute_image.clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
.add_image(compute_image.clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
.build().unwrap());
|
|
|
|
.build().unwrap());
|
|
|
|
o
|
|
|
|
o
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
pub fn draw_commands(&self,
|
|
|
|
pub fn draw_commands(&self,
|
|
|
|
mut command_buffer: AutoCommandBufferBuilder,
|
|
|
|
mut command_buffer: AutoCommandBufferBuilder,
|
|
|
|
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
|
|
|
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
|
|
@ -378,7 +422,7 @@ impl Canvas {
|
|
|
|
let clear_values = vec!(ClearValue::Float([0.0, 0.0, 1.0, 1.0]));
|
|
|
|
let clear_values = vec!(ClearValue::Float([0.0, 0.0, 1.0, 1.0]));
|
|
|
|
|
|
|
|
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
let mut command_buffer = command_buffer.begin_render_pass(
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone()
|
|
|
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -389,17 +433,19 @@ impl Canvas {
|
|
|
|
kernel.clone().get_pipeline().clone(),
|
|
|
|
kernel.clone().get_pipeline().clone(),
|
|
|
|
&self.dynamic_state.clone(),
|
|
|
|
&self.dynamic_state.clone(),
|
|
|
|
self.colored_vertex_buffer.clone(),
|
|
|
|
self.colored_vertex_buffer.clone(),
|
|
|
|
(), ()
|
|
|
|
(), (),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ShaderType::TEXTURED => {
|
|
|
|
ShaderType::TEXTURED => {
|
|
|
|
// command_buffer = command_buffer.draw(
|
|
|
|
// command_buffer = command_buffer.draw(
|
|
|
|
// kernel.clone().get_pipeline().clone(),
|
|
|
|
// kernel.clone().get_pipeline().clone(),
|
|
|
|
// &dynamic_state.clone(), self.textured_vertex_buffer.clone(),
|
|
|
|
// &dynamic_state.clone(), self.textured_vertex_buffer.clone(),
|
|
|
|
// vec![self.get_textured_descriptor_set(String::from("funky-bird.jpg"))], ()
|
|
|
|
// vec![self.get_textured_descriptor_set(String::from("funky-bird.jpg"))], ()
|
|
|
|
// ).unwrap();
|
|
|
|
// ).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ShaderType::COMPUTE => {},
|
|
|
|
ShaderType::IMAGE => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -408,28 +454,6 @@ impl Canvas {
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// This method is called once during initialization, then again whenever the window is resized
|
|
|
|
|
|
|
|
pub fn window_size_dependent_setup(&mut self,
|
|
|
|
|
|
|
|
images: &[Arc<SwapchainImage<Window>>],
|
|
|
|
|
|
|
|
) -> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dimensions = images[0].dimensions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
images.iter().map(|image| {
|
|
|
|
|
|
|
|
Arc::new(
|
|
|
|
|
|
|
|
Framebuffer::start(self.shader_kernels.get(&ShaderType::SOLID).unwrap().render_pass.clone())
|
|
|
|
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
|
|
|
|
.build().unwrap()
|
|
|
|
|
|
|
|
) as Arc<dyn FramebufferAbstract + Send + Sync>
|
|
|
|
|
|
|
|
}).collect::<Vec<_>>()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|