From c142b2fd47f51493df8d4ca05ad0d43d81eb4c69 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 16 May 2023 12:08:56 +0200 Subject: [PATCH] add fullscreen mode, release shader compiler after loading shader prefabs --- kubi/src/prefabs.rs | 1 + kubi/src/rendering.rs | 56 +++++++++++++++++++++++++++++++++++++++---- kubi/src/settings.rs | 11 +++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/kubi/src/prefabs.rs b/kubi/src/prefabs.rs index 3598eb2..ba16e81 100644 --- a/kubi/src/prefabs.rs +++ b/kubi/src/prefabs.rs @@ -97,4 +97,5 @@ pub fn load_prefabs( &renderer.display ) )); + renderer.display.release_shader_compiler(); } diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index aa16e02..5c13a09 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -4,12 +4,12 @@ use glium::{ Version, Api, glutin::{ event_loop::EventLoop, - window::WindowBuilder, - ContextBuilder, GlProfile + window::{WindowBuilder, Fullscreen}, + ContextBuilder, GlProfile, }, }; use glam::{Vec3, UVec2}; -use crate::{events::WindowResizedEvent, settings::GameSettings}; +use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; pub mod primitives; pub mod world; @@ -31,19 +31,67 @@ pub struct Renderer { impl Renderer { pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { log::info!("initializing display"); + let wb = WindowBuilder::new() .with_title("uwu") + .with_fullscreen({ + if let Some(fs_settings) = &settings.fullscreen { + let monitor = event_loop.primary_monitor().or_else(|| { + event_loop.available_monitors().next() + }); + if let Some(monitor) = monitor { + log::info!("monitor: {}", monitor.name().unwrap_or_else(|| "generic".into())); + match fs_settings.mode { + FullscreenMode::Borderless => { + log::info!("starting in borderless fullscreen mode"); + Some(Fullscreen::Borderless(Some(monitor))) + }, + FullscreenMode::Exclusive => { + log::info!("starting in exclusive fullscreen mode"); + //TODO: grabbing the first video mode is probably not the best idea... + monitor.video_modes().next() + .map(|vmode| { + log::info!("video mode: {}", vmode.to_string()); + Some(Fullscreen::Exclusive(vmode)) + }) + .unwrap_or_else(|| { + log::warn!("no valid video modes found, falling back to windowed mode instead"); + None + }) + } + } + } else { + log::warn!("no monitors found, falling back to windowed mode"); + None + } + } else { + log::info!("starting in windowed mode"); + None + } + }) .with_maximized(true); + let cb = ContextBuilder::new() .with_depth_buffer(24) .with_multisampling(settings.msaa.unwrap_or_default()) .with_gl_profile(GlProfile::Core); + let display = Display::new(wb, cb, event_loop) .expect("Failed to create a glium Display"); + + log::info!("Vendor: {}", display.get_opengl_vendor_string()); log::info!("Renderer: {}", display.get_opengl_renderer_string()); log::info!("OpenGL {}", display.get_opengl_version_string()); - log::info!("Supports GLES {:?}", display.get_supported_glsl_version()); + log::info!("Supports GLSL {:?}", display.get_supported_glsl_version()); + if display.is_context_loss_possible() { + log::warn!("ogl context loss possible"); + } + if display.is_robust() { + log::warn!("ogl implementation is not robust"); + } + assert!(display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLES 3.0 is not supported"); + Self { display } } } diff --git a/kubi/src/settings.rs b/kubi/src/settings.rs index bf6d8f8..9be37c5 100644 --- a/kubi/src/settings.rs +++ b/kubi/src/settings.rs @@ -1,7 +1,17 @@ use shipyard::{Unique, AllStoragesView}; +pub enum FullscreenMode { + Borderless, + Exclusive, +} + +pub struct FullscreenSettings { + pub mode: FullscreenMode, +} + #[derive(Unique)] pub struct GameSettings { + pub fullscreen: Option, pub msaa: Option, pub max_anisotropy: Option, /// there's a 1 chunk border of loaded but invisible around this @@ -12,6 +22,7 @@ pub struct GameSettings { impl Default for GameSettings { fn default() -> Self { Self { + fullscreen: None, msaa: Some(4), //not used yet max_anisotropy: Some(16), render_distance: 6,