From 665d832454f84cd11f87bed9aa3816dfaa629730 Mon Sep 17 00:00:00 2001 From: Michal Marcinkowski Date: Tue, 5 May 2015 20:19:19 -0400 Subject: [PATCH] optimization for projections --- .../planets/renderableplanetprojection.h | 5 ++ openspace-data | 2 +- scripts/default_startup.lua | 13 ++-- .../planets/renderableplanetprojection.cpp | 69 +++++++++++++------ src/util/hongkangparser.cpp | 2 +- 5 files changed, 61 insertions(+), 30 deletions(-) diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index cbd89d127f..cff08a8341 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -53,6 +53,7 @@ namespace planetgeometryprojection { class PlanetGeometryProjection; } + class RenderablePlanetProjection : public Renderable { public: RenderablePlanetProjection(const ghoul::Dictionary& dictionary); @@ -74,6 +75,9 @@ protected: glm::mat4 computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up); void attitudeParameters(double time); + void textureBind(); + void project(); + private: void imageProjectGPU(); @@ -90,6 +94,7 @@ private: ghoul::opengl::Texture* _texture; ghoul::opengl::Texture* _textureOriginal; ghoul::opengl::Texture* _textureProj; + ghoul::opengl::Texture* _textureWhiteSquare; planetgeometryprojection::PlanetGeometryProjection* _geometry; glm::vec2 _camScaling; diff --git a/openspace-data b/openspace-data index d03aa05d72..15254d339b 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit d03aa05d729b564a2ac1dfafbcaac24da4cba614 +Subproject commit 15254d339bfc390190230502d04a26c35de6e934 diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index 9d7089981b..19fdb57b85 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -7,23 +7,22 @@ openspace.setInvertRoll(true); --openspace.time.setTime("2007 FEB 27 16:30:00") -- This is the start time for a Jupiter run of New Horizons ---openspace.time.setTime("2007 FEB 28 03:45:00") -- Io Capture! +--TESTING ALICE +--openspace.time.setTime("2015-07-13T00:00:00.00") +--openspace.time.setTime("2015-07-14T08:00:00.00") ---openspace.time.setTime("2011 AUG 6 07:15:00") -- Dawn @ Vestaprojection ---openspace.time.setTime("2014 AUG 28 03:45:00") -- Rosetta Travels 67p in triangular shape - -openspace.time.setDeltaTime(10) -- How many seconds pass per second of realtime, changeable in the GUI +openspace.time.setDeltaTime(0) -- How many seconds pass per second of realtime, changeable in the GUI dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load the default keybindings -- openspace.time.setDeltaTime(50); -openspace.time.setTime("2015-07-14T10:50:00.00") -- PLUTO +--openspace.time.setTime("2015-07-14T12:00:00.00") -- PLUTO -- NH takes series of images from visible to dark side (across terminator) -- Sequence lasts ~10 mins, (recommended dt = 10) ---openspace.time.setTime("2015-07-14T11:22:00.00") -- PLUTO +openspace.time.setTime("2015-07-14T11:22:00.00") -- PLUTO --BEAUTIFUL SEQUENCE -- NH takes series of images (same as previous) -- Sequence ends at 2015 JUL 14T11:24:00:000, (recommended dt = 1) diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index c171217504..3509076a42 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #define _USE_MATH_DEFINES #include @@ -91,6 +92,7 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& , _texture(nullptr) , _textureProj(nullptr) , _textureOriginal(nullptr) + , _textureWhiteSquare(nullptr) , _geometry(nullptr) , _rotation("rotation", "Rotation", 0, 0, 360) , _once(false) @@ -219,7 +221,9 @@ bool RenderablePlanetProjection::initialize(){ loadTexture(); loadProjectionTexture(); completeSuccess &= (_texture != nullptr); + completeSuccess &= (_textureOriginal != nullptr); completeSuccess &= (_textureProj != nullptr); + completeSuccess &= (_textureWhiteSquare != nullptr); completeSuccess &= _geometry->initialize(this); @@ -272,6 +276,10 @@ bool RenderablePlanetProjection::deinitialize(){ _texture = nullptr; delete _textureProj; _textureProj = nullptr; + delete _textureOriginal; + _textureOriginal = nullptr; + delete _textureWhiteSquare; + _textureWhiteSquare = nullptr; delete _geometry; _geometry = nullptr; return true; @@ -401,26 +409,43 @@ void RenderablePlanetProjection::attitudeParameters(double time){ _projectorMatrix = computeProjectorMatrix(cpos, bs, _up); } + +void RenderablePlanetProjection::textureBind(){ + ghoul::opengl::TextureUnit unit[2]; + unit[0].activate(); + _texture->bind(); + _programObject->setUniform("texture1", unit[0]); + unit[1].activate(); + _textureWhiteSquare->bind(); + _programObject->setUniform("texture2", unit[1]); +} + +void RenderablePlanetProjection::project(){ + for (auto img : _imageTimes){ + std::thread t1(&RenderablePlanetProjection::attitudeParameters, this, img.startTime); + t1.join(); + _projectionTexturePath = img.path; // path to current images + imageProjectGPU(); //fbopass + } + _capture = false; +} + + #define GPU_PROJ void RenderablePlanetProjection::render(const RenderData& data){ if (!_programObject) return; if (!_textureProj) return; - + _camScaling = data.camera.scaling(); _up = data.camera.lookUpVector(); + double startTime, endTime; + #ifdef GPU_PROJ - if (_capture){ - for (auto img : _imageTimes){ - attitudeParameters(img.startTime); // compute projector viewmatrix - _projectionTexturePath = img.path; // path to current images - imageProjectGPU(); //fbopass - } - _capture = false; - } + if (_capture) + project(); #endif attitudeParameters(_time); - _projectionTexturePath = _defaultProjImage; psc sun_pos; double lt; @@ -435,20 +460,14 @@ void RenderablePlanetProjection::render(const RenderData& data){ _programObject->setUniform("ModelTransform" , _transform); _programObject->setUniform("boresight" , _boresight); setPscUniforms(_programObject, &data.camera, data.position); - - // Bind texture - ghoul::opengl::TextureUnit unit[2]; - unit[0].activate(); - _texture->bind(); - _programObject->setUniform("texture1", unit[0]); - unit[1].activate(); - _textureProj->bind(); - _programObject->setUniform("texture2", unit[1]); - + + textureBind(); + // render geometry _geometry->render(); // disable shader _programObject->deactivate(); + } void RenderablePlanetProjection::update(const UpdateData& data){ @@ -461,7 +480,6 @@ void RenderablePlanetProjection::update(const UpdateData& data){ _capture = openspace::ImageSequencer2::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID); } //floor fading to decimal - //_fadeProjection = floorf(_fadeProjection * 10) / 10; } void RenderablePlanetProjection::loadProjectionTexture(){ @@ -496,5 +514,14 @@ void RenderablePlanetProjection::loadTexture(){ _textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear); } } + delete _textureWhiteSquare; + _textureWhiteSquare = nullptr; + if (_colorTexturePath.value() != "") { + _textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage)); + if (_textureWhiteSquare) { + _textureWhiteSquare->uploadTexture(); + _textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + } + } } } // namespace openspace diff --git a/src/util/hongkangparser.cpp b/src/util/hongkangparser.cpp index 53bb9df700..74bc79967a 100644 --- a/src/util/hongkangparser.cpp +++ b/src/util/hongkangparser.cpp @@ -46,7 +46,7 @@ namespace openspace { std::string spacecraft, ghoul::Dictionary translationDictionary, std::vector potentialTargets) : - _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder_blank.png")) + _defaultCaptureImage(absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png")) { _fileName = fileName; _spacecraft = spacecraft;