package com.gebauz.bauzoid.graphics.renderstates;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
/** Depth test render state. */
public class DepthTestStates
extends RenderStatesObject
{
/** Comparison mode for depth test. */
public enum ComparisonMode
{
NEVER,
ALWAYS,
LESS,
LESSEQUAL,
EQUAL,
GREATER,
GREATEREQUAL,
NONEQUAL
};
private boolean mEnabled =
true;
private boolean mWriteEnabled =
true;
private ComparisonMode mDepthTestFunction = ComparisonMode.
LESSEQUAL;
private boolean mCurrentlyEnabled =
true;
private boolean mCurrentlyWriteEnabled =
true;
private ComparisonMode mCurrentDepthTestFunction = ComparisonMode.
LESSEQUAL;
private boolean mDefaultEnabled =
true;
private boolean mDefaultWriteEnabled =
true;
private ComparisonMode mDefaultDepthTestFunction = ComparisonMode.
LESSEQUAL;
/** Constructor. */
public DepthTestStates
(RenderStates renderStates
)
{
super(renderStates
);
}
/** Activate the render state. */
@
Override
public void activate
(boolean force
)
{
if ((force
) ||
(mEnabled
!= mCurrentlyEnabled
))
{
mCurrentlyEnabled = mEnabled
;
if (mEnabled
)
Gdx.
gl.
glEnable(GL20.
GL_DEPTH_TEST);
else
Gdx.
gl.
glDisable(GL20.
GL_DEPTH_TEST);
}
if ((force
) ||
(mWriteEnabled
!= mCurrentlyWriteEnabled
))
{
mCurrentlyWriteEnabled = mWriteEnabled
;
Gdx.
gl.
glDepthMask(mWriteEnabled
);
}
if ((force
) ||
(mDepthTestFunction
!= mCurrentDepthTestFunction
))
{
mCurrentDepthTestFunction = mDepthTestFunction
;
switch (mDepthTestFunction
)
{
case NEVER:
Gdx.
gl.
glDepthFunc(GL20.
GL_NEVER);
break;
case ALWAYS:
Gdx.
gl.
glDepthFunc(GL20.
GL_ALWAYS);
break;
case EQUAL:
Gdx.
gl.
glDepthFunc(GL20.
GL_EQUAL);
break;
case LESS:
Gdx.
gl.
glDepthFunc(GL20.
GL_LESS);
break;
case LESSEQUAL:
Gdx.
gl.
glDepthFunc(GL20.
GL_LEQUAL);
break;
case GREATER:
Gdx.
gl.
glDepthFunc(GL20.
GL_GREATER);
break;
case GREATEREQUAL:
Gdx.
gl.
glDepthFunc(GL20.
GL_GEQUAL);
break;
case NONEQUAL:
Gdx.
gl.
glDepthFunc(GL20.
GL_NOTEQUAL);
break;
}
}
}
/** Reset to default values. */
@
Override
public void reset
()
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mEnabled = mDefaultEnabled
;
mWriteEnabled = mDefaultWriteEnabled
;
mDepthTestFunction = mDefaultDepthTestFunction
;
}
/** Check if enabled. */
public final boolean isEnabled
()
{
return mEnabled
;
}
/** Check default enabled state. */
public final boolean isDefaultEnabled
()
{
return mDefaultEnabled
;
}
/** Check if depth-write is enabled. */
public final boolean isWriteEnabled
()
{
return mWriteEnabled
;
}
/** Check if depth-write is enabled by default. */
public final boolean isDefaultWriteEnabled
()
{
return mDefaultWriteEnabled
;
}
/** Get the depth test function. */
public final ComparisonMode getDepthTestFunction
()
{
return mDepthTestFunction
;
}
/** Get the default depth test function. */
public final ComparisonMode getDefaultDepthTestFunction
()
{
return mDefaultDepthTestFunction
;
}
/** Enable depth testing. */
public final void setEnabled
(boolean value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mEnabled = value
;
}
/** Set the default depth test enabled state. */
public final void setDefaultEnabled
(boolean value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mDefaultEnabled = value
;
}
/** Enable depth write. */
public final void setWriteEnabled
(boolean value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mWriteEnabled = value
;
}
/** Set the default depth write enabled state. */
public final void setDefaultWriteEnabled
(boolean value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mDefaultWriteEnabled = value
;
}
/** Set the depth test function. */
public final void setDepthTestFunction
(ComparisonMode value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mDepthTestFunction = value
;
}
/** Set the default depth test function. */
public final void setDefaultDepthTestFunction
(ComparisonMode value
)
{
if ((mLocked
) ||
(mRenderStates.
isLocked()))
return;
mDefaultDepthTestFunction = value
;
}
}