Rev 787 | 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 ScissorStates : RenderStatesObject |
||
| 13 | { |
||
| 14 | public class ScissorRect |
||
| 15 | { |
||
| 16 | public int x; |
||
| 17 | public int y; |
||
| 18 | public int width; |
||
| 19 | public int height; |
||
| 20 | |||
| 21 | public ScissorRect(int _x, int _y, int _w, int _h) |
||
| 22 | { |
||
| 23 | x = _x; |
||
| 24 | y = _y; |
||
| 25 | width = _w; |
||
| 26 | height = _h; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | private bool mEnabled = false; |
||
| 31 | private ScissorRect mScissorRect = null; // not set means full screen |
||
| 32 | private bool mCurrentlyEnabled = false; |
||
| 33 | private bool mDefaultEnabled = false; |
||
| 34 | |||
| 35 | public ScissorStates(RenderStates renderStates) : base(renderStates) |
||
| 36 | { |
||
| 37 | |||
| 38 | } |
||
| 39 | |||
| 40 | public override void activate(bool force) |
||
| 41 | { |
||
| 42 | if ((force) || (mEnabled != mCurrentlyEnabled)) |
||
| 43 | { |
||
| 44 | if (mEnabled && (mScissorRect != null)) |
||
| 45 | { |
||
| 46 | mCurrentlyEnabled = true; |
||
| 47 | Gl.glEnable(Gl.GL_SCISSOR_TEST); |
||
| 48 | Gl.glScissor(mScissorRect.x, mScissorRect.y, mScissorRect.width, mScissorRect.height); |
||
| 49 | } |
||
| 50 | else |
||
| 51 | { |
||
| 52 | Gl.glDisable(Gl.GL_SCISSOR_TEST); |
||
| 53 | mCurrentlyEnabled = false; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | public override void reset() |
||
| 59 | { |
||
| 60 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 61 | return; |
||
| 62 | |||
| 63 | mEnabled = mDefaultEnabled; |
||
| 64 | mScissorRect = null; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** Check enabled state. */ |
||
| 68 | public bool isEnabled() |
||
| 69 | { |
||
| 70 | return mEnabled; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** Check default enabled state. */ |
||
| 74 | public bool isDefaultEnabled() |
||
| 75 | { |
||
| 76 | return mDefaultEnabled; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** Set enabled state. */ |
||
| 80 | public void setEnabled(bool value) |
||
| 81 | { |
||
| 82 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 83 | return; |
||
| 84 | mEnabled = value; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** Set default enabled state. */ |
||
| 88 | public void setDefaultEnabled(bool value) |
||
| 89 | { |
||
| 90 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 91 | return; |
||
| 92 | mDefaultEnabled = value; |
||
| 93 | } |
||
| 94 | |||
| 95 | /** Set a scissor rect. Note that Y is bottom up. */ |
||
| 96 | public void setScissor(int x, int y, int w, int h) |
||
| 97 | { |
||
| 98 | mScissorRect = new ScissorRect(x, y, w, h); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |