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

天行健 君子當自強而不息

D3D中的網格模型(1)

ID3DXMesh接口的主要功能繼承自ID3DXBaseMesh父接口,了解這些是很重要的,其它一些mesh接口如ID3DXPMesh也是繼承自ID3DXBaseMesh。


10.1 幾何信息

ID3DXBaseMesh接口包含一個用來存儲網格頂點的頂點緩存和一個用來定義這些頂點怎樣連接在一起組成網格三角形的索引緩存。我們使用下面的方法來得到這些緩存的指針:

HRESULT ID3DXMesh::GetVertexBuffer(LPDIRECT3DVERTEXBUFFER9* ppVB);

HRESULT ID3DXMesh::GetIndexBuffer(LPDIRECT3DINDEXBUFFER9* ppIB);

這里有一些使用這些方法的例子:

IDirect3DVertexBuffer9* vb = 0;

Mesh->GetVertexBuffer( &vb );

IDirect3DIndexBuffer9* ib = 0;

Mesh->GetIndexBuffer( &ib );

假如想鎖定這些緩存來讀寫數據,那么我們能夠使用下面的方法。注意這些方法鎖定整個頂點/索引緩存。

Locks a vertex buffer and obtains a pointer to the vertex buffer memory.

HRESULT LockVertexBuffer(
DWORD Flags,
LPVOID * ppData
);

Parameters

Flags

Combination of zero or more locking flags that describe the type of lock to perform. For this method, the valid flags are:

  • D3DLOCK_DISCARD
  • D3DLOCK_NO_DIRTY_UPDATE
  • D3DLOCK_NOSYSLOCK
  • D3DLOCK_READONLY
  • D3DLOCK_NOOVERWRITE
[in] For a description of the flags, see D3DLOCK.

 

ppData
[out, retval] VOID* pointer to a buffer containing the vertex data.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

When working with vertex buffers, you are allowed to make multiple lock calls; however, you must ensure that the number of lock calls match the number of unlock calls. DrawPrimitive calls will not succeed with any outstanding lock count on any currently set vertex buffer.

Locks an index buffer and obtains a pointer to the index buffer memory.

HRESULT LockIndexBuffer(
DWORD Flags,
LPVOID * ppData
);

Parameters

Flags

Combination of zero or more locking flags that describe the type of lock to perform. For this method, the valid flags are:

  • D3DLOCK_DISCARD
  • D3DLOCK_NO_DIRTY_UPDATE
  • D3DLOCK_NOSYSLOCK
  • D3DLOCK_READONLY
[in] For a description of the flags, see D3DLOCK.

 

ppData
[out, retval] VOID* pointer to a buffer containing the index data. The count of indices in this buffer will be equal to ID3DXBaseMesh::GetNumFaces * 3.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

When working with index buffers, you are allowed to make multiple lock calls. However, you must ensure that the number of lock calls match the number of unlock calls. DrawPrimitive calls will not succeed with any outstanding lock count on any currently set index buffer.


D3DLOCK

A combination of zero or more locking options that describe the type of lock to perform.

#define Description
D3DLOCK_DISCARD The application discards all memory within the locked region. For vertex and index buffers, the entire buffer will be discarded. This option is only valid when the resource is created with dynamic usage (see D3DUSAGE).
D3DLOCK_DONOTWAIT Allows an application to gain back CPU cycles if the driver cannot lock the surface immediately. If this flag is set and the driver cannot lock the surface immediately, the lock call will return D3DERR_WASSTILLDRAWING. This flag can only be used when locking a surface created using IDirect3DDevice9::CreateOffscreenPlainSurface, IDirect3DDevice9::CreateRenderTarget, or IDirect3DDevice9::CreateDepthStencilSurface. This flag can also be used with a back buffer.
D3DLOCK_NO_DIRTY_UPDATE By default, a lock on a resource adds a dirty region to that resource. This option prevents any changes to the dirty state of the resource. Applications should use this option when they have additional information about the set of regions changed during the lock operation.
D3DLOCK_NOOVERWRITE Indicates that memory that was referred to in a drawing call since the last lock without this flag will not be modified during the lock. This can enable optimizations when the application is appending data to a resource. Specifying this flag enables the driver to return immediately if the resource is in use, otherwise, the driver must finish using the resource before returning from locking.
D3DLOCK_NOSYSLOCK The default behavior of a video memory lock is to reserve a system-wide critical section, guaranteeing that no display mode changes will occur for the duration of the lock. This option causes the system-wide critical section not to be held for the duration of the lock.

