Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.bauzoid.graphics.renderstates;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
public class ScissorStates
extends RenderStatesObject
{
public class ScissorRect
{
public int x
;
public int y
;
public int width
;
public int height
;
public ScissorRect
(int _x,
int _y,
int _w,
int _h
)
{
x = _x
;
y = _y
;
width = _w
;
height = _h
;
}
}
private boolean mEnabled =
false;
private ScissorRect mScissorRect =
null; // not set means full screen
private boolean mCurrentlyEnabled =
false;
private boolean mDefaultEnabled =
false;
public ScissorStates
(RenderStates renderStates
)
{
super(renderStates
);
}
@
Override
public void activate
(boolean force
)
{
if ((force
) ||
(mEnabled
!= mCurrentlyEnabled
))
{
if (mEnabled
&& (mScissorRect
!=
null))
{
mCurrentlyEnabled =
true;
Gdx.
gl.
glEnable(GL20.
GL_SCISSOR_TEST);
Gdx.
gl.
glScissor(mScissorRect.
x, mScissorRect.
y, mScissorRect.
width, mScissorRect.
height);
}
else
{
Gdx.
gl.
glDisable(GL20.
GL_SCISSOR_TEST);
mCurrentlyEnabled =
false;
}
}
}
@
Override
public void reset
()
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mEnabled = mDefaultEnabled
;
mScissorRect =
null;
}
/** Check enabled state. */
public final boolean isEnabled
()
{
return mEnabled
;
}
/** Check default enabled state. */
public final boolean isDefaultEnabled
()
{
return mDefaultEnabled
;
}
/** Set enabled state. */
public final void setEnabled
(boolean value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mEnabled = value
;
}
/** Set default enabled state. */
public final void setDefaultEnabled
(boolean value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mDefaultEnabled = value
;
}
/** Set a scissor rect. Note that Y is bottom up. */
public final void setScissor
(int x,
int y,
int w,
int h
)
{
mScissorRect =
new ScissorRect
(x, y, w, h
);
}
}