MPO: use List instead of ArrayList

Also rename get*Overrides to get*MatParamOverrides to be more specific.
experimental^2^2
Kirill Vainer 9 years ago
parent 50658b8e53
commit 8344994328
  1. 6
      jme3-core/src/main/java/com/jme3/material/Material.java
  2. 3
      jme3-core/src/main/java/com/jme3/material/Technique.java
  3. 8
      jme3-core/src/main/java/com/jme3/scene/Spatial.java
  4. 6
      jme3-core/src/test/java/com/jme3/scene/MPOTestUtils.java
  5. 58
      jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java
  6. 4
      jme3-examples/src/main/java/jme3test/material/TestMatParamOverride.java

@ -785,7 +785,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
sortingId = -1; sortingId = -1;
} }
private void updateShaderMaterialParameters(Renderer renderer, Shader shader, ArrayList<MatParamOverride> overrides) { private void updateShaderMaterialParameters(Renderer renderer, Shader shader, List<MatParamOverride> overrides) {
int unit = 0; int unit = 0;
for (MatParamOverride override : overrides) { for (MatParamOverride override : overrides) {
@ -964,7 +964,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
updateRenderState(renderManager, renderer, techniqueDef); updateRenderState(renderManager, renderer, techniqueDef);
// Get world overrides // Get world overrides
ArrayList<MatParamOverride> overrides = geometry.getWorldOverrides(); List<MatParamOverride> overrides = geometry.getWorldMatParamOverrides();
// Select shader to use // Select shader to use
Shader shader = technique.makeCurrent(renderManager, overrides, lights, rendererCaps); Shader shader = technique.makeCurrent(renderManager, overrides, lights, rendererCaps);
@ -976,7 +976,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
renderManager.updateUniformBindings(shader); renderManager.updateUniformBindings(shader);
// Set material parameters // Set material parameters
updateShaderMaterialParameters(renderer, shader, geometry.getWorldOverrides()); updateShaderMaterialParameters(renderer, shader, geometry.getWorldMatParamOverrides());
// Clear any uniforms not changed by material. // Clear any uniforms not changed by material.
resetUniformsNotSetByCurrent(shader); resetUniformsNotSetByCurrent(shader);

@ -44,6 +44,7 @@ import com.jme3.shader.VarType;
import com.jme3.util.ListMap; import com.jme3.util.ListMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List;
/** /**
* Represents a technique instance. * Represents a technique instance.
@ -119,7 +120,7 @@ public final class Technique {
* @param rendererCaps The renderer capabilities which the shader should support. * @param rendererCaps The renderer capabilities which the shader should support.
* @return A compatible shader. * @return A compatible shader.
*/ */
Shader makeCurrent(RenderManager renderManager, ArrayList<MatParamOverride> overrides, Shader makeCurrent(RenderManager renderManager, List<MatParamOverride> overrides,
LightList lights, EnumSet<Caps> rendererCaps) { LightList lights, EnumSet<Caps> rendererCaps) {
TechniqueDefLogic logic = def.getLogic(); TechniqueDefLogic logic = def.getLogic();
AssetManager assetManager = owner.getMaterialDef().getAssetManager(); AssetManager assetManager = owner.getMaterialDef().getAssetManager();

@ -430,7 +430,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
* *
* @return The list of local material parameter overrides. * @return The list of local material parameter overrides.
*/ */
public ArrayList<MatParamOverride> getLocalOverrides() { public List<MatParamOverride> getLocalMatParamOverrides() {
return localOverrides; return localOverrides;
} }
@ -440,11 +440,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
* Note that this list is only updated on a call to * Note that this list is only updated on a call to
* {@link #updateGeometricState()}. After update, the world overrides list * {@link #updateGeometricState()}. After update, the world overrides list
* will contain the {@link #getParent() parent's} world overrides combined * will contain the {@link #getParent() parent's} world overrides combined
* with this spatial's {@link #getLocalOverrides() local overrides}. * with this spatial's {@link #getLocalMatParamOverrides() local overrides}.
* *
* @return The list of world material parameter overrides. * @return The list of world material parameter overrides.
*/ */
public ArrayList<MatParamOverride> getWorldOverrides() { public List<MatParamOverride> getWorldMatParamOverrides() {
return worldOverrides; return worldOverrides;
} }
@ -600,7 +600,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
* Adds a local material parameter override. * Adds a local material parameter override.
* *
* @param override The override to add. * @param override The override to add.
* @see #getLocalOverrides() * @see MatParamOverride
*/ */
public void addMatParamOverride(MatParamOverride override) { public void addMatParamOverride(MatParamOverride override) {
localOverrides.add(override); localOverrides.add(override);

@ -57,14 +57,14 @@ public class MPOTestUtils {
scene.checkCulling(DUMMY_CAM); scene.checkCulling(DUMMY_CAM);
Set<MatParamOverride> actualOverrides = new HashSet<MatParamOverride>(); Set<MatParamOverride> actualOverrides = new HashSet<MatParamOverride>();
for (MatParamOverride override : scene.getWorldOverrides()) { for (MatParamOverride override : scene.getWorldMatParamOverrides()) {
actualOverrides.add(override); actualOverrides.add(override);
} }
Set<MatParamOverride> expectedOverrides = new HashSet<MatParamOverride>(); Set<MatParamOverride> expectedOverrides = new HashSet<MatParamOverride>();
Spatial current = scene; Spatial current = scene;
while (current != null) { while (current != null) {
for (MatParamOverride override : current.getLocalOverrides()) { for (MatParamOverride override : current.getLocalMatParamOverrides()) {
expectedOverrides.add(override); expectedOverrides.add(override);
} }
current = current.getParent(); current = current.getParent();
@ -151,7 +151,7 @@ public class MPOTestUtils {
sb.append(")"); sb.append(")");
} }
if (!scene.getLocalOverrides().isEmpty()) { if (!scene.getLocalMatParamOverrides().isEmpty()) {
sb.append(" [MPO]"); sb.append(" [MPO]");
} }

@ -41,11 +41,11 @@ import static org.junit.Assert.*;
import com.jme3.system.TestUtil; import com.jme3.system.TestUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class SceneMatParamOverrideTest { public class SceneMatParamOverrideTest {
private static Node createDummyScene() { private static Node createDummyScene() {
Node scene = new Node("Scene Node"); Node scene = new Node("Scene Node");
@ -81,12 +81,12 @@ public class SceneMatParamOverrideTest {
@Test @Test
public void testOverrides_Empty() { public void testOverrides_Empty() {
Node n = new Node("Node"); Node n = new Node("Node");
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
n.updateGeometricState(); n.updateGeometricState();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
} }
@Test @Test
@ -95,25 +95,25 @@ public class SceneMatParamOverrideTest {
Node n = new Node("Node"); Node n = new Node("Node");
n.removeMatParamOverride(override); n.removeMatParamOverride(override);
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
n.addMatParamOverride(override); n.addMatParamOverride(override);
assertSame(n.getLocalOverrides().get(0), override); assertSame(n.getLocalMatParamOverrides().get(0), override);
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
n.updateGeometricState(); n.updateGeometricState();
assertSame(n.getLocalOverrides().get(0), override); assertSame(n.getLocalMatParamOverrides().get(0), override);
assertSame(n.getWorldOverrides().get(0), override); assertSame(n.getWorldMatParamOverrides().get(0), override);
n.removeMatParamOverride(override); n.removeMatParamOverride(override);
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertSame(n.getWorldOverrides().get(0), override); assertSame(n.getWorldMatParamOverrides().get(0), override);
n.updateGeometricState(); n.updateGeometricState();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
} }
@Test @Test
@ -122,29 +122,29 @@ public class SceneMatParamOverrideTest {
Node n = new Node("Node"); Node n = new Node("Node");
n.clearMatParamOverrides(); n.clearMatParamOverrides();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
n.addMatParamOverride(override); n.addMatParamOverride(override);
n.clearMatParamOverrides(); n.clearMatParamOverrides();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
n.addMatParamOverride(override); n.addMatParamOverride(override);
n.updateGeometricState(); n.updateGeometricState();
n.clearMatParamOverrides(); n.clearMatParamOverrides();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertSame(n.getWorldOverrides().get(0), override); assertSame(n.getWorldMatParamOverrides().get(0), override);
n.updateGeometricState(); n.updateGeometricState();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
n.addMatParamOverride(override); n.addMatParamOverride(override);
n.clearMatParamOverrides(); n.clearMatParamOverrides();
n.updateGeometricState(); n.updateGeometricState();
assertTrue(n.getLocalOverrides().isEmpty()); assertTrue(n.getLocalMatParamOverrides().isEmpty());
assertTrue(n.getWorldOverrides().isEmpty()); assertTrue(n.getWorldMatParamOverrides().isEmpty());
} }
@Test @Test
@ -233,8 +233,8 @@ public class SceneMatParamOverrideTest {
validateScene(clonedScene); validateScene(clonedScene);
validateScene(originalScene); validateScene(originalScene);
ArrayList<MatParamOverride> clonedOverrides = clonedScene.getChild("A").getLocalOverrides(); List<MatParamOverride> clonedOverrides = clonedScene.getChild("A").getLocalMatParamOverrides();
ArrayList<MatParamOverride> originalOverrides = originalScene.getChild("A").getLocalOverrides(); List<MatParamOverride> originalOverrides = originalScene.getChild("A").getLocalMatParamOverrides();
assertNotSame(clonedOverrides, originalOverrides); assertNotSame(clonedOverrides, originalOverrides);
assertEquals(clonedOverrides, originalOverrides); assertEquals(clonedOverrides, originalOverrides);
@ -258,8 +258,8 @@ public class SceneMatParamOverrideTest {
validateScene(root); validateScene(root);
validateScene(scene); validateScene(scene);
assertNotSame(override, loadedScene.getChild("A").getLocalOverrides().get(0)); assertNotSame(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0));
assertEquals(override, loadedScene.getChild("A").getLocalOverrides().get(0)); assertEquals(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0));
} }
@Test @Test

@ -79,12 +79,12 @@ public class TestMatParamOverride extends SimpleApplication {
@Override @Override
public void onAction(String name, boolean isPressed, float tpf) { public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("override") && isPressed) { if (name.equals("override") && isPressed) {
if (!rootNode.getLocalOverrides().isEmpty()) { if (!rootNode.getLocalMatParamOverrides().isEmpty()) {
rootNode.clearMatParamOverrides(); rootNode.clearMatParamOverrides();
} else { } else {
rootNode.addMatParamOverride(override); rootNode.addMatParamOverride(override);
} }
System.out.println(rootNode.getLocalOverrides()); System.out.println(rootNode.getLocalMatParamOverrides());
} }
} }
}, "override"); }, "override");

Loading…
Cancel
Save