0

Currently I'm creating an OpenGL application that will render to multiple "targets" (e.g. different Winforms Panels, separate windows etc.).

I actually have a working prototype that uses multiple rendering threads (one for each target). In the threads I use wglMakeCurrent to switch between the different rendering targets.

The problem is: this approach is incredibly slow. Sometimes a rendering cycle can take 30ms or more (and I'm only drawing a single quad).

While doing a little research, I read that rendering on multiple threads in parallel is a very very bad idea (race conditions and whatnot). So now I need some advice on how to do this the right way.

  • Should I use only one thread to draw to all my "targets"?
  • Can I get rid of all those slow wglMakeCurrent calls?
  • Are there any other tricks/best practices to do fast multi-window rendering?
Boris
  • 8,551
  • 25
  • 67
  • 120
  • wglMakeCurrent already sets the context for the current thread. The "don't render on multiple threads" advice applies to using a single context across multiple threads, which clearly - or hopefully - does not apply in your case. – Chris Becke May 22 '17 at 06:20
  • at any rate, while wglMakeCurrent might be slow, creating lots of windows on different threads is pretty terrible for performance. So I'd say that you might get better performance just creating all your windows in a single thread. – Chris Becke May 22 '17 at 06:22
  • 1
    Are you creating windows dynamically or something? I seriously doubt that calls to `wglMakeCurrent` are what is causing the 30ms frame time. Also, if you are creating multiple threads, you don't need to use wglMakeCurrent more than once per thread, as current GL contexts are thread local. Whether or not spawning threads for each target is a good idea depends on what you are doing. If you show some of your code, the performance hit will likely be obvious. – rationalcoder May 22 '17 at 06:30
  • https://stackoverflow.com/questions/29617370/multiple-opengl-contexts-multiple-windows-multithreading-and-vsync – Ripi2 May 22 '17 at 14:54

0 Answers0