Fallback for if GL_ARB_clip_control not available

If GL_ARB_clip_control not available then [znear, zfar] -> [1, -1] instead of [1, 0] in normalized device coordinates

Thus, Z is still reversed, but not shifted, clipping should still work properly, and conversion to window coordinates does not cause accuracy regression compared to non-reversed Z rendering.
This commit is contained in:
Levi Burner
2023-10-02 18:20:58 -04:00
parent 9868486af0
commit c6961b77d7
3 changed files with 31 additions and 11 deletions
+6 -1
View File
@@ -119,6 +119,9 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
int N_pixels = viewport.width * viewport.height;
for (int i = 0; i < N_pixels; i++) depth[i] = 1.0 - depth[i]; // Reverse the reversed Z buffer
}
else if (!mjGLAD_GL_ARB_clip_control) {
mju_warning("ARB_clip_control unavailable while mjDEPTH_ZEROFAR requested, depth accuracy will be limited");
}
}
}
@@ -163,11 +166,13 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
if (depth) {
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
if (con->readDepthMap == mjDEPTH_ZERONEAR) {
int N_pixels = viewport.width * viewport.height;
for (int i = 0; i < N_pixels; i++) depth[i] = 1.0 - depth[i]; // Reverse the reversed Z buffer
}
else if (!mjGLAD_GL_ARB_clip_control) {
mju_warning("ARB_clip_control unavailable while mjDEPTH_ZEROFAR requested, depth accuracy will be limited");
}
}
// restore currentBuffer