LCOV - code coverage report
Current view: top level - eq/fabric - segment.ipp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 113 143 79.0 %
Date: 2014-06-18 Functions: 19 38 50.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@eyescale.ch>
       3             :  *                    2012, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *                    2010, Cedric Stalder <cedric.stalder@gmail.com>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #include "segment.h"
      21             : 
      22             : #include "leafVisitor.h"
      23             : #include "log.h"
      24             : #include "paths.h"
      25             : 
      26             : #include <co/dataIStream.h>
      27             : #include <co/dataOStream.h>
      28             : 
      29             : namespace eq
      30             : {
      31             : namespace fabric
      32             : {
      33             : 
      34             : template< class C, class S, class CH >
      35         385 : Segment< C, S, CH >::Segment( C* canvas )
      36             :         : _canvas( canvas )
      37             :         , _channel( 0 )
      38             :         , _eyes( EYES_ALL )
      39         385 :         , _swapBarrier( canvas->getSwapBarrier( ))
      40             : {
      41         385 :     LBASSERT( canvas );
      42         385 :     canvas->_addChild( static_cast< S* >( this ));
      43         385 :     LBLOG( LOG_INIT ) << "New " << lunchbox::className( this ) << std::endl;
      44         385 : }
      45             : 
      46             : template< class C, class S, class CH >
      47         384 : Segment< C, S, CH >::~Segment()
      48             : {
      49         384 :     LBLOG( LOG_INIT ) << "Delete " << lunchbox::className( this ) << std::endl;
      50         384 :     _canvas->_removeChild( static_cast< S* >( this ));
      51         384 :     _channel = 0;
      52         768 : }
      53             : 
      54             : template< class C, class S, class CH >
      55          19 : uint128_t Segment< C, S, CH >::commit( const uint32_t incarnation )
      56             : {
      57          19 :     if( Serializable::isDirty( DIRTY_CHANNEL ) && _channel )
      58           0 :         commitChild< typename CH::Parent >( _channel->getWindow(), incarnation);
      59          19 :     return Object::commit( incarnation );
      60             : }
      61             : 
      62             : template< class C, class S, class CH >
      63          22 : void Segment< C, S, CH >::setEyes( const uint32_t eyes )
      64             : {
      65          22 :     if( _eyes == eyes )
      66          22 :         return;
      67          22 :     setDirty( DIRTY_EYES );
      68          22 :     _eyes = eyes;
      69             : }
      70             : 
      71             : template< class C, class S, class CH > void
      72          14 : Segment< C, S, CH >::serialize( co::DataOStream& os, const uint64_t dirtyBits )
      73             : {
      74          14 :     Object::serialize( os, dirtyBits );
      75          14 :     if( dirtyBits & DIRTY_VIEWPORT )
      76          13 :         os << _vp;
      77          14 :     if( dirtyBits & DIRTY_FRUSTUM )
      78          14 :         Frustum::serialize( os );
      79          14 :     if( dirtyBits & DIRTY_CHANNEL )
      80          13 :         os << co::ObjectVersion( _channel );
      81          14 :     if( dirtyBits & DIRTY_EYES )
      82          13 :         os << _eyes;
      83          14 : }
      84             : 
      85             : template< class C, class S, class CH >
      86          11 : void Segment< C, S, CH >::deserialize( co::DataIStream& is,
      87             :                                        const uint64_t dirtyBits )
      88             : {
      89          11 :     Object::deserialize( is, dirtyBits );
      90          11 :     if( dirtyBits & DIRTY_VIEWPORT )
      91          10 :         is >> _vp;
      92          11 :     if( dirtyBits & DIRTY_FRUSTUM )
      93          11 :         Frustum::deserialize( is );
      94          11 :     if( dirtyBits & DIRTY_CHANNEL )
      95             :     {
      96          10 :         LBASSERT( _canvas->_mapViewObjects( ))
      97             : 
      98          10 :         co::ObjectVersion ov;
      99          10 :         is >> ov;
     100             : 
     101          10 :         _channel = 0;
     102          10 :         if( ov.identifier != 0 )
     103             :         {
     104          10 :             _canvas->getConfig()->find( ov.identifier, &_channel );
     105          10 :             LBASSERT( !isMaster() || _channel );
     106             :         }
     107             :     }
     108          11 :     if( dirtyBits & DIRTY_EYES )
     109          10 :         is >> _eyes;
     110          11 : }
     111             : 
     112             : template< class C, class S, class CH >
     113         933 : void Segment< C, S, CH >::setDirty( const uint64_t dirtyBits )
     114             : {
     115         933 :     Object::setDirty( dirtyBits );
     116         933 :     _canvas->setDirty( C::DIRTY_SEGMENTS );
     117         933 : }
     118             : 
     119             : template< class C, class S, class CH >
     120        3860 : VisitorResult Segment< C, S, CH >::accept( Visitor& visitor )
     121             : {
     122        3860 :     return visitor.visit( static_cast< S* >( this ));
     123             : }
     124             : 
     125             : template< class C, class S, class CH >
     126           0 : VisitorResult Segment< C, S, CH >::accept( Visitor& visitor ) const
     127             : {
     128           0 :     return visitor.visit( static_cast< const S* >( this ));
     129             : }
     130             : 
     131          10 : template< class C, class S, class CH > void Segment< C, S, CH >::backup()
     132             : {
     133          10 :     Frustum::backup();
     134          10 :     Object::backup();
     135          10 : }
     136             : 
     137           2 : template< class C, class S, class CH > void Segment< C, S, CH >::restore()
     138             : {
     139           2 :     Object::restore();
     140           2 :     Frustum::restore();
     141           2 : }
     142             : 
     143             : template< class C, class S, class CH >
     144         120 : void Segment< C, S, CH >::setViewport( const Viewport& vp )
     145             : {
     146         120 :     if( _vp == vp )
     147         120 :         return;
     148             : 
     149         120 :     _vp = vp;
     150         120 :     setDirty( DIRTY_VIEWPORT );
     151         120 :     inheritFrustum();
     152             : }
     153             : 
     154             : template< class C, class S, class CH >
     155           0 : void Segment< C, S, CH >::setSwapBarrier( SwapBarrierPtr barrier )
     156             : {
     157           0 :     if( barrier.isValid() && barrier->getName().empty( ))
     158             :     {
     159           0 :         const std::string& name = getName();
     160           0 :         std::stringstream out;
     161           0 :         out << "barrier.segment.";
     162           0 :         if( name.empty( ))
     163           0 :             if( getCanvas( ))
     164           0 :                 out << getCanvas()->getPath().canvasIndex;
     165             :             else
     166           0 :                 out << (void*)this;
     167             :         else
     168           0 :             out << name;
     169             : 
     170           0 :         barrier->setName( out.str( ));
     171             :     }
     172             : 
     173           0 :     _swapBarrier = barrier;
     174           0 : }
     175             : 
     176             : template< class C, class S, class CH >
     177         124 : void Segment< C, S, CH >::inheritFrustum()
     178             : {
     179         124 :     if( getCurrentType() != TYPE_NONE || _canvas->getCurrentType() == TYPE_NONE)
     180         127 :         return;
     181             : 
     182             :     // if segment has no frustum...
     183         121 :     Wall wall( _canvas->getWall( ));
     184         121 :     wall.apply( _vp );
     185             : 
     186         121 :     switch( _canvas->getCurrentType( ))
     187             :     {
     188             :         case TYPE_WALL:
     189         121 :             setWall( wall );
     190         121 :             break;
     191             : 
     192             :         case TYPE_PROJECTION:
     193             :         {
     194           0 :             Projection projection( _canvas->getProjection( )); // keep distance
     195           0 :             projection = wall;
     196           0 :             setProjection( projection );
     197           0 :             break;
     198             :         }
     199             :         default:
     200           0 :             LBUNIMPLEMENTED;
     201             :         case TYPE_NONE:
     202           0 :             break;
     203             :     }
     204             : }
     205             : 
     206             : template< class C, class S, class CH >
     207         243 : void Segment< C, S, CH >::setWall( const Wall& wall )
     208             : {
     209         243 :     if( getWall() == wall && getCurrentType() == TYPE_WALL )
     210         285 :         return;
     211             : 
     212         201 :     Frustum::setWall( wall );
     213         201 :     setDirty( DIRTY_FRUSTUM );
     214             : }
     215             : 
     216             : template< class C, class S, class CH >
     217           6 : void Segment< C, S, CH >::setProjection( const Projection& projection )
     218             : {
     219           6 :     if( getProjection() == projection && getCurrentType() == TYPE_PROJECTION )
     220           6 :         return;
     221             : 
     222           6 :     Frustum::setProjection( projection );
     223           6 :     setDirty( DIRTY_FRUSTUM );
     224             : }
     225             : 
     226             : template< class C, class S, class CH >
     227           0 : void Segment< C, S, CH >::unsetFrustum()
     228             : {
     229           0 :     if( getCurrentType() == TYPE_NONE )
     230           0 :         return;
     231             : 
     232           0 :     Frustum::unsetFrustum();
     233           0 :     setDirty( DIRTY_FRUSTUM );
     234             : }
     235             : 
     236             : template< class C, class S, class CH >
     237         200 : std::ostream& operator << ( std::ostream& os, const Segment< C, S, CH >& s )
     238             : {
     239         200 :     const S& segment = static_cast< const S& >( s );
     240         200 :     os << lunchbox::disableFlush << lunchbox::disableHeader << "segment"
     241             :        << std::endl;
     242         200 :     os << "{" << std::endl << lunchbox::indent;
     243             : 
     244         200 :     const std::string& name = segment.getName();
     245         200 :     if( !name.empty( ))
     246           0 :         os << "name     \"" << name << "\"" << std::endl;
     247             : 
     248         200 :     if( segment.getChannel( ))
     249             :     {
     250         200 :         const std::string& channelName = segment.getChannel()->getName();
     251         200 :         if( segment.getConfig()->findChannel( channelName ) ==
     252             :             segment.getChannel( ))
     253             :         {
     254         200 :             os << "channel  \"" << channelName << "\"" << std::endl;
     255             :         }
     256             :         else
     257           0 :             os << "channel  " << segment.getChannel()->getPath() << std::endl;
     258             :     }
     259             : 
     260         200 :     const uint32_t eyes = segment.getEyes();
     261         200 :     if( eyes != EYES_ALL )
     262             :     {
     263          11 :         os << "eye      [ ";
     264          11 :         if( eyes & EYE_CYCLOP )
     265           8 :             os << "CYCLOP ";
     266          11 :         if( eyes & EYE_LEFT )
     267           5 :             os << "LEFT ";
     268          11 :         if( eyes & EYE_RIGHT )
     269           5 :             os << "RIGHT ";
     270          11 :         os << "]" << std::endl;
     271             :     }
     272         200 :     const Viewport& vp  = segment.getViewport();
     273         200 :     if( vp.isValid( ) && vp != Viewport::FULL )
     274          60 :         os << "viewport " << vp << std::endl;
     275             : 
     276         200 :     SwapBarrierConstPtr barrier = segment.getSwapBarrier();
     277         200 :     if( barrier && barrier != segment.getCanvas()->getSwapBarrier( ))
     278           0 :         os << *segment.getSwapBarrier();
     279         200 :     os << static_cast< const Frustum& >( segment );
     280             : 
     281         200 :     os << lunchbox::exdent << "}" << std::endl << lunchbox::enableHeader
     282             :        << lunchbox::enableFlush;
     283         200 :     return os;
     284             : }
     285             : 
     286             : 
     287             : }
     288             : }

Generated by: LCOV version 1.10