OpenSceneGraph icon indicating copy to clipboard operation
OpenSceneGraph copied to clipboard

Fix issue with VertexArrayState current VBO/EBO pointers being set after it is no longer current

Open gregkalata opened this issue 3 years ago • 2 comments

My understanding is that osg::VertexArrayState keeps _currentVBO/_currentEBO to avoid re-binding buffers unnecessarily. However when osg::Drawable finishes drawing, it keeps those pointers set. So the following can happen:

  1. During draw() Drawable A binds VBO1 and sets its _currentVBO to point to VBO1.
  2. During draw() Drawable B binds VBO2 and sets its _currentVBO to point to VBO2.
  3. Next time Drawable A decides to bind VBO1 it will see that _currentVBO to points to VBO1, so it will do nothing.
  4. Drawable A will now dispatch an attribute stored in VBO1, but since it didn't bind VBO1, its VAO will be now bound with VBO2.

I have noticed this issue with multiple osg::Geometry objects that share some attributes and use a shared VBO for those, and have some individual attributes in their individual VBOs.

This PR will reset _currentVBO/_currentEBO pointers when drawing is complete.

gregkalata avatar Mar 24 '22 11:03 gregkalata

Have you tried PR #1079 with https://github.com/openscenegraph/OpenSceneGraph/pull/1079/commits/84a36eb9c26067868806b43db4bb1acd36f17bd7 ? Can it fix your issues?

I am not sure, but I think it is not a good idea to reset buffers like that, OSG uses "lazy mechanism".

valid-ptr avatar Apr 19 '22 09:04 valid-ptr

Apologies for the late response, was swamped with work. I have tried PR #1079 and it seems to fix the problem for me as well. However I suspect only part of the PR is necessary to fix the issue and it doesn't look like it will be accepted any time soon. I was hoping that a PR smaller in scope could be easier to accept

gregkalata avatar May 12 '22 16:05 gregkalata