Ignore:
Timestamp:
02/27/07 10:25:01 (17 years ago)
Author:
mattausch
Message:

implemented function for exact visibility queries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp

    r2170 r2171  
    2424#include "IVReader.h" 
    2525#include "ObjReader.h" 
    26  
     26#include "OgreOcclusionQueriesQueryManager.h" 
    2727 
    2828 
     
    194194        String val; 
    195195 
    196         LogManager::getSingleton().logMessage("****** OcclusionCullingSceneManager Options ********"); 
     196        LogManager::getSingleton(). 
     197                logMessage("****** OcclusionCullingSceneManager Options ********"); 
    197198        config.load(stream); 
    198199 
     
    717718                // because shadows have low occlusion anyway 
    718719                if ((mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&  
    719                         mIlluminationStage == IRS_RENDER_TO_TEXTURE) || 
     720                         mIlluminationStage == IRS_RENDER_TO_TEXTURE) || 
    720721                        mNormalExecution) 
    721722                { 
     
    772773        { 
    773774                // note matt: this is also called in TerrainSceneManager: really necessary? 
    774                 mDestRenderSystem -> setLightingEnabled(false); 
     775                mDestRenderSystem->setLightingEnabled(false); 
    775776 
    776777                if (mUseItemBuffer) 
     
    10771078                * static_cast<unsigned int *>(val) = (unsigned int)algorithm; 
    10781079 
    1079                 getRenderQueue()->clear(true); 
    1080  
     1080                //getRenderQueue()->clear(); 
     1081 
     1082                return true; 
     1083        } 
     1084        if (key == "VisibleObjects") 
     1085        {  
     1086                if (mNormalExecution) 
     1087                        return false; 
     1088 
     1089                const bool fromPoint = true; 
     1090                const bool nodeVisibility = true; 
     1091                 
     1092                * static_cast<unsigned int *>(val) =  
     1093                        (unsigned int)FindExactVisibleObjects(mCameraInProgress,  
     1094                                                                                                  mCurrentViewport,  
     1095                                                                                                  fromPoint,  
     1096                                                                                                  nodeVisibility); 
    10811097                return true; 
    10821098        } 
     
    18181834} 
    18191835//----------------------------------------------------------------------- 
    1820 void OcclusionCullingSceneManager::RenderDepthPass() 
    1821 { 
     1836void OcclusionCullingSceneManager::RenderDepthPass(const bool fillRenderQueue) 
     1837{ 
     1838        if (mNormalExecution) 
     1839        { 
     1840                // not in the normal workflow 
     1841                return; 
     1842        } 
     1843 
    18221844        // create material for depth pass 
    18231845        InitDepthPass(); 
     
    18531875        mLeavePassesInQueue = 0; 
    18541876                 
    1855         // the shaded geometry is rendered in a second pass 
    1856         // add visible nodes found by the visibility culling algorithm 
    1857         NodeList::const_iterator it, it_end = mVisible.end(); 
    1858  
    1859         if(1)  
    1860         for (it = mVisible.begin(); it != it_end; ++ it) 
    1861         { 
    1862                 (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 
     1877        if (fillRenderQueue) 
     1878        { 
     1879                // the shaded geometry is rendered in a second pass 
     1880                // add visible nodes found by the visibility culling algorithm 
     1881                NodeList::const_iterator it, it_end = mVisible.end(); 
     1882        for (it = mVisible.begin(); it != it_end; ++ it) 
     1883                { 
     1884                        (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 
     1885                } 
    18631886        } 
    18641887} 
     
    18871910 
    18881911//----------------------------------------------------------------------- 
    1889 void OcclusionCullingSceneManager::_renderScene(Camera* camera, Viewport* vp, bool includeOverlays) 
     1912void OcclusionCullingSceneManager::_renderScene(Camera* camera,  
     1913                                                                                                Viewport* vp,  
     1914                                                                                                bool includeOverlays) 
    18901915{ 
    18911916    Root::getSingleton()._setCurrentSceneManager(this); 
     
    20572082    camera->_notifyRenderedFaces(mDestRenderSystem->_getFaceCount()); 
    20582083} 
    2059  
     2084//----------------------------------------------------------------------- 
     2085int OcclusionCullingSceneManager::FindExactVisibleObjects(Camera *camera, 
     2086                                                                                                                  Viewport* vp, 
     2087                                                                                                                  const bool fromPoint, 
     2088                                                                                                                  const bool nodeVisibility) 
     2089{ 
     2090        const int itemBufferMode = 0; 
     2091        const bool relativeVisibility = false; 
     2092 
     2093        int queryModes = 0; 
     2094 
     2095        if (nodeVisibility) 
     2096                queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY; 
     2097        else 
     2098                queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY; 
     2099 
     2100        OcclusionQueriesQueryManager *queryManager =  
     2101                new OcclusionQueriesQueryManager(mHierarchyInterface, 
     2102                                                                                 vp, 
     2103                                                                                 queryModes,  
     2104                                                                                 itemBufferMode); 
     2105 
     2106        mVisibilityManager->SetQueryManager(queryManager); 
     2107 
     2108        GtpVisibility::NodeInfoContainer visibleNodes; 
     2109        GtpVisibility::MeshInfoContainer visibleGeometry; 
     2110        GtpVisibility::PatchInfoContainer visiblePatches; 
     2111 
     2112        if (fromPoint) 
     2113        { 
     2114                queryManager->ComputeFromPointVisibility(camera->getDerivedPosition(),  
     2115                                                                                                 &visibleNodes,  
     2116                                                                                                 &visibleGeometry,  
     2117                                                                                                 &visiblePatches,  
     2118                                                                                                 relativeVisibility); 
     2119        } 
     2120        else 
     2121        { 
     2122                queryManager->ComputeCameraVisibility(*camera, 
     2123                                                                                          &visibleNodes,  
     2124                                                                                          &visibleGeometry,  
     2125                                                                                          &visiblePatches,  
     2126                                                                                          relativeVisibility); 
     2127        } 
     2128                 
     2129        if (0) 
     2130        { 
     2131                std::stringstream d;  
     2132                d << "Query mode: " << queryModes  
     2133                  << " visible nodes: " << (int)visibleNodes.size()  
     2134                  << " visible geometry: " << (int)visibleGeometry.size(); 
     2135 
     2136                LogManager::getSingleton().logMessage(d.str()); 
     2137        } 
     2138 
     2139        /////////////////////// 
     2140        //-- put items in render queue 
     2141        ////////// 
     2142 
     2143        getRenderQueue()->clear(); 
     2144 
     2145        ////////////////////// 
     2146        //-- apply queries on geometry level 
     2147 
     2148        if (!nodeVisibility) 
     2149        { 
     2150                GtpVisibility::MeshInfoContainer::iterator geomIt, geomIt_end = visibleGeometry.end(); 
     2151 
     2152                for (geomIt = visibleGeometry.begin(); geomIt != geomIt_end; ++geomIt) 
     2153                { 
     2154                        MovableObject *mo = (*geomIt).GetSource(); 
     2155 
     2156                        // add if not 0 
     2157                        if (!(*geomIt).GetVisiblePixels()) 
     2158                                continue; 
     2159 
     2160                        mo->_notifyCurrentCamera(camera); 
     2161 
     2162                        if (mo->isVisible()) 
     2163                        { 
     2164                                mo->_updateRenderQueue(getRenderQueue()); 
     2165                        } 
     2166                } 
     2167        } 
     2168        else 
     2169        { 
     2170                //////////////// 
     2171                //-- apply queries on node level 
     2172 
     2173                GtpVisibility::NodeInfoContainer::iterator nodesIt, nodesIt_end = visibleNodes.end(); 
     2174 
     2175                for (nodesIt = visibleNodes.begin(); nodesIt != nodesIt_end; ++ nodesIt) 
     2176                { 
     2177                        if (!(*nodesIt).GetVisiblePixels()) 
     2178                                continue; 
     2179 
     2180                        Octree *octree = static_cast<Octree *>((*nodesIt).GetSource()); 
     2181 
     2182                        NodeList::iterator nIt, nIt_end = octree->mNodes.end(); 
     2183 
     2184                        for (nIt = octree->mNodes.begin(); nIt != nIt_end; ++ nIt) 
     2185                        { 
     2186                                (*nIt)->_addToRenderQueue(camera, getRenderQueue(), false); 
     2187                        } 
     2188                } 
     2189        } 
     2190 
     2191    delete queryManager; 
     2192 
     2193        if (nodeVisibility) 
     2194                return (int)visibleNodes.size(); 
     2195        else 
     2196                return (int)visibleGeometry.size(); 
     2197} 
     2198//----------------------------------------------------------------------- 
     2199void OcclusionCullingSceneManager::RenderDepthForQuery(Camera* camera,  
     2200                                                                                                           Viewport* vp) 
     2201{ 
     2202    Root::getSingleton()._setCurrentSceneManager(this); 
     2203        mActiveQueuedRenderableVisitor->targetSceneMgr = this; 
     2204 
     2205    mCameraInProgress = camera; 
     2206 
     2207    // Update scene graph for this camera (can happen multiple times per frame) 
     2208    _updateSceneGraph(camera); 
     2209 
     2210    // Invert vertex winding? 
     2211    if (camera->isReflected()) 
     2212    { 
     2213        mDestRenderSystem->setInvertVertexWinding(true); 
     2214    } 
     2215    else 
     2216    { 
     2217        mDestRenderSystem->setInvertVertexWinding(false); 
     2218    } 
     2219 
     2220    // Tell params about viewport 
     2221    mAutoParamDataSource.setCurrentViewport(vp); 
     2222    // Set the viewport 
     2223    setViewport(vp); 
     2224 
     2225    // Tell params about camera 
     2226    mAutoParamDataSource.setCurrentCamera(camera); 
     2227    // Set autoparams for finite dir light extrusion 
     2228    mAutoParamDataSource.setShadowDirLightExtrusionDistance(mShadowDirLightExtrudeDist); 
     2229 
     2230    // Tell params about current ambient light 
     2231    mAutoParamDataSource.setAmbientLightColour(mAmbientLight); 
     2232        // Tell rendersystem 
     2233        mDestRenderSystem->setAmbientLight(mAmbientLight.r, mAmbientLight.g, mAmbientLight.b); 
     2234 
     2235    // Tell params about render target 
     2236    mAutoParamDataSource.setCurrentRenderTarget(vp->getTarget()); 
     2237 
     2238 
     2239    // Set camera window clipping planes (if any) 
     2240    if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_USER_CLIP_PLANES)) 
     2241    { 
     2242        if (camera->isWindowSet())   
     2243        { 
     2244            const std::vector<Plane>& planeList =  
     2245                camera->getWindowPlanes(); 
     2246            for (ushort i = 0; i < 4; ++i) 
     2247            { 
     2248                mDestRenderSystem->enableClipPlane(i, true); 
     2249                mDestRenderSystem->setClipPlane(i, planeList[i]); 
     2250            } 
     2251        } 
     2252        else 
     2253        { 
     2254            for (ushort i = 0; i < 4; ++i) 
     2255            { 
     2256                mDestRenderSystem->enableClipPlane(i, false); 
     2257            } 
     2258        } 
     2259    } 
     2260 
     2261        // Prepare render queue for receiving new objects 
     2262        prepareRenderQueue(); 
     2263 
     2264        // Begin the frame 
     2265    mDestRenderSystem->_beginFrame(); 
     2266 
     2267    // Set rasterisation mode 
     2268    mDestRenderSystem->_setPolygonMode(camera->getPolygonMode()); 
     2269 
     2270        // Set initial camera state 
     2271        mDestRenderSystem->_setProjectionMatrix(mCameraInProgress->getProjectionMatrixRS()); 
     2272        mDestRenderSystem->_setViewMatrix(mCameraInProgress->getViewMatrix(true)); 
     2273 
     2274        // // Render scene content in order fill depth buffer 
     2275        bool savedUseDepthPass = mUseDepthPass; 
     2276        mUseDepthPass = true; 
     2277 
     2278        // don't need shading, render only depth pass 
     2279        const bool fillQueue = false; 
     2280        RenderDepthPass(fillQueue); 
     2281        // _renderVisibleObjects(); 
     2282     
     2283        mUseDepthPass = savedUseDepthPass; 
     2284    
     2285    // End frame 
     2286    mDestRenderSystem->_endFrame(); 
     2287} 
    20602288//----------------------------------------------------------------------- 
    20612289const String OcclusionCullingSceneManagerFactory::FACTORY_TYPE_NAME = "OcclusionCullingSceneManager"; 
Note: See TracChangeset for help on using the changeset viewer.