我对“SwapChain.ResizeBuffers(...)”方法有疑问,每当我调用它时都会出错...基本上,我想要做的是:我希望能够更改渲染分辨率所以当我改变了_RenderingWidth和_RenderingHeight的值时,我调用了这个方法(如下)......
protected override void UpdateResolution()
{
if (_RenderTargetView != null) _RenderTargetView.Dispose();
if (_BackBuffer != null) _BackBuffer.Dispose();
_Device.OutputMerger.SetTargets((RenderTargetView) null);
_SwapChain.ResizeBuffers(_SwapChain.Description.BufferCount, _RenderingWidth, _RenderingHeight, _SwapChain.Description.ModeDescription.Format, _SwapChain.Description.Flags);
_BackBuffer = Texture2D.FromSwapChain<Texture2D>(_SwapChain, 0);
_RenderTargetView = new RenderTargetView(_Device, _BackBuffer);
_Device.OutputMerger.SetTargets(_RenderTargetView);
}
它给我的唯一信息是:
An unhandled exception of type 'SlimDX.DXGI.DXGIException' occurred in SlimDX.dll
Additional information: DXGI_ERROR_INVALID_CALL: The application has made an erroneous API call that it had enough information to avoid. This error is intended to denote that the application should be altered to avoid the error.
我的声明:
protected SlimDX.Direct3D10_1.Device1 _Device = null;
protected SwapChain _SwapChain = null;
protected Texture2D _BackBuffer = null;
protected RenderTargetView _RenderTargetView = null;
[编辑] 我想通了:
var description = _SwapChain.Description;
if (_RenderTargetView != null) _RenderTargetView.Dispose();
if (_BackBuffer != null) _BackBuffer.Dispose();
_SwapChain.Dispose();
description.ModeDescription = new ModeDescription(_RenderingWidth, _RenderingHeight, new Rational(160, 1), Format.B8G8R8A8_UNorm);
_SwapChain = new SwapChain(_Factory_DXGI, _Device, description);
_BackBuffer = Texture2D.FromSwapChain<Texture2D>(_SwapChain, 0);
_RenderTargetView = new RenderTargetView(_Device, _BackBuffer);
_Device.OutputMerger.SetTargets(_RenderTargetView);
重新启动一切......不知道为什么我以前没有想到这个!