Hello.
At last I setup my D2D render target for drawing directly to backbuffer.
I did it like this:
private void Initialize()
{
var device = (SharpDX.Direct3D11.Device)_graphicsDevice;
using (var dxgiDevice = device.QueryInterface<SharpDX.DXGI.Device>())
{
DeviceCreationFlags flags = new DeviceCreationFlags();
d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(dxgiDevice, new CreationProperties() { DebugLevel = DebugLevel.Information }));
d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, DeviceContextOptions.None));
}
_directWriteFactory = ToDispose(new SharpDX.DirectWrite.Factory1());
textBrush = new SolidColorBrush(d2dContext, Color4.White);
textFormat = new TextFormat(_directWriteFactory, "Cambria", 24.0f)
{
FlowDirection = FlowDirection.TopToBottom,
ParagraphAlignment = ParagraphAlignment.Center,
TextAlignment = TextAlignment.Center,
WordWrapping = WordWrapping.WholeWord
};
var parameters = new PresentationParameters((int)swapchainPanel.ActualWidth, (int)swapchainPanel.ActualHeight, swapchainPanel);
_presenter = ToDispose(new SwapChainGraphicsPresenter(_graphicsDevice, parameters));
_graphicsDevice.Presenter = _presenter;
CreateD2DRenderTarget();
}
private void CreateD2DRenderTarget()
{
var renderTarget = _presenter.BackBuffer;
var dpi = DisplayProperties.LogicalDpi;
// 1. Use same format as the underlying render target with premultiplied alpha mode
// 2. Use correct DPI
// 3. Deny drawing direct calls and specify that this is a render target.
var bitmapProperties = new BitmapProperties1(new SharpDX.Direct2D1.PixelFormat(renderTarget.Format, SharpDX.Direct2D1.AlphaMode.Premultiplied),
dpi,
dpi,
BitmapOptions.CannotDraw | BitmapOptions.Target);
// create the bitmap render target and assign it to the device context
d2dTarget = ToDispose(new Bitmap1(d2dContext, renderTarget, bitmapProperties));
d2dContext.Target = d2dTarget;
}
But now I want to render NOT not backbuffer, but to texture, so I tried to change render target from _presenter.BackBuffer to my loaded texture2d, but when It runs, framework says:
D2D DEBUG ERROR - The bitmap options [0x5] must be a subset of the flags associated with the DXGI surface.
What I am missing here and what I need to do to draw text or whatever d2d content to a texture (2d or other) to apply it after that to the object, for example?
Does someone alredy did this before in sharpDX?