I'm trying to create ID2D1RenderTarget to be used for writing text with DirectWrite. I tried two methods but can't get it working, both yield "The parameter is incorrect" error code.
In the first one I created Texture2D with CreateTexture2D and got IDXGISurface with ID3D11Texture2D_QueryInterface. In the second one i got surface directly from back buffer with IDXGISwapChain2_GetBuffer but that doesn't work either.
I think the problem is in the surface but i just don't understand this stuff deeply enough to debug it correctly. Here is my code for the second method:
Getting the surface (i tried with IDXGISurface2 too):
IDXGISurface * BackBuffer = 0;
HR = IDXGISwapChain2_GetBuffer(Renderer.SwapChain2,
0,
&IID_IDXGISurface,
(void**)&BackBuffer);
AssertHR(HR && BackBuffer);
D2DMake(BackBuffer ,&Renderer.DWriteRenderTarget);
And the code for creating RenderTarget:
extern "C" void
D2DMake(IDXGISurface * DxgiSurface,
ID2D1RenderTarget ** DWriteRenderTarget)
{
ID2D1Factory2 * D2DFactory2 = 0;
HRESULT HR = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED ,&D2DFactory2);
AssertHR(HR);
D2D1_RENDER_TARGET_PROPERTIES Props =
D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,
D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
0,
0);
Assert(DxgiSurface && D2DFactory2);
HR = D2DFactory2->CreateDxgiSurfaceRenderTarget(DxgiSurface,
Props,
DWriteRenderTarget);
AssertHR(HR); // Here is where it fails
...
And the way i create SwapAndChain
DXGI_SWAP_CHAIN_DESC1 SwapChainDesc =
{
.Format = DXGI_FORMAT_B8G8R8A8_UNORM,
.SampleDesc = {1, 0},
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
.BufferCount = 2,
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
.Scaling = DXGI_SCALING_NONE,
.AlphaMode = DXGI_ALPHA_MODE_IGNORE,
.Flags = 0,
};
IDXGISwapChain1 *SwapChain1 = 0;
HR = IDXGIFactory2_CreateSwapChainForHwnd(DxgiFactory2,
(IUnknown*)Renderer.Device2,
Window,
&SwapChainDesc,
0,
0,
&SwapChain1);
AssertHR(HR);
HR = IDXGISwapChain2_QueryInterface(SwapChain1,
&IID_IDXGISwapChain2,
(void **)&Renderer.SwapChain2);
AssertHR(HR);