mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Only show available present modes in graphic settings
This commit is contained in:
parent
82989979a6
commit
b7a56e895a
@ -72,6 +72,7 @@ hud-settings-maximum_fps = Maximum FPS
|
||||
hud-settings-background_fps = Background FPS
|
||||
hud-settings-present_mode = Present Mode
|
||||
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_off = Vsync off
|
||||
hud-settings-fov = Field of View (deg)
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
},
|
||||
render::{
|
||||
AaMode, BloomConfig, BloomFactor, BloomMode, CloudMode, FluidMode, LightingMode,
|
||||
PresentMode, ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode,
|
||||
ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode,
|
||||
},
|
||||
session::settings_change::Graphics as GraphicsChange,
|
||||
settings::{Fps, GraphicsSettings},
|
||||
@ -659,17 +659,11 @@ impl<'a> Widget for Video<'a> {
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.present_mode_text, ui);
|
||||
|
||||
let mode_list = [
|
||||
PresentMode::Fifo,
|
||||
PresentMode::Mailbox,
|
||||
PresentMode::Immediate,
|
||||
];
|
||||
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));
|
||||
let mode_list = self.global_state.window.renderer().present_modes();
|
||||
let mode_label_list = mode_list
|
||||
.iter()
|
||||
.map(|mode| self.localized_strings.get_msg(mode.localize()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Get which present mode is currently active
|
||||
let selected = mode_list
|
||||
|
@ -292,21 +292,48 @@ impl Default for UpscaleMode {
|
||||
pub enum PresentMode {
|
||||
Mailbox,
|
||||
Immediate,
|
||||
FifoRelaxed,
|
||||
#[default]
|
||||
#[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 {
|
||||
fn from(mode: PresentMode) -> Self {
|
||||
match mode {
|
||||
PresentMode::Fifo => wgpu::PresentMode::Fifo,
|
||||
PresentMode::FifoRelaxed => wgpu::PresentMode::FifoRelaxed,
|
||||
PresentMode::Mailbox => wgpu::PresentMode::Mailbox,
|
||||
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
|
||||
/// Controls fraction of output image luminosity that is blurred bloom
|
||||
#[derive(Default, PartialEq, Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
|
@ -28,8 +28,8 @@ use super::{
|
||||
terrain, ui, GlobalsBindGroup, GlobalsLayouts, ShadowTexturesBindGroup,
|
||||
},
|
||||
texture::Texture,
|
||||
AddressMode, FilterMode, OtherModes, PipelineModes, RenderError, RenderMode, ShadowMapMode,
|
||||
ShadowMode, Vertex,
|
||||
AddressMode, FilterMode, OtherModes, PipelineModes, PresentMode, RenderError, RenderMode,
|
||||
ShadowMapMode, ShadowMode, Vertex,
|
||||
};
|
||||
use common::assets::{self, AssetExt, AssetHandle, ReloadWatcher};
|
||||
use common_base::span;
|
||||
@ -135,6 +135,7 @@ enum State {
|
||||
pub struct Renderer {
|
||||
device: Arc<wgpu::Device>,
|
||||
queue: wgpu::Queue,
|
||||
adapter: wgpu::Adapter,
|
||||
surface: wgpu::Surface,
|
||||
surface_config: wgpu::SurfaceConfiguration,
|
||||
|
||||
@ -350,12 +351,21 @@ impl Renderer {
|
||||
let format = surface_capabilities.formats[0];
|
||||
info!("Using {:?} as the surface format", format);
|
||||
|
||||
let present_mode = other_modes.present_mode.into();
|
||||
let surface_config = wgpu::SurfaceConfiguration {
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
format,
|
||||
width: dims.width,
|
||||
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,
|
||||
view_formats: Vec::new(),
|
||||
};
|
||||
@ -555,6 +565,7 @@ impl Renderer {
|
||||
Ok(Self {
|
||||
device,
|
||||
queue,
|
||||
adapter,
|
||||
surface,
|
||||
surface_config,
|
||||
|
||||
@ -675,6 +686,16 @@ impl Renderer {
|
||||
/// Get the pipelines mode.
|
||||
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
|
||||
/// Nested timings immediately follow their parent
|
||||
/// Returns Vec<(how nested this timing is, label, length in seconds)>
|
||||
|
Loading…
Reference in New Issue
Block a user