Line Drawing Support in D3DX (Direct3D 9)

D3DX is a utility library that provides helper services. It is a layer above the Direct3D component.

D3DX supports single-pixel-wide antialiased lines. Line patterns are no longer supported.

The line drawing library emulates lines using texture triangles and assumes the following:

  • Hardware is available through the Direct3D 9 interfaces.
  • At least one texture stage is available.
  • 64x64 textures are used.
  • The following modes are available:
    • Bilinear filtering
    • Clamp address mode
    • Wrap address mode
    • Alpha op modulate
    • Alpha blending (SRCBLEND = SRC_ALPHA, DESTBLEND = INV_SRC_ALPHA)
    • Alpha test if alpha blending is not available; lower quality result

For antialiased line rendering in multisample render targets, use ID3DXLine which generates textured polygons. The pixel coverage values, generated by antialiased line rasterization, modulate the pixel's alpha value computed by the pixel shader. To draw an antialiased line, an application must enable alpha blending and then it must set the D3DRS_ANTIALIASEDLINEENABLE render state to TRUE.

Functionality Description

The library supports drawing colored line strips with the following line features, each of which is independent of any other:

  • Line width
  • Line pattern with repetition (the line pattern counter resets with each ID3DXLine::Draw or ID3DXLine::DrawTransform call. It does not reset with each segment of the line strip.)
  • Antialiasing
  • OpenGL-style lines

Note

No mitering is supported.

 

The library uses native hardware line drawing support (if available in the device) only if:

  • Line width is 1.
  • No line pattern is enabled.

Single-pixel-wide antialiased lines are supported by some hardware, so the library uses that, if available. The LineCaps member of the D3DCAPS9 structure enumerates hardware capabilities for line-drawing primitives.

When the software line drawing is used, each line is expanded into a rectangle and four vertices are sent down to the driver.

Each line segment is drawn with two triangles. The width of the primitive is the specified width plus 1.0, which may result in an extra row or column of pixels. As the line gets wider, the antialias gradient in the texture becomes more coarse, and more fully-opaque texels are replicated around the middle. The gradient is encoded in the v-direction of the texture, and typically replicated along the u-direction. The texture addressing mode for v is clamp.

Each line segment in the list can be considered to be a separate line that happens to start from the previous end point.

Antialiasing quality along the edges parallel to the length of the original line suffers as the line gets wider. It is expected that line widths greater than 32.0 will start to exhibit artifacts along these edges.

D3DX