コード例 #1
0
        internal void Resize()
        {
            // 等到以前的所有 GPU 工作完成。
            device.WaitForGpu();

            // 清除特定于先前窗口大小的内容。
            for (int n = 0; n < c_frameCount; n++)
            {
                m_renderTargets[n]?.Dispose();
                m_renderTargets[n]            = null;
                renderTargetResourceStates[n] = ResourceStates.Common;
            }

            if (m_swapChain != null)
            {
                // 如果交换链已存在,请调整其大小。
                Result hr = m_swapChain.ResizeBuffers(c_frameCount, this.width, this.height, format, SwapChainFlags.AllowTearing);

                ThrowIfFailed(hr);
            }
            else
            {
                // 否则,使用与现有 Direct3D 设备相同的适配器新建一个。
                SwapChainDescription1 swapChainDescription1 = new SwapChainDescription1();

                swapChainDescription1.Width  = this.width;                     // 匹配窗口的大小。
                swapChainDescription1.Height = this.height;
                swapChainDescription1.Format = format;
                swapChainDescription1.Stereo = false;
                swapChainDescription1.SampleDescription.Count   = 1;                       // 请不要使用多采样。
                swapChainDescription1.SampleDescription.Quality = 0;
                swapChainDescription1.BufferUsage = Usage.RenderTargetOutput;
                swapChainDescription1.BufferCount = c_frameCount;                   // 使用三重缓冲最大程度地减小延迟。
                swapChainDescription1.SwapEffect  = SwapEffect.FlipSequential;
                swapChainDescription1.Flags       = SwapChainFlags.AllowTearing;
                swapChainDescription1.Scaling     = Scaling.Stretch;
                swapChainDescription1.AlphaMode   = AlphaMode.Ignore;

                var swapChain = device.m_dxgiFactory.CreateSwapChainForHwnd(device.commandQueue, hwnd, swapChainDescription1);
                m_swapChain?.Dispose();
                m_swapChain = swapChain.QueryInterface <IDXGISwapChain3>();
                swapChain.Dispose();
            }

            for (int n = 0; n < c_frameCount; n++)
            {
                ThrowIfFailed(m_swapChain.GetBuffer(n, out m_renderTargets[n]));
            }
        }
コード例 #2
0
ファイル: GraphicsDevice.cs プロジェクト: sselecirPyM/RTUGame
 public void Dispose()
 {
     WaitForGpu();
     while (delayDestroy.Count > 0)
     {
         var p = delayDestroy.Dequeue();
         p.pipelineState?.Dispose();
         p.resource?.Dispose();
     }
     foreach (var commandAllocator in commandAllocators)
     {
         commandAllocator.Dispose();
     }
     if (screenResources != null)
     {
         foreach (var screenResource in screenResources)
         {
             screenResource.Dispose();
         }
     }
     dxgiFactory?.Dispose();
     commandQueue?.Dispose();
     cbvsrvuavHeap?.Dispose();
     dsvHeap?.Dispose();
     rtvHeap?.Dispose();
     swapChain?.Dispose();
     fence?.Dispose();
     device?.Dispose();
     adapter?.Dispose();
 }