Jump to content

  • Log In with Google      Sign In   
  • Create Account


Humblest

Member Since 08 Jan 2013
Offline Last Active Jan 09 2013 01:09 AM

Posts I've Made

In Topic: Does wglMakeCurrent() leak memory in a worker thread?

09 January 2013 - 01:09 AM

I can't tell whether wglMakeCurrent really leaks or whether there is a different reason for what you see, but if you need to call wglMakeCurrent more than 2-3 times in a program, you're very likely doing something wrong.

Usually you will have one render thread (for most people that is the main thread, too). Often you have worker threads to fill buffers (given a pointer to a mapping), too.
Sometimes you have shared contexts and two threads (one for rendering, one for uploading data), but this is rarely done both for added overhead and complexity.

You really never want to have a hundred or a thousand threads with a hundred/thousand contexts. You also really do not want to call wglMakeCurrent in the middle of your program, because it kills the pipeline.

What you want to do is create one (or at most two or three) threads that will deal with OpenGL, and one (or at most two or three) contexts. Then you want to make exactly one context current in one thread. And then you never want to change that again.

For each thread, there's one dedicated OpenGL context and only one wglMakeCurrent(). This is a server rendering program rather than a desktop application, each thread is responding to one client request and doing its own job. No OpenGL context is shared among them. The maximum number of concurrency won't be high, but concurrency is required.


PARTNERS