max
max

Reputation: 19

c++ OpenGL Multithreading with buffer resource

I have an OpenGL program that needs to periodically update the textures. But at the same time I want the program to be responsive (specifically, to continue running the draw/display code) while it's updating these textures.

But this seems impossible: If I make thread1 do the draw/display code and thread2 to the texture moving, then they will conflict under the resource GL_ARRAY_BUFFER_ARB because thread2 has to keep that resource to move some textures over to a vbo. And I need GL_ARRAY_BUFFER_ARB to do the draw/display code for thread1 because that uses different vbo's.

For example this code

glBindBufferARB(GL_ARRAY_BUFFER_ARB, tVboId);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVertices*2*sizeof(GLfloat), texCoords, GL_DYNAMIC_DRAW_ARB);  
    glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);

will move some textures over but it will take a while. During that time the display code is supposed to run many times but it will instead crash, because GL_ARRAY_BUFFER_ARB is in use.

I thought I could do something like GL_ARRAY_BUFFER_ARB2 but there is no such thing, I think.

Upvotes: 2

Views: 506

Answers (2)

ronag
ronag

Reputation: 51283

Use PBOs they allow you to do asynchronous transfers, read more here.

Upvotes: 3

Related Questions