ruffle
ruffle copied to clipboard
webgl: Support basic BitmapData.draw on webgl backend
Not a lot of code, is it :) The non-renderer side is based on @torokati44 's wgpu BitmapData.draw branch, and that could be restarted on top of this. TBH I'd love for someone else to take this over, I feel more comfortable in AVM2 land :)
Missing stuff that needs to be fixed, in order from "necessary for MVP" to "maybe later", with no clear border:
-
~~bug: blending of transparent stuff is broken, I couldn't figure it out.~~ Fixed by Mike's premultiplied alpha PRs
-
~~bug: current implementation of
attachBitmapmeans that drawing on attached bitmap will reflect on the screen 1 frame late~~ -
no antialiasing, especially visible on text
-
it's slow, halfway because
readPixelsneeds to wait till GPU finishes work, halfway because the implementation ofcopy_pixels_to_bitmapdatais really slow , especially the manual blending logic. -
- need to figure out the long-term solution for this ~~and the attachBitmap bug~~, especially permanently storing on GPU side and not loading to CPU unless AS actually needs it. This might help blending too.
Example profile (I dropped some samples to make it smaller, so readPixels should have more like 45%). You can see the readPixels just waiting, and manual copy+blend loop being damn slow.

- clip rect argument
- ~~supporting
BitmapDataas argument~~ - ~~- smoothing flag~~
- blending parameter (needed for collision detection in Learn 2 Fly)
- ~~what about other backends?~~
I'll post some more screenshots in a comment.
Fancy pants 2 (https://github.com/ruffle-rs/ruffle/issues/4646): backgrounds show up :)

Mind Bender (https://github.com/ruffle-rs/ruffle/issues/2296): backgrounds show up, but 170 synchronous draw calls in a row are slooow - the game lags for ~10s until this shows up:

(note: it is my belief that not calling readPixels would make draw() calls slightly more gpu-asynchronous and lag the VM less, but I don't have a guarantee here. If it turns out that it's slow no matter what... we have a problem.)
From the other reports we have:
-- #6336 and #5139 seem to be displayed perfectly now.
-- #4122 is playable as collisions are fixed.
-- #6584 is improved.
https://github.com/ruffle-rs/ruffle/issues/2013 slightly improved, now displays wind and rainbow

I'm working on a related feature locally - BitmapData.draw for the webgpu backend.
My earlier work here may be relevant @Aaron1011: https://github.com/ruffle-rs/ruffle/discussions/4288
I've incorporated the AVM1-specific logic from this PR into https://github.com/ruffle-rs/ruffle/pull/7254, which adds support for the wgpu backend.
#6629 is this PR. Did you mean to refer to, or comment under, https://github.com/ruffle-rs/ruffle/pull/7254 perhaps?