From 5d2f2b19e6110c8c8429d16beb4f68f305d9db8b Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sat, 5 Mar 2016 19:31:26 -0500 Subject: [PATCH] spatial: fix bug in remove/clear MPO add unit test for those methods --- .../src/main/java/com/jme3/scene/Spatial.java | 6 +- .../TechniqueDefMatParamOverrideTest.java | 4 ++ .../jme3/scene/SceneMatParamOverrideTest.java | 69 +++++++++++++++++++ 3 files changed, 76 insertions(+), 3 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 6392c24d1..016e8e969 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -608,16 +608,16 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab } public void removeMatParamOverride(MatParamOverride override) { - if (worldOverrides.remove(override)) { + if (localOverrides.remove(override)) { setMatParamOverrideRefresh(); } } public void clearMatParamOverrides() { - if (!worldOverrides.isEmpty()) { + if (!localOverrides.isEmpty()) { setMatParamOverrideRefresh(); } - worldOverrides.clear(); + localOverrides.clear(); } /** diff --git a/jme3-core/src/test/java/com/jme3/material/TechniqueDefMatParamOverrideTest.java b/jme3-core/src/test/java/com/jme3/material/TechniqueDefMatParamOverrideTest.java index f527103a0..1be918492 100644 --- a/jme3-core/src/test/java/com/jme3/material/TechniqueDefMatParamOverrideTest.java +++ b/jme3-core/src/test/java/com/jme3/material/TechniqueDefMatParamOverrideTest.java @@ -196,6 +196,7 @@ public class TechniqueDefMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); + geometry.updateGeometricState(); outDefines(def("NUM_BONES", VarType.Int, 1234)); outUniforms(uniform("NumberOfBones", VarType.Int, 1234)); @@ -245,6 +246,7 @@ public class TechniqueDefMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); + geometry.updateGeometricState(); outDefines(); outUniforms(); } @@ -287,6 +289,7 @@ public class TechniqueDefMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); + geometry.updateGeometricState(); outDefines(); outUniforms(); outTextures(); @@ -312,6 +315,7 @@ public class TechniqueDefMatParamOverrideTest { reset(); geometry.clearMatParamOverrides(); + geometry.updateGeometricState(); outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1)); outUniforms(uniform("DiffuseMap", VarType.Int, 0)); outTextures(tex1); diff --git a/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java b/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java index df1f58744..739ca6eee 100644 --- a/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java +++ b/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java @@ -78,6 +78,75 @@ public class SceneMatParamOverrideTest { return scene; } + @Test + public void testOverrides_Empty() { + Node n = new Node("Node"); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + + n.updateGeometricState(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + } + + @Test + public void testOverrides_AddRemove() { + MatParamOverride override = mpoBool("Test", true); + Node n = new Node("Node"); + + n.removeMatParamOverride(override); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + + n.addMatParamOverride(override); + + assertSame(n.getLocalOverrides().get(0), override); + assertTrue(n.getWorldOverrides().isEmpty()); + n.updateGeometricState(); + + assertSame(n.getLocalOverrides().get(0), override); + assertSame(n.getWorldOverrides().get(0), override); + + n.removeMatParamOverride(override); + assertTrue(n.getLocalOverrides().isEmpty()); + assertSame(n.getWorldOverrides().get(0), override); + + n.updateGeometricState(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + } + + @Test + public void testOverrides_Clear() { + MatParamOverride override = mpoBool("Test", true); + Node n = new Node("Node"); + + n.clearMatParamOverrides(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + + n.addMatParamOverride(override); + n.clearMatParamOverrides(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + + n.addMatParamOverride(override); + n.updateGeometricState(); + n.clearMatParamOverrides(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertSame(n.getWorldOverrides().get(0), override); + + n.updateGeometricState(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + + n.addMatParamOverride(override); + n.clearMatParamOverrides(); + n.updateGeometricState(); + assertTrue(n.getLocalOverrides().isEmpty()); + assertTrue(n.getWorldOverrides().isEmpty()); + } + @Test public void testOverrides_AddAfterAttach() { Node scene = createDummyScene();