Browse Source

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

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

38
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 */

40
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 */

Loading…
Cancel
Save