Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating mapped OpenGL buffers from another thread

OpenGL functions are only supposed to be called from the thread in which the OpenGL context is current. Does this limit apply to updating data using glMapBuffer/glMapBufferRange, i.e. can I map (a region of) a buffer and then read from / write to that region in another thread? Assuming, of course, that the mapping (and unmapping) functions are called from the rendering thread.

like image 760
jaymmer - Reinstate Monica Avatar asked Oct 23 '25 16:10

jaymmer - Reinstate Monica


1 Answers

Before answering the main question, let's cover some misinformation:

I know that you're supposed to only call OpenGL functions in the thread that created the OpenGL context.

This is not true. You must call OpenGL functions only on the thread where the context is current. You can make an OpenGL context current in a different thread (which will automatically make it not current in the previous one. OpenGL contexts can only be current in one thread at the same time). And you can create multiple contexts which share objects. Each such context can be current in a different thread.

Now to the issue. Yes, you are perfectly free to use the mapped pointer however you wish from another thread. Though, as you said, you must use appropriate synchronization mechanisms to let the original thread know that you've finished.

like image 82
Nicol Bolas Avatar answered Oct 26 '25 09:10

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!