Equalizer  1.2.1
image.h
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/client/frame.h>         // for Frame::Buffer enum
00023 #include <eq/client/pixelData.h>     // member
00024 
00025 #include <eq/util/texture.h>         // member
00026 #include <eq/util/types.h>
00027 #include <eq/fabric/pixelViewport.h> // member
00028 #include <eq/fabric/viewport.h>      // member
00029 
00030 #include <co/plugins/compressor.h> // EqCompressorInfos typedef
00031 #include <co/base/buffer.h>          // member
00032 
00033 
00034 namespace eq
00035 {
00041     class Image
00042     {
00043     public:
00045         EQ_API Image();
00046 
00048         EQ_API virtual ~Image();
00049 
00064         EQ_API void setInternalFormat( const Frame::Buffer buffer, 
00065                                        const uint32_t internalFormat );
00066 
00068         EQ_API uint32_t getInternalFormat( const Frame::Buffer buffer )const;
00069 
00082         uint32_t getExternalFormat( const Frame::Buffer buffer ) const
00083             {  return _getMemory( buffer ).externalFormat; }
00084 
00092         uint32_t getPixelSize( const Frame::Buffer buffer ) const
00093             { return _getMemory( buffer ).pixelSize; }
00094 
00100         EQ_API bool hasAlpha() const;
00101 
00113         void setStorageType( const Frame::Type type ) { _type = type; }
00114 
00116         Frame::Type getStorageType() const{ return _type; }
00117 
00129         EQ_API void setPixelViewport( const PixelViewport& pvp );
00130 
00132         const PixelViewport& getPixelViewport() const { return _pvp; }
00133 
00135         void setZoom( const Zoom& zoom ) { _zoom = zoom; }
00136 
00138         const Zoom& getZoom() const      { return _zoom; }
00139 
00149         EQ_API void useCompressor( const Frame::Buffer buffer,
00150                                    const uint32_t name );
00151 
00161         EQ_API void reset();
00162 
00164         EQ_API void flush();
00166 
00170         EQ_API const uint8_t* getPixelPointer( const Frame::Buffer buffer )
00171             const;
00172 
00174         EQ_API uint8_t* getPixelPointer( const Frame::Buffer buffer );
00175 
00177         EQ_API uint32_t getPixelDataSize( const Frame::Buffer buffer ) const;
00178 
00180         EQ_API const PixelData& getPixelData( const Frame::Buffer ) const;
00181 
00183         EQ_API const PixelData& compressPixelData( const Frame::Buffer );
00184 
00189         bool hasPixelData( const Frame::Buffer buffer ) const
00190             { return _getAttachment( buffer ).memory.state == Memory::VALID; }
00191 
00202         EQ_API void clearPixelData( const Frame::Buffer buffer );
00203 
00205         EQ_API void validatePixelData( const Frame::Buffer buffer );
00206 
00218         EQ_API void setPixelData( const Frame::Buffer buffer,
00219                                      const PixelData& data );
00220 
00225         EQ_API void setAlphaUsage( const bool enabled );
00226 
00228         bool getAlphaUsage() const { return !_ignoreAlpha; }
00229 
00242         EQ_API void setQuality( const Frame::Buffer buffer,
00243                                 const float quality );
00244 
00246         EQ_API float getQuality( const Frame::Buffer buffer ) const;
00248 
00252         EQ_API const util::Texture& getTexture( const Frame::Buffer buffer )
00253             const;
00254 
00259         EQ_API bool hasTextureData( const Frame::Buffer buffer ) const;
00261 
00274         EQ_API bool readback( const uint32_t buffers, const PixelViewport& pvp,
00275                               const Zoom& zoom,
00276                               util::ObjectManager< const void* >* glObjects );
00277 
00290         bool readback( const Frame::Buffer buffer, const util::Texture* texture,
00291                        const GLEWContext* glewContext );
00292 
00307         EQ_API void upload( const Frame::Buffer buffer, util::Texture* texture,
00308                             const Vector2i& position,
00309                             util::ObjectManager< const void* >* glObjects )
00310             const;
00311 
00313         EQ_API bool writeImage( const std::string& filename,
00314                                    const Frame::Buffer buffer ) const;
00315 
00317         EQ_API bool writeImages( const std::string& filenameTemplate ) const;
00318 
00320         EQ_API bool readImage( const std::string& filename, 
00321                                const Frame::Buffer buffer );
00322 
00324         void setOffset( int32_t x, int32_t y ) { _pvp.x = x; _pvp.y = y; }
00326 
00333         EQ_API std::vector< uint32_t > 
00334         findCompressors( const Frame::Buffer buffer ) const;
00335 
00340         EQ_API void findTransferers( const Frame::Buffer buffer,
00341                                      const GLEWContext* glewContext,
00342                                      std::vector< uint32_t >& names );
00343         
00345         EQ_API bool allocCompressor( const Frame::Buffer buffer, 
00346                                      const uint32_t name );
00347 
00349         EQ_API bool allocDownloader( const Frame::Buffer buffer, 
00350                                      const uint32_t name,
00351                                      const GLEWContext* glewContext );
00352 
00354         EQ_API uint32_t getDownloaderName( const Frame::Buffer buffer ) const;
00356 
00357     private:
00359         PixelViewport _pvp;
00360 
00362         Zoom _zoom;
00363 
00365         struct Memory : public PixelData
00366         {
00367         public:
00368             Memory() : state( INVALID ) {}
00369 
00370             void resize( const uint32_t size );
00371             void flush();            
00372             void useLocalBuffer();
00373 
00374             enum State
00375             {
00376                 INVALID,
00377                 VALID
00378             };
00379 
00380             State state;   
00381 
00384             co::base::Bufferb localBuffer;
00385 
00386             bool hasAlpha; 
00387         };
00388 
00390         uint32_t _chooseCompressor( const Frame::Buffer buffer ) const;
00391 
00393         Frame::Type _type;
00394 
00396         struct Attachment
00397         {
00398             Attachment();
00399             ~Attachment();
00400 
00401             void flush();
00402             co::base::CPUCompressor* const fullCompressor;
00403             co::base::CPUCompressor* const lossyCompressor;
00404 
00405             util::GPUCompressor* const fullTransfer;
00406             util::GPUCompressor* const lossyTransfer;
00407 
00408             co::base::CPUCompressor* compressor; 
00409             util::GPUCompressor* transfer;   
00410 
00411             float quality; 
00412 
00414             util::Texture texture;
00415 
00417             Memory memory;
00418         };
00419         
00420         Attachment _color;
00421         Attachment _depth;
00422 
00424         bool _ignoreAlpha;
00425 
00426         struct Private;
00427         Private* _private; // placeholder for binary-compatible changes
00428 
00429         EQ_API Attachment& _getAttachment( const Frame::Buffer buffer );
00430         EQ_API const Attachment& _getAttachment( const Frame::Buffer ) const;
00431 
00432         Memory& _getMemory( const Frame::Buffer buffer )
00433             { return _getAttachment( buffer ).memory; }
00434         const Memory& _getMemory( const Frame::Buffer buffer ) const
00435             { return  _getAttachment( buffer ).memory; }
00436 
00438         bool _allocDecompressor( Attachment& attachment, uint32_t name );
00439 
00440         void _findTransferers( const Frame::Buffer buffer,
00441                                const GLEWContext* glewContext,
00442                                co::base::CompressorInfos& result );
00443 
00445         const void* _getBufferKey( const Frame::Buffer buffer ) const;
00446 
00448         const void* _getCompressorKey( const Frame::Buffer buffer ) const;
00449 
00460         void _setExternalFormat( const Frame::Buffer buffer,
00461                                  const uint32_t externalFormat,
00462                                  const uint32_t pixelSize,
00463                                  const bool hasAlpha );
00464 
00465         bool _readback( const Frame::Buffer buffer, const Zoom& zoom,
00466                         util::ObjectManager< const void* >* glObjects );
00467         bool _readbackZoom( const Frame::Buffer buffer, const Zoom& zoom,
00468                             util::ObjectManager< const void* >* glObjects );
00469     };
00470 };
00471 #endif // EQ_IMAGE_H
Generated on Fri Jun 8 2012 15:44:31 for Equalizer 1.2.1 by  doxygen 1.8.0