Asked by:
D3D on an ID2D1Bitmap

Question
-
I have seen plenty of sample that show how to share an ID3D11Texture2D with D2D.
Now I want to do the opposite. I have a D2D bitmap (ID2D1Bitmap) and I would like to write some code that help me make it a D3D render target. I.e. how to create a ID3D11RenderTargetView that will draw on the ID2D1Bitmap
Tuesday, February 5, 2013 3:52 PM
All replies
-
Hi,
Please follow these codes.
DX::ThrowIfFailed( m_d3dDevice->CreateTexture2D( &textureDesc, nullptr, &m_texture ) ); CD3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc( m_texture.Get(), D3D11_SRV_DIMENSION_TEXTURE2D ); DX::ThrowIfFailed( m_d3dDevice->CreateShaderResourceView( m_texture.Get(), &shaderResourceViewDesc, &m_textureShaderResourceView ) ); // Use D2D to attach to and draw some text to the cube texture. Note that the cube // texture is DPI-independent, so when drawing content to it using D2D, a fixed DPI // value should be used. const float dxgiDpi = 96.0f; m_d2dContext->SetDpi(dxgiDpi, dxgiDpi); D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1( D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), dxgiDpi, dxgiDpi ); ComPtr<ID2D1Bitmap1> cubeTextureTarget; ComPtr<IDXGISurface> cubeTextureSurface; DX::ThrowIfFailed( m_texture.As(&cubeTextureSurface) ); DX::ThrowIfFailed( m_d2dContext->CreateBitmapFromDxgiSurface( cubeTextureSurface.Get(), &bitmapProperties, &cubeTextureTarget ) ); m_d2dContext->SetTarget(cubeTextureTarget.Get());
And this sample code
Direct3D-Direct2D interop sample
http://code.msdn.microsoft.com/windowsapps/Direct2D-Direct3D-Interop-ee641e46Best regards,
JesseJesse Jiang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Wednesday, February 6, 2013 10:08 AMModerator -
Hi Jess, unless I misunderstand you or your sample, it's not quite what I want!
Although I should admit I didn't express my problem very well in the first place.... :/
Here is a better question:
I instantiated an ID2D1Bitmap that I use to do some D2D drawing.
Now at some stage I'd like to draw a D3D scene on that particular ID2D1Bitmap, i.e. I'd like to do:
ID3D11DeviceContext1* d3dctxt;
ID2D1Bitmap* d2dimaged3dctxt->SetTarget(d2dimage)
or something roughly equivalent!!
or maybe this is not possible and I would settle for the followin (which I bet is possible, I just don't know how)
ID3D11Texture2D* renderTarget
ID2D1Bitmap* d2dimagerenderTarget->CopyTo(d2dimage)
Thanks! :)
Wednesday, February 6, 2013 10:38 AM -
Hi Lloyd - I am researching this and will get back with you if it's possible.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Monday, February 11, 2013 8:22 PMModerator -
Hi Matt,
Just in case you ask for code, take a look at: http://directwinrt.codeplex.com/
And at Sample_D2D project.
I create a (D2D) Image brush in it. Maybe I want to create with a Texture2D rather than a bitmap file.
In fact, to make it simple, you can also create a Texture2D with a file! (LoadFile)
Tuesday, February 12, 2013 4:17 AM