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