Equalizer  1.9.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
subPixel.h
1 
2 /* Copyright (c) 2009-2014, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2009, 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:
48  SubPixel() : index( 0 ), size( 1 ) {}
49 
54  SubPixel( const uint32_t index_, const uint32_t size_ )
55  : index( index_ ), size( size_ ) {}
57 
59  void apply( const SubPixel& rhs )
60  {
61  if( !isValid() || !rhs.isValid( ))
62  return;
63 
64  index = index * rhs.size + rhs.index;
65  size *= rhs.size;
66  }
67 
72  bool operator == ( const SubPixel& rhs ) const
73  {
74  return index==rhs.index && size==rhs.size;
75  }
76 
81  bool operator != ( const SubPixel& rhs ) const
82  {
83  return index != rhs.index || size != rhs.size;
84  }
85 
87  void invalidate() { index = size = 0; }
88 
90  void validate()
91  {
92  if( isValid( )) return;
93  LBWARN << "Invalid " << *this << std::endl;
94  if( index >= size ) index = 0;
95  if( size == 0 ) size = 1;
96  LBWARN << "Corrected " << *this << std::endl;
97  }
98 
100  bool isValid() const { return ( index < size ); }
101 
102  uint32_t index;
103  uint32_t size;
104 
105  EQFABRIC_API static const SubPixel ALL;
106  };
107 
108  inline std::ostream& operator << ( std::ostream& os,
109  const SubPixel& subPixel )
110  {
111  if( subPixel.isValid( ))
112  os << "subpixel [ " << subPixel.index << ' ' << subPixel.size
113  << " ]";
114  return os;
115  }
116 }
117 }
118 
119 namespace lunchbox
120 {
121 template<> inline void byteswap( eq::fabric::SubPixel& value )
122 {
123  byteswap( value.index );
124  byteswap( value.size );
125 }
126 }
127 #endif // EQFABRIC_SUBPIXEL_H
uint32_t index
The contributor id.
Definition: subPixel.h:102
bool isValid() const
Definition: subPixel.h:100
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:90
void invalidate()
Make the subpixel specification invalid.
Definition: subPixel.h:87
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:54
uint32_t size
Total number of contributors.
Definition: subPixel.h:103
bool operator!=(const SubPixel &rhs) const
Definition: subPixel.h:81
bool operator==(const SubPixel &rhs) const
Definition: subPixel.h:72
void apply(const SubPixel &rhs)
Apply (accumulate) another subpixel specification.
Definition: subPixel.h:59