00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __IMAGEDDS_H__
00018 #define __IMAGEDDS_H__
00019
00020
00021 #include "image.h"
00022 #include "common.h"
00023
00024
00025 #define DDS_MAGIC 0x20534444
00026
00027 #define DDSD_CAPS 0x00000001
00028 #define DDSD_HEIGHT 0x00000002
00029 #define DDSD_WIDTH 0x00000004
00030 #define DDSD_PITCH 0x00000008
00031 #define DDSD_PIXELFORMAT 0x00001000
00032 #define DDSD_MIPMAPCOUNT 0x00020000
00033 #define DDSD_LINEARSIZE 0x00080000
00034 #define DDSD_DEPTH 0x00800000
00035
00036
00037 #define DDPF_ALPHAPIXELS 0x00000001
00038 #define DDPF_FOURCC 0x00000004
00039 #define DDPF_INDEXED 0x00000020
00040 #define DDPF_RGB 0x00000040
00041
00042
00043 #define DDSCAPS_COMPLEX 0x00000008
00044 #define DDSCAPS_TEXTURE 0x00001000
00045 #define DDSCAPS_MIPMAP 0x00400000
00046
00047
00048 #define DDSCAPS2_CUBEMAP 0x00000200
00049 #define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400
00050 #define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800
00051 #define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000
00052 #define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000
00053 #define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000
00054 #define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
00055 #define DDSCAPS2_VOLUME 0x00200000
00056
00057 #ifndef MAKEFOURCC
00058 #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
00059 (GLuint)( \
00060 (((GLuint)(GLubyte)(ch3) << 24) & 0xFF000000) | \
00061 (((GLuint)(GLubyte)(ch2) << 16) & 0x00FF0000) | \
00062 (((GLuint)(GLubyte)(ch1) << 8) & 0x0000FF00) | \
00063 ((GLuint)(GLubyte)(ch0) & 0x000000FF) )
00064 #endif
00065
00066 #define D3DFMT_DXT1 MAKEFOURCC('D', 'X', 'T', '1') // DXT1 compression texture format
00067 #define D3DFMT_DXT2 MAKEFOURCC('D', 'X', 'T', '2') // DXT2 compression texture format
00068 #define D3DFMT_DXT3 MAKEFOURCC('D', 'X', 'T', '3') // DXT3 compression texture format
00069 #define D3DFMT_DXT4 MAKEFOURCC('D', 'X', 'T', '4') // DXT4 compression texture format
00070 #define D3DFMT_DXT5 MAKEFOURCC('D', 'X', 'T', '5') // DXT5 compression texture format
00071
00072 #define PF_IS_DXT1(pf) \
00073 ((pf.dwFlags & DDPF_FOURCC) && \
00074 (pf.dwFourCC == D3DFMT_DXT1))
00075
00076 #define PF_IS_DXT3(pf) \
00077 ((pf.dwFlags & DDPF_FOURCC) && \
00078 (pf.dwFourCC == D3DFMT_DXT3))
00079
00080 #define PF_IS_DXT5(pf) \
00081 ((pf.dwFlags & DDPF_FOURCC) && \
00082 (pf.dwFourCC == D3DFMT_DXT5))
00083
00084 #define PF_IS_BGRA8(pf) \
00085 ((pf.dwFlags & DDPF_RGB) && \
00086 (pf.dwFlags & DDPF_ALPHAPIXELS) && \
00087 (pf.dwRGBBitCount == 32) && \
00088 (pf.dwRBitMask == 0xff0000) && \
00089 (pf.dwGBitMask == 0xff00) && \
00090 (pf.dwBBitMask == 0xff) && \
00091 (pf.dwAlphaBitMask == 0xff000000U))
00092
00093 #define PF_IS_BGR8(pf) \
00094 ((pf.dwFlags & DDPF_ALPHAPIXELS) && \
00095 !(pf.dwFlags & DDPF_ALPHAPIXELS) && \
00096 (pf.dwRGBBitCount == 24) && \
00097 (pf.dwRBitMask == 0xff0000) && \
00098 (pf.dwGBitMask == 0xff00) && \
00099 (pf.dwBBitMask == 0xff))
00100
00101 #define PF_IS_BGR5A1(pf) \
00102 ((pf.dwFlags & DDPF_RGB) && \
00103 (pf.dwFlags & DDPF_ALPHAPIXELS) && \
00104 (pf.dwRGBBitCount == 16) && \
00105 (pf.dwRBitMask == 0x00007c00) && \
00106 (pf.dwGBitMask == 0x000003e0) && \
00107 (pf.dwBBitMask == 0x0000001f) && \
00108 (pf.dwAlphaBitMask == 0x00008000))
00109
00110 #define PF_IS_BGR565(pf) \
00111 ((pf.dwFlags & DDPF_RGB) && \
00112 !(pf.dwFlags & DDPF_ALPHAPIXELS) && \
00113 (pf.dwRGBBitCount == 16) && \
00114 (pf.dwRBitMask == 0x0000f800) && \
00115 (pf.dwGBitMask == 0x000007e0) && \
00116 (pf.dwBBitMask == 0x0000001f))
00117
00118 #define PF_IS_INDEX8(pf) \
00119 ((pf.dwFlags & DDPF_INDEXED) && \
00120 (pf.dwRGBBitCount == 8))
00121
00122
00123 namespace VRUT
00124 {
00126 class ImageDDS : public Image
00127 {
00128 protected:
00130 union DDS_header
00131 {
00132 struct
00133 {
00134 unsigned int dwMagic;
00135 unsigned int dwSize;
00136 unsigned int dwFlags;
00137 unsigned int dwHeight;
00138 unsigned int dwWidth;
00139 unsigned int dwPitchOrLinearSize;
00140 unsigned int dwDepth;
00141 unsigned int dwMipMapCount;
00142 unsigned int dwReserved1[ 11 ];
00143
00144
00145 struct
00146 {
00147 unsigned int dwSize;
00148 unsigned int dwFlags;
00149 unsigned int dwFourCC;
00150 unsigned int dwRGBBitCount;
00151 unsigned int dwRBitMask;
00152 unsigned int dwGBitMask;
00153 unsigned int dwBBitMask;
00154 unsigned int dwAlphaBitMask;
00155 } sPixelFormat;
00156
00157
00158 struct
00159 {
00160 unsigned int dwCaps1;
00161 unsigned int dwCaps2;
00162 unsigned int dwDDSX;
00163 unsigned int dwReserved;
00164 } sCaps;
00165
00166 unsigned int dwReserved2;
00167 };
00168 char data[ 128 ];
00169 };
00170
00172 struct DdsLoadInfo
00173 {
00174 bool compressed;
00175 bool swap;
00176 bool palette;
00177 unsigned int divSize;
00178 unsigned int blockBytes;
00179 GLenum internalFormat;
00180 GLenum externalFormat;
00181 GLenum type;
00182 DDS_header header;
00183 unsigned char * data;
00184
00186 DdsLoadInfo() : data((unsigned char *)NULL) {}
00188 ~DdsLoadInfo()
00189 {
00190 SAFE_DELETE_ARR(data);
00191 }
00192 } image;
00193
00194 public:
00196 ImageDDS();
00198 virtual ~ImageDDS();
00199
00201 virtual bool IsOk() const;
00203 virtual bool Load(const wxString & fname);
00206 virtual GLuint BuildOglTexture() const;
00208 virtual bool HasTransparency() const;
00210 virtual int GetWidth() const;
00212 virtual int GetHeight() const;
00213 };
00214 };
00215
00216
00217 #endif