Browse Source

Platform: make it possible to test contextless SDL and GLFW apps.

next
Vladimír Vondruš 2 days ago
parent
commit
32661c165d
  1. 22
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  2. 18
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

22
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -299,6 +299,8 @@ struct GlfwApplicationTest: Platform::Application {
void drawEvent() override { void drawEvent() override {
Debug{} << "draw"; Debug{} << "draw";
if(!_contextless)
swapBuffers(); swapBuffers();
/* Invalid keys are tested in the constructor */ /* Invalid keys are tested in the constructor */
@ -411,6 +413,7 @@ struct GlfwApplicationTest: Platform::Application {
#endif #endif
private: private:
bool _contextless = true;
bool _redraw = false; bool _redraw = false;
bool _vsync = false; bool _vsync = false;
}; };
@ -425,6 +428,7 @@ GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform::
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
.addBooleanOption("quiet").setHelp("quiet", "like --magnum-log quiet, but specified via a Context::Configuration instead") .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("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 #endif
.parse(arguments.argc, arguments.argv); .parse(arguments.argc, arguments.argv);
@ -443,19 +447,29 @@ GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform::
if(args.isSet("always-on-top")) if(args.isSet("always-on-top"))
conf.addWindowFlags(Configuration::WindowFlag::AlwaysOnTop); conf.addWindowFlags(Configuration::WindowFlag::AlwaysOnTop);
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
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; GLConfiguration glConf;
if(args.isSet("quiet")) if(args.isSet("quiet"))
glConf.addFlags(GLConfiguration::Flag::QuietLog); glConf.addFlags(GLConfiguration::Flag::QuietLog);
/* No GL-specific verbose log in GlfwApplication that we'd need to handle /* No GL-specific verbose log in GlfwApplication that we'd need to
explicitly */ handle explicitly */
if(args.isSet("gpu-validation")) if(args.isSet("gpu-validation"))
glConf.addFlags(GLConfiguration::Flag::GpuValidation); glConf.addFlags(GLConfiguration::Flag::GpuValidation);
create(conf, glConf); create(conf, glConf);
#else }
create(conf);
#endif #endif
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
if(!_contextless)
Debug{} << "GL context flags:" << GL::Context::current().flags(); Debug{} << "GL context flags:" << GL::Context::current().flags();
#endif #endif

18
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -338,6 +338,7 @@ struct Sdl2ApplicationTest: Platform::Application {
void drawEvent() override { void drawEvent() override {
Debug{} << "draw event"; Debug{} << "draw event";
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
if(!_contextless)
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
#endif #endif
@ -347,6 +348,7 @@ struct Sdl2ApplicationTest: Platform::Application {
Debug{} << Key::M << "is pressed"; Debug{} << Key::M << "is pressed";
#endif #endif
if(!_contextless)
swapBuffers(); swapBuffers();
if(_redraw) if(_redraw)
@ -516,6 +518,7 @@ struct Sdl2ApplicationTest: Platform::Application {
#endif #endif
private: private:
bool _contextless = true;
#ifdef CORRADE_TARGET_EMSCRIPTEN #ifdef CORRADE_TARGET_EMSCRIPTEN
bool _fullscreen = false; bool _fullscreen = false;
#endif #endif
@ -539,6 +542,7 @@ Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
.addBooleanOption("quiet").setHelp("quiet", "like --magnum-log quiet, but specified via a Context::Configuration instead") .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("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 #endif
.parse(arguments.argc, arguments.argv); .parse(arguments.argc, arguments.argv);
@ -561,6 +565,16 @@ Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::
#endif #endif
#endif #endif
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
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; GLConfiguration glConf;
if(args.isSet("quiet")) if(args.isSet("quiet"))
glConf.addFlags(GLConfiguration::Flag::QuietLog); glConf.addFlags(GLConfiguration::Flag::QuietLog);
@ -569,11 +583,11 @@ Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::
if(args.isSet("gpu-validation")) if(args.isSet("gpu-validation"))
glConf.addFlags(GLConfiguration::Flag::GpuValidation); glConf.addFlags(GLConfiguration::Flag::GpuValidation);
create(conf, glConf); create(conf, glConf);
#else }
create(conf);
#endif #endif
#if defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_WEBGL) #if defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_WEBGL)
if(!_contextless)
Debug{} << "GL context flags:" << GL::Context::current().flags(); Debug{} << "GL context flags:" << GL::Context::current().flags();
#endif #endif

Loading…
Cancel
Save