diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index b2abbb7710..aed925b2aa 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -28,7 +28,6 @@ #include #include -#include #include @@ -42,6 +41,10 @@ namespace ghoul { namespace openspace { +struct RenderData; +struct UpdateData; +struct RendererTasks; + namespace documentation { struct Documentation; } // Forward declare to minimize dependencies diff --git a/modules/base/rendering/modelgeometry.cpp b/modules/base/rendering/modelgeometry.cpp index b74f44bd59..5b1cc4b287 100644 --- a/modules/base/rendering/modelgeometry.cpp +++ b/modules/base/rendering/modelgeometry.cpp @@ -25,20 +25,24 @@ #include #include +#include #include + #include #include #include +#include #include namespace { const char* _loggerCat = "ModelGeometry"; - const char* keyGeomModelFile = "GeometryFile"; + + const char* KeyName = "Name"; + const char* KeyType = "Type"; + const char* KeyGeomModelFile = "GeometryFile"; const int8_t CurrentCacheVersion = 3; - const char* keyType = "Type"; - const char* keyName = "Name"; -} +} // namespace namespace openspace { namespace modelgeometry { @@ -50,13 +54,13 @@ documentation:: Documentation ModelGeometry::Documentation() { "base_geometry_model", { { - keyType, + KeyType, new StringVerifier, "The type of the Model Geometry that should be generated", Optional::No }, { - keyGeomModelFile, + KeyGeomModelFile, new StringVerifier, "The file that should be loaded in this ModelGeometry. The file can " "contain filesystem tokens or can be specified relatively to the " @@ -71,25 +75,18 @@ documentation:: Documentation ModelGeometry::Documentation() { std::unique_ptr ModelGeometry::createFromDictionary( const ghoul::Dictionary& dictionary) { - if (!dictionary.hasKeyAndValue(keyType)) { + if (!dictionary.hasKeyAndValue(KeyType)) { throw ghoul::RuntimeError("Dictionary did not contain a key 'Type'"); } - std::string geometryType = dictionary.value(keyType); + const std::string geometryType = dictionary.value(KeyType); + auto factory = FactoryManager::ref().factory(); - - std::unique_ptr result = factory->create(geometryType, dictionary); - if (result == nullptr) { - throw ghoul::RuntimeError( - "Failed to create a ModelGeometry object of type '" + geometryType + "'" - ); - } - return result; + return factory->create(geometryType, dictionary);; } ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary) : properties::PropertyOwner("ModelGeometry") - , _parent(nullptr) , _mode(GL_TRIANGLES) { documentation::testSpecificationAndThrow( @@ -98,11 +95,7 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary) "ModelGeometry" ); - std::string name; - bool success = dictionary.getValue(keyName, name); - ghoul_assert(success, "Name tag was not present"); - - _file = absPath(dictionary.value(keyGeomModelFile)); + _file = absPath(dictionary.value(KeyGeomModelFile)); } double ModelGeometry::boundingRadius() const { @@ -119,10 +112,6 @@ double ModelGeometry::boundingRadius() const { return maxDist; } - -ModelGeometry::~ModelGeometry() { -} - void ModelGeometry::render() { glBindVertexArray(_vaoID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo); @@ -135,39 +124,67 @@ void ModelGeometry::changeRenderMode(const GLenum mode) { } bool ModelGeometry::initialize(Renderable* parent) { - _parent = parent; float maximumDistanceSquared = 0; - for (auto v: _vertices) - { + for (const Vertex& v : _vertices) { maximumDistanceSquared = glm::max( glm::pow(v.location[0], 2.f) + glm::pow(v.location[1], 2.f) + glm::pow(v.location[2], 2.f), maximumDistanceSquared); } - _parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared)); + parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared)); - if (_vertices.empty()) + if (_vertices.empty()) { return false; + } + glGenVertexArrays(1, &_vaoID); glGenBuffers(1, &_vbo); glGenBuffers(1, &_ibo); glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vbo); - glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(Vertex), _vertices.data(), GL_STATIC_DRAW); + glBufferData( + GL_ARRAY_BUFFER, + _vertices.size() * sizeof(Vertex), + _vertices.data(), + GL_STATIC_DRAW + ); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, location))); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, tex))); - glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, normal))); + glVertexAttribPointer( + 0, + 4, + GL_FLOAT, + GL_FALSE, + sizeof(Vertex), + reinterpret_cast(offsetof(Vertex, location)) + ); + glVertexAttribPointer( + 1, + 2, + GL_FLOAT, + GL_FALSE, + sizeof(Vertex), + reinterpret_cast(offsetof(Vertex, tex)) + ); + glVertexAttribPointer( + 2, + 3, + GL_FLOAT, + GL_FALSE, + sizeof(Vertex), + reinterpret_cast(offsetof(Vertex, normal)) + ); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, _indices.size() * sizeof(int), _indices.data(), GL_STATIC_DRAW); + glBufferData( + GL_ELEMENT_ARRAY_BUFFER, + _indices.size() * sizeof(int), + _indices.data(), + GL_STATIC_DRAW + ); glBindVertexArray(0); @@ -181,37 +198,42 @@ void ModelGeometry::deinitialize() { } bool ModelGeometry::loadObj(const std::string& filename) { - std::string cachedFile = FileSys.cacheManager()->cachedFilename( + const std::string cachedFile = FileSys.cacheManager()->cachedFilename( filename, ghoul::filesystem::CacheManager::Persistent::Yes - ); + ); - bool hasCachedFile = FileSys.fileExists(cachedFile); + const bool hasCachedFile = FileSys.fileExists(cachedFile); if (hasCachedFile) { - LINFO("Cached file '" << cachedFile << "' used for Model file '" << filename << "'"); + LINFO("Cached file '" << cachedFile << "' used for file '" << filename << "'"); - bool success = loadCachedFile(cachedFile); - if (success) + const bool success = loadCachedFile(cachedFile); + if (success) { return true; - else + } + else { FileSys.cacheManager()->removeCacheFile(filename); + } // Intentional fall-through to the 'else' computation to generate the cache // file for the next run } else { - LINFO("Cached file '" << cachedFile << "' used for Model file '" << filename << "' not found"); + LINFO( + "Cached file '" << cachedFile << "' for file '" << filename << "' not found" + ); } LINFO("Loading Model file '" << filename << "'"); - bool success = loadModel(filename); + const bool modelSuccess = loadModel(filename); - if (!success) + if (!modelSuccess) { return false; + } LINFO("Saving cache"); - success = saveCachedFile(cachedFile); + const bool cacheSuccess = saveCachedFile(cachedFile); - return success; + return cacheSuccess; } bool ModelGeometry::saveCachedFile(const std::string& filename) { @@ -271,22 +293,6 @@ bool ModelGeometry::loadCachedFile(const std::string& filename) { } } -bool ModelGeometry::getVertices(std::vector* vertexList) { - vertexList->clear(); - for (auto v : _vertices) - vertexList->push_back(v); - - return !(vertexList->empty()); -} - -bool ModelGeometry::getIndices(std::vector* indexList) { - indexList->clear(); - for (auto i : _indices) - indexList->push_back(i); - - return !(indexList->empty()); -} - void ModelGeometry::setUniforms(ghoul::opengl::ProgramObject&) {} } // namespace modelgeometry diff --git a/modules/base/rendering/modelgeometry.h b/modules/base/rendering/modelgeometry.h index 508b523101..f76685404c 100644 --- a/modules/base/rendering/modelgeometry.h +++ b/modules/base/rendering/modelgeometry.h @@ -27,36 +27,46 @@ #include -#include +#include -namespace ghoul { class Dictionary; } +#include + +namespace ghoul { + class Dictionary; + + namespace opengl { class ProgramObject; } +} // namespace ghoul namespace openspace { -namespace documentation { struct Documentation; } +class Renderable; + +namespace documentation { struct Documentation; } namespace modelgeometry { class ModelGeometry : public properties::PropertyOwner { public: - static std::unique_ptr createFromDictionary( - const ghoul::Dictionary& dictionary - ); - struct Vertex { GLfloat location[4]; GLfloat tex[2]; GLfloat normal[3]; }; + static std::unique_ptr createFromDictionary( + const ghoul::Dictionary& dictionary + ); + ModelGeometry(const ghoul::Dictionary& dictionary); - virtual ~ModelGeometry(); + virtual ~ModelGeometry() = default; + virtual bool initialize(Renderable* parent); virtual void deinitialize(); void render(); + virtual bool loadModel(const std::string& filename) = 0; void changeRenderMode(const GLenum mode); - bool getVertices(std::vector* vertexList); - bool getIndices(std::vector* indexList); + //bool getVertices(std::vector* vertexList); + //bool getIndices(std::vector* indexList); double boundingRadius() const; @@ -65,8 +75,6 @@ public: static documentation::Documentation Documentation(); protected: - Renderable* _parent; - bool loadObj(const std::string& filename); bool loadCachedFile(const std::string& filename); bool saveCachedFile(const std::string& filename); diff --git a/modules/base/rendering/multimodelgeometry.cpp b/modules/base/rendering/multimodelgeometry.cpp index 5428bd5724..ab6b249457 100644 --- a/modules/base/rendering/multimodelgeometry.cpp +++ b/modules/base/rendering/multimodelgeometry.cpp @@ -24,15 +24,7 @@ #include -#include "ghoul/logging/logmanager.h" #include "ghoul/io/model/modelreadermultiformat.h" -#include "ghoul/opengl/vertexbufferobject.h" - -#include - -namespace { - const std::string _loggerCat = "MultiModelGeometry"; -} namespace openspace { namespace modelgeometry { @@ -43,25 +35,13 @@ MultiModelGeometry::MultiModelGeometry(const ghoul::Dictionary& dictionary) loadObj(_file); } -bool MultiModelGeometry::initialize(Renderable* parent) { - bool success = ModelGeometry::initialize(parent); - return success; -} - -void MultiModelGeometry::deinitialize() { - ModelGeometry::deinitialize(); -} - bool MultiModelGeometry::loadModel(const std::string& filename) { - ghoul::io::ModelReaderMultiFormat modelReader; - std::vector vertices; std::vector indices; - - modelReader.loadModel(filename, vertices, indices); + ghoul::io::ModelReaderMultiFormat().loadModel(filename, vertices, indices); _vertices.reserve(vertices.size()); - for (const auto & v : vertices) { + for (const ghoul::io::ModelReaderBase::Vertex& v : vertices) { Vertex vv; memcpy(vv.location, v.location, sizeof(GLfloat) * 3); vv.location[3] = 1.0; diff --git a/modules/base/rendering/multimodelgeometry.h b/modules/base/rendering/multimodelgeometry.h index dedd7f256c..57f255f646 100644 --- a/modules/base/rendering/multimodelgeometry.h +++ b/modules/base/rendering/multimodelgeometry.h @@ -38,9 +38,6 @@ class MultiModelGeometry : public ModelGeometry { public: MultiModelGeometry(const ghoul::Dictionary& dictionary); - bool initialize(Renderable* parent) override; - void deinitialize() override; - private: bool loadModel(const std::string& filename); }; diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index d1d2cfebee..8fc7f385ef 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -24,38 +24,33 @@ #include +#include + #include #include -#include -#include #include - -#include -#include -#include -#include - -#include -#include - #include +#include +#include +#include -#define _USE_MATH_DEFINES -#include +#include +#include +#include +#include +#include +#include namespace { - const std::string _loggerCat = "RenderableModel"; - const char* KeyGeometry = "Geometry"; const char* KeyTexture = "Textures.Color"; - + const char* KeyModelTransform = "Rotation.ModelTransform"; + const char* KeyFading = "Shading.Fadeable"; const char* keyBody = "Body"; const char* keyStart = "StartTime"; const char* keyEnd = "EndTime"; - const char* keyFading = "Shading.Fadeable"; - const char* keyModelTransform = "Rotation.ModelTransform"; } // namespace namespace openspace { @@ -75,9 +70,23 @@ documentation::Documentation RenderableModel::Documentation() { { KeyTexture, new StringVerifier, - "A color texture that can be applied to the model specified bny the " + "A color texture that can be applied to the model specified by the " "Geometry.", Optional::Yes + }, + { + KeyModelTransform, + new DoubleMatrix3Verifier, + "Specifies a distinct transformation matrix that is applied to the " + "model. If it is not specified, it is equal to the Identity matrix.", + Optional::Yes + }, + { + KeyFading, + new BoolVerifier, + "Specifies whether the model should be periodically fading in and out. " + "If this value is not specified, it will not fade.", + Optional::Yes } } }; @@ -85,16 +94,14 @@ documentation::Documentation RenderableModel::Documentation() { RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) : Renderable(dictionary) + , _geometry(nullptr) , _colorTexturePath("colorTexture", "Color Texture") , _performFade("performFading", "Perform Fading", false) + , _performShading("performShading", "Perform Shading", true) , _fading("fading", "Fade", 0) - , _debugModelRotation("modelrotation", "Model Rotation", glm::vec3(0.f), glm::vec3(0.f), glm::vec3(360.f)) , _programObject(nullptr) , _texture(nullptr) - , _geometry(nullptr) - , _alpha(1.f) - , _performShading("performShading", "Perform Shading", true) - , _frameCount(0) + , _modelTransform(1.0) { ghoul_precondition( dictionary.hasKeyAndValue(SceneGraphNode::KeyName), @@ -107,7 +114,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) "RenderableModel" ); - if (dictionary.hasKey(KeyGeometry)) { std::string name = dictionary.value(SceneGraphNode::KeyName); ghoul::Dictionary dict = dictionary.value(KeyGeometry); @@ -119,57 +125,39 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _colorTexturePath = absPath(dictionary.value(KeyTexture)); } + if (dictionary.hasKey(KeyModelTransform)) { + _modelTransform = dictionary.value(KeyModelTransform); + } + + if (dictionary.hasKey(KeyFading)) { + _performFade = dictionary.value(KeyFading); + } + addPropertySubOwner(_geometry.get()); addProperty(_colorTexturePath); _colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this)); - addProperty(_debugModelRotation); - - if (dictionary.hasKeyAndValue(keyModelTransform)) { - dictionary.getValue(keyModelTransform, _modelTransform); - } - else { - _modelTransform = glm::dmat3(1.f); - } addProperty(_performShading); - - if (dictionary.hasKeyAndValue(keyFading)) { - bool fading; - dictionary.getValue(keyFading, fading); - _performFade = fading; - } addProperty(_performFade); } bool RenderableModel::isReady() const { - bool ready = true; - ready &= (_programObject != nullptr); - ready &= (_texture != nullptr); - return ready; + return _programObject && _texture; } bool RenderableModel::initialize() { - bool completeSuccess = true; - if (_programObject == nullptr) { - // NH shader - - RenderEngine& renderEngine = OsEng.renderEngine(); - _programObject = renderEngine.buildRenderProgram("ModelProgram", - "${MODULE_BASE}/shaders/model_vs.glsl", - "${MODULE_BASE}/shaders/model_fs.glsl"); - - if (!_programObject) - return false; - } + _programObject = OsEng.renderEngine().buildRenderProgram( + "ModelProgram", + "${MODULE_BASE}/shaders/model_vs.glsl", + "${MODULE_BASE}/shaders/model_fs.glsl" + ); loadTexture(); + bool completeSuccess = true; completeSuccess &= (_texture != nullptr); completeSuccess &= _geometry->initialize(this); - //completeSuccess &= !_source.empty(); - //completeSuccess &= !_destination.empty(); - return completeSuccess; } @@ -180,10 +168,8 @@ bool RenderableModel::deinitialize() { } _texture = nullptr; - - RenderEngine& renderEngine = OsEng.renderEngine(); if (_programObject) { - renderEngine.removeRenderProgram(_programObject); + OsEng.renderEngine().removeRenderProgram(_programObject); _programObject = nullptr; } @@ -199,30 +185,18 @@ void RenderableModel::render(const RenderData& data) { } else if (!_performFade && _fading < 1.f) { _fading = _fading + 0.01f; - } - - // debug rotation controlled from GUI - glm::mat4 unitMat4(1); - glm::vec3 debugEulerRot = glm::radians(_debugModelRotation.value()); - glm::mat4 rotX = glm::rotate(unitMat4, debugEulerRot.x, glm::vec3(1, 0, 0)); - glm::mat4 rotY = glm::rotate(unitMat4, debugEulerRot.y, glm::vec3(0, 1, 0)); - glm::mat4 rotZ = glm::rotate(unitMat4, debugEulerRot.z, glm::vec3(0, 0, 1)); - glm::dmat4 debugModelRotation = rotX * rotY * rotZ; - // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation glm::dmat4(data.modelTransform.rotation) * // Spice rotation glm::dmat4(glm::scale(glm::dmat4(_modelTransform), glm::dvec3(data.modelTransform.scale))); - debugModelRotation; // debug model rotation controlled from GUI glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; glm::vec3 directionToSun = glm::normalize(_sunPos - data.modelTransform.translation); glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun; - _programObject->setUniform("transparency", _alpha); _programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace); _programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform)); _programObject->setUniform("projectionTransform", data.camera.projectionMatrix()); @@ -239,7 +213,6 @@ void RenderableModel::render(const RenderData& data) { _geometry->render(); - // disable shader _programObject->deactivate(); } @@ -247,23 +220,6 @@ void RenderableModel::update(const UpdateData& data) { if (_programObject->isDirty()) { _programObject->rebuildFromFile(); } -// double _time = data.time; - - //if (_isGhost){ - // futureTime = openspace::ImageSequencer::ref().getNextCaptureTime(); - // double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - data.time; - // double interval = openspace::ImageSequencer::ref().getIntervalLength(); - // double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength(); - // if (interval > 60) { - // if (t < 0.8) - // _fading = static_cast(t); - // else if (t >= 0.95) - // _fading = _fading - 0.5f; - // } - // else - // _fading = 0.f; - // _time = futureTime; - //} _sunPos = OsEng.renderEngine().scene()->sceneGraphNode("Sun")->worldPosition(); } @@ -273,7 +229,10 @@ void RenderableModel::loadTexture() { if (_colorTexturePath.value() != "") { _texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)); if (_texture) { - LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'"); + LDEBUGC( + "RenderableModel", + "Loaded texture from '" << absPath(_colorTexturePath) << "'" + ); _texture->uploadTexture(); _texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); } diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 03f1798f99..f169710df7 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -31,15 +31,21 @@ #include #include #include -#include - -#include -#include #include +namespace ghoul { +namespace opengl { + class ProgramObject; + class Texture; +} // namespace opengl +} // namespace ghoul + namespace openspace { +struct RenderData; +struct UpdateData; + namespace documentation { struct Documentation; } namespace modelgeometry { @@ -64,24 +70,18 @@ protected: void loadTexture(); private: + std::unique_ptr _geometry; + properties::StringProperty _colorTexturePath; properties::BoolProperty _performFade; + properties::BoolProperty _performShading; properties::FloatProperty _fading; + std::unique_ptr _programObject; std::unique_ptr _texture; - std::unique_ptr _geometry; - glm::dmat3 _modelTransform; - - float _alpha; - - int _frameCount; - glm::dvec3 _sunPos; - - properties::BoolProperty _performShading; - properties::Vec3Property _debugModelRotation; }; } // namespace openspace diff --git a/modules/base/rendering/renderableplane.cpp b/modules/base/rendering/renderableplane.cpp index cb7e9129bb..1398d290b2 100644 --- a/modules/base/rendering/renderableplane.cpp +++ b/modules/base/rendering/renderableplane.cpp @@ -26,13 +26,10 @@ #include #include -#include #include -#include - -#include #include -#include +#include +#include #include #include @@ -45,14 +42,6 @@ namespace { const char* KeyBillboard = "Billboard"; const char* KeyBlendMode = "BlendMode"; const char* KeyTexture = "Texture"; - - - const char* keyFieldlines = "Fieldlines"; - const char* keyFilename = "File"; - const char* keyHints = "Hints"; - const char* keyShaders = "Shaders"; - const char* keyVertexShader = "VertexShader"; - const char* keyFragmentShader = "FragmentShader"; } // namespace namespace openspace { @@ -102,11 +91,12 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary) , _billboard("billboard", "Billboard", false) , _size("size", "Size", 10, 0, std::pow(10, 25)) , _shader(nullptr) - , _textureIsDirty(false) , _texture(nullptr) , _blendMode(BlendMode::Normal) , _quad(0) , _vertexPositionBuffer(0) + , _planeIsDirty(false) + , _textureIsDirty(false) { documentation::testSpecificationAndThrow( Documentation(), @@ -131,7 +121,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary) } } _texturePath = absPath(dictionary.value(KeyTexture)); - _textureFile = new ghoul::filesystem::File(_texturePath); + _textureFile = std::make_unique(_texturePath); addProperty(_billboard); addProperty(_texturePath); @@ -146,11 +136,6 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary) setBoundingSphere(_size); } -RenderablePlane::~RenderablePlane() { - delete _textureFile; - _textureFile = nullptr; -} - bool RenderablePlane::isReady() const { return _shader && _texture; } @@ -177,7 +162,6 @@ bool RenderablePlane::deinitialize() { glDeleteBuffers(1, &_vertexPositionBuffer); _vertexPositionBuffer = 0; - delete _textureFile; _textureFile = nullptr; RenderEngine& renderEngine = OsEng.renderEngine(); @@ -190,9 +174,6 @@ bool RenderablePlane::deinitialize() { } void RenderablePlane::render(const RenderData& data) { - glm::mat4 scaleTransform = glm::mat4(1.0); - - // Activate shader _shader->activate(); //if (_projectionListener){ // //get parent node-texture and set with correct dimensions @@ -208,28 +189,20 @@ void RenderablePlane::render(const RenderData& data) { //} // Model transform and view transform needs to be in double precision - glm::dmat4 rotationTransform; - if (_billboard) { - rotationTransform = glm::inverse(glm::dmat4(data.camera.viewRotationMatrix())); - } - else { - rotationTransform = glm::dmat4(data.modelTransform.rotation); - } + const glm::dmat4 rotationTransform = _billboard ? + glm::inverse(glm::dmat4(data.camera.viewRotationMatrix())) : + glm::dmat4(data.modelTransform.rotation); - glm::dmat4 modelTransform = + const glm::dmat4 modelTransform = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * rotationTransform * glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))) * - glm::dmat4(scaleTransform); - glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; + glm::dmat4(1.0); + const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; _shader->setUniform("modelViewProjectionTransform", data.camera.projectionMatrix() * glm::mat4(modelViewTransform)); - //_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); - //_shader->setUniform("ModelTransform", transform); - //setPscUniforms(*_shader.get(), data.camera, data.position); - ghoul::opengl::TextureUnit unit; unit.activate(); _texture->bind(); @@ -292,19 +265,15 @@ void RenderablePlane::loadTexture() { _texture = std::move(texture); - delete _textureFile; - _textureFile = new ghoul::filesystem::File(_texturePath); + _textureFile = std::make_unique(_texturePath); _textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; }); } } } void RenderablePlane::createPlane() { - // ============================ - // GEOMETRY (quad) - // ============================ const GLfloat size = _size; - const GLfloat vertex_data[] = { + const GLfloat vertexData[] = { // x y z w s t -size, -size, 0.f, 0.f, 0.f, 0.f, size, size, 0.f, 0.f, 1.f, 1.f, @@ -314,13 +283,28 @@ void RenderablePlane::createPlane() { size, size, 0.f, 0.f, 1.f, 1.f, }; - glBindVertexArray(_quad); // bind array - glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer - glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); + glBindVertexArray(_quad); + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(0)); + glVertexAttribPointer( + 0, + 4, + GL_FLOAT, + GL_FALSE, + sizeof(GLfloat) * 6, + reinterpret_cast(0) + ); + glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); + glVertexAttribPointer( + 1, + 2, + GL_FLOAT, + GL_FALSE, + sizeof(GLfloat) * 6, + reinterpret_cast(sizeof(GLfloat) * 4) + ); } } // namespace openspace diff --git a/modules/base/rendering/renderableplane.h b/modules/base/rendering/renderableplane.h index ef937da10a..7b81ec0ed2 100644 --- a/modules/base/rendering/renderableplane.h +++ b/modules/base/rendering/renderableplane.h @@ -29,34 +29,29 @@ #include #include -#include +#include namespace ghoul { - namespace filesystem { - class File; - } - namespace opengl { - class ProgramObject; - class Texture; - } +namespace filesystem { class File; } + +namespace opengl { + class ProgramObject; + class Texture; } +} // namespace ghoul namespace openspace { +struct RenderData; +struct UpdateData; + namespace documentation { struct Documentation; } struct LinePoint; class RenderablePlane : public Renderable { - public: - enum class BlendMode : int { - Normal = 0, - Additive - }; - RenderablePlane(const ghoul::Dictionary& dictionary); - ~RenderablePlane(); bool initialize() override; bool deinitialize() override; @@ -69,6 +64,11 @@ public: static documentation::Documentation Documentation(); private: + enum class BlendMode : int { + Normal = 0, + Additive + }; + void loadTexture(); void createPlane(); @@ -76,15 +76,17 @@ private: properties::BoolProperty _billboard; properties::FloatProperty _size; - bool _planeIsDirty; - std::unique_ptr _shader; - bool _textureIsDirty; std::unique_ptr _texture; + std::unique_ptr _textureFile; + BlendMode _blendMode; - ghoul::filesystem::File* _textureFile; + GLuint _quad; GLuint _vertexPositionBuffer; + + bool _planeIsDirty; + bool _textureIsDirty; }; } // namespace openspace diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index b720d482f3..25ca8c0494 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -26,12 +26,16 @@ #include #include - #include #include -#include -#include +#include +#include + #include +#include +#include +#include +#include #define _USE_MATH_DEFINES #include @@ -42,8 +46,6 @@ namespace { const char* KeyTexture = "Texture"; const char* KeyOrientation = "Orientation"; - - enum Orientation { Outside = 1, Inside = 2 diff --git a/modules/base/rendering/renderablesphere.h b/modules/base/rendering/renderablesphere.h index 3f6fa1e3ca..8f74d6fe96 100644 --- a/modules/base/rendering/renderablesphere.h +++ b/modules/base/rendering/renderablesphere.h @@ -26,19 +26,25 @@ #define __OPENSPACE_MODULE_BASE___RENDERABLESPHERE___H__ #include -#include #include #include #include #include -#include -#include -#include -#include + +namespace ghoul { +namespace opengl { + class ProgramObject; + class Texture; +} +} // namespace ghoul namespace openspace { +class PowerScaledSphere; +struct RenderData; +struct UpdateData; + namespace documentation { struct Documentation; } class RenderableSphere : public Renderable { diff --git a/modules/base/rendering/renderablesphericalgrid.cpp b/modules/base/rendering/renderablesphericalgrid.cpp index b6a8f0f7e5..f167f514aa 100644 --- a/modules/base/rendering/renderablesphericalgrid.cpp +++ b/modules/base/rendering/renderablesphericalgrid.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #define _USE_MATH_DEFINES diff --git a/modules/base/rendering/renderablesphericalgrid.h b/modules/base/rendering/renderablesphericalgrid.h index f5290bc1d5..b4dabab32a 100644 --- a/modules/base/rendering/renderablesphericalgrid.h +++ b/modules/base/rendering/renderablesphericalgrid.h @@ -32,6 +32,7 @@ #include namespace openspace { + class RenderableSphericalGrid : public Renderable{ public: RenderableSphericalGrid(const ghoul::Dictionary& dictionary); diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 4dd118eb1b..7124c72bb3 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace { const char* KeyTranslation = "Translation"; diff --git a/modules/base/rendering/renderabletrailorbit.cpp b/modules/base/rendering/renderabletrailorbit.cpp index 2f21fd320a..eff3ad8b42 100644 --- a/modules/base/rendering/renderabletrailorbit.cpp +++ b/modules/base/rendering/renderabletrailorbit.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index 25f5fc686d..889bdf3a14 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -28,6 +28,7 @@ #include #include #include +#include // This class creates the entire trajectory at once and keeps it in memory the entire // time. This means that there is no need for updating the trail at runtime, but also that diff --git a/modules/globebrowsing/chunk/chunk.cpp b/modules/globebrowsing/chunk/chunk.cpp index 5e140bfc3b..2d2adf6c4f 100644 --- a/modules/globebrowsing/chunk/chunk.cpp +++ b/modules/globebrowsing/chunk/chunk.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace openspace { diff --git a/modules/globebrowsing/chunk/chunklevelevaluator/distanceevaluator.cpp b/modules/globebrowsing/chunk/chunklevelevaluator/distanceevaluator.cpp index e7ce4379d7..73624a9e26 100644 --- a/modules/globebrowsing/chunk/chunklevelevaluator/distanceevaluator.cpp +++ b/modules/globebrowsing/chunk/chunklevelevaluator/distanceevaluator.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace openspace { namespace globebrowsing { diff --git a/modules/globebrowsing/chunk/chunklevelevaluator/projectedareaevaluator.cpp b/modules/globebrowsing/chunk/chunklevelevaluator/projectedareaevaluator.cpp index a92a9c62e8..31514dc6c5 100644 --- a/modules/globebrowsing/chunk/chunklevelevaluator/projectedareaevaluator.cpp +++ b/modules/globebrowsing/chunk/chunklevelevaluator/projectedareaevaluator.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace openspace { namespace globebrowsing { diff --git a/modules/globebrowsing/chunk/culling/frustumculler.cpp b/modules/globebrowsing/chunk/culling/frustumculler.cpp index 03410a4dd0..090d91ba4a 100644 --- a/modules/globebrowsing/chunk/culling/frustumculler.cpp +++ b/modules/globebrowsing/chunk/culling/frustumculler.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace openspace { namespace globebrowsing { diff --git a/modules/globebrowsing/chunk/culling/horizonculler.cpp b/modules/globebrowsing/chunk/culling/horizonculler.cpp index 5e7e09b989..c7c62a89bd 100644 --- a/modules/globebrowsing/chunk/culling/horizonculler.cpp +++ b/modules/globebrowsing/chunk/culling/horizonculler.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace openspace { namespace globebrowsing { diff --git a/modules/globebrowsing/globes/pointglobe.cpp b/modules/globebrowsing/globes/pointglobe.cpp index 7e1887a3e2..d6a66d2160 100644 --- a/modules/globebrowsing/globes/pointglobe.cpp +++ b/modules/globebrowsing/globes/pointglobe.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace openspace { namespace globebrowsing { diff --git a/modules/globebrowsing/other/distanceswitch.cpp b/modules/globebrowsing/other/distanceswitch.cpp index 18f4644643..063286ad92 100644 --- a/modules/globebrowsing/other/distanceswitch.cpp +++ b/modules/globebrowsing/other/distanceswitch.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace openspace { namespace globebrowsing { diff --git a/modules/globebrowsing/rendering/chunkrenderer.cpp b/modules/globebrowsing/rendering/chunkrenderer.cpp index 717c0c4038..de389b9cdd 100644 --- a/modules/globebrowsing/rendering/chunkrenderer.cpp +++ b/modules/globebrowsing/rendering/chunkrenderer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace { const char* keyFrame = "Frame"; diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index 39f595ae71..250438f4a1 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include namespace { const std::string _loggerCat = "IswaCygnet"; diff --git a/modules/kameleonvolume/rendering/kameleonvolumeraycaster.h b/modules/kameleonvolume/rendering/kameleonvolumeraycaster.h index d45590d2a7..4def71f6a0 100644 --- a/modules/kameleonvolume/rendering/kameleonvolumeraycaster.h +++ b/modules/kameleonvolume/rendering/kameleonvolumeraycaster.h @@ -50,7 +50,7 @@ namespace ghoul { namespace openspace { struct RenderData; -class RaycastData; +struct RaycastData; class KameleonVolumeRaycaster : public VolumeRaycaster { public: diff --git a/modules/newhorizons/rendering/renderablecrawlingline.cpp b/modules/newhorizons/rendering/renderablecrawlingline.cpp index 8ff7e4c9fd..14fed21b53 100644 --- a/modules/newhorizons/rendering/renderablecrawlingline.cpp +++ b/modules/newhorizons/rendering/renderablecrawlingline.cpp @@ -24,12 +24,15 @@ #include +#include #include #include #include #include #include -#include +#include + +#include namespace { const char* KeySource = "Source"; diff --git a/modules/newhorizons/rendering/renderablefov.cpp b/modules/newhorizons/rendering/renderablefov.cpp index fc264a4516..ffea6bb70f 100644 --- a/modules/newhorizons/rendering/renderablefov.cpp +++ b/modules/newhorizons/rendering/renderablefov.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include diff --git a/modules/newhorizons/rendering/renderablemodelprojection.h b/modules/newhorizons/rendering/renderablemodelprojection.h index ac85b7df0d..4dec2aba5b 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.h +++ b/modules/newhorizons/rendering/renderablemodelprojection.h @@ -34,6 +34,8 @@ #include #include +#include + namespace ghoul { namespace opengl { class ProgramObject; diff --git a/modules/toyvolume/rendering/toyvolumeraycaster.h b/modules/toyvolume/rendering/toyvolumeraycaster.h index 1577ede5ec..badfe4430a 100644 --- a/modules/toyvolume/rendering/toyvolumeraycaster.h +++ b/modules/toyvolume/rendering/toyvolumeraycaster.h @@ -42,7 +42,7 @@ namespace ghoul { namespace openspace { struct RenderData; -class RaycastData; +struct RaycastData; class ToyVolumeRaycaster : public VolumeRaycaster { public: