Reputation: 63
For a 2d game I need to draw many textured quads each frame. They do not share any vertexes and should should be considered to have a random location that change every frame. As I am using opengl 3+ I can no longer use quads (it has been removed). I could instead use 2 triangles to make each quad but this would create a large amount of redundant reused data being passed to the GPU each frame. So I was wondering what would be the best way to achieve my goal?
I could create a geometry shader and simply pass it the quads top left point as well as it's width, height and texture position. The shader could then create the 2 triangles. However I think this would be quite slow?
Upvotes: 0
Views: 942
Reputation: 48347
You have two potential methods:
You probably should not use a geometry shader. They typically aren't meant to be run every frame, although they certainly can be. You get some benefits, particularly very little memory bandwidth being used, but the hardware requirements are significantly higher and the APIs are much stricter. If your data is coming from CPU calculation that can be optimized on there, you may also end up with better performance; at best you'll have to either translate the calculations or download the data to video memory.
You absolutely do not want to calculate two triangles from the geometry shader, unless you mean two per square. The main benefit of shaders is parallelism, so you'd want to run through as many squares as possible and draw those in large batches. Batching will almost always give you a performance boost, and there are a variety of ways to do it. Things like changing the transforms in the API are terribly slow and best avoided (probably not much of an issue if you're on 3.0+, but it used to be a huge one).
Upvotes: 2