HaxeFlixel / HaxeFlixel/flixel

Proposal: Replace BLITTING with DRAW_TILES everywhere

Open
#3,468 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

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: https://github.com/HaxeFlixel/flixel/issues/3408#issuecomment-2783717616, https://github.com/HaxeFlixel/flixel/issues/3408#issuecomment-2796528475.

*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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the rendering paths that use DRAW_TILES and BLITTING, especially FlxDrawQuadsItem, FlxDrawItems, and the FlxG.renderBlit checks. Use the modified FlxBunnyMark results and the linked issue comments as initial context, then verify behavior on HTML5, Hashlink, Flash, and other targets. Done means a staged opt-in path works across targets without the listed rendering regressions.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics, game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.