MPO: add ability to disable an override

experimental^2^2
Kirill Vainer 9 years ago
parent db691dab99
commit 50658b8e53
  1. 34
      jme3-core/src/main/java/com/jme3/material/MatParamOverride.java
  2. 2
      jme3-core/src/main/java/com/jme3/material/Material.java
  3. 3
      jme3-core/src/main/java/com/jme3/material/Technique.java
  4. 27
      jme3-core/src/test/java/com/jme3/material/MaterialMatParamOverrideTest.java

@ -35,6 +35,8 @@ import com.jme3.shader.VarType;
public final class MatParamOverride extends MatParam {
private boolean enabled = true;
public MatParamOverride() {
super();
}
@ -43,4 +45,36 @@ public final class MatParamOverride extends MatParam {
super(type, name, value);
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && this.enabled == ((MatParamOverride) obj).enabled;
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 59 * hash + (enabled ? 1 : 0);
return hash;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(enabled, "enabled", true);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
enabled = ic.readBoolean("enabled", true);
}
}

@ -792,7 +792,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
VarType type = override.getVarType();
MatParam paramDef = def.getMaterialParam(override.getName());
if (paramDef == null || paramDef.getVarType() != type) {
if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) {
continue;
}

@ -128,6 +128,9 @@ public final class Technique {
dynamicDefines.setAll(paramDefines);
for (MatParamOverride override : overrides) {
if (!override.isEnabled()) {
continue;
}
Integer defineId = def.getShaderParamDefineId(override.name);
if (defineId != null) {
if (def.getDefineIdType(defineId) == override.type) {

@ -55,7 +55,7 @@ import com.jme3.texture.Texture2D;
import java.util.HashMap;
import java.util.Map;
public class TechniqueDefMatParamOverrideTest {
public class MaterialMatParamOverrideTest {
private static final HashSet<String> IGNORED_UNIFORMS = new HashSet<String>(
Arrays.asList(new String[]{"m_ParallaxHeight", "m_Shininess"}));
@ -119,6 +119,27 @@ public class TechniqueDefMatParamOverrideTest {
outUniforms(uniform("AlphaDiscardThreshold", VarType.Float, 2.79f));
}
@Test
public void testMpoDisable() {
material("Common/MatDefs/Light/Lighting.j3md");
inputMp(mpoFloat("AlphaDiscardThreshold", 3.12f));
MatParamOverride override = mpoFloat("AlphaDiscardThreshold", 2.79f);
inputMpo(override);
outDefines(def("DISCARD_ALPHA", VarType.Float, 2.79f));
outUniforms(uniform("AlphaDiscardThreshold", VarType.Float, 2.79f));
reset();
override.setEnabled(false);
outDefines(def("DISCARD_ALPHA", VarType.Float, 3.12f));
outUniforms(uniform("AlphaDiscardThreshold", VarType.Float, 3.12f));
reset();
override.setEnabled(true);
outDefines(def("DISCARD_ALPHA", VarType.Float, 2.79f));
outUniforms(uniform("AlphaDiscardThreshold", VarType.Float, 2.79f));
}
@Test
public void testIntMpoOnly() {
material("Common/MatDefs/Light/Lighting.j3md");
@ -349,13 +370,13 @@ public class TechniqueDefMatParamOverrideTest {
private final NullRenderer renderer = new NullRenderer() {
@Override
public void setShader(Shader shader) {
TechniqueDefMatParamOverrideTest.this.usedShader = shader;
MaterialMatParamOverrideTest.this.usedShader = shader;
evaluated = true;
}
@Override
public void setTexture(int unit, Texture texture) {
TechniqueDefMatParamOverrideTest.this.usedTextures[unit] = texture;
MaterialMatParamOverrideTest.this.usedTextures[unit] = texture;
}
};
private final RenderManager renderManager = new RenderManager(renderer);
Loading…
Cancel
Save