Search code examples
javaopenglgraphicslibgdx

Should blending be set on/off in every render call?


This function is required to blend the colors of sprites and to manipulate alphas

Gdx.gl.glEnable(GL20.GL_BLEND);  

Now to get max performance, should I enable and disable GL_BLEND every render() call or just enable once in the show() for the rest of the game object's life ?


Solution

  • OpenGL uses the state machine concept. Most values stays the same until you modify them. When you enable or disable a feature it is enough to do this once in the initialization phase. Optimising here for performance may be considered premature optimisation. When in doubt always measure.