Equalizer  1.3.1-git
image.h
00001 
00002 /* Copyright (c) 2006-2012, 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 <lunchbox/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 
00196         bool hasAsyncReadback( const Frame::Buffer buffer ) const
00197             { return _getAttachment(buffer).memory.state == Memory::DOWNLOAD; }
00198 
00203         bool hasAsyncReadback() const
00204             { return hasAsyncReadback( Frame::BUFFER_COLOR ) ||
00205                      hasAsyncReadback( Frame::BUFFER_DEPTH ); }
00206 
00217         EQ_API void clearPixelData( const Frame::Buffer buffer );
00218 
00220         EQ_API void validatePixelData( const Frame::Buffer buffer );
00221 
00233         EQ_API void setPixelData( const Frame::Buffer buffer,
00234                                      const PixelData& data );
00235 
00240         EQ_API void setAlphaUsage( const bool enabled );
00241 
00243         bool getAlphaUsage() const { return !_ignoreAlpha; }
00244 
00257         EQ_API void setQuality( const Frame::Buffer buffer,
00258                                 const float quality );
00259 
00261         EQ_API float getQuality( const Frame::Buffer buffer ) const;
00263 
00267         EQ_API const util::Texture& getTexture( const Frame::Buffer buffer )
00268             const;
00269 
00274         EQ_API bool hasTextureData( const Frame::Buffer buffer ) const;
00276 
00279 #ifndef EQ_2_0_API
00280 
00291         EQ_API bool readback( const uint32_t buffers, const PixelViewport& pvp,
00292                               const Zoom& zoom, ObjectManager* glObjects );
00293 #endif
00294 
00305         EQ_API bool startReadback( const uint32_t buffers,
00306                                    const PixelViewport& pvp, const Zoom& zoom,
00307                                    ObjectManager* glObjects );
00308 
00310         bool startReadback( const Frame::Buffer buffer,
00311                             const util::Texture* texture,
00312                             const GLEWContext* glewContext );
00313 
00321         EQ_API void finishReadback( const Zoom& zoom,
00322                                     const GLEWContext* glewContext );
00323 
00338         EQ_API void upload( const Frame::Buffer buffer, util::Texture* texture,
00339                             const Vector2i& position,
00340                             ObjectManager* glObjects ) const;
00341 
00343         EQ_API bool writeImage( const std::string& filename,
00344                                    const Frame::Buffer buffer ) const;
00345 
00347         EQ_API bool writeImages( const std::string& filenameTemplate ) const;
00348 
00350         EQ_API bool readImage( const std::string& filename, 
00351                                const Frame::Buffer buffer );
00352 
00354         void setOffset( int32_t x, int32_t y ) { _pvp.x = x; _pvp.y = y; }
00356 
00363         EQ_API std::vector< uint32_t > 
00364         findCompressors( const Frame::Buffer buffer ) const;
00365 
00370         EQ_API void findTransferers( const Frame::Buffer buffer,
00371                                      const GLEWContext* glewContext,
00372                                      std::vector< uint32_t >& names );
00373         
00375         EQ_API bool allocCompressor( const Frame::Buffer buffer, 
00376                                      const uint32_t name );
00377 
00379         EQ_API bool allocDownloader( const Frame::Buffer buffer, 
00380                                      const uint32_t name,
00381                                      const GLEWContext* glewContext );
00382 
00384         EQ_API uint32_t getDownloaderName( const Frame::Buffer buffer ) const;
00386 
00387     private:
00389         PixelViewport _pvp;
00390 
00392         Zoom _zoom;
00393 
00395         struct Memory : public PixelData
00396         {
00397         public:
00398             Memory() : state( INVALID ) {}
00399 
00400             void resize( const uint32_t size );
00401             void flush();
00402             void useLocalBuffer();
00403 
00404             enum State
00405             {
00406                 INVALID,
00407                 VALID,
00408                 DOWNLOAD // async RB is in progress
00409             };
00410 
00411             State state;   
00412 
00415             lunchbox::Bufferb localBuffer;
00416 
00417             bool hasAlpha; 
00418         };
00419 
00421         uint32_t _chooseCompressor( const Frame::Buffer buffer ) const;
00422 
00424         Frame::Type _type;
00425 
00427         struct Attachment
00428         {
00429             Attachment();
00430             ~Attachment();
00431 
00432             void flush();
00433             co::CPUCompressor* const fullCompressor;
00434             co::CPUCompressor* const lossyCompressor;
00435 
00436             util::GPUCompressor* const fullTransfer;
00437             util::GPUCompressor* const lossyTransfer;
00438 
00439             co::CPUCompressor* compressor; 
00440             util::GPUCompressor* transfer;   
00441 
00442             float quality; 
00443 
00445             util::Texture texture;
00446 
00448             Memory memory;
00449         };
00450         
00451         Attachment _color;
00452         Attachment _depth;
00453 
00455         bool _ignoreAlpha;
00456 
00457         struct Private;
00458         Private* _private; // placeholder for binary-compatible changes
00459 
00460         EQ_API Attachment& _getAttachment( const Frame::Buffer buffer );
00461         EQ_API const Attachment& _getAttachment( const Frame::Buffer ) const;
00462 
00463         Memory& _getMemory( const Frame::Buffer buffer )
00464             { return _getAttachment( buffer ).memory; }
00465         const Memory& _getMemory( const Frame::Buffer buffer ) const
00466             { return  _getAttachment( buffer ).memory; }
00467 
00469         bool _allocDecompressor( Attachment& attachment, uint32_t name );
00470 
00471         void _findTransferers( const Frame::Buffer buffer,
00472                                const GLEWContext* glewContext,
00473                                co::CompressorInfos& result );
00474 
00476         const void* _getBufferKey( const Frame::Buffer buffer ) const;
00477 
00479         const void* _getCompressorKey( const Frame::Buffer buffer ) const;
00480 
00491         void _setExternalFormat( const Frame::Buffer buffer,
00492                                  const uint32_t externalFormat,
00493                                  const uint32_t pixelSize,
00494                                  const bool hasAlpha );
00495 
00496         bool _readback( const Frame::Buffer buffer, const Zoom& zoom,
00497                         ObjectManager* glObjects );
00498 
00499         bool _startReadback( const Frame::Buffer buffer, const Zoom& zoom,
00500                              ObjectManager* glObjects );
00501 
00502         void _finishReadback( const Frame::Buffer buffer, const Zoom& zoom,
00503                               const GLEWContext* glewContext );
00504 
00505         bool _readbackZoom( const Frame::Buffer buffer, const Zoom& zoom,
00506                             ObjectManager* glObjects );
00507     };
00508 };
00509 #endif // EQ_IMAGE_H
Generated on Tue May 1 2012 15:14:27 for Equalizer 1.3.1-git by  doxygen 1.8.0