windowswinapiopenglgdiwgl

What do Windows DCs and GLRCs correspond to?


What does a DC correspond to in Windows? I know I can get an HDC from an HWND or an HMONITOR. Does that mean that a window's DC is an alias or proxy for its monitor's DC? Windows allows you to say that a window class should have its own DC, so it seems like they're not the same DC, although the Windows API also seems to support having a parent-child relationship between DCs. Would I find the monitor's DC to be one of the parent DCs?

What happens if a window spans multiple monitors? The Windows API seems to only support getting a single HDC back from a window and getting a single HGLRC from an HDC. I've read that OpenGL doesn't support having a full-screen window span multiple monitors and thus you must have multiple windows to accomplish this.

Would an SLI/Crossfire system be a single GLRC?

It seems to me that a GLRC is what most closely resembles a graphics system. The GLRC represents a single graphics system. The DCs represent the outputs. A GLRC can draw to any DCs that are associated with the outputs connected to the graphics system and any child DCs of those DCs. You can also have multiple monitors and multiple graphics cards, each of which are paired together, and thus each GLRC paired with each DC.

Correct or confirm?


Solution

  • A device context in Windows is a surface that can (theoretically) be drawn to, and may well be visible to a display. Windows have device contexts, as does the desktop window and monitors. Individual windows can share device contexts; this can happen with subwindows that represent simple controls and so forth.

    Device contexts don't have parent/child relationships in the way you mean. The whole CS_PARENTDC thing is about the clipping rectangle for the window's device context.

    A window has a single device context, period (it's a bit more complex than that if the window doesn't use CS_OWNDC, but you should always use that when dealing with OpenGL), no matter where the window goes. The term "device context" should not be confused with "monitor" or any actual hardware. It is simply a surface that you can perhaps draw to.

    As for OpenGL, device contexts only have a relatively loose association to rendering contexts. It is legal to use any device context with an RC as long as that RC was created with the same pixel format that the new DC has. So you can set a pixel format on DC1, make an RC with it, then set the same pixel format on DC2, and you can use wglMakeCurrent with DC1 or DC2 and that RC.

    How multimonitor stuff works with OpenGL depends entirely on the GPU setup. The ICD mechanism that allows OpenGL to work on Windows only allows for a single driver to be installed. So if you have two cards in your system, each plugged into separate monitors, with two different drivers, OpenGL will only recognize one of them. Attempting to draw to a DC that is partially on the other GPU's screen will have unpredictable results.

    Now, if you have one card feeding multiple monitors, OpenGL doesn't care. The issue is the number of independent, visible graphics processors.

    That being said, the whole point of SLI/Crossfire is to pretend that two GPUs are actually just one. As such, you have one driver, the OS only really sees one GPU, and only one of those cards outputs to monitors. Thus, OpenGL works exactly as it would for one card feeding multiple monitors.