|
|
@ -42,12 +42,12 @@ use crate::canvas::compu_frame::CompuFrame;
|
|
|
|
|
|
|
|
|
|
|
|
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
|
|
|
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
|
|
|
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
|
|
|
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone, Default)]
|
|
|
|
pub struct CanvasState {
|
|
|
|
pub struct CanvasState {
|
|
|
|
/// Generated during new()
|
|
|
|
/// Generated during new()
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
/// Generated during new()
|
|
|
|
/// Generated during new()
|
|
|
|
sampler: Arc<Sampler>,
|
|
|
|
sampler: Option<Arc<Sampler>>,
|
|
|
|
|
|
|
|
|
|
|
|
/// hold the image, texture, and Fonts the same was as we do CompuState
|
|
|
|
/// hold the image, texture, and Fonts the same was as we do CompuState
|
|
|
|
image_buffers: Vec<Arc<CanvasImage>>,
|
|
|
|
image_buffers: Vec<Arc<CanvasImage>>,
|
|
|
@ -58,9 +58,9 @@ pub struct CanvasState {
|
|
|
|
shader_buffers: Vec<Arc<Box<dyn CompiledShader + Send + Sync>>>,
|
|
|
|
shader_buffers: Vec<Arc<Box<dyn CompiledShader + Send + 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: Option<Arc<Queue>>,
|
|
|
|
device: Arc<Device>,
|
|
|
|
device: Option<Arc<Device>>,
|
|
|
|
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,
|
|
|
|
render_pass: Option<Arc<dyn RenderPassAbstract + Send + Sync>>,
|
|
|
|
|
|
|
|
|
|
|
|
compute_buffers: Vec<CompuBuffers>,
|
|
|
|
compute_buffers: Vec<CompuBuffers>,
|
|
|
|
kernels: Vec<CompuKernel>,
|
|
|
|
kernels: Vec<CompuKernel>,
|
|
|
@ -81,11 +81,11 @@ impl CanvasState {
|
|
|
|
}]);
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
let dimensions = [dimensions.width(), dimensions.height()];
|
|
|
|
let dimensions = [dimensions.width(), dimensions.height()];
|
|
|
|
let depth_buffer = AttachmentImage::transient(self.device.clone(), dimensions, Format::D32Sfloat_S8Uint).unwrap();
|
|
|
|
let depth_buffer = AttachmentImage::transient(self.device.clone().unwrap(), dimensions, Format::D32Sfloat_S8Uint).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
images.iter().map(|image| {
|
|
|
|
images.iter().map(|image| {
|
|
|
|
Arc::new(
|
|
|
|
Arc::new(
|
|
|
|
Framebuffer::start(self.render_pass.clone())
|
|
|
|
Framebuffer::start(self.render_pass.clone().unwrap())
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
.add(image.clone()).unwrap()
|
|
|
|
.add(depth_buffer.clone()).unwrap()
|
|
|
|
.add(depth_buffer.clone()).unwrap()
|
|
|
|
.build().unwrap()
|
|
|
|
.build().unwrap()
|
|
|
@ -160,19 +160,19 @@ impl CanvasState {
|
|
|
|
value: 0xFF,
|
|
|
|
value: 0xFF,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sampler: Sampler::new(device.clone(),
|
|
|
|
sampler: Some(Sampler::new(device.clone(),
|
|
|
|
Filter::Linear, Filter::Linear,
|
|
|
|
Filter::Linear, Filter::Linear,
|
|
|
|
MipmapMode::Nearest,
|
|
|
|
MipmapMode::Nearest,
|
|
|
|
SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
|
|
|
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()),
|
|
|
|
image_buffers: vec![],
|
|
|
|
image_buffers: vec![],
|
|
|
|
texture_buffers: vec![],
|
|
|
|
texture_buffers: vec![],
|
|
|
|
shader_buffers: vec![],
|
|
|
|
shader_buffers: vec![],
|
|
|
|
font_buffers: vec![],
|
|
|
|
font_buffers: vec![],
|
|
|
|
|
|
|
|
|
|
|
|
queue: queue.clone(),
|
|
|
|
queue: Some(queue.clone()),
|
|
|
|
device: device.clone(),
|
|
|
|
device: Some(device.clone()),
|
|
|
|
render_pass: render_pass.clone(),
|
|
|
|
render_pass: Some(render_pass.clone()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -310,7 +310,7 @@ impl CanvasState {
|
|
|
|
let image = CanvasImage {
|
|
|
|
let image = CanvasImage {
|
|
|
|
handle: handle.clone(),
|
|
|
|
handle: handle.clone(),
|
|
|
|
buffer: AttachmentImage::with_usage(
|
|
|
|
buffer: AttachmentImage::with_usage(
|
|
|
|
self.device.clone(),
|
|
|
|
self.device.clone().unwrap(),
|
|
|
|
[dimensions.0, dimensions.1],
|
|
|
|
[dimensions.0, dimensions.1],
|
|
|
|
Format::R8G8B8A8Uint,
|
|
|
|
Format::R8G8B8A8Uint,
|
|
|
|
usage).unwrap(),
|
|
|
|
usage).unwrap(),
|
|
|
@ -364,7 +364,7 @@ impl CanvasState {
|
|
|
|
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();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
texture
|
|
|
|
texture
|
|
|
@ -391,8 +391,7 @@ impl CanvasState {
|
|
|
|
/// Load and Compile a shader with the filename at resources/shaders
|
|
|
|
/// Load and Compile a shader with the filename at resources/shaders
|
|
|
|
/// Takes physical and capabilities as we don't store that in Canvas
|
|
|
|
/// Takes physical and capabilities as we don't store that in Canvas
|
|
|
|
pub fn load_shader<T, V>(&mut self,
|
|
|
|
pub fn load_shader<T, V>(&mut self,
|
|
|
|
filename: String,
|
|
|
|
filename: String) -> Option<Arc<CompiledShaderHandle>>
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
|
|
|
|
|
|
|
|
where T: CompiledShader + Send + Sync + 'static, V: Vertex {
|
|
|
|
where T: CompiledShader + Send + Sync + 'static, V: Vertex {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CompiledShaderHandle {
|
|
|
|
let handle = Arc::new(CompiledShaderHandle {
|
|
|
@ -401,9 +400,9 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
let shader: Box<dyn CompiledShader + Send + Sync> = Box::new(T::new::<V>(
|
|
|
|
let shader: Box<dyn CompiledShader + Send + Sync> = Box::new(T::new::<V>(
|
|
|
|
filename.clone(),
|
|
|
|
filename.clone(),
|
|
|
|
self.device.clone(),
|
|
|
|
self.device.clone().unwrap(),
|
|
|
|
handle.clone(),
|
|
|
|
handle.clone(),
|
|
|
|
self.render_pass.clone(),
|
|
|
|
self.render_pass.clone().unwrap(),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
self.shader_buffers.push(Arc::new(shader));
|
|
|
|
self.shader_buffers.push(Arc::new(shader));
|
|
|
@ -461,7 +460,7 @@ impl CanvasState {
|
|
|
|
name: name,
|
|
|
|
name: name,
|
|
|
|
buffer: ImmutableBuffer::from_iter(
|
|
|
|
buffer: ImmutableBuffer::from_iter(
|
|
|
|
accumulator.iter().cloned(),
|
|
|
|
accumulator.iter().cloned(),
|
|
|
|
BufferUsage::vertex_buffer(), self.queue.clone()).unwrap().0,
|
|
|
|
BufferUsage::vertex_buffer(), self.queue.clone().unwrap()).unwrap().0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
@ -556,7 +555,7 @@ impl CanvasState {
|
|
|
|
allocated_colored_buffer.push(ImmutableBuffer::from_iter(
|
|
|
|
allocated_colored_buffer.push(ImmutableBuffer::from_iter(
|
|
|
|
colored_vertex_buffer.iter().cloned(),
|
|
|
|
colored_vertex_buffer.iter().cloned(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone().unwrap(),
|
|
|
|
).unwrap().0);
|
|
|
|
).unwrap().0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -565,7 +564,7 @@ impl CanvasState {
|
|
|
|
allocated_text_buffer.push(ImmutableBuffer::from_iter(
|
|
|
|
allocated_text_buffer.push(ImmutableBuffer::from_iter(
|
|
|
|
text_vertex_buffer.iter().cloned(),
|
|
|
|
text_vertex_buffer.iter().cloned(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone().unwrap(),
|
|
|
|
).unwrap().0);
|
|
|
|
).unwrap().0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -576,7 +575,7 @@ impl CanvasState {
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
v.iter().cloned(),
|
|
|
|
v.iter().cloned(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone().unwrap(),
|
|
|
|
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
|
|
|
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
|
|
|
}).collect(),
|
|
|
|
}).collect(),
|
|
|
|
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
|
|
|
|
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
|
|
|
@ -584,7 +583,7 @@ impl CanvasState {
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
v.iter().cloned(),
|
|
|
|
v.iter().cloned(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone().unwrap(),
|
|
|
|
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
|
|
|
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
|
|
|
}).collect(),
|
|
|
|
}).collect(),
|
|
|
|
text_instances: Default::default(),
|
|
|
|
text_instances: Default::default(),
|
|
|
@ -669,7 +668,7 @@ impl CanvasState {
|
|
|
|
for (texture_handle, vertex_buffer) in allocated_buffers.textured_vertex_buffer.clone() {
|
|
|
|
for (texture_handle, vertex_buffer) in allocated_buffers.textured_vertex_buffer.clone() {
|
|
|
|
let handle = texture_handle.clone().get_handle() as usize;
|
|
|
|
let handle = texture_handle.clone().get_handle() as usize;
|
|
|
|
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
|
|
|
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
|
|
|
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone());
|
|
|
|
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone().unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|