Using OpenGL to accelerate 2D graphics

2d, opengl, optimization, performance

Solution

Sounds like you're up against the maximum fill rate of the card, coupled with the fact that you're doing blending so reads as well as writes are required.

If you overdraw enough of the frame buffer (particularly at high res), then you're going to drop the frame rate eventually, because of limitations in the fill rate of the card.

Although modern cards can do a lot of operations, they still have a limit to how many pixels they can push.

To reduce this some suggestions are:

- Don't draw everything every frame - if possible - render some parts to other buffers, then blend those over - at a lower resolution if possible

- Don't use blending if you don't have to - blending is much slower than drawing opaque stuff

- Use a cheaper fragment shader / fragment program - if you're using a programmable pipeline (NB: I don't know how you can really tell how expensive it is)

- Use as much culling as you can - avoid drawing things which can't be seen at all. If a sprite is entirely (or mostly) hidden behind others, you don't need to draw it.

- Scaling / interpolation is probably relatively cheap - use lower res textures and scale them - particularly if your textures are "blurry" to begin with.

If you're doing this to get some funky smoke / particle effect, you probably can't use all or many of these optimisations.

Problem

Me and my friend are trying to accelerate a 2D game with OpenGL. The video chipset is Radeon X1250 which seems to be underpowered and can display up to some 80 1366x768 full frames/s. Given that we are drawing many sprites on top of each other the performace drops dramatically under the 60 FPS we are targeting at. Could you please provide optimization tips for rendering fast 2D with OpenGL? EDIT: some clarifications: Development takes place in C++ under Linux. We did it with SDL but the performance was unsatisfactory so we decided to switch to OpenGL which proved much faster, Of course then there was a push to implement more features requiring us to redraw entire screen every frame. Our test program renders textured 256x256 quad tiles across the 1366x768 screen. If a single layer of tiles is laid before buffer swap it yields 80 FPS, if two layers are laid framerate drops below 60 FPS. Given that the board will be required to decode and render some small MPEGs at the same time this might be unsatisfactory. I just thought that I could look for optimizations resulting from the fact that the game is 2D - I thought of, for example: 1) if this is possible to disable texture scaling. 2) render directly to frame buffer (though we've heard that glDrawPixels is supposed to be slow.

Original source