Jump to content
  • Advertisement
Sign in to follow this  
bobFritzelpuff

OpenGL Multithreading VBOs

This topic is 3699 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm using Vertex Buffer Objects in some openGL code. Update and Draw are running on different threads. I would like the update to be able to change the data in the VBOs that will then be drawn. Is there any way to do this without a whole lot of locking and concurrency issues? For example, I want one thread to be doing this: glBindBuffer(GL_ARRAY_BUFFER, aBuffer) glBufferData(GL_ARRAY_BUFFER, size, newdata, usage) at the same time that the draw is doing this: glBindBuffer(GL_ARRAY_BUFFER, anotherBuffer) glVertexPointer(num,type,offset,NULL) glDrawArrays(and so forth) Obviously, in order for this to work, there would have to be some way to: bind more than one buffer at once (in different threads) potentially draw a buffer while it is being modified Is there any way to do this? Will using glMapBuffer() in the update be any help, or will that fail too because it requires that a buffer be bound first? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You could keep two buffer objects, one active which is used for drawing, and an inactive used for updating. When you need to update the data, use the inactive vbo, bind and map it in the rendering thread, then pass the pointer to the update thread.

Once it's done updating, the update thread would signal the rendering thread, which would unmap the updated vbo, and swap the active and inactive vbo handles.

You could go one step further if you want and use a pool of vbo's. You'd then dequeue, update, swap and enqueue.

Share this post


Link to post
Share on other sites
Quote:
Original post by bobFritzelpuff
[...]
Obviously, in order for this to work, there would have to be some way to:
bind more than one buffer at once (in different threads)
potentially draw a buffer while it is being modified

[...]


No you can't bind two buffers because of OpenGL architecture. Binding a buffer means telling the GPU which object in video RAM you are working on.
So, by binding a buffer you call some graphic card hardware-coded function.
Now, the graphic card has no visibility on the context of the processes using it:
your graphic card doesn't know that process1 is working on buffer1 and process2 on buffer2.
In other words, the call to glVertexPointer(num,type,offset,NULL) refers to the actually bound buffer.

You cannot draw a buffer while modifing it: you modify it in RAM and then you have to recreate the buffer (guess there are some ways to update it..) in the video RAM. In this case, since you want to do it in multitasking you probably also need some locking system on the video ram buffer... guess opengl provides it.

You're just mixing a little things that happen in CPU/RAM and GPU/VRAM contexts.

Hope it helps...
LLL

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!