From 542f92e7688da728cbc4e62129584db3568d5c6c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 18 Oct 2016 18:52:30 +0200 Subject: [PATCH] Add a fix to the window resolution for Retina displays Add a new setting to the ConfigurationManager that can specify whether to scale the onscreen text by window size or resolution --- .../openspace/engine/configurationmanager.h | 3 ++ include/openspace/rendering/renderengine.h | 3 ++ src/engine/configurationmanager.cpp | 2 + src/engine/configurationmanager_doc.inl | 12 ++++++ src/engine/openspaceengine.cpp | 5 ++- src/engine/wrapper/sgctwindowwrapper.cpp | 10 ++++- src/interaction/luaconsole.cpp | 3 +- src/rendering/renderengine.cpp | 39 +++++++++++++++---- 8 files changed, 66 insertions(+), 11 deletions(-) diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index b826094735..3f57aa59d9 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -97,6 +97,9 @@ public: /// The key that stores the time (in seconds) that the application will wait before /// shutting down after the shutdown call is made static const std::string KeyShutdownCountdown; + /// The key that stores whether the onscreen text should be scaled to the window size + /// or the window resolution + static const std::string KeyOnScreenTextScaling; /// The key that stores whether the master node should perform rendering just function /// as a pure manager static const std::string KeyDisableMasterRendering; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 26fa01089c..c8c5b2b5fb 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -190,6 +190,9 @@ public: void sortScreenspaceRenderables(); + glm::ivec2 renderingResolution() const; + glm::ivec2 fontResolution() const; + // This is temporary until a proper screenspace solution is found ---abock struct OnScreenInformation{ glm::vec2 _position; diff --git a/src/engine/configurationmanager.cpp b/src/engine/configurationmanager.cpp index 881a8dfcb2..2e326d520c 100644 --- a/src/engine/configurationmanager.cpp +++ b/src/engine/configurationmanager.cpp @@ -72,6 +72,8 @@ const string ConfigurationManager::KeyDisableMasterRendering = "DisableRendering const string ConfigurationManager::KeyDownloadRequestURL = "DownloadRequestURL"; const string ConfigurationManager::KeyRenderingMethod = "RenderingMethod"; +const string ConfigurationManager::KeyOnScreenTextScaling = "OnScreenTextScaling"; + const string ConfigurationManager::KeyHttpProxy = "HttpProxy"; const string ConfigurationManager::PartHttpProxyAddress = "Address"; const string ConfigurationManager::PartHttpProxyPort = "Port"; diff --git a/src/engine/configurationmanager_doc.inl b/src/engine/configurationmanager_doc.inl index f260d37f79..3f1b33c058 100644 --- a/src/engine/configurationmanager_doc.inl +++ b/src/engine/configurationmanager_doc.inl @@ -295,6 +295,18 @@ Documentation ConfigurationManager::Documentation() { "shutdown is aborted.", Optional::Yes }, + { + ConfigurationManager::KeyOnScreenTextScaling, + new StringInListVerifier({ + // Values from RenderEngine:updateRenderer + "window", "framebuffer" + }), + "The method for scaling the onscreen text in the window. As the resolution " + "of the rendering can be different from the size of the window, the onscreen " + "text can either be scaled according to the window size (\"window\"), or the " + "rendering resolution (\"framebuffer\"). This value defaults to \"window\".", + Optional::Yes + }, { ConfigurationManager::KeyDownloadRequestURL, new OrVerifier( diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 4883b1cd36..8d2e35b724 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -744,7 +744,7 @@ void OpenSpaceEngine::loadFonts() { LERROR("Error initializing default font renderer"); ghoul::fontrendering::FontRenderer::defaultRenderer().setFramebufferSize( - glm::vec2(_windowWrapper->currentWindowSize()) + _renderEngine->fontResolution() ); } @@ -898,6 +898,9 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { glm::ivec2 windowSize = _windowWrapper->currentWindowSize(); uint32_t mouseButtons = _windowWrapper->mouseButtons(2); + LINFO("Size" + std::to_string(windowSize)); + LINFO("Res " + std::to_string(_windowWrapper->currentWindowResolution())); + //glm::vec2 windowBufferCorrectionFactor = glm::vec2( // static_cast(drawBufferResolution.x) / static_cast(windowSize.x), // static_cast(drawBufferResolution.y) / static_cast(windowSize.y) diff --git a/src/engine/wrapper/sgctwindowwrapper.cpp b/src/engine/wrapper/sgctwindowwrapper.cpp index c6a2f8a9cd..965ff9b184 100644 --- a/src/engine/wrapper/sgctwindowwrapper.cpp +++ b/src/engine/wrapper/sgctwindowwrapper.cpp @@ -90,12 +90,20 @@ uint32_t SGCTWindowWrapper::mouseButtons(int maxNumber) const { } glm::ivec2 SGCTWindowWrapper::currentWindowSize() const { + //return glm::ivec2(sgct::Engine::instance()->getCurrentWindowPtr()->getXResolution(), + // sgct::Engine::instance()->getCurrentWindowPtr()->getYResolution()); + return glm::ivec2(sgct::Engine::instance()->getCurrentWindowPtr()->getXResolution(), sgct::Engine::instance()->getCurrentWindowPtr()->getYResolution()); } glm::ivec2 SGCTWindowWrapper::currentWindowResolution() const { - int x,y; + //int width, height; + //auto window = sgct::Engine::instance()->getCurrentWindowPtr()->getWindowHandle(); + //glfwGetFramebufferSize(window, &width, &height); + //return glm::ivec2(width, height); + + int x, y; sgct::Engine::instance()->getCurrentWindowPtr()->getFinalFBODimensions(x, y); return glm::ivec2(x, y); } diff --git a/src/interaction/luaconsole.cpp b/src/interaction/luaconsole.cpp index 9cf06207b7..2a5b8847b3 100644 --- a/src/interaction/luaconsole.cpp +++ b/src/interaction/luaconsole.cpp @@ -315,7 +315,8 @@ void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) { void LuaConsole::render() { const float font_size = 10.0f; - int ySize = OsEng.windowWrapper().currentWindowSize().y; + int ySize = OsEng.renderEngine().fontResolution().y; + //int ySize = OsEng.windowWrapper().currentWindowSize().y; //int ySize = OsEng.windowWrapper().viewportPixelCoordinates().w; float startY = static_cast(ySize) - 2.0f * font_size; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 8ca2af7cd7..04667c4372 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -370,11 +370,10 @@ void RenderEngine::updateRenderer() { bool windowResized = OsEng.windowWrapper().windowHasResized(); if (windowResized) { - glm::ivec2 res = OsEng.windowWrapper().currentWindowSize(); - //glm::ivec2 res = OsEng.windowWrapper().currentDrawBufferResolution(); - _renderer->setResolution(res); + _renderer->setResolution(renderingResolution()); + ghoul::fontrendering::FontRenderer::defaultRenderer().setFramebufferSize( - glm::vec2(res) + fontResolution() ); } @@ -387,6 +386,31 @@ void RenderEngine::updateScreenSpaceRenderables() { } } +glm::ivec2 RenderEngine::renderingResolution() const { + if (OsEng.windowWrapper().isRegularRendering()) { + return OsEng.windowWrapper().currentWindowResolution(); + } + else { + return OsEng.windowWrapper().currentDrawBufferResolution(); + } +} + +glm::ivec2 RenderEngine::fontResolution() const { + std::string value; + bool hasValue = OsEng.configurationManager().getValue( + ConfigurationManager::KeyOnScreenTextScaling, + value + ); + if (hasValue && value == "framebuffer") { + return OsEng.windowWrapper().currentWindowResolution(); + } + else { + // The default is to use the window size + return OsEng.windowWrapper().currentWindowSize(); + } +} + + void RenderEngine::updateFade() { //temporary fade funtionality float fadedIn = 1.0; @@ -686,14 +710,12 @@ void RenderEngine::postRaycast(ghoul::opengl::ProgramObject& programObject) { * Set renderer */ void RenderEngine::setRenderer(std::unique_ptr renderer) { - glm::ivec2 res = OsEng.windowWrapper().currentDrawBufferResolution(); - if (_renderer) { _renderer->deinitialize(); } _renderer = std::move(renderer); - _renderer->setResolution(res); + _renderer->setResolution(renderingResolution()); _renderer->setNAaSamples(_nAaSamples); _renderer->initialize(); _renderer->setCamera(_mainCamera); @@ -1279,7 +1301,8 @@ void RenderEngine::renderInformation() { if (_fontDate) { glm::vec2 penPosition = glm::vec2( 10.f, - OsEng.windowWrapper().viewportPixelCoordinates().w + fontResolution().y + //OsEng.windowWrapper().viewportPixelCoordinates().w ); penPosition.y -= _fontDate->height();