11How context objects work
22========================
33
4- This page documents the working bentween the ``RenderCanvas `` and the context object.
4+ This page documents the inner working between the ``RenderCanvas `` and the context object.
55
66
77Introduction
@@ -23,16 +23,13 @@ then present the result to the screen. For this, the canvas provides one or more
2323 │ │ ──bitmap──► │ │
2424 └─────────┘ └────────┘
2525
26- This means that for the context to be able to present to any canvas, it must
27- support *both * the 'bitmap' and 'screen' present-methods. If the context prefers
28- presenting to the screen, and the canvas supports that, all is well. Similarly,
29- if the context has a bitmap to present, and the canvas supports the
30- bitmap-method, there's no problem.
26+ If the context is a ``BitmapContext ``, and the canvas supports the bitmap present-method,
27+ things are easy. Similarly, if the context is a ``WgpuContext ``, and the canvas
28+ supports the screen present-method, the presenting is simply delegated to wgpu.
3129
32- It get's a little trickier when there's a mismatch, but we can deal with these
33- cases too. When the context prefers presenting to screen, the rendered result is
34- probably a texture on the GPU. This texture must then be downloaded to a bitmap
35- on the CPU. All GPU API's have ways to do this.
30+ When there's a mismatch, we use different context sub-classes that handle the conversion.
31+ With the ``WgpuContextToBitmap `` context, the rendered result is inside a texture on the GPU.
32+ This texture is then downloaded to a bitmap on the CPU that can be passed to the canvas.
3633
3734.. code-block ::
3835
@@ -41,11 +38,10 @@ on the CPU. All GPU API's have ways to do this.
4138 ──render──► | Context │ | │ Canvas │
4239 │ │ └─bitmap──► │ |
4340 └─────────┘ └────────┘
44- download from gpu to cpu
41+ download to CPU
4542
46- If the context has a bitmap to present, and the canvas only supports presenting
47- to screen, you can use a small utility: the ``BitmapPresentAdapter `` takes a
48- bitmap and presents it to the screen.
43+ With the ``BitmapContextToScreen `` context, the bitmap is uploaded to a GPU texture,
44+ which is then rendered to screen using the lower-level canvas-context from ``wgpu ``.
4945
5046.. code-block ::
5147
@@ -54,46 +50,6 @@ bitmap and presents it to the screen.
5450 ──render──► | Context │ │ │ Canvas │
5551 │ │ ──bitmap─┘ │ |
5652 └─────────┘ └────────┘
57- use BitmapPresentAdapter
53+ upload to GPU
5854
5955 This way, contexts can be made to work with all canvas backens.
60-
61- Canvases may also provide additionally present-methods. If a context knows how to
62- use that present-method, it can make use of it. Examples could be presenting
63- diff images or video streams.
64-
65- .. code-block ::
66-
67- ┌─────────┐ ┌────────┐
68- │ │ │ │
69- ──render──► | Context │ ──special-present-method──► │ Canvas │
70- │ │ │ |
71- └─────────┘ └────────┘
72-
73-
74- Context detection
75- -----------------
76-
77- Anyone can make a context that works with ``rendercanvas ``. In order for ``rendercanvas `` to find, it needs a little hook.
78-
79- .. autofunction :: rendercanvas._context.rendercanvas_context_hook
80- :no-index:
81-
82-
83- Context API
84- -----------
85-
86- The class below describes the API and behavior that is expected of a context object.
87- Also see https://github.com/pygfx/rendercanvas/blob/main/rendercanvas/_context.py.
88-
89- .. autoclass :: rendercanvas._context.ContextInterface
90- :members:
91- :no-index:
92-
93-
94- Adapter
95- -------
96-
97- .. autoclass :: rendercanvas.utils.bitmappresentadapter.BitmapPresentAdapter
98- :members:
99- :no-index:
0 commit comments