source: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp @ 159

Revision 159, 9.1 KB checked in by mattausch, 19 years ago (diff)

added flags for switching on/off transparents for item buffer and vertex programs for depth pass / item buffer

RevLine 
[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
10namespace Ogre {
11
12//-----------------------------------------------------------------------
[74]13PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
[121]14mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL), mCamera(NULL),
[139]15mCullCamera(NULL), mOnlyShadowCasters(false), mLeavePassesInQueue(0),
[121]16mIsBoundingBoxQuery(false)
[85]17{
[59]18}
19//-----------------------------------------------------------------------
[115]20void 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]66PlatformHierarchyInterface::~PlatformHierarchyInterface()
67{
68        DeleteQueries();
69
[100]70        if (mSolidBoundingBox)
[92]71                delete mSolidBoundingBox;
[59]72}
73//-----------------------------------------------------------------------
74void 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//-----------------------------------------------------------------------
82void 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//-----------------------------------------------------------------------
112void PlatformHierarchyInterface::SetCamera(Ogre::Camera *cam)
113{
114        mCamera = cam;
115}
116//-----------------------------------------------------------------------
[94]117void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
118{
119        mCullCamera = cullCam;
120}
121//-----------------------------------------------------------------------
[59]122GtpVisibility::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//-----------------------------------------------------------------------
[158]132void PlatformHierarchyInterface::InitTraversal(Camera *cam, Camera *cullCam,
133                                                                                           int leavePassesInQueue)
[59]134{
[155]135        GtpVisibility::HierarchyInterface::InitTraversal();
[121]136       
[155]137        mSavedNode = NULL;
[139]138        mLeavePassesInQueue = leavePassesInQueue;
[94]139
[121]140        mCamera = cam;
141        mCullCamera = cullCam ? cullCam : cam;
[113]142
[121]143        // create materials for node visualization
[115]144        CreateNodeVizMaterials();
[59]145}
146//-----------------------------------------------------------------------
147void PlatformHierarchyInterface::SetSceneManager(SceneManager *sm)
148{
149        mSceneManager = sm;
150}
151//-----------------------------------------------------------------------
152void PlatformHierarchyInterface::SetRenderSystem(RenderSystem *rsys)
153{
154        mRenderSystem = rsys;
155}
156//-----------------------------------------------------------------------
[85]157bool PlatformHierarchyInterface::CheckFrustumVisible(GtpVisibility::HierarchyNode *node,
158                                                                                                         bool &intersects)
[59]159{
160#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[94]161        return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
[59]162#else
163        return true;
164#endif
165}
166//-----------------------------------------------------------------------
[85]167GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(
[86]168        GtpVisibility::HierarchyNode *node, const bool wasVisible)
[59]169{
170        // get next available test id
171        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
172
173        //-- the actual query test
174        query->BeginQuery();
[122]175       
[135]176        // if node is leaf and was visible => will be rendered anyway.
177        // In this case we can also test with the real geometry.
178        // If camera for culling is different from camera for rendering or only solids
179        // will be rendereded => cannot optimize
[155]180        if (mTestGeometryForVisibleLeaves && (mCamera == mCullCamera) && wasVisible && IsLeaf(node))
[135]181        {
182                //LogManager::getSingleton().logMessage("render node\n");
183                RenderNode(node);
184        }
[86]185        else
[89]186        {
[135]187                // this information is used e.g., by the scene graph, because the bounding box
188                // must be treated differently to the scene geometry during rendering
[121]189                mIsBoundingBoxQuery = true;
[130]190
[94]191                //LogManager::getSingleton().logMessage("render box\n");
[86]192                RenderBoundingBox(GetBoundingBox(node));
[121]193
194                mIsBoundingBoxQuery = false;
[89]195        }
[59]196
197        query->EndQuery();
198       
199        return query;
200}
[130]201//-----------------------------------------------------------------------
[159]202GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(
203        GtpVisibility::Mesh *mesh)
[130]204{
205        // get next available test id
206        GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
207
208        //-- the actual query test
209        query->BeginQuery();
210       
211        RenderGeometry(mesh);
212
213        query->EndQuery();
214
215        return query;
216}
[135]217//-----------------------------------------------------------------------
218/*void PlatformHierarchyInterface::SetOcclusionPass()
219{
220    // disable vertex and fragment program
221        mRenderSystem->unbindGpuProgram(GPT_VERTEX_PROGRAM);
222        mRenderSystem->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
223       
224        // disable lighting
225        mRenderSystem->setLightingEnabled(false);
226
227    // Disable remaining texture units
228    mRenderSystem->_disableTextureUnitsFrom(0);
229
230    //--Set up non-texture related material settings
231   
232        // Depth buffer settings
233        mRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS_EQUAL);
234        // Set colour write mode off
235        mRenderSystem->_setColourBufferWriteEnabled(false, false, false, false);
[130]236}*/
[85]237//-----------------------------------------------------------------------
[92]238SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
[85]239{
[100]240        if (!mSolidBoundingBox)
[92]241                mSolidBoundingBox = new SolidBoundingBox;
[59]242
[92]243        return mSolidBoundingBox;
[85]244}
[103]245//-----------------------------------------------------------------------
246void PlatformHierarchyInterface::SetOnlyShadowCasters(bool onlyShadowCasters)
247{
248        mOnlyShadowCasters = onlyShadowCasters;
249}
[111]250//-----------------------------------------------------------------------
251bool PlatformHierarchyInterface::GetOnlyShadowCasters()
252{
253        return mOnlyShadowCasters;
254}
[120]255//-----------------------------------------------------------------------
[155]256bool PlatformHierarchyInterface::GetTestGeometryForVisibleLeaves()
[120]257{
[155]258        return mTestGeometryForVisibleLeaves;
[120]259}
[121]260//-----------------------------------------------------------------------
261bool PlatformHierarchyInterface::IsBoundingBoxQuery()
262{
263        return mIsBoundingBoxQuery;
264}
[130]265//-----------------------------------------------------------------------
266void PlatformHierarchyInterface::RenderGeometry(GtpVisibility::Mesh *geom)
267{
[139]268        mSceneManager->_renderMovableObject(geom, mLeavePassesInQueue);
[130]269}
270//-----------------------------------------------------------------------
271SceneManager *PlatformHierarchyInterface::GetSceneManager()
272{
273        return mSceneManager;
274}
275//-----------------------------------------------------------------------
276RenderSystem *PlatformHierarchyInterface::GetRenderSystem()
277{
278        return mRenderSystem;
279}
[135]280} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.