1 | #include <OgreCamera.h>
|
---|
2 | #include <OgreLogManager.h>
|
---|
3 | //#include "OgreSolidHalfBoundingBox.h"
|
---|
4 | #include "OgreSolidBoundingBox.h"
|
---|
5 | #include "OgrePlatformHierarchyInterface.h"
|
---|
6 | #include "OgrePlatformOcclusionQuery.h"
|
---|
7 | #include <windows.h>
|
---|
8 |
|
---|
9 | namespace Ogre {
|
---|
10 |
|
---|
11 | //-----------------------------------------------------------------------
|
---|
12 | PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
|
---|
13 | mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL),
|
---|
14 | mCamera(NULL), mCullCamera(NULL)
|
---|
15 | {
|
---|
16 | }
|
---|
17 | //-----------------------------------------------------------------------
|
---|
18 | PlatformHierarchyInterface::~PlatformHierarchyInterface()
|
---|
19 | {
|
---|
20 | DeleteQueries();
|
---|
21 |
|
---|
22 | if(mSolidBoundingBox)
|
---|
23 | delete mSolidBoundingBox;
|
---|
24 | }
|
---|
25 | //-----------------------------------------------------------------------
|
---|
26 | void PlatformHierarchyInterface::DeleteQueries()
|
---|
27 | {
|
---|
28 | for(int i=0; i < (int)mOcclusionQueries.size(); ++i)
|
---|
29 | delete mOcclusionQueries[i];
|
---|
30 |
|
---|
31 | mOcclusionQueries.clear();
|
---|
32 | }
|
---|
33 | //-----------------------------------------------------------------------
|
---|
34 | void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
|
---|
35 | {
|
---|
36 | static RenderOperation ro;
|
---|
37 |
|
---|
38 | //TODO: this should be the full bounding box
|
---|
39 | SolidBoundingBox *solidBox = GetSolidBoundingBox();
|
---|
40 |
|
---|
41 | mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
|
---|
42 | mSceneManager->useRenderableViewProjMode(solidBox);
|
---|
43 | mSceneManager->setPass(solidBox->getTechnique()->getPass(0));
|
---|
44 |
|
---|
45 | solidBox->SetupBoundingBoxVertices(*box);
|
---|
46 |
|
---|
47 | solidBox->getRenderOperation(ro);
|
---|
48 | ro.srcRenderable = solidBox;
|
---|
49 | mRenderSystem->_render(ro);
|
---|
50 |
|
---|
51 | // Render two halfes of the bounding box (using triangle fans)
|
---|
52 | /*for(int halfIdx = 0; halfIdx < 2; ++halfIdx)
|
---|
53 | {
|
---|
54 | solidBox->SetupBoundingBoxVertices(*box, halfIdx == 1);
|
---|
55 |
|
---|
56 | solidBox->getRenderOperation(ro);
|
---|
57 | ro.srcRenderable = solidBox;
|
---|
58 | mRenderSystem->_render(ro);
|
---|
59 | }*/
|
---|
60 | }
|
---|
61 | //-----------------------------------------------------------------------
|
---|
62 | void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
|
---|
63 | {
|
---|
64 | mCamera = cam;
|
---|
65 | }
|
---|
66 | //-----------------------------------------------------------------------
|
---|
67 | void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
|
---|
68 | {
|
---|
69 | mCullCamera = cullCam;
|
---|
70 | }
|
---|
71 | //-----------------------------------------------------------------------
|
---|
72 | GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
|
---|
73 | {
|
---|
74 | if(mCurrentTestIdx == mOcclusionQueries.size())
|
---|
75 | {
|
---|
76 | mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
|
---|
77 | }
|
---|
78 |
|
---|
79 | return mOcclusionQueries[mCurrentTestIdx ++];
|
---|
80 | }
|
---|
81 | //-----------------------------------------------------------------------
|
---|
82 | void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam)
|
---|
83 | {
|
---|
84 | GtpVisibility::HierarchyInterface::InitFrame(root);
|
---|
85 | mPreviousNode = NULL;
|
---|
86 |
|
---|
87 | SetCamera(cam);
|
---|
88 |
|
---|
89 | if(cullCam)
|
---|
90 | SetCullCamera(cullCam);
|
---|
91 | else
|
---|
92 | SetCullCamera(cam);
|
---|
93 | }
|
---|
94 | //-----------------------------------------------------------------------
|
---|
95 | void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
|
---|
96 | {
|
---|
97 | mSceneManager = sm;
|
---|
98 | }
|
---|
99 | //-----------------------------------------------------------------------
|
---|
100 | void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
|
---|
101 | {
|
---|
102 | mRenderSystem = rsys;
|
---|
103 | }
|
---|
104 | //-----------------------------------------------------------------------
|
---|
105 | bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
|
---|
106 | bool &intersects)
|
---|
107 | {
|
---|
108 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
109 | return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
|
---|
110 | #else
|
---|
111 | return true;
|
---|
112 | #endif
|
---|
113 | }
|
---|
114 | //-----------------------------------------------------------------------
|
---|
115 | GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(
|
---|
116 | GtpVisibility::HierarchyNode *node, const bool wasVisible)
|
---|
117 | {
|
---|
118 | // get next available test id
|
---|
119 | GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
|
---|
120 |
|
---|
121 | //-- the actual query test
|
---|
122 | query->BeginQuery();
|
---|
123 |
|
---|
124 | // if node is leaf and was visible => will be rendered anyway. |
---|
125 | // In this case we can also test with the real geometry. |
---|
126 | // if camera for culling is different from camera for rendering => cannot optimize |
---|
127 | if (mUseOptimization && wasVisible && IsLeaf(node) && (mCamera == mCullCamera)) |
---|
128 | { |
---|
129 | //LogManager::getSingleton().logMessage("render node\n"); |
---|
130 | RenderNode(node); |
---|
131 | } |
---|
132 | else
|
---|
133 | {
|
---|
134 | //LogManager::getSingleton().logMessage("render box\n");
|
---|
135 | RenderBoundingBox(GetBoundingBox(node));
|
---|
136 | }
|
---|
137 |
|
---|
138 | query->EndQuery();
|
---|
139 |
|
---|
140 | return query;
|
---|
141 | }
|
---|
142 | //-----------------------------------------------------------------------
|
---|
143 | SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
|
---|
144 | {
|
---|
145 | if(!mSolidBoundingBox)
|
---|
146 | mSolidBoundingBox = new SolidBoundingBox;
|
---|
147 |
|
---|
148 | return mSolidBoundingBox;
|
---|
149 | }
|
---|
150 |
|
---|
151 | } // namespace Ogre |
---|