Microsoft DirectX 8.1 (Visual Basic)

Access the Contents of an Index Buffer

Index buffers enable Microsoft® Visual Basic® applications to easily update the index data they contain. To lock, fill, and unlock index buffers use the D3DIndexBuffer8SetData helper function. D3DIndexBuffer8SetData accepts five parameters, The first, Ibuffer, is the Direct3DIndexBuffer8 object that contains the index data. The second parameter, Offset, is the offset into the index data. The third parameter is the size, measured in bytes, of the index data.

The fourth parameter, Flags, tells the system how the memory should be locked. You can use it to indicate how the application accesses the data in the buffer. Specify constants for the Flags parameter according to the way the index data will be accessed by your application. This allows the driver to lock the memory and provide the best performance given the requested access type. Use D3DLOCK_READONLY flag if your application will read only from the index buffer memory. Including this flag enables Microsoft® Direct3D® to optimize its internal procedures to improve efficiency, given that access to the memory will be read-only.

The last parameter accepted by the D3DIndexBuffer8SetData helper function, Data, is the first element of an array of data to load into the index buffer. Note this parameter is of type Any. To use it properly, you must specify the first element of the array for Data, as shown in the following code example.

Dim Indices(2) As CUSTOMINDEX
Dim IndexSizeInBytes As Long

'Determine the length of the index data.
IndexSizeInBytes = Len(Indices(0))

'Copy indices into the index buffer.
D3DIndexBuffer8SetData VB, 0, IndexSizeInBytes * 3, 0, Indices(0)

Note  If you create an index buffer with the D3DUSAGE_WRITEONLY flag, do not use the D3DLOCK_READONLY locking flag. Use the D3DLOCK_READONLY flag if your application will read only from the index buffer memory. Including this flag enables Direct3D to optimize its internal procedures to improve efficiency, given that access to the memory will be read-only.

See Using Dynamic Vertex and Index Buffers for information on using D3DLOCK_DISCARD or D3DLOCK_NOOVERWRITE for the Flags parameter of the Lock method.

To lock, read, and unlock the contents of index buffers, use the D3DIndexBuffer8GetData helper function.

Retrieving Index Buffer Descriptions

Retrieve information about an index buffer by calling the Direct3DIndexBuffer8.GetDesc method. This method fills the members of the D3DINDEXBUFFER_DESC structure with information about the vertex buffer.