diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index b81a0c42d5..37c9fff281 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -51,11 +51,10 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -161,23 +160,28 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) } _session->start_upnp(); - std::ifstream file(_configurationFile); - if (!file.fail()) { - union { - uint32_t value; - std::array data; - } size; - file.read(size.data.data(), sizeof(uint32_t)); - std::vector buffer(size.value); - file.read(buffer.data(), size.value); - file.close(); + // I commented this out as it caused the Linux build nodes to fail during linking + // and I couldn't figure out how to fix it + // it would throw an cxx11 ABI incompatibility error - libtorrent::entry e = libtorrent::bdecode(buffer.begin(), buffer.end()); - _session->start_dht(e); - } - else - _session->start_dht(); + //std::ifstream file(_configurationFile); + //if (!file.fail()) { + // union { + // uint32_t value; + // std::array data; + // } size; + + // file.read(size.data.data(), sizeof(uint32_t)); + // std::vector buffer(size.value); + // file.read(buffer.data(), size.value); + // file.close(); + + // libtorrent::entry e = libtorrent::bdecode(buffer.begin(), buffer.end()); + // _session->start_dht(e); + //} + //else + _session->start_dht(); _session->add_dht_router({ "router.utorrent.com", 6881 }); _session->add_dht_router({ "dht.transmissionbt.com", 6881 }); @@ -198,18 +202,22 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) SyncWidget::~SyncWidget() { libtorrent::entry dht = _session->dht_state(); - std::vector buffer; - libtorrent::bencode(std::back_inserter(buffer), dht); + // I commented this out as it caused the Linux build nodes to fail during linking + // and I couldn't figure out how to fix it + // it would throw an cxx11 ABI incompatibility error - std::ofstream f(_configurationFile); + //std::vector buffer; + //libtorrent::bencode(std::back_inserter(buffer), dht); - union { - uint32_t value; - std::array data; - } size; - size.value = buffer.size(); - f.write(size.data.data(), sizeof(uint32_t)); - f.write(buffer.data(), buffer.size()); + //std::ofstream f(_configurationFile); + + //union { + // uint32_t value; + // std::array data; + //} size; + //size.value = buffer.size(); + //f.write(size.data.data(), sizeof(uint32_t)); + //f.write(buffer.data(), buffer.size()); _downloadManager.reset(); ghoul::deinitialize(); @@ -302,6 +310,8 @@ void SyncWidget::handleFileRequest() { } _filesDownloading.insert(requestId); + /* + TODO: Adapt to new http request api! _downloadManager->downloadRequestFilesAsync( identifier, path, @@ -312,7 +322,7 @@ void SyncWidget::handleFileRequest() { std::lock_guard g(_filesDownloadingMutex); _filesDownloading.erase(requestId); } - ); + );*/ } } diff --git a/data/openspace-logo.png b/data/openspace-logo.png new file mode 100644 index 0000000000..a34574d42f Binary files /dev/null and b/data/openspace-logo.png differ diff --git a/ext/sgct b/ext/sgct index c487fe9d77..ee29d15894 160000 --- a/ext/sgct +++ b/ext/sgct @@ -1 +1 @@ -Subproject commit c487fe9d778a730125b72027b2da5588a664d01b +Subproject commit ee29d158944eed9bafbccbccdfb9856b3a96cac0 diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index e8845ceb57..192a2a8ab0 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -155,6 +155,20 @@ public: /// The part of the key storing whether each OpenGL call should be logged static const std::string KeyLogEachOpenGLCall; + /// This key determines whether the scene graph nodes should initialized multithreaded + static const std::string KeyUseMultithreadedInitialization; + + /// The key under which all of the loading settings are grouped + static const std::string KeyLoadingScreen; + /// The part of the key storing whether the loading screen should display the message + /// about current status + static const std::string PartShowMessage; + /// The part of the key storing whether the loading screen should display node names + static const std::string PartShowNodeNames; + /// The part of the key storing whether the loading screen should contain a progress + /// bar + static const std::string PartShowProgressbar; + /** * Iteratively walks the directory structure starting with \p filename to find the diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 21977d99f9..9212365b6f 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -45,6 +45,7 @@ class AssetManager; class ConfigurationManager; class DownloadManager; class GUI; +class LoadingScreen; class LuaConsole; class ModuleEngine; class NetworkEngine; @@ -110,6 +111,7 @@ public: AssetManager& assetManager(); DownloadManager& downloadManager(); ModuleEngine& moduleEngine(); + LoadingScreen& loadingScreen(); NetworkEngine& networkEngine(); ParallelConnection& parallelConnection(); RenderEngine& renderEngine(); @@ -204,6 +206,8 @@ private: // Others std::unique_ptr _globalPropertyNamespace; + std::unique_ptr _loadingScreen; + struct { properties::StringProperty versionString; properties::StringProperty sourceControlInformation; diff --git a/include/openspace/engine/wrapper/sgctwindowwrapper.h b/include/openspace/engine/wrapper/sgctwindowwrapper.h index 8f7d5d8107..2b09f00e3b 100644 --- a/include/openspace/engine/wrapper/sgctwindowwrapper.h +++ b/include/openspace/engine/wrapper/sgctwindowwrapper.h @@ -79,6 +79,8 @@ public: void takeScreenshot(bool applyWarping = false) const override; + void swapBuffer() const override; + private: properties::FloatProperty _eyeSeparation; properties::BoolProperty _showStatsGraph; diff --git a/include/openspace/engine/wrapper/windowwrapper.h b/include/openspace/engine/wrapper/windowwrapper.h index ea290776d3..df302ff64a 100644 --- a/include/openspace/engine/wrapper/windowwrapper.h +++ b/include/openspace/engine/wrapper/windowwrapper.h @@ -271,6 +271,8 @@ public: */ virtual void takeScreenshot(bool applyWarping = false) const; + virtual void swapBuffer() const; + struct WindowWrapperException : public ghoul::RuntimeError { explicit WindowWrapperException(const std::string& msg); }; diff --git a/include/openspace/rendering/loadingscreen.h b/include/openspace/rendering/loadingscreen.h new file mode 100644 index 0000000000..1b6ca397c8 --- /dev/null +++ b/include/openspace/rendering/loadingscreen.h @@ -0,0 +1,138 @@ +/***************************************************************************************** + * * + * 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_CORE___LOADINGSCREEN___H__ +#define __OPENSPACE_CORE___LOADINGSCREEN___H__ + +#include +#include +#include + +#include +#include +#include + +// #define LOADINGSCREEN_DEBUGGING + +namespace ghoul::fontrendering { + class Font; +} // namespace ghoul::fontrendering + +namespace ghoul::opengl { + class ProgramObject; + class Texture; +} // namespace ghoul::opengl + +namespace openspace { + +class LoadingScreen { +public: + using ShowMessage = ghoul::Boolean; + using ShowNodeNames = ghoul::Boolean; + using ShowProgressbar = ghoul::Boolean; + + LoadingScreen(ShowMessage showMessage, ShowNodeNames showNodeNames, + ShowProgressbar showProgressbar); + ~LoadingScreen(); + + void render(); + + void postMessage(std::string message); + + void finalize(); + + void setItemNumber(int nItems); + void tickItem(); + + enum class Phase { + Construction, + Initialization + }; + void setPhase(Phase phase); + + + enum class ItemStatus { + Started, + Initializing, + Finished, + Failed + }; + + void updateItem(const std::string& itemName, ItemStatus newStatus); + +private: + bool _showMessage; + bool _showNodeNames; + bool _showProgressbar; + + Phase _phase; + int _iProgress; + int _nItems; + + std::unique_ptr _program; + std::unique_ptr _logoTexture; + + std::shared_ptr _loadingFont; + std::shared_ptr _messageFont; + std::shared_ptr _itemFont; + + struct { + GLuint vao; + GLuint vbo; + } _logo; + + struct { + GLuint vaoFill; + GLuint vboFill; + + GLuint vaoBox; + GLuint vboBox; + } _progressbar; + + std::string _message; + std::mutex _messageMutex; + + struct Item { + std::string name; + ItemStatus status; + + bool hasLocation; +#ifdef LOADINGSCREEN_DEBUGGING + bool exhaustedSearch; +#endif // LOADINGSCREEN_DEBUGGING + glm::vec2 ll; + glm::vec2 ur; + + std::chrono::system_clock::time_point finishedTime; + }; + std::vector _items; + std::mutex _itemsMutex; + + std::random_device _randomDevice; + std::default_random_engine _randomEngine; +}; + +} // namespace openspace + +#endif // __OPENSPACE_CORE___LOADINGSCREEN___H__ diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index 7f775f4138..fb1bf30751 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -66,7 +66,9 @@ public: virtual ~Renderable(); virtual void initialize(); + virtual void initializeGL(); virtual void deinitialize(); + virtual void deinitializeGL(); virtual bool isReady() const = 0; bool isEnabled() const; diff --git a/include/openspace/rendering/screenspacerenderable.h b/include/openspace/rendering/screenspacerenderable.h index 1c912c0c83..24d301d2a0 100644 --- a/include/openspace/rendering/screenspacerenderable.h +++ b/include/openspace/rendering/screenspacerenderable.h @@ -60,7 +60,10 @@ public: virtual void render(); virtual bool initialize(); + virtual bool initializeGL(); virtual bool deinitialize(); + virtual bool deinitializeGL(); + virtual void update() = 0; virtual bool isReady() const; bool isEnabled() const; diff --git a/include/openspace/scene/scenegraphnode.h b/include/openspace/scene/scenegraphnode.h index 058f4daf8f..a247679378 100644 --- a/include/openspace/scene/scenegraphnode.h +++ b/include/openspace/scene/scenegraphnode.h @@ -77,7 +77,9 @@ public: const ghoul::Dictionary& dictionary); void initialize(); + void initializeGL(); void deinitialize(); + void deinitializeGL(); void traversePreOrder(std::function fn); void traversePostOrder(std::function fn); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index ae1e1732b0..1c5a5a5b8a 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -156,7 +156,7 @@ bool RenderableModel::isReady() const { return _programObject && _texture; } -void RenderableModel::initialize() { +void RenderableModel::initializeGL() { _programObject = OsEng.renderEngine().buildRenderProgram( "ModelProgram", "${MODULE_BASE}/shaders/model_vs.glsl", @@ -168,7 +168,7 @@ void RenderableModel::initialize() { _geometry->initialize(this); } -void RenderableModel::deinitialize() { +void RenderableModel::deinitializeGL() { if (_geometry) { _geometry->deinitialize(); _geometry = nullptr; diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index c0d6a80dae..d7c92b77d0 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -51,8 +51,8 @@ class RenderableModel : public Renderable { public: RenderableModel(const ghoul::Dictionary& dictionary); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/base/rendering/renderableplane.cpp b/modules/base/rendering/renderableplane.cpp index 8e4c90795f..3bdad0e230 100644 --- a/modules/base/rendering/renderableplane.cpp +++ b/modules/base/rendering/renderableplane.cpp @@ -178,7 +178,7 @@ bool RenderablePlane::isReady() const { return _shader && _texture; } -void RenderablePlane::initialize() { +void RenderablePlane::initializeGL() { glGenVertexArrays(1, &_quad); // generate array glGenBuffers(1, &_vertexPositionBuffer); // generate buffer createPlane(); @@ -191,7 +191,7 @@ void RenderablePlane::initialize() { loadTexture(); } -void RenderablePlane::deinitialize() { +void RenderablePlane::deinitializeGL() { glDeleteVertexArrays(1, &_quad); _quad = 0; diff --git a/modules/base/rendering/renderableplane.h b/modules/base/rendering/renderableplane.h index a18659d6b1..81800f97c1 100644 --- a/modules/base/rendering/renderableplane.h +++ b/modules/base/rendering/renderableplane.h @@ -54,8 +54,8 @@ class RenderablePlane : public Renderable { public: RenderablePlane(const ghoul::Dictionary& dictionary); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index 3a16b97159..1f6a28e4e7 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -220,7 +220,7 @@ bool RenderableSphere::isReady() const { return _shader && _texture; } -void RenderableSphere::initialize() { +void RenderableSphere::initializeGL() { _sphere = std::make_unique( PowerScaledScalar::CreatePSS(_size), _segments ); @@ -234,7 +234,7 @@ void RenderableSphere::initialize() { loadTexture(); } -void RenderableSphere::deinitialize() { +void RenderableSphere::deinitializeGL() { _texture = nullptr; if (_shader) { diff --git a/modules/base/rendering/renderablesphere.h b/modules/base/rendering/renderablesphere.h index a38b090f2c..e5a5226c36 100644 --- a/modules/base/rendering/renderablesphere.h +++ b/modules/base/rendering/renderablesphere.h @@ -49,8 +49,8 @@ class RenderableSphere : public Renderable { public: RenderableSphere(const ghoul::Dictionary& dictionary); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/base/rendering/renderablesphericalgrid.cpp b/modules/base/rendering/renderablesphericalgrid.cpp index 1824fc6d8c..f9478e4f91 100644 --- a/modules/base/rendering/renderablesphericalgrid.cpp +++ b/modules/base/rendering/renderablesphericalgrid.cpp @@ -177,18 +177,7 @@ bool RenderableSphericalGrid::isReady() const { return ready; } -void RenderableSphericalGrid::deinitialize() { - glDeleteVertexArrays(1,&_vaoID); - _vaoID = 0; - - glDeleteBuffers(1,&_vBufferID); - _vBufferID = 0; - - glDeleteBuffers(1,&_iBufferID); - _iBufferID = 0; -} - -void RenderableSphericalGrid::initialize() { +void RenderableSphericalGrid::initializeGL() { _gridProgram = OsEng.renderEngine().buildRenderProgram( "GridProgram", "${MODULE_BASE}/shaders/grid_vs.glsl", @@ -206,6 +195,17 @@ void RenderableSphericalGrid::initialize() { glBindVertexArray(0); } +void RenderableSphericalGrid::deinitializeGL() { + glDeleteVertexArrays(1, &_vaoID); + _vaoID = 0; + + glDeleteBuffers(1, &_vBufferID); + _vBufferID = 0; + + glDeleteBuffers(1, &_iBufferID); + _iBufferID = 0; +} + void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){ _gridProgram->activate(); diff --git a/modules/base/rendering/renderablesphericalgrid.h b/modules/base/rendering/renderablesphericalgrid.h index 66a042c58a..9fff6708fd 100644 --- a/modules/base/rendering/renderablesphericalgrid.h +++ b/modules/base/rendering/renderablesphericalgrid.h @@ -48,8 +48,8 @@ public: RenderableSphericalGrid(const ghoul::Dictionary& dictionary); ~RenderableSphericalGrid(); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index bf44556ad7..3f11564117 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -217,7 +217,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) addProperty(_renderingModes); } -void RenderableTrail::initialize() { +void RenderableTrail::initializeGL() { RenderEngine& renderEngine = OsEng.renderEngine(); _programObject = renderEngine.buildRenderProgram( "EphemerisProgram", @@ -228,7 +228,7 @@ void RenderableTrail::initialize() { setRenderBin(Renderable::RenderBin::Overlay); } -void RenderableTrail::deinitialize() { +void RenderableTrail::deinitializeGL() { RenderEngine& renderEngine = OsEng.renderEngine(); if (_programObject) { renderEngine.removeRenderProgram(_programObject); diff --git a/modules/base/rendering/renderabletrail.h b/modules/base/rendering/renderabletrail.h index ed45eab5be..447c083f40 100644 --- a/modules/base/rendering/renderabletrail.h +++ b/modules/base/rendering/renderabletrail.h @@ -73,8 +73,8 @@ class RenderableTrail : public Renderable { public: ~RenderableTrail() = default; - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/base/rendering/renderabletrailorbit.cpp b/modules/base/rendering/renderabletrailorbit.cpp index 8688c032d8..3d6fcf0b1d 100644 --- a/modules/base/rendering/renderabletrailorbit.cpp +++ b/modules/base/rendering/renderabletrailorbit.cpp @@ -169,20 +169,20 @@ RenderableTrailOrbit::RenderableTrailOrbit(const ghoul::Dictionary& dictionary) _primaryRenderInformation.sorting = RenderInformation::VertexSorting::NewestFirst; } -void RenderableTrailOrbit::initialize() { - RenderableTrail::initialize(); +void RenderableTrailOrbit::initializeGL() { + RenderableTrail::initializeGL(); glGenVertexArrays(1, &_primaryRenderInformation._vaoID); glGenBuffers(1, &_primaryRenderInformation._vBufferID); glGenBuffers(1, &_primaryRenderInformation._iBufferID); } -void RenderableTrailOrbit::deinitialize() { +void RenderableTrailOrbit::deinitializeGL() { glDeleteVertexArrays(1, &_primaryRenderInformation._vaoID); glDeleteBuffers(1, &_primaryRenderInformation._vBufferID); glDeleteBuffers(1, &_primaryRenderInformation._iBufferID); - RenderableTrail::deinitialize(); + RenderableTrail::deinitializeGL(); } void RenderableTrailOrbit::update(const UpdateData& data) { diff --git a/modules/base/rendering/renderabletrailorbit.h b/modules/base/rendering/renderabletrailorbit.h index 2e6b7be12b..a76caf4edc 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 initialize() override; - void deinitialize() override; + + void initializeGL() override; + void deinitializeGL() override; void update(const UpdateData& data) override; - + static documentation::Documentation Documentation(); private: diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index f8438ccf58..a3117122ff 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -187,8 +187,8 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di _primaryRenderInformation.sorting = RenderInformation::VertexSorting::OldestFirst; } -void RenderableTrailTrajectory::initialize() { - RenderableTrail::initialize(); +void RenderableTrailTrajectory::initializeGL() { + RenderableTrail::initializeGL(); // We don't need an index buffer, so we keep it at the default value of 0 glGenVertexArrays(1, &_primaryRenderInformation._vaoID); @@ -201,14 +201,14 @@ void RenderableTrailTrajectory::initialize() { _floatingRenderInformation.sorting = RenderInformation::VertexSorting::OldestFirst; } -void RenderableTrailTrajectory::deinitialize() { +void RenderableTrailTrajectory::deinitializeGL() { glDeleteVertexArrays(1, &_primaryRenderInformation._vaoID); glDeleteBuffers(1, &_primaryRenderInformation._vBufferID); glDeleteVertexArrays(1, &_floatingRenderInformation._vaoID); glDeleteBuffers(1, &_floatingRenderInformation._vBufferID); - RenderableTrail::deinitialize(); + RenderableTrail::deinitializeGL(); } void RenderableTrailTrajectory::update(const UpdateData& data) { diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index 5f68bdfe01..0f56d48221 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -53,8 +53,8 @@ class RenderableTrailTrajectory : public RenderableTrail { public: explicit RenderableTrailTrajectory(const ghoul::Dictionary& dictionary); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; void update(const UpdateData& data) override; diff --git a/modules/base/rendering/screenspaceframebuffer.cpp b/modules/base/rendering/screenspaceframebuffer.cpp index de508f4fe9..d6d9803957 100644 --- a/modules/base/rendering/screenspaceframebuffer.cpp +++ b/modules/base/rendering/screenspaceframebuffer.cpp @@ -75,15 +75,15 @@ ScreenSpaceFramebuffer::ScreenSpaceFramebuffer(const ghoul::Dictionary& dictiona ScreenSpaceFramebuffer::~ScreenSpaceFramebuffer() {} -bool ScreenSpaceFramebuffer::initialize() { - ScreenSpaceRenderable::initialize(); +bool ScreenSpaceFramebuffer::initializeGL() { + ScreenSpaceRenderable::initializeGL(); createFragmentbuffer(); return isReady(); } -bool ScreenSpaceFramebuffer::deinitialize() { - ScreenSpaceRenderable::deinitialize(); +bool ScreenSpaceFramebuffer::deinitializeGL() { + ScreenSpaceRenderable::deinitializeGL(); _framebuffer->detachAll(); removeAllRenderFunctions(); diff --git a/modules/base/rendering/screenspaceframebuffer.h b/modules/base/rendering/screenspaceframebuffer.h index 0bb96c53d5..a4cc947f51 100644 --- a/modules/base/rendering/screenspaceframebuffer.h +++ b/modules/base/rendering/screenspaceframebuffer.h @@ -48,8 +48,8 @@ public: ScreenSpaceFramebuffer(const ghoul::Dictionary& dictionary = ghoul::Dictionary()); ~ScreenSpaceFramebuffer(); - bool initialize() override; - bool deinitialize() override; + bool initializeGL() override; + bool deinitializeGL() override; void render() override; void update() override; bool isReady() const override; diff --git a/modules/base/rotation/fixedrotation.cpp b/modules/base/rotation/fixedrotation.cpp index 5d7b1e1f08..00729a5a5b 100644 --- a/modules/base/rotation/fixedrotation.cpp +++ b/modules/base/rotation/fixedrotation.cpp @@ -36,6 +36,14 @@ namespace { const char* KeyYAxis = "YAxis"; const char* KeyZAxis = "ZAxis"; + static const openspace::properties::Property::PropertyInfo EnableInfo = { + "Enable", + "Enabled", + "If this value is 'true', all the machinery of this rotation is used, of it is " + "'false', it provides the ability to change its attributes without risking some " + "undefined behavior." + }; + static const openspace::properties::Property::PropertyInfo TypeInfo = { "Type", "Specification Type", @@ -53,6 +61,14 @@ namespace { "stay fixed to the current position of that object." }; + static const openspace::properties::Property::PropertyInfo InvertObjectInfo = { + "InvertObject", + "Invert Object Point Direction", + "If this value is set to 'true', and the type is set to 'Object', the inverse of " + "the pointing direction is used, causing the object to point away from the " + "referenced object." + }; + static const openspace::properties::Property::PropertyInfo VectorInfo = { "Vector", "Direction vector", @@ -155,13 +171,15 @@ documentation::Documentation FixedRotation::Documentation() { } FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) - : _xAxis{ + : _enabled(EnableInfo, true) + , _xAxis{ properties::OptionProperty( { "xAxis-" + TypeInfo.identifier, "xAxis:" + TypeInfo.guiName, TypeInfo.description - } + }, + properties::OptionProperty::DisplayType::Dropdown ), properties::StringProperty( { @@ -171,6 +189,14 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) }, "" ), + properties::BoolProperty( + { + "xAxis-" + InvertObjectInfo.identifier, + "xAxis:" + InvertObjectInfo.guiName, + InvertObjectInfo.description + }, + false + ), properties::Vec3Property( { "xAxis-" + VectorInfo.identifier, @@ -197,7 +223,8 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) "yAxis-" + TypeInfo.identifier, "yAxis:" + TypeInfo.guiName, "yAxis:" + TypeInfo.description - } + }, + properties::OptionProperty::DisplayType::Dropdown ), properties::StringProperty( { @@ -207,6 +234,14 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) }, "" ), + properties::BoolProperty( + { + "yAxis-" + InvertObjectInfo.identifier, + "yAxis:" + InvertObjectInfo.guiName, + InvertObjectInfo.description + }, + false + ), properties::Vec3Property( { "yAxis-" + VectorInfo.identifier, @@ -233,7 +268,8 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) "zAxis-" + TypeInfo.identifier, "zAxis:" + TypeInfo.guiName, "zAxis:" + TypeInfo.description - } + }, + properties::OptionProperty::DisplayType::Dropdown ), properties::StringProperty( { @@ -243,6 +279,14 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) }, "" ), + properties::BoolProperty( + { + "zAxis-" + InvertObjectInfo.identifier, + "zAxis:" + InvertObjectInfo.guiName, + InvertObjectInfo.description + }, + false + ), properties::Vec3Property( { "zAxis-" + VectorInfo.identifier, @@ -274,11 +318,44 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) _constructorDictionary = dictionary; + setPropertyGroupName("global", "Global"); + setPropertyGroupName("xAxis", "X Axis"); + setPropertyGroupName("yAxis", "Y Axis"); + setPropertyGroupName("zAxis", "Z Axis"); + + + + _enabled.setGroupIdentifier("global"); + addProperty(_enabled); + + _attachedObject.setGroupIdentifier("global"); addProperty(_attachedObject); _attachedObject.onChange([this](){ _attachedNode = sceneGraphNode(_attachedObject); }); + auto setPropertyVisibility = [this](Axis& axis) { + using Visibility = properties::Property::Visibility; + switch (axis.type) { + case Axis::Type::Object: + axis.object.setVisibility(Visibility::User); + axis.invertObject.setVisibility(Visibility::User); + axis.vector.setVisibility(Visibility::Hidden); + break; + case Axis::Type::Vector: + case Axis::Type::OrthogonalVector: + axis.object.setVisibility(Visibility::Hidden); + axis.invertObject.setVisibility(Visibility::Hidden); + axis.vector.setVisibility(Visibility::User); + break; + case Axis::Type::CoordinateSystemCompletion: + axis.object.setVisibility(Visibility::Hidden); + axis.invertObject.setVisibility(Visibility::Hidden); + axis.vector.setVisibility(Visibility::Hidden); + break; + } + }; + _xAxis.type.addOptions({ { Axis::Type::Object, "Object" }, @@ -286,11 +363,22 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) { Axis::Type::OrthogonalVector, "Orthogonal Vector" }, { Axis::Type::CoordinateSystemCompletion, "Coordinate System Completion" } }); + _xAxis.type.setGroupIdentifier("xAxis"); + _xAxis.type.onChange([&]() { + setPropertyVisibility(_xAxis); + }); addProperty(_xAxis.type); + + _xAxis.object.setGroupIdentifier("xAxis"); addProperty(_xAxis.object); _xAxis.object.onChange([this](){ _xAxis.node = sceneGraphNode(_xAxis.object); }); + + _xAxis.invertObject.setGroupIdentifier("xAxis"); + addProperty(_xAxis.invertObject); + + _xAxis.vector.setGroupIdentifier("xAxis"); addProperty(_xAxis.vector); @@ -300,11 +388,22 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) { Axis::Type::OrthogonalVector, "Orthogonal Vector" }, { Axis::Type::CoordinateSystemCompletion, "Coordinate System Completion" } }); + _yAxis.type.setGroupIdentifier("yAxis"); + _yAxis.type.onChange([&]() { + setPropertyVisibility(_yAxis); + }); addProperty(_yAxis.type); + + _yAxis.object.setGroupIdentifier("yAxis"); addProperty(_yAxis.object); _yAxis.object.onChange([this](){ _yAxis.node = sceneGraphNode(_yAxis.object); }); + + _yAxis.invertObject.setGroupIdentifier("yAxis"); + addProperty(_yAxis.invertObject); + + _yAxis.vector.setGroupIdentifier("yAxis"); addProperty(_yAxis.vector); @@ -314,12 +413,27 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) { Axis::Type::OrthogonalVector, "Orthogonal Vector" }, { Axis::Type::CoordinateSystemCompletion, "Coordinate System Completion" } }); + _zAxis.type.setGroupIdentifier("zAxis"); + _zAxis.type.onChange([&]() { + setPropertyVisibility(_zAxis); + }); addProperty(_zAxis.type); + + _zAxis.object.setGroupIdentifier("zAxis"); addProperty(_zAxis.object); _zAxis.object.onChange([this](){ _zAxis.node = sceneGraphNode(_zAxis.object); }); + + _zAxis.invertObject.setGroupIdentifier("zAxis"); + addProperty(_zAxis.invertObject); + + _zAxis.vector.setGroupIdentifier("zAxis"); addProperty(_zAxis.vector); + + setPropertyVisibility(_xAxis); + setPropertyVisibility(_yAxis); + setPropertyVisibility(_zAxis); } bool FixedRotation::initialize() { @@ -421,14 +535,15 @@ bool FixedRotation::initialize() { } void FixedRotation::update(const UpdateData&) { + if (!_enabled) { + _matrix = glm::dmat3(); + return; + } + glm::vec3 x = xAxis(); glm::vec3 y = yAxis(); glm::vec3 z = zAxis(); - LINFOC("x", x); - LINFOC("y", y); - LINFOC("z", z); - static const float Epsilon = 1e-3; if (glm::dot(x, y) > 1.f - Epsilon || @@ -458,10 +573,11 @@ glm::vec3 FixedRotation::xAxis() const { return glm::vec3(1.f, 0.f, 0.f); case Axis::Type::Object: if (_xAxis.node && _attachedNode) { - return glm::vec3(glm::normalize( + glm::vec3 dir = glm::vec3(glm::normalize( glm::dvec3(_xAxis.node->worldPosition()) - glm::dvec3(_attachedNode->worldPosition()) )); + return _xAxis.invertObject ? -dir : dir; } else { if (_xAxis.node) { @@ -512,10 +628,11 @@ glm::vec3 FixedRotation::yAxis() const { return glm::vec3(0.f, 1.f, 0.f); case Axis::Type::Object: if (_yAxis.node && _attachedNode) { - return glm::vec3(glm::normalize( + glm::vec3 dir = glm::vec3(glm::normalize( glm::dvec3(_yAxis.node->worldPosition()) - glm::dvec3(_attachedNode->worldPosition()) )); + return _yAxis.invertObject ? -dir : dir; } else { if (_yAxis.node) { @@ -566,10 +683,11 @@ glm::vec3 FixedRotation::zAxis() const { return glm::vec3(0.f, 0.f, 1.f); case Axis::Type::Object: if (_zAxis.node && _attachedNode) { - return glm::vec3(glm::normalize( + glm::vec3 dir = glm::vec3(glm::normalize( glm::dvec3(_zAxis.node->worldPosition()) - glm::dvec3(_attachedNode->worldPosition()) )); + return _zAxis.invertObject ? -dir : dir; } else { if (_zAxis.node) { diff --git a/modules/base/rotation/fixedrotation.h b/modules/base/rotation/fixedrotation.h index b5da119922..94f6148c3a 100644 --- a/modules/base/rotation/fixedrotation.h +++ b/modules/base/rotation/fixedrotation.h @@ -66,12 +66,15 @@ private: properties::OptionProperty type; properties::StringProperty object; + properties::BoolProperty invertObject; properties::Vec3Property vector; properties::BoolProperty isOrthogonal; SceneGraphNode* node; }; + properties::BoolProperty _enabled; + Axis _xAxis; Axis _yAxis; Axis _zAxis; diff --git a/modules/debugging/rendering/renderabledebugplane.cpp b/modules/debugging/rendering/renderabledebugplane.cpp index dc381c172a..1e1847ae38 100644 --- a/modules/debugging/rendering/renderabledebugplane.cpp +++ b/modules/debugging/rendering/renderabledebugplane.cpp @@ -190,7 +190,7 @@ bool RenderableDebugPlane::isReady() const { return ready; } -void RenderableDebugPlane::initialize() { +void RenderableDebugPlane::initializeGL() { glGenVertexArrays(1, &_quad); // generate array glGenBuffers(1, &_vertexPositionBuffer); // generate buffer createPlane(); @@ -204,7 +204,7 @@ void RenderableDebugPlane::initialize() { } } -void RenderableDebugPlane::deinitialize() { +void RenderableDebugPlane::deinitializeGL() { glDeleteVertexArrays(1, &_quad); _quad = 0; diff --git a/modules/debugging/rendering/renderabledebugplane.h b/modules/debugging/rendering/renderabledebugplane.h index 91fa8914b2..62bbe4d2f0 100644 --- a/modules/debugging/rendering/renderabledebugplane.h +++ b/modules/debugging/rendering/renderabledebugplane.h @@ -49,8 +49,8 @@ public: RenderableDebugPlane(const ghoul::Dictionary& dictionary); ~RenderableDebugPlane(); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 343b3d68f3..2700b1f5f1 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include @@ -69,7 +69,7 @@ namespace { "Point Sprite Texture", "The path to the texture that should be used as the point sprite." }; - + static const openspace::properties::Property::PropertyInfo TransparencyInfo = { "Transparency", "Transparency", @@ -324,7 +324,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _hasSpeckFile = _hasSpeckFile == true? false : true; }); addProperty(_drawElements); } - + // DEBUG: _renderOption.addOption(0, "Camera View Direction"); _renderOption.addOption(1, "Camera Position Normal"); @@ -386,7 +386,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di ghoul::Dictionary colorOptionDataDic = dictionary.value( ColorOptionInfo.identifier ); - for (int i = 0; i < static_cast(colorOptionDataDic.size()); ++i) { + for (int i = 0; i < colorOptionDataDic.size(); ++i) { std::string colorMapInUseName( colorOptionDataDic.value(std::to_string(i + 1))); _colorOption.addOption(i, colorMapInUseName); @@ -405,17 +405,17 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di ghoul::Dictionary rangeDataDic = dictionary.value( ColorRangeInfo.identifier ); - for (int i = 0; i < static_cast(rangeDataDic.size()); ++i) { + for (int i = 0; i < rangeDataDic.size(); ++i) { _colorRangeData.push_back( rangeDataDic.value(std::to_string(i+1))); } - + } } else if (dictionary.hasKey(keyColor)) { _pointColor = dictionary.value(keyColor); addProperty(_pointColor); - } + } if (dictionary.hasKey(TransparencyInfo.identifier)) { _alphaValue = static_cast( @@ -446,7 +446,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _labelFile = absPath(dictionary.value( LabelFileInfo.identifier - )); + )); _hasLabel = true; if (dictionary.hasKey(TextColorInfo.identifier)) { @@ -465,7 +465,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di if (dictionary.hasKey(LabelMinSizeInfo.identifier)) { _textMinSize = static_cast(dictionary.value(LabelMinSizeInfo.identifier)); - } + } addProperty(_textMinSize); } } @@ -475,13 +475,6 @@ bool RenderableBillboardsCloud::isReady() const { } void RenderableBillboardsCloud::initialize() { - RenderEngine& renderEngine = OsEng.renderEngine(); - - _program = renderEngine.buildRenderProgram("RenderableBillboardsCloud", - "${MODULE_DIGITALUNIVERSE}/shaders/billboard2_vs.glsl", - "${MODULE_DIGITALUNIVERSE}/shaders/billboard2_fs.glsl", - "${MODULE_DIGITALUNIVERSE}/shaders/billboard2_gs.glsl"); - bool success = loadData(); if (!success) { throw ghoul::RuntimeError("Error loading data"); @@ -490,8 +483,17 @@ void RenderableBillboardsCloud::initialize() { if (!_colorOptionString.empty()) { // Following DU behavior here. The last colormap variable // entry is the one selected by default. - _colorOption = static_cast(_colorRangeData.size() - 1); + _colorOption.setValue(_colorRangeData.size() - 1); } +} + +void RenderableBillboardsCloud::initializeGL() { + RenderEngine& renderEngine = OsEng.renderEngine(); + + _program = renderEngine.buildRenderProgram("RenderableBillboardsCloud", + "${MODULE_DIGITALUNIVERSE}/shaders/billboard2_vs.glsl", + "${MODULE_DIGITALUNIVERSE}/shaders/billboard2_fs.glsl", + "${MODULE_DIGITALUNIVERSE}/shaders/billboard2_gs.glsl"); if (_hasPolygon) { createPolygonTexture(); @@ -504,14 +506,12 @@ void RenderableBillboardsCloud::initialize() { if (_font == nullptr) { size_t _fontSize = 30; _font = OsEng.fontManager().font("Mono", static_cast(_fontSize), - ghoul::fontrendering::FontManager::Outline::Yes, - ghoul::fontrendering::FontManager::LoadGlyphs::No - ); + ghoul::fontrendering::FontManager::Outline::Yes, ghoul::fontrendering::FontManager::LoadGlyphs::No); } } } -void RenderableBillboardsCloud::deinitialize() { +void RenderableBillboardsCloud::deinitializeGL() { glDeleteBuffers(1, &_vbo); _vbo = 0; glDeleteVertexArrays(1, &_vao); @@ -572,7 +572,7 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g _program->setUniform("renderOption", _renderOption.value()); glm::dvec4 centerScreenWorld = glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0); _program->setUniform("centerScreenInWorldPosition", centerScreenWorld); - + _program->setUniform("minBillboardSize", 1.f); // in pixels _program->setUniform("color", _pointColor); _program->setUniform("sides", 4); @@ -631,7 +631,7 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm:: RenderEngine& renderEngine = OsEng.renderEngine(); _fontRenderer->setFramebufferSize(renderEngine.renderingResolution()); - + float scale = 0.0; switch (_unit) { case Meter: @@ -685,7 +685,7 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix; - // glm::mat4 viewMatrix = data.camera.viewMatrix(); + glm::mat4 viewMatrix = data.camera.viewMatrix(); glm::mat4 projectionMatrix = data.camera.projectionMatrix(); glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix; @@ -698,14 +698,14 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))); glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))); - + if (_hasSpeckFile) { renderBillboards(data, modelViewMatrix, projectionMatrix, orthoRight, orthoUp); } - + if (_drawLabels && _hasLabel) { renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); - } + } } void RenderableBillboardsCloud::update(const UpdateData&) { @@ -734,13 +734,13 @@ void RenderableBillboardsCloud::update(const UpdateData&) { GL_STATIC_DRAW ); GLint positionAttrib = _program->attributeLocation("in_position"); - + if (_hasColorMapFile) { - + /*const size_t nAstronomicalObjects = _fullData.size() / _nValuesPerAstronomicalObject; const size_t nValues = _slicedData.size() / nAstronomicalObjects; GLsizei stride = static_cast(sizeof(float) * nValues);*/ - + glEnableVertexAttribArray(positionAttrib); glVertexAttribPointer( positionAttrib, @@ -762,7 +762,7 @@ void RenderableBillboardsCloud::update(const UpdateData&) { reinterpret_cast(sizeof(float)*4) ); } - else { + else { glEnableVertexAttribArray(positionAttrib); glVertexAttribPointer( positionAttrib, @@ -796,10 +796,11 @@ void RenderableBillboardsCloud::update(const UpdateData&) { [&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; } ); } - _spriteTextureIsDirty = false; + _spriteTextureIsDirty = false; } if (_hasLabel && _labelDataIsDirty) { + _labelDataIsDirty = false; } } @@ -879,7 +880,7 @@ bool RenderableBillboardsCloud::loadData() { // } } - + return success; } @@ -940,7 +941,7 @@ bool RenderableBillboardsCloud::readSpeckFile() { _variableDataPositionMap.insert({ dummy, _nValuesPerAstronomicalObject }); _nValuesPerAstronomicalObject += 1; // We want the number, but the index is 0 based - } + } } _nValuesPerAstronomicalObject += 3; // X Y Z are not counted in the Speck file indices @@ -963,7 +964,7 @@ bool RenderableBillboardsCloud::readSpeckFile() { std::stringstream str(line); for (int i = 0; i < _nValuesPerAstronomicalObject; ++i) { - str >> values[i]; + str >> values[i]; } _fullData.insert(_fullData.end(), values.begin(), values.end()); @@ -979,15 +980,15 @@ bool RenderableBillboardsCloud::readColorMapFile() { LERROR("Failed to open Color Map file '" << _file << "'"); return false; } - - int numberOfColors = 0; + + std::size_t numberOfColors = 0; // The beginning of the speck file has a header that either contains comments // (signaled by a preceding '#') or information about the structure of the file // (signaled by the keywords 'datavar', 'texturevar', and 'texture') std::string line = ""; while (true) { - // std::streampos position = file.tellg(); + std::streampos position = file.tellg(); std::getline(file, line); if (line[0] == '#' || line.empty()) { @@ -998,18 +999,18 @@ bool RenderableBillboardsCloud::readColorMapFile() { std::locale loc; if (std::isdigit(line[0], loc)) { std::string::size_type sz; - numberOfColors = static_cast(std::stoi(line, &sz)); + numberOfColors = std::stoi(line, &sz); break; } else if (file.eof()) { return false; - } + } } - - for (int i = 0; i < numberOfColors; ++i) { + + for (auto i = 0; i < numberOfColors; ++i) { std::getline(file, line); std::stringstream str(line); - + glm::vec4 color; for (auto j = 0; j < 4; ++j) { str >> color[j]; @@ -1017,7 +1018,7 @@ bool RenderableBillboardsCloud::readColorMapFile() { _colorMapData.push_back(color); } - + return true; } @@ -1028,7 +1029,7 @@ bool RenderableBillboardsCloud::readLabelFile() { LERROR("Failed to open Label file '" << _file << "'"); return false; } - + // The beginning of the speck file has a header that either contains comments // (signaled by a preceding '#') or information about the structure of the file // (signaled by the keywords 'datavar', 'texturevar', and 'texture') @@ -1090,7 +1091,7 @@ bool RenderableBillboardsCloud::readLabelFile() { std::string dummy; str >> dummy; // text keyword - + std::string label; str >> label; dummy.clear(); @@ -1101,7 +1102,7 @@ bool RenderableBillboardsCloud::readLabelFile() { } _labelData.push_back(std::make_pair(position, label)); - + } while (!file.eof()); return true; @@ -1134,7 +1135,7 @@ bool RenderableBillboardsCloud::loadCachedFile(const std::string& file) { for (int i = 0; i < nItems; ++i) { int32_t keySize = 0; fileStream.read(reinterpret_cast(&keySize), sizeof(int32_t)); - std::string key; + std::string key; for (int c = 0; c < keySize; ++c) { char t[2]; t[1] = '\0'; @@ -1172,7 +1173,7 @@ bool RenderableBillboardsCloud::saveCachedFile(const std::string& file) const { int32_t nValuesPerAstronomicalObject = static_cast(_nValuesPerAstronomicalObject); fileStream.write(reinterpret_cast(&nValuesPerAstronomicalObject), sizeof(int32_t)); - + size_t nBytes = nValues * sizeof(_fullData[0]); fileStream.write(reinterpret_cast(&_fullData[0]), nBytes); @@ -1183,7 +1184,7 @@ bool RenderableBillboardsCloud::saveCachedFile(const std::string& file) const { for (auto pair : _variableDataPositionMap) { int32_t keySize = static_cast(pair.first.size()); fileStream.write(reinterpret_cast(&keySize), sizeof(int32_t)); - for (int c = 0; c < static_cast(pair.first.size()); ++c) { + for (int c = 0; c < pair.first.size(); ++c) { int32_t keyChar = static_cast(pair.first[c]); fileStream.write(reinterpret_cast(&keyChar), sizeof(int32_t)); } @@ -1200,7 +1201,7 @@ bool RenderableBillboardsCloud::saveCachedFile(const std::string& file) const { return false; } } - + void RenderableBillboardsCloud::createDataSlice() { _slicedData.clear(); if (_hasColorMapFile) { @@ -1218,38 +1219,34 @@ void RenderableBillboardsCloud::createDataSlice() { glm::vec2 currentColorRange = _colorRangeData[_colorOption.value()]; float colorMapBinSize = (currentColorRange.y - currentColorRange.x) / static_cast(_colorMapData.size()); float bin = colorMapBinSize; - for (int i = 0; i < static_cast(_colorMapData.size()); ++i) { + for (int i = 0; i < _colorMapData.size(); ++i) { colorBins.push_back(bin); bin += colorMapBinSize; } - } + } for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) { glm::dvec4 transformedPos = glm::dvec4(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2], 1.0); glm::vec4 position(glm::vec3(transformedPos), static_cast(_unit)); - + if (_hasColorMapFile) { - for (int j = 0; j < 4; ++j) { + for (auto j = 0; j < 4; ++j) { _slicedData.push_back(position[j]); } // Finds from which bin to get the color. // Note: the first color in the colormap file // is the outliers color. - glm::vec4 itemColor; + glm::vec4 itemColor; float variableColor = _fullData[i + 3 + colorMapInUse]; - int c = static_cast(colorBins.size() - 1); - // Float vs int comparison? + int c = colorBins.size()-1; while (variableColor < colorBins[c]) { --c; if (c == 0) break; } - - int colorIndex = 0; - if (c != static_cast(colorBins.size() - 1)) { - colorIndex = c + 1; - } - + + int colorIndex = c == colorBins.size() - 1 ? 0 : c + 1; + for (auto j = 0; j < 4; ++j) { _slicedData.push_back(_colorMapData[colorIndex][j]); } @@ -1258,7 +1255,7 @@ void RenderableBillboardsCloud::createDataSlice() { for (auto j = 0; j < 4; ++j) { _slicedData.push_back(position[j]); } - } + } } } @@ -1280,7 +1277,7 @@ void RenderableBillboardsCloud::createPolygonTexture() { this), std::bind(&openspace::RenderableBillboardsCloud::renderPolygonGeometry, this, std::placeholders::_1), - _pTexture, 256, 256); + _pTexture, 256, 256); } void RenderableBillboardsCloud::renderToTexture( @@ -1288,7 +1285,7 @@ void RenderableBillboardsCloud::renderToTexture( std::function renderFunction, GLuint textureToRenderTo, GLuint textureWidth, GLuint textureHeight) { LDEBUG("Rendering to Texture"); - + // Saves initial Application's OpenGL State GLint defaultFBO; GLint viewport[4]; @@ -1302,12 +1299,12 @@ void RenderableBillboardsCloud::renderToTexture( glDrawBuffers(1, drawBuffers); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureToRenderTo, 0); - + glViewport(0, 0, textureWidth, textureHeight); - + geometryLoadingFunction(); renderFunction(_polygonVao); - + // Restores Applications' OpenGL State glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); @@ -1319,7 +1316,7 @@ void RenderableBillboardsCloud::renderToTexture( if (_polygonVao) { glDeleteVertexArrays(1, &_polygonVao); } - glDeleteFramebuffers(1, &textureFBO); + glDeleteFramebuffers(1, &textureFBO); } void RenderableBillboardsCloud::loadPolygonGeometryForRendering() { diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index 83fd07723b..dce5e74b21 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -59,7 +59,8 @@ public: ~RenderableBillboardsCloud() = default; void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index b750215bed..bef3fa63e4 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -371,7 +371,7 @@ bool RenderableDUMeshes::isReady() const { return (_program != nullptr) && (!_renderingMeshesMap.empty() || (!_labelData.empty())); } -void RenderableDUMeshes::initialize() { +void RenderableDUMeshes::initializeGL() { RenderEngine& renderEngine = OsEng.renderEngine(); _program = renderEngine.buildRenderProgram("RenderableDUMeshes", "${MODULE_DIGITALUNIVERSE}/shaders/dumesh_vs.glsl", @@ -396,7 +396,7 @@ void RenderableDUMeshes::initialize() { } } -void RenderableDUMeshes::deinitialize() { +void RenderableDUMeshes::deinitializeGL() { for (const std::pair& pair : _renderingMeshesMap) { for (int i = 0; i < pair.second.numU; ++i) { glDeleteVertexArrays(1, &pair.second.vaoArray[i]); diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.h b/modules/digitaluniverse/rendering/renderabledumeshes.h index 989d7dd0e7..c246e0f002 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.h +++ b/modules/digitaluniverse/rendering/renderabledumeshes.h @@ -56,8 +56,8 @@ public: explicit RenderableDUMeshes(const ghoul::Dictionary& dictionary); ~RenderableDUMeshes() = default; - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 1066622437..2a6612c8cd 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include @@ -291,7 +291,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _hasSpeckFile = _hasSpeckFile == true? false : true; }); addProperty(_drawElements); } - + // DEBUG: _renderOption.addOption(0, "Camera View Direction"); _renderOption.addOption(1, "Camera Position Normal"); @@ -347,11 +347,11 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _scaleFactor.onChange([&]() { _dataIsDirty = true; }); - + if (dictionary.hasKey(LabelFileInfo.identifier)) { _labelFile = absPath(dictionary.value( LabelFileInfo.identifier - )); + )); _hasLabel = true; if (dictionary.hasKey(TextColorInfo.identifier)) { @@ -370,7 +370,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary if (dictionary.hasKey(LabelMinSizeInfo.identifier)) { _textMinSize = static_cast(dictionary.value(LabelMinSizeInfo.identifier)); - } + } } if (dictionary.hasKey(TransformationMatrixInfo.identifier)) { @@ -420,17 +420,19 @@ bool RenderablePlanesCloud::isReady() const { } void RenderablePlanesCloud::initialize() { - RenderEngine& renderEngine = OsEng.renderEngine(); - - _program = renderEngine.buildRenderProgram("RenderablePlanesCloud", - "${MODULE_DIGITALUNIVERSE}/shaders/plane2_vs.glsl", - "${MODULE_DIGITALUNIVERSE}/shaders/plane2_fs.glsl"); - bool success = loadData(); if (!success) { throw ghoul::RuntimeError("Error loading data"); } +} +void RenderablePlanesCloud::initializeGL() { + RenderEngine& renderEngine = OsEng.renderEngine(); + + _program = renderEngine.buildRenderProgram("RenderablePlanesCloud", + "${MODULE_DIGITALUNIVERSE}/shaders/plane2_vs.glsl", + "${MODULE_DIGITALUNIVERSE}/shaders/plane2_fs.glsl"); + createPlanes(); loadTextures(); @@ -455,14 +457,14 @@ void RenderablePlanesCloud::deleteDataGPU() { } } -void RenderablePlanesCloud::deinitialize() { +void RenderablePlanesCloud::deinitializeGL() { deleteDataGPU(); - + RenderEngine& renderEngine = OsEng.renderEngine(); if (_program) { renderEngine.removeRenderProgram(_program); _program = nullptr; - } + } } void RenderablePlanesCloud::renderPlanes(const RenderData&, @@ -499,7 +501,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, _program->setUniform("alphaValue", _alphaValue); _program->setUniform("scaleFactor", _scaleFactor); //_program->setUniform("minPlaneSize", 1.f); // in pixels - + //bool usingFramebufferRenderer = // OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer; @@ -515,7 +517,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, // //glDepthMask(false); // glBlendFunc(GL_SRC_ALPHA, GL_ONE); //} - + for (auto pair : _renderingPlanesMap) { ghoul::opengl::TextureUnit unit; unit.activate(); @@ -523,14 +525,14 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, _program->setUniform("galaxyTexture", unit); glBindVertexArray(pair.second.vao); - glDrawArrays(GL_TRIANGLES, 0, 6); - } - + glDrawArrays(GL_TRIANGLES, 0, 6); + } + //if (additiveBlending) { // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // //glDepthMask(true); //} - + glBindVertexArray(0); using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; @@ -545,7 +547,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, if (!blendEnabled) { glDisable(GL_BLEND); - } + } } void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, @@ -553,7 +555,7 @@ void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat RenderEngine& renderEngine = OsEng.renderEngine(); _fontRenderer->setFramebufferSize(renderEngine.renderingResolution()); - + float scale = 0.0; switch (_unit) { case Meter: @@ -578,14 +580,14 @@ void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat scale = 306391534.73091 * PARSEC; break; } - + for (const std::pair& pair : _labelData) { //glm::vec3 scaledPos(_transformationMatrix * glm::dvec4(pair.first, 1.0)); glm::vec3 scaledPos(pair.first); scaledPos *= scale; _fontRenderer->render( *_font, - scaledPos, + scaledPos, _textColor, pow(10.0, _textSize.value()), _textMinSize, @@ -597,7 +599,8 @@ void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat _renderOption.value(), "%s", pair.second.c_str()); - } + } + } void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) { @@ -619,14 +622,14 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) { glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))); glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))); - + if (_hasSpeckFile) { - renderPlanes(data, modelViewMatrix, projectionMatrix); + renderPlanes(data, modelViewMatrix, projectionMatrix); } - + if (_hasLabel) { renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); - } + } } void RenderablePlanesCloud::update(const UpdateData&) { @@ -638,7 +641,7 @@ void RenderablePlanesCloud::update(const UpdateData&) { } bool RenderablePlanesCloud::loadData() { - bool success = false; + bool success = false; if (_hasSpeckFile) { std::string _file = _speckFile; // I disabled the cache as it didn't work on Mac --- abock @@ -672,7 +675,7 @@ bool RenderablePlanesCloud::loadData() { //success &= saveCachedFile(cachedFile); // } } - + std::string labelFile = _labelFile; if (!labelFile.empty()) { // I disabled the cache as it didn't work on Mac --- abock @@ -703,7 +706,7 @@ bool RenderablePlanesCloud::loadData() { // } } - + return success; } @@ -721,7 +724,7 @@ bool RenderablePlanesCloud::loadTextures() { it->second->uploadTexture(); it->second->setFilter(ghoul::opengl::Texture::FilterMode::Linear); } - } + } } else { return false; @@ -791,7 +794,7 @@ bool RenderablePlanesCloud::readSpeckFile() { } else { _nValuesPerAstronomicalObject += 1; // We want the number, but the index is 0 based - } + } } if (line.substr(0, 10) == "polyorivar") { @@ -816,9 +819,9 @@ bool RenderablePlanesCloud::readSpeckFile() { if (line.substr(0, 8) == "texture ") { std::stringstream str(line); - + int textureIndex = 0; - + std::string dummy; str >> dummy; // command str >> textureIndex; @@ -846,7 +849,7 @@ bool RenderablePlanesCloud::readSpeckFile() { if (line.empty()) { continue; } - + std::stringstream str(line); glm::vec3 u(0.0f), v(0.0f); @@ -897,7 +900,7 @@ bool RenderablePlanesCloud::readLabelFile() { LERROR("Failed to open Label file '" << _file << "'"); return false; } - + // The beginning of the speck file has a header that either contains comments // (signaled by a preceding '#') or information about the structure of the file // (signaled by the keywords 'datavar', 'texturevar', and 'texture') @@ -934,7 +937,7 @@ bool RenderablePlanesCloud::readLabelFile() { } } - + do { std::vector values(_nValuesPerAstronomicalObject); @@ -959,7 +962,7 @@ bool RenderablePlanesCloud::readLabelFile() { std::string dummy; str >> dummy; // text keyword - + std::string label; str >> label; dummy.clear(); @@ -1039,9 +1042,9 @@ void RenderablePlanesCloud::createPlanes() { LDEBUG("Creating planes"); int planeNumber = 0; - for (int p = 0; p < static_cast(_fullData.size()); p += _nValuesPerAstronomicalObject) { + for (int p = 0; p < _fullData.size(); p += _nValuesPerAstronomicalObject) { glm::vec4 transformedPos = glm::vec4(_transformationMatrix * - glm::dvec4(_fullData[p + 0], _fullData[p + 1], _fullData[p + 2], 1.0)); + glm::dvec4(_fullData[p + 0], _fullData[p + 1], _fullData[p + 2], 1.0)); // Plane vectors u and v glm::vec4 u = glm::vec4(_transformationMatrix * @@ -1072,21 +1075,21 @@ void RenderablePlanesCloud::createPlanes() { RenderingPlane plane; plane.planeIndex = _fullData[p + _textureVariableIndex]; - + // JCC: Ask Abbott about these points refeering to a non-existing texture. if (plane.planeIndex == 30) { //std::cout << "--- Creating planes - index: " << plane.planeIndex << std::endl; plane.planeIndex = 0; } - + glGenVertexArrays(1, &plane.vao); glGenBuffers(1, &plane.vbo); - + glm::vec4 vertex0 = transformedPos - u - v; // same as 3 glm::vec4 vertex1 = transformedPos + u + v; // same as 5 glm::vec4 vertex2 = transformedPos - u + v; glm::vec4 vertex4 = transformedPos + u - v; - + float scale = 0.0; switch (_unit) { case Meter: @@ -1142,7 +1145,7 @@ void RenderablePlanesCloud::createPlanes() { sizeof(GLfloat) * 6, nullptr ); - + // texture coords glEnableVertexAttribArray(1); glVertexAttribPointer( @@ -1152,7 +1155,7 @@ void RenderablePlanesCloud::createPlanes() { GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4) - ); + ); _renderingPlanesMap.insert({planeNumber++, plane}); } @@ -1163,6 +1166,7 @@ void RenderablePlanesCloud::createPlanes() { } if (_hasLabel && _labelDataIsDirty) { + _labelDataIsDirty = false; } } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index 42347cd686..40d7e4e41c 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -61,7 +61,8 @@ namespace openspace { ~RenderablePlanesCloud() = default; void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index 707c2a0b70..0724b35305 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -64,7 +64,7 @@ namespace { "Point Sprite Texture", "The path to the texture that should be used as the point sprite." }; - + static const openspace::properties::Property::PropertyInfo TransparencyInfo = { "Transparency", "Transparency", @@ -174,9 +174,9 @@ namespace openspace { dictionary, "RenderablePoints" ); - + _speckFile = absPath(dictionary.value(KeyFile)); - + if (dictionary.hasKey(keyUnit)) { std::string unit = dictionary.value(keyUnit); if (unit == MeterUnit) { @@ -254,6 +254,13 @@ namespace openspace { } void RenderablePoints::initialize() { + bool success = loadData(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } + } + + void RenderablePoints::initializeGL() { RenderEngine& renderEngine = OsEng.renderEngine(); if (_hasSpriteTexture) { _program = renderEngine.buildRenderProgram("RenderablePoints", @@ -266,14 +273,9 @@ namespace openspace { "${MODULE_DIGITALUNIVERSE}/shaders/points_fs.glsl");// , //"${MODULE_DIGITALUNIVERSE}/shaders/points_gs.glsl"); } - - bool success = loadData(); - if (!success) { - throw ghoul::RuntimeError("Error loading data"); - } } - void RenderablePoints::deinitialize() { + void RenderablePoints::deinitializeGL() { glDeleteBuffers(1, &_vbo); _vbo = 0; glDeleteVertexArrays(1, &_vao); @@ -295,7 +297,7 @@ namespace openspace { _program->activate(); glm::dmat4 modelMatrix = glm::dmat4(1.0); - + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; _program->setIgnoreUniformLocationError(IgnoreError::Yes); _program->setUniform("modelViewProjectionTransform", glm::dmat4(data.camera.projectionMatrix()) * @@ -305,7 +307,7 @@ namespace openspace { _program->setUniform("sides", 4); _program->setUniform("alphaValue", _alphaValue); _program->setUniform("scaleFactor", _scaleFactor); - + if (_hasSpriteTexture) { ghoul::opengl::TextureUnit spriteTextureUnit; spriteTextureUnit.activate(); @@ -319,12 +321,12 @@ namespace openspace { else { _program->setUniform("hasColorMap", false); } - + glEnable(GL_PROGRAM_POINT_SIZE); glBindVertexArray(_vao); const GLsizei nAstronomicalObjects = static_cast(_fullData.size() / _nValuesPerAstronomicalObject); glDrawArrays(GL_POINTS, 0, nAstronomicalObjects); - + glDisable(GL_PROGRAM_POINT_SIZE); glBindVertexArray(0); using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; @@ -362,10 +364,11 @@ namespace openspace { GLint positionAttrib = _program->attributeLocation("in_position"); if (_hasColorMapFile) { + const size_t nAstronomicalObjects = _fullData.size() / _nValuesPerAstronomicalObject; - // const size_t nValues = _slicedData.size() / nAstronomicalObjects; - // GLsizei stride = static_cast(sizeof(double) * nValues); - + const size_t nValues = _slicedData.size() / nAstronomicalObjects; + GLsizei stride = static_cast(sizeof(double) * nValues); + glEnableVertexAttribArray(positionAttrib); glVertexAttribLPointer( positionAttrib, @@ -385,7 +388,7 @@ namespace openspace { reinterpret_cast(sizeof(double)*4) ); } - else { + else { glEnableVertexAttribArray(positionAttrib); glVertexAttribLPointer( positionAttrib, @@ -418,7 +421,7 @@ namespace openspace { [&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; } ); } - _spriteTextureIsDirty = false; + _spriteTextureIsDirty = false; } } @@ -483,7 +486,7 @@ namespace openspace { while (true) { std::streampos position = file.tellg(); std::getline(file, line); - + if (line[0] == '#' || line.empty()) { continue; } @@ -538,15 +541,15 @@ namespace openspace { LERROR("Failed to open Color Map file '" << _file << "'"); return false; } - - int numberOfColors = 0; + + std::size_t numberOfColors = 0; // The beginning of the speck file has a header that either contains comments // (signaled by a preceding '#') or information about the structure of the file // (signaled by the keywords 'datavar', 'texturevar', and 'texture') std::string line = ""; while (true) { - // std::streampos position = file.tellg(); + std::streampos position = file.tellg(); std::getline(file, line); if (line[0] == '#' || line.empty()) { @@ -557,18 +560,18 @@ namespace openspace { std::locale loc; if (std::isdigit(line[0], loc)) { std::string::size_type sz; - numberOfColors = static_cast(std::stoi(line, &sz)); + numberOfColors = std::stoi(line, &sz); break; } else if (file.eof()) { return false; - } + } } - - for (int i = 0; i < numberOfColors; ++i) { + + for (auto i = 0; i < numberOfColors; ++i) { std::getline(file, line); std::stringstream str(line); - + glm::vec4 color; for (auto j = 0; j < 4; ++j) { str >> color[j]; @@ -576,7 +579,7 @@ namespace openspace { _colorMapData.push_back(color); } - + return true; } @@ -636,7 +639,7 @@ namespace openspace { return false; } } - + void RenderablePoints::createDataSlice() { _slicedData.clear(); if (_hasColorMapFile) { @@ -673,24 +676,22 @@ namespace openspace { glm::dvec4 position(p, 1.0); if (_hasColorMapFile) { - for (int j = 0; j < 4; ++j) { + for (auto j = 0; j < 4; ++j) { _slicedData.push_back(position[j]); } - for (int j = 0; j < 4; ++j) { + for (auto j = 0; j < 4; ++j) { _slicedData.push_back(_colorMapData[colorIndex][j]); } } else { - for (int j = 0; j < 4; ++j) { + for (auto j = 0; j < 4; ++j) { _slicedData.push_back(position[j]); } } - - colorIndex = - (colorIndex == (static_cast(_colorMapData.size()) - 1)) ? - 0 : - colorIndex + 1; + + colorIndex = (colorIndex == (_colorMapData.size() - 1)) ? 0 : colorIndex + 1; } } + } // namespace openspace diff --git a/modules/digitaluniverse/rendering/renderablepoints.h b/modules/digitaluniverse/rendering/renderablepoints.h index afcdaed93f..5d5cb88159 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.h +++ b/modules/digitaluniverse/rendering/renderablepoints.h @@ -54,7 +54,8 @@ namespace openspace { ~RenderablePoints() = default; void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/fieldlines/rendering/renderablefieldlines.cpp b/modules/fieldlines/rendering/renderablefieldlines.cpp index 8fb00b0131..c038b13891 100644 --- a/modules/fieldlines/rendering/renderablefieldlines.cpp +++ b/modules/fieldlines/rendering/renderablefieldlines.cpp @@ -235,7 +235,7 @@ bool RenderableFieldlines::isReady() const { return programReady && vectorFieldReady && fieldlineReady && seedPointsReady; } -void RenderableFieldlines::initialize() { +void RenderableFieldlines::initializeGL() { if (_vectorFieldInfo.empty() || _fieldlineInfo.empty() || _seedPointsInfo.empty()) { throw ghoul::RuntimeError("Error initializing"); } @@ -248,7 +248,7 @@ void RenderableFieldlines::initialize() { ); } -void RenderableFieldlines::deinitialize() { +void RenderableFieldlines::deinitializeGL() { glDeleteVertexArrays(1, &_fieldlineVAO); _fieldlineVAO = 0; glDeleteBuffers(1, &_vertexPositionBuffer); diff --git a/modules/fieldlines/rendering/renderablefieldlines.h b/modules/fieldlines/rendering/renderablefieldlines.h index c2701af6f9..5dc5dacbda 100644 --- a/modules/fieldlines/rendering/renderablefieldlines.h +++ b/modules/fieldlines/rendering/renderablefieldlines.h @@ -45,8 +45,8 @@ class RenderableFieldlines : public Renderable { public: RenderableFieldlines(const ghoul::Dictionary& dictionary); - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index be5aaa79a3..6ef4b4c635 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -150,10 +150,10 @@ namespace openspace { } } - + RenderableGalaxy::~RenderableGalaxy() {} -void RenderableGalaxy::initialize() { +void RenderableGalaxy::initializeGL() { // Aspect is currently hardcoded to cubic voxels. _aspect = static_cast(_volumeDimensions); _aspect = _aspect / std::max(std::max(_aspect.x, _aspect.y), _aspect.z); @@ -163,7 +163,7 @@ void RenderableGalaxy::initialize() { _volumeDimensions ); _volume = reader.read(); - + _texture = std::make_unique( _volumeDimensions, ghoul::opengl::Texture::Format::RGBA, @@ -176,6 +176,7 @@ void RenderableGalaxy::initialize() { _volume->data()), ghoul::opengl::Texture::TakeOwnership::No ); + _texture->setDimensions(_volume->dimensions()); _texture->uploadTexture(); @@ -200,7 +201,7 @@ void RenderableGalaxy::initialize() { addProperty(_translation); addProperty(_rotation); addProperty(_enabledPointsRatio); - + // initialize points. std::ifstream pointFile(_pointsFilename, std::ios::in | std::ios::binary); @@ -221,7 +222,7 @@ void RenderableGalaxy::initialize() { pointFile.close(); float maxdist = 0; - + for (size_t i = 0; i < _nPoints; ++i) { float x = pointData[i * 7 + 0]; float y = pointData[i * 7 + 1]; @@ -231,9 +232,9 @@ void RenderableGalaxy::initialize() { float b = pointData[i * 7 + 5]; maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z))); //float a = pointData[i * 7 + 6]; alpha is not used. - + pointPositions.push_back(glm::vec3(x, y, z)); - pointColors.push_back(glm::vec3(r, g, b)); + pointColors.push_back(glm::vec3(r, g, b)); } std::cout << maxdist << std::endl; @@ -278,22 +279,22 @@ void RenderableGalaxy::initialize() { glBindBuffer(GL_ARRAY_BUFFER, _colorVbo); glEnableVertexAttribArray(colorAttrib); glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0); - + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } - -void RenderableGalaxy::deinitialize() { + +void RenderableGalaxy::deinitializeGL() { if (_raycaster) { OsEng.renderEngine().raycasterManager().detachRaycaster(*_raycaster.get()); _raycaster = nullptr; } } - + bool RenderableGalaxy::isReady() const { return true; } - + void RenderableGalaxy::update(const UpdateData& data) { if (_raycaster) { @@ -312,7 +313,7 @@ void RenderableGalaxy::update(const UpdateData& data) { static_cast(_volumeSize) ); _pointTransform = glm::scale(transform, static_cast(_pointScaling)); - + glm::vec4 translation = glm::vec4(static_cast(_translation), 0.0); // Todo: handle floating point overflow, to actually support translation. @@ -337,6 +338,7 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { glm::vec3 galaxySize = static_cast(_volumeSize); float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z); + float lowerRampStart = maxDim * 0.02; float lowerRampEnd = maxDim * 0.5; @@ -409,5 +411,5 @@ float RenderableGalaxy::safeLength(const glm::vec3& vector) { OsEng.ref().renderEngine().postRaycast(*_pointsProgram); }*/ - + } diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 9bc543bdc1..d910be4650 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -35,14 +35,14 @@ namespace openspace { struct RenderData; - + class RenderableGalaxy : public Renderable { public: RenderableGalaxy(const ghoul::Dictionary& dictionary); ~RenderableGalaxy(); - - void initialize() override; - void deinitialize() override; + + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; void render(const RenderData& data, RendererTasks& tasks) override; void update(const UpdateData& data) override; diff --git a/modules/globebrowsing/globebrowsingmodule_lua.inl b/modules/globebrowsing/globebrowsingmodule_lua.inl index b2407b1a59..85c6e6d040 100644 --- a/modules/globebrowsing/globebrowsingmodule_lua.inl +++ b/modules/globebrowsing/globebrowsingmodule_lua.inl @@ -84,7 +84,10 @@ int addLayer(lua_State* L) { return 0; } - globe->layerManager()->addLayer(groupID, d); + std::shared_ptr layer = globe->layerManager()->addLayer(groupID, d); + if (layer) { + layer->initialize(); + } return 0; } diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index 5b50ab4297..0e57dc3442 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -259,17 +259,24 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) addPropertySubOwner(_layerManager.get()); //addPropertySubOwner(_pointGlobe.get()); +} + +void RenderableGlobe::initializeGL() { + _layerManager->initialize(); + + _layerManager->update(); + + _distanceSwitch.initializeGL(); + // Recompile the shaders directly so that it is not done the first time the render // function is called. _chunkedLodGlobe->recompileShaders(); } -void RenderableGlobe::initialize() { - _distanceSwitch.initialize(); -} +void RenderableGlobe::deinitializeGL() { + _distanceSwitch.deinitializeGL(); -void RenderableGlobe::deinitialize() { - _distanceSwitch.deinitialize(); + _layerManager->deinitialize(); } bool RenderableGlobe::isReady() const { diff --git a/modules/globebrowsing/globes/renderableglobe.h b/modules/globebrowsing/globes/renderableglobe.h index 2dc6f001ab..f4e0ad28b3 100644 --- a/modules/globebrowsing/globes/renderableglobe.h +++ b/modules/globebrowsing/globes/renderableglobe.h @@ -81,8 +81,8 @@ public: RenderableGlobe(const ghoul::Dictionary& dictionary); ~RenderableGlobe() = default; - void initialize() override; - void deinitialize() override; + void initializeGL() override; + void deinitializeGL() override; bool isReady() const override; void render(const RenderData& data, RendererTasks& rendererTask) override; diff --git a/modules/globebrowsing/other/distanceswitch.cpp b/modules/globebrowsing/other/distanceswitch.cpp index 043dc78967..4d5cbb08e9 100644 --- a/modules/globebrowsing/other/distanceswitch.cpp +++ b/modules/globebrowsing/other/distanceswitch.cpp @@ -37,6 +37,13 @@ bool DistanceSwitch::initialize() { return true; } +bool DistanceSwitch::initializeGL() { + for (unsigned int i = 0; i < _renderables.size(); ++i) { + _renderables[i]->initializeGL(); + } + return true; +} + bool DistanceSwitch::deinitialize() { for (unsigned int i = 0; i < _renderables.size(); ++i) { _renderables[i]->deinitialize(); @@ -44,6 +51,13 @@ bool DistanceSwitch::deinitialize() { return true; } +bool DistanceSwitch::deinitializeGL() { + for (unsigned int i = 0; i < _renderables.size(); ++i) { + _renderables[i]->deinitializeGL(); + } + return true; +} + void DistanceSwitch::render(const RenderData& data, RendererTasks& tasks) { const double distanceToCamera = distance(data.camera.positionVec3(), data.modelTransform.translation); diff --git a/modules/globebrowsing/other/distanceswitch.h b/modules/globebrowsing/other/distanceswitch.h index 2a3d63271b..810c1f71fd 100644 --- a/modules/globebrowsing/other/distanceswitch.h +++ b/modules/globebrowsing/other/distanceswitch.h @@ -46,7 +46,9 @@ public: ~DistanceSwitch(); bool initialize(); + bool initializeGL(); bool deinitialize(); + bool deinitializeGL(); /** * Picks the first Renderable with the associated maxDistance greater than the diff --git a/modules/globebrowsing/rendering/chunkrenderer.cpp b/modules/globebrowsing/rendering/chunkrenderer.cpp index 41e504094f..b420caa61f 100644 --- a/modules/globebrowsing/rendering/chunkrenderer.cpp +++ b/modules/globebrowsing/rendering/chunkrenderer.cpp @@ -38,7 +38,7 @@ namespace openspace::globebrowsing { ChunkRenderer::ChunkRenderer(std::shared_ptr grid, std::shared_ptr layerManager) : _grid(grid) - ,_layerManager(layerManager) + , _layerManager(layerManager) { _globalLayerShaderManager = std::make_shared( "GlobalChunkedLodPatch", diff --git a/modules/globebrowsing/rendering/layer/layer.cpp b/modules/globebrowsing/rendering/layer/layer.cpp index e99d0d1d23..76fe4e1766 100644 --- a/modules/globebrowsing/rendering/layer/layer.cpp +++ b/modules/globebrowsing/rendering/layer/layer.cpp @@ -173,12 +173,16 @@ Layer::Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict, } }); - _remove.onChange([&](){ - if (_tileProvider) { - _tileProvider->reset(); + _remove.onChange([&]() { + try { + if (_tileProvider) { + _tileProvider->reset(); + } + } + catch (...) { + _parent.deleteLayer(name()); + throw; } - - _parent.deleteLayer(name()); }); _typeOption.onChange([&](){ @@ -221,6 +225,18 @@ Layer::Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict, addPropertySubOwner(_layerAdjustment); } +void Layer::initialize() { + if (_tileProvider) { + _tileProvider->initialize(); + } +} + +void Layer::deinitialize() { + if (_tileProvider) { + _tileProvider->deinitialize(); + } +} + ChunkTilePile Layer::getChunkTilePile(const TileIndex& tileIndex, int pileSize) const { if (_tileProvider) { return _tileProvider->getChunkTilePile(tileIndex, pileSize); diff --git a/modules/globebrowsing/rendering/layer/layer.h b/modules/globebrowsing/rendering/layer/layer.h index 9af39b7a02..d7c4f1afca 100644 --- a/modules/globebrowsing/rendering/layer/layer.h +++ b/modules/globebrowsing/rendering/layer/layer.h @@ -56,6 +56,9 @@ public: Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict, LayerGroup& parent); + void initialize(); + void deinitialize(); + ChunkTilePile getChunkTilePile(const TileIndex& tileIndex, int pileSize) const; Tile::Status getTileStatus(const TileIndex& index) const; diff --git a/modules/globebrowsing/rendering/layer/layergroup.cpp b/modules/globebrowsing/rendering/layer/layergroup.cpp index aaa6aed481..cd089d58c3 100644 --- a/modules/globebrowsing/rendering/layer/layergroup.cpp +++ b/modules/globebrowsing/rendering/layer/layergroup.cpp @@ -79,6 +79,18 @@ LayerGroup::LayerGroup(layergroupid::GroupID id, const ghoul::Dictionary& dict) } } +void LayerGroup::initialize() { + for (const std::shared_ptr& l : _layers) { + l->initialize(); + } +} + +void LayerGroup::deinitialize() { + for (const std::shared_ptr& l : _layers) { + l->deinitialize(); + } +} + void LayerGroup::update() { _activeLayers.clear(); @@ -90,26 +102,28 @@ void LayerGroup::update() { } } -void LayerGroup::addLayer(const ghoul::Dictionary& layerDict) { +std::shared_ptr LayerGroup::addLayer(const ghoul::Dictionary& layerDict) { if (!layerDict.hasKeyAndValue("Name")) { LERROR("'Name' must be specified for layer."); - return; + return nullptr; } auto layer = std::make_shared(_groupId, layerDict, *this); layer->onChange(_onChangeCallback); if (hasPropertySubOwner(layer->name())) { LINFO("Layer with name " + layer->name() + " already exists."); + _levelBlendingEnabled.setVisibility(properties::Property::Visibility::User); + return nullptr; } else { _layers.push_back(layer); - update(); + //update(); if (_onChangeCallback) { _onChangeCallback(); } addPropertySubOwner(layer.get()); + _levelBlendingEnabled.setVisibility(properties::Property::Visibility::User); + return layer; } - - _levelBlendingEnabled.setVisibility(properties::Property::Visibility::User); } void LayerGroup::deleteLayer(const std::string& layerName) { @@ -119,6 +133,7 @@ void LayerGroup::deleteLayer(const std::string& layerName) { { if (it->get()->name() == layerName) { removePropertySubOwner(it->get()); + (*it)->deinitialize(); _layers.erase(it); update(); if (_onChangeCallback) { diff --git a/modules/globebrowsing/rendering/layer/layergroup.h b/modules/globebrowsing/rendering/layer/layergroup.h index 602cfaf342..e08641b333 100644 --- a/modules/globebrowsing/rendering/layer/layergroup.h +++ b/modules/globebrowsing/rendering/layer/layergroup.h @@ -46,10 +46,13 @@ struct LayerGroup : public properties::PropertyOwner { LayerGroup(layergroupid::GroupID id); LayerGroup(layergroupid::GroupID id, const ghoul::Dictionary& dict); + void initialize(); + void deinitialize(); + /// Updates all layers tile providers within this group void update(); - void addLayer(const ghoul::Dictionary& layerDict); + std::shared_ptr addLayer(const ghoul::Dictionary& layerDict); void deleteLayer(const std::string& layerName); /// @returns const vector of all layers diff --git a/modules/globebrowsing/rendering/layer/layermanager.cpp b/modules/globebrowsing/rendering/layer/layermanager.cpp index 2b7942d981..d3a870d063 100644 --- a/modules/globebrowsing/rendering/layer/layermanager.cpp +++ b/modules/globebrowsing/rendering/layer/layermanager.cpp @@ -68,9 +68,23 @@ LayerManager::LayerManager(const ghoul::Dictionary& layerGroupsDict) } } -void LayerManager::addLayer(layergroupid::GroupID groupId, ghoul::Dictionary layerDict) { +void LayerManager::initialize() { + for (const std::shared_ptr& lg : _layerGroups) { + lg->initialize(); + } +} + +void LayerManager::deinitialize() { + for (const std::shared_ptr& lg : _layerGroups) { + lg->deinitialize(); + } +} + +std::shared_ptr LayerManager::addLayer(layergroupid::GroupID groupId, + ghoul::Dictionary layerDict) +{ ghoul_assert(groupId != layergroupid::Unknown, "Layer group ID must be known"); - _layerGroups[groupId]->addLayer(layerDict); + return _layerGroups[groupId]->addLayer(layerDict); } void LayerManager::deleteLayer(layergroupid::GroupID groupId, std::string layerName) { diff --git a/modules/globebrowsing/rendering/layer/layermanager.h b/modules/globebrowsing/rendering/layer/layermanager.h index ec877a4539..1ffbbeb334 100644 --- a/modules/globebrowsing/rendering/layer/layermanager.h +++ b/modules/globebrowsing/rendering/layer/layermanager.h @@ -45,7 +45,10 @@ class LayerManager : public properties::PropertyOwner { public: LayerManager(const ghoul::Dictionary& textureCategoriesDictionary); - void addLayer(layergroupid::GroupID groupId, ghoul::Dictionary layerDict); + void initialize(); + void deinitialize(); + + 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/temporaltileprovider.cpp b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp index 85999d9b84..af24cfbc68 100644 --- a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp @@ -86,15 +86,10 @@ TemporalTileProvider::TemporalTileProvider(const ghoul::Dictionary& dictionary) if (hasStart && hasEnd) { const std::string start = dictionary.value(KeyPreCacheStartTime); const std::string end = dictionary.value(KeyPreCacheEndTime); - std::vector