image.h

00001 
00002 /* Copyright (c) 2006-2009, 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 EQ_IMAGE_H
00019 #define EQ_IMAGE_H
00020 
00021 #include <eq/client/frame.h>         // for Frame::Buffer enum
00022 #include <eq/client/pixelViewport.h> // member
00023 #include <eq/client/texture.h>       // member
00024 #include <eq/client/viewport.h>      // member
00025 #include <eq/client/windowSystem.h>  // for OpenGL types
00026 
00027 namespace eq
00028 {
00029     class Compressor;
00030 
00036     class Image
00037     {
00038     public:
00040         EQ_EXPORT Image();
00041         EQ_EXPORT virtual ~Image();
00042 
00043         struct PixelData : public base::NonCopyable
00044         {
00045             PixelData();
00046             ~PixelData();
00047             void flush();
00048 
00049             uint32_t format;         
00050             uint32_t type;           
00051             
00052             base::Bufferb pixels;    
00053         
00054             uint32_t compressorName; 
00055             bool isCompressed;       
00056 
00058             std::vector< uint64_t > compressedSize;
00060             std::vector< void* >    compressedData;
00061         };
00062 
00065 
00075         EQ_EXPORT void setFormat( const Frame::Buffer buffer,
00076                                   const uint32_t format );
00077 
00079         EQ_EXPORT uint32_t getFormat( const Frame::Buffer buffer ) const;
00080 
00088         EQ_EXPORT void setType( const Frame::Buffer buffer, 
00089                                 const uint32_t type );
00090 
00092         EQ_EXPORT uint32_t getType( const Frame::Buffer buffer ) const;
00093 
00095         EQ_EXPORT bool hasAlpha() const;
00096 
00106         void setStorageType( const Frame::Type type) { _type = type; }
00107 
00109         Frame::Type getStorageType() const{ return _type; }
00110 
00112         EQ_EXPORT bool hasData( const Frame::Buffer buffer ) const;
00113 
00115         //const eq::Viewport& getViewport() const { return _data.vp; }
00116 
00124         EQ_EXPORT void setPixelViewport( const PixelViewport& pvp );
00125 
00127         const PixelViewport& getPixelViewport() const { return _pvp; }
00128 
00130         EQ_EXPORT void reset();
00132 
00133 
00137         EQ_EXPORT const uint8_t* getPixelPointer( const Frame::Buffer buffer )
00138                                      const;
00139         EQ_EXPORT uint8_t* getPixelPointer( const Frame::Buffer buffer );
00140 
00142         uint32_t getPixelDataSize( const Frame::Buffer buffer ) const
00143             { return _pvp.getArea() * getDepth( buffer ); }
00144 
00146         EQ_EXPORT const PixelData& getPixelData( const Frame::Buffer buffer )
00147                                        const;
00148 
00150         EQ_EXPORT const PixelData& compressPixelData( const Frame::Buffer 
00151                                                           buffer );
00152 
00157         bool hasPixelData( const Frame::Buffer buffer ) const
00158             { return _getAttachment( buffer ).memory.state == Memory::VALID; }
00159 
00165         EQ_EXPORT void clearPixelData( const Frame::Buffer buffer );
00166 
00168         EQ_EXPORT void validatePixelData( const Frame::Buffer buffer );
00169 
00179         EQ_EXPORT void setPixelData( const Frame::Buffer buffer, 
00180                                      const uint8_t* data );
00181 
00191         EQ_EXPORT void setPixelData( const Frame::Buffer buffer,
00192                                      const PixelData& data );
00193 
00195         void enablePBO() { _usePBO = true; }
00196 
00198         void disablePBO() { _usePBO = false; }
00199 
00201         bool usePBO() const { return _usePBO; }
00202 
00204         EQ_EXPORT void enableAlphaUsage();
00205 
00207         EQ_EXPORT void disableAlphaUsage();
00208 
00210         bool ignoreAlpha() const { return _ignoreAlpha; }
00212 
00213 
00217         EQ_EXPORT const Texture& getTexture( const Frame::Buffer buffer ) const;
00218 
00223         EQ_EXPORT bool hasTextureData( const Frame::Buffer buffer ) const;
00224 
00229         EQ_EXPORT uint32_t getInternalTextureFormat( const Frame::Buffer which )
00230                                const;
00232 
00233 
00247         EQ_EXPORT void startReadback( const uint32_t buffers, 
00248                                       const PixelViewport& pvp,
00249                                       const Zoom& zoom,
00250                                       Window::ObjectManager* glObjects );
00251 
00253         EQ_EXPORT void syncReadback();
00254 
00256         EQ_EXPORT void writeImage( const std::string& filename,
00257                                    const Frame::Buffer buffer ) const;
00258 
00260         EQ_EXPORT void writeImages( const std::string& filenameTemplate ) const;
00261 
00263         EQ_EXPORT bool readImage( const std::string& filename, 
00264                                   const Frame::Buffer buffer   );
00265 
00268         void setOffset( int32_t x, int32_t y ) { _pvp.x = x; _pvp.y = y; }
00269 
00271         EQ_EXPORT void flush();
00273 
00275         GLEWContext* glewGetContext() { return _glObjects->glewGetContext(); }
00276 
00278         EQ_EXPORT uint8_t getNumChannels( const Frame::Buffer buffer ) const;
00279 
00281         EQ_EXPORT uint8_t getChannelSize( const Frame::Buffer buffer ) const;
00282 
00284         EQ_EXPORT uint32_t getDepth( const Frame::Buffer buffer ) const;
00285 
00290         EQ_EXPORT std::vector< uint32_t > 
00291         findCompressors( const Frame::Buffer buffer ) const;
00292 
00297         EQ_EXPORT bool allocCompressor( const Frame::Buffer buffer, 
00298                                         const uint32_t name );
00299 
00300     private:
00302         struct Data
00303         {
00304             Viewport vp;
00305         } _data;
00306 
00308         PixelViewport _pvp;
00309 
00313         struct Memory : public PixelData
00314         {
00315         public:
00316             Memory() : state( INVALID ), pboSize(0) {}
00317 
00318             void resize( const uint32_t size );
00319             void flush();
00320 
00321             enum State
00322             {
00323                 INVALID,
00324                 PBO_READBACK,
00325                 ZOOM_READBACK,
00326                 VALID
00327             };
00328 
00329             State     state;   
00330             uint32_t  pboSize; 
00331         };
00332 
00334         uint32_t _getCompressorTokenType( const Frame::Buffer buffer ) const;
00335 
00337         uint32_t _getCompressorName( const Frame::Buffer buffer ) const;
00338 
00340         Window::ObjectManager* _glObjects;
00341 
00343         Frame::Type _type;
00344 
00346         class Attachment
00347         {
00348         public:  
00349             struct CompressorData
00350             {
00351                 CompressorData();
00352                 void flush();
00353 
00354                 uint32_t name;      
00355                 void* instance;     
00356                 Compressor* plugin; 
00357                 bool isCompressor;  
00358             }
00359                 compressor;
00360 
00362             Texture texture;
00363 
00365             Memory memory;
00366         }; 
00367         
00368         Attachment _color;
00369         Attachment _depth;
00370 
00371         Attachment& _getAttachment( const Frame::Buffer buffer );
00372         const Attachment& _getAttachment( const Frame::Buffer buffer ) const;
00373 
00375         bool _allocDecompressor( Attachment& attachment, uint32_t name );
00376 
00378         bool _usePBO;
00379 
00381         bool _ignoreAlpha;
00382 
00383         union // placeholder for binary-compatible changes
00384         {
00385             char dummy[64];
00386         };
00387 
00389         const void* _getBufferKey( const Frame::Buffer buffer ) const;
00390 
00391         bool _canIgnoreAlpha( const Frame::Buffer buffer ) const;
00392 
00393         void _startReadback( const Frame::Buffer buffer, const Zoom& zoom );
00394         void _startReadbackPBO( const Frame::Buffer buffer );
00395         void _startReadbackZoom( const Frame::Buffer buffer, const Zoom& zoom );
00396                                 
00397         void _syncReadback( const Frame::Buffer buffer );
00398         void _syncReadbackPBO( const Frame::Buffer buffer );
00399         void _syncReadbackZoom( const Frame::Buffer buffer );
00400 
00401         friend std::ostream& operator << ( std::ostream& os, const Image* );
00402     };
00403 
00404     std::ostream& operator << ( std::ostream& os, const Image* image );
00405 };
00406 #endif // EQ_IMAGE_H
Generated on Mon Aug 10 18:58:39 2009 for Equalizer 0.9 by  doxygen 1.5.8