Currently I have around 15 render passes in my pipeline. For every pass, I set the correct settings before drawing and reset them afterwards. Those settings include viewport size, depth test on or off, blending function or off, stencil function, stencil operation, and more.
I wonder whether OpenGL is clever enough to ignore API calls which set a state that is already present. Because otherwise I would keep track of the state with a lot of flags and before a render pass only set the state if it is actually necessary.
The short answer: It depends on the driver.
OpenGL itself doesn't do much of anything. It is up to vendors to implement the functions specified by the standard any way they see fit. Do they usually test the existing state to avoid unnecessarily stalling the pipeline? Perhaps, but short of reading advice from vendors or measuring performance yourself, there is no way to know for sure.
The consensus of the advice I have seen (no reference for this as it is spread around all over the place), is that you should avoid calling OpenGL with redundant state changes. It can't do very much harm and it might do some good.
In your case (changing state a few times per frame between passes), it probably won't make much difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With