diff --git a/include/openspace/rendering/renderablepath.h b/include/openspace/rendering/renderablepath.h index dc3d12c7c1..b116f0f40a 100644 --- a/include/openspace/rendering/renderablepath.h +++ b/include/openspace/rendering/renderablepath.h @@ -52,7 +52,7 @@ namespace openspace { private: ghoul::opengl::ProgramObject* _programObject; void loadTexture(); - void fullYearSweep(); + bool fullYearSweep(); // modfile reads // spice diff --git a/include/openspace/rendering/renderabletrail.h b/include/openspace/rendering/renderabletrail.h index 54d7a42376..201ba32539 100644 --- a/include/openspace/rendering/renderabletrail.h +++ b/include/openspace/rendering/renderabletrail.h @@ -55,6 +55,8 @@ public: void loadTexture(); void fullYearSweep(); + bool _successfullDictionaryFetch; + // modfile reads // spice std::string _target; diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 5a3015401b..3a8d2b7af9 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -32,6 +32,7 @@ #include #include #include +#include namespace { const std::string _loggerCat = "Renderable"; @@ -69,9 +70,14 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary) : _enabled("enabled", "Is Enabled", true) { setName("renderable"); - +#ifndef NDEBUG + std::string name; + ghoul_assert(dictionary.getValue(constants::scenegraphnode::keyName, name), + "Scenegraphnode need to specify '" << constants::scenegraphnode::keyName + << "' because renderables is going to use this for debugging!"); +#endif // get path if available - const bool success = dictionary.getValue(constants::scenegraph::keyPathModule, _relativePath); + bool success = dictionary.getValue(constants::scenegraph::keyPathModule, _relativePath); if (success) _relativePath += ghoul::filesystem::FileSystem::PathSeparator; diff --git a/src/rendering/renderablefieldlines.cpp b/src/rendering/renderablefieldlines.cpp index 99caf2244d..755a78178d 100644 --- a/src/rendering/renderablefieldlines.cpp +++ b/src/rendering/renderablefieldlines.cpp @@ -48,12 +48,11 @@ RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary) , _shader(nullptr) { std::string name; - bool success = dictionary.getValue(constants::scenegraphnode::keyName, name); - assert(success); + dictionary.getValue(constants::scenegraphnode::keyName, name); // Read fieldlines module into dictionary ghoul::Dictionary fieldlines; - success = dictionary.getValue(keyFieldlines, fieldlines); + bool success = dictionary.getValue(keyFieldlines, fieldlines); if (!success) { LERROR("RenderableFieldlines '" << name << "' did not contain a '" << keyFieldlines << "' key"); diff --git a/src/rendering/renderablefov.cpp b/src/rendering/renderablefov.cpp index 3f8f6b46dc..1b3507ded7 100644 --- a/src/rendering/renderablefov.cpp +++ b/src/rendering/renderablefov.cpp @@ -1,26 +1,26 @@ /***************************************************************************************** -* * -* OpenSpace * -* * -* Copyright (c) 2014 * -* * -* 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. * -****************************************************************************************/ + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * 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 @@ -54,13 +54,10 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary) , _vBufferID(0) , _iBufferID(0) { - - bool b1 = dictionary.getValue(keyBody, _target); - bool b2 = dictionary.getValue(keyObserver, _observer); - bool b3 = dictionary.getValue(keyFrame, _frame); - assert(b1 == true); - assert(b2 == true); - assert(b3 == true); + // @TODO Uncomment when used again, do not depend on assert in constructor --jonasstrandstedt + //dictionary.getValue(keyBody, _target); + //dictionary.getValue(keyObserver, _observer); + //dictionary.getValue(keyFrame, _frame); if (!dictionary.getValue(keyColor, _c)){ _c = glm::vec3(0.0); @@ -97,7 +94,10 @@ RenderableFov::~RenderableFov(){ } bool RenderableFov::isReady() const { - return _programObject != nullptr; + bool ready = true; + ready &= (_programObject != nullptr); + + return ready; } void RenderableFov::sendToGPU(){ @@ -130,7 +130,6 @@ bool RenderableFov::initialize(){ if (_programObject == nullptr) completeSuccess &= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject); - _startTrail; SpiceManager::ref().getETfromDate("2007 feb 26 20:00:00", _startTrail); fullYearSweep(); @@ -232,6 +231,7 @@ void RenderableFov::render(const RenderData& data){ } void RenderableFov::update(const UpdateData& data){ + double lightTime; _time = data.time; _delta = data.delta; diff --git a/src/rendering/renderablepath.cpp b/src/rendering/renderablepath.cpp index 588b63a2aa..9513f9c783 100644 --- a/src/rendering/renderablepath.cpp +++ b/src/rendering/renderablepath.cpp @@ -53,19 +53,19 @@ RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary) , _iBufferID(0) { - bool b1 = dictionary.getValue(keyBody, _target); - bool b2 = dictionary.getValue(keyObserver, _observer); - bool b3 = dictionary.getValue(keyFrame, _frame); - assert(b1 == true); - assert(b2 == true); - assert(b3 == true); - /*assert(dictionary.getValue(keyTropicalOrbitPeriod, _tropic)); - assert(dictionary.getValue(keyEarthOrbitRatio, _ratio)); - assert(dictionary.getValue(keyDayLength, _day));//not used now, will be though. - // values in modfiles set from here*/ + dictionary.getValue(keyBody, _target); + dictionary.getValue(keyObserver, _observer); + dictionary.getValue(keyFrame, _frame); + + // not used now, will be though. + // dictionary.getValue(keyTropicalOrbitPeriod, _tropic); + // dictionary.getValue(keyEarthOrbitRatio, _ratio); + // dictionary.getValue(keyDayLength, _day); + + // values in modfiles set from here // http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html - //white is default col + // white is default col if (!dictionary.getValue(keyColor, _c)){ _c = glm::vec3(0.0); } @@ -75,7 +75,7 @@ RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary) _b = 1 / _c[2]; } } -void RenderablePath::fullYearSweep(){ +bool RenderablePath::fullYearSweep(){ double lightTime = 0.0; SpiceManager::ref().getETfromDate("2006 jan 20 19:00:00", _time); @@ -98,7 +98,14 @@ void RenderablePath::fullYearSweep(){ for (int i = 0; i < segments + 1; i++){ std::cout << i << std::endl; bool gotData = SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "LT+S", et, _pscpos, lightTime); - assert(gotData); + +#ifndef NDEBUG + if (!gotData) { + LERROR("Could not fetch data from spice!"); + return false; + } +#endif + if (_pscpos[0] != 0 && _pscpos[1] != 0 && _pscpos[2] != 0 && _pscpos[3] != 1){ _pscpos[3] += 3; _varray.push_back(_pscpos[0]); @@ -131,6 +138,7 @@ void RenderablePath::fullYearSweep(){ _stride = 8; _vsize = _varray.size(); _vtotal = static_cast(_vsize / _stride); + return true; } RenderablePath::~RenderablePath(){ @@ -138,18 +146,33 @@ RenderablePath::~RenderablePath(){ } bool RenderablePath::isReady() const { - return _programObject != nullptr; + bool ready = true; + ready &= (_programObject != nullptr); + return ready; } bool RenderablePath::initialize(){ + + if (_target.empty() || _observer.empty() || _frame.empty()) { + LERROR("The following keys need to be set in the Dictionary. Cannot initialize!"); + LERROR(keyBody << ": " << _target); + LERROR(keyObserver << ": " << _observer); + LERROR(keyFrame << ": " << _frame); + return false; + } + // Does checking if can fetch spice data (debug mode only) + if (!fullYearSweep()) + return false; + + // If the programobject is fetched after the string checking, then + // the isReady function will properly reflect the state of this object + // -- jonasstrandstedt bool completeSuccess = true; if (_programObject == nullptr) completeSuccess &= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject); - fullYearSweep(); - // Initialize and upload to graphics card glGenVertexArrays(1, &_vaoID); glGenBuffers(1, &_vBufferID); @@ -176,6 +199,9 @@ bool RenderablePath::initialize(){ } bool RenderablePath::deinitialize(){ + glDeleteVertexArrays(1, &_vaoID); + glDeleteBuffers(1, &_vBufferID); + glDeleteBuffers(1, &_iBufferID); return true; } @@ -211,6 +237,10 @@ void RenderablePath::render(const RenderData& data){ } void RenderablePath::update(const UpdateData& data){ +#ifndef NDEBUG + if (_target.empty() || _observer.empty() || _frame.empty()) + return; +#endif double lightTime; _time = data.time; diff --git a/src/rendering/renderablesphericalgrid.cpp b/src/rendering/renderablesphericalgrid.cpp index 3aee338b6d..3110cbf8dd 100644 --- a/src/rendering/renderablesphericalgrid.cpp +++ b/src/rendering/renderablesphericalgrid.cpp @@ -129,10 +129,16 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio RenderableSphericalGrid::~RenderableSphericalGrid(){ deinitialize(); + + // Delete not done in deinitialize because new is done in constructor + delete[] _varray; + delete[] _iarray; } bool RenderableSphericalGrid::isReady() const { - return _gridProgram != nullptr; + bool ready = true; + ready &= (_gridProgram != nullptr); + return ready; } bool RenderableSphericalGrid::deinitialize(){ diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 80bcef3627..7c73b06497 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -55,38 +55,27 @@ namespace { } //#define DEBUG namespace openspace{ - RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) - : Renderable(dictionary) - , _colorTexturePath("colorTexture", "Color Texture") - , _programObject(nullptr) - , _texture(nullptr) - , _vaoID(0) - , _vBufferID(0) - , _iBufferID(0) - , _mode(GL_LINE_STRIP){ +RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _colorTexturePath("colorTexture", "Color Texture") + , _programObject(nullptr) + , _texture(nullptr) + , _vaoID(0) + , _vBufferID(0) + , _iBufferID(0) + , _mode(GL_LINE_STRIP) +{ - bool b1 = dictionary.getValue(keyBody, _target); - bool b2 = dictionary.getValue(keyObserver, _observer); - bool b3 = dictionary.getValue(keyFrame, _frame); - bool b4 = dictionary.getValue(keyTropicalOrbitPeriod, _tropic); - bool b5 = dictionary.getValue(keyEarthOrbitRatio, _ratio); - bool b6 = dictionary.getValue(keyDayLength, _day); + _successfullDictionaryFetch = true; + _successfullDictionaryFetch &= dictionary.getValue(keyBody, _target); + _successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer); + _successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame); + _successfullDictionaryFetch &= dictionary.getValue(keyTropicalOrbitPeriod, _tropic); + _successfullDictionaryFetch &= dictionary.getValue(keyEarthOrbitRatio, _ratio); + _successfullDictionaryFetch &= dictionary.getValue(keyDayLength, _day); - assert(b1 == true); - assert(b2 == true); - assert(b3 == true); - assert(b4 == true); - assert(b5 == true); - assert(b6 == true); - - //assert(dictionary.getValue(keyBody , _target)); - //assert(dictionary.getValue(keyObserver, _observer)); - //assert(dictionary.getValue(keyFrame , _frame)); - //assert(dictionary.getValue(keyTropicalOrbitPeriod, _tropic)); - //assert(dictionary.getValue(keyEarthOrbitRatio , _ratio)); - //assert(dictionary.getValue(keyDayLength , _day));//not used now, will be though. - // values in modfiles set from here - // http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html + // values in modfiles set from here + // http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html //white is default col @@ -154,7 +143,9 @@ RenderableTrail::~RenderableTrail(){ } bool RenderableTrail::isReady() const { - return _programObject != nullptr; + bool ready = true; + ready &= (_programObject != nullptr); + return ready; } void RenderableTrail::sendToGPU(){ @@ -183,6 +174,18 @@ void RenderableTrail::sendToGPU(){ bool RenderableTrail::initialize(){ + + if (!_successfullDictionaryFetch) { + LERROR("The following keys need to be set in the Dictionary. Cannot initialize!"); + LERROR(keyBody << ": " << _target); + LERROR(keyObserver << ": " << _observer); + LERROR(keyFrame << ": " << _frame); + LERROR(keyTropicalOrbitPeriod << ": " << _tropic); + LERROR(keyEarthOrbitRatio << ": " << _ratio); + LERROR(keyDayLength << ": " << _day); + return false; + } + bool completeSuccess = true; if (_programObject == nullptr) completeSuccess @@ -203,8 +206,13 @@ bool RenderableTrail::initialize(){ } bool RenderableTrail::deinitialize(){ - delete _texture; + if (_texture) + delete _texture; _texture = nullptr; + + glDeleteVertexArrays(1, &_vaoID); + glDeleteBuffers(1, &_vBufferID); + glDeleteBuffers(1, &_iBufferID); return true; } @@ -226,6 +234,10 @@ psc pscInterpolate(psc p0, psc p1, float t){ */ void RenderableTrail::updateTrail(){ +#ifndef NDEBUG + if (!_successfullDictionaryFetch) + return; +#endif int m = _stride; float *begin = &_varray[0]; //float *end = &_varray[_vsize - 1] + 1; @@ -267,7 +279,6 @@ void RenderableTrail::updateTrail(){ } void RenderableTrail::render(const RenderData& data){ - assert(_programObject); _programObject->activate(); // fetch data