コード例 #1
0
void CompoundUpdateOutputVisitor::_updateOutput( Compound* compound )
{
    const Channel* channel = compound->getChannel();

    const TileQueues& outputQueues = compound->getOutputTileQueues();
    for( TileQueuesCIter i = outputQueues.begin(); 
        i != outputQueues.end(); ++i )
    {
        //----- Check uniqueness of output queue name
        TileQueue* queue  = *i;
        const std::string& name   = queue->getName();

        if( _outputTileQueues.find( name ) != _outputTileQueues.end())
        {
            LBWARN << "Multiple output queues of the same name are unsupported"
                << ", ignoring output queue " << name << std::endl;
            queue->unsetData();
            continue;
        }

        queue->cycleData( _frameNumber, compound );

        //----- Generate tile task packets
        _generateTiles( queue, compound );
        _outputTileQueues[name] = queue;
    }

    if( !compound->testInheritTask( fabric::TASK_READBACK ) || !channel )
        return;

    const Frames& outputFrames = compound->getOutputFrames();
    if( outputFrames.empty( ))
    {
        compound->unsetInheritTask( fabric::TASK_READBACK );
        return;
    }

    for( Frames::const_iterator i = outputFrames.begin(); 
         i != outputFrames.end(); ++i )
    {
        //----- Check uniqueness of output frame name
        Frame*             frame  = *i;
        const std::string& name   = frame->getName();

        if( _outputFrames.find( name ) != _outputFrames.end())
        {
            LBWARN << "Multiple output frames of the same name are unsupported"
                   << ", ignoring output frame " << name << std::endl;
            frame->unsetData();
            continue;
        }

        //----- compute readback area
        const Viewport& frameVP = frame->getViewport();
        const PixelViewport& inheritPVP = compound->getInheritPixelViewport();
        PixelViewport framePVP( inheritPVP );
        framePVP.apply( frameVP );
        
        if( !framePVP.hasArea( )) // output frame has no pixels
        {
            LBINFO << "Skipping output frame " << name << ", no pixels"
                   << std::endl;
            frame->unsetData();
            continue;
        }

        //----- Create new frame datas
        //      one frame data used for each eye pass
        //      data is set only on master frame data (will copy to all others)
        frame->cycleData( _frameNumber, compound );
        FrameData* frameData = frame->getMasterData();
        LBASSERT( frameData );

        LBLOG( LOG_ASSEMBLY )
            << lunchbox::disableFlush << "Output frame \"" << name << "\" id " 
            << frame->getID() << " v" << frame->getVersion()+1
            << " data id " << frameData->getID() << " v" 
            << frameData->getVersion() + 1 << " on channel \""
            << channel->getName() << "\" tile pos " << framePVP.x << ", " 
            << framePVP.y;

        //----- Set frame data parameters:
        // 1) offset is position wrt destination view
        const bool usesTiles = !compound->getInputTileQueues().empty();
        frameData->setOffset( usesTiles ? Vector2i( 0 , 0 ) :
                                          Vector2i( framePVP.x, framePVP.y ) );

        // 2) pvp is area within channel
        framePVP.x = static_cast< int32_t >( frameVP.x * inheritPVP.w );
        framePVP.y = static_cast< int32_t >( frameVP.y * inheritPVP.h );
        frameData->setPixelViewport( framePVP );

        // 3) image buffers and storage type
        uint32_t buffers = frame->getBuffers();

        frameData->setType( frame->getType() );
        frameData->setBuffers( buffers == eq::Frame::BUFFER_UNDEFINED ? 
                                   compound->getInheritBuffers() : buffers );

        // 4) (source) render context
        frameData->setRange( compound->getInheritRange( ));
        frameData->setPixel( compound->getInheritPixel( ));
        frameData->setSubPixel( compound->getInheritSubPixel( ));
        frameData->setPeriod( compound->getInheritPeriod( ));
        frameData->setPhase( compound->getInheritPhase( ));

        //----- Set frame parameters:
        // 1) offset is position wrt window, i.e., the channel position
        if( compound->getInheritChannel() == channel )
            frame->setOffset( Vector2i( inheritPVP.x, inheritPVP.y ));
        else
        {
            const PixelViewport& nativePVP = channel->getPixelViewport();
            frame->setOffset( Vector2i( nativePVP.x, nativePVP.y ));
        }

        // 2) zoom
        _updateZoom( compound, frame );

        //----- Commit
        frame->commitData();
        
        _outputFrames[name] = frame;
        LBLOG( LOG_ASSEMBLY ) 
            << " buffers " << frameData->getBuffers() << " read area "
            << framePVP << " readback " << frame->getZoom() << " assemble "
            << frameData->getZoom()<< lunchbox::enableFlush << std::endl ;
    }
}