Browse Source

Material / MatParamTexture: remove texture unit fields

Kirill Vainer 9 years ago
parent
commit
2e6f2701c0

+ 3 - 19
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);
     }
 }

+ 2 - 18
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -93,7 +93,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
     private ListMap<String, MatParam> paramValues = new ListMap<String, MatParam>();
     private Technique technique;
     private HashMap<String, Technique> techniques = new HashMap<String, Technique>();
-    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) {

+ 1 - 1
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));
     }
     
     /**