pulled out the draw call. forgot to allocate buffers

master
mitchellhansen 5 years ago
parent 0be20eb959
commit e351e36c92

@ -3,6 +3,16 @@ layout(location = 0) in vec4 out_color;
layout(location = 0) out vec4 f_color; layout(location = 0) out vec4 f_color;
void main() { void main() {
f_color = out_color; f_color = out_color;
} }

@ -5,6 +5,12 @@ layout(location = 1) in vec4 color;
layout(location = 0) out vec4 out_color; layout(location = 0) out vec4 out_color;
void main() { void main() {
out_color = color; // out_color = color;
gl_Position = vec4(position, 0.0, 1.0); gl_Position = vec4(position, 0.0, 1.0);
} }

@ -95,6 +95,52 @@ pub enum ShaderType {
COMPUTE = 2 COMPUTE = 2
} }
pub struct CanvasFrame {
colored_drawables : Vec<ColoredVertex2D>,
textured_drawables: HashMap<String, Vec<Vertex2D>>,
}
impl CanvasFrame {
pub fn new() -> CanvasFrame {
CanvasFrame {
colored_drawables: vec![],
textured_drawables: Default::default()
}
}
// After done using this, need to call allocated vertex buffers
pub fn draw(&mut self, drawable: &dyn Drawable) {
match drawable.get_texture_id() {
Some(id) => {
self.textured_drawables
.entry(id)
.or_insert(Vec::new())
.extend(drawable.get_vertices().iter().map(|n|
Vertex2D {
position: [n.0, n.1],
}
));
},
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]
}
)
);
}
}
}
}
#[derive(Clone)] #[derive(Clone)]
pub struct Canvas { pub struct Canvas {
@ -108,6 +154,8 @@ pub struct Canvas {
texture_store: HashMap<String, Arc<ImmutableImage<Format>>>, texture_store: HashMap<String, Arc<ImmutableImage<Format>>>,
dynamic_state: DynamicState,
// 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> sampler: Arc<Sampler>
@ -139,12 +187,14 @@ impl Canvas {
shader_kernels: shader_kernels, shader_kernels: shader_kernels,
texture_store: Default::default(), texture_store: Default::default(),
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
queue: queue.clone(), queue: queue.clone(),
sampler: Sampler::new(device.clone(), Filter::Linear, Filter::Linear, 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(),
} }
} }
// TODO Handle file not found gracefully // TODO Handle file not found gracefully
@ -200,37 +250,12 @@ impl Canvas {
self.texture_store.insert(filename, texture.clone()); self.texture_store.insert(filename, texture.clone());
texture texture
} }
} }
// 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, drawable: &dyn Drawable) { pub fn draw(&mut self, canvas_frame: CanvasFrame) {
self.textured_drawables = canvas_frame.textured_drawables;
match drawable.get_texture_id() { self.colored_drawables = canvas_frame.colored_drawables;
Some(id) => {
self.textured_drawables
.entry(id)
.or_insert(Vec::new())
.extend(drawable.get_vertices().iter().map(|n|
Vertex2D {
position: [n.0, n.1],
}
));
},
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]
}
)
);
}
}
} }
@ -313,6 +338,7 @@ impl Canvas {
/* /*
*/ */
pub fn draw_commands(&self, pub fn draw_commands(&self,
mut command_buffer: AutoCommandBufferBuilder, mut command_buffer: AutoCommandBufferBuilder,
@ -322,8 +348,6 @@ impl Canvas {
// 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!(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 dynamic_state = DynamicState { line_width: None, viewports: None, scissors: None };
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();
@ -334,8 +358,9 @@ impl Canvas {
ShaderType::SOLID => { ShaderType::SOLID => {
command_buffer = command_buffer.draw( command_buffer = command_buffer.draw(
kernel.clone().get_pipeline().clone(), kernel.clone().get_pipeline().clone(),
&dynamic_state.clone(), self.colored_vertex_buffer.clone(), &self.dynamic_state.clone(),
vec![self.get_solid_color_descriptor_set()], () self.colored_vertex_buffer.clone(),
(), ()
).unwrap(); ).unwrap();
}, },
ShaderType::TEXTURED => { ShaderType::TEXTURED => {
@ -355,21 +380,18 @@ impl Canvas {
} }
/// This method is called once during initialization, then again whenever the window is resized /// This method is called once during initialization, then again whenever the window is resized
pub fn window_size_dependent_setup(&self, pub fn window_size_dependent_setup(&mut self,
images: &[Arc<SwapchainImage<Window>>], images: &[Arc<SwapchainImage<Window>>],
) -> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> { ) -> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
let dimensions = images[0].dimensions(); let dimensions = images[0].dimensions();
let mut dynamic_state = DynamicState { self.dynamic_state.viewports =
line_width: None, Some(vec![Viewport {
viewports: Some(vec![Viewport {
origin: [0.0, 0.0], origin: [0.0, 0.0],
dimensions: [dimensions.width() as f32, dimensions.height() as f32], dimensions: [dimensions.width() as f32, dimensions.height() as f32],
depth_range: 0.0..1.0, depth_range: 0.0..1.0,
}]), }]);
scissors: None
};
images.iter().map(|image| { images.iter().map(|image| {
Arc::new( Arc::new(

@ -19,6 +19,7 @@ use winit::{EventsLoop, WindowBuilder, WindowEvent, Event, DeviceEvent, VirtualK
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use vulkano_win::VkSurfaceBuild; use vulkano_win::VkSurfaceBuild;
use sprite::Sprite; use sprite::Sprite;
use crate::canvas::CanvasFrame;
mod util; mod util;
@ -62,7 +63,7 @@ fn main() {
let mut mouse_xy = Vector2i::new(0,0); let mut mouse_xy = Vector2i::new(0,0);
Sprite::new_with_color((0.,0.), (0,0), (0.,0.,0.,0.)); let sprite = Sprite::new_with_color((0.,0.), (0,0), (0.,0.,0.,0.));
while let Some(p) = window.get_position() { while let Some(p) = window.get_position() {
@ -110,9 +111,10 @@ fn main() {
return; return;
} }
let mut canvas = CanvasFrame::new();
canvas.draw(&sprite);
(frame_future) = processor.run(&surface, frame_future, canvas);
(frame_future) = processor.run(&surface, frame_future);
} }
} }

@ -130,8 +130,11 @@ impl ShaderKernels {
GraphicsShaderType::Vertex)) GraphicsShaderType::Vertex))
}; };
let render_pass = Arc::new(vulkano::single_pass_renderpass!( let render_pass = Arc::new(vulkano::single_pass_renderpass!(
device.clone(), device.clone(),
// Attachments are outgoing like f_color
attachments: { attachments: {
// `color` is a custom name we give to the first and only attachment. // `color` is a custom name we give to the first and only attachment.
color: { color: {
@ -153,6 +156,7 @@ impl ShaderKernels {
pass: { pass: {
// We use the attachment named `color` as the one and only color attachment. // We use the attachment named `color` as the one and only color attachment.
color: [color], color: [color],
//color: [],
// No depth-stencil attachment is indicated with empty brackets. // No depth-stencil attachment is indicated with empty brackets.
depth_stencil: {} depth_stencil: {}
} }

@ -9,7 +9,7 @@ use vulkano::image::swapchain::SwapchainImage;
use winit::{Window}; use winit::{Window};
use crate::util::compute_kernel::ComputeKernel; use crate::util::compute_kernel::ComputeKernel;
use crate::util::compute_image::ComputeImage; use crate::util::compute_image::ComputeImage;
use crate::canvas::Canvas; use crate::canvas::{Canvas, CanvasFrame};
pub struct VkProcessor<'a> { pub struct VkProcessor<'a> {
@ -146,9 +146,15 @@ impl<'a> VkProcessor<'a> {
self.compute_image.clone().unwrap().clone().save_image(); self.compute_image.clone().unwrap().clone().save_image();
} }
pub fn get_canvas(&mut self) -> &Canvas {
&self.canvas
}
pub fn run(&mut self, pub fn run(&mut self,
surface: &'a Arc<Surface<Window>>, surface: &'a Arc<Surface<Window>>,
mut frame_future: Box<dyn GpuFuture>, mut frame_future: Box<dyn GpuFuture>,
canvas_frame: CanvasFrame,
) -> Box<dyn GpuFuture> { ) -> Box<dyn GpuFuture> {
let mut framebuffers = let mut framebuffers =
self.canvas.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone()); self.canvas.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
@ -190,6 +196,8 @@ impl<'a> VkProcessor<'a> {
.copy_buffer_to_image(self.compute_image.clone().unwrap().clone().rw_buffers.get(0).unwrap().clone(), .copy_buffer_to_image(self.compute_image.clone().unwrap().clone().rw_buffers.get(0).unwrap().clone(),
self.compute_image.clone().unwrap().clone().get_swap_buffer().clone()).unwrap(); self.compute_image.clone().unwrap().clone().get_swap_buffer().clone()).unwrap();
self.canvas.draw(canvas_frame);
self.canvas.allocate_vertex_buffers(self.device.clone());
let mut command_buffer = self.canvas.draw_commands(command_buffer, framebuffers, image_num); let mut command_buffer = self.canvas.draw_commands(command_buffer, framebuffers, image_num);

Loading…
Cancel
Save