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

RmDDSLoader.h

00001 //============================================================================//
00002 // filename: RmDDSLoader.h                                                    //
00003 //                                                                            //
00004 // author:   Toshiaki Tsuji                                                   //
00005 //           ATI Research, Inc.                                               //
00006 //           3D Application Research Group                                    //
00007 //                                                                            //
00008 // description: DDS Loader Interface                                          //
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/RmDDSLoader.h $
00014 // $Author: natasha $ $Revision: #3 $
00015 //============================================================================//
00016 //   (C) 2004 ATI Research, Inc.  All rights reserved.                        //
00017 //============================================================================//
00018 
00019 #ifndef _RM_UTILITIES_DDS_LOADER_H_
00020 #define _RM_UTILITIES_DDS_LOADER_H_
00021 
00022 #include "Utilities/RmDDSLoaderTypes.h"
00023 #include "Utilities/RmDDSSurface.h"
00024 #include "Utilities/RmDDSVolume.h"
00025 
00026 //============================================================================//
00027 // PixelFormat Flags ( Bit Flags )
00028 //============================================================================//
00029 typedef enum DDS_PIXELFORMAT_FLAGS
00030 {
00031    DDS_PIXELFORMAT_FLAGS_ALPHA     = 0x00000001,
00032    DDS_PIXELFORMAT_FLAGS_FOURCC    = 0x00000004,
00033    DDS_PIXELFORMAT_FLAGS_RGB       = 0x00000040,
00034    DDS_PIXELFORMAT_FLAGS_LUMINANCE = 0x00020000
00035 }; // End of DDS_PIXELFORMAT_FLAGS
00036 
00037 
00038 //============================================================================//
00039 // Surface Cap Flags ( Bit Flags )
00040 //
00041 // - The dwCaps1 member of the DDSCAPS2 structure can be set to one or more 
00042 //   of the following values.
00043 //============================================================================//
00044 typedef enum DDS_SURFACE_CAPS1
00045 {
00046    DDS_SURFACE_CAPS1_COMPLEX = 0x00000008,
00047    DDS_SURFACE_CAPS1_TEXTURE = 0x00001000,
00048    DDS_SURFACE_CAPS1_MIPMAP  = 0x00400000 
00049 }; // End of DDS_SURFACE_CAPS1
00050 
00051 
00052 //============================================================================//
00053 // Surface Cap2 Flags ( Bit Flags )
00054 //
00055 // - The dwCaps2 member of the DDSCAPS2 structure can be set to one or more 
00056 //   of the following values.
00057 //============================================================================//
00058 typedef enum DDS_SURFACE_CAPS2
00059 {
00060    DDS_SURFACE_CAPS2_CUBEMAP           = 0x00000200, 
00061    DDS_SURFACE_CAPS2_CUBEMAP_POSITIVEX = 0x00000400, 
00062    DDS_SURFACE_CAPS2_CUBEMAP_NEGATIVEX = 0x00000800, 
00063    DDS_SURFACE_CAPS2_CUBEMAP_POSITIVEY = 0x00001000, 
00064    DDS_SURFACE_CAPS2_CUBEMAP_NEGATIVEY = 0x00002000, 
00065    DDS_SURFACE_CAPS2_CUBEMAP_POSITIVEZ = 0x00004000, 
00066    DDS_SURFACE_CAPS2_CUBEMAP_NEGATIVEZ = 0x00008000, 
00067    DDS_SURFACE_CAPS2_VOLUME            = 0x00200000 
00068 }; // End of DDS_SURFACE_CAPS2
00069 
00070 
00071 //============================================================================
00072 // 
00073 // DDS Surface Capability Structure
00074 //
00075 //============================================================================
00076 class RMUTIL_API RmDDSSurfaceCaps
00077 {
00078 public :
00079    DWORD dwCaps1; // DDS files should always include DDSCAPS_TEXTURE. If the file contains mipmaps, DDSCAPS_MIPMAP should be set. For any DDS file with more than one main surface, such as a mipmaps, cubic environment map, or volume texture, DDSCAPS_COMPLEX should also be set. 
00080    DWORD dwCaps2; // For cubic environment maps, DDSCAPS2_CUBEMAP should be included as well as one or more faces of the map (DDSCAPS2_CUBEMAP_POSITIVEX, DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, DDSCAPS2_CUBEMAP_NEGATIVEY, DDSCAPS2_CUBEMAP_POSITIVEZ, DDSCAPS2_CUBEMAP_NEGATIVEZ). For volume textures, DDSCAPS2_VOLUME should be included. 
00081    DWORD Reserved[2]; 
00082 }; // End RmDDSSurfaceCaps
00083 
00084 
00085 //============================================================================
00086 // 
00087 // DDS Pixel Format Header
00088 //
00089 //============================================================================
00090 class RMUTIL_API CDDSPixelFormatHeader
00091 {
00092 public :
00093    DWORD dwSize;            // Size of structure. This member must be set to 32. 
00094    DWORD dwFlags;           // Flags to indicate valid fields. Uncompressed formats will usually use DDPF_RGB to indicate an RGB format, while compressed formats will use DDPF_FOURCC with a four-character code. 
00095    DWORD dwFourCC;          // This is the four-character code for compressed formats. dwFlags should include DDPF_FOURCC in this case. For DXTn compression, this is set to "DXT1", "DXT2", "DXT3", "DXT4", or "DXT5". 
00096    DWORD dwRGBBitCount;     // For RGB formats, this is the total number of bits in the format. dwFlags should include DDPF_RGB in this case. This value is usually 16, 24, or 32. For A8R8G8B8, this value would be 32. 
00097 
00098    DWORD dwRBitMask;
00099    DWORD dwGBitMask; 
00100    DWORD dwBBitMask;        // For RGB formats, these three fields contain the masks for the red, green, and blue channels. For A8R8G8B8, these values would be 0x00ff0000, 0x0000ff00, and 0x000000ff respectively. 
00101 
00102    DWORD dwRGBAlphaBitMask; // For RGB formats, this contains the mask for the alpha channel, if any. dwFlags should include DDPF_ALPHAPIXELS in this case. For A8R8G8B8, this value would be 0xff000000. 
00103 }; // End of CDDSPixelFormatHeader
00104 
00105 
00106 //============================================================================
00107 // 
00108 // DDS Surface Format Header
00109 //
00110 //============================================================================
00111 class RMUTIL_API RmDDSSurfaceHeader
00112 {
00113 public :
00114    DWORD dwSize;              // Size of structure. This member must be set to 124. 
00115    DWORD dwFlags;             // Flags to indicate valid fields. Always include DDSD_CAPS, DDSD_PIXELFORMAT, DDSD_WIDTH, DDSD_HEIGHT. 
00116    DWORD dwHeight;            // Height of the main image in pixels 
00117    DWORD dwWidth;             // Width of the main image in pixels 
00118    DWORD dwPitchOrLinearSize; // For uncompressed formats, this is the number of bytes per scan line (DWORD> aligned) for the main image. dwFlags should include DDSD_PITCH in this case. For compressed formats, this is the total number of bytes for the main image. dwFlags should be include DDSD_LINEARSIZE in this case. 
00119    DWORD dwDepth;             // For volume textures, this is the depth of the volume. dwFlags should include DDSD_DEPTH in this case. 
00120    DWORD dwMipMapCount;       // For items with mipmap levels, this is the total number of levels in the mipmap chain of the main image. dwFlags should include DDSD_MIPMAPCOUNT in this case. 
00121    DWORD dwReserved1[11];       
00122    CDDSPixelFormatHeader  ddpfPixelFormat;     // 32-byte value that specifies the pixel format structure. 
00123    RmDDSSurfaceCaps       ddsCaps;             // 16-byte value that specifies the capabilities structure. 
00124    DWORD dwReserved2;
00125 }; // RmDDSSurfaceHeader
00126 
00127 
00128 //============================================================================
00129 // 
00130 // DDS Loader
00131 //
00132 //============================================================================
00133 class RMUTIL_API RmDDSLoader
00134 {
00135 public :
00136    RmDDSLoader();
00137    virtual ~RmDDSLoader();
00138 
00139    //-------------------------------------------------------------------------
00140    // Loading Texture function
00141    //
00142    // - On success, ppTexture contains the pointer to newly created Texture
00143    //-------------------------------------------------------------------------
00144    bool LoadTexture( const TCHAR *strDDSFilePath, 
00145                      RmDDSTexture **ppTexture );
00146 
00147    //-------------------------------------------------------------------------
00148    // Loading Cubemap function
00149    //
00150    // - On success, ppCubemap contains the pointer to newly created Cubemap
00151    //-------------------------------------------------------------------------
00152    bool LoadCubemap( const TCHAR *strDDSFilePath, 
00153                      RmDDSCubemap **ppCubemap );
00154 
00155    //-------------------------------------------------------------------------
00156    // Loading VolumeTexture function
00157    //
00158    // - On success, ppVolumeTexture contains the pointer to newly created VolumeTexture
00159    //-------------------------------------------------------------------------
00160    bool LoadVolumeTexture( const TCHAR *strDDSFilePath, 
00161                            RmDDSVolumeTexture **ppVolumeTexture );
00162 
00163 private :
00164    //-------------------------------------------------------------------------
00165    // Read Surface Header
00166    //-------------------------------------------------------------------------
00167    bool ReadSurfaceHeader( FILE *pFile, RmDDSSurfaceHeader &header );
00168 
00169    //-------------------------------------------------------------------------
00170    // Read CubeMap
00171    //-------------------------------------------------------------------------
00172    bool ReadCubeMap( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSCubemap **ppCubemap );
00173 
00174    //-------------------------------------------------------------------------
00175    // Read Texture
00176    //-------------------------------------------------------------------------
00177    bool ReadTexture( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSTexture *pTexture );
00178 
00179    //-------------------------------------------------------------------------
00180    // Read Surface
00181    //-------------------------------------------------------------------------
00182    bool ReadSurface( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSSurface *pSurface );
00183    bool ReadRGBASurface( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSSurface *pSurface );
00184    bool ReadDXTSurface( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSSurface *pSurface );
00185    bool ReadLuminanceSurface( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSSurface *pSurface );
00186 
00187    //-------------------------------------------------------------------------
00188    // Returns Pixelformat that we support from SurfaceHeader
00189    // If we don't support that format, returns RM_DDS_PIXEL_FORMAT_UNKNOWN
00190    //-------------------------------------------------------------------------
00191    RM_DDS_PIXEL_FORMAT GetPixelFormat( RmDDSSurfaceHeader &header );
00192 
00193    //-------------------------------------------------------------------------
00194    // Read VolumeTexture
00195    //-------------------------------------------------------------------------
00196    bool ReadVolumeTexture( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSVolumeTexture **ppVolumeTexture );
00197    bool ReadVolume( FILE *pFile, RmDDSSurfaceHeader &header, RmDDSVolume *pVolume );
00198 
00199    //-------------------------------------------------------------------------
00200    // Returns the size of Buffer ( in bytes ) for a given surface
00201    //-------------------------------------------------------------------------
00202    int GetSurfaceBufferSize( RmDDSSurfaceHeader &header, RmDDSSurface *pSurface );
00203 }; // End of RmDDSLoader
00204 
00205 #endif

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