Added sprite and better vertex format. works, but now I lost texturing
This commit is contained in:
66
src/main.rs
66
src/main.rs
@@ -46,7 +46,7 @@ use crate::workpiece::{WorkpieceLoader, Workpiece};
|
||||
use winit::{EventsLoop, WindowBuilder, WindowEvent, Event, DeviceEvent, VirtualKeyCode, ElementState};
|
||||
use winit::dpi::LogicalSize;
|
||||
use vulkano_win::VkSurfaceBuild;
|
||||
|
||||
use sprite::Sprite;
|
||||
|
||||
mod slider;
|
||||
mod timer;
|
||||
@@ -55,28 +55,9 @@ mod vkprocessor;
|
||||
mod util;
|
||||
mod button;
|
||||
mod workpiece;
|
||||
|
||||
|
||||
//struct Sprite {
|
||||
// pub texture:
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
How the F am I going to do sprites?
|
||||
|
||||
I need sprites for the slider and buttons at least
|
||||
|
||||
The background + render of the toolpath can probably just be straight up hand manipulated textures
|
||||
|
||||
Sprite will have 4 verticies and a texture along with position and size attributes
|
||||
|
||||
|
||||
|
||||
*/
|
||||
mod vertex_2d;
|
||||
mod vertex_3d;
|
||||
mod sprite;
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -91,18 +72,13 @@ fn main() {
|
||||
.build_vk_surface(&events_loop, instance.clone()).unwrap();
|
||||
let mut window = surface.window();
|
||||
|
||||
|
||||
let mut processor = vkprocessor::VkProcessor::new(&instance, &surface);
|
||||
|
||||
processor.compile_kernel(String::from("simple-edge.compute"));
|
||||
processor.compile_shaders(String::from("simple_texture"), &surface);
|
||||
|
||||
processor.load_buffers(String::from("background.jpg"));
|
||||
|
||||
|
||||
let mut timer = Timer::new();
|
||||
// let mut input = Input::new();
|
||||
|
||||
let mut frame_future = Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
|
||||
|
||||
let step_size: f32 = 0.005;
|
||||
let mut elapsed_time: f32;
|
||||
@@ -113,36 +89,11 @@ fn main() {
|
||||
let mut mouse_xy = Vector2i::new(0,0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let mut s = Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
|
||||
Sprite::new_with_color((0.,0.), (0,0), (0.,0.,0.,0.));
|
||||
|
||||
|
||||
while let Some(p) = window.get_position() {
|
||||
|
||||
// Event::MouseButtonPressed { button, x, y} => {
|
||||
// let x = x as u32;
|
||||
// let y = y as u32;
|
||||
// mouse_xy = mouse::desktop_position();
|
||||
// let r = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 0) as usize] as u8;
|
||||
// let g = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 1) as usize] as u8;
|
||||
// let b = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 2) as usize] as u8;
|
||||
// let a = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 3) as usize] as u8;
|
||||
//
|
||||
// selected_colors.push(
|
||||
// RectangleShape::with_size(Vector2f::new(30.0, 30.0))
|
||||
// );
|
||||
//
|
||||
// let mut x_position = 45.0 * selected_colors.len() as f32;
|
||||
//
|
||||
// selected_colors.last_mut().unwrap().set_position(Vector2f::new(x_position, 80.0));
|
||||
// selected_colors.last_mut().unwrap().set_fill_color(&Color::rgba(r,g,b,a));
|
||||
// }
|
||||
|
||||
|
||||
elapsed_time = timer.elap_time();
|
||||
delta_time = elapsed_time - current_time;
|
||||
current_time = elapsed_time;
|
||||
@@ -176,6 +127,9 @@ fn main() {
|
||||
_ => ()
|
||||
}
|
||||
},
|
||||
// Event::DeviceEvent { event: DeviceEvent::Button(mouse_input), .. } => {
|
||||
// mouse_xy.x
|
||||
// },
|
||||
_ => ()
|
||||
}
|
||||
});
|
||||
@@ -185,7 +139,7 @@ fn main() {
|
||||
}
|
||||
|
||||
|
||||
s = processor.run(&surface, s);
|
||||
frame_future = processor.run(&surface, frame_future);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
src/sprite.rs
Normal file
34
src/sprite.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use crate::vertex_2d::ColoredVertex2D;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
vertices: [ColoredVertex2D; 6],
|
||||
color: [f32; 4],
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
|
||||
pub fn new(position: (f32, f32), size: (u32, u32)) -> Sprite {
|
||||
Sprite::new_with_color(position, size, (0.,0.,0.,0.))
|
||||
}
|
||||
|
||||
pub fn new_with_color(position: (f32, f32), size: (u32, u32), color: (f32, f32, f32, f32)) -> Sprite {
|
||||
|
||||
let size = (size.0 as f32, size.1 as f32);
|
||||
|
||||
let color = [color.0, color.1, color.2, color.3];
|
||||
|
||||
Sprite {
|
||||
vertices: [
|
||||
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
|
||||
ColoredVertex2D { position: [ position.0, position.1 + size.1], color }, // bottom left
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
|
||||
|
||||
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 ], color }, // top right
|
||||
],
|
||||
color: color,
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/vertex_2d.rs
Normal file
13
src/vertex_2d.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Vertex2D {
|
||||
pub position: [f32; 2]
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ColoredVertex2D {
|
||||
pub position: [f32; 2],
|
||||
pub color : [f32; 4],
|
||||
}
|
||||
|
||||
vulkano::impl_vertex!(ColoredVertex2D, position, color);
|
||||
11
src/vertex_3d.rs
Normal file
11
src/vertex_3d.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Vertex3D {
|
||||
position: [f32; 3]
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ColoredVertex3D {
|
||||
position: [f32; 3],
|
||||
color : [u8; 4],
|
||||
}
|
||||
@@ -48,44 +48,8 @@ mod compute_image;
|
||||
use crate::vkprocessor::compute_image::ComputeImage;
|
||||
|
||||
use vulkano::descriptor::descriptor::DescriptorDesc;
|
||||
use crate::vertex_2d::ColoredVertex2D;
|
||||
|
||||
//
|
||||
//#[derive(Clone)]
|
||||
//struct ImageBuffers {
|
||||
// pub image_buffers : Vec<Box<ImageAccess + Send + Sync>>,
|
||||
//}
|
||||
//
|
||||
//impl ImageBuffers {
|
||||
//
|
||||
// pub fn new() -> ImageBuffers {
|
||||
// ImageBuffers {
|
||||
// image_buffers: vec![]
|
||||
// }
|
||||
// }
|
||||
// pub fn add_image(self) -> Self {
|
||||
//
|
||||
// self
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//unsafe impl DescriptorSetsCollection for ImageBuffers {
|
||||
// fn into_vec(self) -> Vec<Box<DescriptorSet>> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//
|
||||
// fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//
|
||||
// fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
struct tVertex { position: [f32; 2] }
|
||||
|
||||
/// This method is called once during initialization, then again whenever the window is resized
|
||||
fn window_size_dependent_setup(
|
||||
@@ -337,24 +301,25 @@ impl<'a> VkProcessor<'a> {
|
||||
|
||||
println!("Allocating Buffers...");
|
||||
|
||||
let color = [0.,0.,0.,0.];
|
||||
|
||||
let vertex_buffer = {
|
||||
vulkano::impl_vertex!(tVertex, position);
|
||||
|
||||
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), [
|
||||
tVertex { position: [ 1.0, 1.0 ] },
|
||||
tVertex { position: [ 1.0, 0.5 ] },
|
||||
tVertex { position: [ 0.5, 0.5 ] },
|
||||
tVertex { position: [ 0.5, 1.0 ] },
|
||||
ColoredVertex2D { position: [ 1.0, 1.0 ], color },
|
||||
ColoredVertex2D { position: [ 1.0, 0.5 ], color },
|
||||
ColoredVertex2D { position: [ 0.5, 0.5 ], color },
|
||||
ColoredVertex2D { position: [ 0.5, 1.0 ], color },
|
||||
].iter().cloned()).unwrap()
|
||||
};
|
||||
|
||||
let vertex_buffer2 = {
|
||||
|
||||
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), [
|
||||
tVertex { position: [-1.0, -1.0 ] },
|
||||
tVertex { position: [-1.0, -0.5 ] },
|
||||
tVertex { position: [-0.5, -0.5 ] },
|
||||
tVertex { position: [-0.5, -1.0 ] },
|
||||
ColoredVertex2D { position: [-1.0, -1.0 ], color },
|
||||
ColoredVertex2D { position: [-1.0, -0.5 ], color },
|
||||
ColoredVertex2D { position: [-0.5, -0.5 ], color },
|
||||
ColoredVertex2D { position: [-0.5, -1.0 ], color },
|
||||
].iter().cloned()).unwrap()
|
||||
};
|
||||
|
||||
@@ -407,6 +372,8 @@ impl<'a> VkProcessor<'a> {
|
||||
self.compute_image.clone().unwrap().clone().save_image();
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn run(&mut self, surface: &'a Arc<Surface<Window>>, mut frame_future: Box<dyn GpuFuture>) -> Box<dyn GpuFuture> {
|
||||
|
||||
let mut framebuffers = window_size_dependent_setup(&self.shader_kernels.clone().unwrap().swapchain_images.clone(),
|
||||
@@ -423,7 +390,8 @@ impl<'a> VkProcessor<'a> {
|
||||
if recreate_swapchain {
|
||||
self.shader_kernels = Some(self.shader_kernels.clone().unwrap().recreate_swapchain(surface));
|
||||
framebuffers = window_size_dependent_setup(&self.shader_kernels.clone().unwrap().swapchain_images.clone(),
|
||||
self.render_pass.clone().unwrap().clone(),
|
||||
self.shader_kernels.clone().unwrap().render_pass.clone(),
|
||||
//self.render_pass.clone().unwrap().clone(),
|
||||
&mut self.dynamic_state);
|
||||
recreate_swapchain = false;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode};
|
||||
use image::flat::NormalForm::ColumnMajorPacked;
|
||||
use image::Rgba;
|
||||
use crate::vkprocessor::SimpleSpecializationConstants;
|
||||
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
struct tVertex { position: [f32; 2] }
|
||||
use crate::vertex_2d::ColoredVertex2D;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputeImage {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess};
|
||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
||||
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc};
|
||||
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc, DescriptorSetDesc};
|
||||
use vulkano::device::{Device, DeviceExtensions, QueuesIter, Queue};
|
||||
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, QueueFamily};
|
||||
use vulkano::pipeline::{ComputePipeline, GraphicsPipeline, GraphicsPipelineAbstract, GraphicsPipelineBuilder};
|
||||
@@ -18,7 +18,7 @@ use image::GenericImage;
|
||||
use shade_runner::{ComputeLayout, CompileError, FragLayout, FragInput, FragOutput, VertInput, VertOutput, VertLayout, CompiledShaders, Entry};
|
||||
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSetBuf, PersistentDescriptorSetImg, PersistentDescriptorSetSampler};
|
||||
use shaderc::CompileOptions;
|
||||
use vulkano::framebuffer::{Subpass, RenderPass, RenderPassAbstract, Framebuffer, FramebufferAbstract};
|
||||
use vulkano::framebuffer::{Subpass, RenderPass, RenderPassAbstract, Framebuffer, FramebufferAbstract, RenderPassDesc};
|
||||
use vulkano::pipeline::shader::{GraphicsShaderType, ShaderModule, GraphicsEntryPoint, SpecializationConstants, SpecializationMapEntry};
|
||||
use vulkano::swapchain::{Swapchain, PresentMode, SurfaceTransform, Surface, SwapchainCreationError, AcquireError};
|
||||
use vulkano::swapchain::acquire_next_image;
|
||||
@@ -26,7 +26,7 @@ use vulkano::image::swapchain::SwapchainImage;
|
||||
use winit::{EventsLoop, WindowBuilder, Window, Event, WindowEvent};
|
||||
use vulkano_win::VkSurfaceBuild;
|
||||
use vulkano::pipeline::vertex::{SingleBufferDefinition, Vertex};
|
||||
use vulkano::descriptor::PipelineLayoutAbstract;
|
||||
use vulkano::descriptor::{PipelineLayoutAbstract, DescriptorSet};
|
||||
use std::alloc::Layout;
|
||||
use vulkano::pipeline::viewport::Viewport;
|
||||
use image::ImageFormat;
|
||||
@@ -37,6 +37,7 @@ use vulkano::format::Format;
|
||||
use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode};
|
||||
use image::flat::NormalForm::ColumnMajorPacked;
|
||||
use crate::vkprocessor::SimpleSpecializationConstants;
|
||||
use crate::vertex_2d::ColoredVertex2D;
|
||||
|
||||
struct EntryPoint<'a> {
|
||||
compiled_shaders: CompiledShaders,
|
||||
@@ -46,35 +47,18 @@ struct EntryPoint<'a> {
|
||||
fragment_shader_module: Arc<ShaderModule>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
struct tVertex { position: [f32; 2] }
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ShaderKernels {
|
||||
pub swapchain : Arc<Swapchain<Window>>,
|
||||
pub swapchain_images: Vec<Arc<SwapchainImage<Window>>>, // Surface which is drawn to
|
||||
//pub physical: PhysicalDevice<'a>,
|
||||
|
||||
//shader: CompiledShaders,
|
||||
|
||||
//options: CompileOptions<'a>,
|
||||
|
||||
pub render_pass: Arc<RenderPassAbstract + Send + Sync>,
|
||||
pub graphics_pipeline: Option<Arc<GraphicsPipelineAbstract + Sync + Send>>,
|
||||
|
||||
device: Arc<Device>,
|
||||
|
||||
// entry_point: EntryPoint<'a>,
|
||||
}
|
||||
|
||||
// return the frame buffers
|
||||
/*
|
||||
let mut framebuffers =
|
||||
window_size_dependent_setup(&self.images.clone().unwrap().clone(),
|
||||
self.render_pass.clone().unwrap().clone(),
|
||||
&mut self.dynamic_state);
|
||||
*/
|
||||
impl ShaderKernels {
|
||||
|
||||
fn get_path(filename: String) -> (PathBuf, PathBuf) {
|
||||
@@ -237,7 +221,6 @@ impl ShaderKernels {
|
||||
}
|
||||
).unwrap());
|
||||
|
||||
vulkano::impl_vertex!(tVertex, position);
|
||||
|
||||
|
||||
ShaderKernels {
|
||||
@@ -250,7 +233,7 @@ impl ShaderKernels {
|
||||
// We need to indicate the layout of the vertices.
|
||||
// The type `SingleBufferDefinition` actually contains a template parameter corresponding
|
||||
// to the type of each vertex. But in this code it is automatically inferred.
|
||||
.vertex_input_single_buffer::<tVertex>()
|
||||
.vertex_input_single_buffer::<ColoredVertex2D>()
|
||||
|
||||
// A Vulkan shader can in theory contain multiple entry points, so we have to specify
|
||||
// which one. The `main` word of `main_entry_point` actually corresponds to the name of
|
||||
@@ -261,7 +244,7 @@ impl ShaderKernels {
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// The content of the vertex buffer describes a list of triangles.
|
||||
.triangle_fan()
|
||||
.triangle_list_with_adjacency()
|
||||
// Use a resizable viewport set to draw over the entire window
|
||||
.viewports_dynamic_scissors_irrelevant(1)
|
||||
// See `vertex_shader`.
|
||||
|
||||
Reference in New Issue
Block a user