|
发表于 2008-7-11 09:47:00
|
显示全部楼层
Re:OpenGL如何直接使用DXT压缩格式的DDS图片做纹理?
glCompressedTexImage2DARB就是直接加载DXT数据的函数哦,该函数不能直接加载dds。
dds格式分为2个部分:
1、dds头
2、dxt压缩数据
dds的头文件信息如下:
/*
* DDCOLORKEY
*/
typedef struct _DDCOLORKEY
{
uint32 dwColorSpaceLowValue; // low boundary of color space that is to
// be treated as Color Key, inclusive
uint32 dwColorSpaceHighValue; // high boundary of color space that is
// to be treated as Color Key, inclusive
} DDCOLORKEY;
/*
* DDSCAPS2
*/
typedef struct _DDSCAPS2
{
uint32 dwCaps; // capabilities of surface wanted
uint32 dwCaps2;
uint32 dwCaps3;
union
{
uint32 dwCaps4;
uint32 dwVolumeDepth;
} DUMMYUNIONNAMEN(1);
} DDSCAPS2;
/*
* DDPIXELFORMAT
*/
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 stencil bits)
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 driver formats. 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 is total 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;
/*
* DDSURFACEDESC2
*/
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;
unsigned int format;
int numMipMaps;
unsigned char *pixels;//这个是压缩的图像信息文件,glCompressedTexImage2DARB就是加载这个。
};
|
|