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

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