Vertex and Index Buffers (Windows Embedded CE 6.0)
1/6/2010
Vertex and index buffers are created similarly: The middleware calls D3DM_CreateSurface with D3DM_CREATESURFACE_DATA->SurfaceType set to D3DMRTYPE_VERTEXBUFFER (for vertex buffers) or D3DMRTYPE_INDEXBUFFER (for index buffers). Each of these buffer types is serviced with its own description structure, either D3DMVERTEXBUFFER_DESC or D3DMINDEXBUFFER_DESC, to instruct the driver how it should create the buffer. The middleware only validates these descriptions in the debug version of the run-time image. The driver is not expected to populate any members of the description structures when it creates the surface.
For a vertex buffer, the D3DMVERTEXBUFFER_DESC.Format member is always D3DMFMT_VERTEXDATA (see D3DMFORMAT) and the D3DMVERTEXBUFFER_DESC.Usage member always contains at least the D3DMUSAGE_LOCKABLE (see D3DMUSAGE Values) bit. The value in D3DMVERTEXBUFFER_DESC.Pool may specify either system or video memory. The D3DMVERTEXBUFFER_DESC.Size member contains the number of bytes that should be allocated for the vertex buffer and the D3DMVERTEXBUFFER_DESC.FVF member identifies the format of the vertices that will reside in this buffer.
Index buffers are similar. The usage bits will still always contain at least the D3DMUSAGE_LOCKABLE bit. The index buffer may reside in either the video or system memory pool. The driver must support at least one type of index buffer. The only major difference is that the index buffer may only be one of two formats: D3DMFMT_INDEX16 or D3DMFMT_INDEX32. These indicate the size of the indices that the application will write into the buffer.
Vertex Data Order
The following list shows the order that the flexible vertex format (FVF) properties appear in the vertex buffer.
1. Position data
2. Normal vector (if present)
3. Diffuse color (if present)
4. Specular color (if present)
5. Texture coordinates, in order from first to fourth. (if present)
When a vertex buffer is made into the active vertex buffer by means of the IDirect3DMobileDevice::SetStreamSource method, the FVF of the vertex buffer should be used to do initial setup on the transformation pipeline.
Vertex Buffer Optimization
An optimized Direct3DĀ® MobileĀ® driver should arrange its vertex buffers into the best possible format for its internal use. The driver should also control where the buffer is allocated to best suit the its internal operations. The driver's D3DM_LockSurface and D3DM_UnlockSurface functions implement these types of optimizations. There are flags to help control the optimization process in both the D3DM_CreateSurface call and the D3DM_LockSurface call.
The following table provides information on handling D3DMUSAGE Values within the implementation of D3DM_CreateSurface.
D3DMUSAGE Value | Action |
---|---|
D3DMUSAGE_DYNAMIC |
This flag indicates to the driver that the application intends to lock the vertex buffer frequently. When a vertex buffer is created using D3DMUSAGE_DYNAMIC, the driver should not do any internal optimizations during calls to D3DM_LockSurface and D3DM_UnlockSurface, and instead do the necessary work when the buffer is used in a drawing operation. |
D3DMUSAGE_DONOTCLIP |
This flag indicates that the vertex buffer content will never require clipping. When rendering with buffers that have this flag set, the D3DMRS_CLIPPING (see D3DMRENDERSTATETYPE)render state must be set to FALSE. |
D3DMUSAGE_WRITEONLY |
This flag indicates that the buffer will never be read. Consequently, the driver will never have to prepare a sub-buffer of the vertex buffer for applications to read back from. Additionally, if a write-only buffer is used as the target of a IDirect3DMobileDevice::ProcessVertices operation, the driver does not need to prepare anything for the application to read back. The driver can leave the data in any intermediate format that it chooses. |
The following table provides information on handling D3DMUSAGE values within the implementation of D3DM_LockSurface.
D3DMUSAGE Value | Action |
---|---|
D3DMLOCK_DISCARD |
This flag indicates that the application overwrites every location within the buffer with a write-only operation. This is a valid option when using dynamic vertex buffers. A pointer to a new memory area is returned so that dynamic memory access (DMA) or rendering from the previous area do not stall. |
D3DMLOCK_NOOVERWRITE |
This flag indicates that the application will not need to overwrite any data in the vertex buffer. Therefore, the driver can return immediately and continue rendering using this buffer. If this flag is not used, the driver must finish rendering before returning from locking. |
D3DMLOCK_READONLY |
This flag indicates that the application will not write to the buffer. This enables vertex buffers stored in non-native formats to save the step of converting the data in the non-native format back into the application's format when unlocking. |
See Also
Concepts
Surface Creation by Direct3D Mobile Drivers
Resources in Direct3D Mobile Drivers