Peer-to-Peer Forum

 

Login Register    
how to change vertex data on the fly for a generated vrVertexBufferObject
Posted: 17 March 2011 06:12 AM  
Newbie
Rank
Total Posts:  3
Joined  2008-12-09

I need to update vertex data for a vrVertexBufferObject. I have been trying to change the sample vp_vertex_buffer_object so that i manipulate the vertex and color data in the frame loop every frame. However it seems that the change does not take effect if its done this way. The data in the buffer changes but i cant see any results in the view. Do i have to unbind and bind the buffer somehow?

 
Posted: 17 March 2011 05:15 PM   [ # 1 ]  
Sr. Member
RankRankRankRank
Total Posts:  118
Joined  2009-01-16

There are a few things here that need to happen. To effectively pass your data downstream (i.e. from your app in the application thread down to the draw), there are a few steps. Look at the vsgs_dynamic_geometry sample. It shows how to modify the underlying geometry on the fly.

Mix that in with the VBO you wish to update. There are a few caveats when using vbos. Since you are dynamically updating your vbo, make sure to specify an appropriate usage (like STREAM_DRAW). This is important from an OpenGL perspective.
The other caveat is if the data you are modifying is of a different size and/or adding new attributes (like colors, normals. etc). Any such changes would require rebuilding a new vbo.

 
Posted: 18 March 2011 01:52 AM   [ # 2 ]  
Newbie
Rank
Total Posts:  3
Joined  2008-12-09
steveo - 17 March 2011 05:15 PM

There are a few things here that need to happen. To effectively pass your data downstream (i.e. from your app in the application thread down to the draw), there are a few steps. Look at the vsgs_dynamic_geometry sample. It shows how to modify the underlying geometry on the fly.

Mix that in with the VBO you wish to update. There are a few caveats when using vbos. Since you are dynamically updating your vbo, make sure to specify an appropriate usage (like STREAM_DRAW). This is important from an OpenGL perspective.
The other caveat is if the data you are modifying is of a different size and/or adding new attributes (like colors, normals. etc). Any such changes would require rebuilding a new vbo.

Hi,

i already set the STREAM_DRAW using the setUsage() function but this did not help. I want to have a fixed size data buffers and modify them every frame. And the thing is that i dont want to keep the data on the client side which would be the case when using the vsgs_dynamic_geometry method. I thought that the iterators that i use in the sample vp_vertex_buffer_object give me a straight pointer to the VBOs data buffers and by modifying these i could change the VBO on the fly. Am i missing something here? I can modify the buffers once just before the first frame and this modification also has results in the view but when using the same method after the first frame nothing happends in the view. I also tried what steveo suggested (modify the data in the vrGeometry on the client side and in the VBOs and update the vrRenderStrategyFrameGeometry) this does not work either?!

 
Posted: 18 March 2011 11:25 AM   [ # 3 ]  
Sr. Member
RankRankRankRank
Total Posts:  118
Joined  2009-01-16

The reason for the reference for the vsgs sample was that you have to be thread safe for modifying data. If you are modifying your data in some other thread than the draw (typically the application thread), you need to be aware of this and account for proper data modification from one thread to another.

Once that is accomplished, simply modifying the data within the vbo class does not modify the vbo. You either have to do a glMapBuffer/glUnMapBuffer sequence or glBufferSubData. This will modify the internals of the OpenGL vbo. This may not be apart of the api (yet) but can be done directly in OGL calls since you do have the complete data.