[osg-users] Updating VBO's during runtime

Brad Colbert bcolbert at rscusa.com
Fri Jun 1 07:20:11 PDT 2018


I'm updating my vertices at runtime.  I've found a few posts that discuss
this:

(a couple are:)
http://forum.openscenegraph.org/viewtopic.php?t=14826
http://forum.openscenegraph.org/viewtopic.php?t=15782

Let me first mention that I've compiled OSG with GL3 support, so no display
lists.  That said, I'm still calling:

  pointsGeom->setUseDisplayList(false);
  pointsGeom->setUseVertexBufferObjects(true);

Here is a snippet of my call to update the vertices (v_ = vertices, c_ =
colors, n_ = normals, da_ = DrawArrays, g_ = Geometry):

    for (int i = 0; i < numVertices; i++) {
      // Verticies
      v_.at(i)[0] = 500.f * (0.0f + (3.0f * float(rand() % 1000) / 1000.f)
- 1.5f);
      v_.at(i)[1] = 500.f * (0.0f + (4.0f * float(rand() % 1000) / 1000.f)
- 2.f);
      v_.at(i)[2] = 500.f * (1.5f + (0.1f * float(rand() % 1000) / 1000.f)
- 0.05f);

      // Colors
      c_.at(i)[0] = 1.f;
      c_.at(i)[1] = 1.f;
      c_.at(i)[2] = 1.f;
      c_.at(i)[3] = 1.f;

      // Normals
      n_.at(i)[0] = 0.f;
      n_.at(i)[1] = 1.f;
      n_.at(i)[2] = 0.f;
    }

    v_.dirty();
    c_.dirty();
    n_.dirty();

    da_.setCount(numVertices);
    da_.dirty();

*    // *** The dirty() calls above are supposed to tell OSG to update the
VBO's.  For*
*    // some reason this isn't happening.  We are going to force it here.
Not sure of the*
*    // performance implications but hopefully this is temporary.*
*    g_.setVertexArray(&v_);*
*    g_.setColorArray(&c_);*
*    g_.setNormalArray(&n_);*

    g_.dirtyBound();

The update just doesn't happen unless I call the *setVertexArray*,
*setColorArray*, *setNormalArray* methods which doesn't match what the
previous posts about this topic.

Is this because of GL3 or something else?

Thanks,
Brad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180601/d3ec0bfe/attachment.html>


More information about the osg-users mailing list