Line data Source code
1 :
2 : /* Copyright (c) 2010-2015, Stefan Eilemann <eile@eyescale.ch>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQFABRIC_SEGMENT_H
19 : #define EQFABRIC_SEGMENT_H
20 :
21 : #include <eq/fabric/types.h>
22 : #include <eq/fabric/frustum.h> // base class
23 : #include <eq/fabric/object.h> // base class
24 : #include <eq/fabric/swapBarrier.h> // RefPtr member
25 : #include <eq/fabric/viewport.h> // member
26 :
27 : namespace eq
28 : {
29 : namespace fabric
30 : {
31 : /** Base data transport class for segments. @sa eq::Segment */
32 : template< class C, class S, class CH >
33 : // cppcheck-suppress noConstructor
34 : class Segment : public Object, public Frustum
35 : {
36 : public:
37 : /** The segment visitor type. @version 1.0 */
38 : typedef LeafVisitor< S > Visitor;
39 :
40 : /** @name Data Access */
41 : //@{
42 : /** @return the parent canvas. @version 1.0 */
43 1570 : const C* getCanvas() const { return _canvas; }
44 :
45 : /** @return the parent canvas. @version 1.0 */
46 2278 : C* getCanvas() { return _canvas; }
47 :
48 : /** @return the segment's viewport. @version 1.0 */
49 3174 : const Viewport& getViewport() const { return _vp; }
50 :
51 : /**
52 : * @internal
53 : * Set the segment's viewport wrt its canvas.
54 : *
55 : * The viewport defines which 2D area of the canvas is covered by this
56 : * segment. Destination channels are created on the intersection of
57 : * segment viewports and the views of the layout used by the canvas.
58 : *
59 : * @param vp the fractional viewport.
60 : */
61 : EQFABRIC_INL void setViewport( const Viewport& vp );
62 :
63 : /**
64 : * @internal
65 : * Set the channel of this segment.
66 : *
67 : * The channel defines the output area for this segment, typically a
68 : * rendering area covering a graphics card output.
69 : *
70 : * @param channel the channel.
71 : */
72 754 : void setChannel( CH* channel )
73 754 : { _channel = channel; setDirty( DIRTY_CHANNEL ); }
74 :
75 : /** Return the output channel of this segment. @version 1.0 */
76 1178 : CH* getChannel() { return _channel; }
77 :
78 : /** Return the output channel of this segment. @version 1.0 */
79 1134 : const CH* getChannel() const { return _channel; }
80 :
81 : /** @internal @sa Frustum::setWall() */
82 : EQFABRIC_INL virtual void setWall( const Wall& wall );
83 :
84 : /** @internal @sa Frustum::setProjection() */
85 : EQFABRIC_INL virtual void setProjection( const Projection& );
86 :
87 : /** @internal @sa Frustum::unsetFrustum() */
88 : EQFABRIC_INL virtual void unsetFrustum();
89 :
90 : /** @return the bitwise OR of the eye values. @version 1.0 */
91 384 : uint32_t getEyes() const { return _eyes; }
92 :
93 : /**
94 : * @internal
95 : * Set the eyes to be used by the segument.
96 : *
97 : * Previously set eyes are overwritten.
98 : *
99 : * @param eyes the segment eyes.
100 : */
101 : EQFABRIC_INL void setEyes( const uint32_t eyes );
102 :
103 : /**
104 : * @internal
105 : * Add eyes to be used by the segument.
106 : *
107 : * Previously set eyes are preserved.
108 : *
109 : * @param eyes the segument eyes.
110 : */
111 72 : void enableEye( const uint32_t eyes ) { _eyes |= eyes; }
112 :
113 : /** @internal
114 : * Set a swap barrier.
115 : *
116 : * This barrier will be set as a barrier on all destination compounds ,
117 : * unless the compounds already has a barrier.
118 : *
119 : * @param barrier the swap barrier.
120 : */
121 : EQFABRIC_INL void setSwapBarrier( SwapBarrierPtr barrier );
122 :
123 : /** @internal @return the current swap barrier. */
124 378 : SwapBarrierConstPtr getSwapBarrier() const { return _swapBarrier; }
125 :
126 : /** @internal @return the current swap barrier. */
127 1178 : SwapBarrierPtr getSwapBarrier() { return _swapBarrier; }
128 : //@}
129 :
130 : /** @name Operations */
131 : //@{
132 : /**
133 : * Traverse this segment using a segment visitor.
134 : *
135 : * @param visitor the visitor.
136 : * @return the result of the visitor traversal.
137 : * @version 1.0
138 : */
139 : EQFABRIC_INL VisitorResult accept( Visitor& visitor );
140 :
141 : /** Const-version of accept(). @version 1.0 */
142 : EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
143 :
144 : /** @internal Update unset frustum from parent */
145 : void inheritFrustum();
146 :
147 : virtual void backup(); //!< @internal
148 : virtual void restore(); //!< @internal
149 :
150 : /** @internal */
151 : virtual uint128_t commit( const uint32_t incarnation=CO_COMMIT_NEXT );
152 : //@}
153 :
154 : protected:
155 : /** @internal Construct a new Segment. */
156 : EQFABRIC_INL explicit Segment( C* canvas );
157 :
158 : /** @internal Destruct this segment. */
159 : EQFABRIC_INL virtual ~Segment();
160 :
161 : /** @internal */
162 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
163 : const uint64_t dirtyBits );
164 : /** @internal */
165 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
166 : const uint64_t dirtyBits );
167 : virtual void setDirty( const uint64_t bits ); //!< @internal
168 :
169 : /** @internal */
170 : enum DirtyBits
171 : {
172 : DIRTY_VIEWPORT = Object::DIRTY_CUSTOM << 0,
173 : DIRTY_FRUSTUM = Object::DIRTY_CUSTOM << 1,
174 : DIRTY_CHANNEL = Object::DIRTY_CUSTOM << 2,
175 : DIRTY_EYES = Object::DIRTY_CUSTOM << 3,
176 : DIRTY_SEGMENT_BITS = DIRTY_VIEWPORT | DIRTY_FRUSTUM |
177 : DIRTY_CHANNEL | DIRTY_EYES | DIRTY_OBJECT_BITS
178 : };
179 :
180 : /** @internal @return the bits to be re-committed by the master. */
181 0 : virtual uint64_t getRedistributableBits() const
182 0 : { return DIRTY_SEGMENT_BITS; }
183 :
184 : /** @internal */
185 422 : virtual void notifyFrustumChanged() { setDirty( DIRTY_FRUSTUM ); }
186 :
187 : private:
188 : /** The parent canvas. */
189 : C* const _canvas;
190 :
191 : /** The 2D area of this segment wrt to the canvas. */
192 : Viewport _vp;
193 :
194 : /** The output channel of this segment. */
195 : CH* _channel;
196 :
197 : uint32_t _eyes;
198 :
199 : SwapBarrierPtr _swapBarrier; //!< default segment swap barrier
200 :
201 : struct Private;
202 : Private* _private; // placeholder for binary-compatible changes
203 : };
204 :
205 : template< class C, class S, class CH >
206 : std::ostream& operator << ( std::ostream&, const Segment< C, S, CH >& );
207 : }
208 : }
209 : #endif // EQFABRIC_SEGMENT_H
|