From c4b1594d9d3bf42ce1b2ad7243f7e16fbef9aaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Jun 2026 14:43:09 +0200 Subject: [PATCH] GL: ... and neither Optional has to be in Context.h. All that work to reduce header dependencies and yet here it's full of them, somehow. Well, given the fallout in various GL tests now I wonder if I should just chuck the rest along with the state allocation as a PIMPL. --- src/Magnum/GL/Context.h | 4 +-- .../GL/Implementation/driverSpecific.cpp | 29 ++++++++++--------- src/Magnum/GL/Shader.cpp | 1 + src/Magnum/GL/Test/ContextGLTest.cpp | 1 + src/Magnum/GL/Test/RendererGLTest.cpp | 1 + src/Magnum/MeshTools/Test/CompileGLTest.cpp | 1 + src/Magnum/Shaders/MeshVisualizerGL.cpp | 1 + src/Magnum/Shaders/Test/LineGLTest.cpp | 1 + .../Shaders/Test/MeshVisualizerGLTest.cpp | 1 + src/Magnum/Shaders/Test/VertexColorGLTest.cpp | 1 + .../Test/DistanceFieldGlyphCacheGLTest.cpp | 1 + .../Test/DistanceFieldGLBenchmark.cpp | 1 + .../TextureTools/Test/DistanceFieldGLTest.cpp | 1 + .../MagnumFont/Test/MagnumFontGLTest.cpp | 1 + 14 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Magnum/GL/Context.h b/src/Magnum/GL/Context.h index 6372f4e96..f8548fdcc 100644 --- a/src/Magnum/GL/Context.h +++ b/src/Magnum/GL/Context.h @@ -34,7 +34,6 @@ #include #include #include -#include #include "Magnum/Magnum.h" #include "Magnum/Math/BitVector.h" @@ -928,7 +927,8 @@ class MAGNUM_GL_EXPORT Context { Containers::ArrayTuple _stateData; Implementation::State* _state; - Containers::Optional _detectedDrivers; + /* ~DetectedDrivers{} means the value is not initialized yet */ + DetectedDrivers _detectedDrivers = ~DetectedDrivers{}; /** @todo these are all needed only until the state gets created and then can be discarded -- what to do? we could avoid including diff --git a/src/Magnum/GL/Implementation/driverSpecific.cpp b/src/Magnum/GL/Implementation/driverSpecific.cpp index 81e240058..538a70f3f 100644 --- a/src/Magnum/GL/Implementation/driverSpecific.cpp +++ b/src/Magnum/GL/Implementation/driverSpecific.cpp @@ -527,8 +527,9 @@ Containers::StringView findWorkaround(Containers::StringView workaround) { } auto Context::detectedDriver() -> DetectedDrivers { - if(_detectedDrivers) - return *_detectedDrivers; + /* ~DetectedDrivers{} means the value is not initialized yet */ + if(_detectedDrivers != ~DetectedDrivers{}) + return _detectedDrivers; _detectedDrivers = DetectedDrivers{}; @@ -563,12 +564,12 @@ auto Context::detectedDriver() -> DetectedDrivers { #ifndef CORRADE_TARGET_APPLE /* AMD binary desktop drivers */ if(vendor.contains("ATI Technologies Inc."_s)) - *_detectedDrivers |= DetectedDriver::Amd; + _detectedDrivers |= DetectedDriver::Amd; #ifdef CORRADE_TARGET_WINDOWS /* Intel Windows drivers */ if(vendor.contains("Intel"_s)) - *_detectedDrivers |= DetectedDriver::IntelWindows; + _detectedDrivers |= DetectedDriver::IntelWindows; #endif /* Mesa drivers. @@ -587,21 +588,21 @@ auto Context::detectedDriver() -> DetectedDrivers { || version.contains("Mesa"_s) #endif ) { - *_detectedDrivers |= DetectedDriver::Mesa; + _detectedDrivers |= DetectedDriver::Mesa; if(renderer.contains("SVGA3D"_s)) - *_detectedDrivers |= DetectedDriver::Svga3D; + _detectedDrivers |= DetectedDriver::Svga3D; } if(vendor.contains("NVIDIA Corporation"_s)) - *_detectedDrivers |= DetectedDriver::NVidia; + _detectedDrivers |= DetectedDriver::NVidia; #endif #ifdef MAGNUM_TARGET_GLES /* ANGLE. On WebGL only if we are so lucky and have access to the unmasked renderer string. */ if(renderer.contains("ANGLE"_s)) - *_detectedDrivers |= DetectedDriver::Angle; + _detectedDrivers |= DetectedDriver::Angle; #ifdef MAGNUM_TARGET_WEBGL /* If the unmasked renderer string is not available, try other means */ /** @todo this (and below) incorrectly detects ANGLE on FF 92+, as it has @@ -620,7 +621,7 @@ auto Context::detectedDriver() -> DetectedDrivers { #else if(isExtensionSupported()) #endif - *_detectedDrivers |= DetectedDriver::Angle; + _detectedDrivers |= DetectedDriver::Angle; /* Otherwise try to detect a D3D ANGLE backend by querying line width. It's always exactly just 1 on D3D, usually (but not always) more on GL, not sure about Metal. So this is not a 100% match. Sources: @@ -629,7 +630,7 @@ auto Context::detectedDriver() -> DetectedDrivers { Range1Di range; glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range.data()); if(range.min() == 1 && range.max() == 1 && vendor != "Internet Explorer"_s) { - *_detectedDrivers |= DetectedDriver::Angle; + _detectedDrivers |= DetectedDriver::Angle; } } } @@ -637,20 +638,20 @@ auto Context::detectedDriver() -> DetectedDrivers { /* SwiftShader */ if(renderer.contains("SwiftShader"_s)) - *_detectedDrivers |= DetectedDriver::SwiftShader; + _detectedDrivers |= DetectedDriver::SwiftShader; #endif #ifdef CORRADE_TARGET_ANDROID if(vendor.contains("ARM"_s) && renderer.contains("Mali"_s)) - *_detectedDrivers |= DetectedDriver::ArmMali; + _detectedDrivers |= DetectedDriver::ArmMali; #endif #if defined(MAGNUM_TARGET_GLES) && !defined(CORRADE_TARGET_APPLE) if(vendor.contains("Qualcomm"_s) && renderer.contains("Adreno"_s)) - *_detectedDrivers |= DetectedDriver::QualcommAdreno; + _detectedDrivers |= DetectedDriver::QualcommAdreno; #endif - return *_detectedDrivers; + return _detectedDrivers; } void Context::disableDriverWorkaround(const Containers::StringView workaround) { diff --git a/src/Magnum/GL/Shader.cpp b/src/Magnum/GL/Shader.cpp index 6f993a5c2..e40dcbe5b 100644 --- a/src/Magnum/GL/Shader.cpp +++ b/src/Magnum/GL/Shader.cpp @@ -29,6 +29,7 @@ #include #include +#include #ifdef MAGNUM_BUILD_DEPRECATED #include #endif diff --git a/src/Magnum/GL/Test/ContextGLTest.cpp b/src/Magnum/GL/Test/ContextGLTest.cpp index ed0c02849..951ebf386 100644 --- a/src/Magnum/GL/Test/ContextGLTest.cpp +++ b/src/Magnum/GL/Test/ContextGLTest.cpp @@ -25,6 +25,7 @@ */ #include /* std::find() */ +#include #include #include #include /** @todo remove once Debug is stream-free */ diff --git a/src/Magnum/GL/Test/RendererGLTest.cpp b/src/Magnum/GL/Test/RendererGLTest.cpp index ffcef6fbe..a1cb1003b 100644 --- a/src/Magnum/GL/Test/RendererGLTest.cpp +++ b/src/Magnum/GL/Test/RendererGLTest.cpp @@ -31,6 +31,7 @@ #include #ifdef CORRADE_TARGET_APPLE +#include #include #include /* isSandboxed() */ #endif diff --git a/src/Magnum/MeshTools/Test/CompileGLTest.cpp b/src/Magnum/MeshTools/Test/CompileGLTest.cpp index 6ebb5e81e..911cd3de5 100644 --- a/src/Magnum/MeshTools/Test/CompileGLTest.cpp +++ b/src/Magnum/MeshTools/Test/CompileGLTest.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include diff --git a/src/Magnum/Shaders/MeshVisualizerGL.cpp b/src/Magnum/Shaders/MeshVisualizerGL.cpp index 47cc976c6..05991e2b5 100644 --- a/src/Magnum/Shaders/MeshVisualizerGL.cpp +++ b/src/Magnum/Shaders/MeshVisualizerGL.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include diff --git a/src/Magnum/Shaders/Test/LineGLTest.cpp b/src/Magnum/Shaders/Test/LineGLTest.cpp index fe9af13dc..58c7ad5e8 100644 --- a/src/Magnum/Shaders/Test/LineGLTest.cpp +++ b/src/Magnum/Shaders/Test/LineGLTest.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp index 8cb6f8b97..4075284f6 100644 --- a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp +++ b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp @@ -27,6 +27,7 @@ #include /* std::iota() */ #include +#include #include #include #include diff --git a/src/Magnum/Shaders/Test/VertexColorGLTest.cpp b/src/Magnum/Shaders/Test/VertexColorGLTest.cpp index 0fd127940..ab0820376 100644 --- a/src/Magnum/Shaders/Test/VertexColorGLTest.cpp +++ b/src/Magnum/Shaders/Test/VertexColorGLTest.cpp @@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include diff --git a/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp b/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp index d0c367501..de7ce3901 100644 --- a/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp +++ b/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include diff --git a/src/Magnum/TextureTools/Test/DistanceFieldGLBenchmark.cpp b/src/Magnum/TextureTools/Test/DistanceFieldGLBenchmark.cpp index 1f7ea733f..e5c2f41c0 100644 --- a/src/Magnum/TextureTools/Test/DistanceFieldGLBenchmark.cpp +++ b/src/Magnum/TextureTools/Test/DistanceFieldGLBenchmark.cpp @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include diff --git a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp index f8f9c433b..4a7201d9e 100644 --- a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp +++ b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include diff --git a/src/MagnumPlugins/MagnumFont/Test/MagnumFontGLTest.cpp b/src/MagnumPlugins/MagnumFont/Test/MagnumFontGLTest.cpp index 32346757e..582b9a358 100644 --- a/src/MagnumPlugins/MagnumFont/Test/MagnumFontGLTest.cpp +++ b/src/MagnumPlugins/MagnumFont/Test/MagnumFontGLTest.cpp @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include