Line data Source code
1 :
2 : /* Copyright (c) 2010-2016, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Cedric Stalder <cedric.stalder@gmail.com>
4 : * Julio Delgado Mangas <julio.delgadomangas@epfl.ch>
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_CHANNEL_H
21 : #define EQFABRIC_CHANNEL_H
22 :
23 : #include <eq/fabric/object.h> // base class
24 : #include <eq/fabric/paths.h>
25 : #include <eq/fabric/renderContext.h> // member
26 : #include <eq/fabric/types.h>
27 :
28 : namespace eq
29 : {
30 : namespace fabric
31 : {
32 : /** Base data transport class for channels. @sa eq::Channel */
33 : template< class W, class C > class Channel : public Object
34 : {
35 : public:
36 : typedef LeafVisitor< C > Visitor; //!< The channel visitor type
37 : typedef W Parent; //!< The parent window type
38 :
39 : /** @name Data Access */
40 : //@{
41 : /** @internal Initialize this channel (calls virtual methods) */
42 : void init();
43 :
44 : /** @return the parent window. @version 1.0 */
45 8266 : W* getWindow() { return _window; }
46 :
47 : /** @return the parent window. @version 1.0 */
48 0 : const W* getWindow() const { return _window; }
49 :
50 : /** @internal @return the native view identifier and version. */
51 0 : bool isDestination() const
52 0 : { return _data.nativeContext.view.identifier != 0;}
53 :
54 : /** @internal Update the native view identifier and version. */
55 : void setViewVersion( const co::ObjectVersion& view );
56 :
57 : /** @internal @return the native view identifier and version. */
58 0 : const co::ObjectVersion& getViewVersion() const
59 0 : { return _data.nativeContext.view; }
60 :
61 : /** @internal Set the channel's pixel viewport wrt its parent window. */
62 : void setPixelViewport( const PixelViewport& pvp );
63 :
64 : /** @internal Set the channel's viewport wrt its parent window. */
65 : EQFABRIC_INL void setViewport( const Viewport& vp );
66 :
67 : /** @internal Notification that the vp/pvp has changed. */
68 : virtual void notifyViewportChanged();
69 :
70 : /** @return the native pixel viewport. @version 1.0 */
71 0 : const PixelViewport& getNativePixelViewport() const
72 0 : { return _data.nativeContext.pvp; }
73 :
74 : /** @return true if a viewport was specified last. @version 1.0 */
75 2006 : bool hasFixedViewport() const { return _data.fixedVP; }
76 :
77 : /**
78 : * Set the near and far planes for this channel.
79 : *
80 : * The given near and far planes update the current perspective and
81 : * orthographics frustum accordingly. Furthermore, they will be used in the
82 : * future by the server to compute the frusta.
83 : *
84 : * @param nearPlane the near plane.
85 : * @param farPlane the far plane.
86 : * @version 1.0
87 : */
88 : EQFABRIC_INL void setNearFar( const float nearPlane, const float farPlane );
89 :
90 : /**
91 : * Perform a depth-first traversal of this channel.
92 : *
93 : * @param visitor the visitor.
94 : * @return the result of the visitor traversal.
95 : * @version 1.0
96 : */
97 : EQFABRIC_INL VisitorResult accept( Visitor& visitor );
98 :
99 : /** Const-version of accept(). @version 1.0 */
100 : EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
101 :
102 : /**
103 : * Set the capabilities supported by the channel
104 : *
105 : * Channel which do not support all capabilities required by the current
106 : * destination view do not execute any tasks. The capabilities are an
107 : * application-defined bit mask. By default all bits are set.
108 : * @version 1.0
109 : */
110 : EQFABRIC_INL void setCapabilities( const uint64_t bitmask );
111 :
112 : /** @return the supported capabilities. @version 1.0 */
113 : EQFABRIC_INL uint64_t getCapabilities() const;
114 :
115 : /** @warning Undocumented - may not be supported in the future */
116 : EQFABRIC_INL void setMaxSize( const Vector2i& size );
117 :
118 : void setOverdraw( const Vector4i& overdraw ); //!< @internal
119 4 : const Vector2i& getMaxSize() const { return _maxSize; } //!< @internal
120 :
121 : /** @internal @return the index path to this channel. */
122 : EQFABRIC_INL ChannelPath getPath() const;
123 :
124 : EQFABRIC_INL virtual void backup(); //!< @internal
125 : EQFABRIC_INL virtual void restore(); //!< @internal
126 : //@}
127 :
128 : /**
129 : * @name Context-specific data access.
130 : *
131 : * The data returned by these methods depends on the context (callback) they
132 : * are called from, typically the data for the current rendering task. If
133 : * they are called outside of a frame task method, they return the channel's
134 : * native parameter, e.g., a placeholder value for the task decomposition
135 : * parameters.
136 : */
137 : //@{
138 : /** @return the current draw buffer for glDrawBuffer. @version 1.0 */
139 0 : uint32_t getDrawBuffer() const { return _context->buffer; }
140 :
141 : /** @return the current read buffer for glReadBuffer. @version 1.0 */
142 0 : uint32_t getReadBuffer() const { return _context->buffer; }
143 :
144 : /** @return the current color mask for glColorMask. @version 1.0 */
145 0 : const ColorMask& getDrawBufferMask() const { return _context->bufferMask; }
146 :
147 : /**
148 : * @return the current pixel viewport for glViewport and glScissor.
149 : * @version 1.0
150 : */
151 844 : const PixelViewport& getPixelViewport() const { return _context->pvp; }
152 :
153 : /**
154 : * Select perspective or orthographic rendering.
155 : *
156 : * Influences the behaviour of getFrustum, getHeadTransform and the
157 : * corresponding apply methods in eq::Channel. Intended to be overwritten by
158 : * the implementation to select orthographic rendering.
159 : * @version 1.0
160 : */
161 0 : virtual bool useOrtho() const { return false; }
162 :
163 : /**
164 : * @return the current frustum for glFrustum or glOrtho.
165 : * @version 1.0
166 : */
167 0 : const Frustumf& getFrustum() const
168 0 : { return useOrtho() ? getOrtho() : getPerspective(); }
169 :
170 : /**
171 : * @return the current perspective frustum for glFrustum.
172 : * @version 1.0
173 : */
174 0 : const Frustumf& getPerspective() const { return _context->frustum; }
175 :
176 : /**
177 : * @return the current orthographic frustum for glOrtho.
178 : * @version 1.0
179 : */
180 0 : const Frustumf& getOrtho() const { return _context->ortho; }
181 :
182 : /**
183 : * Return the view matrix.
184 : *
185 : * The view matrix is part of the GL_MODEL*VIEW* matrix, and is typically
186 : * applied first to the GL_MODELVIEW matrix.
187 : *
188 : * @return the head transformation matrix
189 : * @version 1.0
190 : */
191 0 : const Matrix4f& getHeadTransform() const
192 0 : { return useOrtho() ? getOrthoTransform() : getPerspectiveTransform(); }
193 :
194 : /**
195 : * Return the perspective view matrix.
196 : *
197 : * The view matrix is part of the GL_MODEL*VIEW* matrix, and is typically
198 : * applied first to the GL_MODELVIEW matrix.
199 : *
200 : * @return the head transformation matrix
201 : * @version 1.0
202 : */
203 0 : const Matrix4f& getPerspectiveTransform() const
204 0 : { return _context->headTransform; }
205 :
206 : /**
207 : * Return the orthographic view matrix.
208 : *
209 : * The view matrix is part of the GL_MODEL*VIEW* matrix, and is typically
210 : * applied first to the GL_MODELVIEW matrix.
211 : *
212 : * @return the head transformation matrix
213 : * @version 1.0
214 : */
215 0 : const Matrix4f& getOrthoTransform() const
216 0 : { return _context->orthoTransform; }
217 :
218 : /**
219 : * @return the fractional viewport wrt the destination view.
220 : * @version 1.0
221 : */
222 1996 : const Viewport& getViewport() const { return _context->vp; }
223 :
224 : /**
225 : * @return the database range for the current rendering task.
226 : * @version 1.0
227 : */
228 0 : const Range& getRange() const { return _context->range; }
229 :
230 : /**
231 : * @return the pixel decomposition for the current rendering task.
232 : * @version 1.0
233 : */
234 0 : const Pixel& getPixel() const { return _context->pixel; }
235 :
236 : /**
237 : * @return the subpixel decomposition for the current rendering task.
238 : * @version 1.0
239 : */
240 0 : const SubPixel& getSubPixel() const { return _context->subPixel; }
241 :
242 : /**
243 : * @return the up/downscale zoom factor for the current rendering task.
244 : * @version 1.0
245 : */
246 0 : const Zoom& getZoom() const { return _context->zoom; }
247 :
248 : /**
249 : * @return the DPlex period for the current rendering task.
250 : * @version 1.0
251 : */
252 0 : uint32_t getPeriod() const { return _context->period; }
253 :
254 : /**
255 : * @return the DPlex phase for the current rendering task.
256 : * @version 1.0
257 : */
258 0 : uint32_t getPhase() const { return _context->phase; }
259 :
260 : /**
261 : * Get the channel's current position wrt the destination channel.
262 : *
263 : * Note that computing this value from the current viewport and pixel
264 : * viewport is inaccurate because it neglects rounding errors of the pixel
265 : * viewport done by the server.
266 : *
267 : * @return the channel's current position wrt the destination channel.
268 : * @version 1.0
269 : */
270 0 : const Vector2i& getPixelOffset() const { return _context->offset; }
271 :
272 : /** @return the currently rendered eye pass. @version 1.0 */
273 0 : Eye getEye() const { return _context->eye; }
274 :
275 : /** @warning Undocumented - may not be supported in the future */
276 2 : const Vector4i& getOverdraw() const { return _context->overdraw; }
277 :
278 : /** @warning Undocumented - may not be supported in the future */
279 0 : uint32_t getTaskID() const { return _context->taskID; }
280 :
281 : /** @return the current render context. */
282 0 : const RenderContext& getContext() const { return *_context; }
283 : //@}
284 :
285 : /** @name Attributes */
286 : //@{
287 : // Note: also update string array initialization in channel.cpp
288 : /** Integer attributes for a channel. @version 1.0 */
289 : enum IAttribute
290 : {
291 : /** Statistics gathering mode (OFF, FASTEST [ON], NICEST) */
292 : IATTR_HINT_STATISTICS,
293 : /** Use a send token for output frames (OFF, ON) */
294 : IATTR_HINT_SENDTOKEN,
295 : IATTR_LAST,
296 : IATTR_ALL = IATTR_LAST + 5
297 : };
298 :
299 : /** String attributes. */
300 : enum SAttribute
301 : {
302 : SATTR_DUMP_IMAGE,
303 : SATTR_LAST,
304 : SATTR_ALL = SATTR_LAST + 5
305 : };
306 :
307 : /** @return the value of an integer attribute. @version 1.0 */
308 : EQFABRIC_INL int32_t getIAttribute( const IAttribute attr ) const;
309 :
310 : /** @return the value of a string attribute. @version 1.7.2 */
311 : EQFABRIC_INL
312 : const std::string& getSAttribute( const SAttribute attr ) const;
313 :
314 : /** @return the name of an integer attribute. @version 1.7.2 */
315 : EQFABRIC_INL static const std::string& getIAttributeString(
316 : const IAttribute attr );
317 :
318 : /** @return the name of an string attribute. @version 1.7.2 */
319 : EQFABRIC_INL static const std::string& getSAttributeString(
320 : const SAttribute attr );
321 : //@}
322 :
323 0 : virtual bool omitOutput() const { return false; } //!< @internal
324 0 : virtual void output( std::ostream& ) const {} //!< @internal
325 :
326 : protected:
327 : /** Construct a new channel. @internal */
328 : EQFABRIC_INL explicit Channel( W* parent );
329 :
330 : /** Construct a copy of a channel (view/segment dest). @internal */
331 : Channel( const Channel& from );
332 :
333 : /** Destruct the channel. @internal */
334 : EQFABRIC_INL virtual ~Channel();
335 :
336 : /** @internal */
337 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
338 : const uint64_t dirtyBits );
339 : /** @internal */
340 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
341 : const uint64_t dirtyBits );
342 :
343 : /** @internal @sa Serializable::setDirty() */
344 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
345 :
346 : /** @name Render context access */
347 : //@{
348 : /** @internal Override the channel's native render context. */
349 0 : void overrideContext( const RenderContext& context )
350 0 : { _overrideContext = context; _context = &_overrideContext; }
351 :
352 : /** @internal Re-set the channel's native render context. */
353 0 : void resetContext() { _context = &_data.nativeContext; }
354 :
355 : /** @internal @return the native render context. */
356 0 : const RenderContext& getNativeContext() const
357 0 : { return _data.nativeContext; }
358 : //@}
359 :
360 : /** @internal */
361 11550 : void setIAttribute( const IAttribute attr, const int32_t value )
362 11550 : { _iAttributes[attr] = value; setDirty( DIRTY_ATTRIBUTES ); }
363 :
364 : /** @internal */
365 9902 : void setSAttribute( const SAttribute attr, const std::string& value )
366 9902 : { _sAttributes[attr] = value; setDirty( DIRTY_ATTRIBUTES ); }
367 :
368 : /** @internal */
369 10 : virtual ChangeType getChangeType() const { return UNBUFFERED; }
370 :
371 : enum DirtyBits
372 : {
373 : DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 0,
374 : DIRTY_VIEWPORT = Object::DIRTY_CUSTOM << 1,
375 : DIRTY_MEMBER = Object::DIRTY_CUSTOM << 2,
376 : DIRTY_FRUSTUM = Object::DIRTY_CUSTOM << 3,
377 : DIRTY_CAPABILITIES = Object::DIRTY_CUSTOM << 4,
378 : DIRTY_CHANNEL_BITS =
379 : DIRTY_ATTRIBUTES | DIRTY_VIEWPORT | DIRTY_MEMBER |
380 : DIRTY_FRUSTUM | DIRTY_OBJECT_BITS
381 : };
382 :
383 : /** @internal @return the bits to be re-committed by the master. */
384 0 : virtual uint64_t getRedistributableBits() const
385 0 : { return DIRTY_CHANNEL_BITS; }
386 :
387 1 : virtual void updateCapabilities() {} //!< @internal
388 :
389 : private:
390 : /** The parent window. */
391 : W* const _window;
392 :
393 5658 : struct BackupData
394 : {
395 6096 : BackupData() : capabilities( LB_BIT_ALL_64 ), fixedVP( true ) {}
396 :
397 : /** The native render context parameters of this channel. */
398 : RenderContext nativeContext;
399 :
400 : /** Bitmask of supported capabilities */
401 : uint64_t capabilities;
402 :
403 : /** true if the vp is immutable, false if the pvp is immutable */
404 : bool fixedVP;
405 : }
406 : _data, _backup;
407 :
408 : /** Overridden context data. */
409 : RenderContext _overrideContext;
410 :
411 : /** The current rendering context, points to native or override context. */
412 : RenderContext* _context;
413 :
414 : /** Integer attributes. */
415 : int32_t _iAttributes[IATTR_ALL];
416 :
417 : /** String attributes. */
418 : std::string _sAttributes[SATTR_ALL];
419 :
420 : /** Overdraw limiter */
421 : Vector2i _maxSize;
422 : };
423 :
424 : template< class W, class C > EQFABRIC_INL
425 : std::ostream& operator << ( std::ostream&, const Channel< W, C >& );
426 : }
427 : }
428 :
429 : #endif // EQFABRIC_CHANNEL_H
|