1 | #include "VisibilityManager.h"
|
---|
2 | #include "StopAndWaitCullingManager.h"
|
---|
3 | #include "CoherentHierarchicalCullingManager.h"
|
---|
4 | #include "FrustumCullingManager.h"
|
---|
5 | #include "DummyPreprocessingManager.h"
|
---|
6 | #include "RandomUpdateCullingManager.h"
|
---|
7 | #include "CoherentHierarchicalCullingPlusPlusManager.h"
|
---|
8 | #include "CullingLogManager.h"
|
---|
9 |
|
---|
10 |
|
---|
11 | namespace GtpVisibility {
|
---|
12 |
|
---|
13 | //-----------------------------------------------------------------------
|
---|
14 | VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment):
|
---|
15 | mVisibilityThreshold(0),
|
---|
16 | mCullingManager(NULL),
|
---|
17 | mQueryManager(NULL),
|
---|
18 | mPreprocessingManager(new DummyPreprocessingManager(NULL)),
|
---|
19 | mVisibilityEnvironment(visEnvironment),
|
---|
20 | mAssumedVisibilityForChc(0)
|
---|
21 | {
|
---|
22 | SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
|
---|
23 | }
|
---|
24 | //-----------------------------------------------------------------------
|
---|
25 | VisibilityManager::~VisibilityManager()
|
---|
26 | {
|
---|
27 | delete mCullingManager;
|
---|
28 | delete mPreprocessingManager;
|
---|
29 | CullingLogManager::DelSingleton();
|
---|
30 | }
|
---|
31 | //-----------------------------------------------------------------------
|
---|
32 | void VisibilityManager::SetCullingManager(VisibilityEnvironment::
|
---|
33 | CullingManagerType ocmType)
|
---|
34 | {
|
---|
35 | // change only if necessary
|
---|
36 | if (!mCullingManager || (mCullingManagerType != ocmType))
|
---|
37 | {
|
---|
38 | // delete old culling manager
|
---|
39 | if (mCullingManager)
|
---|
40 | delete mCullingManager;
|
---|
41 |
|
---|
42 | mCullingManagerType = ocmType;
|
---|
43 |
|
---|
44 | switch (ocmType)
|
---|
45 | {
|
---|
46 | case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
|
---|
47 | {
|
---|
48 | CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
|
---|
49 | chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
|
---|
50 | mCullingManager = chcm;
|
---|
51 | }
|
---|
52 | break;
|
---|
53 | case VisibilityEnvironment::FRUSTUM_CULLING:
|
---|
54 | mCullingManager = new FrustumCullingManager();
|
---|
55 | break;
|
---|
56 | case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS:
|
---|
57 | {
|
---|
58 | CoherentHierarchicalCullingPlusPlusManager *chcm =
|
---|
59 | new CoherentHierarchicalCullingPlusPlusManager(mAssumedVisibilityForChc);
|
---|
60 | mCullingManager = chcm;
|
---|
61 | }
|
---|
62 | break;
|
---|
63 | case VisibilityEnvironment::STOP_AND_WAIT_CULLING:
|
---|
64 | mCullingManager = new StopAndWaitCullingManager();
|
---|
65 | break;
|
---|
66 | default:
|
---|
67 | mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
|
---|
68 | break;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /////////
|
---|
72 | //-- set threshold
|
---|
73 |
|
---|
74 | mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | //-----------------------------------------------------------------------
|
---|
78 | void VisibilityManager::SetVisibilityCullingThreshold(unsigned int visibilityThreshold)
|
---|
79 | {
|
---|
80 | mVisibilityThreshold = visibilityThreshold;
|
---|
81 | mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
|
---|
82 | }
|
---|
83 | //-----------------------------------------------------------------------
|
---|
84 | CullingManager *VisibilityManager::GetCullingManager()
|
---|
85 | {
|
---|
86 | return mCullingManager;
|
---|
87 | }
|
---|
88 | //-----------------------------------------------------------------------
|
---|
89 | void VisibilityManager::ApplyVisibilityCulling()
|
---|
90 | {
|
---|
91 | mCullingManager->RenderScene();
|
---|
92 | }
|
---|
93 | //-----------------------------------------------------------------------
|
---|
94 | VisibilityEnvironment::CullingManagerType VisibilityManager::GetCullingManagerType()
|
---|
95 | {
|
---|
96 | return mCullingManagerType;
|
---|
97 | }
|
---|
98 | //-----------------------------------------------------------------------
|
---|
99 | void VisibilityManager::SetQueryManager(QueryManager *queryManager)
|
---|
100 | {
|
---|
101 | mQueryManager = queryManager;
|
---|
102 | }
|
---|
103 | //-----------------------------------------------------------------------
|
---|
104 | QueryManager *VisibilityManager::GetQueryManager()
|
---|
105 | {
|
---|
106 | return mQueryManager;
|
---|
107 | }
|
---|
108 | //-----------------------------------------------------------------------
|
---|
109 | void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility)
|
---|
110 | {
|
---|
111 | mAssumedVisibilityForChc = assumedVisibility;
|
---|
112 |
|
---|
113 | switch (mCullingManagerType)
|
---|
114 | {
|
---|
115 | case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
|
---|
116 | static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
|
---|
117 | SetAssumedVisibility(mAssumedVisibilityForChc);
|
---|
118 | break;
|
---|
119 | case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS:
|
---|
120 | static_cast<CoherentHierarchicalCullingPlusPlusManager *>(mCullingManager)->
|
---|
121 | SetAssumedVisibility(mAssumedVisibilityForChc);
|
---|
122 | break;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | //-----------------------------------------------------------------------
|
---|
126 | void VisibilityManager::SetRandomUpdateCandidatesForRuc(unsigned int randomCandidates)
|
---|
127 | {
|
---|
128 | mRandomCandidatesForRuc = randomCandidates;
|
---|
129 |
|
---|
130 | if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS)
|
---|
131 | {
|
---|
132 | static_cast<RandomUpdateCullingManager *>(mCullingManager)->
|
---|
133 | SetRandomCandidates(mRandomCandidatesForRuc);
|
---|
134 | }
|
---|
135 | }
|
---|
136 | //-----------------------------------------------------------------------
|
---|
137 | VisibilityEnvironment *VisibilityManager::GetVisibilityEnvironment()
|
---|
138 | {
|
---|
139 | return mVisibilityEnvironment;
|
---|
140 | }
|
---|
141 | //-----------------------------------------------------------------------
|
---|
142 | unsigned int VisibilityManager::GetAssumedVisibilityForChc()
|
---|
143 | {
|
---|
144 | return mAssumedVisibilityForChc;
|
---|
145 | }
|
---|
146 | //-----------------------------------------------------------------------
|
---|
147 | unsigned int VisibilityManager::GetRandomUpdateCandidatesForRuc()
|
---|
148 | {
|
---|
149 | return mRandomCandidatesForRuc;
|
---|
150 | }
|
---|
151 | //-----------------------------------------------------------------------
|
---|
152 | void VisibilityManager::SetTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves)
|
---|
153 | {
|
---|
154 | mTestGeometryForVisibleLeaves = testGeometryForVisibleLeaves;
|
---|
155 |
|
---|
156 | if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
|
---|
157 | {
|
---|
158 | static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
|
---|
159 | SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
|
---|
160 | }
|
---|
161 | /*else if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS)
|
---|
162 | {
|
---|
163 | static_cast<RandomUpdateCullingManager *>(mCullingManager)->
|
---|
164 | SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
|
---|
165 | }*/
|
---|
166 | }
|
---|
167 | //-----------------------------------------------------------------------
|
---|
168 | bool VisibilityManager::GetTestGeometryForVisibleLeaves()
|
---|
169 | {
|
---|
170 | return mTestGeometryForVisibleLeaves;
|
---|
171 | }
|
---|
172 |
|
---|
173 | } // namespace GtpVisibility
|
---|