Skip to content

Commit

Permalink
Merge pull request #121 from Snowiiii/vent_window
Browse files Browse the repository at this point in the history
Replace winit -> Vent window
  • Loading branch information
Snowiiii authored May 22, 2024
2 parents f7233c2 + 8d59b27 commit d30f8db
Show file tree
Hide file tree
Showing 28 changed files with 1,117 additions and 776 deletions.
721 changes: 119 additions & 602 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/vent-assets/src/model/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ash::{
util::read_spv,
vk::{self},
};
use gltf::{material::AlphaMode, mesh::{Mode}, texture::Sampler};
use gltf::{material::AlphaMode, mesh::Mode, texture::Sampler};
use image::DynamicImage;
use vent_rendering::{
image::VulkanImage, instance::VulkanInstance, MaterialPipelineInfo, Vertex, Vertex3D,
Expand Down
2 changes: 0 additions & 2 deletions crates/vent-assets/src/model/optimizer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


use vent_rendering::Vertex3D;

pub fn optimize_vertices(mut vertices: Vec<Vertex3D>) -> Vec<Vertex3D> {
Expand Down
1 change: 0 additions & 1 deletion crates/vent-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
winit = "0.30"
sysinfo = "0.30"
chrono = "0.4"

Expand Down
1 change: 0 additions & 1 deletion crates/vent-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod project;
pub mod util;
pub mod window;
31 changes: 0 additions & 31 deletions crates/vent-common/src/window.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/vent-ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
winit = { version = "0.30", default-features = false }
[dependencies]
4 changes: 1 addition & 3 deletions crates/vent-ecs/src/component/input_component.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use winit::{event::ElementState, keyboard};

pub trait InputComponent {
fn process_keyboard(&mut self, key: keyboard::Key, state: ElementState);
// fn process_keyboard(&mut self, key: keyboard::Key, state: ElementState);

fn process_mouse_motion(&mut self, mouse_dx: f64, mouse_dy: f64);
}
1 change: 0 additions & 1 deletion crates/vent-editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ash = { version= "0.38", default-features = false, features = ["linked", "debug"
egui = "0.27"
egui_dock = "0.12"

winit = "0.30"
pollster = "0.3.0"

log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion crates/vent-rendering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
vent-window = { path= "../vent-window"}
ash = { version= "0.38", default-features = false, features = ["linked", "debug", "std"] }
spirv = "0.3.0"

image = "0.25"

winit = "0.30"
raw-window-handle = "0.6"
log = "0.4"

Expand Down
21 changes: 13 additions & 8 deletions crates/vent-rendering/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ash::prelude::VkResult;
use ash::vk::{Extent2D, PushConstantRange, SwapchainKHR};
use ash::{khr, vk, Entry};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use winit::dpi::PhysicalSize;

use std::{default::Default, ffi::CStr};

Expand Down Expand Up @@ -70,7 +69,7 @@ pub struct VulkanInstance {
}

impl VulkanInstance {
pub fn new(application_name: &str, window: &winit::window::Window) -> Self {
pub fn new(application_name: &str, window: &vent_window::Window) -> Self {
let entry = Entry::linked();

let engine_version: u32 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap();
Expand Down Expand Up @@ -162,7 +161,10 @@ impl VulkanInstance {
&surface_loader,
pdevice,
surface,
window.inner_size(),
(
window.width().try_into().unwrap(),
window.height().try_into().unwrap(),
),
None,
);

Expand Down Expand Up @@ -257,7 +259,7 @@ impl VulkanInstance {
}
}

pub fn recreate_swap_chain(&mut self, new_size: &PhysicalSize<u32>) {
pub fn recreate_swap_chain(&mut self, new_size: (u32, u32)) {
unsafe {
self.device.device_wait_idle().unwrap();

Expand All @@ -267,7 +269,7 @@ impl VulkanInstance {
&self.surface_loader,
self.physical_device,
self.surface,
*new_size,
new_size,
Some(self.swapchain),
);
// We reuse the old Swapchain and then deleting it
Expand Down Expand Up @@ -504,7 +506,7 @@ impl VulkanInstance {
surface_loader: &khr::surface::Instance,
pdevice: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
size: winit::dpi::PhysicalSize<u32>,
size: (u32, u32),
old_swapchain: Option<vk::SwapchainKHR>,
) -> (vk::SwapchainKHR, Extent2D) {
let surface_capabilities =
Expand All @@ -517,13 +519,16 @@ impl VulkanInstance {
desired_image_count = surface_capabilities.max_image_count;
}

let width = size.0;
let height = size.1;

let surface_resolution = match surface_capabilities.current_extent.width {
std::u32::MAX => vk::Extent2D {
width: size.width.clamp(
width: width.clamp(
surface_capabilities.min_image_extent.width,
surface_capabilities.max_image_extent.width,
),
height: size.height.clamp(
height: height.clamp(
surface_capabilities.min_image_extent.height,
surface_capabilities.max_image_extent.height,
),
Expand Down
4 changes: 1 addition & 3 deletions crates/vent-rendering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::{
mem::{self, offset_of},
};
use std::mem::{self, offset_of};

use ash::vk;

Expand Down
10 changes: 4 additions & 6 deletions crates/vent-rendering/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ash::{util::read_spv, vk};

use crate::instance::VulkanInstance;


///
/// Creates an Simple Pipeline from an Vertex & Fragment Shader
///
Expand Down Expand Up @@ -57,7 +56,6 @@ pub fn create_simple_pipeline(
..Default::default()
},
];


let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::default()
.vertex_attribute_descriptions(attrib_desc)
Expand Down Expand Up @@ -139,10 +137,12 @@ pub fn create_simple_pipeline(
}

fn conv_shader_stage(model: spirv::ExecutionModel) -> vk::ShaderStageFlags {
match model {
match model {
spirv::ExecutionModel::Vertex => vk::ShaderStageFlags::VERTEX,
spirv::ExecutionModel::TessellationControl => vk::ShaderStageFlags::TESSELLATION_CONTROL,
spirv::ExecutionModel::TessellationEvaluation => vk::ShaderStageFlags::TESSELLATION_EVALUATION,
spirv::ExecutionModel::TessellationEvaluation => {
vk::ShaderStageFlags::TESSELLATION_EVALUATION
}
spirv::ExecutionModel::Geometry => vk::ShaderStageFlags::GEOMETRY,
spirv::ExecutionModel::Fragment => vk::ShaderStageFlags::FRAGMENT,
spirv::ExecutionModel::GLCompute => vk::ShaderStageFlags::COMPUTE,
Expand All @@ -159,5 +159,3 @@ fn conv_shader_stage(model: spirv::ExecutionModel) -> vk::ShaderStageFlags {
spirv::ExecutionModel::MeshEXT => vk::ShaderStageFlags::MESH_EXT,
}
}


2 changes: 1 addition & 1 deletion crates/vent-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ vent-common = { path = "../vent-common"}
vent-rendering = { path = "../vent-rendering"}
vent-assets = { path = "../vent-assets" }
vent-ecs = { path = "../vent-ecs"}
vent-window = { path = "../vent-window"}

ash = { version= "0.38", default-features = false, features = ["linked", "debug"] }

winit = "0.30"
pollster = "0.3.0"
log = "0.4"

Expand Down
132 changes: 69 additions & 63 deletions crates/vent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::process::exit;

use crate::render::Dimension;

use render::camera::camera_controller3d::CameraController3D;
use render::DefaultRuntimeRenderer;
use simple_logger::SimpleLogger;
use vent_common::project::VentApplicationProject;

use vent_common::util::crash::init_panic_hook;
use vent_common::window::VentWindow;
use winit::{event::{DeviceEvent, Event, WindowEvent}, window::WindowAttributes};
use vent_window::{EventLoop, Window, WindowAttribs, WindowEvent};

pub mod render;

Expand Down Expand Up @@ -39,70 +39,76 @@ impl VentApplication {
}

pub fn start(self) {
let window_builder = WindowAttributes::default().with_title(self.project.name);
let vent_window = VentWindow::new(window_builder);
let window_size = (800, 600);
let mut event_loop = EventLoop::new();
let attribs = WindowAttribs::default().with_title(self.project.name);
let vent_window = Window::new(attribs);

// TODO
let mut renderer = DefaultRuntimeRenderer::new(
Dimension::D3,
&vent_window.window,
);
let mut renderer = DefaultRuntimeRenderer::new(Dimension::D3, &vent_window);

let mut controller = CameraController3D::new(1000.0, 10.0);
// let mut controller = CameraController3D::new(1000.0, 10.0);
let mut delta_time = 0.0;

vent_window
.event_loop
.run(move |event, elwt| {
match event {
Event::WindowEvent {
ref event,
window_id: _,
} => {
renderer.progress_event(event);

match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::MouseInput { button, state, .. } => {
controller.process_mouse_input(&vent_window.window, button, state);
}
WindowEvent::KeyboardInput { event, .. } => {
controller.process_keyboard(
renderer.camera.downcast_mut().expect("TODO"),
event,
delta_time,
);
}
WindowEvent::Resized(physical_size) => {
renderer.resize(physical_size);
}
// WindowEvent::ScaleFactorChanged {
// inner_size_writer, ..
// } => {
// // new_inner_size is &mut so w have to dereference it twice
// renderer.resize(new_inner_size, &mut cam);
// }
WindowEvent::RedrawRequested => {
delta_time = renderer.render(&vent_window.window);
}
_ => {}
}
}
Event::AboutToWait {} => vent_window.window.request_redraw(),
Event::DeviceEvent {
event: DeviceEvent::MouseMotion { delta },
..
} => controller.process_mouse_movement(
renderer.camera.downcast_mut().expect("TODO"),
delta.0,
delta.1,
delta_time,
),

// ...
_ => {}
}
})
.expect("Window Event Loop Error");
event_loop.add_window(vent_window);

event_loop.poll(move |event| {
if event == WindowEvent::Draw {
delta_time = renderer.render(window_size); // Default
} else if event == WindowEvent::Close {
exit(0) // maybe not so pretty
}
});

// match event {
// Event::WindowEvent {
// ref event,
// window_id: _,
// } => {
// renderer.progress_event(event);

// match event {
// WindowEvent::CloseRequested => elwt.exit(),
// WindowEvent::MouseInput { button, state, .. } => {
// controller.process_mouse_input(&vent_window.window, button, state);
// }
// WindowEvent::KeyboardInput { event, .. } => {
// controller.process_keyboard(
// renderer.camera.downcast_mut().expect("TODO"),
// event,
// delta_time,
// );
// }
// WindowEvent::Resized(physical_size) => {
// renderer.resize(physical_size);
// }
// // WindowEvent::ScaleFactorChanged {
// // inner_size_writer, ..
// // } => {
// // // new_inner_size is &mut so w have to dereference it twice
// // renderer.resize(new_inner_size, &mut cam);
// // }
// WindowEvent::RedrawRequested => {
// delta_time = renderer.render(&vent_window.window);
// }
// _ => {}
// }
// }
// Event::AboutToWait {} => vent_window.window.request_redraw(),
// Event::DeviceEvent {
// event: DeviceEvent::MouseMotion { delta },
// ..
// } => controller.process_mouse_movement(
// renderer.camera.downcast_mut().expect("TODO"),
// delta.0,
// delta.1,
// delta_time,
// ),

// // ...
// _ => {}
// }
// })
// .expect("Window Event Loop Error");
}
}
Loading

0 comments on commit d30f8db

Please sign in to comment.