Brainstorming the design.

master
mitchellhansen 5 years ago
parent c5b3c29ad4
commit 2207c41956

@ -16,6 +16,7 @@ use vulkano::descriptor::DescriptorSet;
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use std::path::PathBuf; use std::path::PathBuf;
use image::GenericImageView; use image::GenericImageView;
use crate::util::compute_image::ComputeImage;
// Canvas is the accumulator of Sprites for drawing // Canvas is the accumulator of Sprites for drawing
// Needs to know: // Needs to know:
@ -101,11 +102,38 @@ impl Vertex for ColoredVertex2D {
pub trait Drawable { pub trait Drawable {
fn get_vertices(&self) -> Vec<(f32, f32)>; fn get_vertices(&self) -> Vec<(f32, f32)>;
fn get_color(&self) -> (f32, f32, 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 { pub struct Canvas {
colored_drawables : Vec<ColoredVertex2D>, colored_drawables : Vec<ColoredVertex2D>,
@ -114,7 +142,7 @@ pub struct Canvas {
vertex_buffers: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>, 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>>>, textures: Vec<Arc<ImmutableImage<Format>>>,
} }
@ -128,8 +156,7 @@ impl Canvas {
textured_drawables: Default::default(), textured_drawables: Default::default(),
vertex_buffers: vec![], vertex_buffers: vec![],
shader_kernels: HashMap::new(),
shader_kernels: Vec::new(),
textures: vec![] textures: vec![]
} }
} }
@ -219,16 +246,25 @@ impl Canvas {
); );
} }
// The image set is the containing object for all texture and image hooks. // I guess these go out as an array. So I can add multiple descriptor sets
fn get_texture_set(&mut self, device: Arc<Device>) -> Box<DescriptorSet + Send + Sync> {
// 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, 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<DescriptorSet + Send + Sync> = Box::new( let o : Box<dyn DescriptorSet + Send + Sync> = Box::new(
PersistentDescriptorSet::start( 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() .add_sampled_image(self.textures.get(0).unwrap().clone(), sampler.clone()).unwrap()
.build().unwrap()); .build().unwrap());
@ -236,17 +272,19 @@ impl Canvas {
} }
// The image set is the containing object for all texture and image hooks. // 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, 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<DescriptorSet + Send + Sync> = Box::new( let o : Box<dyn DescriptorSet + Send + Sync> = Box::new(
PersistentDescriptorSet::start( 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()); .build().unwrap());
o o
} }
@ -256,14 +294,17 @@ impl Canvas {
So I need the image set in order to get my texture or compute texture 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 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 vkprocessor creates the image sets for draw calls
takes the pipeline from the ShaderKernel takes the pipeline from the ShaderKernel - Which we own
adds vk processor owned texture adds vk processor owned texture - Not any more
adds compute image taken from the ComputeImage adds compute image taken from the ComputeImage - Still true
we have shaderkernel in here so thats fine we have shaderkernel in here so thats fine
Who should own the texture? Who should own the texture?

@ -10,7 +10,7 @@ pub struct Sprite {
color: (f32, f32, f32, f32), color: (f32, f32, f32, f32),
textured: bool, textured: bool,
texture_id: i32, texture_id: Option<String>,
} }
@ -39,11 +39,11 @@ impl Sprite {
size: size, size: size,
color: color, color: color,
textured: false, textured: false,
texture_id: 0 texture_id: None
} }
} }
pub fn new_with_texture(position: (f32, f32), size: (u32, u32), texture_id: i32) -> Sprite { pub fn new_with_texture(position: (f32, f32), size: (u32, u32), texture_id: String) -> Sprite {
let fsize = (size.0 as f32, size.1 as f32); let fsize = (size.0 as f32, size.1 as f32);
@ -60,7 +60,7 @@ impl Sprite {
size, size,
color: (0.0, 0.0, 0.0, 0.0), color: (0.0, 0.0, 0.0, 0.0),
textured: false, textured: false,
texture_id texture_id: Some(texture_id)
} }
} }
@ -77,10 +77,10 @@ impl Drawable for Sprite {
self.color.clone() self.color.clone()
} }
fn get_texture_id(&self) -> Option<i32> { fn get_texture_id(&self) -> Option<String> {
match self.textured { match self.textured {
true => { true => {
Some(self.texture_id.clone()) self.texture_id.clone()
}, },
false => None, false => None,
} }

Loading…
Cancel
Save