Skip to content

Commit

Permalink
Add tests for offscreen and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipitis committed Nov 5, 2023
1 parent 2cc0600 commit 1885692
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_util_shadertoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,56 @@ def test_shadertoy_glsl():
assert shader.shader_type == "glsl"

shader._draw_frame()

def test_shadertoy_offscreen():
# Import here, because it imports the wgpu.gui.auto
from wgpu.utils.shadertoy import Shadertoy # noqa

shader_code = """
void shader_main(out vec4 fragColor, vec2 frag_coord) {
vec2 uv = frag_coord / i_resolution.xy;
if ( length(frag_coord - i_mouse.xy) < 20.0 ) {
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
}else{
fragColor = vec4( 0.5 + 0.5 * sin(i_time * vec3(uv, 1.0) ), 1.0);
}
}
"""

shader = Shadertoy(shader_code, resolution=(800, 450), offscreen=True)
assert shader.resolution == (800, 450)
assert shader.shader_code == shader_code
assert shader.shader_type == "glsl"
assert shader._offscreen is True

def test_shadertoy_snapshot():
# Import here, because it imports the wgpu.gui.auto
from wgpu.utils.shadertoy import Shadertoy # noqa

shader_code = """
void shader_main(out vec4 fragColor, vec2 frag_coord) {
vec2 uv = frag_coord / i_resolution.xy;
if ( length(frag_coord - i_mouse.xy) < 20.0 ) {
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
}else{
fragColor = vec4( 0.5 + 0.5 * sin(i_time * vec3(uv, 1.0) ), 1.0);
}
}
"""

shader = Shadertoy(shader_code, resolution=(800, 450), offscreen=True)
frame1a = shader.snapshot(time_float=0.0, mouse_pos=(0, 0, 0, 0,))
frame2a = shader.snapshot(time_float=1.2, mouse_pos=(100, 200, 0, 0,))
frame1b = shader.snapshot(time_float=0.0, mouse_pos=(0, 0, 0, 0,))
frame2b = shader.snapshot(time_float=1.2, mouse_pos=(100, 200, 0, 0,))

assert shader.resolution == (800, 450)
assert shader.shader_code == shader_code
assert shader.shader_type == "glsl"
assert shader._offscreen is True
assert frame1a == frame1b
assert frame2a == frame2b

0 comments on commit 1885692

Please sign in to comment.