Most efficient way to update vertex buffer?

Hey ya’ll,

I’m trying to update small sections of the vertex buffer in real-time (60fps). Applications include vertex editing + weight painting.
Was wondering what is the most efficient way to update vertex buffer positions/weights each frame? I only see updateVerticesData/setVerticesData, but this does not seem efficient, esp if I only need to update one single vertex.

Would be great to know if there is an API for this, to avoid a deep dive into the source code i.e. Buffer class etc :slight_smile:

I see something in this thread @Deltakosh
Perhaps that’s my answer? :grinning:

In which case, question

  1. Does it have to be set to updatable first on creation? From line it seems to be the case
  2. If I want to update e.g. 10 non-contiguous vertices, do I loop the vertices and run updateDirectly 10 times (one per vertex) and would this affect performance

Hello!

Yes, it is. If you have a look at the example PG it logs the timings. updateDirectly is faster.

This results only in one draw call at the end so it’s ok. But you should do your own tests. It’s very easy using console.time(). It depends on your scenario. Maybe it’s worth to update the whole buffer so you don’t have to slice the buffer array and save some CPU cycles.

Yes.

:vulcan_salute:

3 Likes