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

Blocking render call #471

Closed
Korijn opened this issue Mar 3, 2024 · 4 comments
Closed

Blocking render call #471

Korijn opened this issue Mar 3, 2024 · 4 comments

Comments

@Korijn
Copy link
Collaborator

Korijn commented Mar 3, 2024

Make it possible to render a new frame synchronously; in other words, a public API to call canvas._draw_frame_and_present directly. Do we have this?

Relates to pygfx/pygfx#667

@almarklein
Copy link
Member

almarklein commented Mar 4, 2024

We don't have this for normal canvases, but the offscreen canvas does exactly that:

def draw(self):
"""Perform a draw and get the resulting image.
The image array is returned as an NxMx4 memoryview object.
This object can be converted to a numpy array (without copying data)
using ``np.asarray(arr)``.
"""
return self._draw_frame_and_present()

Users could use the private canvas._draw_frame_and_present for now. I'm a little worried, if we make this a public method, how this affects e.g. async code, once we implement that.

@almarklein
Copy link
Member

Relates to #391

@almarklein
Copy link
Member

I implemented this in #618. Some context I found along the way: It's not a matter of just calling _draw_frame_and_present(). Well, it is for glfw, for qt that'd result in flicker, because the drawing is done outside qt's draw event. Fortunately, the systems that need it (qt and wx) both have a method to force a repaint. For the jupyter backend we can also force the drawing, which will basically feed images to the browser until the websocket buffer fills up.

Another, more friendly, approach for supporting uses-cases for drawing inside a loop, could be to have an async method, that can request a draw and then await for that draw to have occurred.

@almarklein
Copy link
Member

Implemented in rendercanvas.

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 a pull request may close this issue.

2 participants