source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp @ 1495

Revision 1495, 10.0 KB checked in by szydlowski, 18 years ago (diff)

added delete render queue for internal rendering

RevLine 
[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
11namespace Ogre {
12
13//-----------------------------------------------------------------------
[726]14PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm,
15                                                                                                           RenderSystem *rsys):
16mSceneManager(sm),
17mRenderSystem(rsys),
18mSolidBoundingBox(NULL),
19mCamera(NULL),
20mCullCamera(NULL),
21mOnlyShadowCasters(false),
22mLeavePassesInQueue(0),
23mIsBoundingBoxQuery(false),
24mCameraPosition(Vector3(0, 0, 0))
[85]25{
[59]26}
27//-----------------------------------------------------------------------
[115]28void 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]74PlatformHierarchyInterface::~PlatformHierarchyInterface()
75{
[897]76        ResetQueries();
[187]77        OGRE_DELETE(mSolidBoundingBox);
[59]78}
79//-----------------------------------------------------------------------
[897]80void PlatformHierarchyInterface::ResetQueries()
[59]81{
[938]82        OcclusionQueryContainer::iterator it, it_end = mOcclusionQueries.end();
83        for (it = mOcclusionQueries.begin(); it != it_end; ++ it)
84        {
85                PlatformOcclusionQuery *query = *it;
86                OGRE_DELETE(query);
87        }
[59]88
[187]89        mCurrentTestIdx = 0;
[903]90    mOcclusionQueries.clear();
[59]91}
92//-----------------------------------------------------------------------
93void PlatformHierarchyInterface::RenderBoundingBox(AxisAlignedBox *box)
94{
[86]95        static RenderOperation ro;
96
[92]97        SolidBoundingBox *solidBox = GetSolidBoundingBox();
[86]98       
99        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
[316]100        mSceneManager->useRenderableViewProjModeWrapper(solidBox);
[1486]101        // HACK! (mySetPass should be setPass)
[115]102        // set no depth write, no color, no lighting material
[1486]103        mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0));
104        //mSceneManager->_setPass(solidBox->getTechnique()->getPass(0));
[121]105        //SetOcclusionPass();
[86]106
[92]107        solidBox->SetupBoundingBoxVertices(*box);
108                               
109        solidBox->getRenderOperation(ro);
110        ro.srcRenderable = solidBox;
111        mRenderSystem->_render(ro);
[59]112}
113//-----------------------------------------------------------------------
114void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
115{
116        mCamera = cam;
117}
118//-----------------------------------------------------------------------
[94]119void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
120{
121        mCullCamera = cullCam;
122}
123//-----------------------------------------------------------------------
[59]124GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
125{
[897]126        // create new query if there is no query left
[938]127        if (mCurrentTestIdx == mOcclusionQueries.size())
[59]128        {
129                mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
130        }
[1486]131
132        std::stringstream d;
[1495]133        d << "resizing queries: " << (int)mOcclusionQueries.size() << std::endl;
[1486]134        LogManager::getSingleton().logMessage(d.str());
[59]135       
136        return mOcclusionQueries[mCurrentTestIdx ++];
137}
138//-----------------------------------------------------------------------
[158]139void PlatformHierarchyInterface::InitTraversal(Camera *cam, Camera *cullCam,
140                                                                                           int leavePassesInQueue)
[59]141{
[155]142        GtpVisibility::HierarchyInterface::InitTraversal();
[121]143       
[155]144        mSavedNode = NULL;
[139]145        mLeavePassesInQueue = leavePassesInQueue;
[94]146
[121]147        mCamera = cam;
[925]148        // set culling camera for visualization
[121]149        mCullCamera = cullCam ? cullCam : cam;
[113]150
[726]151        mCameraPosition = mCullCamera->getDerivedPosition();
[121]152        // create materials for node visualization
[115]153        CreateNodeVizMaterials();
[59]154}
155//-----------------------------------------------------------------------
156void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
157{
158        mSceneManager = sm;
159}
160//-----------------------------------------------------------------------
161void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
162{
163        mRenderSystem = rsys;
164}
165//-----------------------------------------------------------------------
[85]166bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
167                                                                                                         bool &intersects)
[59]168{
169#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[94]170        return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
[59]171#else
172        return true;
173#endif
174}
175//-----------------------------------------------------------------------
[175]176GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueNodeOcclusionQuery(
[86]177        GtpVisibility::HierarchyNode *node, const bool wasVisible)
[59]178{
179        // get next available test id
180        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
181
182        //-- the actual query test
183        query->BeginQuery();
[122]184       
[135]185        // if node is leaf and was visible => will be rendered anyway.
186        // In this case we can also test with the real geometry.
187        // If camera for culling is different from camera for rendering or only solids
188        // will be rendereded => cannot optimize
[155]189        if (mTestGeometryForVisibleLeaves && (mCamera == mCullCamera) && wasVisible && IsLeaf(node))
[135]190        {
191                RenderNode(node);
192        }
[86]193        else
[89]194        {
[135]195                // this information is used e.g., by the scene graph, because the bounding box
196                // must be treated differently to the scene geometry during rendering
[121]197                mIsBoundingBoxQuery = true;
[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]208GtpVisibility::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]224GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueMeshOcclusionQuery(
[159]225        GtpVisibility::Mesh *mesh)
[130]226{
227        // get next available test id
228        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
[1486]229       
230        ////////
231        //-- the actual query test
[130]232
233        query->BeginQuery();
234        RenderGeometry(mesh);
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]260SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
[85]261{
[100]262        if (!mSolidBoundingBox)
[92]263                mSolidBoundingBox = new SolidBoundingBox;
[59]264
[92]265        return mSolidBoundingBox;
[85]266}
[103]267//-----------------------------------------------------------------------
268void PlatformHierarchyInterface::SetOnlyShadowCasters(bool onlyShadowCasters)
269{
270        mOnlyShadowCasters = onlyShadowCasters;
271}
[111]272//-----------------------------------------------------------------------
273bool PlatformHierarchyInterface::GetOnlyShadowCasters()
274{
275        return mOnlyShadowCasters;
276}
[120]277//-----------------------------------------------------------------------
[155]278bool PlatformHierarchyInterface::GetTestGeometryForVisibleLeaves()
[120]279{
[155]280        return mTestGeometryForVisibleLeaves;
[120]281}
[121]282//-----------------------------------------------------------------------
283bool PlatformHierarchyInterface::IsBoundingBoxQuery()
284{
285        return mIsBoundingBoxQuery;
286}
[130]287//-----------------------------------------------------------------------
288void PlatformHierarchyInterface::RenderGeometry(GtpVisibility::Mesh *geom)
289{
[139]290        mSceneManager->_renderMovableObject(geom, mLeavePassesInQueue);
[130]291}
292//-----------------------------------------------------------------------
[174]293void PlatformHierarchyInterface::RenderPatch(GtpVisibility::Patch *patch)
294{
[175]295        mSceneManager->_renderSingleRenderable(patch);
[174]296}
297//-----------------------------------------------------------------------
[130]298SceneManager *PlatformHierarchyInterface::GetSceneManager()
299{
300        return mSceneManager;
301}
302//-----------------------------------------------------------------------
303RenderSystem *PlatformHierarchyInterface::GetRenderSystem()
304{
305        return mRenderSystem;
306}
[174]307
[135]308} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.