Filling the Execute Buffer

After you have finished filling your execute buffer, it contains the vertices describing your model and a series of instructions about how the vertices should be interpreted. The following sections describe filling an execute buffer:

·Selecting the Vertex Type

·Triangles

·Processing Vertices

·Finishing the Instructions

You can streamline the task of filling execute buffers by taking advantage of the helper macros that ship with the samples in the DirectX Programmer's Reference. The D3dmacs.h header file in the Misc directory of the samples contains many useful macros that will simplify your work. In particular, the macros PUTD3DINSTRUCTION and VERTEX_DATA are useful for filling execute buffers.

For an example of filling an execute buffer, see Filling the Execute Buffer, in the Direct3D Execute-Buffer Tutorial.

Selecting the Vertex Type

Applications may use all or part of the Direct3D rendering pipeline. The type of vertex that you use in your program determines how much of the rendering pipeline is used. For details, see Vertex Types.

Triangles

You use the D3DOP_TRIANGLE opcode to insert a triangle into an execute buffer. In a triangle, vertices are zero-based indices into the vertex list that begins the execute buffer. Triangles are described by the D3DTRIANGLE structure.

Triangles are the only geometry type that can be processed by the rasterization module. The screen coordinates range from (0, 0) for the top left of the device (screen or window) to (width - 1, height - 1) for the bottom right of the device. The depth values range from zero at the front of the viewing frustum to one at the back. Rasterization is performed so that if two triangles that share two vertices are rendered, no pixel along the line joining the shared vertices is rendered twice. The rasterizer culls back facing triangles by determining the winding order of the three vertices of the triangle. Only those triangles whose vertices are traversed in a clockwise orientation are rendered.

You should be sure that your triangle data is aligned on QWORD (8-byte) boundaries. The OP_NOP helper macro in D3dmacs.h can help you with this alignment task. Note that if you use this macro, you must always bracket it with opening and closing braces.

Processing Vertices

After filling in the vertices in your execute buffer, you typically use the D3DOP_PROCESSVERTICES opcode to set the lighting and transformations for the vertices.

The D3DPROCESSVERTICES structure describes how the vertices should be processed. The dwFlags member of this structure specifies the type of vertex you are using in your execute buffer. If you are using D3DTLVERTEX vertices, you should specify D3DPROCESSVERTICES_COPY for dwFlags. For D3DLVERTEX, specify D3DPROCESSVERTICES_TRANSFORM. For D3DVERTEX, specify D3DPROCESSVERTICES_TRANSFORMLIGHT.

Finishing the Instructions

The last opcode in your list of instructions should be D3DOP_EXIT. This opcode simply signals that the system can stop processing the data.