"Simple" OpenGLES (2D) efficiency question .. for OpenGLES experts!

Member
Posts: 43
Joined: 2009.10
Post: #16
fattoh, one thing I noticed that I don't think anyone mentioned. If you're in 2D, what are you using 3D triangles? I'm not sure if this will make a noticeable difference, but you can specify strictly 2D triangles. In 2D, each triangle data only needs 2 floats per vertex then, and to set up your vertex pointer, you just switch the following:

Code:
glVertexPointer(2, GL_FLOAT, 0, happyVertices);



You should also consider interleaving your data. If you just have position and texture coords, then this means you set up a struct such as:

Code:
typedef struct _texturedVertex{
    GLfloat position[2];
    GLfloat texCoord[2];
}

Then in your draw routine given an array called vertices of type texturedVertex, you just tell it the stride in the ptr functions and offset the start address:

Code:
glVertexPointer(2, GL_FLOAT, sizeof(texturedVertex), &vertices[0].position);
    glTexCoordPointer(2, GL_FLOAT, sizeof(texturedVertex), &vertices[0].texCoord);


The iPhone supposedly runs much faster when you interleave your vertex data, though I haven't personally done any comparisons.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.04
Post: #17
So that's what that is for! That is an amazing tip ALERUS, THANKS. Fantastic.

I will also try interleaving my data, when I have a lot of triangles. Thanks.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.04
Post: #18
For completeness and the sake of anyone reading this in the year 3000 and trying to work out OpenGLES. I forgot to mention that:

if you use "method B", and indeed if you doing more than one sprite (say, a small number), and you call that draw method one time for each sprite you are doing...

of course you'll have to wrap your translate, rotate etc. drawing code inside a pair of push/pop statements to push and pop the matrix situation on and off each time. (otherwise all your individual positions will sort of add together during the frame construction, of course.)

I have no idea if glPushMatrix(), glPopMatrix() are FAST or not.

(Again, the overall idea of using MethodB if you have LOTS of sprites is probably not the way to go, so you'd only be using a handful of sprites anyway, so it likely doesn't matter much.)
Quote this message in a reply
Member
Posts: 64
Joined: 2008.10
Post: #19
alerus Wrote:fattoh, one thing I noticed that I don't think anyone mentioned. If you're in 2D, what are you using 3D triangles? I'm not sure if this will make a noticeable difference, but you can specify strictly 2D triangles. In 2D, each triangle data only needs 2 floats per vertex then, and to set up your vertex pointer, you just switch the following:

Code:
glVertexPointer(2, GL_FLOAT, 0, happyVertices);



You should also consider interleaving your data. If you just have position and texture coords, then this means you set up a struct such as:

Code:
typedef struct _texturedVertex{
    GLfloat position[2];
    GLfloat texCoord[2];
}

Then in your draw routine given an array called vertices of type texturedVertex, you just tell it the stride in the ptr functions and offset the start address:

Code:
glVertexPointer(2, GL_FLOAT, sizeof(texturedVertex), &vertices[0].position);
    glTexCoordPointer(2, GL_FLOAT, sizeof(texturedVertex), &vertices[0].texCoord);


The iPhone supposedly runs much faster when you interleave your vertex data, though I haven't personally done any comparisons.

I have and I haven't seen any improvement in performance. At least if there is any improvement it's too small to measure Rasp
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #20
Interleaving really only matters when you are submitting a big array of vertexes at a time. I usually just do it for readability. By using structs you can do something like vert[4].vertex.x or vert[3].texcoord.y instead of trying to figure out the correct index offset by hand.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL1.3/OpenGLES and iPhone Orientation SparkyNZ 10 10,290 Apr 13, 2011 02:38 AM
Last Post: SparkyNZ
  Newbie question: simple Sesame Street-like app redbaron 2 2,940 Apr 25, 2010 12:42 PM
Last Post: redbaron
  Simple 3D Game Engine(well not that simple) geoface 9 8,765 Apr 14, 2010 04:08 AM
Last Post: sio2interactive
  Using Obj-c in latest xcode opengles tempalte kendric 0 1,754 Dec 7, 2009 09:27 AM
Last Post: kendric
  Why Does OpenGLES Appear To Leak Memory? muleskinner 2 3,432 Oct 22, 2009 04:54 AM
Last Post: muleskinner