Equalizer
1.4.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 <lunchbox/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 explicit Viewport( const float x_, const float y_, 00046 const float w_, const float h_ ) 00047 : x(x_), y(y_), w(w_), h(h_) {} 00048 00050 explicit Viewport( const Vector4f& from ) 00051 : x( from[0] ), y( from[1] ), w( from[2] ), h( from[3] ) {} 00053 00055 void invalidate() { x=0.0f; y=0.0f; w=-1.0f; h=-1.0f; } 00056 00058 void apply( const Viewport& rhs ) 00059 { 00060 LBASSERTINFO( isValid(), *this); 00061 LBASSERTINFO( rhs.isValid(), rhs ); 00062 x += rhs.x * w; 00063 y += rhs.y * h; 00064 w *= rhs.w; 00065 h *= rhs.h; 00066 } 00067 00069 void transform( const Viewport& rhs ) 00070 { 00071 w = w / rhs.w; 00072 h = h / rhs.h; 00073 x = ( x - rhs.x ) / rhs.w; 00074 y = ( y - rhs.y ) / rhs.h; 00075 } 00076 00081 bool operator == ( const Viewport& rhs ) const 00082 { 00083 return ( x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h); 00084 } 00085 00090 bool operator != ( const Viewport& rhs ) const 00091 { 00092 return ( x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h); 00093 } 00094 00100 bool isValid() const 00101 { return ( x>=0.0f && y>=0.0f && w>=0.0f && h>=0.0f ); } 00102 00108 bool hasArea() const { return (w>0.0f && h>0.0f); } 00109 00111 float getArea() const { return w*h; } 00112 00114 float getXEnd() const { return x+w; } 00115 00117 float getYEnd() const { return y+h; } 00118 00120 void intersect( const Viewport& rhs ) 00121 { 00122 if( *this == rhs ) 00123 return; 00124 00125 if( !rhs.isValid() || !isValid() ) 00126 { 00127 invalidate(); 00128 return; 00129 } 00130 00131 if( !rhs.hasArea() || !hasArea() ) 00132 { 00133 x = 0; 00134 y = 0; 00135 w = 0; 00136 h = 0; 00137 return; 00138 } 00139 00140 const float sEx = static_cast< float >( x + w ); 00141 const float sEy = static_cast< float >( y + h ); 00142 const float dEx = static_cast< float >( rhs.x + rhs.w ); 00143 const float dEy = static_cast< float >( rhs.y + rhs.h ); 00144 00145 x = LB_MAX( x, rhs.x ); 00146 y = LB_MAX( y, rhs.y ); 00147 w = LB_MIN( sEx, dEx ) - x; 00148 h = LB_MIN( sEy, dEy ) - y; 00149 } 00150 00152 void unite( const Viewport& rhs ) 00153 { 00154 const float xEnd = LB_MAX( getXEnd(), rhs.getXEnd( )); 00155 const float yEnd = LB_MAX( getYEnd(), rhs.getYEnd( )); 00156 x = LB_MIN( x, rhs.x ); 00157 y = LB_MIN( y, rhs.y ); 00158 w = xEnd - x; 00159 h = yEnd - y; 00160 } 00161 00166 Viewport getCoverage( const Viewport& with ) const 00167 { 00168 Viewport coverage( with ); 00169 coverage.intersect( *this ); // intersection 00170 coverage.transform( *this ); // in our coordinate system 00171 00172 return coverage; 00173 } 00174 00176 EQFABRIC_API void applyView( const Viewport& segmentVP, 00177 const Viewport& viewVP, 00178 const PixelViewport& pvp, 00179 const Vector4i& overdraw ); 00180 00181 float x; 00182 float y; 00183 float w; 00184 float h; 00185 00186 EQFABRIC_API static const Viewport FULL; 00187 }; 00188 00189 inline std::ostream& operator << ( std::ostream& os, const Viewport& vp ) 00190 { 00191 os << "[ " << vp.x << " " << vp.y << " " << vp.w << " " << vp.h << " ]"; 00192 return os; 00193 } 00194 } 00195 } 00196 00197 #endif // EQFABRIC_VIEWPORT_H