Hi all.
I have a direct2d1 application with all my UI. And now i'm trying to insert 3d rendering in my UI. I tried a lot of thing as i'm new to that. and failed....
So my UI contain a control that is a 3d render. so stupidly i was thinking of making a 3d rendertarget, get the bitmap of that. and draw it at the place of my control.
So i created this function
public Bitmap1 CreateTarget(int i_Width, int i_Height)
{
Texture2DDescription l_Description = new Texture2DDescription();
l_Description.BindFlags = BindFlags.RenderTarget;
l_Description.Format = m_BackBuffer.Description.Format;
l_Description.Width = i_Width;
l_Description.Height = i_Height;
l_Description.Usage = ResourceUsage.Default;
l_Description.ArraySize = 1;
l_Description.MipLevels = 1;
l_Description.SampleDescription = new SampleDescription(1, 0);
l_Description.CpuAccessFlags = CpuAccessFlags.None;
l_Description.OptionFlags = ResourceOptionFlags.None;
Texture2D l_RenderTarget = new Texture2D(m_Device, l_Description);
BitmapProperties1 properties = new BitmapProperties1()
{
PixelFormat = new PixelFormat(l_Description.Format, SharpDX.Direct2D1.AlphaMode.Premultiplied),
BitmapOptions = BitmapOptions.Target,
DpiX=96,
DpiY = 96
};
Bitmap1 m_OffscreenBitmap;
using (Surface l_Surface = l_RenderTarget.QueryInterface<Surface>())
{
m_OffscreenBitmap = new Bitmap1(m_2DContext, l_Surface, properties);
}
return m_OffscreenBitmap;
}
And my control does a simple :
if (m_OldSize != Size)
{
m_OldSize = Size;
if (m_OffscreenBitmap != null)
{
m_OffscreenBitmap.Dispose();
}
m_OffscreenBitmap = i_Param.CurrentWindow.CreateTarget(Size.Width, Size.Height);
}
i_Context.DrawContext2D.DrawBitmap(m_OffscreenBitmap, m_Rect, 1.0f, BitmapInterpolationMode.Linear);
Here is my problem, if BitmapOptions is different from BitmapOptions = BitmapOptions.Target | BitmapOptions.CannotDraw
i crash when creating my new Bitmap1 because of invalid params.
and if i let it, i crash at present because :
Additional information: HRESULT: [0x88990021], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_BITMAP_CANNOT_DRAW/BitmapCannotDraw], Message: Impossible de dessiner avec une bitmap qui a l’option D2D1_BITMAP_OPTIONS_CANNOT_DRAW.
I must admit i'm out of idea. and i'm stuck. Please help.
Does my method is totally wrong ?
I tried to make my control owning is own 3d device so i can render that at a different pace than the 2d and did get the same result
↧