Overte C++ Documentation
BackgroundStage.h
1 //
2 // BackgroundStage.h
3 
4 // Created by Sam Gateau on 5/9/2017.
5 // Copyright 2015 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_BackgroundStage_h
12 #define hifi_render_utils_BackgroundStage_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 #include "HazeStage.h"
20 
21 #include "LightingModel.h"
22 
23 
24 // Background stage to set up background-related rendering tasks
25 class BackgroundStage : 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 BackgroundPointer = graphics::SunSkyStagePointer;
35  using Backgrounds = render::indexed_container::IndexedPointerVector<graphics::SunSkyStage>;
36  using BackgroundMap = std::unordered_map<BackgroundPointer, Index>;
37 
38  using BackgroundIndices = std::vector<Index>;
39 
40 
41  Index findBackground(const BackgroundPointer& background) const;
42  Index addBackground(const BackgroundPointer& background);
43 
44  BackgroundPointer removeBackground(Index index);
45 
46  bool checkBackgroundId(Index index) const { return _backgrounds.checkIndex(index); }
47 
48  Index getNumBackgrounds() const { return _backgrounds.getNumElements(); }
49  Index getNumFreeBackgrounds() const { return _backgrounds.getNumFreeIndices(); }
50  Index getNumAllocatedBackgrounds() const { return _backgrounds.getNumAllocatedIndices(); }
51 
52  BackgroundPointer getBackground(Index backgroundId) const {
53  return _backgrounds.get(backgroundId);
54  }
55 
56  Backgrounds _backgrounds;
57  BackgroundMap _backgroundMap;
58 
59  class Frame {
60  public:
61  Frame() {}
62 
63  void clear() { _backgrounds.clear(); }
64 
65  void pushBackground(BackgroundStage::Index index) { _backgrounds.emplace_back(index); }
66 
67  BackgroundStage::BackgroundIndices _backgrounds;
68  };
69  using FramePointer = std::shared_ptr<Frame>;
70 
71  Frame _currentFrame;
72 };
73 using BackgroundStagePointer = std::shared_ptr<BackgroundStage>;
74 
75 class BackgroundStageSetup {
76 public:
77  using JobModel = render::Job::Model<BackgroundStageSetup>;
78 
79  BackgroundStageSetup();
80  void run(const render::RenderContextPointer& renderContext);
81 };
82 
83 class DrawBackgroundStage {
84 public:
85  using Inputs = render::VaryingSet3<LightingModelPointer, BackgroundStage::FramePointer, HazeStage::FramePointer>;
86  using JobModel = render::Job::ModelI<DrawBackgroundStage, Inputs>;
87 
88  DrawBackgroundStage() {}
89 
90  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
91 };
92 
93 #endif