moved to rust style file tree

master
mitchellhansen 5 years ago
parent fa2c9397bf
commit 34c23eebc0

@ -1,13 +1,13 @@
use crate::canvas::{CanvasTextureHandle, CanvasImageHandle};
use crate::canvas::canvas_state::{CanvasTextureHandle, CanvasImageHandle};
use vulkano::image::{ImmutableImage, AttachmentImage};
use std::sync::Arc;
use vulkano::format::{Format, R8Unorm};
use crate::canvas_shader::CanvasShader;
use crate::canvas::canvas_shader::CanvasShader;
use vulkano::sampler::Sampler;
use vulkano::descriptor::DescriptorSet;
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use vulkano::buffer::CpuAccessibleBuffer;
use crate::canvas_text::{CanvasTextCacheHandle, CanvasTextHandle};
use crate::canvas::canvas_text::{CanvasTextCacheHandle, CanvasTextHandle};
#[derive(Clone)]
pub struct CanvasTexture {

@ -1,7 +1,7 @@
use crate::vertex_3d::{Vertex3D};
use crate::util::vertex_3d::{Vertex3D};
use std::sync::Arc;
use std::collections::HashMap;
use crate::canvas::{Drawable, CanvasTextureHandle, CanvasImageHandle};
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle};
///
pub struct CanvasFrame {

@ -8,9 +8,8 @@ use shade_runner as sr;
use vulkano::framebuffer::{Subpass, RenderPassAbstract, Framebuffer, FramebufferAbstract};
use vulkano::pipeline::shader::{GraphicsShaderType, ShaderModule, SpecializationConstants, SpecializationMapEntry};
use vulkano::swapchain::Capabilities;
use crate::vertex_2d::Vertex2D;
use vulkano::pipeline::vertex::SingleBufferDefinition;
use crate::vertex_3d::Vertex3D;
use crate::util::vertex_3d::Vertex3D;
use vulkano::pipeline::depth_stencil::{DepthStencil, Stencil, StencilOp, Compare, DepthBounds};
use std::collections::HashSet;
@ -21,30 +20,30 @@ pub struct CompiledGraphicsPipelineHandle {
}
pub trait CompiledGraphicsPipeline {
fn get_paths(&self, filename: String) -> Vec<(ShaderType, PathBuf)> {
let project_root =
std::env::current_dir()
.expect("failed to get root directory");
let mut shader_path = project_root.clone();
shader_path.push(PathBuf::from("resources/shaders/"));
let mut vertex_shader_path = shader_path.clone();
vertex_shader_path.push(PathBuf::from("resources/shaders/"));
vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
let mut fragment_shader_path = project_root.clone();
fragment_shader_path.push(PathBuf::from("resources/shaders/"));
fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
(vertex_shader_path, fragment_shader_path)
}
fn new(filename: String, shaders: HashSet<ShaderType>) -> Box<dyn CompiledGraphicsPipeline>;
// fn get_paths(&self, filename: String) -> Vec<(ShaderType, PathBuf)> {
//
// let project_root =
// std::env::current_dir()
// .expect("failed to get root directory");
//
// let mut shader_path = project_root.clone();
// shader_path.push(PathBuf::from("resources/shaders/"));
//
//
//
// let mut vertex_shader_path = shader_path.clone();
// vertex_shader_path.push(PathBuf::from("resources/shaders/"));
// vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
//
// let mut fragment_shader_path = project_root.clone();
// fragment_shader_path.push(PathBuf::from("resources/shaders/"));
// fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
//
// (vertex_shader_path, fragment_shader_path)
// }
fn new(filename: String, shaders: HashSet<ShaderType>) -> Self;
fn get_name() -> String;
fn get_handle() -> Arc<AbstractCompiledPipelineHandle>;
fn get_handle() -> Arc<CompiledGraphicsPipelineHandle>;
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
fn recompile();
}
@ -78,38 +77,38 @@ pub struct CanvasShader {
impl CompiledGraphicsPipeline for CanvasShader {
fn get_path(filename: String) -> (PathBuf, PathBuf) {
let project_root =
std::env::current_dir()
.expect("failed to get root directory");
let mut shader_path = project_root.clone();
shader_path.push(PathBuf::from("resources/shaders/"));
let mut vertex_shader_path = project_root.clone();
vertex_shader_path.push(PathBuf::from("resources/shaders/"));
vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
let mut fragment_shader_path = project_root.clone();
fragment_shader_path.push(PathBuf::from("resources/shaders/"));
fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
(vertex_shader_path, fragment_shader_path)
}
fn new(filename: String, shaders: HashSet<ShaderType>) -> Box<dyn CompiledGraphicsPipeline> {
// fn get_path(filename: String) -> (PathBuf, PathBuf) {
// let project_root =
// std::env::current_dir()
// .expect("failed to get root directory");
//
// let mut shader_path = project_root.clone();
// shader_path.push(PathBuf::from("resources/shaders/"));
//
// let mut vertex_shader_path = project_root.clone();
// vertex_shader_path.push(PathBuf::from("resources/shaders/"));
// vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
//
// let mut fragment_shader_path = project_root.clone();
// fragment_shader_path.push(PathBuf::from("resources/shaders/"));
// fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
//
// (vertex_shader_path, fragment_shader_path)
// }
fn new(filename: String, shaders: HashSet<ShaderType>) -> Self {
unimplemented!()
}
fn get_name() -> String {
unimplemented!()
}
fn get_handle() -> Arc<_> {
fn get_handle() -> Arc<CompiledGraphicsPipelineHandle> {
unimplemented!()
}
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract> {
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {
unimplemented!()
}
@ -120,6 +119,24 @@ impl CompiledGraphicsPipeline for CanvasShader {
impl CanvasShader {
fn get_path(filename: String) -> (PathBuf, PathBuf) {
let project_root =
std::env::current_dir()
.expect("failed to get root directory");
let mut shader_path = project_root.clone();
shader_path.push(PathBuf::from("resources/shaders/"));
let mut vertex_shader_path = project_root.clone();
vertex_shader_path.push(PathBuf::from("resources/shaders/"));
vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
let mut fragment_shader_path = project_root.clone();
fragment_shader_path.push(PathBuf::from("resources/shaders/"));
fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
(vertex_shader_path, fragment_shader_path)
}
/// Clone and returns the compiled graphics pipeline
pub fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {

@ -18,12 +18,12 @@ use vulkano::swapchain::Capabilities;
use winit::Window;
use vulkano::pipeline::viewport::Viewport;
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
use crate::canvas_frame::CanvasFrame;
use crate::canvas::canvas_frame::CanvasFrame;
use std::hash::Hash;
use crate::canvas_text::{CanvasText, CanvasTextHandle};
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
use crate::vertex_3d::Vertex3D;
use crate::canvas::canvas_text::{CanvasText, CanvasTextHandle};
use crate::canvas::canvas_shader::{CanvasShader, CanvasShaderHandle};
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
use crate::util::vertex_3d::Vertex3D;
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
/// A drawable object can be passed into a CanvasFrame to be rendered

@ -7,7 +7,6 @@ use std::sync::Arc;
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
use vulkano::image::{ImmutableImage, ImageUsage, ImageLayout, Dimensions};
use vulkano::format::ClearValue;
use crate::vertex_2d::Vertex2D;
use vulkano::format::Format::R8Unorm;
const CACHE_WIDTH: usize = 1000;
@ -43,8 +42,7 @@ impl CanvasText {
let cache = Cache::builder().dimensions(CACHE_WIDTH as u32, CACHE_HEIGHT as u32).build();
let cache_pixel_buffer = vec!(0; CACHE_WIDTH * CACHE_HEIGHT);
let font_data = include_bytes!("../resources/fonts/sansation.ttf");
let font_data = include_bytes!("../../resources/fonts/sansation.ttf");
let font = Font::from_bytes(font_data as &[u8]).unwrap();
CanvasText {

@ -0,0 +1,9 @@
pub mod canvas_state;
pub mod canvas_frame;
pub mod canvas_shader;
pub mod canvas_text;
pub mod canvas_buffer;
use crate::canvas::canvas_frame::CanvasFrame;

@ -1,8 +1,8 @@
use crate::canvas::{CanvasImageHandle, Drawable};
use crate::canvas::canvas_state::{CanvasImageHandle, Drawable};
use std::sync::Arc;
use crate::compu_sprite::CompuSprite;
use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
use crate::compute::compu_sprite::CompuSprite;
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
pub struct CompuFrame {
// Vec<(Buffer, Kernel)>

@ -8,7 +8,7 @@ use vulkano::descriptor::pipeline_layout::PipelineLayout;
use shade_runner::{CompileError, FragLayout, FragInput, FragOutput, VertInput, VertOutput, VertLayout, CompiledShaders, Entry};
use shaderc::CompileOptions;
use vulkano::pipeline::shader::{ShaderModule, GraphicsEntryPoint, SpecializationConstants, SpecializationMapEntry};
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompuKernelHandle {

@ -1,4 +1,4 @@
use crate::canvas::{CanvasImageHandle, Drawable, CanvasTextureHandle};
use crate::canvas::canvas_state::{CanvasImageHandle, Drawable, CanvasTextureHandle};
use std::sync::Arc;
pub struct CompuSprite {

@ -1,7 +1,7 @@
use std::ffi::CStr;
use vulkano::buffer::{CpuAccessibleBuffer, BufferUsage};
use std::sync::Arc;
use crate::canvas::{Drawable, CanvasState, CanvasImageHandle, CanvasTextureHandle};
use crate::canvas::canvas_state::{Drawable, CanvasState, CanvasImageHandle, CanvasTextureHandle};
use vulkano::framebuffer::RenderPassAbstract;
use vulkano::pipeline::{GraphicsPipelineAbstract, ComputePipeline};
use vulkano::device::Device;
@ -18,9 +18,9 @@ use std::path::PathBuf;
use shade_runner::{CompiledShaders, Entry, CompileError};
use vulkano::pipeline::shader::ShaderModule;
use shaderc::CompileOptions;
use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
use crate::compu_frame::CompuFrame;
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
use crate::compute::compu_frame::CompuFrame;
// Canvas analog
@ -30,7 +30,6 @@ pub struct CompuState {
}
impl CompuState {
pub fn new() -> CompuState {
CompuState {
compute_buffers: vec![],
@ -43,7 +42,6 @@ impl CompuState {
dimensions: (u32, u32),
stride: u32,
device: Arc<Device>) -> Arc<CompuBufferHandle> {
let handle = Arc::new(CompuBufferHandle {
handle: self.compute_buffers.len() as u32
});
@ -65,7 +63,6 @@ impl CompuState {
pub fn new_kernel(&mut self,
filename: String,
device: Arc<Device>) -> Arc<CompuKernelHandle> {
let handle = Arc::new(CompuKernelHandle {
handle: self.kernels.len() as u32
});
@ -104,7 +101,7 @@ impl CompuState {
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], p, d, ()).unwrap()
}
// i = (Buffer, Image, Kernel)
@ -129,7 +126,7 @@ impl CompuState {
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], p, d, ()).unwrap()
.copy_buffer_to_image(buffer.get_input_buffer(), image).unwrap();
}

@ -0,0 +1,11 @@
pub mod compu_frame;
pub mod compu_kernel;
pub mod compu_sprite;
pub mod compu_state;
pub mod compu_buffer;
use crate::compute::compu_state::CompuState;
use crate::compute::compu_frame::CompuFrame;
use crate::compute::compu_sprite::CompuSprite;
use crate::compute::compu_kernel::CompuKernel;
use crate::compute::compu_buffer::CompuBuffers;

@ -1,44 +0,0 @@
use std::collections::HashSet;
pub struct Input {
held_keys: HashSet<Key>,
held_mouse: HashSet<u8>,
}
impl Input {
pub fn new() -> Input {
let mut key_container = HashSet::new();
let mut mouse_container = HashSet::new();
Input {
held_keys: key_container,
held_mouse: mouse_container,
}
}
pub fn is_held(&self, key: Key) -> bool {
self.held_keys.contains(&key)
}
pub fn is_mousebutton_held(&self, button: Button) -> bool {
self.held_mouse.contains(&(button as u8))
}
pub fn ingest(&mut self, event: &Event) {
match event {
Event::KeyPressed { code, .. } => {
self.held_keys.insert(code.clone());
}
Event::KeyReleased { code, .. } => {
self.held_keys.remove(code);
}
Event::MouseButtonPressed { button, x, y } => {
self.held_mouse.insert(button.clone() as u8);
},
Event::MouseButtonReleased { button, x, y } => {
self.held_mouse.remove(&(button.clone() as u8));
},
_ => {}
}
}
}

@ -2,6 +2,8 @@
#![allow(unused_variables)]
#![allow(unused_mut)]
extern crate cgmath;
extern crate image;
extern crate nalgebra as na;
@ -10,43 +12,30 @@ extern crate time;
extern crate hprof;
use vulkano::sync;
use crate::timer::Timer;
use crate::util::timer::Timer;
use vulkano::instance::Instance;
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::compu_state::CompuState;
use crate::compu_frame::CompuFrame;
use crate::compu_sprite::CompuSprite;
use crate::compu_kernel::CompuKernel;
use crate::compu_buffer::CompuBuffers;
use crate::util::load_raw;
use crate::canvas_frame::CanvasFrame;
use crate::sprite::Poly;
use vulkano::instance::debug::DebugCallback;
use crate::compute::compu_sprite::CompuSprite;
use crate::compute::compu_frame::CompuFrame;
use crate::canvas::canvas_frame::CanvasFrame;
pub mod util;
pub mod timer;
//pub mod input;
pub mod vkprocessor;
pub mod vertex_2d;
pub mod vertex_3d;
pub mod sprite;
pub mod canvas;
pub mod canvas_frame;
pub mod canvas_shader;
pub mod canvas_buffer;
pub mod canvas_text;
pub mod compu_state;
pub mod compu_frame;
pub mod compu_sprite;
pub mod compu_kernel;
pub mod compu_buffer;
pub mod compute;
/// Main Entry
pub fn main() {

@ -1,4 +1,4 @@
use crate::canvas::{Drawable, CanvasTextureHandle, CanvasImageHandle};
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle};
use std::sync::Arc;
#[derive(Debug, Clone)]

@ -3,6 +3,10 @@ use std::sync::Arc;
use std::ffi::CStr;
use std::path::PathBuf;
pub mod timer;
pub mod vertex_2d;
pub mod vertex_3d;
pub fn load_raw(filename: String) -> (Vec<u8>, (u32,u32)) {
let project_root =

@ -0,0 +1,10 @@
/// Generic vertex 2d with vertex position, texture position and a 32bit color
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex2D {
pub v_position: [f32; 2],
pub color : [f32; 4],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(Vertex2D, v_position, color, ti_position);

@ -1,4 +1,5 @@
/// Generic vertex 3d with vertex position, texture position and a 32bit color
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex3D {
pub v_position: [f32; 3],

@ -1,33 +0,0 @@
/// Generic vertex 2d with vertex position, texture position and a 32bit color
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex2D {
pub v_position: [f32; 2],
pub color : [f32; 4],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(Vertex2D, v_position, color, ti_position);
//impl From<(f32, f32)> for Vertex2D {
// fn from(item: (f32, f32)) -> Self {
// Vertex2D {
// v_position: [],
// color: [],
// ti_position: []
// }
// }
//}
//
//impl From<((f32,f32),(f32, f32))> for Vertex2D {
// fn from(item: ((f32,f32),(f32, f32))) -> Self {
// Vertex2D {
// v_position: [],
// color: [],
// ti_position: []
// }
// }
//}

@ -8,15 +8,15 @@ use std::sync::Arc;
use vulkano::swapchain::{Swapchain, PresentMode, SurfaceTransform, Surface, SwapchainCreationError, AcquireError, Capabilities};
use vulkano::image::swapchain::SwapchainImage;
use winit::Window;
use crate::compu_state::CompuState;
use crate::compute::compu_state::CompuState;
use vulkano::image::ImageUsage;
use crate::compu_frame::CompuFrame;
use crate::canvas::{CanvasState, CanvasTextureHandle, CanvasImageHandle, ShaderType};
use crate::canvas_frame::CanvasFrame;
use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
use crate::compute::compu_frame::CompuFrame;
use crate::canvas::canvas_state::{CanvasState, CanvasTextureHandle, CanvasImageHandle, ShaderType};
use crate::canvas::canvas_frame::CanvasFrame;
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
use std::time::Duration;
use crate::canvas_shader::CanvasShaderHandle;
use crate::canvas::canvas_shader::CanvasShaderHandle;
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
/// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states

Loading…
Cancel
Save