some fiddling with documentation. Added Poly type
This commit is contained in:
@@ -200,7 +200,7 @@ impl CanvasState {
|
||||
|
||||
let mut compute_path = project_root.clone();
|
||||
compute_path.push(PathBuf::from("resources/images/"));
|
||||
compute_path.push(PathBuf::from(image_filename));
|
||||
compute_path.push(PathBuf::from(image_filename.clone()));
|
||||
|
||||
let img = image::open(compute_path).expect("Couldn't find image");
|
||||
|
||||
@@ -212,7 +212,7 @@ impl CanvasState {
|
||||
let mut image_buffer = Vec::new();
|
||||
|
||||
if pixel_count != data_length as usize {
|
||||
println!("Creating apha channel...");
|
||||
println!("Creating alpha channel for {}", image_filename.clone());
|
||||
for i in img.raw_pixels().iter() {
|
||||
if (image_buffer.len() + 1) % 4 == 0 {
|
||||
image_buffer.push(255);
|
||||
@@ -236,7 +236,6 @@ impl CanvasState {
|
||||
|
||||
/// Load a texture using it's filename from a file. Returns the handle of the loaded texture
|
||||
pub fn load_texture(&mut self, filename: String) -> Option<Arc<CanvasTextureHandle>> {
|
||||
let texture_buffer = self.get_texture_from_file(filename.clone());
|
||||
|
||||
let handle = Arc::new(CanvasTextureHandle {
|
||||
handle: self.texture_buffers.len() as u32
|
||||
|
||||
@@ -105,13 +105,13 @@ impl CompuState {
|
||||
let buffer = self.compute_buffers.get(buffer_id).unwrap();
|
||||
let kernel = self.kernels.get(kernel_id).unwrap();
|
||||
|
||||
let p = kernel.clone().get_pipeline();
|
||||
let d = buffer.get_descriptor_set(kernel.clone().get_pipeline());
|
||||
let pipeline = kernel.clone().get_pipeline();
|
||||
let descriptorset = buffer.get_descriptor_set(kernel.clone().get_pipeline());
|
||||
|
||||
let size = buffer.get_size();
|
||||
|
||||
command_buffer = command_buffer
|
||||
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
|
||||
.dispatch([size.0 / 8, size.1 / 8, 1], pipeline, descriptorset, ()).unwrap()
|
||||
}
|
||||
|
||||
// i = (Buffer, Image, Kernel)
|
||||
|
||||
3
src/drawables/mod.rs
Normal file
3
src/drawables/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod polygon;
|
||||
pub mod sprite;
|
||||
pub mod rect;
|
||||
71
src/drawables/polygon.rs
Normal file
71
src/drawables/polygon.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use std::sync::Arc;
|
||||
use crate::canvas::*;
|
||||
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
|
||||
use crate::canvas::canvas_frame::{Drawable};
|
||||
use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D, ColorVertex3D};
|
||||
use crate::drawables::sprite::Sprite;
|
||||
|
||||
/// Convex multi verticy polygon
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Polygon {
|
||||
|
||||
pub verts: VertexTypes,
|
||||
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
}
|
||||
|
||||
/// Container class which implements drawable.
|
||||
impl Polygon {
|
||||
|
||||
///
|
||||
pub fn new(position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
depth: u32,) -> Polygon {
|
||||
|
||||
let normalized_depth = (depth as f32 / 255.0);
|
||||
|
||||
let verts = vec![
|
||||
ColorVertex3D{v_position: [-0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.0, 0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.0, 0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.0, -0.1, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [0.0, -0.1, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
ColorVertex3D{v_position: [-0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||||
];
|
||||
|
||||
|
||||
Polygon {
|
||||
verts: VertexTypes::ColorType(verts),
|
||||
position: position,
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Drawable for Polygon {
|
||||
fn get(&self) -> VertexTypes {
|
||||
self.verts.clone()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
57
src/drawables/rect.rs
Normal file
57
src/drawables/rect.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use crate::canvas::canvas_frame::Drawable;
|
||||
use crate::util::vertex::{VertexTypes, ColorVertex3D};
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Rect {
|
||||
|
||||
pub verts: VertexTypes,
|
||||
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
}
|
||||
|
||||
/// Container class which implements drawable.
|
||||
impl Rect {
|
||||
|
||||
///
|
||||
pub fn new(position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
depth: u32) -> Rect {
|
||||
|
||||
let normalized_depth = (depth as f32 / 255.0);
|
||||
|
||||
let verts = vec![
|
||||
ColorVertex3D{
|
||||
v_position: [position.0, position.1, normalized_depth], // top left
|
||||
color: [0.0, 1.0, 1.0, 0.5] },
|
||||
ColorVertex3D{
|
||||
v_position: [position.0, position.1 + size.1, normalized_depth], // bottom left
|
||||
color: [1.0, 1.0, 1.0, 1.0] },
|
||||
ColorVertex3D{
|
||||
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
||||
color: [1.0, 1.0, 1.0, 1.0] },
|
||||
ColorVertex3D{
|
||||
v_position: [position.0, position.1, normalized_depth], // top left
|
||||
color: [1.0, 1.0, 1.0, 1.0] },
|
||||
ColorVertex3D{
|
||||
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
||||
color: [1.0, 1.0, 1.0, 1.0] },
|
||||
ColorVertex3D{
|
||||
v_position: [position.0 + size.0, position.1, normalized_depth], // top right
|
||||
color: [1.0, 1.0, 1.0, 1.0] },
|
||||
];
|
||||
|
||||
Rect {
|
||||
verts: VertexTypes::ColorType(verts),
|
||||
position: position,
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Drawable for Rect {
|
||||
fn get(&self) -> VertexTypes {
|
||||
self.verts.clone()
|
||||
}
|
||||
|
||||
}
|
||||
48
src/main.rs
48
src/main.rs
@@ -18,7 +18,6 @@ use vulkano::sync::GpuFuture;
|
||||
use winit::{EventsLoop, WindowBuilder, WindowEvent, Event, DeviceEvent, VirtualKeyCode, ElementState};
|
||||
use winit::dpi::LogicalSize;
|
||||
use vulkano_win::VkSurfaceBuild;
|
||||
use sprite::Sprite;
|
||||
|
||||
use crate::util::load_raw;
|
||||
|
||||
@@ -30,34 +29,15 @@ use std::sync::Arc;
|
||||
use crate::canvas::managed::handles::{CanvasTextureHandle, Handle, CanvasFontHandle};
|
||||
use crate::util::vertex::{VertexTypes, TextureVertex3D};
|
||||
use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
|
||||
|
||||
use crate::drawables::sprite::Sprite;
|
||||
use crate::drawables::rect::Rect;
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
pub mod sprite;
|
||||
|
||||
pub mod drawables;
|
||||
pub mod canvas;
|
||||
pub mod compute;
|
||||
|
||||
/*
|
||||
|
||||
Trac3r : A program to convert images to 2D toolpaths
|
||||
|
||||
TODO:
|
||||
+ Text rendering is half implemented.
|
||||
+ Need generalized interface for render (image, texture, text)
|
||||
+ Currently using local copies of a few libraries:
|
||||
shade_runner
|
||||
vulkano/vulkano-win
|
||||
vulkano/vulkano-shaders
|
||||
vulkano/vulkano
|
||||
+ Need to generate runtime vertex definitions if I want to have on the fly shaders
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
pub fn main() {
|
||||
hprof::start_frame();
|
||||
|
||||
@@ -125,8 +105,12 @@ pub fn main() {
|
||||
let font_handle : Arc<CanvasFontHandle> =
|
||||
processor.get_font_handle(String::from("sansation.ttf")).unwrap();
|
||||
|
||||
let funky_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
|
||||
let funky_sprite = Sprite::new((0.0, 0.5), (0.5, 0.5), 0, funky_handle.clone());
|
||||
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
||||
let rect = Rect::new((-0.5, -0.5), (0.5, 0.5), 1);
|
||||
|
||||
|
||||
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
||||
//let text_sprite = Text::new((-0.1,-0.1), (10.0, 10.0), font_handle.clone());
|
||||
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
||||
|
||||
@@ -187,20 +171,15 @@ pub fn main() {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
let funky_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
|
||||
|
||||
let mut canvas_frame = CanvasFrame::default();
|
||||
canvas_frame.draw(&funky_sprite);
|
||||
canvas_frame.draw(&sfml_sprite);
|
||||
// canvas_frame.draw(&funky_sprite);
|
||||
// canvas_frame.draw(&sfml_sprite);
|
||||
// canvas_frame.draw(&rect);
|
||||
|
||||
let mut compu_frame = CompuFrame::new();
|
||||
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||
compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||
//
|
||||
// let mut canvas = CanvasFrame::new();
|
||||
// canvas.draw(&funky_sprite);
|
||||
// canvas.draw(&test_polygon);
|
||||
|
||||
|
||||
{
|
||||
let g = hprof::enter("Run");
|
||||
@@ -213,7 +192,6 @@ pub fn main() {
|
||||
drop(l);
|
||||
|
||||
|
||||
return;
|
||||
hprof::end_frame();
|
||||
hprof::profiler().print_timing();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn load_raw(filename: String) -> (Vec<u8>, (u32,u32)) {
|
||||
let mut image_buffer = Vec::new();
|
||||
|
||||
if pixel_count != data_length as usize {
|
||||
println!("Creating apha channel...");
|
||||
println!("Creating alpha channel for {}", filename);
|
||||
for i in img.raw_pixels().iter() {
|
||||
if (image_buffer.len() + 1) % 4 == 0 {
|
||||
image_buffer.push(255);
|
||||
|
||||
@@ -222,10 +222,9 @@ impl<'a> VkProcessor<'a> {
|
||||
self.compute_state.write_compute_buffer(handle, data)
|
||||
}
|
||||
|
||||
///
|
||||
/// Run the VKprocessor for a single frame, consuming the Canvas/Compu Frames
|
||||
pub fn run(&mut self,
|
||||
surface: &'a Arc<Surface<Window>>,
|
||||
//canvas_frame: CanvasFrame,
|
||||
canvas_frame: CanvasFrame,
|
||||
compute_frame: CompuFrame,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user