All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ImplicitGridOcclusionResolver.h
1 #pragma once
2 
3 #include "Labels.h"
4 #include "IOcclusionResolver.h"
5 #include "Types.h"
6 #include "IndexPairSet.h"
7 #include "VectorMath.h"
8 
9 #include <vector>
10 
11 namespace Eegeo
12 {
13  namespace Labels
14  {
15 
16 
18  {
19  public:
20  ImplicitGridOcclusionResolver(const v2& screenDimensions,
21  int cellWidth,
22  OcclusionResolverMode::Type occlusionMode);
23 
24  void Clear();
25 
26  void Shrink();
27 
28  InputListType& InputList() { return m_inputList; }
29 
30  InputLodListType& InputLodList() { return m_inputLodList; }
31 
32  void SetScreenDimensions(const v2& screenDimensions) { m_screenDimensions = screenDimensions; }
33 
34  void Resolve(const IOcclusionIntersectionPredicate& intersectionPredicate);
35 
36  const ResultsListType& GetResults() const { return m_resultsList; }
37 
38  void SetMode(OcclusionResolverMode::Type occlusionMode) { m_occlusionMode = occlusionMode; }
39 
40 
41  private:
42  struct GridAABB
43  {
44  int gridMinX;
45  int gridMinY;
46  int gridMaxX;
47  int gridMaxY;
48  };
49 
50  void ClearAllExceptInputLists();
51 
52  void ResetImplicitGrid();
53 
54  void StageLod(const int objectIndex);
55 
56  void UnstageLod(const int objectIndex);
57 
58  void PopulateDisabledOcclusionResults();
59 
60  void FindLodsIntersectingAABB(const int inputLodIndexA,
61  std::vector<u32>& mergedXScratch,
62  std::vector<u32>& mergedYScratch,
63  std::vector<int>& out_inputLodsIntersectingAABB) const;
64 
65  bool Intersects(const int inputLodIndexA,
66  const std::vector<int>& potentiallyIntersectingInputLods,
67  const IOcclusionIntersectionPredicate& intersectionPredicate) const;
68 
69  inline int CellIndexFromGridCoord(int cellX, int cellY) const
70  {
71  return m_gridSizeX*cellY + cellX;
72  }
73 
74  inline int GridCoordX(float x) const
75  {
76  return Math::Clamp(static_cast<int>(x / m_cellWidth), 0, m_gridSizeX - 1);
77  }
78  inline int GridCoordY(float y) const
79  {
80  return Math::Clamp(static_cast<int>(y / m_cellWidth), 0, m_gridSizeY - 1);
81  }
82 
83  void PopulateGridAABBs(const std::vector<OcclusionInputLod>& inputAABBs, std::vector<GridAABB>& out_gridAABBs) const;
84 
85  size_t CalcStoreElementsPerCell() const
86  {
87  return (m_inputLodList.size() + 31) / 32;
88  }
89 
90  bool Intersects(const int objectIndexA) const;
91 
92  struct SolutionEntry
93  {
94  s8 lod;
95  s8 lodCount;
96  s8 previousLod;
97  bool solutionFound;
98  };
99 
100 
101  v2 m_screenDimensions;
102  int m_cellWidth;
103  OcclusionResolverMode::Type m_occlusionMode;
104  float m_oneOverCellWidth;
105  int m_gridSizeX;
106  int m_gridSizeY;
107  int m_storeElementsPerCell;
108 
109  InputListType m_inputList;
110  InputLodListType m_inputLodList;
111  ResultsListType m_resultsList;
112 
113  std::vector<int> m_inputLodsOrderedByPriority;
114  std::vector<SolutionEntry> m_solutionVector;
115 
116  std::vector<GridAABB> m_gridAABBs;
117  std::vector<u32> m_storeX;
118  std::vector<u32> m_storeY;
119 
120  std::vector<u32> m_scratchMergedX;
121  std::vector<u32> m_scratchMergedY;
122  std::vector<int> m_scratchInputLodsIntersectingAABB;
123  };
124  }
125 }