render_plugin: Begin add window plugin
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 3m7s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 3m7s
This commit is contained in:
parent
0ee29a3649
commit
ae0a2be097
8 changed files with 134 additions and 48 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -676,7 +676,10 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
"engine_vulkan",
|
||||
"engine_window",
|
||||
"log",
|
||||
"vulkano",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -7,3 +7,6 @@ edition = "2024"
|
|||
log = { workspace = true }
|
||||
bevy_app = { workspace = true }
|
||||
bevy_ecs = { workspace = true }
|
||||
vulkano = { workspace = true }
|
||||
engine_vulkan = { workspace = true }
|
||||
engine_window = { workspace = true }
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
use bevy_app::{App, AppLabel, Last, Plugin, SubApp};
|
||||
use bevy_ecs::{
|
||||
schedule::{IntoScheduleConfigs, Schedule, ScheduleLabel, SystemSet},
|
||||
system::Commands,
|
||||
system::{Commands, Res},
|
||||
world::World,
|
||||
};
|
||||
use engine_vulkan::{
|
||||
VulkanCommandBufferAllocator, VulkanDescriptorSetAllocator, VulkanDevice, VulkanGraphicsQueue,
|
||||
VulkanMemoryAllocator,
|
||||
};
|
||||
use engine_window::raw_handle::WindowWrapper;
|
||||
use window::WindowRenderPlugin;
|
||||
|
||||
pub mod window;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
||||
pub enum RenderSystems {
|
||||
ManageViews,
|
||||
Prepare,
|
||||
Queue,
|
||||
Render,
|
||||
|
@ -33,33 +43,69 @@ pub struct RenderApp;
|
|||
pub struct RenderPlugin;
|
||||
|
||||
impl Plugin for RenderPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
fn build(&self, _app: &mut App) {}
|
||||
|
||||
fn ready(&self, app: &App) -> bool {
|
||||
let world = app.world();
|
||||
|
||||
world.get_resource::<WindowWrapper>().is_some()
|
||||
&& world.get_resource::<VulkanDevice>().is_some()
|
||||
&& world.get_resource::<VulkanGraphicsQueue>().is_some()
|
||||
&& world.get_resource::<VulkanMemoryAllocator>().is_some()
|
||||
&& world
|
||||
.get_resource::<VulkanCommandBufferAllocator>()
|
||||
.is_some()
|
||||
&& world
|
||||
.get_resource::<VulkanDescriptorSetAllocator>()
|
||||
.is_some()
|
||||
}
|
||||
|
||||
fn finish(&self, app: &mut App) {
|
||||
let mut render_app = SubApp::new();
|
||||
render_app.update_schedule = Some(Render.intern());
|
||||
|
||||
render_app.add_schedule(Render::base_schedule());
|
||||
|
||||
render_app.add_systems(Render, test_prepare.in_set(RenderSystems::Prepare));
|
||||
render_app.add_systems(Render, test_queue.in_set(RenderSystems::Queue));
|
||||
render_app.add_systems(Render, test_render.in_set(RenderSystems::Render));
|
||||
render_app.add_systems(Render, test_present.in_set(RenderSystems::Present));
|
||||
extract_app_resources(app.world_mut(), render_app.world_mut());
|
||||
|
||||
app.insert_sub_app(RenderApp, render_app);
|
||||
|
||||
app.add_plugins(WindowRenderPlugin);
|
||||
}
|
||||
|
||||
fn cleanup(&self, app: &mut App) {
|
||||
app.remove_sub_app(RenderApp);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_prepare(mut commands: Commands) {
|
||||
log::info!("test_prepare");
|
||||
}
|
||||
fn extract_app_resources(world: &mut World, render_world: &mut World) {
|
||||
let window_wrapper = world
|
||||
.get_resource::<WindowWrapper>()
|
||||
.expect("Failed to get WindowWrapper. Check is WindowPlugin is added before RenderPlugin.");
|
||||
|
||||
fn test_queue(mut commands: Commands) {
|
||||
log::info!("test_queue");
|
||||
}
|
||||
let vulkan_device = world
|
||||
.get_resource::<VulkanDevice>()
|
||||
.expect("Failed to get Vulkan device. Check is VulkanPlugin is added before RenderPlugin.");
|
||||
|
||||
fn test_render(mut commands: Commands) {
|
||||
log::info!("test_render");
|
||||
}
|
||||
let vulkan_graphics_queue = world.get_resource::<VulkanGraphicsQueue>().expect(
|
||||
"Failed to get Vulkan graphics queue. Check is VulkanPlugin is added before RenderPlugin.",
|
||||
);
|
||||
|
||||
fn test_present(mut commands: Commands) {
|
||||
log::info!("test_present");
|
||||
let vulkan_memory_allocator = world
|
||||
.get_resource::<VulkanMemoryAllocator>()
|
||||
.expect("Failed to get Vulkan memory allocator. Check is VulkanPlugin is added before RenderPlugin.");
|
||||
|
||||
let vulkan_command_buffer_allocator = world
|
||||
.get_resource::<VulkanCommandBufferAllocator>()
|
||||
.expect("Failed to get Vulkan command buffer allocator. Check is VulkanPlugin is added before RenderPlugin.");
|
||||
|
||||
let vulkan_descriptor_set_allocator = world
|
||||
.get_resource::<VulkanDescriptorSetAllocator>()
|
||||
.expect("Failed to get Vulkan descriptor set allocator. Check is VulkanPlugin is added before RenderPlugin.");
|
||||
|
||||
render_world.insert_resource(vulkan_device.clone());
|
||||
render_world.insert_resource(vulkan_graphics_queue.clone());
|
||||
render_world.insert_resource(vulkan_memory_allocator.clone());
|
||||
render_world.insert_resource(vulkan_command_buffer_allocator.clone());
|
||||
render_world.insert_resource(vulkan_descriptor_set_allocator.clone());
|
||||
render_world.insert_resource(window_wrapper.clone());
|
||||
}
|
||||
|
|
35
crates/engine_render/src/window/mod.rs
Normal file
35
crates/engine_render/src/window/mod.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_ecs::resource::Resource;
|
||||
use vulkano::{
|
||||
image::view::ImageView, pipeline::graphics::viewport::Viewport, swapchain::Swapchain,
|
||||
sync::GpuFuture,
|
||||
};
|
||||
|
||||
use crate::RenderApp;
|
||||
|
||||
pub struct WindowSurfaceData {
|
||||
pub swapchain: Arc<Swapchain>,
|
||||
pub attachment_image_views: Vec<Arc<ImageView>>,
|
||||
pub viewport: Viewport,
|
||||
pub recreate_swapchain: bool,
|
||||
pub previous_frame_end: Option<Box<dyn GpuFuture + Send + Sync>>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct WindowSurface {
|
||||
pub surface: Option<WindowSurfaceData>,
|
||||
}
|
||||
|
||||
pub struct WindowRenderPlugin;
|
||||
|
||||
impl Plugin for WindowRenderPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
let render_app = app
|
||||
.get_sub_app_mut(RenderApp)
|
||||
.expect("Failed to get RenderApp. Check is RenderPlugin is added.");
|
||||
|
||||
render_app.init_resource::<WindowSurface>();
|
||||
}
|
||||
}
|
|
@ -17,28 +17,29 @@ use bevy_app::{App, Plugin};
|
|||
mod utils;
|
||||
mod window_render_context;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanInstance(Arc<Instance>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanInstance(pub Arc<Instance>);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanDevice(Arc<Device>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanDevice(pub Arc<Device>);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanGraphicsQueue(Arc<Queue>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanGraphicsQueue(pub Arc<Queue>);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanComputeQueue(Arc<Queue>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanComputeQueue(pub Arc<Queue>);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanTransferQueue(Arc<Queue>);
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanMemoryAllocator(Arc<StandardMemoryAllocator>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanTransferQueue(pub Arc<Queue>);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanCommandBufferAllocator(Arc<StandardCommandBufferAllocator>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanMemoryAllocator(pub Arc<StandardMemoryAllocator>);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanDescriptorSetAllocator(Arc<StandardDescriptorSetAllocator>);
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanCommandBufferAllocator(pub Arc<StandardCommandBufferAllocator>);
|
||||
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct VulkanDescriptorSetAllocator(pub Arc<StandardDescriptorSetAllocator>);
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum VulkanError {
|
||||
|
@ -82,13 +83,4 @@ impl Plugin for VulkanPlugin {
|
|||
create_and_insert_instance(world, &self.vulkan_config);
|
||||
create_and_insert_device(world, &self.vulkan_config);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy_app::{App, AppExit, Plugin, PluginsState};
|
||||
use config::WindowConfig;
|
||||
use raw_handle::{DisplayHandleWrapper, EventLoopProxyWrapper};
|
||||
use raw_handle::{DisplayHandleWrapper, EventLoopProxyWrapper, WindowWrapper};
|
||||
use state::WindowState;
|
||||
use winit::event_loop::EventLoop;
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ impl<T: 'static> EventLoopProxyWrapper<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct DisplayHandleWrapper(pub winit::event_loop::OwnedDisplayHandle);
|
||||
|
||||
#[derive(Resource)]
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct WindowWrapper(pub Arc<Window>);
|
||||
|
|
|
@ -33,6 +33,13 @@ pub fn init(app: &mut App) {
|
|||
VulkanPlugin { vulkan_config },
|
||||
RenderPlugin,
|
||||
));
|
||||
// Window::new(app, window_config).unwrap();
|
||||
// Vulkan::new(app).unwrap();
|
||||
|
||||
// app.get_sub_app_mut(RenderApp)
|
||||
// .expect("Failed to get RenderApp. Check is RenderPlugin is added.")
|
||||
// .add_systems(Render, test_system.in_set(RenderSystems::Prepare));
|
||||
}
|
||||
|
||||
// fn test_system(vulkan_device: Res<VulkanDevice>, vulkan_graphics_queue: Res<VulkanGraphicsQueue>) {
|
||||
// log::trace!("vulkan_device: {:?}", vulkan_device.0);
|
||||
// log::trace!("vulkan_graphics_queue: {:?}", vulkan_graphics_queue.0);
|
||||
// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue