Sign in to follow this  

Locking a D3DXMesh's vertex buffer

This topic is 1605 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

Hey GameDev

 

I'm trying to lock an LPD3DXMESH's vertex buffer so as I can fiddle with the vertices.

My problem is that as follows:

 

When you manually create a mesh in code, you have your own CUSTOMVERTEX kind of struct, and then when you lock the vertex buffer, you can hand it a void pointer to your CUSTOMVERTEX type. EG

	CUSTOMVERTEX* vert;
	vb->Lock(0, 0, (void**)&vert, NULL);

But when I need to lock the meshs vertex buffer, I don't have a vertex class to lock it with.

 

So my question is, how do I lock the mesh vertex buffer when I don't have a vertex struct? Is there a kind of default vertex stuct I can use?

Share this post


Link to post
Share on other sites

Hey GameDev
 
I'm trying to lock an LPD3DXMESH's vertex buffer so as I can fiddle with the vertices.
My problem is that as follows:
 
When you manually create a mesh in code, you have your own CUSTOMVERTEX kind of struct, and then when you lock the vertex buffer, you can hand it a void pointer to your CUSTOMVERTEX type. EG

	CUSTOMVERTEX* vert;
	vb->Lock(0, 0, (void**)&vert, NULL);
But when I need to lock the meshs vertex buffer, I don't have a vertex class to lock it with.
 
So my question is, how do I lock the mesh vertex buffer when I don't have a vertex struct? Is there a kind of default vertex stuct I can use?

 


The ID3DXMesh interface is derived form the ID3DXBaseMesh interface, which includes several lock functions, as described here

Share this post


Link to post
Share on other sites
You don't need a struct to lock a buffer, that's just for convenience (like you said: to manually/programmatically create a mesh).

If you're looking for such a convenience, well you probably want to provide structs for all the vertex formats you want to work with.

You can, however, retrieve enough information programmatically to work without a struct. ID3DXBaseMesh::GetDeclaration will get you the vertex declaration, D3DXGetDeclVertexSize thereof gives you the stride. Lock the buffer and offset the (BYTE!) pointer with index*stride to get to a particular vertex' start, offset again by D3DVERTEXELEMENT9.Offset to get to an individual element. D3DVERTEXELEMENT9.Type will tell you what type it is. There is only a handful so you could switch/case on that (and cast e.g. to D3DVECTOR or D3DCOLOR). Edited by unbird

Share this post


Link to post
Share on other sites

This topic is 1605 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.

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