The lock operation is time consuming, but can enable the system to perform other duties, such as moving the mouse cursor. This option is useful for long-duration locks, such as the lock of the back buffer for software rendering that would otherwise adversely affect system responsiveness.

D3DLOCK_READONLY The application will not write to the buffer. This enables resources stored in non-native formats to save the recompression step when unlocking.

當然在你鎖定以后一定要記得解鎖:

HRESULT ID3DXMesh::UnlockVertexBuffer();

HRESULT ID3DXMesh::UnlockIndexBuffer();

下面是另外一些與mesh幾何結構有關的ID3DXMesh接口方法:

 DWORD GetFVF() — 返回頂點的格式

DWORD GetNumVertices() — 返回頂點緩存中的頂點數

DWORD GetNumBytesPerVertex() — 返回一個頂點所占的字節數

DWORD GetNumFaces() — 返回在mesh中的面(三角形)數


10.2 子集和屬性緩存

一個mesh由一個或數個子集組成。一個子集(subset)是在mesh中的使用相同屬性渲染的一組三角形。這里的屬性是指材質,紋理和渲染狀態。圖10.1顯示了一座房子mesh可能被分成的幾個子集。

在mesh中的每個三角形都與一個屬性ID相關聯,表示該三角形屬于該子集。例如,圖10.1中組成地板的三角形具有屬性ID0,它表示這些三角形屬于子集0。同樣,組成墻的三角形具有屬性ID1,它表示這些三角形屬于子集1。

三角形的屬性ID存儲在mesh的屬性緩存中,它是一個DWORD數組。因為每個面對應屬性緩存中的一項,所以屬性緩存中的項目數等于mesh中的面的個數。屬性緩存中的項目和索引緩存中定義的三角形一一對應。即,屬性緩存中的第i項和索引緩存中的第i個三角形相對應。三角形i由下面三個索引緩存中的索引項定義:

A = i * 3

B = i * 3 + 1

C = i * 3 + 2

圖10.2顯示了這個對應關系:

我們可以通過LockAttributeBuffer()鎖定屬性緩存:

Locks the mesh buffer that contains the mesh attribute data, and returns a pointer to it.

HRESULT LockAttributeBuffer(
DWORD Flags,
DWORD ** ppData
);

Parameters

Flags

Combination of zero or more locking flags that describe the type of lock to perform. For this method, the valid flags are:

  • D3DLOCK_DISCARD
  • D3DLOCK_NO_DIRTY_UPDATE
  • D3DLOCK_NOSYSLOCK
  • D3DLOCK_READONLY
[in] For a description of the flags, see D3DLOCK.

 

ppData
[out] Address of a pointer to a buffer containing a DWORD for each face in the mesh.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

If ID3DXMesh::Optimize has been called, the mesh will also have an attribute table that can be accessed using the ID3DXBaseMesh::GetAttributeTable method.

就象下面的代碼片段:

DWORD* buffer = 0;

Mesh->LockAttributeBuffer(lockingFlags, &buffer);

// Read or write to attribute buffer...

Mesh->UnlockAttributeBuffer();


10.3 繪制

ID3DXMesh接口提供了DrawSubset(DWORD AttribId)方法來繪制AttribId指示的子集中的各個三角形。

