[59] | 1 | #include "VisibilityManager.h"
|
---|
| 2 | #include "StopAndWaitCullingManager.h"
|
---|
| 3 | #include "CoherentHierarchicalCullingManager.h"
|
---|
| 4 | #include "FrustumCullingManager.h"
|
---|
[65] | 5 | #include "DummyPreprocessingManager.h"
|
---|
[2278] | 6 | #include "RandomUpdateCullingManager.h"
|
---|
[2280] | 7 | #include "CullingLogManager.h"
|
---|
[59] | 8 |
|
---|
[2280] | 9 |
|
---|
[59] | 10 | namespace GtpVisibility {
|
---|
[95] | 11 |
|
---|
[74] | 12 | //-----------------------------------------------------------------------
|
---|
| 13 | VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment):
|
---|
[722] | 14 | mVisibilityThreshold(0),
|
---|
| 15 | mCullingManager(NULL),
|
---|
[153] | 16 | mQueryManager(NULL),
|
---|
[100] | 17 | mPreprocessingManager(new DummyPreprocessingManager(NULL)),
|
---|
[147] | 18 | mVisibilityEnvironment(visEnvironment),
|
---|
[155] | 19 | mAssumedVisibilityForChc(0)
|
---|
[59] | 20 | {
|
---|
[720] | 21 | #if 1
|
---|
[107] | 22 | SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
|
---|
[720] | 23 | #endif
|
---|
| 24 | #if 0
|
---|
| 25 | SetCullingManager(VisibilityEnvironment::STOP_AND_WAIT_CULLING);
|
---|
| 26 | #endif
|
---|
| 27 | #if 0
|
---|
| 28 | SetCullingManager(VisibilityEnvironment::FRUSTUM_CULLING);
|
---|
| 29 | #endif
|
---|
[59] | 30 | }
|
---|
[74] | 31 | //-----------------------------------------------------------------------
|
---|
[59] | 32 | VisibilityManager::~VisibilityManager()
|
---|
| 33 | {
|
---|
| 34 | delete mCullingManager;
|
---|
[153] | 35 | delete mPreprocessingManager;
|
---|
[2280] | 36 | CullingLogManager::DelSingleton();
|
---|
[59] | 37 | }
|
---|
[74] | 38 | //-----------------------------------------------------------------------
|
---|
[155] | 39 | void VisibilityManager::SetCullingManager(VisibilityEnvironment::
|
---|
| 40 | CullingManagerType ocmType)
|
---|
[59] | 41 | {
|
---|
[94] | 42 | // change only if necessary
|
---|
| 43 | if (!mCullingManager || (mCullingManagerType != ocmType))
|
---|
[59] | 44 | {
|
---|
[92] | 45 | // delete old culling manager
|
---|
[100] | 46 | if (mCullingManager)
|
---|
[94] | 47 | delete mCullingManager;
|
---|
[155] | 48 |
|
---|
[92] | 49 | mCullingManagerType = ocmType;
|
---|
| 50 |
|
---|
[59] | 51 | switch (ocmType)
|
---|
| 52 | {
|
---|
| 53 | case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
|
---|
[2455] | 54 | {
|
---|
| 55 | CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
|
---|
| 56 | chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
|
---|
| 57 | mCullingManager = chcm;
|
---|
| 58 | }
|
---|
[59] | 59 | break;
|
---|
| 60 | case VisibilityEnvironment::FRUSTUM_CULLING:
|
---|
[2289] | 61 | mCullingManager = new FrustumCullingManager();
|
---|
| 62 | break;
|
---|
| 63 | case VisibilityEnvironment::RANDOM_UPDATE_CULLING:
|
---|
[2455] | 64 | {
|
---|
| 65 | RandomUpdateCullingManager *rum = new RandomUpdateCullingManager(mRandomCandidatesForRuc);
|
---|
| 66 | rum->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
|
---|
| 67 | mCullingManager = rum;
|
---|
| 68 | }
|
---|
[59] | 69 | break;
|
---|
[2287] | 70 | case VisibilityEnvironment::STOP_AND_WAIT_CULLING:
|
---|
| 71 | mCullingManager = new StopAndWaitCullingManager();
|
---|
| 72 | break;
|
---|
[59] | 73 | default:
|
---|
[2280] | 74 | mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
|
---|
[59] | 75 | break;
|
---|
| 76 | }
|
---|
[114] | 77 |
|
---|
[2280] | 78 | /////////
|
---|
[254] | 79 | //-- set threshold
|
---|
[2455] | 80 |
|
---|
[2280] | 81 | mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
|
---|
[59] | 82 | }
|
---|
| 83 | }
|
---|
[74] | 84 | //-----------------------------------------------------------------------
|
---|
| 85 | void VisibilityManager::SetVisibilityCullingThreshold(unsigned int visibilityThreshold)
|
---|
| 86 | {
|
---|
| 87 | mVisibilityThreshold = visibilityThreshold;
|
---|
| 88 | mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
|
---|
| 89 | }
|
---|
| 90 | //-----------------------------------------------------------------------
|
---|
[59] | 91 | CullingManager *VisibilityManager::GetCullingManager()
|
---|
| 92 | {
|
---|
| 93 | return mCullingManager;
|
---|
| 94 | }
|
---|
[74] | 95 | //-----------------------------------------------------------------------
|
---|
[59] | 96 | void VisibilityManager::ApplyVisibilityCulling()
|
---|
| 97 | {
|
---|
| 98 | mCullingManager->RenderScene();
|
---|
| 99 | }
|
---|
[100] | 100 | //-----------------------------------------------------------------------
|
---|
[92] | 101 | VisibilityEnvironment::CullingManagerType VisibilityManager::GetCullingManagerType()
|
---|
| 102 | {
|
---|
| 103 | return mCullingManagerType;
|
---|
| 104 | }
|
---|
[130] | 105 | //-----------------------------------------------------------------------
|
---|
| 106 | void VisibilityManager::SetQueryManager(QueryManager *queryManager)
|
---|
| 107 | {
|
---|
| 108 | mQueryManager = queryManager;
|
---|
| 109 | }
|
---|
| 110 | //-----------------------------------------------------------------------
|
---|
| 111 | QueryManager *VisibilityManager::GetQueryManager()
|
---|
| 112 | {
|
---|
| 113 | return mQueryManager;
|
---|
| 114 | }
|
---|
[153] | 115 | //-----------------------------------------------------------------------
|
---|
[2455] | 116 | void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility)
|
---|
[146] | 117 | {
|
---|
[155] | 118 | mAssumedVisibilityForChc = assumedVisibility;
|
---|
[146] | 119 |
|
---|
[2455] | 120 | if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
|
---|
[146] | 121 | {
|
---|
[2066] | 122 | static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
|
---|
[2455] | 123 | SetAssumedVisibility(mAssumedVisibilityForChc);
|
---|
[146] | 124 | }
|
---|
| 125 | }
|
---|
[925] | 126 | //-----------------------------------------------------------------------
|
---|
[2455] | 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 | //-----------------------------------------------------------------------
|
---|
[925] | 138 | VisibilityEnvironment *VisibilityManager::GetVisibilityEnvironment()
|
---|
| 139 | {
|
---|
| 140 | return mVisibilityEnvironment;
|
---|
| 141 | }
|
---|
[2455] | 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;
|
---|
[155] | 156 |
|
---|
[2455] | 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 |
|
---|
[59] | 174 | } // namespace GtpVisibility
|
---|