XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

How to use D2D with D3D11?

Last post 9/20/2009 7:28 AM by daVinci. 2 replies.
  • 9/19/2009 9:21 AM

    How to use D2D with D3D11?

    I write something like the following

    // Use the texture to obtain a DXGI surface.
    IDXGISurface *pDxgiSurface = NULL;
    renderTarget->QueryInterface(&pDxgiSurface);
    if (pDxgiSurface == NULL) return NULL;

    // Create a D2D render target which can draw into.
    D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
    D2D1_RENDER_TARGET_TYPE_DEFAULT,
    D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), 96,96);
    HRESULT result = GetDirect2DFactory()->CreateDxgiSurfaceRenderTarget(pDxgiSurface, &props, &renderTargetDirect2D);

    I got E_NOINTERFACE in result. It must be D2D integrates with D3D10.1 only.
    How with minimal efforts we can render using D2D to D3D11 surface?
  • 9/19/2009 8:04 PM In reply to

    Re: How to use D2D with D3D11?

    One thing that could be a problem here is the "To work with Direct2D, the Direct3D device that provides the IDXGISurface must be created with the D3D10_CREATE_DEVICE_BGRA_SUPPORT flag." (from ID2D1Factory::CreateDxgiSurfaceRenderTarget Overloaded Method) requirement (E_NOINTERFACE seems to be a weird error in that case, though). Of what type if renderTarget?

    Side note: from the looks of it DXGI surfaces seem to be (more or less) D3D version agnostic so it shouldn't matter if it's D3D10.1 or 11 (D2D needs access to the surface bits only which the IDXGISurface interface provides).
    We are boki. The rest is known.

    The not so known part of the rest: It is Björn or Bjoern, but never Bjorn.

    Twitter ~ Bnoerj ~ SharpSteer ~ SgtConker.com
  • 9/20/2009 7:28 AM In reply to

    Re: How to use D2D with D3D11?

    Bjoern Graf:
    One thing that could be a problem here is the "To work with Direct2D, the Direct3D device that provides the IDXGISurface must be created with the D3D10_CREATE_DEVICE_BGRA_SUPPORT flag." (from ID2D1Factory::CreateDxgiSurfaceRenderTarget Overloaded Method) requirement (E_NOINTERFACE seems to be a weird error in that case, though). Of what type if renderTarget?

    Side note: from the looks of it DXGI surfaces seem to be (more or less) D3D version agnostic so it shouldn't matter if it's D3D10.1 or 11 (D2D needs access to the surface bits only which the IDXGISurface interface provides).


    The D3D11 device was created with flag D3D11_CREATE_DEVICE_BGRA_SUPPORT.
    The render target:

    D3D11_TEXTURE2D_DESC desc;
    ZeroMemory(&desc, sizeof(desc));
    desc.Width = width;
    desc.Height = height;
    desc.MipLevels = 1;
    desc.ArraySize = 1;
    desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    desc.SampleDesc.Count = 1;
    desc.Usage = D3D11_USAGE_DEFAULT;
    desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
    desc.MiscFlags = 0;

    Do you have working sample D3D11+D2D?
Page 1 of 1 (3 items) Previous Next