Direct3D中繪製圖元的兩種方式,direct3d繪製圖元
DirectX 中繪製圖元有兩種類型的函數,一個是DrawPrimitiveUp,一個是DrawPrimitive,當然跟索引相關的也有兩個類似的函
數,一個DrawIndexedPrimitiveUp,一個是DrawIndexedPrimitive;
HRESULT DrawPrimitiveUP(
[in] D3DPRIMITIVETYPE PrimitiveType,
[in] UINT PrimitiveCount,
[in] const void *pVertexStreamZeroData,
[in] UINT VertexStreamZeroStride
);
HRESULT DrawIndexedPrimitiveUP(
[in] D3DPRIMITIVETYPE PrimitiveType,
[in] UINT MinVertexIndex,
[in] UINT NumVertices,
[in] UINT PrimitiveCount,
[in] const void *pIndexData,
[in] D3DFORMAT IndexDataFormat,
[in] const void *pVertexStreamZeroData,
[in] UINT VertexStreamZeroStride
);
這個方法就是用數組來儲存頂點的資料,而不是頂點緩衝。它的缺點是要求所有的資料都放在stream 0中,因此不能夠使用多流。優點是用這個函數去繪製圖元時候,頂點的資料不用儲存,原因是IDirect3DDevice9::DrawPrimitiveUP 函數在函數返回之前已經擷取了頂點資料。
毫無例外的是在調用繪製函數之前,必須先調用IDirect3DDevice9::SetFVF或者IDirect3DDevice9::SetVertexDeclaration來設定頂點格式。
DrawIndexedPrimitiveUP函數的用法跟DrawPrimitiveUp函數一樣的優缺點。
HRESULT DrawPrimitive(
[in] D3DPRIMITIVETYPE PrimitiveType,
[in] UINT StartVertex,
[in] UINT PrimitiveCount
);
HRESULT DrawIndexedPrimitive(
[in] D3DPRIMITIVETYPE Type,
[in] INT BaseVertexIndex,
[in] UINT MinIndex,
[in] UINT NumVertices,
[in] UINT StartIndex,
[in] UINT PrimitiveCount
);
這兩個函數分別是採用頂點緩衝和索引緩衝來繪製圖元的,當然繪製圖元之前需要設定頂點的FVF。它可以使用多個stream。不過需要注意的是IDirect3DDevice9::DrawIndexedPrimitive 這個函數中不能使用D3DPT_POINTLIST類型的圖元。