From e3dc54f60946789d76633be05e780977126b48b7 Mon Sep 17 00:00:00 2001 From: Nimrod Gileadi Date: Mon, 5 Feb 2024 03:35:05 -0800 Subject: [PATCH] Emit only one warning about ARB_depth_buffer_float or ARB_clip_control. This code was warning on every frame, which was unhelpful. PiperOrigin-RevId: 604267726 Change-Id: Ied1d46e3d84d58f3b21201e3752e3c2d43ea3ba9 --- src/render/render_gl2.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/render/render_gl2.c b/src/render/render_gl2.c index 75e91856..d345b110 100644 --- a/src/render/render_gl2.c +++ b/src/render/render_gl2.c @@ -93,6 +93,32 @@ void mjr_restoreBuffer(const mjrContext* con) { +// emit one warning about mjGLAD_GL_ARB_clip_control +static void warnAboutARBClipControl(void) { + // not thread safe, but the consequence is just too many log lines + static int warned = 0; + if (!warned) { + warned = 1; + mju_warning("ARB_clip_control unavailable while mjDEPTH_ZEROFAR requested, " + "depth accuracy will be limited"); + } +} + + + +// emit one warning about mjGLAD_GL_ARB_depth_buffer_float +static void warnAboutARBDepthBuffer(void) { + // not thread safe, but the consequence is just too many log lines + static int warned = 0; + if (!warned) { + warned = 1; + mju_warning("ARB_depth_buffer_float unavailable while mjDEPTH_ZEROFAR requested, " + "depth accuracy will be limited"); + } +} + + + static inline void flipDepthIfRequired(float* depth, mjrRect viewport, const mjrContext* con) { if (con->readDepthMap == mjDEPTH_ZERONEAR) { int npixel = viewport.width * viewport.height; @@ -100,11 +126,9 @@ static inline void flipDepthIfRequired(float* depth, mjrRect viewport, const mjr 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"); + warnAboutARBClipControl(); } else if (!mjGLAD_GL_ARB_depth_buffer_float) { - mju_warning("ARB_depth_buffer_float unavailable while mjDEPTH_ZEROFAR requested, " - "depth accuracy will be limited"); + warnAboutARBDepthBuffer(); } }