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

@ -44,6 +44,7 @@ import com.jme3.shader.VarType;
import com.jme3.util.ListMap;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
/**
* Represents a technique instance.
@ -119,7 +120,7 @@ public final class Technique {
* @param rendererCaps The renderer capabilities which the shader should support.
* @return A compatible shader.
*/
Shader makeCurrent(RenderManager renderManager, ArrayList<MatParamOverride> overrides,
Shader makeCurrent(RenderManager renderManager, List<MatParamOverride> overrides,
LightList lights, EnumSet<Caps> rendererCaps) {
TechniqueDefLogic logic = def.getLogic();
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.
*/
public ArrayList<MatParamOverride> getLocalOverrides() {
public List<MatParamOverride> getLocalMatParamOverrides() {
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
* {@link #updateGeometricState()}. After update, the world overrides list
* 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.
*/
public ArrayList<MatParamOverride> getWorldOverrides() {
public List<MatParamOverride> getWorldMatParamOverrides() {
return worldOverrides;
}
@ -600,7 +600,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
* Adds a local material parameter override.
*
* @param override The override to add.
* @see #getLocalOverrides()
* @see MatParamOverride
*/
public void addMatParamOverride(MatParamOverride override) {
localOverrides.add(override);

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

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

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

Loading…
Cancel
Save