DXTC减少了纹理内存消耗的50%甚至更多,有3种DXTC的格式可供使用,分别是DXT1,DXT3和DXT5。
DXT1 压缩比例:1:8
压缩比最高,它只有1BitAlpha,Alpha通道信息几乎完全丧失。一般将不带Alpha通道的图片压缩成这种格式。如WorldWind用的卫星图片
DXT3 压缩比例:1:4
使用了4BitAlpha,可以有16个Alpha值,可很好地用于alpha通道锐利、对比强烈的半透和镂空材质。
DXT5 压缩比例:1:4
使用了线形插值的4BitAlpha,特别适合Alpha通道柔和的材质,比如高光掩码材质。
dds格式分为2个部分:
1、dds头
2、dxt压缩数据
dds的头文件信息如下:
typedef struct _DDCOLORKEY
{
uint32 dwColorSpaceLowvalue; // lowboundary of color space that is to
//be treated as Color Key, inclusive
uint32 dwColorSpaceHighvalue; // highboundary of color space that is
//to be treated as Color Key, inclusive
} DDCOLORKEY;
typedef struct _DDSCAPS2
{
uint32 dwCaps; // capabilities of surface wanted
uint32 dwCaps2;
uint32 dwCaps3;
union
{
uint32 dwCaps4;
uint32 dwVolumeDepth;
}DUMMYUNIONNAMEN(1);
} DDSCAPS2;
typedef struct _DDPIXELFORMAT
{
uint32 dwSize; // size of structure
uint32 dwFlags; //pixel format flags
uint32 dwFourCC; // (FOURCC code)
union
{
uint32 dwRGBBitCount; //how many bits per pixel
uint32 dwYUVBitCount; //how many bits per pixel
uint32 dwZBufferBitDepth; //how many total bits/pixel in z buffer (including any stencilbits)
uint32 dwAlphaBitDepth; //how many bits for alpha channels
uint32 dwLuminanceBitCount; //how many bits per pixel
uint32 dwBumpBitCount; // how many bits per "buxel", total
uint32 dwPrivateFormatBitCount;// Bits per pixel of private driverformats. Only valid in texture
//format list and if DDPF_D3DFORMAT is set
}DUMMYUNIONNAMEN(1);
union
{
uint32 dwRBitMask; // mask for red bit
uint32 dwYBitMask; // mask for Y bits
uint32 dwStencilBitDepth; //how many stencil bits (note: dwZBufferBitDepth-dwStencilBitDepth istotal Z-only bits)
uint32 dwLuminanceBitMask; // mask for luminance bits
uint32 dwBumpDuBitMask; //mask for bump map U delta bits
uint32 dwOperations; // DDPF_D3DFORMAT Operations
}DUMMYUNIONNAMEN(2);
union
{
uint32 dwGBitMask; // mask for green bits
uint32 dwUBitMask; // mask for U bits
uint32 dwZBitMask; // mask for Z bits
uint32 dwBumpDvBitMask; //mask for bump map V delta bits
struct
{
uint16 wFlipMSTypes; // Multisample methods supported via flip for this D3DFORMAT
uint16 wBltMSTypes; //Multisample methods supported via blt for this D3DFORMAT
}MultiSampleCaps;
}DUMMYUNIONNAMEN(3);
union
{
uint32 dwBBitMask; // mask for blue bits
uint32 dwVBitMask; // mask for V bits
uint32 dwStencilBitMask; // mask for stencil bits
uint32 dwBumpLuminanceBitMask; // mask for luminance in bump map
}DUMMYUNIONNAMEN(4);
union
{
uint32 dwRGBAlphaBitMask; //mask for alpha channel
uint32 dwYUVAlphaBitMask; //mask for alpha channel
uint32 dwLuminanceAlphaBitMask;// mask for alpha channel
uint32 dwRGBZBitMask; //mask for Z channel
uint32 dwYUVZBitMask; //mask for Z channel
}DUMMYUNIONNAMEN(5);
} DDPIXELFORMAT;
typedef struct _DDSURFACEDESC2
{
uint32 dwSize; // size of the DDSURFACEDESC structure
uint32 dwFlags; //determines what fields are valid
uint32 dwHeight; // height of surface to be created
uint32 dwWidth; //width of input surface
union
{
int32 lPitch; // distance to start of next line (return value only)
uint32 dwLinearSize; // Formless late-allocated optimized surface size
}DUMMYUNIONNAMEN(1);
union
{
uint32 dwBackBufferCount; //number of back buffers requested
uint32 dwDepth; //the depth if this is a volume texture
}DUMMYUNIONNAMEN(5);
union
{
uint32 dwMipMapCount; //number of mip-map levels requestde
//dwZBufferBitDepth removed, use ddpfPixelFormat one instead
uint32 dwRefreshRate; //refresh rate (used when display mode is described)
uint32 dwSrcVBHandle; //The source used in VB::Optimize
}DUMMYUNIONNAMEN(2);
uint32 dwAlphaBitDepth; //depth of alpha buffer requested
uint32 dwReserved; // reserved
void* lpSurface; //pointer to the associated surface memory
union
{
DDCOLORKEY ddckCKDestOverlay; //color key for destination overlay use
uint32 dwEmptyFaceColor; // Physical color for empty cubemap faces
}DUMMYUNIONNAMEN(3);
DDCOLORKEY ddckCKDestBlt; //color key for destination blt use
DDCOLORKEY ddckCKSrcOverlay; // color key for source overlay use
DDCOLORKEY ddckCKSrcBlt; // color key for source blt use
union
{
DDPIXELFORMAT ddpfPixelFormat; //pixel format description of the surface
uint32 dwFVF; //vertex format description of vertex buffers
}DUMMYUNIONNAMEN(4);
DDSCAPS2 ddsCaps; //direct draw surface capabilities
uint32 dwTextureStage; // stage in multitexture cascade
} DDSURFACEDESC2;
struct DDS_IMAGE_DATA
{
int width;
int height;
int components;
unsignedint format;
int numMipMaps;
unsignedchar *pixels;//这个是压缩的图像信息文件,glCompressedTexImage2DARB就是加载这个。
};