Skip to content

Refactor FlxBitmapText rendering in renderTile #3394

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

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Mar 11, 2025

Previously, FlxBitmapText, on text/size/font changes, would cache the position of every character it draws, this includes caching each border character individually, but this did very to actually reduce rendering time, the real bottle-neck came from clipping each frame to the clipRect. By removing this caching in renderTile, we open up the possibility for better features, such as per character text effects

To stress test I added this to my test state

override function draw()
{
	for (i in 0...100)
		super.draw();
	}
}

I noticed a huge perf difference with the following code:

final stringLong = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

final text = new FlxBitmapText(10, 10, stringLong);
text.fieldWidth = 200;
text.setBorderStyle(OUTLINE, FlxColor.BLACK, 1);
text.autoSize = false;
text.multiLine = false;
text.clipRect = FlxRect.get(0, 0, fieldWidth, lineHeight);
add(text);
old new
Screenshot 2025-03-11 at 10 20 17 AM Screenshot 2025-03-11 at 10 22 10 AM

A 98% reduction in render time

I also tried multiline with a cliprect
Old:
Screenshot 2025-03-11 at 10 24 27 AM
New:
Screenshot 2025-03-11 at 10 27 13 AM

A 99.6% reduction in rendering time

I also tested all of these without a clipRect and with renderBlit and found no difference in performance (all tests ran at 120fps with 100 draw calls per frame)

@Geokureli Geokureli changed the title Improve FlxBitmapText rendering when using renderTile with clipRect Refactor FlxBitmapText rendering in renderTile Mar 19, 2025
@Geokureli Geokureli marked this pull request as draft March 19, 2025 16:40
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 this pull request may close these issues.

1 participant