Jump to content
  • Advertisement
Sign in to follow this  
yuppies

Manipulate vertex from vertex buffer

This topic is 4956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Let's say you have a valid vertex buffer pVB.

and lets say u use the following vertex structure for storing vertices :

Struct Vertex
{
float x, y, z;
DWORD color;
}

void *p = (Vertex*)pVB->Lock();
p is a pointer to the first vertex structure in stored in VB
(the first vertex);

Now u can use p for manipulating the vertex like this :

p->x = 123;
p->y = 120

and so on...

p[1] - Second vertex
p[2] - Third vertex
.
.
.


u must unlock the VB after you done manipulating so use

pVB->Unlock();

Look at directx sdk for the definition of the lock and unlock functions for more understanding-

Share this post


Link to post
Share on other sites
Lock()'s actual prototype is this:

Lock(UINT OffsetToLock, UINT SizeToLock, VOID **ppbData, DWORD Flags);

Frequently, you can call it like this (to lock the entire buffer):

Vertex *lockedVerts = NULL;

pVB->Lock(0, 0, (VOID **)&lockedVerts, D3DLOCK_DISCARD);

However, since you said you want to just retrieve verts in the buffer, you probably want to use D3DLOCK_READONLY for the final parameter.

When you're done, Unlock() the VB and you're good to render from it again.

-Mezz

Share this post


Link to post
Share on other sites
how can I know Vertex structure of a mesh, so I can access the vertexbuffer ?

I have a mesh. I need access to its vertexbuffer, but I have to know its vertexstructure to get a pointer to the vertexbuffer.

Quote:

Vertex *lockedVerts = NULL;

Share this post


Link to post
Share on other sites
When you create the mesh you also specify the flexible vertex format (FVF) from which u shold know which structure to use

for example :

Lets say you used D3DFVF_XYZ | D3DFVF_DIFFUSE
ur structure will look like this :

struct Vertex
{
float x, y, z;
DWORD color;
}

Share this post


Link to post
Share on other sites
If you created your mesh from a file or by using other function which not use FVF you can call the GetFVF() method of your mesh
interface (ID3DXMesh or ID3DXBaseMesh) and get the vertex FVF

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!