Question

I'm just currently writing my various routines. What I am doing is at every routine that say needs blending, I enable blending at the beginning and disable it at the end. Is this a bad thing?

For example:

Public Sub DrawQuad()
        GL.Enable(EnableCap.Blend)
        GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha)

        GL.Begin()
        GL.End()

        GL.Disable(EnableCap.Blend)
End Sub

I have this, but I might call this 500 times in the same go, which means blending will get enabled/disabled 500 times. Will this greatly effect performance compared to just enabling once, drawing 500 quads and than disabling?

Was it helpful?

Solution

Premature optimization is the root of all evil!

  • As bcrist pointed out in the comments, if you're looking to optimize your OpenGL code, do learn the programmable pipeline. It's faster, more customizable, less reliant on magical function calls, and generally more awesome.

  • In general, optimize your big problems first, then get specific.

  • The best way to find out the answer to your question is to profile your code. OpenGL drivers are implemented by the hardware vendors for each device. Yes, calling any function repeatedly when you could call it just once will cause a performance hit, but how does that stack up against the rest of your code?

The take home point is admittedly annoying - your question is misguided and the "answer" isn't going to answer your actual question about calls to glEnable. You should optimize many things before you start looking at small functions like that.

For example, once you get the rest of your design sorted out and you realize that grouping together certain drawing routines by glEnable is even possible in your program, much less doable without incurring more overhead than it eliminates, then you might look into doing something to get rid of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top