I was looking at the template for OpenGL ES 2.0 in Xcode, and I noticed that Apple creates a new Perspective Matrix and a new Transform Matrix before every frame. I also see this in tutorials. When I use OpenGL on other platforms, I only have to create the Matrices once. Why does Apple want you to make a new one every frame?
Share
In a complex application, there are a few ways to deal with OpenGL state:
1) Have a policy where every function or method that changes OpenGL state must set it back to what it was before they did anything
2) Every function or method sets the state to what they want it to be assuming nothing about the existing state
3) You keep track of the state and functions and methods can check it locally and set only what they need to
In case 1, if someone forgets to follow the policy, bugs occur and are hard to track down. Also, getting the current state can be expensive for certain bits of state.
In case 2, you spend time setting state you might not need to. This is usually not too bad, though.
In case 3, you expend a lot of effort and memory tracking the state that OpenGL is already keeping. It’s expensive and error-prone.
So usually, I go with #2. It’s the least amount of work for me and has reasonably good performance in most cases. Your mileage may vary.