//#include //#include #include #include "OgreSolidHalfBoundingBox.h" #include "OgrePlatformHierarchyInterface.h" #include "OgrePlatformOcclusionQuery.h" #include namespace Ogre { //----------------------------------------------------------------------- PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys): mSceneManager(sm), mRenderSystem(rsys), mSolidHalfBoundingBox(NULL) { } //----------------------------------------------------------------------- PlatformHierarchyInterface::~PlatformHierarchyInterface() { DeleteQueries(); if(mSolidHalfBoundingBox) delete mSolidHalfBoundingBox; } //----------------------------------------------------------------------- void PlatformHierarchyInterface::DeleteQueries() { for(int i=0; i < (int)mOcclusionQueries.size(); ++i) delete mOcclusionQueries[i]; mOcclusionQueries.clear(); } //----------------------------------------------------------------------- void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box) { static RenderOperation ro; //TODO: this should be the full bounding box SolidHalfBoundingBox *halfbox = GetSolidHalfBoundingBox(); mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY); mSceneManager->useRenderableViewProjMode(halfbox); mSceneManager->setPass(halfbox->getTechnique()->getPass(0)); // Render two halfes of the bounding box (using triangle fans) for(int halfIdx = 0; halfIdx < 2; ++halfIdx) { halfbox->SetupBoundingBoxVertices(*box, halfIdx == 1); halfbox->getRenderOperation(ro); ro.srcRenderable = halfbox; mRenderSystem->_render(ro); } } //----------------------------------------------------------------------- void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam) { mCamera = cam; } //----------------------------------------------------------------------- GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery() { if(mCurrentTestIdx == mOcclusionQueries.size()) { mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem)); } return mOcclusionQueries[mCurrentTestIdx ++]; } //----------------------------------------------------------------------- void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam) { GtpVisibility::HierarchyInterface::InitFrame(root); mPreviousNode = NULL; SetCamera(cam); } //----------------------------------------------------------------------- void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm) { mSceneManager = sm; } //----------------------------------------------------------------------- void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys) { mRenderSystem = rsys; } //----------------------------------------------------------------------- bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node, bool &intersects) { #ifdef GTP_VISIBILITY_MODIFIED_OGRE return mCamera->isVisible(*GetBoundingBox(node), intersects); #else return true; #endif } //----------------------------------------------------------------------- GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery( GtpVisibility::HierarchyNode *node, const bool wasVisible) { // get next available test id GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery(); //-- the actual query test query->BeginQuery(); // if node is leaf and was visible => // will be rendered anyway. // In this case we can also test with the real geometry. /*if(mUseOptimization && wasVisible && IsLeaf(node)) { RenderNode(node); } else {*/ RenderBoundingBox(GetBoundingBox(node)); //} query->EndQuery(); return query; } //----------------------------------------------------------------------- SolidHalfBoundingBox *PlatformHierarchyInterface::GetSolidHalfBoundingBox() { if(!mSolidHalfBoundingBox) mSolidHalfBoundingBox = new SolidHalfBoundingBox; return mSolidHalfBoundingBox; } } // namespace Ogre