Added RenderState.BlendMode.Custom
BlendMode.Custom allows glBlendFuncSeparate() calls.
This commit is contained in:
parent
0299e401cc
commit
d39b780fa5
@ -104,6 +104,10 @@ public class AndroidGL implements GL, GLExt, GLFbo {
|
|||||||
GLES20.glBlendFunc(sfactor, dfactor);
|
GLES20.glBlendFunc(sfactor, dfactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha) {
|
||||||
|
GLES20.glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
public void glBufferData(int target, FloatBuffer data, int usage) {
|
public void glBufferData(int target, FloatBuffer data, int usage) {
|
||||||
GLES20.glBufferData(target, getLimitBytes(data), data, usage);
|
GLES20.glBufferData(target, getLimitBytes(data), data, usage);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
package com.jme3.material;
|
package com.jme3.material;
|
||||||
|
|
||||||
import com.jme3.export.*;
|
import com.jme3.export.*;
|
||||||
|
import com.jme3.renderer.opengl.GL;
|
||||||
import com.jme3.scene.Mesh;
|
import com.jme3.scene.Mesh;
|
||||||
import com.jme3.scene.Mesh.Mode;
|
import com.jme3.scene.Mesh.Mode;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -277,7 +278,13 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
* Result = (Source Color * (1 - Dest Color)) + (Dest Color * (1 - Source Color))
|
* Result = (Source Color * (1 - Dest Color)) + (Dest Color * (1 - Source Color))
|
||||||
* -> (GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR)
|
* -> (GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR)
|
||||||
*/
|
*/
|
||||||
Exclusion
|
Exclusion,
|
||||||
|
/**
|
||||||
|
* Allows for custom blending by using glBlendFuncSeparate.
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Custom
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -408,6 +415,10 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
TestFunction frontStencilFunction = TestFunction.Always;
|
TestFunction frontStencilFunction = TestFunction.Always;
|
||||||
TestFunction backStencilFunction = TestFunction.Always;
|
TestFunction backStencilFunction = TestFunction.Always;
|
||||||
int cachedHashCode = -1;
|
int cachedHashCode = -1;
|
||||||
|
int sfactorRGB=GL.GL_ONE;
|
||||||
|
int dfactorRGB=GL.GL_ZERO;
|
||||||
|
int sfactorAlpha=GL.GL_ONE;
|
||||||
|
int dfactorAlpha=GL.GL_ZERO;
|
||||||
|
|
||||||
public void write(JmeExporter ex) throws IOException {
|
public void write(JmeExporter ex) throws IOException {
|
||||||
OutputCapsule oc = ex.getCapsule(this);
|
OutputCapsule oc = ex.getCapsule(this);
|
||||||
@ -434,6 +445,10 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
oc.write(blendEquationAlpha, "blendEquationAlpha", BlendEquationAlpha.InheritColor);
|
oc.write(blendEquationAlpha, "blendEquationAlpha", BlendEquationAlpha.InheritColor);
|
||||||
oc.write(depthFunc, "depthFunc", TestFunction.LessOrEqual);
|
oc.write(depthFunc, "depthFunc", TestFunction.LessOrEqual);
|
||||||
oc.write(lineWidth, "lineWidth", 1);
|
oc.write(lineWidth, "lineWidth", 1);
|
||||||
|
oc.write(sfactorRGB, "sfactorRGB", GL.GL_ONE);
|
||||||
|
oc.write(dfactorRGB, "dfactorRGB", GL.GL_ZERO);
|
||||||
|
oc.write(sfactorAlpha, "sfactorAlpha", GL.GL_ONE);
|
||||||
|
oc.write(dfactorAlpha, "dfactorAlpha", GL.GL_ZERO);
|
||||||
|
|
||||||
// Only "additional render state" has them set to false by default
|
// Only "additional render state" has them set to false by default
|
||||||
oc.write(applyWireFrame, "applyWireFrame", true);
|
oc.write(applyWireFrame, "applyWireFrame", true);
|
||||||
@ -474,6 +489,10 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
blendEquationAlpha = ic.readEnum("blendEquationAlpha", BlendEquationAlpha.class, BlendEquationAlpha.InheritColor);
|
blendEquationAlpha = ic.readEnum("blendEquationAlpha", BlendEquationAlpha.class, BlendEquationAlpha.InheritColor);
|
||||||
depthFunc = ic.readEnum("depthFunc", TestFunction.class, TestFunction.LessOrEqual);
|
depthFunc = ic.readEnum("depthFunc", TestFunction.class, TestFunction.LessOrEqual);
|
||||||
lineWidth = ic.readFloat("lineWidth", 1);
|
lineWidth = ic.readFloat("lineWidth", 1);
|
||||||
|
sfactorRGB = ic.readInt("sfactorRGB", GL.GL_ONE);
|
||||||
|
dfactorAlpha = ic.readInt("dfactorRGB", GL.GL_ZERO);
|
||||||
|
sfactorRGB = ic.readInt("sfactorAlpha", GL.GL_ONE);
|
||||||
|
dfactorAlpha = ic.readInt("dfactorAlpha", GL.GL_ZERO);
|
||||||
|
|
||||||
|
|
||||||
applyWireFrame = ic.readBoolean("applyWireFrame", true);
|
applyWireFrame = ic.readBoolean("applyWireFrame", true);
|
||||||
@ -606,6 +625,14 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (blendMode.equals(BlendMode.Custom)) {
|
||||||
|
return sfactorRGB==rs.getCustomSfactorRGB()
|
||||||
|
&& dfactorRGB==rs.getCustomDfactorRGB()
|
||||||
|
&& sfactorAlpha==rs.getCustomSfactorAlpha()
|
||||||
|
&& dfactorAlpha==rs.getCustomDfactorAlpha();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,6 +771,26 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
cachedHashCode = -1;
|
cachedHashCode = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the custom blend factors for <code>BlendMode.Custom</code> as
|
||||||
|
* defined by glBlendFuncSeparate.
|
||||||
|
*
|
||||||
|
* @param sfactorRGB The source blend factor for RGB components.
|
||||||
|
* @param dfactorRGB The destination blend factor for RGB components.
|
||||||
|
* @param sfactorAlpha The source blend factor for the alpha component.
|
||||||
|
* @param dfactorAlpha The destination blend factor for the alpha component.
|
||||||
|
*/
|
||||||
|
public void setCustomBlendFactors(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha)
|
||||||
|
{
|
||||||
|
this.sfactorRGB = sfactorRGB;
|
||||||
|
this.dfactorRGB = dfactorRGB;
|
||||||
|
this.sfactorAlpha = sfactorAlpha;
|
||||||
|
this.dfactorAlpha = dfactorAlpha;
|
||||||
|
cachedHashCode = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable depth testing.
|
* Enable depth testing.
|
||||||
*
|
*
|
||||||
@ -1085,6 +1132,46 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
return blendMode;
|
return blendMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the source factor for the RGB components in
|
||||||
|
* <code>BlendMode.Custom</code>.
|
||||||
|
*
|
||||||
|
* @return the custom source factor for RGB components.
|
||||||
|
*/
|
||||||
|
public int getCustomSfactorRGB() {
|
||||||
|
return sfactorRGB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the destination factor for the RGB components in
|
||||||
|
* <code>BlendMode.Custom</code>.
|
||||||
|
*
|
||||||
|
* @return the custom destination factor for RGB components.
|
||||||
|
*/
|
||||||
|
public int getCustomDfactorRGB() {
|
||||||
|
return dfactorRGB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the source factor for the alpha component in
|
||||||
|
* <code>BlendMode.Custom</code>.
|
||||||
|
*
|
||||||
|
* @return the custom destination factor for alpha component.
|
||||||
|
*/
|
||||||
|
public int getCustomSfactorAlpha() {
|
||||||
|
return sfactorAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the destination factor for the alpha component in
|
||||||
|
* <code>BlendMode.Custom</code>.
|
||||||
|
*
|
||||||
|
* @return the custom destination factor for alpha component.
|
||||||
|
*/
|
||||||
|
public int getCustomDfactorAlpha() {
|
||||||
|
return dfactorAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true
|
* @return true
|
||||||
* @deprecated Always returns true since point sprite is always enabled.
|
* @deprecated Always returns true since point sprite is always enabled.
|
||||||
@ -1306,6 +1393,11 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
hash = 79 * hash + (this.frontStencilFunction != null ? this.frontStencilFunction.hashCode() : 0);
|
hash = 79 * hash + (this.frontStencilFunction != null ? this.frontStencilFunction.hashCode() : 0);
|
||||||
hash = 79 * hash + (this.backStencilFunction != null ? this.backStencilFunction.hashCode() : 0);
|
hash = 79 * hash + (this.backStencilFunction != null ? this.backStencilFunction.hashCode() : 0);
|
||||||
hash = 79 * hash + Float.floatToIntBits(this.lineWidth);
|
hash = 79 * hash + Float.floatToIntBits(this.lineWidth);
|
||||||
|
|
||||||
|
hash = 79 * hash + this.sfactorRGB;
|
||||||
|
hash = 79 * hash + this.dfactorRGB;
|
||||||
|
hash = 79 * hash + this.sfactorAlpha;
|
||||||
|
hash = 79 * hash + this.dfactorAlpha;
|
||||||
cachedHashCode = hash;
|
cachedHashCode = hash;
|
||||||
}
|
}
|
||||||
return cachedHashCode;
|
return cachedHashCode;
|
||||||
@ -1380,6 +1472,13 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
}
|
}
|
||||||
if (additionalState.applyBlendMode) {
|
if (additionalState.applyBlendMode) {
|
||||||
state.blendMode = additionalState.blendMode;
|
state.blendMode = additionalState.blendMode;
|
||||||
|
if (additionalState.getBlendMode().equals(BlendMode.Custom)) {
|
||||||
|
state.setCustomBlendFactors(
|
||||||
|
additionalState.getCustomSfactorRGB(),
|
||||||
|
additionalState.getCustomDfactorRGB(),
|
||||||
|
additionalState.getCustomSfactorAlpha(),
|
||||||
|
additionalState.getCustomDfactorAlpha());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
state.blendMode = blendMode;
|
state.blendMode = blendMode;
|
||||||
}
|
}
|
||||||
@ -1464,6 +1563,11 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
applyPolyOffset = true;
|
applyPolyOffset = true;
|
||||||
applyDepthFunc = true;
|
applyDepthFunc = true;
|
||||||
applyLineWidth = true;
|
applyLineWidth = true;
|
||||||
|
|
||||||
|
sfactorRGB = state.sfactorRGB;
|
||||||
|
dfactorRGB = state.dfactorRGB;
|
||||||
|
sfactorAlpha = state.sfactorAlpha;
|
||||||
|
dfactorAlpha = state.dfactorAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1490,6 +1594,8 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
+ "\noffsetFactor=" + offsetFactor
|
+ "\noffsetFactor=" + offsetFactor
|
||||||
+ "\noffsetUnits=" + offsetUnits
|
+ "\noffsetUnits=" + offsetUnits
|
||||||
+ "\nlineWidth=" + lineWidth
|
+ "\nlineWidth=" + lineWidth
|
||||||
+ "\n]";
|
+ (blendMode.equals(BlendMode.Custom)?
|
||||||
|
"\ncustomBlendFactors=("+sfactorRGB+", "+dfactorRGB+", "+sfactorAlpha+", "+dfactorAlpha+")":
|
||||||
|
"\n]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,6 +197,7 @@ public interface GL {
|
|||||||
public void glBindTexture(int target, int texture);
|
public void glBindTexture(int target, int texture);
|
||||||
public void glBlendEquationSeparate(int colorMode, int alphaMode);
|
public void glBlendEquationSeparate(int colorMode, int alphaMode);
|
||||||
public void glBlendFunc(int sfactor, int dfactor);
|
public void glBlendFunc(int sfactor, int dfactor);
|
||||||
|
public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha);
|
||||||
public void glBufferData(int target, long data_size, int usage);
|
public void glBufferData(int target, long data_size, int usage);
|
||||||
public void glBufferData(int target, FloatBuffer data, int usage);
|
public void glBufferData(int target, FloatBuffer data, int usage);
|
||||||
public void glBufferData(int target, ShortBuffer data, int usage);
|
public void glBufferData(int target, ShortBuffer data, int usage);
|
||||||
|
@ -45,6 +45,12 @@ public class GLDebugES extends GLDebug implements GL, GLFbo, GLExt {
|
|||||||
checkError();
|
checkError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dFactorAlpha)
|
||||||
|
{
|
||||||
|
gl.glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dFactorAlpha);
|
||||||
|
checkError();
|
||||||
|
}
|
||||||
|
|
||||||
public void glBufferData(int target, FloatBuffer data, int usage) {
|
public void glBufferData(int target, FloatBuffer data, int usage) {
|
||||||
gl.glBufferData(target, data, usage);
|
gl.glBufferData(target, data, usage);
|
||||||
checkError();
|
checkError();
|
||||||
|
@ -748,6 +748,9 @@ public final class GLRenderer implements Renderer {
|
|||||||
case Exclusion:
|
case Exclusion:
|
||||||
gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR);
|
gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR);
|
||||||
break;
|
break;
|
||||||
|
case Custom:
|
||||||
|
gl.glBlendFuncSeparate(state.getCustomSfactorRGB(), state.getCustomDfactorRGB(), state.getCustomSfactorAlpha(), state.getCustomDfactorAlpha());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unrecognized blend mode: "
|
throw new UnsupportedOperationException("Unrecognized blend mode: "
|
||||||
+ state.getBlendMode());
|
+ state.getBlendMode());
|
||||||
|
@ -136,6 +136,11 @@ public class IosGL implements GL, GLExt, GLFbo {
|
|||||||
JmeIosGLES.glBlendFunc(sfactor, dfactor);
|
JmeIosGLES.glBlendFunc(sfactor, dfactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha) {
|
||||||
|
JmeIosGLES.glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void glBufferData(int target, FloatBuffer data, int usage) {
|
public void glBufferData(int target, FloatBuffer data, int usage) {
|
||||||
JmeIosGLES.glBufferData(target, getLimitBytes(data), data, usage);
|
JmeIosGLES.glBufferData(target, getLimitBytes(data), data, usage);
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,7 @@ public class JmeIosGLES {
|
|||||||
// public static native void glBindVertexArray // TODO: Investigate this
|
// public static native void glBindVertexArray // TODO: Investigate this
|
||||||
public static native void glBlendEquationSeparate(int colorMode, int alphaMode);
|
public static native void glBlendEquationSeparate(int colorMode, int alphaMode);
|
||||||
public static native void glBlendFunc(int sfactor, int dfactor);
|
public static native void glBlendFunc(int sfactor, int dfactor);
|
||||||
|
public static native void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha);
|
||||||
public static native void glBufferData(int target, int size, Buffer data, int usage);
|
public static native void glBufferData(int target, int size, Buffer data, int usage);
|
||||||
public static native void glBufferData2(int target, int size, byte[] data, int offset, int usage);
|
public static native void glBufferData2(int target, int size, byte[] data, int offset, int usage);
|
||||||
public static native void glBufferSubData(int target, int offset, int size, Buffer data);
|
public static native void glBufferSubData(int target, int offset, int size, Buffer data);
|
||||||
|
@ -88,6 +88,11 @@ public class JoglGL implements GL, GL2, GL3, GL4 {
|
|||||||
GLContext.getCurrentGL().glBlendFunc(param1, param2);
|
GLContext.getCurrentGL().glBlendFunc(param1, param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha) {
|
||||||
|
GLContext.getCurrentGL().glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void glBufferData(int param1, long param2, int param3) {
|
public void glBufferData(int param1, long param2, int param3) {
|
||||||
GLContext.getCurrentGL().glBufferData(param1, param2, null, param3);
|
GLContext.getCurrentGL().glBufferData(param1, param2, null, param3);
|
||||||
@ -610,4 +615,5 @@ public class JoglGL implements GL, GL2, GL3, GL4 {
|
|||||||
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5) {
|
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5) {
|
||||||
GLContext.getCurrentGL().getGL3().glFramebufferTextureLayer(param1, param2, param3, param4, param5);
|
GLContext.getCurrentGL().getGL3().glFramebufferTextureLayer(param1, param2, param3, param4, param5);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,10 @@ public final class LwjglGL implements GL, GL2, GL3, GL4 {
|
|||||||
GL11.glBlendFunc(param1, param2);
|
GL11.glBlendFunc(param1, param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void glBlendFuncSeparate(int param1, int param2, int param3, int param4) {
|
||||||
|
GL14.glBlendFuncSeparate(param1, param2, param3, param4);
|
||||||
|
}
|
||||||
|
|
||||||
public void glBufferData(int param1, long param2, int param3) {
|
public void glBufferData(int param1, long param2, int param3) {
|
||||||
GL15.glBufferData(param1, param2, param3);
|
GL15.glBufferData(param1, param2, param3);
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,10 @@ public class LwjglGL implements GL, GL2, GL3, GL4 {
|
|||||||
GL11.glBlendFunc(param1, param2);
|
GL11.glBlendFunc(param1, param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void glBlendFuncSeparate(int param1, int param2, int param3, int param4) {
|
||||||
|
GL14.glBlendFuncSeparate(param1, param2, param3, param4);
|
||||||
|
}
|
||||||
|
|
||||||
public void glBufferData(int param1, long param2, int param3) {
|
public void glBufferData(int param1, long param2, int param3) {
|
||||||
GL15.glBufferData(param1, param2, param3);
|
GL15.glBufferData(param1, param2, param3);
|
||||||
}
|
}
|
||||||
|
@ -367,7 +367,11 @@ public class J3MOutputCapsule implements OutputCapsule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int value, String name, int defVal) throws IOException {
|
public void write(int value, String name, int defVal) throws IOException {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
if (value == defVal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
putParameter(name, Integer.toString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user