LCOV - code coverage report
Current view: top level - eq/fabric - frustum.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 45 62 72.6 %
Date: 2017-12-16 05:07:20 Functions: 10 13 76.9 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "frustum.h"
      19             : 
      20             : #include <co/dataIStream.h>
      21             : #include <co/dataOStream.h>
      22             : 
      23             : namespace eq
      24             : {
      25             : namespace fabric
      26             : {
      27        6172 : Frustum::Frustum()
      28             : {
      29        6172 : }
      30             : 
      31       12332 : Frustum::~Frustum()
      32             : {
      33        6166 :     _data.current = TYPE_NONE;
      34        6166 : }
      35             : 
      36          18 : void Frustum::backup()
      37             : {
      38          18 :     _backup = _data;
      39          18 : }
      40             : 
      41           0 : void Frustum::restore()
      42             : {
      43           0 :     _data = _backup;
      44           0 : }
      45             : 
      46        1420 : void Frustum::setWall(const Wall& wall)
      47             : {
      48        1420 :     if (_data.wall == wall && _data.current == TYPE_WALL)
      49         104 :         return;
      50             : 
      51        1316 :     _data.wall = wall;
      52        1316 :     _data.projection = wall;
      53        1316 :     _data.current = TYPE_WALL;
      54        1316 :     notifyFrustumChanged();
      55             : }
      56             : 
      57          68 : void Frustum::setProjection(const Projection& projection)
      58             : {
      59          68 :     if (_data.projection == projection && _data.current == TYPE_PROJECTION)
      60           0 :         return;
      61             : 
      62          68 :     _data.projection = projection;
      63          68 :     _data.wall = projection;
      64          68 :     _data.current = TYPE_PROJECTION;
      65          68 :     notifyFrustumChanged();
      66             : }
      67             : 
      68           0 : void Frustum::unsetFrustum()
      69             : {
      70           0 :     if (_data.current == TYPE_NONE)
      71           0 :         return;
      72             : 
      73           0 :     _data.current = TYPE_NONE;
      74           0 :     notifyFrustumChanged();
      75             : }
      76             : 
      77          60 : void Frustum::serialize(co::DataOStream& os)
      78             : {
      79          60 :     switch (getCurrentType())
      80             :     {
      81             :     case TYPE_WALL:
      82          58 :         os << TYPE_WALL << _data.wall;
      83          58 :         break;
      84             : 
      85             :     case TYPE_PROJECTION:
      86           0 :         os << TYPE_PROJECTION << _data.projection;
      87           0 :         break;
      88             : 
      89             :     case TYPE_NONE:
      90           2 :         os << TYPE_NONE;
      91           2 :         break;
      92             : 
      93             :     default:
      94           0 :         LBASSERT(false);
      95             :     }
      96          60 : }
      97             : 
      98          24 : void Frustum::deserialize(co::DataIStream& is)
      99             : {
     100          24 :     is >> _data.current;
     101             : 
     102          24 :     switch (_data.current)
     103             :     {
     104             :     case TYPE_WALL:
     105             :     {
     106          22 :         is >> _data.wall;
     107          22 :         break;
     108             :     }
     109             :     case Frustum::TYPE_PROJECTION:
     110             :     {
     111           0 :         is >> _data.projection;
     112           0 :         break;
     113             :     }
     114             :     case Frustum::TYPE_NONE:
     115           2 :         break;
     116             : 
     117             :     default:
     118           0 :         LBASSERT(false);
     119             :     }
     120          24 :     updateFrustum();
     121          24 : }
     122             : 
     123         986 : std::ostream& operator<<(std::ostream& os, const Frustum& frustum)
     124             : {
     125         986 :     switch (frustum.getCurrentType())
     126             :     {
     127             :     case Frustum::TYPE_WALL:
     128         528 :         os << frustum.getWall() << std::endl;
     129         528 :         break;
     130             :     case Frustum::TYPE_PROJECTION:
     131          34 :         os << frustum.getProjection() << std::endl;
     132          34 :         break;
     133             :     case Frustum::TYPE_NONE:
     134         424 :         break;
     135             :     default:
     136           0 :         os << "INVALID FRUSTUM";
     137           0 :         break;
     138             :     }
     139         986 :     return os;
     140             : }
     141             : }
     142          60 : }

Generated by: LCOV version 1.11