From 1caaac47f7f0619e36b5623415ad9ab6a4600115 Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 4 Aug 2026 16:05:09 -0700 Subject: [PATCH] Fix CGL headless screenshots to read from FBO color attachment --- lib/aux_vis.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/aux_vis.cpp b/lib/aux_vis.cpp index 5aa0b5aa..35de1c0e 100644 --- a/lib/aux_vis.cpp +++ b/lib/aux_vis.cpp @@ -1106,7 +1106,20 @@ int Screenshot(const char *fname, bool convert) int w, h; wnd->getGLDrawSize(w, h); - if (wnd->isSwapPending()) + // Headless EGL/CGL windows render into an FBO. + // GL_BACK/GL_FRONT are not valid read buffers there and leave a + // sticky GL error that later asserts in EglWindow::getGLDrawSize. + GLint bound_fbo = 0; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &bound_fbo); + if (bound_fbo != 0) + { +#ifdef GLVIS_DEBUG + cerr << "Screenshot: reading image data from color attachment 0..." + << endl; +#endif + glReadBuffer(GL_COLOR_ATTACHMENT0); + } + else if (wnd->isSwapPending()) { #ifdef GLVIS_DEBUG cerr << "Screenshot: reading image data from back buffer..." << endl;