From cba6201b673ee3dbbd3b03a83cb76cbe797b0a38 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 7 Nov 2018 13:49:33 -0500 Subject: [PATCH 01/12] Minor coding style changes --- ext/ghoul | 2 +- .../rendering/renderableplanescloud.cpp | 2 +- modules/globebrowsing/src/rawtiledatareader.cpp | 7 ++----- modules/globebrowsing/src/renderableglobe.cpp | 3 +-- modules/globebrowsing/src/renderableglobe.h | 2 +- modules/globebrowsing/src/skirtedgrid.cpp | 4 +--- modules/globebrowsing/src/tileloadjob.cpp | 2 +- modules/globebrowsing/src/tileprovider.cpp | 16 ---------------- modules/server/src/topics/versiontopic.cpp | 4 ---- src/interaction/sessionrecording.cpp | 3 +-- src/scene/scenegraphnode.cpp | 2 +- src/scripting/scriptengine_lua.inl | 4 +--- 12 files changed, 11 insertions(+), 40 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index a6bb81f5b5..29829ac11a 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a6bb81f5b544966d27020696340aedddc6974824 +Subproject commit 29829ac11a99df218ece3c8501269afce84f8e3f diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 6fae1481e9..a7b7fde7d2 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -591,7 +591,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, _program->setUniform(_uniformCache.galaxyTexture, unit); int currentTextureIndex = -1; - for (const std::unordered_map::reference pAMapItem : _planesMap) + for (std::unordered_map::reference pAMapItem : _planesMap) { // For planes with undefined textures references if (pAMapItem.first == 30) { diff --git a/modules/globebrowsing/src/rawtiledatareader.cpp b/modules/globebrowsing/src/rawtiledatareader.cpp index 66e59abe99..c9f4e9b864 100644 --- a/modules/globebrowsing/src/rawtiledatareader.cpp +++ b/modules/globebrowsing/src/rawtiledatareader.cpp @@ -244,9 +244,6 @@ bool isInside(const PixelRegion& lhs, const PixelRegion& rhs) { } IODescription cutIODescription(IODescription& io, Side side, int pos) { - const PixelRegion readPreCut = io.read.region; - const PixelRegion writePreCut = io.write.region; - glm::dvec2 ratio = { io.write.region.numPixels.x / static_cast(io.read.region.numPixels.x), io.write.region.numPixels.y / static_cast(io.read.region.numPixels.y) @@ -368,9 +365,9 @@ RawTile::ReadError postProcessErrorCheck(const RawTile& rawTile, size_t nRasters RawTileDataReader::RawTileDataReader(std::string filePath, TileTextureInitData initData, PerformPreprocessing preprocess) - : _initData(std::move(initData)) + : _datasetFilePath(std::move(filePath)) + , _initData(std::move(initData)) , _preprocess(preprocess) - , _datasetFilePath(std::move(filePath)) { initialize(); } diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 34db102e75..8f4e65a342 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -399,9 +399,9 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) FloatProperty(OrenNayarRoughnessInfo, 0.f, 0.f, 1.f) }) , _debugPropertyOwner({ "Debug" }) + , _grid(DefaultSkirtedGridSegments, DefaultSkirtedGridSegments) , _leftRoot(Chunk(LeftHemisphereIndex)) , _rightRoot(Chunk(RightHemisphereIndex)) - , _grid(DefaultSkirtedGridSegments, DefaultSkirtedGridSegments) { // Read the radii in to its own dictionary if (dictionary.hasKeyAndValue(KeyRadii)) { @@ -1229,7 +1229,6 @@ void RenderableGlobe::recompileShaders() { // Different layer types can be height layers or color layers for example. // These are used differently within the shaders. - preprocessingData.layeredTextureInfo; for (size_t i = 0; i < preprocessingData.layeredTextureInfo.size(); i++) { // lastLayerIndex must be at least 0 for the shader to compile, diff --git a/modules/globebrowsing/src/renderableglobe.h b/modules/globebrowsing/src/renderableglobe.h index 2e4182f9ea..ebac79fcbf 100644 --- a/modules/globebrowsing/src/renderableglobe.h +++ b/modules/globebrowsing/src/renderableglobe.h @@ -86,7 +86,7 @@ public: void update(const UpdateData& data) override; SurfacePositionHandle calculateSurfacePositionHandle( - const glm::dvec3& targetModelSpace) const; + const glm::dvec3& targetModelSpace) const override; const Ellipsoid& ellipsoid() const; const LayerManager& layerManager() const; diff --git a/modules/globebrowsing/src/skirtedgrid.cpp b/modules/globebrowsing/src/skirtedgrid.cpp index d3426116aa..1c35d2c283 100644 --- a/modules/globebrowsing/src/skirtedgrid.cpp +++ b/modules/globebrowsing/src/skirtedgrid.cpp @@ -28,8 +28,6 @@ #include namespace { - constexpr const char* _loggerCat = "SkirtedGrid"; - size_t numElements(int xSegments, int ySegments) { return 3 * 2 * xSegments * ySegments; } @@ -162,7 +160,7 @@ void SkirtedGrid::initializeGL() { glBindVertexArray(0); ghoul_assert( - elementData.size() == _elementSize, + static_cast(elementData.size()) == _elementSize, "Wrong element size. The correct number is assumed in the render method" ); } diff --git a/modules/globebrowsing/src/tileloadjob.cpp b/modules/globebrowsing/src/tileloadjob.cpp index 52ee6751db..8bbbd3a1df 100644 --- a/modules/globebrowsing/src/tileloadjob.cpp +++ b/modules/globebrowsing/src/tileloadjob.cpp @@ -40,7 +40,7 @@ TileLoadJob::~TileLoadJob() { } void TileLoadJob::execute() { - _rawTile = std::move(_rawTileDataReader.readTileData(_chunkIndex)); + _rawTile = _rawTileDataReader.readTileData(_chunkIndex); _hasTile = true; } diff --git a/modules/globebrowsing/src/tileprovider.cpp b/modules/globebrowsing/src/tileprovider.cpp index dabf25bfa6..ffcce43c7d 100644 --- a/modules/globebrowsing/src/tileprovider.cpp +++ b/modules/globebrowsing/src/tileprovider.cpp @@ -131,8 +131,6 @@ namespace bylevelprovider { namespace temporal { constexpr const char* KeyBasePath = "BasePath"; - constexpr const char* KeyPreCacheStartTime = "PreCacheStartTime"; - constexpr const char* KeyPreCacheEndTime = "PreCacheEndTime"; constexpr const char* UrlTimePlaceholder = "${OpenSpaceTimeId}"; constexpr const char* TimeStart = "OpenSpaceTimeStart"; @@ -148,20 +146,6 @@ namespace temporal { }; } // namespace temporal -Type toType(const layergroupid::TypeID& id) { - using T = layergroupid::TypeID; - switch (id) { - case T::Unknown: throw ghoul::MissingCaseException(); - case T::DefaultTileLayer: return Type::DefaultTileProvider; - case T::SingleImageTileLayer: return Type::SingleImageTileProvider; - case T::SizeReferenceTileLayer: return Type::SizeReferenceTileProvider; - case T::TemporalTileLayer: return Type::TemporalTileProvider; - case T::TileIndexTileLayer: return Type::TileIndexTileProvider; - case T::ByIndexTileLayer: return Type::ByIndexTileProvider; - case T::ByLevelTileLayer: return Type::ByLevelTileProvider; - default: throw ghoul::MissingCaseException(); - } -} // // DefaultTileProvider diff --git a/modules/server/src/topics/versiontopic.cpp b/modules/server/src/topics/versiontopic.cpp index c1c59fe400..ad7d64f86b 100644 --- a/modules/server/src/topics/versiontopic.cpp +++ b/modules/server/src/topics/versiontopic.cpp @@ -28,10 +28,6 @@ #include #include -namespace { - constexpr const char* _loggerCat = "VersionTopic"; -} // namespace - namespace openspace { bool VersionTopic::isDone() const { diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 69320979fc..41b1c46188 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -360,7 +360,7 @@ void SessionRecording::saveStringToFile(const std::string s) { _bufferIndex = 0; unsigned char const *p = reinterpret_cast(&strLen); memcpy((_keyframeBuffer + _bufferIndex), p, writeSize_bytes); - _bufferIndex += (unsigned int)writeSize_bytes; + _bufferIndex += static_cast(writeSize_bytes); saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex); _recordFile.write(s.c_str(), s.size()); @@ -1065,7 +1065,6 @@ bool SessionRecording::findNextFutureCameraIndex(double currTime) { { _idxTimeline_cameraPtrPrev = _idxTimeline_cameraPtrNext; return false; - break; } if (seekAheadIndex == (_timeline.size() - 1)) { diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 0353e5baa1..21e41b7a59 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -226,9 +226,9 @@ std::unique_ptr SceneGraphNode::createFromDictionary( SceneGraphNode::SceneGraphNode() : properties::PropertyOwner({ "" }) + , _guiHidden(GuiHiddenInfo) , _guiPath(GuiPathInfo) , _guiDisplayName(GuiNameInfo) - , _guiHidden(GuiHiddenInfo) , _transform { std::make_unique(), std::make_unique(), diff --git a/src/scripting/scriptengine_lua.inl b/src/scripting/scriptengine_lua.inl index 5a3ec004dd..1d2b7873b1 100644 --- a/src/scripting/scriptengine_lua.inl +++ b/src/scripting/scriptengine_lua.inl @@ -365,9 +365,7 @@ int unzipFile(lua_State* L) { deleteSource = ghoul::lua::value(L, 3, ghoul::lua::PopValue::No); } - auto onExtractEntry = [](const char *filename, void *arg) { - return 0; - }; + auto onExtractEntry = [](const char*, void*) { return 0; }; int arg = 2; zip_extract(source.c_str(), dest.c_str(), onExtractEntry, &arg); From e9c82facefbfe2d0c5e13a8b5eadd761d542a65e Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Wed, 7 Nov 2018 15:35:07 -0500 Subject: [PATCH 02/12] Add webgui to scenes --- data/assets/dawn.scene | 1 + data/assets/juno.scene | 2 ++ data/assets/messenger.scene | 2 ++ data/assets/newhorizons.scene | 2 ++ data/assets/osirisrex.scene | 2 ++ data/assets/rosetta.scene | 2 ++ data/assets/voyager.scene | 2 ++ ext/ghoul | 2 +- 8 files changed, 14 insertions(+), 1 deletion(-) diff --git a/data/assets/dawn.scene b/data/assets/dawn.scene index e97f778d92..6169619bb7 100644 --- a/data/assets/dawn.scene +++ b/data/assets/dawn.scene @@ -15,6 +15,7 @@ asset.require('scene/solarsystem/missions/dawn/vesta') asset.require('util/default_keybindings') asset.require('util/default_dashboard') +asset.require('util/webgui') local DawnAsset = asset.require('scene/solarsystem/missions/dawn/dawn') diff --git a/data/assets/juno.scene b/data/assets/juno.scene index d6ad6518f2..d7d2cc52e0 100644 --- a/data/assets/juno.scene +++ b/data/assets/juno.scene @@ -14,6 +14,8 @@ asset.require('util/default_keybindings') asset.require('util/default_dashboard') asset.require('util/default_joystick') +asset.require('util/webgui') + local junoAsset = asset.require('scene/solarsystem/missions/juno/juno') asset.onInitialize(function () diff --git a/data/assets/messenger.scene b/data/assets/messenger.scene index 1f1caddd7e..aa445df254 100644 --- a/data/assets/messenger.scene +++ b/data/assets/messenger.scene @@ -13,6 +13,8 @@ asset.request('scene/digitaluniverse/milkyway') asset.require('util/default_keybindings') asset.require('util/default_dashboard') +asset.require('util/webgui') + local MessengerAsset = asset.require('scene/solarsystem/missions/messenger/messengerSC') if not openspace.modules.isLoaded("Volume") then diff --git a/data/assets/newhorizons.scene b/data/assets/newhorizons.scene index 8dbc35f671..8cc2d6dd7f 100644 --- a/data/assets/newhorizons.scene +++ b/data/assets/newhorizons.scene @@ -16,6 +16,8 @@ asset.require('util/default_keybindings') asset.require('util/default_dashboard') asset.require('util/default_joystick') +asset.require('util/webgui') + -- Custom Keybindings local Keybindings = { { diff --git a/data/assets/osirisrex.scene b/data/assets/osirisrex.scene index 8688ef0e1d..81f0eef20c 100644 --- a/data/assets/osirisrex.scene +++ b/data/assets/osirisrex.scene @@ -15,6 +15,8 @@ asset.require('util/default_keybindings') asset.require('util/default_dashboard') asset.require('util/default_joystick') +asset.require('util/webgui') + -- Custom Keybindings local Keybindings = { { diff --git a/data/assets/rosetta.scene b/data/assets/rosetta.scene index a6e2d643cf..4661adfa3e 100644 --- a/data/assets/rosetta.scene +++ b/data/assets/rosetta.scene @@ -17,6 +17,8 @@ asset.require('util/default_keybindings') asset.require('util/default_dashboard') asset.require('util/default_joystick') +asset.require('util/webgui') + -- Custom Keybindings local Keybindings = { { diff --git a/data/assets/voyager.scene b/data/assets/voyager.scene index e48cac630a..c9f274aed1 100644 --- a/data/assets/voyager.scene +++ b/data/assets/voyager.scene @@ -21,6 +21,8 @@ asset.require('util/default_keybindings') asset.require('util/default_dashboard') asset.require('util/default_joystick') +asset.require('util/webgui') + local VoyagerAsset = asset.require('scene/solarsystem/missions/voyager/voyager1') assetHelper.registerDashboardItems(asset, { diff --git a/ext/ghoul b/ext/ghoul index a6bb81f5b5..b381513244 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a6bb81f5b544966d27020696340aedddc6974824 +Subproject commit b381513244c9ad55197fdefccbfe95898d1cf1a8 From 4ce29842d30379e0a4de03b091d3d95fd4ab8718 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Thu, 8 Nov 2018 10:32:42 -0500 Subject: [PATCH 03/12] Add shortcut to disable master rendering --- data/assets/util/default_keybindings.asset | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/assets/util/default_keybindings.asset b/data/assets/util/default_keybindings.asset index eca30ca2a0..cdca66d315 100644 --- a/data/assets/util/default_keybindings.asset +++ b/data/assets/util/default_keybindings.asset @@ -127,6 +127,14 @@ openspace.setPropertyValueSingle("RenderEngine.ShowCamera", not isEnabled)]], Documentation = "Toggles the dashboard and overlays", GuiPath = "/GUI", Local = false + }, + { + Key = "Alt+Tab", + Name = "Toggle rendering on master", + Command = propertyHelper.invert('RenderEngine.DisableMasterRendering'), + Documentation = "Toggles the rendering on master", + GuiPath = "/Rendering", + Local = false } } From f9514ab92a1b7d181ae66486b68797cf18e3dc26 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Thu, 8 Nov 2018 11:54:27 -0500 Subject: [PATCH 04/12] Use bin folder instead of cwd to find configuration file --- src/engine/configuration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index 33851179fc..807322a765 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -309,7 +309,7 @@ void parseLuaState(Configuration& configuration) { std::string findConfiguration(const std::string& filename) { using ghoul::filesystem::Directory; - Directory directory = FileSys.currentDirectory(); + Directory directory = FileSys.absolutePath("${BIN}"); while (true) { std::string fullPath = FileSys.pathByAppendingComponent( From 32226fe560a85158eabd80372a54c9efba31c81e Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Fri, 9 Nov 2018 16:17:02 -0500 Subject: [PATCH 05/12] Use bin folder instead of cwd to find configuration file (#761) --- src/engine/configuration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index 33851179fc..807322a765 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -309,7 +309,7 @@ void parseLuaState(Configuration& configuration) { std::string findConfiguration(const std::string& filename) { using ghoul::filesystem::Directory; - Directory directory = FileSys.currentDirectory(); + Directory directory = FileSys.absolutePath("${BIN}"); while (true) { std::string fullPath = FileSys.pathByAppendingComponent( From 989304835d877c3f3cc27f0c083a30211c66a1b2 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Mon, 12 Nov 2018 11:05:30 +0100 Subject: [PATCH 06/12] Only update part of gui that was updated by CEF (#760) --- modules/cefwebgui/src/guirenderhandler.cpp | 6 + modules/webbrowser/include/webrenderhandler.h | 31 ++-- modules/webbrowser/src/screenspacebrowser.cpp | 4 + modules/webbrowser/src/webrenderhandler.cpp | 145 ++++++++++++++---- 4 files changed, 142 insertions(+), 44 deletions(-) diff --git a/modules/cefwebgui/src/guirenderhandler.cpp b/modules/cefwebgui/src/guirenderhandler.cpp index e9e765e252..86c7f8b1d8 100644 --- a/modules/cefwebgui/src/guirenderhandler.cpp +++ b/modules/cefwebgui/src/guirenderhandler.cpp @@ -74,10 +74,16 @@ void GUIRenderHandler::draw() { return; } + if (!isTextureReady()) { + return; + } + if (_programObject->isDirty()) { _programObject->rebuildFromFile(); } + updateTexture(); + glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/modules/webbrowser/include/webrenderhandler.h b/modules/webbrowser/include/webrenderhandler.h index 8fb0ce413f..60b587efb7 100644 --- a/modules/webbrowser/include/webrenderhandler.h +++ b/modules/webbrowser/include/webrenderhandler.h @@ -25,6 +25,9 @@ #ifndef __OPENSPACE_MODULE_WEBBROWSER__WEB_RENDER_HANDLER_H #define __OPENSPACE_MODULE_WEBBROWSER__WEB_RENDER_HANDLER_H +#include +#include + #ifdef _MSC_VER #pragma warning (push) #pragma warning (disable : 4100) @@ -42,6 +45,8 @@ namespace openspace { class WebRenderHandler : public CefRenderHandler { public: + using Pixel = glm::tvec4; + virtual void draw(void) = 0; virtual void render() = 0; @@ -52,23 +57,25 @@ public: const RectList &dirtyRects, const void* buffer, int width, int height) override; bool hasContent(int x, int y); + bool isTextureReady() const; + void updateTexture(); + protected: - int _width = 0; - int _height = 0; GLuint _texture; +private: + glm::ivec2 _windowSize; + glm::ivec2 _browserBufferSize; + /** - * Alpha mask showing whether or not a pixel is filled with content - * - * Depending on what config you're running (Debug/Release), use different types here. - * This is to increase performance on Debug, since VS is performing lots of extra - * checks on vector. + * RGBA buffer from browser */ -#if !(defined(NDEBUG) || defined(DEBUG)) - std::vector _alphaMask; -#else - std::vector _alphaMask; -#endif + std::vector _browserBuffer; + bool _needsRepaint = true; + bool _textureSizeIsDirty = true; + bool _textureIsDirty = true; + glm::ivec2 _lowerDirtyRectBound; + glm::ivec2 _upperDirtyRectBound; IMPLEMENT_REFCOUNTING(WebRenderHandler); }; diff --git a/modules/webbrowser/src/screenspacebrowser.cpp b/modules/webbrowser/src/screenspacebrowser.cpp index 989b542b6a..f9e2e9e688 100644 --- a/modules/webbrowser/src/screenspacebrowser.cpp +++ b/modules/webbrowser/src/screenspacebrowser.cpp @@ -133,6 +133,10 @@ bool ScreenSpaceBrowser::deinitialize() { } void ScreenSpaceBrowser::render() { + if (!_renderHandler->isTextureReady()) { + return; + } + _renderHandler->updateTexture(); draw(rotationMatrix() * translationMatrix() * scaleMatrix()); } diff --git a/modules/webbrowser/src/webrenderhandler.cpp b/modules/webbrowser/src/webrenderhandler.cpp index 5fc6ebb62c..9dc606c2b4 100644 --- a/modules/webbrowser/src/webrenderhandler.cpp +++ b/modules/webbrowser/src/webrenderhandler.cpp @@ -25,18 +25,21 @@ #include #include +#include +#include namespace openspace { void WebRenderHandler::reshape(int w, int h) { - _width = w; - _height = h; - _alphaMask.clear(); - _alphaMask.resize(w * h); + if (w == _windowSize.x && h == _windowSize.y) { + return; + } + _windowSize = glm::ivec2(w, h); + _needsRepaint = true; } bool WebRenderHandler::GetViewRect(CefRefPtr browser, CefRect& rect) { - rect = CefRect(0, 0, _width, _height); + rect = CefRect(0, 0, _windowSize.x, _windowSize.y); return true; } @@ -45,38 +48,116 @@ void WebRenderHandler::OnPaint(CefRefPtr browser, const CefRenderHandler::RectList& dirtyRects, const void* buffer, int w, int h) { - glBindTexture(GL_TEXTURE_2D, _texture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA, - w, - h, - 0, - GL_BGRA_EXT, - GL_UNSIGNED_BYTE, - buffer - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBindTexture(GL_TEXTURE_2D, 0); + const size_t bufferSize = static_cast(w * h); - // copy alpha channel from buffer into the alpha mask - const unsigned char* bf = reinterpret_cast(buffer); - for (int maskIndex = 0, bufferIndex = 3; - maskIndex < w * h; - bufferIndex += 4, ++maskIndex) - { - _alphaMask[maskIndex] = bf[bufferIndex] > 0; + glm::ivec2 upperUpdatingRectBound = glm::ivec2(0, 0); + glm::ivec2 lowerUpdatingRectBound = glm::ivec2(w, h); + + if (_needsRepaint || _browserBuffer.size() != bufferSize) { + _browserBufferSize = glm::ivec2(w, h); + _browserBuffer.resize(w * h, Pixel(0)); + _textureSizeIsDirty = true; + _upperDirtyRectBound = upperUpdatingRectBound = glm::ivec2(w, h); + _lowerDirtyRectBound = lowerUpdatingRectBound = glm::ivec2(0, 0); } + + for (auto it = dirtyRects.begin(); it != dirtyRects.end(); ++it) { + lowerUpdatingRectBound = glm::min( + lowerUpdatingRectBound, + glm::ivec2(it->x, it->y) + ); + upperUpdatingRectBound = glm::max( + upperUpdatingRectBound, + glm::ivec2(it->x + it->width, it->y + it->height) + ); + } + const glm::ivec2 rectSize = upperUpdatingRectBound - lowerUpdatingRectBound; + if (rectSize.x > 0 && rectSize.y > 0) { + _textureIsDirty = true; + } else { + return; + } + + // Copy the updated rectangle line by line. + for (int y = lowerUpdatingRectBound.y; y < upperUpdatingRectBound.y; ++y) { + int lineOffset = y * w + lowerUpdatingRectBound.x; + int rectWidth = upperUpdatingRectBound.x - lowerUpdatingRectBound.x; + std::copy( + reinterpret_cast(buffer) + lineOffset, + reinterpret_cast(buffer) + lineOffset + rectWidth, + _browserBuffer.data() + lineOffset + ); + } + + // Add the dirty rect bounds to the GPU texture dirty rect. + _lowerDirtyRectBound = glm::min(lowerUpdatingRectBound, _lowerDirtyRectBound); + _upperDirtyRectBound = glm::max(upperUpdatingRectBound, _upperDirtyRectBound); + _needsRepaint = false; +} + +void WebRenderHandler::updateTexture() { + if (_needsRepaint) { + return; + } + + if (_textureSizeIsDirty) { + glBindTexture(GL_TEXTURE_2D, _texture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA, + _browserBufferSize.x, + _browserBufferSize.y, + 0, + GL_BGRA_EXT, + GL_UNSIGNED_BYTE, + reinterpret_cast(_browserBuffer.data()) + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glBindTexture(GL_TEXTURE_2D, 0); + } else if (_textureIsDirty) { + glBindTexture(GL_TEXTURE_2D, _texture); + glPixelStorei(GL_UNPACK_ROW_LENGTH, _browserBufferSize.x); + + glTexSubImage2D( + GL_TEXTURE_2D, + 0, + _lowerDirtyRectBound.x, + _lowerDirtyRectBound.y, + _upperDirtyRectBound.x - _lowerDirtyRectBound.x, + _upperDirtyRectBound.y - _lowerDirtyRectBound.y, + GL_BGRA_EXT, + GL_UNSIGNED_BYTE, + reinterpret_cast( + _browserBuffer.data() + + _lowerDirtyRectBound.y * _browserBufferSize.x + _lowerDirtyRectBound.x + ) + ); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glBindTexture(GL_TEXTURE_2D, 0); + } + + _upperDirtyRectBound = glm::ivec2(0, 0); + _lowerDirtyRectBound = glm::ivec2(_browserBufferSize.x, _browserBufferSize.y); + _textureSizeIsDirty = false; + _textureIsDirty = false; } bool WebRenderHandler::hasContent(int x, int y) { - int index = x + (_width * y); - index = glm::clamp(index, 0, static_cast(_alphaMask.size() - 1)); - return _alphaMask[index]; + if (_browserBuffer.empty()) { + return false; + } + int index = x + (_browserBufferSize.x * y); + index = glm::clamp(index, 0, static_cast(_browserBuffer.size() - 1)); + return _browserBuffer[index].a; +} + +bool WebRenderHandler::isTextureReady() const { + return !_needsRepaint; } } // namespace openspace From 5a49c662042b8cfd48d9fc3d5b013ab0a00a5dda Mon Sep 17 00:00:00 2001 From: Lovisa Hassler Date: Mon, 12 Nov 2018 18:26:12 -0500 Subject: [PATCH 07/12] moved the color mapping to the asset files --- .../communicationlines.asset | 9 +- .../scene/solarsystem/dsn/stations.asset | 29 ++++ modules/dsn/rendering/renderablesignals.cpp | 143 +++++++----------- modules/dsn/rendering/renderablesignals.h | 45 ++---- 4 files changed, 101 insertions(+), 125 deletions(-) diff --git a/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset b/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset index dfdec3d829..59441be63c 100644 --- a/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset +++ b/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset @@ -1,6 +1,6 @@ local assetHelper = asset.require('util/asset_helper') -local kernels = asset.require('scene/solarsystem/missions/voyager1/kernels') -local earthAsset = asset.require('scene/solarsystem/planets/earth/earth') +local stationsAsset = asset.require('scene/solarsystem/dsn/stations') + --Communicationline data local dataFolder = openspace.absPath("../../../sync/http/dsn_data/1/json") @@ -14,9 +14,8 @@ local Signals = { Type = "RenderableSignals", DataFolder = dataFolder, DataFileType = "json", - MadridColor = {1.0, 0.0, 0.0}, - GoldstoneColor = {0.0, 0.0, 1.0}, - CanberraColor = {0.0, 1.0, 0.0} + SiteColors = stationsAsset.siteColorMap, + StationSites = stationsAsset.stationSiteMap }, GUI = { Name = "Signals", diff --git a/data/assets/scene/solarsystem/dsn/stations.asset b/data/assets/scene/solarsystem/dsn/stations.asset index fd85db670b..4804cc6c8a 100644 --- a/data/assets/scene/solarsystem/dsn/stations.asset +++ b/data/assets/scene/solarsystem/dsn/stations.asset @@ -27,6 +27,31 @@ local LightSources = { } } +-- Colormap for the different sites +local siteColorMap = { + Goldstone = {0.0, 0.0, 1.0}, + Canberra = {0.0, 1.0, 0.0}, + Madrid = {1.0, 0.0, 0.0} + } + +-- Map to the site locations above, this will determine the signal colors +local stationSiteMap = { + DSS14 = "Goldstone", + DSS15 = "Goldstone", + DSS24 = "Goldstone", + DSS25 = "Goldstone", + DSS26 = "Goldstone", + DSS43 = "Canberra", + DSS34 = "Canberra", + DSS35 = "Canberra", + DSS36 = "Canberra", + DSS45 = "Canberra", + DSS63 = "Madrid", + DSS65 = "Madrid", + DSS54 = "Madrid", + DSS55 = "Madrid" + } + --------------------- Goldstone ------------------------ local DSS14 = { Identifier = "DSS14", @@ -375,6 +400,10 @@ local DSS55 = { + assetHelper.registerSceneGraphNodesAndExport(asset, { DSS14, DSS15, DSS24, DSS25, DSS26, DSS43, DSS34, DSS35, DSS36, DSS45, DSS63, DSS65, DSS54, DSS55 }) + +asset.export("siteColorMap", siteColorMap) +asset.export("stationSiteMap", stationSiteMap) \ No newline at end of file diff --git a/modules/dsn/rendering/renderablesignals.cpp b/modules/dsn/rendering/renderablesignals.cpp index b8493b862a..bc766d45a4 100644 --- a/modules/dsn/rendering/renderablesignals.cpp +++ b/modules/dsn/rendering/renderablesignals.cpp @@ -41,35 +41,24 @@ namespace { constexpr const char* ProgramName = "SignalsProgram"; constexpr const char* KeyTranslation = "Translation"; constexpr const char* _loggerCat = "RenderableSignals"; + constexpr const char* KeyStationSites = "StationSites"; + constexpr const std::array UniformNames = { "modelViewStation","modelViewSpacecraft", "projectionTransform" }; - constexpr openspace::properties::Property::PropertyInfo MadridColorInfo = { - "MadridColor", - "MadridColor", + constexpr openspace::properties::Property::PropertyInfo SiteColorsInfo = { + "SiteColors", + "SiteColors", "This value determines the RGB main color for the lines " - "of communication to and from Madrid." - }; - - constexpr openspace::properties::Property::PropertyInfo GoldstoneColorInfo = { - "GoldstoneColor", - "GoldstoneColor", - "This value determines the RGB main color for the lines " - "of communication to and from Goldstone." - }; - constexpr openspace::properties::Property::PropertyInfo CanberraColorInfo = { - "CanberraColor", - "CanberraColor", - "This value determines the RGB main color for the lines " - "of communication to and from Canberra." + "of communication to and from different sites on Earth." }; constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { "LineWidth", "Line Width", - "This value specifies the line width of the communication package. " + "This value specifies the line width of the signals. " }; } // namespace @@ -90,22 +79,17 @@ documentation::Documentation RenderableSignals::Documentation() { "Translation object can be used here." }, { - MadridColorInfo.identifier, - new DoubleVector3Verifier, - Optional::Yes, - MadridColorInfo.description + SiteColorsInfo.identifier, + new TableVerifier, + Optional::No, + SiteColorsInfo.description }, { - GoldstoneColorInfo.identifier, - new DoubleVector3Verifier, - Optional::Yes, - GoldstoneColorInfo.description - }, - { - CanberraColorInfo.identifier, - new DoubleVector3Verifier, - Optional::Yes, - GoldstoneColorInfo.description + KeyStationSites, + new TableVerifier, + Optional::No, + "This is a map of the individual stations to their " + "respective site location on Earth." }, { LineWidthInfo.identifier, @@ -119,9 +103,6 @@ documentation::Documentation RenderableSignals::Documentation() { RenderableSignals::RenderableSignals(const ghoul::Dictionary& dictionary) : Renderable(dictionary) - , _madridLineColor(MadridColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) - , _goldstoneLineColor(GoldstoneColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) - , _canberraLineColor(CanberraColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) , _lineWidth(LineWidthInfo, 2.f, 1.f, 20.f) { _translation = Translation::createFromDictionary( @@ -129,30 +110,40 @@ RenderableSignals::RenderableSignals(const ghoul::Dictionary& dictionary) ); addPropertySubOwner(_translation.get()); - if (dictionary.hasKeyAndValue(MadridColorInfo.identifier)) { - _madridLineColor = dictionary.value(MadridColorInfo.identifier); - } - else { - _madridLineColor = glm::vec3(1.f, 0.f, 0.f); - } - addProperty(_madridLineColor); + if (dictionary.hasKeyAndValue(SiteColorsInfo.identifier)) { + ghoul::Dictionary colorDictionary = dictionary.value(SiteColorsInfo.identifier); + std::vector siteNames = colorDictionary.keys(); - if (dictionary.hasKeyAndValue(CanberraColorInfo.identifier)) { - _canberraLineColor = dictionary.value(CanberraColorInfo.identifier); + // Create + for (int siteIndex = 0; siteIndex < siteNames.size(); siteIndex++) + { + const char* str = siteNames.at(siteIndex).c_str(); + openspace::properties::Property::PropertyInfo SiteColorsInfo = { + str, + str, + "This value determines the RGB main color for signals " + "of communication to and from different sites on Earth." + }; + std::string site = siteNames[siteIndex]; + glm::vec3 siteColor = colorDictionary.value(siteNames.at(siteIndex)); + _siteColors.push_back(std::make_unique(SiteColorsInfo, siteColor, glm::vec3(0.f), glm::vec3(1.f))); + _siteToIndex[siteNames.at(siteIndex)] = siteIndex; + addProperty(_siteColors.back().get()); + } } - else { - _canberraLineColor = glm::vec3(0.f, 1.f, 0.f); - } - addProperty(_canberraLineColor); - if (dictionary.hasKeyAndValue(GoldstoneColorInfo.identifier)) { - _goldstoneLineColor = dictionary.value(GoldstoneColorInfo.identifier); - } - else { - _goldstoneLineColor = glm::vec3(0.f, 0.f, 1.f); - } - addProperty(_goldstoneLineColor); + if (dictionary.hasKeyAndValue(KeyStationSites)) { + ghoul::Dictionary stationDictionary = dictionary.value(KeyStationSites); + std::vector keys = stationDictionary.keys(); + for (int i = 0; i < keys.size(); i++) + { + std::string station = keys.at(i); + std::string site = stationDictionary.value(keys.at(i)); + _stationToSite[station] = site; + } + } + if (dictionary.hasKeyAndValue(LineWidthInfo.identifier)) { _lineWidth = static_cast(dictionary.value( LineWidthInfo.identifier @@ -367,7 +358,8 @@ void RenderableSignals::extractData(std::unique_ptr &dictiona void RenderableSignals::pushSignalDataToVertexArray(SignalManager::Signal signal) { - ColorVBOLayout color = getSiteColor(signal.dishName); + glm::dvec4 color = { getStationColor(signal.dishName), 1.0 }; + //glm::vec4 color = { signal.color, 1.0 }; glm::vec3 posStation = getPositionForGeocentricSceneGraphNode(signal.dishName.c_str()); glm::vec3 posSpacecraft = getSuitablePrecisionPositionForSceneGraphNode(signal.spacecraft.c_str()); @@ -477,46 +469,23 @@ glm::dvec3 RenderableSignals::convertRaDecRangeToCartesian() { return raDecPos; } +glm::vec3 RenderableSignals::getStationColor(std::string dishidentifier) { -RenderableSignals::ColorVBOLayout RenderableSignals::getSiteColor(std::string dishidentifier) { - - glm::vec3 color(0.0f,0.0f,0.0f); - RenderableSignals::ColorVBOLayout colorVbo; - SiteEnum site; + glm::dvec3 color(0.0f, 0.0f, 1.0f); + std::string site; try { - site = StationToSiteConversion.at(dishidentifier); + site = _stationToSite.at(dishidentifier); } catch (const std::exception& e) { LERROR(fmt::format("Station {} has no site location.", dishidentifier)); } - switch (site) { - case 0: - color = _goldstoneLineColor; - break; - case 1: - color = _madridLineColor; - break; - case 2: - color = _canberraLineColor; - break; - } + int siteIndex = _siteToIndex.at(site); + color = _siteColors[siteIndex]->value(); - colorVbo.r = color.r; - colorVbo.g = color.g; - colorVbo.b = color.b; - - //have different alpha for the 70m antennas - if (dishidentifier == "DSS14" || dishidentifier == "DSS63" || dishidentifier == "DSS43") - { - colorVbo.a = 1.0; - } - else { - colorVbo.a = 0.6f; - } - - return colorVbo; + return color; } + } // namespace openspace diff --git a/modules/dsn/rendering/renderablesignals.h b/modules/dsn/rendering/renderablesignals.h index c8bc6c23df..f6e46bcf8b 100644 --- a/modules/dsn/rendering/renderablesignals.h +++ b/modules/dsn/rendering/renderablesignals.h @@ -90,10 +90,12 @@ namespace openspace { glm::dvec3 getEstimatedCoordinatePosFromFocusNode(glm::vec3 pos); /* Converts the Ra Dec range coordinates into cartesian coordinates*/ glm::dvec3 convertRaDecRangeToCartesian(); - /*Returns a position for a spacecraft*/ + /* Returns a position for a spacecraft*/ glm::vec3 getSuitablePrecisionPositionForSceneGraphNode(std::string id); - /*Returns a position for a station that has Earth as parent*/ + /* Returns a position for a station that has Earth as parent*/ glm::vec3 getPositionForGeocentricSceneGraphNode(const char* id); + /* Returns a color based on what site the station is located to */ + glm::vec3 getStationColor(std::string dishidentifier); /* The VBO layout of the vertex position */ struct PositionVBOLayout { @@ -104,9 +106,6 @@ namespace openspace { float r, g, b, a; }; - /* The function deciding what color to use for a signal */ - // Todo: move to asset file - ColorVBOLayout getSiteColor(std::string dishIdentifier); const char* _identifier = "Signals"; protected: @@ -142,10 +141,14 @@ namespace openspace { /// Set of information about the main rendering parts RenderInformation _lineRenderInformation; - /// Specifies the base color of the site lines - properties::Vec3Property _madridLineColor; - properties::Vec3Property _goldstoneLineColor; - properties::Vec3Property _canberraLineColor; + /// Specifies the base color for the different sites + std::vector> _siteColors; + + /// Maps a station identifier to a site location + std::map _stationToSite; + + /// Maps a site location to an index in the _siteColors property vector + std::map _siteToIndex; /// The attribute location for vertex position const GLuint _locVer = 0; @@ -166,30 +169,6 @@ namespace openspace { UniformCache(modelViewStation, modelViewSpacecraft, projection) _uniformCache; - enum SiteEnum { - GoldStone = 0, - Madrid, - Canberra - }; - - // Todo: move to asset file - // Key Value map of stations and their sites - const std::map StationToSiteConversion = { - { "DSS14", GoldStone }, - { "DSS15", GoldStone }, - { "DSS24", GoldStone }, - { "DSS25", GoldStone }, - { "DSS26", GoldStone }, - { "DSS43", Canberra }, - { "DSS34", Canberra }, - { "DSS35", Canberra }, - { "DSS36", Canberra }, - { "DSS45", Canberra }, - { "DSS63", Madrid }, - { "DSS65", Madrid }, - { "DSS54", Madrid }, - { "DSS55", Madrid } - }; /*Checks if the current time is within a signal's start and endtime*/ bool isSignalActive(double currentTime, std::string signalStartTime, std::string signalEndTime); From 1d12c82cf9b2f19d28674b05c3f6205080905382 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 13 Nov 2018 08:03:38 -0500 Subject: [PATCH 08/12] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 29829ac11a..30a5be7593 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 29829ac11a99df218ece3c8501269afce84f8e3f +Subproject commit 30a5be75933400b59dda36593c25be2be1ff2f9d From 1632c09af37829b3317c4b4a591b1e0ef0bfc8be Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Tue, 13 Nov 2018 14:09:14 +0100 Subject: [PATCH 09/12] Coordinate Axes * Add coordinate axes renderable * Add debug helper * Add example asset * Fix bug with dynamic loading of assets. (#763) --- .../assets/examples/debugcoordinateaxes.asset | 19 ++ data/assets/util/debug_helper.asset | 133 +++++++++ include/openspace/engine/openspaceengine.h | 2 +- modules/base/CMakeLists.txt | 6 + modules/base/basemodule.cpp | 2 + .../rendering/renderablecartesianaxes.cpp | 275 ++++++++++++++++++ .../base/rendering/renderablecartesianaxes.h | 75 +++++ modules/base/shaders/axes_fs.glsl | 49 ++++ modules/base/shaders/axes_vs.glsl | 46 +++ src/engine/openspaceengine.cpp | 5 +- src/scene/sceneinitializer.cpp | 48 +-- 11 files changed, 635 insertions(+), 25 deletions(-) create mode 100644 data/assets/examples/debugcoordinateaxes.asset create mode 100644 data/assets/util/debug_helper.asset create mode 100644 modules/base/rendering/renderablecartesianaxes.cpp create mode 100644 modules/base/rendering/renderablecartesianaxes.h create mode 100644 modules/base/shaders/axes_fs.glsl create mode 100644 modules/base/shaders/axes_vs.glsl diff --git a/data/assets/examples/debugcoordinateaxes.asset b/data/assets/examples/debugcoordinateaxes.asset new file mode 100644 index 0000000000..e975e1b526 --- /dev/null +++ b/data/assets/examples/debugcoordinateaxes.asset @@ -0,0 +1,19 @@ +local transforms = asset.require('scene/solarsystem/planets/earth/transforms') +local debugHelper = asset.require('util/debug_helper') + +local earthRadius = 6.371E6 + +debugHelper.registerCartesianAxes(asset, { + Parent = transforms.EarthBarycenter.Identifier, + Scale = earthRadius * 3.5 +}) + +debugHelper.registerCartesianAxes(asset, { + Parent = transforms.EarthInertial.Identifier, + Scale = earthRadius * 2.5 +}) + +debugHelper.registerCartesianAxes(asset, { + Parent = transforms.EarthIAU.Identifier, + Scale = earthRadius * 1.5 +}) diff --git a/data/assets/util/debug_helper.asset b/data/assets/util/debug_helper.asset new file mode 100644 index 0000000000..2a1175ee84 --- /dev/null +++ b/data/assets/util/debug_helper.asset @@ -0,0 +1,133 @@ +local identifierGeneratorFunction = function (suffix) + local nextIndex = 0 + return function (specification) + nextIndex = nextIndex + 1 + return specification.Identifier or + (specification.Parent .. suffix .. nextIndex) + end +end + +local generateGridIdentifier = identifierGeneratorFunction("Grid") + +local addGrid = function (specification) + local identifier = specification.Identifier or + generateGridIdentifier(specification) + + local name = specification.Name + local color = specification.Color + local parent = specification.Parent + local scale = specification.Scale + local position = specification.Position + local rotation = specification.Rotation + + local grid = { + Identifier = identifier, + Parent = parent, + Transform = { + Scale = { + Type = "StaticScale", + Scale = scale; + }, + Translation = { + Type = "StaticTranslation", + Position = position + }, + Rotation = { + Type = "StaticRotation", + Rotation = rotation + } + }, + Renderable = { + Type = "RenderableSphericalGrid", + Enabled = true, + LineWidth = 2.0, + GridColor = color + }, + GUI = { + Name = name, + Path = "/Other/Grids" + } + } + openspace.addSceneGraphNode(grid) + return identifier; +end + +local generateAxesIdentifier = identifierGeneratorFunction("Axes") + +local addCartesianAxes = function (specification) + local identifier = specification.Identifier or + generateAxesIdentifier(specification) + + local name = specification.Name or specification.Identifier + local parent = specification.Parent or "Root" + local scale = specification.Scale or 1.0 + local position = specification.Position or {0.0, 0.0, 0.0} + local rotation = specification.Rotation or {0.0, 0.0, 0.0} + + local axes = { + Identifier = identifier, + Parent = parent, + Transform = { + Scale = { + Type = "StaticScale", + Scale = scale; + }, + Translation = { + Type = "StaticTranslation", + Position = position + }, + Rotation = { + Type = "StaticRotation", + Rotation = rotation + } + }, + Renderable = { + Type = "RenderableCartesianAxes", + Enabled = true, + XColor = {1.0, 0.0, 0.0, 1.0}, + YColor = {0.0, 1.0, 0.0, 1.0}, + ZColor = {0.0, 0.0, 1.0, 1.0} + }, + GUI = { + Name = name, + Path = "/Other/Coordinate Systems" + } + } + openspace.addSceneGraphNode(axes) + return identifier; +end + + +local registerNode = function( + containerAsset, + nodeCreationFunction, + identifierGeneratorFunction, + specification +) + local identifier = specification.Identifier or + identifierGeneratorFunction(specification) + + specification.Identifier = identifier + + containerAsset.onInitialize(function () + nodeCreationFunction(specification) + end) + containerAsset.onDeinitialize(function () + openspace.removeSceneGraphNode(identifier) + end) +end + +local registerGrid = function(gridAsset, specification) + registerNode(gridAsset, addGrid, generateGridIdentifier, specification) +end + +local registerCartesianAxes = function(axesAsset, specification) + registerNode(axesAsset, addCartesianAxes, generateAxesIdentifier, specification) +end + +asset.export("addGrid", addGrid) +asset.export("registerGrid", registerGrid) + +asset.export("addCartesianAxes", addGrid) +asset.export("registerCartesianAxes", registerCartesianAxes) + diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 5fb860fff1..921a658c0c 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -88,7 +88,7 @@ public: // Guaranteed to return a valid pointer AssetManager& assetManager(); - LoadingScreen& loadingScreen(); + LoadingScreen* loadingScreen(); void writeSceneDocumentation(); void writeStaticDocumentation(); diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index ad38bfb017..117b53a7f7 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -39,6 +39,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/scenegraphlightsource.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecartesianaxes.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimagelocal.h @@ -81,6 +82,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/scenegraphlightsource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecartesianaxes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimagelocal.cpp @@ -109,6 +111,10 @@ set(SOURCE_FILES source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/axes_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/axes_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/grid_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/grid_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/model_fs.glsl diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index ca6c8e1baa..be13023c2c 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -116,6 +117,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "Renderable factory was not created"); + fRenderable->registerClass("RenderableCartesianAxes"); fRenderable->registerClass("RenderableModel"); fRenderable->registerClass("RenderablePlaneImageLocal"); fRenderable->registerClass("RenderablePlaneImageOnline"); diff --git a/modules/base/rendering/renderablecartesianaxes.cpp b/modules/base/rendering/renderablecartesianaxes.cpp new file mode 100644 index 0000000000..283a80924b --- /dev/null +++ b/modules/base/rendering/renderablecartesianaxes.cpp @@ -0,0 +1,275 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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 + +namespace { + constexpr const char* ProgramName = "CartesianAxesProgram"; + const int NVertexIndices = 6; + + constexpr openspace::properties::Property::PropertyInfo XColorInfo = { + "XColor", + "X Color", + "This value determines the color of the x axis." + }; + + constexpr openspace::properties::Property::PropertyInfo YColorInfo = { + "YColor", + "Y Color", + "This value determines the color of the y axis." + }; + + constexpr openspace::properties::Property::PropertyInfo ZColorInfo = { + "ZColor", + "Z Color", + "This value determines the color of the z axis." + }; +} // namespace + +namespace openspace { + +documentation::Documentation RenderableCartesianAxes::Documentation() { + using namespace documentation; + return { + "CartesianAxesProgram", + "base_renderable_cartesianaxes", + { + { + XColorInfo.identifier, + new DoubleVector4Verifier, + Optional::Yes, + XColorInfo.description + }, + { + YColorInfo.identifier, + new DoubleVector4Verifier, + Optional::Yes, + YColorInfo.description + }, + { + ZColorInfo.identifier, + new DoubleVector4Verifier, + Optional::Yes, + ZColorInfo.description + } + } + }; +} + + +RenderableCartesianAxes::RenderableCartesianAxes(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _program(nullptr) + , _xColor( + XColorInfo, + glm::vec4(0.f, 0.f, 0.f, 1.f), + glm::vec4(0.f), + glm::vec4(1.f) + ) + , _yColor( + YColorInfo, + glm::vec4(0.f, 1.f, 0.f, 1.f), + glm::vec4(0.f), + glm::vec4(1.f) + ) + , _zColor( + ZColorInfo, + glm::vec4(0.f, 0.f, 1.f, 1.f), + glm::vec4(0.f), + glm::vec4(1.f) + ) +{ + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "RenderableCartesianAxes" + ); + + if (dictionary.hasKey(XColorInfo.identifier)) { + _xColor = dictionary.value(XColorInfo.identifier); + } + _xColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_xColor); + + if (dictionary.hasKey(XColorInfo.identifier)) { + _yColor = dictionary.value(YColorInfo.identifier); + } + _yColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_yColor); + + if (dictionary.hasKey(ZColorInfo.identifier)) { + _zColor = dictionary.value(ZColorInfo.identifier); + } + _zColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_zColor); +} + +bool RenderableCartesianAxes::isReady() const { + bool ready = true; + ready &= (_program != nullptr); + return ready; +} + +void RenderableCartesianAxes::initializeGL() { + _program = BaseModule::ProgramObjectManager.request( + ProgramName, + []() -> std::unique_ptr { + return global::renderEngine.buildRenderProgram( + ProgramName, + absPath("${MODULE_BASE}/shaders/axes_vs.glsl"), + absPath("${MODULE_BASE}/shaders/axes_fs.glsl") + ); + } + ); + + glGenVertexArrays(1, &_vaoId); + glGenBuffers(1, &_vBufferId); + glGenBuffers(1, &_iBufferId); + + glBindVertexArray(_vaoId); + glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); + glEnableVertexAttribArray(0); + glBindVertexArray(0); + + std::vector vertices({ + Vertex{0.f, 0.f, 0.f}, + Vertex{1.f, 0.f, 0.f}, + Vertex{0.f, 1.f, 0.f}, + Vertex{0.f, 0.f, 1.f} + }); + + std::vector indices = { + 0, 1, + 0, 2, + 0, 3 + }; + + glBindVertexArray(_vaoId); + glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); + glBufferData( + GL_ARRAY_BUFFER, + vertices.size() * sizeof(Vertex), + vertices.data(), + GL_STATIC_DRAW + ); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); + glBufferData( + GL_ELEMENT_ARRAY_BUFFER, + indices.size() * sizeof(int), + indices.data(), + GL_STATIC_DRAW + ); +} + +void RenderableCartesianAxes::deinitializeGL() { + glDeleteVertexArrays(1, &_vaoId); + _vaoId = 0; + + glDeleteBuffers(1, &_vBufferId); + _vBufferId = 0; + + glDeleteBuffers(1, &_iBufferId); + _iBufferId = 0; + + BaseModule::ProgramObjectManager.release( + ProgramName, + [](ghoul::opengl::ProgramObject* p) { + global::renderEngine.removeRenderProgram(p); + } + ); + _program = nullptr; +} + +void RenderableCartesianAxes::render(const RenderData& data, RendererTasks&){ + _program->activate(); + + const glm::dmat4 modelTransform = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * + glm::dmat4(data.modelTransform.rotation) * + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); + + const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * + modelTransform; + + _program->setUniform("modelViewTransform", glm::mat4(modelViewTransform)); + _program->setUniform("projectionTransform", data.camera.projectionMatrix()); + + _program->setUniform("xColor", _xColor); + _program->setUniform("yColor", _yColor); + _program->setUniform("zColor", _zColor); + + // Saves current state: + GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0); + GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH); + GLfloat currentLineWidth; + glGetFloatv(GL_LINE_WIDTH, ¤tLineWidth); + + GLenum blendEquationRGB, blendEquationAlpha, blendDestAlpha, + blendDestRGB, blendSrcAlpha, blendSrcRGB; + glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); + glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); + glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); + glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB); + glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha); + glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB); + + // Changes GL state: + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnablei(GL_BLEND, 0); + glEnable(GL_LINE_SMOOTH); + + glBindVertexArray(_vaoId); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); + glDrawElements(GL_LINES, NVertexIndices, GL_UNSIGNED_INT, nullptr); + glBindVertexArray(0); + + _program->deactivate(); + + // Restores GL State + glLineWidth(currentLineWidth); + glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha); + glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha); + if (!isBlendEnabled) { + glDisablei(GL_BLEND, 0); + } + if (!isLineSmoothEnabled) { + glDisable(GL_LINE_SMOOTH); + } +} + +} // namespace openspace diff --git a/modules/base/rendering/renderablecartesianaxes.h b/modules/base/rendering/renderablecartesianaxes.h new file mode 100644 index 0000000000..9444461180 --- /dev/null +++ b/modules/base/rendering/renderablecartesianaxes.h @@ -0,0 +1,75 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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___RENDERABLECARTESIANAXES___H__ +#define __OPENSPACE_MODULE_BASE___RENDERABLECARTESIANAXES___H__ + +#include + +#include +#include +#include +#include +#include +#include + +namespace ghoul::opengl { class ProgramObject; } + +namespace openspace::documentation { struct Documentation; } + +namespace openspace { + +class RenderableCartesianAxes : public Renderable { +public: + RenderableCartesianAxes(const ghoul::Dictionary& dictionary); + ~RenderableCartesianAxes() = default; + + void initializeGL() override; + void deinitializeGL() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + + static documentation::Documentation Documentation(); + +protected: + struct Vertex { + float location[3]; + }; + + ghoul::opengl::ProgramObject* _program; + + properties::Vec4Property _xColor; + properties::Vec4Property _yColor; + properties::Vec4Property _zColor; + + GLuint _vaoId = 0; + GLuint _vBufferId = 0; + GLuint _iBufferId = 0; +}; + +}// namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___RENDERABLECARTESIANAXES___H__ diff --git a/modules/base/shaders/axes_fs.glsl b/modules/base/shaders/axes_fs.glsl new file mode 100644 index 0000000000..1dcf78e416 --- /dev/null +++ b/modules/base/shaders/axes_fs.glsl @@ -0,0 +1,49 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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 "fragment.glsl" +#include "PowerScaling/powerScaling_fs.hglsl" + +in float vs_screenSpaceDepth; +in vec4 vs_positionViewSpace; +in vec3 vs_positionModelSpace; + +uniform vec4 xColor; +uniform vec4 yColor; +uniform vec4 zColor; + +Fragment getFragment() { + Fragment frag; + + vec3 colorComponents = step(0.01f, vs_positionModelSpace); + + frag.color = colorComponents.x * xColor + + colorComponents.y * yColor + + colorComponents.z * zColor; + + frag.depth = vs_screenSpaceDepth; + frag.gPosition = vs_positionViewSpace; + frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + return frag; +} diff --git a/modules/base/shaders/axes_vs.glsl b/modules/base/shaders/axes_vs.glsl new file mode 100644 index 0000000000..b20e90f8e2 --- /dev/null +++ b/modules/base/shaders/axes_vs.glsl @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +layout(location = 0) in vec3 in_position; + +out float vs_screenSpaceDepth; +out vec4 vs_positionViewSpace; +out vec3 vs_positionModelSpace; + +uniform mat4 modelViewTransform; +uniform mat4 projectionTransform; + +void main() { + vec4 positionViewSpace = modelViewTransform * vec4(in_position, 1.0); + vec4 positionClipSpace = projectionTransform * positionViewSpace; + vec4 positionScreenSpace = positionClipSpace; + positionScreenSpace.z = 0.f; + vs_positionModelSpace = in_position; + vs_screenSpaceDepth = positionScreenSpace.w; + vs_positionViewSpace = positionViewSpace; + + gl_Position = positionScreenSpace; +} diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 9ccf4dd613..460135707b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1344,9 +1344,8 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { }; } -LoadingScreen& OpenSpaceEngine::loadingScreen() { - ghoul_assert(_loadingScreen, "Loading Screen must not be nullptr"); - return *_loadingScreen; +LoadingScreen* OpenSpaceEngine::loadingScreen() { + return _loadingScreen.get(); } AssetManager& OpenSpaceEngine::assetManager() { diff --git a/src/scene/sceneinitializer.cpp b/src/scene/sceneinitializer.cpp index 9a220bf2c4..a1ed44669d 100644 --- a/src/scene/sceneinitializer.cpp +++ b/src/scene/sceneinitializer.cpp @@ -52,41 +52,47 @@ MultiThreadedSceneInitializer::MultiThreadedSceneInitializer(unsigned int nThrea void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { auto initFunction = [this, node]() { - LoadingScreen& loadingScreen = global::openSpaceEngine.loadingScreen(); + LoadingScreen* loadingScreen = global::openSpaceEngine.loadingScreen(); LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = 1.f; - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Initializing, - progressInfo - ); + if (loadingScreen) { + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Initializing, + progressInfo + ); + } node->initialize(); std::lock_guard g(_mutex); _initializedNodes.push_back(node); _initializingNodes.erase(node); - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Finished, - progressInfo - ); + if (loadingScreen) { + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Finished, + progressInfo + ); + } }; LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = 0.f; - LoadingScreen& loadingScreen = global::openSpaceEngine.loadingScreen(); - loadingScreen.setItemNumber(loadingScreen.itemNumber() + 1); - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Started, - progressInfo - ); + LoadingScreen* loadingScreen = global::openSpaceEngine.loadingScreen(); + if (loadingScreen) { + loadingScreen->setItemNumber(loadingScreen->itemNumber() + 1); + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Started, + progressInfo + ); + } std::lock_guard g(_mutex); _initializingNodes.insert(node); From 9a368ede256d2d0e492b01161608965e5de88998 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 13 Nov 2018 08:27:07 -0500 Subject: [PATCH 10/12] Fix issue that causes atmosphere to show up on the other side of a planet if the shading is disabled (closes #677) --- modules/globebrowsing/shaders/renderer_fs.glsl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/globebrowsing/shaders/renderer_fs.glsl b/modules/globebrowsing/shaders/renderer_fs.glsl index 912399ab46..0446156bf8 100644 --- a/modules/globebrowsing/shaders/renderer_fs.glsl +++ b/modules/globebrowsing/shaders/renderer_fs.glsl @@ -248,7 +248,13 @@ Fragment getFragment() { // because all calculation for light interactions are done in Object // Space, we avoid a new computation saving the normals in Object Space. frag.gNormal.xyz = normalModelSpace; - frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space + + if (dot(positionCameraSpace, vec3(1.0)) != 0.0) { + frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space + } + else { + frag.gPosition = vec4(1.0); // in Camera Rig Space + } frag.depth = fs_position.w; From dbe90fd94b736603bd972f0cccf78d12eeb7be28 Mon Sep 17 00:00:00 2001 From: Lovisa Hassler Date: Tue, 13 Nov 2018 11:51:48 -0500 Subject: [PATCH 11/12] cleanup and renaming some variables --- modules/dsn/managers/signalmanager.h | 6 --- modules/dsn/rendering/renderablesignals.cpp | 41 ++++----------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/modules/dsn/managers/signalmanager.h b/modules/dsn/managers/signalmanager.h index d24fca52a0..7052059f06 100644 --- a/modules/dsn/managers/signalmanager.h +++ b/modules/dsn/managers/signalmanager.h @@ -30,12 +30,6 @@ #include #include - -//#include -//#include -//#include -//#include -//#include #include #include diff --git a/modules/dsn/rendering/renderablesignals.cpp b/modules/dsn/rendering/renderablesignals.cpp index b911611523..1828c28074 100644 --- a/modules/dsn/rendering/renderablesignals.cpp +++ b/modules/dsn/rendering/renderablesignals.cpp @@ -43,7 +43,6 @@ namespace { constexpr const char* _loggerCat = "RenderableSignals"; constexpr const char* KeyStationSites = "StationSites"; - constexpr const std::array UniformNames = { "modelViewStation","modelViewSpacecraft", "projectionTransform" }; @@ -51,8 +50,8 @@ namespace { constexpr openspace::properties::Property::PropertyInfo SiteColorsInfo = { "SiteColors", "SiteColors", - "This value determines the RGB main color for the lines " - "of communication to and from different sites on Earth." + "This value determines the RGB main color for the communication " + "signals to and from different sites on Earth." }; constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { @@ -71,13 +70,6 @@ documentation::Documentation RenderableSignals::Documentation() { "Renderable Signals", "dsn_renderable_renderablesignals", { - { - KeyTranslation, - new ReferencingVerifier("core_transform_translation"), - Optional::No, - "This object is used to compute locations along the path. Any " - "Translation object can be used here." - }, { SiteColorsInfo.identifier, new TableVerifier, @@ -105,27 +97,21 @@ RenderableSignals::RenderableSignals(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _lineWidth(LineWidthInfo, 2.f, 1.f, 20.f) { - _translation = Translation::createFromDictionary( - dictionary.value(KeyTranslation) - ); - addPropertySubOwner(_translation.get()); - if (dictionary.hasKeyAndValue(SiteColorsInfo.identifier)) { - ghoul::Dictionary colorDictionary = dictionary.value(SiteColorsInfo.identifier); - std::vector siteNames = colorDictionary.keys(); + ghoul::Dictionary siteColorDictionary = dictionary.value(SiteColorsInfo.identifier); + std::vector siteNames = siteColorDictionary.keys(); - // Create for (int siteIndex = 0; siteIndex < siteNames.size(); siteIndex++) { - const char* str = siteNames.at(siteIndex).c_str(); + const char* siteColorIdentifier = siteNames.at(siteIndex).c_str(); openspace::properties::Property::PropertyInfo SiteColorsInfo = { - str, - str, + siteColorIdentifier, + siteColorIdentifier, "This value determines the RGB main color for signals " "of communication to and from different sites on Earth." }; std::string site = siteNames[siteIndex]; - glm::vec3 siteColor = colorDictionary.value(siteNames.at(siteIndex)); + glm::vec3 siteColor = siteColorDictionary.value(siteNames.at(siteIndex)); _siteColors.push_back(std::make_unique(SiteColorsInfo, siteColor, glm::vec3(0.f), glm::vec3(1.f))); _siteToIndex[siteNames.at(siteIndex)] = siteIndex; addProperty(_siteColors.back().get()); @@ -243,8 +229,6 @@ void RenderableSignals::render(const RenderData& data, RendererTasks&) { _programObject->deactivate(); } - - void RenderableSignals::update(const UpdateData& data) { double currentTime = data.time.j2000Seconds(); @@ -311,7 +295,6 @@ void RenderableSignals::update(const UpdateData& data) { unbindGL(); } - int RenderableSignals::findFileIndexForCurrentTime(double time, std::vector vec) { // upper_bound has O(log n) for sorted vectors, more efficient than for loop auto iter = std::upper_bound(vec.begin(), vec.end(), time); @@ -355,11 +338,9 @@ void RenderableSignals::extractData(std::unique_ptr &dictiona } } - void RenderableSignals::pushSignalDataToVertexArray(SignalManager::Signal signal) { glm::dvec4 color = { getStationColor(signal.dishName), 1.0 }; - //glm::vec4 color = { signal.color, 1.0 }; glm::vec3 posStation = getPositionForGeocentricSceneGraphNode(signal.dishName.c_str()); glm::vec3 posSpacecraft = getSuitablePrecisionPositionForSceneGraphNode(signal.spacecraft.c_str()); @@ -400,7 +381,6 @@ glm::dvec3 RenderableSignals::getCoordinatePosFromFocusNode(SceneGraphNode* node return diff; } - glm::vec3 RenderableSignals::getSuitablePrecisionPositionForSceneGraphNode(std::string id) { glm::vec3 position; @@ -411,13 +391,11 @@ glm::vec3 RenderableSignals::getSuitablePrecisionPositionForSceneGraphNode(std:: } else { LERROR(fmt::format("No scengraphnode found for the spacecraft {}", id)); - } return position; } - glm::vec3 RenderableSignals::getPositionForGeocentricSceneGraphNode(const char* id) { glm::dvec3 position; @@ -433,8 +411,6 @@ glm::vec3 RenderableSignals::getPositionForGeocentricSceneGraphNode(const char* return position; } - - glm::vec3 RenderableSignals::getStationColor(std::string dishidentifier) { glm::dvec3 color(0.0f, 0.0f, 1.0f); @@ -453,5 +429,4 @@ glm::vec3 RenderableSignals::getStationColor(std::string dishidentifier) { return color; } - } // namespace openspace From 8b881ae89ea094e8dac8b433517ed243c968ec6a Mon Sep 17 00:00:00 2001 From: Lovisa Hassler Date: Tue, 13 Nov 2018 12:29:21 -0500 Subject: [PATCH 12/12] renamed communicationlines asset file renamed the communicationlines asset to signals fix --- data/assets/dsn.scene | 7 ++++--- .../{communicationlines.asset => signals.asset} | 6 +----- modules/dsn/rendering/renderablesignals.cpp | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) rename data/assets/scene/solarsystem/dsn/communicationlines/{communicationlines.asset => signals.asset} (77%) diff --git a/data/assets/dsn.scene b/data/assets/dsn.scene index 05d7f00247..a2f30d79e6 100644 --- a/data/assets/dsn.scene +++ b/data/assets/dsn.scene @@ -14,14 +14,15 @@ asset.request('scene/digitaluniverse/grids') asset.require('scene/solarsystem/missions/voyager1/voyager1') asset.require('scene/solarsystem/missions/voyager2/voyager2') asset.require('scene/solarsystem/missions/voyager1/trails') +asset.require('scene/solarsystem/dsn/spacecrafts') -- Stations asset.require('scene/solarsystem/dsn/stations') ---Communication +--Signals --assetHelper.requestAll(asset, 'scene/solarsystem/dsn') -asset.require('scene/solarsystem/dsn/communicationlines/communicationlines') -asset.require('scene/solarsystem/dsn/spacecrafts') +asset.require('scene/solarsystem/dsn/communicationlines/signals') + -- Load default key bindings applicable to most scenes asset.require('util/default_keybindings') diff --git a/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset b/data/assets/scene/solarsystem/dsn/communicationlines/signals.asset similarity index 77% rename from data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset rename to data/assets/scene/solarsystem/dsn/communicationlines/signals.asset index 59441be63c..d149672ee9 100644 --- a/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset +++ b/data/assets/scene/solarsystem/dsn/communicationlines/signals.asset @@ -1,16 +1,12 @@ local assetHelper = asset.require('util/asset_helper') local stationsAsset = asset.require('scene/solarsystem/dsn/stations') ---Communicationline data +--Signals data local dataFolder = openspace.absPath("../../../sync/http/dsn_data/1/json") local Signals = { Identifier = "Signals", Renderable = { - Translation = { - Type = "RadecTranslation", - Position = {0.0, 0.0, 0.0} --no parent, sun center is 0, 0, 0 - }, Type = "RenderableSignals", DataFolder = dataFolder, DataFileType = "json", diff --git a/modules/dsn/rendering/renderablesignals.cpp b/modules/dsn/rendering/renderablesignals.cpp index 1828c28074..9c784349ca 100644 --- a/modules/dsn/rendering/renderablesignals.cpp +++ b/modules/dsn/rendering/renderablesignals.cpp @@ -39,7 +39,6 @@ namespace { constexpr const char* ProgramName = "SignalsProgram"; - constexpr const char* KeyTranslation = "Translation"; constexpr const char* _loggerCat = "RenderableSignals"; constexpr const char* KeyStationSites = "StationSites";