Enabling and disabling vertex attribute arrays

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:

if ( gl_state != new_state )
  change GL state;
  gl_state = new_state;

I lazy state like Dark Photon; but I have wonder whether it is necessary.

Does anyone know if you explictly set states to true or false will the driver only issue a gpu calls if the state actually changes?

You can use VAO. It always starts with all arrays disabled.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.