summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/config.rs b/src/config.rs
index c29a957..312cf91 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,4 +1,3 @@
-use std::borrow::Cow;
use std::num::NonZeroU32;
use winit::dpi::{LogicalPosition, LogicalSize};
@@ -60,7 +59,7 @@ pub struct RenderWindowConfig<'a> {
/// The window may be fullscreen
pub mode: WindowMode,
/// The title for the window
- pub title: Cow<'a, str>,
+ pub title: &'a str,
/// If true, a low-power device will be selected as the GPU, if possible
pub low_power: bool,
/// If true, Fifo mode is used to present frames. If false, then Mailbox or
@@ -78,7 +77,7 @@ impl<'a> Default for RenderWindowConfig<'a> {
default_width: NonZeroU32::new(640).unwrap(),
default_height: NonZeroU32::new(480).unwrap(),
mode: WindowMode::default(),
- title: "Alligator Game".into(),
+ title: "Alligator Game",
low_power: true,
vsync: true,
instance_capacity: 0,
@@ -87,12 +86,27 @@ impl<'a> Default for RenderWindowConfig<'a> {
}
impl<'a> RenderWindowConfig<'a> {
+ pub(crate) fn present_mode(
+ vsync: bool,
+ supported_modes: &[wgpu::PresentMode],
+ ) -> wgpu::PresentMode {
+ if vsync {
+ wgpu::PresentMode::Fifo
+ } else if supported_modes.contains(&wgpu::PresentMode::Mailbox) {
+ wgpu::PresentMode::Mailbox
+ } else if supported_modes.contains(&wgpu::PresentMode::Immediate) {
+ wgpu::PresentMode::Immediate
+ } else {
+ wgpu::PresentMode::Fifo
+ }
+ }
+
/// Create a `WindowBuilder` from the configuration given. This window is
/// initially invisible and must later be made visible.
pub(crate) fn to_window(&self) -> WindowBuilder {
// start building the window
let mut builder = WindowBuilder::new()
- .with_title(self.title.as_ref())
+ .with_title(self.title)
.with_visible(false)
.with_inner_size(LogicalSize::new(
self.default_width.get(),
@@ -143,15 +157,7 @@ impl<'a> RenderWindowConfig<'a> {
supported_modes: &[wgpu::PresentMode],
texture_format: wgpu::TextureFormat,
) -> wgpu::SurfaceConfiguration {
- let present_mode = if self.vsync {
- wgpu::PresentMode::Fifo
- } else if supported_modes.contains(&wgpu::PresentMode::Mailbox) {
- wgpu::PresentMode::Mailbox
- } else if supported_modes.contains(&wgpu::PresentMode::Immediate) {
- wgpu::PresentMode::Immediate
- } else {
- wgpu::PresentMode::Fifo
- };
+ let present_mode = Self::present_mode(self.vsync, supported_modes);
// configuration for the surface
wgpu::SurfaceConfiguration {