Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas interface #87

Merged
merged 5 commits into from
Apr 14, 2020
Merged

Canvas interface #87

merged 5 commits into from
Apr 14, 2020

Conversation

almarklein
Copy link
Collaborator

@almarklein almarklein commented Apr 14, 2020

Closes #86

The WebGPU spec defines part of the API on the canvas object. I can see how this makes sense in JS, where there is one type of canvas, under the control of the browser. But for us it makes the code a bit "entangled".

Therefore I moved these API functions to the device. One tricky part was how to do the presenting (aka swap the buffers). Then I realized that getting the texture view from the swap-chain, and presenting it, are two actions that always go in pairs. Python context managers are awesome for this, so this is what the swap-chain now uses.

So ...

  • There now is a WgpuCanvasInterafce class with three methods.
  • I added a test to make sure that using just this interface works, even without subclassing that class.
  • The WgpuCanvaseBase subclasses the interface and ads convenience stuff.
  • Clarify the docs.
  • configure_swap_chain and get_swap_chain_preferred_format are now methods of device instead of canvas.
  • The swap-chain has one API-thing: use it as a context manager to get the texture view to render to.

@almarklein almarklein changed the title Canva sinterface Canvas interface Apr 14, 2020
@Korijn
Copy link
Collaborator

Korijn commented Apr 14, 2020

Looks good. I'm not entirely sure how this would work when rendering to an image directly without a GUI but I get the impression you've thought about this already.

@almarklein
Copy link
Collaborator Author

I'm not entirely sure how this would work when rendering to an image directly without a GUI

Then you won't need any canvas stuff. You call request_adapter with canvas=None, and you never call device.configure_swap_chain().

@almarklein almarklein merged commit a0e6c56 into master Apr 14, 2020
@almarklein almarklein deleted the canvasinterface branch April 14, 2020 15:57
@almarklein almarklein mentioned this pull request Apr 15, 2020
34 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple wrappers and GUI convenience utilities
2 participants