From f72df167c0311dc9a4fe14bba86d84669f6cefa7 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Fri, 8 Apr 2016 23:05:15 -0400 Subject: [PATCH] MPO: make sure child overrides parent --- .../src/main/java/com/jme3/scene/Spatial.java | 2 +- .../MaterialMatParamOverrideTest.java | 46 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index 7870d5849..452ccce47 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -593,8 +593,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab worldOverrides.addAll(localOverrides); } else { assert (parent.refreshFlags & RF_MATPARAM_OVERRIDE) == 0; - worldOverrides.addAll(localOverrides); worldOverrides.addAll(parent.worldOverrides); + worldOverrides.addAll(localOverrides); } } diff --git a/jme3-core/src/test/java/com/jme3/material/MaterialMatParamOverrideTest.java b/jme3-core/src/test/java/com/jme3/material/MaterialMatParamOverrideTest.java index 846059e6e..ebd1ec2b4 100644 --- a/jme3-core/src/test/java/com/jme3/material/MaterialMatParamOverrideTest.java +++ b/jme3-core/src/test/java/com/jme3/material/MaterialMatParamOverrideTest.java @@ -46,6 +46,7 @@ import org.junit.Assert; import org.junit.Test; import static com.jme3.scene.MPOTestUtils.*; +import com.jme3.scene.Node; import com.jme3.shader.DefineList; import com.jme3.system.NullRenderer; import com.jme3.system.TestUtil; @@ -54,6 +55,7 @@ import com.jme3.texture.Texture; import com.jme3.texture.Texture2D; import java.util.HashMap; import java.util.Map; +import org.junit.Before; /** * Validates how {@link MatParamOverride MPOs} work on the material level. @@ -124,6 +126,18 @@ public class MaterialMatParamOverrideTest { outUniforms(uniform("AlphaDiscardThreshold", VarType.Float, 2.79f)); } + @Test + @Test + public void testChildOverridesParent() { + material("Common/MatDefs/Light/Lighting.j3md"); + + inputParentMpo(mpoFloat("AlphaDiscardThreshold", 3.12f)); + inputMpo(mpoFloat("AlphaDiscardThreshold", 2.79f)); + + outUniforms(uniform("AlphaDiscardThreshold", VarType.Float, 2.79f)); + outDefines(def("DISCARD_ALPHA", VarType.Float, 2.79f)); + } + @Test public void testMpoDisable() { material("Common/MatDefs/Light/Lighting.j3md"); @@ -222,7 +236,7 @@ public class MaterialMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); - geometry.updateGeometricState(); + root.updateGeometricState(); outDefines(def("NUM_BONES", VarType.Int, 1234)); outUniforms(uniform("NumberOfBones", VarType.Int, 1234)); @@ -272,7 +286,7 @@ public class MaterialMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); - geometry.updateGeometricState(); + root.updateGeometricState(); outDefines(); outUniforms(); } @@ -315,7 +329,7 @@ public class MaterialMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); - geometry.updateGeometricState(); + root.updateGeometricState(); outDefines(); outUniforms(); outTextures(); @@ -341,7 +355,7 @@ public class MaterialMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); - geometry.updateGeometricState(); + root.updateGeometricState(); outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1)); outUniforms(uniform("DiffuseMap", VarType.Int, 0)); outTextures(tex1); @@ -369,9 +383,15 @@ public class MaterialMatParamOverrideTest { } } - private final Geometry geometry = new Geometry("geometry", new Box(1, 1, 1)); + private final Geometry geometry = new Geometry("Geometry", new Box(1, 1, 1)); + private final Node root = new Node("Root Node"); private final LightList lightList = new LightList(geometry); + @Before + public void setUp() { + root.attachChild(geometry); + } + private final NullRenderer renderer = new NullRenderer() { @Override public void setShader(Shader shader) { @@ -407,7 +427,17 @@ public class MaterialMatParamOverrideTest { for (MatParamOverride override : overrides) { geometry.addMatParamOverride(override); } - geometry.updateGeometricState(); + root.updateGeometricState(); + } + + private void inputParentMpo(MatParamOverride... overrides) { + if (evaluated) { + throw new IllegalStateException(); + } + for (MatParamOverride override : overrides) { + root.addMatParamOverride(override); + } + root.updateGeometricState(); } private void reset() { @@ -520,6 +550,10 @@ public class MaterialMatParamOverrideTest { } private void outUniforms(Uniform... uniforms) { + if (!evaluated) { + evaluateTechniqueDef(); + } + HashSet actualUniforms = new HashSet<>(); for (Uniform uniform : usedShader.getUniformMap().values()) {