Skip to content

Commit

Permalink
Some more GL/no-GL macro switches, get compiling and remove offscreen…
Browse files Browse the repository at this point in the history
… canv.
  • Loading branch information
Squareys committed Apr 15, 2019
1 parent 09aed27 commit 5d91571
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
3 changes: 3 additions & 0 deletions modules/FindMagnum.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/Magnum/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down Expand Up @@ -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 $<TARGET_OBJECTS:MagnumCglContextObjects>)
Expand Down Expand Up @@ -178,6 +178,7 @@ if(WITH_EMSCRIPTENAPPLICATION)
endif()

set(MagnumEmscriptenApplication_SRCS
$<TARGET_OBJECTS:MagnumPlatformObjects>
EmscriptenApplication.cpp)
set(MagnumEmscriptenApplication_HEADERS
EmscriptenApplication.h)
Expand All @@ -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
Expand Down
27 changes: 12 additions & 15 deletions src/Magnum/Platform/EmscriptenApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@

#include <emscripten/emscripten.h>

#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/String.h>

#include "Magnum/GL/Version.h"
#include "Magnum/Platform/GLContext.h"

#include "Magnum/Platform/Implementation/DpiScaling.h"


namespace Magnum { namespace Platform {

Expand All @@ -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() {
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

}}
8 changes: 6 additions & 2 deletions src/Magnum/Platform/EmscriptenApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <memory>

#include <Corrade/Containers/Pointer.h>

#include "Magnum/Magnum.h"
#include "Magnum/Tags.h"
#include "Magnum/GL/GL.h"
Expand Down Expand Up @@ -134,7 +136,7 @@ class EmscriptenApplication {
*
* See @ref MAGNUM_EMSCRIPTENAPPLICATION_MAIN() for usage information.
*/
static void exec();
int exec();

#ifdef MAGNUM_TARGET_GL
/**
Expand Down Expand Up @@ -337,7 +339,9 @@ class EmscriptenApplication {

Flags _flags;

std::unique_ptr<Platform::GLContext> _context;
#ifdef MAGNUM_TARGET_GL
Containers::Pointer<Platform::GLContext> _context;
#endif
CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)

void setupCallbacks();
Expand Down

0 comments on commit 5d91571

Please sign in to comment.