diff --git a/modules/space/rendering/renderablesatellites.cpp b/modules/space/rendering/renderablesatellites.cpp index 3dece3e0d3..7453ff44f5 100644 --- a/modules/space/rendering/renderablesatellites.cpp +++ b/modules/space/rendering/renderablesatellites.cpp @@ -21,17 +21,12 @@ * 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 -#include +#include #include - -#include - #include #include #include @@ -39,15 +34,15 @@ #include #include #include - #include #include #include #include #include - +#include #include #include +#include namespace { constexpr const char* ProgramName = "RenderableSatellites"; @@ -317,7 +312,7 @@ documentation::Documentation RenderableSatellites::Documentation() { new DoubleVector3Verifier, Optional::No, LineColorInfo.description - }, + } } }; } @@ -333,14 +328,11 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary) Documentation(), dictionary, "RenderableSatellites" - ); + ); - _path = - dictionary.value(PathInfo.identifier); - _nSegments = - static_cast(dictionary.value(SegmentsInfo.identifier)); - _lineFade = - static_cast(dictionary.value(FadeInfo.identifier)); + _path = dictionary.value(PathInfo.identifier); + _nSegments = static_cast(dictionary.value(SegmentsInfo.identifier)); + _lineFade = static_cast(dictionary.value(FadeInfo.identifier)); if (dictionary.hasKeyAndValue(LineColorInfo.identifier)) { _appearance.lineColor = dictionary.value(LineColorInfo.identifier); @@ -364,16 +356,15 @@ void RenderableSatellites::readTLEFile(const std::string& filename) { file.exceptions(std::ifstream::failbit | std::ifstream::badbit); file.open(filename); - __int64 numberOfLines = std::count(std::istreambuf_iterator(file), + std::streamoff numberOfLines = std::count(std::istreambuf_iterator(file), std::istreambuf_iterator(), '\n' ); file.seekg(std::ios_base::beg); // reset iterator to beginning of file // 3 because a TLE has 3 lines per element/ object. - __int64 numberOfObjects = numberOfLines/3; + std::streamoff numberOfObjects = numberOfLines / 3; std::string line = "-"; - for (__int64 i = 0; i < numberOfObjects; i++) { - + for (std::streamoff i = 0; i < numberOfObjects; i++) { std::getline(file, line); // get rid of title KeplerParameters keplerElements; @@ -470,14 +461,6 @@ void RenderableSatellites::readTLEFile(const std::string& filename) { file.close(); } -void RenderableSatellites::initialize() { - -} - -void RenderableSatellites::deinitialize() { - -} - void RenderableSatellites::initializeGL() { glGenVertexArrays(1, &_vertexArray); glGenBuffers(1, &_vertexBuffer); @@ -493,21 +476,19 @@ void RenderableSatellites::initializeGL() { } ); - _uniformCache.modelView = _programObject->uniformLocation("modelViewTransform"); - _uniformCache.projection = _programObject->uniformLocation("projectionTransform"); - _uniformCache.lineFade = _programObject->uniformLocation("lineFade"); - _uniformCache.inGameTime = _programObject->uniformLocation("inGameTime"); - _uniformCache.color = _programObject->uniformLocation("color"); - _uniformCache.opacity = _programObject->uniformLocation("opacity"); + _uniformCache.modelView = _programObject->uniformLocation("modelViewTransform"); + _uniformCache.projection = _programObject->uniformLocation("projectionTransform"); + _uniformCache.lineFade = _programObject->uniformLocation("lineFade"); + _uniformCache.inGameTime = _programObject->uniformLocation("inGameTime"); + _uniformCache.color = _programObject->uniformLocation("color"); + _uniformCache.opacity = _programObject->uniformLocation("opacity"); updateBuffers(); - setRenderBin(Renderable::RenderBin::Overlay); } void RenderableSatellites::deinitializeGL() { glDeleteBuffers(1, &_vertexBuffer); - //glDeleteBuffers(1, &_indexBuffer); glDeleteVertexArrays(1, &_vertexArray); SpaceModule::ProgramObjectManager.release( @@ -519,25 +500,17 @@ void RenderableSatellites::deinitializeGL() { _programObject = nullptr; } - bool RenderableSatellites::isReady() const { - _programObject->activate(); - - return true; -} - -void RenderableSatellites::update(const UpdateData& data) { + return _programObject != nullptr; } void RenderableSatellites::render(const RenderData& data, RendererTasks&) { if (_TLEData.empty()) return; - _inGameTime = data.time.j2000Seconds(); _programObject->activate(); - _programObject->setUniform(_uniformCache.opacity, _opacity); - _programObject->setUniform(_uniformCache.inGameTime, _inGameTime); + _programObject->setUniform(_uniformCache.inGameTime, data.time.j2000Seconds()); glm::dmat4 modelTransform = diff --git a/modules/space/rendering/renderablesatellites.h b/modules/space/rendering/renderablesatellites.h index d3143d564e..e052683cfc 100644 --- a/modules/space/rendering/renderablesatellites.h +++ b/modules/space/rendering/renderablesatellites.h @@ -22,26 +22,47 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_BASE___RenderableSatellites___H__ -#define __OPENSPACE_MODULE_BASE___RenderableSatellites___H__ +#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLESATELLITES___H__ +#define __OPENSPACE_MODULE_SPACE___RENDERABLESATELLITES___H__ #include #include #include - #include #include - -#include +#include #include - -#include -#include -#include +#include namespace openspace { +class RenderableSatellites : public Renderable { +public: + RenderableSatellites(const ghoul::Dictionary& dictionary); + + void initializeGL() override; + void deinitializeGL() override; + + bool isReady() const override; + void render(const RenderData& data, RendererTasks& rendererTask) override; + + static documentation::Documentation Documentation(); + /** + * Reads the provided TLE file and calls the KeplerTranslation::setKeplerElments + * method with the correct values. If \p filename is a valid TLE file but contains + * disallowed values (see KeplerTranslation::setKeplerElements), a + * KeplerTranslation::RangeError is thrown. + * + * \param filename The path to the file that contains the TLE file. + * + * \throw ghoul::RuntimeError if the TLE file does not exist or there is a + * problem with its format. + * \pre The \p filename must exist + */ + void readTLEFile(const std::string& filename); + +private: struct Vertex { glm::vec3 position; glm::vec3 color; @@ -60,82 +81,49 @@ namespace openspace { double period = 0.0; }; - class RenderableSatellites : public Renderable { - public: - RenderableSatellites(const ghoul::Dictionary& dictionary); - - void initialize() override; - void deinitialize() override; - void initializeGL() override; - void deinitializeGL() override; - - bool isReady() const override; - - void render(const RenderData& data, RendererTasks& rendererTask) override; - void update(const UpdateData& data) override; - - static documentation::Documentation Documentation(); - /** - * Reads the provided TLE file and calls the KeplerTranslation::setKeplerElments - * method with the correct values. If \p filename is a valid TLE file but contains - * disallowed values (see KeplerTranslation::setKeplerElements), a - * KeplerTranslation::RangeError is thrown. - * - * \param filename The path to the file that contains the TLE file. - * - * \throw ghoul::RuntimeError if the TLE file does not exist or there is a - * problem with its format. - * \pre The \p filename must exist - */ - void readTLEFile(const std::string& filename); - - private: - /// The layout of the VBOs - struct TrailVBOLayout { - float x, y, z, time; - double epoch, period; - }; - // static_assert(sizeof(struct TrailVBOLayout)==4*sizeof(float)+2*sizeof(double),"Implementation error!"); - - KeplerTranslation _keplerTranslator; - std::vector _TLEData; - - /// The backend storage for the vertex buffer object containing all points for this - /// trail. - std::vector _vertexBufferData; - - /// The index array that is potentially used in the draw call. If this is empty, no - /// element draw call is used. - std::vector _indexBufferData; - - GLuint _vertexArray; - GLuint _vertexBuffer; - GLuint _indexBuffer; - - //GLuint _vaoTest; // vertexArrayObject - //GLuint _vboTest; // vertextBufferObject - //GLuint _eboTest; // elementBufferObject/ indexBufferObject - - void updateBuffers(); - - ghoul::opengl::ProgramObject* _programObject; - - properties::StringProperty _path; - properties::UIntProperty _nSegments; - - properties::DoubleProperty _lineFade; - - RenderableTrail::Appearance _appearance; - - glm::vec3 _position; - - double _inGameTime = 0.0; - - UniformCache(modelView, projection, lineFade, inGameTime, color, opacity, numberOfSegments) - _uniformCache; - + /// The layout of the VBOs + struct TrailVBOLayout { + float x, y, z, time; + double epoch, period; }; -} -#endif // __OPENSPACE_MODULE_BASE___RenderableSatellites___H__ + KeplerTranslation _keplerTranslator; + std::vector _TLEData; + + /// The backend storage for the vertex buffer object containing all points for this + /// trail. + std::vector _vertexBufferData; + + /// The index array that is potentially used in the draw call. If this is empty, no + /// element draw call is used. + std::vector _indexBufferData; + + GLuint _vertexArray; + GLuint _vertexBuffer; + GLuint _indexBuffer; + + //GLuint _vaoTest; // vertexArrayObject + //GLuint _vboTest; // vertextBufferObject + //GLuint _eboTest; // elementBufferObject/ indexBufferObject + + void updateBuffers(); + + ghoul::opengl::ProgramObject* _programObject; + + properties::StringProperty _path; + properties::UIntProperty _nSegments; + + properties::DoubleProperty _lineFade; + + RenderableTrail::Appearance _appearance; + + glm::vec3 _position; + + UniformCache(modelView, projection, lineFade, inGameTime, color, opacity, + numberOfSegments) _uniformCache; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_SPACE___RENDERABLESATELLITES___H__