青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

Using the .X File Format(7)

Retrieving Data from a Data Object

Remember that data objects are containers for data, and if you're going to the trouble to enumerate data objects, it's a safe bet that you're after the data in each one. Once you've got a valid IDirectXFileData object that points at an enumerated data object, you can retrieve the object's instance name, template GUID, and data using a trio of functions. The first function, IDirectXFileData::GetName, retrieves the name of the data object instance.

HRESULT IDirectXFileData::GetName(
  LPSTR pstrNameBuf, // Name buffer
  LPDWORD pdwBufLen); // Size of name buffer

The GetName function takes two parameters−a pointer to a buffer that contains the name and a pointer to a variable that contains the name buffer's size (in bytes). Before you obtain a name from the GetName function, you first have to obtain the name's data size by specifying a NULL value for pstrNameBuf and supplying a value DWORD pointer for pdwBufLen.

// pData = pre−loaded IDirectXFileData object
// Get size of name, in bytes
DWORD Size;
pData−>GetName(NULL, &Size);

Once you've got the size of the name buffer, you can allocate an appropriate buffer and read in the name.

// Allocate name buffer and get name
char *Name = new char[Size];
pData−>GetName(Name, &Size);

While having the data object's instance name helps, you really need the GUID of the object's template to distinguish which template an object uses. To retrieve the GUID of the object's template, you use the IDirectXFileData::GetType function.

HRESULT IDirectXFileData::GetType(const GUID ** ppguid);

With only one parameter to use−a pointer to a const GUID pointer−you can call the GetType function using the following code:

const GUID *TemplateGUID = NULL;
pData−>GetType(&TemplateGUID);

Now that you have the GUID, you can compare it to a list of internal GUIDs (such as those from the standard templates or from your custom templates) and process the data appropriately. For instance, to check whether a data object's type matches that of the MeshNormals standard template, you can use the following code:

// TemplateGUID = template's GUID to check
if(*TemplateGUID == TID_D3DRMMeshNormals) {
  // Process MeshNormals template
}

Of course, knowing the object's template GUID can only get you so far. The real trick is to get at the data object's data. No problem! With one more simple function call at your disposal, your .X file parsing abilities will be nearly complete! The last function you use to access an object's data is GetData.

Retrieves the data for one of the object's members or the data for all members. Deprecated.

HRESULT GetData(
LPCSTR szMember,
DWORD * pcbSize,
void ** ppvData
);

Parameters

szMember
[in] Pointer to the name of the member for which to retrieve data. Specify NULL to retrieve all required members' data.
pcbSize
[out] Pointer to receive the ppvData buffer size, in bytes.
ppvData
[out] Address of a pointer to the buffer to receive the data associated with szMember. If szMember is NULL, ppvData is set to point to a buffer containing all required members' data in a contiguous block of memory.

Return Values

If the method succeeds, the return value is DXFILE_OK. If the method fails, the return value can be one of the following values: DXFILEERR_BADARRAYSIZE, DXFILEERR_BADDataReference, DXFILEERR_BADVALUE.

Remarks

This method retrieves the data for required members of a data object but no data for optional (child) members. Use IDirectXFileData::GetNextObject to retrieve child objects.

To use the GetData function, you need to provide a pointer to access the data object's data buffer and a DWORD variable to contain the buffer's size (in bytes). Here's a snippet of code that shows how you can use GetData to obtain a pointer to the object's data and its size.

char *DataPtr;
DWORD DataSize;
pData−>GetData(NULL, &DataSize, (void**)&DataPtr);

The pointer to the data buffer now points to a block of contiguous memory that is structured just like the data object's template definition. You can access the data as a large buffer or, if you want to be crafty, you can create a structure to match the template's definition for easier access. For example, suppose you have enumerated the ColorRGBA standard template, which is defined as follows:

template ColorRGBA {
  <35FF44E0−6C7C−11cf−8F52−0040333594A3>
  FLOAT red;
  FLOAT green;
  FLOAT blue;
  FLOAT alpha;
}

To access the red, green, blue, and alpha values, you can grab the data pointer and cast it to a float data type.

DWORD DataSize;
float *DataPtr;

pData−>GetData(NULL, &DataSize, (void**)&DataPtr);

float red = *DataPtr++;
float green = *DataPtr++;
float blue = *DataPtr++;
float alpha = *DataPtr++;

While this approach is fine and dandy, you can process the object's data much easier by using a matching C structure.

