From ca7dcd4762314aebd33c8763180f17afc79f7b34 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 21 May 2015 15:17:38 +0200 Subject: [PATCH] Move shaders into their correct modules Add path determination to modules that automatically sets correct path resolve tokens --- ext/ghoul | 2 +- include/openspace/util/openspacemodule.h | 9 +- modules/base/CMakeLists.txt | 25 ++++++ modules/base/basemodule.cpp | 10 +++ modules/base/basemodule.h | 1 + .../renderableconstellationbounds.cpp | 4 +- modules/base/rendering/renderablemodel.cpp | 4 +- modules/base/rendering/renderablepath.cpp | 78 ++++++++--------- modules/base/rendering/renderableplane.cpp | 4 +- modules/base/rendering/renderablesphere.cpp | 4 +- modules/base/rendering/renderablestars.cpp | 6 +- modules/base/rendering/renderabletrail.cpp | 4 +- .../base/shaders}/constellationbounds_fs.glsl | 0 .../base/shaders}/constellationbounds_vs.glsl | 0 .../base/shaders}/ephemeris_fs.glsl | 0 .../base/shaders}/ephemeris_vs.glsl | 0 .../base/shaders}/fieldline_fs.glsl | 0 .../base/shaders}/fieldline_gs.glsl | 0 .../base/shaders}/fieldline_vs.glsl | 0 .../base/shaders}/imageplane_fs.glsl | 0 .../base/shaders}/imageplane_vs.glsl | 0 .../base/shaders}/model_fs.glsl | 0 .../base/shaders}/model_vs.glsl | 0 .../base/shaders}/path_fs.glsl | 0 .../base/shaders}/path_gs.glsl | 0 .../base/shaders}/path_vs.glsl | 0 .../base/shaders}/plane_fs.glsl | 0 .../base/shaders}/plane_vs.glsl | 0 .../base/shaders}/sphere_fs.glsl | 0 .../base/shaders}/sphere_vs.glsl | 0 .../base/shaders}/star_fs.glsl | 0 .../base/shaders}/star_ge.glsl | 0 .../base/shaders}/star_vs.glsl | 0 modules/newhorizons/newhorizonsmodule.cpp | 8 ++ modules/newhorizons/newhorizonsmodule.h | 1 + .../rendering/renderablecrawlingline.cpp | 4 +- .../newhorizons/rendering/renderablefov.cpp | 4 +- .../rendering/renderableplaneprojection.cpp | 4 +- .../rendering/renderableplanetprojection.cpp | 6 +- .../newhorizons/shaders}/crawlingline_fs.glsl | 0 .../newhorizons/shaders}/crawlingline_vs.glsl | 0 .../newhorizons/shaders}/fov_fs.glsl | 0 .../newhorizons/shaders}/fov_vs.glsl | 0 .../shaders}/projectiveTexture_fs.glsl | 0 .../shaders}/projectiveTexture_vs.glsl | 0 modules/volume/volumemodule.cpp | 7 ++ modules/volume/volumemodule.h | 1 + openspace.cfg | 1 + src/abuffer/abuffer.cpp | 2 + src/engine/openspaceengine.cpp | 6 +- src/gui/gui.cpp | 2 + src/util/openspacemodule.cpp | 83 +++++++++++++++++++ 52 files changed, 212 insertions(+), 68 deletions(-) rename {shaders/modules/constellationbounds => modules/base/shaders}/constellationbounds_fs.glsl (100%) rename {shaders/modules/constellationbounds => modules/base/shaders}/constellationbounds_vs.glsl (100%) rename {shaders/modules/trails => modules/base/shaders}/ephemeris_fs.glsl (100%) rename {shaders/modules/trails => modules/base/shaders}/ephemeris_vs.glsl (100%) rename {shaders/modules/fieldlines => modules/base/shaders}/fieldline_fs.glsl (100%) rename {shaders/modules/fieldlines => modules/base/shaders}/fieldline_gs.glsl (100%) rename {shaders/modules/fieldlines => modules/base/shaders}/fieldline_vs.glsl (100%) rename {shaders/modules/imageplane => modules/base/shaders}/imageplane_fs.glsl (100%) rename {shaders/modules/imageplane => modules/base/shaders}/imageplane_vs.glsl (100%) rename {shaders/modules/model => modules/base/shaders}/model_fs.glsl (100%) rename {shaders/modules/model => modules/base/shaders}/model_vs.glsl (100%) rename {shaders/modules/trails => modules/base/shaders}/path_fs.glsl (100%) rename {shaders/modules/trails => modules/base/shaders}/path_gs.glsl (100%) rename {shaders/modules/trails => modules/base/shaders}/path_vs.glsl (100%) rename {shaders/modules/plane => modules/base/shaders}/plane_fs.glsl (100%) rename {shaders/modules/plane => modules/base/shaders}/plane_vs.glsl (100%) rename {shaders/modules/sphere => modules/base/shaders}/sphere_fs.glsl (100%) rename {shaders/modules/sphere => modules/base/shaders}/sphere_vs.glsl (100%) rename {shaders/modules/stars => modules/base/shaders}/star_fs.glsl (100%) rename {shaders/modules/stars => modules/base/shaders}/star_ge.glsl (100%) rename {shaders/modules/stars => modules/base/shaders}/star_vs.glsl (100%) rename {shaders/modules/crawlingline => modules/newhorizons/shaders}/crawlingline_fs.glsl (100%) rename {shaders/modules/crawlingline => modules/newhorizons/shaders}/crawlingline_vs.glsl (100%) rename {shaders/modules/projection => modules/newhorizons/shaders}/fov_fs.glsl (100%) rename {shaders/modules/projection => modules/newhorizons/shaders}/fov_vs.glsl (100%) rename {shaders/modules/projection => modules/newhorizons/shaders}/projectiveTexture_fs.glsl (100%) rename {shaders/modules/projection => modules/newhorizons/shaders}/projectiveTexture_vs.glsl (100%) create mode 100644 src/util/openspacemodule.cpp diff --git a/ext/ghoul b/ext/ghoul index 711fd33d85..f48a0a6420 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 711fd33d8536abc52242ae266566245bdc199a97 +Subproject commit f48a0a6420fced7b5e605bdd5f74685ca0f4b37e diff --git a/include/openspace/util/openspacemodule.h b/include/openspace/util/openspacemodule.h index b0a73522ac..7f2d17c7d7 100644 --- a/include/openspace/util/openspacemodule.h +++ b/include/openspace/util/openspacemodule.h @@ -34,13 +34,14 @@ public: OpenSpaceModule() = default; virtual ~OpenSpaceModule() = default; - virtual bool initialize() { return true; } - virtual bool deinitialize() { return true; } + virtual bool initialize(); + virtual bool deinitialize(); - std::string name() const { return _name; } + std::string name() const; protected: - void setName(std::string name) { _name = std::move(name); } + void setName(std::string name); + std::string modulePath() const; std::string _name; }; diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index c1b679fc71..2f6af054f8 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -40,6 +40,31 @@ set(SOURCE_FILES ) source_group("Source Files" FILES ${SOURCE_FILES}) +set(SHADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/ephemeris_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/ephemeris_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/fieldline_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/fieldline_gs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/fieldline_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/model_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/model_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/path_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/path_gs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/path_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/plane_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/plane_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/sphere_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/sphere_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl +) +source_group("Shader Files" FILES ${SHADER_FILES}) + set(MODULE_CLASS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/basemodule.h ${CMAKE_CURRENT_SOURCE_DIR}/basemodule.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index bb6b5a59a3..f2edeb85a2 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -48,9 +48,19 @@ #include #include +#include + namespace openspace { +BaseModule::BaseModule() { + setName("Base"); +} + bool BaseModule::initialize() { + bool success = OpenSpaceModule::initialize(); + if (!success) + return false; + FactoryManager::ref().addFactory(new ghoul::TemplateFactory); FactoryManager::ref().addFactory(new ghoul::TemplateFactory); diff --git a/modules/base/basemodule.h b/modules/base/basemodule.h index 6561a5cace..37dc678bb2 100644 --- a/modules/base/basemodule.h +++ b/modules/base/basemodule.h @@ -31,6 +31,7 @@ namespace openspace { class BaseModule : public OpenSpaceModule { public: + BaseModule(); bool initialize() override; }; diff --git a/modules/base/rendering/renderableconstellationbounds.cpp b/modules/base/rendering/renderableconstellationbounds.cpp index 9837d56656..52fa9785a7 100644 --- a/modules/base/rendering/renderableconstellationbounds.cpp +++ b/modules/base/rendering/renderableconstellationbounds.cpp @@ -91,8 +91,8 @@ RenderableConstellationBounds::~RenderableConstellationBounds() { bool RenderableConstellationBounds::initialize() { _program = ghoul::opengl::ProgramObject::Build("ConstellationBounds", - "${SHADERS}/modules/constellationbounds/constellationbounds_vs.glsl", - "${SHADERS}/modules/constellationbounds/constellationbounds_fs.glsl"); + "${MODULE_BASE}/shaders/constellationbounds_vs.glsl", + "${MODULE_BASE}/shaders/constellationbounds_fs.glsl"); if (!_program) return false; diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index b48257c4ca..487450f7bd 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -128,8 +128,8 @@ bool RenderableModel::initialize() { if (_programObject == nullptr) { // NH shader _programObject = ghoul::opengl::ProgramObject::Build("ModelProgram", - "${SHADERS}/modules/model/model_vs.glsl", - "${SHADERS}/modules/model/model_fs.glsl"); + "${MODULE_BASE}/shaders/model_vs.glsl", + "${MODULE_BASE}/shaders/model_fs.glsl"); if (!_programObject) return false; } diff --git a/modules/base/rendering/renderablepath.cpp b/modules/base/rendering/renderablepath.cpp index 2108a23f6d..8e145f220e 100644 --- a/modules/base/rendering/renderablepath.cpp +++ b/modules/base/rendering/renderablepath.cpp @@ -100,9 +100,8 @@ bool RenderablePath::initialize() { bool completeSuccess = true; _programObject = ghoul::opengl::ProgramObject::Build("PathProgram", - "${SHADERS}/modules/trails/path_vs.glsl", - "${SHADERS}/modules/trails/path_fs.glsl" - //,"${SHADERS}/modules/trails/path_gs.glsl" + "${MODULE_BASE}/shaders/path_vs.glsl", + "${MODULE_BASE}/shaders/path_fs.glsl" ); if (!_programObject) return false; @@ -200,45 +199,48 @@ void RenderablePath::update(const UpdateData& data) { } void RenderablePath::calculatePath(std::string observer) { - - double interval = (_stop - _start); - int segments = static_cast(interval /_increment); - double lightTime; - bool correctPosition = true; + double interval = (_stop - _start); + int segments = static_cast(interval /_increment); - psc pscPos; - double currentTime = _start; - _vertexArray.resize(segments); + if (segments == 0) + return; - //float r, g, b; - //float g = _lineColor[1]; - //float b = _lineColor[2]; - for (int i = 0; i < segments; i++) { - correctPosition = SpiceManager::ref().getTargetPosition(_target, observer, _frame, "NONE", currentTime, pscPos, lightTime); - pscPos[3] += 3; + double lightTime; + bool correctPosition = true; + + psc pscPos; + double currentTime = _start; + _vertexArray.resize(segments); + + //float r, g, b; + //float g = _lineColor[1]; + //float b = _lineColor[2]; + for (int i = 0; i < segments; i++) { + correctPosition = SpiceManager::ref().getTargetPosition(_target, observer, _frame, "NONE", currentTime, pscPos, lightTime); + pscPos[3] += 3; - //if (!correctPosition) { - // r = 1.f; - // g = b = 0.5f; - //} - //else if ((i % 8) == 0) { - // r = _lineColor[0]; - // g = _lineColor[1]; - // b = _lineColor[2]; - //} - //else { - // r = g = b = 0.6f; - //} - //add position - _vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] }; - //add color for position - //_vertexArray[i + 1] = { r, g, b, a }; - currentTime += _increment; - } - _lastPosition = pscPos.dvec4(); + //if (!correctPosition) { + // r = 1.f; + // g = b = 0.5f; + //} + //else if ((i % 8) == 0) { + // r = _lineColor[0]; + // g = _lineColor[1]; + // b = _lineColor[2]; + //} + //else { + // r = g = b = 0.6f; + //} + //add position + _vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] }; + //add color for position + //_vertexArray[i + 1] = { r, g, b, a }; + currentTime += _increment; + } + _lastPosition = pscPos.dvec4(); - glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); - glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]); + glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); + glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]); } void RenderablePath::sendToGPU() { diff --git a/modules/base/rendering/renderableplane.cpp b/modules/base/rendering/renderableplane.cpp index 96b18ad9cf..aac8d1fb84 100644 --- a/modules/base/rendering/renderableplane.cpp +++ b/modules/base/rendering/renderableplane.cpp @@ -128,8 +128,8 @@ bool RenderablePlane::initialize() { if (_shader == nullptr) { // Plane Program _shader = ghoul::opengl::ProgramObject::Build("PlaneProgram", - "${SHADERS}/modules/plane/plane_vs.glsl", - "${SHADERS}/modules/plane/plane_fs.glsl"); + "${MODULE_BASE}/shaders/plane_vs.glsl", + "${MODULE_BASE}/shaders/plane_fs.glsl"); if (!_shader) return false; } diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index 996f5e9863..70c6dee647 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -120,8 +120,8 @@ bool RenderableSphere::initialize() { // pscstandard _shader = ghoul::opengl::ProgramObject::Build("Sphere", - "${SHADERS}/modules/sphere/sphere_vs.glsl", - "${SHADERS}/modules/sphere/sphere_fs.glsl"); + "${MODULES}/base/shaders/sphere_vs.glsl", + "${MODULES}/base/shaders/sphere_fs.glsl"); if (!_shader) return false; diff --git a/modules/base/rendering/renderablestars.cpp b/modules/base/rendering/renderablestars.cpp index 079645859b..1bc08cff79 100644 --- a/modules/base/rendering/renderablestars.cpp +++ b/modules/base/rendering/renderablestars.cpp @@ -147,9 +147,9 @@ bool RenderableStars::initialize() { bool completeSuccess = true; _program = ghoul::opengl::ProgramObject::Build("Star", - "${SHADERS}/modules/stars/star_vs.glsl", - "${SHADERS}/modules/stars/star_fs.glsl", - "${SHADERS}/modules/stars/star_ge.glsl"); + "${MODULE_BASE}/shaders/star_vs.glsl", + "${MODULE_BASE}/shaders/star_fs.glsl", + "${MODULE_BASE}/shaders/star_ge.glsl"); if (!_program) return false; completeSuccess &= loadData(); diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 6110b6056a..045ee51131 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -114,8 +114,8 @@ bool RenderableTrail::initialize() { bool completeSuccess = true; _programObject = ghoul::opengl::ProgramObject::Build("EphemerisProgram", - "${SHADERS}/modules/trails/ephemeris_vs.glsl", - "${SHADERS}/modules/trails/ephemeris_fs.glsl"); + "${MODULE_BASE}/shaders/ephemeris_vs.glsl", + "${MODULE_BASE}/shaders/ephemeris_fs.glsl"); if (!_programObject) return false; diff --git a/shaders/modules/constellationbounds/constellationbounds_fs.glsl b/modules/base/shaders/constellationbounds_fs.glsl similarity index 100% rename from shaders/modules/constellationbounds/constellationbounds_fs.glsl rename to modules/base/shaders/constellationbounds_fs.glsl diff --git a/shaders/modules/constellationbounds/constellationbounds_vs.glsl b/modules/base/shaders/constellationbounds_vs.glsl similarity index 100% rename from shaders/modules/constellationbounds/constellationbounds_vs.glsl rename to modules/base/shaders/constellationbounds_vs.glsl diff --git a/shaders/modules/trails/ephemeris_fs.glsl b/modules/base/shaders/ephemeris_fs.glsl similarity index 100% rename from shaders/modules/trails/ephemeris_fs.glsl rename to modules/base/shaders/ephemeris_fs.glsl diff --git a/shaders/modules/trails/ephemeris_vs.glsl b/modules/base/shaders/ephemeris_vs.glsl similarity index 100% rename from shaders/modules/trails/ephemeris_vs.glsl rename to modules/base/shaders/ephemeris_vs.glsl diff --git a/shaders/modules/fieldlines/fieldline_fs.glsl b/modules/base/shaders/fieldline_fs.glsl similarity index 100% rename from shaders/modules/fieldlines/fieldline_fs.glsl rename to modules/base/shaders/fieldline_fs.glsl diff --git a/shaders/modules/fieldlines/fieldline_gs.glsl b/modules/base/shaders/fieldline_gs.glsl similarity index 100% rename from shaders/modules/fieldlines/fieldline_gs.glsl rename to modules/base/shaders/fieldline_gs.glsl diff --git a/shaders/modules/fieldlines/fieldline_vs.glsl b/modules/base/shaders/fieldline_vs.glsl similarity index 100% rename from shaders/modules/fieldlines/fieldline_vs.glsl rename to modules/base/shaders/fieldline_vs.glsl diff --git a/shaders/modules/imageplane/imageplane_fs.glsl b/modules/base/shaders/imageplane_fs.glsl similarity index 100% rename from shaders/modules/imageplane/imageplane_fs.glsl rename to modules/base/shaders/imageplane_fs.glsl diff --git a/shaders/modules/imageplane/imageplane_vs.glsl b/modules/base/shaders/imageplane_vs.glsl similarity index 100% rename from shaders/modules/imageplane/imageplane_vs.glsl rename to modules/base/shaders/imageplane_vs.glsl diff --git a/shaders/modules/model/model_fs.glsl b/modules/base/shaders/model_fs.glsl similarity index 100% rename from shaders/modules/model/model_fs.glsl rename to modules/base/shaders/model_fs.glsl diff --git a/shaders/modules/model/model_vs.glsl b/modules/base/shaders/model_vs.glsl similarity index 100% rename from shaders/modules/model/model_vs.glsl rename to modules/base/shaders/model_vs.glsl diff --git a/shaders/modules/trails/path_fs.glsl b/modules/base/shaders/path_fs.glsl similarity index 100% rename from shaders/modules/trails/path_fs.glsl rename to modules/base/shaders/path_fs.glsl diff --git a/shaders/modules/trails/path_gs.glsl b/modules/base/shaders/path_gs.glsl similarity index 100% rename from shaders/modules/trails/path_gs.glsl rename to modules/base/shaders/path_gs.glsl diff --git a/shaders/modules/trails/path_vs.glsl b/modules/base/shaders/path_vs.glsl similarity index 100% rename from shaders/modules/trails/path_vs.glsl rename to modules/base/shaders/path_vs.glsl diff --git a/shaders/modules/plane/plane_fs.glsl b/modules/base/shaders/plane_fs.glsl similarity index 100% rename from shaders/modules/plane/plane_fs.glsl rename to modules/base/shaders/plane_fs.glsl diff --git a/shaders/modules/plane/plane_vs.glsl b/modules/base/shaders/plane_vs.glsl similarity index 100% rename from shaders/modules/plane/plane_vs.glsl rename to modules/base/shaders/plane_vs.glsl diff --git a/shaders/modules/sphere/sphere_fs.glsl b/modules/base/shaders/sphere_fs.glsl similarity index 100% rename from shaders/modules/sphere/sphere_fs.glsl rename to modules/base/shaders/sphere_fs.glsl diff --git a/shaders/modules/sphere/sphere_vs.glsl b/modules/base/shaders/sphere_vs.glsl similarity index 100% rename from shaders/modules/sphere/sphere_vs.glsl rename to modules/base/shaders/sphere_vs.glsl diff --git a/shaders/modules/stars/star_fs.glsl b/modules/base/shaders/star_fs.glsl similarity index 100% rename from shaders/modules/stars/star_fs.glsl rename to modules/base/shaders/star_fs.glsl diff --git a/shaders/modules/stars/star_ge.glsl b/modules/base/shaders/star_ge.glsl similarity index 100% rename from shaders/modules/stars/star_ge.glsl rename to modules/base/shaders/star_ge.glsl diff --git a/shaders/modules/stars/star_vs.glsl b/modules/base/shaders/star_vs.glsl similarity index 100% rename from shaders/modules/stars/star_vs.glsl rename to modules/base/shaders/star_vs.glsl diff --git a/modules/newhorizons/newhorizonsmodule.cpp b/modules/newhorizons/newhorizonsmodule.cpp index a6e835b595..720472deac 100644 --- a/modules/newhorizons/newhorizonsmodule.cpp +++ b/modules/newhorizons/newhorizonsmodule.cpp @@ -43,7 +43,15 @@ namespace openspace { +NewHorizonsModule::NewHorizonsModule() { + setName("NewHorizons"); +} + bool NewHorizonsModule::initialize() { + bool success = OpenSpaceModule::initialize(); + if (!success) + return false; + FactoryManager::ref().addFactory(new ghoul::TemplateFactory); FactoryManager::ref().addFactory(new ghoul::TemplateFactory); diff --git a/modules/newhorizons/newhorizonsmodule.h b/modules/newhorizons/newhorizonsmodule.h index c5d89d8cbd..ebbc4ef3d6 100644 --- a/modules/newhorizons/newhorizonsmodule.h +++ b/modules/newhorizons/newhorizonsmodule.h @@ -31,6 +31,7 @@ namespace openspace { class NewHorizonsModule : public OpenSpaceModule { public: + NewHorizonsModule(); bool initialize() override; }; diff --git a/modules/newhorizons/rendering/renderablecrawlingline.cpp b/modules/newhorizons/rendering/renderablecrawlingline.cpp index 58dcdd354d..8169ce1b33 100644 --- a/modules/newhorizons/rendering/renderablecrawlingline.cpp +++ b/modules/newhorizons/rendering/renderablecrawlingline.cpp @@ -77,8 +77,8 @@ bool RenderableCrawlingLine::initialize() { _frameCounter = 0; bool completeSuccess = true; _program = ghoul::opengl::ProgramObject::Build("RenderableCrawlingLine", - "${SHADERS}/modules/crawlingline/crawlingline_vs.glsl", - "${SHADERS}/modules/crawlingline/crawlingline_fs.glsl" + "${MODULE_NEWHORIZONS}/shaders/crawlingline_vs.glsl", + "${MODULE_NEWHORIZONS}/shaders/crawlingline_fs.glsl" ); if (!_program) return false; diff --git a/modules/newhorizons/rendering/renderablefov.cpp b/modules/newhorizons/rendering/renderablefov.cpp index 6f82510f10..43e8a941a4 100644 --- a/modules/newhorizons/rendering/renderablefov.cpp +++ b/modules/newhorizons/rendering/renderablefov.cpp @@ -145,8 +145,8 @@ bool RenderableFov::initialize() { bool completeSuccess = true; if (_programObject == nullptr) { _programObject = ghoul::opengl::ProgramObject::Build("FovProgram", - "${SHADERS}/modules/projection/fov_vs.glsl", - "${SHADERS}/modules/projection/fov_fs.glsl"); + "${MODULE_NEWHORIZONS}/shaders/fov_vs.glsl", + "${MODULE_NEWHORIZONS}/shaders/fov_fs.glsl"); if (!_programObject) return false; } diff --git a/modules/newhorizons/rendering/renderableplaneprojection.cpp b/modules/newhorizons/rendering/renderableplaneprojection.cpp index ef2def2353..bdcf032200 100644 --- a/modules/newhorizons/rendering/renderableplaneprojection.cpp +++ b/modules/newhorizons/rendering/renderableplaneprojection.cpp @@ -98,8 +98,8 @@ bool RenderablePlaneProjection::initialize() { if (_shader == nullptr) { // Image Plane Program _shader = ghoul::opengl::ProgramObject::Build("ImagePlaneProgram", - "${SHADERS}/modules/imageplane/imageplane_vs.glsl", - "${SHADERS}/modules/imageplane/imageplane_fs.glsl"); + "${MODULE_BASE}/shaders/imageplane_vs.glsl", + "${MODULE_BASE}/shaders/imageplane_fs.glsl"); if (!_shader) return false; } diff --git a/modules/newhorizons/rendering/renderableplanetprojection.cpp b/modules/newhorizons/rendering/renderableplanetprojection.cpp index 1a13599eab..e17d4f81bc 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.cpp +++ b/modules/newhorizons/rendering/renderableplanetprojection.cpp @@ -212,8 +212,8 @@ bool RenderablePlanetProjection::initialize() { if (_programObject == nullptr) { // projection program _programObject = ghoul::opengl::ProgramObject::Build("projectiveProgram", - "${SHADERS}/modules/projection/projectiveTexture_vs.glsl", - "${SHADERS}/modules/projection/projectiveTexture_fs.glsl"); + "${MODULES}/newhorizons/shaders/projectiveTexture_vs.glsl", + "${MODULES}/newhorizons/shaders/projectiveTexture_fs.glsl"); if (!_programObject) return false; } @@ -289,7 +289,7 @@ bool RenderablePlanetProjection::deinitialize(){ return true; } bool RenderablePlanetProjection::isReady() const { - return (_geometry != nullptr); + return _geometry && _programObject; } void RenderablePlanetProjection::imageProjectGPU(){ diff --git a/shaders/modules/crawlingline/crawlingline_fs.glsl b/modules/newhorizons/shaders/crawlingline_fs.glsl similarity index 100% rename from shaders/modules/crawlingline/crawlingline_fs.glsl rename to modules/newhorizons/shaders/crawlingline_fs.glsl diff --git a/shaders/modules/crawlingline/crawlingline_vs.glsl b/modules/newhorizons/shaders/crawlingline_vs.glsl similarity index 100% rename from shaders/modules/crawlingline/crawlingline_vs.glsl rename to modules/newhorizons/shaders/crawlingline_vs.glsl diff --git a/shaders/modules/projection/fov_fs.glsl b/modules/newhorizons/shaders/fov_fs.glsl similarity index 100% rename from shaders/modules/projection/fov_fs.glsl rename to modules/newhorizons/shaders/fov_fs.glsl diff --git a/shaders/modules/projection/fov_vs.glsl b/modules/newhorizons/shaders/fov_vs.glsl similarity index 100% rename from shaders/modules/projection/fov_vs.glsl rename to modules/newhorizons/shaders/fov_vs.glsl diff --git a/shaders/modules/projection/projectiveTexture_fs.glsl b/modules/newhorizons/shaders/projectiveTexture_fs.glsl similarity index 100% rename from shaders/modules/projection/projectiveTexture_fs.glsl rename to modules/newhorizons/shaders/projectiveTexture_fs.glsl diff --git a/shaders/modules/projection/projectiveTexture_vs.glsl b/modules/newhorizons/shaders/projectiveTexture_vs.glsl similarity index 100% rename from shaders/modules/projection/projectiveTexture_vs.glsl rename to modules/newhorizons/shaders/projectiveTexture_vs.glsl diff --git a/modules/volume/volumemodule.cpp b/modules/volume/volumemodule.cpp index 6811bbb55f..08eba0f856 100644 --- a/modules/volume/volumemodule.cpp +++ b/modules/volume/volumemodule.cpp @@ -33,7 +33,14 @@ namespace openspace { +VolumeModule::VolumeModule() { + setName("Volume"); +} + bool VolumeModule::initialize() { + bool success = OpenSpaceModule::initialize(); + if (!success) + return false; auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "No renderable factory existed"); diff --git a/modules/volume/volumemodule.h b/modules/volume/volumemodule.h index 5377c1940b..73094ba1d6 100644 --- a/modules/volume/volumemodule.h +++ b/modules/volume/volumemodule.h @@ -31,6 +31,7 @@ namespace openspace { class VolumeModule : public OpenSpaceModule { public: + VolumeModule(); bool initialize() override; }; diff --git a/openspace.cfg b/openspace.cfg index 505bf7812c..1fb1965c3e 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -15,6 +15,7 @@ return { SHADERS = "${BASE_PATH}/shaders", SHADERS_GENERATED = "${SHADERS}/generated", OPENSPACE_DATA = "${BASE_PATH}/openspace-data", + MODULES = "${BASE_PATH}/modules", TESTDIR = "${BASE_PATH}/tests", CONFIG = "${BASE_PATH}/config", CACHE = "${BASE_PATH}/cache", diff --git a/src/abuffer/abuffer.cpp b/src/abuffer/abuffer.cpp index 52ced2a1ce..700413430d 100644 --- a/src/abuffer/abuffer.cpp +++ b/src/abuffer/abuffer.cpp @@ -191,6 +191,8 @@ int ABuffer::addSamplerfile(const std::string& filename) { } bool ABuffer::updateShader() { + if (_resolveShader == nullptr) + return false; bool s = _resolveShader->rebuildFromFile(); if (s) { int startAt = 0; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 4717af4fec..686ca9c836 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -110,9 +110,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName) SpiceManager::initialize(); Time::initialize(); ghoul::systemcapabilities::SystemCapabilities::initialize(); - - // Register modules - _moduleEngine->initialize(); } OpenSpaceEngine::~OpenSpaceEngine() { @@ -226,6 +223,9 @@ bool OpenSpaceEngine::create( } } + // Register modules + _engine->_moduleEngine->initialize(); + // Create the cachemanager FileSys.createCacheManager(absPath("${" + ConfigurationManager::KeyCache + "}"), CacheVersion); _engine->_console->initialize(); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index f022906ac1..80da9a901f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -198,6 +198,8 @@ void GUI::initialize() { void GUI::initializeGL() { _program = ghoul::opengl::ProgramObject::Build("GUI", "${SHADERS}/gui_vs.glsl", "${SHADERS}/gui_fs.glsl"); + if (!_program) + return; positionLocation = glGetAttribLocation(*_program, "in_position"); uvLocation = glGetAttribLocation(*_program, "in_uv"); diff --git a/src/util/openspacemodule.cpp b/src/util/openspacemodule.cpp new file mode 100644 index 0000000000..dc944f3fe3 --- /dev/null +++ b/src/util/openspacemodule.cpp @@ -0,0 +1,83 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include + +#include + +namespace { + const std::string _loggerCat = "OpenSpaceModule"; + const std::string ModuleBaseToken = "MODULE_"; +} +//ghoul::filesystem::FileSystem::TokenOpeningBraces +//ghoul::filesystem::FileSystem::TokenClosingBraces +namespace openspace { + +bool OpenSpaceModule::initialize() { + ghoul_assert(!(name().empty()), "Module name must be set before initialize call"); + std::string moduleNameUpper = name(); + std::transform(moduleNameUpper.begin(), moduleNameUpper.end(), moduleNameUpper.begin(), toupper); + std::string moduleToken = + ghoul::filesystem::FileSystem::TokenOpeningBraces + + ModuleBaseToken + + moduleNameUpper + + ghoul::filesystem::FileSystem::TokenClosingBraces; + + std::string path = modulePath(); + LDEBUG("Registering module path: " << moduleToken << ": " << path); + FileSys.registerPathToken(moduleToken, path); + return true; +} + +bool OpenSpaceModule::deinitialize() { + return true; +} + +std::string OpenSpaceModule::name() const { + return _name; +} + +void OpenSpaceModule::setName(std::string name) { + _name = std::move(name); +} + +std::string OpenSpaceModule::modulePath() const { + std::string moduleName = name(); + std::transform(moduleName.begin(), moduleName.end(), moduleName.begin(), tolower); + + if (FileSys.directoryExists("${MODULES}/" + moduleName)) + return absPath("${MODULES}/" + moduleName); + +#ifdef EXTERNAL_MODULES_PATHS + +#endif + LERROR("Could not resolve path for module '" << name() << "'"); + return ""; +} + + +} // namespace openspace