About off-screen rendering #4288
Replies: 2 comments
-
This also makes The Binding of Isaac look better, at least the parts covered by the offscreen buffer: |
Beta Was this translation helpful? Give feedback.
-
Also, at the moment, in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
A while ago, I started experimenting with off-screen rendering in Ruffle.
This will be needed for some features, such as:
BitmapData.draw()
methodcacheAsBitmap
propertyfilters
propertyAs the first is the one requiring the least amount of extra supporting work, that's what I started with.
Internals
See the four latest commits in this branch for my changes so far: https://github.com/torokati44/ruffle/commits/bitmapdata-draw-noconflictrebase
There have been some refactors done to the wgpu backend on
master
since then, so I couldn't easily rebase them, but the idea is there.The new
[begin|end]_frame_offscreen
methods would basically turn the renderer backends from a 2-state FSM (either there is a frame in progress, or not), into a 3-state FSM (no frame, onscreen frame, offscreen frame). This could perhaps be made explicit, and some asserts could be put in place, to ensure proper sequence of calls.My initial conclusion was that there shouldn't necessarily be a need for both an onscreen and an offscreen frame to be in progress at the same time.
Backends
The implementation for the
wgpu
backend was not that difficult, thanks to the already existing similar functionality for theexporter
package. I still had to fix some small bugs, and in the end struggled with asynchronity issues(?) when trying to properly resize the render target between "frames".As I have no experience with either of the web backends, I left the new methods as unimplemented stubs in those for now, but I imagine creating a
<canvas>
that is not in the DOM (or maybe it's justhidden
) could do the trick; or perhaps https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas would be needed.At the moment the image data is always copied back to a CPU-side array. Mostly for simplicity reasons.
This will be necessary for some things though.
BitmapData
always stores its data in "CPU-side memory" as it is now.Then, for example, until there are backend-native implementations of filters (maybe as shaders), applying filters will have to be done entirely by the CPU.
In the future, this could be optional, because for simple blend modes and the like, the actual data is not needed outside of the backend.
Results
The commits linked above have already, at least partially, fixed #3193 and #2296.

Also they make the character creator on https://www.dolldivine.com/star-wars-an-avatar-creator.php work better.
I also threw together a quick test that seemed to work just fine:
Questions
BitmapData.draw()
works acceptably well? The main remaining issue is the proper resizing of the offscreen render target between frames.Beta Was this translation helpful? Give feedback.
All reactions