diff --git a/data/test.png b/data/test.png index a67058ce50..dc49d4f9e0 100644 Binary files a/data/test.png and b/data/test.png differ diff --git a/modules/base/rendering/screenspaceimage.cpp b/modules/base/rendering/screenspaceimage.cpp index ec01b63abd..a26d1cce7e 100644 --- a/modules/base/rendering/screenspaceimage.cpp +++ b/modules/base/rendering/screenspaceimage.cpp @@ -74,10 +74,10 @@ bool ScreenSpaceImage::deinitialize(){ _texture = nullptr; RenderEngine& renderEngine = OsEng.renderEngine(); - if (_shader) { - renderEngine.removeRenderProgram(_shader); - _shader = nullptr; - } + if (_shader) { + renderEngine.removeRenderProgram(_shader); + _shader = nullptr; + } return true; } diff --git a/modules/iswa/CMakeLists.txt b/modules/iswa/CMakeLists.txt index 75d3cf2d3b..801d5286fb 100644 --- a/modules/iswa/CMakeLists.txt +++ b/modules/iswa/CMakeLists.txt @@ -30,6 +30,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswacygnet.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/textureplane.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.h ${CMAKE_CURRENT_SOURCE_DIR}/util/iswamanager.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -40,6 +41,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/cygnetplane.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/textureplane.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.cpp ${CMAKE_CURRENT_SOURCE_DIR}/util/iswamanager.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/iswa/rendering/iswacontainer.cpp b/modules/iswa/rendering/iswacontainer.cpp index 4877bd2fb3..2f9839aa71 100644 --- a/modules/iswa/rendering/iswacontainer.cpp +++ b/modules/iswa/rendering/iswacontainer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace openspace{ @@ -48,6 +49,8 @@ bool ISWAContainer::initialize(){ // addISWACygnet("${OPENSPACE_DATA}/ENLIL.cdf"); addISWACygnet("${OPENSPACE_DATA}/test.png"); + OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared(3)); + return true; } diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp new file mode 100644 index 0000000000..ffffc52c35 --- /dev/null +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -0,0 +1,157 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2016 * +* * +* 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 +#include + +namespace { + const std::string _loggerCat = "ScreenSpaceCygnet"; +} + +namespace openspace { + +ScreenSpaceCygnet::ScreenSpaceCygnet(int cygnetId) +: ScreenSpaceRenderable() +, _cygnetId("cygnetId", "CygnetID",7, 0, 10) +, _updateInterval("updateInterval", "Update Interval", 3, 1, 10) +{ + _id = id(); + setName("ScreenSpaceCygnet" + std::to_string(_id)); + addProperty(_cygnetId); + addProperty(_updateInterval); + + registerProperties(); + OsEng.gui()._property.registerProperty(&_cygnetId); + OsEng.gui()._property.registerProperty(&_updateInterval); + + _path = "${OPENSPACE_DATA}/test.png"; +} + +ScreenSpaceCygnet::~ScreenSpaceCygnet(){} + +bool ScreenSpaceCygnet::initialize(){ + _originalViewportSize = OsEng.windowWrapper().currentWindowResolution(); + + createPlane(); + createShaders(); + + loadTexture(); + + // Setting spherical/euclidean onchange handler + _useFlatScreen.onChange([this](){ + useEuclideanCoordinates(_useFlatScreen.value()); + }); + return isReady(); +} + +bool ScreenSpaceCygnet::deinitialize(){ + glDeleteVertexArrays(1, &_quad); + _quad = 0; + + glDeleteBuffers(1, &_vertexPositionBuffer); + _vertexPositionBuffer = 0; + + + _path = ""; + _texture = nullptr; + + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_shader) { + renderEngine.removeRenderProgram(_shader); + _shader = nullptr; + } + + return true; +} + +void ScreenSpaceCygnet::render(){ + glm::mat4 rotation = rotationMatrix(); + glm::mat4 translation = translationMatrix(); + glm::mat4 scale = scaleMatrix(); + glm::mat4 modelTransform = rotation*translation*scale; + + draw(modelTransform); +} + +void ScreenSpaceCygnet::update(){ + _time = Time::ref().currentTime(); + + if((_time-_lastUpdateTime) >= _updateInterval){ + updateTexture(); + _lastUpdateTime = _time; + } + + if(_futureTexture && _futureTexture->isFinished){ + _path = absPath("${OPENSPACE_DATA}/"+_futureTexture->filePath); + loadTexture(); + + delete _futureTexture; + _futureTexture = nullptr; + } +} + +void ScreenSpaceCygnet::updateTexture(){ + DownloadManager::FileFuture* future; + future = DlManager.downloadFile( + ISWAManager::ref().iSWAurl(_cygnetId.value()), + absPath(_path), + true, + [](const DownloadManager::FileFuture& f){ + std::cout<<"download finished"< texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path)); + + if (texture) { + LDEBUG("Loaded texture from '" << absPath(_path) << "'"); + + texture->uploadTexture(); + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + + _texture = std::move(texture); + } +} + +int ScreenSpaceCygnet::id(){ + static int id = 0; + return id++; +} + +} \ No newline at end of file diff --git a/modules/iswa/rendering/screenspacecygnet.h b/modules/iswa/rendering/screenspacecygnet.h new file mode 100644 index 0000000000..a71be35194 --- /dev/null +++ b/modules/iswa/rendering/screenspacecygnet.h @@ -0,0 +1,61 @@ +/***************************************************************************************** +* * +* 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. * +****************************************************************************************/ + +#ifndef __SCREENSPACECYGNET_H__ +#define __SCREENSPACECYGNET_H__ + +#include +#include + +namespace openspace{ + +class ScreenSpaceCygnet : public ScreenSpaceRenderable { +public: + ScreenSpaceCygnet(int cygnetId); + ~ScreenSpaceCygnet(); + + void render() override; + bool initialize() override; + bool deinitialize() override; + void update() override; + bool isReady() const override; + +private: + static int id(); + void updateTexture(); + void loadTexture(); + + properties::IntProperty _cygnetId; + properties::FloatProperty _updateInterval; + + std::string _path; + int _id; + float _time; + float _lastUpdateTime = 0.0f; + DownloadManager::FileFuture* _futureTexture; +}; + + } // namespace openspace + +#endif //__SCREENSPACECYGNET_H__ \ No newline at end of file diff --git a/modules/iswa/rendering/textureplane.cpp b/modules/iswa/rendering/textureplane.cpp index 49cbcbcc54..14b266301d 100644 --- a/modules/iswa/rendering/textureplane.cpp +++ b/modules/iswa/rendering/textureplane.cpp @@ -177,7 +177,7 @@ void TexturePlane::updateTexture(){ void TexturePlane::loadTexture() { - std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path)); + std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path)); if (texture) { LDEBUG("Loaded texture from '" << absPath(_path) << "'"); diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 19370cab6c..3b6db9b66d 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -58,7 +58,8 @@ namespace openspace{ } else { cygnet = std::make_shared(path); } - + //if screenspacecygnet + //OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared(3)); cygnet->initialize(); return cygnet; // _iSWACygnets.push_back(cygnet); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 991325387a..d586619eea 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -213,18 +213,6 @@ bool RenderEngine::initialize() { ghoul::io::TextureReader::ref().addReader(std::make_shared()); - //For testing screenspacerenderables - - - std::shared_ptr ssfb = std::make_shared(); - ssfb->addRenderFunction(std::make_shared>([this](){renderInformation();})); - ssfb->addRenderFunction(std::make_shared>([this](){ssr->render();})); - registerScreenSpaceRenderable(ssfb); - - - ssr = std::make_shared("${OPENSPACE_DATA}/test2.jpg"); - registerScreenSpaceRenderable(ssr); - return true; }