Draws a subset of a mesh.

HRESULT DrawSubset(
DWORD AttribId
);

Parameters

AttribId
[in] DWORD that specifies which subset of the mesh to draw. This value is used to differentiate faces in a mesh as belonging to one or more attribute groups.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

The subset that is specified by AttribId will be rendered by the IDirect3DDevice9::DrawIndexedPrimitive method, using the D3DPT_TRIANGLELIST primitive type, so an index buffer must be properly initialized.

An attribute table is used to identify areas of the mesh that need to be drawn with different textures, render states, materials, and so on. In addition, the application can use the attribute table to hide portions of a mesh by not drawing a given attribute identifier (AttribId) when drawing the frame.

例如,要繪制子集0中的所有三角形,我們將這樣寫:

Mesh->DrawSubset(0);

為了繪制整個mesh,我們必須繪制mesh的所有子集。這是非常方便的用0,1,2,…,n-1來標識子集,這里的n是子集的總數。且有一個相對應的材質和紋理數組,即子集i與材質和紋理數組的第i項對應。這就使我們能夠簡單的用循環來渲染mesh:

for(int i = 0; i < numSubsets; i++)

{

       Device->SetMaterial( mtrls[i] );

       Device->SetTexture( 0, textures[i] );

       Mesh->DrawSubset(i);

}


