I was wondering how people generally manage the state of vertex attribute arrays.
As I see it now it works as follows: Let’s say that array 1 and 2 need to be enabled for shader A. If we then switch to shader B those arrays are still enabled. Is it then best practice to disable them if shader B doesn’t need them?
it’s always best practice to disable any state that you have just enabled. Otherwise it’s difficult to track just which state is enabled or disbaled at any time.
It’s down to your application to define what your ‘default state’ should be. Alpha test off, blend off, texturing enabled for texture unit#0 and so forth. There is no rule. Bear in mind it is exceptionally hard to debug problems due to state being left on in one part of the application and yet your code fails elsewhere all because you didn’t disable something you had used previosuly.
It’s better than losing track of what you’ve got enabled vs. not, true.
But I’d argue it’s an even more efficient best practice to “lazy state” set your OpenGL state. That is track what the GL state is in your app state, and only change the GL state when the app state says you need to. Example: