void D3DApp::OnResize()
{
assert(md3dImmediateContext);
assert(md3dDevice);
assert(mSwapChain);
// Release the old views, as they hold references to the buffers we
// will be destroying. Also release the old depth/stencil buffer.
ReleaseCOM(mRenderTargetView);
ReleaseCOM(mDepthStencilView);
ReleaseCOM(mDepthStencilBuffer);
// Resize the swap chain and recreate the render target view.
HR(mSwapChain->ResizeBuffers(1, mClientWidth, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
ID3D11Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCOM(backBuffer);
我在理解这段代码究竟是做什么方面有点麻烦。我认为它是将当前的后台缓冲区存储在内存中,然后再将其渲染到屏幕上?得到的缓冲区内容可能是什么?我很迷茫。我的程序使用800 x 600像素的窗口。
答案 0 :(得分:0)
当函数名称指出时,它只是重置backbuffer和rendertarget,每当调整渲染窗口的大小时都应调用此函数。
HR(mSwapChain->ResizeBuffers(1, mClientWidth, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
在DirectX应用程序中,我们总是将后备缓冲区大小设置为与窗口大小相同,因此当窗口大小发生变化时,我们应该相应地更新后备缓冲区大小,否则您的场景将被拉伸。
ID3D11Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCOM(backBuffer);
渲染目标基于后备缓冲区,后备缓冲区又应该更新。