コード例 #1
0
        public virtual void Initialize(SharpDX.Direct3D11.Device3 device)
        {
            lock (lockObject)
            {
                // Startup MediaManager
                MediaManager.Startup(useLightVersion: true);

                d3dDevice = device;

                // Setup multithread on the Direct3D11 device
                var multithread = d3dDevice.QueryInterface <SharpDX.Direct3D.DeviceMultithread>();
                multithread.SetMultithreadProtected(true);

                // Create a DXGI Device Manager
                dxgiDeviceManager = new DXGIDeviceManager();
                dxgiDeviceManager.ResetDevice(d3dDevice);

                // Setup Media Engine attributes
                var attributes = new MediaEngineAttributes
                {
                    DxgiManager       = dxgiDeviceManager,
                    VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm
                };

                using (var factory = new MediaEngineClassFactory())
                    mediaEngine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.None, OnMediaEngineEvent);
                mediaEngineEx = mediaEngine.QueryInterface <MediaEngineEx>();
            }
        }
コード例 #2
0
    public TextureMaskRenderer(Device device, ShaderCache shaderCache)
    {
        this.device = device.QueryInterface <Device3>();

        var features = this.device.CheckD3D113Features2();

        var vertexShaderAndBytecode = shaderCache.GetVertexShader <TextureMaskRenderer>("texturing/processing/TextureMask");

        inputLayout  = new InputLayout(device, vertexShaderAndBytecode.Bytecode, MeshBuffers.InputElements);
        vertexShader = vertexShaderAndBytecode;

        var rasterizerStateDesc = new RasterizerStateDescription2()
        {
            FillMode = FillMode.Solid,
            CullMode = CullMode.None,
            IsFrontCounterClockwise = false,
            DepthBias                     = 0,
            SlopeScaledDepthBias          = 0.0f,
            DepthBiasClamp                = 0.0f,
            IsDepthClipEnabled            = true,
            IsScissorEnabled              = false,
            IsMultisampleEnabled          = true,
            IsAntialiasedLineEnabled      = false,
            ConservativeRasterizationMode = ConservativeRasterizationMode.On
        };

        rasterizerState = new RasterizerState2(this.device, rasterizerStateDesc);

        pixelShader = shaderCache.GetPixelShader <TextureMaskRenderer>("texturing/processing/TextureMask");

        var blendStateDesc = BlendStateDescription.Default();

        blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Alpha;
        blendState = new BlendState(device, blendStateDesc);
    }
コード例 #3
0
        /// <summary>
        /// Unloads all resources.
        /// </summary>
        public void UnloadResources()
        {
            m_immediateContext  = CommonTools.DisposeObject(m_immediateContext);
            m_immediateContext3 = CommonTools.DisposeObject(m_immediateContext3);
            m_device1           = CommonTools.DisposeObject(m_device1);
            m_device3           = CommonTools.DisposeObject(m_device3);

            m_creationFlags = D3D11.DeviceCreationFlags.None;
            m_featureLevel  = D3D.FeatureLevel.Level_11_0;
        }
コード例 #4
0
ファイル: Texture2D1.cs プロジェクト: JoeErickson/SharpDX
        /// <summary>
        ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture2D1" /> class.
        /// </summary>
        /// <param name = "device">The device with which to associate the texture.</param>
        /// <param name = "description">The description of the texture.</param>
        /// <param name = "data">An array of initial texture data for each subresource.</param>
        /// <msdn-id>ff476521</msdn-id>	
        /// <unmanaged>HRESULT ID3D11Device3::CreateTexture2D1([In] const D3D11_TEXTURE2D_DESC1* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D1** ppTexture2D)</unmanaged>	
        /// <unmanaged-short>ID3D11Device3::CreateTexture2D1</unmanaged-short>	
        public Texture2D1(Device3 device, Texture2DDescription1 description, params DataRectangle[] data)
            : base(IntPtr.Zero)
        {
            DataBox[] subResourceDatas = null;

            if (data != null && data.Length > 0)
            {
                subResourceDatas = new DataBox[data.Length];
                for (int i = 0; i < subResourceDatas.Length; i++)
                {
                    subResourceDatas[i].DataPointer = data[i].DataPointer;
                    subResourceDatas[i].RowPitch = data[i].Pitch;
                }
            }

            device.CreateTexture2D1(ref description, subResourceDatas, this);
        }
