Optimizing text drawing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
molul
Party member
Posts: 255
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Optimizing text drawing

Post by molul » Sun Jul 22, 2018 9:08 am

I'm making a frontend for a Rockchip RK3066 board, which apparently has a, say, "modest" GPU. A friend of mine is helping me with building LÖVE for this board (he's modifying SDL and other dependencies as needed), and I'm changing my LÖVE code to improve performance. So far we've managed to make the frontend run at 40-50fps (to give you an idea, it runs at 450fps on my Windows gaming laptop).

We currently have two bottlenecks: textures (I'm working on making spritebatches to improve this) and texts. Correct me if I'm wrong but texts seem to be drawn treating each character as a texture, which results in a very noticable slowdown when there the character amount displayed is high. Printing 50 characters is around 4-7fps slower than printing 5 characters.

I tried changing from using print of printf to display texts, to making a canvas and drawing the texts there, then drawing the canvas (less drawing calls). It got a little better, but eats too much GPU memory (I have around 200 different texts, and could have more) and the application is still very slow. So I tried drawing the canvas in runtime. Not bad, but switching texts quickly resulted in higher slowdowns. So I switched back to printing texts with print and printf again.

I wonder if there's anything we could do, either in LÖVE code or in SDL or any other dependency. My friend still wants to try to add triple buffer to SDL, but we're starting to run out of ideas. Any advice would be greatly appreciated :)

User avatar
Nixola
Inner party member
Posts: 1935
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Optimizing text drawing

Post by Nixola » Sun Jul 22, 2018 9:12 am

How are you printing stuff exactly? Could the bottleneck be in string manipulation rather than lg.print itself? Could using a Text object help? I'd help more but I'm afraid I don't have access to devices of similar power.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
molul
Party member
Posts: 255
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Optimizing text drawing

Post by molul » Sun Jul 22, 2018 9:56 am

Thanks for replying :)

I'm mostly using love.graphics.printf, as I need to print texts (sometimes with more than one line) centered, and one of the texts (the currently selected option, displayed at the bottom of the UI) is constantly changing. So I think a Text object wouldn't help :(

It would be cool if Text objects had more features, like settin justification and wrapping.

EDIT: oh wait! I just noticed the :addf function. This might actually help. I'll investigate.

User avatar
pgimeno
Party member
Posts: 1264
Joined: Sun Oct 18, 2015 2:58 pm

Re: Optimizing text drawing

Post by pgimeno » Sun Jul 22, 2018 10:26 am

For what I heard, Text objects are sort of spritebatches of text.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories
The Microsoft Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

User avatar
raidho36
Party member
Posts: 1685
Joined: Mon Jun 17, 2013 12:00 pm

Re: Optimizing text drawing

Post by raidho36 » Sun Jul 22, 2018 11:49 am

40 fps is not half bad for a device like this. Industry "standard" framerate is in single digits.

Try modifying the love.run function not to call the love.draw unless somewhere in love.update an appropriate flag is set. Don't update the screen either. Cut down on smooth animations to make use of this. Pro tip: people don't actually appreciate having to wait on animations to complete. They're cool to look at the first time, but it gets old fast - if you work with it every day you will hate it. Also try to cram as much data and controls on the same screen as possible - people positively hate navigating through dozens of screens to do simple things. If you have to split them, do extensive usage testing to figure out what's used together or in sequence - don't just split by category; don't make assumptions in general.

User avatar
molul
Party member
Posts: 255
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Optimizing text drawing

Post by molul » Mon Jul 23, 2018 6:51 am

The problem is there are a few nice animations always running ^_^U Of course I'll cut them down if I can't reach 60fps but I'd rather not while there are other things to try.

I believe the sprite batches and text objects might give me 7-10 fps more, which would make the application run at 50-60. Hopefully triple buffer would give the last boost, and if not, I'll have to cut whatever is needed to.



EDIT: well, using drawable texts got me around 3fps more. Yay! :D I also found out I was always drawing a few objects out of the viewport, so I culled them and got another couple of fps. I'm currently on 47 to 60fps depending on the section, and I think the last LÖVE build my friend sent me is a bit slower due to constantly printing SDL debug messages on the console, so it might be 50-60 now. Let's see how spritebatches help ^^

EDIT2: spritebatches my ass. I only had to make texture atlases of all my textures and properly define quads ^_^U

User avatar
Nixola
Inner party member
Posts: 1935
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Optimizing text drawing

Post by Nixola » Mon Jul 23, 2018 9:51 am

molul wrote:
Mon Jul 23, 2018 6:51 am
EDIT2: spritebatches my ass. I only had to make texture atlases of all my textures and properly define quads ^_^U
If you're using LÖVE 11, that's probably because it automatically batches draw calls with the same texture
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
molul
Party member
Posts: 255
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Optimizing text drawing

Post by molul » Mon Jul 23, 2018 10:37 am

Yes, I'm using LÖVE 11, fortunately :) Using texture atlases and quads added another couple of frames. Not bad!

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests