Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2006-2010, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 00004 * This library is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU Lesser General Public License version 2.1 as published 00006 * by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, but WITHOUT 00009 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00010 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00011 * details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this library; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 */ 00017 00018 #ifndef EQFABRIC_VIEWPORT_H 00019 #define EQFABRIC_VIEWPORT_H 00020 00021 #include <eq/fabric/api.h> 00022 #include <eq/fabric/types.h> 00023 #include <co/base/debug.h> 00024 00025 #include <iostream> 00026 00027 namespace eq 00028 { 00029 namespace fabric 00030 { 00031 class PixelViewport; 00032 class Viewport; 00033 std::ostream& operator << ( std::ostream& os, const Viewport& vp ); 00034 00036 class Viewport 00037 { 00038 public: 00042 Viewport() : x(0.0f), y(0.0f), w(1.0f), h(1.0f) {} 00043 00045 Viewport( const float x_, const float y_, const float w_,const float h_) 00046 : x(x_), y(y_), w(w_), h(h_) {} 00048 00050 void invalidate() { x=0.0f; y=0.0f; w=-1.0f; h=-1.0f; } 00051 00053 void apply( const Viewport& rhs ) 00054 { 00055 EQASSERTINFO( isValid(), *this); 00056 EQASSERTINFO( rhs.isValid(), rhs ); 00057 x += rhs.x * w; 00058 y += rhs.y * h; 00059 w *= rhs.w; 00060 h *= rhs.h; 00061 } 00062 00064 void transform( const Viewport& rhs ) 00065 { 00066 w = w / rhs.w; 00067 h = h / rhs.h; 00068 x = ( x - rhs.x ) / rhs.w; 00069 y = ( y - rhs.y ) / rhs.h; 00070 } 00071 00076 bool operator == ( const Viewport& rhs ) const 00077 { 00078 return ( x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h); 00079 } 00080 00085 bool operator != ( const Viewport& rhs ) const 00086 { 00087 return ( x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h); 00088 } 00089 00095 bool isValid() const 00096 { return ( x>=0.0f && y>=0.0f && w>=0.0f && h>=0.0f ); } 00097 00103 bool hasArea() const { return (w>0.0f && h>0.0f); } 00104 00106 float getArea() const { return w*h; } 00107 00109 float getXEnd() const { return x+w; } 00110 00112 float getYEnd() const { return y+h; } 00113 00115 void intersect( const Viewport& rhs ) 00116 { 00117 if( *this == rhs ) 00118 return; 00119 00120 if( !rhs.isValid() || !isValid() ) 00121 { 00122 invalidate(); 00123 return; 00124 } 00125 00126 if( !rhs.hasArea() || !hasArea() ) 00127 { 00128 x = 0; 00129 y = 0; 00130 w = 0; 00131 h = 0; 00132 return; 00133 } 00134 00135 const float sEx = static_cast< float >( x + w ); 00136 const float sEy = static_cast< float >( y + h ); 00137 const float dEx = static_cast< float >( rhs.x + rhs.w ); 00138 const float dEy = static_cast< float >( rhs.y + rhs.h ); 00139 00140 x = EQ_MAX( x, rhs.x ); 00141 y = EQ_MAX( y, rhs.y ); 00142 w = EQ_MIN( sEx, dEx ) - x; 00143 h = EQ_MIN( sEy, dEy ) - y; 00144 } 00145 00147 void unite( const Viewport& rhs ) 00148 { 00149 const float xEnd = EQ_MAX( getXEnd(), rhs.getXEnd( )); 00150 const float yEnd = EQ_MAX( getYEnd(), rhs.getYEnd( )); 00151 x = EQ_MIN( x, rhs.x ); 00152 y = EQ_MIN( y, rhs.y ); 00153 w = xEnd - x; 00154 h = yEnd - y; 00155 } 00156 00161 Viewport getCoverage( const Viewport& with ) const 00162 { 00163 Viewport coverage( with ); 00164 coverage.intersect( *this ); // intersection 00165 coverage.transform( *this ); // in our coordinate system 00166 00167 return coverage; 00168 } 00169 00171 EQFABRIC_API void applyView( const Viewport& segmentVP, 00172 const Viewport& viewVP, 00173 const PixelViewport& pvp, 00174 const Vector4i& overdraw ); 00175 00176 float x; 00177 float y; 00178 float w; 00179 float h; 00180 00181 EQFABRIC_API static const Viewport FULL; 00182 }; 00183 00184 inline std::ostream& operator << ( std::ostream& os, const Viewport& vp ) 00185 { 00186 os << "[ " << vp.x << " " << vp.y << " " << vp.w << " " << vp.h << " ]"; 00187 return os; 00188 } 00189 } 00190 } 00191 00192 #endif // EQFABRIC_VIEWPORT_H