コード例 #5
0
ファイル: Texture2D1.cs プロジェクト: zmtzawqlp/SharpDX
        /// <summary>
        ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture2D1" /> class.
        /// </summary>
        /// <param name = "device">The device with which to associate the texture.</param>
        /// <param name = "description">The description of the texture.</param>
        /// <param name = "data">An array of initial texture data for each subresource.</param>
        /// <msdn-id>ff476521</msdn-id>
        /// <unmanaged>HRESULT ID3D11Device3::CreateTexture2D1([In] const D3D11_TEXTURE2D_DESC1* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D1** ppTexture2D)</unmanaged>
        /// <unmanaged-short>ID3D11Device3::CreateTexture2D1</unmanaged-short>
        public Texture2D1(Device3 device, Texture2DDescription1 description, params DataRectangle[] data)
            : base(IntPtr.Zero)
        {
            DataBox[] subResourceDatas = null;

            if (data != null && data.Length > 0)
            {
                subResourceDatas = new DataBox[data.Length];
                for (int i = 0; i < subResourceDatas.Length; i++)
                {
                    subResourceDatas[i].DataPointer = data[i].DataPointer;
                    subResourceDatas[i].RowPitch    = data[i].Pitch;
                }
            }

            device.CreateTexture2D1(ref description, subResourceDatas, this);
        }
コード例 #6
0
        private void InitializeHolographicSpace(CoreWindow targetWindow)
        {
            // Create the holographic space
            m_holoSpace = HolographicSpace.CreateForCoreWindow(targetWindow);

            // The holographic space might need to determine which adapter supports
            // holograms, in which case it will specify a non-zero PrimaryAdapterId.
            int   shiftPos = sizeof(uint);
            ulong id       = (ulong)m_holoSpace.PrimaryAdapterId.LowPart | (((ulong)m_holoSpace.PrimaryAdapterId.HighPart) << shiftPos);

            // Get the device with the luid or get the default device of the current system
            if (id != 0)
            {
                m_hostDevice = GraphicsCore.Current.TryGetDeviceByLuid((long)id);
            }
            if (m_hostDevice == null)
            {
                m_hostDevice = GraphicsCore.Current.DefaultDevice;
            }

            // Acquire the DXGI interface for the Direct3D device.
            D3D11.Device3 d3dDevice = m_hostDevice.Device3D11_3;
            using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device3>())
            {
                // Wrap the native device using a WinRT interop object.
                IntPtr pUnknown;
                UInt32 hr = NativeMethods.CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out pUnknown);
                if (hr == 0)
                {
                    m_d3dInteropDevice = (MS_D3D11.IDirect3DDevice)Marshal.GetObjectForIUnknown(pUnknown);
                    Marshal.Release(pUnknown);
                }

                // Store a pointer to the DXGI adapter.
                // This is for the case of no preferred DXGI adapter, or fallback to WARP.
                m_dxgiAdapter = dxgiDevice.Adapter.QueryInterface <SharpDX.DXGI.Adapter3>();
            }

            // Set the Direct3D device on the holographic space
            m_holoSpace.SetDirect3D11Device(m_d3dInteropDevice);
        }
コード例 #7
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">RenderTarget</see> flag.</param>
 /// <unmanaged>ID3D11Device3::CreateRenderTargetView1</unmanaged>
 public RenderTargetView1(Device3 device, Resource resource)
     : base(IntPtr.Zero)
 {
     device.CreateRenderTargetView1(resource, null, this);
 }
