batch opengl calls - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: batch opengl calls (/thread-1212.html)
Pages: 1 2
batch opengl calls - kendric - Jun 1, 2009 07:00 AM
So people have talked about some performance gains(though the amount varies) by having just one batch of vertex renders per texture instead of many. My question is, can this only be done with quads? I use a triangle strip of size 2 to render quads as I heard it was faster slightly. But if I tried to specify more verticies it would connect my triangles together. I haven't used the quads functionality yet but I assume you specify all 4 corners so perhaps this is how people are doing it. There might be a trade off between quads and triangle strips that could cancel the bonus you get from a single call but thats beyond my knowledge level.
batch opengl calls - ThemsAllTook - Jun 1, 2009 07:20 AM
I'm not entirely sure about the relative performance gains (it's unlikely you'll be able to get a reliable answer other than by trying it yourself), but you'll most likely want to be looking at GL_TRIANGLES instead of GL_QUADS. GL_QUADS doesn't exist in OpenGL ES, and wouldn't be a very natural choice for replacing GL_TRIANGLE_STRIP anyway.
batch opengl calls - ShiftZ - Jun 1, 2009 11:51 AM
kendric Wrote:So people have talked about some performance gains(though the amount varies) by having just one batch of vertex renders per texture instead of many.
If you can do it by minor efforts, then you pobably should do that (GL_TRIANGLES see above)
As for me, i use sprites with animated textures, and to have one render call per texture i have to reconstruct vertex array for each texture every frame, and i see that unacceptable.
batch opengl calls - warmi - Jun 1, 2009 02:57 PM
ShiftZ Wrote:If you can do it by minor efforts, then you pobably should do that (GL_TRIANGLES see above)
You don't have to do that if your texture contains all animation frames.
All you need to to is to set correctly the current texture matrix (to scale and translate your texture coordinates ) and the GPU will do it for you.
batch opengl calls - ShiftZ - Jun 2, 2009 03:06 AM
warmi Wrote:You don't have to do that if your texture contains all animation frames.
I cannot see any way to do that.
Sprites could be anywhere, and have any anim frame id, and to render all of them in one draw call i should reconstruct vertex array and also tex coords array every new frame, and texture \ model \ view matrix could be set up only once before actuall draw call.
batch opengl calls - warmi - Jun 2, 2009 07:36 AM
ShiftZ Wrote:I cannot see any way to do that.
Yeah, if you are rendering multiple sprites within the same batch then yeah.
batch opengl calls - kendric - Jun 3, 2009 08:41 AM
Thanks for the answers. I can move from triangle strips to triangles and check the performance. My drawing s all done through a few functions so I should be able to just cache vertex's until I hit a new texture and render it all.
batch opengl calls - kendric - Jul 11, 2009 06:29 PM
Well, I finally got around to trying this. It works for some stuff and others its all wonky. I think its most likely related to when there are more then one atlas's being used on the screen at the same time as the one screen that works fine has images from only one atlas.
Anyhow I thought I would post this code as if we can get it working it might be a nice library item for other people to use. If you see anything wrong here that might be causing the problems let me know. also may have to do with rotation as my images are drawing at the wrong rotations in some cases(but not others). I used to a seperate triangle strip of size 2 for each render and this code attempts to render it all in one go per texture.
batch opengl calls - kendric - Jul 11, 2009 06:43 PM
I think it is rotations. If I am building a big vertex array but then a rotation is performed, a render has to happen before the rotation and then right before you pop the stack on your model. Ill put this in later and post if it did the trick.
batch opengl calls - maximile - Jul 12, 2009 09:28 AM
Check the Apple docs on optimising OpenGL ES. They suggest using triangle strips with degenerate triangles connecting them. Sounds pretty inelegant to me, so I just use triangles and get adequate performance. Batching certainly made a big difference for me.
batch opengl calls - kendric - Jul 13, 2009 05:22 PM
I scrapped this whole thing because it makes doing rotations and translations a big mess. You have to render after and before each one. I dont think its worth it for my code. I do a translation on a large # of my thigns that are drawing.
One thing I did notice is that my bitmaped texture font rendering is eating up a lot of time. I may need to move to prerendered textures and 1 render rather then drawing each frame.
batch opengl calls - warmi - Jul 14, 2009 12:02 AM
The only way you can get separate parts of batched geometry to rotate independently is by rotating them with your own code.
It certainly makes a lot of sense for 2d rendering when you are displaying independently rotated/scaled/positioned quads (sprites).
It is much faster to rotate/scale 4 vertices than issuing a batch call for just 4 vertices.
batch opengl calls - kendric - Jul 15, 2009 06:36 AM
Rotating the verticies won't rotate the image though right? My game supports 360 degree rotation of the guys. From my profiling, I got the load down from 40% game loop 40% render to like 20% game loop 60% render. The only thing left I can think of is batching my opengl calls. I do about 70-100 renders per frame, each being its own call to this function. I'm very interested to see if there is a way around this without giving up my arbitrarily rotated images.
batch opengl calls - warmi - Jul 15, 2009 07:49 AM
kendric Wrote:Rotating the verticies won't rotate the image though right? My game supports 360 degree rotation of the guys.
Of course it will - otherwise the whole thing would be pointless.
batch opengl calls - kendric - Jul 15, 2009 08:09 AM
So if i render a square(2 triangles) and i specify the texture co-ordinates unrotated, and I specify the vertex's each rotated around its center by 45 degrees i will get the exact same thing as if i rotated normally 45 degrees and drew it with un rotated vertexes?