I'm working on an OpenGL application and some routines render textured objects, some are just colored primitives. I was wondering if there was a standard convention for how to deal with setting the OpenGL 'state'.

For example, consider this routine (using OpenGL ES / OpenTK):

/// <summary>
/// Renders the given tile at the corresponding screen-tile location.
/// </summary>
public static void RenderTile(float[] vertices, float xOffset, float yOffset, uint textureId)


    GL.Translate(xOffset, yOffset, 0.0f);

    GL.BindTexture(All.Texture2D, textureId);
    GL.VertexPointer(2, All.Float, 0, vertices);
    GL.ColorPointer(4, All.Float, 0, SQUARE_COLORS);
    GL.TexCoordPointer(2, All.Float, 0, SQUARE_TEXTURE_COORDS);

    GL.DrawArrays(All.TriangleStrip, 0, 4);


I'm curious about that GL.EnableClientState(All.TextureCoordArray); bit. Should I just get into the habit of calling GL.Enable(...) / Gl.EnableClientState(...) for everything the current function needs? Even if it is largely redundant? Or is it better to just assume that the application has a certain set of things enabled (blending, back-face culling, 2D textures, etc.).

I know this question is pretty subjective, so I'm looking for advice from someone who has worked with a large OpenGL codebase. (As all my experience is for solo projects.)


1 Answer 1


Redundant state changes can add some overhead, and whether or not your driver filters them depends on the driver (so far as I'm aware the GL spec says nothing about this).

Generally I like to set state at the start of each drawing function, and implement wrappers that do their own filtering. I don't unset state at the end because to do so would mean that separation between drawing functions becomes broken - each function should definitely not have knowledge of what's coming next.

  • \$\begingroup\$ But not unsetting things would cause problems too, right? For example: Render X with blending, render Y which is now blended since GL_BLEND wasn't disabled. \$\endgroup\$ Commented Dec 22, 2011 at 1:56
  • \$\begingroup\$ Your state wrapper would handle this, of course. \$\endgroup\$ Commented Dec 22, 2011 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .