[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] OBJ loader using VBOs



On Sat, Dec 4, 2010 at 3:37 PM, Christopher Night <cosmologicon@xxxxxxxxx> wrote:
For this model, glEnableClientState gets called once for vertices, normals, and texcoords. There are 5 materials, each with one glBindTexture and two glDrawArrays (one for triangles, one for quads). So the total calls per render is:

2 x glEnable/glDisable
1 x glFrontFace
3 x vbo.bind
3 x glEnableClientState
10 x glDrawArrays
5 x glBindTexture
4 x glColor

And I'm rendering 40 sprites, so I'm doing this 40 times per frame. I'm assuming that in a real application, each model would have its own separate VBOs. Is that what I'm doing wrong? Or is there something else?
Buffer binding is one of the slowest GL calls you can do, short of transferring huge chunks of data around (glTexImage2D, glReadPixels, etc.).  State changing is one of the worst things you can do for efficiency, especially on top of a scripting language where the overhead is much higher.  You have 40 sprites, each with 3 VBO bindings, and 5 texture bindings.  If I'm understanding right, that's 120 VBO bindings and 200 texture bindings!  Transferring this data across the bus once (when you put it in a display list) will speed things up greatly, but you'll notice that the framerate in 6 is still much lower than in 2 or 4. 

If you're just drawing sprites, chances are you don't need very many textures.  At the very least, you can use a texture atlas, or batch calls by the texture required.

I don't know exactly the situation you're in here, but unless the 40 sprites all have different geometry, you need only bind the data once, and then call glDrawArrays 40 times. 

In general, try to minimize binding calls, such as glUseShader, glBindFramebuffer, glBindTexture, and glBindBuffer. 
The reason it takes so long to load on 2 is generating the display list. This method was taken from the objloader on the wiki, and it involves 1646 glVertex3f calls, one for each vertex in the model, and similarly with glNormal and glTexCoords.

Thanks again!

-Christopher
Ian