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