Subversion Repositories AndroidProjects

Rev

Blame | Last modification | View Log | RSS feed

package com.gebauz.pingK.common.framework.renderstates;

import javax.microedition.khronos.opengles.GL10;

import com.gebauz.pingK.common.framework.GLUtil;


public class DepthTestStates extends RenderStatesObject
{
        public enum ComparisonMode
        {
                NEVER,
                ALWAYS,
                LESS,
                LESSEQUAL,
                EQUAL,
                GREATER,
                GREATEREQUAL,
                NONEQUAL
        }
       
        private boolean mEnabled = true;
        private boolean mWriteEnabled = true;
        private ComparisonMode mDepthTestFunction = ComparisonMode.LESSEQUAL;
       
        private boolean mCurrentlyEnabled = true;
        private boolean mCurrentlyWriteEnabled = true;
        private ComparisonMode mCurrentDepthTestFunction = ComparisonMode.LESSEQUAL;

        private boolean mDefaultEnabled = true;
        private boolean mDefaultWriteEnabled = true;
        private ComparisonMode mDefaultDepthTestFunction = ComparisonMode.LESSEQUAL;
       
       
        public DepthTestStates(RenderStates renderStates)
        {
                super(renderStates);
        }
       
       
        @Override
        public void activate(boolean force)
        {
                GL10 gl = GLUtil.getGL();
               
                if ((force) || (mEnabled != mCurrentlyEnabled))
                {
                        mCurrentlyEnabled = mEnabled;
                        if (mEnabled)
                                gl.glEnable(GL10.GL_DEPTH_TEST);
                        else
                                gl.glDisable(GL10.GL_DEPTH_TEST);
                }

                if ((force) || (mWriteEnabled != mCurrentlyWriteEnabled))
                {
                        mCurrentlyWriteEnabled = mWriteEnabled;
                        gl.glDepthMask(mWriteEnabled);
                }

                if ((force) || (mDepthTestFunction != mCurrentDepthTestFunction))
                {
                        mCurrentDepthTestFunction = mDepthTestFunction;
                        switch (mDepthTestFunction)
                        {
                        case NEVER:
                                gl.glDepthFunc(GL10.GL_NEVER);
                                break;
                        case ALWAYS:
                                gl.glDepthFunc(GL10.GL_ALWAYS);
                                break;
                        case EQUAL:
                                gl.glDepthFunc(GL10.GL_EQUAL);
                                break;
                        case LESS:
                                gl.glDepthFunc(GL10.GL_LESS);
                                break;
                        case LESSEQUAL:
                                gl.glDepthFunc(GL10.GL_LEQUAL);
                                break;
                        case GREATER:
                                gl.glDepthFunc(GL10.GL_GREATER);
                                break;
                        case GREATEREQUAL:
                                gl.glDepthFunc(GL10.GL_GEQUAL);
                                break;
                        case NONEQUAL:
                                gl.glDepthFunc(GL10.GL_NOTEQUAL);
                                break;
                        }
                }              
        }
       
        @Override
        public void reset()
        {
                mEnabled = mDefaultEnabled;
                mWriteEnabled = mDefaultWriteEnabled;
                mDepthTestFunction = mDefaultDepthTestFunction;
        }

        public final boolean isEnabled() { return mEnabled; }
        public final boolean isDefaultEnabled() { return mDefaultEnabled; }
        public final boolean isWriteEnabled() { return mWriteEnabled; }
        public final boolean sDefaultWriteEnabled() { return mDefaultWriteEnabled; }
        public final ComparisonMode getDepthTestFunction() { return mDepthTestFunction; }
        public final ComparisonMode getDefaultDepthTestFunction() { return mDefaultDepthTestFunction; }

        public final void setEnabled(boolean value)
        {
                if ((mLocked) || (mRenderStates.isLocked()))
                        return;
                mEnabled = value;
        }

        public final void setDefaultEnabled(boolean value)
        {
                if ((mLocked) || (mRenderStates.isLocked()))
                        return;
                mDefaultEnabled = value;
        }

        public final void setWriteEnabled(boolean value)
        {
                if ((mLocked) || (mRenderStates.isLocked()))
                        return;
                mWriteEnabled = value;
        }

        public final void setDefaultWriteEnabled(boolean value)
        {
                if ((mLocked) || (mRenderStates.isLocked()))
                        return;
                mDefaultWriteEnabled = value;
        }

        public final void setDepthTestFunction(ComparisonMode value)
        {
                if ((mLocked) || (mRenderStates.isLocked()))
                        return;
                mDepthTestFunction = value;
        }

        public final void setDefaultDepthTestFunction(ComparisonMode value)
        {
                if ((mLocked) || (mRenderStates.isLocked()))
                        return;
                mDefaultDepthTestFunction = value;
        }

}