Compare commits

..

3 commits

Author SHA1 Message Date
765e55edc0 Update Rust crate openvr to 0.7.0 2025-03-01 06:02:33 +00:00
f90dfb6236 Rename crates 2025-03-01 06:43:44 +01:00
e22381b8e9 Get rendering somewhat working 2025-03-01 06:01:46 +01:00
29 changed files with 129 additions and 63 deletions

View file

@ -2,8 +2,8 @@
resolver = "2" resolver = "2"
members = [ members = [
"ConfigHandler", "config_handler",
"Networking", "networking",
"asset", "asset",
"context", "context",
"controllable_thread", "controllable_thread",

View file

@ -86,17 +86,10 @@ impl VulkanCore {
// device extensions // device extensions
let mut dev_exts = DeviceExtensions::default(); let mut dev_exts = DeviceExtensions::default();
presentation_core.activate_vulkan_device_extensions(&mut dev_exts, &physical_device)?; presentation_core.activate_vulkan_device_extensions(&mut dev_exts, &physical_device)?;
dev_exts.memory_requirements2 = true;
dev_exts.amd_rasterization_order = true; dev_exts.amd_rasterization_order = true;
dev_exts.descriptor_indexing = true;
dev_exts.maintenance3 = true;
dev_exts.ray_tracing_pipeline = true; dev_exts.ray_tracing_pipeline = true;
dev_exts.deferred_host_operations = 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.acceleration_structure = true;
dev_exts.shader_float_controls = true;
dev_exts.pipeline_library = true; dev_exts.pipeline_library = true;
if vulkan_debug_info.renderdoc { if vulkan_debug_info.renderdoc {

View file

@ -17,7 +17,7 @@ utilities = { workspace = true }
assetpath = { workspace = true } assetpath = { workspace = true }
shaderc = { workspace = true } shaderc = { workspace = true }
config_handler = { path = "../ConfigHandler" } config_handler = { path = "../config_handler" }
asset = { path = "../asset" } asset = { path = "../asset" }
loading_screen = { path = "../loading-screen" } loading_screen = { path = "../loading-screen" }
context = { path = "../context", features = ["bundle_sdl2", "sound"] } context = { path = "../context", features = ["bundle_sdl2", "sound"] }

View file

@ -176,33 +176,18 @@ impl Engine {
gui_handler: GuiHandler::new(create_info.gui_info, &context)?, 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 { let engine = Engine {
asset_manager, asset_manager,
resource_base_path: create_info.resource_base_path, 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(context);
world.resources.insert(engine);
world.resources.insert(engine_settings);
let scene = Scene::new( let scene = Scene::new(
create_info.rasterizer_info, create_info.rasterizer_info,
@ -211,6 +196,18 @@ impl Engine {
world, 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.resources.insert(scene);
world.add_system(Self::main_system::<T>); world.add_system(Self::main_system::<T>);

View file

@ -9,13 +9,13 @@ use utilities::prelude::cgmath::{Vector3, Zero};
use super::{ use super::{
super::{ super::{
shared::{bufferhandler::*, safecommandbuffer::SafeCommandBuffer},
ExtensionCheck, RasterizerDescriptorLayouts, RenderingFrontEnd, ExtensionCheck, RasterizerDescriptorLayouts, RenderingFrontEnd,
shared::{bufferhandler::*, safecommandbuffer::SafeCommandBuffer},
}, },
SceneInfo,
lights::light_wrapper::LightHandler, lights::light_wrapper::LightHandler,
pipelines::RasterizerPipelines, pipelines::RasterizerPipelines,
rasterizershader::RasterizerShader, rasterizershader::RasterizerShader,
SceneInfo,
}; };
use deferredhandler::{DeferredHandler, FallbackInfo}; use deferredhandler::{DeferredHandler, FallbackInfo};
@ -352,10 +352,6 @@ impl Rasterizer {
impl ExtensionCheck for Rasterizer { impl ExtensionCheck for Rasterizer {
fn check(device: &Arc<Device>) -> bool { fn check(device: &Arc<Device>) -> bool {
if !device.enabled_extensions().descriptor_indexing {
return false;
}
let physical_device = device.physical_device(); let physical_device = device.physical_device();
if physical_device if physical_device

View file

@ -5,12 +5,12 @@ use utilities::{impl_reprc, prelude::cgmath::Vector3};
use super::{ use super::{
super::{ super::{
shared::position_buffer_reader::PositionBuffer, ExtensionCheck, RaytracerDesciptorLayouts, ExtensionCheck, RaytracerDesciptorLayouts, RenderingFrontEnd,
RenderingFrontEnd, shared::position_buffer_reader::PositionBuffer,
}, },
RenderingCore,
animator::ComputeBasedAnimator, animator::ComputeBasedAnimator,
light::{LightData, RayTracerLight}, light::{LightData, RayTracerLight},
RenderingCore,
}; };
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -488,10 +488,6 @@ where
T: RenderingCore, T: RenderingCore,
{ {
fn check(device: &Arc<Device>) -> bool { fn check(device: &Arc<Device>) -> bool {
if !device.enabled_extensions().descriptor_indexing {
return false;
}
let physical_device = device.physical_device(); let physical_device = device.physical_device();
if physical_device if physical_device

View file

@ -9,3 +9,4 @@ anyhow.workspace = true
ecs = { path = "../../ecs" } ecs = { path = "../../ecs" }
engine = { path = "../../engine" } engine = { path = "../../engine" }
skybox = { path = "../../skybox" }

View file

@ -1,7 +1,10 @@
use std::path::Path;
use anyhow::Result; use anyhow::Result;
use ecs::*; use ecs::*;
use engine::prelude::*; use engine::prelude::*;
use skybox::SkyBox;
fn main() -> Result<()> { fn main() -> Result<()> {
let mut world_builder = World::builder(); let mut world_builder = World::builder();
@ -11,6 +14,20 @@ fn main() -> Result<()> {
world_builder.add_system(GameState::update); world_builder.add_system(GameState::update);
world_builder.resources.insert(GameState::Startup); 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() world_builder.build().run()
} }

View file

@ -7,7 +7,7 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
config_handler = { path = "../ConfigHandler" } config_handler = { path = "../config_handler" }
anyhow = { workspace = true } anyhow = { workspace = true }
chrono = { workspace = true } chrono = { workspace = true }

View file

@ -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 { pub struct RenderBackend {
device: Arc<Device>, device: Arc<Device>,
queue: Arc<Mutex<Queue>>, queue: Arc<Mutex<Queue>>,
@ -61,7 +107,7 @@ pub struct RenderBackend {
command_buffer: Arc<CommandBuffer>, command_buffer: Arc<CommandBuffer>,
render_routines: Vec<(u32, TypeId)>, render_routines: Vec<SceneHandle>,
} }
impl RenderBackend { impl RenderBackend {
@ -169,17 +215,13 @@ impl RenderBackend {
// make a call to the connected scenes // make a call to the connected scenes
self.render_routines self.render_routines
.iter_mut() .iter_mut()
.try_for_each(|(_, type_id)| -> Result<()> { .try_for_each(|scene_handle| {
let scene: &mut dyn TScene = world.resources.get_mut_by_type_id_untyped(*type_id); (scene_handle.render)(
scene.process(
&mut buffer_recorder, &mut buffer_recorder,
&*self.swapchain_images.lock().unwrap(), &*self.swapchain_images.lock().unwrap(),
&image_indices, &image_indices,
world, world,
)?; )
Ok(())
})?; })?;
Ok(&self.command_buffer) Ok(&self.command_buffer)
@ -205,10 +247,8 @@ impl RenderBackend {
self.render_routines self.render_routines
.iter_mut() .iter_mut()
.try_for_each(|(_, type_id)| -> Result<()> { .try_for_each(|scene_handle| {
let scene: &mut dyn TScene = world.resources.get_mut_by_type_id_untyped(*type_id); (scene_handle.resize)(width as f32, height as f32, &images, world)
scene.resize(width as f32, height as f32, &images)
})?; })?;
Ok(()) Ok(())
@ -216,15 +256,16 @@ impl RenderBackend {
/// lower priority means it is more important /// lower priority means it is more important
pub fn add_render_routine<T: TScene>(&mut self, priority: u32) { pub fn add_render_routine<T: TScene>(&mut self, priority: u32) {
self.render_routines.push((priority, TypeId::of::<T>())); self.render_routines.push(SceneHandle::new::<T>(priority));
self.render_routines.sort_by_key(|(p, _)| *p); self.render_routines
.sort_by_key(|scene_handle| scene_handle.priority);
} }
pub fn remove_render_routine<T: TScene>(&mut self) { pub fn remove_render_routine<T: TScene>(&mut self) {
if let Some(&(index, _)) = self if let Some(index) = self
.render_routines .render_routines
.iter() .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); self.render_routines.remove(index as usize);
} }

View file

@ -33,9 +33,10 @@ pub struct SkyBox {
} }
impl 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 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([ let cube_map = Image::cube_map([
images.left.try_into()?, images.left.try_into()?,
@ -49,6 +50,30 @@ impl SkyBox {
.attach_pretty_sampler(context.device())? .attach_pretty_sampler(context.device())?
.build(context.device(), context.queue())?; .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!()
} }
} }