Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
108 chris 1
package com.gebauz.pingK.common.framework.renderstates;
2
 
3
import javax.microedition.khronos.opengles.GL10;
4
 
5
import com.gebauz.pingK.common.framework.GLUtil;
6
 
7
 
8
public class DepthTestStates extends RenderStatesObject
9
{
10
        public enum ComparisonMode
11
        {
12
                NEVER,
13
                ALWAYS,
14
                LESS,
15
                LESSEQUAL,
16
                EQUAL,
17
                GREATER,
18
                GREATEREQUAL,
19
                NONEQUAL
20
        }
21
 
22
        private boolean mEnabled = true;
23
        private boolean mWriteEnabled = true;
24
        private ComparisonMode mDepthTestFunction = ComparisonMode.LESSEQUAL;
25
 
26
        private boolean mCurrentlyEnabled = true;
27
        private boolean mCurrentlyWriteEnabled = true;
28
        private ComparisonMode mCurrentDepthTestFunction = ComparisonMode.LESSEQUAL;
29
 
30
        private boolean mDefaultEnabled = true;
31
        private boolean mDefaultWriteEnabled = true;
32
        private ComparisonMode mDefaultDepthTestFunction = ComparisonMode.LESSEQUAL;
33
 
34
 
35
        public DepthTestStates(RenderStates renderStates)
36
        {
37
                super(renderStates);
38
        }
39
 
40
 
41
        @Override
42
        public void activate(boolean force)
43
        {
44
                GL10 gl = GLUtil.getGL();
45
 
46
                if ((force) || (mEnabled != mCurrentlyEnabled))
47
                {
48
                        mCurrentlyEnabled = mEnabled;
49
                        if (mEnabled)
50
                                gl.glEnable(GL10.GL_DEPTH_TEST);
51
                        else
52
                                gl.glDisable(GL10.GL_DEPTH_TEST);
53
                }
54
 
55
                if ((force) || (mWriteEnabled != mCurrentlyWriteEnabled))
56
                {
57
                        mCurrentlyWriteEnabled = mWriteEnabled;
58
                        gl.glDepthMask(mWriteEnabled);
59
                }
60
 
61
                if ((force) || (mDepthTestFunction != mCurrentDepthTestFunction))
62
                {
63
                        mCurrentDepthTestFunction = mDepthTestFunction;
64
                        switch (mDepthTestFunction)
65
                        {
66
                        case NEVER:
67
                                gl.glDepthFunc(GL10.GL_NEVER);
68
                                break;
69
                        case ALWAYS:
70
                                gl.glDepthFunc(GL10.GL_ALWAYS);
71
                                break;
72
                        case EQUAL:
73
                                gl.glDepthFunc(GL10.GL_EQUAL);
74
                                break;
75
                        case LESS:
76
                                gl.glDepthFunc(GL10.GL_LESS);
77
                                break;
78
                        case LESSEQUAL:
79
                                gl.glDepthFunc(GL10.GL_LEQUAL);
80
                                break;
81
                        case GREATER:
82
                                gl.glDepthFunc(GL10.GL_GREATER);
83
                                break;
84
                        case GREATEREQUAL:
85
                                gl.glDepthFunc(GL10.GL_GEQUAL);
86
                                break;
87
                        case NONEQUAL:
88
                                gl.glDepthFunc(GL10.GL_NOTEQUAL);
89
                                break;
90
                        }
91
                }              
92
        }
93
 
94
        @Override
95
        public void reset()
96
        {
97
                mEnabled = mDefaultEnabled;
98
                mWriteEnabled = mDefaultWriteEnabled;
99
                mDepthTestFunction = mDefaultDepthTestFunction;
100
        }
101
 
102
        public final boolean isEnabled() { return mEnabled; }
103
        public final boolean isDefaultEnabled() { return mDefaultEnabled; }
104
        public final boolean isWriteEnabled() { return mWriteEnabled; }
105
        public final boolean sDefaultWriteEnabled() { return mDefaultWriteEnabled; }
106
        public final ComparisonMode getDepthTestFunction() { return mDepthTestFunction; }
107
        public final ComparisonMode getDefaultDepthTestFunction() { return mDefaultDepthTestFunction; }
108
 
109
        public final void setEnabled(boolean value)
110
        {
111
                if ((mLocked) || (mRenderStates.isLocked()))
112
                        return;
113
                mEnabled = value;
114
        }
115
 
116
        public final void setDefaultEnabled(boolean value)
117
        {
118
                if ((mLocked) || (mRenderStates.isLocked()))
119
                        return;
120
                mDefaultEnabled = value;
121
        }
122
 
123
        public final void setWriteEnabled(boolean value)
124
        {
125
                if ((mLocked) || (mRenderStates.isLocked()))
126
                        return;
127
                mWriteEnabled = value;
128
        }
129
 
130
        public final void setDefaultWriteEnabled(boolean value)
131
        {
132
                if ((mLocked) || (mRenderStates.isLocked()))
133
                        return;
134
                mDefaultWriteEnabled = value;
135
        }
136
 
137
        public final void setDepthTestFunction(ComparisonMode value)
138
        {
139
                if ((mLocked) || (mRenderStates.isLocked()))
140
                        return;
141
                mDepthTestFunction = value;
142
        }
143
 
144
        public final void setDefaultDepthTestFunction(ComparisonMode value)
145
        {
146
                if ((mLocked) || (mRenderStates.isLocked()))
147
                        return;
148
                mDefaultDepthTestFunction = value;
149
        }
150
 
151
}