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

Revision 74, 4.1 KB checked in by mattausch, 19 years ago (diff)

added support for release mode

Line 
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
9namespace Ogre {
10
11//-----------------------------------------------------------------------
12PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
13mSceneManager(sm), mRenderSystem(rsys)
14{               
15        mHalfBoundingBox[0] = mHalfBoundingBox[1] = NULL;
16}
17//-----------------------------------------------------------------------
18PlatformHierarchyInterface::~PlatformHierarchyInterface()
19{
20        DeleteQueries();
21       
22        if (mHalfBoundingBox[0])
23                delete mHalfBoundingBox[0];
24
25        if (mHalfBoundingBox[1])
26                delete mHalfBoundingBox[1];
27}
28//-----------------------------------------------------------------------
29void PlatformHierarchyInterface::DeleteQueries()
30{
31        for(unsigned int i=0; i < (unsigned int)mOcclusionQueries.size(); ++i)
32                delete mOcclusionQueries[i];
33
34        mOcclusionQueries.clear();
35}
36//-----------------------------------------------------------------------
37void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
38{
39        // Render two halfes of the bounding box (using triangle fans)
40        for(int half = 0; half < 2; half ++)
41        {
42                static Matrix4 xform[256];
43                //TODO: this should be full bounding box
44                SolidHalfBoundingBox *halfbox = GetSolidHalfBoundingBox(half);
45                halfbox->setupBoundingBox(*box);
46               
47                mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
48               
49                static RenderOperation ro;
50
51        mSceneManager->useRenderableViewProjMode(halfbox);
52                mSceneManager->setPass(halfbox->getTechnique()->getPass(0));
53                halfbox->getRenderOperation(ro);
54                ro.srcRenderable = halfbox;
55                mRenderSystem->_render(ro);
56               
57                // matt: change this
58//              mSceneManager->myrenderSingleObject(getSolidHalfBoundingBox(half),
59//                      getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), true);
60        }
61}
62//-----------------------------------------------------------------------
63SolidHalfBoundingBox *PlatformHierarchyInterface::GetSolidHalfBoundingBox(int half)
64{
65        if(!mHalfBoundingBox[half])
66                mHalfBoundingBox[half] = new Ogre::SolidHalfBoundingBox(half == 1);
67
68        return mHalfBoundingBox[half]; 
69}
70//-----------------------------------------------------------------------
71void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
72{
73        mCamera = cam;
74}
75//-----------------------------------------------------------------------
76GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
77{
78        if(mCurrentTestIdx == mOcclusionQueries.size())
79        {
80                mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
81        }
82       
83        return mOcclusionQueries[mCurrentTestIdx ++];
84}
85//-----------------------------------------------------------------------
86void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam)
87{
88        GtpVisibility::HierarchyInterface::InitFrame(root);
89        SetCamera(cam);
90}
91//-----------------------------------------------------------------------
92void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
93{
94        mSceneManager = sm;
95}
96//-----------------------------------------------------------------------
97void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
98{
99        mRenderSystem = rsys;
100}
101//-----------------------------------------------------------------------
102bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node, bool &intersects)
103{
104#ifdef GTP_VISIBILITY_MODIFIED_OGRE
105        return mCamera->isVisible(*GetBoundingBox(node), intersects);
106#else
107        return true;
108#endif
109}
110//-----------------------------------------------------------------------
111GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(GtpVisibility::HierarchyNode *node)
112{
113        // get next available test id
114        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
115
116        //-- the actual query test
117        query->BeginQuery();
118                       
119        RenderBoundingBox(GetBoundingBox(node));
120
121        query->EndQuery();
122       
123        return query;
124}
125
126} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.