Line data Source code
1 :
2 : /* Copyright (c) 2008-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2011-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 "view.h"
21 :
22 : #include "equalizerTypes.h"
23 : #include "leafVisitor.h"
24 : #include "log.h"
25 : #include "paths.h"
26 :
27 : #include <co/dataIStream.h>
28 : #include <co/dataOStream.h>
29 :
30 : namespace eq
31 : {
32 : namespace fabric
33 : {
34 : namespace
35 : {
36 : #define _MAKE_ATTR_STRING( attr ) ( std::string("EQ_VIEW_") + #attr )
37 224 : static std::string _sAttributeStrings[] = {
38 : _MAKE_ATTR_STRING( SATTR_DEFLECT_HOST ),
39 : _MAKE_ATTR_STRING( SATTR_DEFLECT_ID )
40 112 : };
41 : }
42 :
43 : template< class L, class V, class O >
44 724 : View< L, V, O >::View( L* layout )
45 : : _layout( layout )
46 : , _observer( 0 )
47 : , _overdraw( Vector2i::ZERO )
48 : , _minimumCapabilities( LB_BIT_NONE )
49 : , _maximumCapabilities( LB_BIT_ALL_64 )
50 : , _capabilities( LB_BIT_ALL_64 )
51 : , _equalizers( EQUALIZER_ALL )
52 724 : , _modelUnit( EQ_M )
53 : {
54 : // Note: Views are an exception to the strong structuring, since render
55 : // client views are multi-buffered (once per pipe) and do not have a parent
56 724 : if( layout )
57 724 : layout->_addChild( static_cast< V* >( this ));
58 724 : LBLOG( LOG_INIT ) << "New " << lunchbox::className( this ) << std::endl;
59 724 : }
60 :
61 : template< class L, class V, class O >
62 722 : View< L, V, O >::~View()
63 : {
64 722 : LBLOG( LOG_INIT ) << "Delete " << lunchbox::className( this ) << std::endl;
65 722 : if( _layout )
66 722 : _layout->_removeChild( static_cast< V* >( this ));
67 1444 : }
68 :
69 : template< class L, class V, class O >
70 1448 : View< L, V, O >::BackupData::BackupData()
71 1448 : : mode( MODE_MONO )
72 1448 : {}
73 :
74 : template< class L, class V, class O >
75 12 : void View< L, V, O >::serialize( co::DataOStream& os, const uint64_t dirtyBits )
76 : {
77 12 : Object::serialize( os, dirtyBits );
78 12 : if( dirtyBits & DIRTY_OBSERVER )
79 10 : os << co::ObjectVersion( _observer );
80 12 : if( dirtyBits & DIRTY_FRUSTUM )
81 10 : Frustum::serialize( os );
82 12 : if( dirtyBits & DIRTY_VIEWPORT )
83 10 : os << _data.viewport;
84 12 : if( dirtyBits & DIRTY_OVERDRAW )
85 10 : os << _overdraw;
86 12 : if( dirtyBits & DIRTY_EQUALIZER )
87 10 : os << _equalizer;
88 12 : if( dirtyBits & DIRTY_MINCAPS )
89 10 : os << _minimumCapabilities;
90 12 : if( dirtyBits & DIRTY_MAXCAPS )
91 10 : os << _maximumCapabilities;
92 12 : if( dirtyBits & DIRTY_CAPABILITIES )
93 10 : os << _capabilities;
94 12 : if( dirtyBits & DIRTY_MODE )
95 10 : os << _data.mode;
96 12 : if( dirtyBits & DIRTY_EQUALIZERS )
97 10 : os << _equalizers;
98 12 : if( dirtyBits & DIRTY_MODELUNIT )
99 10 : os << _modelUnit;
100 12 : if( dirtyBits & DIRTY_ATTRIBUTES )
101 12 : os << co::Array< std::string >( _sAttributes, SATTR_ALL );
102 12 : }
103 :
104 : template< class L, class V, class O >
105 3 : void View< L, V, O >::deserialize( co::DataIStream& is,
106 : const uint64_t dirtyBits )
107 : {
108 3 : Object::deserialize( is, dirtyBits );
109 3 : if( dirtyBits & DIRTY_OBSERVER )
110 : {
111 2 : co::ObjectVersion observer;
112 2 : is >> observer;
113 :
114 2 : if( observer.identifier == 0 )
115 : {
116 0 : if( _observer )
117 0 : _observer->removeView( static_cast< V* >( this ));
118 0 : _observer = 0;
119 : }
120 : else
121 : {
122 2 : if( !_observer && _layout ) // don't map render client observers yet
123 : {
124 2 : L* layout = getLayout();
125 2 : LBASSERT( layout && layout->getConfig( ));
126 2 : layout->getConfig()->find( observer.identifier, &_observer );
127 2 : if( _observer )
128 2 : _observer->addView( static_cast< V* >( this ));
129 2 : LBASSERT( _observer );
130 2 : LBASSERT( _observer->getID() == observer.identifier );
131 : }
132 2 : if( _observer )
133 : {
134 2 : LBASSERT( _observer->getID() == observer.identifier );
135 2 : if( _observer->isMaster( ))
136 0 : _observer->sync();
137 : else
138 2 : _observer->sync( observer.version );
139 : }
140 : }
141 : }
142 3 : if( dirtyBits & DIRTY_FRUSTUM )
143 2 : Frustum::deserialize( is );
144 3 : if( dirtyBits & DIRTY_VIEWPORT )
145 2 : is >> _data.viewport;
146 3 : if( dirtyBits & DIRTY_OVERDRAW )
147 2 : is >> _overdraw;
148 3 : if( dirtyBits & DIRTY_EQUALIZER )
149 2 : is >> _equalizer;
150 3 : if( dirtyBits & ( DIRTY_MINCAPS | DIRTY_MAXCAPS ) )
151 : {
152 2 : if( dirtyBits & DIRTY_MINCAPS )
153 2 : is >> _minimumCapabilities;
154 2 : if( dirtyBits & DIRTY_MAXCAPS )
155 2 : is >> _maximumCapabilities;
156 2 : updateCapabilities();
157 : }
158 3 : if( dirtyBits & DIRTY_CAPABILITIES )
159 2 : is >> _capabilities;
160 3 : if( dirtyBits & DIRTY_MODE )
161 : {
162 2 : uint32_t mode( 0 );
163 2 : is >> mode;
164 2 : activateMode( Mode( mode ));
165 : }
166 3 : if( dirtyBits & DIRTY_EQUALIZERS )
167 2 : is >> _equalizers;
168 3 : if( dirtyBits & DIRTY_MODELUNIT )
169 2 : is >> _modelUnit;
170 3 : if( dirtyBits & DIRTY_ATTRIBUTES )
171 3 : is >> co::Array< std::string >( _sAttributes, SATTR_ALL );
172 3 : }
173 :
174 : template< class L, class V, class O >
175 18 : void View< L, V, O >::setDirty( const uint64_t dirtyBits )
176 : {
177 18 : Object::setDirty( dirtyBits );
178 18 : if( _layout )
179 18 : _layout->setDirty( L::DIRTY_VIEWS );
180 18 : }
181 :
182 : template< class L, class V, class O >
183 176 : void View< L, V, O >::changeMode( const Mode mode )
184 : {
185 176 : if ( _data.mode == mode )
186 264 : return;
187 :
188 88 : _data.mode = mode;
189 88 : setDirty( DIRTY_MODE );
190 : }
191 :
192 : template< class L, class V, class O >
193 0 : bool View< L, V, O >::isActive() const
194 : {
195 0 : const L* layout = getLayout();
196 0 : if( !layout )
197 0 : return true; // render client view, active by definition.
198 0 : return layout->isActive();
199 : }
200 :
201 : template< class L, class V, class O >
202 1 : bool View< L, V, O >::setModelUnit( const float modelUnit )
203 : {
204 1 : if( modelUnit < std::numeric_limits< float >::epsilon() ||
205 : _modelUnit == modelUnit )
206 : {
207 1 : return false;
208 : }
209 0 : _modelUnit = modelUnit;
210 0 : setDirty( DIRTY_MODELUNIT );
211 0 : return true;
212 : }
213 :
214 : template< class L, class V, class O >
215 4 : float View< L, V, O >::getModelUnit() const
216 : {
217 4 : LBASSERT( _modelUnit > 0.f );
218 4 : return _modelUnit;
219 : }
220 :
221 : template< class L, class V, class O >
222 236 : void View< L, V, O >::setViewport( const Viewport& viewport )
223 : {
224 236 : _data.viewport = viewport;
225 236 : setDirty( DIRTY_VIEWPORT );
226 236 : }
227 :
228 4 : template< class L, class V, class O > void View< L, V, O >::backup()
229 : {
230 4 : _backup = _data;
231 4 : Frustum::backup();
232 4 : Object::backup();
233 4 : }
234 :
235 4 : template< class L, class V, class O > void View< L, V, O >::restore()
236 : {
237 4 : Object::restore();
238 4 : Frustum::restore();
239 4 : _data = _backup;
240 4 : _overdraw = Vector2i::ZERO;
241 4 : _minimumCapabilities = LB_BIT_NONE;
242 4 : _maximumCapabilities = LB_BIT_ALL_64;
243 4 : _capabilities = LB_BIT_ALL_64;
244 4 : _equalizers = EQUALIZER_ALL;
245 4 : _modelUnit = EQ_M;
246 :
247 4 : setDirty( DIRTY_VIEW_BITS );
248 4 : }
249 :
250 : template< class L, class V, class O >
251 698 : void View< L, V, O >::setObserver( O* observer )
252 : {
253 698 : if( _observer == observer )
254 698 : return;
255 :
256 698 : if( _observer )
257 0 : _observer->removeView( static_cast< V* >( this ));
258 698 : _observer = observer;
259 698 : if( _observer )
260 698 : _observer->addView( static_cast< V* >( this ));
261 698 : setDirty( DIRTY_OBSERVER );
262 : }
263 :
264 : template< class L, class V, class O >
265 1984 : const Viewport& View< L, V, O >::getViewport() const
266 : {
267 1984 : return _data.viewport;
268 : }
269 :
270 : template< class L, class V, class O >
271 0 : void View< L, V, O >::setOverdraw( const Vector2i& pixels )
272 : {
273 0 : if( _overdraw == pixels )
274 0 : return;
275 :
276 0 : _overdraw = pixels;
277 0 : setDirty( DIRTY_OVERDRAW );
278 : }
279 :
280 : template< class L, class V, class O >
281 0 : void View< L, V, O >::useEqualizer( uint32_t bitmask )
282 : {
283 0 : if( _equalizers == bitmask )
284 0 : return;
285 0 : _equalizers = bitmask;
286 0 : setDirty( DIRTY_EQUALIZERS );
287 : }
288 :
289 : template< class L, class V, class O >
290 0 : const Equalizer& View< L, V, O >::getEqualizer() const
291 : {
292 0 : return _equalizer;
293 : }
294 :
295 : template< class L, class V, class O >
296 0 : Equalizer& View< L, V, O >::getEqualizer()
297 : {
298 0 : setDirty( DIRTY_EQUALIZER );
299 0 : return _equalizer;
300 : }
301 :
302 : template< class L, class V, class O >
303 18903 : VisitorResult View< L, V, O >::accept( LeafVisitor< V >& visitor )
304 : {
305 18903 : return visitor.visit( static_cast< V* >( this ));
306 : }
307 :
308 : template< class L, class V, class O >
309 0 : VisitorResult View< L, V, O >::accept( LeafVisitor< V >& visitor ) const
310 : {
311 0 : return visitor.visit( static_cast< const V* >( this ));
312 : }
313 :
314 : template< class L, class V, class O >
315 0 : uint32_t View< L, V, O >::getUserDataLatency() const
316 : {
317 0 : return static_cast< const V* >( this )->getConfig()->getLatency();
318 : }
319 :
320 : template< class L, class V, class O >
321 0 : void View< L, V, O >::setMinimumCapabilities( uint64_t bitmask )
322 : {
323 0 : if( bitmask == _minimumCapabilities )
324 0 : return;
325 :
326 0 : _minimumCapabilities = bitmask;
327 0 : setDirty( DIRTY_MINCAPS );
328 : }
329 :
330 : template< class L, class V, class O >
331 2 : uint64_t View< L, V, O >::getMinimumCapabilities() const
332 : {
333 2 : return _minimumCapabilities;
334 : }
335 :
336 : template< class L, class V, class O >
337 0 : void View< L, V, O >::setMaximumCapabilities( uint64_t bitmask )
338 : {
339 0 : if( bitmask == _maximumCapabilities )
340 0 : return;
341 :
342 0 : _maximumCapabilities = bitmask;
343 0 : setDirty( DIRTY_MAXCAPS );
344 : }
345 :
346 : template< class L, class V, class O >
347 0 : uint64_t View< L, V, O >::getMaximumCapabilities() const
348 : {
349 0 : return _maximumCapabilities;
350 : }
351 :
352 : template< class L, class V, class O >
353 0 : void View< L, V, O >::setCapabilities( uint64_t bitmask )
354 : {
355 0 : if( bitmask == _capabilities )
356 0 : return;
357 :
358 0 : _capabilities = bitmask;
359 0 : setDirty( DIRTY_CAPABILITIES );
360 : }
361 :
362 : template< class L, class V, class O >
363 0 : uint64_t View< L, V, O >::getCapabilities() const
364 : {
365 0 : return _capabilities;
366 : }
367 :
368 : template< class L, class V, class O >
369 2 : const std::string& View< L, V, O >::getSAttribute( const SAttribute attr ) const
370 : {
371 2 : LBASSERT( attr < SATTR_ALL );
372 2 : return _sAttributes[ attr ];
373 : }
374 :
375 : template< class L, class V, class O >
376 1360 : const std::string& View< L, V, O >::getSAttributeString( const SAttribute attr )
377 : {
378 1360 : return _sAttributeStrings[attr];
379 : }
380 :
381 : template< class L, class V, class O >
382 362 : std::ostream& operator << ( std::ostream& os, const View< L, V, O >& view )
383 : {
384 724 : os << lunchbox::disableFlush << lunchbox::disableHeader
385 362 : << "view" << std::endl;
386 362 : os << "{" << std::endl << lunchbox::indent;
387 :
388 362 : const std::string& name = view.getName();
389 362 : if( !name.empty( ))
390 2 : os << "name \"" << name << "\"" << std::endl;
391 :
392 362 : const Viewport& vp = view.getViewport();
393 362 : if( vp.isValid( ) && vp != Viewport::FULL )
394 118 : os << "viewport " << vp << std::endl;
395 :
396 362 : if( view.getMode() == View< L, V, O >::MODE_STEREO )
397 44 : os << "mode STEREO" << std::endl; // MONO is default
398 :
399 362 : const O* observer = static_cast< const O* >( view.getObserver( ));
400 362 : if( observer )
401 : {
402 350 : const std::string& observerName = observer->getName();
403 350 : const L* layout = view.getLayout();
404 350 : const O* foundObserver = 0;
405 350 : layout->getConfig()->find( observerName, &foundObserver );
406 :
407 350 : if( layout && foundObserver == observer )
408 : {
409 350 : os << "observer \"" << observerName << "\"" << std::endl;
410 : }
411 : else
412 0 : os << observer->getPath() << std::endl;
413 : }
414 :
415 362 : return os << static_cast< const Frustum& >( view )
416 362 : << lunchbox::exdent << "}" << std::endl << lunchbox::enableHeader
417 362 : << lunchbox::enableFlush;
418 : }
419 :
420 : }
421 : }
|