remove framebuffer caching for debug
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-09-02 10:07:28 -04:00
parent 1dff7ecc28
commit 9443811a2c
12 changed files with 43 additions and 45 deletions

8
.vscode/launch.json vendored
View File

@ -18,6 +18,14 @@
"vmArgs": "-Xmx2G -Xms100m -XX:+UseZGC -XX:+UseDynamicNumberOfGCThreads -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"/tmp\"", "vmArgs": "-Xmx2G -Xms100m -XX:+UseZGC -XX:+UseDynamicNumberOfGCThreads -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"/tmp\"",
"projectName": "Renderer" "projectName": "Renderer"
}, },
{
"type": "java",
"name": "Launch Main (Debug Memory)",
"request": "launch",
"mainClass": "electrosphere.engine.Main",
"vmArgs": "-Xmx2G -Xms100m -XX:+UseZGC -XX:+UseDynamicNumberOfGCThreads -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"/tmp\" -javaagent:./lwjglx-debug-1.0.0.jar=t;o=trace.log",
"projectName": "Renderer"
},
{ {
"type": "java", "type": "java",
"name": "Launch Main (Debug Audio)", "name": "Launch Main (Debug Audio)",

View File

@ -102,7 +102,6 @@ import electrosphere.menu.WindowUtils;
import electrosphere.menu.debug.ImGuiWindowMacros; import electrosphere.menu.debug.ImGuiWindowMacros;
import electrosphere.menu.ingame.MenuGeneratorsInGame; import electrosphere.menu.ingame.MenuGeneratorsInGame;
import electrosphere.menu.ingame.MenuGeneratorsInventory; import electrosphere.menu.ingame.MenuGeneratorsInventory;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.ui.elements.Window; import electrosphere.renderer.ui.elements.Window;
import electrosphere.renderer.ui.events.ClickEvent; import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.KeyboardEvent; import electrosphere.renderer.ui.events.KeyboardEvent;
@ -1206,7 +1205,7 @@ public class ControlHandler {
menuNavigationControlList.add(controls.get(MENU_CAPTURE_SCREEN)); menuNavigationControlList.add(controls.get(MENU_CAPTURE_SCREEN));
controls.get(MENU_CAPTURE_SCREEN).setOnPress(new Control.ControlMethod() {public void execute(){ controls.get(MENU_CAPTURE_SCREEN).setOnPress(new Control.ControlMethod() {public void execute(){
FileUtils.writeBufferedImage( FileUtils.writeBufferedImage(
RenderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState()), Globals.renderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState()),
"Screenshots/" + System.currentTimeMillis() + ".png" "Screenshots/" + System.currentTimeMillis() + ".png"
); );
}}); }});

View File

@ -159,12 +159,12 @@ public class OpenGLState {
* @param framebufferPointer the pointer to the framebuffer * @param framebufferPointer the pointer to the framebuffer
*/ */
public void glBindFramebuffer(int framebufferType, int framebufferPointer){ public void glBindFramebuffer(int framebufferType, int framebufferPointer){
if(DISABLE_CACHING || this.framebufferType != framebufferType || this.framebufferPointer != framebufferPointer){ // if(DISABLE_CACHING || this.framebufferType != framebufferType || this.framebufferPointer != framebufferPointer){
this.framebufferType = framebufferType; this.framebufferType = framebufferType;
this.framebufferPointer = framebufferPointer; this.framebufferPointer = framebufferPointer;
GL40.glBindFramebuffer(this.framebufferType,this.framebufferPointer); GL40.glBindFramebuffer(this.framebufferType,this.framebufferPointer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} // }
} }
/** /**

View File

@ -19,15 +19,7 @@ import org.joml.Vector3f;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import static org.lwjgl.opengl.GL11.GL_FLOAT; import static org.lwjgl.opengl.GL11.GL_FLOAT;
import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL40;
import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
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.glVertexAttribPointer;
import static org.lwjgl.opengl.GL30.glBindVertexArray;
import static org.lwjgl.opengl.GL30.glGenVertexArrays;
/** /**
* Utilities to assist with rendering * Utilities to assist with rendering
@ -37,8 +29,8 @@ public class RenderUtils {
static int createScreenTextureVAO(){ static int createScreenTextureVAO(){
int rVal = glGenVertexArrays(); int rVal = GL40.glGenVertexArrays();
glBindVertexArray(rVal); GL40.glBindVertexArray(rVal);
//vertices //vertices
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(12); FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(12);
vertexArrayBufferData.put(-1.0f); vertexArrayBufferData.put(-1.0f);
@ -59,11 +51,11 @@ public class RenderUtils {
vertexArrayBufferData.put( 1.0f); vertexArrayBufferData.put( 1.0f);
vertexArrayBufferData.put( 1.0f); vertexArrayBufferData.put( 1.0f);
vertexArrayBufferData.flip(); vertexArrayBufferData.flip();
int vertexBuffer = glGenBuffers(); int vertexBuffer = GL40.glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); GL40.glBindBuffer(GL40.GL_ARRAY_BUFFER, vertexBuffer);
GL15.glBufferData(GL_ARRAY_BUFFER, vertexArrayBufferData, GL_STATIC_DRAW); GL40.glBufferData(GL40.GL_ARRAY_BUFFER, vertexArrayBufferData, GL40.GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0); GL40.glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(0); GL40.glEnableVertexAttribArray(0);
@ -89,11 +81,11 @@ public class RenderUtils {
textureArrayBufferData.put(1.0f); textureArrayBufferData.put(1.0f);
textureArrayBufferData.put(1.0f); textureArrayBufferData.put(1.0f);
textureArrayBufferData.flip(); textureArrayBufferData.flip();
int textureCoordBuffer = glGenBuffers(); int textureCoordBuffer = GL40.glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer); GL40.glBindBuffer(GL40.GL_ARRAY_BUFFER, textureCoordBuffer);
GL15.glBufferData(GL_ARRAY_BUFFER, textureArrayBufferData, GL_STATIC_DRAW); GL40.glBufferData(GL40.GL_ARRAY_BUFFER, textureArrayBufferData, GL40.GL_STATIC_DRAW);
glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0); GL40.glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(1); GL40.glEnableVertexAttribArray(1);
return rVal; return rVal;
} }
@ -215,7 +207,7 @@ public class RenderUtils {
glBindVertexArray(0); GL40.glBindVertexArray(0);
@ -328,7 +320,7 @@ public class RenderUtils {
glBindVertexArray(0); GL40.glBindVertexArray(0);
@ -423,7 +415,7 @@ public class RenderUtils {
m.setShader(ShaderProgram.loadSpecificShader("/Shaders/font/basicbitmap/basicbitmap.vs", "/Shaders/font/basicbitmap/basicbitmap.fs")); m.setShader(ShaderProgram.loadSpecificShader("/Shaders/font/basicbitmap/basicbitmap.vs", "/Shaders/font/basicbitmap/basicbitmap.fs"));
glBindVertexArray(0); GL40.glBindVertexArray(0);
m.setParent(rVal); m.setParent(rVal);
Material uiMat = new Material(); Material uiMat = new Material();
@ -520,7 +512,7 @@ public class RenderUtils {
m.setShader(ShaderProgram.loadSpecificShader("/Shaders/font/bitmapchar/bitmapchar.vs", "/Shaders/font/bitmapchar/bitmapchar.fs")); m.setShader(ShaderProgram.loadSpecificShader("/Shaders/font/bitmapchar/bitmapchar.vs", "/Shaders/font/bitmapchar/bitmapchar.fs"));
glBindVertexArray(0); GL40.glBindVertexArray(0);
m.setParent(rVal); m.setParent(rVal);
rVal.getMeshes().add(m); rVal.getMeshes().add(m);
@ -604,7 +596,7 @@ public class RenderUtils {
m.setShader(ShaderProgram.loadSpecificShader(vertexShader, fragmentShader)); m.setShader(ShaderProgram.loadSpecificShader(vertexShader, fragmentShader));
glBindVertexArray(0); GL40.glBindVertexArray(0);
m.setParent(rVal); m.setParent(rVal);
rVal.getMeshes().add(m); rVal.getMeshes().add(m);
@ -774,7 +766,7 @@ public class RenderUtils {
//texture indices //texture indices
m.bufferCustomFloatAttribArray(textureIndices, 4, 5); m.bufferCustomFloatAttribArray(textureIndices, 4, 5);
m.setShader(program); m.setShader(program);
glBindVertexArray(0); GL40.glBindVertexArray(0);
m.setParent(rVal); m.setParent(rVal);
Material groundMat = new Material(); Material groundMat = new Material();
@ -1334,7 +1326,7 @@ public class RenderUtils {
//texture indices //texture indices
m.bufferCustomFloatAttribArray(textureIndices, 4, 5); m.bufferCustomFloatAttribArray(textureIndices, 4, 5);
m.setShader(program); m.setShader(program);
glBindVertexArray(0); GL40.glBindVertexArray(0);
m.setParent(rVal); m.setParent(rVal);
Material groundMat = new Material(); Material groundMat = new Material();
@ -1558,7 +1550,7 @@ public class RenderUtils {
//buffer texture coords //buffer texture coords
m.bufferTextureCoords(texture_coords, 2); m.bufferTextureCoords(texture_coords, 2);
m.setShader(ShaderProgram.smart_assemble_shader(false,true)); m.setShader(ShaderProgram.smart_assemble_shader(false,true));
glBindVertexArray(0); GL40.glBindVertexArray(0);
m.setParent(rVal); m.setParent(rVal);
Material groundMat = new Material(); Material groundMat = new Material();

View File

@ -116,7 +116,7 @@ public class RenderingEngine {
public static int screenTextureVAO; public static int screenTextureVAO;
public static ShaderProgram screenTextureShaders; public static ShaderProgram screenTextureShaders;
public static ShaderProgram drawChannel; public static ShaderProgram drawChannel;
public static Framebuffer defaultFramebuffer; public Framebuffer defaultFramebuffer;

View File

@ -43,7 +43,7 @@ public class Framebuffer {
* Creates a framebuffer * Creates a framebuffer
*/ */
public Framebuffer(){ public Framebuffer(){
framebufferPointer = GL40.glGenFramebuffers(); this.framebufferPointer = GL40.glGenFramebuffers();
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
@ -213,7 +213,7 @@ public class Framebuffer {
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer); openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer);
GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_COLOR_ATTACHMENT0 + attachmentNum, GL40.GL_TEXTURE_2D, texture.getTexturePointer(), 0); GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_COLOR_ATTACHMENT0 + attachmentNum, GL40.GL_TEXTURE_2D, texture.getTexturePointer(), 0);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, 0); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
} }
/** /**
@ -226,7 +226,7 @@ public class Framebuffer {
this.depthTexture = depthTexture; this.depthTexture = depthTexture;
GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_DEPTH_ATTACHMENT, GL40.GL_TEXTURE_2D, depthTexture.getTexturePointer(), 0); GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_DEPTH_ATTACHMENT, GL40.GL_TEXTURE_2D, depthTexture.getTexturePointer(), 0);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, 0); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
} }
/** /**

View File

@ -187,7 +187,7 @@ public class FramebufferUtils {
//check make sure compiled //check make sure compiled
buffer.checkStatus(); buffer.checkStatus();
//re-bind default buffer //re-bind default buffer
RenderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
return buffer; return buffer;
} }

View File

@ -73,7 +73,7 @@ public class CompositePipeline implements RenderPipeline {
//Close down pipeline //Close down pipeline
// //
GL40.glBindVertexArray(0); GL40.glBindVertexArray(0);
RenderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();

View File

@ -209,7 +209,7 @@ public class MainContentPipeline implements RenderPipeline {
// //
// Reset State // Reset State
// //
RenderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);

View File

@ -81,7 +81,7 @@ public class NormalsForOutlinePipeline implements RenderPipeline {
} }
} }
RenderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }

View File

@ -42,7 +42,7 @@ public class PostProcessingPipeline implements RenderPipeline {
GL40.glBindVertexArray(0); GL40.glBindVertexArray(0);
} }
RenderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }

View File

@ -9,7 +9,6 @@ import javax.imageio.ImageIO;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.renderer.RenderingEngine;
/** /**
* Utilities for comparing renders * Utilities for comparing renders
@ -32,7 +31,7 @@ public class TestRenderingUtils {
} catch (IOException e){ } catch (IOException e){
fail("Failed to read existing image path " + existingRenderPath); fail("Failed to read existing image path " + existingRenderPath);
} }
BufferedImage screenshot = RenderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState()); BufferedImage screenshot = Globals.renderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState());
//check basic data //check basic data
// //
//width //width
@ -89,7 +88,7 @@ public class TestRenderingUtils {
* @param existingRenderPath The filepath of the existing render * @param existingRenderPath The filepath of the existing render
*/ */
public static void saveTestRender(String existingRenderPath){ public static void saveTestRender(String existingRenderPath){
BufferedImage screenshot = RenderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState()); BufferedImage screenshot = Globals.renderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState());
try { try {
ImageIO.write(screenshot, "png", new File(existingRenderPath)); ImageIO.write(screenshot, "png", new File(existingRenderPath));
} catch (IOException e) { } catch (IOException e) {