Skip to content

Commit

Permalink
Fix: make the stencil test functions usable. (#1866)
Browse files Browse the repository at this point in the history
* Fix: make the stencil test functions usable.

* Fix: formatting

* Fix: formatting

* Fix: formatting

* Fix: copyright year
  • Loading branch information
zzuegg authored Nov 25, 2022
1 parent 81c26e1 commit 930809e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
90 changes: 89 additions & 1 deletion jme3-core/src/main/java/com/jme3/material/RenderState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2021 jMonkeyEngine
* Copyright (c) 2009-2022 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -480,6 +480,10 @@ public enum StencilOperation {
StencilOperation backStencilDepthPassOperation = StencilOperation.Keep;
TestFunction frontStencilFunction = TestFunction.Always;
TestFunction backStencilFunction = TestFunction.Always;
int frontStencilReference = 0;
int backStencilReference = 0;
int frontStencilMask = Integer.MAX_VALUE;
int backStencilMask = Integer.MAX_VALUE;
int cachedHashCode = -1;
BlendFunc sfactorRGB = BlendFunc.One;
BlendFunc dfactorRGB = BlendFunc.One;
Expand Down Expand Up @@ -508,6 +512,10 @@ public void write(JmeExporter ex) throws IOException {
oc.write(backStencilDepthPassOperation, "backStencilDepthPassOperation", StencilOperation.Keep);
oc.write(frontStencilFunction, "frontStencilFunction", TestFunction.Always);
oc.write(backStencilFunction, "backStencilFunction", TestFunction.Always);
oc.write(frontStencilReference, "frontStencilReference", 0);
oc.write(backStencilReference, "backStencilReference", 0);
oc.write(frontStencilMask, "frontStencilMask", Integer.MAX_VALUE);
oc.write(backStencilMask, "backStencilMask", Integer.MAX_VALUE);
oc.write(blendEquation, "blendEquation", BlendEquation.Add);
oc.write(blendEquationAlpha, "blendEquationAlpha", BlendEquationAlpha.InheritColor);
oc.write(depthFunc, "depthFunc", TestFunction.LessOrEqual);
Expand Down Expand Up @@ -551,6 +559,10 @@ public void read(JmeImporter im) throws IOException {
backStencilDepthPassOperation = ic.readEnum("backStencilDepthPassOperation", StencilOperation.class, StencilOperation.Keep);
frontStencilFunction = ic.readEnum("frontStencilFunction", TestFunction.class, TestFunction.Always);
backStencilFunction = ic.readEnum("backStencilFunction", TestFunction.class, TestFunction.Always);
frontStencilReference = ic.readInt("frontStencilReference", 0);
backStencilReference = ic.readInt("backStencilReference", 0);
frontStencilMask = ic.readInt("frontStencilMask", Integer.MAX_VALUE);
backStencilMask = ic.readInt("backStencilMask", Integer.MAX_VALUE);
blendEquation = ic.readEnum("blendEquation", BlendEquation.class, BlendEquation.Add);
blendEquationAlpha = ic.readEnum("blendEquationAlpha", BlendEquationAlpha.class, BlendEquationAlpha.InheritColor);
depthFunc = ic.readEnum("depthFunc", TestFunction.class, TestFunction.LessOrEqual);
Expand Down Expand Up @@ -695,6 +707,18 @@ public boolean equals(Object o) {
if (backStencilFunction != rs.backStencilFunction) {
return false;
}
if (frontStencilMask != rs.frontStencilMask) {
return false;
}
if (backStencilMask != rs.backStencilMask) {
return false;
}
if (frontStencilReference != rs.frontStencilReference) {
return false;
}
if (backStencilReference != rs.backStencilReference) {
return false;
}
}

if(lineWidth != rs.lineWidth){
Expand Down Expand Up @@ -1128,6 +1152,70 @@ public TestFunction getBackStencilFunction() {
return backStencilFunction;
}

/**
* Sets the front stencil mask
* @param frontStencilMask
*/
public void setFrontStencilMask(int frontStencilMask) {
this.frontStencilMask = frontStencilMask;
}

/**
* Sets the back stencil mask
* @param backStencilMask
*/
public void setBackStencilMask(int backStencilMask) {
this.backStencilMask = backStencilMask;
}

/**
* Sets the front stencil reference
* @param frontStencilReference
*/
public void setFrontStencilReference(int frontStencilReference) {
this.frontStencilReference = frontStencilReference;
}

/**
* Sets the back stencil reference
* @param backStencilReference
*/
public void setBackStencilReference(int backStencilReference) {
this.backStencilReference = backStencilReference;
}

/**
* Returns the front stencil mask
* @return
*/
public int getFrontStencilMask() {
return frontStencilMask;
}

/**
* Returns the front stencil reference
* @return
*/
public int getFrontStencilReference() {
return frontStencilReference;
}

/**
* Returns the back stencil mask
* @return
*/
public int getBackStencilMask() {
return backStencilMask;
}

/**
* Returns the back stencil reference
* @return
*/
public int getBackStencilReference() {
return backStencilReference;
}

/**
* Retrieve the blend equation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ public void applyRenderState(RenderState state) {
convertStencilOperation(state.getBackStencilDepthPassOperation()));
gl.glStencilFuncSeparate(GL.GL_FRONT,
convertTestFunction(state.getFrontStencilFunction()),
0, Integer.MAX_VALUE);
state.getFrontStencilReference(), state.getFrontStencilMask());
gl.glStencilFuncSeparate(GL.GL_BACK,
convertTestFunction(state.getBackStencilFunction()),
0, Integer.MAX_VALUE);
state.getBackStencilReference(), state.getBackStencilMask());
} else {
gl.glDisable(GL.GL_STENCIL_TEST);
}
Expand Down

0 comments on commit 930809e

Please sign in to comment.