Subversion Repositories AndroidProjects

Rev

Rev 800 | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Tao.OpenGl;
#pragma warning disable 0618

namespace BauzoidNET.graphics.renderstates
{
    public class DepthTestStates : RenderStatesObject
    {
        /** Comparison mode for depth test. */
            public enum ComparisonMode
            {
                    NEVER,
                    ALWAYS,
                    LESS,
                    LESSEQUAL,
                    EQUAL,
                    GREATER,
                    GREATEREQUAL,
                    NONEQUAL
            };
       
            private bool mEnabled = false;
        private bool mWriteEnabled = false;
            private ComparisonMode mDepthTestFunction = ComparisonMode.LESSEQUAL;

        private bool mCurrentlyEnabled = false;
        private bool mCurrentlyWriteEnabled = false;
            private ComparisonMode mCurrentDepthTestFunction = ComparisonMode.LESSEQUAL;

        private bool mDefaultEnabled = false;
        private bool mDefaultWriteEnabled = false;
            private ComparisonMode mDefaultDepthTestFunction = ComparisonMode.LESSEQUAL;
       
            /** Constructor. */
            public DepthTestStates(RenderStates renderStates) : base(renderStates)
            {
            }
       
            /** Activate the render state. */
            public override void activate(bool force)
            {
                    if ((force) || (mEnabled != mCurrentlyEnabled))
                    {
                            mCurrentlyEnabled = mEnabled;
                            if (mEnabled)
                                    Gl.glEnable(Gl.GL_DEPTH_TEST);
                            else
                                    Gl.glDisable(Gl.GL_DEPTH_TEST);
                    }

                    if ((force) || (mWriteEnabled != mCurrentlyWriteEnabled))
                    {
                            mCurrentlyWriteEnabled = mWriteEnabled;
                            Gl.glDepthMask(mWriteEnabled ? Gl.GL_TRUE : Gl.GL_FALSE);
                    }

                    if ((force) || (mDepthTestFunction != mCurrentDepthTestFunction))
                    {
                            mCurrentDepthTestFunction = mDepthTestFunction;
                            switch (mDepthTestFunction)
                            {
                            case ComparisonMode.NEVER:
                                    Gl.glDepthFunc(Gl.GL_NEVER);
                                    break;
                            case ComparisonMode.ALWAYS:
                                    Gl.glDepthFunc(Gl.GL_ALWAYS);
                                    break;
                            case ComparisonMode.EQUAL:
                                    Gl.glDepthFunc(Gl.GL_EQUAL);
                                    break;
                            case ComparisonMode.LESS:
                                    Gl.glDepthFunc(Gl.GL_LESS);
                                    break;
                            case ComparisonMode.LESSEQUAL:
                                    Gl.glDepthFunc(Gl.GL_LEQUAL);
                                    break;
                            case ComparisonMode.GREATER:
                                    Gl.glDepthFunc(Gl.GL_GREATER);
                                    break;
                            case ComparisonMode.GREATEREQUAL:
                                    Gl.glDepthFunc(Gl.GL_GEQUAL);
                                    break;
                            case ComparisonMode.NONEQUAL:
                                    Gl.glDepthFunc(Gl.GL_NOTEQUAL);
                                    break;
                            }
                    }          
            }
       
            /** Reset to default values. */
            public override void reset()
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
               
                    mEnabled = mDefaultEnabled;
                    mWriteEnabled = mDefaultWriteEnabled;
                    mDepthTestFunction = mDefaultDepthTestFunction;
            }

            /** Check if enabled. */
            public bool isEnabled()
            {
                    return mEnabled;
            }
       
            /** Check default enabled state. */
            public bool isDefaultEnabled()
            {
                    return mDefaultEnabled;
            }
       
            /** Check if depth-write is enabled. */
            public bool isWriteEnabled()
            {
                    return mWriteEnabled;
            }
       
            /** Check if depth-write is enabled by default. */
            public bool isDefaultWriteEnabled()
            {
                    return mDefaultWriteEnabled;
            }
       
            /** Get the depth test function. */
            public ComparisonMode getDepthTestFunction()
            {
                    return mDepthTestFunction;
            }
       
            /** Get the default depth test function. */
            public ComparisonMode getDefaultDepthTestFunction()
            {
                    return mDefaultDepthTestFunction;
            }

            /** Enable depth testing. */
            public void setEnabled(bool value)
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
                    mEnabled = value;
            }

            /** Set the default depth test enabled state. */
            public void setDefaultEnabled(bool value)
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
                    mDefaultEnabled = value;
            }

            /** Enable depth write. */
            public void setWriteEnabled(bool value)
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
                    mWriteEnabled = value;
            }

            /** Set the default depth write enabled state. */
            public void setDefaultWriteEnabled(bool value)
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
                    mDefaultWriteEnabled = value;
            }

            /** Set the depth test function. */
            public void setDepthTestFunction(ComparisonMode value)
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
                    mDepthTestFunction = value;
            }

            /** Set the default depth test function. */
            public void setDefaultDepthTestFunction(ComparisonMode value)
            {
                    if ((mLocked) || (mRenderStates.isLocked()))
                            return;
                    mDefaultDepthTestFunction = value;
            }

    }
}