DirectX9 creating vertex and Index caches

Source: Internet
Author: User

C + + create vertex and index caches

A vertex buffer is simply a chunk of contiguous memory, that contains vertex data. Similarly, an index buffer was a chunk of contiguous memory that contains index data.

We can create a vertex and index buffer with the following and the methods:

HRESULT Idirect3ddevice9::createvertexbuffer (
UINT Length,
DWORD Usage,
DWORD FVF,
D3dpool Pool
idirect3dvertexbuffer9** Ppvertexbuffer,
handle* Psharedhandle
);


HRESULT Idirect3ddevice9::createindexbuffer (
UINT Length,
DWORD Usage,
D3dformat Format,
D3dpool Pool,
idirect3dindexbuffer9** Ppindexbuffer,
handle* Psharedhandle
);


The majority of the parameters is identical for both methods, so let's cover the parameters of both methods together.

Length-the number of bytes to allocate for the buffer. If we wanted a vertex buffer to the enough memory to store eight vertices, we would set this parameter To8 * sizeof (verte x), Wherevertexis our vertex structure.

Usage-specifies some additional properties about what the buffer is used. This value can is zero, indicating no additional properties, or a combination of one or more of the following flags:

D3dusage_dynamic-setting This flag makes the bufferdynamic. See the notes in static and dynamic buffers on the following page.
D3dusage_points-this flag specifies that the buffer would hold point primitives. Point primitives is covered in "particle Systems" in Chapter 14. This flag was used only for vertex buffers.
D3dusage_softwareprocessing-vertex processing is do in software.
D3dusage_writeonly-specifies that the application would only write to the buffer. This allows the driver-place the buffer in the best memory location for write operations. Note that reading from a buffer created with the this flag would result in an error.

Fvf-the flexible vertex format of the vertices that's stored in the vertex buffer

Pool-the memory pool in which the buffer is placed

Ppvertexbuffer-pointer to receive the created vertex buffer

Psharedhandle-not used; Set to zero

Format-specifies the size of the indices; used3dfmt_index16 for 16-bit indices or used3dfmt_index32for 32-bit indices. Note that the devices support 32-bit indices; Check the device capabilities.

Ppindexbuffer-pointer to receive the created index buffer


The following example creates a static vertex buffer that have enough memory to hold eight vertices of typevertex.

idirect3dvertexbuffer9* vb;
_device->createvertexbuffer (
8 * sizeof (VERTEX),
0,
D3DFVF_XYZ,
D3dpool_managed,

&VB,

0);


This next code example shows what to create a dynamic index of buffer that have enough memory to hold the 16-bit indices.

Idirect3dindexbuffer9* IB;
_device->createindexbuffer (
$ * sizeof (WORD),
D3dusage_dynamic | D3dusage_writeonly,
d3dfmt_index16,
d3dpool_managed,
&ib,
0);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.