Archived

This topic is now archived and is closed to further replies.

vbisme

Dynamic Vertices

Recommended Posts

vbisme    100
Is there away to dynamically change vertices data without recreating the vertex buffer? For example, we could use transformation for rotation, scaling, and translation or use texture transformation to "change the tu and tv" in a sense. I can''t figure out how to change the vertex color? Any insights? One thought is to us materials and lighting, but you would need to have a lot of them and change it quite often. Thanks.

Share this post


Link to post
Share on other sites
sirob    1181
One you create a VB, its there, so you don''t need to recreate it under any cirucumstance, other than to change the size (or any other option you set at creation).

If you want to modify a vertex, all you need to do is lock the VB at the desired location (you could lock it all if you don''t know what part you need or you need to change a lot of it''s data). Once its locked you get a pointer to the data, so you can change it by accessing it directly.

A simple use would be to keep the vertex data in an array outside the VB, modify it when you need to, then before rendering lock the whole VB, memcopy all the vertices in, and render.

Kepp in mind any vertex you don''t need to recopy is a waste of time, so to make this efficient you should copy as little as possible.

Another way would be to directly access the memory using the pointer, since it''s really a pointer to an array of vertices.

Hope this helps .

Sirob Yes.»
Footman, at large.

Share this post


Link to post
Share on other sites
create your vertex buffer with the DYNAMIC usage flag(see sdk), this will allow you to use dynamic vertex information without to great a hit to your rendering speed. for simplicity you can use a simple DrawPrimitiveUP, which allows you to pass an array of vertex data. the problem with UP is that it bogs after the 5th or 6th call in a cycle, and is measurably slower with large arrays.


Dredd

Share this post


Link to post
Share on other sites
IFooBar    906
they lock the vb and alter the color component of the vertices. then when they''re done altering the color component you aunlock the vb and send it to the graphics card for further processing.


:::: [ Triple Buffer ] ::::

Share this post


Link to post
Share on other sites
Lupin    122
If you just want an solid color for all your vertices you could use an simple vertex shader to do this.

Memcpying is very slow! sirob, if you want to use an pointer you''d still have to lock it because when manipulating the pointer without locking it''s possible that the gfx card wants to access the data whilst you''re altering it (most likely results in an crash I think), that''s the reason why the lock function exists.

Share this post


Link to post
Share on other sites