D3D11 Device

I am trying to figure out how to use the D3D11 renderer after initialization. I am familiar with using modern OpenGL with SDL2, but not D3D11. There is a function SDL_RenderGetD3D9Device to obtain the D3D9 device, but there seems to be no equivalent function for D3D11. Without a ID3D11Device, I do not know how to do GPU resource allocation. I can’t find a single example or tutorial with SDL2 being used with D3D11, so I am not sure how to proceed.

How is the SDL2 D3D11 renderer supposed to be used after the renderer and window are created? Specifically, how am I supposed to use the D3D11 API to allocate resources (create buffers, etc.)?

Thanks for any help!

holocronweaver wrote:

I am trying to figure out how to use the D3D11 renderer after initialization. I am familiar with using modern OpenGL with SDL2, but not D3D11. There is a function SDL_RenderGetD3D9Device to obtain the D3D9 device, but there seems to be no equivalent function for D3D11. Without a ID3D11Device, I do not know how to do GPU resource allocation. I can’t find a single example or tutorial with SDL2 being used with D3D11, so I am not sure how to proceed.

How is the SDL2 D3D11 renderer supposed to be used after the renderer and window are created? Specifically, how am I supposed to use the D3D11 API to allocate resources (create buffers, etc.)?

D3D11 presents a lot less through its ‘Device’ interface than D3D9 did. It tends to break things up into a much larger set of interfaces. I.e. D3D9 had a pretty well defined focal point (in IDirect3DDevice9), with which all manner of things could be accomplished. D3D11 really doesn’t have a similar, singular counterpart, and instead opts for lots of different objects, each with different interfaces.

If you’d like to do D3D11 programming with SDL, which is possible, I’d recommend creating the D3D11 resources yourself. You can use SDL to create the OS-native window(s), and you can let SDL handle user input(s), audio, and the like. For rendering, I’d suggest that you:

  1. use SDL_CreateWindow() to create a window
  2. use SDL_GetWindowWMInfo() to get OS-specific info on the window. For Win32, this would be an HWND; for WinRT, this would be an ICoreWindow.
  3. create your own DXGIFactory and D3D11 device (with Windows API functions like CreateDXGIFactory1() and D3D11CreateDevice()).
  4. use one of several methods in IDXGIFactory2 to create the swap chain, passing-in data provided by SDL_GetWindowWMInfo()
  5. create the rest of your GPU resources using the fore-mentioned D3D11 objects (the DXGIFactory, swap chain, and D3D11 device)

Make sense?

Cheers,
– David L.