[59] | 1 | #include <OgreCamera.h>
|
---|
[94] | 2 | #include <OgreLogManager.h>
|
---|
[130] | 3 | #include <OgreSubEntity.h>
|
---|
| 4 | #include <OgreEntity.h>
|
---|
| 5 | #include <OgreMovableObject.h>
|
---|
[897] | 6 | #include <OgreMaterialManager.h>
|
---|
[92] | 7 | #include "OgreSolidBoundingBox.h"
|
---|
[59] | 8 | #include "OgrePlatformHierarchyInterface.h"
|
---|
| 9 | #include "OgrePlatformOcclusionQuery.h"
|
---|
| 10 |
|
---|
| 11 | namespace Ogre {
|
---|
| 12 |
|
---|
| 13 | //-----------------------------------------------------------------------
|
---|
[726] | 14 | PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm,
|
---|
| 15 | RenderSystem *rsys):
|
---|
| 16 | mSceneManager(sm),
|
---|
| 17 | mRenderSystem(rsys),
|
---|
| 18 | mSolidBoundingBox(NULL),
|
---|
| 19 | mCamera(NULL),
|
---|
| 20 | mCullCamera(NULL),
|
---|
| 21 | mOnlyShadowCasters(false),
|
---|
| 22 | mLeavePassesInQueue(0),
|
---|
| 23 | mIsBoundingBoxQuery(false),
|
---|
| 24 | mCameraPosition(Vector3(0, 0, 0))
|
---|
[85] | 25 | {
|
---|
[59] | 26 | }
|
---|
| 27 | //-----------------------------------------------------------------------
|
---|
[115] | 28 | void PlatformHierarchyInterface::CreateNodeVizMaterials()
|
---|
[112] | 29 | {
|
---|
| 30 | // material for frustum culled nodes
|
---|
| 31 | MaterialPtr mat = MaterialManager::getSingleton().getByName("FrustumCulledNodesMaterial");
|
---|
[113] | 32 |
|
---|
[112] | 33 | if (mat.isNull())
|
---|
| 34 | {
|
---|
| 35 | mat = MaterialManager::getSingleton().create("FrustumCulledNodesMaterial",
|
---|
| 36 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
[113] | 37 | mat->createTechnique()->createPass();
|
---|
| 38 |
|
---|
[115] | 39 | mat->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0);
|
---|
[113] | 40 | mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
|
---|
| 41 | //mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
|
---|
| 42 | mat->load();
|
---|
[112] | 43 | }
|
---|
| 44 |
|
---|
| 45 | // material for query culled nodes
|
---|
[113] | 46 | mat = MaterialManager::getSingleton().getByName("QueryCulledNodesMaterial");
|
---|
[112] | 47 |
|
---|
[113] | 48 | if (mat.isNull())
|
---|
[112] | 49 | {
|
---|
[113] | 50 | mat = MaterialManager::getSingleton().create("QueryCulledNodesMaterial",
|
---|
[112] | 51 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
[113] | 52 | mat->createTechnique()->createPass();
|
---|
| 53 |
|
---|
[115] | 54 | mat->getTechnique(0)->getPass(0)->setAmbient(0, 0, 1);
|
---|
[113] | 55 | mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
|
---|
| 56 | mat->load();
|
---|
[112] | 57 | }
|
---|
[115] | 58 |
|
---|
| 59 | // material for scene nodes
|
---|
| 60 | /*mat = MaterialManager::getSingleton().getByName("SceneNodesMaterial");
|
---|
| 61 |
|
---|
| 62 | if (mat.isNull())
|
---|
| 63 | {
|
---|
| 64 | mat = MaterialManager::getSingleton().create("SceneNodesMaterial",
|
---|
| 65 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 66 | mat->createTechnique()->createPass();
|
---|
| 67 |
|
---|
| 68 | mat->getTechnique(0)->getPass(0)->setAmbient(1, 1, 0);
|
---|
| 69 | mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
|
---|
| 70 | mat->load();
|
---|
| 71 | }*/
|
---|
[112] | 72 | }
|
---|
| 73 | //-----------------------------------------------------------------------
|
---|
[59] | 74 | PlatformHierarchyInterface::~PlatformHierarchyInterface()
|
---|
| 75 | {
|
---|
[897] | 76 | ResetQueries();
|
---|
[59] | 77 |
|
---|
[187] | 78 | OGRE_DELETE(mSolidBoundingBox);
|
---|
[59] | 79 | }
|
---|
| 80 | //-----------------------------------------------------------------------
|
---|
[897] | 81 | void PlatformHierarchyInterface::ResetQueries()
|
---|
[59] | 82 | {
|
---|
[938] | 83 | OcclusionQueryContainer::iterator it, it_end = mOcclusionQueries.end();
|
---|
| 84 | for (it = mOcclusionQueries.begin(); it != it_end; ++ it)
|
---|
| 85 | {
|
---|
| 86 | PlatformOcclusionQuery *query = *it;
|
---|
| 87 | OGRE_DELETE(query);
|
---|
| 88 | }
|
---|
[59] | 89 |
|
---|
[187] | 90 | mCurrentTestIdx = 0;
|
---|
[903] | 91 | mOcclusionQueries.clear();
|
---|
[59] | 92 | }
|
---|
| 93 | //-----------------------------------------------------------------------
|
---|
| 94 | void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
|
---|
| 95 | {
|
---|
[86] | 96 | static RenderOperation ro;
|
---|
| 97 |
|
---|
[92] | 98 | SolidBoundingBox *solidBox = GetSolidBoundingBox();
|
---|
[86] | 99 |
|
---|
| 100 | mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
|
---|
[316] | 101 | mSceneManager->useRenderableViewProjModeWrapper(solidBox);
|
---|
[115] | 102 |
|
---|
| 103 | // set no depth write, no color, no lighting material
|
---|
[903] | 104 | mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
|
---|
| 105 | //mSceneManager->_setPass(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
|
---|
[121] | 106 | //SetOcclusionPass();
|
---|
[86] | 107 |
|
---|
[92] | 108 | solidBox->SetupBoundingBoxVertices(*box);
|
---|
| 109 |
|
---|
| 110 | solidBox->getRenderOperation(ro);
|
---|
| 111 | ro.srcRenderable = solidBox;
|
---|
| 112 | mRenderSystem->_render(ro);
|
---|
[59] | 113 | }
|
---|
| 114 | //-----------------------------------------------------------------------
|
---|
| 115 | void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
|
---|
| 116 | {
|
---|
| 117 | mCamera = cam;
|
---|
| 118 | }
|
---|
| 119 | //-----------------------------------------------------------------------
|
---|
[94] | 120 | void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
|
---|
| 121 | {
|
---|
| 122 | mCullCamera = cullCam;
|
---|
| 123 | }
|
---|
| 124 | //-----------------------------------------------------------------------
|
---|
[59] | 125 | GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
|
---|
| 126 | {
|
---|
[897] | 127 | // create new query if there is no query left
|
---|
[938] | 128 | if (mCurrentTestIdx == mOcclusionQueries.size())
|
---|
[59] | 129 | {
|
---|
| 130 | mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | return mOcclusionQueries[mCurrentTestIdx ++];
|
---|
| 134 | }
|
---|
| 135 | //-----------------------------------------------------------------------
|
---|
[158] | 136 | void PlatformHierarchyInterface::InitTraversal(Camera *cam, Camera *cullCam,
|
---|
| 137 | int leavePassesInQueue)
|
---|
[59] | 138 | {
|
---|
[155] | 139 | GtpVisibility::HierarchyInterface::InitTraversal();
|
---|
[121] | 140 |
|
---|
[155] | 141 | mSavedNode = NULL;
|
---|
[139] | 142 | mLeavePassesInQueue = leavePassesInQueue;
|
---|
[94] | 143 |
|
---|
[121] | 144 | mCamera = cam;
|
---|
[925] | 145 | // set culling camera for visualization
|
---|
[121] | 146 | mCullCamera = cullCam ? cullCam : cam;
|
---|
[113] | 147 |
|
---|
[726] | 148 | mCameraPosition = mCullCamera->getDerivedPosition();
|
---|
[121] | 149 | // create materials for node visualization
|
---|
[115] | 150 | CreateNodeVizMaterials();
|
---|
[59] | 151 | }
|
---|
| 152 | //-----------------------------------------------------------------------
|
---|
| 153 | void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
|
---|
| 154 | {
|
---|
| 155 | mSceneManager = sm;
|
---|
| 156 | }
|
---|
| 157 | //-----------------------------------------------------------------------
|
---|
| 158 | void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
|
---|
| 159 | {
|
---|
| 160 | mRenderSystem = rsys;
|
---|
| 161 | }
|
---|
| 162 | //-----------------------------------------------------------------------
|
---|
[85] | 163 | bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
|
---|
| 164 | bool &intersects)
|
---|
[59] | 165 | {
|
---|
| 166 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
[94] | 167 | return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
|
---|
[59] | 168 | #else
|
---|
| 169 | return true;
|
---|
| 170 | #endif
|
---|
| 171 | }
|
---|
| 172 | //-----------------------------------------------------------------------
|
---|
[175] | 173 | GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueNodeOcclusionQuery(
|
---|
[86] | 174 | GtpVisibility::HierarchyNode *node, const bool wasVisible)
|
---|
[59] | 175 | {
|
---|
| 176 | // get next available test id
|
---|
| 177 | GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
|
---|
| 178 |
|
---|
| 179 | //-- the actual query test
|
---|
| 180 | query->BeginQuery();
|
---|
[122] | 181 |
|
---|
[135] | 182 | // if node is leaf and was visible => will be rendered anyway.
|
---|
| 183 | // In this case we can also test with the real geometry.
|
---|
| 184 | // If camera for culling is different from camera for rendering or only solids
|
---|
| 185 | // will be rendereded => cannot optimize
|
---|
[155] | 186 | if (mTestGeometryForVisibleLeaves && (mCamera == mCullCamera) && wasVisible && IsLeaf(node))
|
---|
[135] | 187 | {
|
---|
| 188 | //LogManager::getSingleton().logMessage("render node\n");
|
---|
| 189 | RenderNode(node);
|
---|
| 190 | }
|
---|
[86] | 191 | else
|
---|
[89] | 192 | {
|
---|
[135] | 193 | // this information is used e.g., by the scene graph, because the bounding box
|
---|
| 194 | // must be treated differently to the scene geometry during rendering
|
---|
[121] | 195 | mIsBoundingBoxQuery = true;
|
---|
[130] | 196 |
|
---|
[94] | 197 | //LogManager::getSingleton().logMessage("render box\n");
|
---|
[86] | 198 | RenderBoundingBox(GetBoundingBox(node));
|
---|
[121] | 199 |
|
---|
| 200 | mIsBoundingBoxQuery = false;
|
---|
[89] | 201 | }
|
---|
[59] | 202 |
|
---|
| 203 | query->EndQuery();
|
---|
| 204 |
|
---|
| 205 | return query;
|
---|
| 206 | }
|
---|
[130] | 207 | //-----------------------------------------------------------------------
|
---|
[175] | 208 | GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssuePatchOcclusionQuery(
|
---|
[174] | 209 | GtpVisibility::Patch *patch)
|
---|
| 210 | {
|
---|
| 211 | // get next available test id
|
---|
| 212 | GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
|
---|
| 213 |
|
---|
| 214 | //-- the actual query test
|
---|
| 215 | query->BeginQuery();
|
---|
| 216 |
|
---|
| 217 | RenderPatch(patch);
|
---|
| 218 |
|
---|
| 219 | query->EndQuery();
|
---|
| 220 |
|
---|
| 221 | return query;
|
---|
| 222 | }
|
---|
| 223 | //-----------------------------------------------------------------------
|
---|
[175] | 224 | GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueMeshOcclusionQuery(
|
---|
[159] | 225 | GtpVisibility::Mesh *mesh)
|
---|
[130] | 226 | {
|
---|
| 227 | // get next available test id
|
---|
| 228 | GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
|
---|
| 229 |
|
---|
| 230 | //-- the actual query test
|
---|
| 231 | query->BeginQuery();
|
---|
| 232 |
|
---|
| 233 | RenderGeometry(mesh);
|
---|
| 234 |
|
---|
| 235 | query->EndQuery();
|
---|
| 236 |
|
---|
| 237 | return query;
|
---|
| 238 | }
|
---|
[135] | 239 | //-----------------------------------------------------------------------
|
---|
| 240 | /*void PlatformHierarchyInterface::SetOcclusionPass()
|
---|
| 241 | {
|
---|
| 242 | // disable vertex and fragment program
|
---|
| 243 | mRenderSystem->unbindGpuProgram(GPT_VERTEX_PROGRAM);
|
---|
| 244 | mRenderSystem->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
|
---|
| 245 |
|
---|
| 246 | // disable lighting
|
---|
| 247 | mRenderSystem->setLightingEnabled(false);
|
---|
| 248 |
|
---|
| 249 | // Disable remaining texture units
|
---|
| 250 | mRenderSystem->_disableTextureUnitsFrom(0);
|
---|
| 251 |
|
---|
| 252 | //--Set up non-texture related material settings
|
---|
| 253 |
|
---|
| 254 | // Depth buffer settings
|
---|
| 255 | mRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS_EQUAL);
|
---|
| 256 | // Set colour write mode off
|
---|
| 257 | mRenderSystem->_setColourBufferWriteEnabled(false, false, false, false);
|
---|
[130] | 258 | }*/
|
---|
[85] | 259 | //-----------------------------------------------------------------------
|
---|
[92] | 260 | SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
|
---|
[85] | 261 | {
|
---|
[100] | 262 | if (!mSolidBoundingBox)
|
---|
[92] | 263 | mSolidBoundingBox = new SolidBoundingBox;
|
---|
[59] | 264 |
|
---|
[92] | 265 | return mSolidBoundingBox;
|
---|
[85] | 266 | }
|
---|
[103] | 267 | //-----------------------------------------------------------------------
|
---|
| 268 | void PlatformHierarchyInterface::SetOnlyShadowCasters(bool onlyShadowCasters)
|
---|
| 269 | {
|
---|
| 270 | mOnlyShadowCasters = onlyShadowCasters;
|
---|
| 271 | }
|
---|
[111] | 272 | //-----------------------------------------------------------------------
|
---|
| 273 | bool PlatformHierarchyInterface::GetOnlyShadowCasters()
|
---|
| 274 | {
|
---|
| 275 | return mOnlyShadowCasters;
|
---|
| 276 | }
|
---|
[120] | 277 | //-----------------------------------------------------------------------
|
---|
[155] | 278 | bool PlatformHierarchyInterface::GetTestGeometryForVisibleLeaves()
|
---|
[120] | 279 | {
|
---|
[155] | 280 | return mTestGeometryForVisibleLeaves;
|
---|
[120] | 281 | }
|
---|
[121] | 282 | //-----------------------------------------------------------------------
|
---|
| 283 | bool PlatformHierarchyInterface::IsBoundingBoxQuery()
|
---|
| 284 | {
|
---|
| 285 | return mIsBoundingBoxQuery;
|
---|
| 286 | }
|
---|
[130] | 287 | //-----------------------------------------------------------------------
|
---|
| 288 | void PlatformHierarchyInterface::RenderGeometry(GtpVisibility::Mesh *geom)
|
---|
| 289 | {
|
---|
[139] | 290 | mSceneManager->_renderMovableObject(geom, mLeavePassesInQueue);
|
---|
[130] | 291 | }
|
---|
| 292 | //-----------------------------------------------------------------------
|
---|
[174] | 293 | void PlatformHierarchyInterface::RenderPatch(GtpVisibility::Patch *patch)
|
---|
| 294 | {
|
---|
[175] | 295 | mSceneManager->_renderSingleRenderable(patch);
|
---|
[174] | 296 | }
|
---|
| 297 | //-----------------------------------------------------------------------
|
---|
[130] | 298 | SceneManager *PlatformHierarchyInterface::GetSceneManager()
|
---|
| 299 | {
|
---|
| 300 | return mSceneManager;
|
---|
| 301 | }
|
---|
| 302 | //-----------------------------------------------------------------------
|
---|
| 303 | RenderSystem *PlatformHierarchyInterface::GetRenderSystem()
|
---|
| 304 | {
|
---|
| 305 | return mRenderSystem;
|
---|
| 306 | }
|
---|
[174] | 307 |
|
---|
[135] | 308 | } // namespace Ogre
|
---|