From 5d915710ecd251c8d6223535fb9d43572b8472b2 Mon Sep 17 00:00:00 2001 From: Squareys Date: Mon, 15 Apr 2019 17:36:03 +0200 Subject: [PATCH] Some more GL/no-GL macro switches, get compiling and remove offscreen canv. --- modules/FindMagnum.cmake | 3 +++ src/Magnum/Platform/CMakeLists.txt | 9 ++++--- src/Magnum/Platform/EmscriptenApplication.cpp | 27 +++++++++---------- src/Magnum/Platform/EmscriptenApplication.h | 8 ++++-- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 536c163706..7a4839459c 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -413,6 +413,9 @@ endif() set(_MAGNUM_Trade_DEPENDENCIES ) set(_MAGNUM_AndroidApplication_DEPENDENCIES GL) set(_MAGNUM_EmscriptenApplication_DEPENDENCIES GL) +if(MAGNUM_TARGET_GL) + list(APPEND _MAGNUM_EmscriptenApplication_DEPENDENCIES GL) +endif() set(_MAGNUM_GlfwApplication_DEPENDENCIES ) if(MAGNUM_TARGET_GL) diff --git a/src/Magnum/Platform/CMakeLists.txt b/src/Magnum/Platform/CMakeLists.txt index 3f9bb22c7c..30e0164d71 100644 --- a/src/Magnum/Platform/CMakeLists.txt +++ b/src/Magnum/Platform/CMakeLists.txt @@ -38,7 +38,7 @@ set(MagnumPlatform_PRIVATE_HEADERS ) # DPI scaling queries only for Sdl2Application and GlfwApplication at the # moment, build the files only then -if(WITH_GLFWAPPLICATION OR WITH_SDL2APPLICATION) +if(WITH_GLFWAPPLICATION OR WITH_SDL2APPLICATION OR WITH_EMSCRIPTENAPPLICATION) # List of libraries to link when using the MagnumPlatformObjects target # TODO: use target_link_libraries() when we are on a CMake version that # supports it (3.12?) @@ -93,7 +93,7 @@ set(MagnumPlatform_FILES ) install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) # Decide about platform-specific context for cross-platform toolkits -if((WITH_GLFWAPPLICATION OR WITH_SDL2APPLICATION) AND TARGET_GL) +if((WITH_GLFWAPPLICATION OR WITH_SDL2APPLICATION OR WITH_EMSCRIPTENAPPLICATION) AND TARGET_GL) if(CORRADE_TARGET_APPLE AND NOT MAGNUM_TARGET_GLES) set(NEED_CGLCONTEXT 1) set(MagnumSomeContext_OBJECTS $) @@ -178,6 +178,7 @@ if(WITH_EMSCRIPTENAPPLICATION) endif() set(MagnumEmscriptenApplication_SRCS + $ EmscriptenApplication.cpp) set(MagnumEmscriptenApplication_HEADERS EmscriptenApplication.h) @@ -191,7 +192,9 @@ if(WITH_EMSCRIPTENAPPLICATION) FOLDER "Magnum/Platform") # Assuming that PIC is not needed because the Application lib is always # linked to the executable and not to any intermediate shared lib - target_link_libraries(MagnumEmscriptenApplication PUBLIC MagnumGL) + if(TARGET_GL) + target_link_libraries(MagnumEmscriptenApplication PUBLIC MagnumGL) + endif() install(FILES ${MagnumEmscriptenApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumEmscriptenApplication diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index c4aad2cff8..95e71135f1 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -28,12 +28,15 @@ #include +#include #include #include #include "Magnum/GL/Version.h" #include "Magnum/Platform/GLContext.h" +#include "Magnum/Platform/Implementation/DpiScaling.h" + namespace Magnum { namespace Platform { @@ -47,7 +50,13 @@ EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, const C } #endif -EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreateT): _context{new GLContext{NoCreate, 0, nullptr}} { +EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreateT) { + Utility::Arguments args{Implementation::windowScalingArguments()}; + #ifdef MAGNUM_TARGET_GL + _context.reset(new GLContext{NoCreate, args, arguments.argc, arguments.argv}); + #else + args.parse(arguments.argc, arguments.argv); + #endif } EmscriptenApplication::~EmscriptenApplication() { @@ -105,19 +114,6 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration, const (glConfiguration.flags() & GLConfiguration::Flag::FailIfMajorPerformanceCaveat) != GLConfiguration::Flags{}; attrs.enableExtensionsByDefault = (glConfiguration.flags() & GLConfiguration::Flag::EnableExtensionsByDefault) != GLConfiguration::Flags{}; -#if FALSE /* "EMSCRIPTEN_VERSION > 1.38.12 */ && OFFSCREEN_FRAMEBUFFER - // TODO! Good thing my Emscripten version is from the bronze era - // We probably never want to use this anyway, except when we have a - // WindowlessEmscriptenApplication - attrs.renderViaOffscreenBackBuffer = - (glConfiguration.flags() & GLConfiguration::Flag::RenderViaOffscreenBackBuffer) != GLConfiguration::Flags{}; -#endif -#if FALSE /* "EMSCRIPTEN_VERSION > 1.38.19 */ && OFFSCREEN_FRAMEBUFFER - // TODO! See above - attrs.proxyContextToMainThread = - (glConfiguration.flags() & GLConfiguration::Flag::ProxyContextToMainThread) != GLConfiguration::Flags{}; -#endif - attrs.explicitSwapControl = true; /* Resize window and match it to the selected format */ @@ -468,7 +464,8 @@ void EmscriptenApplication::mouseMoveEvent(MouseMoveEvent&) {} EmscriptenApplication::GLConfiguration::GLConfiguration(): _colorBufferSize{8, 8, 8, 0}, _depthBufferSize{24}, _stencilBufferSize{0} {} -void EmscriptenApplication::exec() { +int EmscriptenApplication::exec() { + return 0; } }} diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 8a7b66b1cd..508b18eae3 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -34,6 +34,8 @@ #include +#include + #include "Magnum/Magnum.h" #include "Magnum/Tags.h" #include "Magnum/GL/GL.h" @@ -134,7 +136,7 @@ class EmscriptenApplication { * * See @ref MAGNUM_EMSCRIPTENAPPLICATION_MAIN() for usage information. */ - static void exec(); + int exec(); #ifdef MAGNUM_TARGET_GL /** @@ -337,7 +339,9 @@ class EmscriptenApplication { Flags _flags; - std::unique_ptr _context; + #ifdef MAGNUM_TARGET_GL + Containers::Pointer _context; + #endif CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) void setupCallbacks();