use shader program flow for setting uniforms
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
parent
224fce0a5a
commit
1374c1c240
@ -652,11 +652,13 @@ public class RenderingEngine {
|
||||
* Checks for any errors currently caught by OpenGL.
|
||||
* Refer: https://docs.gl/gl4/glGetError
|
||||
*/
|
||||
public void checkError(){
|
||||
public boolean checkError(){
|
||||
int error = this.getError();
|
||||
if(error != GL11.GL_NO_ERROR){
|
||||
LoggerInterface.loggerRenderer.ERROR("checkError - " + getErrorInEnglish(error), new IllegalStateException("OpenGL Error"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -41,7 +41,6 @@ import static org.lwjgl.opengl.GL15.glBindBuffer;
|
||||
import static org.lwjgl.opengl.GL15.glGenBuffers;
|
||||
import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
|
||||
import static org.lwjgl.opengl.GL20.glGetUniformLocation;
|
||||
import static org.lwjgl.opengl.GL20.glUniform1f;
|
||||
import static org.lwjgl.opengl.GL20.glUniform1i;
|
||||
import static org.lwjgl.opengl.GL20.glUniform3fv;
|
||||
import static org.lwjgl.opengl.GL20.glUniformMatrix4fv;
|
||||
@ -484,24 +483,15 @@ public class Mesh {
|
||||
if(renderPipelineState.getBufferStandardUniforms()){
|
||||
//buffer model/view/proj matrices
|
||||
try(MemoryStack stack = MemoryStack.stackPush()){
|
||||
GL45.glUniformMatrix4fv(openGLState.getActiveShader().shaderVertexModelLoc, false, parent.getModelMatrix().get(new float[16]));
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniformMatrix4fv(openGLState.getActiveShader().shaderVertexViewLoc, false, Globals.viewMatrix.get(new float[16]));
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniformMatrix4fv(openGLState.getActiveShader().shaderVertexProjectionLoc, false, Globals.projectionMatrix.get(new float[16]));
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniform3fv(openGLState.getActiveShader().shaderVertexViewPosLoc, CameraEntityUtils.getCameraEye(Globals.playerCamera).get(stack.floats(3)));
|
||||
Globals.renderingEngine.checkError();
|
||||
openGLState.getActiveShader().setUniform(openGLState, "model", parent.getModelMatrix());
|
||||
openGLState.getActiveShader().setUniform(openGLState, "view", Globals.viewMatrix);
|
||||
openGLState.getActiveShader().setUniform(openGLState, "projection", Globals.projectionMatrix);
|
||||
openGLState.getActiveShader().setUniform(openGLState, "viewPos", CameraEntityUtils.getCameraEye(Globals.playerCamera));
|
||||
Vector3f worldPos = new Vector3f((float)parent.getWorldPos().x,(float)parent.getWorldPos().y,(float)parent.getWorldPos().z);
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniform3fv(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), "modelWorldPos"), worldPos.get(stack.mallocFloat(3)));
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniformMatrix4fv(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), "lightSpaceMatrix"), false, Globals.lightDepthMatrix.get(new float[16]));
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniform1i(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), "frame"), (int)Globals.timekeeper.getNumberOfRenderFramesElapsed());
|
||||
Globals.renderingEngine.checkError();
|
||||
glUniform1f(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), "time"), (float)Globals.timekeeper.getCurrentRendererTime());
|
||||
Globals.renderingEngine.checkError();
|
||||
openGLState.getActiveShader().setUniform(openGLState, "modelWorldPos", worldPos);
|
||||
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.lightDepthMatrix);
|
||||
openGLState.getActiveShader().setUniform(openGLState, "frame", (int)Globals.timekeeper.getNumberOfRenderFramesElapsed());
|
||||
openGLState.getActiveShader().setUniform(openGLState, "time", (float)Globals.timekeeper.getCurrentRendererTime());
|
||||
}
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import static org.lwjgl.opengl.GL20.glDeleteShader;
|
||||
import static org.lwjgl.opengl.GL20.glGetProgramInfoLog;
|
||||
import static org.lwjgl.opengl.GL20.glGetProgrami;
|
||||
import static org.lwjgl.opengl.GL20.glGetShaderi;
|
||||
import static org.lwjgl.opengl.GL20.glGetUniformLocation;
|
||||
import static org.lwjgl.opengl.GL20.glLinkProgram;
|
||||
import static org.lwjgl.opengl.GL20.glShaderSource;
|
||||
import static org.lwjgl.opengl.GL32.GL_GEOMETRY_SHADER;
|
||||
@ -35,6 +34,7 @@ import org.joml.Vector3f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL40;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
@ -61,13 +61,6 @@ public class ShaderProgram {
|
||||
//
|
||||
//Uniform locations
|
||||
//
|
||||
public int shaderVertexModelLoc;
|
||||
public int shaderVertexViewLoc;
|
||||
public int shaderVertexProjectionLoc;
|
||||
public int shaderVertexViewPosLoc;
|
||||
public int shaderVertexBonesLoc;
|
||||
public int shaderVertexHasBonesLoc;
|
||||
public int shaderVertexNumBonesLoc;
|
||||
|
||||
|
||||
//Uniforms
|
||||
@ -184,20 +177,6 @@ public class ShaderProgram {
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Set locations
|
||||
//
|
||||
rVal.shaderVertexModelLoc = glGetUniformLocation(rVal.shaderId, "model");
|
||||
rVal.shaderVertexViewLoc = glGetUniformLocation(rVal.shaderId, "view");
|
||||
rVal.shaderVertexProjectionLoc = glGetUniformLocation(rVal.shaderId, "projection");
|
||||
rVal.shaderVertexViewPosLoc = glGetUniformLocation(rVal.shaderId, "viewPos");
|
||||
if(ContainsBones){
|
||||
rVal.shaderVertexBonesLoc = glGetUniformLocation(rVal.shaderId, "bones");
|
||||
rVal.shaderVertexNumBonesLoc = glGetUniformLocation(rVal.shaderId, "numBones");
|
||||
}
|
||||
rVal.shaderVertexHasBonesLoc = glGetUniformLocation(rVal.shaderId, "hasBones");
|
||||
|
||||
|
||||
alreadyCompiledMap.put(shaderKey,rVal);
|
||||
|
||||
return rVal;
|
||||
@ -318,20 +297,6 @@ public class ShaderProgram {
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Set locations
|
||||
//
|
||||
rVal.shaderVertexModelLoc = glGetUniformLocation(rVal.shaderId, "model");
|
||||
rVal.shaderVertexViewLoc = glGetUniformLocation(rVal.shaderId, "view");
|
||||
rVal.shaderVertexProjectionLoc = glGetUniformLocation(rVal.shaderId, "projection");
|
||||
rVal.shaderVertexViewPosLoc = glGetUniformLocation(rVal.shaderId, "viewPos");
|
||||
if(ContainsBones){
|
||||
rVal.shaderVertexBonesLoc = glGetUniformLocation(rVal.shaderId, "bones");
|
||||
rVal.shaderVertexNumBonesLoc = glGetUniformLocation(rVal.shaderId, "numBones");
|
||||
}
|
||||
rVal.shaderVertexHasBonesLoc = glGetUniformLocation(rVal.shaderId, "hasBones");
|
||||
|
||||
|
||||
alreadyCompiledMap.put(shaderKey,rVal);
|
||||
|
||||
return rVal;
|
||||
@ -433,20 +398,6 @@ public class ShaderProgram {
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Set locations
|
||||
//
|
||||
rVal.shaderVertexModelLoc = glGetUniformLocation(rVal.shaderId, "model");
|
||||
rVal.shaderVertexViewLoc = glGetUniformLocation(rVal.shaderId, "view");
|
||||
rVal.shaderVertexProjectionLoc = glGetUniformLocation(rVal.shaderId, "projection");
|
||||
rVal.shaderVertexViewPosLoc = glGetUniformLocation(rVal.shaderId, "viewPos");
|
||||
rVal.shaderVertexBonesLoc = glGetUniformLocation(rVal.shaderId, "bones");
|
||||
rVal.shaderVertexNumBonesLoc = glGetUniformLocation(rVal.shaderId, "numBones");
|
||||
rVal.shaderVertexHasBonesLoc = glGetUniformLocation(rVal.shaderId, "hasBones");
|
||||
|
||||
|
||||
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -627,17 +578,6 @@ public class ShaderProgram {
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Set locations
|
||||
//
|
||||
rVal.shaderVertexModelLoc = glGetUniformLocation(rVal.shaderId, "model");
|
||||
rVal.shaderVertexViewLoc = glGetUniformLocation(rVal.shaderId, "view");
|
||||
rVal.shaderVertexProjectionLoc = glGetUniformLocation(rVal.shaderId, "projection");
|
||||
rVal.shaderVertexViewPosLoc = glGetUniformLocation(rVal.shaderId, "viewPos");
|
||||
|
||||
|
||||
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -726,17 +666,6 @@ public class ShaderProgram {
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Set locations
|
||||
//
|
||||
rVal.shaderVertexModelLoc = glGetUniformLocation(rVal.shaderId, "model");
|
||||
rVal.shaderVertexViewLoc = glGetUniformLocation(rVal.shaderId, "view");
|
||||
rVal.shaderVertexProjectionLoc = glGetUniformLocation(rVal.shaderId, "projection");
|
||||
rVal.shaderVertexViewPosLoc = glGetUniformLocation(rVal.shaderId, "viewPos");
|
||||
|
||||
|
||||
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -745,24 +674,38 @@ public class ShaderProgram {
|
||||
* @param uniformLocation the uniform location
|
||||
* @param value the value
|
||||
*/
|
||||
public void setUniform(int uniformLocation, Object value){
|
||||
public void setUniform(OpenGLState openGLState, int uniformLocation, Object value){
|
||||
if(DISABLE_CACHING || !uniformMap.containsKey(uniformLocation) || !uniformMap.get(uniformLocation).equals(value)){
|
||||
uniformMap.put(uniformLocation,value);
|
||||
if(value instanceof Matrix4f){
|
||||
Matrix4f currentUniform = (Matrix4f)value;
|
||||
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
||||
}
|
||||
if(value instanceof Matrix4d){
|
||||
Matrix4d currentUniform = (Matrix4d)value;
|
||||
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
||||
}
|
||||
if(value instanceof Vector3f){
|
||||
Vector3f currentUniform = (Vector3f)value;
|
||||
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
|
||||
}
|
||||
if(value instanceof Integer){
|
||||
int currentInform = (Integer)value;
|
||||
GL40.glUniform1i(uniformLocation, currentInform);
|
||||
try(MemoryStack stack = MemoryStack.stackPush()){
|
||||
uniformMap.put(uniformLocation,value);
|
||||
if(value instanceof Matrix4f){
|
||||
Matrix4f currentUniform = (Matrix4f)value;
|
||||
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
if(value instanceof Matrix4d){
|
||||
Matrix4d currentUniform = (Matrix4d)value;
|
||||
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
if(value instanceof Vector3f){
|
||||
Vector3f currentUniform = (Vector3f)value;
|
||||
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
if(value instanceof Integer){
|
||||
GL40.glUniform1i(uniformLocation, (Integer)value);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
if(value instanceof Float){
|
||||
GL40.glUniform1f(uniformLocation, (Float)value);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
if(value instanceof Vector3f){
|
||||
Vector3f vectorView = (Vector3f)value;
|
||||
GL40.glUniform3fv(uniformLocation, vectorView.get(stack.mallocFloat(3)));
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -776,13 +719,17 @@ public class ShaderProgram {
|
||||
* @param value The value to set the uniform to
|
||||
*/
|
||||
public void setUniform(OpenGLState openGLState, String uniformName, Object value){
|
||||
int uniformLocation = glGetUniformLocation(this.getShaderId(), uniformName);
|
||||
Globals.renderingEngine.checkError();
|
||||
if(uniformName == null || uniformName.equals("")){
|
||||
throw new IllegalArgumentException("Trying to set invalid uniform name");
|
||||
}
|
||||
int uniformLocation = GL40.glGetUniformLocation(this.getShaderId(), uniformName);
|
||||
if(Globals.renderingEngine.checkError()){
|
||||
LoggerInterface.loggerRenderer.WARNING("Shader id: " + this.getShaderId());
|
||||
}
|
||||
if(uniformLocation == INVALID_UNIFORM_NAME){
|
||||
LoggerInterface.loggerRenderer.DEBUG_LOOP("Searched for uniform in a shader that does not contain it. Uniform name: \"" + uniformName + "\"");
|
||||
} else {
|
||||
setUniform(uniformLocation, value);
|
||||
Globals.renderingEngine.checkError();
|
||||
this.setUniform(openGLState, uniformLocation, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user