1 | #include "VisibilityManager.h"
|
---|
2 | #include "StopAndWaitCullingManager.h"
|
---|
3 | #include "CoherentHierarchicalCullingManager.h"
|
---|
4 | #include "FrustumCullingManager.h"
|
---|
5 | #include "DummyPreprocessingManager.h"
|
---|
6 | #include "DummyQueryManager.h"
|
---|
7 |
|
---|
8 | namespace GtpVisibility {
|
---|
9 |
|
---|
10 | //-----------------------------------------------------------------------
|
---|
11 | VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment):
|
---|
12 | mVisibilityThreshold(0), mCullingManager(NULL),
|
---|
13 | mQueryManager(new DummyQueryManager(NULL)),
|
---|
14 | mPreprocessingManager(new DummyPreprocessingManager(NULL)),
|
---|
15 | mVisibilityEnvironment(visEnvironment)
|
---|
16 | {
|
---|
17 | SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
|
---|
18 | //SetCullingManager(VisibilityEnvironment::STOP_AND_WAIT_CULLING);
|
---|
19 | //SetCullingManager(VisibilityEnvironment::FRUSTUM_CULLING);
|
---|
20 | }
|
---|
21 | //-----------------------------------------------------------------------
|
---|
22 | VisibilityManager::~VisibilityManager()
|
---|
23 | {
|
---|
24 | delete mCullingManager;
|
---|
25 | }
|
---|
26 | //-----------------------------------------------------------------------
|
---|
27 | void VisibilityManager::SetCullingManager(
|
---|
28 | VisibilityEnvironment::CullingManagerType ocmType)
|
---|
29 | {
|
---|
30 | // change only if necessary
|
---|
31 | if (!mCullingManager || (mCullingManagerType != ocmType))
|
---|
32 | {
|
---|
33 | // delete old culling manager
|
---|
34 | if (mCullingManager)
|
---|
35 | {
|
---|
36 | delete mCullingManager;
|
---|
37 | }
|
---|
38 | mCullingManagerType = ocmType;
|
---|
39 |
|
---|
40 | switch (ocmType)
|
---|
41 | {
|
---|
42 | case VisibilityEnvironment::STOP_AND_WAIT_CULLING:
|
---|
43 | mCullingManager = new StopAndWaitCullingManager();
|
---|
44 | break;
|
---|
45 |
|
---|
46 | case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
|
---|
47 | mCullingManager = new CoherentHierarchicalCullingManager();
|
---|
48 | dynamic_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
|
---|
49 | SetAssumedVisibility(mAssumedVisibility);
|
---|
50 | break;
|
---|
51 |
|
---|
52 | case VisibilityEnvironment::FRUSTUM_CULLING:
|
---|
53 | mCullingManager = new FrustumCullingManager();
|
---|
54 | break;
|
---|
55 |
|
---|
56 | default:
|
---|
57 | mCullingManager = new StopAndWaitCullingManager();
|
---|
58 | break;
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | // -- set threshold
|
---|
63 | mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | //-----------------------------------------------------------------------
|
---|
67 | void VisibilityManager::SetVisibilityCullingThreshold(unsigned int visibilityThreshold)
|
---|
68 | {
|
---|
69 | mVisibilityThreshold = visibilityThreshold;
|
---|
70 | mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
|
---|
71 | }
|
---|
72 | //-----------------------------------------------------------------------
|
---|
73 | CullingManager *VisibilityManager::GetCullingManager()
|
---|
74 | {
|
---|
75 | return mCullingManager;
|
---|
76 | }
|
---|
77 | //-----------------------------------------------------------------------
|
---|
78 | void VisibilityManager::ApplyVisibilityCulling()
|
---|
79 | {
|
---|
80 | mCullingManager->RenderScene();
|
---|
81 | }
|
---|
82 | //-----------------------------------------------------------------------
|
---|
83 | VisibilityEnvironment::CullingManagerType VisibilityManager::GetCullingManagerType()
|
---|
84 | {
|
---|
85 | return mCullingManagerType;
|
---|
86 | }
|
---|
87 | //-----------------------------------------------------------------------
|
---|
88 | void VisibilityManager::SetQueryManager(QueryManager *queryManager)
|
---|
89 | {
|
---|
90 | mQueryManager = queryManager;
|
---|
91 | }
|
---|
92 | //-----------------------------------------------------------------------
|
---|
93 | QueryManager *VisibilityManager::GetQueryManager()
|
---|
94 | {
|
---|
95 | return mQueryManager;
|
---|
96 | }
|
---|
97 | void VisibilityManager::SetAssumedVisibility(unsigned int assumedVisibility)
|
---|
98 | {
|
---|
99 | mAssumedVisibility = assumedVisibility;
|
---|
100 |
|
---|
101 | if (VisibilityManager::GetCullingManagerType() ==
|
---|
102 | VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
|
---|
103 | {
|
---|
104 | dynamic_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
|
---|
105 | SetAssumedVisibility(mAssumedVisibility);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | } // namespace GtpVisibility
|
---|