Continue new platform/glium implementations
- Assets, asset manager system - Rendering system trait - Kick off glium platform implementation - And more
This commit is contained in:
parent
f7d5c14caf
commit
e817abf8ab
18 changed files with 2557 additions and 32 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
target/
|
||||
*.patch
|
||||
.idea/
|
||||
2270
Cargo.lock
generated
Normal file
2270
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"raidillon_core",
|
||||
"raidillon_glium",
|
||||
"raidillon_platform"
|
||||
]
|
||||
113
raidillon_core/Cargo.lock
generated
113
raidillon_core/Cargo.lock
generated
|
|
@ -2,6 +2,119 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hecs"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1cbc675ee8d97b4d206a985137f8ad59666538f56f906474f554467a63c776d"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"spin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raidillon_core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hecs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
hecs = "0.10.5"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
mod scene;
|
||||
pub use scene::{Scene, SceneManager};
|
||||
30
raidillon_core/src/scene.rs
Normal file
30
raidillon_core/src/scene.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
pub struct Scene {
|
||||
title: String,
|
||||
world: hecs::World,
|
||||
skybox_texture_path: String,
|
||||
}
|
||||
|
||||
pub struct SceneManager {
|
||||
scenes: Vec<Option<Scene>>,
|
||||
active_index: usize,
|
||||
}
|
||||
|
||||
impl SceneManager {
|
||||
pub fn current(&self) -> &Scene {
|
||||
self.scenes[self.active_index].as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn current_mut(&mut self) -> &mut Scene {
|
||||
self.scenes[self.active_index].as_mut().unwrap()
|
||||
}
|
||||
|
||||
pub fn add_scene(&mut self, scene: Scene) -> usize {
|
||||
let idx = self.scenes.len();
|
||||
self.scenes.push(Some(scene));
|
||||
idx
|
||||
}
|
||||
|
||||
pub fn remove_scene(&mut self, idx: usize) {
|
||||
self.scenes[idx] = None;
|
||||
}
|
||||
}
|
||||
6
raidillon_glium/Cargo.lock
generated
6
raidillon_glium/Cargo.lock
generated
|
|
@ -1225,6 +1225,10 @@ version = "5.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "raidillon_core"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "raidillon_glium"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1233,7 +1237,9 @@ dependencies = [
|
|||
"glam",
|
||||
"glium",
|
||||
"gltf",
|
||||
"raidillon_core",
|
||||
"raidillon_platform",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -9,3 +9,5 @@ glam = "0.30.5"
|
|||
glium = { version = "0.35.0", features = ["glutin_backend", "simple_window_builder"] }
|
||||
gltf = { version = "1.4.1", features = ["import", "utils", "KHR_texture_transform"] }
|
||||
raidillon_platform = { path = "../raidillon_platform" }
|
||||
raidillon_core = { path = "../raidillon_core" }
|
||||
winit = "0.30.12"
|
||||
|
|
|
|||
|
|
@ -1,30 +1,47 @@
|
|||
use raidillon_platform::AssetManager;
|
||||
use raidillon_platform::assets::AssetManager;
|
||||
use crate::model::Model;
|
||||
use std::path::Path;
|
||||
use raidillon_platform::assets::ModelHandle;
|
||||
use std::path::{Path, PathBuf};
|
||||
use crate::gltf_loader::load_gltf;
|
||||
use glium::backend::Facade;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
/// Glium platform asset manager implementation.
|
||||
pub struct GliumAssetManager {
|
||||
models: Vec<Option<Model>>,
|
||||
models: HashMap<PathBuf, Model>,
|
||||
facade: Box<dyn Facade>,
|
||||
next_model_id: usize,
|
||||
}
|
||||
|
||||
impl AssetManager for GliumAssetManager {
|
||||
fn load_gltf(&mut self, path: &Path) -> ModelHandle {
|
||||
let model_id = self.next_model_id;
|
||||
let model = load_gltf(path, self.facade.as_ref()).unwrap();
|
||||
self.models.push(Some(model));
|
||||
self.next_model_id += 1;
|
||||
model_id
|
||||
}
|
||||
|
||||
fn unload_model(&mut self, model_handle: ModelHandle) {
|
||||
if model_handle < self.models.len() {
|
||||
self.models[model_handle] = None;
|
||||
impl GliumAssetManager {
|
||||
pub fn new(facade: Box<dyn Facade>) -> Self {
|
||||
let models = HashMap::new();
|
||||
Self {
|
||||
models,
|
||||
facade,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AssetManager for GliumAssetManager {
|
||||
type Model = Model;
|
||||
|
||||
fn load_gltf(&mut self, path: &Path) {
|
||||
let model = load_gltf(path, self.facade.as_ref()).unwrap();
|
||||
self.models.insert(path.to_path_buf(), model);
|
||||
}
|
||||
|
||||
fn unload_model(&mut self, path: &Path) {
|
||||
self.models.remove(&path.to_path_buf());
|
||||
}
|
||||
|
||||
fn get_model(&mut self, path: &Path) -> &Self::Model {
|
||||
let path_buf = path.to_path_buf();
|
||||
match self.models.entry(path_buf) {
|
||||
Entry::Occupied(entry) => entry.into_mut(),
|
||||
Entry::Vacant(entry) => {
|
||||
let model = load_gltf(path, self.facade.as_ref()).unwrap();
|
||||
entry.insert(model)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ pub mod platform;
|
|||
pub mod assets;
|
||||
pub mod model;
|
||||
pub mod gltf_loader;
|
||||
pub mod system;
|
||||
mod render;
|
||||
|
||||
pub use assets::GliumAssetManager;
|
||||
pub use platform::GliumPlatform;
|
||||
pub use system::RenderingSystem;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,24 @@
|
|||
use std::sync::{Arc, RwLock};
|
||||
use glium::backend::Facade;
|
||||
use raidillon_platform::Platform;
|
||||
use glium::winit::event_loop::EventLoop;
|
||||
use glium::winit::window::Window;
|
||||
use glium::backend::glutin::Display;
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
use glium::backend::glutin::SimpleWindowBuilder;
|
||||
use crate::system::{RenderingSystemManager, RenderingSystem};
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use crate::GliumAssetManager;
|
||||
|
||||
pub struct GliumPlatform {
|
||||
pub struct GliumPlatform<RS: RenderingSystem> {
|
||||
event_loop: EventLoop<()>,
|
||||
window: Window,
|
||||
display: Display<WindowSurface>,
|
||||
rendering_system_manager: RenderingSystemManager<RS>,
|
||||
asset_manager: Arc<RwLock<GliumAssetManager>>,
|
||||
}
|
||||
|
||||
impl Platform for GliumPlatform {
|
||||
impl<RS: RenderingSystem> Platform for GliumPlatform<RS> {
|
||||
fn initialize(title: String, width: u32, height: u32) -> Self {
|
||||
let event_loop = glium::winit::event_loop::EventLoop::builder()
|
||||
.build()
|
||||
|
|
@ -22,10 +29,32 @@ impl Platform for GliumPlatform {
|
|||
.with_inner_size(width, height)
|
||||
.build(&event_loop);
|
||||
|
||||
let rendering_system_manager = RenderingSystemManager::new();
|
||||
let asset_manager = Arc::new(RwLock::new(GliumAssetManager::new(Box::new(display.clone()))));
|
||||
Self {
|
||||
event_loop,
|
||||
window,
|
||||
display
|
||||
display,
|
||||
rendering_system_manager,
|
||||
asset_manager,
|
||||
}
|
||||
}
|
||||
|
||||
fn run(self) {
|
||||
let _ = &self.event_loop.run(move |event, el| {
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::CloseRequested => {},
|
||||
WindowEvent::RedrawRequested => {
|
||||
|
||||
}
|
||||
_ => {},
|
||||
},
|
||||
Event::AboutToWait => {
|
||||
self.window.request_redraw();
|
||||
}
|
||||
_ => {},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
raidillon_glium/src/render/basic.rs
Normal file
12
raidillon_glium/src/render/basic.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use glium::Surface;
|
||||
use crate::RenderingSystem;
|
||||
use crate::system::RenderingContext;
|
||||
|
||||
/// A basic renderer pipeline step.
|
||||
pub struct BasicRenderingSystem;
|
||||
|
||||
impl RenderingSystem for BasicRenderingSystem {
|
||||
fn render<S: Surface>(ctx: &mut RenderingContext<S>) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
2
raidillon_glium/src/render/mod.rs
Normal file
2
raidillon_glium/src/render/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
mod basic;
|
||||
pub use basic::BasicRenderingSystem;
|
||||
35
raidillon_glium/src/system.rs
Normal file
35
raidillon_glium/src/system.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
use std::collections::HashMap;
|
||||
use raidillon_core::Scene;
|
||||
use glium::Surface;
|
||||
|
||||
pub struct RenderingContext<'a, S: Surface> {
|
||||
pub scene: &'a mut Scene,
|
||||
pub target: &'a mut S,
|
||||
}
|
||||
|
||||
/// The internal "rendering system" trait of raidillon_glium.
|
||||
/// This is unrelated to the main System trait in raidillon_core.
|
||||
pub trait RenderingSystem {
|
||||
fn render<S: Surface>(ctx: &mut RenderingContext<S>);
|
||||
}
|
||||
|
||||
type SystemID = String;
|
||||
|
||||
pub struct RenderingSystemManager<T: RenderingSystem> {
|
||||
pub systems: HashMap<SystemID, Box<T>>,
|
||||
}
|
||||
|
||||
impl<T: RenderingSystem> RenderingSystemManager<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
systems: HashMap::new(),
|
||||
}
|
||||
}
|
||||
pub fn add_system(&mut self, id: SystemID, system: T) {
|
||||
self.systems.insert(id, Box::new(system));
|
||||
}
|
||||
|
||||
pub fn remove_system(&mut self, id: SystemID) {
|
||||
self.systems.remove(&id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
use std::path::Path;
|
||||
|
||||
pub type ModelHandle = usize;
|
||||
|
||||
/// The asset manager trait of Raidillon.
|
||||
pub trait AssetManager {
|
||||
type Model;
|
||||
/// Loads a gltf model to VRAM.
|
||||
fn load_gltf(&mut self, path: &Path) -> ModelHandle;
|
||||
fn load_gltf(&mut self, path: &Path);
|
||||
/// Unloads the loaded model from VRAM.
|
||||
fn unload_model(&mut self, model_handle: ModelHandle);
|
||||
fn unload_model(&mut self, path: &Path);
|
||||
fn get_model(&mut self, path: &Path) -> &Self::Model;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
use winit::event::Event;
|
||||
use crate::AssetManager;
|
||||
|
||||
pub struct FrameContext {
|
||||
pub event: Event<()>,
|
||||
}
|
||||
|
||||
pub struct PlatformContext {
|
||||
pub frame_context: FrameContext,
|
||||
pub asset_manager: dyn AssetManager,
|
||||
pub struct PlatformContext<AM: AssetManager> {
|
||||
pub current_event: Event<()>,
|
||||
pub asset_manager: AM,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
pub trait Platform {
|
||||
/// Initialize platform.
|
||||
fn initialize(title: String, width: u32, height: u32) -> Self;
|
||||
fn run(self);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue