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::VaryingSet2<render::ShapeBounds, HighlightResourcesPointer>;
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, uint transformSlot);
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  uint _transformSlot { 0 };
132 
133  static gpu::PipelinePointer _stencilMaskPipeline;
134  static gpu::PipelinePointer _stencilMaskFillPipeline;
135 };
136 
137 class DrawHighlight {
138 public:
139 
140  using Inputs = render::VaryingSet4<DeferredFrameTransformPointer, HighlightResourcesPointer, DeferredFramebufferPointer, glm::ivec4>;
141  using Config = render::Job::Config;
142  using JobModel = render::Job::ModelI<DrawHighlight, Inputs, Config>;
143 
144  DrawHighlight(unsigned int highlightIndex, HighlightSharedParametersPointer parameters);
145 
146  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
147 
148 private:
149 
150 #include "Highlight_shared.slh"
151 
152  using HighlightConfigurationBuffer = gpu::StructBuffer<HighlightParameters>;
153 
154  static const gpu::PipelinePointer& getPipeline(const render::HighlightStyle& style);
155 
156  static gpu::PipelinePointer _pipeline;
157  static gpu::PipelinePointer _pipelineFilled;
158 
159  unsigned int _highlightPassIndex;
160  HighlightParameters _parameters;
161  HighlightSharedParametersPointer _sharedParameters;
162  HighlightConfigurationBuffer _configuration;
163 };
164 
165 class DebugHighlightConfig : public render::Job::Config {
166  Q_OBJECT
167  Q_PROPERTY(bool viewMask MEMBER viewMask NOTIFY dirty)
168 
169 public:
170  bool viewMask { false };
171 
172 signals:
173  void dirty();
174 };
175 
176 class DebugHighlight {
177 public:
178  using Inputs = render::VaryingSet2<HighlightResourcesPointer, glm::ivec4>;
179  using Config = DebugHighlightConfig;
180  using JobModel = render::Job::ModelI<DebugHighlight, Inputs, Config>;
181 
182  DebugHighlight(uint transformSlot);
183  ~DebugHighlight();
184 
185  void configure(const Config& config);
186  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
187 
188 private:
189 
190  static gpu::PipelinePointer _depthPipeline;
191  int _geometryDepthId { 0 };
192  bool _isDisplayEnabled { false };
193  uint _transformSlot { 0 };
194 
195  static gpu::PipelinePointer& getDepthPipeline();
196  static void initializePipelines();
197 };
198 
199 class DrawHighlightTask {
200 public:
201 
202  using Inputs = render::VaryingSet4<RenderFetchCullSortTask::BucketList, DeferredFramebufferPointer, gpu::FramebufferPointer, DeferredFrameTransformPointer>; using Config = render::Task::Config;
203  using JobModel = render::Task::ModelI<DrawHighlightTask, Inputs, Config>;
204 
205  DrawHighlightTask();
206 
207  void configure(const Config& config);
208  void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, uint transformSlot);
209 
210 private:
211  static const render::Varying addSelectItemJobs(JobModel& task, const render::Varying& selectionName, const RenderFetchCullSortTask::BucketList& items);
212 
213 };
214 
215 class AppendNonMetaOutlines {
216 public:
217  using Inputs = render::VaryingSet2<render::ItemIDs, render::ItemBounds>;
218  using Outputs = render::ItemIDs;
219  using JobModel = render::Job::ModelIO<AppendNonMetaOutlines, Inputs, Outputs>;
220 
221  AppendNonMetaOutlines() {}
222 
223  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
224 };
225 
226 class HighlightCleanup {
227 public:
228  using Inputs = render::VaryingSet2<std::vector<render::HighlightStage::Index>, render::Args::RenderMode>;
229  using JobModel = render::Job::ModelI<HighlightCleanup, Inputs>;
230 
231  HighlightCleanup() {}
232 
233  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
234 };
235 
236 #endif // hifi_render_utils_HighlightEffect_h