ConstCacheObjects generateRenderingSet( const NodeIds& visibles, size_t& nAvailable, size_t& nNotAvailable ) const { ConstCacheMap cacheMap; for( const NodeId& nodeId : visibles ) { collectLoadedTextures( nodeId, cacheMap ); cacheMap.count( nodeId.getId( )) > 0 ? ++nAvailable : ++nNotAvailable; } if( visibles.size() != cacheMap.size( )) { ConstCacheMap::const_iterator it = cacheMap.begin(); size_t previousSize = 0; do { previousSize = cacheMap.size(); while( it != cacheMap.end( )) { if( hasParentInMap( NodeId( it->first ), cacheMap )) it = cacheMap.erase( it ); else ++it; } } while( previousSize != cacheMap.size( )); } ConstCacheObjects cacheObjects; cacheObjects.reserve( cacheMap.size( )); for( ConstCacheMap::const_iterator it = cacheMap.begin(); it != cacheMap.end(); ++it ) { cacheObjects.push_back( it->second ); } return cacheObjects; }
void renderSync( RenderStatistics& statistics, Renderer& renderer, const RenderInputs& renderInputs ) { tuyau::PipeFilter sendHistogramFilter = renderInputs.filters.find( "SendHistogramFilter" )->second; tuyau::PipeFilter preRenderFilter = renderInputs.filters.find( "PreRenderFilter" )->second; tuyau::PipeFilterT< VisibleSetGeneratorFilter > visibleSetGenerator( "VisibleSetGenerator", renderInputs.dataSource ); setupVisibleGeneratorFilter( visibleSetGenerator, renderInputs ); visibleSetGenerator.connect( "VisibleNodes", preRenderFilter, "VisibleNodes" ); preRenderFilter.getPromise( "Frustum" ).set( renderInputs.frameInfo.frustum ); visibleSetGenerator.execute(); preRenderFilter.execute(); const tuyau::UniqueFutureMap portFutures( visibleSetGenerator.getPostconditions( )); NodeIds nodeIdsCopy = portFutures.get< NodeIds >( "VisibleNodes" ); DistanceOperator distanceOp( renderInputs.dataSource, renderInputs.frameInfo.frustum ); std::sort( nodeIdsCopy.begin(), nodeIdsCopy.end(), distanceOp ); const uint32_t maxNodesPerPass = texturePool->getTextureMem() / texturePool->getSlotMemSize(); const uint32_t numberOfPasses = std::ceil( (float)nodeIdsCopy.size() / (float)maxNodesPerPass ); std::unique_ptr< boost::progress_display > showProgress; if( numberOfPasses > 1 ) { LBINFO << "Multipass rendering. Number of passes: " << numberOfPasses << std::endl; showProgress.reset( new boost::progress_display( numberOfPasses )); } for( uint32_t i = 0; i < numberOfPasses; ++i ) { uint32_t renderStages = RENDER_FRAME; if( i == 0 ) renderStages |= RENDER_BEGIN; if( i == numberOfPasses - 1u ) renderStages |= RENDER_END; const uint32_t startIndex = i * maxNodesPerPass; const uint32_t endIndex = ( i + 1 ) * maxNodesPerPass; const NodeIds nodesPerPass( nodeIdsCopy.begin() + startIndex, endIndex > nodeIdsCopy.size() ? nodeIdsCopy.end() : nodeIdsCopy.begin() + endIndex ); createAndExecuteSyncPass( nodesPerPass, renderInputs, renderer, renderStages ); if( numberOfPasses > 1 ) ++(*showProgress); } tuyau::PipeFilterT< HistogramFilter > histogramFilter( "HistogramFilter", *histogramCache, *dataCache, renderInputs.dataSource ); histogramFilter.getPromise( "NodeIds" ).set( nodeIdsCopy ); sendHistogramFilter.getPromise( "RelativeViewport" ).set( renderInputs.viewport ); sendHistogramFilter.getPromise( "Id" ).set( renderInputs.frameInfo.frameId ); histogramFilter.getPromise( "Frustum" ).set( renderInputs.frameInfo.frustum ); histogramFilter.connect( "Histogram", sendHistogramFilter, "Histogram" ); histogramFilter.getPromise( "RelativeViewport" ).set( renderInputs.viewport ); histogramFilter.getPromise( "DataSourceRange" ).set( renderInputs.dataSourceRange ); histogramFilter.schedule( _computeExecutor ); sendHistogramFilter.schedule( _computeExecutor ); const tuyau::UniqueFutureMap futures( visibleSetGenerator.getPostconditions( )); statistics.nAvailable = futures.get< NodeIds >( "VisibleNodes" ).size(); statistics.nNotAvailable = 0; statistics.nRenderAvailable = statistics.nAvailable; }