Exemple #1
0
        DXGI.SwapChain1 IDirect3DWindow.CreateSwapChain(D3D11.Device1 device, ref DXGI.SwapChainDescription1 description)
        {
            var dxgiDevice = device.QueryInterface<DXGI.Device1>();
            var dxgiAdapter = dxgiDevice.Adapter;

            var dxgiFactory = dxgiAdapter.GetParent<DXGI.Factory2>();

            return dxgiFactory.CreateSwapChainForHwnd(dxgiDevice, _form.Handle, ref description, null, null);
        }
Exemple #2
0
        DXGI.SwapChain1 IDirect3DWindow.CreateSwapChain(D3D11.Device1 device, ref DXGI.SwapChainDescription1 description)
        {
            var dxgiDevice = device.QueryInterface<DXGI.Device1>();
            var dxgiAdapter = dxgiDevice.Adapter;

            var dxgiFactory = dxgiAdapter.GetParent<DXGI.Factory2>();

            var coWindow = new SharpDX.ComObject(_coreWindow);
            return dxgiFactory.CreateSwapChainForCoreWindow(dxgiDevice, coWindow, ref description, null);
        }
 void SetTextureInner(D3D11.ShaderResourceView texture)
 {
     if (texture != currentTexture)
     {
         currentTexture = texture;
         deviceContext.PixelShader.SetShaderResource(0, texture);
     }
 }
 public static D3D.DepthStencilState CreateDepthStencilState(this D3D.Device device, D3D.Comparison comparison, D3D.StencilOperation failOperation, D3D.StencilOperation passOperation)
 {
     var operationDesc = new D3D.DepthStencilOperationDescription()
     {
         Comparison = comparison,
         DepthFailOperation = D3D.StencilOperation.Keep,
         FailOperation = failOperation,
         PassOperation = passOperation,
     };
     var depthStencilDesc = new D3D.DepthStencilStateDescription()
     {
         IsDepthEnabled = false,
         IsStencilEnabled = true,
         StencilReadMask = byte.MaxValue,
         StencilWriteMask = byte.MaxValue,
         FrontFace = operationDesc,
         BackFace = operationDesc,
     };
     return new D3D.DepthStencilState(device, depthStencilDesc);
 }
        public static D3D.Buffer CreateDynamicBuffer(this D3D.Device device, int sizeInBytes, D3D.BindFlags bindFlags)
        {
            var desc = new D3D.BufferDescription((int)System.Math.Ceiling(sizeInBytes / 16f) * 16,
                D3D.ResourceUsage.Dynamic,
                bindFlags,
                D3D.CpuAccessFlags.Write,
                D3D.ResourceOptionFlags.None,
                0);

            return new D3D.Buffer(device, desc);
        }
        public static D3D.Texture2D CreateDepthStencilBuffer(this D3D.Device device, int width, int height, DXGI.SampleDescription sampleDescription, out D3D.DepthStencilView view)
        {
            var desc = new D3D.Texture2DDescription
            {
                Width = width,
                Height = height,
                MipLevels = 1,
                ArraySize = 1,
                Format = DXGI.Format.D24_UNorm_S8_UInt,
                SampleDescription = sampleDescription,
                Usage = D3D.ResourceUsage.Default,
                BindFlags = D3D.BindFlags.DepthStencil,
                CpuAccessFlags = D3D.CpuAccessFlags.None,
                OptionFlags = D3D.ResourceOptionFlags.None,
            };
            var depthStencilBuffer = new D3D.Texture2D(device, desc);

            view = new D3D.DepthStencilView(device, depthStencilBuffer);
            return depthStencilBuffer;
        }
        public static D3D.Texture2D CreateSurface(this D3D.Device device, int width, int height, DXGI.SampleDescription sampleDescription, out D3D.RenderTargetView renderTarget)
        {
            var desc = new D3D.Texture2DDescription
            {
                Width = width,
                Height = height,
                MipLevels = 1,
                ArraySize = 1,
                Format = DXGI.Format.R8G8B8A8_UNorm,
                SampleDescription = sampleDescription,
                Usage = D3D.ResourceUsage.Default,
                BindFlags = D3D.BindFlags.RenderTarget | D3D.BindFlags.ShaderResource,
                CpuAccessFlags = D3D.CpuAccessFlags.None,
                OptionFlags = D3D.ResourceOptionFlags.Shared,
            };
            var surface = new D3D.Texture2D(device, desc);

            var targetDesc = new D3D.RenderTargetViewDescription
            {
                Format = desc.Format,
                Dimension = desc.SampleDescription.Count == 1
                        ? D3D.RenderTargetViewDimension.Texture2D
                        : D3D.RenderTargetViewDimension.Texture2DMultisampled,
            };
            renderTarget = new D3D.RenderTargetView(device, surface, targetDesc);

            return surface;
        }