Compare commits
3 commits
79ff38cc21
...
72fc88066d
Author | SHA1 | Date | |
---|---|---|---|
72fc88066d | |||
f90dfb6236 | |||
e22381b8e9 |
29 changed files with 129 additions and 63 deletions
|
@ -2,8 +2,8 @@
|
|||
resolver = "2"
|
||||
|
||||
members = [
|
||||
"ConfigHandler",
|
||||
"Networking",
|
||||
"config_handler",
|
||||
"networking",
|
||||
"asset",
|
||||
"context",
|
||||
"controllable_thread",
|
||||
|
|
|
@ -86,17 +86,10 @@ impl VulkanCore {
|
|||
// device extensions
|
||||
let mut dev_exts = DeviceExtensions::default();
|
||||
presentation_core.activate_vulkan_device_extensions(&mut dev_exts, &physical_device)?;
|
||||
dev_exts.memory_requirements2 = true;
|
||||
dev_exts.amd_rasterization_order = true;
|
||||
dev_exts.descriptor_indexing = true;
|
||||
dev_exts.maintenance3 = true;
|
||||
|
||||
dev_exts.ray_tracing_pipeline = true;
|
||||
dev_exts.deferred_host_operations = true;
|
||||
dev_exts.spirv_1_4 = true;
|
||||
dev_exts.buffer_device_address = true;
|
||||
dev_exts.acceleration_structure = true;
|
||||
dev_exts.shader_float_controls = true;
|
||||
dev_exts.pipeline_library = true;
|
||||
|
||||
if vulkan_debug_info.renderdoc {
|
||||
|
|
|
@ -17,7 +17,7 @@ utilities = { workspace = true }
|
|||
assetpath = { workspace = true }
|
||||
shaderc = { workspace = true }
|
||||
|
||||
config_handler = { path = "../ConfigHandler" }
|
||||
config_handler = { path = "../config_handler" }
|
||||
asset = { path = "../asset" }
|
||||
loading_screen = { path = "../loading-screen" }
|
||||
context = { path = "../context", features = ["bundle_sdl2", "sound"] }
|
||||
|
|
|
@ -176,33 +176,18 @@ impl Engine {
|
|||
gui_handler: GuiHandler::new(create_info.gui_info, &context)?,
|
||||
};
|
||||
|
||||
context
|
||||
.render_core_mut()
|
||||
.add_render_routine::<GuiHandlerRenderer>(10_000_000);
|
||||
|
||||
world.resources.insert(gui_handler);
|
||||
|
||||
// default keyboard navigation
|
||||
let mut direction_mapping = HashMap::new();
|
||||
// direction_mapping.insert(Keycode::A, GuiDirection::Left);
|
||||
// direction_mapping.insert(Keycode::D, GuiDirection::Right);
|
||||
// direction_mapping.insert(Keycode::W, GuiDirection::Up);
|
||||
// direction_mapping.insert(Keycode::S, GuiDirection::Down);
|
||||
direction_mapping.insert(Keycode::Left, GuiDirection::Left);
|
||||
direction_mapping.insert(Keycode::Right, GuiDirection::Right);
|
||||
direction_mapping.insert(Keycode::Up, GuiDirection::Up);
|
||||
direction_mapping.insert(Keycode::Down, GuiDirection::Down);
|
||||
|
||||
let engine = Engine {
|
||||
asset_manager,
|
||||
|
||||
resource_base_path: create_info.resource_base_path,
|
||||
};
|
||||
|
||||
world.resources.insert(InputMap { direction_mapping });
|
||||
context
|
||||
.render_core_mut()
|
||||
.add_render_routine::<GuiHandlerRenderer>(10_000_000);
|
||||
context.render_core_mut().add_render_routine::<Scene>(100);
|
||||
|
||||
world.resources.insert(context);
|
||||
world.resources.insert(engine);
|
||||
world.resources.insert(engine_settings);
|
||||
|
||||
let scene = Scene::new(
|
||||
create_info.rasterizer_info,
|
||||
|
@ -211,6 +196,18 @@ impl Engine {
|
|||
world,
|
||||
)?;
|
||||
|
||||
// default keyboard navigation
|
||||
let mut direction_mapping = HashMap::new();
|
||||
direction_mapping.insert(Keycode::Left, GuiDirection::Left);
|
||||
direction_mapping.insert(Keycode::Right, GuiDirection::Right);
|
||||
direction_mapping.insert(Keycode::Up, GuiDirection::Up);
|
||||
direction_mapping.insert(Keycode::Down, GuiDirection::Down);
|
||||
|
||||
world.resources.insert(gui_handler);
|
||||
world.resources.insert(InputMap { direction_mapping });
|
||||
|
||||
world.resources.insert(engine);
|
||||
world.resources.insert(engine_settings);
|
||||
world.resources.insert(scene);
|
||||
|
||||
world.add_system(Self::main_system::<T>);
|
||||
|
|
|
@ -9,13 +9,13 @@ use utilities::prelude::cgmath::{Vector3, Zero};
|
|||
|
||||
use super::{
|
||||
super::{
|
||||
shared::{bufferhandler::*, safecommandbuffer::SafeCommandBuffer},
|
||||
ExtensionCheck, RasterizerDescriptorLayouts, RenderingFrontEnd,
|
||||
shared::{bufferhandler::*, safecommandbuffer::SafeCommandBuffer},
|
||||
},
|
||||
SceneInfo,
|
||||
lights::light_wrapper::LightHandler,
|
||||
pipelines::RasterizerPipelines,
|
||||
rasterizershader::RasterizerShader,
|
||||
SceneInfo,
|
||||
};
|
||||
|
||||
use deferredhandler::{DeferredHandler, FallbackInfo};
|
||||
|
@ -352,10 +352,6 @@ impl Rasterizer {
|
|||
|
||||
impl ExtensionCheck for Rasterizer {
|
||||
fn check(device: &Arc<Device>) -> bool {
|
||||
if !device.enabled_extensions().descriptor_indexing {
|
||||
return false;
|
||||
}
|
||||
|
||||
let physical_device = device.physical_device();
|
||||
|
||||
if physical_device
|
||||
|
|
|
@ -5,12 +5,12 @@ use utilities::{impl_reprc, prelude::cgmath::Vector3};
|
|||
|
||||
use super::{
|
||||
super::{
|
||||
shared::position_buffer_reader::PositionBuffer, ExtensionCheck, RaytracerDesciptorLayouts,
|
||||
RenderingFrontEnd,
|
||||
ExtensionCheck, RaytracerDesciptorLayouts, RenderingFrontEnd,
|
||||
shared::position_buffer_reader::PositionBuffer,
|
||||
},
|
||||
RenderingCore,
|
||||
animator::ComputeBasedAnimator,
|
||||
light::{LightData, RayTracerLight},
|
||||
RenderingCore,
|
||||
};
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -488,10 +488,6 @@ where
|
|||
T: RenderingCore,
|
||||
{
|
||||
fn check(device: &Arc<Device>) -> bool {
|
||||
if !device.enabled_extensions().descriptor_indexing {
|
||||
return false;
|
||||
}
|
||||
|
||||
let physical_device = device.physical_device();
|
||||
|
||||
if physical_device
|
||||
|
|
|
@ -9,3 +9,4 @@ anyhow.workspace = true
|
|||
|
||||
ecs = { path = "../../ecs" }
|
||||
engine = { path = "../../engine" }
|
||||
skybox = { path = "../../skybox" }
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use ecs::*;
|
||||
use engine::prelude::*;
|
||||
use skybox::SkyBox;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut world_builder = World::builder();
|
||||
|
@ -11,6 +14,20 @@ fn main() -> Result<()> {
|
|||
world_builder.add_system(GameState::update);
|
||||
world_builder.resources.insert(GameState::Startup);
|
||||
|
||||
let dir = Path::new("/home/michaelh/Sync/skybox");
|
||||
SkyBox::new(
|
||||
&mut world_builder,
|
||||
[
|
||||
dir.join("left.png"),
|
||||
dir.join("right.png"),
|
||||
dir.join("front.png"),
|
||||
dir.join("back.png"),
|
||||
dir.join("top.png"),
|
||||
dir.join("bottom.png"),
|
||||
]
|
||||
.into_iter(),
|
||||
)?;
|
||||
|
||||
world_builder.build().run()
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ edition = "2024"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
config_handler = { path = "../ConfigHandler" }
|
||||
config_handler = { path = "../config_handler" }
|
||||
anyhow = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
|
|
@ -49,6 +49,52 @@ impl Default for VRTransformations {
|
|||
}
|
||||
}
|
||||
|
||||
struct SceneHandle {
|
||||
type_id: TypeId,
|
||||
priority: u32,
|
||||
|
||||
render: Box<
|
||||
dyn FnMut(
|
||||
&mut CommandBufferRecorder<'_>,
|
||||
&TargetMode<Vec<Arc<Image>>>,
|
||||
&TargetMode<usize>,
|
||||
&mut World,
|
||||
) -> Result<()>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
>,
|
||||
|
||||
resize: Box<
|
||||
dyn FnMut(f32, f32, &TargetMode<Vec<Arc<Image>>>, &mut World) -> Result<()>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
>,
|
||||
}
|
||||
|
||||
impl SceneHandle {
|
||||
fn new<T: TScene>(priority: u32) -> Self {
|
||||
Self {
|
||||
type_id: TypeId::of::<T>(),
|
||||
priority,
|
||||
render: Box::new(|recorder, images, indices, world| {
|
||||
world
|
||||
.resources
|
||||
.get_mut_unchecked::<T>()
|
||||
.process(recorder, images, indices, world)
|
||||
}),
|
||||
|
||||
resize: Box::new(|width, height, images, world| {
|
||||
world
|
||||
.resources
|
||||
.get_mut_unchecked::<T>()
|
||||
.resize(width, height, images)
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RenderBackend {
|
||||
device: Arc<Device>,
|
||||
queue: Arc<Mutex<Queue>>,
|
||||
|
@ -61,7 +107,7 @@ pub struct RenderBackend {
|
|||
|
||||
command_buffer: Arc<CommandBuffer>,
|
||||
|
||||
render_routines: Vec<(u32, TypeId)>,
|
||||
render_routines: Vec<SceneHandle>,
|
||||
}
|
||||
|
||||
impl RenderBackend {
|
||||
|
@ -169,17 +215,13 @@ impl RenderBackend {
|
|||
// make a call to the connected scenes
|
||||
self.render_routines
|
||||
.iter_mut()
|
||||
.try_for_each(|(_, type_id)| -> Result<()> {
|
||||
let scene: &mut dyn TScene = world.resources.get_mut_by_type_id_untyped(*type_id);
|
||||
|
||||
scene.process(
|
||||
.try_for_each(|scene_handle| {
|
||||
(scene_handle.render)(
|
||||
&mut buffer_recorder,
|
||||
&*self.swapchain_images.lock().unwrap(),
|
||||
&image_indices,
|
||||
world,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(&self.command_buffer)
|
||||
|
@ -205,10 +247,8 @@ impl RenderBackend {
|
|||
|
||||
self.render_routines
|
||||
.iter_mut()
|
||||
.try_for_each(|(_, type_id)| -> Result<()> {
|
||||
let scene: &mut dyn TScene = world.resources.get_mut_by_type_id_untyped(*type_id);
|
||||
|
||||
scene.resize(width as f32, height as f32, &images)
|
||||
.try_for_each(|scene_handle| {
|
||||
(scene_handle.resize)(width as f32, height as f32, &images, world)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
|
@ -216,15 +256,16 @@ impl RenderBackend {
|
|||
|
||||
/// lower priority means it is more important
|
||||
pub fn add_render_routine<T: TScene>(&mut self, priority: u32) {
|
||||
self.render_routines.push((priority, TypeId::of::<T>()));
|
||||
self.render_routines.sort_by_key(|(p, _)| *p);
|
||||
self.render_routines.push(SceneHandle::new::<T>(priority));
|
||||
self.render_routines
|
||||
.sort_by_key(|scene_handle| scene_handle.priority);
|
||||
}
|
||||
|
||||
pub fn remove_render_routine<T: TScene>(&mut self) {
|
||||
if let Some(&(index, _)) = self
|
||||
if let Some(index) = self
|
||||
.render_routines
|
||||
.iter()
|
||||
.find(|(_, type_id)| *type_id == TypeId::of::<T>())
|
||||
.position(|scene_handle| scene_handle.type_id == TypeId::of::<T>())
|
||||
{
|
||||
self.render_routines.remove(index as usize);
|
||||
}
|
||||
|
|
|
@ -33,9 +33,10 @@ pub struct SkyBox {
|
|||
}
|
||||
|
||||
impl SkyBox {
|
||||
pub fn new(world: &mut WorldBuilder, images: impl Into<SkyBoxImages>) -> Result<Self> {
|
||||
pub fn new(world: &mut WorldBuilder, images: impl Into<SkyBoxImages>) -> Result<()> {
|
||||
let images = images.into();
|
||||
let context = world.resources.get::<Context>();
|
||||
let context = world.resources.get_mut::<Context>();
|
||||
context.render_core_mut().add_render_routine::<Self>(1);
|
||||
|
||||
let cube_map = Image::cube_map([
|
||||
images.left.try_into()?,
|
||||
|
@ -49,6 +50,30 @@ impl SkyBox {
|
|||
.attach_pretty_sampler(context.device())?
|
||||
.build(context.device(), context.queue())?;
|
||||
|
||||
Ok(Self { cube_map })
|
||||
let me = Self { cube_map };
|
||||
world.resources.insert(me);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TScene for SkyBox {
|
||||
fn process(
|
||||
&mut self,
|
||||
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
||||
images: &TargetMode<Vec<Arc<Image>>>,
|
||||
indices: &TargetMode<usize>,
|
||||
world: &World,
|
||||
) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn resize(
|
||||
&mut self,
|
||||
window_width: f32,
|
||||
window_height: f32,
|
||||
images: &TargetMode<Vec<Arc<Image>>>,
|
||||
) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue