vendredi 12 juin 2015

Win32 Message Pump and std::thread Used to Create OpenGL Context and Render

If I have a function that does the following:

bool foo::init()
{
    [Code that creates window]
    std::thread run(std::bind(&foo::run, this));

    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

Where run is defined as:

void foo::run()
{
    [Code that creates initial opengl context]
    [Code that recreates window based on new PixelFormat using wglChoosePixelFormatARB]
    [Code that creates new opengl context using wglCreateContextAttribsARB]

    do {
        [Code that handles rendering]
    } while (!terminate);   
}

Since the window is recreated on the rendering thread, and the message pump will be performed on the main thread is this considered safe? What function will the WndProc be called on? The above code could be considered bad design, but that is not what I am interested in. I am only interested in what is the defined behavior.

Aucun commentaire:

Enregistrer un commentaire