Improve abstraction of the engine
- Improved camera controls - Introduce new convenience function ecsr.load_mesh_from_gltf - Abstract out the glium stuff to allow for more backends in the future. We're still tied to winit though as it can be used with any of the major graphics libraries in the Rust ecosystem.
This commit is contained in:
parent
97195fbd05
commit
a3d3f641cd
10 changed files with 115 additions and 74 deletions
|
|
@ -5,8 +5,8 @@ use imgui::{Context as ImguiContext, Ui};
|
|||
use imgui_winit_support::{HiDpiMode, WinitPlatform};
|
||||
use imgui_glium_renderer::Renderer as ImguiGliumRenderer;
|
||||
use winit::window::Window;
|
||||
use glium::{Frame};
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
use glium::Frame;
|
||||
use raidillon_render::{DisplayHandle, ECSRenderer};
|
||||
|
||||
/// Convenience wrapper that owns all ImGui state required for integration with
|
||||
/// winit + glium.
|
||||
|
|
@ -18,13 +18,13 @@ pub struct Gui {
|
|||
}
|
||||
|
||||
impl Gui {
|
||||
pub fn new(display: &glium::Display<WindowSurface>, window: &Window) -> Result<Self> {
|
||||
pub fn new(display: &DisplayHandle, window: &Window) -> Result<Self> {
|
||||
let mut imgui = ImguiContext::create();
|
||||
imgui.set_ini_filename(None);
|
||||
let mut platform = WinitPlatform::new(&mut imgui);
|
||||
platform.attach_window(imgui.io_mut(), window, HiDpiMode::Default);
|
||||
imgui.fonts().add_font(&[imgui::FontSource::DefaultFontData { config: None }]);
|
||||
let renderer = ImguiGliumRenderer::new(&mut imgui, display)?;
|
||||
let renderer = ImguiGliumRenderer::new(&mut imgui, display.as_inner())?;
|
||||
|
||||
Ok(Self {
|
||||
imgui,
|
||||
|
|
@ -74,6 +74,21 @@ impl Gui {
|
|||
.expect("imgui rendering failed");
|
||||
}
|
||||
|
||||
pub fn render_world<F>(&mut self, ecsr: &mut ECSRenderer, window: &Window, build_ui: F)
|
||||
where
|
||||
F: FnOnce(&Ui, &mut ECSRenderer),
|
||||
{
|
||||
let mut target = ecsr.renderer.display().draw();
|
||||
|
||||
ecsr.render_into(&mut target);
|
||||
|
||||
self.render_with(&mut target, window, |ui| {
|
||||
build_ui(ui, ecsr);
|
||||
});
|
||||
|
||||
target.finish().expect("Failed to swap buffers");
|
||||
}
|
||||
|
||||
pub fn ui<F>(&mut self, build: F)
|
||||
where
|
||||
F: FnOnce(&Ui),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue