Reputation: 21136
I have a d3dDevice:
ComPtr<ID3D11Device1>d3dDevice;
I use it here for the dxgiDevice:
ComPtr<IDXGIDevice3> dxgiDevice2;
HRESULT hr;
hr = d3dDevice.As( &dxgiDevice2 ); // S_OK
hr = d2dFactory->CreateDevice( dxgiDevice2.Get(), d2dDevice.GetAddressOf() ); // E_INVALIDARG One or more arguments are invalid
hr = d2dDevice->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&d2dDeviceContext
);
Why might this error be happening on runtime?
http://msdn.microsoft.com/en-us/library/windows/desktop/dn280482(v=vs.85).aspx
Entirety of my code that is relevant to problem: http://pastebin.com/P7Rs9xdh
Upvotes: 1
Views: 7991
Reputation: 26259
The problem is that you haven't created your DX11 device to be compatible with Direct2D. You need to pass the correct creation flags and you should also consider defining the required feature level. Something like:
// This flag adds support for surfaces with a different color channel
// ordering than the API default.
// You need it for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
// This array defines the set of DirectX hardware feature levels this
// app supports.
// The ordering is important and you should preserve it.
// Don't forget to declare your app's minimum required feature level in its
// description. All apps are assumed to support 9.1 unless otherwise stated.
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
D3D_FEATURE_LEVEL m_featureLevel;
// Create 3D device and device context objects
D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
creationFlags,
featureLevels,
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION,
&d3dDevice11,
&m_featureLevel,
&d3dDeviceContext11);
Upvotes: 7