Search code examples
directxdirectx-11direct3ddirect2d

Why do I need a 3D device to create a 2D device context in DirectX?


I am reading this page of the DirectX programming guide (https://learn.microsoft.com/en-us/windows/win32/direct2d/devices-and-device-contexts) and I wonder if anyone could help me understand the reason behind the following paragraph:

What is a Direct2D device? You need a Direct2D device and a Direct3D device to create a Direct2D device context. A Direct2D device (exposes an ID2D1Device interface pointer) represents a display adapter. A Direct3D device (exposes an ID3D11Device interface pointer) is associated with a Direct2D device. Each app must have one Direct2D device, but can have more than one device. enter image description here

Why do I need a 3D device for creating a 2D device context instead of just creating a 2D device? What is happening behind the scenes and what is the role of the 3D device for rendering 2D graphics?


Solution

  • The basic answer here is that the Direct3D API talks to the video driver which natively supports Direct3D primitives (points, single-pixel lines, and triangles all with optional textures).

    Direct2D is a software layer that implement 'vector graphics' primitives which are ultimately scan-converted into Direct3D primitives.

    DirectWrite uses Direct2D to do it's output, which in turn uses Direct3D.

    Direct2D uses Direct3D 10.1 specifically. With DirectX 11.1 (Windows 8 or later, Windows 7 with KB2670838 installed) the interop between Direct3D 10.1 and Direct3D 11 is handled by the system. Prior to that, the developer had to have a Direct3D 10.1, Direct3D 11, and Direct2D device.

    See Vector vs. Raster Graphics.