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

Revision 726, 9.6 KB checked in by mattausch, 18 years ago (diff)

improved performance of TerrainSceneManager?
revisit octreescenemanager

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