Merge branch 'master' into feature/multitexturing

* Resolve conflicts
This commit is contained in:
Malin Ejdbo
2021-02-01 11:57:31 +01:00
1794 changed files with 120988 additions and 19808 deletions

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* Copyright (c) 2014-2021 *
* *
* 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 *
@@ -33,12 +33,12 @@
#include <openspace/util/updatestructures.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/lightsource.h>
#include <ghoul/io/model/modelgeometry.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/invariants.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/textureunit.h>
@@ -47,11 +47,25 @@ namespace {
constexpr const char* KeyGeomModelFile = "GeometryFile";
constexpr const char* KeyForceRenderInvisible = "ForceRenderInvisible";
constexpr const std::array<const char*, 12> UniformNames = {
constexpr const int DefaultBlending = 0;
constexpr const int AdditiveBlending = 1;
constexpr const int PointsAndLinesBlending = 2;
constexpr const int PolygonBlending = 3;
constexpr const int ColorAddingBlending = 4;
std::map<std::string, int> BlendingMapping = {
{ "Default", DefaultBlending },
{ "Additive", AdditiveBlending },
{ "Points and Lines", PointsAndLinesBlending },
{ "Polygon", PolygonBlending },
{ "Color Adding", ColorAddingBlending }
};
constexpr const std::array<const char*, 13> UniformNames = {
"opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities",
"modelViewTransform", "crippedModelViewTransform", "projectionTransform",
"performShading", "texture1", "ambientIntensity", "diffuseIntensity",
"specularIntensity"
"modelViewTransform", "normalTransform", "projectionTransform",
"performShading", "texture1", "ambientIntensity", "diffuseIntensity",
"specularIntensity", "opacityBlending"
};
constexpr openspace::properties::Property::PropertyInfo AmbientIntensityInfo = {
@@ -103,6 +117,24 @@ namespace {
"Light Sources",
"A list of light sources that this model should accept light from."
};
constexpr openspace::properties::Property::PropertyInfo DisableDepthTestInfo = {
"DisableDepthTest",
"Disable Depth Test",
"Disable Depth Testing for the Model."
};
constexpr openspace::properties::Property::PropertyInfo BlendingOptionInfo = {
"BledingOption",
"Blending Options",
"Debug option for blending colors."
};
constexpr openspace::properties::Property::PropertyInfo EnableOpacityBlendingInfo = {
"EnableOpacityBlending",
"Enable Opacity Blending",
"Enable Opacity Blending."
};
} // namespace
namespace openspace {
@@ -182,7 +214,25 @@ documentation::Documentation RenderableModel::Documentation() {
}),
Optional::Yes,
LightSourcesInfo.description
}
},
{
DisableDepthTestInfo.identifier,
new BoolVerifier,
Optional::Yes,
DisableDepthTestInfo.description
},
{
BlendingOptionInfo.identifier,
new StringVerifier,
Optional::Yes,
BlendingOptionInfo.description
},
{
EnableOpacityBlendingInfo.identifier,
new BoolVerifier,
Optional::Yes,
EnableOpacityBlendingInfo.description
},
}
};
}
@@ -201,6 +251,12 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
glm::dmat3(1.0)
)
, _rotationVec(RotationVecInfo, glm::dvec3(0.0), glm::dvec3(0.0), glm::dvec3(360.0))
, _enableOpacityBlending(EnableOpacityBlendingInfo, false)
, _disableDepthTest(DisableDepthTestInfo, false)
, _blendingFuncOption(
BlendingOptionInfo,
properties::OptionProperty::DisplayType::Dropdown
)
, _lightSourcePropertyOwner({ "LightSources", "Light Sources" })
{
documentation::testSpecificationAndThrow(
@@ -225,7 +281,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
if (dictionary.hasKey(KeyGeomModelFile)) {
std::string file;
if (dictionary.hasKeyAndValue<std::string>(KeyGeomModelFile)) {
if (dictionary.hasValue<std::string>(KeyGeomModelFile)) {
// Handle single file
file = absPath(dictionary.value<std::string>(KeyGeomModelFile));
_geometry = ghoul::io::ModelReader::ref().loadModel(
@@ -234,13 +290,13 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
_notifyInvisibleDropped
);
}
else if (dictionary.hasKeyAndValue<ghoul::Dictionary>(KeyGeomModelFile)) {
else if (dictionary.hasValue<ghoul::Dictionary>(KeyGeomModelFile)) {
ghoul::Dictionary fileDictionary = dictionary.value<ghoul::Dictionary>(
KeyGeomModelFile
);
std::vector<std::unique_ptr<ghoul::modelgeometry::ModelGeometry>> geometries;
for (std::string k : fileDictionary.keys()) {
for (std::string_view k : fileDictionary.keys()) {
// Handle each file
file = absPath(fileDictionary.value<std::string>(k));
geometries.push_back(ghoul::io::ModelReader::ref().loadModel(
@@ -281,19 +337,23 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
}
if (dictionary.hasKey(AmbientIntensityInfo.identifier)) {
_ambientIntensity = dictionary.value<float>(AmbientIntensityInfo.identifier);
_ambientIntensity = dictionary.value<double>(AmbientIntensityInfo.identifier);
}
if (dictionary.hasKey(DiffuseIntensityInfo.identifier)) {
_diffuseIntensity = dictionary.value<float>(DiffuseIntensityInfo.identifier);
_diffuseIntensity = dictionary.value<double>(DiffuseIntensityInfo.identifier);
}
if (dictionary.hasKey(SpecularIntensityInfo.identifier)) {
_specularIntensity = dictionary.value<float>(SpecularIntensityInfo.identifier);
_specularIntensity = dictionary.value<double>(SpecularIntensityInfo.identifier);
}
if (dictionary.hasKey(ShadingInfo.identifier)) {
_performShading = dictionary.value<bool>(ShadingInfo.identifier);
}
if (dictionary.hasKey(DisableDepthTestInfo.identifier)) {
_disableDepthTest = dictionary.value<bool>(DisableDepthTestInfo.identifier);
}
if (dictionary.hasKey(DisableFaceCullingInfo.identifier)) {
_disableFaceCulling = dictionary.value<bool>(DisableFaceCullingInfo.identifier);
}
@@ -302,7 +362,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
const ghoul::Dictionary& lsDictionary =
dictionary.value<ghoul::Dictionary>(LightSourcesInfo.identifier);
for (const std::string& k : lsDictionary.keys()) {
for (std::string_view k : lsDictionary.keys()) {
std::unique_ptr<LightSource> lightSource = LightSource::createFromDictionary(
lsDictionary.value<ghoul::Dictionary>(k)
);
@@ -311,14 +371,13 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
}
}
addPropertySubOwner(_lightSourcePropertyOwner);
addProperty(_ambientIntensity);
addProperty(_diffuseIntensity);
addProperty(_specularIntensity);
addProperty(_performShading);
addProperty(_disableFaceCulling);
addProperty(_disableDepthTest);
addProperty(_modelTransform);
addProperty(_rotationVec);
@@ -328,8 +387,31 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
if (dictionary.hasKey(RotationVecInfo.identifier)) {
_rotationVec = dictionary.value<glm::vec3>(RotationVecInfo.identifier);
_rotationVec = dictionary.value<glm::dvec3>(RotationVecInfo.identifier);
}
_blendingFuncOption.addOption(DefaultBlending, "Default");
_blendingFuncOption.addOption(AdditiveBlending, "Additive");
_blendingFuncOption.addOption(PointsAndLinesBlending, "Points and Lines");
_blendingFuncOption.addOption(PolygonBlending, "Polygon");
_blendingFuncOption.addOption(ColorAddingBlending, "Color Adding");
addProperty(_blendingFuncOption);
if (dictionary.hasKey(BlendingOptionInfo.identifier)) {
const std::string blendingOpt = dictionary.value<std::string>(
BlendingOptionInfo.identifier
);
_blendingFuncOption.set(BlendingMapping[blendingOpt]);
}
if (dictionary.hasKey(DisableDepthTestInfo.identifier)) {
_enableOpacityBlending = dictionary.value<bool>(
EnableOpacityBlendingInfo.identifier
);
}
addProperty(_enableOpacityBlending);
}
bool RenderableModel::isReady() const {
@@ -350,7 +432,7 @@ void RenderableModel::initializeGL() {
_program = BaseModule::ProgramObjectManager.request(
ProgramName,
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
return global::renderEngine.buildRenderProgram(
return global::renderEngine->buildRenderProgram(
ProgramName,
absPath("${MODULE_BASE}/shaders/model_vs.glsl"),
absPath("${MODULE_BASE}/shaders/model_fs.glsl")
@@ -372,7 +454,7 @@ void RenderableModel::deinitializeGL() {
BaseModule::ProgramObjectManager.release(
ProgramName,
[](ghoul::opengl::ProgramObject* p) {
global::renderEngine.removeRenderProgram(p);
global::renderEngine->removeRenderProgram(p);
}
);
_program = nullptr;
@@ -426,13 +508,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
glm::mat4(modelViewTransform)
);
glm::dmat4 crippedModelViewTransform = glm::transpose(glm::inverse(
glm::dmat4(glm::inverse(data.camera.sgctInternal.viewMatrix())) * modelViewTransform
));
glm::dmat4 normalTransform = glm::transpose(glm::inverse(modelViewTransform));
_program->setUniform(
_uniformCache.crippedModelViewTransform,
glm::mat4(crippedModelViewTransform)
_uniformCache.normalTransform,
glm::mat4(normalTransform)
);
_program->setUniform(
@@ -443,11 +523,35 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
_program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity);
_program->setUniform(_uniformCache.specularIntensity, _specularIntensity);
_program->setUniform(_uniformCache.performShading, _performShading);
_program->setUniform(_uniformCache.opacityBlending, _enableOpacityBlending);
if (_disableFaceCulling) {
glDisable(GL_CULL_FACE);
}
glEnablei(GL_BLEND, 0);
switch (_blendingFuncOption) {
case DefaultBlending:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
break;
case AdditiveBlending:
glBlendFunc(GL_ONE, GL_ONE);
break;
case PointsAndLinesBlending:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
break;
case PolygonBlending:
glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
break;
case ColorAddingBlending:
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
break;
};
if (_disableDepthTest) {
glDisable(GL_DEPTH_TEST);
}
ghoul::opengl::TextureUnit unit;
unit.activate();
_program->setUniform(_uniformCache.texture, unit);
@@ -457,6 +561,12 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
glEnable(GL_CULL_FACE);
}
global::renderEngine->openglStateCache().resetBlendState();
if (_disableDepthTest) {
glEnable(GL_DEPTH_TEST);
}
_program->deactivate();
}