Removed assertions from renderable constructors

- Removed assertions from RenderableFieldlines constructor
- Removed assertions from RenderableFov constructor, the variables wasn't
  even used.
- Removed assertions from RenderablePath constructor
- Fixed missing delete[] is RenderableSphericalGrid
- Removed assertions from RenderableTrail constructor, added glDelete*
  functions
- Removed assertions from RenderablevolumeGL constructor
This commit is contained in:
Jonas Strandstedt
2014-12-12 10:59:28 +01:00
parent 9e61d3ac94
commit 37a59f3f09
8 changed files with 141 additions and 87 deletions

View File

@@ -52,7 +52,7 @@ namespace openspace {
private:
ghoul::opengl::ProgramObject* _programObject;
void loadTexture();
void fullYearSweep();
bool fullYearSweep();
// modfile reads
// spice

View File

@@ -55,6 +55,8 @@ public:
void loadTexture();
void fullYearSweep();
bool _successfullDictionaryFetch;
// modfile reads
// spice
std::string _target;

View File

@@ -32,6 +32,7 @@
#include <ghoul/misc/dictionary.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/misc/assert.h>
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;

View File

@@ -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");

View File

@@ -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 <openspace/rendering/renderablefov.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/constants.h>
@@ -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;

View File

@@ -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<int>(_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;

View File

@@ -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(){

View File

@@ -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