Continue new platform/glium implementations

- Assets, asset manager system
- Rendering system trait
- Kick off glium platform implementation
- And more
This commit is contained in:
reo 2025-08-07 17:56:35 +03:00 committed by Emre
parent f7d5c14caf
commit e817abf8ab
18 changed files with 2557 additions and 32 deletions

View file

@ -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]]

View file

@ -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"

View file

@ -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)
}
}
}
}

View file

@ -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;

View file

@ -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();
}
_ => {},
}
});
}
}

View 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!()
}
}

View file

@ -0,0 +1,2 @@
mod basic;
pub use basic::BasicRenderingSystem;

View 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);
}
}