Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Enabling and disabling vertex attribute arrays

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2010
    Posts
    2

    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?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Enabling and disabling vertex attribute arrays

    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.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: Enabling and disabling vertex attribute arrays

    Quote Originally Posted by BionicBytes
    it's always best practice to disable any state that you have just enabled.
    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:

    Code :
    if ( gl_state != new_state )
    {
      change GL state;
      gl_state = new_state;
    }

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    738

    Re: Enabling and disabling vertex attribute arrays

    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?

  5. #5
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    318

    Re: Enabling and disabling vertex attribute arrays

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •