0
            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 像素的窗口。

4

1 回答 1

0

正如函数名所指出的,它只是重置后备缓冲区和渲染目标,并且每当调整渲染窗口大小时都应该调用此函数。

HR(mSwapChain->ResizeBuffers(1, mClientWidth, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));

在 DirectX 应用程序中,我们总是将 backbuffer 大小设置为与窗口大小相同,因此当窗口大小发生变化时,我们应该相应地更新 backbuffer 大小,否则您的场景将被拉伸。

ID3D11Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCOM(backBuffer);

渲染目标基于应该更新的后备缓冲区。

于 2013-08-05T08:13:27.017 回答