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 @Override
protected Object clone() throws CloneNotSupportedException { protected ShaderGenerationInfo clone() throws CloneNotSupportedException {
ShaderGenerationInfo clone = (ShaderGenerationInfo) super.clone(); ShaderGenerationInfo clone = (ShaderGenerationInfo) super.clone();
for (ShaderNodeVariable attribute : attributes) { for (ShaderNodeVariable attribute : attributes) {
clone.attributes.add((ShaderNodeVariable) attribute.clone()); clone.attributes.add(attribute.clone());
} }
for (ShaderNodeVariable uniform : vertexUniforms) { 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) { for (ShaderNodeVariable varying : varyings) {
clone.varyings.add((ShaderNodeVariable) varying.clone()); clone.varyings.add(varying.clone());
} }
for (ShaderNodeVariable uniform : fragmentUniforms) { for (ShaderNodeVariable uniform : fragmentUniforms) {
clone.fragmentUniforms.add((ShaderNodeVariable) uniform.clone()); clone.fragmentUniforms.add(uniform.clone());
} }
for (ShaderNodeVariable globals : fragmentGlobals) { for (ShaderNodeVariable globals : fragmentGlobals) {
clone.fragmentGlobals.add((ShaderNodeVariable) globals.clone()); clone.fragmentGlobals.add(globals.clone());
} }
clone.unusedNodes.addAll(unusedNodes); clone.unusedNodes.addAll(unusedNodes);

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

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

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

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

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

Loading…
Cancel
Save