Merge branch 'master' into feature/planetlabels

This commit is contained in:
Jonathas Costa
2019-12-08 14:51:39 -05:00
19 changed files with 761 additions and 32 deletions
+4
View File
@@ -43,6 +43,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecartesianaxes.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelabels.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablenodeline.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimagelocal.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimageonline.h
@@ -91,6 +92,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecartesianaxes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelabels.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablenodeline.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimagelocal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimageonline.cpp
@@ -126,6 +128,8 @@ set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/grid_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/line_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/line_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/model_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/model_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/plane_fs.glsl
+3
View File
@@ -40,6 +40,7 @@
#include <modules/base/rendering/renderablecartesianaxes.h>
#include <modules/base/rendering/renderablelabels.h>
#include <modules/base/rendering/renderablemodel.h>
#include <modules/base/rendering/renderablenodeline.h>
#include <modules/base/rendering/renderablesphere.h>
#include <modules/base/rendering/renderablesphericalgrid.h>
#include <modules/base/rendering/renderabletrailorbit.h>
@@ -125,6 +126,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) {
fRenderable->registerClass<RenderableCartesianAxes>("RenderableCartesianAxes");
fRenderable->registerClass<RenderableLabels>("RenderableLabels");
fRenderable->registerClass<RenderableModel>("RenderableModel");
fRenderable->registerClass<RenderableNodeLine>("RenderableNodeLine");
fRenderable->registerClass<RenderablePlaneImageLocal>("RenderablePlaneImageLocal");
fRenderable->registerClass<RenderablePlaneImageOnline>("RenderablePlaneImageOnline");
fRenderable->registerClass<RenderableSphere>("RenderableSphere");
@@ -193,6 +195,7 @@ std::vector<documentation::Documentation> BaseModule::documentations() const {
RenderableBoxGrid::Documentation(),
RenderableLabels::Documentation(),
RenderableModel::Documentation(),
RenderableNodeLine::Documentation(),
RenderablePlane::Documentation(),
RenderableSphere::Documentation(),
RenderableTrailOrbit::Documentation(),
@@ -0,0 +1,305 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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 <modules/base/rendering/renderablenodeline.h>
#include <modules/base/basemodule.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/translation.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/opengl/programobject.h>
namespace {
constexpr const char* ProgramName = "NodeLineProgram";
constexpr const char* Root = "Root";
constexpr openspace::properties::Property::PropertyInfo StartNodeInfo = {
"StartNode",
"Start Node",
"The identifier of the node the line starts from. "
};
constexpr openspace::properties::Property::PropertyInfo EndNodeInfo = {
"EndNode",
"End Node",
"The identifier of the node the line ends at. "
};
constexpr openspace::properties::Property::PropertyInfo LineColorInfo = {
"Color",
"Color",
"This value determines the RGB color for the line."
};
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
"LineWidth",
"Line Width",
"This value specifies the line width."
};
} // namespace
namespace openspace {
documentation::Documentation RenderableNodeLine::Documentation() {
using namespace documentation;
return {
"Renderable Node Line",
"base_renderable_renderablenodeline",
{
{
StartNodeInfo.identifier,
new StringVerifier,
Optional::No,
StartNodeInfo.description
},
{
EndNodeInfo.identifier,
new StringVerifier,
Optional::No,
EndNodeInfo.description
},
{
LineColorInfo.identifier,
new DoubleVector3Verifier,
Optional::Yes,
LineColorInfo.description
},
{
LineWidthInfo.identifier,
new DoubleVerifier,
Optional::Yes,
LineWidthInfo.description
}
}
};
}
RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lineColor(LineColorInfo, glm::vec3(1.f, 1.f, 1.f), glm::vec3(0.f), glm::vec3(1.f))
, _lineWidth(LineWidthInfo, 2.f, 1.f, 20.f)
, _start(StartNodeInfo, Root)
, _end(EndNodeInfo, Root)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"RenderableNodeLine"
);
_start = dictionary.value<std::string>(StartNodeInfo.identifier);
_end = dictionary.value<std::string>(EndNodeInfo.identifier);
if (dictionary.hasKey(LineColorInfo.identifier)) {
_lineColor = dictionary.value<glm::vec3>(LineColorInfo.identifier);
}
if (dictionary.hasKey(LineWidthInfo.identifier)) {
_lineWidth = static_cast<float>(dictionary.value<double>(LineWidthInfo.identifier));
}
addProperty(_start);
addProperty(_end);
addProperty(_lineColor);
addProperty(_lineWidth);
addProperty(_opacity);
}
void RenderableNodeLine::initializeGL() {
_program = BaseModule::ProgramObjectManager.request(
ProgramName,
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
return global::renderEngine.buildRenderProgram(
ProgramName,
absPath("${MODULE_BASE}/shaders/line_vs.glsl"),
absPath("${MODULE_BASE}/shaders/line_fs.glsl")
);
}
);
// Generate
glGenVertexArrays(1, &_vaoId);
glGenBuffers(1, &_vBufferId);
bindGL();
glVertexAttribPointer(_locVertex, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
glEnableVertexAttribArray(_locVertex);
unbindGL();
}
void RenderableNodeLine::deinitializeGL() {
glDeleteVertexArrays(1, &_vaoId);
_vaoId = 0;
glDeleteBuffers(1, &_vBufferId);
_vBufferId = 0;
BaseModule::ProgramObjectManager.release(
ProgramName,
[](ghoul::opengl::ProgramObject* p) {
global::renderEngine.removeRenderProgram(p);
}
);
_program = nullptr;
}
bool RenderableNodeLine::isReady() const {
bool ready = true;
ready &= (_program != nullptr);
return ready;
}
void RenderableNodeLine::unbindGL() {
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void RenderableNodeLine::bindGL()
{
glBindVertexArray(_vaoId);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferId);
}
void RenderableNodeLine::updateVertexData()
{
_vertexArray.clear();
// Update the positions of the nodes
_startPos = getCoordinatePosFromAnchorNode(global::renderEngine.scene()->sceneGraphNode(_start)->worldPosition());
_endPos = getCoordinatePosFromAnchorNode(global::renderEngine.scene()->sceneGraphNode(_end)->worldPosition());
_vertexArray.push_back(_startPos.x);
_vertexArray.push_back(_startPos.y);
_vertexArray.push_back(_startPos.z);
_vertexArray.push_back(_endPos.x);
_vertexArray.push_back(_endPos.y);
_vertexArray.push_back(_endPos.z);
_vertexArray;
bindGL();
glBufferData(
GL_ARRAY_BUFFER,
_vertexArray.size() * sizeof(float),
_vertexArray.data(),
GL_DYNAMIC_DRAW
);
//update vertex attributes
glVertexAttribPointer(_locVertex, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
unbindGL();
}
void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
updateVertexData();
_program->activate();
glm::dmat4 anchorTranslation(1.0);
// Update anchor node information, used to counter precision problems
if (global::navigationHandler.orbitalNavigator().anchorNode()) {
anchorTranslation = glm::translate(glm::dmat4(1.0), global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition());
}
const glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() *
modelTransform * anchorTranslation;
_program->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_program->setUniform("projectionTransform", data.camera.projectionMatrix());
_program->setUniform("color", glm::vec4(_lineColor.value(), _opacity));
// Save current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLenum blendEquationRGB, blendEquationAlpha, blendDestAlpha,
blendDestRGB, blendSrcAlpha, blendSrcRGB;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
// Change GL state:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnablei(GL_BLEND, 0);
glEnable(GL_LINE_SMOOTH);
glLineWidth(_lineWidth);
// Bind and draw
bindGL();
glDrawArrays(GL_LINES, 0, 2);
// Restore GL State
unbindGL();
_program->deactivate();
glLineWidth(currentLineWidth);
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
if (!isBlendEnabled) {
glDisablei(GL_BLEND, 0);
}
if (!isLineSmoothEnabled) {
glDisable(GL_LINE_SMOOTH);
}
}
/* Returns a position that is relative to the current
anchor node. This is a method to handle precision
problems that occur when approaching a line end point */
glm::dvec3 RenderableNodeLine::getCoordinatePosFromAnchorNode(glm::dvec3 worldPos) {
glm::dvec3 anchorNodePos(0);
if (global::navigationHandler.orbitalNavigator().anchorNode()) {
anchorNodePos = global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition();
}
glm::dvec3 diffPos = glm::dvec3(worldPos.x - anchorNodePos.x, worldPos.y - anchorNodePos.y,
worldPos.z - anchorNodePos.z);
return diffPos;
}
} // namespace openspace
@@ -0,0 +1,86 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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 __OPENSPACE_MODULE_BASE___RENDERABLENODELINE___H__
#define __OPENSPACE_MODULE_BASE___RENDERABLENODELINE___H__
#include <openspace/rendering/renderable.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/glm.h>
namespace ghoul::opengl { class ProgramObject; }
namespace openspace {
namespace documentation { struct Documentation; }
class Translation;
/**
* This is a class for a line that is drawn between two nodes in OpenSpace.
*/
class RenderableNodeLine : public Renderable {
public:
RenderableNodeLine(const ghoul::Dictionary& dictionary);
~RenderableNodeLine() = default;
static documentation::Documentation Documentation();
private:
void initializeGL() override;
void deinitializeGL() override;
bool isReady() const override;
void updateVertexData();
void render(const RenderData& data, RendererTasks& rendererTask) override;
void unbindGL();
void bindGL();
glm::dvec3 getCoordinatePosFromAnchorNode(glm::dvec3 worldPos);
ghoul::opengl::ProgramObject* _program;
/// The vertex attribute location for position
/// must correlate to layout location in vertex shader
const GLuint _locVertex = 0;
GLuint _vaoId = 0;
GLuint _vBufferId = 0;
std::vector<float> _vertexArray;
glm::dvec3 _startPos;
glm::dvec3 _endPos;
properties::StringProperty _start;
properties::StringProperty _end;
properties::Vec3Property _lineColor;
properties::FloatProperty _lineWidth;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_BASE___RENDERABLENODELINE___H__
+42
View File
@@ -0,0 +1,42 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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 "fragment.glsl"
#include "floatoperations.glsl"
in float vs_depth;
in vec4 vs_positionViewSpace;
uniform vec4 color;
Fragment getFragment() {
Fragment frag;
frag.color = color;
frag.depth = vs_depth;
frag.gPosition = vs_positionViewSpace;
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
return frag;
}
+43
View File
@@ -0,0 +1,43 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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. *
****************************************************************************************/
#version __CONTEXT__
layout(location = 0) in vec3 in_position;
out float vs_depth;
out vec4 vs_positionViewSpace;
uniform mat4 modelViewTransform;
uniform mat4 projectionTransform;
void main() {
vs_positionViewSpace = vec4(modelViewTransform * dvec4(in_position, 1));
vec4 positionScreenSpace = projectionTransform * vs_positionViewSpace;
vs_depth = positionScreenSpace.w;
gl_Position = positionScreenSpace;
// Set z to 0 to disable near and far plane, unique handling for perspective in space
gl_Position.z = 0.f;
}