Line data Source code
1 :
2 : /* Copyright (c) 2012-2014, 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 : #include "frame.h"
19 :
20 : #include "zoom.h"
21 : #include <co/dataIStream.h>
22 : #include <co/dataOStream.h>
23 :
24 : namespace eq
25 : {
26 : namespace fabric
27 : {
28 35118 : struct ToNodes
29 : {
30 : std::vector< uint128_t > inputNodes;
31 : co::NodeIDs inputNetNodes;
32 : };
33 :
34 : namespace detail
35 : {
36 5853 : class Frame
37 : {
38 : public:
39 : // shared data:
40 : std::string name;
41 : Vector2i offset;
42 : Zoom zoom;
43 : co::ObjectVersion frameDataVersion[ NUM_EYES ];
44 : ToNodes toNodes[ NUM_EYES ];
45 :
46 5853 : Frame() : offset( Vector2i::ZERO ) {}
47 :
48 180 : void serialize( co::DataOStream& os ) const
49 : {
50 180 : os << name << offset << zoom;
51 :
52 720 : for( unsigned i = 0; i < NUM_EYES; ++i )
53 540 : os << frameDataVersion[i] << toNodes[i].inputNodes
54 1080 : << toNodes[i].inputNetNodes;
55 180 : }
56 :
57 4 : void deserialize( co::DataIStream& is )
58 : {
59 4 : is >> name >> offset >> zoom;
60 :
61 16 : for( unsigned i = 0; i < NUM_EYES; ++i )
62 12 : is >> frameDataVersion[i] >> toNodes[i].inputNodes
63 24 : >> toNodes[i].inputNetNodes;
64 4 : }
65 : };
66 : }
67 5853 : Frame::Frame()
68 5853 : : _impl( new detail::Frame )
69 5853 : {}
70 :
71 11706 : Frame::~Frame()
72 : {
73 5853 : delete _impl;
74 5853 : }
75 :
76 180 : void Frame::getInstanceData( co::DataOStream& os )
77 : {
78 180 : _impl->serialize( os );
79 180 : }
80 :
81 4 : void Frame::applyInstanceData( co::DataIStream& is )
82 : {
83 4 : _impl->deserialize( is );
84 4 : }
85 :
86 2924 : void Frame::setName( const std::string& name )
87 : {
88 2924 : _impl->name = name;
89 2924 : }
90 :
91 4647 : const std::string& Frame::getName() const
92 : {
93 4647 : return _impl->name;
94 : }
95 :
96 143 : const Vector2i& Frame::getOffset() const
97 : {
98 143 : return _impl->offset;
99 : }
100 :
101 18 : void Frame::setOffset( const Vector2i& offset )
102 : {
103 18 : _impl->offset = offset;
104 18 : }
105 :
106 2942 : void Frame::setZoom( const Zoom& zoom )
107 : {
108 2942 : _impl->zoom = zoom;
109 2942 : }
110 :
111 1748 : const Zoom& Frame::getZoom() const
112 : {
113 1748 : return _impl->zoom;
114 : }
115 :
116 54 : void Frame::_setDataVersion( const unsigned i, const co::ObjectVersion& ov )
117 : {
118 54 : _impl->frameDataVersion[ i ] = ov;
119 54 : }
120 :
121 4 : const co::ObjectVersion& Frame::getDataVersion( const Eye eye ) const
122 : {
123 4 : return _impl->frameDataVersion[ lunchbox::getIndexOfLastBit( eye )];
124 : }
125 :
126 4 : const std::vector< uint128_t >& Frame::getInputNodes( const Eye eye ) const
127 : {
128 4 : return _impl->toNodes[ lunchbox::getIndexOfLastBit( eye )].inputNodes;
129 : }
130 :
131 4 : const co::NodeIDs& Frame::getInputNetNodes(const Eye eye) const
132 : {
133 4 : return _impl->toNodes[ lunchbox::getIndexOfLastBit( eye )].inputNetNodes;
134 : }
135 :
136 459 : std::vector< uint128_t >& Frame::_getInputNodes( const unsigned i )
137 : {
138 459 : return _impl->toNodes[ i ].inputNodes;
139 : }
140 :
141 459 : co::NodeIDs& Frame::_getInputNetNodes( const unsigned i )
142 : {
143 459 : return _impl->toNodes[ i ].inputNetNodes;
144 : }
145 :
146 0 : std::ostream& operator << ( std::ostream& os, const Frame& frame )
147 : {
148 0 : os << lunchbox::disableFlush << "frame" << std::endl
149 0 : << "{" << std::endl << lunchbox::indent
150 0 : << "name \"" << frame.getName() << "\"" << std::endl;
151 :
152 0 : const Zoom& zoom = frame.getZoom();
153 0 : if( zoom.isValid() && zoom != Zoom::NONE )
154 0 : os << zoom << std::endl;
155 :
156 0 : return os << lunchbox::exdent << "}" << std::endl << lunchbox::enableFlush;
157 : }
158 :
159 29 : std::ostream& operator << ( std::ostream& os, const Frame::Type type )
160 : {
161 29 : os << "type ";
162 29 : if ( type == Frame::TYPE_TEXTURE )
163 29 : os << " texture" << std::endl;
164 0 : else if ( type == Frame::TYPE_MEMORY )
165 0 : os << " memory" << std::endl;
166 :
167 29 : return os;
168 : }
169 :
170 0 : std::ostream& operator << ( std::ostream& os, const Frame::Buffer buffer )
171 : {
172 0 : if( buffer == Frame::BUFFER_NONE )
173 0 : os << "none ";
174 0 : else if( buffer & Frame::BUFFER_UNDEFINED )
175 0 : os << "undefined ";
176 : else
177 : {
178 0 : if( buffer & Frame::BUFFER_COLOR )
179 0 : os << "color ";
180 0 : if( buffer & Frame::BUFFER_DEPTH )
181 0 : os << "depth ";
182 : }
183 :
184 0 : return os;
185 : }
186 :
187 : }
188 45 : }
|