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