Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
99 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 What is IM?
 Execute Buffers
 Steps to Create
 an Application

 Scene Management
 Sample App
 IM Objects
 DrawPrimitive
 Comparing Modes
 Summary

 Printable version

 


Execute Buffers

As we mentioned before, the immediate mode does not provide a built-in geometry engine. All the rendering of the data has to be done by the application, using the concept of execute buffers. An execute buffer is nothing but the vertex data and a set of instructions to manipulate the vertex data. Execute buffers are used directly by immediate mode and indirectly by the retained mode.

Each execute buffer is a complete packet of information. Each execute buffer contains a vertex list and an instruction stream. The instruction stream consists of an operation code (opcode), followed by the data required for the operation. The instructions in the execute buffer define how the vertex list is to be organized, lit and rendered.

Figure 1 shows a diagrammatic representation of an execute buffer. In this figure, even though we have shown three data elements following the first opcode, it is not necessary that all opcodes will require three data elements. Different opcodes require may different number of data elements.

exbuff
Figure 1: Execute Buffer

Execute Buffer Opcodes

Before proceeding any further, let us cover some of the execute buffer opcodes we will be using. Each opcode by convention, has the D3DOP_ prefix. The opcode name follows this prefix. Some of the opcodes are:

D3DOP_POINT
- used to send one or more points to the renderer. The points to be sent should be in a D3DPOINT structure. For this opcode, we have to specify the starting index of the point(s) in the vertex list and the number of points to be rendered
D3DOP_LINE
- used to send a line to the renderer. The line to be rendered has to be sent in the D3DLINE structure. For the opcode, we have to specify two vertices of the line, as indices into the vertex list
D3DOP_TRIANGLE
- used to send a triangle to the renderer. The triangle to be rendered has to be sent in the D3DTRIANGLE structure. For the opcode, we have to specify three vertices which make up the triangle, which are indices into the vertex list. Alongith the points, a flag indicating the edges of the triangle to be rendered, is also specified. The flag describes which edges of the triangle are enabled and is only useful while displaying wireframe models. Some of the value of the flag are
  • D3DTRIFLAG_EDGEENABLE1 - draw an edge only between the first and second point
  • D3DTRIFLAG_EDGEENABLETRIANGLE - draws all edges of the triangle, namely between p1-p2, p2-p3 and p3-p1
D3DOP_MATRIXLOAD
- used to load a matrix into a destination matrix. The matrices have to be specified in the D3DMATRIXLOAD structure. Each of the matrices specified has to be in the D3DMATRIX structure. This opcode copies the source matrix into the destination matrix
D3DOP_MATRIXMULTIPLY
- used to multiply two matrices, into a third matrix. This operation takes two source matrices and multiplies them into a third matrix. The three matrices have to be specified in the D3DMATRIXMULTIPLY structure, with each matrix specified in the D3DMATRIX structure
D3DOP_PROCESSVERTICES
- used to set the lighting and transformations for the specified vertices. The vertices to be processed have to be specified in the
D3DPROCESSVERTICES structure. In this structure, the indices of the start vertex in the source and destination buffers have to be specified, alongwith the number of vertices and a processing flag. The flag indicates the processing to be done on the specified vertices. Some of the values of this flag are:
  • D3DPROCESSVERTICES_COPY
  • D3DPROCESSVERTICES_TRANSFORMLIGHT
  • D3DPROCESSVERTICES_TRANSFORM
D3DOP_STATEX
- used to set the value of the internal variables in the rendering engine. For setting values of the different modules, the are different state opcodes, one to set each variable. Here, the X represents the variable to be used. The different opcodes used are D3DOP_STATETRANSFORM, D3DOP_STATELIGHT and D3DOP_STATERENDER. For each of these opcode, we have to use the D3DSTATE structure. In this structure, we specify the state type to be set and the state information to be set. The different states are:
D3D_STATETRANSFORM
- used to set the internal values for the transformation module. Using this state stransformation, we can set the values of the state registers of the transformation module. The state types used to set the different matrices are:
  • D3DTRANSFOR_WORLD
  • D3DTRANSFORMSATE_VIEW
  • D3DTRANSFORM_PROJECTION
D3D_STATELIGHT
- used to set the internal values for the lighting module of the rendering engine. Using this state, we can set the values of the ambient light, the material properties and the colour model used in the lighting module. The state types used are:
  • D3DLIGHTSTATE_MATERIAL
  • D3DLIGHTSTATE_AMBIENT
  • D3DLIGHTSTATE_COLORMODEL

The colour model can be of two types, namely the monochromatic model or the RGB model. The RGB model is used by default

D3D_STATERENDER
- used to set the internal values for the rasterization module of the rendering engine. Using this state, we can specify the different textures to be used, the texture mapping parameters, and other things. Some of the state types used are:
  • D3DRENDERSTATE_TEXTUREHANDLE
  • D3DRENDERSTATE_ANTIALIAS
  • D3DRENDERSTATE_WRAPU
  • D3DRENDERSTATE_WRAPV
  • D3DRENDERSTATE_FILLMODE
D3DOP_TEXTURELOAD
- used to load a specified texture, to be used for texture mapping. The texture to be loaded is specified in the D3DTEXTURE structure. This structure specifies two texture handles, each in the D3DTEXTUREHANDLE structure. The source texture is copied into the destination texture. A restriction of this opcode is that that the textures have to be of the same size
D3DOP_EXIT
- used to indicate the end of the execute buffer. Immediate mode executes the contents of the execute buffer till it encounters the end of the buffer. Hence, it is important to terminate each execute buffer with this opcode

Execute Buffer Sample Code

After covering some of the opcodes used in execute buffers, let us consider a sample source code, to illustrate the use of the opcodes, to create an execute buffer.

The execute buffer shown in Source Listing 1 stores the data for one point.

Popup : Source Listing 1




Next : Steps to Create an Application