NVidia Gameworks
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

NvImage.h

Go to the documentation of this file.
00001 // TAGRELEASE: PUBLIC
00002 
00003 #ifndef NV_IMAGE_H
00004 #define NV_IMAGE_H
00005 
00006 #include <NvFoundation.h>
00007 
00008 
00009 #ifdef WIN32
00010 
00011 #if _MSC_VER >= 1400  
00012 # pragma warning(disable:4996) 
00013 #endif 
00014 
00015 #endif
00016 
00017 #include <vector>
00018 #include <assert.h>
00019 #include <NV/NvGfxAPI.h>
00020 
00023 
00024 class NvImage;
00025 
00031 class NvImage {
00032 public:
00033 
00041     static void UpperLeftOrigin( bool ul);
00042 
00046     static uint32_t UploadTexture(NvImage* image);
00047 
00053     static uint32_t UploadTextureFromDDSFile(const char* filename);
00054 
00059     static uint32_t UploadTextureFromDDSData(const char* ddsData, int32_t length);
00060 
00066     static NvImage* CreateFromDDSFile(const char* filename);
00067 
00068     NvImage();
00069     virtual ~NvImage();
00070 
00073     int32_t getWidth() const { return _width; }
00074 
00077     int32_t getHeight() const { return _height; }
00078 
00082     int32_t getDepth() const { return _depth; }
00083 
00086     int32_t getMipLevels() const { return _levelCount; }
00087 
00090     int32_t getFaces() const { return _cubeMap ? _layers : 0; }
00091 
00094     int32_t getLayers() const { return _layers; }
00095 
00098     uint32_t getFormat() const { return _format; }
00099 
00102     uint32_t getInternalFormat() const { return _internalFormat; }
00103 
00106     uint32_t getType() const { return _type; }
00107 
00111     int32_t getImageSize(int32_t level = 0) const;
00112 
00115     bool isCompressed() const;
00116 
00119     bool isCubeMap() const { return _cubeMap; }
00120 
00123     bool hasAlpha() const;
00124 
00127     bool isArray() const { return _layers > 1; }
00128 
00131     bool isVolume() const { return _depth > 0; }
00132 
00137     const void* getLevel( int32_t level) const;
00138     void* getLevel( int32_t level);
00140 
00146     const void* getLevel( int32_t level, uint32_t face) const;
00147     void* getLevel( int32_t level, uint32_t face);
00149 
00155     const void* getLayerLevel( int32_t level, int32_t slice) const;
00156     void* getLayerLevel( int32_t level, int32_t slice);
00158 
00165     bool loadImageFromFileData(const uint8_t* fileData, size_t size, const char* fileExt);
00166 
00170     bool convertCrossToCubemap();
00171 
00172     bool setImage( int32_t width, int32_t height, uint32_t format, uint32_t type, const void* data);
00173 
00178     static void setAPIVersion(const NvGfxAPIVersion& api) { m_gfxAPIVersion = api; }
00179 
00182     static const NvGfxAPIVersion& getAPIVersion() { return m_gfxAPIVersion; }
00183 
00184 protected:
00186 
00187     static NvGfxAPIVersion m_gfxAPIVersion;
00188     int32_t _width;
00189     int32_t _height;
00190     int32_t _depth;
00191     int32_t _levelCount;
00192     int32_t _layers;
00193     uint32_t _format;
00194     uint32_t _internalFormat;
00195     uint32_t _type;
00196     int32_t _elementSize;
00197     bool _cubeMap;
00198 
00199     //pointers to the levels
00200     std::vector<uint8_t*> _data;
00201 
00202     void freeData();
00203     void flipSurface(uint8_t *surf, int32_t width, int32_t height, int32_t depth);
00204     void componentSwapSurface(uint8_t *surf, int32_t width, int32_t height, int32_t depth);
00205 
00206     //
00207     // Static elements used to dispatch to proper sub-readers
00208     //
00210     struct FormatInfo {
00211         const char* extension;
00212         bool (*reader)(const uint8_t* fileData, size_t size, NvImage& i);
00213         bool (*writer)(uint8_t* fileData, size_t size, NvImage& i);
00214     };
00215 
00216     static FormatInfo formatTable[]; 
00217     static bool upperLeftOrigin;
00218 
00219     static bool readDDS(const uint8_t* fileData, size_t size, NvImage& i);
00220 
00221     static void flip_blocks_dxtc1(uint8_t *ptr, uint32_t numBlocks);
00222     static void flip_blocks_dxtc3(uint8_t *ptr, uint32_t numBlocks);
00223     static void flip_blocks_dxtc5(uint8_t *ptr, uint32_t numBlocks);
00224     static void flip_blocks_bc4(uint8_t *ptr, uint32_t numBlocks);
00225     static void flip_blocks_bc5(uint8_t *ptr, uint32_t numBlocks);
00226 
00227     friend bool TranslateDX10Format( const void *ptr, NvImage &i, int32_t &bytesPerElement, bool &btcCompressed);
00228 };
00229 
00230 #endif //NV_IMAGE_H
Generated on Sat Mar 8 14:58:35 2014 for NVIDIA GameWorks OpenGL App Framework and Libraries by Doxygen
©2014 NVIDIA Corporation.