Equalizer  2.1.0
Parallel Rendering Framework
subPixel.h
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 
42 class SubPixel
43 {
44 public:
49  : index(0)
50  , size(1)
51  {
52  }
53 
58  SubPixel(const uint32_t index_, const uint32_t size_)
59  : index(index_)
60  , size(size_)
61  {
62  }
64 
66  void apply(const SubPixel& rhs)
67  {
68  if (!isValid() || !rhs.isValid())
69  return;
70 
71  index = index * rhs.size + rhs.index;
72  size *= rhs.size;
73  }
74 
79  bool operator==(const SubPixel& rhs) const
80  {
81  return index == rhs.index && size == rhs.size;
82  }
83 
88  bool operator!=(const SubPixel& rhs) const
89  {
90  return index != rhs.index || size != rhs.size;
91  }
92 
94  void invalidate() { index = size = 0; }
96  void validate()
97  {
98  if (isValid())
99  return;
100  LBWARN << "Invalid " << *this << std::endl;
101  if (index >= size)
102  index = 0;
103  if (size == 0)
104  size = 1;
105  LBWARN << "Corrected " << *this << std::endl;
106  }
107 
109  bool isValid() const { return (index < size); }
110  uint32_t index;
111  uint32_t size;
112 
113  EQFABRIC_API static const SubPixel ALL;
114 };
115 
116 inline std::ostream& operator<<(std::ostream& os, const SubPixel& subPixel)
117 {
118  if (subPixel.isValid())
119  os << "subpixel [ " << subPixel.index << ' ' << subPixel.size << " ]";
120  return os;
121 }
122 }
123 }
124 
125 #endif // EQFABRIC_SUBPIXEL_H
uint32_t index
The contributor id.
Definition: subPixel.h:110
bool isValid() const
Definition: subPixel.h:109
Defines export visibility macros for library EqualizerFabric.
Holds a subpixel decomposition specification along with some methods for manipulation.
Definition: subPixel.h:42
void validate()
Make the subpixel specification valid.
Definition: subPixel.h:96
void invalidate()
Make the subpixel specification invalid.
Definition: subPixel.h:94
SubPixel()
Construct an empty subpixel specification.
Definition: subPixel.h:48
SubPixel(const uint32_t index_, const uint32_t size_)
Construct a subpixel specification with default values.
Definition: subPixel.h:58
The Equalizer client library.
Definition: eq/agl/types.h:23
std::ostream & operator<<(std::ostream &os, const AxisEvent &event)
Print the axis event to the given output stream.
Definition: axisEvent.h:49
uint32_t size
Total number of contributors.
Definition: subPixel.h:111
bool operator!=(const SubPixel &rhs) const
Definition: subPixel.h:88
bool operator==(const SubPixel &rhs) const
Definition: subPixel.h:79
void apply(const SubPixel &rhs)
Apply (accumulate) another subpixel specification.
Definition: subPixel.h:66