Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Fix create_reloadable_sprite_shader in wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
darthdeus committed Dec 8, 2023
1 parent 425c404 commit c9fef18
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ EXAMPLE=fragment-shader
# default: wasm-build
# default: profile-startup
# default: bitmob
# default: example
default: wasm-egui-scaling
default: example
# default: example-wasm
# default: wasm-egui-scaling
# default: egui-demo
# default: lint
# default: test
Expand All @@ -53,6 +54,9 @@ bitmob:
example:
$(ENV_VARS) cargo run --example $(EXAMPLE) $(FLAGS)

example-wasm:
$(ENV_VARS) cargo run --example $(EXAMPLE) $(FLAGS) --target wasm32-unknown-unknown

egui-demo:
$(ENV_VARS) cargo run --bin egui-scaling

Expand Down
28 changes: 0 additions & 28 deletions comfy-wgpu/src/hot_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,6 @@ macro_rules! reloadable_shader_source {
};
}

/// Similar to `create_shader` but automatically hot reloads the shader on change.
/// Note that `create_reloadable_sprite_shader` will automatically call
/// `sprite_shader_from_fragment`, meaning your source should only contain the fragment part.
///
/// The user needs to provide a `ReloadableShaderSource` which contains the static source to be
/// embedded in the binary, as well as the path to the shader file path for hot reloading.
///
/// The [fragment_shader
/// example](https://github.com/darthdeus/comfy/blob/master/comfy/examples/fragment-shader.rs#L24-L57)
/// contains a full working example of how works.
pub fn create_reloadable_sprite_shader(
shaders: &mut ShaderMap,
name: &str,
reloadable_source: ReloadableShaderSource,
uniform_defs: UniformDefs,
) -> Result<ShaderId> {
let id = create_shader(
shaders,
name,
&sprite_shader_from_fragment(&reloadable_source.static_source),
uniform_defs,
)?;

watch_shader_path(&reloadable_source.path, id)?;

Ok(id)
}

pub fn watch_shader_path(
path: &str,
shader_id: ShaderId,
Expand Down
2 changes: 1 addition & 1 deletion comfy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use crate::game_loop::*;
// pub use crate::macros::*;
pub use crate::particles::*;
pub use crate::render::*;
// pub use crate::shaders::*;
pub use crate::shaders::*;
pub use crate::timer::*;
pub use crate::trail::*;
pub use crate::update_stages::*;
Expand Down
30 changes: 30 additions & 0 deletions comfy/src/shaders.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
// use miniquad::{BlendFactor, BlendState, BlendValue, Equation};
use crate::*;

/// Similar to `create_shader` but automatically hot reloads the shader on change.
/// Note that `create_reloadable_sprite_shader` will automatically call
/// `sprite_shader_from_fragment`, meaning your source should only contain the fragment part.
///
/// The user needs to provide a `ReloadableShaderSource` which contains the static source to be
/// embedded in the binary, as well as the path to the shader file path for hot reloading.
///
/// The [fragment_shader
/// example](https://github.com/darthdeus/comfy/blob/master/comfy/examples/fragment-shader.rs#L24-L57)
/// contains a full working example of how works.
pub fn create_reloadable_sprite_shader(
shaders: &mut ShaderMap,
name: &str,
reloadable_source: ReloadableShaderSource,
uniform_defs: UniformDefs,
) -> Result<ShaderId> {
let id = create_shader(
shaders,
name,
&sprite_shader_from_fragment(&reloadable_source.static_source),
uniform_defs,
)?;

#[cfg(not(target_arch = "wasm32"))]
watch_shader_path(&reloadable_source.path, id)?;

Ok(id)
}

// use crate::*;
// use notify::{event::AccessKind, Event, EventKind, RecursiveMode, Watcher};
Expand Down

0 comments on commit c9fef18

Please sign in to comment.