首页 > 解决方案 > 使用 ID2D1Device3 的 direct2d 快速入门

问题描述

本教程是否有在任何地方使用 ID2D1Device3 的版本?只是换掉所有指针类型似乎不起作用

https://docs.microsoft.com/en-us/windows/win32/direct2d/direct2d-quickstart-with-device-context?redirectedfrom=MSDN 由于参数列表不匹配,此尝试在工厂失败-> CreateDevice:

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);

标签: c++graphicsdirect2dwrl

解决方案


您必须首先获得一个 ID2D1Device2,然后在此获得QueryInterface。使用 WRL 助手,这将是类似于以下的代码:

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

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

推荐阅读