public static void apply(final StencilState state) {
// ask for the current state record
final RenderContext context = ContextManager.getCurrentContext();
final ContextCapabilities caps = context.getCapabilities();
final StencilStateRecord record = (StencilStateRecord) context.getStateRecord(StateType.Stencil);
context.setCurrentState(StateType.Stencil, state);
setEnabled(state.isEnabled(), caps.isTwoSidedStencilSupported() ? state.isUseTwoSided() : false, record, caps);
if (state.isEnabled()) {
if (state.isUseTwoSided() && caps.isTwoSidedStencilSupported()) {
EXTStencilTwoSide.glActiveStencilFaceEXT(GL11.GL_BACK);
applyMask(state.getStencilWriteMaskBack(), record, 2);
applyFunc(getGLStencilFunction(state.getStencilFunctionBack()), state.getStencilReferenceBack(),
state.getStencilFuncMaskBack(), record, 2);
applyOp(getGLStencilOp(state.getStencilOpFailBack(), caps),
getGLStencilOp(state.getStencilOpZFailBack(), caps),
getGLStencilOp(state.getStencilOpZPassBack(), caps), record, 2);
EXTStencilTwoSide.glActiveStencilFaceEXT(GL11.GL_FRONT);
applyMask(state.getStencilWriteMaskFront(), record, 1);
applyFunc(getGLStencilFunction(state.getStencilFunctionFront()), state.getStencilReferenceFront(),
state.getStencilFuncMaskFront(), record, 1);
applyOp(getGLStencilOp(state.getStencilOpFailFront(), caps),
getGLStencilOp(state.getStencilOpZFailFront(), caps),
getGLStencilOp(state.getStencilOpZPassFront(), caps), record, 1);
} else {
applyMask(state.getStencilWriteMaskFront(), record, 0);
applyFunc(getGLStencilFunction(state.getStencilFunctionFront()), state.getStencilReferenceFront(),
state.getStencilFuncMaskFront(), record, 0);
applyOp(getGLStencilOp(state.getStencilOpFailFront(), caps),
getGLStencilOp(state.getStencilOpZFailFront(), caps),
getGLStencilOp(state.getStencilOpZPassFront(), caps), record, 0);
}
}
if (!record.isValid()) {
record.validate();
}
}