Subversion Repositories AndroidProjects

Rev

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