From 211949d3ced8ec20e2da208765fb01670be6e578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Mar 2019 14:35:33 +0100 Subject: [PATCH] DebugTools: improve the reverse format mapping in screenshot(). Previously it was going through all following ifs even after it found the matching value. Using a lambda to do early returns. --- src/Magnum/DebugTools/Screenshot.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Magnum/DebugTools/Screenshot.cpp b/src/Magnum/DebugTools/Screenshot.cpp index 4d868094f..60f5ca1fa 100644 --- a/src/Magnum/DebugTools/Screenshot.cpp +++ b/src/Magnum/DebugTools/Screenshot.cpp @@ -45,14 +45,16 @@ bool screenshot(PluginManager::Manager& manager, /* Get the implementation-specific color read format for given framebuffer */ const GL::PixelFormat format = framebuffer.implementationColorReadFormat(); const GL::PixelType type = framebuffer.implementationColorReadType(); - Containers::Optional genericFormat; - #ifndef DOXYGEN_GENERATING_OUTPUT /* It gets *really* confused */ - #define _c(generic, glFormat, glType) if(format == GL::PixelFormat::glFormat && type == GL::PixelType::glType) genericFormat = PixelFormat::generic; - #define _s(generic) - #include "Magnum/GL/Implementation/pixelFormatMapping.hpp" - #undef _c - #undef _s - #endif + auto genericFormat = [](GL::PixelFormat format, GL::PixelType type) -> Containers::Optional { + #ifndef DOXYGEN_GENERATING_OUTPUT /* It gets *really* confused */ + #define _c(generic, glFormat, glType) if(format == GL::PixelFormat::glFormat && type == GL::PixelType::glType) return PixelFormat::generic; + #define _s(generic) return {}; + #include "Magnum/GL/Implementation/pixelFormatMapping.hpp" + #undef _c + #undef _s + #endif + return {}; + }(format, type); if(!genericFormat) { Error{} << "DebugTools::screenshot(): can't map (" << Debug::nospace << format << Debug::nospace << "," << type << Debug::nospace << ") to a generic pixel format"; return false;