summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-05-27 13:56:25 -0400
committerLLLL Colonq <llll@colonq>2025-05-27 13:56:25 -0400
commit71b13aa5dd17ab2548dfb2c579b93921a4b449fe (patch)
tree020deb443b90b1664aaaac9b6901160dea0973eb
parent42583de2e0691ea28f4ac62b301ccbd3384c71d9 (diff)
Add bind_initial
-rw-r--r--crates/teleia/src/lib.rs3
-rw-r--r--crates/teleia/src/scene.rs2
-rw-r--r--crates/teleia/src/state.rs8
-rw-r--r--crates/teleia/src/texture.rs7
4 files changed, 16 insertions, 4 deletions
diff --git a/crates/teleia/src/lib.rs b/crates/teleia/src/lib.rs
index 5e9e03b..6d2713f 100644
--- a/crates/teleia/src/lib.rs
+++ b/crates/teleia/src/lib.rs
@@ -68,7 +68,6 @@ where
log::info!("hello computer, starting up...");
- let resize = !options.contains(Options::NORESIZE);
let (rglfw, rwindow, gl, events) = {
use glfw::fail_on_errors;
let mut glfw = glfw::init(glfw::fail_on_errors!()).expect("failed to initialize GLFW");
@@ -119,7 +118,7 @@ where
let ctx = Box::leak(Box::new(context::Context::new(
glfw, window, gl,
- w as f32, h as f32, resize,
+ w as f32, h as f32, options,
)));
let game = Box::leak(Box::new(gnew(ctx)));
let st = Box::leak(Box::new(state::State::new(&ctx)));
diff --git a/crates/teleia/src/scene.rs b/crates/teleia/src/scene.rs
index 3146b5d..ccef8f6 100644
--- a/crates/teleia/src/scene.rs
+++ b/crates/teleia/src/scene.rs
@@ -347,6 +347,8 @@ impl Scene {
.and_then(|m| m.base_color_texture)
.and_then(|t| self.textures.get(t)) {
tex.bind(ctx);
+ } else {
+ texture::Texture::bind_initial(ctx);
}
p.mesh.render(ctx);
}
diff --git a/crates/teleia/src/state.rs b/crates/teleia/src/state.rs
index 51ef683..763f302 100644
--- a/crates/teleia/src/state.rs
+++ b/crates/teleia/src/state.rs
@@ -522,8 +522,12 @@ impl State {
let now = now(ctx);
let diff = now - self.last;
- // update, if enough time has accumulated since last update
- if diff >= DELTA_TIME {
+ // skip update if not enough time has accumulated since last update
+ // we truncate to below the target framerate, which is pretty gross
+ // the intention here is to allow vsync to dictate the framerate most of the time
+ // however, we need some way to limit the framerate on monitors with >60Hz
+ // so we use this to skip frames. in general this should be tested more on faster monitors
+ if diff >= DELTA_TIME.trunc() as f64 {
self.last = now;
self.tick += 1;
game.update(ctx, self)?;
diff --git a/crates/teleia/src/texture.rs b/crates/teleia/src/texture.rs
index dce7607..1682500 100644
--- a/crates/teleia/src/texture.rs
+++ b/crates/teleia/src/texture.rs
@@ -74,6 +74,13 @@ impl Texture {
}
}
+ pub fn bind_initial(ctx: &context::Context) {
+ unsafe {
+ ctx.gl.active_texture(glow::TEXTURE0);
+ ctx.gl.bind_texture(glow::TEXTURE_2D, None);
+ }
+ }
+
pub fn bind_index(&self, ctx: &context::Context, idx: u32) {
unsafe {
ctx.gl.active_texture(glow::TEXTURE0 + idx);