Jump to content
  • Advertisement
Sign in to follow this  
littletray26

Locking a D3DXMesh's vertex buffer

This topic is 1816 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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!