In all the examples I’ve seen, these lines are used before drawing meshes:
glEnableClientState(GL10.GL_VERTEX_ARRAY);
glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
and sometimes glEnableClientState(GL10.GL_NORMAL_ARRAY);
And then these are always disabled again at the end of the draw call for each mesh.
I don’t really understand what they actually do, and why you would want to disable them. I know that I probably need to turn them on if I’m drawing triangles from an array, using textures, and using lighting. But I don’t know when I actually need to turn them off.
I presume it would be more efficient not to disable and re-enable these for each mesh in your scene if you don’t have to. Can you just leave them on all the time? In what circumstances do you need to disable them?
I haven’t been able to find any explanation of the actual meaning of these client states, so I don’t know where I can safely leave them on or off in my code.
Yes, if you want to, and if all your primitives uses all the arrays you’re enabling.
In order to not destroy or mess up the next drawings.
For example, consider you have a primitive that uses normals, you’ll simply enable it by a call to
glEnableClientState(GL_NORMAL_ARRAY)and telling OpenGL where your normal data is throughglNormalPointer(). If you don’t disableGL_NORMAL_ARRAYyour next coming primitive will use the same normal array as your previous primitive. This may have consequences if your next coming primitive doesn’t use normals.Therefore, it’s considered as a good practice to restore the OpenGL state when a primitive’s drawing is done. That being said, you can leave them enabled if all your primitives uses all the arrays you enable, exactly like I leave
GL_TEXTURE_2Denabled during the entire time the application is running. That’s because I know I’ll use textures frequently, and then there’s no reason for enable/disable it in every object’s draw call; this will only decrease the application’s performance.