source: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp @ 316

Revision 316, 9.5 KB checked in by mattausch, 19 years ago (diff)

queries are realized as templates

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