pygfx / rendercanvas

One canvas API, multiple backends
https://rendercanvas.readthedocs.io
BSD 2-Clause "Simplified" License
8 stars 0 forks source link

Scope: who can render to our canvas? #20

Closed almarklein closed 1 week ago

almarklein commented 2 weeks ago

Intro

Our canvas.get_context() always returns a WgpuCanvasContext. I think we can release this a bit, opening options for other tools that want to render to a canvas, without adding much complexity on our end. I did some thinking and experimenting today. In this issue I try to stick to the high-level ideas; I have a PR underway with implementation.

Rendering vs presenting

Let's get some terms straight. The context helps the user-code to render to a canvas. The context presents the result to the canvas. From the p.o.v. of RenderCanvas, we don't care what API the context provides the user with. We only care that the context presents the result in a way that the canvas supports.

            ┌─────────┐      ┌────────┐ 
            │         │      │        │ 
            │ Context │      │ Canvas │ 
            │         │      │        │ 
user        └─────────┘      └────────┘ 
    ───────►          ──────►           
     render            present          

Some thoughts / observations / statements

Proposal

To get a canvas:

The contract between the context and the canvas:

Future:

almarklein commented 2 weeks ago

BTW: a context being able to present to the screen means that it can make the result appear on screen based only on the window id.

Re opengl: I think its possible to create an OpenGL context that way, So if someone was to create an OpenGLContext that follows our rules, people can use that, and we don't have to care.

almarklein commented 2 weeks ago

Reading this the next morning. It's rather long, so let's try to summarize it:

Rendercanvas looks independent on wgpu, but right now you can only really render to it with wgpu. I propose to enable other contexts to present to it as well, by formalizing (and tweaking) the API between the canvas and the context. Contexts must support the render-methods that we already have, so the changes are quite minimal. The effect is that other rendering tools can use rendercanvas as well.