Rev 800 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 787 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.Linq; |
||
| 4 | using System.Text; |
||
| 5 | using System.Threading.Tasks; |
||
| 6 | |||
| 7 | using Tao.OpenGl; |
||
| 1451 | chris | 8 | #pragma warning disable 0618 |
| 787 | chris | 9 | |
| 10 | namespace BauzoidNET.graphics.renderstates |
||
| 11 | { |
||
| 12 | public class DepthTestStates : RenderStatesObject |
||
| 13 | { |
||
| 14 | /** Comparison mode for depth test. */ |
||
| 15 | public enum ComparisonMode |
||
| 16 | { |
||
| 17 | NEVER, |
||
| 18 | ALWAYS, |
||
| 19 | LESS, |
||
| 20 | LESSEQUAL, |
||
| 21 | EQUAL, |
||
| 22 | GREATER, |
||
| 23 | GREATEREQUAL, |
||
| 24 | NONEQUAL |
||
| 25 | }; |
||
| 26 | |||
| 800 | chris | 27 | private bool mEnabled = false; |
| 28 | private bool mWriteEnabled = false; |
||
| 787 | chris | 29 | private ComparisonMode mDepthTestFunction = ComparisonMode.LESSEQUAL; |
| 800 | chris | 30 | |
| 31 | private bool mCurrentlyEnabled = false; |
||
| 32 | private bool mCurrentlyWriteEnabled = false; |
||
| 787 | chris | 33 | private ComparisonMode mCurrentDepthTestFunction = ComparisonMode.LESSEQUAL; |
| 34 | |||
| 800 | chris | 35 | private bool mDefaultEnabled = false; |
| 36 | private bool mDefaultWriteEnabled = false; |
||
| 787 | chris | 37 | private ComparisonMode mDefaultDepthTestFunction = ComparisonMode.LESSEQUAL; |
| 38 | |||
| 39 | /** Constructor. */ |
||
| 40 | public DepthTestStates(RenderStates renderStates) : base(renderStates) |
||
| 41 | { |
||
| 42 | } |
||
| 43 | |||
| 44 | /** Activate the render state. */ |
||
| 45 | public override void activate(bool force) |
||
| 46 | { |
||
| 47 | if ((force) || (mEnabled != mCurrentlyEnabled)) |
||
| 48 | { |
||
| 49 | mCurrentlyEnabled = mEnabled; |
||
| 50 | if (mEnabled) |
||
| 51 | Gl.glEnable(Gl.GL_DEPTH_TEST); |
||
| 52 | else |
||
| 53 | Gl.glDisable(Gl.GL_DEPTH_TEST); |
||
| 54 | } |
||
| 55 | |||
| 56 | if ((force) || (mWriteEnabled != mCurrentlyWriteEnabled)) |
||
| 57 | { |
||
| 58 | mCurrentlyWriteEnabled = mWriteEnabled; |
||
| 59 | Gl.glDepthMask(mWriteEnabled ? Gl.GL_TRUE : Gl.GL_FALSE); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ((force) || (mDepthTestFunction != mCurrentDepthTestFunction)) |
||
| 63 | { |
||
| 64 | mCurrentDepthTestFunction = mDepthTestFunction; |
||
| 65 | switch (mDepthTestFunction) |
||
| 66 | { |
||
| 67 | case ComparisonMode.NEVER: |
||
| 68 | Gl.glDepthFunc(Gl.GL_NEVER); |
||
| 69 | break; |
||
| 70 | case ComparisonMode.ALWAYS: |
||
| 71 | Gl.glDepthFunc(Gl.GL_ALWAYS); |
||
| 72 | break; |
||
| 73 | case ComparisonMode.EQUAL: |
||
| 74 | Gl.glDepthFunc(Gl.GL_EQUAL); |
||
| 75 | break; |
||
| 76 | case ComparisonMode.LESS: |
||
| 77 | Gl.glDepthFunc(Gl.GL_LESS); |
||
| 78 | break; |
||
| 79 | case ComparisonMode.LESSEQUAL: |
||
| 80 | Gl.glDepthFunc(Gl.GL_LEQUAL); |
||
| 81 | break; |
||
| 82 | case ComparisonMode.GREATER: |
||
| 83 | Gl.glDepthFunc(Gl.GL_GREATER); |
||
| 84 | break; |
||
| 85 | case ComparisonMode.GREATEREQUAL: |
||
| 86 | Gl.glDepthFunc(Gl.GL_GEQUAL); |
||
| 87 | break; |
||
| 88 | case ComparisonMode.NONEQUAL: |
||
| 89 | Gl.glDepthFunc(Gl.GL_NOTEQUAL); |
||
| 90 | break; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | /** Reset to default values. */ |
||
| 96 | public override void reset() |
||
| 97 | { |
||
| 98 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 99 | return; |
||
| 100 | |||
| 101 | mEnabled = mDefaultEnabled; |
||
| 102 | mWriteEnabled = mDefaultWriteEnabled; |
||
| 103 | mDepthTestFunction = mDefaultDepthTestFunction; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** Check if enabled. */ |
||
| 107 | public bool isEnabled() |
||
| 108 | { |
||
| 109 | return mEnabled; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** Check default enabled state. */ |
||
| 113 | public bool isDefaultEnabled() |
||
| 114 | { |
||
| 115 | return mDefaultEnabled; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** Check if depth-write is enabled. */ |
||
| 119 | public bool isWriteEnabled() |
||
| 120 | { |
||
| 121 | return mWriteEnabled; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** Check if depth-write is enabled by default. */ |
||
| 125 | public bool isDefaultWriteEnabled() |
||
| 126 | { |
||
| 127 | return mDefaultWriteEnabled; |
||
| 128 | } |
||
| 129 | |||
| 130 | /** Get the depth test function. */ |
||
| 131 | public ComparisonMode getDepthTestFunction() |
||
| 132 | { |
||
| 133 | return mDepthTestFunction; |
||
| 134 | } |
||
| 135 | |||
| 136 | /** Get the default depth test function. */ |
||
| 137 | public ComparisonMode getDefaultDepthTestFunction() |
||
| 138 | { |
||
| 139 | return mDefaultDepthTestFunction; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** Enable depth testing. */ |
||
| 143 | public void setEnabled(bool value) |
||
| 144 | { |
||
| 145 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 146 | return; |
||
| 147 | mEnabled = value; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** Set the default depth test enabled state. */ |
||
| 151 | public void setDefaultEnabled(bool value) |
||
| 152 | { |
||
| 153 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 154 | return; |
||
| 155 | mDefaultEnabled = value; |
||
| 156 | } |
||
| 157 | |||
| 158 | /** Enable depth write. */ |
||
| 159 | public void setWriteEnabled(bool value) |
||
| 160 | { |
||
| 161 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 162 | return; |
||
| 163 | mWriteEnabled = value; |
||
| 164 | } |
||
| 165 | |||
| 166 | /** Set the default depth write enabled state. */ |
||
| 167 | public void setDefaultWriteEnabled(bool value) |
||
| 168 | { |
||
| 169 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 170 | return; |
||
| 171 | mDefaultWriteEnabled = value; |
||
| 172 | } |
||
| 173 | |||
| 174 | /** Set the depth test function. */ |
||
| 175 | public void setDepthTestFunction(ComparisonMode value) |
||
| 176 | { |
||
| 177 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 178 | return; |
||
| 179 | mDepthTestFunction = value; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** Set the default depth test function. */ |
||
| 183 | public void setDefaultDepthTestFunction(ComparisonMode value) |
||
| 184 | { |
||
| 185 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 186 | return; |
||
| 187 | mDefaultDepthTestFunction = value; |
||
| 188 | } |
||
| 189 | |||
| 190 | } |
||
| 191 | } |