I believe that it is described here:
https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/UWP/D3D1211On12/src
how to set that up in UWP and that the device that is created would have to be created in a compatible form with appropriate flags for use with a Direct2D context.
D2D with ID3D11On12Device
From a Directx12 project template created with Visual Studio 2019:
I added to "pch.h" as follows:
#include <d3d11on12.h>
#include <d2d1_3.h>
#include <dwrite.h>
Based of reading this article:
https://learn.microsoft.com/en-us/windows/win32/direct3d12/d2d-using-d3d11on12#:~:text=The%20D3D1211on12%20sample%20demonstrates%20how%20to%20render%20D2D,D2D%20factory%20Create%20a%20render%20target%20for%20D2D
I added to the top of DeviceResources.cpp these items:
static UINT d3d11DeviceFlags;
static ComPtr <ID3D11DeviceContext> m_d3d11DeviceContext;
static ComPtr <ID3D11On12Device> m_d3d11On12Device;
static ComPtr<ID3D11Device> d3d11Device;
static ComPtr<ID2D1Factory3> m_d2dFactory;
static ComPtr<IDXGIDevice> dxgiDevice;
static ComPtr<ID2D1Device> m_d2dDevice;
static ComPtr<ID2D1DeviceContext> m_d2dDeviceContext;
static ComPtr<IDWriteFactory> m_dWriteFactory;
I appended to the end of "void DX::DeviceResources::CreateDeviceResources() { ... " in DeviceResources.cpp:
ThrowIfFailed(D3D11On12CreateDevice(
m_d3dDevice.Get(),
d3d11DeviceFlags,
nullptr,
0,
reinterpret_cast<IUnknown**>(m_commandQueue.GetAddressOf()),
1,
0,
&d3d11Device,
&m_d3d11DeviceContext,
nullptr
));
// Query the 11On12 device from the 11 device.
ThrowIfFailed(d3d11Device.As(&m_d3d11On12Device));
// Create D2D/DWrite components.
{
D2D1_DEVICE_CONTEXT_OPTIONS deviceOptions = D2D1_DEVICE_CONTEXT_OPTIONS_NONE;
D2D1_FACTORY_OPTIONS d2dFactoryOptions;
d2dFactoryOptions.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
ThrowIfFailed(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &m_d2dFactory));
ThrowIfFailed(m_d3d11On12Device.As(&dxgiDevice));
ThrowIfFailed(m_d2dFactory->CreateDevice(dxgiDevice.Get(), &m_d2dDevice)); <--Exception is Thrown
ThrowIfFailed(m_d2dDevice->CreateDeviceContext(deviceOptions, &m_d2dDeviceContext));
ThrowIfFailed(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &m_dWriteFactory));
}
Does anyone know why an exception is being thrown at the line:
ThrowIfFailed(m_d2dFactory->CreateDevice(dxgiDevice.Get(), &m_d2dDevice));
Things don't seem to run past that point and an exception is thrown? Is it possible to know how to fix the exception being thrown. I would like to use D2D with DirectX12 to draw simple 2D graphics to the screen.
Thank you....
-
Anonymous
2020-08-06T02:47:01.89+00:00