PDA

View Full Version : updating VOB data!



Golgoth
02-22-2008, 02:23 PM
hi all!

Im using VOB and Im doing vertex animation... the animation is not working unless I rebind the vertex data using glBufferSubData... I wondering what is the commun way to tell the vob that the data has changed? do I even need to?

thx

noncopyable
02-22-2008, 04:32 PM
Yes, you have to, you uploaded buffer to gpu and lost the pointers.
glMapBufferARB/glUnMapBufferARB maybe?

And it is VBO!

Golgoth
02-23-2008, 08:06 AM
ya you r right its VBO... now.. here is the version where I think it should work but the vertices are not updated when animated:



void OpenGL::SetClientBuffer(Primitive *in_primitive)
{
UInt &l_buffer = in_primitive->GetBufferArray();
if (l_buffer == 0)
{
glGenBuffers(1, &l_buffer);
glBindBuffer(GL_ARRAY_BUFFER, l_buffer);
glBufferData(GL_ARRAY_BUFFER, in_primitive->GetBufferArraySize(), NULL, in_primitive->GetBufferType());
glBufferSubData(GL_ARRAY_BUFFER, in_primitive->GetVertices().GetBufferOffset(), in_primitive->GetVertices().GetBufferSize(), in_primitive->GetVertices().GetData());

else
glBindBuffer(GL_ARRAY_BUFFER, l_buffer);
}

and here is the version where the vertices are being updated:



void OpenGL::SetClientBuffer(Primitive *in_primitive)
{
UInt &l_buffer = in_primitive->GetBufferArray();
if (l_buffer == 0)
{
glGenBuffers(1, &l_buffer);
glBindBuffer(GL_ARRAY_BUFFER, l_buffer);
glBufferData(GL_ARRAY_BUFFER, in_primitive->GetBufferArraySize(), NULL, in_primitive->GetBufferType());
glBufferSubData(GL_ARRAY_BUFFER, in_primitive->GetVertices().GetBufferOffset(), in_primitive->GetVertices().GetBufferSize(), in_primitive->GetVertices().GetData());

else
{
glBindBuffer(GL_ARRAY_BUFFER, l_buffer);
glBufferSubData(GL_ARRAY_BUFFER, in_primitive->GetVertices().GetBufferOffset(), in_primitive->GetVertices().GetBufferSize(), in_primitive->GetVertices().GetData());
}
}


is this the way to go?

Komat
02-23-2008, 08:26 AM
I think you misunderstood how the VBOs work. When you call glBufferSubData, the pointed data are copied into VBOs memory. They will be not influenced by any change to the content of the original array they were copied from. You need to explicitly copy new data to the buffer by use of glBufferSubData or the glMapBufferARB api if you need them to change.

Golgoth
02-23-2008, 08:41 AM
You need to explicitly copy new data to the buffer

I see, in that case, is the use of vbo still worth it for vertex animation instead of standard client states?

my understanding of using the buffer type set to dynamic would have reset the data automaticly...

thx

Komat
02-23-2008, 10:38 AM
I see, in that case, is the use of vbo still worth it for vertex animation instead of standard client states?

It depends on how many times you will draw that geometry per one upload and how the driver handles memory management for draws issued using standard client arrays. You can try to compare the performance for your specific case.



my understanding of using the buffer type set to dynamic would have reset the data automaticly...

No. That only tells the driver that the buffer is expected to be updated often.