Compare commits
No commits in common. 'a-star' and 'master' have entirely different histories.
@ -1,53 +0,0 @@
|
|||||||
Content-Type: text/x-zim-wiki
|
|
||||||
Wiki-Format: zim 0.4
|
|
||||||
Creation-Date: 2020-08-06T21:51:48-07:00
|
|
||||||
|
|
||||||
====== MakingAnActualThing ======
|
|
||||||
Created Thursday 06 August 2020
|
|
||||||
|
|
||||||
So, I need to figure out how to determine which objects will :
|
|
||||||
* Be rendered
|
|
||||||
* Be notified
|
|
||||||
* Get batched
|
|
||||||
* And initialized
|
|
||||||
|
|
||||||
|
|
||||||
Looks like it could possibly be specs...
|
|
||||||
|
|
||||||
Sprites currently are just a container for the meta-information needed in order to return a VertexTypeContainer.
|
|
||||||
|
|
||||||
{{{code: lang="rust" linenumbers="True"
|
|
||||||
pub enum VertexTypeContainer {
|
|
||||||
TextureType(Vec<TextureVertex3D>, Arc<CanvasTextureHandle>),
|
|
||||||
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
|
|
||||||
ColorType(Vec<ColorVertex3D>),
|
|
||||||
ThreeDType(Vec<Vertex3D>),
|
|
||||||
TextType(Vec<ColorVertex3D>),
|
|
||||||
}
|
|
||||||
}}}
|
|
||||||
|
|
||||||
|
|
||||||
So for a sprite, which is a generic texture and position/size combo
|
|
||||||
Images are similar, but instead of a "sprite" I made a computsprite because that's the only thing that uses them.
|
|
||||||
|
|
||||||
Now if I had to shove these into a component / a set of components... I could have a component of the vertex type even?
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
===== Sep 2020 =====
|
|
||||||
|
|
||||||
Lets think about this for a minute...
|
|
||||||
|
|
||||||
* We have components which are purely data...
|
|
||||||
* But can also have structs that impl functionality
|
|
||||||
* The data can be contained within traits. But it has to do all IO through the trait interface. ALL
|
|
||||||
* Problem, for example I have primitives like textured sprites, and also complex widgets which also have additional IO they they need. Like text input or buttons. I suppose This could all be made message based. So when the text input receives a focus, and then key presses it would update. When the enter key is pressed it could create a customer event for which another component is the listener...
|
|
||||||
* Maybe this is the way to go... Have some generic structure that has a render(params), notify(event), update(delta) -> VEvent
|
|
||||||
* So if I had a textbox sprite it could notify(key events) render
|
|
||||||
* We can split up components in order to have sharable sets of data for shared functionality. e.g rendering
|
|
||||||
|
|
||||||
[[paste]]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
So that article more or less talked about what I was thinking with the ECS. But they didn't really go into the separation of components.
|
|
@ -1,40 +0,0 @@
|
|||||||
Content-Type: text/x-zim-wiki
|
|
||||||
Wiki-Format: zim 0.4
|
|
||||||
Creation-Date: 2020-09-09T22:41:18-07:00
|
|
||||||
|
|
||||||
====== paste ======
|
|
||||||
Created Wednesday 09 September 2020
|
|
||||||
|
|
||||||
// If I were to have multiple systems
|
|
||||||
/*
|
|
||||||
|
|
||||||
One for rendering
|
|
||||||
One for updating
|
|
||||||
One for eventing
|
|
||||||
|
|
||||||
Rendering is easy enough. It needs all the components necessary in order
|
|
||||||
to generate the vertices. This includes the position, size, and vertex generator
|
|
||||||
|
|
||||||
Updating can probably be multiple types, I imagine something that implemented an Updatable
|
|
||||||
trait could then be used.
|
|
||||||
|
|
||||||
So the big problem here is that I have two traits that I want to expose, BUT
|
|
||||||
I have to put the concrete value in both containers... I don't think this is something
|
|
||||||
that specs will like since it wants to be the only owner. No use in RefCell'ing it
|
|
||||||
because that's just stupid
|
|
||||||
|
|
||||||
What if I turn this on it's head and really embrace the systems. So for example I could have
|
|
||||||
the User system. Ooof this is a big question actually...
|
|
||||||
|
|
||||||
// Components that want to be updated
|
|
||||||
Move
|
|
||||||
|
|
||||||
// want to be drawn
|
|
||||||
Drawable
|
|
||||||
Geom
|
|
||||||
|
|
||||||
Notifyable
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
File diff suppressed because one or more lines are too long
@ -1,58 +0,0 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use specs::{Component, Join, System, VecStorage, Write, WriteStorage};
|
|
||||||
|
|
||||||
use crate::canvas::canvas_frame::CanvasFrame;
|
|
||||||
use crate::canvas::compu_frame::CompuFrame;
|
|
||||||
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle, CompuBufferHandle, CompuKernelHandle};
|
|
||||||
use crate::PersistentState;
|
|
||||||
use crate::render_system::{Geometry, Images, Position, Textures};
|
|
||||||
use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer};
|
|
||||||
use crate::vkprocessor::VkProcessor;
|
|
||||||
|
|
||||||
pub struct Compu {
|
|
||||||
pub kernels: Vec<Arc<CompuKernelHandle>>,
|
|
||||||
pub buffers: Vec<Arc<CompuBufferHandle>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Compu {
|
|
||||||
type Storage = VecStorage<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CompuSystem;
|
|
||||||
|
|
||||||
impl<'a> System<'a> for CompuSystem {
|
|
||||||
type SystemData = (
|
|
||||||
WriteStorage<'a, Compu>,
|
|
||||||
WriteStorage<'a, Images>,
|
|
||||||
Write<'a, PersistentState>, // delta_time, window size, etc.
|
|
||||||
Write<'a, VkProcessor>, // Renderer
|
|
||||||
);
|
|
||||||
|
|
||||||
fn run(&mut self, (
|
|
||||||
mut compu_list,
|
|
||||||
mut image_list,
|
|
||||||
mut state,
|
|
||||||
mut vk_processor
|
|
||||||
): Self::SystemData) {
|
|
||||||
state.compu_frame = CompuFrame::new(state.window_size);
|
|
||||||
|
|
||||||
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
||||||
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
||||||
|
|
||||||
for (compute_item, image) in (&mut compu_list, &mut image_list).join() {
|
|
||||||
state.compu_frame.add_with_image_swap(
|
|
||||||
compute_item.buffers.get(0).unwrap().clone(),
|
|
||||||
compute_item.kernels.get(0).unwrap().clone(),
|
|
||||||
image,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (compute_item) in (&mut compu_list).join() {
|
|
||||||
state.compu_frame.add(
|
|
||||||
compute_item.buffers.get(0).unwrap().clone(),
|
|
||||||
compute_item.kernels.get(0).unwrap().clone(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,169 @@
|
|||||||
|
use std::ffi::CStr;
|
||||||
|
use vulkano::buffer::{CpuAccessibleBuffer, BufferUsage};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use vulkano::framebuffer::RenderPassAbstract;
|
||||||
|
use vulkano::pipeline::{GraphicsPipelineAbstract, ComputePipeline};
|
||||||
|
use vulkano::device::Device;
|
||||||
|
use image::ImageBuffer;
|
||||||
|
use image::GenericImageView;
|
||||||
|
use vulkano::image::{ImageUsage, AttachmentImage};
|
||||||
|
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSetBuf, PersistentDescriptorSet};
|
||||||
|
use vulkano::format::Format;
|
||||||
|
use vulkano::descriptor::pipeline_layout::PipelineLayout;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use image::Rgba;
|
||||||
|
use vulkano::command_buffer::AutoCommandBufferBuilder;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use shade_runner::{CompiledShaders, Entry, CompileError};
|
||||||
|
use vulkano::pipeline::shader::ShaderModule;
|
||||||
|
use shaderc::CompileOptions;
|
||||||
|
use crate::compute::compu_frame::CompuFrame;
|
||||||
|
use crate::canvas::managed::handles::Handle;
|
||||||
|
use crate::compute::managed::compu_buffer::CompuBuffers;
|
||||||
|
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
|
||||||
|
use crate::compute::managed::compu_kernel::CompuKernel;
|
||||||
|
use crate::canvas::canvas_state::CanvasState;
|
||||||
|
|
||||||
|
|
||||||
|
/// State holding the compute buffers for computation and the kernels which will compute them
|
||||||
|
pub struct CompuState {
|
||||||
|
compute_buffers: Vec<CompuBuffers>,
|
||||||
|
kernels: Vec<CompuKernel>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompuState {
|
||||||
|
|
||||||
|
pub fn new() -> CompuState {
|
||||||
|
CompuState {
|
||||||
|
compute_buffers: vec![],
|
||||||
|
kernels: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a 2d compute buffer from incoming data
|
||||||
|
pub fn new_compute_buffer(&mut self,
|
||||||
|
data: Vec<u8>,
|
||||||
|
dimensions: (u32, u32),
|
||||||
|
stride: u32,
|
||||||
|
device: Arc<Device>) -> Arc<CompuBufferHandle> {
|
||||||
|
|
||||||
|
let handle = Arc::new(CompuBufferHandle {
|
||||||
|
handle: self.compute_buffers.len() as u32
|
||||||
|
});
|
||||||
|
|
||||||
|
self.compute_buffers.push(
|
||||||
|
(CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone())));
|
||||||
|
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_compute_buffer(&mut self, handle: Arc<CompuBufferHandle>) -> Vec<u8> {
|
||||||
|
let mut buffer : &CompuBuffers = self.compute_buffers.get(handle.handle as usize).unwrap();
|
||||||
|
let v = buffer.read_output_buffer();
|
||||||
|
v.into_vec()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write to the compute buffer, ostensibly overwriting what's already there
|
||||||
|
pub fn write_compute_buffer(&self, handle: Arc<CompuBufferHandle>, data: Vec<u8>) {
|
||||||
|
unimplemented!("read_compute_buffer is not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_kernel(&mut self,
|
||||||
|
filename: String,
|
||||||
|
device: Arc<Device>) -> Arc<CompuKernelHandle> {
|
||||||
|
let handle = Arc::new(CompuKernelHandle {
|
||||||
|
handle: self.kernels.len() as u32
|
||||||
|
});
|
||||||
|
|
||||||
|
self.kernels.push((CompuKernel::new(filename, device.clone(), handle.clone())));
|
||||||
|
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> {
|
||||||
|
for i in self.kernels.clone() {
|
||||||
|
if i.get_name() == kernel_name {
|
||||||
|
return Some(i.get_handle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compute_commands(&mut self,
|
||||||
|
compute_frame: &CompuFrame,
|
||||||
|
mut command_buffer: &mut AutoCommandBufferBuilder,
|
||||||
|
canvas: &CanvasState) {
|
||||||
|
|
||||||
|
// i = (Buffer, Kernel)
|
||||||
|
for i in &compute_frame.pure_compute {
|
||||||
|
let buffer_id = (*i.0).clone().get_handle() as usize;
|
||||||
|
let kernel_id = (*i.1).clone().get_handle() as usize;
|
||||||
|
|
||||||
|
let buffer = self.compute_buffers.get(buffer_id).unwrap();
|
||||||
|
let kernel = self.kernels.get(kernel_id).unwrap();
|
||||||
|
|
||||||
|
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], pipeline, descriptorset, ()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
// i = (Buffer, Image, Kernel)
|
||||||
|
for i in &compute_frame.swapped_to_image {
|
||||||
|
let buffer_id = (*i.0).clone().get_handle() as usize;
|
||||||
|
let image_id = i.1.clone();
|
||||||
|
let kernel_id = (*i.2).clone().handle as usize;
|
||||||
|
|
||||||
|
let buffer = self.compute_buffers.get(buffer_id).unwrap();
|
||||||
|
let image = canvas.get_image(image_id);
|
||||||
|
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 dimensions = image.dimensions();
|
||||||
|
let dimensions = (dimensions[0], dimensions[1]);
|
||||||
|
if dimensions != buffer.get_size() {
|
||||||
|
panic!("Buffer sizes not the same");
|
||||||
|
}
|
||||||
|
|
||||||
|
let size = buffer.get_size();
|
||||||
|
|
||||||
|
command_buffer = command_buffer
|
||||||
|
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
|
||||||
|
.copy_buffer_to_image(buffer.get_output_buffer(), image).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// i = (Input Buffer, Output Buffer, Kernel)
|
||||||
|
// Input buffer -> Kernel -> Output buffer
|
||||||
|
for i in &compute_frame.swapped_to_buffer {
|
||||||
|
let input_buffer_id = (*i.0).clone().get_handle() as usize;
|
||||||
|
let output_buffer_id = (*i.1).clone().get_handle() as usize;
|
||||||
|
let kernel_id = (*i.2).clone().handle as usize;
|
||||||
|
|
||||||
|
let input_buffer = self.compute_buffers.get(input_buffer_id).unwrap();
|
||||||
|
let output_buffer = self.compute_buffers.get(output_buffer_id).unwrap();
|
||||||
|
let kernel = self.kernels.get(kernel_id).unwrap();
|
||||||
|
|
||||||
|
let pipeline = kernel.clone().get_pipeline();
|
||||||
|
let descriptor_set = input_buffer.get_descriptor_set(kernel.clone().get_pipeline());
|
||||||
|
|
||||||
|
if input_buffer.get_size() != output_buffer.get_size() {
|
||||||
|
panic!("Buffer sizes not the same");
|
||||||
|
}
|
||||||
|
let size = input_buffer.get_size();
|
||||||
|
|
||||||
|
command_buffer = command_buffer
|
||||||
|
// .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap()
|
||||||
|
.copy_buffer(
|
||||||
|
input_buffer.get_output_buffer(),
|
||||||
|
output_buffer.get_input_buffer()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
use crate::canvas::managed::handles::Handle;
|
||||||
|
|
||||||
|
/// Typed wrapper for a u32 handle
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
|
pub struct CompuBufferHandle {
|
||||||
|
pub(in crate::compute) handle: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Handle for CompuBufferHandle {
|
||||||
|
fn get_handle(&self) -> u32 {
|
||||||
|
self.handle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Typed wrapper for a u32 handle
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
|
pub struct CompuKernelHandle {
|
||||||
|
pub(in crate::compute) handle: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Handle for CompuKernelHandle {
|
||||||
|
fn get_handle(&self) -> u32 {
|
||||||
|
self.handle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
pub mod compu_buffer;
|
||||||
|
pub mod compu_kernel;
|
||||||
|
pub mod handles;
|
@ -0,0 +1,6 @@
|
|||||||
|
pub mod compu_frame;
|
||||||
|
pub mod compu_state;
|
||||||
|
pub mod managed;
|
||||||
|
|
||||||
|
use crate::compute::compu_state::CompuState;
|
||||||
|
use crate::compute::compu_frame::CompuFrame;
|
@ -1,64 +0,0 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use specs::{Component, Entities, Join, System, VecStorage, Write, WriteStorage};
|
|
||||||
use vulkano::swapchain::Surface;
|
|
||||||
use winit::window::Window;
|
|
||||||
|
|
||||||
use crate::canvas::canvas_frame::CanvasFrame;
|
|
||||||
use crate::canvas::compu_frame::CompuFrame;
|
|
||||||
use crate::PersistentState;
|
|
||||||
use crate::render_system::Position;
|
|
||||||
use crate::util::tr_event::{TrEvent, TrEventExtension, TrWindowEvent};
|
|
||||||
use crate::vkprocessor::VkProcessor;
|
|
||||||
use winit::event::ElementState;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Evented {
|
|
||||||
pub subscribed: fn(event: TrEvent<TrEventExtension>) -> bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Evented {
|
|
||||||
type Storage = VecStorage<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventSystem;
|
|
||||||
|
|
||||||
impl<'a> System<'a> for EventSystem {
|
|
||||||
type SystemData = (
|
|
||||||
Entities<'a>,
|
|
||||||
WriteStorage<'a, Position>,
|
|
||||||
WriteStorage<'a, Evented>,
|
|
||||||
Write<'a, PersistentState>,
|
|
||||||
Write<'a, VkProcessor>,
|
|
||||||
Write<'a, Vec<TrEvent<TrEventExtension>>>
|
|
||||||
);
|
|
||||||
|
|
||||||
fn run(&mut self, (
|
|
||||||
entity,
|
|
||||||
mut position_list,
|
|
||||||
mut evented_list,
|
|
||||||
mut state,
|
|
||||||
mut vk_processor,
|
|
||||||
event_stack
|
|
||||||
): Self::SystemData) {
|
|
||||||
|
|
||||||
for (position, evented) in (&mut position_list, &evented_list).join() {
|
|
||||||
for event in &*event_stack {
|
|
||||||
match event {
|
|
||||||
TrEvent::WindowEvent { window_id, event } => {
|
|
||||||
match event {
|
|
||||||
TrWindowEvent::MouseInput { device_id, state, button, modifiers } => {
|
|
||||||
if *state == ElementState::Pressed {
|
|
||||||
position.x += 100.0;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (entity, evented) in (&*entity, &mut evented_list).join() {}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,220 +0,0 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use specs::{Component, Join, System, VecStorage, Write, WriteStorage};
|
|
||||||
|
|
||||||
use crate::canvas::canvas_frame::CanvasFrame;
|
|
||||||
use crate::canvas::compu_frame::CompuFrame;
|
|
||||||
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
|
|
||||||
use crate::PersistentState;
|
|
||||||
use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer};
|
|
||||||
use crate::vkprocessor::VkProcessor;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Position {
|
|
||||||
pub x: f32,
|
|
||||||
pub y: f32,
|
|
||||||
pub z: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Position {
|
|
||||||
type Storage = VecStorage<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Geometry {
|
|
||||||
pub size_x: f32,
|
|
||||||
pub size_y: f32,
|
|
||||||
pub rotation: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Geometry {
|
|
||||||
type Storage = VecStorage<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Textures {
|
|
||||||
pub textures: Vec<Arc<CanvasTextureHandle>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Textures {
|
|
||||||
type Storage = VecStorage<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Images {
|
|
||||||
pub images: Vec<Arc<CanvasImageHandle>>,
|
|
||||||
pub image_resolutions: Vec<(u32, u32)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Images {
|
|
||||||
type Storage = VecStorage<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct RenderSystem;
|
|
||||||
|
|
||||||
impl<'a> System<'a> for RenderSystem {
|
|
||||||
type SystemData = (
|
|
||||||
WriteStorage<'a, Position>,
|
|
||||||
WriteStorage<'a, Geometry>,
|
|
||||||
WriteStorage<'a, Textures>,
|
|
||||||
WriteStorage<'a, Images>,
|
|
||||||
Write<'a, PersistentState>, // delta_time, window size, etc.
|
|
||||||
Write<'a, VkProcessor>, // Renderer
|
|
||||||
);
|
|
||||||
|
|
||||||
fn run(&mut self, (
|
|
||||||
mut pos_list,
|
|
||||||
mut geom_list,
|
|
||||||
mut textures_list,
|
|
||||||
mut images_list,
|
|
||||||
mut state,
|
|
||||||
mut vk_processor
|
|
||||||
): Self::SystemData) {
|
|
||||||
state.canvas_frame = CanvasFrame::new(state.window_size);
|
|
||||||
|
|
||||||
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
||||||
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
||||||
|
|
||||||
for (position, geometry, textures) in (&mut pos_list, &mut geom_list, &mut textures_list).join() {
|
|
||||||
// geom.pos_x += mv.vel_x * state.delta_time;
|
|
||||||
// geom.pos_y += mv.vel_y * state.delta_time;
|
|
||||||
|
|
||||||
let window_size = state.window_size.clone();
|
|
||||||
let pos = (position.x, position.y);
|
|
||||||
let size = (geometry.size_x, geometry.size_y);
|
|
||||||
let normalized_depth = position.z as f32 / 255.0;
|
|
||||||
|
|
||||||
let textured_vertices = vec![
|
|
||||||
VertexTypeContainer::TextureType(
|
|
||||||
generate_textured_verts(window_size, pos, size, normalized_depth),
|
|
||||||
textures.textures.get(0).unwrap().clone(),
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
state.canvas_frame.add(textured_vertices);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (position, geometry, images) in (&mut pos_list, &mut geom_list, &mut images_list).join() {
|
|
||||||
// geom.pos_x += mv.vel_x * state.delta_time;
|
|
||||||
// geom.pos_y += mv.vel_y * state.delta_time;
|
|
||||||
|
|
||||||
let window_size = state.window_size.clone();
|
|
||||||
let pos = (position.x, position.y);
|
|
||||||
let size = (geometry.size_x, geometry.size_y);
|
|
||||||
let normalized_depth = position.z as f32 / 255.0;
|
|
||||||
|
|
||||||
let textured_vertices = vec![
|
|
||||||
VertexTypeContainer::ImageType(
|
|
||||||
generate_image_verts(window_size, pos, size, images.image_resolutions.get(0).unwrap().clone(), normalized_depth),
|
|
||||||
images.images.get(0).unwrap().clone(),
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
state.canvas_frame.add(textured_vertices);
|
|
||||||
}
|
|
||||||
|
|
||||||
let compu_frame = &state.compu_frame;
|
|
||||||
vk_processor.run(&state.surface.clone().unwrap(),
|
|
||||||
&state.canvas_frame,
|
|
||||||
compu_frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_image_verts(
|
|
||||||
window_size: (u32, u32),
|
|
||||||
position: (f32, f32),
|
|
||||||
size: (f32, f32),
|
|
||||||
image_size: (u32, u32),
|
|
||||||
depth: f32,
|
|
||||||
) -> Vec<ImageVertex3D> {
|
|
||||||
let image_size = (image_size.0 as f32, image_size.1 as f32);
|
|
||||||
|
|
||||||
// screen space position
|
|
||||||
let ss_position = (
|
|
||||||
position.0 / window_size.0 as f32 - 1.0,
|
|
||||||
position.1 / window_size.1 as f32 - 1.0
|
|
||||||
);
|
|
||||||
|
|
||||||
// screen space size
|
|
||||||
let ss_size = (
|
|
||||||
size.0 / window_size.0 as f32,
|
|
||||||
size.1 / window_size.1 as f32
|
|
||||||
);
|
|
||||||
|
|
||||||
// pub fn new(position: (f32, f32),
|
|
||||||
// size: (f32, f32),
|
|
||||||
// depth: u32,
|
|
||||||
// image_size: (f32, f32),
|
|
||||||
// image_handle: Arc<CanvasImageHandle>) -> CompuSprite {
|
|
||||||
|
|
||||||
vec![
|
|
||||||
ImageVertex3D {
|
|
||||||
v_position: [ss_position.0, ss_position.1, depth], // top left
|
|
||||||
ti_position: [-0.0, -0.0],
|
|
||||||
},
|
|
||||||
ImageVertex3D {
|
|
||||||
v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left
|
|
||||||
ti_position: [-0.0, image_size.1],
|
|
||||||
},
|
|
||||||
ImageVertex3D {
|
|
||||||
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
|
|
||||||
ti_position: [image_size.0, image_size.1],
|
|
||||||
},
|
|
||||||
ImageVertex3D {
|
|
||||||
v_position: [ss_position.0, ss_position.1, depth], // top left
|
|
||||||
ti_position: [-0.0, -0.0],
|
|
||||||
},
|
|
||||||
ImageVertex3D {
|
|
||||||
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
|
|
||||||
ti_position: [image_size.0, image_size.1],
|
|
||||||
},
|
|
||||||
ImageVertex3D {
|
|
||||||
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right
|
|
||||||
ti_position: [image_size.0, -0.0],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_textured_verts(
|
|
||||||
window_size: (u32, u32),
|
|
||||||
position: (f32, f32),
|
|
||||||
size: (f32, f32),
|
|
||||||
depth: f32,
|
|
||||||
) -> Vec<TextureVertex3D> {
|
|
||||||
let ss_position = (
|
|
||||||
position.0 / window_size.0 as f32 - 1.0,
|
|
||||||
position.1 / window_size.1 as f32 - 1.0
|
|
||||||
);
|
|
||||||
|
|
||||||
let ss_size = (
|
|
||||||
size.0 / window_size.0 as f32,
|
|
||||||
size.1 / window_size.1 as f32
|
|
||||||
);
|
|
||||||
|
|
||||||
vec![
|
|
||||||
TextureVertex3D {
|
|
||||||
v_position: [ss_position.0, ss_position.1, depth], // top left
|
|
||||||
ti_position: [-0.0, -0.0],
|
|
||||||
},
|
|
||||||
TextureVertex3D {
|
|
||||||
v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left
|
|
||||||
ti_position: [-0.0, 1.0],
|
|
||||||
},
|
|
||||||
TextureVertex3D {
|
|
||||||
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
|
|
||||||
ti_position: [1.0, 1.0],
|
|
||||||
},
|
|
||||||
TextureVertex3D {
|
|
||||||
v_position: [ss_position.0, ss_position.1, depth], // top left
|
|
||||||
ti_position: [-0.0, -0.0],
|
|
||||||
},
|
|
||||||
TextureVertex3D {
|
|
||||||
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
|
|
||||||
ti_position: [1.0, 1.0],
|
|
||||||
},
|
|
||||||
TextureVertex3D {
|
|
||||||
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right
|
|
||||||
ti_position: [1.0, -0.0],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,214 +1,25 @@
|
|||||||
use winit::window::{WindowId, Theme};
|
use winit::window::WindowId;
|
||||||
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch, StartCause, Event};
|
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use winit::dpi::{PhysicalPosition, PhysicalSize};
|
use winit::dpi::{PhysicalPosition, PhysicalSize};
|
||||||
use gilrs::Event as GilEvent;
|
use gilrs::Event as GilEvent;
|
||||||
use vulkano::pipeline::shader::GeometryShaderExecutionMode::TrianglesWithAdjacency;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
pub enum TrEvent {
|
||||||
pub enum TrUIEvent<T> {
|
MouseFocusEvent {
|
||||||
UIEvent(T)
|
position : (f32, f32),
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum TrEventExtension {
|
|
||||||
|
|
||||||
/// Custom events here
|
|
||||||
MouseHeldEvent {},
|
|
||||||
KeyHeldEvent {},
|
|
||||||
GamepadEvent {
|
|
||||||
gil_event: GilEvent,
|
|
||||||
},
|
},
|
||||||
}
|
MouseClickEvent {
|
||||||
|
position : (f32, f32),
|
||||||
#[derive(Clone, Debug)]
|
button : MouseButton,
|
||||||
pub enum TrEvent<T> {
|
|
||||||
|
|
||||||
/// Custom events here
|
|
||||||
MouseHeldEvent {},
|
|
||||||
KeyHeldEvent {},
|
|
||||||
GamepadEvent {
|
|
||||||
gil_event: GilEvent,
|
|
||||||
},
|
},
|
||||||
|
MouseHeldEvent {
|
||||||
|
|
||||||
/// Winit events here
|
|
||||||
NewEvents(StartCause),
|
|
||||||
WindowEvent {
|
|
||||||
window_id: WindowId,
|
|
||||||
event: TrWindowEvent,
|
|
||||||
},
|
},
|
||||||
DeviceEvent {
|
KeyHeldEvent {
|
||||||
device_id: DeviceId,
|
|
||||||
event: DeviceEvent,
|
|
||||||
},
|
|
||||||
UserEvent(T),
|
|
||||||
Suspended,
|
|
||||||
Resumed,
|
|
||||||
MainEventsCleared,
|
|
||||||
RedrawRequested(WindowId),
|
|
||||||
RedrawEventsCleared,
|
|
||||||
LoopDestroyed,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
},
|
||||||
|
GamepadEvent {
|
||||||
|
gil_event: GilEvent,
|
||||||
|
|
||||||
impl<T> From<Event<'_, T>> for TrEvent<T> {
|
|
||||||
fn from(event: Event<T>) -> Self {
|
|
||||||
match event {
|
|
||||||
Event::NewEvents(cause) => {
|
|
||||||
TrEvent::NewEvents(cause)
|
|
||||||
},
|
|
||||||
Event::WindowEvent { window_id: window_id, event: event } => {
|
|
||||||
TrEvent::WindowEvent {
|
|
||||||
window_id: window_id,
|
|
||||||
event: match event {
|
|
||||||
WindowEvent::AxisMotion { device_id, axis, value } => {
|
|
||||||
TrWindowEvent::AxisMotion { device_id, axis, value }
|
|
||||||
},
|
|
||||||
WindowEvent::Resized(physical_size) => {
|
|
||||||
TrWindowEvent::Resized(physical_size)
|
|
||||||
}
|
|
||||||
WindowEvent::Moved(physical_position) => {
|
|
||||||
TrWindowEvent::Moved(physical_position)
|
|
||||||
}
|
|
||||||
WindowEvent::CloseRequested => {
|
|
||||||
TrWindowEvent::CloseRequested
|
|
||||||
}
|
|
||||||
WindowEvent::Destroyed => {
|
|
||||||
TrWindowEvent::Destroyed
|
|
||||||
}
|
|
||||||
WindowEvent::DroppedFile(path_buf) => {
|
|
||||||
TrWindowEvent::DroppedFile(path_buf)
|
|
||||||
}
|
|
||||||
WindowEvent::HoveredFile(path_buf) => {
|
|
||||||
TrWindowEvent::HoveredFile(path_buf)
|
|
||||||
}
|
|
||||||
WindowEvent::HoveredFileCancelled => {
|
|
||||||
TrWindowEvent::HoveredFileCancelled
|
|
||||||
}
|
|
||||||
WindowEvent::ReceivedCharacter(char) => {
|
|
||||||
TrWindowEvent::ReceivedCharacter(char)
|
|
||||||
}
|
|
||||||
WindowEvent::Focused(bool) => {
|
|
||||||
TrWindowEvent::Focused(bool)
|
|
||||||
}
|
|
||||||
WindowEvent::KeyboardInput { device_id: device_id, input: input, is_synthetic: is_synthetic } => {
|
|
||||||
TrWindowEvent::KeyboardInput { device_id, input, is_synthetic }
|
|
||||||
}
|
|
||||||
WindowEvent::ModifiersChanged(modifiers_state) => {
|
|
||||||
TrWindowEvent::ModifiersChanged(modifiers_state)
|
|
||||||
}
|
|
||||||
WindowEvent::CursorMoved { device_id: device_id, position: position, modifiers: modifiers } => {
|
|
||||||
TrWindowEvent::CursorMoved { device_id, position, modifiers }
|
|
||||||
}
|
|
||||||
WindowEvent::CursorEntered { device_id: device_id } => {
|
|
||||||
TrWindowEvent::CursorEntered { device_id }
|
|
||||||
}
|
|
||||||
WindowEvent::CursorLeft { device_id: device_id } => {
|
|
||||||
TrWindowEvent::CursorLeft { device_id }
|
|
||||||
}
|
|
||||||
WindowEvent::MouseWheel { device_id: device_id, delta: delta, phase: phase, modifiers: modifiers } => {
|
|
||||||
TrWindowEvent::MouseWheel { device_id, delta, phase, modifiers }
|
|
||||||
}
|
|
||||||
WindowEvent::MouseInput { device_id: device_id, state: state, button: button, modifiers: modifiers } => {
|
|
||||||
TrWindowEvent::MouseInput { device_id, state, button, modifiers }
|
|
||||||
}
|
|
||||||
WindowEvent::TouchpadPressure { device_id: device_id, pressure: pressure, stage: stage } => {
|
|
||||||
TrWindowEvent::TouchpadPressure { device_id, pressure, stage }
|
|
||||||
}
|
|
||||||
WindowEvent::Touch(touch) => {
|
|
||||||
TrWindowEvent::Touch(touch)
|
|
||||||
}
|
|
||||||
WindowEvent::ScaleFactorChanged { scale_factor: scale_factor, new_inner_size: new_inner_size } => {
|
|
||||||
TrWindowEvent::ScaleFactorChanged { scale_factor, new_inner_size: PhysicalSize { width: new_inner_size.width, height: new_inner_size.height } }
|
|
||||||
}
|
|
||||||
WindowEvent::ThemeChanged(theme) => {
|
|
||||||
TrWindowEvent::ThemeChanged(theme)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::DeviceEvent { device_id: device_id, event: event } => {
|
|
||||||
TrEvent::DeviceEvent { device_id, event }
|
|
||||||
}
|
|
||||||
Event::UserEvent(user_event) => {
|
|
||||||
TrEvent::UserEvent(user_event)
|
|
||||||
}
|
|
||||||
Event::Suspended => {
|
|
||||||
TrEvent::Suspended
|
|
||||||
}
|
|
||||||
Event::Resumed => {
|
|
||||||
TrEvent::Resumed
|
|
||||||
}
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
TrEvent::MainEventsCleared
|
|
||||||
}
|
|
||||||
Event::RedrawRequested(window_id) => {
|
|
||||||
TrEvent::RedrawRequested(window_id)
|
|
||||||
}
|
|
||||||
Event::RedrawEventsCleared => {
|
|
||||||
TrEvent::RedrawEventsCleared
|
|
||||||
}
|
|
||||||
Event::LoopDestroyed => {
|
|
||||||
TrEvent::LoopDestroyed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
|
||||||
pub enum TrWindowEvent {
|
|
||||||
|
|
||||||
Resized(PhysicalSize<u32>),
|
|
||||||
Moved(PhysicalPosition<i32>),
|
|
||||||
CloseRequested,
|
|
||||||
Destroyed,
|
|
||||||
DroppedFile(PathBuf),
|
|
||||||
HoveredFile(PathBuf),
|
|
||||||
HoveredFileCancelled,
|
|
||||||
ReceivedCharacter(char),
|
|
||||||
Focused(bool),
|
|
||||||
KeyboardInput {
|
|
||||||
device_id: DeviceId,
|
|
||||||
input: KeyboardInput,
|
|
||||||
is_synthetic: bool,
|
|
||||||
},
|
|
||||||
ModifiersChanged(ModifiersState),
|
|
||||||
CursorMoved {
|
|
||||||
device_id: DeviceId,
|
|
||||||
position: PhysicalPosition<f64>,
|
|
||||||
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
|
||||||
modifiers: ModifiersState,
|
|
||||||
},
|
|
||||||
CursorEntered { device_id: DeviceId },
|
|
||||||
CursorLeft { device_id: DeviceId },
|
|
||||||
MouseWheel {
|
|
||||||
device_id: DeviceId,
|
|
||||||
delta: MouseScrollDelta,
|
|
||||||
phase: TouchPhase,
|
|
||||||
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
|
||||||
modifiers: ModifiersState,
|
|
||||||
},
|
|
||||||
MouseInput {
|
|
||||||
device_id: DeviceId,
|
|
||||||
state: ElementState,
|
|
||||||
button: MouseButton,
|
|
||||||
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
|
||||||
modifiers: ModifiersState,
|
|
||||||
},
|
|
||||||
TouchpadPressure {
|
|
||||||
device_id: DeviceId,
|
|
||||||
pressure: f32,
|
|
||||||
stage: i64,
|
|
||||||
},
|
|
||||||
AxisMotion {
|
|
||||||
device_id: DeviceId,
|
|
||||||
axis: AxisId,
|
|
||||||
value: f64,
|
|
||||||
},
|
|
||||||
Touch(Touch),
|
|
||||||
ScaleFactorChanged {
|
|
||||||
scale_factor: f64,
|
|
||||||
new_inner_size: PhysicalSize<u32>,
|
|
||||||
},
|
|
||||||
ThemeChanged(Theme),
|
|
||||||
}
|
|
Loading…
Reference in new issue