From 2e6f2701c0f7748308c77be7c61d26b1a2f338ac Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Fri, 8 Apr 2016 23:09:19 -0400 Subject: [PATCH] Material / MatParamTexture: remove texture unit fields --- .../com/jme3/material/MatParamTexture.java | 22 +++---------------- .../main/java/com/jme3/material/Material.java | 20 ++--------------- .../java/com/jme3/material/MaterialDef.java | 2 +- 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java b/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java index 78c8ef33c..cb800e75b 100644 --- a/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java +++ b/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java @@ -35,7 +35,6 @@ import com.jme3.export.InputCapsule; import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.renderer.Renderer; import com.jme3.shader.VarType; import com.jme3.texture.Texture; import com.jme3.texture.image.ColorSpace; @@ -44,13 +43,11 @@ import java.io.IOException; public class MatParamTexture extends MatParam { private Texture texture; - private int unit; private ColorSpace colorSpace; - public MatParamTexture(VarType type, String name, Texture texture, int unit, ColorSpace colorSpace) { + public MatParamTexture(VarType type, String name, Texture texture, ColorSpace colorSpace) { super(type, name, texture); this.texture = texture; - this.unit = unit; this.colorSpace = colorSpace; } @@ -92,31 +89,18 @@ public class MatParamTexture extends MatParam { this.colorSpace = colorSpace; } - public void setUnit(int unit) { - this.unit = unit; - } - - public int getUnit() { - return unit; - } - - @Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule oc = ex.getCapsule(this); - oc.write(unit, "texture_unit", -1); - - // For backwards compat - oc.write(texture, "texture", null); + oc.write(0, "texture_unit", -1); + oc.write(texture, "texture", null); // For backwards compatibility } @Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule ic = im.getCapsule(this); - unit = ic.readInt("texture_unit", -1); texture = (Texture) value; - //texture = (Texture) ic.readSavable("texture", null); } } \ No newline at end of file diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index 180cdc544..49d98a72c 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -93,7 +93,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { private ListMap paramValues = new ListMap(); private Technique technique; private HashMap techniques = new HashMap(); - private int nextTexUnit = 0; private RenderState additionalState = null; private RenderState mergedRenderState = new RenderState(); private boolean transparent = false; @@ -510,16 +509,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { paramValues.remove(name); if (matParam instanceof MatParamTexture) { - int texUnit = ((MatParamTexture) matParam).getUnit(); - nextTexUnit--; - for (MatParam param : paramValues.values()) { - if (param instanceof MatParamTexture) { - MatParamTexture texParam = (MatParamTexture) param; - if (texParam.getUnit() > texUnit) { - texParam.setUnit(texParam.getUnit() - 1); - } - } - } sortingId = -1; } if (technique != null) { @@ -562,13 +551,13 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { + "Linear using texture.getImage.setColorSpace().", new Object[]{value.getName(), value.getImage().getColorSpace().name(), name}); } - paramValues.put(name, new MatParamTexture(type, name, value, nextTexUnit++, null)); + paramValues.put(name, new MatParamTexture(type, name, value, null)); } else { val.setTextureValue(value); } if (technique != null) { - technique.notifyParamChanged(name, type, nextTexUnit - 1); + technique.notifyParamChanged(name, type, value); } // need to recompute sort ID @@ -1078,11 +1067,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { MatParam param = entry.getValue(); if (param instanceof MatParamTexture) { MatParamTexture texVal = (MatParamTexture) param; - - if (nextTexUnit < texVal.getUnit() + 1) { - nextTexUnit = texVal.getUnit() + 1; - } - // the texture failed to load for this param // do not add to param values if (texVal.getTextureValue() == null || texVal.getTextureValue().getImage() == null) { diff --git a/jme3-core/src/main/java/com/jme3/material/MaterialDef.java b/jme3-core/src/main/java/com/jme3/material/MaterialDef.java index 47d672f3b..21eac324c 100644 --- a/jme3-core/src/main/java/com/jme3/material/MaterialDef.java +++ b/jme3-core/src/main/java/com/jme3/material/MaterialDef.java @@ -135,7 +135,7 @@ public class MaterialDef { * @see ColorSpace */ public void addMaterialParamTexture(VarType type, String name, ColorSpace colorSpace) { - matParams.put(name, new MatParamTexture(type, name, null , 0, colorSpace)); + matParams.put(name, new MatParamTexture(type, name, null, colorSpace)); } /**