State Enable optimization

Hello everyone,

I would like to know something that I’ve found anywhere on the OpenGL state, even in books.

Is it better to enable every state to load the world, or enable the states one by one to each frame as and when we should use it?

Thank you and goodbye,

I am not sure to understand your question but I will try to answer. Opengl states are not like game engines features, “enabling” all of them as you said, won’t result in fantastic graphics.

With opengl, you enable or set states you need and disable the ones you don’t need.

No my question is:

What is the best method?

  1. Enable all statements at the opening of the window.

  2. Enable and disable the states in each frame every time I use it.

I would like to gain speed.

What is the best method?

Like he said, “you enable or set states you need and disable the ones you don’t need.”

You can’t set gl states once for all at the beginning of your your program (except if your program is very simple). Sometimes you may need for example, to enable 2D texturing, sometimes you don’t. Each rendering batch has its set of gl states. The best method is to draw all batches consecutively that require the same set of states and avoid expensive states initialization as much as you can.

Thank for your answer.

Goodbye!