multithreading - MFC: how to draw opengl from a different thread? -


I am trying to do some open 160 animation in the CWND window with 60 fps. I create a subclass of CW:

class COpenGLControl: public CWnd {...}

I think if I build-in timer "setTimer ()" I used to set it up and set fire to every 1000/60 ms, able to present all the open orders correctly. However, if I apply my own timer using a different thread, then nothing is prepared. I found a black screen

Is there a way to issue open commands from a different thread?

Even if you do not intend to issue GL calls from multiple threads You have to keep in mind the rules of ODGL: an OpenCL reference can only be used by one thread at most, at a time. (And, per thread, can be an active GL context at any time). This does not mean that you can not use the same context in many threads, or you can create it in one and use it in another, you can explicitly "assign" the context from one thread to another. Have to do.

I do not know if you use some other libraries to deal with the GL context, then I am assuming that you are using the original API of your OS - in this case wgl related functions Therefore, to assign a reference, from thread A to "on" in Thread B., Thread A will have to call wglMakeCurrent (NULL, NULL) before referencing Thread B by reference < Code> wglMakeCurrent (SomeDC, myGLCtx) . You can of course switch around a GL context, as often as you want, but it will present a large synchronization overhead and it should be avoided.

From your comments:

Work if I can make reference in the timer thread too?

Yes, it will be.

Just note one side: not create is not the issue at all, since creating the GL context, it does not automatically make "current" in any thread - so that you can create it in Thread A and later it can turn it into Thread B directly.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -