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 : #ifndef EQFABRIC_VIEW_H
21 : #define EQFABRIC_VIEW_H
22 :
23 : #include <eq/fabric/api.h>
24 : #include <eq/fabric/equalizer.h> // member
25 : #include <eq/fabric/frustum.h> // base class
26 : #include <eq/fabric/object.h> // base class
27 : #include <eq/fabric/types.h>
28 : #include <eq/fabric/viewport.h> // member
29 :
30 : #define EQ_MM 1000.f
31 : #define EQ_CM 100.f
32 : #define EQ_DM 10.f
33 : #define EQ_M 1.f
34 : #define EQ_KM 0.001f
35 : #define EQ_UNDEFINED_UNIT -1.f
36 :
37 : namespace eq
38 : {
39 : namespace fabric
40 : {
41 : /** Base data transport class for views. @sa eq::View */
42 : template< class L, class V, class O >
43 : class View : public Object, public Frustum
44 : {
45 : public:
46 : /** The current rendering mode. */
47 : enum Mode
48 : {
49 : MODE_MONO = 1, //!< Render in mono (cyclop eye)
50 : MODE_STEREO //!< Render in stereo (left & right eye)
51 : };
52 :
53 : /** @name Data Access. */
54 : //@{
55 : /** @return the viewport of the view wrt its layout. @version 1.0 */
56 : EQFABRIC_INL const Viewport& getViewport() const;
57 :
58 : /**
59 : * @return the parent layout of this view, 0 for render client views.
60 : * @version 1.0
61 : */
62 2347 : L* getLayout() { return _layout; }
63 :
64 : /**
65 : * @return the parent layout of this view, 0 for render client views.
66 : * @version 1.0
67 : */
68 1133 : const L* getLayout() const { return _layout; }
69 :
70 : /** Set the entity tracking this view. @version 1.0 */
71 : EQFABRIC_INL void setObserver( O* observer );
72 :
73 : /**
74 : * @return the observer tracking this view, or 0 for untracked views.
75 : * @version 1.0
76 : */
77 368 : O* getObserver() { return _observer; }
78 :
79 : /** const version of getObserver(). @version 1.0 */
80 325 : const O* getObserver() const { return _observer; }
81 :
82 : /** @warning Undocumented - may not be supported in the future */
83 : EQFABRIC_INL void setOverdraw( const Vector2i& pixels );
84 :
85 : /** @warning Undocumented - may not be supported in the future */
86 368 : const Vector2i& getOverdraw() const { return _overdraw; }
87 :
88 : /** @warning Undocumented - may not be supported in the future */
89 : EQFABRIC_INL void useEqualizer( uint32_t equalizerMask );
90 :
91 : /** @warning Undocumented - may not be supported in the future */
92 0 : uint32_t getEqualizers() const { return _equalizers; }
93 :
94 : /** @return read-access to Equalizer properties. @version 1.5.1 */
95 : EQFABRIC_INL const Equalizer& getEqualizer() const;
96 :
97 : /** @return write-access to Equalizer properties. @version 1.5.1 */
98 : EQFABRIC_INL Equalizer& getEqualizer();
99 :
100 : /** @internal Set the 2D viewport wrt Layout and Canvas. */
101 : EQFABRIC_INL void setViewport( const Viewport& viewport );
102 :
103 : /** @return the stereo mode of this view. @version 1.0 */
104 315 : Mode getMode() const { return _data.mode; }
105 :
106 : /**
107 : * Set the mode of this view.
108 : *
109 : * @param mode the new rendering mode
110 : * @version 1.0
111 : */
112 : EQFABRIC_INL virtual void changeMode( const Mode mode );
113 :
114 : /**
115 : * @internal
116 : * Activate the given mode on this view.
117 : *
118 : * @param mode the new rendering mode
119 : */
120 64 : virtual void activateMode( const Mode mode ){ _data.mode = mode; }
121 :
122 : /** @return true if the view's layout is active. @version 1.1.5 */
123 : EQFABRIC_INL bool isActive() const;
124 :
125 : /**
126 : * Set the model unit of this view.
127 : *
128 : * The model unit defines the size of the model wrt the virtual room
129 : * unit which is always in meter.
130 : *
131 : * @param modelUnit the new model unit value
132 : * @return true if the model unit has changed.
133 : * @version 1.3.1
134 : */
135 : EQFABRIC_INL bool setModelUnit( const float modelUnit );
136 :
137 : /**
138 : * Get the model unit of this view.
139 : *
140 : * The default model unit is 1 (1 meter or EQ_M).
141 : *
142 : * @return the model unit of this view.
143 : * @version 1.3.1
144 : */
145 : EQFABRIC_INL float getModelUnit() const;
146 :
147 : /** Set the DisplayCluster hostname for this view. @version 1.5.2 */
148 : void setDisplayCluster( const std::string& hostname );
149 :
150 : /** @return the DisplayCluster host name. @version 1.5.2 */
151 : const std::string& getDisplayCluster() const;
152 : //@}
153 :
154 : /** @name Operations */
155 : //@{
156 : /**
157 : * Traverse this view using a view visitor.
158 : *
159 : * @param visitor the visitor.
160 : * @return the result of the visitor traversal.
161 : * @version 1.0
162 : */
163 : EQFABRIC_INL VisitorResult accept( LeafVisitor< V >& visitor );
164 :
165 : /** Const-version of accept(). @version 1.0 */
166 : EQFABRIC_INL VisitorResult accept( LeafVisitor< V >& visitor ) const;
167 :
168 : virtual EQFABRIC_INL void backup(); //!< @internal
169 : virtual EQFABRIC_INL void restore(); //!< @internal
170 :
171 : /**
172 : * Set the minimum required capabilities for this view.
173 : *
174 : * Any channel which does not support all of the bits in this mask does
175 : * not execute any tasks. By default no bit is set.
176 : *
177 : * @param bitmask the capabilities as bitmask
178 : * @version 1.0
179 : */
180 : EQFABRIC_INL void setMinimumCapabilities( const uint64_t bitmask );
181 :
182 : /** @return the bitmask of the minimum capabilities. @version 1.0 */
183 : EQFABRIC_INL uint64_t getMinimumCapabilities() const;
184 :
185 : /**
186 : * Set the maximum desired capabilities for this view.
187 : *
188 : * The capabilities returned by getCapabilities() during rendering match
189 : * the lowest common denominator of all channel capabilities and this
190 : * bitmask. Logically it has to be a superset of the minimum
191 : * capabilities. By default all bits are set.
192 : *
193 : * The capabilities are used to selectively disable source channels in
194 : * conjunction with a load equalizer. Each channel typically sets its
195 : * capabilities during configInit. The application sets the minimum
196 : * and maximum capabilities needed or desired to render this view. The
197 : * channel queries the capabilities to be used using getCapabilities().
198 : *
199 : * @param bitmask the capabilities as bitmask
200 : * @version 1.0
201 : */
202 : EQFABRIC_INL void setMaximumCapabilities(const uint64_t bitmask);
203 :
204 : /**
205 : * @return the bitmask that represents the maximum capabilities.
206 : * @version 1.0
207 : */
208 : EQFABRIC_INL uint64_t getMaximumCapabilities() const;
209 :
210 : /**
211 : * @return the bitmask usable for rendering.
212 : * @sa setMaximumCapabilities()
213 : * @version 1.0
214 : */
215 : EQFABRIC_INL uint64_t getCapabilities() const;
216 : //@}
217 :
218 : void setCapabilities( const uint64_t bitmask ); //!< @internal
219 64 : virtual void updateCapabilities() {} //!< @internal
220 :
221 : /** @internal */
222 : enum DirtyBits
223 : {
224 : DIRTY_VIEWPORT = Object::DIRTY_CUSTOM << 0,
225 : DIRTY_OBSERVER = Object::DIRTY_CUSTOM << 1,
226 : DIRTY_OVERDRAW = Object::DIRTY_CUSTOM << 2,
227 : DIRTY_FRUSTUM = Object::DIRTY_CUSTOM << 3,
228 : DIRTY_MODE = Object::DIRTY_CUSTOM << 4,
229 : DIRTY_MINCAPS = Object::DIRTY_CUSTOM << 5,
230 : DIRTY_MAXCAPS = Object::DIRTY_CUSTOM << 6,
231 : DIRTY_CAPABILITIES = Object::DIRTY_CUSTOM << 7,
232 : DIRTY_EQUALIZER = Object::DIRTY_CUSTOM << 8,
233 : DIRTY_EQUALIZERS = Object::DIRTY_CUSTOM << 9,
234 : DIRTY_MODELUNIT = Object::DIRTY_CUSTOM << 10,
235 : DIRTY_DISPLAYCLUSTER = Object::DIRTY_CUSTOM << 11,
236 : DIRTY_VIEW_BITS =
237 : DIRTY_VIEWPORT | DIRTY_OBSERVER | DIRTY_OVERDRAW |
238 : DIRTY_FRUSTUM | DIRTY_MODE | DIRTY_MINCAPS | DIRTY_MAXCAPS |
239 : DIRTY_CAPABILITIES | DIRTY_OBJECT_BITS | DIRTY_EQUALIZER |
240 : DIRTY_EQUALIZERS | DIRTY_MODELUNIT | DIRTY_DISPLAYCLUSTER
241 : };
242 :
243 : protected:
244 : /** @internal Construct a new view. */
245 : EQFABRIC_INL View( L* layout );
246 :
247 : /** @internal Destruct this view. */
248 : EQFABRIC_INL virtual ~View();
249 :
250 : /**
251 : * The application view instance holds the user data master by default.
252 : * @sa Object::hasMasterUserData().
253 : * @version 1.0
254 : */
255 32 : virtual bool hasMasterUserData() { return getLayout() != 0; }
256 :
257 : /**
258 : * The view user data instance uses the config latency by default.
259 : * @sa Object::getUserDataLatency().
260 : * @version 1.0
261 : */
262 : EQFABRIC_INL virtual uint32_t getUserDataLatency() const;
263 :
264 : /** @internal */
265 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
266 : const uint64_t dirtyBits );
267 :
268 : /** @internal */
269 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
270 : const uint64_t dirtyBits );
271 :
272 : /** @internal */
273 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
274 :
275 : /** @internal @return the bits to be re-committed by the master. */
276 8 : virtual uint64_t getRedistributableBits() const
277 8 : { return DIRTY_VIEW_BITS; }
278 :
279 : /** @internal */
280 175 : virtual void notifyFrustumChanged() { setDirty( DIRTY_FRUSTUM ); }
281 :
282 : private:
283 : /** Parent layout (application-side). */
284 : L* const _layout;
285 :
286 : /** The observer for tracking. */
287 : O* _observer;
288 :
289 : Equalizer _equalizer; //!< Equalizer settings
290 : /** Enlarge size of dest channels and adjust frustum accordingly. */
291 : Vector2i _overdraw;
292 :
293 : uint64_t _minimumCapabilities; //!< caps required from channels
294 : uint64_t _maximumCapabilities; //!< caps used from channels
295 : uint64_t _capabilities; //!< intersection of all active channel caps
296 : uint32_t _equalizers; //!< Active Equalizers
297 : float _modelUnit; //!< Scaling of scene in this view
298 : std::string _displayCluster;
299 :
300 : struct BackupData
301 : {
302 : BackupData();
303 :
304 : /** Logical 2D area of Canvas covered. */
305 : Viewport viewport;
306 :
307 : Mode mode; //!< Stereo mode
308 : }
309 : _data, _backup;
310 :
311 : struct Private;
312 : Private* _private; // placeholder for binary-compatible changes
313 : };
314 :
315 : template< class L, class V, class O >
316 : EQFABRIC_INL std::ostream& operator << ( std::ostream& os,
317 : const View< L, V, O >& view );
318 : }
319 : }
320 : #endif // EQFABRIC_VIEW_H
|