Is OpenGL HDC creation realistic?

My company would like to use SDL2 for an OpenGL project. However, it requires creating our own Windows device context in order to use Nvidia specific extensions for assigning GPU affinity.

Is there a realistic path to accomplish this? We are willing to modify source code if it’s not too drastic.

Do you want to use wglCreateAffinityDCNV? I don’t have Windows with nvidia at the moment, but maybe you can get HWND from your HDC (WindowFromDC) and use SDL_CreateWindowFrom (maybe you’ll have to fiddle with OpenGL hints/flags)

Yes, you can get the HDC from an existing SDL window, just create it with the SDL_WINDOW_OPENGL flag and then do something like this:

SDL_SysWMinfo info;
HDC hdc;

SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(window, &info);
hdc = info.info.win.hdc;

If you’re using SDL3, that becomes:

HDC hdc = (HDC)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HDC_POINTER, NULL);

I didn’t know about SDL_CreateWindowFrom(). This might do what we need! I assume it will create its own context which is not affinity so there might be a hack involved to replace that.

Thank you, I will look further into it.

To use Nvidia’s GPU affinity context it has to be created using a device context that is assigned a GPU using Nvidia calls. So to use SDL it requires a way to create both the device context and the OpenGL context that SDL uses. It might require altering the source code, but hopefully very little.