Search code examples
openglbatching

Which one is more important in batching in OpenGL?


I have read Batch,Batch,Batch.

In the Batching process, there are two main things:

1 Submit n number of triangles

2 SetState

So which one is more cpu time consuming?

Or the SetState itself actually does not matter at all. It matters only because once the state has been changed, we have to submit triangles again?


Solution

  • All in all, it doesn't really matter (like you say at the end of your question)

    • If you do a SetState without submitting data to draw with that state, that's just dumb. Don't do the SetState.
    • If you draw several batch with the same state, you should probably have submitted them as one single batch.

    What the "set state" does is going to be very driver dependent, and which state you change. Some changes might need a lot of validation, and that could be done when you set the state, or when it's actually going to be sent to the GPU, no way to know for sure.

    In general, I would count that "submitting a draw" counts as 1 batch, no matter whether the state was changed before doing it or not.