GLRenderer: added fast uniforms - still need to fix Uniform.clear()

experimental^2^2
Kirill Vainer 9 years ago
parent b4d295ee1b
commit e6d829fac4
  1. 14
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  2. 64
      jme3-core/src/main/java/com/jme3/shader/Uniform.java

@ -964,12 +964,12 @@ public final class GLRenderer implements Renderer {
gl.glUniform1i(loc, b.booleanValue() ? GL.GL_TRUE : GL.GL_FALSE); gl.glUniform1i(loc, b.booleanValue() ? GL.GL_TRUE : GL.GL_FALSE);
break; break;
case Matrix3: case Matrix3:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
assert fb.remaining() == 9; assert fb.remaining() == 9;
gl.glUniformMatrix3(loc, false, fb); gl.glUniformMatrix3(loc, false, fb);
break; break;
case Matrix4: case Matrix4:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
assert fb.remaining() == 16; assert fb.remaining() == 16;
gl.glUniformMatrix4(loc, false, fb); gl.glUniformMatrix4(loc, false, fb);
break; break;
@ -978,23 +978,23 @@ public final class GLRenderer implements Renderer {
gl.glUniform1(loc, ib); gl.glUniform1(loc, ib);
break; break;
case FloatArray: case FloatArray:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
gl.glUniform1(loc, fb); gl.glUniform1(loc, fb);
break; break;
case Vector2Array: case Vector2Array:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
gl.glUniform2(loc, fb); gl.glUniform2(loc, fb);
break; break;
case Vector3Array: case Vector3Array:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
gl.glUniform3(loc, fb); gl.glUniform3(loc, fb);
break; break;
case Vector4Array: case Vector4Array:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
gl.glUniform4(loc, fb); gl.glUniform4(loc, fb);
break; break;
case Matrix4Array: case Matrix4Array:
fb = (FloatBuffer) uniform.getValue(); fb = uniform.getMultiData();
gl.glUniformMatrix4(loc, false, fb); gl.glUniformMatrix4(loc, false, fb);
break; break;
case Int: case Int:

@ -102,6 +102,10 @@ public class Uniform extends ShaderVariable {
public Object getValue(){ public Object getValue(){
return value; return value;
} }
public FloatBuffer getMultiData() {
return multiData;
}
public boolean isSetByCurrentMaterial() { public boolean isSetByCurrentMaterial() {
return setByCurrentMaterial; return setByCurrentMaterial;
@ -111,21 +115,6 @@ public class Uniform extends ShaderVariable {
setByCurrentMaterial = false; setByCurrentMaterial = false;
} }
private static void setVector4(Vector4f vec, Object value) {
if (value instanceof ColorRGBA) {
ColorRGBA color = (ColorRGBA) value;
vec.set(color.r, color.g, color.b, color.a);
} else if (value instanceof Quaternion) {
Quaternion quat = (Quaternion) value;
vec.set(quat.getX(), quat.getY(), quat.getZ(), quat.getW());
} else if (value instanceof Vector4f) {
Vector4f vec4 = (Vector4f) value;
vec.set(vec4);
} else{
throw new IllegalArgumentException();
}
}
public void clearValue(){ public void clearValue(){
updateNeeded = true; updateNeeded = true;
@ -189,20 +178,36 @@ public class Uniform extends ShaderVariable {
switch (type){ switch (type){
case Matrix3: case Matrix3:
if (value.equals(this.value)) {
return;
}
Matrix3f m3 = (Matrix3f) value; Matrix3f m3 = (Matrix3f) value;
if (multiData == null) { if (multiData == null) {
multiData = BufferUtils.createFloatBuffer(9); multiData = BufferUtils.createFloatBuffer(9);
} }
m3.fillFloatBuffer(multiData, true); m3.fillFloatBuffer(multiData, true);
multiData.clear(); multiData.clear();
if (this.value == null) {
this.value = new Matrix3f(m3);
} else {
((Matrix3f)this.value).set(m3);
}
break; break;
case Matrix4: case Matrix4:
if (value.equals(this.value)) {
return;
}
Matrix4f m4 = (Matrix4f) value; Matrix4f m4 = (Matrix4f) value;
if (multiData == null) { if (multiData == null) {
multiData = BufferUtils.createFloatBuffer(16); multiData = BufferUtils.createFloatBuffer(16);
} }
m4.fillFloatBuffer(multiData, true); m4.fillFloatBuffer(multiData, true);
multiData.clear(); multiData.clear();
if (this.value == null) {
this.value = new Matrix4f(m4);
} else {
((Matrix4f)this.value).copy(m4);
}
break; break;
case IntArray: case IntArray:
int[] ia = (int[]) value; int[] ia = (int[]) value;
@ -283,11 +288,32 @@ public class Uniform extends ShaderVariable {
} }
multiData.clear(); multiData.clear();
break; break;
case Vector4:
if (value.equals(this.value)) {
return;
}
if (value instanceof ColorRGBA) {
if (this.value == null) {
this.value = new ColorRGBA();
}
((ColorRGBA) this.value).set((ColorRGBA) value);
} else if (value instanceof Vector4f) {
if (this.value == null) {
this.value = new Vector4f();
}
((Vector4f) this.value).set((Vector4f) value);
} else {
if (this.value == null) {
this.value = new Quaternion();
}
((Quaternion) this.value).set((Quaternion) value);
}
break;
// Only use check if equals optimization for primitive values // Only use check if equals optimization for primitive values
case Int: case Int:
case Float: case Float:
case Boolean: case Boolean:
if (this.value != null && this.value.equals(value)) { if (value.equals(this.value)) {
return; return;
} }
this.value = value; this.value = value;
@ -297,9 +323,9 @@ public class Uniform extends ShaderVariable {
break; break;
} }
if (multiData != null) { // if (multiData != null) {
this.value = multiData; // this.value = multiData;
} // }
varType = type; varType = type;
updateNeeded = true; updateNeeded = true;

Loading…
Cancel
Save