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 756 : Segment< C, S, CH >::Segment( C* canvas )
36 : : _canvas( canvas )
37 : , _channel( 0 )
38 : , _eyes( EYES_ALL )
39 756 : , _swapBarrier( canvas->getSwapBarrier( ))
40 : {
41 756 : LBASSERT( canvas );
42 756 : canvas->_addChild( static_cast< S* >( this ));
43 756 : LBLOG( LOG_INIT ) << "New " << lunchbox::className( this ) << std::endl;
44 756 : }
45 :
46 : template< class C, class S, class CH >
47 754 : Segment< C, S, CH >::~Segment()
48 : {
49 754 : LBLOG( LOG_INIT ) << "Delete " << lunchbox::className( this ) << std::endl;
50 754 : _canvas->_removeChild( static_cast< S* >( this ));
51 754 : _channel = 0;
52 1508 : }
53 :
54 : template< class C, class S, class CH >
55 6 : uint128_t Segment< C, S, CH >::commit( const uint32_t incarnation )
56 : {
57 6 : if( Serializable::isDirty( DIRTY_CHANNEL ) && _channel )
58 0 : commitChild< typename CH::Parent >( _channel->getWindow(), incarnation);
59 6 : return Object::commit( incarnation );
60 : }
61 :
62 : template< class C, class S, class CH >
63 44 : void Segment< C, S, CH >::setEyes( const uint32_t eyes )
64 : {
65 44 : if( _eyes == eyes )
66 44 : return;
67 44 : setDirty( DIRTY_EYES );
68 44 : _eyes = eyes;
69 : }
70 :
71 : template< class C, class S, class CH > void
72 12 : Segment< C, S, CH >::serialize( co::DataOStream& os, const uint64_t dirtyBits )
73 : {
74 12 : Object::serialize( os, dirtyBits );
75 12 : if( dirtyBits & DIRTY_VIEWPORT )
76 10 : os << _vp;
77 12 : if( dirtyBits & DIRTY_FRUSTUM )
78 12 : Frustum::serialize( os );
79 12 : if( dirtyBits & DIRTY_CHANNEL )
80 10 : os << co::ObjectVersion( _channel );
81 12 : if( dirtyBits & DIRTY_EYES )
82 10 : os << _eyes;
83 12 : }
84 :
85 : template< class C, class S, class CH >
86 3 : void Segment< C, S, CH >::deserialize( co::DataIStream& is,
87 : const uint64_t dirtyBits )
88 : {
89 3 : Object::deserialize( is, dirtyBits );
90 3 : if( dirtyBits & DIRTY_VIEWPORT )
91 2 : is >> _vp;
92 3 : if( dirtyBits & DIRTY_FRUSTUM )
93 3 : Frustum::deserialize( is );
94 3 : if( dirtyBits & DIRTY_CHANNEL )
95 : {
96 2 : LBASSERT( _canvas->_mapViewObjects( ))
97 :
98 2 : co::ObjectVersion ov;
99 2 : is >> ov;
100 :
101 2 : _channel = 0;
102 2 : if( ov.identifier != 0 )
103 : {
104 2 : _canvas->getConfig()->find( ov.identifier, &_channel );
105 2 : LBASSERT( !isMaster() || _channel );
106 : }
107 : }
108 3 : if( dirtyBits & DIRTY_EYES )
109 2 : is >> _eyes;
110 3 : }
111 :
112 : template< class C, class S, class CH >
113 1894 : void Segment< C, S, CH >::setDirty( const uint64_t dirtyBits )
114 : {
115 1894 : Object::setDirty( dirtyBits );
116 1894 : _canvas->setDirty( C::DIRTY_SEGMENTS );
117 1894 : }
118 :
119 : template< class C, class S, class CH >
120 6605 : VisitorResult Segment< C, S, CH >::accept( Visitor& visitor )
121 : {
122 6605 : 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 4 : template< class C, class S, class CH > void Segment< C, S, CH >::backup()
132 : {
133 4 : Frustum::backup();
134 4 : Object::backup();
135 4 : }
136 :
137 4 : template< class C, class S, class CH > void Segment< C, S, CH >::restore()
138 : {
139 4 : Object::restore();
140 4 : Frustum::restore();
141 4 : }
142 :
143 : template< class C, class S, class CH >
144 248 : void Segment< C, S, CH >::setViewport( const Viewport& vp )
145 : {
146 248 : if( _vp == vp )
147 248 : return;
148 :
149 248 : _vp = vp;
150 248 : setDirty( DIRTY_VIEWPORT );
151 248 : 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 252 : void Segment< C, S, CH >::inheritFrustum()
178 : {
179 252 : if( getCurrentType() != TYPE_NONE || _canvas->getCurrentType() == TYPE_NONE)
180 254 : return;
181 :
182 : // if segment has no frustum...
183 250 : Wall wall( _canvas->getWall( ));
184 250 : wall.apply( _vp );
185 :
186 250 : switch( _canvas->getCurrentType( ))
187 : {
188 : case TYPE_WALL:
189 250 : setWall( wall );
190 250 : 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 498 : void Segment< C, S, CH >::setWall( const Wall& wall )
208 : {
209 498 : if( getWall() == wall && getCurrentType() == TYPE_WALL )
210 586 : return;
211 :
212 410 : Frustum::setWall( wall );
213 410 : setDirty( DIRTY_FRUSTUM );
214 : }
215 :
216 : template< class C, class S, class CH >
217 12 : void Segment< C, S, CH >::setProjection( const Projection& projection )
218 : {
219 12 : if( getProjection() == projection && getCurrentType() == TYPE_PROJECTION )
220 12 : return;
221 :
222 12 : Frustum::setProjection( projection );
223 12 : 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 378 : std::ostream& operator << ( std::ostream& os, const Segment< C, S, CH >& s )
238 : {
239 378 : const S& segment = static_cast< const S& >( s );
240 378 : os << lunchbox::disableFlush << lunchbox::disableHeader << "segment"
241 : << std::endl;
242 378 : os << "{" << std::endl << lunchbox::indent;
243 :
244 378 : const std::string& name = segment.getName();
245 378 : if( !name.empty( ))
246 0 : os << "name \"" << name << "\"" << std::endl;
247 :
248 378 : if( segment.getChannel( ))
249 : {
250 378 : const std::string& channelName = segment.getChannel()->getName();
251 378 : if( segment.getConfig()->findChannel( channelName ) ==
252 : segment.getChannel( ))
253 : {
254 378 : os << "channel \"" << channelName << "\"" << std::endl;
255 : }
256 : else
257 0 : os << "channel " << segment.getChannel()->getPath() << std::endl;
258 : }
259 :
260 378 : const uint32_t eyes = segment.getEyes();
261 378 : if( eyes != EYES_ALL )
262 : {
263 22 : os << "eye [ ";
264 22 : if( eyes & EYE_CYCLOP )
265 16 : os << "CYCLOP ";
266 22 : if( eyes & EYE_LEFT )
267 10 : os << "LEFT ";
268 22 : if( eyes & EYE_RIGHT )
269 10 : os << "RIGHT ";
270 22 : os << "]" << std::endl;
271 : }
272 378 : const Viewport& vp = segment.getViewport();
273 378 : if( vp.isValid( ) && vp != Viewport::FULL )
274 124 : os << "viewport " << vp << std::endl;
275 :
276 378 : SwapBarrierConstPtr barrier = segment.getSwapBarrier();
277 378 : if( barrier && barrier != segment.getCanvas()->getSwapBarrier( ))
278 0 : os << *segment.getSwapBarrier();
279 378 : os << static_cast< const Frustum& >( segment );
280 :
281 378 : os << lunchbox::exdent << "}" << std::endl << lunchbox::enableHeader
282 : << lunchbox::enableFlush;
283 378 : return os;
284 : }
285 :
286 :
287 : }
288 : }
|