// // HighlightEffect.h // render-utils/src/ // // Created by Olivier Prat on 08/08/17. // Copyright 2017 High Fidelity, Inc. // 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_utils_HighlightEffect_h #define hifi_render_utils_HighlightEffect_h #include #include #include #include "DeferredFramebuffer.h" #include "DeferredFrameTransform.h" class HighlightResources { public: HighlightResources(); gpu::FramebufferPointer getDepthFramebuffer(); gpu::TexturePointer getDepthTexture(); gpu::FramebufferPointer getColorFramebuffer(); // Update the source framebuffer size which will drive the allocation of all the other resources. void update(const gpu::FramebufferPointer& primaryFrameBuffer); const glm::ivec2& getSourceFrameSize() const { return _frameSize; } protected: gpu::FramebufferPointer _depthFrameBuffer; gpu::FramebufferPointer _colorFrameBuffer; gpu::TexturePointer _depthStencilTexture; glm::ivec2 _frameSize; void allocateColorBuffer(const gpu::FramebufferPointer& primaryFrameBuffer); void allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer); }; using HighlightResourcesPointer = std::shared_ptr; class HighlightSharedParameters { public: enum { MAX_PASS_COUNT = 8 }; HighlightSharedParameters(); std::array _highlightIds; static float getBlurPixelWidth(const render::HighlightStyle& style, int frameBufferHeight); }; using HighlightSharedParametersPointer = std::shared_ptr; class PrepareDrawHighlight { public: using Inputs = gpu::FramebufferPointer; using Outputs = render::VaryingSet2; using JobModel = render::Job::ModelIO; PrepareDrawHighlight(); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); private: HighlightResourcesPointer _resources; }; class SelectionToHighlight { public: using Inputs = render::VaryingSet2; using Outputs = render::VaryingSet2, std::vector>; using JobModel = render::Job::ModelIO; SelectionToHighlight(HighlightSharedParametersPointer parameters) : _sharedParameters{ parameters } {} void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); private: HighlightSharedParametersPointer _sharedParameters; }; class ExtractSelectionName { public: using Inputs = std::vector; using Outputs = std::string; using JobModel = render::Job::ModelIO; ExtractSelectionName(unsigned int highlightIndex) : _highlightPassIndex{ highlightIndex } {} void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); private: unsigned int _highlightPassIndex; }; class DrawHighlightMask { public: using Inputs = render::VaryingSet2; using Outputs = glm::ivec4; using JobModel = render::Job::ModelIO; DrawHighlightMask(unsigned int highlightIndex, render::ShapePlumberPointer shapePlumber, HighlightSharedParametersPointer parameters, uint transformSlot); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); protected: unsigned int _highlightPassIndex; render::ShapePlumberPointer _shapePlumber; HighlightSharedParametersPointer _sharedParameters; gpu::BufferPointer _boundsBuffer; gpu::StructBuffer _outlineWidth; uint _transformSlot { 0 }; static gpu::PipelinePointer _stencilMaskPipeline; static gpu::PipelinePointer _stencilMaskFillPipeline; }; class DrawHighlight { public: using Inputs = render::VaryingSet4; using Config = render::Job::Config; using JobModel = render::Job::ModelI; DrawHighlight(unsigned int highlightIndex, HighlightSharedParametersPointer parameters); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); private: #include "Highlight_shared.slh" using HighlightConfigurationBuffer = gpu::StructBuffer; static const gpu::PipelinePointer& getPipeline(const render::HighlightStyle& style); static gpu::PipelinePointer _pipeline; static gpu::PipelinePointer _pipelineFilled; unsigned int _highlightPassIndex; HighlightParameters _parameters; HighlightSharedParametersPointer _sharedParameters; HighlightConfigurationBuffer _configuration; }; class DebugHighlightConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(bool viewMask MEMBER viewMask NOTIFY dirty) public: bool viewMask { false }; signals: void dirty(); }; class DebugHighlight { public: using Inputs = render::VaryingSet2; using Config = DebugHighlightConfig; using JobModel = render::Job::ModelI; DebugHighlight(uint transformSlot); ~DebugHighlight(); void configure(const Config& config); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); private: static gpu::PipelinePointer _depthPipeline; int _geometryDepthId { 0 }; bool _isDisplayEnabled { false }; uint _transformSlot { 0 }; static gpu::PipelinePointer& getDepthPipeline(); static void initializePipelines(); }; class DrawHighlightTask { public: using Inputs = render::VaryingSet4; using Config = render::Task::Config; using JobModel = render::Task::ModelI; DrawHighlightTask(); void configure(const Config& config); void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, uint transformSlot); private: static const render::Varying addSelectItemJobs(JobModel& task, const render::Varying& selectionName, const RenderFetchCullSortTask::BucketList& items); }; class AppendNonMetaOutlines { public: using Inputs = render::VaryingSet2; using Outputs = render::ItemIDs; using JobModel = render::Job::ModelIO; AppendNonMetaOutlines() {} void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); }; class HighlightCleanup { public: using Inputs = render::VaryingSet2, render::Args::RenderMode>; using JobModel = render::Job::ModelI; HighlightCleanup() {} void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); }; #endif // hifi_render_utils_HighlightEffect_h