Subversion Repositories AndroidProjects

Rev

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