Only show available present modes in graphic settings

This commit is contained in:
Isse 2024-01-18 00:57:01 +01:00 committed by Marcel Märtens
parent 82989979a6
commit b7a56e895a
4 changed files with 58 additions and 15 deletions

View File

@ -72,6 +72,7 @@ hud-settings-maximum_fps = Maximum FPS
hud-settings-background_fps = Background FPS hud-settings-background_fps = Background FPS
hud-settings-present_mode = Present Mode hud-settings-present_mode = Present Mode
hud-settings-present_mode-vsync_capped = Vsync capped hud-settings-present_mode-vsync_capped = Vsync capped
hud-settings-present_mode-vsync_adaptive = Adaptive vsync
hud-settings-present_mode-vsync_uncapped = Vsync uncapped hud-settings-present_mode-vsync_uncapped = Vsync uncapped
hud-settings-present_mode-vsync_off = Vsync off hud-settings-present_mode-vsync_off = Vsync off
hud-settings-fov = Field of View (deg) hud-settings-fov = Field of View (deg)

View File

@ -7,7 +7,7 @@ use crate::{
}, },
render::{ render::{
AaMode, BloomConfig, BloomFactor, BloomMode, CloudMode, FluidMode, LightingMode, AaMode, BloomConfig, BloomFactor, BloomMode, CloudMode, FluidMode, LightingMode,
PresentMode, ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode, ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode,
}, },
session::settings_change::Graphics as GraphicsChange, session::settings_change::Graphics as GraphicsChange,
settings::{Fps, GraphicsSettings}, settings::{Fps, GraphicsSettings},
@ -659,17 +659,11 @@ impl<'a> Widget for Video<'a> {
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.present_mode_text, ui); .set(state.ids.present_mode_text, ui);
let mode_list = [ let mode_list = self.global_state.window.renderer().present_modes();
PresentMode::Fifo, let mode_label_list = mode_list
PresentMode::Mailbox, .iter()
PresentMode::Immediate, .map(|mode| self.localized_strings.get_msg(mode.localize()))
]; .collect::<Vec<_>>();
let mode_label_list = [
"hud-settings-present_mode-vsync_capped",
"hud-settings-present_mode-vsync_uncapped",
"hud-settings-present_mode-vsync_off",
]
.map(|k| self.localized_strings.get_msg(k));
// Get which present mode is currently active // Get which present mode is currently active
let selected = mode_list let selected = mode_list

View File

@ -292,21 +292,48 @@ impl Default for UpscaleMode {
pub enum PresentMode { pub enum PresentMode {
Mailbox, Mailbox,
Immediate, Immediate,
FifoRelaxed,
#[default] #[default]
#[serde(other)] #[serde(other)]
Fifo, // has to be last for `#[serde(other)]` Fifo, // has to be last for `#[serde(other)]`
} }
impl PresentMode {
pub fn localize(&self) -> &'static str {
match self {
Self::Fifo => "hud-settings-present_mode-vsync_capped",
Self::FifoRelaxed => "hud-settings-present_mode-vsync_adaptive",
Self::Mailbox => "hud-settings-present_mode-vsync_uncapped",
Self::Immediate => "hud-settings-present_mode-vsync_off",
}
}
}
impl From<PresentMode> for wgpu::PresentMode { impl From<PresentMode> for wgpu::PresentMode {
fn from(mode: PresentMode) -> Self { fn from(mode: PresentMode) -> Self {
match mode { match mode {
PresentMode::Fifo => wgpu::PresentMode::Fifo, PresentMode::Fifo => wgpu::PresentMode::Fifo,
PresentMode::FifoRelaxed => wgpu::PresentMode::FifoRelaxed,
PresentMode::Mailbox => wgpu::PresentMode::Mailbox, PresentMode::Mailbox => wgpu::PresentMode::Mailbox,
PresentMode::Immediate => wgpu::PresentMode::Immediate, PresentMode::Immediate => wgpu::PresentMode::Immediate,
} }
} }
} }
impl TryFrom<wgpu::PresentMode> for PresentMode {
type Error = ();
fn try_from(mode: wgpu::PresentMode) -> Result<Self, ()> {
match mode {
wgpu::PresentMode::Fifo => Ok(PresentMode::Fifo),
wgpu::PresentMode::FifoRelaxed => Ok(PresentMode::FifoRelaxed),
wgpu::PresentMode::Mailbox => Ok(PresentMode::Mailbox),
wgpu::PresentMode::Immediate => Ok(PresentMode::Immediate),
_ => Err(()),
}
}
}
/// Bloom factor /// Bloom factor
/// Controls fraction of output image luminosity that is blurred bloom /// Controls fraction of output image luminosity that is blurred bloom
#[derive(Default, PartialEq, Clone, Copy, Debug, Serialize, Deserialize)] #[derive(Default, PartialEq, Clone, Copy, Debug, Serialize, Deserialize)]

