I made a program that could easily be implemented with custom classes and shaders.
Then I added a simple post processing step using compute shaders which caused the depth testing to break, everything else works though. By simply removing the post processing, the depth testing works again.
Here is the main render method:
public void render() {
post.start();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST); // Breaks when using post processing
for (Mesh m : meshes) {
if (m.doDepthTest()) {
ShaderProgram p = m.getShader();
p.use();
uploadUniform(p);
m.render();
p.unuse();
}
}
glDisable(GL_DEPTH_TEST);
for (Mesh m : meshes) {
if (!m.doDepthTest()) {
ShaderProgram p = m.getShader();
p.use();
uploadUniform(p);
m.render();
p.unuse();
}
}
post.runPostProcess();
glfwSwapBuffers(window);
glfwPollEvents();
}
The start method is very simple and only binds the framebuffer and sets the viewport size:
public void start() {
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
glViewport(0, 0, width, height);
}
This is the main post processing step where it renders the output:
public void runPostProcess() {
computeProgram.use();
glBindImageTexture(0, renderedTexture, 0, false, 0, GL_READ_ONLY, GL_RGBA32F);
glBindImageTexture(1, processedTexture, 0, false, 0, GL_WRITE_ONLY, GL_RGBA32F);
glDispatchCompute((int) Math.ceil(width / 16.0), (int) Math.ceil(height / 16.0), 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
computeProgram.unuse();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT);
quadProgram.use();
glBindTexture(GL_TEXTURE_2D, processedTexture);
renderFullscreenQuad();
quadProgram.unuse();
}
I don’t see where the problem is, I used Nsight to see if there was any problem that was visible. But apart from the calls that didn’t change the state, there was nothing.
I tried to change places when using the shaders, when clearing the depth buffer and when binding the framebuffer, but nothing helped.
Graph3r is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.