From 049a11ae5868a3558f1a1b61e158c040b094f3ab Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Wed, 16 Oct 2024 12:24:50 -0700 Subject: [PATCH] templated setup jobs --- .../src/AmbientOcclusionStage.cpp | 9 ----- .../render-utils/src/AmbientOcclusionStage.h | 8 ++--- .../render-utils/src/BackgroundStage.cpp | 9 ----- libraries/render-utils/src/BackgroundStage.h | 8 ++--- libraries/render-utils/src/BloomStage.cpp | 12 +------ libraries/render-utils/src/BloomStage.h | 10 ++---- libraries/render-utils/src/HazeStage.cpp | 12 +------ libraries/render-utils/src/HazeStage.h | 10 ++---- libraries/render-utils/src/LightStage.cpp | 12 ------- libraries/render-utils/src/LightStage.h | 9 ++--- .../render-utils/src/TonemappingStage.cpp | 10 +----- libraries/render-utils/src/TonemappingStage.h | 10 ++---- .../render/src/render/HighlightStage.cpp | 6 ++-- libraries/render/src/render/HighlightStage.h | 2 +- libraries/render/src/render/HighlightStyle.h | 2 ++ libraries/render/src/render/Stage.h | 2 +- libraries/render/src/render/StageSetup.h | 35 +++++++++++++++++++ .../render/src/render/TransitionStage.cpp | 9 ----- libraries/render/src/render/TransitionStage.h | 12 +++---- 19 files changed, 64 insertions(+), 123 deletions(-) create mode 100644 libraries/render/src/render/StageSetup.h diff --git a/libraries/render-utils/src/AmbientOcclusionStage.cpp b/libraries/render-utils/src/AmbientOcclusionStage.cpp index a4a1837ea8..a65bcf8260 100644 --- a/libraries/render-utils/src/AmbientOcclusionStage.cpp +++ b/libraries/render-utils/src/AmbientOcclusionStage.cpp @@ -10,13 +10,4 @@ #include "AmbientOcclusionStage.h" -#include - std::string AmbientOcclusionStage::_name { "AMBIENT_OCCLUSION_STAGE" }; - -void AmbientOcclusionStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(AmbientOcclusionStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(AmbientOcclusionStage::getName(), std::make_shared()); - } -} diff --git a/libraries/render-utils/src/AmbientOcclusionStage.h b/libraries/render-utils/src/AmbientOcclusionStage.h index 90d70d19c9..1b54a0828e 100644 --- a/libraries/render-utils/src/AmbientOcclusionStage.h +++ b/libraries/render-utils/src/AmbientOcclusionStage.h @@ -12,20 +12,16 @@ #define hifi_render_utils_AmbientOcclusionStage_h #include -#include -#include #include +#include // AmbientOcclusion stage to set up ambientOcclusion-related rendering tasks class AmbientOcclusionStage : public render::PointerStage {}; using AmbientOcclusionStagePointer = std::shared_ptr; -class AmbientOcclusionStageSetup { +class AmbientOcclusionStageSetup : public render::StageSetup { public: using JobModel = render::Job::Model; - - AmbientOcclusionStageSetup() {} - void run(const render::RenderContextPointer& renderContext); }; #endif diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index 1857fba0d0..4f837e7a2f 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -13,8 +13,6 @@ #include "DeferredLightingEffect.h" -#include - #include std::string BackgroundStage::_name { "BACKGROUND_STAGE" }; @@ -74,10 +72,3 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, args->_batch = nullptr; } } - -void BackgroundStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(BackgroundStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(BackgroundStage::getName(), std::make_shared()); - } -} diff --git a/libraries/render-utils/src/BackgroundStage.h b/libraries/render-utils/src/BackgroundStage.h index ae3df67215..4da8fbf9fb 100644 --- a/libraries/render-utils/src/BackgroundStage.h +++ b/libraries/render-utils/src/BackgroundStage.h @@ -1,6 +1,6 @@ // // BackgroundStage.h - +// // Created by Sam Gateau on 5/9/2017. // Copyright 2015 High Fidelity, Inc. // Copyright 2024 Overte e.V. @@ -14,6 +14,7 @@ #include #include +#include #include "HazeStage.h" #include "LightingModel.h" @@ -22,12 +23,9 @@ class BackgroundStage : public render::PointerStage {}; using BackgroundStagePointer = std::shared_ptr; -class BackgroundStageSetup { +class BackgroundStageSetup : public render::StageSetup { public: using JobModel = render::Job::Model; - - BackgroundStageSetup() {} - void run(const render::RenderContextPointer& renderContext); }; class DrawBackgroundStage { diff --git a/libraries/render-utils/src/BloomStage.cpp b/libraries/render-utils/src/BloomStage.cpp index eb493322c7..9cca02b5ad 100644 --- a/libraries/render-utils/src/BloomStage.cpp +++ b/libraries/render-utils/src/BloomStage.cpp @@ -8,17 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #include "BloomStage.h" -#include "DeferredLightingEffect.h" - -#include - std::string BloomStage::_name { "BLOOM_STAGE" }; - -void BloomStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(BloomStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(BloomStage::getName(), std::make_shared()); - } -} diff --git a/libraries/render-utils/src/BloomStage.h b/libraries/render-utils/src/BloomStage.h index ed8439e4a8..37e72bacea 100644 --- a/libraries/render-utils/src/BloomStage.h +++ b/libraries/render-utils/src/BloomStage.h @@ -13,22 +13,16 @@ #define hifi_render_utils_BloomStage_h #include -#include -#include #include +#include // Bloom stage to set up bloom-related rendering tasks class BloomStage : public render::PointerStage {}; using BloomStagePointer = std::shared_ptr; -class BloomStageSetup { +class BloomStageSetup : public render::StageSetup { public: using JobModel = render::Job::Model; - - BloomStageSetup() {} - void run(const render::RenderContextPointer& renderContext); - -protected: }; #endif diff --git a/libraries/render-utils/src/HazeStage.cpp b/libraries/render-utils/src/HazeStage.cpp index 7c857d5124..b204e905d0 100644 --- a/libraries/render-utils/src/HazeStage.cpp +++ b/libraries/render-utils/src/HazeStage.cpp @@ -8,17 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #include "HazeStage.h" -#include "DeferredLightingEffect.h" - -#include - std::string HazeStage::_name { "HAZE_STAGE" }; - -void HazeStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(HazeStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(HazeStage::getName(), std::make_shared()); - } -} diff --git a/libraries/render-utils/src/HazeStage.h b/libraries/render-utils/src/HazeStage.h index 008759776f..70a33b27eb 100644 --- a/libraries/render-utils/src/HazeStage.h +++ b/libraries/render-utils/src/HazeStage.h @@ -13,22 +13,16 @@ #define hifi_render_utils_HazeStage_h #include -#include -#include #include +#include // Haze stage to set up haze-related rendering tasks class HazeStage : public render::PointerStage {}; using HazeStagePointer = std::shared_ptr; -class HazeStageSetup { +class HazeStageSetup : public render::StageSetup { public: using JobModel = render::Job::Model; - - HazeStageSetup() {} - void run(const render::RenderContextPointer& renderContext); - -protected: }; class FetchHazeConfig : public render::Job::Config { diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index 358729da77..c16dd8d1d3 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -403,15 +403,3 @@ void LightStage::updateLightArrayBuffer(Index lightId) { // this should not happen ? } } - -LightStageSetup::LightStageSetup() { -} - -void LightStageSetup::run(const render::RenderContextPointer& renderContext) { - if (renderContext->_scene) { - auto stage = renderContext->_scene->getStage(LightStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(LightStage::getName(), std::make_shared()); - } - } -} diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index ace816b18e..5b0a90ddb6 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -15,8 +15,8 @@ #include #include -#include #include +#include class ViewFrustum; @@ -185,14 +185,9 @@ protected: }; using LightStagePointer = std::shared_ptr; - -class LightStageSetup { +class LightStageSetup : public render::StageSetup { public: using JobModel = render::Job::Model; - - LightStageSetup(); - void run(const render::RenderContextPointer& renderContext); }; - #endif diff --git a/libraries/render-utils/src/TonemappingStage.cpp b/libraries/render-utils/src/TonemappingStage.cpp index e5a489d513..e44f8b3501 100644 --- a/libraries/render-utils/src/TonemappingStage.cpp +++ b/libraries/render-utils/src/TonemappingStage.cpp @@ -7,15 +7,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #include "TonemappingStage.h" -#include - std::string TonemappingStage::_name { "TONEMAPPING_STAGE" }; - -void TonemappingStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(TonemappingStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(TonemappingStage::getName(), std::make_shared()); - } -} diff --git a/libraries/render-utils/src/TonemappingStage.h b/libraries/render-utils/src/TonemappingStage.h index e898e8dd43..ee05c0ace4 100644 --- a/libraries/render-utils/src/TonemappingStage.h +++ b/libraries/render-utils/src/TonemappingStage.h @@ -12,22 +12,16 @@ #define hifi_render_utils_TonemappingStage_h #include -#include -#include #include +#include // Tonemapping stage to set up tonemapping-related rendering tasks class TonemappingStage : public render::PointerStage {}; using TonemappingStagePointer = std::shared_ptr; -class TonemappingStageSetup { +class TonemappingStageSetup : public render::StageSetup { public: using JobModel = render::Job::Model; - - TonemappingStageSetup() {} - void run(const render::RenderContextPointer& renderContext); - -protected: }; #endif diff --git a/libraries/render/src/render/HighlightStage.cpp b/libraries/render/src/render/HighlightStage.cpp index d55340adf4..1c35233e74 100644 --- a/libraries/render/src/render/HighlightStage.cpp +++ b/libraries/render/src/render/HighlightStage.cpp @@ -1,6 +1,6 @@ // // HighlightStage.cpp - +// // Created by Olivier Prat on 07/07/2017. // Copyright 2017 High Fidelity, Inc. // Copyright 2024 Overte e.V. @@ -11,6 +11,8 @@ #include "HighlightStage.h" +#include "Engine.h" + using namespace render; std::string HighlightStage::_name { "HIGHLIGHT_STAGE" }; @@ -20,7 +22,7 @@ HighlightStage::Index HighlightStage::addHighlight(const std::string& selectionN return addElement(outline); } -Index HighlightStage::getHighlightIdBySelection(const std::string& selectionName) const { +HighlightStage::Index HighlightStage::getHighlightIdBySelection(const std::string& selectionName) const { for (auto outlineId : _activeElementIDs) { const auto& outline = _elements.get(outlineId); if (outline._selectionName == selectionName) { diff --git a/libraries/render/src/render/HighlightStage.h b/libraries/render/src/render/HighlightStage.h index 4b7f1f5999..d675ed9f6b 100644 --- a/libraries/render/src/render/HighlightStage.h +++ b/libraries/render/src/render/HighlightStage.h @@ -12,9 +12,9 @@ #ifndef hifi_render_utils_HighlightStage_h #define hifi_render_utils_HighlightStage_h -#include "Stage.h" #include "Engine.h" #include "HighlightStyle.h" +#include "Stage.h" namespace render { diff --git a/libraries/render/src/render/HighlightStyle.h b/libraries/render/src/render/HighlightStyle.h index 138674ffbb..266ce71262 100644 --- a/libraries/render/src/render/HighlightStyle.h +++ b/libraries/render/src/render/HighlightStyle.h @@ -17,6 +17,8 @@ #include +#include + namespace render { // This holds the configuration for a particular outline style diff --git a/libraries/render/src/render/Stage.h b/libraries/render/src/render/Stage.h index 4db210d09c..f2a1e10b36 100644 --- a/libraries/render/src/render/Stage.h +++ b/libraries/render/src/render/Stage.h @@ -108,7 +108,7 @@ namespace render { P getElement(Index id) const { return _elements.get(id); } Index findElement(const P& element) const { - auto found = _elementMap.find(haze); + auto found = _elementMap.find(element); if (found != _elementMap.end()) { return INVALID_INDEX; } else { diff --git a/libraries/render/src/render/StageSetup.h b/libraries/render/src/render/StageSetup.h new file mode 100644 index 0000000000..5691bca207 --- /dev/null +++ b/libraries/render/src/render/StageSetup.h @@ -0,0 +1,35 @@ +// +// StageSetup.h +// render/src/render +// +// Created by HifiExperiments on 10/16/24 +// Copyright 2024 Overte e.V. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_render_StageSetup_h +#define hifi_render_StageSetup_h + +#include "Engine.h" + +namespace render { + + template + class StageSetup { + public: + StageSetup() {} + + void run(const RenderContextPointer& renderContext) { + if (renderContext->_scene) { + auto stage = renderContext->_scene->getStage(T::getName()); + if (!stage) { + renderContext->_scene->resetStage(T::getName(), std::make_shared()); + } + } + } + }; +} + +#endif // hifi_render_StageSetup_h diff --git a/libraries/render/src/render/TransitionStage.cpp b/libraries/render/src/render/TransitionStage.cpp index 1d34f5584e..6c0daf5953 100644 --- a/libraries/render/src/render/TransitionStage.cpp +++ b/libraries/render/src/render/TransitionStage.cpp @@ -11,8 +11,6 @@ #include "TransitionStage.h" -#include - using namespace render; std::string TransitionStage::_name { "TRANSITION_STAGE" }; @@ -24,10 +22,3 @@ TransitionStage::Index TransitionStage::addTransition(ItemID itemId, Transition: transition.boundItemId = boundId; return addElement(transition); } - -void TransitionStageSetup::run(const RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(TransitionStage::getName()); - if (!stage) { - renderContext->_scene->resetStage(TransitionStage::getName(), std::make_shared()); - } -} diff --git a/libraries/render/src/render/TransitionStage.h b/libraries/render/src/render/TransitionStage.h index 7f30bee255..11256fb346 100644 --- a/libraries/render/src/render/TransitionStage.h +++ b/libraries/render/src/render/TransitionStage.h @@ -1,6 +1,6 @@ // // TransitionStage.h - +// // Created by Olivier Prat on 07/07/2017. // Copyright 2017 High Fidelity, Inc. // Copyright 2024 Overte e.V. @@ -13,7 +13,7 @@ #define hifi_render_TransitionStage_h #include "Stage.h" -#include "Engine.h" +#include "StageSetup.h" #include "Transition.h" namespace render { @@ -26,13 +26,11 @@ namespace render { }; using TransitionStagePointer = std::shared_ptr; - class TransitionStageSetup { + class TransitionStageSetup : public StageSetup { public: - using JobModel = render::Job::Model; - - TransitionStageSetup() {} - void run(const RenderContextPointer& renderContext); + using JobModel = Job::Model; }; + } #endif // hifi_render_TransitionStage_h