posted on 2008-03-27 09:54 lovedday 閱讀(1502) 評論(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>
            另类天堂视频在线观看| 欧美mv日韩mv国产网站| 国产精品网站视频| 欧美在线看片| 久久国产直播| 亚洲激情成人网| 99热精品在线| 国产婷婷色一区二区三区在线 | 欧美岛国激情| 在线亚洲高清视频| 午夜视频在线观看一区| 伊人久久大香线蕉av超碰演员| 亚洲第一免费播放区| 欧美精品一区三区在线观看| 亚洲制服av| 久久久久五月天| 亚洲深夜福利网站| 久久久高清一区二区三区| 亚洲国内自拍| 亚洲宅男天堂在线观看无病毒| 国产综合18久久久久久| 亚洲国产免费| 国产女主播一区| 欧美激情视频给我| 国产精品视频观看| 欧美激情免费在线| 国产午夜精品久久久久久免费视 | 麻豆免费精品视频| 欧美日韩国产999| 久久婷婷久久| 欧美午夜久久| 亚洲第一精品福利| 韩日精品视频一区| 亚洲一区二区三| 亚洲精品九九| 久久精品人人爽| 午夜在线精品偷拍| 欧美精品在线视频观看| 久久婷婷国产麻豆91天堂| 国产精品xxx在线观看www| 欧美成人一区二区三区片免费| 国产精品久久一区主播| 亚洲人成网在线播放| 在线精品在线| 欧美一区二区精品| 欧美一区二区三区免费在线看| 欧美精品三级| 亚洲国产精品成人久久综合一区| 国产视频亚洲精品| 亚洲一区中文字幕在线观看| 夜夜精品视频一区二区| 久久综合久色欧美综合狠狠| 久久久久欧美| 国产综合久久久久久| 欧美一区二区三区免费看| 亚洲欧美日韩直播| 国产精品日韩一区| 亚洲制服av| 久久久久久穴| 久久精品久久99精品久久| 欧美三级韩国三级日本三斤| 亚洲国产精品久久| 亚洲人成亚洲人成在线观看图片| 久久亚洲精品视频| 噜噜噜躁狠狠躁狠狠精品视频 | 国产精品麻豆成人av电影艾秋| 亚洲黄一区二区三区| 亚洲三级电影全部在线观看高清| 久久综合给合| 亚洲电影网站| 中文亚洲视频在线| 国产精品视频午夜| 欧美在线播放| 男女视频一区二区| 亚洲精品永久免费精品| 欧美日本亚洲韩国国产| 99国产精品久久久久久久久久| 亚洲一区www| 国产一区二区黄| 免费亚洲电影| 日韩亚洲精品电影| 欧美在线91| 最新亚洲激情| 欧美日韩一区在线观看| 亚洲欧美亚洲| 免费日韩av| 亚洲视频精品在线| 国产人妖伪娘一区91| 久久久久久婷| 一本色道久久88精品综合| 午夜一区二区三区不卡视频| 在线观看久久av| 欧美三级视频| 久久久91精品| 亚洲美女在线国产| 欧美一区二区三区在线播放| 在线日韩电影| 国产精品免费aⅴ片在线观看| 久久久99精品免费观看不卡| 亚洲日韩成人| 久久综合一区| 亚洲综合精品一区二区| 精品不卡一区二区三区| 欧美午夜免费| 免费成人av| 午夜免费久久久久| 亚洲日本欧美在线| 美日韩免费视频| 午夜伦欧美伦电影理论片| 亚洲二区免费| 国产亚洲精品v| 欧美日韩另类国产亚洲欧美一级| 久久精品国产亚洲高清剧情介绍| 亚洲精品日日夜夜| 欧美成人a∨高清免费观看| 性欧美大战久久久久久久久| 日韩网站在线观看| 亚洲第一区色| 午夜日韩在线| 99国产精品久久久久久久久久 | 伊人精品在线| 国产麻豆日韩| 国产精品成人观看视频免费| 欧美aⅴ一区二区三区视频| 久久国产精品一区二区三区| 国产精品99久久久久久久女警| 欧美电影电视剧在线观看| 久久精品国产免费看久久精品| 亚洲免费在线观看| 亚洲图片欧美日产| 一区二区三区产品免费精品久久75| 亚洲激情视频在线| 亚洲国产黄色| 亚洲成色777777在线观看影院| 国产有码在线一区二区视频| 国产精品高潮呻吟久久av黑人| 欧美日韩激情小视频| 欧美freesex8一10精品| 噜噜爱69成人精品| 免费人成网站在线观看欧美高清| 久久久久9999亚洲精品| 久久久久久噜噜噜久久久精品| 久久精品观看| 久久影院亚洲| 欧美高清在线一区| 欧美女主播在线| 欧美日韩国产综合久久| 欧美日韩一卡| 国产精品久久波多野结衣| 国产精品久久久久久五月尺| 国产精品欧美久久| 国产欧美日本一区二区三区| 国产午夜精品久久久久久久| 红桃视频国产一区| 亚洲经典自拍| 亚洲天堂偷拍| 久久国产精品99国产精| 久久频这里精品99香蕉| 欧美波霸影院| 亚洲美洲欧洲综合国产一区| 中国日韩欧美久久久久久久久| 亚洲视频一区二区在线观看| 亚洲自拍偷拍视频| 久久久精品动漫| 欧美高清在线| 国产精品入口尤物| 激情综合视频| 一区二区免费在线视频| 欧美在线观看视频| 欧美激情中文不卡| 在线亚洲欧美| 久久免费黄色| 国产精品区二区三区日本 | 欧美激情精品久久久六区热门| 欧美日韩99| 国外成人在线视频网站| 亚洲免费成人| 久久精品91| 亚洲精品乱码| 欧美伊人久久久久久午夜久久久久| 久热成人在线视频| 国产精品久久久久久久久久ktv | 亚洲精品欧美精品| 亚洲欧美日韩久久精品 | 久久精品一区二区三区中文字幕| 亚洲电影天堂av| 午夜免费日韩视频| 欧美精品一区二区三区在线播放| 国产一区二区三区久久精品| 99国产一区| 女同性一区二区三区人了人一| 亚洲图片欧美一区| 免费观看一区| 韩国av一区二区三区| 亚洲综合日韩| 亚洲韩国一区二区三区| 久久久久久综合| 国产精品综合| 亚洲欧美在线一区二区| 最新中文字幕亚洲|