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