Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I call glEnableClientState() and glDisableClientState() in android

I just call glEnableClientState() once in onSurfaceCreated() method of GLSurfaceView.Renderer interface. Eg:

public class GLRenderer implements GLSurfaceView.Renderer {
   @Override
   public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
      ...
}

After that I don't invoke them again. I never invoke the glDisableClientState() method. But I see many programmers call both methods often wrapping them around all drawing calls.

Is anything wrong with my approach? Or is it a good practice or maybe more efficient to use the approach of wrapping them around all drawing calls?

like image 295
Leonel Machava Avatar asked Apr 04 '12 16:04

Leonel Machava


1 Answers

I don't think there's anything wrong with your approach provided that all of your draw calls require the same state. If you're drawing something without normals/colors, you don't want to have the normal/color array enabled, etc.

If all your objects are sure to use the same arrays, then your method is likely the best, as you can eliminate unnecessary opengl calls. Disabling everything after each object is potentially worse for performance, but it is safer in general that you won't accidentally leave something enabled that you don't want.

like image 189
Tim Avatar answered Oct 31 '22 23:10

Tim