fix static state bug
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
881ff98308
commit
c6948b89ce
@ -1795,6 +1795,7 @@ Explicitly scream if trying to bind a shader that is invalid
|
||||
Support for freeing shaders
|
||||
Utilities to free all of a type of resource
|
||||
Slowdown entity tests to prevent VSCode from exploding when running tests
|
||||
Fix static state caching between tests in visual shader construction
|
||||
|
||||
|
||||
|
||||
|
||||
@ -21,41 +21,70 @@ import electrosphere.renderer.shader.VisualShader;
|
||||
*/
|
||||
public class OpenGLState {
|
||||
|
||||
//tracks whether caching should be used or not (to deduplicate opengl calls)
|
||||
/**
|
||||
* tracks whether caching should be used or not (to deduplicate opengl calls)
|
||||
*/
|
||||
public static final boolean DISABLE_CACHING = false;
|
||||
|
||||
//the max texture allowed by the current environment
|
||||
/**
|
||||
* the max texture allowed by the current environment
|
||||
*/
|
||||
int MAX_TEXTURE_WIDTH;
|
||||
|
||||
//the current viewport dimensions
|
||||
/**
|
||||
* the current viewport dimensions
|
||||
*/
|
||||
private Vector2i viewport;
|
||||
|
||||
//whether depth test is enabled or not
|
||||
/**
|
||||
* whether depth test is enabled or not
|
||||
*/
|
||||
boolean depthTest;
|
||||
|
||||
//the current depth function
|
||||
/**
|
||||
* the current depth function
|
||||
*/
|
||||
int depthFunction;
|
||||
|
||||
//whether to blend or nit
|
||||
/**
|
||||
* whether to blend or not
|
||||
*/
|
||||
boolean blendTest;
|
||||
|
||||
//the current blend func
|
||||
//map is (texture unit) -> [sfactor,dfactor]
|
||||
/**
|
||||
* the current blend func
|
||||
* map is (texture unit) -> [sfactor,dfactor]
|
||||
*/
|
||||
Map<Integer,int[]> blendFuncMap;
|
||||
//the key that contains the value of glBlendFunc (which would affect all buffers)
|
||||
|
||||
/**
|
||||
* the key that contains the value of glBlendFunc (which would affect all buffers)
|
||||
*/
|
||||
static final int ALL_BUFFERS_KEY = -1;
|
||||
|
||||
//the currently active texture
|
||||
/**
|
||||
* the currently active texture
|
||||
*/
|
||||
int activeTexture;
|
||||
|
||||
//the currently bound framebuffer
|
||||
/**
|
||||
* Currently bound framebuffer type
|
||||
*/
|
||||
int framebufferType;
|
||||
|
||||
/**
|
||||
* Pointer for currently bound framebuffer
|
||||
*/
|
||||
int framebufferPointer;
|
||||
|
||||
//active shader
|
||||
/**
|
||||
* active shader
|
||||
*/
|
||||
Shader activeShader;
|
||||
|
||||
//map of texture units and their corresponding texture pointers
|
||||
/**
|
||||
* map of texture units and their corresponding texture pointers
|
||||
*/
|
||||
Map<Integer,Integer> unitToPointerMap;
|
||||
|
||||
/**
|
||||
@ -82,6 +111,7 @@ public class OpenGLState {
|
||||
framebufferPointer = 0;
|
||||
GL45.glBindFramebuffer(this.framebufferType, this.framebufferPointer);
|
||||
activeShader = null;
|
||||
GL45.glUseProgram(Shader.UNBIND_SHADER_ID);
|
||||
this.unitToPointerMap = new HashMap<Integer,Integer>();
|
||||
this.indexBlockMap = new HashMap<Integer,UniformBlockBinding>();
|
||||
this.storeCurrentEnvironmentContraints();
|
||||
@ -233,10 +263,13 @@ public class OpenGLState {
|
||||
*/
|
||||
public void setActiveShader(RenderPipelineState renderPipelineState, Shader program){
|
||||
if(DISABLE_CACHING || program != activeShader){
|
||||
activeShader = program;
|
||||
if(!GL40.glIsProgram(activeShader.getId()) && activeShader.getId() != Shader.UNBIND_SHADER_ID){
|
||||
throw new Error("Tried to bind shader that is not an active program! " + activeShader.getId());
|
||||
//error check
|
||||
if(program.getId() != Shader.UNBIND_SHADER_ID && !GL40.glIsProgram(program.getId())){
|
||||
throw new Error("Tried to bind shader that is not an active program! " + program.getId());
|
||||
}
|
||||
|
||||
//actually bind
|
||||
activeShader = program;
|
||||
GL40.glUseProgram(activeShader.getId());
|
||||
int glErrorCode = Globals.renderingEngine.getError();
|
||||
if(glErrorCode != 0){
|
||||
|
||||
@ -208,8 +208,8 @@ public class RenderUtils {
|
||||
|
||||
|
||||
|
||||
|
||||
particleMesh.setShader(VisualShader.smartAssembleOITProgram(false, true));
|
||||
VisualShader shader = VisualShader.smartAssembleOITProgram(false, true);
|
||||
particleMesh.setShader(shader);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -849,6 +849,15 @@ public class RenderingEngine {
|
||||
volumeDepthFrontfaceTexture = null;
|
||||
normalsOutlineTexture = null;
|
||||
|
||||
//reset shader loading
|
||||
VisualShader.clearAlreadyCompiledMap();
|
||||
|
||||
//destroy loaded resources
|
||||
Globals.assetManager.queueAllModelsForDeletion();
|
||||
Globals.assetManager.queueAllTexturesForDeletion();
|
||||
Globals.assetManager.queueAllShadersForDeletion();
|
||||
Globals.assetManager.handleDeleteQueue();
|
||||
|
||||
//end glfw
|
||||
GLFW.glfwDestroyWindow(Globals.window);
|
||||
GLFW.glfwTerminate();
|
||||
|
||||
@ -13,6 +13,7 @@ import java.util.regex.Pattern;
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
import org.lwjgl.opengl.GL40;
|
||||
import org.lwjgl.opengl.GL45;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
@ -172,6 +173,11 @@ public class VisualShader implements Shader {
|
||||
|
||||
|
||||
alreadyCompiledMap.put(shaderKey,rVal);
|
||||
|
||||
//check program status
|
||||
if(!GL45.glIsProgram(rVal.shaderId)){
|
||||
throw new Error("Failed to build program!");
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -213,7 +219,7 @@ public class VisualShader implements Shader {
|
||||
//This alerts openGL to the presence of a vertex shader and points the shader at its source
|
||||
GL40.glShaderSource(rVal.vertexShader, vertexShaderSource);
|
||||
//Compiles the source for the vertex shader object
|
||||
GL40. glCompileShader(rVal.vertexShader);
|
||||
GL40.glCompileShader(rVal.vertexShader);
|
||||
//The following tests if the vertex shader compiles successfully
|
||||
int success;
|
||||
success = GL40.glGetShaderi(rVal.vertexShader, GL40.GL_COMPILE_STATUS);
|
||||
@ -246,8 +252,8 @@ public class VisualShader implements Shader {
|
||||
GL40. glLinkProgram(rVal.shaderId);
|
||||
//Tests for the success of the shader program creation
|
||||
success = GL40.glGetProgrami(rVal.shaderId, GL40.GL_LINK_STATUS);
|
||||
if (success != GL40.GL_TRUE) {
|
||||
throw new RuntimeException(GL40.glGetProgramInfoLog(rVal.shaderId));
|
||||
if(success != GL40.GL_TRUE){
|
||||
throw new Error(GL40.glGetProgramInfoLog(rVal.shaderId));
|
||||
}
|
||||
|
||||
//Deletes the individual shader objects to free up memory
|
||||
@ -257,6 +263,9 @@ public class VisualShader implements Shader {
|
||||
|
||||
|
||||
alreadyCompiledMap.put(shaderKey,rVal);
|
||||
|
||||
//check program status
|
||||
rVal.validate();
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -417,7 +426,10 @@ public class VisualShader implements Shader {
|
||||
GL40.glDeleteShader(rVal.fragmentShader);
|
||||
Globals.renderingEngine.checkError();
|
||||
|
||||
|
||||
//check program status
|
||||
if(!GL45.glIsProgram(rVal.shaderId)){
|
||||
throw new Error("Failed to build program!");
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -475,6 +487,14 @@ public class VisualShader implements Shader {
|
||||
return this.shaderId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the shader
|
||||
*/
|
||||
public void validate(){
|
||||
if(!GL40.glIsProgram(this.getId())){
|
||||
throw new Error("Shader is not a program!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the shader
|
||||
@ -483,5 +503,12 @@ public class VisualShader implements Shader {
|
||||
GL40.glDeleteShader(this.getId());
|
||||
this.shaderId = VisualShader.INVALID_UNIFORM_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the map of already-compiled shaders
|
||||
*/
|
||||
public static void clearAlreadyCompiledMap(){
|
||||
VisualShader.alreadyCompiledMap.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user