Overte C++ Documentation
CullTask.h
1 //
2 // CullTask.h
3 // render/src/render
4 //
5 // Created by Sam Gateau on 2/2/16.
6 // Copyright 2016 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_render_CullTask_h
13 #define hifi_render_CullTask_h
14 
15 #include "Engine.h"
16 #include "ViewFrustum.h"
17 
18 namespace render {
19 
20  using CullFunctor = std::function<bool(const RenderArgs*, const AABox&)>;
21 
22  // Culling Frustum / solidAngle test helper class
23  struct CullTest {
24  CullFunctor _functor;
25  RenderArgs* _args;
26  RenderDetails::Item& _renderDetails;
27  ViewFrustumPointer _antiFrustum;
28  glm::vec3 _eyePos;
29  float _squareTanAlpha;
30 
31  CullTest(CullFunctor& functor, RenderArgs* pargs, RenderDetails::Item& renderDetails, ViewFrustumPointer antiFrustum = nullptr);
32 
33  bool frustumTest(const AABox& bound);
34  bool antiFrustumTest(const AABox& bound);
35  bool solidAngleTest(const AABox& bound);
36  bool zoneOcclusionTest(const render::Item& item);
37 
38  static std::unordered_set<QUuid> _containingZones;
39  static std::unordered_set<QUuid> _prevContainingZones;
40  };
41 
42  class FetchNonspatialItems {
43  public:
44  using JobModel = Job::ModelIO<FetchNonspatialItems, ItemFilter, ItemBounds>;
45  void run(const RenderContextPointer& renderContext, const ItemFilter& filter, ItemBounds& outItems);
46  };
47 
48  class FetchSpatialTreeConfig : public Job::Config {
49  Q_OBJECT
50  Q_PROPERTY(int numItems READ getNumItems)
51  Q_PROPERTY(bool freezeFrustum MEMBER freezeFrustum WRITE setFreezeFrustum)
52 
53  public:
54  int numItems{ 0 };
55  int getNumItems() { return numItems; }
56 
57  bool freezeFrustum{ false };
58 
59  public slots:
60  void setFreezeFrustum(bool enabled) { freezeFrustum = enabled; emit dirty(); }
61 
62  signals:
63  void dirty();
64  };
65 
66  class FetchSpatialTree {
67  bool _freezeFrustum{ false }; // initialized by Config
68  bool _justFrozeFrustum{ false };
69  ViewFrustum _frozenFrustum;
70 
71  public:
72  using Config = FetchSpatialTreeConfig;
73  using Inputs = render::VaryingSet2<ItemFilter, glm::ivec2>;
74  using JobModel = Job::ModelIO<FetchSpatialTree, Inputs, ItemSpatialTree::ItemSelection, Config>;
75 
76  FetchSpatialTree() {}
77 
78  void configure(const Config& config);
79  void run(const RenderContextPointer& renderContext, const Inputs& inputs, ItemSpatialTree::ItemSelection& outSelection);
80  };
81 
82  class CullSpatialSelectionConfig : public Job::Config {
83  Q_OBJECT
84  Q_PROPERTY(int numItems READ getNumItems)
85  Q_PROPERTY(bool freezeFrustum MEMBER freezeFrustum WRITE setFreezeFrustum)
86  Q_PROPERTY(bool skipCulling MEMBER skipCulling WRITE setSkipCulling)
87  public:
88  int numItems{ 0 };
89  int getNumItems() { return numItems; }
90 
91  bool freezeFrustum{ false };
92  bool skipCulling{ false };
93  public slots:
94  void setFreezeFrustum(bool enabled) { freezeFrustum = enabled; emit dirty(); }
95  void setSkipCulling(bool enabled) { skipCulling = enabled; emit dirty(); }
96  signals:
97  void dirty();
98  };
99 
100  class CullSpatialSelection {
101  public:
102  using Config = CullSpatialSelectionConfig;
103  using Inputs = render::VaryingSet2<ItemSpatialTree::ItemSelection, ItemFilter>;
104  using JobModel = Job::ModelIO<CullSpatialSelection, Inputs, ItemBounds, Config>;
105 
106  CullSpatialSelection(CullFunctor cullFunctor, bool skipCulling, RenderDetails::Type type) :
107  _cullFunctor(cullFunctor),
108  _skipCulling(skipCulling),
109  _detailType(type) {}
110 
111  CullFunctor _cullFunctor;
112  bool _skipCulling { false };
113  RenderDetails::Type _detailType{ RenderDetails::OTHER };
114 
115  bool _freezeFrustum { false }; // initialized by Config
116  bool _justFrozeFrustum { false };
117  bool _overrideSkipCulling { false };
118  ViewFrustum _frozenFrustum;
119 
120  void configure(const Config& config);
121  void run(const RenderContextPointer& renderContext, const Inputs& inputs, ItemBounds& outItems);
122  };
123 
124  class CullShapeBounds {
125  public:
126  using Inputs = render::VaryingSet4<ShapeBounds, ItemFilter, ItemFilter, ViewFrustumPointer>;
127  using Outputs = render::VaryingSet2<ShapeBounds, AABox>;
128  using JobModel = Job::ModelIO<CullShapeBounds, Inputs, Outputs>;
129 
130  CullShapeBounds(CullFunctor cullFunctor, RenderDetails::Type type) :
131  _cullFunctor{ cullFunctor },
132  _detailType(type) {}
133 
134  CullShapeBounds(CullFunctor cullFunctor) :
135  _cullFunctor{ cullFunctor } {
136  }
137 
138  void run(const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
139 
140  private:
141 
142  CullFunctor _cullFunctor;
143  RenderDetails::Type _detailType{ RenderDetails::OTHER };
144 
145  };
146 
147  class ApplyCullFunctorOnItemBounds {
148  public:
149  using Inputs = render::VaryingSet2<ItemBounds, ViewFrustumPointer>;
150  using Outputs = ItemBounds;
151  using JobModel = Job::ModelIO<ApplyCullFunctorOnItemBounds, Inputs, Outputs>;
152 
153  ApplyCullFunctorOnItemBounds(render::CullFunctor cullFunctor) : _cullFunctor(cullFunctor) {}
154  void run(const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
155 
156  private:
157 
158  render::CullFunctor _cullFunctor;
159  };
160 
161  class ClearContainingZones {
162  public:
163  using JobModel = Job::Model<ClearContainingZones>;
164  void run(const RenderContextPointer& renderContext);
165  };
166 }
167 
168 #endif // hifi_render_CullTask_h;