spatial: fix bug in remove/clear MPO

add unit test for those methods
experimental^2^2
Kirill Vainer 9 years ago
parent 5be03af564
commit 5d2f2b19e6
  1. 6
      jme3-core/src/main/java/com/jme3/scene/Spatial.java
  2. 4
      jme3-core/src/test/java/com/jme3/material/TechniqueDefMatParamOverrideTest.java
  3. 69
      jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java

@ -608,16 +608,16 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
} }
public void removeMatParamOverride(MatParamOverride override) { public void removeMatParamOverride(MatParamOverride override) {
if (worldOverrides.remove(override)) { if (localOverrides.remove(override)) {
setMatParamOverrideRefresh(); setMatParamOverrideRefresh();
} }
} }
public void clearMatParamOverrides() { public void clearMatParamOverrides() {
if (!worldOverrides.isEmpty()) { if (!localOverrides.isEmpty()) {
setMatParamOverrideRefresh(); setMatParamOverrideRefresh();
} }
worldOverrides.clear(); localOverrides.clear();
} }
/** /**

@ -196,6 +196,7 @@ public class TechniqueDefMatParamOverrideTest {
reset(); reset();
geometry.clearMatParamOverrides(); geometry.clearMatParamOverrides();
geometry.updateGeometricState();
outDefines(def("NUM_BONES", VarType.Int, 1234)); outDefines(def("NUM_BONES", VarType.Int, 1234));
outUniforms(uniform("NumberOfBones", VarType.Int, 1234)); outUniforms(uniform("NumberOfBones", VarType.Int, 1234));
@ -245,6 +246,7 @@ public class TechniqueDefMatParamOverrideTest {
reset(); reset();
geometry.clearMatParamOverrides(); geometry.clearMatParamOverrides();
geometry.updateGeometricState();
outDefines(); outDefines();
outUniforms(); outUniforms();
} }
@ -287,6 +289,7 @@ public class TechniqueDefMatParamOverrideTest {
reset(); reset();
geometry.clearMatParamOverrides(); geometry.clearMatParamOverrides();
geometry.updateGeometricState();
outDefines(); outDefines();
outUniforms(); outUniforms();
outTextures(); outTextures();
@ -312,6 +315,7 @@ public class TechniqueDefMatParamOverrideTest {
reset(); reset();
geometry.clearMatParamOverrides(); geometry.clearMatParamOverrides();
geometry.updateGeometricState();
outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1)); outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1));
outUniforms(uniform("DiffuseMap", VarType.Int, 0)); outUniforms(uniform("DiffuseMap", VarType.Int, 0));
outTextures(tex1); outTextures(tex1);

@ -78,6 +78,75 @@ public class SceneMatParamOverrideTest {
return scene; 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 @Test
public void testOverrides_AddAfterAttach() { public void testOverrides_AddAfterAttach() {
Node scene = createDummyScene(); Node scene = createDummyScene();

Loading…
Cancel
Save