Add flag to mjrContext to support legacy depth mapping by default
This commit is contained in:
@@ -1612,6 +1612,9 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
|
||||
|
||||
// set default color pixel format for mjr_readPixels
|
||||
con->readPixelFormat = GL_RGB;
|
||||
|
||||
// set default depth mapping for mjr_readPixels
|
||||
con->readDepthMapping = mjDM_ZEROTOONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -115,6 +115,10 @@ 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->readDepthMapping == mjDM_ZEROTOONE) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +163,11 @@ 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->readDepthMapping == mjDM_ZEROTOONE) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// restore currentBuffer
|
||||
|
||||
Reference in New Issue
Block a user