Direct3D中繪製圖元的兩種方式,direct3d繪製圖元

來源:互聯網
上載者:User

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類型的圖元。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.