summaryrefslogtreecommitdiff
path: root/crates/throwshade/src
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-02-17 22:54:50 -0500
committerLLLL Colonq <llll@colonq>2025-02-17 22:54:50 -0500
commitd7c175733194b406990cb0113aab2b26836e8edb (patch)
treec95a478ce568eeffd2186548453acb7f86da17ee /crates/throwshade/src
parent80ae56c9e28454cb351b0ad3217adc2484e67107 (diff)
Set the shader from JS
Diffstat (limited to 'crates/throwshade/src')
-rw-r--r--crates/throwshade/src/lib.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/crates/throwshade/src/lib.rs b/crates/throwshade/src/lib.rs
index c20b5fb..402be0e 100644
--- a/crates/throwshade/src/lib.rs
+++ b/crates/throwshade/src/lib.rs
@@ -34,16 +34,25 @@ impl ThrowShade {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
- struct Game {}
+ struct Game {
+ throwshade: ThrowShade,
+ }
impl Game {
pub async fn new(_ctx: &context::Context) -> Self {
- Self {}
+ Self {
+ throwshade: ThrowShade::new(),
+ }
}
}
impl state::Game for Game {
fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> {
- ctx.clear_color(glam::Vec4::new(1.0, 0.0, 0.0, 1.0));
- ctx.clear();
+ if let Some(s) = &self.throwshade.shader {
+ s.bind(ctx);
+ s.set_vec2(ctx, "resolution", &glam::Vec2::new(ctx.render_width, ctx.render_height));
+ let elapsed = (st.tick - self.throwshade.tickset) as f32 / 60.0;
+ s.set_f32(ctx, "time", elapsed);
+ ctx.render_no_geometry();
+ }
Some(())
}
}
@@ -57,6 +66,10 @@ cfg_if::cfg_if! {
pub async fn set_shader(s: &str) {
contextualize(|ctx, st, g: &mut Game| {
log::info!("set shader: {}", s);
+ if let Err(e) = g.throwshade.set(ctx, st, &s) {
+ log::warn!("error compiling shader: {}", e);
+ g.throwshade.shader = None;
+ }
});
}
}