summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-05-27 00:03:55 -0400
committerLLLL Colonq <llll@colonq>2025-05-27 00:03:55 -0400
commit42583de2e0691ea28f4ac62b301ccbd3384c71d9 (patch)
treefa3a3f8fd820d10c0e5a8e7dd847b34e77318a38
parentfa62367de73065ea6ca6da45d9c8745bb80a21e3 (diff)
Update clear color for non-overlay cases
-rw-r--r--crates/teleia/src/context.rs16
-rw-r--r--crates/teleia/src/framebuffer.rs3
-rw-r--r--crates/teleia/src/lib.rs2
-rw-r--r--crates/teleia/src/state.rs23
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<glfw::Glfw>,
pub window: std::cell::RefCell<glfw::PWindow>,
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<glfw::Glfw>, window: std::cell::RefCell<glfw::PWindow>, gl: glow::Context, render_width: f32, render_height: f32, resize: bool) -> Self {
+ pub fn new(glfw: std::cell::RefCell<glfw::Glfw>, window: std::cell::RefCell<glfw::PWindow>, 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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where S: serde::Serializer {
+ self.kc.serialize(serializer)
+ }
+}
+#[cfg(target_arch = "wasm32")]
+impl<'de> Deserialize<'de> for Keycode {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ 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);