コード例 #8
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">UnorderedAccess</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" /> to be created.</param>
 /// <unmanaged>ID3D11Device3::CreateUnorderedAccessView1</unmanaged>
 public UnorderedAccessView1(Device3 device, Resource resource, UnorderedAccessViewDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateUnorderedAccessView1(resource, description, this);
 }
コード例 #9
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture3D1" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 public Texture3D1(Device3 device, Texture3DDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateTexture3D1(ref description, null, this);
 }
コード例 #10
0
ファイル: Texture3D1.cs プロジェクト: JoeErickson/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture3D1" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 /// <param name = "data">An array of initial texture data for each subresource.</param>
 public Texture3D1(Device3 device, Texture3DDescription1 description, DataBox[] data) : base(IntPtr.Zero)
 {
     device.CreateTexture3D1(ref description, data, this);
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new deferred context instance of <see cref="SharpDX.Direct3D11.DeviceContext3"/> class.
 /// </summary>
 /// <param name="device"></param>
 public DeviceContext3(Device3 device)
     : base(IntPtr.Zero)
 {
     device.CreateDeferredContext3(0, this);
 }
コード例 #12
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">UnorderedAccess</see> flag.</param>
 /// <unmanaged>ID3D11Device3::CreateUnorderedAccessView1</unmanaged>
 public UnorderedAccessView1(Device3 device, Resource resource)
     : base(IntPtr.Zero)
 {
     device.CreateUnorderedAccessView1(resource, null, this);
 }
コード例 #13
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">ShaderResource</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> to be created.</param>
 /// <msdn-id>ff476519</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device3::CreateShaderResourceView1([In] ID3D11Resource* pResource,[In, Optional] const D3D11_SHADER_RESOURCE_VIEW_DESC1* pDesc,[Out, Fast] ID3D11ShaderResourceView1** ppSRView)</unmanaged>	
 /// <unmanaged-short>ID3D11Device3::CreateShaderResourceView1</unmanaged-short>	
 public ShaderResourceView1(Device3 device, Resource resource, ShaderResourceViewDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateShaderResourceView1(resource, description, this);
 }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceHandlerD3D11"/> class.
        /// </summary>
        /// <param name="dxgiAdapter">The tasrget adapter.</param>
        /// <param name="debugEnabled">Is debug mode enabled?</param>
        internal DeviceHandlerD3D11(DXGI.Adapter1 dxgiAdapter, bool debugEnabled)
        {
            m_dxgiAdapter = dxgiAdapter;

            // Define possible create flags
            D3D11.DeviceCreationFlags createFlagsBgra = D3D11.DeviceCreationFlags.BgraSupport;
            D3D11.DeviceCreationFlags createFlags     = D3D11.DeviceCreationFlags.None;
            if (debugEnabled)
            {
                createFlagsBgra |= D3D11.DeviceCreationFlags.Debug;
                createFlags     |= D3D11.DeviceCreationFlags.Debug;
            }

            // Define all steps on which we try to initialize Direct3D
            List <Tuple <D3D.FeatureLevel, D3D11.DeviceCreationFlags, HardwareDriverLevel> > initParameterQueue =
                new List <Tuple <D3D.FeatureLevel, D3D11.DeviceCreationFlags, HardwareDriverLevel> >();

            // Define all trys for hardware initialization
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_11_1, createFlagsBgra, HardwareDriverLevel.Direct3D11));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_11_0, createFlagsBgra, HardwareDriverLevel.Direct3D11));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_10_0, createFlagsBgra, HardwareDriverLevel.Direct3D10));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_9_3, createFlagsBgra, HardwareDriverLevel.Direct3D9_3));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_9_2, createFlagsBgra, HardwareDriverLevel.Direct3D9_2));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_9_1, createFlagsBgra, HardwareDriverLevel.Direct3D9_1));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_10_0, createFlags, HardwareDriverLevel.Direct3D10));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_9_3, createFlags, HardwareDriverLevel.Direct3D9_3));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_9_2, createFlags, HardwareDriverLevel.Direct3D9_2));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_9_1, createFlags, HardwareDriverLevel.Direct3D9_1));

            // Try to create the device, each defined configuration step by step
            foreach (Tuple <D3D.FeatureLevel, D3D11.DeviceCreationFlags, HardwareDriverLevel> actInitParameters in initParameterQueue)
            {
                D3D.FeatureLevel          featureLevel    = actInitParameters.Item1;
                D3D11.DeviceCreationFlags direct3D11Flags = actInitParameters.Item2;
                HardwareDriverLevel       actDriverLevel  = actInitParameters.Item3;

                try
                {
                    // Try to create the device using current parameters
                    using (D3D11.Device device = new D3D11.Device(dxgiAdapter, direct3D11Flags, featureLevel))
                    {
                        m_device1 = device.QueryInterface <D3D11.Device1>();
                        m_device3 = CommonTools.TryExecute(() => m_device1.QueryInterface <D3D11.Device3>());
                        if (m_device3 != null)
                        {
                            m_immediateContext3 = m_device3.ImmediateContext3;
                        }
                    }

                    // Device successfully created, save all parameters and break this loop
                    m_featureLevel  = featureLevel;
                    m_creationFlags = direct3D11Flags;
                    m_driverLevel   = actDriverLevel;
                    break;
                }
                catch (Exception) { }
            }

            // Throw exception on failure
            if (m_device1 == null)
            {
                throw new SeeingSharpGraphicsException("Unable to initialize d3d11 device!");
            }

            // Get immediate context from the device
            m_immediateContext = m_device1.ImmediateContext;
        }
