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