* Shader now has accelerated access to attribute by using IntMap
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7671 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
31027a0b2c
commit
8c69c7d205
@ -2347,7 +2347,7 @@ public class OGLESShaderRenderer implements Renderer {
|
|||||||
|
|
||||||
int programId = context.boundShaderProgram;
|
int programId = context.boundShaderProgram;
|
||||||
if (programId > 0) {
|
if (programId > 0) {
|
||||||
Attribute attrib = boundShader.getAttribute(vb.getBufferType().name());
|
Attribute attrib = boundShader.getAttribute(vb.getBufferType());
|
||||||
int loc = attrib.getLocation();
|
int loc = attrib.getLocation();
|
||||||
if (loc == -1) {
|
if (loc == -1) {
|
||||||
|
|
||||||
@ -2874,7 +2874,7 @@ public class OGLESShaderRenderer implements Renderer {
|
|||||||
if (programId > 0) {
|
if (programId > 0) {
|
||||||
VertexBuffer[] attribs = context.boundAttribs;
|
VertexBuffer[] attribs = context.boundAttribs;
|
||||||
|
|
||||||
Attribute attrib = boundShader.getAttribute(vb.getBufferType().name());
|
Attribute attrib = boundShader.getAttribute(vb.getBufferType());
|
||||||
int loc = attrib.getLocation();
|
int loc = attrib.getLocation();
|
||||||
if (loc == -1) {
|
if (loc == -1) {
|
||||||
//throw new IllegalArgumentException("Location is invalid for attrib: [" + vb.getBufferType().name() + "]");
|
//throw new IllegalArgumentException("Location is invalid for attrib: [" + vb.getBufferType().name() + "]");
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.jme3.util;
|
package com.jme3.util;
|
||||||
|
|
||||||
import com.jme3.util.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.DataBufferByte;
|
import java.awt.image.DataBufferByte;
|
||||||
import java.awt.image.WritableRaster;
|
import java.awt.image.WritableRaster;
|
||||||
|
@ -2068,7 +2068,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
|
|
||||||
int programId = context.boundShaderProgram;
|
int programId = context.boundShaderProgram;
|
||||||
if (programId > 0) {
|
if (programId > 0) {
|
||||||
Attribute attrib = boundShader.getAttribute(vb.getBufferType().name());
|
Attribute attrib = boundShader.getAttribute(vb.getBufferType());
|
||||||
int loc = attrib.getLocation();
|
int loc = attrib.getLocation();
|
||||||
if (loc == -1) {
|
if (loc == -1) {
|
||||||
return; // not defined
|
return; // not defined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user