コード例 #15
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.RenderTargetView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">RenderTarget</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" /> to be created.</param>
 /// <unmanaged>ID3D11Device3::CreateRenderTargetView1</unmanaged>
 public RenderTargetView1(Device3 device, Resource resource, RenderTargetViewDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateRenderTargetView1(resource, description, this);
 }
コード例 #16
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">RenderTarget</see> flag.</param>
 /// <unmanaged>ID3D11Device3::CreateRenderTargetView1</unmanaged>
 public RenderTargetView1(Device3 device, Resource resource)
     : base(IntPtr.Zero)
 {
     device.CreateRenderTargetView1(resource, null, this);
 }
コード例 #17
0
ファイル: DeviceContext3.cs プロジェクト: JoeErickson/SharpDX
 /// <summary>
 /// Initializes a new deferred context instance of <see cref="SharpDX.Direct3D11.DeviceContext3"/> class.
 /// </summary>
 /// <param name="device"></param>
 public DeviceContext3(Device3 device)
     : base(IntPtr.Zero)
 {
     device.CreateDeferredContext3(0, this);
 }
コード例 #18
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.ShaderResourceView1" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.ShaderResourceView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">ShaderResource</see> flag.</param>
 /// <msdn-id>ff476519</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device3::CreateShaderResourceView1([In] ID3D11Resource* pResource,[In, Optional] const D3D11_SHADER_RESOURCE_VIEW_DESC1* pDesc,[Out, Fast] ID3D11ShaderResourceView1** ppSRView)</unmanaged>	
 /// <unmanaged-short>ID3D11Device3::CreateShaderResourceView1</unmanaged-short>	
 public ShaderResourceView1(Device3 device, Resource resource)
     : base(IntPtr.Zero)
 {
     device.CreateShaderResourceView1(resource, null, this);
 }
コード例 #19
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.RenderTargetView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">RenderTarget</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.RenderTargetView1" /> to be created.</param>
 /// <unmanaged>ID3D11Device3::CreateRenderTargetView1</unmanaged>
 public RenderTargetView1(Device3 device, Resource resource, RenderTargetViewDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateRenderTargetView1(resource, description, this);
 }
