From 1632c09af37829b3317c4b4a591b1e0ef0bfc8be Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Tue, 13 Nov 2018 14:09:14 +0100 Subject: [PATCH] Coordinate Axes * Add coordinate axes renderable * Add debug helper * Add example asset * Fix bug with dynamic loading of assets. (#763) --- .../assets/examples/debugcoordinateaxes.asset | 19 ++ data/assets/util/debug_helper.asset | 133 +++++++++ include/openspace/engine/openspaceengine.h | 2 +- modules/base/CMakeLists.txt | 6 + modules/base/basemodule.cpp | 2 + .../rendering/renderablecartesianaxes.cpp | 275 ++++++++++++++++++ .../base/rendering/renderablecartesianaxes.h | 75 +++++ modules/base/shaders/axes_fs.glsl | 49 ++++ modules/base/shaders/axes_vs.glsl | 46 +++ src/engine/openspaceengine.cpp | 5 +- src/scene/sceneinitializer.cpp | 48 +-- 11 files changed, 635 insertions(+), 25 deletions(-) create mode 100644 data/assets/examples/debugcoordinateaxes.asset create mode 100644 data/assets/util/debug_helper.asset create mode 100644 modules/base/rendering/renderablecartesianaxes.cpp create mode 100644 modules/base/rendering/renderablecartesianaxes.h create mode 100644 modules/base/shaders/axes_fs.glsl create mode 100644 modules/base/shaders/axes_vs.glsl diff --git a/data/assets/examples/debugcoordinateaxes.asset b/data/assets/examples/debugcoordinateaxes.asset new file mode 100644 index 0000000000..e975e1b526 --- /dev/null +++ b/data/assets/examples/debugcoordinateaxes.asset @@ -0,0 +1,19 @@ +local transforms = asset.require('scene/solarsystem/planets/earth/transforms') +local debugHelper = asset.require('util/debug_helper') + +local earthRadius = 6.371E6 + +debugHelper.registerCartesianAxes(asset, { + Parent = transforms.EarthBarycenter.Identifier, + Scale = earthRadius * 3.5 +}) + +debugHelper.registerCartesianAxes(asset, { + Parent = transforms.EarthInertial.Identifier, + Scale = earthRadius * 2.5 +}) + +debugHelper.registerCartesianAxes(asset, { + Parent = transforms.EarthIAU.Identifier, + Scale = earthRadius * 1.5 +}) diff --git a/data/assets/util/debug_helper.asset b/data/assets/util/debug_helper.asset new file mode 100644 index 0000000000..2a1175ee84 --- /dev/null +++ b/data/assets/util/debug_helper.asset @@ -0,0 +1,133 @@ +local identifierGeneratorFunction = function (suffix) + local nextIndex = 0 + return function (specification) + nextIndex = nextIndex + 1 + return specification.Identifier or + (specification.Parent .. suffix .. nextIndex) + end +end + +local generateGridIdentifier = identifierGeneratorFunction("Grid") + +local addGrid = function (specification) + local identifier = specification.Identifier or + generateGridIdentifier(specification) + + local name = specification.Name + local color = specification.Color + local parent = specification.Parent + local scale = specification.Scale + local position = specification.Position + local rotation = specification.Rotation + + local grid = { + Identifier = identifier, + Parent = parent, + Transform = { + Scale = { + Type = "StaticScale", + Scale = scale; + }, + Translation = { + Type = "StaticTranslation", + Position = position + }, + Rotation = { + Type = "StaticRotation", + Rotation = rotation + } + }, + Renderable = { + Type = "RenderableSphericalGrid", + Enabled = true, + LineWidth = 2.0, + GridColor = color + }, + GUI = { + Name = name, + Path = "/Other/Grids" + } + } + openspace.addSceneGraphNode(grid) + return identifier; +end + +local generateAxesIdentifier = identifierGeneratorFunction("Axes") + +local addCartesianAxes = function (specification) + local identifier = specification.Identifier or + generateAxesIdentifier(specification) + + local name = specification.Name or specification.Identifier + local parent = specification.Parent or "Root" + local scale = specification.Scale or 1.0 + local position = specification.Position or {0.0, 0.0, 0.0} + local rotation = specification.Rotation or {0.0, 0.0, 0.0} + + local axes = { + Identifier = identifier, + Parent = parent, + Transform = { + Scale = { + Type = "StaticScale", + Scale = scale; + }, + Translation = { + Type = "StaticTranslation", + Position = position + }, + Rotation = { + Type = "StaticRotation", + Rotation = rotation + } + }, + Renderable = { + Type = "RenderableCartesianAxes", + Enabled = true, + XColor = {1.0, 0.0, 0.0, 1.0}, + YColor = {0.0, 1.0, 0.0, 1.0}, + ZColor = {0.0, 0.0, 1.0, 1.0} + }, + GUI = { + Name = name, + Path = "/Other/Coordinate Systems" + } + } + openspace.addSceneGraphNode(axes) + return identifier; +end + + +local registerNode = function( + containerAsset, + nodeCreationFunction, + identifierGeneratorFunction, + specification +) + local identifier = specification.Identifier or + identifierGeneratorFunction(specification) + + specification.Identifier = identifier + + containerAsset.onInitialize(function () + nodeCreationFunction(specification) + end) + containerAsset.onDeinitialize(function () + openspace.removeSceneGraphNode(identifier) + end) +end + +local registerGrid = function(gridAsset, specification) + registerNode(gridAsset, addGrid, generateGridIdentifier, specification) +end + +local registerCartesianAxes = function(axesAsset, specification) + registerNode(axesAsset, addCartesianAxes, generateAxesIdentifier, specification) +end + +asset.export("addGrid", addGrid) +asset.export("registerGrid", registerGrid) + +asset.export("addCartesianAxes", addGrid) +asset.export("registerCartesianAxes", registerCartesianAxes) + diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 5fb860fff1..921a658c0c 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -88,7 +88,7 @@ public: // Guaranteed to return a valid pointer AssetManager& assetManager(); - LoadingScreen& loadingScreen(); + LoadingScreen* loadingScreen(); void writeSceneDocumentation(); void writeStaticDocumentation(); diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index ad38bfb017..117b53a7f7 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -39,6 +39,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/scenegraphlightsource.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecartesianaxes.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimagelocal.h @@ -81,6 +82,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/scenegraphlightsource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecartesianaxes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneimagelocal.cpp @@ -109,6 +111,10 @@ set(SOURCE_FILES source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/axes_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/axes_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/grid_vs.glsl + ${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/model_fs.glsl diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index ca6c8e1baa..be13023c2c 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -116,6 +117,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "Renderable factory was not created"); + fRenderable->registerClass("RenderableCartesianAxes"); fRenderable->registerClass("RenderableModel"); fRenderable->registerClass("RenderablePlaneImageLocal"); fRenderable->registerClass("RenderablePlaneImageOnline"); diff --git a/modules/base/rendering/renderablecartesianaxes.cpp b/modules/base/rendering/renderablecartesianaxes.cpp new file mode 100644 index 0000000000..283a80924b --- /dev/null +++ b/modules/base/rendering/renderablecartesianaxes.cpp @@ -0,0 +1,275 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr const char* ProgramName = "CartesianAxesProgram"; + const int NVertexIndices = 6; + + constexpr openspace::properties::Property::PropertyInfo XColorInfo = { + "XColor", + "X Color", + "This value determines the color of the x axis." + }; + + constexpr openspace::properties::Property::PropertyInfo YColorInfo = { + "YColor", + "Y Color", + "This value determines the color of the y axis." + }; + + constexpr openspace::properties::Property::PropertyInfo ZColorInfo = { + "ZColor", + "Z Color", + "This value determines the color of the z axis." + }; +} // namespace + +namespace openspace { + +documentation::Documentation RenderableCartesianAxes::Documentation() { + using namespace documentation; + return { + "CartesianAxesProgram", + "base_renderable_cartesianaxes", + { + { + XColorInfo.identifier, + new DoubleVector4Verifier, + Optional::Yes, + XColorInfo.description + }, + { + YColorInfo.identifier, + new DoubleVector4Verifier, + Optional::Yes, + YColorInfo.description + }, + { + ZColorInfo.identifier, + new DoubleVector4Verifier, + Optional::Yes, + ZColorInfo.description + } + } + }; +} + + +RenderableCartesianAxes::RenderableCartesianAxes(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _program(nullptr) + , _xColor( + XColorInfo, + glm::vec4(0.f, 0.f, 0.f, 1.f), + glm::vec4(0.f), + glm::vec4(1.f) + ) + , _yColor( + YColorInfo, + glm::vec4(0.f, 1.f, 0.f, 1.f), + glm::vec4(0.f), + glm::vec4(1.f) + ) + , _zColor( + ZColorInfo, + glm::vec4(0.f, 0.f, 1.f, 1.f), + glm::vec4(0.f), + glm::vec4(1.f) + ) +{ + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "RenderableCartesianAxes" + ); + + if (dictionary.hasKey(XColorInfo.identifier)) { + _xColor = dictionary.value(XColorInfo.identifier); + } + _xColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_xColor); + + if (dictionary.hasKey(XColorInfo.identifier)) { + _yColor = dictionary.value(YColorInfo.identifier); + } + _yColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_yColor); + + if (dictionary.hasKey(ZColorInfo.identifier)) { + _zColor = dictionary.value(ZColorInfo.identifier); + } + _zColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_zColor); +} + +bool RenderableCartesianAxes::isReady() const { + bool ready = true; + ready &= (_program != nullptr); + return ready; +} + +void RenderableCartesianAxes::initializeGL() { + _program = BaseModule::ProgramObjectManager.request( + ProgramName, + []() -> std::unique_ptr { + return global::renderEngine.buildRenderProgram( + ProgramName, + absPath("${MODULE_BASE}/shaders/axes_vs.glsl"), + absPath("${MODULE_BASE}/shaders/axes_fs.glsl") + ); + } + ); + + glGenVertexArrays(1, &_vaoId); + glGenBuffers(1, &_vBufferId); + glGenBuffers(1, &_iBufferId); + + glBindVertexArray(_vaoId); + glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); + glEnableVertexAttribArray(0); + glBindVertexArray(0); + + std::vector vertices({ + Vertex{0.f, 0.f, 0.f}, + Vertex{1.f, 0.f, 0.f}, + Vertex{0.f, 1.f, 0.f}, + Vertex{0.f, 0.f, 1.f} + }); + + std::vector indices = { + 0, 1, + 0, 2, + 0, 3 + }; + + glBindVertexArray(_vaoId); + glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); + glBufferData( + GL_ARRAY_BUFFER, + vertices.size() * sizeof(Vertex), + vertices.data(), + GL_STATIC_DRAW + ); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); + glBufferData( + GL_ELEMENT_ARRAY_BUFFER, + indices.size() * sizeof(int), + indices.data(), + GL_STATIC_DRAW + ); +} + +void RenderableCartesianAxes::deinitializeGL() { + glDeleteVertexArrays(1, &_vaoId); + _vaoId = 0; + + glDeleteBuffers(1, &_vBufferId); + _vBufferId = 0; + + glDeleteBuffers(1, &_iBufferId); + _iBufferId = 0; + + BaseModule::ProgramObjectManager.release( + ProgramName, + [](ghoul::opengl::ProgramObject* p) { + global::renderEngine.removeRenderProgram(p); + } + ); + _program = nullptr; +} + +void RenderableCartesianAxes::render(const RenderData& data, RendererTasks&){ + _program->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 modelViewTransform = data.camera.combinedViewMatrix() * + modelTransform; + + _program->setUniform("modelViewTransform", glm::mat4(modelViewTransform)); + _program->setUniform("projectionTransform", data.camera.projectionMatrix()); + + _program->setUniform("xColor", _xColor); + _program->setUniform("yColor", _yColor); + _program->setUniform("zColor", _zColor); + + // Saves current state: + GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0); + GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH); + GLfloat currentLineWidth; + glGetFloatv(GL_LINE_WIDTH, ¤tLineWidth); + + 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); + + // Changes GL state: + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnablei(GL_BLEND, 0); + glEnable(GL_LINE_SMOOTH); + + glBindVertexArray(_vaoId); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); + glDrawElements(GL_LINES, NVertexIndices, GL_UNSIGNED_INT, nullptr); + glBindVertexArray(0); + + _program->deactivate(); + + // Restores GL State + glLineWidth(currentLineWidth); + glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha); + glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha); + if (!isBlendEnabled) { + glDisablei(GL_BLEND, 0); + } + if (!isLineSmoothEnabled) { + glDisable(GL_LINE_SMOOTH); + } +} + +} // namespace openspace diff --git a/modules/base/rendering/renderablecartesianaxes.h b/modules/base/rendering/renderablecartesianaxes.h new file mode 100644 index 0000000000..9444461180 --- /dev/null +++ b/modules/base/rendering/renderablecartesianaxes.h @@ -0,0 +1,75 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___RENDERABLECARTESIANAXES___H__ +#define __OPENSPACE_MODULE_BASE___RENDERABLECARTESIANAXES___H__ + +#include + +#include +#include +#include +#include +#include +#include + +namespace ghoul::opengl { class ProgramObject; } + +namespace openspace::documentation { struct Documentation; } + +namespace openspace { + +class RenderableCartesianAxes : public Renderable { +public: + RenderableCartesianAxes(const ghoul::Dictionary& dictionary); + ~RenderableCartesianAxes() = default; + + void initializeGL() override; + void deinitializeGL() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + + static documentation::Documentation Documentation(); + +protected: + struct Vertex { + float location[3]; + }; + + ghoul::opengl::ProgramObject* _program; + + properties::Vec4Property _xColor; + properties::Vec4Property _yColor; + properties::Vec4Property _zColor; + + GLuint _vaoId = 0; + GLuint _vBufferId = 0; + GLuint _iBufferId = 0; +}; + +}// namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___RENDERABLECARTESIANAXES___H__ diff --git a/modules/base/shaders/axes_fs.glsl b/modules/base/shaders/axes_fs.glsl new file mode 100644 index 0000000000..1dcf78e416 --- /dev/null +++ b/modules/base/shaders/axes_fs.glsl @@ -0,0 +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. * + ****************************************************************************************/ + +#include "fragment.glsl" +#include "PowerScaling/powerScaling_fs.hglsl" + +in float vs_screenSpaceDepth; +in vec4 vs_positionViewSpace; +in vec3 vs_positionModelSpace; + +uniform vec4 xColor; +uniform vec4 yColor; +uniform vec4 zColor; + +Fragment getFragment() { + Fragment frag; + + vec3 colorComponents = step(0.01f, vs_positionModelSpace); + + frag.color = colorComponents.x * xColor + + colorComponents.y * yColor + + colorComponents.z * zColor; + + frag.depth = vs_screenSpaceDepth; + frag.gPosition = vs_positionViewSpace; + frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + return frag; +} diff --git a/modules/base/shaders/axes_vs.glsl b/modules/base/shaders/axes_vs.glsl new file mode 100644 index 0000000000..b20e90f8e2 --- /dev/null +++ b/modules/base/shaders/axes_vs.glsl @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +layout(location = 0) in vec3 in_position; + +out float vs_screenSpaceDepth; +out vec4 vs_positionViewSpace; +out vec3 vs_positionModelSpace; + +uniform mat4 modelViewTransform; +uniform mat4 projectionTransform; + +void main() { + vec4 positionViewSpace = modelViewTransform * vec4(in_position, 1.0); + vec4 positionClipSpace = projectionTransform * positionViewSpace; + vec4 positionScreenSpace = positionClipSpace; + positionScreenSpace.z = 0.f; + vs_positionModelSpace = in_position; + vs_screenSpaceDepth = positionScreenSpace.w; + vs_positionViewSpace = positionViewSpace; + + gl_Position = positionScreenSpace; +} diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 9ccf4dd613..460135707b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1344,9 +1344,8 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { }; } -LoadingScreen& OpenSpaceEngine::loadingScreen() { - ghoul_assert(_loadingScreen, "Loading Screen must not be nullptr"); - return *_loadingScreen; +LoadingScreen* OpenSpaceEngine::loadingScreen() { + return _loadingScreen.get(); } AssetManager& OpenSpaceEngine::assetManager() { diff --git a/src/scene/sceneinitializer.cpp b/src/scene/sceneinitializer.cpp index 9a220bf2c4..a1ed44669d 100644 --- a/src/scene/sceneinitializer.cpp +++ b/src/scene/sceneinitializer.cpp @@ -52,41 +52,47 @@ MultiThreadedSceneInitializer::MultiThreadedSceneInitializer(unsigned int nThrea void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { auto initFunction = [this, node]() { - LoadingScreen& loadingScreen = global::openSpaceEngine.loadingScreen(); + LoadingScreen* loadingScreen = global::openSpaceEngine.loadingScreen(); LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = 1.f; - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Initializing, - progressInfo - ); + if (loadingScreen) { + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Initializing, + progressInfo + ); + } node->initialize(); std::lock_guard g(_mutex); _initializedNodes.push_back(node); _initializingNodes.erase(node); - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Finished, - progressInfo - ); + if (loadingScreen) { + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Finished, + progressInfo + ); + } }; LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = 0.f; - LoadingScreen& loadingScreen = global::openSpaceEngine.loadingScreen(); - loadingScreen.setItemNumber(loadingScreen.itemNumber() + 1); - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Started, - progressInfo - ); + LoadingScreen* loadingScreen = global::openSpaceEngine.loadingScreen(); + if (loadingScreen) { + loadingScreen->setItemNumber(loadingScreen->itemNumber() + 1); + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Started, + progressInfo + ); + } std::lock_guard g(_mutex); _initializingNodes.insert(node);