From c4bddacfeb1d58a06230b061249dde52cb9ef835 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 30 Jul 2021 12:00:56 +0200 Subject: [PATCH] Remove nonfunctioning ABufferRenderer from RenderEngine --- CMakeLists.txt | 2 - include/openspace/engine/configuration.h | 8 +- include/openspace/rendering/abufferrenderer.h | 183 --- .../openspace/rendering/framebufferrenderer.h | 34 +- include/openspace/rendering/renderengine.h | 30 +- include/openspace/rendering/renderer.h | 83 -- modules/base/rendering/renderableplane.cpp | 16 +- modules/base/rendering/renderablesphere.cpp | 14 +- modules/base/rendering/renderabletrail.cpp | 16 +- .../renderablefieldlinessequence.cpp | 19 +- openspace.cfg | 1 - src/CMakeLists.txt | 7 - src/engine/configuration.cpp | 27 +- src/rendering/abufferrenderer.cpp | 1062 ----------------- src/rendering/renderengine.cpp | 212 +--- src/rendering/renderengine_lua.inl | 24 - 16 files changed, 64 insertions(+), 1674 deletions(-) delete mode 100644 include/openspace/rendering/abufferrenderer.h delete mode 100644 include/openspace/rendering/renderer.h delete mode 100644 src/rendering/abufferrenderer.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b4b73947d7..c17d3703a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,8 +132,6 @@ if (MSVC) set(GHOUL_OPTIMIZATION_ENABLE_OTHER_OPTIMIZATIONS ${OPENSPACE_OPTIMIZATION_ENABLE_OTHER_OPTIMIZATIONS} CACHE BOOL "" FORCE) endif () -option(OPENSPACE_WITH_ABUFFER_RENDERER "Compile ABuffer Renderer" OFF) - if (UNIX) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++") diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index eed5c055c5..daf0ac7ee4 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -98,16 +98,14 @@ struct Configuration { bool usePerProfileCache = false; bool isRenderingOnMasterDisabled = false; - glm::dvec3 globalRotation = glm::dvec3(0.0); - glm::dvec3 screenSpaceRotation = glm::dvec3(0.0); - glm::dvec3 masterRotation = glm::dvec3(0.0); + glm::vec3 globalRotation = glm::vec3(0.0); + glm::vec3 screenSpaceRotation = glm::vec3(0.0); + glm::vec3 masterRotation = glm::vec3(0.0); bool isConsoleDisabled = false; bool bypassLauncher = false; std::map moduleConfigurations; - std::string renderingMethod = "Framebuffer"; - struct OpenGLDebugContext { bool isActive = false; bool isSynchronous = true; diff --git a/include/openspace/rendering/abufferrenderer.h b/include/openspace/rendering/abufferrenderer.h deleted file mode 100644 index 5769c1e28c..0000000000 --- a/include/openspace/rendering/abufferrenderer.h +++ /dev/null @@ -1,183 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * 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 * - * 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_CORE___ABUFFERRENDERER___H__ -#define __OPENSPACE_CORE___ABUFFERRENDERER___H__ - -#ifdef OPENSPACE_WITH_ABUFFER_RENDERER - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace ghoul::filesystem { class File; } - -namespace ghoul::opengl { - class ProgramObject; - class Texture; -} // namespace ghoul::opengl - -namespace openspace { - -struct RaycasterTask; -class RenderableVolume; -class Camera; -class Scene; -struct RaycastData; - -class ABufferRenderer : public Renderer, public RaycasterListener { -public: - virtual ~ABufferRenderer() = default; - - void initialize() override; - void deinitialize() override; - - void setResolution(glm::ivec2 res) override; - void setNAaSamples(int nAaSamples) override; - void setBlurrinessLevel(int level) override; - void setHDRExposure(float hdrExposure) override; - void setGamma(float gamma) override; - void setMaxWhite(float maxWhite) override; - void setToneMapOperator(int tmOp) override; - void setBloomThreMin(float minV) override; - void setBloomThreMax(float maxV) override; - void setBloomOrigFactor(float origFactor) override; - void setBloomNewFactor(float newFactor) override; - void setKey(float key) override; - void setYwhite(float white) override; - void setTmoSaturation(float sat) override; - void setHue(float hue) override; - void setValue(float value) override; - void setSaturation(float sat) override; - void setLightness(float lightness) override; - void setColorSpace(unsigned int colorspace) override; - - void enableBloom(bool enable) override; - void enableHistogram(bool enable) override; - - int nAaSamples() const override; - const std::vector& mSSAPattern() const override; - - using Renderer::preRaycast; - void preRaycast(const RaycasterTask& raycasterTask); - using Renderer::postRaycast; - void postRaycast(const RaycasterTask& raycasterTask); - - void update() override; - void render(Scene* scene, Camera* camera, float blackoutFactor) override; - - /** - * Update render data - * Responsible for calling renderEngine::setRenderData - */ - virtual void updateRendererData() override; - virtual void raycastersChanged(VolumeRaycaster& raycaster, - IsAttached attached) override; - -private: - void clear(); - void updateResolution(); - void updateRaycastData(); - void updateResolveDictionary(); - void updateMSAASamplingPattern(); - void saveTextureToMemory(GLenum color_buffer_attachment, int width, int height, - std::vector & memory) const; - - glm::ivec2 _resolution = glm::ivec2(0); - - bool _dirtyResolution = true; - bool _dirtyRendererData = true; - bool _dirtyRaycastData = true; - bool _dirtyResolveDictionary = true; - - std::unique_ptr _resolveProgram = nullptr; - - /** - * When a volume is attached or detached from the scene graph, - * the resolve program needs to be recompiled. - * The _volumes map keeps track of which volumes that can - * be rendered using the current resolve program, along with their raycast data - * (id, namespace, etc) - */ - std::map _raycastData; - std::map< - VolumeRaycaster*, std::unique_ptr - > _boundsPrograms; - std::vector _helperPaths; - - ghoul::Dictionary _resolveDictionary; - - GLuint _mainColorTexture; - GLuint _mainDepthTexture; - - GLuint _mainFramebuffer; - GLuint _screenQuad; - GLuint _anchorPointerTexture; - GLuint _anchorPointerTextureInitializer; - GLuint _atomicCounterBuffer; - GLuint _fragmentBuffer; - GLuint _fragmentTexture; - GLuint _vertexPositionBuffer; - int _nAaSamples; - int _blurrinessLevel = 1; - - float _hdrExposure = 0.4f; - float _hdrBackground = 2.8f; - float _gamma = 2.2f; - float _maxWhite = 1.f; - float _blackoutFactor; - bool _bloomEnabled = false; - float _bloomThresholdMin = 0.0; - float _bloomThresholdMax = 1.0; - float _bloomOrigFactor = 1.0; - float _bloomNewFactor = 1.0; - int _toneMapOperator = 0; - bool _histogramEnabled = false; - int _numberOfBins = 1024; // JCC TODO: Add a parameter control for this. - float _tmoKey = 0.18f; - float _tmoYwhite = 1e6f; - float _tmoSaturation = 1.0f; - float _hue = 1.f; - float _saturation = 1.f; - float _value = 1.f; - float _lightness = 1.f; - unsigned int _colorSpace = 1; - - std::vector _mSAAPattern; - - ghoul::Dictionary _rendererData; -}; - -} // namespace openspace - -#endif // OPENSPACE_WITH_ABUFFER_RENDERER - -#endif // __OPENSPACE_CORE___ABUFFERRENDERER___H__ diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index d76c2c5d88..f88e6460c3 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -25,8 +25,6 @@ #ifndef __OPENSPACE_CORE___FRAMEBUFFERRENDERER___H__ #define __OPENSPACE_CORE___FRAMEBUFFERRENDERER___H__ -#include -#include #include #include @@ -56,14 +54,14 @@ struct RaycasterTask; class Scene; struct UpdateStructures; -class FramebufferRenderer : public Renderer, public RaycasterListener, +class FramebufferRenderer : public RaycasterListener, public DeferredcasterListener { public: virtual ~FramebufferRenderer() = default; - void initialize() override; - void deinitialize() override; + void initialize(); + void deinitialize(); void updateResolution(); void updateRaycastData(); @@ -72,33 +70,33 @@ public: void updateFXAA(); void updateDownscaledVolume(); - void setResolution(glm::ivec2 res) override; - void setHDRExposure(float hdrExposure) override; - void setGamma(float gamma) override; - void setHue(float hue) override; - void setValue(float value) override; - void setSaturation(float sat) override; + void setResolution(glm::ivec2 res); + void setHDRExposure(float hdrExposure); + void setGamma(float gamma); + void setHue(float hue); + void setValue(float value); + void setSaturation(float sat); - void enableFXAA(bool enable) override; - void setDisableHDR(bool disable) override; + void enableFXAA(bool enable); + void setDisableHDR(bool disable); - void update() override; + void update(); void performRaycasterTasks(const std::vector& tasks, const glm::ivec4& viewport); void performDeferredTasks(const std::vector& tasks, const glm::ivec4& viewport); - void render(Scene* scene, Camera* camera, float blackoutFactor) override; + void render(Scene* scene, Camera* camera, float blackoutFactor); /** * Update render data * Responsible for calling renderEngine::setRenderData */ - virtual void updateRendererData() override; + virtual void updateRendererData(); virtual void raycastersChanged(VolumeRaycaster& raycaster, - RaycasterListener::IsAttached attached) override; + RaycasterListener::IsAttached attached); virtual void deferredcastersChanged(Deferredcaster& deferredcaster, - DeferredcasterListener::IsAttached isAttached) override; + DeferredcasterListener::IsAttached isAttached); private: using RaycasterProgObjMap = std::map< diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index d32734712c..388e0c8044 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -54,7 +55,6 @@ namespace scripting { struct LuaLibrary; } class Camera; class RaycasterManager; class DeferredcasterManager; -class Renderer; class Scene; class SceneManager; class ScreenLog; @@ -63,12 +63,6 @@ struct ShutdownInformation; class RenderEngine : public properties::PropertyOwner { public: - enum class RendererImplementation { - Framebuffer = 0, - ABuffer, - Invalid - }; - RenderEngine(); ~RenderEngine(); @@ -80,9 +74,6 @@ public: Scene* scene(); void updateScene(); - const Renderer& renderer() const; - RendererImplementation rendererImplementation() const; - ghoul::opengl::OpenGLStateCache& openglStateCache(); void updateShaderPrograms(); @@ -120,24 +111,11 @@ public: void removeRenderProgram(ghoul::opengl::ProgramObject* program); - /** - * Set raycasting uniforms on the program object, and setup raycasting. - */ - void preRaycast(ghoul::opengl::ProgramObject& programObject); - - /** - * Tear down raycasting for the specified program object. - */ - void postRaycast(ghoul::opengl::ProgramObject& programObject); - /** * Set the camera to use for rendering */ void setCamera(Camera* camera); - - void setRendererFromString(const std::string& renderingMethod); - /** * Lets the renderer update the data to be brought into the rendererer programs * as a 'rendererData' variable in the dictionary. @@ -176,9 +154,6 @@ public: uint64_t frameNumber() const; private: - void setRenderer(std::unique_ptr renderer); - RendererImplementation rendererFromString(const std::string& renderingMethod) const; - void renderScreenLog(); void renderVersionInformation(); void renderCameraInformation(); @@ -188,8 +163,7 @@ private: Camera* _camera = nullptr; Scene* _scene = nullptr; - std::unique_ptr _renderer; - RendererImplementation _rendererImplementation = RendererImplementation::Invalid; + FramebufferRenderer _renderer; ghoul::Dictionary _rendererData; ghoul::Dictionary _resolveData; ScreenLog* _log = nullptr; diff --git a/include/openspace/rendering/renderer.h b/include/openspace/rendering/renderer.h deleted file mode 100644 index 6a9243592d..0000000000 --- a/include/openspace/rendering/renderer.h +++ /dev/null @@ -1,83 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * 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 * - * 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_CORE___RENDERER___H__ -#define __OPENSPACE_CORE___RENDERER___H__ - -#include -#include - -namespace ghoul { class Dictionary; } -namespace ghoul::filesystem { class File; } -namespace ghoul::opengl { - class ProgramObject; - class Texture; -} // namespace ghoul::opengl - -namespace openspace { - -class RenderableVolume; -class Camera; -class Scene; - -class Renderer { -public: - virtual ~Renderer() = default; - - virtual void initialize() = 0; - virtual void deinitialize() = 0; - - virtual void setResolution(glm::ivec2 res) = 0; - virtual void setHDRExposure(float hdrExposure) = 0; - virtual void setGamma(float gamma) = 0; - virtual void setHue(float hue) = 0; - virtual void setValue(float value) = 0; - virtual void setSaturation(float sat) = 0; - virtual void enableFXAA(bool enable) = 0; - virtual void setDisableHDR(bool disable) = 0; - - /** - * Set raycasting uniforms on the program object, and setup raycasting. - */ - virtual void preRaycast(ghoul::opengl::ProgramObject& /*programObject*/) {}; - - /** - * Tear down raycasting for the specified program object. - */ - virtual void postRaycast(ghoul::opengl::ProgramObject& /*programObject*/) {}; - - - virtual void update() = 0; - - virtual void render(Scene* scene, Camera* camera, float blackoutFactor) = 0; - /** - * Update render data - * Responsible for calling renderEngine::setRenderData - */ - virtual void updateRendererData() = 0; -}; - -} // openspace - -#endif // __OPENSPACE_CORE___RENDERER___H__ diff --git a/modules/base/rendering/renderableplane.cpp b/modules/base/rendering/renderableplane.cpp index 86401eb031..f8079ec26e 100644 --- a/modules/base/rendering/renderableplane.cpp +++ b/modules/base/rendering/renderableplane.cpp @@ -255,21 +255,7 @@ void RenderablePlane::render(const RenderData& data, RendererTasks&) { _shader->setUniform("multiplyColor", _multiplyColor); - bool usingFramebufferRenderer = global::renderEngine->rendererImplementation() == - RenderEngine::RendererImplementation::Framebuffer; - - bool usingABufferRenderer = global::renderEngine->rendererImplementation() == - RenderEngine::RendererImplementation::ABuffer; - - if (usingABufferRenderer) { - _shader->setUniform( - "additiveBlending", - _blendMode == static_cast(BlendMode::Additive) - ); - } - - bool additiveBlending = - (_blendMode == static_cast(BlendMode::Additive)) && usingFramebufferRenderer; + bool additiveBlending = (_blendMode == static_cast(BlendMode::Additive)); if (additiveBlending) { glDepthMask(false); glBlendFunc(GL_SRC_ALPHA, GL_ONE); diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index 4d05f81f3d..be23335a4e 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -398,24 +398,14 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) { glDisable(GL_CULL_FACE); } - bool usingFramebufferRenderer = global::renderEngine->rendererImplementation() == - RenderEngine::RendererImplementation::Framebuffer; - - bool usingABufferRenderer = global::renderEngine->rendererImplementation() == - RenderEngine::RendererImplementation::ABuffer; - - if (usingABufferRenderer && _useAdditiveBlending) { - _shader->setUniform("additiveBlending", true); - } - - if (usingFramebufferRenderer && _useAdditiveBlending) { + if (_useAdditiveBlending) { glBlendFunc(GL_SRC_ALPHA, GL_ONE); glDepthMask(false); } _sphere->render(); - if (usingFramebufferRenderer && _useAdditiveBlending) { + if (_useAdditiveBlending) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(true); } diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 63e7d99764..509be6db13 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -430,14 +430,8 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { /*glm::ivec2 resolution = global::renderEngine.renderingResolution(); _programObject->setUniform(_uniformCache.resolution, resolution);*/ - const bool usingFramebufferRenderer = - global::renderEngine->rendererImplementation() == - RenderEngine::RendererImplementation::Framebuffer; - - if (usingFramebufferRenderer) { - glDepthMask(false); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } + glDepthMask(false); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); const bool renderLines = (_appearance.renderingModes == RenderingModeLines) || (_appearance.renderingModes == RenderingModeLinesPoints); @@ -508,10 +502,8 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { glBindVertexArray(0); - if (usingFramebufferRenderer) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthMask(true); - } + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(true); _programObject->deactivate(); } diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp index 95e075a9a6..8f58744cf4 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp @@ -1112,22 +1112,9 @@ void RenderableFieldlinesSequence::render(const RenderData& data, RendererTasks& bool additiveBlending = false; if (_pColorABlendEnabled) { - const auto renderer = global::renderEngine->rendererImplementation(); - const bool usingFBufferRenderer = renderer == - RenderEngine::RendererImplementation::Framebuffer; - - const bool usingABufferRenderer = renderer == - RenderEngine::RendererImplementation::ABuffer; - - if (usingABufferRenderer) { - _shaderProgram->setUniform("usingAdditiveBlending", _pColorABlendEnabled); - } - - additiveBlending = usingFBufferRenderer; - if (additiveBlending) { - glDepthMask(false); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } + additiveBlending = true; + glDepthMask(false); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); } glBindVertexArray(_vertexArrayObject); diff --git a/openspace.cfg b/openspace.cfg index 3a5e56d9e0..b1afa57fd7 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -236,7 +236,6 @@ GlobalRotation = { 0.0, 0.0, 0.0 } MasterRotation = { 0.0, 0.0, 0.0 } ScreenSpaceRotation = { 0.0, 0.0, 0.0 } -RenderingMethod = "Framebuffer" OpenGLDebugContext = { Activate = true, FilterIdentifier = { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23d6ff8de2..3d5ef003ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,7 +108,6 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/properties/vector/vec3property.cpp ${OPENSPACE_BASE_DIR}/src/properties/vector/vec4property.cpp ${OPENSPACE_BASE_DIR}/src/query/query.cpp - ${OPENSPACE_BASE_DIR}/src/rendering/abufferrenderer.cpp ${OPENSPACE_BASE_DIR}/src/rendering/dashboard.cpp ${OPENSPACE_BASE_DIR}/src/rendering/dashboard_lua.inl ${OPENSPACE_BASE_DIR}/src/rendering/dashboarditem.cpp @@ -284,7 +283,6 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/vec3property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/vec4property.h ${OPENSPACE_BASE_DIR}/include/openspace/query/query.h - ${OPENSPACE_BASE_DIR}/include/openspace/rendering/abufferrenderer.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/dashboard.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/dashboarditem.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/dashboardtextitem.h @@ -298,7 +296,6 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/rendering/raycasterlistener.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/raycastermanager.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderable.h - ${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderer.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderengine.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/screenspacerenderable.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/texturecomponent.h @@ -464,10 +461,6 @@ endif () set_openspace_compile_settings(openspace-core) target_link_libraries(openspace-core PUBLIC Ghoul spice external-curl) -if (OPENSPACE_WITH_ABUFFER_RENDERER) - target_compile_definitions(openspace-core PUBLIC "OPENSPACE_WITH_ABUFFER_RENDERER") -endif () - # Just in case, create the bin directory add_custom_command( TARGET openspace-core diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index 7194824f06..ad7b113f67 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -161,15 +161,6 @@ namespace { // resolution ('framebuffer'). This value defaults to 'window' std::optional onScreenTextScaling; - // List from RenderEngine::setRendererFromString - enum class RenderingMethod { - Framebuffer, - ABuffer - }; - // The renderer that is use after startup. The renderer 'ABuffer' requires support - // for at least OpenGL 4.3 - std::optional renderingMethod; - // Toggles whether the master in a multi-application setup should be rendering or // just managing the state of the network. This is desired in cases where the // master computer does not have the resources to render a scene @@ -178,16 +169,16 @@ namespace { // Applies a global view rotation. Use this to rotate the position of the focus // node away from the default location on the screen. This setting persists even // when a new focus node is selected. Defined using roll, pitch, yaw in radians - std::optional globalRotation; + std::optional globalRotation; // Applies a view rotation for only the master node, defined using roll, pitch yaw // in radians. This can be used to compensate the master view direction for tilted // display systems in clustered immersive environments - std::optional masterRotation; + std::optional masterRotation; // Applies a global rotation for all screenspace renderables. Defined using roll, // pitch, yaw in radians - std::optional screenSpaceRotation; + std::optional screenSpaceRotation; // If this value is set to 'true' the ingame console is disabled, locking the // system down against random access @@ -415,18 +406,6 @@ void parseLuaState(Configuration& configuration) { c.globalRotation = p.globalRotation.value_or(c.globalRotation); c.masterRotation = p.masterRotation.value_or(c.masterRotation); c.screenSpaceRotation = p.screenSpaceRotation.value_or(c.screenSpaceRotation); - if (p.renderingMethod.has_value()) { - switch (*p.renderingMethod) { - case Parameters::RenderingMethod::Framebuffer: - c.renderingMethod = "Framebuffer"; - break; - case Parameters::RenderingMethod::ABuffer: - c.renderingMethod = "ABuffer"; - break; - default: - throw ghoul::MissingCaseException(); - } - } c.isConsoleDisabled = p.disableInGameConsole.value_or(c.isConsoleDisabled); if (p.logging.has_value()) { if (p.logging->logLevel.has_value()) { diff --git a/src/rendering/abufferrenderer.cpp b/src/rendering/abufferrenderer.cpp deleted file mode 100644 index 4b4f4d4654..0000000000 --- a/src/rendering/abufferrenderer.cpp +++ /dev/null @@ -1,1062 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * 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 * - * 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. * - ****************************************************************************************/ - -#ifdef OPENSPACE_WITH_ABUFFER_RENDERER - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - constexpr const char* _loggerCat = "ABufferRenderer"; - constexpr const char* BoundsFragmentShaderPath = - "${SHADERS}/abuffer/boundsabuffer.frag"; - constexpr const char* RenderFragmentShaderPath = - "${SHADERS}/abuffer/renderabuffer.frag"; - - constexpr int MaxRaycasters = 32; - constexpr int MaxLayers = 32; - constexpr int MaxAverageLayers = 8; -} // namespace - -namespace openspace { - -void ABufferRenderer::initialize() { - LINFO("Initializing ABufferRenderer"); - const GLfloat vertexData[] = { - // x y - -1.f, -1.f, - 1.f, 1.f, - -1.f, 1.f, - -1.f, -1.f, - 1.f, -1.f, - 1.f, 1.f, - }; - - glGenVertexArrays(1, &_screenQuad); - glBindVertexArray(_screenQuad); - - glGenBuffers(1, &_vertexPositionBuffer); - glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); - - glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr); - glEnableVertexAttribArray(0); - - glGenTextures(1, &_anchorPointerTexture); - glGenBuffers(1, &_anchorPointerTextureInitializer); - glGenBuffers(1, &_atomicCounterBuffer); - glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, _atomicCounterBuffer); - glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), nullptr, GL_DYNAMIC_COPY); - glGenBuffers(1, &_fragmentBuffer); - glGenTextures(1, &_fragmentTexture); - - glGenTextures(1, &_mainColorTexture); - glGenTextures(1, &_mainDepthTexture); - glGenFramebuffers(1, &_mainFramebuffer); - - GLint defaultFbo; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFbo); - - updateResolution(); - updateRendererData(); - updateRaycastData(); - updateResolveDictionary(); - updateMSAASamplingPattern(); - - glBindFramebuffer(GL_FRAMEBUFFER, _mainFramebuffer); - glFramebufferTexture2D( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D_MULTISAMPLE, - _mainColorTexture, - 0 - ); - glFramebufferTexture2D( - GL_FRAMEBUFFER, - GL_DEPTH_ATTACHMENT, - GL_TEXTURE_2D_MULTISAMPLE, - _mainDepthTexture, - 0 - ); - - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - LERROR("Main framebuffer is not complete"); - } - - glBindFramebuffer(GL_FRAMEBUFFER, defaultFbo); - - try { - ghoul::Dictionary dict; - dict.setValue("resolveData", _resolveDictionary); - dict.setValue("rendererData", _rendererData); - - _resolveProgram = ghoul::opengl::ProgramObject::Build( - "ABuffer Resolve", - absPath("${SHADERS}/abuffer/resolveabuffer.vert"), - absPath("${SHADERS}/abuffer/resolveabuffer.frag"), - dict - ); - } catch (const ghoul::RuntimeError& e) { - LERRORC(e.component, e.message); - } - - global::raycasterManager.addListener(*this); -} - -void ABufferRenderer::deinitialize() { - LINFO("Deinitializing ABufferRenderer"); - glDeleteBuffers(1, &_fragmentBuffer); - glDeleteTextures(1, &_fragmentTexture); - - glDeleteTextures(1, &_anchorPointerTexture); - glDeleteBuffers(1, &_anchorPointerTextureInitializer); - glDeleteBuffers(1, &_atomicCounterBuffer); - - glDeleteBuffers(1, &_vertexPositionBuffer); - glDeleteVertexArrays(1, &_screenQuad); - - global::raycasterManager.removeListener(*this); -} - -void ABufferRenderer::raycastersChanged(VolumeRaycaster&, IsAttached) { - _dirtyRaycastData = true; -} - -void ABufferRenderer::update() { - PerfMeasure("ABufferRenderer::update"); - - // Make sure that the fragment buffer has the correct resoliution - // according to the output render buffer size - if (_dirtyResolution) { - updateResolution(); - updateMSAASamplingPattern(); - } - - // Make sure that the renderengine gets the correct render data - // to feed into all render programs. - // This will trigger a recompilation of all the shader programs - // involved in rendering geometries. - if (_dirtyRendererData) { - updateRendererData(); - } - - // Make sure that all raycaster data is up to date. - if (_dirtyRaycastData) { - updateRaycastData(); - } - - // Make sure that the resolve dictionary is up to date. - // The resolve dictionary contains information for all - // ray casters, including shader include paths. - - if (_dirtyResolveDictionary) { - updateResolveDictionary(); - ghoul::Dictionary dict; - dict.setValue("resolveData", _resolveDictionary); - dict.setValue("rendererData", _rendererData); - _resolveProgram->setDictionary(dict); - } - - // If the resolve dictionary changed (or a file changed on disk) - // then rebuild the resolve program. - if (_resolveProgram->isDirty()) { - try { - _resolveProgram->rebuildFromFile(); - } catch (const ghoul::RuntimeError& error) { - LERRORC(error.component, error.message); - } - } - using K = VolumeRaycaster* const; - using V = std::unique_ptr; - for (std::pair& program : _boundsPrograms) { - if (program.second->isDirty()) { - try { - program.second->rebuildFromFile(); - } catch (const ghoul::RuntimeError& e) { - LERRORC(e.component, e.message); - } - } - } -} - -void ABufferRenderer::updateMSAASamplingPattern() { - // @CLEANUP(abock): This should probably be merged with the same code from the - // framebuffer renderer? - LINFO("Updating MSAA Sampling Pattern"); - - constexpr const int GridSize = 32; - GLfloat step = 2.f / static_cast(GridSize); - GLfloat sizeX = -1.f; - GLfloat sizeY = 1.f; - - constexpr const int NVertex = 4 * 6; - // openPixelSizeVertexData - GLfloat vertexData[GridSize * GridSize * NVertex]; - - for (int y = 0; y < GridSize; ++y) { - for (int x = 0; x < GridSize; ++x) { - vertexData[y * GridSize * NVertex + x * NVertex] = sizeX; - vertexData[y * GridSize * NVertex + x * NVertex + 1] = sizeY - step; - vertexData[y * GridSize * NVertex + x * NVertex + 2] = 0.f; - vertexData[y * GridSize * NVertex + x * NVertex + 3] = 1.f; - - vertexData[y * GridSize * NVertex + x * NVertex + 4] = sizeX + step; - vertexData[y * GridSize * NVertex + x * NVertex + 5] = sizeY; - vertexData[y * GridSize * NVertex + x * NVertex + 6] = 0.f; - vertexData[y * GridSize * NVertex + x * NVertex + 7] = 1.f; - - vertexData[y * GridSize * NVertex + x * NVertex + 8] = sizeX; - vertexData[y * GridSize * NVertex + x * NVertex + 9] = sizeY; - vertexData[y * GridSize * NVertex + x * NVertex + 10] = 0.f; - vertexData[y * GridSize * NVertex + x * NVertex + 11] = 1.f; - - vertexData[y * GridSize * NVertex + x * NVertex + 12] = sizeX; - vertexData[y * GridSize * NVertex + x * NVertex + 13] = sizeY - step; - vertexData[y * GridSize * NVertex + x * NVertex + 14] = 0.f; - vertexData[y * GridSize * NVertex + x * NVertex + 15] = 1.f; - - vertexData[y * GridSize * NVertex + x * NVertex + 16] = sizeX + step; - vertexData[y * GridSize * NVertex + x * NVertex + 17] = sizeY - step; - vertexData[y * GridSize * NVertex + x * NVertex + 18] = 0.f; - vertexData[y * GridSize * NVertex + x * NVertex + 19] = 1.f; - - vertexData[y * GridSize * NVertex + x * NVertex + 20] = sizeX + step; - vertexData[y * GridSize * NVertex + x * NVertex + 21] = sizeY; - vertexData[y * GridSize * NVertex + x * NVertex + 22] = 0.f; - vertexData[y * GridSize * NVertex + x * NVertex + 23] = 1.f; - - sizeX += step; - } - sizeX = -1.f; - sizeY -= step; - } - - GLuint pixelSizeQuadVAO = 0; - glGenVertexArrays(1, &pixelSizeQuadVAO); - glBindVertexArray(pixelSizeQuadVAO); - - GLuint pixelSizeQuadVBO = 0; - glGenBuffers(1, &pixelSizeQuadVBO); - glBindBuffer(GL_ARRAY_BUFFER, pixelSizeQuadVBO); - - glBufferData( - GL_ARRAY_BUFFER, - sizeof(GLfloat) * GridSize * GridSize * NVertex, - vertexData, - GL_STATIC_DRAW - ); - - // Position - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr); - glEnableVertexAttribArray(0); - - // Saves current state - GLint defaultFbo; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFbo); - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); - - // Main framebuffer - - GLuint pixelSizeTexture = 0; - glGenTextures(1, &pixelSizeTexture); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, pixelSizeTexture); - - constexpr const GLsizei OnePixel = 1; - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_RGBA32F, - OnePixel, - OnePixel, - true - ); - - glViewport(0, 0, OnePixel, OnePixel); - - GLuint pixelSizeFramebuffer = 0; - glGenFramebuffers(1, &pixelSizeFramebuffer); - glBindFramebuffer(GL_FRAMEBUFFER, pixelSizeFramebuffer); - glFramebufferTexture2D( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D_MULTISAMPLE, - pixelSizeTexture, - 0 - ); - - GLenum textureBuffers[1] = { GL_COLOR_ATTACHMENT0 }; - glDrawBuffers(1, textureBuffers); - - glClearColor(0.f, 0.f, 0.f, 1.f); - glClear(GL_COLOR_BUFFER_BIT); - - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - LERROR("MSAA Sampling pattern framebuffer is not complete"); - return; - } - - std::unique_ptr pixelSizeProgram = - ghoul::opengl::ProgramObject::Build( - "OnePixel MSAA", - absPath("${SHADERS}/framebuffer/pixelSizeMSAA.vert"), - absPath("${SHADERS}/framebuffer/pixelSizeMSAA.frag") - ); - - pixelSizeProgram->activate(); - - // Draw sub-pixel grid - glEnable(GL_SAMPLE_SHADING); - glBindVertexArray(pixelSizeQuadVAO); - glDisable(GL_DEPTH_TEST); - glDepthMask(false); - glDrawArrays(GL_TRIANGLES, 0, GridSize * GridSize * 6); - glBindVertexArray(0); - glDepthMask(true); - glEnable(GL_DEPTH_TEST); - glDisable(GL_SAMPLE_SHADING); - - pixelSizeProgram->deactivate(); - - // Now we render the Nx1 quad strip - GLuint nOneStripFramebuffer = 0; - GLuint nOneStripVAO = 0; - GLuint nOneStripVBO = 0; - GLuint nOneStripTexture = 0; - - sizeX = -1.f; - step = 2.f / static_cast(_nAaSamples); - - std::vector nOneStripVertexData(_nAaSamples * (NVertex + 12)); - - for (int x = 0; x < _nAaSamples; ++x) { - nOneStripVertexData[x * (NVertex + 12)] = sizeX; - nOneStripVertexData[x * (NVertex + 12) + 1] = -1.f; - nOneStripVertexData[x * (NVertex + 12) + 2] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 3] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 4] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 5] = 0.f; - - nOneStripVertexData[x * (NVertex + 12) + 6] = sizeX + step; - nOneStripVertexData[x * (NVertex + 12) + 7] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 8] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 9] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 10] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 11] = 1.f; - - nOneStripVertexData[x * (NVertex + 12) + 12] = sizeX; - nOneStripVertexData[x * (NVertex + 12) + 13] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 14] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 15] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 16] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 17] = 0.f; - - nOneStripVertexData[x * (NVertex + 12) + 18] = sizeX; - nOneStripVertexData[x * (NVertex + 12) + 19] = -1.f; - nOneStripVertexData[x * (NVertex + 12) + 20] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 21] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 22] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 23] = 0.f; - - nOneStripVertexData[x * (NVertex + 12) + 24] = sizeX + step; - nOneStripVertexData[x * (NVertex + 12) + 25] = -1.f; - nOneStripVertexData[x * (NVertex + 12) + 26] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 27] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 28] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 29] = 1.f; - - nOneStripVertexData[x * (NVertex + 12) + 30] = sizeX + step; - nOneStripVertexData[x * (NVertex + 12) + 31] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 32] = 0.f; - nOneStripVertexData[x * (NVertex + 12) + 33] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 34] = 1.f; - nOneStripVertexData[x * (NVertex + 12) + 35] = 1.f; - - sizeX += step; - } - - glGenVertexArrays(1, &nOneStripVAO); - glBindVertexArray(nOneStripVAO); - glGenBuffers(1, &nOneStripVBO); - glBindBuffer(GL_ARRAY_BUFFER, nOneStripVBO); - glBufferData( - GL_ARRAY_BUFFER, - sizeof(GLfloat) * _nAaSamples * (NVertex + 12), - nOneStripVertexData.data(), - GL_STATIC_DRAW - ); - - // position - glVertexAttribPointer( - 0, - 4, - GL_FLOAT, - GL_FALSE, - sizeof(GLfloat) * 6, - nullptr - ); - glEnableVertexAttribArray(0); - - // texture coords - glVertexAttribPointer( - 1, - 2, - GL_FLOAT, - GL_FALSE, - sizeof(GLfloat) * 6, - reinterpret_cast(sizeof(GLfloat) * 4) - ); - glEnableVertexAttribArray(1); - - // fbo texture buffer - glGenTextures(1, &nOneStripTexture); - glBindTexture(GL_TEXTURE_2D, nOneStripTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - _nAaSamples, - OnePixel, - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glGenFramebuffers(1, &nOneStripFramebuffer); - glBindFramebuffer(GL_FRAMEBUFFER, nOneStripFramebuffer); - glFramebufferTexture2D( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, - nOneStripTexture, - 0 - ); - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - LERROR("nOneStrip framebuffer is not complete"); - } - - glViewport(0, 0, _nAaSamples, OnePixel); - - std::unique_ptr nOneStripProgram = - ghoul::opengl::ProgramObject::Build( - "OneStrip MSAA", - absPath("${SHADERS}/framebuffer/nOneStripMSAA.vert"), - absPath("${SHADERS}/framebuffer/nOneStripMSAA.frag") - ); - - nOneStripProgram->activate(); - - ghoul::opengl::TextureUnit pixelSizeTextureUnit; - pixelSizeTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, pixelSizeTexture); - nOneStripProgram->setUniform("pixelSizeTexture", pixelSizeTextureUnit); - - // render strip - glDrawBuffers(1, textureBuffers); - - glClearColor(0.f, 1.f, 0.f, 1.f); - glClear(GL_COLOR_BUFFER_BIT); - glBindVertexArray(nOneStripVAO); - glDisable(GL_DEPTH_TEST); - glDepthMask(false); - for (int sample = 0; sample < _nAaSamples; ++sample) { - nOneStripProgram->setUniform("currentSample", sample); - glDrawArrays(GL_TRIANGLES, sample * 6, 6); - } - /*nOneStripProgram->setUniform("currentSample", 0); - glDrawArrays(GL_TRIANGLES, 0, 6 * _nAaSamples);*/ - glDepthMask(true); - glEnable(GL_DEPTH_TEST); - glBindVertexArray(0); - - saveTextureToMemory(GL_COLOR_ATTACHMENT0, _nAaSamples, 1, _mSAAPattern); - // Convert back to [-1, 1] range and then scales to the current viewport size: - for (int d = 0; d < _nAaSamples; ++d) { - _mSAAPattern[d * 3] = (2.0 * _mSAAPattern[d * 3] - 1.0) / - static_cast(viewport[2]); - _mSAAPattern[(d * 3) + 1] = (2.0 * _mSAAPattern[(d * 3) + 1] - 1.0) / - static_cast(viewport[3]); - _mSAAPattern[(d * 3) + 2] = 0.0; - } - - nOneStripProgram->deactivate(); - - // Restores default state - glBindFramebuffer(GL_FRAMEBUFFER, defaultFbo); - glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); - - // Deletes unused buffers - glDeleteFramebuffers(1, &pixelSizeFramebuffer); - glDeleteTextures(1, &pixelSizeTexture); - glDeleteBuffers(1, &pixelSizeQuadVBO); - glDeleteVertexArrays(1, &pixelSizeQuadVAO); - - glDeleteFramebuffers(1, &nOneStripFramebuffer); - glDeleteTextures(1, &nOneStripTexture); - glDeleteBuffers(1, &nOneStripVBO); - glDeleteVertexArrays(1, &nOneStripVAO); -} - -void ABufferRenderer::render(Scene* scene, Camera* camera, float blackoutFactor) { - ZoneScoped - - const bool doPerformanceMeasurements = global::performanceManager.isEnabled(); - - PerfMeasure("ABufferRenderer::render"); - - if (!scene || !camera) { - return; - } - - ghoul::opengl::TextureUnit mainColorTextureUnit; - mainColorTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainColorTexture); - - ghoul::opengl::TextureUnit mainDepthTextureUnit; - mainDepthTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainDepthTexture); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - GLint defaultFbo; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFbo); - glBindFramebuffer(GL_FRAMEBUFFER, _mainFramebuffer); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Reset - clear(); - glEnable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - - // Step 1: Render geometries to the fragment buffer - - // Bind head-pointer image for read-write - glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, _atomicCounterBuffer); - glBindImageTexture(0, _anchorPointerTexture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI); - glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32UI); - - // Render the scene to the fragment buffer. Collect renderer tasks (active raycasters) - int renderBinMask = static_cast(Renderable::RenderBin::Background) | - static_cast(Renderable::RenderBin::Opaque) | - static_cast(Renderable::RenderBin::PreDeferredTransparent) | - static_cast(Renderable::RenderBin::PostDeferredTransparent) | - static_cast(Renderable::RenderBin::Overlay); - - Time time = global::timeManager.time(); - RenderData data{ *camera, psc(), time, doPerformanceMeasurements, renderBinMask, {} }; - RendererTasks tasks; - scene->render(data, tasks); - _blackoutFactor = blackoutFactor; - - glBindFramebuffer(GL_FRAMEBUFFER, defaultFbo); - - - // Step 2: Perform raycasting tasks requested by the scene - for (const RaycasterTask& raycasterTask : tasks.raycasterTasks) { - VolumeRaycaster* raycaster = raycasterTask.raycaster; - ghoul::opengl::ProgramObject* program = _boundsPrograms[raycaster].get(); - if (program) { - program->activate(); - program->setUniform("_exit_", false); - raycaster->renderEntryPoints(raycasterTask.renderData, *program); - program->setUniform("_exit_", true); - raycaster->renderExitPoints(raycasterTask.renderData, *program); - program->deactivate(); - } - else { - LWARNING("Raycaster is not attached when trying to perform raycaster task"); - } - } - - - // Step 3: Resolve the buffer - _resolveProgram->activate(); - - // TEMPORARY GAMMA CORRECTION. - - glm::vec3 cameraPos = data.camera.position().vec3(); - float maxComponent = std::max( - std::max(std::abs(cameraPos.x), std::abs(cameraPos.y)), std::abs(cameraPos.z) - ); - float logDistance = std::log(glm::length(cameraPos / maxComponent) * maxComponent) - / std::log(10.f); - - const float minLogDist = 15.f; - const float maxLogDist = 20.f; - - float t = (logDistance - minLogDist) / (maxLogDist - minLogDist); - t = glm::clamp(t, 0.0f, 1.0f); - const float gamma = 1.f * (1.f - t) + 2.2f * t; - - _resolveProgram->setUniform("gamma", gamma); - - // END TEMPORARY GAMMA CORRECTION. - - _resolveProgram->setUniform("mainColorTexture", mainColorTextureUnit.unitNumber()); - _resolveProgram->setUniform("mainDepthTexture", mainDepthTextureUnit.unitNumber()); - _resolveProgram->setUniform("blackoutFactor", _blackoutFactor); - _resolveProgram->setUniform("nAaSamples", _nAaSamples); - - for (const RaycasterTask& raycasterTask : tasks.raycasterTasks) { - preRaycast(raycasterTask); - } - - glBindVertexArray(_screenQuad); - glDrawArrays(GL_TRIANGLES, 0, 6); - - for (const RaycasterTask& raycasterTask : tasks.raycasterTasks) { - postRaycast(raycasterTask); - } - - _resolveProgram->deactivate(); -} - -void ABufferRenderer::preRaycast(const RaycasterTask& raycasterTask) { - VolumeRaycaster& raycaster = *raycasterTask.raycaster; - const RaycastData& raycastData = _raycastData[&raycaster]; - const RenderData& renderData = raycasterTask.renderData; - - raycaster.preRaycast(raycastData, *_resolveProgram); - - glm::vec3 localCameraPosition; - bool isCameraInside = raycaster.isCameraInside(renderData, localCameraPosition); - int uniformIndex = raycastData.id + 1; // uniforms are indexed from 1 (not from 0) - _resolveProgram->setUniform( - "insideRaycaster" + std::to_string(uniformIndex), - isCameraInside - ); - if (isCameraInside) { - _resolveProgram->setUniform( - "cameraPosInRaycaster" + std::to_string(uniformIndex), - localCameraPosition - ); - } -} - -void ABufferRenderer::postRaycast(const RaycasterTask& raycasterTask) { - VolumeRaycaster& raycaster = *raycasterTask.raycaster; - const RaycastData& raycastData = _raycastData[&raycaster]; - - raycaster.postRaycast(raycastData, *_resolveProgram); -} - -void ABufferRenderer::setResolution(glm::ivec2 res) { - if (res != _resolution) { - _resolution = std::move(res); - _dirtyResolution = true; - } -} - -void ABufferRenderer::setNAaSamples(int nAaSamples) { - _nAaSamples = nAaSamples; - if (_nAaSamples == 0) { - _nAaSamples = 1; - } - if (_nAaSamples > 8) { - LERROR("Framebuffer renderer does not support more than 8 MSAA samples."); - _nAaSamples = 8; - } - _dirtyResolution = true; -} - -void ABufferRenderer::setBlurrinessLevel(int level) { - ghoul_assert( - level > 0 && nAaSamples < 4, - "Blurriness level has to be between 1 and 3" - ); - _blurrinessLevel = level; -} - -void ABufferRenderer::setHDRExposure(float hdrExposure) { - _hdrExposure = hdrExposure; - if (_hdrExposure < 0.f) { - LERROR("HDR Exposure constant must be greater than zero."); - _hdrExposure = 1.0; - } -} - -void ABufferRenderer::setGamma(float gamma) { - _gamma = gamma; - if (_gamma < 0.f) { - LERROR("Gamma value must be greater than zero."); - _gamma = 2.2f; - } -} - -void ABufferRenderer::setMaxWhite(float maxWhite) { - _maxWhite = maxWhite; -} - -void ABufferRenderer::setToneMapOperator(int tmOp) { - _toneMapOperator = tmpOp; -}; - -void ABufferRenderer::setToneMapOperator(int tmOp) { - _toneMapOperator = tmOp; -} - -void ABufferRenderer::setBloomThreMin(float minV) { - _bloomThresholdMin = minV; -} - -void ABufferRenderer::setBloomThreMax(float maxV) { - _bloomThresholdMax = maxV; -} - -void ABufferRenderer::setBloomOrigFactor(float origFactor) { - _bloomOrigFactor = origFactor; -} - -void ABufferRenderer::setBloomNewFactor(float newFactor) { - _bloomNewFactor = newFactor; -} - -void ABufferRenderer::setKey(float key) { - _tmoKey = key; -} - -void ABufferRenderer::setYwhite(float white) { - _tmoYwhite = white; -} - -void ABufferRenderer::setTmoSaturation(float sat) { - _tmoSaturation = sat; -} - -void ABufferRenderer::setHue(float hue) { - _hue = hue; -} - -void ABufferRenderer::setValue(float value) { - _value = value; -} - -void ABufferRenderer::setSaturation(float sat) { - _saturation = sat; -} - -void ABufferRenderer::setLightness(float lightness) { - _lightness = lightness; -} - -void ABufferRenderer::setColorSpace(unsigned int colorspace) { - _colorSpace = colorspace; -} - -void ABufferRenderer::enableBloom(bool enable) { - _bloomEnabled = enable; -} - -void ABufferRenderer::enableHistogram(bool enable) { - _histogramEnabled = enable; -} - -int ABufferRenderer::nAaSamples() const { - return _nAaSamples; -} - -const std::vector& ABufferRenderer::mSSAPattern() const { - return _mSAAPattern; -} - -void ABufferRenderer::clear() { - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer); - glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture); - - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_R32UI, - _resolution.x, - _resolution.y, - 0, - GL_RED_INTEGER, - GL_UNSIGNED_INT, - nullptr - ); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - static const GLuint zero = 1; - glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, _atomicCounterBuffer); - glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(zero), &zero); - glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 0); -} - -void ABufferRenderer::updateResolution() { - PerfMeasure("ABufferRenderer::updateResolution"); - - int totalPixels = _resolution.x * _resolution.y; - glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_R32UI, - _resolution.x, - _resolution.y, - 0, - GL_RED_INTEGER, - GL_UNSIGNED_INT, - nullptr - ); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer); - glBufferData( - GL_PIXEL_UNPACK_BUFFER, - totalPixels * sizeof(GLuint), - nullptr, - GL_STATIC_DRAW - ); - - GLuint* data = reinterpret_cast( - glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY) - ); - memset(data, 0x00, totalPixels * sizeof(GLuint)); - glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - glBindBuffer(GL_TEXTURE_BUFFER, _fragmentBuffer); - glBufferData( - GL_TEXTURE_BUFFER, - MaxAverageLayers*totalPixels * sizeof(GLuint) * 4, - nullptr, - GL_DYNAMIC_COPY - ); - - glBindTexture(GL_TEXTURE_BUFFER, _fragmentTexture); - glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32UI, _fragmentBuffer); - glBindTexture(GL_TEXTURE_BUFFER, 0); - - glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI); - - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainColorTexture); - - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_RGBA, - _resolution.x, - _resolution.y, - true - ); - - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainDepthTexture); - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_DEPTH_COMPONENT32F, - _resolution.x, - _resolution.y, - true - ); - - _dirtyResolution = false; -} - -void ABufferRenderer::updateResolveDictionary() { - ghoul::Dictionary dict; - ghoul::Dictionary raycastersDict; - - for (const std::pair& raycastPair : _raycastData) { - ghoul::Dictionary innerDict; - int id = raycastPair.second.id; - std::string namespaceName = raycastPair.second.namespaceName; - std::string raycastPath = raycastPair.first->raycasterPath(); - - innerDict.setValue("id", id); - innerDict.setValue("namespace", namespaceName); - innerDict.setValue("bitmask", 1 << id); - innerDict.setValue("raycastPath", raycastPath); - - raycastersDict.setValue(std::to_string(id), innerDict); - } - - dict.setValue("raycasters", raycastersDict); - - ghoul::Dictionary helperPathsDict; - for (size_t i = 0; i < _helperPaths.size(); ++i) { - helperPathsDict.setValue(std::to_string(i), _helperPaths[i]); - } - - dict.setValue("helperPaths", helperPathsDict); - dict.setValue("raycastingEnabled", !_raycastData.empty()); - dict.setValue("storeSorted", true); - dict.setValue("nRaycasters", static_cast(_raycastData.size())); - - _resolveDictionary = dict; - - global::renderEngine.setResolveData(dict); - - _dirtyResolveDictionary = false; -} - -void ABufferRenderer::updateRaycastData() { - PerfMeasure("ABufferRenderer::updateRaycastData"); - - _raycastData.clear(); - _boundsPrograms.clear(); - _helperPaths.clear(); - - const std::vector& raycasters = - global::raycasterManager.raycasters(); - - std::map namespaceIndices; - // raycaster ids are positive integers starting at 0. (for raycasters, - // fragment type is id+1) - int nextId = 0; - int nextNamespaceIndex = 0; - - for (VolumeRaycaster* raycaster : raycasters) { - if (nextId > MaxRaycasters) { - int nIgnored = MaxRaycasters - static_cast(raycasters.size()); - LWARNING(fmt::format( - "ABufferRenderer does not support more than 32 raycasters. " - "Ignoring {} raycasters", - nIgnored - )); - break; - } - - RaycastData data; - data.id = nextId++; - - std::string helperPath = raycaster->helperPath(); - // Each new helper path generates a new namespace, - // to avoid glsl name collisions between raycaster implementaitons. - // Assign a new namespace or find an already created index. - - if (helperPath.empty()) { - data.namespaceName = "NAMESPACE_" + std::to_string(nextNamespaceIndex++); - } - else { - auto iter = namespaceIndices.find(helperPath); - if (iter == namespaceIndices.end()) { - int namespaceIndex = nextNamespaceIndex++; - data.namespaceName = std::to_string(namespaceIndex); - namespaceIndices[helperPath] = namespaceIndex; - _helperPaths.push_back(helperPath); - } - else { - data.namespaceName = "NAMESPACE_" + std::to_string(iter->second); - } - } - - _raycastData[raycaster] = data; - std::string vsPath = raycaster->boundsVertexShaderPath(); - std::string fsPath = raycaster->boundsFragmentShaderPath(); - ghoul::Dictionary dict; - - // set path to the current renderer's main fragment shader - dict.setValue("rendererData", _rendererData); - // parameterize the main fragment shader program with specific contents. - // fsPath should point to a shader file defining a Fragment getFragment() function - // instead of a void main() setting glFragColor, glFragDepth, etc. - dict.setValue("fragmentPath", fsPath); - dict.setValue("fragmentType", data.id + 1); - try { - _boundsPrograms[raycaster] = ghoul::opengl::ProgramObject::Build( - "Volume " + std::to_string(data.id) + " bounds", - vsPath, - BoundsFragmentShaderPath, - dict - ); - } - catch (ghoul::RuntimeError& error) { - LERRORC(error.component, error.message); - } - } - - _dirtyRaycastData = false; - _dirtyResolveDictionary = true; -} - -void ABufferRenderer::updateRendererData() { - PerfMeasure("ABufferRenderer::updateRendererData"); - - ghoul::Dictionary dict; - dict.setValue("fragmentRendererPath", std::string(RenderFragmentShaderPath)); - dict.setValue("maxLayers", MaxLayers); - dict.setValue("maxTotalFragments", MaxLayers * _resolution.x * _resolution.y); - - _rendererData = dict; - - global::renderEngine.setRendererData(dict); - _dirtyRendererData = false; -} - -void ABufferRenderer::saveTextureToMemory(GLenum color_buffer_attachment, int width, - int height, std::vector& memory) const -{ - memory.clear(); - - memory.reserve(width * height * 3); - std::vector tmpMemory(width * height * 3); - - if (color_buffer_attachment != GL_DEPTH_ATTACHMENT) { - glReadBuffer(color_buffer_attachment); - glReadPixels(0, 0, width, height, GL_RGB, GL_FLOAT, tmpMemory.data()); - - } - else { - glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, tmpMemory.data()); - } - - for (int i = 0; i < width * height * 3; ++i) { - memory[i] = static_cast(tmpMemory[i]); - } -} - -} // namespace openspace - -#else -int _StubToPreventLinkerWarningAboutMissingExportSymbols; -#endif // OPENSPACE_WITH_ABUFFER_RENDERER diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 21d63a2c28..a61e71fd9e 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -302,57 +301,27 @@ RenderEngine::RenderEngine() addProperty(_showVersionInfo); addProperty(_showCameraInfo); - _enableFXAA.onChange([this]() { - if (_renderer) { - _renderer->enableFXAA(_enableFXAA); - } - }); + _enableFXAA.onChange([this]() { _renderer.enableFXAA(_enableFXAA); }); addProperty(_enableFXAA); _disableHDRPipeline.onChange([this]() { - if (_renderer) { - _renderer->setDisableHDR(_disableHDRPipeline); - } + _renderer.setDisableHDR(_disableHDRPipeline); }); addProperty(_disableHDRPipeline); - _hdrExposure.onChange([this]() { - if (_renderer) { - _renderer->setHDRExposure(_hdrExposure); - } - }); + _hdrExposure.onChange([this]() { _renderer.setHDRExposure(_hdrExposure); }); addProperty(_hdrExposure); - _gamma.onChange([this]() { - if (_renderer) { - _renderer->setGamma(_gamma); - } - }); + _gamma.onChange([this]() { _renderer.setGamma(_gamma); }); addProperty(_gamma); - _hue.onChange([this]() { - if (_renderer) { - const float h = _hue / 360.f; - _renderer->setHue(h); - } - }); - + _hue.onChange([this]() { _renderer.setHue(_hue / 360.f); }); addProperty(_hue); - _saturation.onChange([this]() { - if (_renderer) { - _renderer->setSaturation(_saturation); - } - }); - + _saturation.onChange([this]() { _renderer.setSaturation(_saturation); }); addProperty(_saturation); - _value.onChange([this]() { - if (_renderer) { - _renderer->setValue(_value); - } - }); - + _value.onChange([this]() { _renderer.setValue(_value); }); addProperty(_value); addProperty(_globalBlackOutFactor); @@ -414,39 +383,16 @@ RenderEngine::RenderEngine() RenderEngine::~RenderEngine() {} // NOLINT -void RenderEngine::setRendererFromString(const std::string& renderingMethod) { - ZoneScoped - - _rendererImplementation = rendererFromString(renderingMethod); - - std::unique_ptr newRenderer = nullptr; - switch (_rendererImplementation) { - case RendererImplementation::Framebuffer: - newRenderer = std::make_unique(); - break; - case RendererImplementation::ABuffer: -#ifdef OPENSPACE_WITH_ABUFFER_RENDERER - newRenderer = std::make_unique(); -#endif // OPENSPACE_WITH_ABUFFER_RENDERER - break; - case RendererImplementation::Invalid: - LFATAL(fmt::format("Rendering method '{}' not available", renderingMethod)); - return; - } - - setRenderer(std::move(newRenderer)); -} - void RenderEngine::initialize() { ZoneScoped // We have to perform these initializations here as the OsEng has not been initialized // in our constructor - _globalRotation = static_cast(global::configuration->globalRotation); - _screenSpaceRotation = - static_cast(global::configuration->screenSpaceRotation); - _masterRotation = static_cast(global::configuration->masterRotation); + _globalRotation = global::configuration->globalRotation; + _screenSpaceRotation = global::configuration->screenSpaceRotation; + _masterRotation = global::configuration->masterRotation; _disableMasterRendering = global::configuration->isRenderingOnMasterDisabled; + _screenshotUseDate = global::configuration->shouldUseScreenshotDate; #ifdef GHOUL_USE_DEVIL ghoul::io::TextureReader::ref().addReader( @@ -499,8 +445,6 @@ void RenderEngine::initialize() { ); } } - - _screenshotUseDate = global::configuration->shouldUseScreenshotDate; } void RenderEngine::initializeGL() { @@ -508,21 +452,10 @@ void RenderEngine::initializeGL() { LTRACE("RenderEngine::initializeGL(begin)"); - std::string renderingMethod = global::configuration->renderingMethod; - if (renderingMethod == "ABuffer") { - using Version = ghoul::systemcapabilities::Version; - - // The default rendering method has a requirement of OpenGL 4.3, so if we are - // below that, we will fall back to frame buffer operation - if (OpenGLCap.openGLVersion() < Version{ 4,3,0 }) { - LINFO("Falling back to framebuffer implementation due to OpenGL limitations"); - renderingMethod = "Framebuffer"; - } - } - - LINFO(fmt::format("Setting renderer from string: {}", renderingMethod)); - setRendererFromString(renderingMethod); - + _renderer.setResolution(renderingResolution()); + _renderer.enableFXAA(_enableFXAA); + _renderer.setHDRExposure(_hdrExposure); + _renderer.initialize(); // set the close clip plane and the far clip plane to extreme values while in // development @@ -532,45 +465,15 @@ void RenderEngine::initializeGL() { // initialized window _horizFieldOfView = static_cast(global::windowDelegate->getHorizFieldOfView()); + configuration::Configuration::FontSizes fontSize = global::configuration->fontSize; { - ZoneScopedN("Font: FrameInfo") - TracyGpuZone("Font: FrameInfo") - _fontFrameInfo = global::fontManager->font( - KeyFontMono, - global::configuration->fontSize.frameInfo - ); - } - { - ZoneScopedN("Font: Shutdown") - TracyGpuZone("Font: Shutdown") - _fontShutdown = global::fontManager->font( - KeyFontMono, - global::configuration->fontSize.shutdown - ); - } - { - ZoneScopedN("Font: CameraInfo") - TracyGpuZone("Font: CameraInfo") - _fontCameraInfo = global::fontManager->font( - KeyFontMono, - global::configuration->fontSize.cameraInfo - ); - } - { - ZoneScopedN("Font: VersionInfo") - TracyGpuZone("Font: VersionInfo") - _fontVersionInfo = global::fontManager->font( - KeyFontMono, - global::configuration->fontSize.versionInfo - ); - } - { - ZoneScopedN("Font: Log") - TracyGpuZone("Font: Log") - _fontLog = global::fontManager->font( - KeyFontLight, - global::configuration->fontSize.log - ); + ZoneScopedN("Fonts") + TracyGpuZone("Fonts") + _fontFrameInfo = global::fontManager->font(KeyFontMono, fontSize.frameInfo); + _fontShutdown = global::fontManager->font(KeyFontMono, fontSize.shutdown); + _fontCameraInfo = global::fontManager->font(KeyFontMono, fontSize.cameraInfo); + _fontVersionInfo = global::fontManager->font(KeyFontMono, fontSize.versionInfo); + _fontLog = global::fontManager->font(KeyFontLight, fontSize.log); } { @@ -588,7 +491,7 @@ void RenderEngine::initializeGL() { void RenderEngine::deinitializeGL() { ZoneScoped - _renderer = nullptr; + _renderer.deinitialize(); } void RenderEngine::updateScene() { @@ -633,7 +536,7 @@ void RenderEngine::updateRenderer() { const bool windowResized = global::windowDelegate->windowHasResized(); if (windowResized) { - _renderer->setResolution(renderingResolution()); + _renderer.setResolution(renderingResolution()); using FR = ghoul::fontrendering::FontRenderer; FR::defaultRenderer().setFramebufferSize(fontResolution()); @@ -643,7 +546,7 @@ void RenderEngine::updateRenderer() { static_cast(global::windowDelegate->getHorizFieldOfView()); } - _renderer->update(); + _renderer.update(); } void RenderEngine::updateScreenSpaceRenderables() { @@ -737,9 +640,9 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat _lastFrameTime = now + std::chrono::microseconds(static_cast(delta)); } - const bool masterEnabled = delegate.isMaster() ? !_disableMasterRendering : true; - if (masterEnabled && !delegate.isGuiWindow() && _globalBlackOutFactor > 0.f) { - _renderer->render( + const bool renderingEnabled = delegate.isMaster() ? !_disableMasterRendering : true; + if (renderingEnabled && !delegate.isGuiWindow() && _globalBlackOutFactor > 0.f) { + _renderer.render( _scene, _camera, _globalBlackOutFactor @@ -776,7 +679,7 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat RenderFont(*_fontFrameInfo, penPosition, res); } - if (masterEnabled && !delegate.isGuiWindow() && _globalBlackOutFactor > 0.f) { + if (renderingEnabled && !delegate.isGuiWindow() && _globalBlackOutFactor > 0.f) { ZoneScopedN("Render Screenspace Renderable") std::vector ssrs; @@ -968,14 +871,6 @@ void RenderEngine::setCamera(Camera* camera) { _camera = camera; } -const Renderer& RenderEngine::renderer() const { - return *_renderer; -} - -RenderEngine::RendererImplementation RenderEngine::rendererImplementation() const { - return _rendererImplementation; -} - ghoul::opengl::OpenGLStateCache& RenderEngine::openglStateCache() { if (_openglStateCache == nullptr) { _openglStateCache = ghoul::opengl::OpenGLStateCache::instance(); @@ -1127,39 +1022,10 @@ unsigned int RenderEngine::latestScreenshotNumber() const { return _latestScreenshotNumber; } -void RenderEngine::preRaycast(ghoul::opengl::ProgramObject& programObject) { - _renderer->preRaycast(programObject); -} - -void RenderEngine::postRaycast(ghoul::opengl::ProgramObject& programObject) { - _renderer->postRaycast(programObject); -} - -void RenderEngine::setRenderer(std::unique_ptr renderer) { - ZoneScoped - - if (_renderer) { - _renderer->deinitialize(); - } - - _renderer = std::move(renderer); - _renderer->setResolution(renderingResolution()); - _renderer->enableFXAA(_enableFXAA); - _renderer->setHDRExposure(_hdrExposure); - _renderer->initialize(); -} - scripting::LuaLibrary RenderEngine::luaLibrary() { return { "", { - { - "setRenderer", - &luascriptfunctions::setRenderer, - {}, - "string", - "Sets the renderer (ABuffer or FrameBuffer)" - }, { "addScreenSpaceRenderable", &luascriptfunctions::addScreenSpaceRenderable, @@ -1266,24 +1132,6 @@ std::vector RenderEngine::screenSpaceRenderables() const return res; } -RenderEngine::RendererImplementation RenderEngine::rendererFromString( - const std::string& renderingMethod) const -{ - const std::map RenderingMethods = { -#ifdef OPENSPACE_WITH_ABUFFER_RENDERER - { "ABuffer", RendererImplementation::ABuffer }, -#endif // OPENSPACE_WITH_ABUFFER_RENDERER - { "Framebuffer", RendererImplementation::Framebuffer } - }; - - if (RenderingMethods.find(renderingMethod) != RenderingMethods.end()) { - return RenderingMethods.at(renderingMethod); - } - else { - return RendererImplementation::Invalid; - } -} - void RenderEngine::renderCameraInformation() { ZoneScoped diff --git a/src/rendering/renderengine_lua.inl b/src/rendering/renderengine_lua.inl index 9bb26d0fcd..b011722f42 100644 --- a/src/rendering/renderengine_lua.inl +++ b/src/rendering/renderengine_lua.inl @@ -26,30 +26,6 @@ namespace openspace::luascriptfunctions { -/** -* \ingroup LuaScripts -* setRenderer(string): -* Set renderer -*/ -int setRenderer(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setRenderer"); - - const int type = lua_type(L, -1); - if (type != LUA_TSTRING) { - return ghoul::lua::luaError(L, "Expected argument of type 'string'"); - } - - const std::string& renderer = ghoul::lua::value( - L, - 1, - ghoul::lua::PopValue::Yes - ); - global::renderEngine->setRendererFromString(renderer); - - ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); - return 0; -} - int addScreenSpaceRenderable(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::addScreenSpaceRenderable");