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