Line data Source code
1 :
2 : /* Copyright (c) 2009-2017, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Sarah Amsellem <sarah.amsellem@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #ifndef EQFABRIC_SUBPIXEL_H
20 : #define EQFABRIC_SUBPIXEL_H
21 :
22 : #include <eq/fabric/api.h>
23 : #include <eq/fabric/types.h>
24 : #include <lunchbox/bitOperation.h>
25 : #include <lunchbox/log.h>
26 : #include <lunchbox/types.h>
27 :
28 : namespace eq
29 : {
30 : namespace fabric
31 : {
32 : std::ostream& operator<<(std::ostream& os, const SubPixel& subPixel);
33 :
34 : /**
35 : * Holds a subpixel decomposition specification along with some methods for
36 : * manipulation.
37 : *
38 : * The index represents the contributor ID within the subpixel
39 : * decomposition. The size determines how many contributors are performing
40 : * anti-aliasing or any other subpixel decomposition.
41 : */
42 : class SubPixel
43 : {
44 : public:
45 : /** @name Constructors */
46 : //@{
47 : /** Construct an empty subpixel specification. @version 1.0 */
48 20190 : SubPixel()
49 20190 : : index(0)
50 20190 : , size(1)
51 : {
52 20190 : }
53 :
54 : /**
55 : * Construct a subpixel specification with default values.
56 : * @version 1.0
57 : */
58 52 : SubPixel(const uint32_t index_, const uint32_t size_)
59 52 : : index(index_)
60 52 : , size(size_)
61 : {
62 52 : }
63 : //@}
64 :
65 : /** Apply (accumulate) another subpixel specification. @internal */
66 590 : void apply(const SubPixel& rhs)
67 : {
68 590 : if (!isValid() || !rhs.isValid())
69 0 : return;
70 :
71 590 : index = index * rhs.size + rhs.index;
72 590 : size *= rhs.size;
73 : }
74 :
75 : /**
76 : * @return true if the two subpixel specifications are identical.
77 : * @version 1.0
78 : */
79 0 : bool operator==(const SubPixel& rhs) const
80 : {
81 0 : return index == rhs.index && size == rhs.size;
82 : }
83 :
84 : /**
85 : * @return true if the two subpixel specifications are not identical.
86 : * @version 1.0
87 : */
88 1216 : bool operator!=(const SubPixel& rhs) const
89 : {
90 1216 : return index != rhs.index || size != rhs.size;
91 : }
92 :
93 : /** Make the subpixel specification invalid. @internal */
94 : void invalidate() { index = size = 0; }
95 : /** Make the subpixel specification valid. @internal */
96 660 : void validate()
97 : {
98 660 : if (isValid())
99 660 : return;
100 0 : LBWARN << "Invalid " << *this << std::endl;
101 0 : if (index >= size)
102 0 : index = 0;
103 0 : if (size == 0)
104 0 : size = 1;
105 0 : LBWARN << "Corrected " << *this << std::endl;
106 : }
107 :
108 : /** @return true if the pixel specification is valid. @internal */
109 4174 : bool isValid() const { return (index < size); }
110 : uint32_t index; //!< The contributor id
111 : uint32_t size; //!< Total number of contributors
112 :
113 : EQFABRIC_API static const SubPixel ALL;
114 : };
115 :
116 30 : inline std::ostream& operator<<(std::ostream& os, const SubPixel& subPixel)
117 : {
118 30 : if (subPixel.isValid())
119 30 : os << "subpixel [ " << subPixel.index << ' ' << subPixel.size << " ]";
120 30 : return os;
121 : }
122 : }
123 : }
124 :
125 : #endif // EQFABRIC_SUBPIXEL_H
|