public DxDevice(DXGIFactory factory, DXGIAdapter adapter, DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport) { this.WICFactory = new WICFactory(); this.D2DFactory = new D2DFactory(); this.DWriteFactory = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared); this.adapterindex = 0; FeatureLevel[] levels = new FeatureLevel[] { #if DIRECTX11_1 FeatureLevel.Level_11_1, #endif FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3 }; var dev = new Device(adapter, flags, levels); #if DIRECTX11_1 this.Device = dev.QueryInterface <DirectXDevice>(); Marshal.Release(this.Device.NativePointer); #else this.Device = dev; #endif this.Adapter = adapter; this.Factory = factory; this.OnLoad(); }
protected override SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc) { return(new SharpDX.DXGI.SwapChain1(factory, device, ref desc)); //// Creates a SwapChain from a CoreWindow pointer //using (var comWindow = new ComObject(window)) // return factory.CreateSwapChainForCoreWindow(device, comWindow, ref desc, null); }
public Direct2DCanvas() { int width = 1024; int height = 1024; SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device( SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport); // Query the default device for the supported device and context interfaces. var device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1> (); // Query for the adapter and more advanced DXGI objects. SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface <SharpDX.DXGI.Device2> (); SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter; SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent <SharpDX.DXGI.Factory2> (); var swapChainDescription = new SharpDX.DXGI.SwapChainDescription1 { Width = width, Height = height, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Stereo = false, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, BufferCount = 2, Scaling = SharpDX.DXGI.Scaling.Stretch, SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential, Flags = SharpDX.DXGI.SwapChainFlags.None, }; swapChainDescription.SampleDescription.Count = 1; swapChainDescription.SampleDescription.Quality = 0; swapChain = dxgiFactory2.CreateSwapChainForComposition(dxgiDevice2, ref swapChainDescription, null); swapChain.BackgroundColor = new Color4(1, 0, 0, 0); var native = SharpDX.ComObject.QueryInterface <SharpDX.DXGI.ISwapChainBackgroundPanelNative> (this); native.SwapChain = swapChain; g = new Direct2DGraphics(swapChain); _drawTimer = new WindowsDrawTimer { Continuous = true, ShouldDrawFunc = () => Content != null && ActualWidth > 0 && ActualHeight > 0, DrawFunc = Draw, }; Unloaded += HandleUnloaded; Loaded += HandleLoaded; LayoutUpdated += HandleLayoutUpdated; }
/// <summary> /// 初期化する。 /// </summary> /// <param name="control"> /// デバイスコンテキストを適用するコントロール。 /// </param> public void Load(bool 機能レベル11が必須 = false, SharpDX.Direct3D11.DeviceCreationFlags dx11flag = SharpDX.Direct3D11.DeviceCreationFlags.None, SharpDX.Direct3D10.DeviceCreationFlags dx10flag_for2DDraw = SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport) { this._ApplyDebugFlags(ref dx11flag, ref dx10flag_for2DDraw); this.DXGIFactory = new SharpDX.DXGI.Factory2(); this.Adapter = DXGIFactory.GetAdapter1(0); #region " D3D11 デバイスを作成する。(機能レベルは 11.0 または 10.1) " //---------------- try { // 機能レベル 11.x の D3D11 デバイスを作成する。 D3DDevice = new SharpDX.Direct3D11.Device( Adapter, dx11flag, new[] { SharpDX.Direct3D.FeatureLevel.Level_11_0 }); } catch (SharpDX.SharpDXException) { if (機能レベル11が必須) { throw new NotSupportedException("DX11がサポートされていません。DX10.1で初期化するにはLoadの第一引数をfalseにして下さい。"); } try { // 機能レベル 10.x の D3D11 デバイスを作成する。 D3DDevice = new SharpDX.Direct3D11.Device( Adapter, dx11flag, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }); } catch (SharpDX.SharpDXException) { throw new NotSupportedException("DX11,DX10.1での初期化を試みましたが、両方ともサポートされていません。"); } } //---------------- #endregion this.DeviceFeatureLevel = D3DDevice.FeatureLevel; this.D3DDeviceContext = D3DDevice.ImmediateContext; // 注: COM参照カウンタが増える。 エフェクト.初期化する(this); }
public BasicCapture(IDirect3DDevice d, GraphicsCaptureItem i) { item = i; device = d; d3dDevice = Direct3D11Helper.CreateSharpDXDevice(device); wicFactory = new ImagingFactory(); // 建立DirectX图形基础设施工厂(DirectX Graphics Infrastructure,DXGI) var dxgiFactory = new SharpDX.DXGI.Factory2(); // 建立交换链 var description = new SharpDX.DXGI.SwapChainDescription1() { Width = item.Size.Width, Height = item.Size.Height, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Stereo = false, // 立体声 SampleDescription = new SharpDX.DXGI.SampleDescription() { Count = 1, Quality = 0 }, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, BufferCount = 2, Scaling = SharpDX.DXGI.Scaling.Stretch, SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential, // 连续翻转 AlphaMode = SharpDX.DXGI.AlphaMode.Premultiplied, // 预乘 Flags = SharpDX.DXGI.SwapChainFlags.None }; swapChain = new SharpDX.DXGI.SwapChain1(dxgiFactory, d3dDevice, ref description); framePool = Direct3D11CaptureFramePool.Create( device, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, i.Size); // 创建捕获会话 session = framePool.CreateCaptureSession(i); // 记录最后帧尺寸 lastSize = i.Size; // 帧已到达事件添加 framePool.FrameArrived += OnFrameArrived; }
public BasicCapture(IDirect3DDevice d, GraphicsCaptureItem i) { __item = i; __device = d; __d3dDevice = Direct3D11Helper.CreateSharpDXDevice(__device); var dxgiFactory = new SharpDX.DXGI.Factory2(); var description = new SharpDX.DXGI.SwapChainDescription1() { Width = __item.Size.Width, Height = __item.Size.Height, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Stereo = false, SampleDescription = new SharpDX.DXGI.SampleDescription() { Count = 1, Quality = 0 }, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, BufferCount = 2, Scaling = SharpDX.DXGI.Scaling.Stretch, SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential, AlphaMode = SharpDX.DXGI.AlphaMode.Premultiplied, Flags = SharpDX.DXGI.SwapChainFlags.None }; __swapChain = new SharpDX.DXGI.SwapChain1(dxgiFactory, __d3dDevice, ref description); __framePool = Direct3D11CaptureFramePool.Create( __device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, i.Size); __session = __framePool.CreateCaptureSession(i); __lastSize = i.Size; // Disable mouse cursor to be visible __session.IsCursorCaptureEnabled = false; __framePool.FrameArrived += OnFrameArrived; }
/// <summary> /// Creates the swap chain. /// </summary> /// <param name="factory">The DXGI factory</param> /// <param name="device">The D3D11 device</param> /// <param name="desc">The swap chain description</param> /// <returns>An instance of swap chain</returns> protected abstract SharpDX.DXGI.SwapChain1 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc);
internal static void Init() { Logger.Info("GraphicsManager initializing."); // Direct3D11 Init --- ResizeNextFrame = true; Factory = new FactoryDXGI(); ImagingFactory = new FactoryWIC(); Factory2D = new FactoryD2D(FactoryType.MultiThreaded, Engine.IsDebug ? DebugLevel.Error : DebugLevel.None); DirectWriteFactory = new FactoryDW(SharpDX.DirectWrite.FactoryType.Shared); CreateDevices(RenderSettings.GraphicsAdapter); Brushes = new MemoizingMRUCache <Colour, SolidColorBrush>( (colour, _) => new SolidColorBrush(Context2D, (Color4)colour) { Opacity = colour.A }, int.MaxValue, brush => brush.Dispose()); // ------------------------------------ Engine.HandleSet += hwnd => { var camera = Game.Workspace.CurrentCamera; camera.RenderHandle = hwnd; }; if (Engine.Handle != IntPtr.Zero) { var camera = Game.Workspace.CurrentCamera; camera.RenderHandle = Engine.Handle; } SamplerStates.Load(); Shaders.Init(); BlendStates.Load(); DepthStencilStates.Load(); RasterizerStates.Load(); //StandardConstants = new ConstantBuffer<StandardConstantData>(); StandardShader = Shaders.Get("Standard"); MainPass = StandardShader.GetPass(); LightingShader = Shaders.Get("Lighting"); LightingPass = LightingShader.GetPass(); PostProcessShader = Shaders.Get("PostProcess"); SkyboxShader = Shaders.Get("Skybox"); SkyboxPass = SkyboxShader.GetPass(); AdornShader = Shaders.Get("Adorn"); AALinePass = AdornShader.GetPass("AALine"); AdornSelfLitPass = AdornShader.GetPass("AdornSelfLit"); Shadows.Init(); // ------------------ IsInitialized = true; Initialized?.Invoke(); Initialized = null; //PixHelper.AllowProfiling(Engine.IsDebug); Logger.Info("Renderer initialized."); }