Jump to content

  • Log In with Google      Sign In   
  • Create Account

Dynamic vertex buffers?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 KurtO   Members   -  Reputation: 230

Like
0Likes
Like

Posted 26 August 2012 - 01:19 PM

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.

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2853

Like
1Likes
Like

Posted 26 August 2012 - 05:52 PM

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!

#3 CryZe   Members   -  Reputation: 768

Like
1Likes
Like

Posted 27 August 2012 - 01:23 AM

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.

#4 KurtO   Members   -  Reputation: 230

Like
0Likes
Like

Posted 27 August 2012 - 10:50 AM

thanks, didnt know you could create the vertecis array on render frame, now porblem is fixed! thanks!

#5 kauna   Crossbones+   -  Reputation: 2853

Like
1Likes
Like

Posted 27 August 2012 - 11:11 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS