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

Revision 120, 7.7 KB checked in by mattausch, 19 years ago (diff)
RevLine 
[59]1#include <OgreCamera.h>
[94]2#include <OgreLogManager.h>
[92]3#include "OgreSolidBoundingBox.h"
[59]4#include "OgrePlatformHierarchyInterface.h"
5#include "OgrePlatformOcclusionQuery.h"
6
7namespace Ogre {
8
9//-----------------------------------------------------------------------
[74]10PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
[94]11mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL),
[115]12mCamera(NULL), mCullCamera(NULL), mOnlyShadowCasters(false), mLeaveTransparentsInQueue(false)
[85]13{
[59]14}
15//-----------------------------------------------------------------------
[115]16void PlatformHierarchyInterface::CreateNodeVizMaterials()
[112]17{
18        // material for frustum culled nodes
19        MaterialPtr mat = MaterialManager::getSingleton().getByName("FrustumCulledNodesMaterial");
[113]20       
[112]21        if (mat.isNull())
22        {
23                mat = MaterialManager::getSingleton().create("FrustumCulledNodesMaterial",
24                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
[113]25                mat->createTechnique()->createPass();
26               
[115]27                mat->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0);
[113]28                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
29                //mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
30                mat->load();
[112]31        }
32
33        // material for query culled nodes
[113]34        mat = MaterialManager::getSingleton().getByName("QueryCulledNodesMaterial");
[112]35
[113]36        if (mat.isNull())
[112]37        {
[113]38                mat = MaterialManager::getSingleton().create("QueryCulledNodesMaterial",
[112]39                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
[113]40                mat->createTechnique()->createPass();
41               
[115]42                mat->getTechnique(0)->getPass(0)->setAmbient(0, 0, 1);
[113]43                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
44                mat->load();
[112]45        }
[115]46
47        // material for scene nodes
48        /*mat = MaterialManager::getSingleton().getByName("SceneNodesMaterial");
49
50        if (mat.isNull())
51        {
52                mat = MaterialManager::getSingleton().create("SceneNodesMaterial",
53                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
54                mat->createTechnique()->createPass();
55               
56                mat->getTechnique(0)->getPass(0)->setAmbient(1, 1, 0);
57                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
58                mat->load();
59        }*/
[112]60}
61//-----------------------------------------------------------------------
[59]62PlatformHierarchyInterface::~PlatformHierarchyInterface()
63{
64        DeleteQueries();
65
[100]66        if (mSolidBoundingBox)
[92]67                delete mSolidBoundingBox;
[59]68}
69//-----------------------------------------------------------------------
70void PlatformHierarchyInterface::DeleteQueries()
71{
[100]72        for (int i=0; i < (int)mOcclusionQueries.size(); ++i)
[59]73                delete mOcclusionQueries[i];
74
75        mOcclusionQueries.clear();
76}
77//-----------------------------------------------------------------------
78void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
79{
[86]80        static RenderOperation ro;
81
[92]82        SolidBoundingBox *solidBox = GetSolidBoundingBox();
[86]83       
84        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
[92]85        mSceneManager->useRenderableViewProjMode(solidBox);
[115]86       
87        // set no depth write, no color, no lighting material
[120]88        //mSceneManager->setPass(solidBox->getTechnique()->getPass(0));
89        SetOcclusionPass();
[86]90
[92]91        solidBox->SetupBoundingBoxVertices(*box);
92                               
93        solidBox->getRenderOperation(ro);
94        ro.srcRenderable = solidBox;
95        mRenderSystem->_render(ro);
96
[59]97        // Render two halfes of the bounding box (using triangle fans)
[92]98        /*for(int halfIdx = 0; halfIdx < 2; ++halfIdx)
[59]99        {
[92]100                solidBox->SetupBoundingBoxVertices(*box, halfIdx == 1);
[85]101                               
[92]102                solidBox->getRenderOperation(ro);
103                ro.srcRenderable = solidBox;
[91]104                mRenderSystem->_render(ro);
[92]105        }*/
[59]106}
107//-----------------------------------------------------------------------
108void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
109{
110        mCamera = cam;
111}
112//-----------------------------------------------------------------------
[94]113void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
114{
115        mCullCamera = cullCam;
116}
117//-----------------------------------------------------------------------
[59]118GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
119{
[100]120        if (mCurrentTestIdx == mOcclusionQueries.size())
[59]121        {
122                mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
123        }
124       
125        return mOcclusionQueries[mCurrentTestIdx ++];
126}
127//-----------------------------------------------------------------------
[103]128void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root,
[115]129                                                                                   Camera *cam, Camera *cullCam, bool leaveTransparentsInQueue)
[59]130{
131        GtpVisibility::HierarchyInterface::InitFrame(root);
[86]132        mPreviousNode = NULL;
[115]133        mLeaveTransparentsInQueue = leaveTransparentsInQueue;
[59]134        SetCamera(cam);
[94]135
[100]136        if (cullCam)
[103]137        {
[94]138                SetCullCamera(cullCam);
[103]139        }
[94]140        else
[103]141        {
[94]142                SetCullCamera(cam);
[103]143        }
[113]144
[115]145        CreateNodeVizMaterials();
[59]146}
147//-----------------------------------------------------------------------
148void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
149{
150        mSceneManager = sm;
151}
152//-----------------------------------------------------------------------
153void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
154{
155        mRenderSystem = rsys;
156}
157//-----------------------------------------------------------------------
[85]158bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
159                                                                                                         bool &intersects)
[59]160{
161#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[94]162        return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
[59]163#else
164        return true;
165#endif
166}
167//-----------------------------------------------------------------------
[85]168GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(
[86]169        GtpVisibility::HierarchyNode *node, const bool wasVisible)
[59]170{
171        // get next available test id
172        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
173
174        //-- the actual query test
175        query->BeginQuery();
176                       
[91]177        // if node is leaf and was visible => will be rendered anyway.
[87]178        // In this case we can also test with the real geometry.
[120]179        // If camera for culling is different from camera for rendering or only solids
180        // will be rendereded => cannot optimize
181        if (mUseOptimization && (mCamera == mCullCamera) && wasVisible && IsLeaf(node) )
[86]182        {
[94]183                //LogManager::getSingleton().logMessage("render node\n");
[86]184                RenderNode(node);
185        }
186        else
[89]187        {
[94]188                //LogManager::getSingleton().logMessage("render box\n");
[86]189                RenderBoundingBox(GetBoundingBox(node));
[89]190        }
[59]191
192        query->EndQuery();
193       
194        return query;
195}
[103]196//-----------------------------------------------------------------------
197void PlatformHierarchyInterface::SetOcclusionPass()
198{
199    // disable vertex and fragment program
200        mRenderSystem->unbindGpuProgram(GPT_VERTEX_PROGRAM);
201        mRenderSystem->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
202       
203        // disable lighting
204        mRenderSystem->setLightingEnabled(false);
205
206    // Disable remaining texture units
207    mRenderSystem->_disableTextureUnitsFrom(0);
208
209    //--Set up non-texture related material settings
210   
211        // Depth buffer settings
212        mRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS_EQUAL);
213        // Set colour write mode off
214        mRenderSystem->_setColourBufferWriteEnabled(false, false, false, false);
215}
[85]216//-----------------------------------------------------------------------
[92]217SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
[85]218{
[100]219        if (!mSolidBoundingBox)
[92]220                mSolidBoundingBox = new SolidBoundingBox;
[59]221
[92]222        return mSolidBoundingBox;
[85]223}
[103]224//-----------------------------------------------------------------------
225void PlatformHierarchyInterface::SetOnlyShadowCasters(bool onlyShadowCasters)
226{
227        mOnlyShadowCasters = onlyShadowCasters;
[112]228        //mIsShadowPass = mOnlyShadowCasters ;
[103]229}
[111]230//-----------------------------------------------------------------------
231bool PlatformHierarchyInterface::GetOnlyShadowCasters()
232{
233        return mOnlyShadowCasters;
234}
[120]235//-----------------------------------------------------------------------
236bool PlatformHierarchyInterface::GetUseOptimization()
237{
238        return mUseOptimization;
239}
[59]240} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.