source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp @ 2497

Revision 2497, 9.4 KB checked in by mattausch, 17 years ago (diff)
RevLine 
[59]1#include <OgreCamera.h>
[94]2#include <OgreLogManager.h>
[130]3#include <OgreSubEntity.h>
4#include <OgreEntity.h>
5#include <OgreMovableObject.h>
[897]6#include <OgreMaterialManager.h>
[92]7#include "OgreSolidBoundingBox.h"
[59]8#include "OgrePlatformHierarchyInterface.h"
9#include "OgrePlatformOcclusionQuery.h"
10
11namespace Ogre {
12
13//-----------------------------------------------------------------------
[726]14PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm,
15                                                                                                           RenderSystem *rsys):
16mSceneManager(sm),
17mRenderSystem(rsys),
18mSolidBoundingBox(NULL),
19mCamera(NULL),
20mCullCamera(NULL),
21mOnlyShadowCasters(false),
22mLeavePassesInQueue(0),
23mIsBoundingBoxQuery(false),
24mCameraPosition(Vector3(0, 0, 0))
[85]25{
[59]26}
27//-----------------------------------------------------------------------
[115]28void PlatformHierarchyInterface::CreateNodeVizMaterials()
[112]29{
30        // material for frustum culled nodes
31        MaterialPtr mat = MaterialManager::getSingleton().getByName("FrustumCulledNodesMaterial");
[113]32       
[112]33        if (mat.isNull())
34        {
35                mat = MaterialManager::getSingleton().create("FrustumCulledNodesMaterial",
36                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
[113]37                mat->createTechnique()->createPass();
38               
[115]39                mat->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0);
[113]40                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
41                //mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
42                mat->load();
[112]43        }
44
45        // material for query culled nodes
[113]46        mat = MaterialManager::getSingleton().getByName("QueryCulledNodesMaterial");
[112]47
[113]48        if (mat.isNull())
[112]49        {
[113]50                mat = MaterialManager::getSingleton().create("QueryCulledNodesMaterial",
[112]51                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
[113]52                mat->createTechnique()->createPass();
53               
[115]54                mat->getTechnique(0)->getPass(0)->setAmbient(0, 0, 1);
[113]55                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
56                mat->load();
[112]57        }
[115]58
59        // material for scene nodes
60        /*mat = MaterialManager::getSingleton().getByName("SceneNodesMaterial");
61
62        if (mat.isNull())
63        {
64                mat = MaterialManager::getSingleton().create("SceneNodesMaterial",
65                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
66                mat->createTechnique()->createPass();
67               
68                mat->getTechnique(0)->getPass(0)->setAmbient(1, 1, 0);
69                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
70                mat->load();
71        }*/
[112]72}
73//-----------------------------------------------------------------------
[59]74PlatformHierarchyInterface::~PlatformHierarchyInterface()
75{
[897]76        ResetQueries();
[187]77        OGRE_DELETE(mSolidBoundingBox);
[59]78}
79//-----------------------------------------------------------------------
[897]80void PlatformHierarchyInterface::ResetQueries()
[59]81{
[938]82        OcclusionQueryContainer::iterator it, it_end = mOcclusionQueries.end();
83        for (it = mOcclusionQueries.begin(); it != it_end; ++ it)
84        {
85                PlatformOcclusionQuery *query = *it;
86                OGRE_DELETE(query);
87        }
[59]88
[187]89        mCurrentTestIdx = 0;
[903]90    mOcclusionQueries.clear();
[59]91}
92//-----------------------------------------------------------------------
93void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
94{
[86]95        static RenderOperation ro;
96
[92]97        SolidBoundingBox *solidBox = GetSolidBoundingBox();
[86]98       
99        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
[316]100        mSceneManager->useRenderableViewProjModeWrapper(solidBox);
[2455]101       
[115]102        // set no depth write, no color, no lighting material
[1486]103        mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0));
[92]104        solidBox->SetupBoundingBoxVertices(*box);
[2184]105
[92]106        solidBox->getRenderOperation(ro);
107        ro.srcRenderable = solidBox;
[2184]108
[92]109        mRenderSystem->_render(ro);
[59]110}
111//-----------------------------------------------------------------------
112void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
113{
114        mCamera = cam;
115}
116//-----------------------------------------------------------------------
[94]117void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
118{
119        mCullCamera = cullCam;
120}
121//-----------------------------------------------------------------------
[59]122GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
123{
[897]124        // create new query if there is no query left
[1595]125        if (mCurrentTestIdx == (int)mOcclusionQueries.size())
[59]126        {
127                mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
128        }
129       
130        return mOcclusionQueries[mCurrentTestIdx ++];
131}
132//-----------------------------------------------------------------------
[2306]133void PlatformHierarchyInterface::InitTraversal(Camera *cam,
134                                                                                           Camera *cullCam,
[158]135                                                                                           int leavePassesInQueue)
[59]136{
[155]137        GtpVisibility::HierarchyInterface::InitTraversal();
[121]138       
[2455]139        mOldNode = NULL;
[139]140        mLeavePassesInQueue = leavePassesInQueue;
[94]141
[121]142        mCamera = cam;
[925]143        // set culling camera for visualization
[121]144        mCullCamera = cullCam ? cullCam : cam;
[113]145
[726]146        mCameraPosition = mCullCamera->getDerivedPosition();
[121]147        // create materials for node visualization
[115]148        CreateNodeVizMaterials();
[59]149}
150//-----------------------------------------------------------------------
151void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
152{
153        mSceneManager = sm;
154}
155//-----------------------------------------------------------------------
156void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
157{
158        mRenderSystem = rsys;
159}
160//-----------------------------------------------------------------------
[85]161bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
162                                                                                                         bool &intersects)
[59]163{
164#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[94]165        return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
[59]166#else
167        return true;
168#endif
169}
170//-----------------------------------------------------------------------
[175]171GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueNodeOcclusionQuery(
[2318]172                                                                              GtpVisibility::HierarchyNode *node,
[2455]173                                                                                                                                                  const bool testGeometry)
[2278]174{
[59]175        // get next available test id
176        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
177
178        //-- the actual query test
179        query->BeginQuery();
[122]180       
[2455]181        if (testGeometry && IsLeaf(node))
[135]182        {
[2455]183                // if node is a leaf and was visible => will be rendered anyway.
184                // In this case we can also test with the real geometry.
[135]185                RenderNode(node);
186        }
[2455]187        else
[89]188        {
[2455]189                if (mTestGeometryBounds && IsLeaf(node))
190                {
191                        mIsBoundingBoxQuery = true;
192                        // we can also test the tighter bounds of the geometry instead of the hierarchy nodes.
193                        RenderGeometryBounds(node);
194                        mIsBoundingBoxQuery = false;
195                }
196                else
197                {
198                        // this information is used e.g., by the scene graph, because the bounding box
199                        // must be treated differently to the scene geometry during rendering
200                        mIsBoundingBoxQuery = true;
201                        RenderBoundingBox(GetBoundingBox(node));
202                        mIsBoundingBoxQuery = false;
203                }
[89]204        }
[59]205
206        query->EndQuery();
207       
208        return query;
209}
[130]210//-----------------------------------------------------------------------
[175]211GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssuePatchOcclusionQuery(
[174]212        GtpVisibility::Patch *patch)
213{
214        // get next available test id
215        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
216
217        //-- the actual query test
218        query->BeginQuery();
219       
220        RenderPatch(patch);
221
222        query->EndQuery();
223
224        return query;
225}
226//-----------------------------------------------------------------------
[175]227GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueMeshOcclusionQuery(
[2254]228                                                                                                                GtpVisibility::Mesh *mesh)
[130]229{
230        // get next available test id
231        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
[1486]232       
233        ////////
234        //-- the actual query test
[130]235        query->BeginQuery();
[2455]236
[130]237        RenderGeometry(mesh);
[2455]238       
[130]239        query->EndQuery();
240
241        return query;
242}
[135]243//-----------------------------------------------------------------------
[92]244SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
[85]245{
[100]246        if (!mSolidBoundingBox)
[92]247                mSolidBoundingBox = new SolidBoundingBox;
[59]248
[92]249        return mSolidBoundingBox;
[85]250}
[103]251//-----------------------------------------------------------------------
252void PlatformHierarchyInterface::SetOnlyShadowCasters(bool onlyShadowCasters)
253{
254        mOnlyShadowCasters = onlyShadowCasters;
255}
[111]256//-----------------------------------------------------------------------
257bool PlatformHierarchyInterface::GetOnlyShadowCasters()
258{
259        return mOnlyShadowCasters;
260}
[120]261//-----------------------------------------------------------------------
[121]262bool PlatformHierarchyInterface::IsBoundingBoxQuery()
263{
264        return mIsBoundingBoxQuery;
265}
[130]266//-----------------------------------------------------------------------
267void PlatformHierarchyInterface::RenderGeometry(GtpVisibility::Mesh *geom)
268{
[139]269        mSceneManager->_renderMovableObject(geom, mLeavePassesInQueue);
[130]270}
271//-----------------------------------------------------------------------
[174]272void PlatformHierarchyInterface::RenderPatch(GtpVisibility::Patch *patch)
273{
[175]274        mSceneManager->_renderSingleRenderable(patch);
[174]275}
276//-----------------------------------------------------------------------
[130]277SceneManager *PlatformHierarchyInterface::GetSceneManager()
278{
279        return mSceneManager;
280}
281//-----------------------------------------------------------------------
282RenderSystem *PlatformHierarchyInterface::GetRenderSystem()
283{
284        return mRenderSystem;
285}
[2455]286//-----------------------------------------------------------------------
287void PlatformHierarchyInterface::SetTestGeometryBounds(bool testGeometryBounds)
288{
289        mTestGeometryBounds = testGeometryBounds;
290}
291//-----------------------------------------------------------------------
292int PlatformHierarchyInterface::GetTestGeometryBounds()
293{
294        return mTestGeometryBounds;
295}
[174]296
[135]297} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.