Better cloning for TechniqueDefs

fix-456
Nehon 8 years ago
parent 51eccfea2e
commit a64594eea9
  1. 14
      jme3-core/src/main/java/com/jme3/material/ShaderGenerationInfo.java
  2. 6
      jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
  3. 2
      jme3-core/src/main/java/com/jme3/shader/ShaderNode.java
  4. 4
      jme3-core/src/main/java/com/jme3/shader/ShaderNodeVariable.java
  5. 6
      jme3-core/src/main/java/com/jme3/shader/VariableMapping.java
  6. 9
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

@ -189,30 +189,30 @@ public class ShaderGenerationInfo implements Savable, Cloneable {
}
@Override
protected Object clone() throws CloneNotSupportedException {
protected ShaderGenerationInfo clone() throws CloneNotSupportedException {
ShaderGenerationInfo clone = (ShaderGenerationInfo) super.clone();
for (ShaderNodeVariable attribute : attributes) {
clone.attributes.add((ShaderNodeVariable) attribute.clone());
clone.attributes.add(attribute.clone());
}
for (ShaderNodeVariable uniform : vertexUniforms) {
clone.vertexUniforms.add((ShaderNodeVariable) uniform.clone());
clone.vertexUniforms.add(uniform.clone());
}
clone.vertexGlobal = (ShaderNodeVariable) vertexGlobal.clone();
clone.vertexGlobal = vertexGlobal.clone();
for (ShaderNodeVariable varying : varyings) {
clone.varyings.add((ShaderNodeVariable) varying.clone());
clone.varyings.add(varying.clone());
}
for (ShaderNodeVariable uniform : fragmentUniforms) {
clone.fragmentUniforms.add((ShaderNodeVariable) uniform.clone());
clone.fragmentUniforms.add(uniform.clone());
}
for (ShaderNodeVariable globals : fragmentGlobals) {
clone.fragmentGlobals.add((ShaderNodeVariable) globals.clone());
clone.fragmentGlobals.add(globals.clone());
}
clone.unusedNodes.addAll(unusedNodes);

@ -778,7 +778,7 @@ public class TechniqueDef implements Savable, Cloneable {
}
@Override
public Object clone() throws CloneNotSupportedException {
public TechniqueDef clone() throws CloneNotSupportedException {
//cannot use super.clone because of the final fields instance that would be shared by the clones.
TechniqueDef clone = new TechniqueDef(name, sortId);
@ -802,9 +802,9 @@ public class TechniqueDef implements Savable, Cloneable {
if (shaderNodes != null) {
for (ShaderNode shaderNode : shaderNodes) {
clone.shaderNodes.add((ShaderNode) shaderNode.clone());
clone.shaderNodes.add(shaderNode.clone());
}
clone.shaderGenerationInfo = (ShaderGenerationInfo) shaderGenerationInfo.clone();
clone.shaderGenerationInfo = shaderGenerationInfo.clone();
}
if (renderState != null) {

@ -214,7 +214,7 @@ public class ShaderNode implements Savable, Cloneable {
}
@Override
public Object clone() throws CloneNotSupportedException {
public ShaderNode clone() throws CloneNotSupportedException {
ShaderNode clone = (ShaderNode) super.clone();
//No need to clone the definition.

@ -278,7 +278,7 @@ public class ShaderNodeVariable implements Savable, Cloneable {
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
public ShaderNodeVariable clone() throws CloneNotSupportedException {
return (ShaderNodeVariable) super.clone();
}
}

@ -197,11 +197,11 @@ public class VariableMapping implements Savable, Cloneable {
}
@Override
protected Object clone() throws CloneNotSupportedException {
protected VariableMapping clone() throws CloneNotSupportedException {
VariableMapping clone = (VariableMapping) super.clone();
clone.leftVariable = (ShaderNodeVariable) leftVariable.clone();
clone.rightVariable = (ShaderNodeVariable) rightVariable.clone();
clone.leftVariable = leftVariable.clone();
clone.rightVariable = rightVariable.clone();
return clone;
}

@ -615,6 +615,7 @@ public class J3MLoader implements AssetLoader {
private void readTechnique(Statement techStat) throws IOException{
isUseNodes = false;
String[] split = techStat.getLine().split(whitespacePattern);
Cloner cloner = new Cloner();
String name;
if (split.length == 1) {
@ -669,12 +670,8 @@ public class J3MLoader implements AssetLoader {
}else if (shaderNames.containsKey(Shader.ShaderType.Vertex) && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
if (shaderLanguages.size() > 1) {
for (int i = 1; i < shaderLanguages.size(); i++) {
TechniqueDef td = null;
try {
td = (TechniqueDef) technique.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
cloner.clearIndex();
TechniqueDef td = cloner.clone(technique);
td.setShaderFile(shaderNames, shaderLanguages.get(i));
techniqueDefs.add(td);
}

Loading…
Cancel
Save