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