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