tags:

views:

73

answers:

3

I'm drawing 2D Polygons, actually I'm drawing lots of triangles and using GLUOrtho2D. I noticed that by zooming out I got much better frame rates. I realized I was maxing out the graphics card's fill rate, not drawing too many polygons as I had initially suspected. I think this is because I'm drawing lots of overlapping polygons and using

glEnable(GL_BLEND);

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Is this the blend function I should be using? How could I minimize the filling given the nature of what I'm doing? I tried enabling the GL_DEPTH_TEST and Z ordered my polygons, but since I alpha blend, this won't help. What is the most efficient way of doing this sort of thing?

Thanks

+1  A: 

avoid alpha blending on as many triangles as possible. It adds up and yes, it gets really expensive. There is no magic high-performance blend function.

The only solution is "use less blending and more z-buffering"

jalf
+2  A: 

I doubt using a different blend function would help. One generally chooses the correct blend function based on desired output, not performance.

Are all the polygons you render transparent/translucent? If not, it might help to separate the rendering of those apart from the opaque polygons you have and set the proper GL states accordingly.

Also are these textured polygons? You might be able to optimize your texture handling (ex: reduce context switches, use more efficient image formats, etc).

Finally, how are you rendering these triangles? If in immediate mode or using vertex arrays, consider using VBOs.

I'm using VBO's and they are all semi transparent, no textures are used just glColor4f()
Milo
Ooh wow, what sort of polygon counts? Are you rendering your triangles in batches? Also do you apply VBOs to both the indices as well as the triangle vertex positions?
each shape is around 150 triangles gets slow at about 4,000 triangles (not much right?), I render them in batches, (per polygon (not triangle)). I'm not firmiliar with indicies and DrawRangeElements so i'm using GlDrawArrays()
Milo
Yeah, 4000 triangles is not much at all. It's odd that you are getting such results. You should be able to improve that performance if you dump all those triangles in one list to render. That would make it kind of a pain to manage when you add new polygons and delete existing ones, but there's a decent chance it'll speed things up noticeably if you can reduce the number of calls to GLDrawArrays.
What does it mean if my framerate gets higher the more I zoom out, like, I have lets say 4,000 polygons from (0,0) to (300,300), then if I move the camera within this range it lags but if 0 - 300 only occupies 1/4 of the screen I get 60 fps no prob.
Milo
@stinky: if the problem is fill rate as the OP suggested (and that's what it sounds like, if zooming out helps), it doesn't really matter how many draw calls you make. And when they're *all* alpha blended, it adds up to an insane amount of overdraw if the triangles fill up a big part of the screen.
jalf
@jalf +1. That's unfortunate then, if there's little that can be done about it.
Thanks anyways though :-)
Milo
A: 

Changing blend function leads only to changes in blending coefficients, but not in equation. Anyways, modern videocards do not use hardcoded equations. You could try to write a pixel shader that satisfies your needs.

BTW, consider using VBO's for yours "lots of triangles" if you still don't.

Dark