(原创)bls文件格式的解析

wow的shader都是放在bls文件中的,前几天对这些文件分析了一下,发现wowdev.org里对bls的解析不大对,这里对bls的文件格式做一下说明。

文件前四个字节肯定是"SVXG"或"SPXG",分别表示这个bls里保存的是vs或ps。 
接下来一个uint表示版本号,没什么用。
接下来一个uint是用来表示每个profile里的shader数目,以下检测pc。
接下来是data block的偏移量,如果是vs,会有6个偏移量,如果是ps,会有12个偏移量,其中有些可能会是0。
然后就可以根据这些偏移量,移动到文件中的指定位置,开始读取shader的数据和代码了。

以下是我写的一个解析bls文件的代码,可以把指定的bls里的shader输出到一个文本文件中。

/********************************************************************
filename:   Blsparser.cpp
created:    2006/07/29
author:     Weiliang Xie (feiyurainy at 163.com)

purpose:    To parse the wow shader file(.bls),and log the shader data
            a file.
*********************************************************************/

#include <iostream>
#include <fstream>
#include <string>

#include <assert.h>

#include <d3dx9.h>
#include <dxerr9.h>

typedef unsigned int uint32;

struct BlsHeader
{
    char    shaderType[4];  /// shader type,must be "SPXG" or "SVXG"
    uint32  version;        /// shader version,useless
    uint32  shaderCount;    /// shader count in each shader block
};

/// global shader header for the input bls file
BlsHeader gBlsHeader;

/// input bls file stream
std::ifstream gBlsFStream;

/// output log file stream
std::ofstream gOutputFile;

/** read the data from the gBlsFStream
@param count num of byte to read
@return num of byte read
*/
size_t _readData(void* buf, size_t count)
{
    gBlsFStream.read( static_cast<char*>(buf), static_cast<std::streamsize>(count) );

    return gBlsFStream.gcount();
}

/** parse the b

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值