From 32661c165dae7a6e080b3ef66c58ee11c65f5c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Aug 2026 18:28:44 +0200 Subject: [PATCH] Platform: make it possible to test contextless SDL and GLFW apps. --- .../Platform/Test/GlfwApplicationTest.cpp | 38 ++++++++++++------ .../Platform/Test/Sdl2ApplicationTest.cpp | 40 +++++++++++++------ 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp index 964128f0d..061429353 100644 --- a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp +++ b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp @@ -299,7 +299,9 @@ struct GlfwApplicationTest: Platform::Application { void drawEvent() override { Debug{} << "draw"; - swapBuffers(); + + if(!_contextless) + swapBuffers(); /* Invalid keys are tested in the constructor */ if(isKeyPressed(Key::M)) @@ -411,6 +413,7 @@ struct GlfwApplicationTest: Platform::Application { #endif private: + bool _contextless = true; bool _redraw = false; bool _vsync = false; }; @@ -425,6 +428,7 @@ GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform:: #ifdef MAGNUM_TARGET_GL .addBooleanOption("quiet").setHelp("quiet", "like --magnum-log quiet, but specified via a Context::Configuration instead") .addBooleanOption("gpu-validation").setHelp("gpu-validation", "like --magnum-gpu-validation, but specified via a Context::Configuration instead") + .addBooleanOption("contextless").setHelp("contextless", "initialize without an OpenGL context") #endif .parse(arguments.argc, arguments.argv); @@ -443,20 +447,30 @@ GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform:: if(args.isSet("always-on-top")) conf.addWindowFlags(Configuration::WindowFlag::AlwaysOnTop); #ifdef MAGNUM_TARGET_GL - GLConfiguration glConf; - if(args.isSet("quiet")) - glConf.addFlags(GLConfiguration::Flag::QuietLog); - /* No GL-specific verbose log in GlfwApplication that we'd need to handle - explicitly */ - if(args.isSet("gpu-validation")) - glConf.addFlags(GLConfiguration::Flag::GpuValidation); - create(conf, glConf); - #else - create(conf); + if((_contextless = args.isSet("contextless"))) + #endif + { + #ifdef MAGNUM_TARGET_GL + conf.addWindowFlags(Configuration::WindowFlag::Contextless); + #endif + create(conf); + } + #ifdef MAGNUM_TARGET_GL + else { + GLConfiguration glConf; + if(args.isSet("quiet")) + glConf.addFlags(GLConfiguration::Flag::QuietLog); + /* No GL-specific verbose log in GlfwApplication that we'd need to + handle explicitly */ + if(args.isSet("gpu-validation")) + glConf.addFlags(GLConfiguration::Flag::GpuValidation); + create(conf, glConf); + } #endif #ifdef MAGNUM_TARGET_GL - Debug{} << "GL context flags:" << GL::Context::current().flags(); + if(!_contextless) + Debug{} << "GL context flags:" << GL::Context::current().flags(); #endif /* For testing resize events */ diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index dff82e73b..2fa4a48df 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -338,7 +338,8 @@ struct Sdl2ApplicationTest: Platform::Application { void drawEvent() override { Debug{} << "draw event"; #ifdef MAGNUM_TARGET_GL - GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); + if(!_contextless) + GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); #endif #ifndef CORRADE_TARGET_EMSCRIPTEN @@ -347,7 +348,8 @@ struct Sdl2ApplicationTest: Platform::Application { Debug{} << Key::M << "is pressed"; #endif - swapBuffers(); + if(!_contextless) + swapBuffers(); if(_redraw) redraw(); @@ -516,6 +518,7 @@ struct Sdl2ApplicationTest: Platform::Application { #endif private: + bool _contextless = true; #ifdef CORRADE_TARGET_EMSCRIPTEN bool _fullscreen = false; #endif @@ -539,6 +542,7 @@ Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform:: #ifdef MAGNUM_TARGET_GL .addBooleanOption("quiet").setHelp("quiet", "like --magnum-log quiet, but specified via a Context::Configuration instead") .addBooleanOption("gpu-validation").setHelp("gpu-validation", "like --magnum-gpu-validation, but specified via a Context::Configuration instead") + .addBooleanOption("contextless").setHelp("contextless", "initialize without an OpenGL context") #endif .parse(arguments.argc, arguments.argv); @@ -561,20 +565,30 @@ Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform:: #endif #endif #ifdef MAGNUM_TARGET_GL - GLConfiguration glConf; - if(args.isSet("quiet")) - glConf.addFlags(GLConfiguration::Flag::QuietLog); - /* No GL-specific verbose log in Sdl2Application that we'd need to handle - explicitly */ - if(args.isSet("gpu-validation")) - glConf.addFlags(GLConfiguration::Flag::GpuValidation); - create(conf, glConf); - #else - create(conf); + if((_contextless = args.isSet("contextless"))) + #endif + { + #ifdef MAGNUM_TARGET_GL + conf.addWindowFlags(Configuration::WindowFlag::Contextless); + #endif + create(conf); + } + #ifdef MAGNUM_TARGET_GL + else { + GLConfiguration glConf; + if(args.isSet("quiet")) + glConf.addFlags(GLConfiguration::Flag::QuietLog); + /* No GL-specific verbose log in Sdl2Application that we'd need to handle + explicitly */ + if(args.isSet("gpu-validation")) + glConf.addFlags(GLConfiguration::Flag::GpuValidation); + create(conf, glConf); + } #endif #if defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_WEBGL) - Debug{} << "GL context flags:" << GL::Context::current().flags(); + if(!_contextless) + Debug{} << "GL context flags:" << GL::Context::current().flags(); #endif /* For testing resize events */