Reputation: 21
I have an issue with D3DImage when resizing.
First I had the flickering when I had a high amount of frames per second too but I could resolve it by only setting the back buffer when I am creating a new texture to render to (which I have to when resizing)
The problem is caused when I set the back buffer right after InvalidateD3DImage which of course happens in resize due to many frames send in a short time.
May SetRenderTarget method which sets the backbuffer:
public void SetRenderTargetDx11(Texture2D target)
{
if (this.mRenderTarget != null)
{
DisposeHelper.TryDispose(ref this.mRenderTarget);
base.Lock();
base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
base.Unlock();
}
if (target == null)
return;
if (!IsShareable(target))
throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared");
var format = TranslateFormat(target);
if (format == Format.Unknown)
throw new ArgumentException("Texture format is not compatible with OpenSharedResource");
var handle = GetSharedHandle(target);
if (handle == IntPtr.Zero)
throw new ArgumentNullException("Handle");
try
{
this.mRenderTarget = new Texture(mDevice, target.Description.Width, target.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle);
using (Surface surface = this.mRenderTarget.GetSurfaceLevel(0))
{
base.Lock();
// "enableSoftwareFallback = true" makes Remote Desktop possible.
// See: http://msdn.microsoft.com/en-us/library/hh140978%28v=vs.110%29.aspx
base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer, true);
base.Unlock();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
My Invalidate image method to draw the backbuffer to the D3DImage.
public void InvalidateD3DImage()
{
if (this.mRenderTarget != null)
{
base.Lock();
base.AddDirtyRect(new Int32Rect(0, 0, base.PixelWidth, base.PixelHeight));
base.Unlock();
}
}
Is there any way to avoid this flickering? It doesn't have any effect to the functionality but it is still not great to see.
Upvotes: 2
Views: 205