Jump to content
  • Advertisement
Sign in to follow this  
Kurt-olsson

Dynamic vertex buffers?

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

Hi!

i have a vertexbuffer with verticies that i am making a trianglelist of.
i create my vertexbuffer array in init() and then draw my triangles on render_frame() with draw_primitives.

it looks like this in init()

[source lang="java"] CUSTOMVERTEX vertices[300] =
{
{ -10, 0, 29, D3DCOLOR_XRGB(0, 0, 255), },
{ -1, 10, 29, D3DCOLOR_XRGB(0, 255, 0), },
{ -1, 0, 29, D3DCOLOR_XRGB(255, 0, 0), },

{ -10, 0, 29, D3DCOLOR_XRGB(0, 0, 255), },
{ -10, 10, 29, D3DCOLOR_XRGB(0, 255, 0), },
{ -1, 10, 29, D3DCOLOR_XRGB(255, 0, 0), },

{ -1, 10, 29, D3DCOLOR_XRGB(0, 0, 255), },
{ -1, 10, -40, D3DCOLOR_XRGB(0, 255, 0), },
{ -1, 0, 29, D3DCOLOR_XRGB(255, 0, 0), },

{ -1, 0, 29, D3DCOLOR_XRGB(0, 0, 255), },
{ -1, 10, -40, D3DCOLOR_XRGB(0, 255, 0), },
{ -1, 0, -40, D3DCOLOR_XRGB(255, 0, 0), },

{ -3,4,-50, D3DCOLOR_XRGB(0, 0, 255), },
{ -18,3,-50, D3DCOLOR_XRGB(0, 255, 0), },
{ -4,22,-50, D3DCOLOR_XRGB(255, 0, 0), }
};

triangle t1 = triangle(D3DXVECTOR3(-1, 0, 29),D3DXVECTOR3(-1, 10, -40),D3DXVECTOR3(-1, 0, -40));
triangle t2 = triangle(D3DXVECTOR3(-1, 10, 29),D3DXVECTOR3(-1, 10, -40),D3DXVECTOR3(-1, 0, 29));
triangle t3 = triangle(D3DXVECTOR3(-10, 0, 29),D3DXVECTOR3(-1, 10, 29),D3DXVECTOR3(-1, 0, 29));
triangle t4 = triangle(D3DXVECTOR3(-10, 0, 29),D3DXVECTOR3(-10, 10, 29),D3DXVECTOR3(-1, 10, 29));
triangle t5 = triangle(D3DXVECTOR3(-3,4,-50),D3DXVECTOR3(-18,3,-50),D3DXVECTOR3(-4,22,-50));

lstTrangles.push_back(t1);
lstTrangles.push_back(t2);
lstTrangles.push_back(t3);
lstTrangles.push_back(t4);
lstTrangles.push_back(t5);[/source]

But i want to alter these values on the fly!
i also want to be able to loop and create my vertexbuffer from my std::vector triangleList.

there must be a way so that i can for example move my triangle left or right in realtime!?

how do i do this?

iam using small triangles as particles for my guns etc in my game. so i need to be able to change the positions all the time.

Share this post


Link to post
Share on other sites
Advertisement
Well, create a dynamic vertex buffer and fill it every frame with map/unmap or lock/unlock depending on the D3D version used.

In any case, do not destroy and recreate your buffer every frame. Make the one used buffer big enough and if it isn't enough, you may split your draw calls.

Cheers!

Share this post


Link to post
Share on other sites
Also, you shouldn't transform every vertex every frame on the CPU. Instead use a vertex shader. The GPU is optimized to transform your vertices. Simply upload a transformation matrix to the graphics card and let a vertex shader deal with the transformation.
If you actually want to transform each vertex in a different way, updating your vertex buffer every frame is the way to go.

Share this post


Link to post
Share on other sites
As stated earlier, you should make use of the world matrix (or equivalent) to transform your mesh to different position. Especially, if the vertices stay at the same position in relation to the other vertices, changing the world matrix is the way to go.

Dynamic vertex buffers are usable for meshes which change their form somehow, particle systems, transferring instance data etc.

Even a bit more complex deformations such as skinned meshes are typically static in the sense that the vertex data doesn't change and they can be stored in a static vertex buffer.

Cheers!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!