Performance questions

(I post it here too so it haves more visibility, the original is on the NME mailing list) Im using drawTriangles and (begin/end)fill to programmatically draw grass. Each grass is composed of 3 or 4 sprites, each sprite contains 2 triangles (1 triangle in…

Viewing 1 to 4 (4 Total)
Performance questions

DanielUranga

DanielUranga
Total Posts: 29
Joined: September 06, 2011

(I post it here too so it haves more visibility, the original is on the NME mailing list)
Im using drawTriangles and (begin/end)fill to programmatically draw grass. Each grass is composed of 3 or 4 sprites, each sprite contains 2 triangles (1 triangle in the case of the end of a grass). Then the grass is animated using rotations of the sprites.
This works perfect when running on a mac, but on Android phone this method seems to slow when animating 50 grass instances.

My question is, if I want to do this programmatically (each grass can be affected, for example, by wind) ¿Im doing it the right way? How performance of graphics.beginFill -> drawTriangles/drawRect/draw* -> endFill compares to graphics.drawTiles?

If I draw all the triangles inside one single sprite, is it faster than drawing 2 triangles per sprite? And if I want a triangle rotation, is faster to rotate the sprite wich contains it, or its better to redraw the triangles with new points calculated using rotation matrix multiplication? How NME internally handles the rotation of a sprite containing a triangle vs rotation of a sprite containing a bitmap?

Im sorry for such a bunch of questions, any information is appreciated. Benchmarks results would be useful, but im interested on internal details too.

I think this is an interesting topic for anyone using graphics primitives to draw things, so it would be nice to document it here.

Tags:
Posted on May 29, 2012 at 2:54 PM

Huge

Huge
Total Posts: 546
Joined: October 07, 2011

Re: Performance questions

Hi,
I think it will probably be fastest with one massive triangle list - especially if everything is changing every frame. You will have to do the rotations yourself - but I think this should be ok - not much different to what drawTiles must do itself. There is some overhead per sprite - probably more than updating a few triangles.
But as you say, do the benchmarking.
Another possibility might be to render off, say, 20 variations/rotations of the grass into a single bitmap, and then use draw-tiles animating through the variations.

Hugh

Posted on May 30, 2012 at 12:03 AM

DanielUranga

DanielUranga
Total Posts: 29
Joined: September 06, 2011

Re: Performance questions

Thanks Hugh, I did some benchmarks, here the results:

(tested on a Samsung galaxy 5500, on Android, with 1000 rotating triangles)
A) Drawing each triangle inside a sprite, then rotate the sprite with Sprite.rotation. I got 11 fps.

B) Drawing each triangle inside a sprite, then rotate the sprite by multiplying each one of its points by a rotation matrix and redraw the triangle. 11 fps too.

C) Drawing all triangles on a single sprite, then rotate the sprite by multiplying each one of its points by a rotation matrix and redraw the triangle. Absolutly smooth, but I see things like more than 100 fps, I dont know why such an high framerate since I limited it to 45 fps...

I attached the source code of the project, if someone modify it please post the new version. Im interested in other's people results too.

Attachments: TriangleBenchmaks.zip
Posted on June 01, 2012 at 5:08 PM

PaoloOliverio

PaoloOliverio
Total Posts: 4
Joined: June 06, 2012

Re: Performance questions

strange you see 100fps as devices normally have vsync set from 56 to 60 so probalby something influence the counter in some subtle way.
c) is the only solution to make sense with the actual api.
It can seem fast but it is quite slower than what it is actually possible directly in opengles.
On good devices you can exepect a realistic 50000 to 200000 triangles per frame at interactive rates udk citadel demo have peaks of 80000 at 20/30 fps on an iphone 3gs and believe it or not it isn't as optimized as someone could expect.
However 500 triangles is more than what you normally need in an average 2d game.
I just also want to remember that not all the games require 30 or 60 fps, some game mechanics runs perfectly smooth at 20 fps all depends about how stable the frame rate is.On mobile make perfectly sense to fix the framerate to the lowest one that feels playable.

Posted on June 06, 2012 at 10:32 AM