Loads of small objects

Started by
3 comments, last by zedz 14 years, 10 months ago
Heya all! I'm currently creating a 2D engine in OpenGL, just as an experiment really. The way I learned OpenGL is with direct mode, using glBegin(GL_QUADS) calls to draw my sprites. I'm currently achieving something like 20FPS for 10.000 quads. I haven't kept up with recent developments, but it seems these days there are other ways with better performance, things like VBOs. So what is the best way to send loads and loads of small objects (basically 2 triangles per sprite) to the GPU? Keep in mind that these objects will change position (and scale and angle) every frame. My current idea is to create one big VBO, put all the coordinates in there (transformed on the CPU) and send it over to the GPU. Will that increase performance? Also, how do I combine that with texture mapping? Think animations: each sprite might have a different texture. Can I batch-upload a list of texture id's to be used together with the vertex data? Or perhaps I should use one big texture and create appropriate texture coordinates? Ah, so many questions. Anyone with some answers? Thanks!
Advertisement
I have 1 big VBO (or Vertex Array fallback). The renderer just throws quads at it, batching for as long as it can, drawing whenever there's a state (eg texture) change.

It's simple to implement, so it's worth seeing if that will give you the performance you need. Combine your sprites to minimize state changes and loading.

If that doesn't get you there, I suspect you'll need to make the renderer sort your commands by state changes--which will make blending harder.
Anthony Umfer
for dynamic stuff you could get away with vertex arrays and for static stuff, put it into VBOs. you shall also draw rather triangles (not polygons) than quads, it's what hardware can draw and if u use quads, the driver has some more work.

20000 quads is not that much, if they're small, you might even draw sprites in software an being faster. if they're bigger, you might not be vertex limited, so vertex arrays might really be enough to get speed. your bottleneck is probably the API-calls to pass vertex by vertex.

like CadetUmfer said, try to combine as many triangles as possible into one drawcall. best would be to have just one big texture atlas with all those sprite textures you need and then to draw all triangles in one call.
Okay, thanks, seems about what I thought then.

I've currently implemented it with one big texture and one VBO with interleaved position/texture data. Seems to work nice. I've seen a small performance increase, but when handling many objects I'm mostly CPU-bound in other code at the moment.

Oh well. I suppose that allows me to add stuff that puts some more load on the GPU then...
>>for dynamic stuff you could get away with vertex arrays and for static stuff, put it into VBOs. you shall also draw rather triangles (not polygons) than quads, it's what hardware can draw and if u use quads, the driver has some more work.

the first part is correct but the 2nd perhaps not, a couple of weeks ago on of the lead guys at nvidia mentioned there hardware does quads i.e. it doesnt change them to 2 triangles.
Ild use quads regaurdless due to the shape fits most particles better (which are roundish or squarish) than a triangle, since fill is much more likely to cause a slowdown than the number of vertices

This topic is closed to new replies.

Advertisement