/// <summary>
        ///     レンダーターゲットを初期化します.
        /// </summary>
        private void InitializeTargets()
        {
            {
                // Direct3D レンダーターゲットの作成
                var desc = new D3D.Texture2DDescription
                {
                    Width             = size.Width,
                    Height            = size.Height,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.B8G8R8A8_UNorm,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = D3D.ResourceUsage.Default,
                    BindFlags         = D3D.BindFlags.RenderTarget,
                    CpuAccessFlags    = D3D.CpuAccessFlags.None,
                    OptionFlags       = D3D.ResourceOptionFlags.GdiCompatible
                };
                d3dRenderTarget = new D3D.Texture2D(deviceManager.Device, desc);
            }
            {
                // レンダーターゲットビューの作成
                D3D.Texture2D target = D3DRenderTarget;
                var           desc   = new D3D.RenderTargetViewDescription
                {
                    Format    = target.Description.Format,
                    Dimension =
                        target.Description.SampleDescription.Count > 1
                            ? D3D.RenderTargetViewDimension.Texture2DMultisampled
                            : D3D.RenderTargetViewDimension.Texture2D,
                    MipSlice = 0
                };
                d3dRenderTargetView = new D3D.RenderTargetView(deviceManager.Device, target, desc);
            }
            // DXGIサーフェスの取得
            dxgiSurface = d3dRenderTarget.AsSurface();
            {
                // レンダーターゲットの作成
                var properties = new D2D.RenderTargetProperties
                {
                    Type                = D2D.RenderTargetType.Default,
                    PixelFormat         = new D2D.PixelFormat(dxgiSurface.Description.Format, D2D.AlphaMode.Premultiplied),
                    HorizontalDpi       = 0,
                    VerticalDpi         = 0,
                    Usage               = D2D.RenderTargetUsage.GdiCompatible,
                    MinimumFeatureLevel = D2D.FeatureLevel.Direct3D10
                };
                d2dRenderTarget           = D2D.RenderTarget.FromDXGI(deviceManager.D2DFactory, dxgiSurface, properties);
                d2dGdiInteropRenderTarget = new D2D.GdiInteropRenderTarget(d2dRenderTarget);
            }

            if (TargetsInitialized != null)
            {
                TargetsInitialized(this, new EventArgs());
            }
        }
Beispiel #2
0
        private void InitDepthStencil()
        {
            Dx11.Texture2DDescription depthBufferDesc = new Dx11.Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = Dx11.BindFlags.DepthStencil,
                Format            = Dxgi.Format.D32_Float,
                Width             = ClientSize.Width,
                Height            = ClientSize.Height,
                MipLevels         = 1,
                SampleDescription = new Dxgi.SampleDescription(1, 0)
            };

            using (Dx11.Texture2D depthBuffer = new Dx11.Texture2D(GraphicsDevice, depthBufferDesc))
            {
                DepthStencil = new Dx11.DepthStencilView(GraphicsDevice, depthBuffer);
            }
        }
        // Resizes the game and windows
        public void onResize(object sender, EventArgs args)
        {
            // Variables
            DX3D.Texture2DDescription	depth;

            dxg.swapChain.ResizeBuffers(1, game.window.widthi, game.window.heighti, DXGI.Format.R8G8B8A8_UNorm, DXGI.SwapChainFlags.None);
            using(DX3D.Resource resource= DX3D.Resource.FromSwapChain<DX3D.Texture2D>(dxg.swapChain, 0))
                dxg.renderTarget=	new DX3D.RenderTargetView(dxg.device, resource);
            depth=	new DX3D.Texture2DDescription();
            depth.Width=	game.window.widthi;
            depth.Height=	game.window.heighti;
            depth.MipLevels=	settings.mipMapLevels;
            depth.ArraySize=	1;
            depth.Format=	DXGI.Format.D24_UNorm_S8_UInt;
            depth.SampleDescription=	((settings.bEnable4XMsaa) ?
                new DXGI.SampleDescription(4, settings.msaa4x-1):
                new DXGI.SampleDescription(1, 0)
            );
            depth.Usage=	DX3D.ResourceUsage.Default;
            depth.BindFlags=	DX3D.BindFlags.DepthStencil;
            depth.CpuAccessFlags=	DX3D.CpuAccessFlags.None;
            depth.OptionFlags=	DX3D.ResourceOptionFlags.None;

            dxg.depthStencilBuffer=	new DX3D.Texture2D(dxg.device, depth);
            dxg.depthStencilView=	new DX3D.DepthStencilView(dxg.device, dxg.depthStencilBuffer);
            dxg.im.OutputMerger.SetTargets(dxg.depthStencilView, dxg.renderTarget);
            dxg.viewport=	new DX3D.Viewport(0, 0, game.window.widthi, game.window.heighti, 0f, 1f);
            dxg.im.Rasterizer.SetViewports(dxg.viewport);

            //if(camera!= null)
            //	camera.resetProjection();
        }