调整大小时,我遇到了 D3DImage 的问题。
首先,当我每秒也有大量帧时,我也会出现闪烁,但我可以通过仅在创建要渲染到的新纹理时设置后台缓冲区来解决它(调整大小时我必须这样做)
问题是当我在 InvalidateD3DImage 之后立即设置后台缓冲区时引起的,这当然会在调整大小时发生,因为在短时间内发送了许多帧。
可以设置后台缓冲区的 SetRenderTarget 方法:
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);
}
}
我的 Invalidate image 方法将后台缓冲区绘制到 D3DImage。
public void InvalidateD3DImage()
{
if (this.mRenderTarget != null)
{
base.Lock();
base.AddDirtyRect(new Int32Rect(0, 0, base.PixelWidth, base.PixelHeight));
base.Unlock();
}
}
有什么办法可以避免这种闪烁?它对功能没有任何影响,但仍然不是很好看。