diff --git a/include/openspace/rendering/renderableplane.h b/include/openspace/rendering/renderableplane.h index 1e09c4aa1e..155b0e9300 100644 --- a/include/openspace/rendering/renderableplane.h +++ b/include/openspace/rendering/renderableplane.h @@ -25,12 +25,11 @@ #ifndef RENDERABLEPLANE_H_ #define RENDERABLEPLANE_H_ -// open space includes #include -#include -// ghoul includes #include +#include +#include #include #include @@ -57,15 +56,19 @@ public: private: void loadTexture(); + void createPlane(); properties::StringProperty _texturePath; properties::BoolProperty _billboard; + properties::Vec2Property _size; - glm::vec2 _size; Origin _origin; + bool _planeIsDirty; + ghoul::opengl::ProgramObject* _shader; bool _programIsDirty; + bool _textureIsDirty; ghoul::opengl::Texture* _texture; GLuint _quad; GLuint _vertexPositionBuffer; diff --git a/openspace-data b/openspace-data index 68bea64699..c13c426dec 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 68bea6469987edc1eb6140f44a8f035eabd2e00b +Subproject commit c13c426decd55a4ecfccfdaa542adf83aa036804 diff --git a/scripts/default_settings.lua b/scripts/default_settings.lua index b9a5c6d3a8..5617e34d4a 100644 --- a/scripts/default_settings.lua +++ b/scripts/default_settings.lua @@ -3,6 +3,7 @@ -- set settings in the loaded scene graph openspace.printInfo("Setting default values") +openspace.setPropertyValue("Sun.renderable.enabled", false) openspace.setPropertyValue("Constellation Bounds.renderable.enabled", false) openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.75) diff --git a/src/gui/guipropertycomponent.cpp b/src/gui/guipropertycomponent.cpp index 8593089110..633a079544 100644 --- a/src/gui/guipropertycomponent.cpp +++ b/src/gui/guipropertycomponent.cpp @@ -148,7 +148,7 @@ namespace { Vec2Property::ValueType value = *p; - ImGui::SliderFloat2((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x); + ImGui::SliderFloat2((ownerName + "." + name).c_str(), &value.x, std::min(p->minValue().x, p->minValue().y), std::max(p->maxValue().x, p->maxValue().y)); if (value != p->value()) executeScript(p->fullyQualifiedIdentifier(), diff --git a/src/rendering/renderableplane.cpp b/src/rendering/renderableplane.cpp index 356fec4200..0177d8d41a 100644 --- a/src/rendering/renderableplane.cpp +++ b/src/rendering/renderableplane.cpp @@ -34,6 +34,8 @@ namespace { const std::string _loggerCat = "RenderablePlane"; + ghoul::filesystem::File* _colorTextureFile; + const std::string keyFieldlines = "Fieldlines"; const std::string keyFilename = "File"; const std::string keyHints = "Hints"; @@ -48,16 +50,18 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _texturePath("texture", "Texture") , _billboard("billboard", "Billboard", false) - , _size(glm::vec2(1,1)) + , _size("size", "Size", glm::vec2(1,1), glm::vec2(0.f), glm::vec2(1.f, 25.f)) , _origin(Origin::Center) , _shader(nullptr) , _programIsDirty(false) , _texture(nullptr) + , _textureIsDirty(false) , _quad(0) , _vertexPositionBuffer(0) { - - dictionary.getValue("Size", _size); + glm::vec2 size; + dictionary.getValue("Size", size); + _size = size; std::string origin; if (dictionary.getValue("Origin", origin)) { @@ -86,16 +90,25 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary) std::string texturePath = ""; bool success = dictionary.getValue("Texture", texturePath); - if (success) + if (success) { _texturePath = findPath(texturePath); + _colorTextureFile = new ghoul::filesystem::File(_texturePath); + } + addProperty(_billboard); addProperty(_texturePath); - _texturePath.onChange(std::bind(&RenderablePlane::loadTexture, this)); + _texturePath.onChange(std::bind(&RenderablePlane::loadTexture, this)); + _colorTextureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; }); - setBoundingSphere(_size); + addProperty(_size); + //_size.onChange(std::bind(&RenderablePlane::createPlane, this)); + _size.onChange([this](){ _planeIsDirty = true; }); + + setBoundingSphere(_size.value()); } RenderablePlane::~RenderablePlane() { + delete _colorTextureFile; } bool RenderablePlane::isReady() const { @@ -108,31 +121,9 @@ bool RenderablePlane::isReady() const { } bool RenderablePlane::initialize() { - - // ============================ - // GEOMETRY (quad) - // ============================ - const GLfloat size = _size[0]; - const GLfloat w = _size[1]; - const GLfloat vertex_data[] = { // square of two triangles (sigh) - // x y z w s t - -size, -size, 0.0f, w, 0,1, - size, size, 0.0f, w, 1, 0, - -size, size, 0.0f, w, 0, 0, - -size, -size, 0.0f, w, 0, 1, - size, -size, 0.0f, w, 1, 1, - size, size, 0.0f, w, 1, 0, - }; - - glGenVertexArrays(1, &_quad); // generate array - glBindVertexArray(_quad); // bind array - glGenBuffers(1, &_vertexPositionBuffer); // generate buffer - glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer - glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(0)); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); + glGenVertexArrays(1, &_quad); // generate array + glGenBuffers(1, &_vertexPositionBuffer); // generate buffer + createPlane(); // Plane program _shader = ghoul::opengl::ProgramObject::Build("Plane", @@ -152,8 +143,7 @@ bool RenderablePlane::deinitialize() { _quad = 0; glDeleteBuffers(1, &_vertexPositionBuffer); _vertexPositionBuffer = 0; - if(_texture) - delete _texture; + delete _texture; delete _shader; return true; } @@ -186,6 +176,14 @@ void RenderablePlane::update(const UpdateData& data) { _shader->rebuildFromFile(); _programIsDirty = false; } + + if (_planeIsDirty) + createPlane(); + + if (_textureIsDirty) { + loadTexture(); + _textureIsDirty = false; + } } void RenderablePlane::loadTexture() { @@ -203,8 +201,37 @@ void RenderablePlane::loadTexture() { if (_texture) delete _texture; _texture = texture; + + delete _colorTextureFile; + _colorTextureFile = new ghoul::filesystem::File(_texturePath); + _colorTextureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; }); } } } +void RenderablePlane::createPlane() { + // ============================ + // GEOMETRY (quad) + // ============================ + const GLfloat size = _size.value()[0]; + const GLfloat w = _size.value()[1]; + const GLfloat vertex_data[] = { // square of two triangles (sigh) + // x y z w s t + -size, -size, 0.0f, w, 0, 1, + size, size, 0.0f, w, 1, 0, + -size, size, 0.0f, w, 0, 0, + -size, -size, 0.0f, w, 0, 1, + size, -size, 0.0f, w, 1, 1, + size, size, 0.0f, w, 1, 0, + }; + + glBindVertexArray(_quad); // bind array + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer + glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(0)); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); +} + } // namespace openspace