From 8e0fde947d83fe069cfc9e7eac3ccd6d3d077b16 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 26 Nov 2017 14:46:54 -0500 Subject: [PATCH 1/3] Cleanup ScreenSpaceFramebuffer (fix orientation issue) Add Dashboard for on-screen information (#closes 201) --- include/openspace/rendering/renderengine.h | 6 +- modules/base/CMakeLists.txt | 2 + modules/base/basemodule.cpp | 3 + .../base/rendering/screenspacedashboard.cpp | 179 ++++++++++++++++++ modules/base/rendering/screenspacedashboard.h | 61 ++++++ .../base/rendering/screenspaceframebuffer.cpp | 29 ++- .../base/rendering/screenspaceframebuffer.h | 14 +- modules/imgui/src/gui.cpp | 12 +- modules/iswa/util/iswamanager_lua.inl | 2 +- openspace.cfg | 4 +- src/rendering/renderengine.cpp | 27 ++- src/rendering/renderengine_lua.inl | 12 +- src/rendering/screenspacerenderable.cpp | 2 +- 13 files changed, 307 insertions(+), 46 deletions(-) create mode 100644 modules/base/rendering/screenspacedashboard.cpp create mode 100644 modules/base/rendering/screenspacedashboard.h diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 7f40d43068..a1410cecfd 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -107,9 +107,9 @@ public: float globalBlackOutFactor(); void setGlobalBlackOutFactor(float factor); - void registerScreenSpaceRenderable(std::shared_ptr s); - void unregisterScreenSpaceRenderable(std::shared_ptr s); - void unregisterScreenSpaceRenderable(const std::string& name); + void addScreenSpaceRenderable(std::shared_ptr s); + void removeScreenSpaceRenderable(std::shared_ptr s); + void removeScreenSpaceRenderable(const std::string& name); std::shared_ptr screenSpaceRenderable(const std::string& name); std::vector screenSpaceRenderables() const; diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 5d49dc687f..dd6592ce96 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -34,6 +34,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrail.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrailorbit.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrailtrajectory.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacedashboard.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimagelocal.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimageonline.h @@ -57,6 +58,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrail.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrailorbit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrailtrajectory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacedashboard.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimagelocal.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimageonline.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index c228629622..1b5b75c9f4 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,7 @@ void BaseModule::internalInitialize() { auto fSsRenderable = FactoryManager::ref().factory(); ghoul_assert(fSsRenderable, "ScreenSpaceRenderable factory was not created"); + fSsRenderable->registerClass("ScreenSpaceDashboard"); fSsRenderable->registerClass("ScreenSpaceImageLocal"); fSsRenderable->registerClass("ScreenSpaceImageOnline"); fSsRenderable->registerClass("ScreenSpaceFramebuffer"); @@ -117,6 +119,7 @@ std::vector BaseModule::documentations() const { RenderableSphere::Documentation(), RenderableTrailOrbit::Documentation(), RenderableTrailTrajectory::Documentation(), + ScreenSpaceDashboard::Documentation(), ScreenSpaceFramebuffer::Documentation(), ScreenSpaceImageLocal::Documentation(), ScreenSpaceImageOnline::Documentation(), diff --git a/modules/base/rendering/screenspacedashboard.cpp b/modules/base/rendering/screenspacedashboard.cpp new file mode 100644 index 0000000000..c85f148c27 --- /dev/null +++ b/modules/base/rendering/screenspacedashboard.cpp @@ -0,0 +1,179 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include > +#include +#include + +#include +#include + +namespace { + const char* KeyName = "Name"; + const char* KeyFontMono = "Mono"; + +} // namespace + +namespace openspace { + +documentation::Documentation ScreenSpaceDashboard::Documentation() { + using namespace openspace::documentation; + return { + "ScreenSpace Dashboard", + "base_screenspace_dashboard", + { + { + KeyName, + new StringVerifier, + Optional::Yes, + "Specifies the GUI name of the ScreenSpaceDashboard" + } + } + }; +} + +ScreenSpaceDashboard::ScreenSpaceDashboard(const ghoul::Dictionary& dictionary) + : ScreenSpaceFramebuffer(dictionary) + , _fontRenderer(nullptr) + , _fontDate(nullptr) + , _fontInfo(nullptr) +{ + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "ScreenSpaceDashboard" + ); + + if (dictionary.hasKey(KeyName)) { + setName(dictionary.value(KeyName)); + } + else { + static int id = 0; + if (id == 0) { + setName("ScreenSpaceDashboard"); + } + else { + setName("ScreenSpaceDashboard" + std::to_string(id)); + } + ++id; + } + + _scale = 1.f; + _scale.setMaxValue(15.f); + + _size.onChange([this]() { + _fontRenderer->setFramebufferSize({ _size.value().z, _size.value().w }); + }); +} + +ScreenSpaceDashboard::~ScreenSpaceDashboard() {} + +bool ScreenSpaceDashboard::initializeGL() { + ScreenSpaceFramebuffer::initializeGL(); + + _fontRenderer = ghoul::fontrendering::FontRenderer::createDefault(); + _fontRenderer->setFramebufferSize({ _size.value().z, _size.value().w }); + + + _fontDate = OsEng.fontManager().font( + KeyFontMono, + 48 + ); + _fontInfo = OsEng.fontManager().font( + KeyFontMono, + 32 + ); + + addRenderFunction([this]() { + + glm::vec2 penPosition = glm::vec2( + 10.f, + _size.value().w + ); + + penPosition.y -= _fontDate->height(); + RenderFontCr( + *_fontDate, + penPosition, + "Date: %s", + OsEng.timeManager().time().UTC().c_str() + ); + + std::pair deltaTime = simplifyTime( + OsEng.timeManager().time().deltaTime() + ); + RenderFontCr( + *_fontInfo, + penPosition, + "Simulation increment: %.1f %s / second", + deltaTime.first, + deltaTime.second.c_str() + ); + + double distance = glm::length( + OsEng.renderEngine().camera()->positionVec3() - + OsEng.navigationHandler().focusNode()->worldPosition() + ); + std::pair dist = simplifyDistance(distance); + RenderFontCr( + *_fontInfo, + penPosition, + "Distance from focus: %f %s", + dist.first, + dist.second.c_str() + ); + }); + + return true; +} + +bool ScreenSpaceDashboard::deinitializeGL() { + _fontRenderer = nullptr; + return ScreenSpaceFramebuffer::deinitializeGL(); +} + +bool ScreenSpaceDashboard::isReady() const { + return (_fontRenderer != nullptr) && (_fontDate != nullptr) && (_fontInfo != nullptr) && ScreenSpaceFramebuffer::isReady(); +} + +void ScreenSpaceDashboard::update() { + if (OsEng.windowWrapper().windowHasResized()) { + glm::ivec2 size = OsEng.windowWrapper().currentWindowResolution(); + _size = { 0.f, 0.f, size.x, size.y }; + _originalViewportSize = size; + createFramebuffer(); + } +} + +} // namespace openspace diff --git a/modules/base/rendering/screenspacedashboard.h b/modules/base/rendering/screenspacedashboard.h new file mode 100644 index 0000000000..39184e354f --- /dev/null +++ b/modules/base/rendering/screenspacedashboard.h @@ -0,0 +1,61 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___SCREENSPACEDASHBOARD___H__ +#define __OPENSPACE_MODULE_BASE___SCREENSPACEDASHBOARD___H__ + +#include + +namespace ghoul::fontrendering { + class Font; + class FontRenderer; +} + +namespace openspace { + +namespace documentation { struct Documentation; } + +class ScreenSpaceDashboard: public ScreenSpaceFramebuffer { +public: + ScreenSpaceDashboard(const ghoul::Dictionary& dictionary); + ~ScreenSpaceDashboard(); + + bool initializeGL() override; + bool deinitializeGL() override; + + bool isReady() const override; + void update() override; + + static documentation::Documentation Documentation(); + +private: + std::unique_ptr _fontRenderer; + + std::shared_ptr _fontDate; + std::shared_ptr _fontInfo; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___SCREENSPACEDASHBOARD___H__ diff --git a/modules/base/rendering/screenspaceframebuffer.cpp b/modules/base/rendering/screenspaceframebuffer.cpp index 32ae93e247..e1f05ea5e7 100644 --- a/modules/base/rendering/screenspaceframebuffer.cpp +++ b/modules/base/rendering/screenspaceframebuffer.cpp @@ -82,7 +82,7 @@ ScreenSpaceFramebuffer::~ScreenSpaceFramebuffer() {} bool ScreenSpaceFramebuffer::initializeGL() { ScreenSpaceRenderable::initializeGL(); - createFragmentbuffer(); + createFramebuffer(); return isReady(); } @@ -90,7 +90,9 @@ bool ScreenSpaceFramebuffer::initializeGL() { bool ScreenSpaceFramebuffer::deinitializeGL() { ScreenSpaceRenderable::deinitializeGL(); + _framebuffer->activate(); _framebuffer->detachAll(); + _framebuffer->deactivate(); removeAllRenderFunctions(); return true; @@ -103,7 +105,7 @@ void ScreenSpaceFramebuffer::render() { float xratio = _originalViewportSize.x / (size.z-size.x); float yratio = _originalViewportSize.y / (size.w-size.y);; - if (!_renderFunctions.empty()) { + if (!_renderFunctions.empty() || !_renderFunctionsShared.empty()) { glViewport( static_cast(-size.x * xratio), static_cast(-size.y * yratio), @@ -113,10 +115,12 @@ void ScreenSpaceFramebuffer::render() { GLint defaultFBO = _framebuffer->getActiveObject(); _framebuffer->activate(); - glClearColor (0.0f, 0.0f, 0.0f, 0.0f); + glClearColor(0.f, 0.f, 0.f, 0.f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glEnable(GL_ALPHA_TEST); for (const auto& renderFunction : _renderFunctions) { + renderFunction(); + } + for (const auto& renderFunction : _renderFunctionsShared) { (*renderFunction)(); } _framebuffer->deactivate(); @@ -131,15 +135,15 @@ void ScreenSpaceFramebuffer::render() { glm::mat4 rotation = rotationMatrix(); glm::mat4 translation = translationMatrix(); - glm::mat4 scale = scaleMatrix(); - scale = glm::scale(scale, glm::vec3((1.0/xratio), -(1.0/yratio), 1.0f)); + glm::mat4 scale = glm::scale( + scaleMatrix(), + glm::vec3((1.f / xratio), (1.f / yratio), 1.f) + ); glm::mat4 modelTransform = rotation*translation*scale; draw(modelTransform); } } -void ScreenSpaceFramebuffer::update() {} - bool ScreenSpaceFramebuffer::isReady() const { bool ready = true; if (!_shader) { @@ -155,17 +159,22 @@ void ScreenSpaceFramebuffer::setSize(glm::vec4 size) { _size.set(size); } +void ScreenSpaceFramebuffer::addRenderFunction(std::function renderFunction) { + _renderFunctions.push_back(std::move(renderFunction)); +} + void ScreenSpaceFramebuffer::addRenderFunction( std::shared_ptr> renderFunction) { - _renderFunctions.push_back(renderFunction); + _renderFunctionsShared.push_back(std::move(renderFunction)); } void ScreenSpaceFramebuffer::removeAllRenderFunctions() { _renderFunctions.clear(); + _renderFunctionsShared.clear(); } -void ScreenSpaceFramebuffer::createFragmentbuffer() { +void ScreenSpaceFramebuffer::createFramebuffer() { _framebuffer = std::make_unique(); _framebuffer->activate(); _texture = std::make_unique(glm::uvec3( diff --git a/modules/base/rendering/screenspaceframebuffer.h b/modules/base/rendering/screenspaceframebuffer.h index a4cc947f51..f610c3356e 100644 --- a/modules/base/rendering/screenspaceframebuffer.h +++ b/modules/base/rendering/screenspaceframebuffer.h @@ -51,23 +51,25 @@ public: bool initializeGL() override; bool deinitializeGL() override; void render() override; - void update() override; bool isReady() const override; void setSize(glm::vec4); void addRenderFunction(std::shared_ptr> renderFunction); + void addRenderFunction(std::function renderFunction); void removeAllRenderFunctions(); static documentation::Documentation Documentation(); -private: - void createFragmentbuffer(); - static int id(); - +protected: + void createFramebuffer(); properties::Vec4Property _size; +private: + static int id(); + std::unique_ptr _framebuffer; - std::vector>> _renderFunctions; + std::vector>> _renderFunctionsShared; + std::vector> _renderFunctions; int _id; }; diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index a47b6d3729..ab19072f11 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -227,7 +227,7 @@ void addScreenSpaceRenderableLocal(std::string texturePath) { const std::string luaTable = "{Type = 'ScreenSpaceImageLocal', TexturePath = openspace.absPath('" + texturePath + "') }"; - const std::string script = "openspace.registerScreenSpaceRenderable(" + + const std::string script = "openspace.addScreenSpaceRenderable(" + luaTable + ");"; OsEng.scriptEngine().queueScript( script, @@ -238,7 +238,7 @@ void addScreenSpaceRenderableLocal(std::string texturePath) { void addScreenSpaceRenderableOnline(std::string texturePath) { const std::string luaTable = "{Type = 'ScreenSpaceImageOnline', TexturePath = '" + texturePath + "' }"; - const std::string script = "openspace.registerScreenSpaceRenderable(" + + const std::string script = "openspace.addScreenSpaceRenderable(" + luaTable + ");"; OsEng.scriptEngine().queueScript( script, @@ -812,6 +812,14 @@ void GUI::render() { addScreenSpaceRenderableOnline(std::string(addImageOnlineBuffer)); } + bool addDashboard = ImGui::Button("Add Dashboard"); + if (addDashboard) { + OsEng.scriptEngine().queueScript( + "openspace.addScreenSpaceRenderable({ Type = 'ScreenSpaceDashboard' });", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + ImGui::Checkbox("ImGUI Internals", &_showInternals); if (_showInternals) { ImGui::Begin("Style Editor"); diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index 3b33dbde44..e65c2f5e9b 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -93,7 +93,7 @@ int iswa_addScreenSpaceCygnet(lua_State* L) { std::shared_ptr s( ScreenSpaceRenderable::createFromDictionary(d) ); - OsEng.renderEngine().registerScreenSpaceRenderable(s); + OsEng.renderEngine().addScreenSpaceRenderable(s); } return 0; } diff --git a/openspace.cfg b/openspace.cfg index f64c733086..8c2e233c27 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -85,8 +85,8 @@ return { ShowNodeNames = true, ShowProgressbar = true }, - -- CheckOpenGLState = true, - -- LogEachOpenGLCall = true, + CheckOpenGLState = true, + LogEachOpenGLCall = true, ShutdownCountdown = 3, -- OnScreenTextScaling = "framebuffer", diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index c32511ceb0..6515c36ef7 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -833,15 +833,15 @@ scripting::LuaLibrary RenderEngine::luaLibrary() { "" }, { - "registerScreenSpaceRenderable", - &luascriptfunctions::registerScreenSpaceRenderable, + "addScreenSpaceRenderable", + &luascriptfunctions::addScreenSpaceRenderable, "table", - "Will create a ScreenSpaceRenderable from a lua Table and register it in " - "the RenderEngine" + "Will create a ScreenSpaceRenderable from a lua Table and add it in the " + "RenderEngine" }, { - "unregisterScreenSpaceRenderable", - &luascriptfunctions::unregisterScreenSpaceRenderable, + "removeScreenSpaceRenderable", + &luascriptfunctions::removeScreenSpaceRenderable, "string", "Given a ScreenSpaceRenderable name this script will remove it from the " "renderengine" @@ -858,16 +858,13 @@ performance::PerformanceManager* RenderEngine::performanceManager() { return _performanceManager.get(); } -void RenderEngine::registerScreenSpaceRenderable(std::shared_ptr s) -{ +void RenderEngine::addScreenSpaceRenderable(std::shared_ptr s) { s->initialize(); s->initializeGL(); _screenSpaceRenderables.push_back(std::move(s)); } -void RenderEngine::unregisterScreenSpaceRenderable( - std::shared_ptr s) -{ +void RenderEngine::removeScreenSpaceRenderable(std::shared_ptr s) { auto it = std::find( _screenSpaceRenderables.begin(), _screenSpaceRenderables.end(), @@ -880,10 +877,10 @@ void RenderEngine::unregisterScreenSpaceRenderable( } } -void RenderEngine::unregisterScreenSpaceRenderable(const std::string& name){ +void RenderEngine::removeScreenSpaceRenderable(const std::string& name) { std::shared_ptr s = screenSpaceRenderable(name); if (s) { - unregisterScreenSpaceRenderable(s); + removeScreenSpaceRenderable(s); } } @@ -981,7 +978,7 @@ void RenderEngine::renderInformation() { penPosition, "Simulation increment: %.1f %s / second", deltaTime.first, - deltaTime.second + deltaTime.second.c_str() ); double distance = glm::length( @@ -994,7 +991,7 @@ void RenderEngine::renderInformation() { penPosition, "Distance from focus: %f %s", dist.first, - dist.second + dist.second.c_str() ); FrametimeType frametimeType = FrametimeType(_frametimeType.value()); diff --git a/src/rendering/renderengine_lua.inl b/src/rendering/renderengine_lua.inl index 3efd03bc06..cdd14c5247 100644 --- a/src/rendering/renderengine_lua.inl +++ b/src/rendering/renderengine_lua.inl @@ -97,7 +97,7 @@ int fadeOut(lua_State* L) { return 0; } -int registerScreenSpaceRenderable(lua_State* L) { +int addScreenSpaceRenderable(lua_State* L) { using ghoul::lua::errorLocation; int nArguments = lua_gettop(L); @@ -110,19 +110,19 @@ int registerScreenSpaceRenderable(lua_State* L) { ghoul::lua::luaDictionaryFromState(L, d); } catch (const ghoul::lua::LuaFormatException& e) { - LERRORC("registerScreenSpaceRenderable", e.what()); + LERRORC("addScreenSpaceRenderable", e.what()); return 0; } std::shared_ptr s( ScreenSpaceRenderable::createFromDictionary(d) ); - OsEng.renderEngine().registerScreenSpaceRenderable(s); + OsEng.renderEngine().addScreenSpaceRenderable(s); return 1; } -int unregisterScreenSpaceRenderable(lua_State* L) { +int removeScreenSpaceRenderable(lua_State* L) { using ghoul::lua::errorLocation; int nArguments = lua_gettop(L); @@ -137,13 +137,13 @@ int unregisterScreenSpaceRenderable(lua_State* L) { ); if (!s) { LERRORC( - "unregisterScreenSpaceRenderable", + "removeScreenSpaceRenderable", errorLocation(L) << "Could not find ScreenSpaceRenderable '" << name << "'" ); return 0; } - OsEng.renderEngine().unregisterScreenSpaceRenderable(s); + OsEng.renderEngine().removeScreenSpaceRenderable(s); return 1; } diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index 0bf777b821..ec240858d5 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -295,7 +295,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary _delete.onChange([this](){ std::string script = - "openspace.unregisterScreenSpaceRenderable('" + name() + "');"; + "openspace.removeScreenSpaceRenderable('" + name() + "');"; OsEng.scriptEngine().queueScript( script, scripting::ScriptEngine::RemoteScripting::Yes From 38338725b9f5f7dee5c2ce6b9c6d1847e6b83cf5 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 26 Nov 2017 14:57:26 -0500 Subject: [PATCH 2/3] Strict coding style adherence --- apps/Launcher/syncwidget.h | 10 ++++-- include/openspace/rendering/loadingscreen.h | 2 +- include/openspace/scene/scene.h | 2 +- .../util/blockplaneintersectiongeometry.h | 3 +- .../openspace/util/powerscaledcoordinate.h | 5 +-- include/openspace/util/powerscaledsphere.h | 2 +- modules/base/rendering/renderabletrailorbit.h | 4 +-- .../base/rendering/screenspacedashboard.cpp | 5 ++- modules/base/rendering/screenspacedashboard.h | 4 +-- modules/base/rotation/fixedrotation.cpp | 1 - .../rendering/layer/layermanager.h | 3 +- .../tile/tileprovider/tileproviderbylevel.cpp | 2 +- modules/imgui/include/gui.h | 1 - modules/imgui/src/gui.cpp | 6 +++- modules/imgui/src/renderproperties.cpp | 2 +- .../rendering/renderablefov.h | 6 ++-- modules/touch/src/touchinteraction.cpp | 2 +- src/engine/openspaceengine.cpp | 5 +-- src/properties/matrix/mat4x3property.cpp | 4 +-- src/properties/scalar/ushortproperty.cpp | 2 +- src/rendering/loadingscreen.cpp | 31 +++++++++---------- src/scene/sceneloader.cpp | 2 +- support/coding/check_style_guide.py | 2 +- 23 files changed, 58 insertions(+), 48 deletions(-) diff --git a/apps/Launcher/syncwidget.h b/apps/Launcher/syncwidget.h index ec7eb88adb..2d55635ce3 100644 --- a/apps/Launcher/syncwidget.h +++ b/apps/Launcher/syncwidget.h @@ -94,7 +94,10 @@ private: void clear(); QStringList selectedScenes() const; - void handleFileFutureAddition(const std::vector>& futures); + void handleFileFutureAddition( + const std::vector>& + futures + ); void handleDirectFiles(); void handleFileRequest(); @@ -116,7 +119,10 @@ private: std::set _filesDownloading; std::vector> _futures; - std::map, InfoWidget*> _futureInfoWidgetMap; + std::map< + std::shared_ptr, + InfoWidget* + > _futureInfoWidgetMap; std::vector> _futuresToAdd; std::atomic_flag _mutex; diff --git a/include/openspace/rendering/loadingscreen.h b/include/openspace/rendering/loadingscreen.h index 1b6ca397c8..1ae6525a85 100644 --- a/include/openspace/rendering/loadingscreen.h +++ b/include/openspace/rendering/loadingscreen.h @@ -41,7 +41,7 @@ namespace ghoul::fontrendering { namespace ghoul::opengl { class ProgramObject; - class Texture; + class Texture; } // namespace ghoul::opengl namespace openspace { diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index 2f61a0675a..291e524603 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -73,7 +73,7 @@ public: * Initalizes the SceneGraph */ void initialize(); - + /** * Initializes the OpenGL part of the SceneGraph */ diff --git a/include/openspace/util/blockplaneintersectiongeometry.h b/include/openspace/util/blockplaneintersectiongeometry.h index c861cb8835..65407362bf 100644 --- a/include/openspace/util/blockplaneintersectiongeometry.h +++ b/include/openspace/util/blockplaneintersectiongeometry.h @@ -35,7 +35,8 @@ namespace openspace { class BlockPlaneIntersectionGeometry { public: // initializers - BlockPlaneIntersectionGeometry(glm::vec3 blockSize, glm::vec3 planeNormal, float planeDistance); + BlockPlaneIntersectionGeometry(glm::vec3 blockSize, glm::vec3 planeNormal, + float planeDistance); ~BlockPlaneIntersectionGeometry(); bool initialize(); diff --git a/include/openspace/util/powerscaledcoordinate.h b/include/openspace/util/powerscaledcoordinate.h index 568fe788b1..c3a3ff3962 100644 --- a/include/openspace/util/powerscaledcoordinate.h +++ b/include/openspace/util/powerscaledcoordinate.h @@ -48,10 +48,11 @@ public: // Sets the power scaled coordinates with w = 0 PowerScaledCoordinate(glm::vec3 v); - static PowerScaledCoordinate CreatePowerScaledCoordinate(double d1, double d2, double d3); + static PowerScaledCoordinate CreatePowerScaledCoordinate(double d1, double d2, + double d3); // get functions - // return the full, unmodified PSC + // return the full, unmodified PSC const glm::vec4& vec4() const; // returns the rescaled, "normal" coordinates diff --git a/include/openspace/util/powerscaledsphere.h b/include/openspace/util/powerscaledsphere.h index c7ad591436..0992642a09 100644 --- a/include/openspace/util/powerscaledsphere.h +++ b/include/openspace/util/powerscaledsphere.h @@ -35,7 +35,7 @@ namespace openspace { class PowerScaledSphere { public: // initializers - PowerScaledSphere(const PowerScaledScalar& radius, + PowerScaledSphere(const PowerScaledScalar& radius, int segments = 8); PowerScaledSphere(glm::vec3 radius, int segments); diff --git a/modules/base/rendering/renderabletrailorbit.h b/modules/base/rendering/renderabletrailorbit.h index a76caf4edc..d15fad2d6b 100644 --- a/modules/base/rendering/renderabletrailorbit.h +++ b/modules/base/rendering/renderabletrailorbit.h @@ -47,12 +47,12 @@ namespace documentation { struct Documentation; } class RenderableTrailOrbit : public RenderableTrail { public: explicit RenderableTrailOrbit(const ghoul::Dictionary& dictionary); - + void initializeGL() override; void deinitializeGL() override; void update(const UpdateData& data) override; - + static documentation::Documentation Documentation(); private: diff --git a/modules/base/rendering/screenspacedashboard.cpp b/modules/base/rendering/screenspacedashboard.cpp index c85f148c27..215f3f0fe3 100644 --- a/modules/base/rendering/screenspacedashboard.cpp +++ b/modules/base/rendering/screenspacedashboard.cpp @@ -164,7 +164,10 @@ bool ScreenSpaceDashboard::deinitializeGL() { } bool ScreenSpaceDashboard::isReady() const { - return (_fontRenderer != nullptr) && (_fontDate != nullptr) && (_fontInfo != nullptr) && ScreenSpaceFramebuffer::isReady(); + return (_fontRenderer != nullptr) && + (_fontDate != nullptr) && + (_fontInfo != nullptr) && + ScreenSpaceFramebuffer::isReady(); } void ScreenSpaceDashboard::update() { diff --git a/modules/base/rendering/screenspacedashboard.h b/modules/base/rendering/screenspacedashboard.h index 39184e354f..fe2b3e6c23 100644 --- a/modules/base/rendering/screenspacedashboard.h +++ b/modules/base/rendering/screenspacedashboard.h @@ -40,7 +40,7 @@ class ScreenSpaceDashboard: public ScreenSpaceFramebuffer { public: ScreenSpaceDashboard(const ghoul::Dictionary& dictionary); ~ScreenSpaceDashboard(); - + bool initializeGL() override; bool deinitializeGL() override; @@ -51,7 +51,7 @@ public: private: std::unique_ptr _fontRenderer; - + std::shared_ptr _fontDate; std::shared_ptr _fontInfo; }; diff --git a/modules/base/rotation/fixedrotation.cpp b/modules/base/rotation/fixedrotation.cpp index 4719adbfee..5a46894823 100644 --- a/modules/base/rotation/fixedrotation.cpp +++ b/modules/base/rotation/fixedrotation.cpp @@ -355,7 +355,6 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) break; } }; - _xAxis.type.addOptions({ { Axis::Type::Object, "Object" }, diff --git a/modules/globebrowsing/rendering/layer/layermanager.h b/modules/globebrowsing/rendering/layer/layermanager.h index 1ffbbeb334..a1e9780f52 100644 --- a/modules/globebrowsing/rendering/layer/layermanager.h +++ b/modules/globebrowsing/rendering/layer/layermanager.h @@ -48,7 +48,8 @@ public: void initialize(); void deinitialize(); - std::shared_ptr addLayer(layergroupid::GroupID groupId, ghoul::Dictionary layerDict); + std::shared_ptr addLayer(layergroupid::GroupID groupId, + ghoul::Dictionary layerDict); void deleteLayer(layergroupid::GroupID groupId, std::string layerName); const LayerGroup& layerGroup(size_t groupId); diff --git a/modules/globebrowsing/tile/tileprovider/tileproviderbylevel.cpp b/modules/globebrowsing/tile/tileprovider/tileproviderbylevel.cpp index aa0899328d..da3cc5fdb3 100644 --- a/modules/globebrowsing/tile/tileprovider/tileproviderbylevel.cpp +++ b/modules/globebrowsing/tile/tileprovider/tileproviderbylevel.cpp @@ -129,7 +129,7 @@ bool TileProviderByLevel::deinitialize() { for (const std::shared_ptr& tp : _levelTileProviders) { success &= tp->deinitialize(); } - + return TileProvider::deinitialize() && success; } diff --git a/modules/imgui/include/gui.h b/modules/imgui/include/gui.h index a56452433d..7d89e05550 100644 --- a/modules/imgui/include/gui.h +++ b/modules/imgui/include/gui.h @@ -94,7 +94,6 @@ private: properties::Property::Visibility _currentVisibility; - std::vector _contexts; }; diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index ab19072f11..49541bce94 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -483,7 +483,11 @@ void GUI::initializeGL() { //_contexts[i] = ImGui::CreateContext(); ImGui::SetCurrentContext(_contexts[i]); - ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pngData, &textureSize.x, &textureSize.y); + ImGui::GetIO().Fonts->GetTexDataAsRGBA32( + &pngData, + &textureSize.x, + &textureSize.y + ); } _fontTexture = std::make_unique( pngData, diff --git a/modules/imgui/src/renderproperties.cpp b/modules/imgui/src/renderproperties.cpp index 2c8074d342..9900b9e06e 100644 --- a/modules/imgui/src/renderproperties.cpp +++ b/modules/imgui/src/renderproperties.cpp @@ -667,7 +667,7 @@ void renderDMat2Property(Property* prop, const std::string& ownerName, isRegular ); } - + ImGui::PopID(); } diff --git a/modules/spacecraftinstruments/rendering/renderablefov.h b/modules/spacecraftinstruments/rendering/renderablefov.h index 8d0c39a32c..d5cedb1483 100644 --- a/modules/spacecraftinstruments/rendering/renderablefov.h +++ b/modules/spacecraftinstruments/rendering/renderablefov.h @@ -48,7 +48,7 @@ namespace documentation { struct Documentation; } class RenderableFov : public Renderable { public: RenderableFov(const ghoul::Dictionary& dictionary); - + void initializeGL() override; void deinitializeGL() override; @@ -56,7 +56,7 @@ public: void render(const RenderData& data, RendererTasks& rendererTask) override; void update(const UpdateData& data) override; - + static documentation::Documentation Documentation(); private: @@ -153,7 +153,7 @@ private: properties::Vec4Property square; // Color for the orthogonal square } _colors; }; - + } // namespace openspace #endif // __OPENSPACE_MODULE_SPACECRAFTINSTRUMENTS___RENDERABLEFOV___H__ diff --git a/modules/touch/src/touchinteraction.cpp b/modules/touch/src/touchinteraction.cpp index 17287d7e3b..2a1eea319c 100644 --- a/modules/touch/src/touchinteraction.cpp +++ b/modules/touch/src/touchinteraction.cpp @@ -385,7 +385,7 @@ void TouchInteraction::directControl(const std::vector& list) { { // Orbit (global rotation) dvec3 eulerAngles(q[1], q[0], 0); dquat rotationDiffCamSpace = dquat(eulerAngles); - + dvec3 centerToCamera = camPos - centerPos; dquat rotationDiffWorldSpace = diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 204548280f..9eeacc42e8 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -611,7 +611,6 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { if (configurationManager().hasKey(kProgress)) { showProgressbar = configurationManager().value(kProgress); } - _loadingScreen = std::make_unique( LoadingScreen::ShowMessage(showMessage), @@ -679,8 +678,6 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { initializeFinished = true; }); - - // While the SceneGraphNodes initialize themselves, we can hand over control to the // Loading screen rendering @@ -693,7 +690,7 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { t.join(); // It's okay to delete it since the last rendered image will remain on screen _loadingScreen = nullptr; - + if (errorWhileLoading) { return; } diff --git a/src/properties/matrix/mat4x3property.cpp b/src/properties/matrix/mat4x3property.cpp index b3202cebb0..85b3d73e3f 100644 --- a/src/properties/matrix/mat4x3property.cpp +++ b/src/properties/matrix/mat4x3property.cpp @@ -31,7 +31,7 @@ #include namespace { - + glm::mat4x3 fromLuaConversion(lua_State* state, bool& success) { glm::mat4x3 result; int number = 1; @@ -106,7 +106,7 @@ bool toStringConversion(std::string& outValue, glm::mat4x3 inValue) { return true; } -} // namespace +} // namespace namespace openspace::properties { diff --git a/src/properties/scalar/ushortproperty.cpp b/src/properties/scalar/ushortproperty.cpp index bec7cdd73e..3d0287a4dc 100644 --- a/src/properties/scalar/ushortproperty.cpp +++ b/src/properties/scalar/ushortproperty.cpp @@ -30,7 +30,7 @@ #include namespace { - + unsigned short fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { diff --git a/src/rendering/loadingscreen.cpp b/src/rendering/loadingscreen.cpp index e1a14f7e32..077b0a7f5d 100644 --- a/src/rendering/loadingscreen.cpp +++ b/src/rendering/loadingscreen.cpp @@ -77,7 +77,7 @@ namespace { { lhsLl -= glm::vec2(ItemStandoffDistance / 2.f); lhsUr += glm::vec2(ItemStandoffDistance / 2.f); - + rhsLl -= glm::vec2(ItemStandoffDistance / 2.f); rhsUr += glm::vec2(ItemStandoffDistance / 2.f); @@ -149,7 +149,7 @@ LoadingScreen::LoadingScreen(ShowMessage showMessage, ShowNodeNames showNodeName absPath("${OPENSPACE_DATA}/openspace-logo.png") ); _logoTexture->uploadTexture(); - + glGenVertexArrays(1, &_logo.vao); glBindVertexArray(_logo.vao); glGenBuffers(1, &_logo.vbo); @@ -216,7 +216,7 @@ LoadingScreen::LoadingScreen(ShowMessage showMessage, ShowNodeNames showNodeName LoadingScreen::~LoadingScreen() { _logoTexture = nullptr; - + _loadingFont = nullptr; _messageFont = nullptr; _itemFont = nullptr; @@ -234,7 +234,7 @@ LoadingScreen::~LoadingScreen() { void LoadingScreen::render() { // We have to recalculate the positions here because we will not be informed about a // window size change - + const glm::vec2 dpiScaling = OsEng.windowWrapper().dpiScaling(); const glm::ivec2 res = glm::vec2(OsEng.windowWrapper().currentWindowResolution()) / dpiScaling; @@ -304,16 +304,14 @@ void LoadingScreen::render() { ProgressbarSize.x, ProgressbarSize.y * screenAspectRatio }; - + glm::vec2 progressbarLl = { ProgressbarCenter.x - progressbarSize.x, ProgressbarCenter.y - progressbarSize.y - }; glm::vec2 progressbarUr = { ProgressbarCenter.x + progressbarSize.x , ProgressbarCenter.y + progressbarSize.y - }; if (_showProgressbar) { @@ -321,14 +319,14 @@ void LoadingScreen::render() { // Depending on the progress, we only want to draw the progress bar to a mixture // of the lowerleft and upper right extent - + float progress = _nItems != 0 ? static_cast(_iProgress) / static_cast(_nItems) : 0.f; glm::vec2 ur = progressbarUr; ur.x = glm::mix(progressbarLl.x, progressbarUr.x, progress); - + GLfloat dataFill[] = { progressbarLl.x, progressbarLl.y, ur.x, ur.y, @@ -471,7 +469,7 @@ void LoadingScreen::render() { for (Item& item : _items) { if (!item.hasLocation) { // Compute a new location - + FR::BoundingBoxInformation b = renderer.boundingBox( *_itemFont, "%s", @@ -500,7 +498,6 @@ void LoadingScreen::render() { ur = ll + b.boundingBox; // Test against logo and text - bool logoOverlap = rectOverlaps( ndcToScreen(logoLl, res), ndcToScreen(logoUr, res), ll, ur @@ -528,7 +525,6 @@ void LoadingScreen::render() { continue; } - // Test against all other boxes bool overlap = false; for (const Item& j : _items) { @@ -569,11 +565,14 @@ void LoadingScreen::render() { return glm::vec4(1.f); } }(); - - if (item.status == ItemStatus::Finished) { - auto t = std::chrono::duration_cast(now - item.finishedTime); - color.a = 1.f - static_cast(t.count()) / static_cast(TTL.count()); + if (item.status == ItemStatus::Finished) { + auto t = std::chrono::duration_cast( + now - item.finishedTime + ); + + color.a = 1.f - static_cast(t.count()) / + static_cast(TTL.count()); } #ifdef LOADINGSCREEN_DEBUGGING diff --git a/src/scene/sceneloader.cpp b/src/scene/sceneloader.cpp index a132f8425f..9cde4d7430 100644 --- a/src/scene/sceneloader.cpp +++ b/src/scene/sceneloader.cpp @@ -145,7 +145,7 @@ std::unique_ptr SceneLoader::loadScene(const std::string& path) { std::unique_ptr rootNode = std::make_unique(); rootNode->setName(SceneGraphNode::RootNodeName); scene->setRoot(std::move(rootNode)); - + OsEng.loadingScreen().updateItem( SceneGraphNode::RootNodeName, LoadingScreen::ItemStatus::Started diff --git a/support/coding/check_style_guide.py b/support/coding/check_style_guide.py index a2c73df3b7..afba3b036d 100644 --- a/support/coding/check_style_guide.py +++ b/support/coding/check_style_guide.py @@ -338,7 +338,7 @@ def check_empty_character_at_end(lines): if not is_strict_mode: return '' - index = [i + 1 for i, s in enumerate(lines) if len(s) > 1 and s[-2] == ' '] + index = [i + 1 for i, s in enumerate(lines) if len(s) > 1 and s[-2] == ' ' and not s.strip() == ''] if len(index) > 0: return index else: From bc61200724211467a53f39b9b878bcb0e4e6763f Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Fri, 1 Dec 2017 15:49:52 -0500 Subject: [PATCH 3/3] Added missing include. --- ext/ghoul | 2 +- modules/imgui/src/renderproperties.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index d7aec4688b..e50afc4291 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit d7aec4688b9673d61e8885f3ce7a0d569b54b614 +Subproject commit e50afc429167fcccc248192281594cd32dc79844 diff --git a/modules/imgui/src/renderproperties.cpp b/modules/imgui/src/renderproperties.cpp index 9900b9e06e..b5a7611ebe 100644 --- a/modules/imgui/src/renderproperties.cpp +++ b/modules/imgui/src/renderproperties.cpp @@ -37,6 +37,8 @@ #include +#include + namespace openspace { using namespace properties;