diff --git a/src/render/render_context.c b/src/render/render_context.c index cafe9519f8..68b336368f 100644 --- a/src/render/render_context.c +++ b/src/render/render_context.c @@ -1126,11 +1126,13 @@ static void makeOff(mjrContext* con) { mju_error("Could not allocate offscreen depth and stencil buffer"); } glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil); + + GLenum depth_buffer_format = mjGLAD_GL_ARB_depth_buffer_float ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8; if (con->offSamples) { - glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH32F_STENCIL8, + glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, depth_buffer_format, con->offWidth, con->offHeight); } else { - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH32F_STENCIL8, con->offWidth, con->offHeight); + glRenderbufferStorage(GL_RENDERBUFFER, depth_buffer_format, con->offWidth, con->offHeight); } glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, con->offDepthStencil); @@ -1169,7 +1171,7 @@ static void makeOff(mjrContext* con) { mju_error("Could not allocate offscreen depth and stencil buffer_r"); } glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil_r); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH32F_STENCIL8, con->offWidth, con->offHeight); + glRenderbufferStorage(GL_RENDERBUFFER, depth_buffer_format, con->offWidth, con->offHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, con->offDepthStencil_r); @@ -1489,9 +1491,6 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale, if (!mjGLAD_GL_ARB_vertex_buffer_object) { mju_error("OpenGL ARB_vertex_buffer_object required"); } - if (!mjGLAD_GL_ARB_depth_buffer_float) { - mju_error("OpenGL ARB_depth_buffer_float required"); - } con->glInitialized = 1; // determine window availability (could be EGL-headless) diff --git a/src/render/render_gl2.c b/src/render/render_gl2.c index 88bb6213f2..9cdb781c02 100644 --- a/src/render/render_gl2.c +++ b/src/render/render_gl2.c @@ -119,8 +119,11 @@ 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"); + if (con->readDepthMap == mjDEPTH_ZEROFAR && !mjGLAD_GL_ARB_clip_control) { + mju_warning("mjDEPTH_ZEROFAR requested but ARB_clip_control unavailable, depth accuracy will be limited"); + } + if (con->readDepthMap == mjDEPTH_ZEROFAR) { + mju_warning("mjDEPTH_ZEROFAR requested but window depth buffer precision may be limited"); } } } @@ -170,8 +173,11 @@ 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"); + if (con->readDepthMap == mjDEPTH_ZEROFAR && !mjGLAD_GL_ARB_clip_control) { + mju_warning("mjDEPTH_ZEROFAR requested but ARB_clip_control unavailable, depth accuracy will be limited"); + } + if (con->readDepthMap == mjDEPTH_ZEROFAR && !mjGLAD_GL_ARB_depth_buffer_float) { + mju_warning("mjDEPTH_ZEROFAR requested but ARB_depth_buffer_float unavailable, depth accuracy will be limited"); } }