• <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>

            天行健 君子當(dāng)自強(qiáng)而不息

            D3D中的網(wǎng)格模型(1)

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


            10.1 幾何信息

            ID3DXBaseMesh接口包含一個(gè)用來(lái)存儲(chǔ)網(wǎng)格頂點(diǎn)的頂點(diǎn)緩存和一個(gè)用來(lái)定義這些頂點(diǎn)怎樣連接在一起組成網(wǎng)格三角形的索引緩存。我們使用下面的方法來(lái)得到這些緩存的指針:

            HRESULT ID3DXMesh::GetVertexBuffer(LPDIRECT3DVERTEXBUFFER9* ppVB);

            HRESULT ID3DXMesh::GetIndexBuffer(LPDIRECT3DINDEXBUFFER9* ppIB);

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

            IDirect3DVertexBuffer9* vb = 0;

            Mesh->GetVertexBuffer( &vb );

            IDirect3DIndexBuffer9* ib = 0;

            Mesh->GetIndexBuffer( &ib );

            假如想鎖定這些緩存來(lái)讀寫(xiě)數(shù)據(jù),那么我們能夠使用下面的方法。注意這些方法鎖定整個(gè)頂點(diǎn)/索引緩存。

            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.

            當(dāng)然在你鎖定以后一定要記得解鎖:

            HRESULT ID3DXMesh::UnlockVertexBuffer();

            HRESULT ID3DXMesh::UnlockIndexBuffer();

            下面是另外一些與mesh幾何結(jié)構(gòu)有關(guān)的ID3DXMesh接口方法:

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

            DWORD GetNumVertices() — 返回頂點(diǎn)緩存中的頂點(diǎn)數(shù)

            DWORD GetNumBytesPerVertex() — 返回一個(gè)頂點(diǎn)所占的字節(jié)數(shù)

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


            10.2 子集和屬性緩存

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

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

            三角形的屬性ID存儲(chǔ)在mesh的屬性緩存中,它是一個(gè)DWORD數(shù)組。因?yàn)槊總€(gè)面對(duì)應(yīng)屬性緩存中的一項(xiàng),所以屬性緩存中的項(xiàng)目數(shù)等于mesh中的面的個(gè)數(shù)。屬性緩存中的項(xiàng)目和索引緩存中定義的三角形一一對(duì)應(yīng)。即,屬性緩存中的第i項(xiàng)和索引緩存中的第i個(gè)三角形相對(duì)應(yīng)。三角形i由下面三個(gè)索引緩存中的索引項(xiàng)定義:

            A = i * 3

            B = i * 3 + 1

            C = i * 3 + 2

            圖10.2顯示了這個(gè)對(duì)應(yīng)關(guān)系:

            我們可以通過(guò)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)方法來(lái)繪制AttribId指示的子集中的各個(gè)三角形。

            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中的所有三角形,我們將這樣寫(xiě):

            Mesh->DrawSubset(0);

            為了繪制整個(gè)mesh,我們必須繪制mesh的所有子集。這是非常方便的用0,1,2,…,n-1來(lái)標(biāo)識(shí)子集,這里的n是子集的總數(shù)。且有一個(gè)相對(duì)應(yīng)的材質(zhì)和紋理數(shù)組,即子集i與材質(zhì)和紋理數(shù)組的第i項(xiàng)對(duì)應(yīng)。這就使我們能夠簡(jiǎn)單的用循環(huán)來(lá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 閱讀(1482) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(lèi)(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評(píng)論

            久久噜噜久久久精品66| 精品999久久久久久中文字幕| AV色综合久久天堂AV色综合在| 久久99精品久久久久久野外| 久久毛片一区二区| 久久99精品久久久久久动态图| 久久伊人五月丁香狠狠色| 国产精品久久久久一区二区三区| 久久久噜噜噜www成人网| 色播久久人人爽人人爽人人片aV| 亚洲国产成人久久一区WWW| 人人狠狠综合久久亚洲高清| 久久国产成人亚洲精品影院| 久久综合综合久久狠狠狠97色88| 岛国搬运www久久| 久久久久久毛片免费播放| AV无码久久久久不卡蜜桃| 久久久久亚洲av成人网人人软件| 国产成人精品久久一区二区三区av| 久久国产亚洲精品| 99久久精品国产综合一区| 91精品国产91久久综合| 亚洲国产精品无码久久久久久曰| 国产成年无码久久久久毛片| 午夜精品久久影院蜜桃| 国产成人精品久久免费动漫 | 99久久免费国产精品特黄| 久久久久久综合一区中文字幕| 久久久久国产精品嫩草影院| 久久e热在这里只有国产中文精品99 | 久久国产乱子伦免费精品| 免费一级欧美大片久久网| 热99re久久国超精品首页| 久久精品国产网红主播| 性高湖久久久久久久久| 亚洲国产精品嫩草影院久久| 亚洲中文字幕伊人久久无码 | 亚洲国产精品无码久久久不卡| 免费久久人人爽人人爽av| 亚洲人成无码网站久久99热国产| 久久久久久国产精品无码下载|