|
@@ -120,6 +120,92 @@ public class RenderState implements Cloneable, Savable {
|
|
|
*/
|
|
|
Always,}
|
|
|
|
|
|
+ /**
|
|
|
+ * <code>BlendEquation</code> specifies the blending equation to combine
|
|
|
+ * pixels.
|
|
|
+ */
|
|
|
+ public enum BlendEquation {
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that the source and destination data are
|
|
|
+ * added. (Default) Clamps to [0,1] Useful for things like antialiasing
|
|
|
+ * and transparency.
|
|
|
+ */
|
|
|
+ Add,
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that the source and destination data are
|
|
|
+ * subtracted (Src - Dest). Clamps to [0,1] Falls back to Add if
|
|
|
+ * supportsSubtract is false.
|
|
|
+ */
|
|
|
+ Subtract,
|
|
|
+ /**
|
|
|
+ * Same as Subtract, but the order is reversed (Dst - Src). Clamps to
|
|
|
+ * [0,1] Falls back to Add if supportsSubtract is false.
|
|
|
+ */
|
|
|
+ ReverseSubtract,
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that each component of the result color is
|
|
|
+ * the minimum of the corresponding components of the source and
|
|
|
+ * destination colors. This and Max are useful for applications that
|
|
|
+ * analyze image data (image thresholding against a constant color, for
|
|
|
+ * example). Falls back to Add if supportsMinMax is false.
|
|
|
+ */
|
|
|
+ Min,
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that each component of the result color is
|
|
|
+ * the maximum of the corresponding components of the source and
|
|
|
+ * destination colors. This and Min are useful for applications that
|
|
|
+ * analyze image data (image thresholding against a constant color, for
|
|
|
+ * example). Falls back to Add if supportsMinMax is false.
|
|
|
+ */
|
|
|
+ Max
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <code>BlendEquationAlpha</code> specifies the blending equation to
|
|
|
+ * combine pixels for the alpha component.
|
|
|
+ */
|
|
|
+ public enum BlendEquationAlpha {
|
|
|
+ /**
|
|
|
+ * Sets the blend equation to be the same as the one defined by
|
|
|
+ * {@link #blendEquation}.
|
|
|
+ *
|
|
|
+ */
|
|
|
+ InheritColor,
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that the source and destination data are
|
|
|
+ * added. (Default) Clamps to [0,1] Useful for things like antialiasing
|
|
|
+ * and transparency.
|
|
|
+ */
|
|
|
+ Add,
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that the source and destination data are
|
|
|
+ * subtracted (Src - Dest). Clamps to [0,1] Falls back to Add if
|
|
|
+ * supportsSubtract is false.
|
|
|
+ */
|
|
|
+ Subtract,
|
|
|
+ /**
|
|
|
+ * Same as Subtract, but the order is reversed (Dst - Src). Clamps to
|
|
|
+ * [0,1] Falls back to Add if supportsSubtract is false.
|
|
|
+ */
|
|
|
+ ReverseSubtract,
|
|
|
+ /**
|
|
|
+ * Sets the blend equation so that the result alpha is the minimum of
|
|
|
+ * the source alpha and destination alpha. This and Max are useful for
|
|
|
+ * applications that analyze image data (image thresholding against a
|
|
|
+ * constant color, for example). Falls back to Add if supportsMinMax is
|
|
|
+ * false.
|
|
|
+ */
|
|
|
+ Min,
|
|
|
+ /**
|
|
|
+ * sSets the blend equation so that the result alpha is the maximum of
|
|
|
+ * the source alpha and destination alpha. This and Min are useful for
|
|
|
+ * applications that analyze image data (image thresholding against a
|
|
|
+ * constant color, for example). Falls back to Add if supportsMinMax is
|
|
|
+ * false.
|
|
|
+ */
|
|
|
+ Max
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* <code>BlendMode</code> specifies the blending operation to use.
|
|
|
*
|
|
@@ -282,6 +368,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
ADDITIONAL.applyDepthWrite = false;
|
|
|
ADDITIONAL.applyDepthTest = false;
|
|
|
ADDITIONAL.applyColorWrite = false;
|
|
|
+ ADDITIONAL.applyBlendEquation = false;
|
|
|
+ ADDITIONAL.applyBlendEquationAlpha = false;
|
|
|
ADDITIONAL.applyBlendMode = false;
|
|
|
ADDITIONAL.applyAlphaTest = false;
|
|
|
ADDITIONAL.applyAlphaFallOff = false;
|
|
@@ -299,6 +387,10 @@ public class RenderState implements Cloneable, Savable {
|
|
|
boolean applyDepthTest = true;
|
|
|
boolean colorWrite = true;
|
|
|
boolean applyColorWrite = true;
|
|
|
+ BlendEquation blendEquation = BlendEquation.Add;
|
|
|
+ boolean applyBlendEquation = true;
|
|
|
+ BlendEquationAlpha blendEquationAlpha = BlendEquationAlpha.InheritColor;
|
|
|
+ boolean applyBlendEquationAlpha = true;
|
|
|
BlendMode blendMode = BlendMode.Off;
|
|
|
boolean applyBlendMode = true;
|
|
|
boolean alphaTest = false;
|
|
@@ -352,6 +444,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
oc.write(backStencilDepthPassOperation, "backStencilDepthPassOperation", StencilOperation.Keep);
|
|
|
oc.write(frontStencilFunction, "frontStencilFunction", TestFunction.Always);
|
|
|
oc.write(backStencilFunction, "backStencilFunction", TestFunction.Always);
|
|
|
+ oc.write(blendEquation, "blendEquation", BlendEquation.Add);
|
|
|
+ oc.write(blendEquationAlpha, "blendEquationAlpha", BlendEquationAlpha.InheritColor);
|
|
|
oc.write(depthFunc, "depthFunc", TestFunction.LessOrEqual);
|
|
|
oc.write(alphaFunc, "alphaFunc", TestFunction.Greater);
|
|
|
oc.write(lineWidth, "lineWidth", 1);
|
|
@@ -363,6 +457,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
oc.write(applyDepthWrite, "applyDepthWrite", true);
|
|
|
oc.write(applyDepthTest, "applyDepthTest", true);
|
|
|
oc.write(applyColorWrite, "applyColorWrite", true);
|
|
|
+ oc.write(applyBlendEquation, "applyBlendEquation", true);
|
|
|
+ oc.write(applyBlendEquationAlpha, "applyBlendEquationAlpha", true);
|
|
|
oc.write(applyBlendMode, "applyBlendMode", true);
|
|
|
oc.write(applyAlphaTest, "applyAlphaTest", true);
|
|
|
oc.write(applyAlphaFallOff, "applyAlphaFallOff", true);
|
|
@@ -396,6 +492,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
backStencilDepthPassOperation = ic.readEnum("backStencilDepthPassOperation", StencilOperation.class, StencilOperation.Keep);
|
|
|
frontStencilFunction = ic.readEnum("frontStencilFunction", TestFunction.class, TestFunction.Always);
|
|
|
backStencilFunction = ic.readEnum("backStencilFunction", TestFunction.class, TestFunction.Always);
|
|
|
+ blendEquation = ic.readEnum("blendEquation", BlendEquation.class, BlendEquation.Add);
|
|
|
+ blendEquationAlpha = ic.readEnum("blendEquationAlpha", BlendEquationAlpha.class, BlendEquationAlpha.InheritColor);
|
|
|
depthFunc = ic.readEnum("depthFunc", TestFunction.class, TestFunction.LessOrEqual);
|
|
|
alphaFunc = ic.readEnum("alphaFunc", TestFunction.class, TestFunction.Greater);
|
|
|
lineWidth = ic.readFloat("lineWidth", 1);
|
|
@@ -407,6 +505,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
applyDepthWrite = ic.readBoolean("applyDepthWrite", true);
|
|
|
applyDepthTest = ic.readBoolean("applyDepthTest", true);
|
|
|
applyColorWrite = ic.readBoolean("applyColorWrite", true);
|
|
|
+ applyBlendEquation = ic.readBoolean("applyBlendEquation", true);
|
|
|
+ applyBlendEquationAlpha = ic.readBoolean("applyBlendEquationAlpha", true);
|
|
|
applyBlendMode = ic.readBoolean("applyBlendMode", true);
|
|
|
applyAlphaTest = ic.readBoolean("applyAlphaTest", true);
|
|
|
applyAlphaFallOff = ic.readBoolean("applyAlphaFallOff", true);
|
|
@@ -433,8 +533,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * returns true if the given renderState is equall to this one
|
|
|
- * @param o the renderState to compate to
|
|
|
+ * returns true if the given renderState is equal to this one
|
|
|
+ * @param o the renderState to compare to
|
|
|
* @return true if the renderStates are equal
|
|
|
*/
|
|
|
@Override
|
|
@@ -475,6 +575,14 @@ public class RenderState implements Cloneable, Savable {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if (blendEquation != rs.blendEquation) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (blendEquationAlpha != rs.blendEquationAlpha) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
if (blendMode != rs.blendMode) {
|
|
|
return false;
|
|
|
}
|
|
@@ -663,6 +771,61 @@ public class RenderState implements Cloneable, Savable {
|
|
|
cachedHashCode = -1;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set the blending equation.
|
|
|
+ * <p>
|
|
|
+ * When blending is enabled, (<code>blendMode</code> is not
|
|
|
+ * {@link BlendMode#Off}) the input pixel will be blended with the pixel
|
|
|
+ * already in the color buffer. The blending equation is determined by the
|
|
|
+ * {@link BlendEquation}. For example, the mode {@link BlendMode#Additive}
|
|
|
+ * and {@link BlendEquation#Add} will add the input pixel's color to the
|
|
|
+ * color already in the color buffer:
|
|
|
+ * <br/>
|
|
|
+ * <code>Result = Source Color + Destination Color</code>
|
|
|
+ * <br/>
|
|
|
+ * However, the mode {@link BlendMode#Additive}
|
|
|
+ * and {@link BlendEquation#Subtract} will subtract the input pixel's color to the
|
|
|
+ * color already in the color buffer:
|
|
|
+ * <br/>
|
|
|
+ * <code>Result = Source Color - Destination Color</code>
|
|
|
+ *
|
|
|
+ * @param blendEquation The blend equation to use.
|
|
|
+ */
|
|
|
+ public void setBlendEquation(BlendEquation blendEquation) {
|
|
|
+ applyBlendEquation = true;
|
|
|
+ this.blendEquation = blendEquation;
|
|
|
+ cachedHashCode = -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set the blending equation for the alpha component.
|
|
|
+ * <p>
|
|
|
+ * When blending is enabled, (<code>blendMode</code> is not
|
|
|
+ * {@link BlendMode#Off}) the input pixel will be blended with the pixel
|
|
|
+ * already in the color buffer. The blending equation is determined by the
|
|
|
+ * {@link BlendEquation} and can be overrode for the alpha component using
|
|
|
+ * the {@link BlendEquationAlpha} . For example, the mode
|
|
|
+ * {@link BlendMode#Additive} and {@link BlendEquationAlpha#Add} will add
|
|
|
+ * the input pixel's alpha to the alpha component already in the color
|
|
|
+ * buffer:
|
|
|
+ * <br/>
|
|
|
+ * <code>Result = Source Alpha + Destination Alpha</code>
|
|
|
+ * <br/>
|
|
|
+ * However, the mode {@link BlendMode#Additive} and
|
|
|
+ * {@link BlendEquationAlpha#Subtract} will subtract the input pixel's alpha
|
|
|
+ * to the alpha component already in the color buffer:
|
|
|
+ * <br/>
|
|
|
+ * <code>Result = Source Alpha - Destination Alpha</code>
|
|
|
+ *
|
|
|
+ * @param blendEquationAlpha The blend equation to use for the alpha
|
|
|
+ * component.
|
|
|
+ */
|
|
|
+ public void setBlendEquationAlpha(BlendEquationAlpha blendEquationAlpha) {
|
|
|
+ applyBlendEquationAlpha = true;
|
|
|
+ this.blendEquationAlpha = blendEquationAlpha;
|
|
|
+ cachedHashCode = -1;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Enable depth testing.
|
|
|
*
|
|
@@ -991,6 +1154,24 @@ public class RenderState implements Cloneable, Savable {
|
|
|
return backStencilFunction;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Retrieve the blend equation.
|
|
|
+ *
|
|
|
+ * @return the blend equation.
|
|
|
+ */
|
|
|
+ public BlendEquation getBlendEquation() {
|
|
|
+ return blendEquation;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieve the blend equation used for the alpha component.
|
|
|
+ *
|
|
|
+ * @return the blend equation for the alpha component.
|
|
|
+ */
|
|
|
+ public BlendEquationAlpha getBlendEquationAlpha() {
|
|
|
+ return blendEquationAlpha;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Retrieve the blend mode.
|
|
|
*
|
|
@@ -1165,6 +1346,14 @@ public class RenderState implements Cloneable, Savable {
|
|
|
return applyBlendMode;
|
|
|
}
|
|
|
|
|
|
+ public boolean isApplyBlendEquation() {
|
|
|
+ return applyBlendEquation;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isApplyBlendEquationAlpha() {
|
|
|
+ return applyBlendEquationAlpha;
|
|
|
+ }
|
|
|
+
|
|
|
public boolean isApplyColorWrite() {
|
|
|
return applyColorWrite;
|
|
|
}
|
|
@@ -1219,6 +1408,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
hash = 79 * hash + (this.depthFunc != null ? this.depthFunc.hashCode() : 0);
|
|
|
hash = 79 * hash + (this.colorWrite ? 1 : 0);
|
|
|
hash = 79 * hash + (this.blendMode != null ? this.blendMode.hashCode() : 0);
|
|
|
+ hash = 79 * hash + (this.blendEquation != null ? this.blendEquation.hashCode() : 0);
|
|
|
+ hash = 79 * hash + (this.blendEquationAlpha != null ? this.blendEquationAlpha.hashCode() : 0);
|
|
|
hash = 79 * hash + (this.alphaTest ? 1 : 0);
|
|
|
hash = 79 * hash + (this.alphaFunc != null ? this.alphaFunc.hashCode() : 0);
|
|
|
hash = 79 * hash + Float.floatToIntBits(this.alphaFallOff);
|
|
@@ -1302,6 +1493,16 @@ public class RenderState implements Cloneable, Savable {
|
|
|
} else {
|
|
|
state.colorWrite = colorWrite;
|
|
|
}
|
|
|
+ if (additionalState.applyBlendEquation) {
|
|
|
+ state.blendEquation = additionalState.blendEquation;
|
|
|
+ } else {
|
|
|
+ state.blendEquation = blendEquation;
|
|
|
+ }
|
|
|
+ if (additionalState.applyBlendEquationAlpha) {
|
|
|
+ state.blendEquationAlpha = additionalState.blendEquationAlpha;
|
|
|
+ } else {
|
|
|
+ state.blendEquation = blendEquation;
|
|
|
+ }
|
|
|
if (additionalState.applyBlendMode) {
|
|
|
state.blendMode = additionalState.blendMode;
|
|
|
} else {
|
|
@@ -1389,6 +1590,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
backStencilDepthPassOperation = state.backStencilDepthPassOperation;
|
|
|
frontStencilFunction = state.frontStencilFunction;
|
|
|
backStencilFunction = state.backStencilFunction;
|
|
|
+ blendEquationAlpha = state.blendEquationAlpha;
|
|
|
+ blendEquation = state.blendEquation;
|
|
|
depthFunc = state.depthFunc;
|
|
|
alphaFunc = state.alphaFunc;
|
|
|
lineWidth = state.lineWidth;
|
|
@@ -1399,6 +1602,8 @@ public class RenderState implements Cloneable, Savable {
|
|
|
applyDepthWrite = true;
|
|
|
applyDepthTest = true;
|
|
|
applyColorWrite = true;
|
|
|
+ applyBlendEquation = true;
|
|
|
+ applyBlendEquationAlpha = true;
|
|
|
applyBlendMode = true;
|
|
|
applyAlphaTest = true;
|
|
|
applyAlphaFallOff = true;
|
|
@@ -1424,6 +1629,9 @@ public class RenderState implements Cloneable, Savable {
|
|
|
+ "\napplyDepthTest=" + applyDepthTest
|
|
|
+ "\ncolorWrite=" + colorWrite
|
|
|
+ "\napplyColorWrite=" + applyColorWrite
|
|
|
+ + "\nblendEquation=" + blendEquation
|
|
|
+ + "\napplyBlendEquation=" + applyBlendEquation
|
|
|
+ + "\napplyBlendEquationAlpha=" + applyBlendEquationAlpha
|
|
|
+ "\nblendMode=" + blendMode
|
|
|
+ "\napplyBlendMode=" + applyBlendMode
|
|
|
+ "\nalphaTest=" + alphaTest
|