From 42583de2e0691ea28f4ac62b301ccbd3384c71d9 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 27 May 2025 00:03:55 -0400 Subject: Update clear color for non-overlay cases --- crates/teleia/src/context.rs | 16 +++++++++------- crates/teleia/src/framebuffer.rs | 3 ++- crates/teleia/src/lib.rs | 2 +- crates/teleia/src/state.rs | 23 ++++++++++++++++++++++- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/crates/teleia/src/context.rs b/crates/teleia/src/context.rs index 9f0d4ad..89592be 100644 --- a/crates/teleia/src/context.rs +++ b/crates/teleia/src/context.rs @@ -1,3 +1,5 @@ +use crate::Options; + use glow::HasContext; #[cfg(target_arch = "wasm32")] @@ -17,7 +19,7 @@ extern { pub struct Context { pub render_width: f32, pub render_height: f32, - pub resize: bool, + pub options: Options, pub glfw: std::cell::RefCell, pub window: std::cell::RefCell, pub gl: glow::Context, @@ -30,7 +32,7 @@ pub struct Context { pub struct Context { pub render_width: f32, pub render_height: f32, - pub resize: bool, + pub options: Options, pub window: winit::window::Window, pub gl: glow::Context, pub emptyvao: glow::VertexArray, @@ -52,13 +54,13 @@ impl Context { } #[cfg(not(target_arch = "wasm32"))] - pub fn new(glfw: std::cell::RefCell, window: std::cell::RefCell, gl: glow::Context, render_width: f32, render_height: f32, resize: bool) -> Self { + pub fn new(glfw: std::cell::RefCell, window: std::cell::RefCell, gl: glow::Context, render_width: f32, render_height: f32, options: Options) -> Self { let emptyvao = unsafe { gl.create_vertex_array().expect("failed to initialize vao") }; let ret = Self { render_width, render_height, - resize, + options, glfw, window, gl, emptyvao, @@ -69,7 +71,7 @@ impl Context { } #[cfg(target_arch = "wasm32")] - pub fn new(window: winit::window::Window, gl: glow::Context, render_width: f32, render_height: f32, resize: bool) -> Self { + pub fn new(window: winit::window::Window, gl: glow::Context, render_width: f32, render_height: f32, options: Options) -> Self { let emptyvao = unsafe { gl.create_vertex_array().expect("failed to initialize vao") }; @@ -79,7 +81,7 @@ impl Context { let ret = Self { render_width, render_height, - resize, + options, window, gl, emptyvao, @@ -111,7 +113,7 @@ impl Context { #[cfg(target_arch = "wasm32")] pub fn maximize_canvas(&self) { - if self.resize { + if !self.options.contains(Options::NORESIZE) { web_sys::window() .and_then(|win| win.document()) .and_then(|doc| { diff --git a/crates/teleia/src/framebuffer.rs b/crates/teleia/src/framebuffer.rs index db808e4..3542b0f 100644 --- a/crates/teleia/src/framebuffer.rs +++ b/crates/teleia/src/framebuffer.rs @@ -1,5 +1,6 @@ use glow::HasContext; +use crate::Options; use crate::context; pub struct Framebuffer { @@ -12,7 +13,7 @@ pub struct Framebuffer { impl Framebuffer { pub fn screen(ctx: &context::Context) -> Self { #[cfg(target_arch = "wasm32")] - let (windoww, windowh): (f32, f32) = if ctx.resize { + let (windoww, windowh): (f32, f32) = if !ctx.options.contains(Options::NORESIZE) { ctx.window.inner_size().into() } else { (ctx.render_width, ctx.render_height) diff --git a/crates/teleia/src/lib.rs b/crates/teleia/src/lib.rs index 3990892..5e9e03b 100644 --- a/crates/teleia/src/lib.rs +++ b/crates/teleia/src/lib.rs @@ -222,7 +222,7 @@ where (window, gl) }; - let ctx = Box::leak(Box::new(context::Context::new(window, gl, w as f32, h as f32, resize))); + let ctx = Box::leak(Box::new(context::Context::new(window, gl, w as f32, h as f32, options))); ctx.maximize_canvas(); let game = Box::leak(Box::new(gnew(ctx))); let st = Box::leak(Box::new(state::State::new(&ctx))); diff --git a/crates/teleia/src/state.rs b/crates/teleia/src/state.rs index 48fd4c3..51ef683 100644 --- a/crates/teleia/src/state.rs +++ b/crates/teleia/src/state.rs @@ -113,6 +113,21 @@ impl Display for Keycode { write!(f, "{:?}", self.kc) } } +#[cfg(target_arch = "wasm32")] +impl Serialize for Keycode { + fn serialize(&self, serializer: S) -> Result + where S: serde::Serializer { + self.kc.serialize(serializer) + } +} +#[cfg(target_arch = "wasm32")] +impl<'de> Deserialize<'de> for Keycode { + fn deserialize(deserializer: D) -> Result + where D: serde::Deserializer<'de> { + let kc = winit::keyboard::KeyCode::deserialize(deserializer)?; + Ok(Self { kc }) + } +} #[cfg(not(target_arch = "wasm32"))] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -523,7 +538,13 @@ impl State { game.render(ctx, self)?; self.screen.bind(&ctx); - ctx.clear_color(glam::Vec4::new(0.0, 0.0, 0.0, 0.0)); + ctx.clear_color( + if ctx.options.contains(crate::Options::OVERLAY) { + glam::Vec4::new(0.0, 0.0, 0.0, 0.0) + } else { + glam::Vec4::new(0.0, 0.0, 0.0, 1.0) + } + ); ctx.clear(); self.shader_upscale.bind(&ctx); self.render_framebuffer.bind_texture(&ctx); -- cgit v1.2.3