|
|
@ -39,6 +39,9 @@ import com.jme3.export.OutputCapsule; |
|
|
|
import com.jme3.export.Savable; |
|
|
|
import com.jme3.export.Savable; |
|
|
|
import com.jme3.renderer.GLObject; |
|
|
|
import com.jme3.renderer.GLObject; |
|
|
|
import com.jme3.renderer.Renderer; |
|
|
|
import com.jme3.renderer.Renderer; |
|
|
|
|
|
|
|
import com.jme3.scene.VertexBuffer; |
|
|
|
|
|
|
|
import com.jme3.util.IntMap; |
|
|
|
|
|
|
|
import com.jme3.util.IntMap.Entry; |
|
|
|
import com.jme3.util.ListMap; |
|
|
|
import com.jme3.util.ListMap; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
@ -69,7 +72,7 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Maps attribute name to the location of the attribute in the shader. |
|
|
|
* Maps attribute name to the location of the attribute in the shader. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private HashMap<String, Attribute> attribs; |
|
|
|
private IntMap<Attribute> attribs; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Type of shader. The shader will control the pipeline of it's type. |
|
|
|
* Type of shader. The shader will control the pipeline of it's type. |
|
|
@ -220,7 +223,7 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
shaderList = new ArrayList<ShaderSource>(); |
|
|
|
shaderList = new ArrayList<ShaderSource>(); |
|
|
|
// uniforms = new HashMap<String, Uniform>();
|
|
|
|
// uniforms = new HashMap<String, Uniform>();
|
|
|
|
uniforms = new ListMap<String, Uniform>(); |
|
|
|
uniforms = new ListMap<String, Uniform>(); |
|
|
|
attribs = new HashMap<String, Attribute>(); |
|
|
|
attribs = new IntMap<Attribute>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -235,7 +238,7 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
shaderList = new ArrayList<ShaderSource>(); |
|
|
|
shaderList = new ArrayList<ShaderSource>(); |
|
|
|
// uniforms = new HashMap<String, Uniform>();
|
|
|
|
// uniforms = new HashMap<String, Uniform>();
|
|
|
|
uniforms = new ListMap<String, Uniform>(); |
|
|
|
uniforms = new ListMap<String, Uniform>(); |
|
|
|
attribs = new HashMap<String, Attribute>(); |
|
|
|
attribs = new IntMap<Attribute>(); |
|
|
|
for (ShaderSource source : s.shaderList){ |
|
|
|
for (ShaderSource source : s.shaderList){ |
|
|
|
addSource((ShaderSource) source.createDestructableClone()); |
|
|
|
addSource((ShaderSource) source.createDestructableClone()); |
|
|
|
} |
|
|
|
} |
|
|
@ -245,7 +248,7 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
OutputCapsule oc = ex.getCapsule(this); |
|
|
|
OutputCapsule oc = ex.getCapsule(this); |
|
|
|
oc.write(language, "language", null); |
|
|
|
oc.write(language, "language", null); |
|
|
|
oc.writeSavableArrayList(shaderList, "shaderList", null); |
|
|
|
oc.writeSavableArrayList(shaderList, "shaderList", null); |
|
|
|
oc.writeStringSavableMap(attribs, "attribs", null); |
|
|
|
oc.writeIntSavableMap(attribs, "attribs", null); |
|
|
|
oc.writeStringSavableMap(uniforms, "uniforms", null); |
|
|
|
oc.writeStringSavableMap(uniforms, "uniforms", null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -253,7 +256,7 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
InputCapsule ic = im.getCapsule(this); |
|
|
|
InputCapsule ic = im.getCapsule(this); |
|
|
|
language = ic.readString("language", null); |
|
|
|
language = ic.readString("language", null); |
|
|
|
shaderList = ic.readSavableArrayList("shaderList", null); |
|
|
|
shaderList = ic.readSavableArrayList("shaderList", null); |
|
|
|
attribs = (HashMap<String, Attribute>) ic.readStringSavableMap("attribs", null); |
|
|
|
attribs = (IntMap<Attribute>) ic.readIntSavableMap("attribs", null); |
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, Uniform> uniMap = (HashMap<String, Uniform>) ic.readStringSavableMap("uniforms", null); |
|
|
|
HashMap<String, Uniform> uniMap = (HashMap<String, Uniform>) ic.readStringSavableMap("uniforms", null); |
|
|
|
uniforms = new ListMap<String, Uniform>(uniMap); |
|
|
|
uniforms = new ListMap<String, Uniform>(uniMap); |
|
|
@ -331,12 +334,13 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
uniforms.remove(name); |
|
|
|
uniforms.remove(name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Attribute getAttribute(String name){ |
|
|
|
public Attribute getAttribute(VertexBuffer.Type attribType){ |
|
|
|
Attribute attrib = attribs.get(name); |
|
|
|
int ordinal = attribType.ordinal(); |
|
|
|
|
|
|
|
Attribute attrib = attribs.get(ordinal); |
|
|
|
if (attrib == null){ |
|
|
|
if (attrib == null){ |
|
|
|
attrib = new Attribute(); |
|
|
|
attrib = new Attribute(); |
|
|
|
attrib.name = name; |
|
|
|
attrib.name = attribType.name(); |
|
|
|
attribs.put(name, attrib); |
|
|
|
attribs.put(ordinal, attrib); |
|
|
|
} |
|
|
|
} |
|
|
|
return attrib; |
|
|
|
return attrib; |
|
|
|
} |
|
|
|
} |
|
|
@ -349,9 +353,9 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
return uniforms; |
|
|
|
return uniforms; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Collection<Attribute> getAttributes() { |
|
|
|
// public Collection<Attribute> getAttributes() {
|
|
|
|
return attribs.values(); |
|
|
|
// return attribs.
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public Collection<ShaderSource> getSources(){ |
|
|
|
public Collection<ShaderSource> getSources(){ |
|
|
|
return shaderList; |
|
|
|
return shaderList; |
|
|
@ -402,8 +406,8 @@ public final class Shader extends GLObject implements Savable { |
|
|
|
for (Uniform uniform : uniforms.values()){ |
|
|
|
for (Uniform uniform : uniforms.values()){ |
|
|
|
uniform.reset(); // fixes issue with re-initialization
|
|
|
|
uniform.reset(); // fixes issue with re-initialization
|
|
|
|
} |
|
|
|
} |
|
|
|
for (Attribute attrib : attribs.values()){ |
|
|
|
for (Entry<Attribute> entry : attribs){ |
|
|
|
attrib.location = -2; |
|
|
|
entry.getValue().location = -2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|