Skip to content

Commit

Permalink
make example testing compatible with shaderoty
Browse files Browse the repository at this point in the history
  • Loading branch information
Korijn committed Jan 5, 2024
1 parent 6be6810 commit 6fc6942
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/shadertoy_star.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# test_example = true
from shadertoy import Shadertoy

shader_code = """
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def unload_module():
request.addfinalizer(unload_module)

# render a frame
img = np.asarray(example.canvas.draw())
img = np.asarray(example.shader.snapshot())

# check if _something_ was rendered
assert img is not None and img.size > 0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dev = [
"wheel",
"setuptools",
"twine",
"glfw",
]

[tool.setuptools.dynamic]
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extend-ignore = E501, E203, B006, B007, D

per-file-ignores =
examples/*.py: F821,F722
shadertoy/__init__.py: F401


[coverage:report]
Expand Down
2 changes: 1 addition & 1 deletion shadertoy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .shadertoy import Shadertoy # noqa: F401,F403
from .shadertoy import Shadertoy, ShadertoyChannel


__version__ = "0.1.0"
Expand Down
7 changes: 6 additions & 1 deletion shadertoy/shadertoy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import ctypes
import collections
import os

import wgpu
from wgpu.gui.auto import WgpuCanvas, run
Expand Down Expand Up @@ -341,7 +342,7 @@ class Shadertoy:
# todo: support multiple render passes (`i_channel0`, `i_channel1`, etc.)

def __init__(
self, shader_code, resolution=(800, 450), offscreen=False, inputs=[]
self, shader_code, resolution=(800, 450), offscreen=None, inputs=[]
) -> None:
self._uniform_data = UniformArray(
("mouse", "f", 4),
Expand All @@ -356,6 +357,10 @@ def __init__(
self._shader_code = shader_code
self._uniform_data["resolution"] = resolution + (1,)

# if no explicit offscreen option was given
# inherit wgpu-py force offscreen option
if offscreen is None and os.environ.get("WGPU_FORCE_OFFSCREEN") == "true":
offscreen = True
self._offscreen = offscreen

if len(inputs) > 4:
Expand Down

0 comments on commit 6fc6942

Please sign in to comment.