Fix when depth test is disabled but depth write is enabled
GL_DEPTH_TEST controls both whether depth testing and depth writes are
enabled. So if depth testing is disabled and depth writes are enabled,
GL_DEPTH_TEST has to be enabled and the compare mode should be GL_ALWAYS.
@@ -974,26 +974,29 @@ static void lovrGpuBindPipeline(Pipeline* pipeline) {
}
}
- // Depth test
- if (state.depthTest != pipeline->depthTest) {
- state.depthTest = pipeline->depthTest;
- if (state.depthTest != COMPARE_NONE) {
- if (!state.depthEnabled) {
- state.depthEnabled = true;
+ // Depth test and depth write
+ bool updateDepthTest = pipeline->depthTest != state.depthTest;
+ bool updateDepthWrite = state.depthWrite != (pipeline->depthWrite && !state.stencilWriting);
+ if (updateDepthTest || updateDepthWrite) {
+ bool enable = state.depthTest != COMPARE_NONE || state.depthWrite;
+
+ if (enable && !state.depthEnabled) {
glEnable(GL_DEPTH_TEST);
- }
- glDepthFunc(convertCompareMode(state.depthTest));
- } else if (state.depthEnabled) {
- state.depthEnabled = false;
+ } else if (!enable && state.depthEnabled) {
glDisable(GL_DEPTH_TEST);
}
+ state.depthEnabled = enable;
+
+ if (enable && updateDepthTest) {
+ state.depthTest = pipeline->depthTest;
+ glDepthFunc(convertCompareMode(state.depthTest));
}
- // Depth write
- if (state.depthWrite != (pipeline->depthWrite && !state.stencilWriting)) {
+ if (enable && updateDepthWrite) {
state.depthWrite = pipeline->depthWrite && !state.stencilWriting;
glDepthMask(state.depthWrite);
}
+ }
// Line width
if (state.lineWidth != pipeline->lineWidth) {
