Line data Source code
1 :
2 : /* Copyright (c) 2012-2017, 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 66612 : struct ToNodes
29 : {
30 : std::vector<uint128_t> inputNodes;
31 : co::NodeIDs inputNetNodes;
32 : };
33 :
34 : namespace detail
35 : {
36 22204 : 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 72 : void serialize(co::DataOStream& os) const
47 : {
48 72 : os << name << offset << zoom;
49 :
50 288 : for (unsigned i = 0; i < NUM_EYES; ++i)
51 216 : os << frameDataVersion[i] << toNodes[i].inputNodes
52 432 : << toNodes[i].inputNetNodes;
53 72 : }
54 :
55 4 : void deserialize(co::DataIStream& is)
56 : {
57 4 : is >> name >> offset >> zoom;
58 :
59 16 : for (unsigned i = 0; i < NUM_EYES; ++i)
60 12 : is >> frameDataVersion[i] >> toNodes[i].inputNodes >>
61 24 : toNodes[i].inputNetNodes;
62 4 : }
63 : };
64 : }
65 11102 : Frame::Frame()
66 11102 : : _impl(new detail::Frame)
67 : {
68 11102 : }
69 :
70 22204 : Frame::~Frame()
71 : {
72 11102 : delete _impl;
73 11102 : }
74 :
75 72 : void Frame::getInstanceData(co::DataOStream& os)
76 : {
77 72 : _impl->serialize(os);
78 72 : }
79 :
80 4 : void Frame::applyInstanceData(co::DataIStream& is)
81 : {
82 4 : _impl->deserialize(is);
83 4 : }
84 :
85 5548 : void Frame::setName(const std::string& name)
86 : {
87 5548 : _impl->name = name;
88 5548 : }
89 :
90 8426 : const std::string& Frame::getName() const
91 : {
92 8426 : return _impl->name;
93 : }
94 :
95 138 : const Vector2i& Frame::getOffset() const
96 : {
97 138 : return _impl->offset;
98 : }
99 :
100 8 : void Frame::setOffset(const Vector2i& offset)
101 : {
102 8 : _impl->offset = offset;
103 8 : }
104 :
105 5556 : void Frame::setZoom(const Zoom& zoom)
106 : {
107 5556 : _impl->zoom = zoom;
108 5556 : }
109 :
110 3008 : const Zoom& Frame::getZoom() const
111 : {
112 3008 : return _impl->zoom;
113 : }
114 :
115 24 : void Frame::_setDataVersion(const unsigned i, const co::ObjectVersion& ov)
116 : {
117 24 : _impl->frameDataVersion[i] = ov;
118 24 : }
119 :
120 4 : const co::ObjectVersion& Frame::getDataVersion(const Eye eye) const
121 : {
122 4 : return _impl->frameDataVersion[lunchbox::getIndexOfLastBit(eye)];
123 : }
124 :
125 4 : const std::vector<uint128_t>& Frame::getInputNodes(const Eye eye) const
126 : {
127 4 : return _impl->toNodes[lunchbox::getIndexOfLastBit(eye)].inputNodes;
128 : }
129 :
130 4 : const co::NodeIDs& Frame::getInputNetNodes(const Eye eye) const
131 : {
132 4 : return _impl->toNodes[lunchbox::getIndexOfLastBit(eye)].inputNetNodes;
133 : }
134 :
135 196 : std::vector<uint128_t>& Frame::_getInputNodes(const unsigned i)
136 : {
137 196 : return _impl->toNodes[i].inputNodes;
138 : }
139 :
140 196 : co::NodeIDs& Frame::_getInputNetNodes(const unsigned i)
141 : {
142 196 : return _impl->toNodes[i].inputNetNodes;
143 : }
144 :
145 0 : std::ostream& operator<<(std::ostream& os, const Frame& frame)
146 : {
147 0 : os << lunchbox::disableFlush << "frame" << std::endl
148 0 : << "{" << std::endl
149 0 : << lunchbox::indent << "name \"" << frame.getName() << "\""
150 0 : << 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 70 : std::ostream& operator<<(std::ostream& os, const Frame::Type type)
160 : {
161 70 : os << "type ";
162 70 : if (type == Frame::TYPE_TEXTURE)
163 70 : os << " texture" << std::endl;
164 0 : else if (type == Frame::TYPE_MEMORY)
165 0 : os << " memory" << std::endl;
166 :
167 70 : 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 60 : }
|