Jump to content
  • Advertisement
Sign in to follow this  
Silverlan

OpenGL Creating multiple OpenGL contexts with GLFW on different threads

This topic is 1461 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

I'm using GLFW 3.0.4.
I'm trying to improve my loading times by having all resources, including textures, loaded on a separate thread. Problem is, to actually use any opengl functions in a different thread, without blocking the main one, I need a separate opengl context as well.
GLFW doesn't seem to provide any functions to create an independent context, you can only create it in combination with a window. That's not much of a problem however, considering you can just hide it. The problem is this:

 

Note: This function may only be called from the main thread.

(http://www.glfw.org/docs/latest/group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344)

 

So that path is basically down the drain.

 

Are there any alternatives for what I'm trying to do, or would I have to end up using a different library for creating the window/rendering context? If so, which one?

Edited by Silverlan

Share this post


Link to post
Share on other sites
Advertisement

OpenGL is not very helpful with multi-threading, and you may simply be trying to do something that is going to be inherently inefficient or widely supported. I'm sure someone here will eventually chime in on the current state of affairs.

See: http://www.gamedev.net/topic/656684-cases-for-multithreading-opengl-code/

 

One thing you can do is utilize SSE though, especially for multimedia (textures). You are pretty much guaranteed SSE3 support these days, so if that helps you, you could take a look at where the bottlenecks are and see if you are IO bound or there are real cases for vectorization.

 

You can load and parse your resources on another thread, I guess, and then simply upload them on the rendering thread using pointer swapping with locks (as that will reduce allocation).

 

The IO also doesn't necessarily have to block in your main thread though, but I don't know anything about multiplatform asynch IO.

I only have a passing familiarity with linux AIO: http://man7.org/linux/man-pages/man7/aio.7.html

Edited by Kaptein

Share this post


Link to post
Share on other sites

Another solution is to map the buffer on your main thread and pass the mapped pointer to your resource loading thread to populate it with whatever data your are loading. Once the loading is complete, signal the main thread that loading is complete, unmap the buffer, then use the resource. NOTE: This is a gross oversimplification, because both GPU and CPU synchronization will be necessary, but thats the general gist.

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!