shader uniform caching fix
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
f6ac972aa7
commit
f01cf94d6f
@ -445,7 +445,6 @@ public class Mesh {
|
|||||||
openGLState.getActiveShader().setUniform(openGLState, "hasBones", 1);
|
openGLState.getActiveShader().setUniform(openGLState, "hasBones", 1);
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "numBones", bones.size());
|
openGLState.getActiveShader().setUniform(openGLState, "numBones", bones.size());
|
||||||
Iterator<String> boneIterator = boneIdList.iterator();
|
Iterator<String> boneIterator = boneIdList.iterator();
|
||||||
// float bufferarray[] = new float[16];
|
|
||||||
int incrementer = 0;
|
int incrementer = 0;
|
||||||
while (boneIterator.hasNext()){
|
while (boneIterator.hasNext()){
|
||||||
String boneName = boneIterator.next();
|
String boneName = boneIterator.next();
|
||||||
@ -453,19 +452,9 @@ public class Mesh {
|
|||||||
String currentUniform = "bones[" + incrementer + "]";
|
String currentUniform = "bones[" + incrementer + "]";
|
||||||
if(currentBone != null){
|
if(currentBone != null){
|
||||||
Matrix4d currentMat = currentBone.getFinalTransform();
|
Matrix4d currentMat = currentBone.getFinalTransform();
|
||||||
// currentMat.get(bufferarray);
|
|
||||||
// if(boneName.equals("Torso")){
|
|
||||||
// System.out.println("Found torso bone");
|
|
||||||
// System.out.println(currentUniform);
|
|
||||||
// System.out.println(currentMat);
|
|
||||||
// }
|
|
||||||
openGLState.getActiveShader().setUniform(openGLState, currentUniform, currentMat);
|
openGLState.getActiveShader().setUniform(openGLState, currentUniform, currentMat);
|
||||||
// GL45.glUniformMatrix4fv(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), currentUniform), false, bufferarray);
|
|
||||||
} else {
|
} else {
|
||||||
// System.out.println("Bonename: " + boneName);
|
|
||||||
// System.exit(1);
|
|
||||||
openGLState.getActiveShader().setUniform(openGLState, currentUniform, new Matrix4f());
|
openGLState.getActiveShader().setUniform(openGLState, currentUniform, new Matrix4f());
|
||||||
// GL45.glUniformMatrix4fv(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), currentUniform), false, new float[16]);
|
|
||||||
}
|
}
|
||||||
incrementer++;
|
incrementer++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -681,25 +681,45 @@ public class ShaderProgram {
|
|||||||
!uniformMap.get(uniformLocation).equals(value)
|
!uniformMap.get(uniformLocation).equals(value)
|
||||||
){
|
){
|
||||||
try(MemoryStack stack = MemoryStack.stackPush()){
|
try(MemoryStack stack = MemoryStack.stackPush()){
|
||||||
uniformMap.put(uniformLocation,value);
|
|
||||||
|
//
|
||||||
|
//matrix4f
|
||||||
if(value instanceof Matrix4f){
|
if(value instanceof Matrix4f){
|
||||||
Matrix4f currentUniform = (Matrix4f)value;
|
Matrix4f currentUniform = (Matrix4f)value;
|
||||||
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
uniformMap.put(uniformLocation,new Matrix4f(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
|
||||||
|
|
||||||
|
//
|
||||||
|
//matrix4d
|
||||||
} else if(value instanceof Matrix4d){
|
} else if(value instanceof Matrix4d){
|
||||||
Matrix4d currentUniform = (Matrix4d)value;
|
Matrix4d currentUniform = (Matrix4d)value;
|
||||||
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
uniformMap.put(uniformLocation,new Matrix4d(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
|
||||||
|
|
||||||
|
//
|
||||||
|
//vector3f
|
||||||
} else if(value instanceof Vector3f){
|
} else if(value instanceof Vector3f){
|
||||||
Vector3f currentUniform = (Vector3f)value;
|
Vector3f currentUniform = (Vector3f)value;
|
||||||
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
|
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
uniformMap.put(uniformLocation,new Vector3f(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
|
||||||
|
|
||||||
|
//
|
||||||
|
//integer
|
||||||
} else if(value instanceof Integer){
|
} else if(value instanceof Integer){
|
||||||
GL40.glUniform1i(uniformLocation, (Integer)value);
|
GL40.glUniform1i(uniformLocation, (Integer)value);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
uniformMap.put(uniformLocation,(Integer)value);
|
||||||
|
|
||||||
|
//
|
||||||
|
//float
|
||||||
} else if(value instanceof Float){
|
} else if(value instanceof Float){
|
||||||
GL40.glUniform1f(uniformLocation, (Float)value);
|
GL40.glUniform1f(uniformLocation, (Float)value);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
uniformMap.put(uniformLocation,(Float)value);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Tried to set uniform with unsupported type!");
|
throw new UnsupportedOperationException("Tried to set uniform with unsupported type!");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user