Overte C++ Documentation
BloomStage.h
1 //
2 // BloomStage.h
3 
4 // Created by Sam Gondelman on 8/7/2018
5 // Copyright 2018 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_render_utils_BloomStage_h
12 #define hifi_render_utils_BloomStage_h
13 
14 #include <graphics/Stage.h>
15 #include <set>
16 #include <unordered_map>
17 #include <render/IndexedContainer.h>
18 #include <render/Stage.h>
19 
20 #include <render/Forward.h>
21 #include <render/DrawTask.h>
22 #include <graphics/Bloom.h>
23 
24 // Bloom stage to set up bloom-related rendering tasks
25 class BloomStage : public render::Stage {
26 public:
27  static std::string _stageName;
28  static const std::string& getName() { return _stageName; }
29 
30  using Index = render::indexed_container::Index;
31  static const Index INVALID_INDEX;
32  static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; }
33 
34  using BloomPointer = graphics::BloomPointer;
35  using Blooms = render::indexed_container::IndexedPointerVector<graphics::Bloom>;
36  using BloomMap = std::unordered_map<BloomPointer, Index>;
37 
38  using BloomIndices = std::vector<Index>;
39 
40  Index findBloom(const BloomPointer& bloom) const;
41  Index addBloom(const BloomPointer& bloom);
42 
43  BloomPointer removeBloom(Index index);
44 
45  bool checkBloomId(Index index) const { return _blooms.checkIndex(index); }
46 
47  Index getNumBlooms() const { return _blooms.getNumElements(); }
48  Index getNumFreeBlooms() const { return _blooms.getNumFreeIndices(); }
49  Index getNumAllocatedBlooms() const { return _blooms.getNumAllocatedIndices(); }
50 
51  BloomPointer getBloom(Index bloomId) const {
52  return _blooms.get(bloomId);
53  }
54 
55  Blooms _blooms;
56  BloomMap _bloomMap;
57 
58  class Frame {
59  public:
60  Frame() {}
61 
62  void clear() { _blooms.clear(); }
63 
64  void pushBloom(BloomStage::Index index) { _blooms.emplace_back(index); }
65 
66  BloomStage::BloomIndices _blooms;
67  };
68  using FramePointer = std::shared_ptr<Frame>;
69 
70  Frame _currentFrame;
71 };
72 using BloomStagePointer = std::shared_ptr<BloomStage>;
73 
74 class BloomStageSetup {
75 public:
76  using JobModel = render::Job::Model<BloomStageSetup>;
77 
78  BloomStageSetup();
79  void run(const render::RenderContextPointer& renderContext);
80 
81 protected:
82 };
83 
84 class FetchBloomConfig : public render::Job::Config {
85  Q_OBJECT
86  Q_PROPERTY(float bloomIntensity MEMBER bloomIntensity WRITE setBloomIntensity NOTIFY dirty);
87  Q_PROPERTY(float bloomThreshold MEMBER bloomThreshold WRITE setBloomThreshold NOTIFY dirty);
88  Q_PROPERTY(float bloomSize MEMBER bloomSize WRITE setBloomSize NOTIFY dirty);
89 
90 public:
91  FetchBloomConfig() : render::Job::Config() {}
92 
93  float bloomIntensity { graphics::Bloom::INITIAL_BLOOM_INTENSITY };
94  float bloomThreshold { graphics::Bloom::INITIAL_BLOOM_THRESHOLD };
95  float bloomSize { graphics::Bloom::INITIAL_BLOOM_SIZE };
96 
97 public slots:
98  void setBloomIntensity(const float value) { bloomIntensity = value; emit dirty(); }
99  void setBloomThreshold(const float value) { bloomThreshold = value; emit dirty(); }
100  void setBloomSize(const float value) { bloomSize = value; emit dirty(); }
101 
102 signals:
103  void dirty();
104 };
105 
106 #endif