From 0dc2fc943027533439984947731cff8ae198edf0 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 10 Apr 2020 17:38:18 +0200 Subject: [PATCH 1/4] Make OpenSpace work with the new SGCT version --- apps/OpenSpace/CMakeLists.txt | 29 +- apps/OpenSpace/ext/sgct | 2 +- apps/OpenSpace/main.cpp | 647 ++++++++++----------- include/openspace/engine/openspaceengine.h | 4 +- include/openspace/engine/syncengine.h | 4 +- include/openspace/engine/windowdelegate.h | 5 - include/openspace/util/syncbuffer.h | 6 +- src/engine/openspaceengine.cpp | 8 +- src/engine/syncengine.cpp | 6 +- src/util/syncbuffer.cpp | 4 +- 10 files changed, 316 insertions(+), 399 deletions(-) diff --git a/apps/OpenSpace/CMakeLists.txt b/apps/OpenSpace/CMakeLists.txt index 267eb2c182..12d4c5bd98 100644 --- a/apps/OpenSpace/CMakeLists.txt +++ b/apps/OpenSpace/CMakeLists.txt @@ -111,42 +111,19 @@ target_compile_definitions(OpenSpace PRIVATE begin_header("Dependency: SGCT") set(SGCT_TEXT OFF CACHE BOOL "" FORCE) -set(SGCT_BUILD_CSHARP_PROJECTS OFF CACHE BOOL "" FORCE) -set(SGCT_LIGHT_ONLY ON CACHE BOOL "" FORCE) -set(SGCT_CUSTOMOUTPUTDIRS OFF CACHE BOOL "" FORCE) -set(JPEG_TURBO_WITH_SIMD OFF CACHE BOOL "" FORCE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ext/sgct) target_include_directories(OpenSpace SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/ext/sgct/include) -target_link_libraries( - OpenSpace - sgct_light glew glfw png16_static quat tinyxml2static turbojpeg-static - vrpn ${GLFW_LIBRARIES} -) +target_link_libraries(OpenSpace sgct) -mark_as_advanced(EXECUTABLE_OUTPUT_PATH GLFW_BUILD_DOCS GLFW_BUILD_EXAMPLES - GLFW_BUILD_TESTS GLFW_INSTALL GLFW_USE_HYBRID_HPG GLFW_USE_OSMESA GLFW_VULKAN_STATIC - INSTALL_BIN_DIR INSTALL_INC_DIR INSTALL_LIB_DIR INSTALL_MAN_DIR INSTALL_PKGCONFIG_DIR - IOKIT_LIBRARY JPEG_TURBO_FORCE32bit JPEG_TURBO_WITH_12BIT JPEG_TURBO_WITH_ARITH_DEC - JPEG_TURBO_WITH_ARITH_ENC JPEG_TURBO_WITH_JPEG7 JPEG_TURBO_WITH_JPEG8 - JPEG_TURBO_WITH_MEM_SRCDST JPEG_TURBO_WITH_SIMD JPEG_TURBO_WITH_TURBOJPEG LIB_SUFFIX - LIBRARY_OUTPUT_PATH M_LIBRARY SGCT_BUILD_ALUT SGCT_BUILD_CSHARP_PROJECTS - SGCT_CUSTOMOUTPUTDIRS SGCT_DOXYGEN SGCT_DOXYGEN_QUIET SGCT_EXAMPLES SGCT_INSTALL - SGCT_LIGHT_ONLY SGCT_NO_EXTERNAL_LIBRARIES SGCT_SPOUT_SUPPORT SGCT_TEXT - SGCT_USE_MSVC_RUNTIMES USE_MSVC_RUNTIME_LIBRARY_DLL -) - -set_folder_location(sgct_light "External") -set_folder_location(glew "External/SGCT") +set_folder_location(sgct "External") set_folder_location(glfw "External/SGCT") +set_folder_location(miniziplibstatic "External/SGCT") set_folder_location(png16_static "External/SGCT") set_folder_location(quat "External/SGCT") -set_folder_location(simd "External/SGCT") set_folder_location(tinyxml2static "External/SGCT") -set_folder_location(turbojpeg-static "External/SGCT") set_folder_location(vrpn "External/SGCT") set_folder_location(zlibstatic "External/SGCT") -set_folder_location(miniziplibstatic "External/SGCT") if (UNIX AND (NOT APPLE)) target_link_libraries(OpenSpace Xcursor Xinerama X11) diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 3622605062..19799abace 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 3622605062ae61736426e3d8d26e98524ec1fc97 +Subproject commit 19799abace7513623902fa5e43158b6f6a565434 diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index ec47265306..87cb5d9b5c 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -41,21 +41,34 @@ #include #include #include -#include -#include -#include +//#include +#include +#define GLFW_EXPOSE_NATIVE_WIN32 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include +#include +#include #ifdef WIN32 #include #include #include +#include #include #include #include -#include #endif // WIN32 #ifdef OPENVR_SUPPORT @@ -79,6 +92,7 @@ constexpr const bool EnableDetailedVtune = false; #endif // OPENSPACE_HAS_NVTOOLS using namespace openspace; +using namespace sgct; namespace { @@ -86,11 +100,15 @@ constexpr const char* _loggerCat = "main"; constexpr const char* SpoutTag = "Spout"; constexpr const char* OpenVRTag = "OpenVR"; -sgct::Engine* SgctEngine; -sgct::SharedVector _synchronizationBuffer; +// @TODO (abock, 2020-04-09): These state variables should disappear +const Window* currentWindow = nullptr; +const BaseViewport* currentViewport = nullptr; +Frustum::Mode currentFrustumMode; +glm::mat4 currentModelViewProjectionMatrix; +glm::mat4 currentModelMatrix; #ifdef OPENVR_SUPPORT -sgct::SGCTWindow* FirstOpenVRWindow = nullptr; +Window* FirstOpenVRWindow = nullptr; #endif #ifdef OPENSPACE_HAS_VTUNE @@ -214,55 +232,10 @@ LONG WINAPI generateMiniDump(EXCEPTION_POINTERS* exceptionPointers) { } #endif // WIN32 -// -// Detect OpenGL version -// -std::pair supportedOpenGLVersion() { - // Just create a window in order to retrieve the available OpenGL version before we - // create the real window - glfwInit(); - - // On OS X we need to explicitly set the version and specify that we are using CORE - // profile to be able to use glGetIntegerv(GL_MAJOR_VERSION, &major) and - // glGetIntegerv(GL_MINOR_VERSION, &minor) explicitly setting to OGL 3.3 CORE works - // since all Mac's now support at least 3.3 -#ifdef __APPLE__ - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#endif - - glfwWindowHint(GLFW_VISIBLE, GL_FALSE); - - // By creating an offscreen window, the user will not know that we created this window - GLFWwindow* offscreen = glfwCreateWindow(128, 128, "", nullptr, nullptr); - glfwMakeContextCurrent(offscreen); - - // Get the OpenGL version - int major, minor; - glGetIntegerv(GL_MAJOR_VERSION, &major); - glGetIntegerv(GL_MINOR_VERSION, &minor); - - // And get rid of the window again - glfwDestroyWindow(offscreen); - glfwWindowHint(GLFW_VISIBLE, GL_TRUE); - - return { major, minor }; -} - -// -// Context creation function -// -void mainContextCreationFunc(GLFWwindow* win) { - // @TODO (abock, 2020-02-10) Remove this after updating SGCT to 3.0 - TracyGpuContext -} - // // Init function // -void mainInitFunc() { +void mainInitFunc(GLFWwindow*) { ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -288,32 +261,33 @@ void mainInitFunc() { icons[0].width = x; icons[0].height = y; - const size_t nWindows = SgctEngine->getNumberOfWindows(); - for (size_t i = 0; i < nWindows; ++i) { - const sgct::SGCTWindow* windowPtr = SgctEngine->getWindowPtr(i); - glfwSetWindowIcon(windowPtr->getWindowHandle(), 1, icons); + for (const std::unique_ptr& window : Engine::instance().windows()) { + glfwSetWindowIcon(window->windowHandle(), 1, icons); } stbi_image_free(icons[0].pixels); } - + currentWindow = Engine::instance().windows().front().get(); + currentViewport = currentWindow->viewports().front().get(); LDEBUG("Initializing OpenGL in OpenSpace Engine started"); global::openSpaceEngine.initializeGL(); LDEBUG("Initializing OpenGL in OpenSpace Engine finished"); + // Find if we have at least one OpenVR window // Save reference to first OpenVR window, which is the one we will copy to the HMD. - for (size_t i = 0; i < SgctEngine->getNumberOfWindows(); ++i) { - if (SgctEngine->getWindowPtr(i)->checkIfTagExists(OpenVRTag)) { + for (const std::unique_ptr& window : Engine::instance().windows()) { + if (window->hasTag(OpenVRTag)) { #ifdef OPENVR_SUPPORT - FirstOpenVRWindow = SgctEngine->getWindowPtr(i); + FirstOpenVRWindow = window.get(); // If we have an OpenVRWindow, initialize OpenVR. - sgct::SGCTOpenVR::initialize( - SgctEngine->getNearClippingPlane(), SgctEngine->getFarClippingPlane() + sgct::OpenVR::initialize( + Engine::instance().nearClippingPlane(), + Engine::instance().farClippingPlane() ); #else LWARNING("OpenVR was requested, but program was compiled without VR support"); @@ -323,11 +297,9 @@ void mainInitFunc() { } } - const size_t nWindows = SgctEngine->getNumberOfWindows(); - for (size_t i = 0; i < nWindows; ++i) { - const sgct::SGCTWindow* windowPtr = SgctEngine->getWindowPtr(i); - - if (!windowPtr->checkIfTagExists(SpoutTag)) { + for (size_t i = 0; i < Engine::instance().windows().size(); ++i) { + Window& window = *Engine::instance().windows()[i]; + if (!window.hasTag(SpoutTag)) { continue; } @@ -336,34 +308,34 @@ void mainInitFunc() { w.windowId = i; - const sgct::SGCTWindow::StereoMode sm = windowPtr->getStereoMode(); - const bool hasStereo = (sm != sgct::SGCTWindow::No_Stereo) && - (sm < sgct::SGCTWindow::Side_By_Side_Stereo); + const Window::StereoMode sm = window.stereoMode(); + const bool hasStereo = (sm != Window::StereoMode::NoStereo) && + (sm < Window::StereoMode::SideBySide); if (hasStereo) { SpoutWindow::SpoutData& left = w.leftOrMain; left.handle = GetSpout(); left.initialized = left.handle->CreateSender( - (windowPtr->getName() + "_left").c_str(), - windowPtr->getXFramebufferResolution(), - windowPtr->getYFramebufferResolution() + (window.name() + "_left").c_str(), + window.framebufferResolution().x, + window.framebufferResolution().y ); SpoutWindow::SpoutData& right = w.right; right.handle = GetSpout(); right.initialized = right.handle->CreateSender( - (windowPtr->getName() + "_right").c_str(), - windowPtr->getXFramebufferResolution(), - windowPtr->getYFramebufferResolution() + (window.name() + "_right").c_str(), + window.framebufferResolution().x, + window.framebufferResolution().y ); } else { SpoutWindow::SpoutData& main = w.leftOrMain; main.handle = GetSpout(); main.initialized = main.handle->CreateSender( - windowPtr->getName().c_str(), - windowPtr->getXFramebufferResolution(), - windowPtr->getYFramebufferResolution() + window.name().c_str(), + window.framebufferResolution().x, + window.framebufferResolution().y ); } @@ -392,23 +364,8 @@ void mainInitFunc() { ); } - for (size_t i = 0; i < nWindows; ++i) { - sgct::SGCTWindow* w = SgctEngine->getWindowPtr(i); - const std::string screenshotNames = nWindows > 1 ? - fmt::format("OpenSpace_{}", i) : - "OpenSpace"; + Settings::instance().setCapturePath(absPath(screenshotPath)); - sgct_core::ScreenCapture* cpt0 = w->getScreenCapturePointer(0); - sgct_core::ScreenCapture* cpt1 = w->getScreenCapturePointer(1); - - if (cpt0) { - cpt0->setPathAndFileName(absPath(screenshotPath), screenshotNames); - } - - if (cpt1) { - cpt1->setPathAndFileName(absPath(screenshotPath), screenshotNames); - } - } LTRACE("main::mainInitFunc(end)"); #ifdef OPENSPACE_HAS_VTUNE @@ -421,10 +378,6 @@ void mainInitFunc() { void mainPreSyncFunc() { - // @TODO (abock, 2020-02-10) Remove this after merging SGCT version 3.0 - FrameMark - - ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -439,7 +392,7 @@ void mainPreSyncFunc() { } catch (const ghoul::RuntimeError& e) { LFATALC(e.component, e.message); - sgct::Engine::instance()->terminate(); + Engine::instance().terminate(); } // Query joystick status @@ -459,13 +412,13 @@ void mainPreSyncFunc() { if (!state.isConnected) { // Joystick was added state.isConnected = true; - state.name = sgct::Engine::getJoystickName(i); + state.name = glfwGetJoystickName(i); std::fill(state.axes.begin(), state.axes.end(), 0.f); std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); } - const float* axes = sgct::Engine::getJoystickAxes(i, &state.nAxes); + const float* axes = glfwGetJoystickAxes(i, &state.nAxes); if (state.nAxes > JoystickInputState::MaxAxes) { LWARNING(fmt::format( "Joystick/Gamepad {} has {} axes, but only {} axes are supported. " @@ -476,10 +429,7 @@ void mainPreSyncFunc() { } std::memcpy(state.axes.data(), axes, state.nAxes * sizeof(float)); - const unsigned char* buttons = sgct::Engine::getJoystickButtons( - i, - &state.nButtons - ); + const unsigned char* buttons = glfwGetJoystickButtons(i, &state.nButtons); if (state.nButtons > JoystickInputState::MaxButtons) { LWARNING(fmt::format( @@ -566,7 +516,7 @@ void mainPostSyncPreDrawFunc() { -void mainRenderFunc() { +void mainRenderFunc(const RenderData& data) { ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -579,10 +529,31 @@ void mainRenderFunc() { #endif // OPENSPACE_HAS_NVTOOLS LTRACE("main::mainRenderFunc(begin)"); - glm::mat4 viewMatrix = SgctEngine->getCurrentViewMatrix() * - glm::translate(glm::mat4(1.f), sgct::Engine::getDefaultUserPtr()->getPos()); + currentWindow = &data.window; + currentViewport = &data.viewport; + currentFrustumMode = data.frustumMode; - glm::mat4 projectionMatrix = SgctEngine->getCurrentProjectionMatrix(); + glm::vec3 pos; + std::memcpy( + glm::value_ptr(pos), + &Engine::instance().defaultUser().posMono().x, + sizeof(vec3) + ); + + glm::mat4 viewMatrix; + std::memcpy( + glm::value_ptr(viewMatrix), + data.viewMatrix.values, + sizeof(mat4) + ); + viewMatrix = viewMatrix * glm::translate(glm::mat4(1.f), pos); + + glm::mat4 projectionMatrix; + std::memcpy( + glm::value_ptr(projectionMatrix), + data.projectionMatrix.values, + sizeof(mat4) + ); #ifdef OPENVR_SUPPORT bool currentWindowIsHMD = FirstOpenVRWindow == SgctEngine->getCurrentWindowPtr(); if (sgct::SGCTOpenVR::isHMDActive() && currentWindowIsHMD) { @@ -593,11 +564,15 @@ void mainRenderFunc() { #endif try { - global::openSpaceEngine.render( - SgctEngine->getModelMatrix(), - viewMatrix, - projectionMatrix + glm::mat4 modelMatrix; + std::memcpy( + glm::value_ptr(modelMatrix), + data.modelMatrix.values, + sizeof(mat4) ); + currentModelMatrix = modelMatrix; + currentModelViewProjectionMatrix = modelMatrix * viewMatrix * projectionMatrix; + global::openSpaceEngine.render(modelMatrix, viewMatrix, projectionMatrix); } catch (const ghoul::RuntimeError& e) { LERRORC(e.component, e.message); @@ -616,7 +591,7 @@ void mainRenderFunc() { -void mainDraw2DFunc() { +void mainDraw2DFunc(const RenderData& data) { ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -626,6 +601,10 @@ void mainDraw2DFunc() { #endif // OPENSPACE_HAS_VTUNE LTRACE("main::mainDraw2DFunc(begin)"); + currentWindow = &data.window; + currentViewport = &data.viewport; + currentFrustumMode = data.frustumMode; + try { global::openSpaceEngine.drawOverlays(); } @@ -661,7 +640,7 @@ void mainPostDrawFunc() { #ifdef OPENVR_SUPPORT if (FirstOpenVRWindow) { // Copy the first OpenVR window to the HMD - sgct::SGCTOpenVR::copyWindowToHMD(FirstOpenVRWindow); + sgct::OpenVR::copyWindowToHMD(FirstOpenVRWindow); } #endif // OPENVR_SUPPORT @@ -669,26 +648,26 @@ void mainPostDrawFunc() { #ifdef OPENSPACE_HAS_SPOUT for (const SpoutWindow& w : SpoutWindows) { - sgct::SGCTWindow* window = SgctEngine->getWindowPtr(w.windowId); + sgct::Window& window = *Engine::instance().windows()[w.windowId]; if (w.leftOrMain.initialized) { - const GLuint texId = window->getFrameBufferTexture(sgct::Engine::LeftEye); + const GLuint texId = window.frameBufferTexture(Window::TextureIndex::LeftEye); glBindTexture(GL_TEXTURE_2D, texId); w.leftOrMain.handle->SendTexture( texId, GL_TEXTURE_2D, - window->getXFramebufferResolution(), - window->getYFramebufferResolution() + window.framebufferResolution().x, + window.framebufferResolution().y ); } if (w.right.initialized) { - const GLuint texId = window->getFrameBufferTexture(sgct::Engine::RightEye); + const GLuint texId = window.frameBufferTexture(Window::TextureIndex::RightEye); glBindTexture(GL_TEXTURE_2D, texId); w.right.handle->SendTexture( texId, GL_TEXTURE_2D, - window->getXFramebufferResolution(), - window->getYFramebufferResolution() + window.framebufferResolution().x, + window.framebufferResolution().y ); } } @@ -705,7 +684,9 @@ void mainPostDrawFunc() { -void mainKeyboardCallback(int key, int, int action, int modifiers) { +void mainKeyboardCallback(sgct::Key key, sgct::Modifier modifiers, sgct::Action action, + int) +{ ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -715,7 +696,7 @@ void mainKeyboardCallback(int key, int, int action, int modifiers) { #endif // OPENSPACE_HAS_VTUNE LTRACE("main::mainKeyboardCallback(begin)"); - const Key k = Key(key); + const openspace::Key k = openspace::Key(key); const KeyModifier m = KeyModifier(modifiers); const KeyAction a = KeyAction(action); global::openSpaceEngine.keyboardCallback(k, m, a); @@ -730,7 +711,9 @@ void mainKeyboardCallback(int key, int, int action, int modifiers) { -void mainMouseButtonCallback(int key, int action, int modifiers) { +void mainMouseButtonCallback(sgct::MouseButton key, sgct::Modifier modifiers, + sgct::Action action) +{ ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -740,9 +723,9 @@ void mainMouseButtonCallback(int key, int action, int modifiers) { #endif // OPENSPACE_HAS_VTUNE LTRACE("main::mainMouseButtonCallback(begin)"); - const MouseButton k = MouseButton(key); - const MouseAction a = MouseAction(action); - const KeyModifier m = KeyModifier(modifiers); + const openspace::MouseButton k = openspace::MouseButton(key); + const openspace::MouseAction a = openspace::MouseAction(action); + const openspace::KeyModifier m = openspace::KeyModifier(modifiers); global::openSpaceEngine.mouseButtonCallback(k, a, m); LTRACE("main::mainMouseButtonCallback(end)"); @@ -818,7 +801,7 @@ void mainCharCallback(unsigned int codepoint, int modifiers) { -void mainEncodeFun() { +std::vector mainEncodeFun() { ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -828,9 +811,7 @@ void mainEncodeFun() { #endif // OPENSPACE_HAS_VTUNE LTRACE("main::mainEncodeFun(begin)"); - std::vector data = global::openSpaceEngine.encode(); - _synchronizationBuffer.setVal(std::move(data)); - sgct::SharedData::instance()->writeVector(&_synchronizationBuffer); + std::vector data = global::openSpaceEngine.encode(); LTRACE("main::mainEncodeFun(end)"); #ifdef OPENSPACE_HAS_VTUNE @@ -838,11 +819,13 @@ void mainEncodeFun() { __itt_frame_end_v3(_vTune.encode, nullptr); } #endif // OPENSPACE_HAS_VTUNE + + return data; } -void mainDecodeFun() { +void mainDecodeFun(const std::vector& data, unsigned int) { ZoneScoped #ifdef OPENSPACE_HAS_VTUNE @@ -852,9 +835,7 @@ void mainDecodeFun() { #endif // OPENSPACE_HAS_VTUNE LTRACE("main::mainDecodeFun(begin)"); - sgct::SharedData::instance()->readVector(&_synchronizationBuffer); - std::vector data = _synchronizationBuffer.getVal(); - global::openSpaceEngine.decode(std::move(data)); + global::openSpaceEngine.decode(data); LTRACE("main::mainDecodeFun(end)"); #ifdef OPENSPACE_HAS_VTUNE @@ -866,17 +847,24 @@ void mainDecodeFun() { -void mainLogCallback(const char* msg) { +void mainLogCallback(Log::Level level, const char* message) { ZoneScoped - std::string message = msg; - if (message.empty() || message == ".") { - // We don't want the empty '.' message that SGCT sends while it is waiting for - // connections from other network nodes - return; - } + std::string msg = message; // Remove the trailing \n that is passed along - LINFOC("SGCT", message.substr(0, message.size() - 1)); + switch (level) { + case Log::Level::Debug: + LDEBUGC("SGCT", msg.substr(0, msg.size() - 1)); + break; + case Log::Level::Info: + LINFOC("SGCT", msg.substr(0, msg.size() - 1)); + break; + case Log::Level::Warning: + LWARNINGC("SGCT", msg.substr(0, msg.size() - 1)); + break; + case Log::Level::Error: + LERRORC("SGCT", msg.substr(0, msg.size() - 1)); + break; } } // namespace @@ -884,57 +872,52 @@ void mainLogCallback(const char* msg) { void setSgctDelegateFunctions() { WindowDelegate& sgctDelegate = global::windowDelegate; - sgctDelegate.terminate = []() { sgct::Engine::instance()->terminate(); }; + sgctDelegate.terminate = []() { Engine::instance().terminate(); }; sgctDelegate.setBarrier = [](bool enabled) { ZoneScoped - sgct::SGCTWindow::setBarrier(enabled); + sgct::Window::setBarrier(enabled); }; sgctDelegate.setSynchronization = [](bool enabled) { ZoneScoped - sgct_core::ClusterManager::instance()->setUseIgnoreSync(enabled); + sgct::ClusterManager::instance().setUseIgnoreSync(enabled); }; sgctDelegate.clearAllWindows = [](const glm::vec4& clearColor) { ZoneScoped - size_t n = sgct::Engine::instance()->getNumberOfWindows(); - for (size_t i = 0; i < n; ++i) { + for (const std::unique_ptr& window : Engine::instance().windows()) { glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - GLFWwindow* w = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle(); - glfwSwapBuffers(w); + glfwSwapBuffers(window->windowHandle()); } }; sgctDelegate.windowHasResized = []() { ZoneScoped - return sgct::Engine::instance()->getCurrentWindowPtr()->isWindowResized(); + return currentWindow->isWindowResized(); }; sgctDelegate.averageDeltaTime = []() { ZoneScoped - return sgct::Engine::instance()->getAvgDt(); - }; - sgctDelegate.deltaTimeStandardDeviation = []() { - ZoneScoped - - return sgct::Engine::instance()->getDtStandardDeviation(); + return Engine::instance().statistics().avgDt( + Engine::instance().currentFrameNumber() + ); }; sgctDelegate.minDeltaTime = []() { ZoneScoped - return sgct::Engine::instance()->getMinDt(); + return Engine::instance().statistics().minDt(); }; sgctDelegate.maxDeltaTime = []() { ZoneScoped - return sgct::Engine::instance()->getMaxDt(); + return Engine::instance().statistics().maxDt(); }; sgctDelegate.deltaTime = []() { ZoneScoped - return sgct::Engine::instance()->getDt(); + return Engine::instance().statistics().dt(); }; sgctDelegate.applicationTime = []() { ZoneScoped @@ -944,18 +927,17 @@ void setSgctDelegateFunctions() { sgctDelegate.mousePosition = []() { ZoneScoped - int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); - double posX, posY; - sgct::Engine::getMousePos(id, &posX, &posY); - return glm::vec2(posX, posY); + double xPos; + double yPos; + glfwGetCursorPos(currentWindow->windowHandle(), &xPos, &yPos); + return glm::vec2(xPos, yPos); }; sgctDelegate.mouseButtons = [](int maxNumber) { ZoneScoped - int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); uint32_t result = 0; for (int i = 0; i < maxNumber; ++i) { - bool button = (sgct::Engine::getMouseButton(id, i) != 0); + bool button = (glfwGetMouseButton(currentWindow->windowHandle(), i) != 0); if (button) { result |= (1 << i); } @@ -965,59 +947,62 @@ void setSgctDelegateFunctions() { sgctDelegate.currentWindowSize = []() { ZoneScoped - return glm::ivec2( - sgct::Engine::instance()->getCurrentWindowPtr()->getXResolution(), - sgct::Engine::instance()->getCurrentWindowPtr()->getYResolution()); + return glm::ivec2(currentWindow->resolution().x, currentWindow->resolution().y); }; sgctDelegate.currentSubwindowSize = []() { ZoneScoped - auto window = sgct::Engine::instance()->getCurrentWindowPtr(); - if (sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfViewports() > 1) { - sgct_core::Viewport* viewport = - sgct::Engine::instance()->getCurrentWindowPtr()->getViewport(0); - return glm::ivec2(window->getXResolution()*viewport->getXSize(), window->getYResolution()*viewport->getYSize()); + if (currentWindow->viewports().size() > 1) { + const Viewport& viewport = *currentWindow->viewports().front(); + return glm::ivec2( + currentWindow->resolution().x * viewport.size().x, + currentWindow->resolution().y * viewport.size().y + ); } - switch (window->getStereoMode()) { - case sgct::SGCTWindow::Side_By_Side_Stereo: - case sgct::SGCTWindow::Side_By_Side_Inverted_Stereo: - return glm::ivec2(window->getXResolution() / 2, window->getYResolution()); - case sgct::SGCTWindow::Top_Bottom_Stereo: - case sgct::SGCTWindow::Top_Bottom_Inverted_Stereo: - return glm::ivec2(window->getXResolution(), window->getYResolution() / 2); + switch (currentWindow->stereoMode()) { + case Window::StereoMode::SideBySide: + case Window::StereoMode::SideBySideInverted: + return glm::ivec2( + currentWindow->resolution().x / 2, + currentWindow->resolution().y + ); + case Window::StereoMode::TopBottom: + case Window::StereoMode::TopBottomInverted: + return glm::ivec2( + currentWindow->resolution().x, + currentWindow->resolution().y / 2 + ); default: - return glm::ivec2(window->getXResolution(), window->getYResolution()); + return glm::ivec2( + currentWindow->resolution().x, + currentWindow->resolution().y + ); } }; sgctDelegate.currentWindowResolution = []() { ZoneScoped - int x, y; - auto window = sgct::Engine::instance()->getCurrentWindowPtr(); - window->getFinalFBODimensions(x, y); - return glm::ivec2(x, y); + ivec2 dim = currentWindow->finalFBODimensions(); + return glm::ivec2(dim.x, dim.y); }; sgctDelegate.currentDrawBufferResolution = []() { ZoneScoped - sgct_core::Viewport* viewport = - sgct::Engine::instance()->getCurrentWindowPtr()->getViewport(0); + Viewport* viewport = currentWindow->viewports().front().get(); if (viewport != nullptr) { - if (viewport->hasSubViewports() && viewport->getNonLinearProjectionPtr()) { - int res = viewport->getNonLinearProjectionPtr()->getCubemapResolution(); + if (viewport->hasSubViewports() && viewport->nonLinearProjection()) { + int res = viewport->nonLinearProjection()->cubemapResolution(); return glm::ivec2(res, res); } - else if (sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfViewports() > 1) { - int x, y; - auto window = sgct::Engine::instance()->getCurrentWindowPtr(); - window->getFinalFBODimensions(x, y); - return glm::ivec2(x*viewport->getXSize(), y*viewport->getYSize()); + else if (currentWindow->viewports().size() > 1) { + // @TODO (abock, 2020-04-09) This should probably be based on the current + // viewport? + ivec2 dim = currentWindow->finalFBODimensions(); + return glm::ivec2(dim.x * viewport->size().x, dim.y * viewport->size().y); } else { - int x, y; - auto window = sgct::Engine::instance()->getCurrentWindowPtr(); - window->getFinalFBODimensions(x, y); - return glm::ivec2(x, y); + ivec2 dim = currentWindow->finalFBODimensions(); + return glm::ivec2(dim.x, dim.y); } } return glm::ivec2(-1, -1); @@ -1025,35 +1010,28 @@ void setSgctDelegateFunctions() { sgctDelegate.currentViewportSize = []() { ZoneScoped - sgct_core::Viewport* viewport = - sgct::Engine::instance()->getCurrentWindowPtr()->getViewport(0); - if (viewport != nullptr) { - int x = 0; - int y = 0; - sgct::Engine::instance()->getCurrentViewportSize(x, y); - return glm::ivec2(x, y); + if (currentViewport != nullptr) { + vec2 size = currentViewport->size(); + return glm::ivec2(size.x, size.y); } return glm::ivec2(-1, -1); }; sgctDelegate.dpiScaling = []() { ZoneScoped - return glm::vec2( - sgct::Engine::instance()->getCurrentWindowPtr()->getXScale(), - sgct::Engine::instance()->getCurrentWindowPtr()->getYScale() - ); + vec2 scale = currentWindow->scale(); + return glm::vec2(scale.x, scale.y); }; sgctDelegate.currentNumberOfAaSamples = []() { ZoneScoped - return sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfAASamples(); + return currentWindow->numberOfAASamples(); }; sgctDelegate.hasGuiWindow = []() { ZoneScoped - auto engine = sgct::Engine::instance(); - for (size_t i = 0; i < engine->getNumberOfWindows(); ++i) { - if (engine->getWindowPtr(i)->checkIfTagExists("GUI")) { + for (const std::unique_ptr& window : Engine::instance().windows()) { + if (window->hasTag("GUI")) { return true; } } @@ -1062,77 +1040,76 @@ void setSgctDelegateFunctions() { sgctDelegate.isGuiWindow = []() { ZoneScoped - return sgct::Engine::instance()->getCurrentWindowPtr()->checkIfTagExists("GUI"); + return currentWindow->hasTag("GUI"); }; sgctDelegate.isMaster = []() { ZoneScoped - return sgct::Engine::instance()->isMaster(); + return Engine::instance().isMaster(); }; sgctDelegate.isUsingSwapGroups = []() { ZoneScoped - return sgct::SGCTWindow::isUsingSwapGroups(); + return Window::isUsingSwapGroups(); }; sgctDelegate.isSwapGroupMaster = []() { ZoneScoped - return sgct::SGCTWindow::isSwapGroupMaster(); + return Window::isSwapGroupMaster(); }; sgctDelegate.viewProjectionMatrix = []() { ZoneScoped - return sgct::Engine::instance()->getCurrentModelViewProjectionMatrix(); + return currentModelViewProjectionMatrix; }; sgctDelegate.modelMatrix = []() { ZoneScoped - return sgct::Engine::instance()->getModelMatrix(); + return currentModelMatrix; }; sgctDelegate.setNearFarClippingPlane = [](float nearPlane, float farPlane) { ZoneScoped - sgct::Engine::instance()->setNearAndFarClippingPlanes(nearPlane, farPlane); + Engine::instance().setNearAndFarClippingPlanes(nearPlane, farPlane); }; sgctDelegate.setEyeSeparationDistance = [](float distance) { ZoneScoped - sgct::Engine::instance()->setEyeSeparation(distance); + Engine::instance().setEyeSeparation(distance); }; - sgctDelegate.viewportPixelCoordinates = []() { - ZoneScoped + //sgctDelegate.viewportPixelCoordinates = []() { + // ZoneScoped - sgct::SGCTWindow* window = sgct::Engine::instance()->getCurrentWindowPtr(); - if (!window || !window->getCurrentViewport()) { - return glm::ivec4(0); - } - else { - const int* data = sgct::Engine::instance()->getCurrentViewportPixelCoords(); - return glm::ivec4(data[0], data[2], data[1], data[3]); - } - }; - sgctDelegate.sendMessageToExternalControl = [](const std::vector& message) { - ZoneScoped + // if (!currentWindow|| !currentViewport) { + // return glm::ivec4(0); + // } + // else { + // const int* data = cur sgct::Engine::instance()->getCurrentViewportPixelCoords(); + // return glm::ivec4(data[0], data[2], data[1], data[3]); + // } + //}; + //sgctDelegate.sendMessageToExternalControl = [](const std::vector& message) { + // ZoneScoped - sgct::Engine::instance()->sendMessageToExternalControl( - message.data(), - static_cast(message.size()) - ); - }; + // + // sgct::Engine::instance()->sendMessageToExternalControl( + // message.data(), + // static_cast(message.size()) + // ); + //}; sgctDelegate.isFisheyeRendering = []() { ZoneScoped - sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr(); - return dynamic_cast( - w->getViewport(0)->getNonLinearProjectionPtr() + return dynamic_cast( + currentWindow->viewports().front()->nonLinearProjection() ) != nullptr; }; sgctDelegate.takeScreenshot = [](bool applyWarping) { ZoneScoped - sgct::SGCTSettings::instance()->setCaptureFromBackBuffer(applyWarping); - sgct::Engine::instance()->takeScreenshot(); - return sgct::Engine::instance()->getScreenShotNumber(); + Settings::instance().setCaptureFromBackBuffer(applyWarping); + Engine::instance().takeScreenshot(); + return Engine::instance().screenShotNumber(); }; sgctDelegate.swapBuffer = []() { ZoneScoped @@ -1144,12 +1121,12 @@ void setSgctDelegateFunctions() { sgctDelegate.nWindows = []() { ZoneScoped - return static_cast(sgct::Engine::instance()->getNumberOfWindows()); + return static_cast(Engine::instance().windows().size()); }; sgctDelegate.currentWindowId = []() { ZoneScoped - return sgct::Engine::instance()->getCurrentWindowPtr()->getId(); + return currentWindow->id(); }; sgctDelegate.openGLProcedureAddress = [](const char* func) { ZoneScoped @@ -1160,23 +1137,22 @@ void setSgctDelegateFunctions() { ZoneScoped return static_cast( - sgct::Engine::instance()->getWindowPtr(0)->getHorizFieldOfViewDegrees() + Engine::instance().windows().front()->horizFieldOfViewDegrees() ); }; sgctDelegate.setHorizFieldOfView = [](float hFovDeg) { ZoneScoped - sgct::SGCTWindow* w = sgct::Engine::instance()->getWindowPtr(0); - w->setHorizFieldOfView(hFovDeg); + Engine::instance().windows().front()->setHorizFieldOfView(hFovDeg); }; #ifdef WIN32 sgctDelegate.getNativeWindowHandle = [](size_t windowIndex) -> void* { ZoneScoped - sgct::SGCTWindow* w = sgct::Engine::instance()->getWindowPtr(windowIndex); + Window* w = Engine::instance().windows()[windowIndex].get(); if (w) { - HWND hWnd = glfwGetWin32Window(w->getWindowHandle()); - return reinterpret_cast(hWnd); + HWND hWnd = glfwGetWin32Window(w->windowHandle()); + return reinterpret_cast(hWnd); } return nullptr; }; @@ -1184,19 +1160,17 @@ void setSgctDelegateFunctions() { sgctDelegate.frustumMode = []() { ZoneScoped - using FM = sgct_core::Frustum::FrustumMode; - switch (sgct::Engine::instance()->getCurrentFrustumMode()) { - case FM::MonoEye: return WindowDelegate::Frustum::Mono; - case FM::StereoLeftEye: return WindowDelegate::Frustum::LeftEye; - case FM::StereoRightEye: return WindowDelegate::Frustum::RightEye; + switch (currentFrustumMode) { + default: + case Frustum::Mode::MonoEye: return WindowDelegate::Frustum::Mono; + case Frustum::Mode::StereoLeftEye: return WindowDelegate::Frustum::LeftEye; + case Frustum::Mode::StereoRightEye: return WindowDelegate::Frustum::RightEye; } }; - sgctDelegate.swapGroupFrameNumber = []() { + sgctDelegate.swapGroupFrameNumber = []() -> uint64_t { ZoneScoped - unsigned int fn = 0; - sgct::Engine::instance()->getCurrentWindowPtr()->getSwapGroupFrameNumber(fn); - return static_cast(fn); + return currentWindow->swapGroupFrameNumber(); }; } @@ -1366,59 +1340,45 @@ int main(int argc, char** argv) { arguments.insert(arguments.begin() + 2, absPath(windowConfiguration)); // Need to set this before the creation of the sgct::Engine - sgct::MessageHandler::instance()->setLogToConsole(false); - sgct::MessageHandler::instance()->setShowTime(false); - sgct::MessageHandler::instance()->setLogToCallback(true); - sgct::MessageHandler::instance()->setLogCallback(mainLogCallback); + + Log::instance().setLogToConsole(false); + Log::instance().setShowTime(false); + Log::instance().setLogCallback(mainLogCallback); #ifdef __APPLE__ glfwWindowHint(GLFW_STENCIL_BITS, 8); #endif LDEBUG("Creating SGCT Engine"); - SgctEngine = new sgct::Engine(arguments); + std::vector arg(argv + 1, argv + argc); + Configuration config = parseArguments(arg); + config::Cluster cluster = loadCluster(windowConfiguration); - // Bind functions - SgctEngine->setContextCreationCallback(mainContextCreationFunc); - SgctEngine->setInitOGLFunction(mainInitFunc); - SgctEngine->setPreSyncFunction(mainPreSyncFunc); - SgctEngine->setPostSyncPreDrawFunction(mainPostSyncPreDrawFunc); - SgctEngine->setDrawFunction(mainRenderFunc); - SgctEngine->setDraw2DFunction(mainDraw2DFunc); - SgctEngine->setPostDrawFunction(mainPostDrawFunc); - SgctEngine->setKeyboardCallbackFunction(mainKeyboardCallback); - SgctEngine->setMouseButtonCallbackFunction(mainMouseButtonCallback); - SgctEngine->setMousePosCallbackFunction(mainMousePosCallback); - SgctEngine->setMouseScrollCallbackFunction(mainMouseScrollCallback); - SgctEngine->setCharCallbackFunction(mainCharCallback); + Engine::Callbacks callbacks; + callbacks.initOpenGL = mainInitFunc; + callbacks.preSync = mainPreSyncFunc; + callbacks.postSyncPreDraw = mainPostSyncPreDrawFunc; + callbacks.draw = mainRenderFunc; + callbacks.draw2D = mainDraw2DFunc; + callbacks.postDraw = mainPostDrawFunc; + callbacks.keyboard = mainKeyboardCallback; + callbacks.mouseButton = mainMouseButtonCallback; + callbacks.mousePos = mainMousePosCallback; + callbacks.mouseScroll = mainMouseScrollCallback; + callbacks.character = mainCharCallback; + callbacks.encode = mainEncodeFun; + callbacks.decode = mainDecodeFun; + Log::instance().setNotifyLevel(Log::Level::Debug); - // Disable the immediate exit of the application when the ESC key is pressed - SgctEngine->setExitKey(SGCT_KEY_UNKNOWN); - - sgct::MessageHandler::instance()->setNotifyLevel(sgct::MessageHandler::NOTIFY_ALL); - - // Set encode and decode functions - // NOTE: starts synchronizing before init functions - sgct::SharedData::instance()->setEncodeFunction(mainEncodeFun); - sgct::SharedData::instance()->setDecodeFunction(mainDecodeFun); - - // Try to open a window - LDEBUG("Initialize SGCT Engine"); - std::map, sgct::Engine::RunMode> versionMapping = { - { { 3, 3 }, sgct::Engine::RunMode::OpenGL_3_3_Core_Profile }, - { { 4, 0 }, sgct::Engine::RunMode::OpenGL_4_0_Core_Profile }, - { { 4, 1 }, sgct::Engine::RunMode::OpenGL_4_1_Core_Profile }, - { { 4, 2 }, sgct::Engine::RunMode::OpenGL_4_2_Core_Profile }, - { { 4, 3 }, sgct::Engine::RunMode::OpenGL_4_3_Core_Profile }, - { { 4, 4 }, sgct::Engine::RunMode::OpenGL_4_4_Core_Profile }, - { { 4, 5 }, sgct::Engine::RunMode::OpenGL_4_5_Core_Profile }, - { { 4, 6 }, sgct::Engine::RunMode::OpenGL_4_6_Core_Profile } - }; - - - std::pair version = supportedOpenGLVersion(); - LINFO(fmt::format("Detected OpenGL version: {}.{}", version.first, version.second)); - bool initSuccess = SgctEngine->init(versionMapping[version]); + try { + Engine::create(cluster, callbacks, config); + } + catch (...) { + Engine::destroy(); + global::openSpaceEngine.deinitialize(); + ghoul::deinitialize(); + throw; + } #ifdef __APPLE__ // Workaround for OpenGL bug that Apple introduced in 10.14 Mojave that prevents an @@ -1431,9 +1391,8 @@ int main(int argc, char** argv) { // machine. If the loading screen shows up without doing anything to the window, it // is fixed. With the bug, the rendering stays gray even well after the main render // loop has started -- 2018-10-28 abock - size_t n = sgct::Engine::instance()->getNumberOfWindows(); - for (size_t i = 0; i < n; ++i) { - GLFWwindow* w = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle(); + for (const std::unique_ptr& window : Engine::instance().windows()) { + GLFWwindow* w = window->windowHandle(); int x, y; glfwGetWindowPos(w, &x, &y); glfwSetWindowPos(w, x + 1, y + 1); @@ -1448,53 +1407,39 @@ int main(int argc, char** argv) { // Do not print message if slaves are waiting for the master // Only timeout after 15 minutes - SgctEngine->setSyncParameters(false, 15.f * 60.f); + Engine::instance().setSyncParameters(false, 15.f * 60.f); - auto cleanup = [&](bool isInitialized) { - if (isInitialized) { - global::openSpaceEngine.deinitializeGL(); - global::openSpaceEngine.deinitialize(); - } + LINFO("Starting rendering loop"); + Engine::instance().render(); + LINFO("Ending rendering loop"); - // Clear function bindings to avoid crash after destroying the OpenSpace Engine - sgct::MessageHandler::instance()->setLogToCallback(false); - sgct::MessageHandler::instance()->setLogCallback(nullptr); + global::openSpaceEngine.deinitializeGL(); + global::openSpaceEngine.deinitialize(); - LDEBUG("Destroying SGCT Engine"); - delete SgctEngine; + // Clear function bindings to avoid crash after destroying the OpenSpace Engine + Log::instance().setLogCallback(nullptr); + + LDEBUG("Destroying SGCT Engine"); + Engine::destroy(); #ifdef OPENVR_SUPPORT - // Clean up OpenVR - sgct::SGCTOpenVR::shutdown(); + // Clean up OpenVR + sgct::SGCTOpenVR::shutdown(); #endif #ifdef OPENSPACE_HAS_SPOUT - for (SpoutWindow& w : SpoutWindows) { - if (w.leftOrMain.handle) { - w.leftOrMain.handle->ReleaseReceiver(); - w.leftOrMain.handle->Release(); - } - if (w.right.handle) { - w.right.handle->ReleaseReceiver(); - w.right.handle->Release(); - } + for (SpoutWindow& w : SpoutWindows) { + if (w.leftOrMain.handle) { + w.leftOrMain.handle->ReleaseReceiver(); + w.leftOrMain.handle->Release(); } + if (w.right.handle) { + w.right.handle->ReleaseReceiver(); + w.right.handle->Release(); + } + } #endif // OPENSPACE_HAS_SPOUT - ghoul::deinitialize(); - }; - - if (!initSuccess) { - LFATAL("Initializing failed"); - cleanup(false); - return EXIT_FAILURE; - } - - LINFO("Starting rendering loop"); - SgctEngine->render(); - LINFO("Ending rendering loop"); - - cleanup(true); - + ghoul::deinitialize(); exit(EXIT_SUCCESS); } diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 539530cad0..2e076e82c4 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -84,8 +84,8 @@ public: void touchDetectionCallback(TouchInput input); void touchUpdateCallback(TouchInput input); void touchExitCallback(TouchInput input); - std::vector encode(); - void decode(std::vector data); + std::vector encode(); + void decode(std::vector data); void scheduleLoadSingleAsset(std::string assetPath); void toggleShutdownMode(); diff --git a/include/openspace/engine/syncengine.h b/include/openspace/engine/syncengine.h index 5b5b4f2d89..67902b34ee 100644 --- a/include/openspace/engine/syncengine.h +++ b/include/openspace/engine/syncengine.h @@ -53,13 +53,13 @@ public: * Encodes all added Syncables in the injected SyncBuffer. * This method is only called on the SGCT master node */ - std::vector encodeSyncables(); + std::vector encodeSyncables(); /** * Decodes the SyncBuffer into the added Syncables. * This method is only called on the SGCT slave nodes */ - void decodeSyncables(std::vector data); + void decodeSyncables(std::vector data); /** * Invokes the presync method of all added Syncables diff --git a/include/openspace/engine/windowdelegate.h b/include/openspace/engine/windowdelegate.h index 1bef12d181..c2a776dd4b 100644 --- a/include/openspace/engine/windowdelegate.h +++ b/include/openspace/engine/windowdelegate.h @@ -94,11 +94,6 @@ struct WindowDelegate { void (*setEyeSeparationDistance)(float distance) = [](float) {}; - glm::ivec4 (*viewportPixelCoordinates)() = []() { return glm::ivec4(0, 0, 0, 0); }; - - void (*sendMessageToExternalControl)(const std::vector& message) = - [](const std::vector&) {}; - bool (*isFisheyeRendering)() = []() { return false; }; unsigned int(*takeScreenshot)(bool applyWarping) = [](bool) { return 0u; }; diff --git a/include/openspace/util/syncbuffer.h b/include/openspace/util/syncbuffer.h index 4f2a7ed370..c73d05270c 100644 --- a/include/openspace/util/syncbuffer.h +++ b/include/openspace/util/syncbuffer.h @@ -57,14 +57,14 @@ public: //void write(); //void read(); - void setData(std::vector data); - std::vector data(); + void setData(std::vector data); + std::vector data(); private: size_t _n; size_t _encodeOffset = 0; size_t _decodeOffset = 0; - std::vector _dataStream; + std::vector _dataStream; }; } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 2ed17ecb9a..e782b56c8d 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -673,9 +673,9 @@ void OpenSpaceEngine::initializeGL() { global::moduleEngine.initializeGL(); + for (const std::function& func : global::callback::initializeGL) { ZoneScopedN("[Module] initializeGL") - func(); } @@ -1452,14 +1452,14 @@ void OpenSpaceEngine::touchExitCallback(TouchInput input) { } -std::vector OpenSpaceEngine::encode() { +std::vector OpenSpaceEngine::encode() { ZoneScoped - std::vector buffer = global::syncEngine.encodeSyncables(); + std::vector buffer = global::syncEngine.encodeSyncables(); return buffer; } -void OpenSpaceEngine::decode(std::vector data) { +void OpenSpaceEngine::decode(std::vector data) { ZoneScoped global::syncEngine.decodeSyncables(std::move(data)); diff --git a/src/engine/syncengine.cpp b/src/engine/syncengine.cpp index f3f341ce74..c2dca81352 100644 --- a/src/engine/syncengine.cpp +++ b/src/engine/syncengine.cpp @@ -38,18 +38,18 @@ SyncEngine::SyncEngine(unsigned int syncBufferSize) } // Should be called on sgct master -std::vector SyncEngine::encodeSyncables() { +std::vector SyncEngine::encodeSyncables() { for (Syncable* syncable : _syncables) { syncable->encode(&_syncBuffer); } - std::vector data = _syncBuffer.data(); + std::vector data = _syncBuffer.data(); _syncBuffer.reset(); return data; } // Should be called on sgct slaves -void SyncEngine::decodeSyncables(std::vector data) { +void SyncEngine::decodeSyncables(std::vector data) { _syncBuffer.setData(std::move(data)); for (Syncable* syncable : _syncables) { syncable->decode(&_syncBuffer); diff --git a/src/util/syncbuffer.cpp b/src/util/syncbuffer.cpp index f52cfa42dc..3869532a4e 100644 --- a/src/util/syncbuffer.cpp +++ b/src/util/syncbuffer.cpp @@ -78,11 +78,11 @@ void SyncBuffer::decode(std::string& s) { s = decode(); } -void SyncBuffer::setData(std::vector data) { +void SyncBuffer::setData(std::vector data) { _dataStream = std::move(data); } -std::vector SyncBuffer::data() { +std::vector SyncBuffer::data() { _dataStream.resize(_encodeOffset); return _dataStream; From eedd0f75e0f1b1d8a89a95c582b2f5c73b3377c0 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 13 Apr 2020 10:40:31 +0200 Subject: [PATCH 2/4] Compile fix --- apps/OpenSpace/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 87cb5d9b5c..de0052caf4 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -162,6 +162,7 @@ std::vector SpoutWindows; #endif // OPENSPACE_HAS_SPOUT +} // // MiniDump generation From 606fa74817f382e6926e74dcf2868452ad25b8db Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 14 Apr 2020 10:47:59 +0200 Subject: [PATCH 3/4] Adapt configuration files and fix old SGCT style in them --- apps/OpenSpace/ext/sgct | 2 +- config/fullscreen1080.xml | 42 +++++++-------- config/gui_projector.xml | 60 ++++++++++----------- config/openvr_htcVive.xml | 40 +++++++------- config/openvr_oculusRiftCv1.xml | 40 +++++++------- config/single.xml | 42 +++++++-------- config/single_fisheye.xml | 66 +++++++++++------------ config/single_fisheye_gui.xml | 94 ++++++++++++++++----------------- config/single_gui.xml | 60 ++++++++++----------- config/single_sbs_stereo.xml | 56 ++++++++++---------- config/single_two_win.xml | 58 ++++++++++---------- config/spherical_mirror.xml | 64 +++++++++++----------- config/spherical_mirror_gui.xml | 4 +- config/spout_output.xml | 42 ++++++--------- config/two_nodes.xml | 71 ++++++++++++------------- ext/ghoul | 2 +- 16 files changed, 364 insertions(+), 379 deletions(-) diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 19799abace..addec5d680 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 19799abace7513623902fa5e43158b6f6a565434 +Subproject commit addec5d6804ab8df8940f5dc3b3bf81b35216ee5 diff --git a/config/fullscreen1080.xml b/config/fullscreen1080.xml index 35506aeb09..3b7f94c4cc 100644 --- a/config/fullscreen1080.xml +++ b/config/fullscreen1080.xml @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/config/gui_projector.xml b/config/gui_projector.xml index 42c3971235..9f50aa7037 100644 --- a/config/gui_projector.xml +++ b/config/gui_projector.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/openvr_htcVive.xml b/config/openvr_htcVive.xml index ee6ea4df20..c5ab46597a 100644 --- a/config/openvr_htcVive.xml +++ b/config/openvr_htcVive.xml @@ -1,23 +1,23 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/config/openvr_oculusRiftCv1.xml b/config/openvr_oculusRiftCv1.xml index 9db0689cbc..665715fb53 100644 --- a/config/openvr_oculusRiftCv1.xml +++ b/config/openvr_oculusRiftCv1.xml @@ -1,23 +1,23 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/config/single.xml b/config/single.xml index a434c31d0b..6ec2d5a125 100644 --- a/config/single.xml +++ b/config/single.xml @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/config/single_fisheye.xml b/config/single_fisheye.xml index 8a03730f5e..e27230e520 100644 --- a/config/single_fisheye.xml +++ b/config/single_fisheye.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - - - - + + + + --> + + + + + + + + + + + + + + + + + + + diff --git a/config/single_fisheye_gui.xml b/config/single_fisheye_gui.xml index b4a201f4c6..6eb46bbabb 100644 --- a/config/single_fisheye_gui.xml +++ b/config/single_fisheye_gui.xml @@ -1,53 +1,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + --> + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + diff --git a/config/single_gui.xml b/config/single_gui.xml index 6c200087d5..3404e572e3 100644 --- a/config/single_gui.xml +++ b/config/single_gui.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/single_sbs_stereo.xml b/config/single_sbs_stereo.xml index 87ee3a33ec..595d92cafb 100644 --- a/config/single_sbs_stereo.xml +++ b/config/single_sbs_stereo.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/single_two_win.xml b/config/single_two_win.xml index ae110d2148..ed1b09fc04 100644 --- a/config/single_two_win.xml +++ b/config/single_two_win.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/spherical_mirror.xml b/config/spherical_mirror.xml index 2243582544..fc98729758 100644 --- a/config/spherical_mirror.xml +++ b/config/spherical_mirror.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/spherical_mirror_gui.xml b/config/spherical_mirror_gui.xml index 14a48ad2e2..c946cbecd2 100644 --- a/config/spherical_mirror_gui.xml +++ b/config/spherical_mirror_gui.xml @@ -1,6 +1,6 @@ - + @@ -27,7 +27,7 @@ - + diff --git a/config/spout_output.xml b/config/spout_output.xml index f40a169c32..bac296112f 100644 --- a/config/spout_output.xml +++ b/config/spout_output.xml @@ -1,29 +1,19 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/config/two_nodes.xml b/config/two_nodes.xml index 5feb265138..e47946d5ef 100644 --- a/config/two_nodes.xml +++ b/config/two_nodes.xml @@ -1,41 +1,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - diff --git a/ext/ghoul b/ext/ghoul index 0461bf1f44..11878e0dc0 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 0461bf1f44b58e04fb21d929b0f385e1120da7b4 +Subproject commit 11878e0dc08e43ecf4bcf158a6ccc00c6160d3a5 From 9ea5c0d66fe87c4ab602ff36db51be5dec219605 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 24 Apr 2020 11:07:18 +0200 Subject: [PATCH 4/4] Update SGCT repository --- apps/OpenSpace/CMakeLists.txt | 1 + apps/OpenSpace/ext/sgct | 2 +- ext/ghoul | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/OpenSpace/CMakeLists.txt b/apps/OpenSpace/CMakeLists.txt index 12d4c5bd98..1d2ad1b9b9 100644 --- a/apps/OpenSpace/CMakeLists.txt +++ b/apps/OpenSpace/CMakeLists.txt @@ -111,6 +111,7 @@ target_compile_definitions(OpenSpace PRIVATE begin_header("Dependency: SGCT") set(SGCT_TEXT OFF CACHE BOOL "" FORCE) +set(SGCT_DEP_INCLUDE_FREETYPE OFF CACHE BOOL "" FORCE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ext/sgct) target_include_directories(OpenSpace SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/ext/sgct/include) diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index addec5d680..72536d99b2 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit addec5d6804ab8df8940f5dc3b3bf81b35216ee5 +Subproject commit 72536d99b2bc463aeeec21c710cf8fd1b7a0a997 diff --git a/ext/ghoul b/ext/ghoul index 11878e0dc0..df1522a1fe 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 11878e0dc08e43ecf4bcf158a6ccc00c6160d3a5 +Subproject commit df1522a1fe6f02b4d03cd36478d9d36f4384e93e