From 4158fed109ae789cb3ca7ff53c2790797a3b4087 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 9 Aug 2026 17:10:03 -0700 Subject: refactor Texture into its own thing as part of this, the command pools are moved from window dressing to permanent note also how mip count is a value computed by loading the texture, and used when creating the sampler, which is part of the window dressing. the assumption about how it's computed will have to change when we support multiple textures, but for now we settle for just pushing the assumption to the top level. Force-Push: yes Change-Id: I545c53feedc99628fbe943120798fe66fe9e065b --- src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9fb89bc..6601982 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![deny(unsafe_code)] use crate::error::*; use crate::graphics::model::Model; +use crate::graphics::texture::Texture; use crate::graphics::permanent::{ PermanentGraphicsState, GraphicsStateForReinit }; @@ -37,6 +38,7 @@ struct Surreality { for_reinit: RefCell>, window_dressing: RefCell>, render_state: RefCell>, + texture: RefCell>, is_minimized: bool, is_reinit_queued: bool, frame_index: usize, @@ -54,6 +56,7 @@ impl Surreality { for_reinit: RefCell::new(None), window_dressing: RefCell::new(None), render_state: RefCell::new(None), + texture: RefCell::new(None), is_minimized: false, is_reinit_queued: false, frame_index: 0, @@ -69,19 +72,21 @@ impl Surreality { let (permanent, for_reinit, enable_anisotropy, enable_swapchain) = PermanentGraphicsState::new(event_loop)?; + let (texture, mip_count) = Texture::new(&permanent)?; + if enable_swapchain.0 { let window_dressing = WindowDressing::new(&permanent, &for_reinit, - enable_anisotropy)?; + enable_anisotropy, mip_count)?; let mut render_state = RenderState::new(&permanent, &for_reinit, - &window_dressing)?; + &window_dressing, &texture)?; let (vertices, indices) = load_obj()?; - render_state.set_model(Model::new(vertices, indices, - &permanent, &window_dressing)?); + render_state.set_model(Model::new(vertices, indices, &permanent)?); *self.window_dressing.get_mut() = Some(window_dressing); *self.render_state.get_mut() = Some(render_state); } + *self.texture.get_mut() = Some(texture); *self.permanent.get_mut() = Some(permanent); *self.for_reinit.get_mut() = Some(for_reinit); @@ -94,9 +99,10 @@ impl Surreality { && let Some(window_dressing) = self.window_dressing.borrow_mut().as_mut() && let Some(render_state) = self.render_state.borrow_mut().as_mut() + && let Some(texture) = self.texture.borrow_mut().as_mut() { window_dressing.reinit(permanent, for_reinit)?; - render_state.reinit(permanent, for_reinit, &window_dressing)?; + render_state.reinit(permanent, for_reinit, &window_dressing, &texture)?; } Ok(()) @@ -221,12 +227,16 @@ impl Drop for Surreality { if let Some(window_dressing) = self.window_dressing.replace(None) { if let Some(render_state) = self.render_state.replace(None) { - render_state.destroy(&permanent.device, &window_dressing); + render_state.destroy(&permanent); } window_dressing.destroy(&permanent.device); } + if let Some(texture) = self.texture.replace(None) { + texture.destroy(&permanent.device); + } + if let Some(for_reinit) = self.for_reinit.replace(None) { for_reinit.destroy(&permanent.device); } -- cgit 1.4.1