Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

RmDDSSurface.h

00001 //============================================================================//
00002 // filename: RmDDSSurface.h                                                   //
00003 //                                                                            //
00004 // author:   Toshiaki Tsuji                                                   //
00005 //           ATI Research, Inc.                                               //
00006 //           3D Application Research Group                                    //
00007 //                                                                            //
00008 // description: DDS Surface definition                                        //
00009 //              Written for 3D Labs guys for loading cubemap.                 //
00010 //              Currently only 32 bit texture format is supported.            //
00011 //                                                                            //
00012 //============================================================================//
00013 // $File: //depot/3darg/Tools/RenderMonkey/sdk/Include/Utilities/RmDDSSurface.h $
00014 // $Author: natasha $ $Revision: #3 $
00015 //============================================================================//
00016 //   (C) 2004 ATI Research, Inc.  All rights reserved.                        //
00017 //============================================================================//
00018 
00019 #ifndef _RM_UTILITIES_DDS_SURFACE_H_
00020 #define _RM_UTILITIES_DDS_SURFACE_H_
00021 
00022 #include "RmDDSLoaderTypes.h"
00023 
00024 //============================================================================
00025 //
00026 // DDS Surface
00027 //
00028 // - Note : Surfacde is organized from top-down and left to right.
00029 //          ( same as DirectX surface or Window Bitmap )
00030 //          If you want to use this for OpenGL, you will have to flip
00031 //          y direction.
00032 //============================================================================
00033 class RMUTIL_API RmDDSSurface
00034 {
00035 public :
00036    RmDDSSurface();
00037    virtual ~RmDDSSurface();
00038 
00039    //-------------------------------------------------------------------------
00040    // Creat/Destroy
00041    //-------------------------------------------------------------------------
00042    bool Create( RM_DDS_PIXEL_FORMAT pixelFormat, int width, int height );
00043    void Destroy();
00044 
00045    //-------------------------------------------------------------------------
00046    // Buffer Accessing
00047    //-------------------------------------------------------------------------
00048    RM_DDS_BYTE*       GetBuffer() { return m_pBuffer; };
00049    const RM_DDS_BYTE* GetBuffer() const { return m_pBuffer; };
00050 
00051    //-------------------------------------------------------------------------
00052    // Returns the beginning of scanline
00053    //-------------------------------------------------------------------------
00054    RM_DDS_BYTE*       GetScanLine( int y );
00055    const RM_DDS_BYTE* GetScanLine( int y ) const;
00056 
00057    //-------------------------------------------------------------------------
00058    // Returns the address of pixel at given (x,y)
00059    //-------------------------------------------------------------------------
00060    RM_DDS_BYTE*       GetPixel( int x, int y );
00061    const RM_DDS_BYTE* GetPixel( int x, int y ) const;
00062 
00063    //-------------------------------------------------------------------------
00064    // Returns the beginning of block ( for DXT )
00065    //-------------------------------------------------------------------------
00066    RM_DDS_BYTE*       GetDXTBlock( int bx, int by );
00067    const RM_DDS_BYTE* GetDXTBlock( int bx, int by ) const;
00068 
00069    //-------------------------------------------------------------------------
00070    // Information
00071    //-------------------------------------------------------------------------
00072    int GetWidth() const { return m_width; };
00073    int GetHeight() const { return m_height; };
00074 
00075    // For DXT
00076    int GetBlockWidth() const { return m_blockWidth; };
00077    int GetBlockHeight() const { return m_blockHeight; };
00078 
00079    // Picth and Bytes Per Pixel are valid in RGB format ( not in DXT )
00080    int GetPitch() const { return m_pitch; };   
00081    int GetBytesPerPixel() const { return m_bytesPerPixel; };
00082 
00083    // Valid for DXT format
00084    int GetDXTBlockSize() const { return m_DXTBlockSize; };
00085 
00086    bool IsRGBAFormat() const;
00087    bool IsDXTFormat() const;
00088    bool IsLuminanceFormat() const;
00089 
00090    // Total size ( in bytes )
00091    int GetTotalSize() const;
00092 
00093    // PixelFormat
00094    RM_DDS_PIXEL_FORMAT GetPixelFormat() const { return m_pixelFormat; };
00095 
00096    // Change format to RGBA 8888 and returns result surface
00097    bool ChangeFormatToRGBA( RmDDSSurface *pSurface );
00098 
00099 private :
00100    RM_DDS_PIXEL_FORMAT m_pixelFormat;
00101    RM_DDS_BYTE        *m_pBuffer;
00102    int                 m_width;
00103    int                 m_height;
00104    int                 m_pitch;  // Bytes per scanline
00105    int                 m_bytesPerPixel;
00106 
00107    int                 m_blockWidth;
00108    int                 m_blockHeight;
00109    int                 m_DXTBlockSize;
00110 
00111    // Decompress DXT block into 4x4 RGBA pixels
00112    // 
00113    // - pDestBlock must have enough size to contain 4x4x4 bytes
00114    bool DecompressToRGBA( RmDDSSurface *pSurface );
00115    void DecompressDXTBlock( RM_DDS_PIXEL_FORMAT format, RM_DDS_BYTE *pDXTBlock, RM_DDS_BYTE  *pDestBlock );
00116    void DecompressDXT1Block( RM_DDS_BYTE *pDXTBlock, RM_DDS_BYTE *pDestBlock, bool bUseTransparency );
00117    void DecompressDXT2_3Block( RM_DDS_BYTE *pDXTBlock, RM_DDS_BYTE *pDestBlock );
00118    void DecompressDXT4_5Block( RM_DDS_BYTE *pDXTBlock, RM_DDS_BYTE *pDestBlock );
00119 
00120    // Changeformat from luminace to RGBA
00121    bool LuminanceToRGBA( RmDDSSurface *pSurface );
00122 }; // End of RmDDSSurface
00123 
00124 
00125 //============================================================================
00126 //
00127 // DDS Texture
00128 //
00129 // - Collection of mip surfaces.  Each successive surface is 1/2 the size
00130 //
00131 //============================================================================
00132 class RMUTIL_API RmDDSTexture
00133 {
00134 public :
00135    RmDDSTexture();
00136    virtual ~RmDDSTexture();
00137 
00138    //-------------------------------------------------------------------------
00139    // Create/Destroy
00140    //-------------------------------------------------------------------------
00141    bool Create( RM_DDS_PIXEL_FORMAT pixelFormat, int width, int height,
00142                 int numMipmaps );
00143    void Destroy();
00144 
00145    //-------------------------------------------------------------------------
00146    // Mipmaps
00147    //-------------------------------------------------------------------------
00148    int          GetNumMipmaps() const { return m_numMipmaps; };
00149 
00150    RmDDSSurface*       GetMipmap( int level );
00151    const RmDDSSurface* GetMipmap( int level ) const;
00152 
00153    //-------------------------------------------------------------------------
00154    // Information
00155    //-------------------------------------------------------------------------
00156    int GetWidth() const { return m_width; };    // Width of top level mipmap
00157    int GetHeight() const { return m_height; };  // Height of top level mipmap
00158 
00159    RM_DDS_PIXEL_FORMAT GetPixelFormat() const { return m_pixelFormat; };
00160 
00161 private :
00162    int                 m_numMipmaps;
00163    RmDDSSurface       *m_pMipmaps;
00164 
00165    RM_DDS_PIXEL_FORMAT m_pixelFormat;
00166    int                 m_width;
00167    int                 m_height;
00168 }; // End of RmDDSTexture
00169 
00170 
00171 //============================================================================
00172 //
00173 // DDS Cubemap
00174 //
00175 // - Collection of six faces of DDSTexture
00176 //
00177 //============================================================================
00178 class RMUTIL_API RmDDSCubemap
00179 {
00180 public :
00181    RmDDSCubemap();
00182    virtual ~RmDDSCubemap();
00183 
00184    //-------------------------------------------------------------------------
00185    // Create/Destroy
00186    //-------------------------------------------------------------------------
00187    bool Create( RM_DDS_PIXEL_FORMAT pixelFormat, int width, int height,
00188                 int numMipmaps );
00189    void Destroy();
00190 
00191    //-------------------------------------------------------------------------
00192    // Surface accessor
00193    //-------------------------------------------------------------------------
00194    RmDDSTexture*       GetFace( RM_DDS_CUBEMAP_FACE  whichFace );
00195    const RmDDSTexture* GetFace( RM_DDS_CUBEMAP_FACE  whichFace ) const;
00196 
00197    //-------------------------------------------------------------------------
00198    // Information
00199    //-------------------------------------------------------------------------
00200    int GetNumMipmaps() const { return m_numMipmaps; };
00201    int GetWidth() const { return m_width; };     
00202    int GetHeight() const { return m_height; };
00203 
00204    RM_DDS_PIXEL_FORMAT GetPixelFormat() const { return m_pixelFormat; };
00205 
00206 private :
00207    RmDDSTexture       *m_pFaces;
00208    int                 m_numMipmaps;
00209 
00210    RM_DDS_PIXEL_FORMAT m_pixelFormat;
00211    int                 m_width;
00212    int                 m_height;
00213 }; // End of RmDDSCubemap
00214 
00215 #endif // __RmDDSSurface_H__

Generated on Fri Feb 25 16:08:33 2005 for RenderMonkey SDK by doxygen 1.3.6