Platform SDK: DirectX

Processing Vertices

[C++]

Processing the vertices in a vertex buffer applies the current transformation matrices for the device, and can optionally apply vertex operations such as lighting, generating clip flags, and updating extents. The IDirect3DVertexBuffer7 interface exposes the IDirect3DVertexBuffer7::ProcessVertices method to process vertices. You process vertices from a source vertex buffer into a destination vertex buffer by calling the ProcessVertices method of the destination vertex buffer, not the source buffer. The method accepts seven parameters that describe the operations to be performed, the location of the source vertex buffer's IDirect3DVertexBuffer7 interface, the rendering device that will perform the vertex operations, and the location and quantity of vertices that the method targets. After the call, the destination buffer contains the processed vertex data, and the source buffer is unchanged.

When preparing to process vertices, set the first parameter, dwVertexOp, to indicate the vertex operations you want to perform. You must include the D3DVOP_TRANSFORM flag, or the method will fail, but the remaining operations are optional. You can include any combination of optional flags to light the vertices, generate clip flags, and update extents during vertex processing.

The second and third parameters, dwDestIndex and dwCount, reflect the index within the destination buffer at which the vertices will be placed and the total number of vertices that should be processed and placed in the destination buffer. The fourth parameter, lpSrcBuffer, should be set to the address of the IDirect3DVertexBuffer7 of the vertex buffer object that contains the source vertices. The dwSrcIndex specifies the index at which the method should start processing vertices. (The total number of source vertices to be processed is implied by the dwCount parameter.) Set the lpD3DDevice parameter to the address of the IDirect3DDevice7 interface for the rendering device that processes the vertices.

The final parameter, dwFlags, determines special processing options for the method. You can set this parameter to 0 for default vertex processing, or to D3DPV_DONOTCOPYDATA to optimize processing in some situations. When you set dwFlags to 0, vertex components of the destination vertex buffer's vertex format that are not affected by the vertex operation are still copied from the source vertex buffer (when present in the source buffer) or set to 0. However, by using D3DPV_DONOTCOPYDATA, any vertex components of the destination buffer's vertex format not computed as part of the call to ProcessVertices are left untouched. Picture yourself calling the ProcessVertices method intending to transform vertices without lighting them (with the D3DVOP_TRANSFORM vertex operation by itself). If the destination vertex buffer uses the D3DFVF_TLVERTEX vertex format, specifying D3DPV_DONOTCOPYDATA flag will cause the system to ignore the diffuse, specular, and the texture coordinate components of the destination buffer. The result is lighter processing and data transfer overhead—you only wanted the system to transform the vertices. Without using D3DPV_DONOTCOPYDATA, the system would copy the extraneous lighting and texture coordinate components to the vertices in the destination buffer, even though your application doesn't need them. The D3DPV_DONOTCOPYDATA flag is useful to reduce the amount of work required by the system for vertex processing. An application that uses ProcessVertices can copy static vertex components to the destination vertex buffer directly, eliminating the need for the system to copy from the source buffer to the destination buffer.

To determine the vertex processing limitations of a device, query the dwVertexProcessingCaps member of the D3DDEVICEDESC7 structure for its supported vertex processing capabilities.

[Visual Basic]

Processing the vertices in a vertex buffer applies the current transformation matrices for the device, and can optionally apply vertex operations such as lighting, generating clip flags, and updating extents. The Direct3DVertexBuffer7 class offers the Direct3DVertexBuffer7.ProcessVertices method to process vertices. You process vertices from a source vertex buffer into a destination vertex buffer by calling the ProcessVertices method of the destination vertex buffer, not the source buffer. The method accepts seven parameters that describe the operations to be performed, a reference to the source Direct3DVertexBuffer7 object, the rendering device that will perform the vertex operations, and the location and quantity of vertices that the method targets. After the call, the destination buffer contains the processed vertex data, and the source buffer is unchanged.

When preparing to process vertices, set the first parameter, vertexOp, to indicate the vertex operations you want to perform. You must include the D3DVOP_TRANSFORM flag, or the method will fail, but the remaining operations are optional. You can include any combination of optional flags to light the vertices, generate clip flags, and update extents during vertex processing.

The second and third parameters, destIndex and count, reflect the index within the destination buffer at which the vertices will be placed and the total number of vertices that should be processed and placed in the destination buffer. The fourth parameter, srcBuffer, should be the Direct3DVertexBuffer7 object that contains the source vertices. The srcIndex specifies the index at which the method should start processing vertices. (The total number of source vertices to be processed is implied by the count parameter.) Set the dev parameter to the Direct3DDevice7 object that will process the vertices.

The final parameter, flags, determines special processing options for the method. You can set this parameter to 0 for default vertex processing, or to D3DPV_DONOTCOPYDATA to optimize processing in some situations. When you set flags to 0, vertex components of the destination vertex buffer's vertex format that are not affected by the vertex operation are still copied from the source vertex buffer (when present in the source buffer) or set to 0. However, by using D3DPV_DONOTCOPYDATA, any vertex components of the destination buffer's vertex format not computed as part of the call to ProcessVertices are left untouched. Picture yourself calling the ProcessVertices method intending to transform vertices without lighting them (with the D3DVOP_TRANSFORM vertex operation by itself). If the destination vertex buffer uses the D3DFVF_TLVERTEX vertex format, specifying D3DPV_DONOTCOPYDATA flag will cause the system to ignore the diffuse, specular, and the texture coordinate components of the destination buffer. The result is lighter processing and data transfer overhead—you only wanted the system to transform the vertices. Without using D3DPV_DONOTCOPYDATA, the system would copy the extraneous lighting and texture coordinate components to the vertices in the destination buffer, even though your application doesn't need them. The D3DPV_DONOTCOPYDATA flag is useful to reduce the amount of work required by the system for vertex processing. An application that uses ProcessVertices can copy static vertex components to the destination vertex buffer directly, eliminating the need for the system to copy from the source buffer to the destination buffer.

To determine the vertex processing limitations of a device, query the lVertexProcessingCaps member of the D3DDEVICEDESC7 type for its supported vertex processing capabilities.

Take care to create vertex buffers that use compatible vertex formats. At the least, the source buffer should contain untransformed vertices (using the D3DFVF_XYZ flag in the vertex format of the buffer description), and the destination buffer should contain transformed vertices (using the D3DFVF_XYZRHW flag). Any lighting or clipping services require that the source and destination vertex formats contain the appropriate fields. For instance, don't request lighting on vertices when the vertex format doesn't include a vertex normal. Likewise, you can't request that the system produce clip flags for a destination vertex buffer that was created without clipping capabilities. Attempts to perform operations on incompatible buffers will fail in debug builds.

Note that applications must use vertex buffer methods when rendering from a vertex buffer.

You cannot process vertices when the source or destination vertex buffers are locked.