Coding style fixes

This commit is contained in:
Alexander Bock
2019-12-16 11:27:53 +01:00
parent d6bdc2519e
commit fdfad19476
11 changed files with 1034 additions and 1078 deletions

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* 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 *

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* 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 *

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* 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 *
@@ -44,4 +44,4 @@ void main() {
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
gl_Position = positionClipSpaceZNorm;
}
}

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* 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 *

View File

@@ -46,6 +46,6 @@ const vec2 texData[6] = vec2[] (
);
void main() {
texCoord = texData[ gl_VertexID ];
gl_Position = vec4(posData[ gl_VertexID ], 1.0);
}
texCoord = texData[gl_VertexID];
gl_Position = vec4(posData[gl_VertexID], 1.0);
}

View File

@@ -956,7 +956,9 @@ const glm::dmat4& RenderableGlobe::modelTransform() const {
//////////////////////////////////////////////////////////////////////////////////////////
void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&,
const ShadowComponent::ShadowMapData& shadowData, const bool renderGeomOnly) {
const ShadowComponent::ShadowMapData& shadowData,
bool renderGeomOnly)
{
if (_shadersNeedRecompilation) {
recompileShaders();
}
@@ -1256,7 +1258,9 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&,
}
void RenderableGlobe::renderChunkGlobally(const Chunk& chunk, const RenderData& data,
const ShadowComponent::ShadowMapData& shadowData, const bool renderGeomOnly) {
const ShadowComponent::ShadowMapData& shadowData,
bool renderGeomOnly)
{
//PerfMeasure("globally");
const TileIndex& tileIndex = chunk.tileIndex;
ghoul::opengl::ProgramObject& program = *_globalRenderer.program;

View File

@@ -189,8 +189,7 @@ private:
float getHeight(const glm::dvec3& position) const;
void renderChunks(const RenderData& data, RendererTasks& rendererTask,
const ShadowComponent::ShadowMapData& shadowData = {},
const bool renderGeomOnly = false
const ShadowComponent::ShadowMapData& shadowData = {}, bool renderGeomOnly = false
);
/**
@@ -202,8 +201,7 @@ private:
* tile will lead to jagging. We only render global chunks for lower chunk levels.
*/
void renderChunkGlobally(const Chunk& chunk, const RenderData& data,
const ShadowComponent::ShadowMapData& shadowData = {},
const bool renderGeomOnly = false
const ShadowComponent::ShadowMapData& shadowData = {}, bool renderGeomOnly = false
);
/**
@@ -218,8 +216,7 @@ private:
* chunks for higher chunk levels.
*/
void renderChunkLocally(const Chunk& chunk, const RenderData& data,
const ShadowComponent::ShadowMapData& shadowData = {},
const bool renderGeomOnly = false
const ShadowComponent::ShadowMapData& shadowData = {}, bool renderGeomOnly = false
);
void debugRenderChunk(const Chunk& chunk, const glm::dmat4& mvp,

View File

@@ -1,56 +1,49 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* 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. *
****************************************************************************************/
* *
* 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/globebrowsing/src/ringscomponent.h>
#include <modules/globebrowsing/globebrowsingmodule.h>
#include <modules/globebrowsing/src/renderableglobe.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/util/updatestructures.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/font/fontmanager.h>
#include <ghoul/font/fontrenderer.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/io/texture/texturereader.h>
#include <fstream>
#include <cstdlib>
#include <locale>
@@ -120,371 +113,370 @@ namespace {
namespace openspace {
documentation::Documentation RingsComponent::Documentation() {
using namespace documentation;
return {
"Rings Component",
"globebrowsing_rings_component",
documentation::Documentation RingsComponent::Documentation() {
using namespace documentation;
return {
"Rings Component",
"globebrowsing_rings_component",
{
{
{
TextureInfo.identifier,
new StringVerifier,
Optional::Yes,
TextureInfo.description
},
{
SizeInfo.identifier,
new DoubleVerifier,
Optional::Yes,
SizeInfo.description
},
{
OffsetInfo.identifier,
new DoubleVector2Verifier,
Optional::Yes,
OffsetInfo.description
},
{
NightFactorInfo.identifier,
new DoubleVerifier,
Optional::Yes,
NightFactorInfo.description
},
{
TransparencyInfo.identifier,
new DoubleVerifier,
Optional::Yes,
TransparencyInfo.description
},
{
ZFightingPercentageInfo.identifier,
new DoubleVerifier,
Optional::Yes,
ZFightingPercentageInfo.description
},
{
NumberShadowSamplesInfo.identifier,
new IntVerifier,
Optional::Yes,
NumberShadowSamplesInfo.description
}
TextureInfo.identifier,
new StringVerifier,
Optional::Yes,
TextureInfo.description
},
{
SizeInfo.identifier,
new DoubleVerifier,
Optional::Yes,
SizeInfo.description
},
{
OffsetInfo.identifier,
new DoubleVector2Verifier,
Optional::Yes,
OffsetInfo.description
},
{
NightFactorInfo.identifier,
new DoubleVerifier,
Optional::Yes,
NightFactorInfo.description
},
{
TransparencyInfo.identifier,
new DoubleVerifier,
Optional::Yes,
TransparencyInfo.description
},
{
ZFightingPercentageInfo.identifier,
new DoubleVerifier,
Optional::Yes,
ZFightingPercentageInfo.description
},
{
NumberShadowSamplesInfo.identifier,
new IntVerifier,
Optional::Yes,
NumberShadowSamplesInfo.description
}
};
}
}
};
}
RingsComponent::RingsComponent(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner({ "Rings" })
, _texturePath(TextureInfo)
, _size(SizeInfo, 1.f, 0.f, 1e25f)
, _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f))
, _nightFactor(NightFactorInfo, 0.33f, 0.f, 1.f)
, _transparency(TransparencyInfo, 0.15f, 0.f, 1.f)
, _enabled({ "Enabled", "Enabled", "Enable/Disable Rings" }, true)
, _zFightingPercentage(ZFightingPercentageInfo, 0.995f, 0.000001f, 1.f)
, _nShadowSamples(NumberShadowSamplesInfo, 2, 1, 20)
, _ringsDictionary(dictionary)
{
using ghoul::filesystem::File;
RingsComponent::RingsComponent(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner({ "Rings" })
, _texturePath(TextureInfo)
, _size(SizeInfo, 1.f, 0.f, 1e25f)
, _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f))
, _nightFactor(NightFactorInfo, 0.33f, 0.f, 1.f)
, _transparency(TransparencyInfo, 0.15f, 0.f, 1.f)
, _enabled({ "Enabled", "Enabled", "Enable/Disable Rings" }, true)
, _zFightingPercentage(ZFightingPercentageInfo, 0.995f, 0.000001f, 1.f)
, _nShadowSamples(NumberShadowSamplesInfo, 2, 1, 20)
, _ringsDictionary(dictionary)
{
using ghoul::filesystem::File;
if (dictionary.hasKey("Rings")) {
dictionary.getValue("Rings", _ringsDictionary);
}
if (dictionary.hasKey("Rings")) {
// @TODO (abock, 2019-12-16) It would be better to not store the dictionary long
// term and rather extract the values directly here. This would require a bit of
// a rewrite in the RenderableGlobe class to not create the RingsComponent in the
// class-initializer list though
dictionary.getValue("Rings", _ringsDictionary);
}
documentation::testSpecificationAndThrow(
Documentation(),
_ringsDictionary,
"RingsComponent"
documentation::testSpecificationAndThrow(
Documentation(),
_ringsDictionary,
"RingsComponent"
);
}
void RingsComponent::initialize() {
using ghoul::filesystem::File;
addProperty(_enabled);
_size = static_cast<float>(_ringsDictionary.value<double>(SizeInfo.identifier));
//setBoundingSphere(_size);
_size.onChange([&]() { _planeIsDirty = true; });
addProperty(_size);
_texturePath = absPath(
_ringsDictionary.value<std::string>(TextureInfo.identifier)
);
_textureFile = std::make_unique<File>(_texturePath);
if (_ringsDictionary.hasKeyAndValue<glm::vec2>(OffsetInfo.identifier)) {
_offset = _ringsDictionary.value<glm::vec2>(OffsetInfo.identifier);
}
addProperty(_offset);
_texturePath.onChange([&]() { loadTexture(); });
addProperty(_texturePath);
_textureFile->setCallback([&](const File&) { _textureIsDirty = true; });
if (_ringsDictionary.hasKeyAndValue<double>(NightFactorInfo.identifier)) {
_nightFactor = static_cast<float>(
_ringsDictionary.value<double>(NightFactorInfo.identifier)
);
}
addProperty(_nightFactor);
if (_ringsDictionary.hasKeyAndValue<double>(TransparencyInfo.identifier)) {
_transparency = static_cast<float>(
_ringsDictionary.value<double>(TransparencyInfo.identifier)
);
}
void RingsComponent::initialize()
{
using ghoul::filesystem::File;
addProperty(_enabled);
_size = static_cast<float>(_ringsDictionary.value<double>(SizeInfo.identifier));
//setBoundingSphere(_size);
_size.onChange([&]() { _planeIsDirty = true; });
addProperty(_size);
_texturePath = absPath(_ringsDictionary.value<std::string>(TextureInfo.identifier));
_textureFile = std::make_unique<File>(_texturePath);
if (_ringsDictionary.hasKeyAndValue<glm::vec2>(OffsetInfo.identifier)) {
_offset = _ringsDictionary.value<glm::vec2>(OffsetInfo.identifier);
}
addProperty(_offset);
_texturePath.onChange([&]() { loadTexture(); });
addProperty(_texturePath);
_textureFile->setCallback([&](const File&) { _textureIsDirty = true; });
if (_ringsDictionary.hasKeyAndValue<double>(NightFactorInfo.identifier)) {
_nightFactor = static_cast<float>(
_ringsDictionary.value<double>(NightFactorInfo.identifier)
);
}
addProperty(_nightFactor);
if (_ringsDictionary.hasKeyAndValue<double>(TransparencyInfo.identifier)) {
_transparency = static_cast<float>(
_ringsDictionary.value<double>(TransparencyInfo.identifier)
);
}
// Shadow Mapping Quality Controls
if (_ringsDictionary.hasKey(ZFightingPercentageInfo.identifier)) {
_zFightingPercentage = _ringsDictionary.value<float>(
ZFightingPercentageInfo.identifier
);
}
addProperty(_zFightingPercentage);
if (_ringsDictionary.hasKey(NumberShadowSamplesInfo.identifier)) {
_nShadowSamples = _ringsDictionary.value<int>(
NumberShadowSamplesInfo.identifier
);
}
addProperty(_nShadowSamples);
addProperty(_transparency);
// Shadow Mapping Quality Controls
if (_ringsDictionary.hasKey(ZFightingPercentageInfo.identifier)) {
_zFightingPercentage = _ringsDictionary.value<float>(
ZFightingPercentageInfo.identifier
);
}
addProperty(_zFightingPercentage);
bool RingsComponent::isReady() const {
return (_shader || _geometryOnlyShader) && _texture;
if (_ringsDictionary.hasKey(NumberShadowSamplesInfo.identifier)) {
_nShadowSamples = _ringsDictionary.value<int>(NumberShadowSamplesInfo.identifier);
}
addProperty(_nShadowSamples);
void RingsComponent::initializeGL() {
_shader = global::renderEngine.buildRenderProgram(
"RingsProgram",
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_vs.glsl"),
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_fs.glsl")
addProperty(_transparency);
}
bool RingsComponent::isReady() const {
return (_shader || _geometryOnlyShader) && _texture;
}
void RingsComponent::initializeGL() {
_shader = global::renderEngine.buildRenderProgram(
"RingsProgram",
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_vs.glsl"),
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_fs.glsl")
);
_geometryOnlyShader = global::renderEngine.buildRenderProgram(
"RingsGeomOnlyProgram",
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_geom_vs.glsl"),
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_geom_fs.glsl")
);
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
ghoul::opengl::updateUniformLocations(
*_geometryOnlyShader,
_geomUniformCache,
GeomUniformNames
);
glGenVertexArrays(1, &_quad);
glGenBuffers(1, &_vertexPositionBuffer);
createPlane();
loadTexture();
}
void RingsComponent::deinitializeGL() {
glDeleteVertexArrays(1, &_quad);
_quad = 0;
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
_textureFile = nullptr;
_texture = nullptr;
global::renderEngine.removeRenderProgram(_shader.get());
_shader = nullptr;
global::renderEngine.removeRenderProgram(_geometryOnlyShader.get());
_geometryOnlyShader = nullptr;
}
void RingsComponent::draw(const RenderData& data,
const RingsComponent::RenderPass renderPass,
const ShadowComponent::ShadowMapData& shadowData)
{
if (renderPass == GeometryAndShading) {
_shader->activate();
}
else if (renderPass == GeometryOnly) {
_geometryOnlyShader->activate();
}
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 modelViewProjectionTransform =
glm::dmat4(data.camera.projectionMatrix()) * data.camera.combinedViewMatrix()
* modelTransform;
ghoul::opengl::TextureUnit ringTextureUnit;
if (renderPass == GeometryAndShading) {
_shader->setUniform(
_uniformCache.modelViewProjectionMatrix,
modelViewProjectionTransform
);
_shader->setUniform(_uniformCache.textureOffset, _offset);
_shader->setUniform(_uniformCache.transparency, _transparency);
_shader->setUniform(_uniformCache.nightFactor, _nightFactor);
_shader->setUniform(_uniformCache.sunPosition, _sunPosition);
_shader->setUniform(_uniformCache.nShadowSamples, _nShadowSamples);
_shader->setUniform(_uniformCache.zFightingPercentage, _zFightingPercentage);
ringTextureUnit.activate();
_texture->bind();
_shader->setUniform(_uniformCache.ringTexture, ringTextureUnit);
// Adding the model transformation to the final shadow matrix so we have a
// complete transformation from the model coordinates to the clip space of
// the light position.
_shader->setUniform(
_uniformCache.shadowMatrix,
shadowData.shadowMatrix * modelTransform
);
_geometryOnlyShader = global::renderEngine.buildRenderProgram(
"RingsGeomOnlyProgram",
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_geom_vs.glsl"),
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_geom_fs.glsl")
);
ghoul::opengl::TextureUnit shadowMapUnit;
shadowMapUnit.activate();
glBindTexture(GL_TEXTURE_2D, shadowData.shadowDepthTexture);
_shader->setUniform(_uniformCache.shadowMapTexture, shadowMapUnit);
}
else if (renderPass == GeometryOnly) {
_geometryOnlyShader->setUniform(
_geomUniformCache.modelViewProjectionMatrix,
modelViewProjectionTransform
);
_geometryOnlyShader->setUniform(_geomUniformCache.textureOffset, _offset);
ringTextureUnit.activate();
_texture->bind();
_shader->setUniform(_geomUniformCache.ringTexture, ringTextureUnit);
}
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_CULL_FACE);
if (renderPass == GeometryAndShading) {
_shader->deactivate();
}
else if (renderPass == GeometryOnly) {
_geometryOnlyShader->deactivate();
}
}
void RingsComponent::update(const UpdateData& data) {
if (_shader->isDirty()) {
_shader->rebuildFromFile();
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
}
if (_geometryOnlyShader->isDirty()) {
_geometryOnlyShader->rebuildFromFile();
ghoul::opengl::updateUniformLocations(
*_geometryOnlyShader,
_geomUniformCache,
GeomUniformNames
);
}
glGenVertexArrays(1, &_quad);
glGenBuffers(1, &_vertexPositionBuffer);
if (_planeIsDirty) {
createPlane();
_planeIsDirty = false;
}
if (_textureIsDirty) {
loadTexture();
_textureIsDirty = false;
}
void RingsComponent::deinitializeGL() {
glDeleteVertexArrays(1, &_quad);
_quad = 0;
_sunPosition = glm::normalize(
global::renderEngine.scene()->sceneGraphNode("Sun")->worldPosition() -
data.modelTransform.translation
);
}
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
_textureFile = nullptr;
_texture = nullptr;
global::renderEngine.removeRenderProgram(_shader.get());
_shader = nullptr;
global::renderEngine.removeRenderProgram(_geometryOnlyShader.get());
_geometryOnlyShader = nullptr;
}
void RingsComponent::draw(
const RenderData& data,
const RingsComponent::RenderPass renderPass,
const ShadowComponent::ShadowMapData& shadowData
) {
if (renderPass == GeometryAndShading) {
_shader->activate();
}
else if (renderPass == GeometryOnly) {
_geometryOnlyShader->activate();
}
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 modelViewProjectionTransform =
glm::dmat4(data.camera.projectionMatrix()) * data.camera.combinedViewMatrix()
* modelTransform;
ghoul::opengl::TextureUnit ringTextureUnit;
if (renderPass == GeometryAndShading) {
_shader->setUniform(
_uniformCache.modelViewProjectionMatrix,
modelViewProjectionTransform
);
_shader->setUniform(_uniformCache.textureOffset, _offset);
_shader->setUniform(_uniformCache.transparency, _transparency);
_shader->setUniform(_uniformCache.nightFactor, _nightFactor);
_shader->setUniform(_uniformCache.sunPosition, _sunPosition);
_shader->setUniform(_uniformCache.nShadowSamples, _nShadowSamples);
_shader->setUniform(_uniformCache.zFightingPercentage, _zFightingPercentage);
ringTextureUnit.activate();
_texture->bind();
_shader->setUniform(_uniformCache.ringTexture, ringTextureUnit);
// Adding the model transformation to the final shadow matrix so we have a
// complete transformation from the model coordinates to the clip space of
// the light position.
_shader->setUniform(
_uniformCache.shadowMatrix,
shadowData.shadowMatrix * modelTransform
);
ghoul::opengl::TextureUnit shadowMapUnit;
shadowMapUnit.activate();
glBindTexture(GL_TEXTURE_2D, shadowData.shadowDepthTexture);
_shader->setUniform(_uniformCache.shadowMapTexture, shadowMapUnit);
}
else if (renderPass == GeometryOnly) {
_geometryOnlyShader->setUniform(
_geomUniformCache.modelViewProjectionMatrix,
modelViewProjectionTransform
);
_geometryOnlyShader->setUniform(
_geomUniformCache.textureOffset,
_offset
);
ringTextureUnit.activate();
_texture->bind();
_shader->setUniform(_geomUniformCache.ringTexture, ringTextureUnit);
}
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_CULL_FACE);
if (renderPass == GeometryAndShading) {
_shader->deactivate();
}
else if (renderPass == GeometryOnly) {
_geometryOnlyShader->deactivate();
}
}
void RingsComponent::update(const UpdateData& data) {
if (_shader->isDirty()) {
_shader->rebuildFromFile();
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
}
if (_geometryOnlyShader->isDirty()) {
_geometryOnlyShader->rebuildFromFile();
ghoul::opengl::updateUniformLocations(
*_geometryOnlyShader,
_geomUniformCache,
GeomUniformNames
);
}
if (_planeIsDirty) {
createPlane();
_planeIsDirty = false;
}
if (_textureIsDirty) {
loadTexture();
_textureIsDirty = false;
}
_sunPosition = glm::normalize(
global::renderEngine.scene()->sceneGraphNode("Sun")->worldPosition() -
data.modelTransform.translation
void RingsComponent::loadTexture() {
if (!_texturePath.value().empty()) {
using namespace ghoul::io;
using namespace ghoul::opengl;
std::unique_ptr<Texture> texture = TextureReader::ref().loadTexture(
absPath(_texturePath)
);
}
void RingsComponent::loadTexture() {
if (!_texturePath.value().empty()) {
using namespace ghoul::io;
using namespace ghoul::opengl;
std::unique_ptr<Texture> texture = TextureReader::ref().loadTexture(
absPath(_texturePath)
if (texture) {
LDEBUGC(
"RingsComponent",
fmt::format("Loaded texture from '{}'", absPath(_texturePath))
);
_texture = std::move(texture);
if (texture) {
LDEBUGC(
"RingsComponent",
fmt::format("Loaded texture from '{}'", absPath(_texturePath))
);
_texture = std::move(texture);
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
}
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
}
}
}
void RingsComponent::createPlane() {
const GLfloat size = _size;
void RingsComponent::createPlane() {
const GLfloat size = _size;
struct VertexData {
GLfloat x;
GLfloat y;
GLfloat s;
GLfloat t;
};
struct VertexData {
GLfloat x;
GLfloat y;
GLfloat s;
GLfloat t;
};
VertexData data[] = {
{ -size, -size, 0.f, 0.f },
{ size, size, 1.f, 1.f },
{ -size, size, 0.f, 1.f },
{ -size, -size, 0.f, 0.f },
{ size, -size, 1.f, 0.f },
{ size, size, 1.f, 1.f },
};
VertexData data[] = {
{ -size, -size, 0.f, 0.f },
{ size, size, 1.f, 1.f },
{ -size, size, 0.f, 1.f },
{ -size, -size, 0.f, 0.f },
{ size, -size, 1.f, 0.f },
{ size, size, 1.f, 1.f },
};
glBindVertexArray(_quad);
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(
0,
2,
GL_FLOAT,
GL_FALSE,
sizeof(VertexData),
nullptr
);
glEnableVertexAttribArray(1);
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(VertexData),
reinterpret_cast<void*>(offsetof(VertexData, s)) // NOLINT
);
}
glBindVertexArray(_quad);
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(
0,
2,
GL_FLOAT,
GL_FALSE,
sizeof(VertexData),
nullptr
);
glEnableVertexAttribArray(1);
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(VertexData),
reinterpret_cast<void*>(offsetof(VertexData, s)) // NOLINT
);
}
bool RingsComponent::isEnabled() const {
return _enabled;
}
bool RingsComponent::isEnabled() const {
return _enabled;
}
} // namespace openspace

View File

@@ -1,26 +1,26 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* 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. *
****************************************************************************************/
* *
* 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_GLOBEBROWSING___RINGSCOMPONENT___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___RINGSCOMPONENT___H__
@@ -28,14 +28,12 @@
#include <openspace/properties/propertyowner.h>
#include <modules/globebrowsing/src/shadowcomponent.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/vector/vec2property.h>
#include <openspace/properties/vector/vec4property.h>
#include <openspace/properties/stringproperty.h>
#include <ghoul/glm.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/uniformcache.h>

File diff suppressed because it is too large Load Diff

View File

@@ -1,46 +1,43 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* 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. *
****************************************************************************************/
* *
* 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_GLOBEBROWSING___SHADOWCOMPONENT___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___SHADOWCOMPONENT___H__
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/vector/vec2property.h>
#include <openspace/properties/vector/vec4property.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <openspace/util/camera.h>
#include <ghoul/glm.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/uniformcache.h>
#include <string>
#include <sstream>
@@ -58,111 +55,109 @@ namespace openspace {
struct RenderData;
struct UpdateData;
namespace documentation { struct Documentation; }
namespace documentation { struct Documentation; }
static const GLfloat ShadowBorder[] = { 1.f, 1.f, 1.f, 1.f };
static const GLfloat ShadowBorder[] = { 1.f, 1.f, 1.f, 1.f };
class ShadowComponent : public properties::PropertyOwner {
public:
struct ShadowMapData {
glm::dmat4 shadowMatrix;
GLuint shadowDepthTexture;
};
public:
ShadowComponent(const ghoul::Dictionary& dictionary);
void initialize();
void initializeGL();
void deinitializeGL();
//bool deinitialize();
bool isReady() const;
RenderData begin(const RenderData& data);
void end();
void update(const UpdateData& data);
static documentation::Documentation Documentation();
bool isEnabled() const;
ShadowComponent::ShadowMapData shadowMapData() const;
void setViewDepthMap(bool enable);
private:
void createDepthTexture();
void createShadowFBO();
void updateDepthTexture();
// Debug
void saveDepthBuffer();
void checkGLError(const std::string & where) const;
private:
ShadowMapData _shadowData;
// Texture coords in [0, 1], while clip coords in [-1, 1]
const glm::dmat4 _toTextureCoordsMatrix = glm::dmat4(
glm::dvec4(0.5, 0.0, 0.0, 0.0),
glm::dvec4(0.0, 0.5, 0.0, 0.0),
glm::dvec4(0.0, 0.0, 1.0, 0.0),
glm::dvec4(0.5, 0.5, 0.0, 1.0)
);
// DEBUG
properties::TriggerProperty _saveDepthTexture;
properties::IntProperty _distanceFraction;
properties::BoolProperty _enabled;
ghoul::Dictionary _shadowMapDictionary;
int _shadowDepthTextureHeight;
int _shadowDepthTextureWidth;
bool _dynamicDepthTextureRes = true;
GLuint _shadowDepthTexture;
GLuint _positionInLightSpaceTexture;
GLuint _shadowFBO;
GLuint _firstPassSubroutine;
GLuint _secondPassSubroutine;
GLint _defaultFBO;
GLint _mViewport[4];
GLboolean _faceCulling;
GLboolean _polygonOffSet;
GLboolean _depthIsEnabled;
GLboolean _blendIsEnabled = false;
GLenum _faceToCull;
GLenum _depthFunction;
GLfloat _polygonOffSetFactor;
GLfloat _polygonOffSetUnits;
GLfloat _colorClearValue[4];
GLfloat _depthClearValue;
glm::vec3 _sunPosition;
glm::dmat4 _shadowMatrix;
glm::dvec3 _cameraPos;
glm::dvec3 _cameraFocus;
glm::dquat _cameraRotation;
std::stringstream _serializedCamera;
std::unique_ptr<Camera> _lightCamera;
// DEBUG
bool _executeDepthTextureSave = false;
bool _viewDepthMap = false;
std::unique_ptr<ghoul::opengl::ProgramObject> _renderDMProgram;
GLuint _quadVAO = 0u;
class ShadowComponent : public properties::PropertyOwner {
public:
struct ShadowMapData {
glm::dmat4 shadowMatrix;
GLuint shadowDepthTexture;
};
ShadowComponent(const ghoul::Dictionary& dictionary);
void initialize();
void initializeGL();
void deinitializeGL();
//bool deinitialize();
bool isReady() const;
RenderData begin(const RenderData& data);
void end();
void update(const UpdateData& data);
static documentation::Documentation Documentation();
bool isEnabled() const;
ShadowComponent::ShadowMapData shadowMapData() const;
void setViewDepthMap(bool enable);
private:
void createDepthTexture();
void createShadowFBO();
void updateDepthTexture();
// Debug
void saveDepthBuffer();
void checkGLError(const std::string & where) const;
ShadowMapData _shadowData;
// Texture coords in [0, 1], while clip coords in [-1, 1]
const glm::dmat4 _toTextureCoordsMatrix = glm::dmat4(
glm::dvec4(0.5, 0.0, 0.0, 0.0),
glm::dvec4(0.0, 0.5, 0.0, 0.0),
glm::dvec4(0.0, 0.0, 1.0, 0.0),
glm::dvec4(0.5, 0.5, 0.0, 1.0)
);
// DEBUG
properties::TriggerProperty _saveDepthTexture;
properties::IntProperty _distanceFraction;
properties::BoolProperty _enabled;
ghoul::Dictionary _shadowMapDictionary;
int _shadowDepthTextureHeight = 4096;
int _shadowDepthTextureWidth = 4096;
bool _dynamicDepthTextureRes = true;
// All of these initializations should probably be 0 since they are GLuints?
GLuint _shadowDepthTexture = -1;
GLuint _positionInLightSpaceTexture = -1;
GLuint _shadowFBO = -1;
GLuint _firstPassSubroutine = -1;
GLuint _secondPassSubroutine = 1;
GLint _defaultFBO = -1;
GLint _mViewport[4];
GLboolean _faceCulling;
GLboolean _polygonOffSet;
GLboolean _depthIsEnabled;
GLboolean _blendIsEnabled = false;
GLenum _faceToCull;
GLenum _depthFunction;
GLfloat _polygonOffSetFactor;
GLfloat _polygonOffSetUnits;
GLfloat _colorClearValue[4];
GLfloat _depthClearValue;
glm::vec3 _sunPosition;
glm::dmat4 _shadowMatrix = glm::dmat4(1.0);
glm::dvec3 _cameraPos = glm::dvec3(0.0);
glm::dvec3 _cameraFocus;
glm::dquat _cameraRotation;
std::stringstream _serializedCamera;
std::unique_ptr<Camera> _lightCamera;
// DEBUG
bool _executeDepthTextureSave = false;
bool _viewDepthMap = false;
std::unique_ptr<ghoul::opengl::ProgramObject> _renderDMProgram;
GLuint _quadVAO = 0u;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___SHADOWCOMPONENT___H__