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类型的图元。

你可能感兴趣的:(Direct3D中绘制图元的两种方式)