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;
void main() {
f_color = out_color;
}

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

@ -95,6 +95,52 @@ pub enum ShaderType {
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)]
pub struct Canvas {
@ -108,6 +154,8 @@ pub struct Canvas {
texture_store: HashMap<String, Arc<ImmutableImage<Format>>>,
dynamic_state: DynamicState,
// Looks like we gotta hold onto the queue for managing textures
queue: Arc<Queue>,
sampler: Arc<Sampler>
@ -139,12 +187,14 @@ impl Canvas {
shader_kernels: shader_kernels,
texture_store: Default::default(),
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
queue: queue.clone(),
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(),
}
}
}
// TODO Handle file not found gracefully
@ -200,37 +250,12 @@ impl Canvas {
self.texture_store.insert(filename, texture.clone());
texture
}
}
// 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]
}
)
);
}
}
pub fn draw(&mut self, canvas_frame: CanvasFrame) {
self.textured_drawables = canvas_frame.textured_drawables;
self.colored_drawables = canvas_frame.colored_drawables;
}
@ -313,6 +338,7 @@ impl Canvas {
/*
*/
pub fn draw_commands(&self,
mut command_buffer: AutoCommandBufferBuilder,
@ -322,8 +348,6 @@ impl Canvas {
// 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 dynamic_state = DynamicState { line_width: None, viewports: None, scissors: None };
let mut command_buffer = command_buffer.begin_render_pass(
framebuffers[image_num].clone(), false, clear_values.clone()
).unwrap();
@ -334,8 +358,9 @@ impl Canvas {
ShaderType::SOLID => {
command_buffer = command_buffer.draw(
kernel.clone().get_pipeline().clone(),
&dynamic_state.clone(), self.colored_vertex_buffer.clone(),
vec![self.get_solid_color_descriptor_set()], ()
&self.dynamic_state.clone(),
self.colored_vertex_buffer.clone(),
(), ()
).unwrap();
},
ShaderType::TEXTURED => {
@ -355,21 +380,18 @@ impl Canvas {
}
/// 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>>],
) -> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
let dimensions = images[0].dimensions();
let mut dynamic_state = DynamicState {
line_width: None,
viewports: Some(vec![Viewport {
self.dynamic_state.viewports =
Some(vec![Viewport {
origin: [0.0, 0.0],
dimensions: [dimensions.width() as f32, dimensions.height() as f32],
depth_range: 0.0..1.0,
}]),
scissors: None
};
}]);
images.iter().map(|image| {
Arc::new(

@ -19,6 +19,7 @@ use winit::{EventsLoop, WindowBuilder, WindowEvent, Event, DeviceEvent, VirtualK
use winit::dpi::LogicalSize;
use vulkano_win::VkSurfaceBuild;
use sprite::Sprite;
use crate::canvas::CanvasFrame;
mod util;
@ -62,7 +63,7 @@ fn main() {
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() {
@ -110,9 +111,10 @@ fn main() {
return;
}
let mut canvas = CanvasFrame::new();
canvas.draw(&sprite);
(frame_future) = processor.run(&surface, frame_future);
(frame_future) = processor.run(&surface, frame_future, canvas);
}
}

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

@ -9,7 +9,7 @@ use vulkano::image::swapchain::SwapchainImage;
use winit::{Window};
use crate::util::compute_kernel::ComputeKernel;
use crate::util::compute_image::ComputeImage;
use crate::canvas::Canvas;
use crate::canvas::{Canvas, CanvasFrame};
pub struct VkProcessor<'a> {
@ -146,9 +146,15 @@ impl<'a> VkProcessor<'a> {
self.compute_image.clone().unwrap().clone().save_image();
}
pub fn get_canvas(&mut self) -> &Canvas {
&self.canvas
}
pub fn run(&mut self,
surface: &'a Arc<Surface<Window>>,
mut frame_future: Box<dyn GpuFuture>,
surface: &'a Arc<Surface<Window>>,
mut frame_future: Box<dyn GpuFuture>,
canvas_frame: CanvasFrame,
) -> Box<dyn GpuFuture> {
let mut framebuffers =
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(),
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);

Loading…
Cancel
Save