First vulkan init working
This commit is contained in:
parent
6639f0bb1e
commit
99be029ff8
4 changed files with 36 additions and 28 deletions
|
@ -1,7 +1,9 @@
|
|||
use vulkan_context::VulkanContext;
|
||||
use window_render_context::WindowRenderContext;
|
||||
|
||||
use bevy_app::App;
|
||||
use bevy_app::{App, Plugin};
|
||||
|
||||
use super::window::raw_handle::WindowWrapper;
|
||||
|
||||
mod utils;
|
||||
mod vulkan_context;
|
||||
|
@ -13,16 +15,20 @@ pub enum VulkanError {
|
|||
FailedToCreateVulkanContext,
|
||||
}
|
||||
|
||||
pub struct Vulkan;
|
||||
pub struct VulkanPlugin;
|
||||
|
||||
impl Vulkan {
|
||||
pub fn new(app: &mut App) -> Result<(), VulkanError> {
|
||||
impl Plugin for VulkanPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
let vulkan_context = VulkanContext::from(app as &App);
|
||||
app.world_mut().insert_resource(vulkan_context);
|
||||
}
|
||||
|
||||
fn ready(&self, app: &App) -> bool {
|
||||
app.world().get_resource::<WindowWrapper>().is_some()
|
||||
}
|
||||
|
||||
fn finish(&self, app: &mut App) {
|
||||
let window_render_context = WindowRenderContext::from(app as &App);
|
||||
app.world_mut().insert_resource(window_render_context);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use bevy_app::{App, AppExit, PluginsState};
|
||||
use bevy_app::{App, AppExit, Plugin, PluginsState};
|
||||
use config::WindowConfig;
|
||||
use raw_handle::{DisplayHandleWrapper, EventLoopProxyWrapper};
|
||||
use state::WindowState;
|
||||
|
@ -14,23 +14,24 @@ pub enum WindowError {
|
|||
FailedToCreateEventLoop,
|
||||
}
|
||||
|
||||
pub struct Window;
|
||||
pub struct WindowPlugin {
|
||||
pub window_config: WindowConfig,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(app: &mut App, window_config: WindowConfig) -> Result<(), WindowError> {
|
||||
impl Plugin for WindowPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
let world = app.world_mut();
|
||||
world.insert_resource(window_config);
|
||||
world.insert_resource(self.window_config.clone());
|
||||
|
||||
let mut event_loop_builder = EventLoop::with_user_event();
|
||||
let event_loop = event_loop_builder
|
||||
.build()
|
||||
.map_err(|_| WindowError::FailedToCreateEventLoop)?;
|
||||
.map_err(|_| WindowError::FailedToCreateEventLoop)
|
||||
.expect("Failed to create event loop");
|
||||
|
||||
world.insert_resource(DisplayHandleWrapper(event_loop.owned_display_handle()));
|
||||
|
||||
app.set_runner(Box::new(move |app| runner(app, event_loop)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use bevy_app::{App, PluginsState};
|
||||
use bevy_ecs::{event, world::World};
|
||||
use bevy_ecs::world::World;
|
||||
use winit::{
|
||||
application::ApplicationHandler, event::WindowEvent, event_loop::ActiveEventLoop,
|
||||
window::WindowId,
|
||||
};
|
||||
|
||||
use super::{
|
||||
config::WindowConfig,
|
||||
raw_handle::{DisplayHandleWrapper, WindowWrapper},
|
||||
};
|
||||
use super::{config::WindowConfig, raw_handle::WindowWrapper};
|
||||
|
||||
pub struct WindowState {
|
||||
app: App,
|
||||
|
@ -54,14 +51,14 @@ impl ApplicationHandler for WindowState {
|
|||
if self.app.plugins_state() == PluginsState::Cleaned {
|
||||
self.app.update();
|
||||
}
|
||||
|
||||
let window_wrapper = self.app.world().get_resource::<WindowWrapper>().unwrap();
|
||||
|
||||
window_wrapper.0.request_redraw();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
let window_wrapper = self.app.world().get_resource::<WindowWrapper>().unwrap();
|
||||
|
||||
window_wrapper.0.request_redraw();
|
||||
}
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use bevy_app::App;
|
||||
|
||||
use crate::core::{
|
||||
vulkan::Vulkan,
|
||||
window::{Window, config::WindowConfig},
|
||||
vulkan,
|
||||
window::{self, config::WindowConfig},
|
||||
};
|
||||
|
||||
pub mod test_plugin;
|
||||
|
@ -14,7 +14,11 @@ pub fn init(app: &mut App) {
|
|||
height: 600,
|
||||
};
|
||||
|
||||
app.add_plugins(test_plugin::TestPlugin);
|
||||
Window::new(app, window_config).unwrap();
|
||||
app.add_plugins((
|
||||
test_plugin::TestPlugin,
|
||||
window::WindowPlugin { window_config },
|
||||
vulkan::VulkanPlugin,
|
||||
));
|
||||
// Window::new(app, window_config).unwrap();
|
||||
// Vulkan::new(app).unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue