Viewport Scaling

The dimensions used in the dwX, dwY, dwWidth, and dwHeight members of the D3DVIEWPORT2 structure for a viewport define the location and dimensions of the viewport on the render target surface. These values are in screen coordinates, relative to the upper-left corner of the surface.

Direct3D uses the viewport location and dimensions to scale the vertices to fit a rendered scene into the appropriate location on the target surface. Internally, Direct3D inserts these values into a matrix that is applied to each vertex:

This matrix simply scales vertices according to the viewport dimensions and translates them to the appropriate location on the render target surface. (The matrix also "flips" the y-coordinate to reflect a screen origin at the top-left corner with y increasing downward.) After this matrix is applied, vertices are still homogeneous—that is, they still exist as [x,y,z,w] vertices—and they must be converted to non-homogeneous coordinates before being sent to the rasterizer. This is performed by way of simple division, as discussed in The Rasterizer.