コード例 #1
0
        public void ReleaseWindowSizeDependentResources()
        {
            D2D1Utils.DisposeAndNull(ref this.bitmap);
            D2D1Utils.DisposeAndNull(ref this.bitmapBrush);

            D2D1Utils.DisposeAndNull(ref this.textBrush);
            DWriteUtils.DisposeAndNull(ref this.textLayout);
        }
コード例 #2
0
 public void ReleaseDeviceDependentResources()
 {
     D2D1Utils.DisposeAndNull(ref this.stateBlock);
     DWriteUtils.DisposeAndNull(ref this.textFormat);
 }
コード例 #3
0
        private void CreateWindowSizeDependentResources()
        {
            this.d3dContext.OutputMergerSetRenderTargets(new D3D11RenderTargetView[] { null }, null);

            D3D11Utils.DisposeAndNull(ref this.backBuffer);
            D3D11Utils.DisposeAndNull(ref this.offscreenBuffer);
            D3D11Utils.DisposeAndNull(ref this.d3dRenderTargetView);
            D3D11Utils.DisposeAndNull(ref this.d3dDepthStencilView);
            D2D1Utils.DisposeAndNull(ref this.d2dRenderTarget);

            this.d3dContext.Flush();

            var createdBackBuffer = this.OnCreateBackBuffer();

            if (createdBackBuffer == null)
            {
                return;
            }

            this.backBuffer = createdBackBuffer;

            var backBufferDesc = this.backBuffer.Description;

            this.backBufferWidth  = backBufferDesc.Width;
            this.backBufferHeight = backBufferDesc.Height;

            if (this.d3dSampleDesc.Count > 1)
            {
                D3D11Texture2DDesc desc = new D3D11Texture2DDesc(
                    DxgiFormat.B8G8R8A8UNorm,
                    this.backBufferWidth,
                    this.backBufferHeight,
                    1,
                    1,
                    D3D11BindOptions.RenderTarget,
                    D3D11Usage.Default,
                    D3D11CpuAccessOptions.None,
                    this.d3dSampleDesc.Count,
                    this.d3dSampleDesc.Quality,
                    D3D11ResourceMiscOptions.None);

                this.offscreenBuffer = this.D3DDevice.CreateTexture2D(desc);
            }

            if (this.d3dSampleDesc.Count > 1)
            {
                D3D11RenderTargetViewDesc renderTargetViewDesc = new D3D11RenderTargetViewDesc(D3D11RtvDimension.Texture2DMs);

                this.d3dRenderTargetView = this.d3dDevice.CreateRenderTargetView(this.offscreenBuffer, renderTargetViewDesc);
            }
            else
            {
                D3D11RenderTargetViewDesc renderTargetViewDesc = new D3D11RenderTargetViewDesc(D3D11RtvDimension.Texture2D);

                this.d3dRenderTargetView = this.d3dDevice.CreateRenderTargetView(this.backBuffer, renderTargetViewDesc);
            }

            D3D11Texture2DDesc depthStencilDesc = new D3D11Texture2DDesc
            {
                Width            = this.backBufferWidth,
                Height           = this.backBufferHeight,
                MipLevels        = 1,
                ArraySize        = 1,
                Format           = DxgiFormat.D24UNormS8UInt,
                SampleDesc       = this.d3dSampleDesc,
                Usage            = D3D11Usage.Default,
                BindOptions      = D3D11BindOptions.DepthStencil,
                CpuAccessOptions = D3D11CpuAccessOptions.None,
                MiscOptions      = D3D11ResourceMiscOptions.None
            };

            using (var depthStencil = this.d3dDevice.CreateTexture2D(depthStencilDesc))
            {
                D3D11DepthStencilViewDesc depthStencilViewDesc = new D3D11DepthStencilViewDesc(this.d3dSampleDesc.Count > 1 ? D3D11DsvDimension.Texture2DMs : D3D11DsvDimension.Texture2D);

                this.d3dDepthStencilView = this.d3dDevice.CreateDepthStencilView(depthStencil, depthStencilViewDesc);
            }

            this.screenViewport = new D3D11Viewport
            {
                TopLeftX = 0,
                TopLeftY = 0,
                Width    = this.backBufferWidth,
                Height   = this.backBufferHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f
            };

            this.d3dContext.RasterizerStageSetViewports(new[] { this.screenViewport });

            using (var surface = new DxgiSurface2(this.d3dSampleDesc.Count > 1 ? this.offscreenBuffer.Handle : this.backBuffer.Handle))
            {
                float dpiX;
                float dpiY;
                this.d2dFactory.GetDesktopDpi(out dpiX, out dpiY);

                var properties = new D2D1RenderTargetProperties(
                    D2D1RenderTargetType.Default,
                    new D2D1PixelFormat(DxgiFormat.B8G8R8A8UNorm, D2D1AlphaMode.Premultiplied),
                    dpiX,
                    dpiY,
                    D2D1RenderTargetUsages.None,
                    D2D1FeatureLevel.Default);

                this.d2dRenderTarget = this.d2dFactory.CreateDxgiSurfaceRenderTarget(surface, properties);
            }

            this.d2dRenderTarget.AntialiasMode     = D2D1AntialiasMode.PerPrimitive;
            this.d2dRenderTarget.TextAntialiasMode = D2D1TextAntialiasMode.Grayscale;

            D3D11RasterizerDesc rasterizerStateDesc = new D3D11RasterizerDesc(D3D11FillMode.Solid, D3D11CullMode.Back, false, 0, 0.0f, 0.0f, true, false, true, false);

            using (var rasterizerState = this.d3dDevice.CreateRasterizerState(rasterizerStateDesc))
            {
                this.d3dContext.RasterizerStageSetState(rasterizerState);
            }
        }