コード例 #20
0
ファイル: Query1.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.Query1" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The query description.</param>
 /// <returns>The newly created object.</returns>
 public Query1(Device3 device, QueryDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateQuery1(description, this);
 }
コード例 #21
0
ファイル: Query1.cs プロジェクト: JoeErickson/SharpDX
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.Query1" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The query description.</param>
 /// <returns>The newly created object.</returns>
 public Query1(Device3 device, QueryDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateQuery1(description, this);
 }
コード例 #22
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">UnorderedAccess</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" /> to be created.</param>
 /// <unmanaged>ID3D11Device3::CreateUnorderedAccessView1</unmanaged>
 public UnorderedAccessView1(Device3 device, Resource resource, UnorderedAccessViewDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateUnorderedAccessView1(resource, description, this);
 }
コード例 #23
0
        public RenderToHandleDeviceProxy(Adapter adapter, IntPtr handle, GraphicSurfaceSize size)
        {
            var backBufferDesc = new ModeDescription(size.Width, size.Height, new Rational(60, 1), GraphicsDevice.BackBufferTextureFormat);

            // Descriptor for the swap chain
            var swapChainDesc = new SwapChainDescription()
            {
                ModeDescription   = backBufferDesc,
                SampleDescription = new SampleDescription(1, 0),
                BufferCount       = 2,
                IsWindowed        = true,
                OutputHandle      = handle,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
                // SwapEffect = SwapEffect.FlipSequential
            };
            // Create device and swap chain
            var flags = DeviceCreationFlags.None;

#if DEBUG
            //flags |= DeviceCreationFlags.Debug;
#endif
            if (SharpDX.Direct3D11.Device.IsSupportedFeatureLevel(adapter, FeatureLevel.Level_11_1))   //update win->dxdiag
                                                                                                       //flags |= DeviceCreationFlags.Debuggable;
            {
            }
            if (SharpDX.Direct3D11.Device.IsSupportedFeatureLevel(adapter, FeatureLevel.Level_12_0))
            {
            }

            //using (var factory = adapter.GetParent<Factory2>()) {
            //    var device11 = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.None,
            //       new[] {
            //               FeatureLevel.Level_12_1,
            //               FeatureLevel.Level_12_0,
            //               FeatureLevel.Level_11_1,
            //               FeatureLevel.Level_11_0,
            //       });
            //    var desc1 = new SwapChainDescription1() {
            //        Width = width,
            //        Height = height,
            //        Format = BackBufferTextureFormat,
            //        Stereo = false,
            //        SampleDescription = new SampleDescription(1, 0),
            //        Usage = Usage.BackBuffer | Usage.RenderTargetOutput,
            //        BufferCount = 1,
            //        Scaling = Scaling.Stretch,
            //        SwapEffect = SwapEffect.Discard,

            //    };
            //    swapChain = new SwapChain1(factory, device11, handle, ref desc1,
            //        new SwapChainFullScreenDescription() {
            //            RefreshRate = new Rational(60, 1),
            //            Scaling = DisplayModeScaling.Centered,
            //            Windowed = true
            //        },
            //        // Restrict output to specific Output (monitor)
            //        null);
            //}

            SharpDX.Direct3D11.Device.CreateWithSwapChain(adapter, flags, swapChainDesc, out var d3dDevice, out var sch);

            var wc = sch.QueryInterfaceOrNull <SwapChain1>();
            if (wc != null)
            {
                swapChain1 = wc;
            }
            var sc3 = sch.QueryInterfaceOrNull <SwapChain3>();
            if (sc3 != null)
            {
                swapChain3 = sc3;
            }

            swapChain = sch;                                                        //.QueryInterface<SwapChain4>();//

            var d3 = d3dDevice.QueryInterfaceOrNull <SharpDX.Direct3D11.Device3>(); //Device5
            if (d3 != null)
            {
                device3 = d3;
            }
            D3DDevice = d3dDevice;

            ImmediateContext = d3dDevice.ImmediateContext;

            // Enable object tracking
            //SharpDX.Configuration.EnableObjectTracking = true;
        }
