调整大小时,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图像方法将后缓冲区绘制到D3DImage。
public void InvalidateD3DImage()
{
if (this.mRenderTarget != null)
{
base.Lock();
base.AddDirtyRect(new Int32Rect(0, 0, base.PixelWidth, base.PixelHeight));
base.Unlock();
}
}
有什么办法可以避免这种闪烁?它对功能没有任何影响,但是仍然不太好看。