diff --git a/data/assets/scene/solarsystem/missions/rosetta/67p.asset b/data/assets/scene/solarsystem/missions/rosetta/67p.asset index 06ff4db8e2..475f33ed04 100644 --- a/data/assets/scene/solarsystem/missions/rosetta/67p.asset +++ b/data/assets/scene/solarsystem/missions/rosetta/67p.asset @@ -88,6 +88,9 @@ local Comet67P = { CHURYUMOVGERASIMENKO11969R1 = { "CHURYUMOV-GERASIMENKO" }, CHURYUMOVGERASIMENKO = { "CHURYUMOV-GERASIMENKO" }, ["CHURYUMOV-GERASIMENKO1(1969R1)"] = { "CHURYUMOV-GERASIMENKO" }, + CALIBRATION = { "CALIBRATION" }, + ALPHALYR = { "ALPHALYR" }, + ZETACAS = { "ZETACAS" } } } }, diff --git a/ext/ghoul b/ext/ghoul index a611066775..01b1f2fd8a 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a6110667751ecd4e9387601c85b1491bc8a44313 +Subproject commit 01b1f2fd8ae5965eef16171dc5c7fe1c79d3022f diff --git a/include/openspace/documentation/verifier.h b/include/openspace/documentation/verifier.h index 71fee5972a..bf832aae37 100644 --- a/include/openspace/documentation/verifier.h +++ b/include/openspace/documentation/verifier.h @@ -939,27 +939,25 @@ struct ReferencingVerifier : public TableVerifier { */ struct AndVerifier : public Verifier { /** - * Constructs an AndVerifier with two Verifiers which must be cleared by incoming - * values in order to pass this Verifier. + * Constructs an AndVerifier with Verifiers that must be cleared by incoming values in + * order to pass this Verifier. * - * \param l The first Verifier that is to be tested - * \param r The second Verifier that is to be tested + * \param values The list of Verifiers that are to be tested * - * \pre l must not be nullptr - * \pre r must not be nullptr + * \pre values must contain at least two values */ - AndVerifier(Verifier* l, Verifier* r); + AndVerifier(const std::vector values); /** * Checks whether the \p dictionary contains the \p key and whether this key passes - * both Verifier%'s that were passed in the constructor. If the value fails either - * of the two Verifiers, it is only added once to the TestResult::offenses list with - * a reason of TestResult::Offense::Reason::Verification. + * all Verifier%s that were passed in the constructor. If the value fails at least + * one Verifiers, it is only added once to the TestResult::offenses list with a reason + * of TestResult::Offense::Reason::Verification. * * \param dictionary The ghoul::Dictionary that is to be tested * \param key The key contained in \p dictionary that is to be tested * \return A TestResult object that contains the test results. If the value fails - * either of the two Verifiers, TestResult::success is \c false and the + * any passed Verifiers, TestResult::success is \c false and the * TestResult::offenses list contains \p with a reason of * TestResult::Offense::Reason::Verification. If \p key%'s value passes both * Verifier%s, the result's TestResult::success is \c true and the @@ -971,10 +969,7 @@ struct AndVerifier : public Verifier { std::string type() const override; std::string documentation() const override; - /// The first Verifier that incoming values are tested against - std::shared_ptr lhs; - /// The second Verifier that incoming values are tested against - std::shared_ptr rhs; + std::vector> values; }; /** @@ -985,27 +980,25 @@ struct AndVerifier : public Verifier { */ struct OrVerifier : public Verifier { /** - * Constructs an OrVerifier with two Verifiers, either of which must be cleared by - * incoming values in order to pass this Verifier. + * Constructs an OrVerifier with Verifiers that must be cleared by incoming values in + * order to pass this Verifier. * - * \param l The first Verifier that is to be tested - * \param r The second Verifier that is to be tested + * \param values The list of Verifiers that are to be tested * - * \pre l must not be nullptr - * \pre r must not be nullptr + * \pre values must contain at least two values */ - OrVerifier(Verifier* l, Verifier* r); + OrVerifier(const std::vector values); /** * Checks whether the \p dictionary contains the \p key and whether this key passes - * either of the two Verifier%'s that were passed in the constructor. If the value - * fails both Verifiers, it is added to the TestResult::offenses list with a reason of + * any of the Verifier%s that were passed in the constructor. If the value fails all + * Verifiers, it is added to the TestResult::offenses list with a reason of * TestResult::Offense::Reason::Verification. * * \param dictionary The ghoul::Dictionary that is to be tested * \param key The key contained in \p dictionary that is to be tested * \return A TestResult object that contains the test results. If the value fails - * both Verifiers, TestResult::success is \c false and the + * all Verifiers, TestResult::success is \c false and the * TestResult::offenses list contains \p with a reason of * TestResult::Offense::Reason::Verification. If \p key%'s value passes either * of the two Verifier%s, the result's TestResult::success is \c true and the @@ -1017,10 +1010,7 @@ struct OrVerifier : public Verifier { std::string type() const override; std::string documentation() const override; - /// The first Verifier that incoming values are tested against - std::shared_ptr lhs; - /// The second Verifier that incoming values are tested against - std::shared_ptr rhs; + std::vector> values; }; /// A short-hand definition for a Verifier checking for glm::bvec2 diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index d809e692ff..05bb1571b0 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -90,6 +90,20 @@ namespace { constexpr const char* _loggerCat = "AtmosphereDeferredcaster"; + + constexpr const std::array UniformNames1 = { + "cullAtmosphere", "Rg", "Rt", "groundRadianceEmittion", "HR", "betaRayleigh", + "HM", "betaMieExtinction", "mieG", "sunRadiance", "ozoneLayerEnabled", "HO", + "betaOzoneExtinction", "SAMPLES_R", "SAMPLES_MU", "SAMPLES_MU_S", "SAMPLES_NU" + }; + + constexpr const std::array UniformNames2 = { + "dInverseModelTransformMatrix", "dModelTransformMatrix", + "dSgctProjectionToModelTransformMatrix", "dSGCTViewToWorldMatrix", "dCamPosObj", + "sunDirectionObj", "hardShadows", "transmittanceTexture", "irradianceTexture", + "inscatterTexture" + }; + constexpr const char* GlslDeferredcastPath = "${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl"; constexpr const char* GlslDeferredcastFSPath = @@ -464,48 +478,11 @@ std::string AtmosphereDeferredcaster::helperPath() const { void AtmosphereDeferredcaster::initializeCachedVariables( ghoul::opengl::ProgramObject& program) { - _uniformCache.cullAtmosphere = program.uniformLocation("cullAtmosphere"); - _uniformCache.Rg = program.uniformLocation("Rg"); - _uniformCache.Rt = program.uniformLocation("Rt"); - _uniformCache.groundRadianceEmittion = program.uniformLocation( - "groundRadianceEmittion" - ); - _uniformCache.HR = program.uniformLocation("HR"); - _uniformCache.betaRayleigh = program.uniformLocation("betaRayleigh"); - _uniformCache.HM = program.uniformLocation("HM"); - _uniformCache.betaMieExtinction = program.uniformLocation("betaMieExtinction"); - _uniformCache.mieG = program.uniformLocation("mieG"); - _uniformCache.sunRadiance = program.uniformLocation("sunRadiance"); - _uniformCache.ozoneLayerEnabled = program.uniformLocation("ozoneLayerEnabled"); - _uniformCache.HO = program.uniformLocation("HO"); - _uniformCache.betaOzoneExtinction = program.uniformLocation("betaOzoneExtinction"); - _uniformCache.SAMPLES_R = program.uniformLocation("SAMPLES_R"); - _uniformCache.SAMPLES_MU = program.uniformLocation("SAMPLES_MU"); - _uniformCache.SAMPLES_MU_S = program.uniformLocation("SAMPLES_MU_S"); - _uniformCache.SAMPLES_NU = program.uniformLocation("SAMPLES_NU"); - _uniformCache2.dInverseModelTransformMatrix = program.uniformLocation( - "dInverseModelTransformMatrix" - ); - _uniformCache2.dModelTransformMatrix = program.uniformLocation( - "dModelTransformMatrix" - ); - _uniformCache2.dSgctProjectionToModelTransformMatrix = program.uniformLocation( - "dSgctProjectionToModelTransformMatrix" - ); - _uniformCache2.dSGCTViewToWorldMatrix = program.uniformLocation( - "dSGCTViewToWorldMatrix" - ); - _uniformCache2.dCamPosObj = program.uniformLocation("dCamPosObj"); - _uniformCache2.sunDirectionObj = program.uniformLocation("sunDirectionObj"); - _uniformCache2.hardShadows = program.uniformLocation("hardShadows"); - _uniformCache2.transmittanceTexture = program.uniformLocation("transmittanceTexture"); - _uniformCache2.irradianceTexture = program.uniformLocation("irradianceTexture"); - _uniformCache2.inscatterTexture = program.uniformLocation("inscatterTexture"); + ghoul::opengl::updateUniformLocations(program, _uniformCache, UniformNames1); + ghoul::opengl::updateUniformLocations(program, _uniformCache2, UniformNames2); } -void AtmosphereDeferredcaster::update(const UpdateData&) { - -} +void AtmosphereDeferredcaster::update(const UpdateData&) {} void AtmosphereDeferredcaster::setModelTransform(const glm::dmat4& transform) { _modelTransform = transform; diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index e67c069e9f..2c7e56e187 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -69,6 +69,7 @@ namespace openspace { ghoul::opengl::ProgramObjectManager BaseModule::ProgramObjectManager; +ghoul::opengl::TextureManager BaseModule::TextureManager; BaseModule::BaseModule() : OpenSpaceModule(BaseModule::Name) {} @@ -159,6 +160,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { void BaseModule::internalDeinitializeGL() { ProgramObjectManager.releaseAll(ghoul::opengl::ProgramObjectManager::Warnings::Yes); + TextureManager.releaseAll(ghoul::opengl::TextureManager::Warnings::Yes); } std::vector BaseModule::documentations() const { diff --git a/modules/base/basemodule.h b/modules/base/basemodule.h index 30064dced0..c1160e213a 100644 --- a/modules/base/basemodule.h +++ b/modules/base/basemodule.h @@ -28,6 +28,7 @@ #include #include +#include namespace openspace { @@ -42,6 +43,7 @@ public: std::vector luaLibraries() const override; static ghoul::opengl::ProgramObjectManager ProgramObjectManager; + static ghoul::opengl::TextureManager TextureManager; protected: void internalInitialize(const ghoul::Dictionary&) override; diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index a5b670ff72..60485523f2 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -47,6 +47,12 @@ namespace { constexpr const char* ProgramName = "ModelProgram"; constexpr const char* KeyGeometry = "Geometry"; + constexpr const std::array UniformNames = { + "opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities", + "modelViewTransform", "projectionTransform", "performShading", "texture1", + "ambientIntensity", "diffuseIntensity", "specularIntensity" + }; + constexpr openspace::properties::Property::PropertyInfo TextureInfo = { "ColorTexture", "Color Texture", @@ -237,7 +243,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) RenderableModel::~RenderableModel() {} bool RenderableModel::isReady() const { - return _programObject && _texture; + return _program && _texture; } void RenderableModel::initialize() { @@ -247,7 +253,7 @@ void RenderableModel::initialize() { } void RenderableModel::initializeGL() { - _programObject = BaseModule::ProgramObjectManager.requestProgramObject( + _program = BaseModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -257,7 +263,8 @@ void RenderableModel::initializeGL() { ); } ); - updateUniformCache(); + + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); loadTexture(); @@ -271,19 +278,19 @@ void RenderableModel::deinitializeGL() { } _texture = nullptr; - BaseModule::ProgramObjectManager.releaseProgramObject( + BaseModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); } ); - _programObject = nullptr; + _program = nullptr; } void RenderableModel::render(const RenderData& data, RendererTasks&) { - _programObject->activate(); + _program->activate(); - _programObject->setUniform(_uniformCache.opacity, _opacity); + _program->setUniform(_uniformCache.opacity, _opacity); // Model transform and view transform needs to be in double precision const glm::dmat4 modelTransform = @@ -309,98 +316,65 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ++nLightSources; } - _programObject->setUniform( + _program->setUniform( _uniformCache.nLightSources, nLightSources ); - _programObject->setUniform( + _program->setUniform( _uniformCache.lightIntensities, _lightIntensitiesBuffer.data(), nLightSources ); - _programObject->setUniform( + _program->setUniform( _uniformCache.lightDirectionsViewSpace, _lightDirectionsViewSpaceBuffer.data(), nLightSources ); - _programObject->setUniform( + _program->setUniform( _uniformCache.modelViewTransform, glm::mat4(modelViewTransform) ); - _programObject->setUniform( + _program->setUniform( _uniformCache.projectionTransform, data.camera.projectionMatrix() ); - _programObject->setUniform( + _program->setUniform( _uniformCache.ambientIntensity, _ambientIntensity ); - _programObject->setUniform( + _program->setUniform( _uniformCache.diffuseIntensity, _diffuseIntensity ); - _programObject->setUniform( + _program->setUniform( _uniformCache.specularIntensity, _specularIntensity ); - _programObject->setUniform( + _program->setUniform( _uniformCache.performShading, _performShading ); - _geometry->setUniforms(*_programObject); + _geometry->setUniforms(*_program); // Bind texture ghoul::opengl::TextureUnit unit; unit.activate(); _texture->bind(); - _programObject->setUniform(_uniformCache.texture, unit); + _program->setUniform(_uniformCache.texture, unit); _geometry->render(); - _programObject->deactivate(); + _program->deactivate(); } void RenderableModel::update(const UpdateData&) { - if (_programObject->isDirty()) { - _programObject->rebuildFromFile(); - updateUniformCache(); + if (_program->isDirty()) { + _program->rebuildFromFile(); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } } - -void RenderableModel::updateUniformCache() { - _uniformCache.opacity = _programObject->uniformLocation("opacity"); - _uniformCache.nLightSources = _programObject->uniformLocation( - "nLightSources" - ); - _uniformCache.lightDirectionsViewSpace = _programObject->uniformLocation( - "lightDirectionsViewSpace" - ); - _uniformCache.lightIntensities = _programObject->uniformLocation( - "lightIntensities" - ); - _uniformCache.modelViewTransform = _programObject->uniformLocation( - "modelViewTransform" - ); - _uniformCache.projectionTransform = _programObject->uniformLocation( - "projectionTransform" - ); - _uniformCache.performShading = _programObject->uniformLocation( - "performShading" - ); - _uniformCache.ambientIntensity = _programObject->uniformLocation( - "ambientIntensity" - ); - _uniformCache.diffuseIntensity = _programObject->uniformLocation( - "diffuseIntensity" - ); - _uniformCache.specularIntensity = _programObject->uniformLocation( - "specularIntensity" - ); - _uniformCache.texture = _programObject->uniformLocation("texture1"); -} - void RenderableModel::loadTexture() { _texture = nullptr; if (!_colorTexturePath.value().empty()) { diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 5ba97a2882..859c7e562d 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -68,8 +68,6 @@ protected: void loadTexture(); private: - void updateUniformCache(); - std::unique_ptr _geometry; properties::StringProperty _colorTexturePath; @@ -81,7 +79,7 @@ private: properties::BoolProperty _performShading; properties::Mat3Property _modelTransform; - ghoul::opengl::ProgramObject* _programObject = nullptr; + ghoul::opengl::ProgramObject* _program = nullptr; UniformCache(opacity, nLightSources, lightDirectionsViewSpace, lightIntensities, modelViewTransform, projectionTransform, performShading, texture, ambientIntensity, diffuseIntensity, specularIntensity) _uniformCache; diff --git a/modules/base/rendering/renderableplane.cpp b/modules/base/rendering/renderableplane.cpp index 5dc41e9405..c04a1332c9 100644 --- a/modules/base/rendering/renderableplane.cpp +++ b/modules/base/rendering/renderableplane.cpp @@ -165,7 +165,7 @@ void RenderablePlane::initializeGL() { glGenBuffers(1, &_vertexPositionBuffer); // generate buffer createPlane(); - _shader = BaseModule::ProgramObjectManager.requestProgramObject( + _shader = BaseModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -184,7 +184,7 @@ void RenderablePlane::deinitializeGL() { glDeleteBuffers(1, &_vertexPositionBuffer); _vertexPositionBuffer = 0; - BaseModule::ProgramObjectManager.releaseProgramObject( + BaseModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); diff --git a/modules/base/rendering/renderableplaneimagelocal.cpp b/modules/base/rendering/renderableplaneimagelocal.cpp index ce1cdb2b93..cfa91c2347 100644 --- a/modules/base/rendering/renderableplaneimagelocal.cpp +++ b/modules/base/rendering/renderableplaneimagelocal.cpp @@ -24,13 +24,16 @@ #include +#include #include #include #include #include #include #include +#include #include +#include namespace { constexpr openspace::properties::Property::PropertyInfo TextureInfo = { @@ -91,7 +94,8 @@ void RenderablePlaneImageLocal::initializeGL() { void RenderablePlaneImageLocal::deinitializeGL() { _textureFile = nullptr; - _texture = nullptr; + + BaseModule::TextureManager.release(_texture); RenderablePlane::deinitializeGL(); } @@ -110,27 +114,36 @@ void RenderablePlaneImageLocal::update(const UpdateData& data) { void RenderablePlaneImageLocal::loadTexture() { if (!_texturePath.value().empty()) { - std::unique_ptr texture = - ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); + ghoul::opengl::Texture* t = _texture; - if (texture) { - LDEBUGC( - "RenderablePlane", - fmt::format("Loaded texture from '{}'", absPath(_texturePath)) - ); - texture->uploadTexture(); + unsigned int hash = ghoul::hashCRC32File(_texturePath); + + _texture = BaseModule::TextureManager.request( + std::to_string(hash), + [path = _texturePath]() -> std::unique_ptr { + std::unique_ptr texture = + ghoul::io::TextureReader::ref().loadTexture(absPath(path)); - // Textures of planets looks much smoother with AnisotropicMipMap rather than - // linear - texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); + if (texture) { + LDEBUGC( + "RenderablePlaneImageLocal", + fmt::format("Loaded texture from '{}'", absPath(path)) + ); + texture->uploadTexture(); - _texture = std::move(texture); + texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - _textureFile = std::make_unique(_texturePath); - _textureFile->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } - ); - } + return texture; + } + } + ); + + BaseModule::TextureManager.release(t); + + _textureFile = std::make_unique(_texturePath); + _textureFile->setCallback( + [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + ); } } diff --git a/modules/base/rendering/renderableplaneimagelocal.h b/modules/base/rendering/renderableplaneimagelocal.h index 6166ebd610..f48314438d 100644 --- a/modules/base/rendering/renderableplaneimagelocal.h +++ b/modules/base/rendering/renderableplaneimagelocal.h @@ -57,7 +57,7 @@ private: void loadTexture(); properties::StringProperty _texturePath; - std::unique_ptr _texture; + ghoul::opengl::Texture* _texture; std::unique_ptr _textureFile; bool _textureIsDirty = false; diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index 83d44bc38b..599ac27a60 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -43,6 +43,10 @@ namespace { constexpr const char* ProgramName = "Sphere"; + constexpr const std::array UniformNames = { + "opacity", "ViewProjection", "ModelTransform", "texture1" + }; + enum Orientation { Outside = 1, Inside = 2 @@ -237,7 +241,7 @@ void RenderableSphere::initializeGL() { ); _sphere->initialize(); - _shader = BaseModule::ProgramObjectManager.requestProgramObject( + _shader = BaseModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -248,10 +252,7 @@ void RenderableSphere::initializeGL() { } ); - _uniformCache.opacity = _shader->uniformLocation("opacity"); - _uniformCache.viewProjection = _shader->uniformLocation("ViewProjection"); - _uniformCache.modelTransform = _shader->uniformLocation("ModelTransform"); - _uniformCache.texture = _shader->uniformLocation("texture1"); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); loadTexture(); } @@ -259,7 +260,7 @@ void RenderableSphere::initializeGL() { void RenderableSphere::deinitializeGL() { _texture = nullptr; - BaseModule::ProgramObjectManager.releaseProgramObject( + BaseModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); @@ -348,11 +349,7 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) { void RenderableSphere::update(const UpdateData&) { if (_shader->isDirty()) { _shader->rebuildFromFile(); - - _uniformCache.opacity = _shader->uniformLocation("opacity"); - _uniformCache.viewProjection = _shader->uniformLocation("ViewProjection"); - _uniformCache.modelTransform = _shader->uniformLocation("ModelTransform"); - _uniformCache.texture = _shader->uniformLocation("texture1"); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); } if (_sphereIsDirty) { diff --git a/modules/base/rendering/renderablesphericalgrid.cpp b/modules/base/rendering/renderablesphericalgrid.cpp index 5f07668d06..a66b7d57cb 100644 --- a/modules/base/rendering/renderablesphericalgrid.cpp +++ b/modules/base/rendering/renderablesphericalgrid.cpp @@ -176,7 +176,7 @@ bool RenderableSphericalGrid::isReady() const { } void RenderableSphericalGrid::initializeGL() { - _gridProgram = BaseModule::ProgramObjectManager.requestProgramObject( + _gridProgram = BaseModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -208,7 +208,7 @@ void RenderableSphericalGrid::deinitializeGL() { glDeleteBuffers(1, &_iBufferID); _iBufferID = 0; - BaseModule::ProgramObjectManager.releaseProgramObject( + BaseModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index dc67969781..a3f43551f4 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -38,6 +38,12 @@ namespace { constexpr const char* ProgramName = "EphemerisProgram"; constexpr const char* KeyTranslation = "Translation"; + constexpr const std::array UniformNames = { + "opacity", "modelViewTransform", "projectionTransform", "color", "useLineFade", + "lineFade", "vertexSortingMethod", "idOffset", "nVertices", "stride", "pointSize", + "renderPhase" + }; + // The possible values for the _renderingModes property enum RenderingMode { RenderingModeLines = 0, @@ -225,7 +231,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) } void RenderableTrail::initializeGL() { - _programObject = BaseModule::ProgramObjectManager.requestProgramObject( + _programObject = BaseModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -236,24 +242,13 @@ void RenderableTrail::initializeGL() { } ); - _uniformCache.opacity = _programObject->uniformLocation("opacity"); - _uniformCache.modelView = _programObject->uniformLocation("modelViewTransform"); - _uniformCache.projection = _programObject->uniformLocation("projectionTransform"); - _uniformCache.color = _programObject->uniformLocation("color"); - _uniformCache.useLineFade = _programObject->uniformLocation("useLineFade"); - _uniformCache.lineFade = _programObject->uniformLocation("lineFade"); - _uniformCache.vertexSorting = _programObject->uniformLocation("vertexSortingMethod"); - _uniformCache.idOffset = _programObject->uniformLocation("idOffset"); - _uniformCache.nVertices = _programObject->uniformLocation("nVertices"); - _uniformCache.stride = _programObject->uniformLocation("stride"); - _uniformCache.pointSize = _programObject->uniformLocation("pointSize"); - _uniformCache.renderPhase = _programObject->uniformLocation("renderPhase"); + ghoul::opengl::updateUniformLocations(*_programObject, _uniformCache, UniformNames); setRenderBin(Renderable::RenderBin::Overlay); } void RenderableTrail::deinitializeGL() { - BaseModule::ProgramObjectManager.releaseProgramObject( + BaseModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); diff --git a/modules/base/rotation/fixedrotation.cpp b/modules/base/rotation/fixedrotation.cpp index 2b98839b4d..b01ee117c0 100644 --- a/modules/base/rotation/fixedrotation.cpp +++ b/modules/base/rotation/fixedrotation.cpp @@ -202,15 +202,14 @@ documentation::Documentation FixedRotation::Documentation() { }, { KeyXAxis, - new OrVerifier( - new StringVerifier, - new DoubleVector3Verifier - ), + new OrVerifier({ new StringVerifier, new DoubleVector3Verifier, }), Optional::Yes, "This value specifies the direction of the new X axis. If this value is " "not specified, it will be computed by completing a right handed " "coordinate system from the Y and Z axis, which must be specified " - "instead." + "instead. If this value is a string, it is interpreted as the identifier " + "of another scenegraph node. If this value is a 3-vector, it is " + "interpreted as a direction vector." }, { KeyXAxisOrthogonal, @@ -220,15 +219,14 @@ documentation::Documentation FixedRotation::Documentation() { }, { KeyYAxis, - new OrVerifier( - new StringVerifier, - new DoubleVector3Verifier - ), + new OrVerifier({ new StringVerifier, new DoubleVector3Verifier, }), Optional::Yes, "This value specifies the direction of the new Y axis. If this value is " "not specified, it will be computed by completing a right handed " "coordinate system from the X and Z axis, which must be specified " - "instead." + "instead. If this value is a string, it is interpreted as the identifier " + "of another scenegraph node. If this value is a 3-vector, it is " + "interpreted as a direction vector." }, { KeyYAxisOrthogonal, @@ -238,15 +236,14 @@ documentation::Documentation FixedRotation::Documentation() { }, { KeyZAxis, - new OrVerifier( - new StringVerifier, - new DoubleVector3Verifier - ), + new OrVerifier({ new StringVerifier, new DoubleVector3Verifier, }), Optional::Yes, "This value specifies the direction of the new Z axis. If this value is " "not specified, it will be computed by completing a right handed " "coordinate system from the X and Y axis, which must be specified " - "instead." + "instead. If this value is a string, it is interpreted as the identifier " + "of another scenegraph node. If this value is a 3-vector, it is " + "interpreted as a direction vector." }, { KeyZAxisOrthogonal, @@ -276,7 +273,7 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) properties::Vec3Property( XAxisVectorInfo, glm::vec3(1.f, 0.f, 0.f), - glm::vec3(0.f), + glm::vec3(-1.f), glm::vec3(1.f) ), properties::BoolProperty(XAxisOrthogonalVectorInfo, false), @@ -292,7 +289,7 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) properties::Vec3Property( YAxisVectorInfo, glm::vec3(0.f, 1.f, 0.f), - glm::vec3(0.f), + glm::vec3(-1.f), glm::vec3(1.f) ), properties::BoolProperty(YAxisOrthogonalVectorInfo, false), @@ -308,7 +305,7 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) properties::Vec3Property( ZAxisVectorInfo, glm::vec3(0.f, 0.f, 1.f), - glm::vec3(0.f), + glm::vec3(-1.f), glm::vec3(1.f) ), properties::BoolProperty(ZAxisOrthogonalVectorInfo, false), @@ -454,10 +451,8 @@ bool FixedRotation::initialize() { } } - if (_constructorDictionary.hasKey(XAxisOrthogonalVectorInfo.identifier)) { - _xAxis.isOrthogonal = _constructorDictionary.value( - XAxisOrthogonalVectorInfo.identifier - ); + if (_constructorDictionary.hasKey(KeyXAxisOrthogonal)) { + _xAxis.isOrthogonal = _constructorDictionary.value(KeyXAxisOrthogonal); } if (_xAxis.isOrthogonal) { _xAxis.type = Axis::Type::OrthogonalVector; @@ -476,10 +471,8 @@ bool FixedRotation::initialize() { } } - if (_constructorDictionary.hasKey(YAxisOrthogonalVectorInfo.identifier)) { - _yAxis.isOrthogonal = _constructorDictionary.value( - YAxisOrthogonalVectorInfo.identifier - ); + if (_constructorDictionary.hasKey(KeyYAxisOrthogonal)) { + _yAxis.isOrthogonal = _constructorDictionary.value(KeyYAxisOrthogonal); } if (_yAxis.isOrthogonal) { _yAxis.type = Axis::Type::OrthogonalVector; @@ -498,10 +491,8 @@ bool FixedRotation::initialize() { } } - if (_constructorDictionary.hasKey(ZAxisOrthogonalVectorInfo.identifier)) { - _zAxis.isOrthogonal = _constructorDictionary.value( - ZAxisOrthogonalVectorInfo.identifier - ); + if (_constructorDictionary.hasKey(KeyZAxisOrthogonal)) { + _zAxis.isOrthogonal = _constructorDictionary.value(KeyZAxisOrthogonal); } if (_zAxis.isOrthogonal) { _zAxis.type = Axis::Type::OrthogonalVector; @@ -543,7 +534,7 @@ glm::dmat3 FixedRotation::matrix(const UpdateData&) const { { LWARNINGC( "FixedRotation", - fmt::format("Near-ollinear vectors detected: x ({}) y ({}) z ({})", x, y, z) + fmt::format("Near-collinear vectors detected: x ({}) y ({}) z ({})", x, y, z) ); return glm::dmat3(); } @@ -619,6 +610,8 @@ glm::vec3 FixedRotation::yAxis() const { case Axis::Type::Object: if (_yAxis.node && _attachedNode) { glm::vec3 dir = glm::vec3(glm::normalize( + // @TODO(abock): This should be changed to be in the coordinate system + // of the attached node // same with xAxis and zAxis ofc _yAxis.node->worldPosition() - _attachedNode->worldPosition() )); return _yAxis.invertObject ? -dir : dir; diff --git a/modules/base/rotation/fixedrotation.h b/modules/base/rotation/fixedrotation.h index 51e49eea00..23055a9c72 100644 --- a/modules/base/rotation/fixedrotation.h +++ b/modules/base/rotation/fixedrotation.h @@ -57,7 +57,7 @@ private: struct Axis { enum Type { - Unspecified = 0, + Unspecified = -1, Object, Vector, OrthogonalVector, diff --git a/modules/base/rotation/staticrotation.cpp b/modules/base/rotation/staticrotation.cpp index cd9678f248..8e91ca1798 100644 --- a/modules/base/rotation/staticrotation.cpp +++ b/modules/base/rotation/staticrotation.cpp @@ -51,10 +51,10 @@ documentation::Documentation StaticRotation::Documentation() { }, { RotationInfo.identifier, - new OrVerifier( + new OrVerifier({ new DoubleVector3Verifier(), new DoubleMatrix3Verifier() - ), + }), Optional::No, "Stores the static rotation as either a vector containing Euler angles " "or by specifiying the 3x3 rotation matrix directly" diff --git a/modules/base/timeframe/timeframeinterval.cpp b/modules/base/timeframe/timeframeinterval.cpp index 345b5785d0..32eafcfa3c 100644 --- a/modules/base/timeframe/timeframeinterval.cpp +++ b/modules/base/timeframe/timeframeinterval.cpp @@ -71,10 +71,7 @@ documentation::Documentation TimeFrameInterval::Documentation() { }, { StartInfo.identifier, - new OrVerifier{ - new DoubleVerifier, - new StringVerifier, - }, + new OrVerifier({ new DoubleVerifier, new StringVerifier }), Optional::Yes, StartInfo.description }, @@ -86,10 +83,7 @@ documentation::Documentation TimeFrameInterval::Documentation() { }, { EndInfo.identifier, - new OrVerifier{ - new DoubleVerifier, - new StringVerifier, - }, + new OrVerifier({ new DoubleVerifier, new StringVerifier }), Optional::Yes, EndInfo.description }, diff --git a/modules/digitaluniverse/digitaluniversemodule.cpp b/modules/digitaluniverse/digitaluniversemodule.cpp index 9a6c5994c3..d41365795a 100644 --- a/modules/digitaluniverse/digitaluniversemodule.cpp +++ b/modules/digitaluniverse/digitaluniversemodule.cpp @@ -37,6 +37,7 @@ namespace openspace { ghoul::opengl::ProgramObjectManager DigitalUniverseModule::ProgramObjectManager; +ghoul::opengl::TextureManager DigitalUniverseModule::TextureManager; DigitalUniverseModule::DigitalUniverseModule() : OpenSpaceModule(DigitalUniverseModule::Name) @@ -54,6 +55,7 @@ void DigitalUniverseModule::internalInitialize(const ghoul::Dictionary&) { void DigitalUniverseModule::internalDeinitializeGL() { ProgramObjectManager.releaseAll(ghoul::opengl::ProgramObjectManager::Warnings::Yes); + TextureManager.releaseAll(ghoul::opengl::TextureManager::Warnings::Yes); } std::vector DigitalUniverseModule::documentations() const { diff --git a/modules/digitaluniverse/digitaluniversemodule.h b/modules/digitaluniverse/digitaluniversemodule.h index cff672cebd..74b9e652b3 100644 --- a/modules/digitaluniverse/digitaluniversemodule.h +++ b/modules/digitaluniverse/digitaluniversemodule.h @@ -28,6 +28,7 @@ #include #include +#include namespace openspace { @@ -40,6 +41,7 @@ public: std::vector documentations() const override; static ghoul::opengl::ProgramObjectManager ProgramObjectManager; + static ghoul::opengl::TextureManager TextureManager; protected: void internalInitialize(const ghoul::Dictionary&) override; diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 237d0bb6fb..8406169dab 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -51,19 +52,27 @@ #include namespace { - constexpr const char* _loggerCat = "RenderableBillboardsCloud"; - constexpr const char* ProgramObjectName = "RenderableBillboardsCloud"; + constexpr const char* _loggerCat = "RenderableBillboardsCloud"; + constexpr const char* ProgramObjectName = "RenderableBillboardsCloud"; constexpr const char* RenderToPolygonProgram = "RenderableBillboardsCloud_Polygon"; - constexpr const char* KeyFile = "File"; - constexpr const char* keyColor = "Color"; - constexpr const char* keyUnit = "Unit"; - constexpr const char* MeterUnit = "m"; - constexpr const char* KilometerUnit = "Km"; - constexpr const char* ParsecUnit = "pc"; - constexpr const char* KiloparsecUnit = "Kpc"; - constexpr const char* MegaparsecUnit = "Mpc"; - constexpr const char* GigaparsecUnit = "Gpc"; + constexpr const std::array UniformNames = { + "cameraViewProjectionMatrix", "modelMatrix", "cameraPosition", "cameraLookUp", + "renderOption", "minBillboardSize", "maxBillboardSize", + "correctionSizeEndDistance", "correctionSizeFactor", "color", "alphaValue", + "scaleFactor", "up", "right", "fadeInValue", "screenSize", "spriteTexture", + "hasColorMap", "enabledRectSizeControl" + }; + + constexpr const char* KeyFile = "File"; + constexpr const char* keyColor = "Color"; + constexpr const char* keyUnit = "Unit"; + constexpr const char* MeterUnit = "m"; + constexpr const char* KilometerUnit = "Km"; + constexpr const char* ParsecUnit = "pc"; + constexpr const char* KiloparsecUnit = "Kpc"; + constexpr const char* MegaparsecUnit = "Mpc"; + constexpr const char* GigaparsecUnit = "Gpc"; constexpr const char* GigalightyearUnit = "Gly"; constexpr int8_t CurrentCacheVersion = 1; @@ -480,14 +489,8 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _spriteTexturePath = absPath(dictionary.value( SpriteTextureInfo.identifier )); - _spriteTextureFile = std::make_unique( - _spriteTexturePath - ); - _spriteTexturePath.onChange([&] { _spriteTextureIsDirty = true; }); - _spriteTextureFile->setCallback( - [&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; } - ); + _spriteTexturePath.onChange([&]() { _spriteTextureIsDirty = true; }); addProperty(_spriteTexturePath); _hasSpriteTexture = true; @@ -658,62 +661,31 @@ void RenderableBillboardsCloud::initialize() { } void RenderableBillboardsCloud::initializeGL() { - _program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject( + _program = DigitalUniverseModule::ProgramObjectManager.request( ProgramObjectName, []() -> std::unique_ptr { - return OsEng.renderEngine().buildRenderProgram( - ProgramObjectName, - absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_vs.glsl"), - absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_fs.glsl"), - absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_gs.glsl") - ); - } + return OsEng.renderEngine().buildRenderProgram( + ProgramObjectName, + absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_vs.glsl"), + absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_fs.glsl"), + absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_gs.glsl") + ); + } ); - _renderToPolygonProgram = - DigitalUniverseModule::ProgramObjectManager.requestProgramObject( - RenderToPolygonProgram, - []() -> std::unique_ptr { - return ghoul::opengl::ProgramObject::Build( - RenderToPolygonProgram, - absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_vs.glsl"), - absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_fs.glsl"), - absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl") - ); - } + _renderToPolygonProgram = DigitalUniverseModule::ProgramObjectManager.request( + RenderToPolygonProgram, + []() -> std::unique_ptr { + return ghoul::opengl::ProgramObject::Build( + RenderToPolygonProgram, + absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_vs.glsl"), + absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_fs.glsl"), + absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl") + ); + } ); - _uniformCache.cameraViewProjectionMatrix = _program->uniformLocation( - "cameraViewProjectionMatrix" - ); - - _uniformCache.modelMatrix = _program->uniformLocation( - "modelMatrix" - ); - - _uniformCache.cameraPos = _program->uniformLocation("cameraPosition"); - _uniformCache.cameraLookup = _program->uniformLocation("cameraLookUp"); - _uniformCache.renderOption = _program->uniformLocation("renderOption"); - _uniformCache.minBillboardSize = _program->uniformLocation("minBillboardSize"); - _uniformCache.maxBillboardSize = _program->uniformLocation("maxBillboardSize"); - _uniformCache.correctionSizeEndDistance = _program->uniformLocation( - "correctionSizeEndDistance" - ); - _uniformCache.correctionSizeFactor = _program->uniformLocation( - "correctionSizeFactor" - ); - _uniformCache.color = _program->uniformLocation("color"); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.up = _program->uniformLocation("up"); - _uniformCache.right = _program->uniformLocation("right"); - _uniformCache.fadeInValue = _program->uniformLocation("fadeInValue"); - _uniformCache.screenSize = _program->uniformLocation("screenSize"); - _uniformCache.spriteTexture = _program->uniformLocation("spriteTexture"); - _uniformCache.hasColormap = _program->uniformLocation("hasColorMap"); - _uniformCache.enabledRectSizeControl = _program->uniformLocation( - "enabledRectSizeControl" - ); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); if (_hasPolygon) { createPolygonTexture(); @@ -738,22 +710,19 @@ void RenderableBillboardsCloud::deinitializeGL() { glDeleteVertexArrays(1, &_vao); _vao = 0; - DigitalUniverseModule::ProgramObjectManager.releaseProgramObject( + DigitalUniverseModule::ProgramObjectManager.release( ProgramObjectName, [](ghoul::opengl::ProgramObject* p) { - OsEng.renderEngine().removeRenderProgram(p); - } + OsEng.renderEngine().removeRenderProgram(p); + } ); _program = nullptr; - DigitalUniverseModule::ProgramObjectManager.releaseProgramObject( - RenderToPolygonProgram - ); + DigitalUniverseModule::ProgramObjectManager.release(RenderToPolygonProgram); _renderToPolygonProgram = nullptr; - if (_hasSpriteTexture) { - _spriteTexture = nullptr; - } + DigitalUniverseModule::TextureManager.release(_spriteTexture); + _spriteTexture = nullptr; if (_hasPolygon) { _polygonTexture = nullptr; @@ -1077,37 +1046,30 @@ void RenderableBillboardsCloud::update(const UpdateData&) { _dataIsDirty = false; } - if (_hasSpriteTexture && _spriteTextureIsDirty) { - LDEBUG("Reloading Sprite Texture"); - _spriteTexture = nullptr; - if (_spriteTexturePath.value() != "") { - _spriteTexture = ghoul::io::TextureReader::ref().loadTexture( - absPath(_spriteTexturePath) - ); - if (_spriteTexture) { - LINFO(fmt::format( - "Loaded texture from '{}'", - absPath(_spriteTexturePath) - )); - _spriteTexture->uploadTexture(); + if (_hasSpriteTexture && _spriteTextureIsDirty && !_spriteTexturePath.value().empty()) + { + ghoul::opengl::Texture* t = _spriteTexture; + + unsigned int hash = ghoul::hashCRC32File(_spriteTexturePath); + + _spriteTexture = DigitalUniverseModule::TextureManager.request( + std::to_string(hash), + [path = _spriteTexturePath]() -> std::unique_ptr { + LINFO(fmt::format("Loaded texture from '{}'", absPath(path))); + std::unique_ptr t = + ghoul::io::TextureReader::ref().loadTexture( + absPath(path) + ); + + t->uploadTexture(); + t->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + return t; } - _spriteTexture->setFilter( - ghoul::opengl::Texture::FilterMode::AnisotropicMipMap - ); + ); - _spriteTextureFile = std::make_unique( - _spriteTexturePath); - _spriteTextureFile->setCallback( - [&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; } - ); - } + DigitalUniverseModule::TextureManager.release(t); _spriteTextureIsDirty = false; } - - if (_hasLabel && _labelDataIsDirty) { - - _labelDataIsDirty = false; - } } bool RenderableBillboardsCloud::loadData() { diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index 1feb69be5a..fe46a4cf67 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -105,7 +105,6 @@ private: bool _hasColorMapFile = false; bool _hasPolygon = false; bool _hasLabel = false; - bool _labelDataIsDirty = true; int _polygonSides = 0; @@ -133,17 +132,15 @@ private: // DEBUG: properties::OptionProperty _renderOption; - - std::unique_ptr _polygonTexture; - std::unique_ptr _spriteTexture; - std::unique_ptr _spriteTextureFile; + ghoul::opengl::Texture* _polygonTexture; + ghoul::opengl::Texture* _spriteTexture; ghoul::opengl::ProgramObject* _program = nullptr; ghoul::opengl::ProgramObject* _renderToPolygonProgram = nullptr; UniformCache(cameraViewProjectionMatrix, modelMatrix, cameraPos, cameraLookup, renderOption, minBillboardSize, maxBillboardSize, correctionSizeEndDistance, - correctionSizeFactor, color, sides, alphaValue, scaleFactor, up, right, - fadeInValue, screenSize, spriteTexture, hasColormap, enabledRectSizeControl + correctionSizeFactor, color, alphaValue, scaleFactor, up, right, fadeInValue, + screenSize, spriteTexture, hasColormap, enabledRectSizeControl ) _uniformCache; std::shared_ptr _font; diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index fb2f46f535..4b713d7d50 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -46,18 +46,22 @@ #include namespace { - constexpr const char* _loggerCat = "RenderableDUMeshes"; + constexpr const char* _loggerCat = "RenderableDUMeshes"; constexpr const char* ProgramObjectName = "RenderableDUMeshes"; - constexpr const char* KeyFile = "File"; - constexpr const char* keyColor = "Color"; - constexpr const char* keyUnit = "Unit"; - constexpr const char* MeterUnit = "m"; - constexpr const char* KilometerUnit = "Km"; - constexpr const char* ParsecUnit = "pc"; - constexpr const char* KiloparsecUnit = "Kpc"; - constexpr const char* MegaparsecUnit = "Mpc"; - constexpr const char* GigaparsecUnit = "Gpc"; + constexpr const std::array UniformNames = { + "modelViewTransform", "projectionTransform", "alphaValue", "color" + }; + + constexpr const char* KeyFile = "File"; + constexpr const char* keyColor = "Color"; + constexpr const char* keyUnit = "Unit"; + constexpr const char* MeterUnit = "m"; + constexpr const char* KilometerUnit = "Km"; + constexpr const char* ParsecUnit = "pc"; + constexpr const char* KiloparsecUnit = "Kpc"; + constexpr const char* MegaparsecUnit = "Mpc"; + constexpr const char* GigaparsecUnit = "Gpc"; constexpr const char* GigalightyearUnit = "Gly"; constexpr const int8_t CurrentCacheVersion = 1; @@ -392,7 +396,7 @@ bool RenderableDUMeshes::isReady() const { } void RenderableDUMeshes::initializeGL() { - _program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject( + _program = DigitalUniverseModule::ProgramObjectManager.request( ProgramObjectName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -403,11 +407,7 @@ void RenderableDUMeshes::initializeGL() { } ); - _uniformCache.modelViewTransform = _program->uniformLocation("modelViewTransform"); - _uniformCache.projectionTransform = _program->uniformLocation("projectionTransform"); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - //_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.color = _program->uniformLocation("color"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); bool success = loadData(); if (!success) { @@ -437,7 +437,7 @@ void RenderableDUMeshes::deinitializeGL() { } } - DigitalUniverseModule::ProgramObjectManager.releaseProgramObject( + DigitalUniverseModule::ProgramObjectManager.release( ProgramObjectName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); @@ -616,16 +616,7 @@ void RenderableDUMeshes::render(const RenderData& data, RendererTasks&) { void RenderableDUMeshes::update(const UpdateData&) { if (_program->isDirty()) { _program->rebuildFromFile(); - - _uniformCache.modelViewTransform = _program->uniformLocation( - "modelViewTransform" - ); - _uniformCache.projectionTransform = _program->uniformLocation( - "projectionTransform" - ); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - //_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.color = _program->uniformLocation("color"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } } diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.h b/modules/digitaluniverse/rendering/renderabledumeshes.h index 169eb608a8..57e1728f0b 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.h +++ b/modules/digitaluniverse/rendering/renderabledumeshes.h @@ -135,7 +135,7 @@ private: ghoul::opengl::ProgramObject* _program = nullptr; UniformCache(modelViewTransform, projectionTransform, alphaValue, - /*scaleFactor,*/ color) _uniformCache; + color) _uniformCache; std::shared_ptr _font = nullptr; std::string _speckFile; diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 2907e71a17..071b6a5b21 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -43,18 +43,21 @@ #include namespace { - constexpr const char* _loggerCat = "RenderablePlanesCloud"; + constexpr const char* _loggerCat = "RenderablePlanesCloud"; constexpr const char* ProgramObjectName = "RenderablePlanesCloud"; + constexpr std::array UniformNames = { + "modelViewProjectionTransform", "alphaValue", "fadeInValue", "galaxyTexture" + }; - constexpr const char* KeyFile = "File"; - constexpr const char* keyUnit = "Unit"; - constexpr const char* MeterUnit = "m"; - constexpr const char* KilometerUnit = "Km"; - constexpr const char* ParsecUnit = "pc"; - constexpr const char* KiloparsecUnit = "Kpc"; - constexpr const char* MegaparsecUnit = "Mpc"; - constexpr const char* GigaparsecUnit = "Gpc"; + constexpr const char* KeyFile = "File"; + constexpr const char* keyUnit = "Unit"; + constexpr const char* MeterUnit = "m"; + constexpr const char* KilometerUnit = "Km"; + constexpr const char* ParsecUnit = "pc"; + constexpr const char* KiloparsecUnit = "Kpc"; + constexpr const char* MegaparsecUnit = "Mpc"; + constexpr const char* GigaparsecUnit = "Gpc"; constexpr const char* GigalightyearUnit = "Gly"; constexpr int8_t CurrentCacheVersion = 2; @@ -488,7 +491,7 @@ void RenderablePlanesCloud::initialize() { } void RenderablePlanesCloud::initializeGL() { - _program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject( + _program = DigitalUniverseModule::ProgramObjectManager.request( ProgramObjectName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -499,12 +502,7 @@ void RenderablePlanesCloud::initializeGL() { } ); - _uniformCache.modelViewProjectionTransform = _program->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.fadeInValue = _program->uniformLocation("fadeInValue"); - _uniformCache.galaxyTexture = _program->uniformLocation("galaxyTexture"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); createPlanes(); @@ -534,7 +532,7 @@ void RenderablePlanesCloud::deleteDataGPU() { void RenderablePlanesCloud::deinitializeGL() { deleteDataGPU(); - DigitalUniverseModule::ProgramObjectManager.releaseProgramObject( + DigitalUniverseModule::ProgramObjectManager.release( ProgramObjectName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); @@ -817,13 +815,7 @@ void RenderablePlanesCloud::update(const UpdateData&) { if (_program->isDirty()) { _program->rebuildFromFile(); - - _uniformCache.modelViewProjectionTransform = _program->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.fadeInValue = _program->uniformLocation("fadeInValue"); - _uniformCache.galaxyTexture = _program->uniformLocation("galaxyTexture"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index f2c0e894bb..f601c4916e 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -129,7 +129,7 @@ private: properties::OptionProperty _renderOption; ghoul::opengl::ProgramObject* _program = nullptr; - UniformCache(modelViewProjectionTransform, alphaValue, scaleFactor, fadeInValue, + UniformCache(modelViewProjectionTransform, alphaValue, fadeInValue, galaxyTexture) _uniformCache; std::shared_ptr _font = nullptr; std::unordered_map> _textureMap; diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index 6e98ab3547..30b6d5caa8 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -45,17 +45,22 @@ #include namespace { - constexpr const char* _loggerCat = "RenderablePoints"; + constexpr const char* _loggerCat = "RenderablePoints"; - constexpr const char* KeyFile = "File"; - constexpr const char* keyColor = "Color"; - constexpr const char* keyUnit = "Unit"; - constexpr const char* MeterUnit = "m"; - constexpr const char* KilometerUnit = "Km"; - constexpr const char* ParsecUnit = "pc"; - constexpr const char* KiloparsecUnit = "Kpc"; - constexpr const char* MegaparsecUnit = "Mpc"; - constexpr const char* GigaparsecUnit = "Gpc"; + constexpr const std::array UniformNames = { + "modelViewProjectionTransform", "color", "sides", "alphaValue", "scaleFactor", + "spriteTexture", "hasColorMap" + }; + + constexpr const char* KeyFile = "File"; + constexpr const char* keyColor = "Color"; + constexpr const char* keyUnit = "Unit"; + constexpr const char* MeterUnit = "m"; + constexpr const char* KilometerUnit = "Km"; + constexpr const char* ParsecUnit = "pc"; + constexpr const char* KiloparsecUnit = "Kpc"; + constexpr const char* MegaparsecUnit = "Mpc"; + constexpr const char* GigaparsecUnit = "Gpc"; constexpr const char* GigalightyearUnit = "Gly"; constexpr int8_t CurrentCacheVersion = 1; @@ -261,7 +266,7 @@ void RenderablePoints::initializeGL() { // end of the program. if (_hasSpriteTexture) { - _program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject( + _program = DigitalUniverseModule::ProgramObjectManager.request( "RenderablePoints Sprite", []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -271,19 +276,9 @@ void RenderablePoints::initializeGL() { ); } ); - - _uniformCache.modelViewProjectionTransform = _program->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.color = _program->uniformLocation("color"); - _uniformCache.sides = _program->uniformLocation("sides"); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.spriteTexture = _program->uniformLocation("spriteTexture"); - _uniformCache.hasColorMap = _program->uniformLocation("hasColorMap"); } else { - _program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject( + _program = DigitalUniverseModule::ProgramObjectManager.request( "RenderablePoints", []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -293,16 +288,8 @@ void RenderablePoints::initializeGL() { ); } ); - - _uniformCache.modelViewProjectionTransform = _program->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.color = _program->uniformLocation("color"); - _uniformCache.sides = _program->uniformLocation("sides"); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.hasColorMap = _program->uniformLocation("hasColorMap"); } + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } void RenderablePoints::deinitializeGL() { @@ -311,7 +298,7 @@ void RenderablePoints::deinitializeGL() { glDeleteVertexArrays(1, &_vao); _vao = 0; - DigitalUniverseModule::ProgramObjectManager.releaseProgramObject( + DigitalUniverseModule::ProgramObjectManager.release( _program->name(), [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); diff --git a/modules/globebrowsing/globes/pointglobe.cpp b/modules/globebrowsing/globes/pointglobe.cpp index 42d1d38e51..49254778f6 100644 --- a/modules/globebrowsing/globes/pointglobe.cpp +++ b/modules/globebrowsing/globes/pointglobe.cpp @@ -32,6 +32,10 @@ #include namespace { + constexpr const std::array UniformNames = { + "lightIntensityClamped", "modelViewTransform", "projectionTransform" + }; + constexpr openspace::properties::Property::PropertyInfo IntensityClampInfo = { "IntensityClamp", "Intensity clamp", @@ -69,15 +73,7 @@ void PointGlobe::initialize() { absPath("${MODULE_GLOBEBROWSING}/shaders/pointglobe_fs.glsl") ); - _uniformCache.lightIntensityClamped = _programObject->uniformLocation( - "lightIntensityClamped" - ); - _uniformCache.modelView = _programObject->uniformLocation( - "modelViewTransform" - ); - _uniformCache.projection = _programObject->uniformLocation( - "projectionTransform" - ); + ghoul::opengl::updateUniformLocations(*_programObject, _uniformCache, UniformNames); glGenVertexArrays(1, &_vaoID); glGenBuffers(1, &_vertexBufferID); @@ -159,8 +155,8 @@ void PointGlobe::render(const RenderData& data, RendererTasks&) { _uniformCache.lightIntensityClamped, lightIntensityClamped ); - //_programObject->setUniform("lightOverflow", lightOverflow); - //_programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace); + //_program->setUniform("lightOverflow", lightOverflow); + //_program->setUniform("directionToSunViewSpace", directionToSunViewSpace); _programObject->setUniform( _uniformCache.modelView, glm::mat4(modelViewTransform) diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index a6b4972c9e..c498e5dd9b 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -53,6 +53,8 @@ namespace { ImFont* captionFont = nullptr; + constexpr const std::array UniformNames = { "tex", "ortho" }; + void addScreenSpaceRenderableLocal(std::string texturePath) { if (!FileSys.fileExists(absPath(texturePath))) { LWARNING(fmt::format("Could not find image '{}'", texturePath)); @@ -172,6 +174,8 @@ void GUI::initialize() { ghoul::filesystem::CacheManager::Persistent::Yes ); + LDEBUG(fmt::format("Using {} as ImGUI cache location", cachedFile)); + iniFileBuffer = new char[cachedFile.size() + 1]; #ifdef WIN32 @@ -304,9 +308,8 @@ void GUI::initializeGL() { absPath("${MODULE_IMGUI}/shaders/gui_vs.glsl"), absPath("${MODULE_IMGUI}/shaders/gui_fs.glsl") ); - - _uniformCache.tex = _program->uniformLocation("tex"); - _uniformCache.ortho = _program->uniformLocation("ortho"); + + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); int nWindows = OsEng.windowWrapper().nWindows(); { @@ -416,9 +419,7 @@ void GUI::startFrame(float deltaTime, const glm::vec2& windowSize, void GUI::endFrame() { if (_program->isDirty()) { _program->rebuildFromFile(); - - _uniformCache.tex = _program->uniformLocation("tex"); - _uniformCache.ortho = _program->uniformLocation("ortho"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } _performance.setEnabled(OsEng.renderEngine().doesPerformanceMeasurements()); diff --git a/modules/multiresvolume/rendering/atlasmanager.cpp b/modules/multiresvolume/rendering/atlasmanager.cpp index c10a87c406..366691d03b 100644 --- a/modules/multiresvolume/rendering/atlasmanager.cpp +++ b/modules/multiresvolume/rendering/atlasmanager.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace openspace { diff --git a/modules/space/rendering/renderableplanet.cpp b/modules/space/rendering/renderableplanet.cpp index 6ae6f70304..0507bf7239 100644 --- a/modules/space/rendering/renderableplanet.cpp +++ b/modules/space/rendering/renderableplanet.cpp @@ -349,7 +349,7 @@ void RenderablePlanet::initializeGL() { // correct one. if (!_programObject && _shadowEnabled && _hasNightTexture) { - _programObject = SpaceModule::ProgramObjectManager.requestProgramObject( + _programObject = SpaceModule::ProgramObjectManager.request( ShadowNightProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -361,7 +361,7 @@ void RenderablePlanet::initializeGL() { ); } else if (!_programObject && _shadowEnabled) { - _programObject = SpaceModule::ProgramObjectManager.requestProgramObject( + _programObject = SpaceModule::ProgramObjectManager.request( ShadowProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -373,7 +373,7 @@ void RenderablePlanet::initializeGL() { ); } else if (!_programObject && _hasNightTexture) { - _programObject = SpaceModule::ProgramObjectManager.requestProgramObject( + _programObject = SpaceModule::ProgramObjectManager.request( NightProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -385,7 +385,7 @@ void RenderablePlanet::initializeGL() { ); } else if (!_programObject) { - _programObject = SpaceModule::ProgramObjectManager.requestProgramObject( + _programObject = SpaceModule::ProgramObjectManager.request( PlainProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -416,7 +416,7 @@ void RenderablePlanet::deinitializeGL() { _geometry = nullptr; } - SpaceModule::ProgramObjectManager.releaseProgramObject( + SpaceModule::ProgramObjectManager.release( _programObject->name(), [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); diff --git a/modules/space/rendering/renderablerings.cpp b/modules/space/rendering/renderablerings.cpp index ad38c81165..169627979b 100644 --- a/modules/space/rendering/renderablerings.cpp +++ b/modules/space/rendering/renderablerings.cpp @@ -38,6 +38,11 @@ #include namespace { + constexpr const std::array UniformNames = { + "modelViewProjectionTransform", "textureOffset", "transparency", "_nightFactor", + "sunPosition", "texture1" + }; + constexpr openspace::properties::Property::PropertyInfo TextureInfo = { "Texture", "Texture", @@ -183,14 +188,7 @@ void RenderableRings::initializeGL() { absPath("${MODULE_SPACE}/shaders/rings_fs.glsl") ); - _uniformCache.modelViewProjection = _shader->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.textureOffset = _shader->uniformLocation("textureOffset"); - _uniformCache.transparency = _shader->uniformLocation("transparency"); - _uniformCache.nightFactor = _shader->uniformLocation("_nightFactor"); - _uniformCache.sunPosition = _shader->uniformLocation("sunPosition"); - _uniformCache.texture = _shader->uniformLocation("texture1"); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); glGenVertexArrays(1, &_quad); glGenBuffers(1, &_vertexPositionBuffer); @@ -250,15 +248,7 @@ void RenderableRings::render(const RenderData& data, RendererTasks&) { void RenderableRings::update(const UpdateData& data) { if (_shader->isDirty()) { _shader->rebuildFromFile(); - - _uniformCache.modelViewProjection = _shader->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.textureOffset = _shader->uniformLocation("textureOffset"); - _uniformCache.transparency = _shader->uniformLocation("transparency"); - _uniformCache.nightFactor = _shader->uniformLocation("_nightFactor"); - _uniformCache.sunPosition = _shader->uniformLocation("sunPosition"); - _uniformCache.texture = _shader->uniformLocation("texture1"); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); } if (_planeIsDirty) { diff --git a/modules/space/rendering/renderablestars.cpp b/modules/space/rendering/renderablestars.cpp index 1278e5f3ba..35b4c51e6e 100644 --- a/modules/space/rendering/renderablestars.cpp +++ b/modules/space/rendering/renderablestars.cpp @@ -48,6 +48,11 @@ namespace { constexpr const char* KeyFile = "File"; + constexpr const std::array UniformNames = { + "view", "projection", "colorOption", "alphaValue", "scaleFactor", + "minBillboardSize", "screenSize", "scaling", "psfTexture", "colorTexture" + }; + constexpr int8_t CurrentCacheVersion = 1; struct ColorVBOLayout { @@ -296,16 +301,7 @@ void RenderableStars::initializeGL() { absPath("${MODULE_SPACE}/shaders/star_ge.glsl") ); - _uniformCache.view = _program->uniformLocation("view"); - _uniformCache.projection = _program->uniformLocation("projection"); - _uniformCache.colorOption = _program->uniformLocation("colorOption"); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.minBillboardSize = _program->uniformLocation("minBillboardSize"); - _uniformCache.screenSize = _program->uniformLocation("screenSize"); - _uniformCache.scaling = _program->uniformLocation("scaling"); - _uniformCache.psfTexture = _program->uniformLocation("psfTexture"); - _uniformCache.colorTexture = _program->uniformLocation("colorTexture"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); bool success = loadData(); if (!success) { @@ -555,17 +551,7 @@ void RenderableStars::update(const UpdateData&) { if (_program->isDirty()) { _program->rebuildFromFile(); - - _uniformCache.view = _program->uniformLocation("view"); - _uniformCache.projection = _program->uniformLocation("projection"); - _uniformCache.colorOption = _program->uniformLocation("colorOption"); - _uniformCache.alphaValue = _program->uniformLocation("alphaValue"); - _uniformCache.scaleFactor = _program->uniformLocation("scaleFactor"); - _uniformCache.minBillboardSize = _program->uniformLocation("minBillboardSize"); - _uniformCache.screenSize = _program->uniformLocation("screenSize"); - _uniformCache.scaling = _program->uniformLocation("scaling"); - _uniformCache.psfTexture = _program->uniformLocation("psfTexture"); - _uniformCache.colorTexture = _program->uniformLocation("colorTexture"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } } diff --git a/modules/space/rendering/simplespheregeometry.cpp b/modules/space/rendering/simplespheregeometry.cpp index 9a57ad1a3e..84045a56b6 100644 --- a/modules/space/rendering/simplespheregeometry.cpp +++ b/modules/space/rendering/simplespheregeometry.cpp @@ -53,10 +53,7 @@ documentation::Documentation SimpleSphereGeometry::Documentation() { { { RadiusInfo.identifier, - new OrVerifier( - new DoubleVerifier, - new DoubleVector3Verifier - ), + new OrVerifier({ new DoubleVerifier, new DoubleVector3Verifier }), Optional::No, RadiusInfo.description }, diff --git a/modules/space/rotation/spicerotation.cpp b/modules/space/rotation/spicerotation.cpp index 3c5d67802e..d4c6afc89c 100644 --- a/modules/space/rotation/spicerotation.cpp +++ b/modules/space/rotation/spicerotation.cpp @@ -75,10 +75,7 @@ documentation::Documentation SpiceRotation::Documentation() { }, { KeyKernels, - new OrVerifier( - new StringListVerifier, - new StringVerifier - ), + new OrVerifier({ new StringListVerifier, new StringVerifier }), Optional::Yes, "A single kernel or list of kernels that this SpiceTranslation depends " "on. All provided kernels will be loaded before any other operation is " diff --git a/modules/space/translation/spicetranslation.cpp b/modules/space/translation/spicetranslation.cpp index bffc86ea80..88ac606a15 100644 --- a/modules/space/translation/spicetranslation.cpp +++ b/modules/space/translation/spicetranslation.cpp @@ -100,10 +100,7 @@ documentation::Documentation SpiceTranslation::Documentation() { }, { KeyKernels, - new OrVerifier( - new StringListVerifier, - new StringVerifier - ), + new OrVerifier({ new StringListVerifier, new StringVerifier }), Optional::Yes, "A single kernel or list of kernels that this SpiceTranslation depends " "on. All provided kernels will be loaded before any other operation is " diff --git a/modules/space/translation/tletranslation.cpp b/modules/space/translation/tletranslation.cpp index a808c9e52e..aa7af14ff3 100644 --- a/modules/space/translation/tletranslation.cpp +++ b/modules/space/translation/tletranslation.cpp @@ -251,9 +251,9 @@ documentation::Documentation TLETranslation::Documentation() { { KeyLineNumber, new DoubleGreaterVerifier(0), - Optional::No, + Optional::Yes, "Specifies the line number within the file where the group of 3 TLE " - "lines begins (1-based)." + "lines begins (1-based). Defaults to 1." } } }; @@ -267,7 +267,10 @@ TLETranslation::TLETranslation(const ghoul::Dictionary& dictionary) { ); const std::string& file = dictionary.value(KeyFile); - int lineNum = static_cast(dictionary.value(KeyLineNumber)); + int lineNum = 1; + if (dictionary.hasKeyAndValue(KeyLineNumber)) { + lineNum = static_cast(dictionary.value(KeyLineNumber)); + } readTLEFile(file, lineNum); } diff --git a/modules/spacecraftinstruments/rendering/renderablefov.cpp b/modules/spacecraftinstruments/rendering/renderablefov.cpp index 409bc6f761..e4bfe2f4bc 100644 --- a/modules/spacecraftinstruments/rendering/renderablefov.cpp +++ b/modules/spacecraftinstruments/rendering/renderablefov.cpp @@ -36,20 +36,22 @@ #include namespace { - constexpr const char* ProgramName = "FovProgram"; - constexpr const char* KeyBody = "Body"; - constexpr const char* KeyFrame = "Frame"; -// const char* KeyColor = "RGB"; - - constexpr const char* KeyInstrument = "Instrument"; - constexpr const char* KeyInstrumentName = "Name"; + constexpr const char* ProgramName = "FovProgram"; + constexpr const char* KeyBody = "Body"; + constexpr const char* KeyFrame = "Frame"; + constexpr const char* KeyInstrument = "Instrument"; + constexpr const char* KeyInstrumentName = "Name"; constexpr const char* KeyInstrumentAberration = "Aberration"; - - constexpr const char* KeyPotentialTargets = "PotentialTargets"; - constexpr const char* KeyFrameConversions = "FrameConversions"; - + constexpr const char* KeyPotentialTargets = "PotentialTargets"; + constexpr const char* KeyFrameConversions = "FrameConversions"; constexpr const char* KeyBoundsSimplification = "SimplifyBounds"; + constexpr const std::array UniformNames = { + "modelViewProjectionTransform", "defaultColorStart", "defaultColorEnd", + "activeColor", "targetInFieldOfViewColor", "intersectionStartColor", + "intersectionEndColor", "squareColor", "interpolation" + }; + constexpr const int InterpolationSteps = 5; constexpr const double Epsilon = 1e-4; @@ -326,8 +328,8 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary) } void RenderableFov::initializeGL() { - _programObject = - SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject( + _program = + SpacecraftInstrumentsModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -338,25 +340,7 @@ void RenderableFov::initializeGL() { } ); - _uniformCache.modelViewProjection = _programObject->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.defaultColorStart = _programObject->uniformLocation( - "defaultColorStart" - ); - _uniformCache.defaultColorEnd = _programObject->uniformLocation("defaultColorEnd"); - _uniformCache.activeColor = _programObject->uniformLocation("activeColor"); - _uniformCache.targetInFieldOfViewColor = _programObject->uniformLocation( - "targetInFieldOfViewColor" - ); - _uniformCache.intersectionStartColor = _programObject->uniformLocation( - "intersectionStartColor" - ); - _uniformCache.intersectionEndColor = _programObject->uniformLocation( - "intersectionEndColor" - ); - _uniformCache.squareColor = _programObject->uniformLocation("squareColor"); - _uniformCache.interpolation = _programObject->uniformLocation("interpolation"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); // Fetch information about the specific instrument SpiceManager::FieldOfViewResult res = SpiceManager::ref().fieldOfView( @@ -493,13 +477,13 @@ void RenderableFov::initializeGL() { } void RenderableFov::deinitializeGL() { - SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject( + SpacecraftInstrumentsModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); } ); - _programObject = nullptr; + _program = nullptr; glDeleteBuffers(1, &_orthogonalPlane.vbo); glDeleteVertexArrays(1, &_orthogonalPlane.vao); @@ -509,7 +493,7 @@ void RenderableFov::deinitializeGL() { } bool RenderableFov::isReady() const { - return _programObject != nullptr && !_instrument.bounds.empty(); + return _program != nullptr && !_instrument.bounds.empty(); } // Orthogonal projection next to planets surface @@ -838,7 +822,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& void RenderableFov::render(const RenderData& data, RendererTasks&) { if (_drawFOV) { - _programObject->activate(); + _program->activate(); // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = @@ -850,28 +834,28 @@ void RenderableFov::render(const RenderData& data, RendererTasks&) { data.camera.projectionMatrix() * glm::mat4(data.camera.combinedViewMatrix() * modelTransform); - _programObject->setUniform( + _program->setUniform( _uniformCache.modelViewProjection, modelViewProjectionTransform ); - _programObject->setUniform(_uniformCache.defaultColorStart, _colors.defaultStart); - _programObject->setUniform(_uniformCache.defaultColorEnd, _colors.defaultEnd); - _programObject->setUniform(_uniformCache.activeColor, _colors.active); - _programObject->setUniform( + _program->setUniform(_uniformCache.defaultColorStart, _colors.defaultStart); + _program->setUniform(_uniformCache.defaultColorEnd, _colors.defaultEnd); + _program->setUniform(_uniformCache.activeColor, _colors.active); + _program->setUniform( _uniformCache.targetInFieldOfViewColor, _colors.targetInFieldOfView ); - _programObject->setUniform( + _program->setUniform( _uniformCache.intersectionStartColor, _colors.intersectionStart ); - _programObject->setUniform( + _program->setUniform( _uniformCache.intersectionEndColor, _colors.intersectionEnd ); - _programObject->setUniform(_uniformCache.squareColor, _colors.square); - _programObject->setUniform(_uniformCache.interpolation, _interpolationTime); + _program->setUniform(_uniformCache.squareColor, _colors.square); + _program->setUniform(_uniformCache.interpolation, _interpolationTime); GLenum mode = _drawSolid ? GL_TRIANGLE_STRIP : GL_LINES; @@ -885,7 +869,7 @@ void RenderableFov::render(const RenderData& data, RendererTasks&) { glBindVertexArray(0); glLineWidth(1.f); - _programObject->deactivate(); + _program->deactivate(); } } @@ -918,30 +902,9 @@ void RenderableFov::update(const UpdateData& data) { } } - if (_programObject->isDirty()) { - _programObject->rebuildFromFile(); - - _uniformCache.modelViewProjection = _programObject->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.defaultColorStart = _programObject->uniformLocation( - "defaultColorStart" - ); - _uniformCache.defaultColorEnd = _programObject->uniformLocation( - "defaultColorEnd" - ); - _uniformCache.activeColor = _programObject->uniformLocation("activeColor"); - _uniformCache.targetInFieldOfViewColor = _programObject->uniformLocation( - "targetInFieldOfViewColor" - ); - _uniformCache.intersectionStartColor = _programObject->uniformLocation( - "intersectionStartColor" - ); - _uniformCache.intersectionEndColor = _programObject->uniformLocation( - "intersectionEndColor" - ); - _uniformCache.squareColor = _programObject->uniformLocation("squareColor"); - _uniformCache.interpolation = _programObject->uniformLocation("interpolation"); + if (_program->isDirty()) { + _program->rebuildFromFile(); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } } diff --git a/modules/spacecraftinstruments/rendering/renderablefov.h b/modules/spacecraftinstruments/rendering/renderablefov.h index e1be48c9a1..c18573e92c 100644 --- a/modules/spacecraftinstruments/rendering/renderablefov.h +++ b/modules/spacecraftinstruments/rendering/renderablefov.h @@ -93,7 +93,7 @@ private: properties::FloatProperty _lineWidth; properties::BoolProperty _drawSolid; properties::DoubleProperty _standOffDistance; - ghoul::opengl::ProgramObject* _programObject = nullptr; + ghoul::opengl::ProgramObject* _program = nullptr; UniformCache(modelViewProjection, defaultColorStart, defaultColorEnd, activeColor, targetInFieldOfViewColor, intersectionStartColor, intersectionEndColor, squareColor, interpolation) _uniformCache; diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index c504c7393c..7bb4fcc442 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -53,6 +53,20 @@ namespace { constexpr const char* DestinationFrame = "GALACTIC"; + constexpr const std::array MainUniformNames = { + "_performShading", "directionToSunViewSpace", "modelViewTransform", + "projectionTransform", "_projectionFading", "baseTexture", "projectionTexture" + }; + + constexpr const std::array FboUniformNames = { + "projectionTexture", "needShadowMap", "ProjectorMatrix", "ModelTransform", + "boresight" + }; + + constexpr const std::array DepthFboUniformNames = { + "ProjectorMatrix", "ModelTransform" + }; + constexpr openspace::properties::Property::PropertyInfo ColorTextureInfo = { "ColorTexture", "Color Base Texture", @@ -175,24 +189,10 @@ void RenderableModelProjection::initializeGL() { absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/renderableModel_fs.glsl") ); - _mainUniformCache.performShading = _programObject->uniformLocation("_performShading"); - _mainUniformCache.directionToSunViewSpace = _programObject->uniformLocation( - "directionToSunViewSpace" - ); - _mainUniformCache.modelViewTransform = _programObject->uniformLocation( - "modelViewTransform" - ); - _mainUniformCache.projectionTransform = _programObject->uniformLocation( - "projectionTransform" - ); - _mainUniformCache.projectionFading = _programObject->uniformLocation( - "_projectionFading" - ); - _mainUniformCache.baseTexture = _programObject->uniformLocation( - "baseTexture" - ); - _mainUniformCache.projectionTexture = _programObject->uniformLocation( - "projectionTexture" + ghoul::opengl::updateUniformLocations( + *_programObject, + _mainUniformCache, + MainUniformNames ); _fboProgramObject = ghoul::opengl::ProgramObject::Build( @@ -205,18 +205,11 @@ void RenderableModelProjection::initializeGL() { ) ); - _fboUniformCache.projectionTexture = _fboProgramObject->uniformLocation( - "projectionTexture" + ghoul::opengl::updateUniformLocations( + *_fboProgramObject, + _fboUniformCache, + FboUniformNames ); - _fboUniformCache.needShadowMap = _fboProgramObject->uniformLocation("needShadowMap"); - _fboUniformCache.ProjectorMatrix = _fboProgramObject->uniformLocation( - "ProjectorMatrix" - ); - _fboUniformCache.ModelTransform = _fboProgramObject->uniformLocation( - "ModelTransform" - ); - _fboUniformCache.boresight = _fboProgramObject->uniformLocation("boresight"); - _depthFboProgramObject = ghoul::opengl::ProgramObject::Build( "DepthPass", @@ -224,13 +217,11 @@ void RenderableModelProjection::initializeGL() { absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/renderableModelDepth_fs.glsl") ); - _depthFboUniformCache.ProjectorMatrix = _depthFboProgramObject->uniformLocation( - "ProjectorMatrix" + ghoul::opengl::updateUniformLocations( + *_depthFboProgramObject, + _depthFboUniformCache, + DepthFboUniformNames ); - _depthFboUniformCache.ModelTransform = _depthFboProgramObject->uniformLocation( - "ModelTransform" - ); - loadTextures(); _projectionComponent.initializeGL(); @@ -330,45 +321,21 @@ void RenderableModelProjection::update(const UpdateData& data) { if (_programObject->isDirty()) { _programObject->rebuildFromFile(); - _mainUniformCache.performShading = _programObject->uniformLocation( - "_performShading" - ); - _mainUniformCache.directionToSunViewSpace = _programObject->uniformLocation( - "directionToSunViewSpace" - ); - _mainUniformCache.modelViewTransform = _programObject->uniformLocation( - "modelViewTransform" - ); - _mainUniformCache.projectionTransform = _programObject->uniformLocation( - "projectionTransform" - ); - _mainUniformCache.projectionFading = _programObject->uniformLocation( - "_projectionFading" - ); - _mainUniformCache.baseTexture = _programObject->uniformLocation( - "baseTexture" - ); - _mainUniformCache.projectionTexture = _programObject->uniformLocation( - "projectionTexture" + ghoul::opengl::updateUniformLocations( + *_programObject, + _mainUniformCache, + MainUniformNames ); } if (_fboProgramObject->isDirty()) { _fboProgramObject->rebuildFromFile(); - _fboUniformCache.projectionTexture = _fboProgramObject->uniformLocation( - "projectionTexture" + ghoul::opengl::updateUniformLocations( + *_fboProgramObject, + _fboUniformCache, + FboUniformNames ); - _fboUniformCache.needShadowMap = _fboProgramObject->uniformLocation( - "needShadowMap" - ); - _fboUniformCache.ProjectorMatrix = _fboProgramObject->uniformLocation( - "ProjectorMatrix" - ); - _fboUniformCache.ModelTransform = _fboProgramObject->uniformLocation( - "ModelTransform" - ); - _fboUniformCache.boresight = _fboProgramObject->uniformLocation("boresight"); } _projectionComponent.update(); @@ -376,11 +343,10 @@ void RenderableModelProjection::update(const UpdateData& data) { if (_depthFboProgramObject->isDirty()) { _depthFboProgramObject->rebuildFromFile(); - _depthFboUniformCache.ProjectorMatrix = _depthFboProgramObject->uniformLocation( - "ProjectorMatrix" - ); - _depthFboUniformCache.ModelTransform = _depthFboProgramObject->uniformLocation( - "ModelTransform" + ghoul::opengl::updateUniformLocations( + *_depthFboProgramObject, + _depthFboUniformCache, + DepthFboUniformNames ); } diff --git a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp index ddd0dace19..0bd7fb8fd9 100644 --- a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp @@ -45,12 +45,20 @@ namespace { constexpr const char* ProjectiveProgramName = "ProjectiveProgram"; constexpr const char* FBOPassProgramName = "FBOPassProgram"; + constexpr const std::array MainUniformNames = { + "sun_pos", "modelTransform", "modelViewProjectionTransform", "_hasBaseMap", + "_hasHeightMap", "_heightExaggeration", "_meridianShift", "_ambientBrightness", + "_projectionFading", "baseTexture", "projectionTexture", "heightTexture" + }; + + constexpr const std::array FboUniformNames = { + "projectionTexture", "ProjectorMatrix", "ModelTransform", "_scaling", + "boresight", "_radius", "_segments" + }; constexpr const char* KeyGeometry = "Geometry"; constexpr const char* KeyProjection = "Projection"; - constexpr const char* KeyRadius = "Geometry.Radius"; -// const char* keyShading = "PerformShading"; constexpr const char* _mainFrame = "GALACTIC"; constexpr const char* NoImageText = "No Image"; @@ -349,7 +357,7 @@ RenderablePlanetProjection::~RenderablePlanetProjection() {} // NOLINT void RenderablePlanetProjection::initializeGL() { _programObject = - SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject( + SpacecraftInstrumentsModule::ProgramObjectManager.request( ProjectiveProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -364,31 +372,14 @@ void RenderablePlanetProjection::initializeGL() { } ); - _mainUniformCache.sunPos = _programObject->uniformLocation("sun_pos"); - _mainUniformCache.modelTransform = _programObject->uniformLocation("modelTransform"); - _mainUniformCache.modelViewProjectionTransform = _programObject->uniformLocation( - "modelViewProjectionTransform" + ghoul::opengl::updateUniformLocations( + *_programObject, + _mainUniformCache, + MainUniformNames ); - _mainUniformCache.hasBaseMap = _programObject->uniformLocation("_hasBaseMap"); - _mainUniformCache.hasHeightMap = _programObject->uniformLocation("_hasHeightMap"); - _mainUniformCache.heightExaggeration = _programObject->uniformLocation( - "_heightExaggeration" - ); - _mainUniformCache.meridianShift = _programObject->uniformLocation("_meridianShift"); - _mainUniformCache.ambientBrightness = _programObject->uniformLocation( - "_ambientBrightness" - ); - _mainUniformCache.projectionFading = _programObject->uniformLocation( - "_projectionFading" - ); - _mainUniformCache.baseTexture = _programObject->uniformLocation("baseTexture"); - _mainUniformCache.projectionTexture = _programObject->uniformLocation( - "projectionTexture" - ); - _mainUniformCache.heightTexture = _programObject->uniformLocation("heightTexture"); _fboProgramObject = - SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject( + SpacecraftInstrumentsModule::ProgramObjectManager.request( FBOPassProgramName, []() -> std::unique_ptr { return ghoul::opengl::ProgramObject::Build( @@ -405,19 +396,11 @@ void RenderablePlanetProjection::initializeGL() { } ); - _fboUniformCache.projectionTexture = _fboProgramObject->uniformLocation( - "projectionTexture" + ghoul::opengl::updateUniformLocations( + *_fboProgramObject, + _fboUniformCache, + FboUniformNames ); - _fboUniformCache.projectorMatrix = _fboProgramObject->uniformLocation( - "ProjectorMatrix" - ); - _fboUniformCache.modelTransform = _fboProgramObject->uniformLocation( - "ModelTransform" - ); - _fboUniformCache.scaling = _fboProgramObject->uniformLocation("_scaling"); - _fboUniformCache.boresight = _fboProgramObject->uniformLocation("boresight"); - _fboUniformCache.radius = _fboProgramObject->uniformLocation("_radius"); - _fboUniformCache.segments = _fboProgramObject->uniformLocation("_segments"); loadColorTexture(); loadHeightTexture(); @@ -464,7 +447,7 @@ void RenderablePlanetProjection::deinitializeGL() { glDeleteVertexArrays(1, &_quad); glDeleteBuffers(1, &_vertexPositionBuffer); - SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject( + SpacecraftInstrumentsModule::ProgramObjectManager.release( ProjectiveProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); @@ -472,7 +455,7 @@ void RenderablePlanetProjection::deinitializeGL() { ); _programObject = nullptr; - SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject( + SpacecraftInstrumentsModule::ProgramObjectManager.release( FBOPassProgramName ); _fboProgramObject = nullptr; @@ -639,8 +622,8 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&) // Main renderpass _programObject->activate(); _programObject->setUniform(_mainUniformCache.sunPos, sun_pos.vec3()); - //_programObject->setUniform("ViewProjection" , data.camera.viewProjectionMatrix()); - //_programObject->setUniform("ModelTransform" , _transform); + //_program->setUniform("ViewProjection" , data.camera.viewProjectionMatrix()); + //_program->setUniform("ModelTransform" , _transform); // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = @@ -714,53 +697,22 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&) void RenderablePlanetProjection::update(const UpdateData& data) { if (_programObject->isDirty()) { _programObject->rebuildFromFile(); - - _mainUniformCache.sunPos = _programObject->uniformLocation("sun_pos"); - _mainUniformCache.modelTransform = _programObject->uniformLocation( - "modelTransform" - ); - _mainUniformCache.modelViewProjectionTransform = _programObject->uniformLocation( - "modelViewProjectionTransform" - ); - _mainUniformCache.hasBaseMap = _programObject->uniformLocation("_hasBaseMap"); - _mainUniformCache.hasHeightMap = _programObject->uniformLocation("_hasHeightMap"); - _mainUniformCache.heightExaggeration = _programObject->uniformLocation( - "_heightExaggeration" - ); - _mainUniformCache.meridianShift = _programObject->uniformLocation( - "_meridianShift" - ); - _mainUniformCache.ambientBrightness = _programObject->uniformLocation( - "_ambientBrightness" - ); - _mainUniformCache.projectionFading = _programObject->uniformLocation( - "_projectionFading" - ); - _mainUniformCache.baseTexture = _programObject->uniformLocation("baseTexture"); - _mainUniformCache.projectionTexture = _programObject->uniformLocation( - "projectionTexture" - ); - _mainUniformCache.heightTexture = _programObject->uniformLocation( - "heightTexture" + + ghoul::opengl::updateUniformLocations( + *_programObject, + _mainUniformCache, + MainUniformNames ); } if (_fboProgramObject->isDirty()) { _fboProgramObject->rebuildFromFile(); - _fboUniformCache.projectionTexture = _fboProgramObject->uniformLocation( - "projectionTexture" + ghoul::opengl::updateUniformLocations( + *_fboProgramObject, + _fboUniformCache, + FboUniformNames ); - _fboUniformCache.projectorMatrix = _fboProgramObject->uniformLocation( - "ProjectorMatrix" - ); - _fboUniformCache.modelTransform = _fboProgramObject->uniformLocation( - "ModelTransform" - ); - _fboUniformCache.scaling = _fboProgramObject->uniformLocation("_scaling"); - _fboUniformCache.boresight = _fboProgramObject->uniformLocation("boresight"); - _fboUniformCache.radius = _fboProgramObject->uniformLocation("_radius"); - _fboUniformCache.segments = _fboProgramObject->uniformLocation("_segments"); } if (_colorTextureDirty) { diff --git a/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp b/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp index 1b1aa682ed..32ef6be233 100644 --- a/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp +++ b/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp @@ -39,6 +39,10 @@ namespace { constexpr const char* ProgramName = "ShadowCylinderProgram"; constexpr const char* MainFrame = "GALACTIC"; + constexpr const std::array UniformNames = { + "modelViewProjectionTransform", "shadowColor" + }; + constexpr openspace::properties::Property::PropertyInfo NumberPointsInfo = { "AmountOfPoints", "Points", @@ -277,7 +281,7 @@ void RenderableShadowCylinder::initializeGL() { glGenVertexArrays(1, &_vao); glGenBuffers(1, &_vbo); - _shader = SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject( + _shader = SpacecraftInstrumentsModule::ProgramObjectManager.request( ProgramName, []() -> std::unique_ptr { return OsEng.renderEngine().buildRenderProgram( @@ -292,16 +296,11 @@ void RenderableShadowCylinder::initializeGL() { } ); - _uniformCache.modelViewProjectionTransform = _shader->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.shadowColor = _shader->uniformLocation( - "shadowColor" - ); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); } void RenderableShadowCylinder::deinitializeGL() { - SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject( + SpacecraftInstrumentsModule::ProgramObjectManager.release( ProgramName, [](ghoul::opengl::ProgramObject* p) { OsEng.renderEngine().removeRenderProgram(p); @@ -352,15 +351,10 @@ void RenderableShadowCylinder::update(const UpdateData& data) { MainFrame, data.time.j2000Seconds() ); + if (_shader->isDirty()) { _shader->rebuildFromFile(); - - _uniformCache.modelViewProjectionTransform = _shader->uniformLocation( - "modelViewProjectionTransform" - ); - _uniformCache.shadowColor = _shader->uniformLocation( - "shadowColor" - ); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); } createCylinder(data.time.j2000Seconds()); } diff --git a/modules/spacecraftinstruments/util/imagesequencer.cpp b/modules/spacecraftinstruments/util/imagesequencer.cpp index 92936d8eae..0043f5595a 100644 --- a/modules/spacecraftinstruments/util/imagesequencer.cpp +++ b/modules/spacecraftinstruments/util/imagesequencer.cpp @@ -233,13 +233,11 @@ bool ImageSequencer::imagePaths(std::vector& captures, // check if this instance is either in range or // a valid candidate to recieve data - if (!isInstrumentActive(time, instrumentRequest)) { - return false; - } - - if (!_subsetMap[projectee]._range.includes(time) && - !_subsetMap[projectee]._range.includes(sinceTime)) - { + const bool instrumentActive = isInstrumentActive(time, instrumentRequest); + const bool hasCurrentTime = _subsetMap[projectee]._range.includes(time); + const bool hasSinceTime = _subsetMap[projectee]._range.includes(sinceTime); + + if (!instrumentActive || (!hasCurrentTime && !hasSinceTime)) { return false; } diff --git a/modules/spacecraftinstruments/util/labelparser.cpp b/modules/spacecraftinstruments/util/labelparser.cpp index 9625afc8d6..fd83d8e28a 100644 --- a/modules/spacecraftinstruments/util/labelparser.cpp +++ b/modules/spacecraftinstruments/util/labelparser.cpp @@ -143,7 +143,7 @@ bool LabelParser::create() { using Recursive = ghoul::filesystem::Directory::Recursive; using Sort = ghoul::filesystem::Directory::Sort; std::vector sequencePaths = sequenceDir.read(Recursive::Yes, Sort::No); - for (std::string path : sequencePaths) { + for (const std::string& path : sequencePaths) { size_t position = path.find_last_of('.') + 1; if (position == 0 || position == std::string::npos) { continue; @@ -182,22 +182,39 @@ bool LabelParser::create() { _detectorType = "CAMERA"; //default value + constexpr const char* ErrorMsg = + "Unrecognized '{}' in line {} in file {}. The 'Convert' table must " + "contain the identity tranformation for all values encountered in the " + "label files, for example: ROSETTA = {{ \"ROSETTA\" }}"; + /* Add more */ if (read == "TARGET_NAME") { _target = decode(line); + if (_target.empty()) { + LWARNING(fmt::format(ErrorMsg, "TARGET_NAME", line, path)); + } count++; } if (read == "INSTRUMENT_HOST_NAME") { _instrumentHostID = decode(line); + if (_instrumentHostID.empty()) { + LWARNING(fmt::format(ErrorMsg, "INSTRUMENT_HOST_NAME", line, path)); + } count++; } if (read == "INSTRUMENT_ID") { _instrumentID = decode(line); + if (_instrumentID.empty()) { + LWARNING(fmt::format(ErrorMsg, "INSTRUMENT_ID", line, path)); + } lblName = encode(line); count++; } if (read == "DETECTOR_TYPE") { _detectorType = decode(line); + if (_detectorType.empty()) { + LWARNING(fmt::format(ErrorMsg, "DETECTOR_TYPE", line, path)); + } count++; } @@ -213,7 +230,7 @@ bool LabelParser::create() { line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); read = line.substr(0, line.find_first_of('=')); - if (read == "STOP_TIME"){ + if (read == "STOP_TIME") { std::string stop = line.substr(line.find('=') + 1); stop.erase( std::remove_if( @@ -245,14 +262,14 @@ bool LabelParser::create() { using namespace std::literals; std::string p = path.substr(0, path.size() - ("lbl"s).size()); for (const std::string& ext : extensions) { - path = p + ext; - if (FileSys.fileExists(path)) { + std::string imagePath = p + ext; + if (FileSys.fileExists(imagePath)) { std::vector spiceInstrument; spiceInstrument.push_back(_instrumentID); Image image = { TimeRange(startTime, stopTime), - path, + imagePath, spiceInstrument, _target, false, diff --git a/modules/spacecraftinstruments/util/projectioncomponent.cpp b/modules/spacecraftinstruments/util/projectioncomponent.cpp index 338bd878bd..2588b9d611 100644 --- a/modules/spacecraftinstruments/util/projectioncomponent.cpp +++ b/modules/spacecraftinstruments/util/projectioncomponent.cpp @@ -22,6 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#pragma optimize ("", off) + #include #include @@ -120,10 +122,7 @@ documentation::Documentation ProjectionComponent::Documentation() { { { keySequenceDir, - new OrVerifier( - new StringVerifier, - new StringListVerifier - ), + new OrVerifier({ new StringVerifier, new StringListVerifier }), Optional::Yes, "This value specifies one or more directories from which images are " "being used for image projections. If the sequence type is set to " diff --git a/modules/sync/syncs/urlsynchronization.cpp b/modules/sync/syncs/urlsynchronization.cpp index f52c713e7b..d21be14d61 100644 --- a/modules/sync/syncs/urlsynchronization.cpp +++ b/modules/sync/syncs/urlsynchronization.cpp @@ -58,7 +58,7 @@ documentation::Documentation UrlSynchronization::Documentation() { { { KeyUrl, - new OrVerifier(new StringVerifier, new StringListVerifier), + new OrVerifier({ new StringVerifier, new StringListVerifier }), Optional::No, "The URL or urls from where the files are downloaded. If multiple URLs " "are provided, all files will be downloaded to the same directory." diff --git a/modules/touch/src/touchmarker.cpp b/modules/touch/src/touchmarker.cpp index ebe26d9faa..64787c1c2a 100644 --- a/modules/touch/src/touchmarker.cpp +++ b/modules/touch/src/touchmarker.cpp @@ -32,6 +32,10 @@ #include namespace { + constexpr const std::array UniformNames = { + "radius", "transparency", "thickness", "color" + }; + constexpr openspace::properties::Property::PropertyInfo VisibilityInfo = { "Visibility", "Toggle visibility of markers", @@ -97,10 +101,7 @@ void TouchMarker::initialize() { absPath("${MODULE_TOUCH}/shaders/marker_fs.glsl") ); - _uniformCache.radius = _shader->uniformLocation("radius"); - _uniformCache.transparency = _shader->uniformLocation("transparency"); - _uniformCache.thickness = _shader->uniformLocation("thickness"); - _uniformCache.color = _shader->uniformLocation("color"); + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); } void TouchMarker::deinitialize() { diff --git a/src/documentation/verifier.cpp b/src/documentation/verifier.cpp index 5019e40203..170be90e5f 100644 --- a/src/documentation/verifier.cpp +++ b/src/documentation/verifier.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace openspace::documentation { @@ -291,21 +292,33 @@ std::string ReferencingVerifier::documentation() const { return "Referencing Documentation: '" + identifier + "'"; } -AndVerifier::AndVerifier(Verifier* l, Verifier* r) - : lhs(l) - , rhs(r) -{ - ghoul_assert(lhs, "lhs must not be nullptr"); - ghoul_assert(rhs, "rhs must not be nullptr"); +AndVerifier::AndVerifier(const std::vector vs) { + ghoul_assert(!vs.empty(), "values must not be empty"); + for (Verifier* v : vs) { + values.push_back(std::shared_ptr(v)); + } } TestResult AndVerifier::operator()(const ghoul::Dictionary& dictionary, const std::string& key) const { - TestResult resLhs = lhs->operator()(dictionary, key); - TestResult resRhs = rhs->operator()(dictionary, key); + std::vector res(values.size()); + std::transform( + values.begin(), + values.end(), + res.begin(), + [dictionary, key](const std::shared_ptr& v) { + return v->operator()(dictionary, key); + } + ); - if (resLhs.success && resRhs.success) { + const bool success = std::all_of( + res.begin(), + res.end(), + [](const TestResult& res) { return res.success; } + ); + + if (success) { return { true, {}, {} }; } else { @@ -314,33 +327,60 @@ TestResult AndVerifier::operator()(const ghoul::Dictionary& dictionary, } std::string AndVerifier::type() const { - if (lhs->type() != rhs->type()) { - return lhs->type() + " and " + rhs->type(); - } - else { - return lhs->type(); - } + // Dirty hack to get an "and " inserted before the last element + std::vector types(values.size() - 1); + std::transform( + values.begin(), + values.end() - 1, + types.begin(), + [](const std::shared_ptr& v) { return v->type(); } + ); + types.push_back(std::string("and ") + values.back()->type()); + + return ghoul::join(types, ", "); } std::string AndVerifier::documentation() const { - return lhs->documentation() + " and " + rhs->documentation(); + // Dirty hack to get an "and " inserted before the last element + std::vector documentations(values.size() - 1); + std::transform( + values.begin(), + values.end() - 1, + documentations.begin(), + [](const std::shared_ptr& v) { return v->documentation(); } + ); + documentations.push_back(std::string("and ") + values.back()->documentation()); + + return ghoul::join(documentations, ", "); } -OrVerifier::OrVerifier(Verifier* l, Verifier* r) - : lhs(l) - , rhs(r) -{ - ghoul_assert(lhs, "lhs must not be nullptr"); - ghoul_assert(rhs, "rhs must not be nullptr"); +OrVerifier::OrVerifier(const std::vector vs) { + ghoul_assert(!vs.empty(), "values must not be empty"); + for (Verifier* v : vs) { + values.push_back(std::shared_ptr(v)); + } } TestResult OrVerifier::operator()(const ghoul::Dictionary& dictionary, - const std::string& key) const + const std::string& key) const { - TestResult resA = lhs->operator()(dictionary, key); - TestResult resB = rhs->operator()(dictionary, key); + std::vector res(values.size()); + std::transform( + values.begin(), + values.end(), + res.begin(), + [dictionary, key](const std::shared_ptr& v) { + return v->operator()(dictionary, key); + } + ); - if (resA.success || resB.success) { + const bool success = std::any_of( + res.begin(), + res.end(), + [](const TestResult& res) { return res.success; } + ); + + if (success) { return { true, {}, {} }; } else { @@ -349,17 +389,31 @@ TestResult OrVerifier::operator()(const ghoul::Dictionary& dictionary, } std::string OrVerifier::type() const { - if (lhs->type() != rhs->type()) { - return lhs->type() + " or " + rhs->type(); - } - else { - return lhs->type(); - } + // Dirty hack to get an "or " inserted before the last element + std::vector types(values.size() - 1); + std::transform( + values.begin(), + values.end() - 1, + types.begin(), + [](const std::shared_ptr& v) { return v->type(); } + ); + types.push_back(std::string("or ") + values.back()->type()); + + return ghoul::join(types, ", "); } std::string OrVerifier::documentation() const { - return lhs->documentation() + " or " + rhs->documentation(); + // Dirty hack to get an "or " inserted before the last element + std::vector documentations(values.size() - 1); + std::transform( + values.begin(), + values.end() - 1, + documentations.begin(), + [](const std::shared_ptr& v) { return v->documentation(); } + ); + documentations.push_back(std::string("or ") + values.back()->documentation()); + + return ghoul::join(documentations, ", "); } - } // namespace openspace::documentation diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 33b62e2001..2a884c08ac 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -49,6 +49,11 @@ namespace { constexpr const char* _loggerCat = "FramebufferRenderer"; + + constexpr const std::array UniformNames = { + "mainColorTextures", "blackoutFactor", "nAaSamples" + }; + constexpr const char* ExitFragmentShaderPath = "${SHADERS}/framebuffer/exitframebuffer.frag"; constexpr const char* RaycastFragmentShaderPath = @@ -222,9 +227,7 @@ void FramebufferRenderer::initialize() { absPath("${SHADERS}/framebuffer/resolveframebuffer.frag") ); - _uniformCache.mainColorTexture = _resolveProgram->uniformLocation("mainColorTexture"); - _uniformCache.blackoutFactor = _resolveProgram->uniformLocation("blackoutFactor"); - _uniformCache.nAaSamples = _resolveProgram->uniformLocation("nAaSamples"); + ghoul::opengl::updateUniformLocations(*_resolveProgram, _uniformCache, UniformNames); OsEng.renderEngine().raycasterManager().addListener(*this); OsEng.renderEngine().deferredcasterManager().addListener(*this); @@ -294,11 +297,11 @@ void FramebufferRenderer::update() { if (_resolveProgram->isDirty()) { _resolveProgram->rebuildFromFile(); - _uniformCache.mainColorTexture = _resolveProgram->uniformLocation( - "mainColorTexture" + ghoul::opengl::updateUniformLocations( + *_resolveProgram, + _uniformCache, + UniformNames ); - _uniformCache.blackoutFactor = _resolveProgram->uniformLocation("blackoutFactor"); - _uniformCache.nAaSamples = _resolveProgram->uniformLocation("nAaSamples"); } using K = VolumeRaycaster*; diff --git a/src/rendering/loadingscreen.cpp b/src/rendering/loadingscreen.cpp index b96832be2c..152f0710b0 100644 --- a/src/rendering/loadingscreen.cpp +++ b/src/rendering/loadingscreen.cpp @@ -110,9 +110,11 @@ LoadingScreen::LoadingScreen(ShowMessage showMessage, ShowNodeNames showNodeName absPath("${SHADERS}/loadingscreen.frag") ); - _uniformCache.logoTexture = _program->uniformLocation("logoTexture"); - _uniformCache.useTexture = _program->uniformLocation("useTexture"); - _uniformCache.color = _program->uniformLocation("color"); + ghoul::opengl::updateUniformLocations( + *_program, + _uniformCache, + { "logoTexture", "useTexture", "color" } + ); _loadingFont = OsEng.fontManager().font( "Loading", diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index ab605b9742..ad5fb4ba16 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -66,6 +66,10 @@ namespace { // when horizontal scrolling is required. constexpr const int NVisibleCharsAfterCursor = 5; + constexpr std::array UniformNames = { + "res", "color", "height", "ortho" + }; + constexpr openspace::properties::Property::PropertyInfo VisibleInfo = { "IsVisible", "Is Visible", @@ -242,10 +246,7 @@ void LuaConsole::initialize() { absPath("${SHADERS}/luaconsole.frag") ); - _uniformCache.res = _program->uniformLocation("res"); - _uniformCache.color = _program->uniformLocation("color"); - _uniformCache.height = _program->uniformLocation("height"); - _uniformCache.ortho = _program->uniformLocation("ortho"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); const GLfloat data[] = { 0.f, 0.f, @@ -701,10 +702,7 @@ void LuaConsole::render() { if (_program->isDirty()) { _program->rebuildFromFile(); - _uniformCache.res = _program->uniformLocation("res"); - _uniformCache.color = _program->uniformLocation("color"); - _uniformCache.height = _program->uniformLocation("height"); - _uniformCache.ortho = _program->uniformLocation("ortho"); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } const glm::vec2 dpiScaling = OsEng.windowWrapper().dpiScaling(); diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index c6cb6c97cc..60f079132b 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -42,6 +42,10 @@ namespace { constexpr const char* KeyTag = "Tag"; constexpr const float PlaneDepth = -2.f; + constexpr const std::array UniformNames = { + "OcclusionDepth", "Alpha", "ModelTransform", "ViewProjectionMatrix", "texture1" + }; + constexpr openspace::properties::Property::PropertyInfo EnabledInfo = { "Enabled", "Is Enabled", @@ -201,10 +205,7 @@ documentation::Documentation ScreenSpaceRenderable::Documentation() { }, { KeyTag, - new OrVerifier( - new StringVerifier, - new StringListVerifier - ), + new OrVerifier({ new StringVerifier, new StringListVerifier }), Optional::Yes, "Defines either a single or multiple tags that apply to this " "ScreenSpaceRenderable, thus making it possible to address multiple, " @@ -474,12 +475,7 @@ void ScreenSpaceRenderable::createShaders() { dict ); - _uniformCache.occlusionDepth = _shader->uniformLocation("OcclusionDepth"); - _uniformCache.alpha = _shader->uniformLocation("Alpha"); - _uniformCache.modelTransform = _shader->uniformLocation("ModelTransform"); - _uniformCache.viewProj = _shader->uniformLocation("ViewProjectionMatrix"); - _uniformCache.texture = _shader->uniformLocation("texture1"); - + ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames); } glm::mat4 ScreenSpaceRenderable::scaleMatrix() { diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index 38b5cba88e..e21845b97d 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -207,12 +207,6 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { if (it != _loadedKernels.end()) { it->refCount++; - LDEBUG( - fmt::format( - "Kernel '{}' was already loaded. New reference count: {}", - path, it->refCount - ) - ); return it->id; } diff --git a/tests/test_documentation.inl b/tests/test_documentation.inl index 90ae1a3a06..a16f4807b9 100644 --- a/tests/test_documentation.inl +++ b/tests/test_documentation.inl @@ -2023,9 +2023,12 @@ TEST_F(DocumentationTest, AndOperator) { Documentation doc { { - { "a", new AndVerifier( - new IntGreaterEqualVerifier(2), new IntLessEqualVerifier(5) - ), Optional::No + { + "a", + new AndVerifier({ + new IntGreaterEqualVerifier(2), new IntLessEqualVerifier(5) + }), + Optional::No } } }; @@ -2061,7 +2064,7 @@ TEST_F(DocumentationTest, OrOperator) { using namespace std::string_literals; Documentation doc { - {{ "a", new OrVerifier(new StringVerifier, new IntVerifier), Optional::No}} + {{ "a", new OrVerifier({ new StringVerifier, new IntVerifier }), Optional::No }} }; ghoul::Dictionary positive {