コード例 #24
0
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.RasterizerState2" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The state description.</param>
 /// <returns>The newly created object.</returns>
 public RasterizerState2(Device3 device, RasterizerStateDescription2 description)
     : base(IntPtr.Zero)
 {
     device.CreateRasterizerState2(ref description, this);
 }
コード例 #25
0
ファイル: RasterizerState2.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.RasterizerState2" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The state description.</param>
 /// <returns>The newly created object.</returns>
 public RasterizerState2(Device3 device, RasterizerStateDescription2 description)
     : base(IntPtr.Zero)
 {
     device.CreateRasterizerState2(ref description, this);
 }
コード例 #26
0
ファイル: Texture3D1.cs プロジェクト: JoeErickson/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture3D1" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 public Texture3D1(Device3 device, Texture3DDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateTexture3D1(ref description, null, this);
 }
コード例 #27
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.ShaderResourceView1" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.ShaderResourceView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">ShaderResource</see> flag.</param>
 /// <msdn-id>ff476519</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device3::CreateShaderResourceView1([In] ID3D11Resource* pResource,[In, Optional] const D3D11_SHADER_RESOURCE_VIEW_DESC1* pDesc,[Out, Fast] ID3D11ShaderResourceView1** ppSRView)</unmanaged>
 /// <unmanaged-short>ID3D11Device3::CreateShaderResourceView1</unmanaged-short>
 public ShaderResourceView1(Device3 device, Resource resource)
     : base(IntPtr.Zero)
 {
     device.CreateShaderResourceView1(resource, null, this);
 }