typedef struct {
  float red, green, blue, alpha;
} sColorRGBA;

sColorRGBA *Color;
DWORD DataSize;
pData−>GetData(NULL, &DataSize, (void**)&Color);

Note Notice that the template's GUID or class name is not part of the data retrieved using IDirectXFileData: :GetData.
Once it is complete, the preceding code gives you the ability to access the colors using the structure instance.

float red = Color−>red;
float blue = Color−>blue;
float green = Color−>green;
float alpha = Color−>alpha;

Accessing single variables is easy, but what about strings and arrays? Arrays, being the easier of the two, are stored contiguously in memory, meaning that you can just increase the memory pointer that contains the object's data. For example, the following code shows you how to access the array of float values stored in a data object of the template type FloatKeys.

// Get the object's data size & pointer
DWORD DataSize;
DWORD *DataPtr;
pData−>GetData(NULL, &DataSize, (void**)&DataPtr);

// The FloatKeys template has a DWORD value 1st that defines how many float values are in the array
DWORD NumKeys = *DataPtr++;

// Next, an array of float values follows
for(DWORD i=0;i<NumKeys;i++) {
  float fValue = *(FLOAT*)DataPtr++;

Accessing arrays wasn't too difficult, so how about accessing strings? Again, it's an easy chore because strings are stored as pointers to a text buffer, which you can access much like I do in the following code. (I'm using the TextureFilename template as an example; it stores the name of a file to use for a texture.)

// Get the data pointer & size
DWORD DataSize;
DWORD *DataPtr;
pData−>GetData(NULL, &DataSize, (void**)&DataPtr);

// Now, access the filename text buffer
char *StringPtr = (char*)*DataPtr;
MessageBox(NULL, StringPtr, "Texture Filename", MB_OK);

With a simple cast to a char pointer, you were able to display the file name contained in the TextureFilename template. Now I know you've got to be banging your forehead and yelling, "Why didn't I see how easy this was before?" Whoa, down boy! I didn't immediately realize just how easy it was to work with .X files either. Now that the secret is out, nothing can stop you from using .X files almost exclusively in your own projects. All you need is a way to wrap up all of this .X parser functionality into a class, making it even easier to work with .X.


posted on 2008-04-17 19:15 lovedday 閱讀(438) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲国产婷婷| 亚洲午夜国产一区99re久久| 亚洲国产精品久久精品怡红院 | 久久蜜桃资源一区二区老牛| 欧美一区二区三区四区视频| 亚洲永久免费精品| 欧美在线一区二区| 免费观看欧美在线视频的网站| 欧美成黄导航| 亚洲成人在线网| 亚洲国产精品精华液网站| 亚洲区在线播放| 亚洲免费av片| 亚洲午夜精品17c| 一区二区三区我不卡| 麻豆精品视频在线观看| 香蕉精品999视频一区二区| 国产日产亚洲精品| 久久久久国产精品www | 久久综合影视| 国语自产精品视频在线看| 欧美精品久久一区二区| 欧美日韩在线免费观看| 久久精品国产欧美激情| 亚洲精品久久久久| 久久在线视频| 亚洲成色www久久网站| 欧美一区二区私人影院日本| 久久精品成人| 国产一区再线| 欧美区视频在线观看| 午夜久久电影网| 久久婷婷av| 国产精品国产三级国产aⅴ9色| 精品电影一区| 亚洲视频狠狠| 男女激情久久| 亚洲欧美日韩电影| 欧美成人激情视频免费观看| 国产精品人成在线观看免费| 最近中文字幕日韩精品| 欧美一区二区在线| 99re66热这里只有精品4| 久久久久久久久久久久久久一区 | 亚洲美女黄色| 久久狠狠一本精品综合网| 欧美在线观看网址综合| 欧美护士18xxxxhd| 午夜精品一区二区三区在线| 欧美人体xx| 亚洲国产婷婷| 蘑菇福利视频一区播放| 欧美一级二区| 国产欧美日韩激情| 中文久久乱码一区二区| 亚洲激情国产精品| 噜噜噜久久亚洲精品国产品小说| 国产麻豆一精品一av一免费| 亚洲免费人成在线视频观看| 亚洲精品欧美在线| 欧美日本亚洲视频| 一区二区三欧美| 亚洲精品乱码久久久久久日本蜜臀| 久久人人97超碰国产公开结果| 国产一区二区三区av电影| 久久国内精品自在自线400部| 一区二区三区视频在线观看| 欧美三级第一页| 亚洲欧美日韩一区二区在线 | 亚洲精品国产品国语在线app| 久久综合久久综合九色| 亚洲国产美女久久久久| 欧美.www| 欧美大片91| 亚洲一卡二卡三卡四卡五卡| 9人人澡人人爽人人精品| 欧美日韩午夜| 午夜精品成人在线| 亚洲欧美日韩精品| 国产亚洲精品自拍| 美女精品一区| 欧美精品亚洲一区二区在线播放| 一区二区三区国产| 亚洲一本视频| 狠狠色香婷婷久久亚洲精品| 欧美激情在线狂野欧美精品| 欧美另类极品videosbest最新版本 | 亚洲欧美视频在线观看视频| 国产一区二区高清不卡| 免费成人黄色av| 欧美成人自拍| 亚洲中字黄色| 欧美中文日韩| 亚洲精品一级| 亚洲影院高清在线| 在线精品亚洲| 亚洲午夜av在线| 亚洲国产精品黑人久久久| 9色精品在线| 狠狠色狠狠色综合| aa亚洲婷婷| 一区二区三区在线视频观看| 亚洲国产美女精品久久久久∴| 久久久蜜桃一区二区人| 欧美精品久久久久久久久老牛影院| 亚洲综合国产| 久久综合婷婷| 欧美一区二区在线| 欧美不卡一区| 久久久亚洲精品一区二区三区| 欧美精品久久一区二区| 久久久久久色| 国产精品二区三区四区| 欧美高清成人| 国产欧美一区二区三区另类精品| 亚洲成人在线视频网站| 国产乱码精品一区二区三| 亚洲国产精品999| 国产一区二区三区精品欧美日韩一区二区三区| 亚洲福利视频一区二区| 国产在线观看精品一区二区三区| 亚洲精品国产品国语在线app| 国产综合久久久久久| 亚洲视频第一页| 99热这里只有成人精品国产| 久久久久久电影| 久久gogo国模啪啪人体图| 欧美三区在线视频| 亚洲卡通欧美制服中文| 亚洲国产日韩欧美| 久久人91精品久久久久久不卡| 久久精品国产亚洲精品| 国产精品久久波多野结衣| 99国产精品久久久久久久成人热| 亚洲国产精品悠悠久久琪琪| 久久久久成人精品| 久久一区欧美| 激情欧美丁香| 久久精品国产第一区二区三区| 性欧美大战久久久久久久久| 国产精品久久久久91| 一区二区三区精品视频在线观看| 日韩视频专区| 欧美久色视频| 在线亚洲免费| 欧美一区二区三区在线看 | 欧美成人在线免费视频| 伊人成人在线| 美女啪啪无遮挡免费久久网站| 欧美成人中文字幕在线| 亚洲国产日韩综合一区| 欧美国产精品v| 亚洲美女中出| 午夜久久福利| 国内精品久久久| 麻豆精品在线视频| 亚洲激情成人网| 亚洲综合国产精品| 国产一区二区三区在线观看精品 | 亚洲深夜影院| 国产精品久久久久久五月尺| 亚洲欧美国产77777| 六月婷婷一区| 日韩天天综合| 国产精品羞羞答答| 久久久久久伊人| 久久精品日产第一区二区| 母乳一区在线观看| 亚洲精品在线免费观看视频| 亚洲主播在线观看| 国产麻豆综合| 免费亚洲网站| 亚洲一区二区视频在线| 久久久久久久久蜜桃| 亚洲精品美女| 国产深夜精品| 欧美黄色成人网| 亚洲欧美日韩国产成人精品影院| 女人天堂亚洲aⅴ在线观看| 国产精品99久久久久久久久久久久| 国产精品羞羞答答| 欧美激情综合色综合啪啪| 午夜精品美女久久久久av福利| 嫩草成人www欧美| 亚洲男人第一网站| 亚洲国产欧美日韩另类综合| 国产毛片精品国产一区二区三区| 久久一二三区| 午夜在线成人av| 亚洲九九精品| 欧美成人一区二免费视频软件| 亚洲欧美在线观看| 99精品欧美一区二区蜜桃免费| 国产一区二区三区自拍| 欧美视频在线免费| 欧美女人交a| 欧美成人免费全部| 久久精品一区二区三区不卡| 亚洲视频在线观看三级| 亚洲美女毛片|