Share via


Processing Vertices

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

Processing the vertices in a vertex buffer applies the current transformation matrices for the device. Vertex operations such as lighting, generating clip flags, and updating extents can also be applied, optionally.

Fixed Function Processing Vertices

In the fixed function vertex pipeline, processing the vertices in a vertex buffer applies the current transformation matrices for the device. Vertex operations such as lighting, generating clip flags, and updating extents can also be applied, optionally. When using fixed function vertex processing, modifying the elements in the destination vertex buffer is controlled by the D3DMPV_DONOTCOPYDATA flag (see D3DMPV Values). This flag applies only to fixed function vertex processing. The IDirect3DMobileDevice interface exposes the IDirect3DMobileDevice::ProcessVertices method to process vertices. You process vertices to the set of input data streams, generating a single stream of interleaved vertex data to the destination vertex buffer, by calling the ProcessVertices method. The method accepts five parameters that describe the location and quantity of vertices that the method targets, the destination vertex buffer, and the processing options. After the call, the destination buffer contains the processed vertex data.

The first, second, and third parameters, SrcStartIndex, DestIndex, and VertexCount, reflect the index of the first vertex to load, the index within the destination buffer at which the vertices will be placed, and the total number of vertices to process and place in the destination buffer. The fourth parameter, pDestBuffer, should be set to the address of the IDirect3DMobileVertexBuffer of the vertex buffer object that will receive the source vertices. The SrcStartIndex specifies the index at which the method should start processing 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 D3DMPV_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 or set to 0. However, when using D3DMPV_DONOTCOPYDATA, ProcessVertices does not overwrite color and texture coordinate information in the destination buffer unless this data is generated by Microsoft® Direct3D Mobile®. Diffuse color is generated when lighting is enabled, that is, D3DMRS_LIGHTING (see D3DMRENDERSTATETYPE) is set to TRUE. Specular color is generated when lighting is enabled and specular is enabled, that is, D3DMRS_SPECULARENABLE and D3DMRS_LIGHTING are set to TRUE. Specular color is also generated when fog is enabled. Texture coordinates are generated when texture transform or texture generation is enabled. ProcessVertices uses the current render states to determine what vertex processing should be done.

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

FVF Usage Settings for Destination Vertex Buffers

The IDirect3DMobileDevice::ProcessVertices method requires specific settings for the flexible vertex format flags (see D3DMFVF Values) of the destination vertex buffer. The flexible vertex format (FVF) usage settings must be compatible with the current settings for vertex processing.

For fixed function vertex processing, ProcessVertices requires the following FVF settings:

  • Position type is always D3DMFVF_XYZRHW; so, D3DMFVF_XYZ and D3DMFVF_XYZB1 through D3DMFVF_XYZB5 are invalid.
  • The D3DMFVF_NORMAL and D3DMFVF_RESERVED flags must not be set.
  • The D3DMFVF_DIFFUSE flag must be set if an OR operation of the following conditions returns true:
    • Lighting is enabled, that is, D3DMRS_LIGHTING (see D3DMRENDERSTATETYPE) is TRUE.
    • Lighting is disabled, and diffuse color is present in the input vertex streams, and D3DMPV_DONOTCOPYDATA is not set.
  • The D3DMFVF_SPECULAR flag must be set if an OR operation of the following conditions returns true:
    • Lighting is enabled and specular color is enabled, that is, D3DMRS_SPECULARENABLE is true.
    • Lighting is disabled, and specular color is present in the input vertex streams, and D3DMPV_DONOTCOPYDATA is not set.
    • Vertex fog is enabled, that is, D3DMRS_FOGVERTEXMODE is not set to D3DMFOG_NONE (see D3DMFOGMODE).

In addition, the texture coordinate count must be set in the following manner:

  • If texture transform and texture generation are disabled for all active texture stages, and the D3DMPV_DONOTCOPYDATA is not set, then the number and type of output texture coordinates are required to match those of the input vertex texture coordinates. If D3DMPV_DONOTCOPYDATA is set and texture transform and texture generation are disabled, then the output texture coordinates are ignored.
  • If texture transform or texture generation is enabled for any active texture stages, the output vertex might need to contain more texture coordinate sets than the input vertex. This is due to the proliferation of texture coordinates from those being generated by texture generation or derived by texture transforms. Note that a similar proliferation of texture coordinates occurs during DrawPrimitive calls, but is not visible to the application programmer. In this case, Direct3D Mobile generates a new set of texture coordinates. The new set of texture coordinates is derived by stepping through the texture stages and analyzing the settings for texture generation, texture transformation, and texture coordinate index to determine if a unique set of texture coordinates is required for that stage. Each time a new set is required it is allocated in increasing order. Note that the maximum, and typical, requirement is one set per stage, although it might be less due to sharing of nontransformed texture coordinates through D3DMTSS_TEXCOORDINDEX (see D3DMTEXTURESTAGESTATETYPE).

Thus, for each texture stage, a new set of texture coordinates is generated if a texture is bound to that stage and any of the following conditions are true:

  • Texture generation is enabled for that stage.
  • Texture transformation is enabled for that stage.
  • Nontransformed input texture coordinates are referenced through D3DMTSS_TEXCOORDINDEX for the first time.

When Direct3D Mobile is generating texture coordinates, the application is required to perform the following actions:

  • Use a destination vertex buffer with the appropriate FVF usage.
  • Reprogram the D3DMTSS_TEXCOORDINDEX of the texture stage according to the placement of the post-processed texture coordinates. Note that the reprogramming of the D3DMTSS_TEXCOORDINDEX setting occurs when the processed vertex buffer is used in subsequent IDirect3DMobileDevice::DrawPrimitive and IDirect3DMobileDevice::DrawIndexedPrimitive calls.

Finally, texture coordinate dimensionality (D3DMFVF_TEX0 through D3DMFVF_TEX4) must be set in the following manner.

For each texture coordinate set, if texture transform and texture generation are disabled, then the output texture coordinate dimensionality must match the input. If the texture transform is enabled, then the output dimensionality must match the count defined by the D3DMTTFF_COUNT1, D3DMTTFF_COUNT2, or D3DMTTFF_COUNT3 settings. If the texture transform is disabled and texture generation is enabled, then the output dimensionality must match the settings for the texture generation mode; currently all modes generate 3 float values.

When ProcessVertices fails due to an incompatible destination vertex buffer FVF code, the expected code is printed to the debug output (debug builds only).

See Also

Concepts

Using Vertex Buffers