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