.
This commit is contained in:
BIN
resources/images/ford2.jpg
Normal file
BIN
resources/images/ford2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
@@ -55,10 +55,12 @@ void main() {
|
|||||||
if ((m.x + m.y + m.z) > 200){
|
if ((m.x + m.y + m.z) > 200){
|
||||||
p.x = 0;
|
p.x = 0;
|
||||||
p.y = 0;
|
p.y = 0;
|
||||||
p.z = p.z * 2;
|
p.z = 255;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//p.w = 125;
|
p.x = 0;
|
||||||
|
p.y = 0;
|
||||||
|
p.z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//write_buffer.buf[0] = write_buffer.buf[0];
|
//write_buffer.buf[0] = write_buffer.buf[0];
|
||||||
|
|||||||
@@ -7,12 +7,18 @@ use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, Ca
|
|||||||
use vulkano::pipeline::vertex::Vertex;
|
use vulkano::pipeline::vertex::Vertex;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use crate::VertexTypes;
|
use crate::VertexTypes;
|
||||||
|
use vulkano::sync::Event;
|
||||||
|
|
||||||
/// Trait which may be inherited by objects that wish to be drawn to the screen
|
/// Trait which may be inherited by objects that wish to be drawn to the screen
|
||||||
pub trait Drawable {
|
pub trait Drawable {
|
||||||
fn get(&self) -> VertexTypes;
|
fn get(&self) -> VertexTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trait which may be inherited by objects that wish to receive events
|
||||||
|
pub trait Eventable {
|
||||||
|
fn notify(&self, event: &Event) -> ();
|
||||||
|
}
|
||||||
|
|
||||||
/// Accumulator for Vectors of VertexTypes
|
/// Accumulator for Vectors of VertexTypes
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CanvasFrame {
|
pub struct CanvasFrame {
|
||||||
@@ -26,3 +32,6 @@ impl CanvasFrame {
|
|||||||
self.map.push(drawable.get());
|
self.map.push(drawable.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -499,7 +499,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"))
|
||||||
@@ -543,8 +542,6 @@ impl CanvasState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
// let mut shader = self.shader_buffers.get(
|
// let mut shader = self.shader_buffers.get(
|
||||||
// self.get_shader_handle(String::from("simple_text"))
|
// self.get_shader_handle(String::from("simple_text"))
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::canvas::*;
|
use crate::canvas::*;
|
||||||
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
|
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
|
||||||
use crate::canvas::canvas_frame::{Drawable};
|
use crate::canvas::canvas_frame::{Drawable, Eventable};
|
||||||
use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D};
|
use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D};
|
||||||
|
use winit::event::{DeviceEvent, MouseButton, ElementState, Event};
|
||||||
|
|
||||||
///
|
///
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Sprite {
|
pub struct Sprite {
|
||||||
|
|
||||||
pub verts: VertexTypes,
|
pub verts: VertexTypes,
|
||||||
|
|
||||||
position: (f32, f32),
|
position: (f32, f32),
|
||||||
@@ -16,34 +16,38 @@ pub struct Sprite {
|
|||||||
|
|
||||||
/// Container class which implements drawable.
|
/// Container class which implements drawable.
|
||||||
impl Sprite {
|
impl Sprite {
|
||||||
|
|
||||||
///
|
///
|
||||||
pub fn new(position: (f32, f32),
|
pub fn new(position: (f32, f32),
|
||||||
size: (f32, f32),
|
size: (f32, f32),
|
||||||
depth: u32,
|
depth: u32,
|
||||||
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
|
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
|
||||||
|
|
||||||
let normalized_depth = (depth as f32 / 255.0);
|
let normalized_depth = (depth as f32 / 255.0);
|
||||||
|
|
||||||
let verts = vec![
|
let verts = vec![
|
||||||
TextureVertex3D{
|
TextureVertex3D {
|
||||||
v_position: [position.0, position.1, normalized_depth], // top left
|
v_position: [position.0, position.1, normalized_depth], // top left
|
||||||
ti_position: [-0.0, -0.0] },
|
ti_position: [-0.0, -0.0],
|
||||||
TextureVertex3D{
|
},
|
||||||
|
TextureVertex3D {
|
||||||
v_position: [position.0, position.1 + size.1, normalized_depth], // bottom left
|
v_position: [position.0, position.1 + size.1, normalized_depth], // bottom left
|
||||||
ti_position: [-0.0, 1.0] },
|
ti_position: [-0.0, 1.0],
|
||||||
TextureVertex3D{
|
},
|
||||||
|
TextureVertex3D {
|
||||||
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
||||||
ti_position: [1.0, 1.0] },
|
ti_position: [1.0, 1.0],
|
||||||
TextureVertex3D{
|
},
|
||||||
|
TextureVertex3D {
|
||||||
v_position: [position.0, position.1, normalized_depth], // top left
|
v_position: [position.0, position.1, normalized_depth], // top left
|
||||||
ti_position: [-0.0, -0.0] },
|
ti_position: [-0.0, -0.0],
|
||||||
TextureVertex3D{
|
},
|
||||||
|
TextureVertex3D {
|
||||||
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
||||||
ti_position: [1.0, 1.0] },
|
ti_position: [1.0, 1.0],
|
||||||
TextureVertex3D{
|
},
|
||||||
|
TextureVertex3D {
|
||||||
v_position: [position.0 + size.0, position.1, normalized_depth], // top right
|
v_position: [position.0 + size.0, position.1, normalized_depth], // top right
|
||||||
ti_position: [1.0, -0.0] },
|
ti_position: [1.0, -0.0],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
Sprite {
|
Sprite {
|
||||||
@@ -53,12 +57,29 @@ impl Sprite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Drawable for Sprite{
|
|
||||||
|
impl Drawable for Sprite {
|
||||||
fn get(&self) -> VertexTypes {
|
fn get(&self) -> VertexTypes {
|
||||||
self.verts.clone()
|
self.verts.clone()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eventable<T> for Sprite {
|
||||||
|
fn notify<T>(&self, event: &Event<T>) -> () {
|
||||||
|
match event {
|
||||||
|
Event::DeviceEvent { event: DeviceEvent::Button{button, state }, .. } => {
|
||||||
|
match button.id.unwrap() {
|
||||||
|
MouseButton::Left => {
|
||||||
|
if state.state == ElementState::Pressed {
|
||||||
|
// processor.save_edges_image();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
20
src/main.rs
20
src/main.rs
@@ -87,7 +87,7 @@ pub fn main() {
|
|||||||
let mut accumulator_time: f32 = 0.0;
|
let mut accumulator_time: f32 = 0.0;
|
||||||
let mut current_time: f32 = timer.elap_time();
|
let mut current_time: f32 = timer.elap_time();
|
||||||
|
|
||||||
let image_data = load_raw(String::from("funky-bird.jpg"));
|
let image_data = load_raw(String::from("ford2.jpg"));
|
||||||
let image_dimensions_f: (f32, f32) = ((image_data.1).clone().0 as f32, (image_data.1).clone().1 as f32);
|
let image_dimensions_f: (f32, f32) = ((image_data.1).clone().0 as f32, (image_data.1).clone().1 as f32);
|
||||||
let image_dimensions_u: (u32, u32) = image_data.1;
|
let image_dimensions_u: (u32, u32) = image_data.1;
|
||||||
let compu_sprite1: CompuSprite =
|
let compu_sprite1: CompuSprite =
|
||||||
@@ -95,9 +95,6 @@ pub fn main() {
|
|||||||
// Swap image to render the result to. Must match dimensions
|
// Swap image to render the result to. Must match dimensions
|
||||||
processor.new_swap_image(image_dimensions_u));
|
processor.new_swap_image(image_dimensions_u));
|
||||||
|
|
||||||
|
|
||||||
// Demo gpu toolpath generation
|
|
||||||
|
|
||||||
// Need to
|
// Need to
|
||||||
let compute_buffer: Arc<CompuBufferHandle> =
|
let compute_buffer: Arc<CompuBufferHandle> =
|
||||||
processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4);
|
processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4);
|
||||||
@@ -149,6 +146,16 @@ pub fn main() {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Events loop is borrowed from the surface
|
// Events loop is borrowed from the surface
|
||||||
events_loop.run(move |event, _, control_flow| {
|
events_loop.run(move |event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
@@ -163,15 +170,12 @@ pub fn main() {
|
|||||||
let mut canvas_frame = CanvasFrame::default();
|
let mut canvas_frame = CanvasFrame::default();
|
||||||
canvas_frame.draw(&funky_sprite);
|
canvas_frame.draw(&funky_sprite);
|
||||||
canvas_frame.draw(&text_sprite);
|
canvas_frame.draw(&text_sprite);
|
||||||
// canvas_frame.draw(&rect);
|
canvas_frame.draw(&compu_sprite1);
|
||||||
|
|
||||||
let mut compu_frame = CompuFrame::new();
|
let mut compu_frame = CompuFrame::new();
|
||||||
//compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
||||||
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||||
compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||||
|
|
||||||
canvas_frame.draw(&compu_sprite1);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let g = hprof::enter("Run");
|
let g = hprof::enter("Run");
|
||||||
processor.run(&surface.clone(),
|
processor.run(&surface.clone(),
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ impl VkProcessor {
|
|||||||
|
|
||||||
/// A hardcoded list of textures which can be preloaded from this function
|
/// A hardcoded list of textures which can be preloaded from this function
|
||||||
pub fn preload_textures(&mut self) {
|
pub fn preload_textures(&mut self) {
|
||||||
|
self.canvas_state.load_texture(String::from("ford2.jpg"));
|
||||||
self.canvas_state.load_texture(String::from("funky-bird.jpg"));
|
self.canvas_state.load_texture(String::from("funky-bird.jpg"));
|
||||||
self.canvas_state.load_texture(String::from("button.png"));
|
self.canvas_state.load_texture(String::from("button.png"));
|
||||||
self.canvas_state.load_texture(String::from("background.jpg"));
|
self.canvas_state.load_texture(String::from("background.jpg"));
|
||||||
|
|||||||
Reference in New Issue
Block a user