游戏开发论坛

 找回密码
 立即注册
搜索
查看: 11682|回复: 5

OpenGL如何直接使用DXT压缩格式的DDS图片做纹理?

[复制链接]

29

主题

157

帖子

163

积分

注册会员

Rank: 2

积分
163
发表于 2008-7-10 08:55:00 | 显示全部楼层 |阅读模式
记得OpenGL中提供了API可以制作压缩格式的纹理,可以把纹理做成DXT格式的,据说显卡可以直接使用这种压缩格式,是这样的吗?
但是现在有这么一个问题:我的硬盘里有一张DXT压缩格式的DDS图片,我要用它做纹理,那么我首先要使用像FreeImage之类的库函数将图片加载到内存中,可以预见这个过程中图片将会被那些函数给解码/解压缩。然后我再使用OpenGL的API将内存中的数据制作成压缩格式的纹理,这又是一个编码/压缩的过程。如果我有上千张的图片,这无疑会是一个很浪费时间的过程,我想请问有没有什么办法可以把DXT图片直接加载到内存(这个貌似我可以用IO直接读取),再直接做成压缩纹理?

10

主题

173

帖子

178

积分

注册会员

Rank: 2

积分
178
发表于 2008-7-10 10:04:00 | 显示全部楼层

Re:OpenGL如何直接使用DXT压缩格式的DDS图片做纹理?

glCompressedTexImage2DARB

29

主题

157

帖子

163

积分

注册会员

Rank: 2

积分
163
 楼主| 发表于 2008-7-10 16:53:00 | 显示全部楼层

Re:OpenGL如何直接使用DXT压缩格式的DDS图片做纹理?

那我怎么在不解码的情况下把DXT图片加载到内存中呢?我想了一下,可以文件IO把文件直接加载到内存,但是文件有文件头和其他一些信息,这些信息glCompressedTexImage2DARB肯定不能处理,所以需要跳过文件头,直接加载DXT图片中的像素数据,有知道DDS数据格式的朋友吗?

10

主题

173

帖子

178

积分

注册会员

Rank: 2

积分
178
发表于 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就是加载这个。
};

29

主题

157

帖子

163

积分

注册会员

Rank: 2

积分
163
 楼主| 发表于 2008-7-12 15:51:00 | 显示全部楼层

Re:OpenGL如何直接使用DXT压缩格式的DDS图片做纹理?

明白了,楼上的朋友多谢了!

5

主题

72

帖子

74

积分

注册会员

Rank: 2

积分
74
发表于 2009-10-15 11:21:00 | 显示全部楼层

Re:OpenGL如何直接使用DXT压缩格式的DDS图片做纹理?

厉害
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-20 02:43

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表