diff --git a/examples/shadertoy_star.py b/examples/shadertoy_star.py index 780e6f9..bcd1556 100644 --- a/examples/shadertoy_star.py +++ b/examples/shadertoy_star.py @@ -1,3 +1,4 @@ +# test_example = true from shadertoy import Shadertoy shader_code = """ diff --git a/examples/tests/test_examples.py b/examples/tests/test_examples.py index 7633295..3a9c586 100644 --- a/examples/tests/test_examples.py +++ b/examples/tests/test_examples.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1549f6a..214e367 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dev = [ "wheel", "setuptools", "twine", + "glfw", ] [tool.setuptools.dynamic] diff --git a/setup.cfg b/setup.cfg index 2fb0efc..9a45c97 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,7 @@ extend-ignore = E501, E203, B006, B007, D per-file-ignores = examples/*.py: F821,F722 + shadertoy/__init__.py: F401 [coverage:report] diff --git a/shadertoy/__init__.py b/shadertoy/__init__.py index 8b3c589..9a7b3ea 100644 --- a/shadertoy/__init__.py +++ b/shadertoy/__init__.py @@ -1,4 +1,4 @@ -from .shadertoy import Shadertoy # noqa: F401,F403 +from .shadertoy import Shadertoy, ShadertoyChannel __version__ = "0.1.0" diff --git a/shadertoy/shadertoy.py b/shadertoy/shadertoy.py index d475c35..590f012 100644 --- a/shadertoy/shadertoy.py +++ b/shadertoy/shadertoy.py @@ -1,6 +1,7 @@ import time import ctypes import collections +import os import wgpu from wgpu.gui.auto import WgpuCanvas, run @@ -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), @@ -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: