Sign in to follow this  
yuppies

Manipulate vertex from vertex buffer

Recommended Posts

DesignerX    174
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
Mezz    571
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
fantasy_world    100
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
DesignerX    174
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
DesignerX    174
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this