Sign in to follow this  
  • entries
    83
  • comments
    0
  • views
    65689

DirectXTK PrimitiveBatch helper makes it easy to draw user primitives with D3D11

Sign in to follow this  
shawnhar

1029 views

The latest version of DirectXTK adds a PrimitiveBatch helper, for easily and efficiently drawing dynamically generated geometry such as lines or triangles. This fills the same role as the legacy D3D9 APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP. PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and NO_OVERWRITE hints to avoid stalling the GPU pipeline. It automatically merges adjacent draw requests, so if you call DrawLine 100 times in a row, only a single GPU draw call will be generated.

PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and primitive topology, then issuing the final draw call. Unlike the higher level SpriteBatch helper, it does not provide shaders, set the input layout, or set any state objects. PrimitiveBatch is often used in conjunction with BasicEffect and the structures from VertexTypes.h, but it can work with any other shader or vertex formats of your own.

To initialize a PrimitiveBatch for drawing VertexPositionColor data: std::unique_ptr> primitiveBatch(new PrimitiveBatch(deviceContext));
To draw a line: basicEffect->Apply(deviceContext);

deviceContext->IASetInputLayout(inputLayout);

primitiveBatch->Begin();
primitiveBatch->DrawLine(VertexPositionColor(...), VertexPositionColor(...));
primitiveBatch->End();
PrimitiveBatch provides five drawing methods:

  • DrawLine(v1, v2)
  • DrawTriangle(v1, v2, v3)
  • DrawQuad(v1, v2, v3, v4)
  • Draw(topology, vertices, vertexCount)
  • DrawIndexed(topology, indices, indexCount, vertices, vertexCount)
    aggbug.aspx?PostID=10359296

    Source
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now