optimize For 2D OpenGL - Android android.opengl

Android examples for android.opengl:OpenGL

Description

optimize For 2D OpenGL

Demo Code


import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
import android.opengl.GLES11;

public class Main{
    private static boolean sEnableVertexArray = false;
    private static boolean sEnableTextures = false;
    private static boolean sEnableTextureCoordArray = false;
    private static boolean sEnableBlend = false;
    public static void optimizeFor2D() {
        disableMultiSample();/*from w  w  w  .  j  a  v  a  2 s.c  om*/
        disableStencilTest();
        disableAlphaTest();
        disableDepthTest();
        disableLightning();
        disableCullFace();
        disableDither();
        disableFog();

        enableTextureCoordArray();
        enableVertexArray();
        enableTextures();
        enableBlend();
    }
    public static void disableMultiSample() {
        GLES11.glDisable(GL11.GL_MULTISAMPLE);
    }
    public static void disableStencilTest() {
        GLES11.glDisable(GL11.GL_STENCIL_TEST);
    }
    public static void disableAlphaTest() {
        GLES11.glDisable(GL11.GL_ALPHA_TEST);
    }
    public static void disableDepthTest() {
        GLES11.glDisable(GL11.GL_DEPTH_TEST);
    }
    public static void disableLightning() {
        GLES11.glDisable(GL11.GL_LIGHTING);
    }
    public static void disableCullFace() {
        GLES11.glDisable(GL11.GL_CULL_FACE);
    }
    public static void disableDither() {
        GLES11.glDisable(GL11.GL_DITHER);
    }
    public static void disableFog() {
        GLES11.glDisable(GL11.GL_FOG);
    }
    public static void enableTextureCoordArray() {
        if (!GLHelper.sEnableTextureCoordArray) {
            GLHelper.sEnableTextureCoordArray = true;
            GLES11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        }
    }
    public static void enableVertexArray() {
        if (!GLHelper.sEnableVertexArray) {
            GLHelper.sEnableVertexArray = true;
            GLES11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        }
    }
    public static void enableTextures() {
        if (!GLHelper.sEnableTextures) {
            GLHelper.sEnableTextures = true;
            GLES11.glEnable(GL11.GL_TEXTURE_2D);
        }
    }
    public static void enableBlend() {
        if (!GLHelper.sEnableBlend) {
            GLHelper.sEnableBlend = true;
            GLES11.glEnable(GL11.GL_BLEND);
            GLES11.glBlendFunc(GL11.GL_SRC_ALPHA,
                    GL11.GL_ONE_MINUS_SRC_ALPHA);
        }
    }
}

Related Tutorials