Equalizer 1.0
|
00001 00002 /* Copyright (c) 2006-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2010, Cedric Stalder <cedric.stalder@gmail.com> 00004 * 00005 * This library is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Lesser General Public License version 2.1 as published 00007 * by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this library; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef EQ_IMAGE_H 00020 #define EQ_IMAGE_H 00021 00022 #include <eq/frame.h> // for Frame::Buffer enum 00023 #include <eq/pixelData.h> // member 00024 #include <eq/windowSystem.h> // for OpenGL types 00025 00026 #include <eq/util/texture.h> // member 00027 #include <eq/util/types.h> 00028 #include <eq/fabric/pixelViewport.h> // member 00029 #include <eq/fabric/viewport.h> // member 00030 00031 #include <co/plugins/compressor.h> // EqCompressorInfos typedef 00032 #include <co/base/buffer.h> // member 00033 00034 00035 namespace eq 00036 { 00042 class Image 00043 { 00044 public: 00046 EQ_API Image(); 00047 00049 EQ_API virtual ~Image(); 00050 00065 EQ_API void setInternalFormat( const Frame::Buffer buffer, 00066 const uint32_t internalFormat ); 00067 00069 EQ_API uint32_t getInternalFormat( const Frame::Buffer buffer )const; 00070 00083 uint32_t getExternalFormat( const Frame::Buffer buffer ) const 00084 { return _getMemory( buffer ).externalFormat; } 00085 00093 uint32_t getPixelSize( const Frame::Buffer buffer ) const 00094 { return _getMemory( buffer ).pixelSize; } 00095 00101 EQ_API bool hasAlpha() const; 00102 00114 void setStorageType( const Frame::Type type ) { _type = type; } 00115 00117 Frame::Type getStorageType() const{ return _type; } 00118 00130 EQ_API void setPixelViewport( const PixelViewport& pvp ); 00131 00133 const PixelViewport& getPixelViewport() const { return _pvp; } 00134 00144 EQ_API void reset(); 00145 00147 EQ_API void flush(); 00149 00153 EQ_API const uint8_t* getPixelPointer( const Frame::Buffer buffer ) 00154 const; 00155 00157 EQ_API uint8_t* getPixelPointer( const Frame::Buffer buffer ); 00158 00160 EQ_API uint32_t getPixelDataSize( const Frame::Buffer buffer ) const; 00161 00163 EQ_API const PixelData& getPixelData( const Frame::Buffer ) const; 00164 00166 EQ_API const PixelData& compressPixelData( const Frame::Buffer ); 00167 00172 bool hasPixelData( const Frame::Buffer buffer ) const 00173 { return _getAttachment( buffer ).memory.state == Memory::VALID; } 00174 00185 EQ_API void clearPixelData( const Frame::Buffer buffer ); 00186 00188 EQ_API void validatePixelData( const Frame::Buffer buffer ); 00189 00201 EQ_API void setPixelData( const Frame::Buffer buffer, 00202 const PixelData& data ); 00203 00208 EQ_API void setAlphaUsage( const bool enabled ); 00209 00211 bool getAlphaUsage() const { return !_ignoreAlpha; } 00212 00225 EQ_API void setQuality( const Frame::Buffer buffer, 00226 const float quality ); 00227 00229 EQ_API float getQuality( const Frame::Buffer buffer ) const; 00231 00235 EQ_API const util::Texture& getTexture( const Frame::Buffer buffer ) 00236 const; 00237 00242 EQ_API bool hasTextureData( const Frame::Buffer buffer ) const; 00244 00257 EQ_API bool readback( const uint32_t buffers, const PixelViewport& pvp, 00258 const Zoom& zoom, 00259 util::ObjectManager< const void* >* glObjects ); 00260 00273 bool readback( const Frame::Buffer buffer, const util::Texture* texture, 00274 const GLEWContext* glewContext ); 00275 00290 EQ_API void upload( const Frame::Buffer buffer, util::Texture* texture, 00291 const Vector2i& position, 00292 util::ObjectManager< const void* >* glObjects ) 00293 const; 00294 00296 EQ_API bool writeImage( const std::string& filename, 00297 const Frame::Buffer buffer ) const; 00298 00300 EQ_API bool writeImages( const std::string& filenameTemplate ) const; 00301 00303 EQ_API bool readImage( const std::string& filename, 00304 const Frame::Buffer buffer ); 00305 00307 void setOffset( int32_t x, int32_t y ) { _pvp.x = x; _pvp.y = y; } 00309 00316 EQ_API std::vector< uint32_t > 00317 findCompressors( const Frame::Buffer buffer ) const; 00318 00323 EQ_API void findTransferers( const Frame::Buffer buffer, 00324 const GLEWContext* glewContext, 00325 std::vector< uint32_t >& names ); 00326 00328 EQ_API bool allocCompressor( const Frame::Buffer buffer, 00329 const uint32_t name ); 00330 00332 EQ_API bool allocDownloader( const Frame::Buffer buffer, 00333 const uint32_t name, 00334 const GLEWContext* glewContext ); 00335 00337 EQ_API uint32_t getDownloaderName( const Frame::Buffer buffer ) const; 00339 00340 private: 00342 PixelViewport _pvp; 00343 00345 struct Memory : public PixelData 00346 { 00347 public: 00348 Memory() : state( INVALID ) {} 00349 00350 void resize( const uint32_t size ); 00351 void flush(); 00352 void useLocalBuffer(); 00353 00354 enum State 00355 { 00356 INVALID, 00357 VALID 00358 }; 00359 00360 State state; 00361 00364 co::base::Bufferb localBuffer; 00365 00366 bool hasAlpha; 00367 }; 00368 00370 uint32_t _chooseCompressor( const Frame::Buffer buffer ) const; 00371 00373 Frame::Type _type; 00374 00376 struct Attachment 00377 { 00378 Attachment(); 00379 ~Attachment(); 00380 00381 void flush(); 00382 co::base::CPUCompressor* const fullCompressor; 00383 co::base::CPUCompressor* const lossyCompressor; 00384 00385 util::GPUCompressor* const fullTransfer; 00386 util::GPUCompressor* const lossyTransfer; 00387 00388 co::base::CPUCompressor* compressor; 00389 util::GPUCompressor* transfer; 00390 00391 float quality; 00392 00394 util::Texture texture; 00395 00397 Memory memory; 00398 }; 00399 00400 Attachment _color; 00401 Attachment _depth; 00402 00404 bool _ignoreAlpha; 00405 00406 struct Private; 00407 Private* _private; // placeholder for binary-compatible changes 00408 00409 EQ_API Attachment& _getAttachment( const Frame::Buffer buffer ); 00410 EQ_API const Attachment& _getAttachment( const Frame::Buffer ) const; 00411 00412 Memory& _getMemory( const Frame::Buffer buffer ) 00413 { return _getAttachment( buffer ).memory; } 00414 const Memory& _getMemory( const Frame::Buffer buffer ) const 00415 { return _getAttachment( buffer ).memory; } 00416 00418 bool _allocDecompressor( Attachment& attachment, uint32_t name ); 00419 00420 void _findTransferers( const Frame::Buffer buffer, 00421 const GLEWContext* glewContext, 00422 co::base::CompressorInfos& result ); 00423 00425 const void* _getBufferKey( const Frame::Buffer buffer ) const; 00426 00428 const void* _getCompressorKey( const Frame::Buffer buffer ) const; 00429 00440 void _setExternalFormat( const Frame::Buffer buffer, 00441 const uint32_t externalFormat, 00442 const uint32_t pixelSize, 00443 const bool hasAlpha ); 00444 00445 bool _readback( const Frame::Buffer buffer, const Zoom& zoom, 00446 util::ObjectManager< const void* >* glObjects ); 00447 bool _readbackZoom( const Frame::Buffer buffer, const Zoom& zoom, 00448 util::ObjectManager< const void* >* glObjects ); 00449 }; 00450 }; 00451 #endif // EQ_IMAGE_H