user3442569
user3442569

Reputation: 51

C++ How to call CreateDeviceContext for ID2D1Device3

I have a graphics engine using ID2D1Device1, but I cant seem to alter it to use ID2D1Device3. Does anyone know of an example anywhere? Here is my core code:

Microsoft::WRL::ComPtr<ID2D1Device1> dev2d;
Microsoft::WRL::ComPtr<ID2D1DeviceContext3> devCon3;
Microsoft::WRL::ComPtr<ID3D11Device> dev;               // the actual Direct3D device
Microsoft::WRL::ComPtr<ID3D11DeviceContext> devCon;     // device context
Microsoft::WRL::ComPtr<IDXGIDevice> dxgiDevice;// to get the DXGI factory
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;// to get the DXGI factory
Microsoft::WRL::ComPtr<IDXGIFactory> dxgiFactory;// to get the DXGI factory
Microsoft::WRL::ComPtr<IDXGISwapChain> swapChain;       // the swap chain
    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 = (dev.Get()->QueryInterface(__uuidof(IDXGIDevice), &dxgiDevice));
    Hres = factory->CreateDevice(dxgiDevice.Get(), &dev2d);
    Hres = dev2d->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, &devCon3);

last line I get the error "C++ no instance of overloaded function matches the argument list" I cant figure out how to call this function with ID2D1Device3 . I've tried changing createdevice (previous line) to create a device3 pointer, but then that complains with same error.

OK thanks Chuck , I now have this which seem to work....we shall see

Microsoft::WRL::ComPtr<ID2D1Device3> dev3d; 
Hres = (D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, __uuidof(ID2D1Factory3), &options, &factory));
//obtain the ID2D1Device3 interface.
dev3d.Get()->QueryInterface(__uuidof(IDXGIDevice), &dxgiDevice);
D2D1_DEVICE_CONTEXT_OPTIONS       options;
Hres = factory->CreateDevice(dxgiDevice.Get(), &dev2d); 
dev3d->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, &devCon3);

CreateDevice call does not work due to mismatched arguments. Am I supposed to call it with ID2D1Device1 ?

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: 253

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41057

You need to first use QueryInterface() - or, since you are using Microsoft::WRL::ComPtr, just use the As operator - to obtain the ID2D1Device3 interface. It has a method:

STDMETHOD(CreateDeviceContext)(
    D2D1_DEVICE_CONTEXT_OPTIONS options,
    _COM_Outptr_ ID2D1DeviceContext3 **deviceContext3 
) PURE;  

You are currently using a ID2D1Device1 which doesn't have this method.

Upvotes: 2

Related Questions