Jump to content
  • Advertisement
Sign in to follow this  
Sol Blue

OpenGL How many quads is too many?

This topic is 3502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to write a 2D tile-based game in OpenGL (I'm sorry, I know you guys are tired of 2D threads :( ) and my performance is slowing down the more tiles I draw. At about 10,000 quads, the game really chugs, but I'd like to display more than this many tiles. Right now, every tile is a separate quad. I calculate the position of the tile from its indices in the grid (easy), then I draw a quad with the appropriate texture at those coordinates. Is 10,000 quads an unreasonable number? If so, how should I optimize my drawing code? Should I try and put all the tiles onto one great big quad somehow? The "red book" has something about "display lists" — should I store a list for one quad, then translate that one?

Share this post


Link to post
Share on other sites
Advertisement
I'd assume OGL has something similar to DX's vertexbuffers, wich just store a series of vertecies, you then set the texture and shaders to be used when displaying all these vetecies.

You should google "Batching" + "OpenGL"

To fill these buffers you'll have to group them by states+texture+shaders+anything else thts specific to a single triangle/quad.

Edit... ZBuffering can help dramatically, to prevent drawing pixels that are behind pixels you have already drawn. One major thing that can increases preformance is not drawing what doesn't need to be drawn.

Sort your draw calls so that what's in front gets drawn first. trust me I went from 125fps to almost 400fps with a current project once a refactored for using a zbuffer.

Share this post


Link to post
Share on other sites
Quote:
Original post by jdindia
You have 10,000 tiles on the screen at once? =O


my DX renderer can handle 10K quads/ 20K Triangles at 200+fps, whats so wrong with 10K quads?

Share this post


Link to post
Share on other sites
Quote:
Original post by freeworld
You should google "Batching" + "OpenGL"

...

Sort your draw calls so that what's in front gets drawn first. trust me I went from 125fps to almost 400fps with a current project once a refactored for using a zbuffer.


Thanks for the tip! As for the z buffer, I'm pretty sure I have to draw back-to-front for alpha blending to work.

Quote:
Original post by freeworld
my DX renderer can handle 10K quads


Ok, great, so I'm not totally out of the realm of possibility here.

Quote:
Original post by GenPFault
Try vertex arrays if you haven't already.


I will look into this...thanks!

Share this post


Link to post
Share on other sites
Seems like you currently draw one quad after another and each quad has its own texture.

That will really kill performance, since you have 10.000 draw calls per frame, up to 10.000 texture state changes etc.

Try batching your quads into vertex arrays / vertex buffers (maybe using indices to further reduce memory consumption and utilize the vertex cache) and using a texture atlas.

Ideally you can draw all of your quads with one draw call. This would mean that all textures have to be in the atlas and your quads have to be sorted in the vertex array/buffer (or in the index buffer, if using any).

Share this post


Link to post
Share on other sites
Quote:
Original post by freeworld

my DX renderer can handle 10K quads/ 20K Triangles at 200+fps, whats so wrong with 10K quads?


There's nothing wrong with 10k quads. He's writing a *2d* game and he says he's trying to draw 10,000 *tiles*. I'm implying that he may be overlooking the most obvious step of not drawing tiles which aren't on screen.

Share this post


Link to post
Share on other sites
Are all 10,000 tiles being shown on screen at one time? If not, you can clip(not-draw) the ones that are not on-screen.

Since you are in 2D, this should be a pretty simple matter.

The box representing your viewable screen is computed this way:

CenterX: the center of your screen horizontally, will be zero if the view is centered.
CenterY: the center of your screen vertically, will be zero if the view is centered.
ResX: the width of your viewable screen.
ResY: the height of your viewable screen.

Left=centerX-(resX/2)
Right=centerX+(resX/2)
Top=centerY-(resY/2)
Bottom=centerY+(resY/2)


Now you have enough information to construct a virtual box outside of which you don't have to draw any tiles. So before you draw a tile, merely check if it is inside our outside of this box(and easy calculation). If it is inside, draw it, if it is outside, dont' draw it.

Hope this helps,
Levi

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!