You copied the Doc URL to your clipboard.

10.2. Minimize state changes

State changes are similar to draw calls in that there is an overhead imposed every time state is changed. To reduce this overhead, minimize the number of state changes your application makes.

You can reduce state changes with the following techniques:

  • Group together triangles or objects with the same texture.

  • Group objects with the same state together and make changes on them in one go.

  • Use texture atlases. This enables you to draw complex single objects or multiple objects with a single texture. See Combining textures in a texture atlas.

  • Check the state in your application to see if it must be changed, only make state changes that are necessary.

  • Remove redundant glEnable() and glDisable() pairs.

    For example, replace this type of construct:

    • glEnable()

      <do operation 1>

      glDisable()

      glEnable()

      <do operation 2>

      glDisable()

    with this:

    • glEnable()

      <do operation 1>

      <do operation 2>

      glDisable()