Jump to content

Easy way to improve performance and reduce draw calls


Noid
 Share

Recommended Posts

My game UI had three icons, each with one with a text. So in code I was adding them in what I thought was a logical way: "level" icon and text, "score" icon and text and "deaths" icon and text. 

 

This resulted in phaser using a separate draw call for each one. It's not that important on desktop but on mobile every performance gain counts. 

 

The fix was to simply arrange the code so that all the icons are added one after the other and then all the texts are added one after the other. Now there's only one draw call for all the icons and one for all the texts.

 

This might be pretty obvious for experienced programmers but I'm sure there must be some other junior devs making the same mistake I made. 

Link to comment
Share on other sites

Does this trick works for both webgl and canvas renderer ?

I've tested it only with webgl

 

Nice tip, thanks. How do you measure draw calls?

There is a canvas inspector in Firefox(at least in the latest Nightly). Open the Developer Tools, click on the gear icon and add a tick on Canvas. It'll enable the canvas debugger. I couldn't find the same feature in Chrome. The same can be enabled as an experimental feature in Chrome http://www.html5rocks.com/en/tutorials/canvas/inspection/ 

Link to comment
Share on other sites

This is pure gold. THank you again. I was able to get rid of few unnecessary draw calls and get small fps boost.

 

Now I'm wondering - is it possible to get rid of very 1st draw call? Which clears whole canvas.

 

post-5731-0-51603200-1437653769.png

Link to comment
Share on other sites

This is pure gold. THank you again. I was able to get rid of few unnecessary draw calls and get small fps boost.

 

Now I'm wondering - is it possible to get rid of very 1st draw call? Which clears whole canvas.

 

attachicon.gifClipboard-2.png

I don't know if it's exposed through the API but you can modify Pixi.js  and set clearBeforeRender: false

 

https://github.com/photonstorm/phaser/blob/v2.3.0/src/pixi/Pixi.js

 

I haven't tested it, though.

Link to comment
Share on other sites

I don't know if it's exposed through the API but you can modify Pixi.js  and set clearBeforeRender: false

 

https://github.com/photonstorm/phaser/blob/v2.3.0/src/pixi/Pixi.js

 

I haven't tested it, though.

Yes, it is exposed game.renderer.clearBeforeRender = false

 

I got -1 draw call and didn't notice any visual glitches. I will test this more extensively on different devices.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...