|
|
|
@ -16,6 +16,7 @@ use vulkano::descriptor::DescriptorSet;
|
|
|
|
|
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use image::GenericImageView;
|
|
|
|
|
use crate::util::compute_image::ComputeImage;
|
|
|
|
|
// Canvas is the accumulator of Sprites for drawing
|
|
|
|
|
|
|
|
|
|
// Needs to know:
|
|
|
|
@ -101,11 +102,38 @@ impl Vertex for ColoredVertex2D {
|
|
|
|
|
pub trait Drawable {
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32)>;
|
|
|
|
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
|
|
|
|
fn get_texture_id(&self) -> Option<i32>;
|
|
|
|
|
fn get_texture_id(&self) -> Option<String>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OASIJDOQIWEJFOWIEJFOWIEJFOWEIJFOIWEJFOIW
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Right now I'm in the middle of adding texture ownership to the canvas.
|
|
|
|
|
I'm aiming at being able to load them on the fly from what texture name (String) the
|
|
|
|
|
sprite is requesting. This might be too slow though as I can't really avoid a lookup table
|
|
|
|
|
somewhere in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Need three types of shaders. Solid, Textured, Compute
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
|
#[derive(Eq)]
|
|
|
|
|
#[derive(Hash)]
|
|
|
|
|
pub enum ShaderType {
|
|
|
|
|
SOLID = 0,
|
|
|
|
|
TEXTURED = 1,
|
|
|
|
|
COMPUTE = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Canvas {
|
|
|
|
|
|
|
|
|
|
colored_drawables : Vec<ColoredVertex2D>,
|
|
|
|
@ -114,7 +142,7 @@ pub struct Canvas {
|
|
|
|
|
|
|
|
|
|
vertex_buffers: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
|
|
|
|
|
shader_kernels: Vec<ShaderKernels>,
|
|
|
|
|
shader_kernels: HashMap<ShaderType, ShaderKernels>,
|
|
|
|
|
|
|
|
|
|
textures: Vec<Arc<ImmutableImage<Format>>>,
|
|
|
|
|
}
|
|
|
|
@ -128,8 +156,7 @@ impl Canvas {
|
|
|
|
|
textured_drawables: Default::default(),
|
|
|
|
|
vertex_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shader_kernels: Vec::new(),
|
|
|
|
|
shader_kernels: HashMap::new(),
|
|
|
|
|
textures: vec![]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -219,16 +246,25 @@ impl Canvas {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The image set is the containing object for all texture and image hooks.
|
|
|
|
|
fn get_texture_set(&mut self, device: Arc<Device>) -> Box<DescriptorSet + Send + Sync> {
|
|
|
|
|
// I guess these go out as an array. So I can add multiple descriptor sets
|
|
|
|
|
|
|
|
|
|
// So probably needs to know which shaders are for textures
|
|
|
|
|
// needs to associate this descriptor set to a texture (key-pair, tuple)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// So this is fine for now. But I want to be able to:
|
|
|
|
|
// Choose which texture I want to add to this descriptor set.
|
|
|
|
|
// Add multiple textures
|
|
|
|
|
// Choose which shader and pipeline it should run on
|
|
|
|
|
fn get_texture_descriptor_set(&mut self, device: Arc<Device>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
let 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();
|
|
|
|
|
|
|
|
|
|
let o : Box<DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
let o : Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|
self.shader_kernels.get(0).unwrap().clone().unwrap().get_pipeline(), 0
|
|
|
|
|
self.shader_kernels.get(&ShaderType::TEXTURED).unwrap().clone().get_pipeline(), 0
|
|
|
|
|
)
|
|
|
|
|
.add_sampled_image(self.textures.get(0).unwrap().clone(), sampler.clone()).unwrap()
|
|
|
|
|
.build().unwrap());
|
|
|
|
@ -236,17 +272,19 @@ impl Canvas {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The image set is the containing object for all texture and image hooks.
|
|
|
|
|
fn get_compute_swap_set(&mut self, device: Arc<Device>) -> Box<DescriptorSet + Send + Sync> {
|
|
|
|
|
fn get_compute_swap_descriptor_set(&mut self,
|
|
|
|
|
device: Arc<Device>,
|
|
|
|
|
compute_image: &ComputeImage) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
let 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();
|
|
|
|
|
|
|
|
|
|
let o : Box<DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
let o : Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|
self.shader_kernels.get(0).unwrap().clone().unwrap().get_pipeline(), 0
|
|
|
|
|
self.shader_kernels.get(&ShaderType::COMPUTE).clone().unwrap().clone().get_pipeline(), 0
|
|
|
|
|
)
|
|
|
|
|
.add_image(self.compute_image.clone().unwrap().clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
|
.add_image(compute_image.clone().get_swap_buffer().clone()).unwrap()
|
|
|
|
|
.build().unwrap());
|
|
|
|
|
o
|
|
|
|
|
}
|
|
|
|
@ -256,14 +294,17 @@ impl Canvas {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
So I need the image set in order to get my texture or compute texture
|
|
|
|
|
Done
|
|
|
|
|
|
|
|
|
|
compute image currently holds the set for compute and its swap buffer
|
|
|
|
|
but during a descriptor set build, we corrow the compute_image and take
|
|
|
|
|
it's swap buffer
|
|
|
|
|
|
|
|
|
|
vkprocessor creates the image sets for draw calls
|
|
|
|
|
|
|
|
|
|
takes the pipeline from the ShaderKernel
|
|
|
|
|
adds vk processor owned texture
|
|
|
|
|
adds compute image taken from the ComputeImage
|
|
|
|
|
takes the pipeline from the ShaderKernel - Which we own
|
|
|
|
|
adds vk processor owned texture - Not any more
|
|
|
|
|
adds compute image taken from the ComputeImage - Still true
|
|
|
|
|
|
|
|
|
|
we have shaderkernel in here so thats fine
|
|
|
|
|
Who should own the texture?
|
|
|
|
|