Draw several instances of the same subset of a mesh.
HRESULT DrawSubsetInstanced( [in] UINT AttribId, [in] UINT InstanceCount, [in] UINT StartInstanceLocation );
- AttribId [in]
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. See remarks.
- InstanceCount [in]
Number of instances to render.
- StartInstanceLocation [in]
Which instance to start fetching from in each buffer marked as instance data.
The return value is one of the values listed in Direct3D 10 Return Codes.
A mesh contains an attribute table. The attribute table can divide a mesh into subsets, where each subset is identified with an attribute ID. For example, a mesh with 200 faces, divided into three subsets, might have an attribute table that looks like this:
|AttribID 0||Faces 0 ~ 50|
|AttribID 1||Faces 51 ~ 125|
|AttribID 2||Faces 126 ~ 200|
Instancing may extend performance by reusing the same geometry to draw multiple objects in a scene. One example of instancing could be to draw the same object with different positions and colors. Indexing requires multiple vertex buffers: at least one for per-vertex data and a second buffer for per-instance data.
Drawing instances with DrawSubsetInstanced is very similar to the process used with ID3D10Device::DrawIndexedInstanced that is outlined in Instancing Sample. The key difference when using DrawSubsetInstanced is that vertex and index buffers must be extracted from the ID3DX10Mesh Interface object before the instancing data can be combined.
The following code illustrates extracting the vertex and index buffers from the mesh object.
ID3D10Buffer* vertexBuffer; pDeviceObj->pMesh->GetDeviceVertexBuffer(0, &vertexBuffer); ID3D10Buffer* indexBuffer; pDeviceObj->pMesh->GetDeviceIndexBuffer(&indexBuffer);