From 66515823c0db33f2b7ecb476c86511a29c7ab792 Mon Sep 17 00:00:00 2001 From: nuts-rice Date: Mon, 26 Feb 2024 17:16:27 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=8A=20shader=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comfy/examples/fragment-shader.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/comfy/examples/fragment-shader.rs b/comfy/examples/fragment-shader.rs index 66dc59e..4c6b343 100644 --- a/comfy/examples/fragment-shader.rs +++ b/comfy/examples/fragment-shader.rs @@ -18,6 +18,7 @@ fn setup(_state: &mut GameState, _c: &mut EngineContext) { } fn update(state: &mut GameState, c: &mut EngineContext) { + debug!("shader instance: {:?}", get_current_shader()); if state.my_shader_id.is_none() { state.my_shader_id = Some( // Comfy now supports shader hot reloading. We'll create a simple shader and provide @@ -57,7 +58,7 @@ fn update(state: &mut GameState, c: &mut EngineContext) { } let shader_id = state.my_shader_id.unwrap(); - + debug!("shader instance: {:?}", get_current_shader()); // First draw with a default shader. draw_comfy(vec2(-2.0, 0.0), WHITE, 0, splat(1.0)); @@ -69,14 +70,17 @@ fn update(state: &mut GameState, c: &mut EngineContext) { }); // When we switch a shader the uniforms will get their default value + // Loading of this uniform has something to do with change to Ordering::seqCst + debug!("shader_id: {:?}", shader_id.0); + use_shader(shader_id); + debug!("shader instance: {:?}", get_current_shader()); let time = get_time() as f32; + set_uniform_f32("time", time); // We can only set one and then draw and the other uniform will be set // to the default value we specified when creating the shader. - set_uniform_f32("time", time); - draw_comfy(vec2(0.0, 0.0), WHITE, 0, splat(1.0)); // This will set "intensity" while retaining "time" from the previous set in this frame, as From 4dddd246812c77b0154c3bb0cbc9054ba1058018 Mon Sep 17 00:00:00 2001 From: nuts-rice Date: Mon, 26 Feb 2024 21:14:42 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=94=8A=20shader=20logs=20before=20use?= =?UTF-8?q?=5Fshader=20calls=20and=20after?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comfy/examples/fragment-shader.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/comfy/examples/fragment-shader.rs b/comfy/examples/fragment-shader.rs index 4c6b343..76d4d85 100644 --- a/comfy/examples/fragment-shader.rs +++ b/comfy/examples/fragment-shader.rs @@ -1,15 +1,18 @@ -use comfy::*; +use comfy::{num_traits::One, *}; simple_game!("Fragment Shader Example", GameState, setup, update); + pub struct GameState { pub my_shader_id: Option, + // pub my_shader_instance : Option, pub intensity: f32, } impl GameState { pub fn new(_c: &mut EngineState) -> Self { - Self { my_shader_id: None, intensity: 2.0 } + Self { my_shader_id: None, intensity: 2.0 , } + //my_shader_instance: None} } } @@ -18,8 +21,10 @@ fn setup(_state: &mut GameState, _c: &mut EngineContext) { } fn update(state: &mut GameState, c: &mut EngineContext) { - debug!("shader instance: {:?}", get_current_shader()); + debug!("get_current_shader : id: {:?}", get_current_shader().0); + debug!("shader id: {:?}", state.my_shader_id); if state.my_shader_id.is_none() { + //state.my_shader_instance = Some(ShaderInstanceId(1)); state.my_shader_id = Some( // Comfy now supports shader hot reloading. We'll create a simple shader and provide // both `static_source` which would be used in release builds allowing the game to be @@ -58,7 +63,10 @@ fn update(state: &mut GameState, c: &mut EngineContext) { } let shader_id = state.my_shader_id.unwrap(); - debug!("shader instance: {:?}", get_current_shader()); + + + debug!("shader_instance_id: {:?}", get_current_shader()); + //debug!("shader instance id {:?}", state.my_shader_instance.unwrap()); // First draw with a default shader. draw_comfy(vec2(-2.0, 0.0), WHITE, 0, splat(1.0)); @@ -71,12 +79,17 @@ fn update(state: &mut GameState, c: &mut EngineContext) { // When we switch a shader the uniforms will get their default value // Loading of this uniform has something to do with change to Ordering::seqCst - debug!("shader_id: {:?}", shader_id.0); - + debug!("shader_id: {:?}", shader_id); + use_shader(shader_id); use_shader(shader_id); - debug!("shader instance: {:?}", get_current_shader()); + + //debug!("shader instance id {:?}", state.my_shader_instance.unwrap()); + debug!("shader_id after use_shader 2X: {:?}", shader_id); + debug!("shader_instance_id after use_shader 2X : {:?}", get_current_shader()); let time = get_time() as f32; + + set_uniform_f32("time", time); // We can only set one and then draw and the other uniform will be set From 3c15a2f3dc35264872ffac180a196dd9fc06dba6 Mon Sep 17 00:00:00 2001 From: nuts-rice Date: Mon, 26 Feb 2024 21:17:44 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A9=B9=20fix=20fragment-shader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comfy/examples/fragment-shader.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/comfy/examples/fragment-shader.rs b/comfy/examples/fragment-shader.rs index 76d4d85..ee94b15 100644 --- a/comfy/examples/fragment-shader.rs +++ b/comfy/examples/fragment-shader.rs @@ -1,18 +1,16 @@ -use comfy::{num_traits::One, *}; +use comfy::{*}; simple_game!("Fragment Shader Example", GameState, setup, update); pub struct GameState { pub my_shader_id: Option, - // pub my_shader_instance : Option, pub intensity: f32, } impl GameState { pub fn new(_c: &mut EngineState) -> Self { Self { my_shader_id: None, intensity: 2.0 , } - //my_shader_instance: None} } } @@ -24,7 +22,6 @@ fn update(state: &mut GameState, c: &mut EngineContext) { debug!("get_current_shader : id: {:?}", get_current_shader().0); debug!("shader id: {:?}", state.my_shader_id); if state.my_shader_id.is_none() { - //state.my_shader_instance = Some(ShaderInstanceId(1)); state.my_shader_id = Some( // Comfy now supports shader hot reloading. We'll create a simple shader and provide // both `static_source` which would be used in release builds allowing the game to be @@ -65,7 +62,6 @@ fn update(state: &mut GameState, c: &mut EngineContext) { let shader_id = state.my_shader_id.unwrap(); - debug!("shader_instance_id: {:?}", get_current_shader()); //debug!("shader instance id {:?}", state.my_shader_instance.unwrap()); // First draw with a default shader. draw_comfy(vec2(-2.0, 0.0), WHITE, 0, splat(1.0)); @@ -79,13 +75,10 @@ fn update(state: &mut GameState, c: &mut EngineContext) { // When we switch a shader the uniforms will get their default value // Loading of this uniform has something to do with change to Ordering::seqCst - debug!("shader_id: {:?}", shader_id); use_shader(shader_id); use_shader(shader_id); //debug!("shader instance id {:?}", state.my_shader_instance.unwrap()); - debug!("shader_id after use_shader 2X: {:?}", shader_id); - debug!("shader_instance_id after use_shader 2X : {:?}", get_current_shader()); let time = get_time() as f32; From 8e3ffefa49279fb7ff253fe98a00f52cc921c0f7 Mon Sep 17 00:00:00 2001 From: nuts-rice Date: Mon, 26 Feb 2024 21:25:41 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8E=A8=20clippy,=20fmt,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comfy/examples/fragment-shader.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/comfy/examples/fragment-shader.rs b/comfy/examples/fragment-shader.rs index ee94b15..12533e6 100644 --- a/comfy/examples/fragment-shader.rs +++ b/comfy/examples/fragment-shader.rs @@ -1,8 +1,7 @@ -use comfy::{*}; +use comfy::*; simple_game!("Fragment Shader Example", GameState, setup, update); - pub struct GameState { pub my_shader_id: Option, pub intensity: f32, @@ -10,7 +9,7 @@ pub struct GameState { impl GameState { pub fn new(_c: &mut EngineState) -> Self { - Self { my_shader_id: None, intensity: 2.0 , } + Self { my_shader_id: None, intensity: 2.0 } } } @@ -19,8 +18,6 @@ fn setup(_state: &mut GameState, _c: &mut EngineContext) { } fn update(state: &mut GameState, c: &mut EngineContext) { - debug!("get_current_shader : id: {:?}", get_current_shader().0); - debug!("shader id: {:?}", state.my_shader_id); if state.my_shader_id.is_none() { state.my_shader_id = Some( // Comfy now supports shader hot reloading. We'll create a simple shader and provide @@ -60,9 +57,7 @@ fn update(state: &mut GameState, c: &mut EngineContext) { } let shader_id = state.my_shader_id.unwrap(); - - - //debug!("shader instance id {:?}", state.my_shader_instance.unwrap()); + // First draw with a default shader. draw_comfy(vec2(-2.0, 0.0), WHITE, 0, splat(1.0)); @@ -74,15 +69,12 @@ fn update(state: &mut GameState, c: &mut EngineContext) { }); // When we switch a shader the uniforms will get their default value - // Loading of this uniform has something to do with change to Ordering::seqCst + // TODO: why does this need to be called twice? use_shader(shader_id); use_shader(shader_id); - //debug!("shader instance id {:?}", state.my_shader_instance.unwrap()); - let time = get_time() as f32; - set_uniform_f32("time", time); // We can only set one and then draw and the other uniform will be set