コード例 #28
0
        private void SwapChainPanel_OnLoaded(object sender, RoutedEventArgs e)
        {
            using (var defDevice = new D3D.Device(DriverType.Hardware, D3D.DeviceCreationFlags.Debug))
            {
                _device = defDevice.QueryInterface <D3D.Device3>();
            }
            _context = _device.ImmediateContext3;

            var pixelScale    = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f;
            var swapChainDesc = new DXGI.SwapChainDescription1()
            {
                AlphaMode         = DXGI.AlphaMode.Premultiplied,
                BufferCount       = 2,
                Flags             = DXGI.SwapChainFlags.None,
                Format            = DXGI.Format.B8G8R8A8_UNorm,
                Width             = (int)(panel.RenderSize.Width * pixelScale),
                Height            = (int)(panel.RenderSize.Height * pixelScale),
                SampleDescription = new DXGI.SampleDescription(1, 0),
                Scaling           = DXGI.Scaling.Stretch,
                Stereo            = false,
                SwapEffect        = DXGI.SwapEffect.FlipSequential,
                Usage             = DXGI.Usage.BackBuffer | DXGI.Usage.RenderTargetOutput
            };

            using (var dxgiDevice = _device.QueryInterface <DXGI.Device3>())
            {
                var factory = dxgiDevice.Adapter.GetParent <DXGI.Factory4>();
                using (var tmpSwapChain = new DXGI.SwapChain1(factory, _device, ref swapChainDesc))
                {
                    _swapChain = tmpSwapChain.QueryInterface <DXGI.SwapChain3>();
                }
            }

            using (var nativeObject = ComObject.As <DXGI.ISwapChainPanelNative>(panel))
            {
                nativeObject.SwapChain = _swapChain;
            }

            using (var depthBuffer = new D3D.Texture2D(_device, new D3D.Texture2DDescription()
            {
                Format = DXGI.Format.D24_UNorm_S8_UInt,
                ArraySize = 1,
                MipLevels = 1,
                Width = swapChainDesc.Width,
                Height = swapChainDesc.Height,
                SampleDescription = new DXGI.SampleDescription(1, 0),
                BindFlags = D3D.BindFlags.DepthStencil,
            }))
            {
                _depthStencilView = new D3D.DepthStencilView(_device, depthBuffer, new D3D.DepthStencilViewDescription()
                {
                    Dimension = D3D.DepthStencilViewDimension.Texture2D
                });
            }

            _backBuffer = D3D.Resource.FromSwapChain <D3D.Texture2D>(_swapChain, 0);
            _renderView = new D3D.RenderTargetView1(_device, _backBuffer);

            var viewport = new ViewportF(0, 0, (float)panel.RenderSize.Width, (float)panel.RenderSize.Height, 0.0f, 1.0f);

            _context.Rasterizer.SetViewport(viewport);

            ShaderBytecode shaderBytecode;

            using (shaderBytecode = ShaderBytecode.CompileFromFile("shaders.hlsl", "vs", "vs_5_0", ShaderFlags.Debug))
            {
                _vertexShader = new D3D.VertexShader(_device, shaderBytecode);
            }

            using (var byteCode = ShaderBytecode.CompileFromFile(@"shaders.hlsl", "ps", "ps_5_0", ShaderFlags.Debug))
            {
                _pixelShader = new D3D.PixelShader(_device, byteCode);
            }

            D3D.InputElement[] inputElements =
            {
                new D3D.InputElement("POSITION", 0, DXGI.Format.R32G32B32A32_Float, 0, 0),
            };
            _inputLayout = new D3D.InputLayout(_device, shaderBytecode, inputElements);

            _vertices = new[]
            {
                new Vector4(-0.5f, 0.0f, 0.5f, 1.0f),
                new Vector4(0.0f, 0.5f, 0.5f, 1.0f),
                new Vector4(0.5f, 0.0f, 0.5f, 1.0f),
            };
            _vertexBuffer  = D3D.Buffer.Create(_device, D3D.BindFlags.VertexBuffer, _vertices);
            _vertexBinding = new D3D.VertexBufferBinding(_vertexBuffer, Utilities.SizeOf <Vector4>(), 0);

            _constantBuffer = new SharpDX.Direct3D11.Buffer(
                _device,
                Utilities.SizeOf <SharpDX.Matrix>(),
                D3D.ResourceUsage.Default,
                D3D.BindFlags.ConstantBuffer,
                D3D.CpuAccessFlags.None,
                D3D.ResourceOptionFlags.None,
                0);

            _timer = new Stopwatch();
            _timer.Start();

            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }
コード例 #29
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">ShaderResource</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> to be created.</param>
 /// <msdn-id>ff476519</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device3::CreateShaderResourceView1([In] ID3D11Resource* pResource,[In, Optional] const D3D11_SHADER_RESOURCE_VIEW_DESC1* pDesc,[Out, Fast] ID3D11ShaderResourceView1** ppSRView)</unmanaged>
 /// <unmanaged-short>ID3D11Device3::CreateShaderResourceView1</unmanaged-short>
 public ShaderResourceView1(Device3 device, Resource resource, ShaderResourceViewDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateShaderResourceView1(resource, description, this);
 }
コード例 #30
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture3D1" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 /// <param name = "data">An array of initial texture data for each subresource.</param>
 public Texture3D1(Device3 device, Texture3DDescription1 description, DataBox[] data) : base(IntPtr.Zero)
 {
     device.CreateTexture3D1(ref description, data, this);
 }
コード例 #31
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView1" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">UnorderedAccess</see> flag.</param>
 /// <unmanaged>ID3D11Device3::CreateUnorderedAccessView1</unmanaged>
 public UnorderedAccessView1(Device3 device, Resource resource)
     : base(IntPtr.Zero)
 {
     device.CreateUnorderedAccessView1(resource, null, this);
 }