user3442569
user3442569

Reputation: 51

direct2d quickstart with ID2D1Device3

Is there a version of this tutorial using ID2D1Device3 anywhere? Just swapping out all the pointer types doesn't seem to work

https://learn.microsoft.com/en-us/windows/win32/direct2d/direct2d-quickstart-with-device-context?redirectedfrom=MSDN This attempt fails at factory->CreateDevice due to mismatch arg list:

Microsoft::WRL::ComPtr<ID2D1DeviceContext3> devCon3;
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
Microsoft::WRL::ComPtr<ID2D1Factory3> factory;  
Microsoft::WRL::ComPtr<IDXGIFactory> dxgiFactory;
Microsoft::WRL::ComPtr<IDXGIDevice> dxgiDevice;
Microsoft::WRL::ComPtr<ID3D11Device> dev;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> devCon;
Microsoft::WRL::ComPtr<ID2D1Device3> dev3d; 
D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, 0, createDeviceFlags, NULL, 0, D3D11_SDK_VERSION, &dev, &featureLevel, &devCon);
Hres = dev.As(&dxgiDevice);
Hres = dxgiDevice->GetAdapter(dxgiAdapter.GetAddressOf());
Hres = dxgiAdapter->GetParent(__uuidof(IDXGIFactory), &dxgiFactory);
Hres = dxgiFactory->CreateSwapChain(dev.Get(), &scd, swapChain.GetAddressOf());
Hres = (D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, __uuidof(ID2D1Factory3), &options, &factory));
Hres =  (dev3d.Get()->QueryInterface(__uuidof(IDXGIDevice), &dxgiDevice));
Hres = factory->CreateDevice(dxgiDevice.Get(), &dev3d) ;
Hres = dev3d->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, &devCon3);

Upvotes: 0

Views: 167

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 138776

You must first get an ID2D1Device2 and then QueryInterface on this. With WRL helpers, this would be a code similar to this:

Microsoft::WRL::ComPtr<ID2D1Device2> dev2;
Hres = factory->CreateDevice(dxgiDevice.Get(), &dev2);

Microsoft::WRL::ComPtr<ID2D1Device3> dev3;
Hres = dev2.As(&dev3); // does QueryInterface

Upvotes: 1

Related Questions