Overte C++ Documentation
HighlightEffect.h
1 //
2 // HighlightEffect.h
3 // render-utils/src/
4 //
5 // Created by Olivier Prat on 08/08/17.
6 // Copyright 2017 High Fidelity, Inc.
7 // Copyright 2024 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_render_utils_HighlightEffect_h
14 #define hifi_render_utils_HighlightEffect_h
15 
16 #include <render/Engine.h>
17 #include <render/HighlightStage.h>
18 #include <render/RenderFetchCullSortTask.h>
19 
20 #include "DeferredFramebuffer.h"
21 #include "DeferredFrameTransform.h"
22 
23 class HighlightResources {
24 public:
25  HighlightResources();
26 
27  gpu::FramebufferPointer getDepthFramebuffer();
28  gpu::TexturePointer getDepthTexture();
29 
30  gpu::FramebufferPointer getColorFramebuffer();
31 
32  // Update the source framebuffer size which will drive the allocation of all the other resources.
33  void update(const gpu::FramebufferPointer& primaryFrameBuffer);
34  const glm::ivec2& getSourceFrameSize() const { return _frameSize; }
35 
36 protected:
37 
38  gpu::FramebufferPointer _depthFrameBuffer;
39  gpu::FramebufferPointer _colorFrameBuffer;
40  gpu::TexturePointer _depthStencilTexture;
41 
42  glm::ivec2 _frameSize;
43 
44  void allocateColorBuffer(const gpu::FramebufferPointer& primaryFrameBuffer);
45  void allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer);
46 };
47 
48 using HighlightResourcesPointer = std::shared_ptr<HighlightResources>;
49 
50 class HighlightSharedParameters {
51 public:
52 
53  enum {
54  MAX_PASS_COUNT = 8
55  };
56 
57  HighlightSharedParameters();
58 
59  std::array<render::HighlightStage::Index, MAX_PASS_COUNT> _highlightIds;
60 
61  static float getBlurPixelWidth(const render::HighlightStyle& style, int frameBufferHeight);
62 };
63 
64 using HighlightSharedParametersPointer = std::shared_ptr<HighlightSharedParameters>;
65 
66 class PrepareDrawHighlight {
67 public:
68  using Inputs = gpu::FramebufferPointer;
69  using Outputs = render::VaryingSet2<HighlightResourcesPointer, render::Args::RenderMode>;
70  using JobModel = render::Job::ModelIO<PrepareDrawHighlight, Inputs, Outputs>;
71 
72  PrepareDrawHighlight();
73 
74  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
75 
76 private:
77 
78  HighlightResourcesPointer _resources;
79 
80 };
81 
82 class SelectionToHighlight {
83 public:
84 
85  using Inputs = render::VaryingSet2<render::ItemBounds, gpu::FramebufferPointer>;
86  using Outputs = render::VaryingSet2<std::vector<std::string>, std::vector<render::HighlightStage::Index>>;
87  using JobModel = render::Job::ModelIO<SelectionToHighlight, Inputs, Outputs>;
88 
89  SelectionToHighlight(HighlightSharedParametersPointer parameters) : _sharedParameters{ parameters } {}
90 
91  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
92 
93 private:
94 
95  HighlightSharedParametersPointer _sharedParameters;
96 };
97 
98 class ExtractSelectionName {
99 public:
100 
101  using Inputs = std::vector<std::string>;
102  using Outputs = std::string;
103  using JobModel = render::Job::ModelIO<ExtractSelectionName, Inputs, Outputs>;
104 
105  ExtractSelectionName(unsigned int highlightIndex) : _highlightPassIndex{ highlightIndex } {}
106 
107  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
108 
109 private:
110 
111  unsigned int _highlightPassIndex;
112 
113 };
114 
115 class DrawHighlightMask {
116 public:
117  using Inputs = render::VaryingSet3<render::ShapeBounds, HighlightResourcesPointer, glm::vec2>;
118  using Outputs = glm::ivec4;
119  using JobModel = render::Job::ModelIO<DrawHighlightMask, Inputs, Outputs>;
120 
121  DrawHighlightMask(unsigned int highlightIndex, render::ShapePlumberPointer shapePlumber, HighlightSharedParametersPointer parameters);
122 
123  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
124 
125 protected:
126  unsigned int _highlightPassIndex;
127  render::ShapePlumberPointer _shapePlumber;
128  HighlightSharedParametersPointer _sharedParameters;
129  gpu::BufferPointer _boundsBuffer;
130  gpu::StructBuffer<glm::vec2> _outlineWidth;
131 
132  static gpu::PipelinePointer _stencilMaskPipeline;
133  static gpu::PipelinePointer _stencilMaskFillPipeline;
134 };
135 
136 class DrawHighlight {
137 public:
138 
139  using Inputs = render::VaryingSet5<DeferredFrameTransformPointer, HighlightResourcesPointer, DeferredFramebufferPointer, glm::ivec4, gpu::FramebufferPointer>;
140  using Config = render::Job::Config;
141  using JobModel = render::Job::ModelI<DrawHighlight, Inputs, Config>;
142 
143  DrawHighlight(unsigned int highlightIndex, HighlightSharedParametersPointer parameters);
144 
145  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
146 
147 private:
148 
149 #include "Highlight_shared.slh"
150 
151  using HighlightConfigurationBuffer = gpu::StructBuffer<HighlightParameters>;
152 
153  static const gpu::PipelinePointer& getPipeline(const render::HighlightStyle& style);
154 
155  static gpu::PipelinePointer _pipeline;
156  static gpu::PipelinePointer _pipelineFilled;
157 
158  unsigned int _highlightPassIndex;
159  HighlightParameters _parameters;
160  HighlightSharedParametersPointer _sharedParameters;
161  HighlightConfigurationBuffer _configuration;
162 };
163 
164 class DebugHighlightConfig : public render::Job::Config {
165  Q_OBJECT
166  Q_PROPERTY(bool viewMask MEMBER viewMask NOTIFY dirty)
167 
168 public:
169  bool viewMask { false };
170 
171 signals:
172  void dirty();
173 };
174 
175 class DebugHighlight {
176 public:
177  using Inputs = render::VaryingSet4<HighlightResourcesPointer, glm::ivec4, glm::vec2, gpu::FramebufferPointer>;
178  using Config = DebugHighlightConfig;
179  using JobModel = render::Job::ModelI<DebugHighlight, Inputs, Config>;
180 
181  DebugHighlight();
182  ~DebugHighlight();
183 
184  void configure(const Config& config);
185  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
186 
187 private:
188 
189  gpu::PipelinePointer _depthPipeline;
190  int _geometryDepthId{ 0 };
191  bool _isDisplayEnabled{ false };
192 
193  const gpu::PipelinePointer& getDepthPipeline();
194  void initializePipelines();
195 };
196 
197 class DrawHighlightTask {
198 public:
199 
200  using Inputs = render::VaryingSet5<RenderFetchCullSortTask::BucketList, DeferredFramebufferPointer, gpu::FramebufferPointer, DeferredFrameTransformPointer, glm::vec2>;
201  using Config = render::Task::Config;
202  using JobModel = render::Task::ModelI<DrawHighlightTask, Inputs, Config>;
203 
204  DrawHighlightTask();
205 
206  void configure(const Config& config);
207  void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs);
208 
209 private:
210  static const render::Varying addSelectItemJobs(JobModel& task, const render::Varying& selectionName, const RenderFetchCullSortTask::BucketList& items);
211 
212 };
213 
214 class AppendNonMetaOutlines {
215 public:
216  using Inputs = render::VaryingSet2<render::ItemIDs, render::ItemBounds>;
217  using Outputs = render::ItemIDs;
218  using JobModel = render::Job::ModelIO<AppendNonMetaOutlines, Inputs, Outputs>;
219 
220  AppendNonMetaOutlines() {}
221 
222  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
223 };
224 
225 class HighlightCleanup {
226 public:
227  using Inputs = render::VaryingSet2<std::vector<render::HighlightStage::Index>, render::Args::RenderMode>;
228  using JobModel = render::Job::ModelI<HighlightCleanup, Inputs>;
229 
230  HighlightCleanup() {}
231 
232  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
233 };
234 
235 #endif // hifi_render_utils_HighlightEffect_h