CheeseCakeMan
|
|
« on: February 15, 2017, 06:45:07 AM » |
|
Graphics performance hasn't been a problem in my game so far, so just using SFML and issuing a ton of draw calls was fine, until now. I haven't had much exposure to OpenGL yet so perhaps the solution is obvious to everyone but me.
If I understand VBOs correctly one of the benefits in a purely 2D and topdown environment is that I could draw a grid of tiles in one go. If all the textures are in one atlas the geometry and texture of the map would be in one big package, send in one go reducing the amount of draw calls immensely.
The draw order of the sprites seems to be the order in which the primitives are defined in the VBO. Because I sort manually on the CPU I have to create the VBO sorted as well, no problem here. Drawing two VBOs after another, the latter one seems to be drawn last. In a very simple case sorting wouldn't even be necessary, if the first sprite was in the upper left and the last one in the lower right we would get a reasonable draw order for free, back to front, left to right.
However, I can only use one texture with a VBO, unless I use shaders (and then there seems to be a limit too). Not all of my textures fit into one atlas (not even the largest texture size possibly on my GPU). I figured I just have to create multiple VBOs, each responsible for drawing sprites sharing the same atlas. But now I have no idea how to get the draw order right.
If I had 4 sprites. A, B, C, D. Drawn in that order, sharing the same texture, 1, I would just create one VBO. But what if they don't share the same texture? Perhaps they look like this: A(1), B(2), C(1), D(1).
One VBO would contain (A, C, D), bound to 1. One VBO would contain (B), bound to 2. However, B has to be drawn before C and D. If I would just draw the two VBOs in order, the draw order would be A, C, D, B. Oh.
My only idea so far is to create one VBO spanning each continous group of sprites using the same texture. So A(1), B(2), C(2), D(1), E(1), F(3) would create 4 VBOs; (A) bound to 1, (B, C) bound to 2, (D, E) bound to 1, (F) bound to 3.
That would work incredibly well if all the sprites shared the same textures and completely fall apart if by chance every other sprite would use a different texture. Is there a better way?
|