summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/renderer.rs43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index 879a447..1b72e12 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -80,7 +80,6 @@ impl Default for WindowMode {
}
#[derive(Clone, Debug, PartialEq, Eq)]
-// TODO to consider: don't allow the x and y to be too big
// TODO window icon
pub struct RenderWindowConfig {
/// The width of the window, once initialized
@@ -127,12 +126,14 @@ impl Renderer {
///
/// Returns a [`NoGpu`] error if no device could be detected that can
/// display to the window
- // TODO make it possible to use without winit (ie, use a bitmap in memory as a surface)
+ // TODO make it possible to use without a window (ie, use a bitmap in memory as a surface)
+ // TODO this function needs to be smaller
#[allow(clippy::missing_panics_doc)]
pub fn new(
config: RenderWindowConfig,
event_loop: &EventLoop<()>,
) -> Result<Self, NewRendererError> {
+ // start building the window
let mut builder = WindowBuilder::new()
.with_title(config.title)
.with_inner_size(LogicalSize::new(
@@ -181,7 +182,6 @@ impl Renderer {
let instance = wgpu::Instance::new(wgpu::Backends::all());
// the surface is the part of the screen we'll draw to
- // TODO guarantee the window to stay open longer than the surface
let surface = unsafe { instance.create_surface(&window) };
let power_preference = if config.low_power {
@@ -253,21 +253,17 @@ impl Renderer {
})
}
- /// Get the current logical size of the window. This adapts to the
- /// window's scale factor
- fn logical_size(&self) -> LogicalSize<u32> {
- self.window
- .inner_size()
- .to_logical(self.window.scale_factor())
- }
-
- // TODO return error for zero-sized windows
- fn resize_renderer(&mut self, size: PhysicalSize<u32>) {
- if size.width > 0 && size.height > 0 {
- self.config.height = size.height;
- self.config.width = size.width;
- self.surface.configure(&self.device, &self.config);
+ /// Resize just the renderer. The window will remain unchanged
+ fn resize_renderer(&mut self, size: PhysicalSize<u32>) -> Option<()> {
+ if size.width == 0 || size.height == 0 {
+ return None;
}
+
+ self.config.height = size.height;
+ self.config.width = size.width;
+ self.surface.configure(&self.device, &self.config);
+
+ Some(())
}
/// Renders a new frame to the window
@@ -315,16 +311,15 @@ impl Renderer {
Ok(())
}
- pub fn run(mut self, event_loop: EventLoop<()>) {
+ /// Run the renderer indefinitely
+ pub fn run(mut self, event_loop: EventLoop<()>) -> ! {
event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent { window_id, event } => {
if window_id == self.window.id() {
match event {
WindowEvent::Resized(size) => {
- if size.width > 0 && size.height > 0 {
- self.config.height = size.height;
- self.config.width = size.width;
- self.surface.configure(&self.device, &self.config);
+ if self.resize_renderer(size).is_none() {
+ log::error!("Somehow the window was resized to zero?");
}
}
WindowEvent::CloseRequested => *control_flow = ControlFlow::ExitWithCode(0),
@@ -334,7 +329,9 @@ impl Renderer {
}
Event::RedrawRequested(window_id) => {
if window_id == self.window.id() {
- _ = self.render();
+ if let Err(e) = self.render() {
+ log::error!("{}", e);
+ }
}
}
Event::MainEventsCleared => {