View Full Version : Best drawing option ?

04-07-2010, 06:52 AM
Hi all, first post here !

I'm currently reading the red book and juste finished reading chapter 2 on the different options for drawing geometric data.

Also, I'm working on a UI Toolkit (Game Interface) in OpenGL-ES (I know I do not have all the options shown in the red book) and I'm trying different drawing options without really knowing what was best performance wise. I tried glDrawArrays and glDrawElements, both working and I think it might be better using glDrawElements since I do not have to specify multiple time the same vertex.

Since I'm doing a UI kit, I do not have a lot of vertex but still would like to use the best technique. Right now, I'm rendering my Component (like a button, frame, slider, label, etc) individually. Here is the code :

if(mSprite != NULL && mSprite->texture != NULL && mSprite->texture->validData)

glVertexPointer(2, GL_FLOAT,0,vertices);
glTexCoordPointer(2, GL_FLOAT, 0, mSprite->texCoords);

glColor4f(mColor.mRed, mColor.mGreen, mColor.mBlue, mColor.mAlpha);
glBindTexture(GL_TEXTURE_2D, mSprite->texture->textureID);


glTranslatef(mPos.x + mVisualPositionOffset.x,mPos.y + mVisualPositionOffset.y, 0.0f);
glScalef(mSize.x*mScale.x + mVisualSizeOffset.x, mSize.y*mScale.y + mVisualSizeOffset.y, 1.0f);
// glDrawArrays(GL_TRIANGLES, 0, 6);
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_SHORT,in dices);


//Reset Matrix for next use

And here the arrays I'm using :

static const GLfloat vertices[] =
0.0f, 0.0f,
0.0f, -1.0f,
1.0f, -1.0f,
1.0f, 0.0f

static const GLushort indices[] = {0,1,3, 3,1,2};

So any recommendation would be welcome !

04-08-2010, 01:03 PM
That's an awful lot of matrix crapola to draw a quad.

Keep it simpler, MUCH simpler.

Manipulate the float values in the array to accomplish your translate and scale and don't do all that GL work.

Also you can draw a tristrip and just make your indices 0, 1, 4, 3. if you do this it's probably cleaner to switch verts 3 & 4, but I hear indexed triangles are first class citizens these days thanks to caching, so your code is probably acceptable w.r.t. their use.

04-08-2010, 01:41 PM
So basically It would be a lot faster to actually modify the vertice data in the array than calling the matrix transformation. OK, I will do that instead then but for more complex geometry (3D stuff), what would be fastest ?

I mean I saw some tutorials (Nate Robins tutors) about VBO for example and Update time is longer while drawing time is faster compared to simple glDrawArrays call.

What about VAO ?

What I want to know is basically this : Is there a rule of thumb on which technique to use if we want the best performance or does it depends of the type of drawing we want to do ?

Still so much to learn !
Thanks in advance !


04-16-2010, 04:20 PM
For complex 3D stuff you want to manipulate the matrix stack.

You've got 4 vertices and a load of matrix crapola per quad, VBOs are the least of your worries right now, but there are tradeoffs with any dispatch mechanism. It depends on your data and your usage, and your platform and even your driver, but under those circumstances you'll be trying to squeeze the last ounce of performance from your card.

If quads are a placeholder for more complex cotent then stick with matrices.

04-19-2010, 10:10 AM
Thanks, answered some questions !