lib/client/view.cpp

00001 
00002 /* Copyright (c) 2008-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "view.h"
00019 
00020 #include "config.h"
00021 #include "event.h"
00022 #include "pipe.h"
00023 #include "layout.h"
00024 #include "observer.h"
00025 #include "viewVisitor.h"
00026 
00027 #include <eq/net/dataIStream.h>
00028 #include <eq/net/dataOStream.h>
00029 
00030 namespace eq
00031 {
00032 View::View()
00033         : _layout( 0 )
00034         , _pipe( 0 )
00035         , _observer( 0 )
00036         , _overdraw( Vector2i::ZERO )
00037 {
00038 }
00039 
00040 View::~View()
00041 {
00042     EQASSERT( !_layout );
00043     _layout = 0;
00044 }
00045 
00046 void View::serialize( net::DataOStream& os, const uint64_t dirtyBits )
00047 {
00048     Frustum::serialize( os, dirtyBits );
00049     if( dirtyBits & DIRTY_VIEWPORT )
00050         os << _viewport;
00051     if( dirtyBits & DIRTY_OBSERVER )
00052         os << ( _observer ? _observer->getID() : EQ_ID_INVALID );
00053     if( dirtyBits & DIRTY_OVERDRAW )
00054         os << _overdraw;
00055 }
00056 
00057 void View::deserialize( net::DataIStream& is, const uint64_t dirtyBits )
00058 {
00059     Frustum::deserialize( is, dirtyBits );
00060     if( dirtyBits & DIRTY_VIEWPORT )
00061         is >> _viewport;
00062     if( dirtyBits & DIRTY_OBSERVER )
00063     {
00064         uint32_t id;
00065         is >> id;
00066 
00067         if( id == EQ_ID_INVALID )
00068             _observer = 0;
00069         else
00070         {
00071             Config* config = getConfig();
00072             EQASSERT( config );
00073             _observer = config->findObserver( id );
00074         }
00075     }
00076     if( dirtyBits & DIRTY_OVERDRAW )
00077         is >> _overdraw;
00078 
00079     if( dirtyBits == ( DIRTY_CUSTOM - 1 ))
00080         _baseFrustum = *this; // save baseline data for resizing
00081 }
00082 
00083 Config* View::getConfig()
00084 {
00085     EQASSERT( _layout || _pipe );
00086 
00087     if( _layout )
00088     {
00089         EQASSERT( !_pipe );
00090         return _layout->getConfig();
00091     }
00092 
00093     if( _pipe )
00094     {
00095         EQASSERT( !_layout );
00096         return _pipe->getConfig();
00097     }
00098 
00099     return 0;
00100 }
00101 
00102 const Config* View::getConfig() const
00103 {
00104     EQASSERT( _layout || _pipe );
00105 
00106     if( _layout )
00107     {
00108         EQASSERT( !_pipe );
00109         return _layout->getConfig();
00110     }
00111 
00112     if( _pipe )
00113     {
00114         EQASSERT( !_layout );
00115         return _pipe->getConfig();
00116     }
00117 
00118     return 0;
00119 }
00120 
00121 const Viewport& View::getViewport() const
00122 {
00123     return _viewport;
00124 }
00125 
00126 void View::setOverdraw( const Vector2i& pixels )
00127 {
00128     _overdraw = pixels;
00129     setDirty( DIRTY_OVERDRAW );
00130 }
00131 
00132 VisitorResult View::accept( ViewVisitor& visitor )
00133 {
00134     return visitor.visit( this );
00135 }
00136 
00137 bool View::handleEvent( const Event& event )
00138 {
00139     switch( event.type )
00140     {
00141         case Event::VIEW_RESIZE:
00142         {
00143             const ResizeEvent& resize = event.resize;
00144             if( resize.dw == 0.f || resize.dh == 0.f )
00145                 return true;
00146 
00147             switch( getCurrentType( ))
00148             {
00149                 case TYPE_WALL:
00150                 {
00151                     const float ratio( resize.dw / resize.dh );
00152                     Wall wall( _baseFrustum.getWall( ));
00153 
00154                     wall.resizeHorizontal( ratio );
00155                     setWall( wall );
00156                     break;
00157                 }
00158 
00159                 case View::TYPE_PROJECTION:
00160                 {
00161                     const float ratio( resize.dw / resize.dh );
00162                     eq::Projection projection( _baseFrustum.getProjection( ));
00163 
00164                     projection.resizeHorizontal( ratio );
00165                     setProjection( projection );
00166                     break;
00167                 }
00168 
00169                 case eq::View::TYPE_NONE:
00170                     break;
00171                 default:
00172                     EQUNIMPLEMENTED;
00173                     break;
00174             }
00175 
00176             return true;
00177         }
00178     }
00179     
00180     return false;
00181 }
00182 
00183 
00184 }
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8