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/dataOStream.h>
21 : #include <co/dataIStream.h>
22 :
23 : namespace eq
24 : {
25 : namespace fabric
26 : {
27 3615 : Frustum::Frustum()
28 3615 : {}
29 :
30 3612 : Frustum::~Frustum()
31 : {
32 3612 : _data.current = TYPE_NONE;
33 3612 : }
34 :
35 83 : void Frustum::backup()
36 : {
37 83 : _backup = _data;
38 83 : }
39 :
40 6 : void Frustum::restore()
41 : {
42 6 : _data = _backup;
43 6 : }
44 :
45 1063 : void Frustum::setWall( const Wall& wall )
46 : {
47 1063 : if( _data.wall == wall && _data.current == TYPE_WALL )
48 1376 : return;
49 :
50 750 : _data.wall = wall;
51 750 : _data.projection = wall;
52 750 : _data.current = TYPE_WALL;
53 750 : notifyFrustumChanged();
54 : }
55 :
56 6 : void Frustum::setProjection( const Projection& projection )
57 : {
58 6 : if( _data.projection == projection && _data.current == TYPE_PROJECTION )
59 6 : return;
60 :
61 6 : _data.projection = projection;
62 6 : _data.wall = projection;
63 6 : _data.current = TYPE_PROJECTION;
64 6 : notifyFrustumChanged();
65 : }
66 :
67 0 : void Frustum::unsetFrustum()
68 : {
69 0 : if( _data.current == TYPE_NONE )
70 0 : return;
71 :
72 0 : _data.current = TYPE_NONE;
73 0 : notifyFrustumChanged();
74 : }
75 :
76 193 : void Frustum::serialize( co::DataOStream& os )
77 : {
78 193 : switch( getCurrentType( ))
79 : {
80 : case TYPE_WALL:
81 176 : os << TYPE_WALL << _data.wall;
82 176 : break;
83 :
84 : case TYPE_PROJECTION:
85 0 : os << TYPE_PROJECTION << _data.projection;
86 0 : break;
87 :
88 : case TYPE_NONE:
89 17 : os << TYPE_NONE;
90 17 : break;
91 :
92 : default:
93 0 : LBASSERT( false );
94 : }
95 193 : }
96 :
97 101 : void Frustum::deserialize( co::DataIStream& is )
98 : {
99 101 : is >> _data.current;
100 :
101 101 : switch( _data.current )
102 : {
103 : case TYPE_WALL:
104 : {
105 89 : is >> _data.wall;
106 89 : break;
107 : }
108 : case Frustum::TYPE_PROJECTION:
109 : {
110 0 : is >> _data.projection;
111 0 : break;
112 : }
113 : case Frustum::TYPE_NONE:
114 12 : break;
115 :
116 : default:
117 0 : LBASSERT( false );
118 : }
119 101 : updateFrustum();
120 101 : }
121 :
122 623 : std::ostream& operator << ( std::ostream& os, const Frustum& frustum )
123 : {
124 623 : switch( frustum.getCurrentType( ))
125 : {
126 : case Frustum::TYPE_WALL:
127 385 : os << frustum.getWall() << std::endl;
128 385 : break;
129 : case Frustum::TYPE_PROJECTION:
130 3 : os << frustum.getProjection() << std::endl;
131 3 : break;
132 : case Frustum::TYPE_NONE:
133 235 : break;
134 : default:
135 0 : os << "INVALID FRUSTUM";
136 0 : break;
137 : }
138 623 : return os;
139 : }
140 :
141 : }
142 45 : }
|