-
Notifications
You must be signed in to change notification settings - Fork 485
Description
Why?
Flixel currently supports two rendering methods: DRAW_TILES (which is an old name that doesn't make sense anymore because it actually uses quads/triangles now but I digress) and BLITTING.
DRAW_TILES is used when hardware acceleration is available on all targets except for Flash. It uses the FlxDrawItems and OpenFL's Graphics API to handle the rendering.
BLITTING is used when hardware acceleration isn't available, or when targeting Flash. In this case everything is drawn to a bitmap and most of the rendering process is handled by Flixel itself.
Because of the difference in how the two rendering APIs work, Flixel (and Flixel users) need to account for this in their code. This leads to a bunch of if (FlxG.renderBlit) checks making code harder to read and harder to maintain. By using a single render method we'd eliminate these issues and make it possible to use the same rendering code across all Flixel targets.
How?
The aforementioned OpenFL Graphics API handles both software and hardware rendering. It should be as simple as just setting the render method to DRAW_TILES everywhere, and well, it is!* See: #3408 (comment), #3408 (comment).
*Flash requires a change in FlxDrawQuadsItem to be able to render anything.
While it's not completely perfect, it seems to be 90% functional out of box. There's a few issues on certain targets: In the case of FlxBunnyMark, the background doesn't render on HTML5 and appears a bit distorted on Hashlink. I'm not too certain but I think these might be OpenFL level issues.
Performance seems to differ between targets. Testing a slightly modified version of FlxBunnyMark (no background or UI) with 5k bunnies results in a performance improvement on HTML5 (~47fps with software DRAW_TILES vs ~28fps with BLITTING), but a performance drop on Hashlink (~4.6fps with software DRAW_TILES vs ~6fps with BLITTING).
Implementation
To start, we could probably introduce an opt-in compiler define to enable DRAW_TILES everywhere whilst deprecating various blitting related fields. Then, in a later major version, make DRAW_TILES the default everywhere and get rid of blitting code.
I could probably start a pull request for this myself.
TL;DR
Get rid of blitting, use quads and triangles everywhere and let OpenFL handle software rendering.