|
|
@ -24,6 +24,7 @@ use crate::canvas_text::{CanvasText, CanvasTextHandle};
|
|
|
|
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
|
|
|
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
|
|
|
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
|
|
|
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
|
|
|
use crate::vertex_3d::Vertex3D;
|
|
|
|
use crate::vertex_3d::Vertex3D;
|
|
|
|
|
|
|
|
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
|
|
|
|
|
|
|
|
|
|
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
|
|
|
/// A drawable object can be passed into a CanvasFrame to be rendered
|
|
|
|
/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color
|
|
|
|
/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color
|
|
|
@ -175,7 +176,23 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CanvasState {
|
|
|
|
CanvasState {
|
|
|
|
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
|
|
|
dynamic_state: DynamicState {
|
|
|
|
|
|
|
|
line_width: None,
|
|
|
|
|
|
|
|
viewports: None,
|
|
|
|
|
|
|
|
scissors: None,
|
|
|
|
|
|
|
|
compare_mask: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
value: 0xFF,
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
write_mask: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
value: 0xFF,
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
reference: Some(DynamicStencilValue {
|
|
|
|
|
|
|
|
face: StencilFaceFlags::StencilFrontAndBack,
|
|
|
|
|
|
|
|
value: 0xFF,
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
},
|
|
|
|
sampler: Sampler::new(device.clone(),
|
|
|
|
sampler: Sampler::new(device.clone(),
|
|
|
|
Filter::Linear, Filter::Linear,
|
|
|
|
Filter::Linear, Filter::Linear,
|
|
|
|
MipmapMode::Nearest,
|
|
|
|
MipmapMode::Nearest,
|
|
|
@ -332,10 +349,12 @@ impl CanvasState {
|
|
|
|
shader_type: ShaderType,
|
|
|
|
shader_type: ShaderType,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
|
|
|
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CanvasShaderHandle {
|
|
|
|
let handle = Arc::new(CanvasShaderHandle {
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
handle: self.shader_buffers.len() as u32
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO : what is even going on here
|
|
|
|
let shader = match shader_type {
|
|
|
|
let shader = match shader_type {
|
|
|
|
ShaderType::SOLID => {
|
|
|
|
ShaderType::SOLID => {
|
|
|
|
Arc::new(CanvasShader::new(
|
|
|
|
Arc::new(CanvasShader::new(
|
|
|
@ -478,7 +497,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
/// Pushes the draw commands to the command buffer. Requires the framebuffers and
|
|
|
|
/// Pushes the draw commands to the command buffer. Requires the framebuffers and
|
|
|
|
/// image number to be passed in as they are taken care of by the vkprocessor
|
|
|
|
/// image number to be passed in as they are taken care of by the vkprocessor
|
|
|
|
pub fn draw_commands(&self,
|
|
|
|
pub fn draw_commands(&mut self,
|
|
|
|
mut command_buffer: AutoCommandBufferBuilder,
|
|
|
|
mut command_buffer: AutoCommandBufferBuilder,
|
|
|
|
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
|
|
|
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
|
|
|
image_num: usize) -> AutoCommandBufferBuilder {
|
|
|
|
image_num: usize) -> AutoCommandBufferBuilder {
|
|
|
@ -486,9 +505,16 @@ impl CanvasState {
|
|
|
|
// Specify the color to clear the framebuffer with i.e. blue
|
|
|
|
// Specify the color to clear the framebuffer with i.e. blue
|
|
|
|
let clear_values = vec!(
|
|
|
|
let clear_values = vec!(
|
|
|
|
ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
|
|
|
|
ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
|
|
|
|
ClearValue::DepthStencil((1.0, 0)),
|
|
|
|
ClearValue::DepthStencil((1.0, 0x00)),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// self.dynamic_state = DynamicState {
|
|
|
|
|
|
|
|
// line_width: None,
|
|
|
|
|
|
|
|
// viewports: self.dynamic_state.viewports.clone(),
|
|
|
|
|
|
|
|
// scissors: None,
|
|
|
|
|
|
|
|
// compare_mask: Some(StencilMask{ face: StencilFaceFlags::StencilFaceFrontBit, mask: 0xFF }),
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
@ -501,6 +527,7 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
// This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs.
|
|
|
|
// This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs.
|
|
|
|
// But we can pass in multiple vertex buffers
|
|
|
|
// But we can pass in multiple vertex buffers
|
|
|
|
|
|
|
|
|
|
|
|
if !self.colored_vertex_buffer.is_empty() {
|
|
|
|
if !self.colored_vertex_buffer.is_empty() {
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
@ -510,7 +537,6 @@ impl CanvasState {
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Images
|
|
|
|
// Images
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
self.get_shader_handle(String::from("simple_image"))
|
|
|
|
self.get_shader_handle(String::from("simple_image"))
|
|
|
@ -529,10 +555,10 @@ impl CanvasState {
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Textures
|
|
|
|
// Textures
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
let mut shader = self.shader_buffers.get(
|
|
|
|
self.get_shader_handle(String::from("simple_texture"))
|
|
|
|
self.get_shader_handle(String::from("simple_texture"))
|
|
|
|