//#include //#include #include #include "OgreSolidHalfBoundingBox.h" #include "OgrePlatformHierarchyInterface.h" #include "OgrePlatformOcclusionQuery.h" namespace Ogre { //----------------------------------------------------------------------- PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys): mSceneManager(sm), mRenderSystem(rsys) { mHalfBoundingBox[0] = mHalfBoundingBox[1] = NULL; } //----------------------------------------------------------------------- PlatformHierarchyInterface::~PlatformHierarchyInterface() { DeleteQueries(); if (mHalfBoundingBox[0]) delete mHalfBoundingBox[0]; if (mHalfBoundingBox[1]) delete mHalfBoundingBox[1]; } //----------------------------------------------------------------------- void PlatformHierarchyInterface::DeleteQueries() { for(unsigned int i=0; i < (unsigned int)mOcclusionQueries.size(); ++i) delete mOcclusionQueries[i]; mOcclusionQueries.clear(); } //----------------------------------------------------------------------- void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box) { // Render two halfes of the bounding box (using triangle fans) for(int half = 0; half < 2; half ++) { static Matrix4 xform[256]; //TODO: this should be full bounding box SolidHalfBoundingBox *halfbox = GetSolidHalfBoundingBox(half); halfbox->setupBoundingBox(*box); mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY); static RenderOperation ro; mSceneManager->useRenderableViewProjMode(halfbox); mSceneManager->setPass(halfbox->getTechnique()->getPass(0)); halfbox->getRenderOperation(ro); ro.srcRenderable = halfbox; mRenderSystem->_render(ro); // matt: change this // mSceneManager->myrenderSingleObject(getSolidHalfBoundingBox(half), // getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), true); } } //----------------------------------------------------------------------- SolidHalfBoundingBox *PlatformHierarchyInterface::GetSolidHalfBoundingBox(int half) { if(!mHalfBoundingBox[half]) mHalfBoundingBox[half] = new Ogre::SolidHalfBoundingBox(half == 1); return mHalfBoundingBox[half]; } //----------------------------------------------------------------------- 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); 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) { // get next available test id GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery(); //-- the actual query test query->BeginQuery(); RenderBoundingBox(GetBoundingBox(node)); query->EndQuery(); return query; } } // namespace Ogre