Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1051 | chris | 1 | package com.gebauz.bauzoid.graphics.renderstates; |
| 2 | |||
| 3 | import com.badlogic.gdx.Gdx; |
||
| 4 | import com.badlogic.gdx.graphics.GL20; |
||
| 5 | |||
| 6 | /** Depth test render state. */ |
||
| 7 | public class DepthTestStates extends RenderStatesObject |
||
| 8 | { |
||
| 9 | /** Comparison mode for depth test. */ |
||
| 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 | /** Constructor. */ |
||
| 35 | public DepthTestStates(RenderStates renderStates) |
||
| 36 | { |
||
| 37 | super(renderStates); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** Activate the render state. */ |
||
| 41 | @Override |
||
| 42 | public void activate(boolean force) |
||
| 43 | { |
||
| 44 | if ((force) || (mEnabled != mCurrentlyEnabled)) |
||
| 45 | { |
||
| 46 | mCurrentlyEnabled = mEnabled; |
||
| 47 | if (mEnabled) |
||
| 48 | Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); |
||
| 49 | else |
||
| 50 | Gdx.gl.glDisable(GL20.GL_DEPTH_TEST); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ((force) || (mWriteEnabled != mCurrentlyWriteEnabled)) |
||
| 54 | { |
||
| 55 | mCurrentlyWriteEnabled = mWriteEnabled; |
||
| 56 | Gdx.gl.glDepthMask(mWriteEnabled); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ((force) || (mDepthTestFunction != mCurrentDepthTestFunction)) |
||
| 60 | { |
||
| 61 | mCurrentDepthTestFunction = mDepthTestFunction; |
||
| 62 | switch (mDepthTestFunction) |
||
| 63 | { |
||
| 64 | case NEVER: |
||
| 65 | Gdx.gl.glDepthFunc(GL20.GL_NEVER); |
||
| 66 | break; |
||
| 67 | case ALWAYS: |
||
| 68 | Gdx.gl.glDepthFunc(GL20.GL_ALWAYS); |
||
| 69 | break; |
||
| 70 | case EQUAL: |
||
| 71 | Gdx.gl.glDepthFunc(GL20.GL_EQUAL); |
||
| 72 | break; |
||
| 73 | case LESS: |
||
| 74 | Gdx.gl.glDepthFunc(GL20.GL_LESS); |
||
| 75 | break; |
||
| 76 | case LESSEQUAL: |
||
| 77 | Gdx.gl.glDepthFunc(GL20.GL_LEQUAL); |
||
| 78 | break; |
||
| 79 | case GREATER: |
||
| 80 | Gdx.gl.glDepthFunc(GL20.GL_GREATER); |
||
| 81 | break; |
||
| 82 | case GREATEREQUAL: |
||
| 83 | Gdx.gl.glDepthFunc(GL20.GL_GEQUAL); |
||
| 84 | break; |
||
| 85 | case NONEQUAL: |
||
| 86 | Gdx.gl.glDepthFunc(GL20.GL_NOTEQUAL); |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | /** Reset to default values. */ |
||
| 93 | @Override |
||
| 94 | public void reset() |
||
| 95 | { |
||
| 96 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 97 | return; |
||
| 98 | |||
| 99 | mEnabled = mDefaultEnabled; |
||
| 100 | mWriteEnabled = mDefaultWriteEnabled; |
||
| 101 | mDepthTestFunction = mDefaultDepthTestFunction; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** Check if enabled. */ |
||
| 105 | public final boolean isEnabled() |
||
| 106 | { |
||
| 107 | return mEnabled; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** Check default enabled state. */ |
||
| 111 | public final boolean isDefaultEnabled() |
||
| 112 | { |
||
| 113 | return mDefaultEnabled; |
||
| 114 | } |
||
| 115 | |||
| 116 | /** Check if depth-write is enabled. */ |
||
| 117 | public final boolean isWriteEnabled() |
||
| 118 | { |
||
| 119 | return mWriteEnabled; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** Check if depth-write is enabled by default. */ |
||
| 123 | public final boolean isDefaultWriteEnabled() |
||
| 124 | { |
||
| 125 | return mDefaultWriteEnabled; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** Get the depth test function. */ |
||
| 129 | public final ComparisonMode getDepthTestFunction() |
||
| 130 | { |
||
| 131 | return mDepthTestFunction; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** Get the default depth test function. */ |
||
| 135 | public final ComparisonMode getDefaultDepthTestFunction() |
||
| 136 | { |
||
| 137 | return mDefaultDepthTestFunction; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** Enable depth testing. */ |
||
| 141 | public final void setEnabled(boolean value) |
||
| 142 | { |
||
| 143 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 144 | return; |
||
| 145 | mEnabled = value; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** Set the default depth test enabled state. */ |
||
| 149 | public final void setDefaultEnabled(boolean value) |
||
| 150 | { |
||
| 151 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 152 | return; |
||
| 153 | mDefaultEnabled = value; |
||
| 154 | } |
||
| 155 | |||
| 156 | /** Enable depth write. */ |
||
| 157 | public final void setWriteEnabled(boolean value) |
||
| 158 | { |
||
| 159 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 160 | return; |
||
| 161 | mWriteEnabled = value; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** Set the default depth write enabled state. */ |
||
| 165 | public final void setDefaultWriteEnabled(boolean value) |
||
| 166 | { |
||
| 167 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 168 | return; |
||
| 169 | mDefaultWriteEnabled = value; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** Set the depth test function. */ |
||
| 173 | public final void setDepthTestFunction(ComparisonMode value) |
||
| 174 | { |
||
| 175 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 176 | return; |
||
| 177 | mDepthTestFunction = value; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** Set the default depth test function. */ |
||
| 181 | public final void setDefaultDepthTestFunction(ComparisonMode value) |
||
| 182 | { |
||
| 183 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 184 | return; |
||
| 185 | mDefaultDepthTestFunction = value; |
||
| 186 | } |
||
| 187 | |||
| 188 | } |