D3D11纹理上的Direct2D绘制不融合

时间:2019-09-04 07:24:50

标签: directx direct3d direct2d

我有一个与Direct3D互操作的Direct2D。

我的Direct2D可以很好地渲染为Direct3d纹理。然后,我尝试在Direct3D场景的顶部渲染该纹理,但是当我渲染该纹理时,它显示得很好,但其余部分用黑色覆盖,而不是混合

D2D1_BITMAP_PROPERTIES1 properties = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1::PixelFormat(
        DXGI_FORMAT_B8G8R8A8_UNORM,
        D2D1_ALPHA_MODE_PREMULTIPLIED
    )
);

pd2dDeviceCtx->CreateBitmapFromDxgiSurface(surface.Get(), &properties, &p2dBitmap);

pd2dDeviceCtx->SetTarget(p2dBitmap.Get());

// BlendState
D3D11_BLEND_DESC blendStateDescription = {};
blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f;
pDevice->CreateBlendState(&blendStateDescription, &blendState);

pContext->OMSetBlendState(blendState.Get(), NULL, sampleMask);

//D3D draws....
pd3dContext->DrawIndexed(6, 0, 0);
//D2D draws
pd2dDeviceCtx->BeginDraw();
pd2dDeviceCtx->Clear(D2D1::ColorF(0, 0, 0, 0));
// .. more D2D draws
pd2dDeviceCtx->EndDraw();

// ... Draw texture that d2d used to direct3d
pContext->VSSetShader(vertextShader.Get(), nullptr, 0);
pContext->PSSetShader(pixelShader.Get(), nullptr, 0);

pContext->PSSetShaderResources(0, 1, d2dTextShaderResource.GetAddressOf());
pContext->PSSetSamplers(0, 1, samplers.GetAddressOf());

pContext->DrawIndexed(6, 0, 0);

我的纹理可以正确渲染,但是在应该透明的地方,所有黑色都隐藏了以前的纹理。

0 个答案:

没有答案
相关问题