Material / MatParamTexture: remove texture unit fields

cleanup_build_scripts
Kirill Vainer 9 years ago
parent f5c5d161d0
commit 2e6f2701c0
  1. 22
      jme3-core/src/main/java/com/jme3/material/MatParamTexture.java
  2. 20
      jme3-core/src/main/java/com/jme3/material/Material.java
  3. 2
      jme3-core/src/main/java/com/jme3/material/MaterialDef.java

@ -35,7 +35,6 @@ import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.renderer.Renderer;
import com.jme3.shader.VarType; import com.jme3.shader.VarType;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import com.jme3.texture.image.ColorSpace; import com.jme3.texture.image.ColorSpace;
@ -44,13 +43,11 @@ import java.io.IOException;
public class MatParamTexture extends MatParam { public class MatParamTexture extends MatParam {
private Texture texture; private Texture texture;
private int unit;
private ColorSpace colorSpace; 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); super(type, name, texture);
this.texture = texture; this.texture = texture;
this.unit = unit;
this.colorSpace = colorSpace; this.colorSpace = colorSpace;
} }
@ -92,31 +89,18 @@ public class MatParamTexture extends MatParam {
this.colorSpace = colorSpace; this.colorSpace = colorSpace;
} }
public void setUnit(int unit) {
this.unit = unit;
}
public int getUnit() {
return unit;
}
@Override @Override
public void write(JmeExporter ex) throws IOException { public void write(JmeExporter ex) throws IOException {
super.write(ex); super.write(ex);
OutputCapsule oc = ex.getCapsule(this); OutputCapsule oc = ex.getCapsule(this);
oc.write(unit, "texture_unit", -1); oc.write(0, "texture_unit", -1);
oc.write(texture, "texture", null); // For backwards compatibility
// For backwards compat
oc.write(texture, "texture", null);
} }
@Override @Override
public void read(JmeImporter im) throws IOException { public void read(JmeImporter im) throws IOException {
super.read(im); super.read(im);
InputCapsule ic = im.getCapsule(this); InputCapsule ic = im.getCapsule(this);
unit = ic.readInt("texture_unit", -1);
texture = (Texture) value; texture = (Texture) value;
//texture = (Texture) ic.readSavable("texture", null);
} }
} }

@ -93,7 +93,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
private ListMap<String, MatParam> paramValues = new ListMap<String, MatParam>(); private ListMap<String, MatParam> paramValues = new ListMap<String, MatParam>();
private Technique technique; private Technique technique;
private HashMap<String, Technique> techniques = new HashMap<String, Technique>(); private HashMap<String, Technique> techniques = new HashMap<String, Technique>();
private int nextTexUnit = 0;
private RenderState additionalState = null; private RenderState additionalState = null;
private RenderState mergedRenderState = new RenderState(); private RenderState mergedRenderState = new RenderState();
private boolean transparent = false; private boolean transparent = false;
@ -510,16 +509,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
paramValues.remove(name); paramValues.remove(name);
if (matParam instanceof MatParamTexture) { 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; sortingId = -1;
} }
if (technique != null) { if (technique != null) {
@ -562,13 +551,13 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
+ "Linear using texture.getImage.setColorSpace().", + "Linear using texture.getImage.setColorSpace().",
new Object[]{value.getName(), value.getImage().getColorSpace().name(), name}); 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 { } else {
val.setTextureValue(value); val.setTextureValue(value);
} }
if (technique != null) { if (technique != null) {
technique.notifyParamChanged(name, type, nextTexUnit - 1); technique.notifyParamChanged(name, type, value);
} }
// need to recompute sort ID // need to recompute sort ID
@ -1078,11 +1067,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
MatParam param = entry.getValue(); MatParam param = entry.getValue();
if (param instanceof MatParamTexture) { if (param instanceof MatParamTexture) {
MatParamTexture texVal = (MatParamTexture) param; MatParamTexture texVal = (MatParamTexture) param;
if (nextTexUnit < texVal.getUnit() + 1) {
nextTexUnit = texVal.getUnit() + 1;
}
// the texture failed to load for this param // the texture failed to load for this param
// do not add to param values // do not add to param values
if (texVal.getTextureValue() == null || texVal.getTextureValue().getImage() == null) { if (texVal.getTextureValue() == null || texVal.getTextureValue().getImage() == null) {

@ -135,7 +135,7 @@ public class MaterialDef {
* @see ColorSpace * @see ColorSpace
*/ */
public void addMaterialParamTexture(VarType type, String name, ColorSpace 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));
} }
/** /**

Loading…
Cancel
Save