View File

@ -28,8 +28,8 @@ use super::{
terrain, ui, GlobalsBindGroup, GlobalsLayouts, ShadowTexturesBindGroup, terrain, ui, GlobalsBindGroup, GlobalsLayouts, ShadowTexturesBindGroup,
}, },
texture::Texture, texture::Texture,
AddressMode, FilterMode, OtherModes, PipelineModes, RenderError, RenderMode, ShadowMapMode, AddressMode, FilterMode, OtherModes, PipelineModes, PresentMode, RenderError, RenderMode,
ShadowMode, Vertex, ShadowMapMode, ShadowMode, Vertex,
}; };
use common::assets::{self, AssetExt, AssetHandle, ReloadWatcher}; use common::assets::{self, AssetExt, AssetHandle, ReloadWatcher};
use common_base::span; use common_base::span;
@ -135,6 +135,7 @@ enum State {
pub struct Renderer { pub struct Renderer {
device: Arc<wgpu::Device>, device: Arc<wgpu::Device>,
queue: wgpu::Queue, queue: wgpu::Queue,
adapter: wgpu::Adapter,
surface: wgpu::Surface, surface: wgpu::Surface,
surface_config: wgpu::SurfaceConfiguration, surface_config: wgpu::SurfaceConfiguration,
@ -350,12 +351,21 @@ impl Renderer {
let format = surface_capabilities.formats[0]; let format = surface_capabilities.formats[0];
info!("Using {:?} as the surface format", format); info!("Using {:?} as the surface format", format);
let present_mode = other_modes.present_mode.into();
let surface_config = wgpu::SurfaceConfiguration { let surface_config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT, usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format, format,
width: dims.width, width: dims.width,
height: dims.height, height: dims.height,
present_mode: other_modes.present_mode.into(), present_mode: if surface_capabilities.present_modes.contains(&present_mode) {
present_mode
} else {
*surface_capabilities
.present_modes
.iter()
.find(|mode| PresentMode::try_from(**mode).is_ok())
.expect("There should never be no supported present modes")
},
alpha_mode: wgpu::CompositeAlphaMode::Opaque, alpha_mode: wgpu::CompositeAlphaMode::Opaque,
view_formats: Vec::new(), view_formats: Vec::new(),
}; };
@ -555,6 +565,7 @@ impl Renderer {
Ok(Self { Ok(Self {
device, device,
queue, queue,
adapter,
surface, surface,
surface_config, surface_config,
@ -675,6 +686,16 @@ impl Renderer {
/// Get the pipelines mode. /// Get the pipelines mode.
pub fn pipeline_modes(&self) -> &PipelineModes { &self.pipeline_modes } pub fn pipeline_modes(&self) -> &PipelineModes { &self.pipeline_modes }
/// Get the supported present modes.
pub fn present_modes(&self) -> Vec<PresentMode> {
self.surface
.get_capabilities(&self.adapter)
.present_modes
.into_iter()
.filter_map(|present_mode| PresentMode::try_from(present_mode).ok())
.collect()
}
/// Get the current profiling times /// Get the current profiling times
/// Nested timings immediately follow their parent /// Nested timings immediately follow their parent
/// Returns Vec<(how nested this timing is, label, length in seconds)> /// Returns Vec<(how nested this timing is, label, length in seconds)>