PDA

View Full Version : Performance of glOrtho VS glPerspective (and switching cost)



Mctittles
08-26-2012, 07:17 AM
I never know whether I should post in "beginners" or "advanced". Anyway...

I'm working on a 2d(ish) game and for some visual effects I position 2d objects in glFrustum with varying depth. They still appear to the user as 2d objects.

I have a couple things like a main background image and some "HUD" type elements that I switch to glOrtho to draw because depth is irrelevant in these things.

I could easily draw these elements in glFrustum mode though.

So my question is this. Is there much difference in performance between glFrustum and glOrtho (especially with GL_DEPTH_TEST disabled)? I'm wondering if the cost to switch between the two modes each frame is more than just drawing my pure 2d elements in glFrustum so they are in the same relative position.

Thanks for any advice :).

JakobProgsch
08-26-2012, 08:03 AM
Both just set up a projection matrix and there aren't "more expensive matrices" or anything like that. The cost of using a perspective or ortho matrix are the same. Switching will most likely also be cheap... as always: when in doubt, measure.

menzel
08-26-2012, 08:05 AM
glFrustum and glOrtho are just creating a projection matrix which will get multiplied to all vertices. They cost the same, switching has a low cost. If you encounter performance problems, there might be other bottlenecks.

Mctittles
08-26-2012, 09:41 AM
Thanks for the help. I'll probably just go with all glFrustum then as it's easier and I might be able to just squish everything into the same array for one draw call.

mhagain
08-26-2012, 09:49 AM
There actually is a slightly faster path that can be applied to verts using an ortho-only projection (also assuming minimal modelview transforms) where the final transform can be collapsed to a single vectorized MAD, but it would be driver-dependent behaviour and shouldn't be relied on. Otherwise what everyone else said - there is no difference.