/// <summary> /// 最適グラフィックスアダプタを返す /// </summary> /// <returns></returns> static Adapter GetAdapter(Factory1 factory) { // 優先順 string[] vender_string = new string[] { "nvidia", "ati", }; Adapter1 result = factory.GetAdapter1(0); int adapterCount = factory.GetAdapterCount1(); for (int i = 1; i < adapterCount; i++) { Adapter1 adapter = factory.GetAdapter1(i); var device_name = adapter.Description.Description.ToLower(); for (int j = 0; j < vender_string.Length; j++) { if (device_name.Contains(vender_string[j])) { result = adapter; } } } return(result); }
public static List <DxEnumeratedDisplay> GetMonitors(int adapterId) { var displays = new List <DxEnumeratedDisplay>(); try { using var factory = new Factory1(); using var adapter = factory.GetAdapter1(adapterId); using var device = new SharpDX.Direct3D11.Device(adapter); var displayCount = adapter.GetOutputCount(); for (var i = 0; i < displayCount; ++i) { using var output = adapter.GetOutput(i); using var output6 = output.QueryInterface <Output6>(); using var duplicatedOutput = output6.DuplicateOutput1(device, 0, 1, new Format[] { Format.B8G8R8A8_UNorm }); displays.Add(new DxEnumeratedDisplay() { OutputId = i, Name = output.Description.DeviceName.ToString(), Width = duplicatedOutput.Description.ModeDescription.Width, Height = duplicatedOutput.Description.ModeDescription.Height, RefreshRate = duplicatedOutput.Description.ModeDescription.RefreshRate.Numerator / duplicatedOutput.Description.ModeDescription.RefreshRate.Denominator, Format = duplicatedOutput.Description.ModeDescription.Format.ToString(), Bpp = output6.Description1.BitsPerColor, ColorSpace = output6.Description1.ColorSpace.ToString() }); } } catch (Exception ex) { Console.WriteLine(ex); } return(displays); }
public Wiring() { _factory = new Factory1(); // Only works as long as you're only using one graphics card. So, TODO to change this someday. _adapter = _factory.GetAdapter1(0); // Create device from Adapter Device = new Device(_adapter, DeviceCreationFlags.Debug); // Works only with a single monitor. I'm only using one monitor, so I'm ignoring this. But, TODO. _output = _adapter.GetOutput(0); _output1 = _output.QueryInterface <Output1>(); Height = _output.Description.DesktopBounds.Bottom - _output.Description.DesktopBounds.Top; Width = _output.Description.DesktopBounds.Right - _output.Description.DesktopBounds.Left; Texture = new Texture2D(Device, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = Width, Height = Height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }); OutputDuplication = _output1.DuplicateOutput(Device); }
/// <summary> /// (Re)configures the class to a fresh state. /// </summary> private void Configure(int adapterIndex, int displayIndex) { Dispose(false); factory = new Factory1(); adapter = factory.GetAdapter1(adapterIndex); device = new Device(adapter); output = adapter.GetOutput(displayIndex); screen = output.QueryInterface <Output1>(); bounds = screen.Description.DesktopBounds; Texture2DDescription textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = bounds.Right - bounds.Left, Height = bounds.Bottom - bounds.Top, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); ResetOutputDuplicator(); }
public DesktopDuplicator(IntPtr window) { User32.GetWindowRect(window, out var rectNative); var windowRect = rectNative.ToRect(); // Search all outputs on all adapters and find the window rect. var factory = new Factory1(); for (var j = 0; j < factory.GetAdapterCount1(); j++) { var adapter = factory.GetAdapter1(j); for (var i = 0; i < adapter.GetOutputCount(); i++) { var output = adapter.GetOutput(i); var bounds = output.Description.DesktopBounds.ToRectangle(); if (bounds.Contains(windowRect)) { Initialize(0, i); return; } } } throw new Exception($"Didn't find the {window} window on any display output."); }
private Rational GetRefreshRateAndSetVideoCardProperties(Dimension size) { var refreshRate = new Rational(0, 1); using (var factory = new Factory1()) using (var adapter = factory.GetAdapter1(0)) using (var monitor = adapter.GetOutput(0)) { var modes = monitor.GetDisplayModeList(RGB8_UNorm, DisplayModeEnumerationFlags.Interlaced); if (_verticalSyncEnabled) { foreach (var mode in modes) { if (size.SameSizeAs(mode)) { refreshRate = new Rational(mode.RefreshRate.Numerator, mode.RefreshRate.Denominator); break; } } } var adapterDescription = adapter.Description; VideoCardMemory = adapterDescription.DedicatedVideoMemory / 1024 / 1024; // In MB VideoCardDescription = adapterDescription.Description.Trim('\0'); } return(refreshRate); }
private void Initialize() { factory = new Factory1(); //Get first adapter adapter = factory.GetAdapter1(0); //Get device from adapter device = new SharpDX.Direct3D11.Device(adapter); //Get front buffer of the adapter output = adapter.GetOutput(0); output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture int width = output.Description.DesktopBounds.Right; int height = output.Description.DesktopBounds.Bottom; size = new Vector2Int(width, height); // Create Staging texture CPU-accessible textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); duplicatedOutput = output1.DuplicateOutput(device); }
public void getCaps() { Factory1 fac = new Factory1(); int numAdapters = fac.GetAdapterCount1(); List <Adapter1> adapts = new List <Adapter1>(); for (int i = 0; i < numAdapters; i++) { adapts.Add(fac.GetAdapter1(i)); } Output outp = adapts[0].GetOutput(0); List <Format> formats = new List <Format>(); foreach (Format format in Enum.GetValues(typeof(Format))) { formats.Add(format); } //List<ReadOnlyCollection<ModeDescription>> ll = new List<ReadOnlyCollection<ModeDescription>>(); List <ModeDescription[]> ll = new List <ModeDescription[]>(); for (int i = 0; i < formats.Count - 1; i++) { //ReadOnlyCollection<ModeDescription> mdl; ModeDescription[] mdl; mdl = outp.GetDisplayModeList(formats[i], DisplayModeEnumerationFlags.Interlaced); ll.Add(mdl); if (mdl != null) { Console.WriteLine(formats[i].ToString()); } } }
/// <summary> /// Init some variables one times to spend execution time. /// </summary> public DirectX() { try { factory = new Factory1(); adapter = factory.GetAdapter1(numAdapter); device = new Device(adapter); output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // get screen wize textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Right - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Left, Height = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Bottom - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Top, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); duplicatedOutput = output1.DuplicateOutput(device); } catch (Exception ex) { throw ex; } }
public DXCapture() { // # of graphics card adapter const int numAdapter = 0; // # of output device (i.e. monitor) const int numOutput = 0; // const string outputFileName = "ScreenCapture.bmp"; // Create DXGI Factory1 var factory = new Factory1(); var adapter = factory.GetAdapter1(numAdapter); // Create device from Adapter device = new Device(adapter); // Get DXGI.Output var output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture width = output.Description.DesktopBounds.Right - output.Description.DesktopBounds.Left; height = output.Description.DesktopBounds.Bottom - output.Description.DesktopBounds.Top; }
public static DxEnumeratedDisplay GetMonitor(int adapterId, int id) { DxEnumeratedDisplay display = null; try { using var factory = new Factory1(); using var adapter = factory.GetAdapter1(adapterId); using var device = new SharpDX.Direct3D11.Device(adapter); if (id > adapter.GetOutputCount()) { return(null); } using var output = adapter.GetOutput(id); using var output6 = output.QueryInterface <Output6>(); using var duplicatedOutput = output6.DuplicateOutput1(device, 0, 1, new Format[] { Format.B8G8R8A8_UNorm }); display = new DxEnumeratedDisplay() { OutputId = id, Name = output.Description.DeviceName.ToString(), Width = duplicatedOutput.Description.ModeDescription.Width, Height = duplicatedOutput.Description.ModeDescription.Height, RefreshRate = duplicatedOutput.Description.ModeDescription.RefreshRate.Numerator / duplicatedOutput.Description.ModeDescription.RefreshRate.Denominator, Format = duplicatedOutput.Description.ModeDescription.Format.ToString(), Bpp = output6.Description1.BitsPerColor, ColorSpace = output6.Description1.ColorSpace.ToString() }; } catch (Exception ex) { Console.WriteLine(ex); } return(display); }
public DirectXScreenCapturer() { // 获取输出设备(显卡、显示器),这里是主显卡和主显示器 factory = new Factory1(); adapter = factory.GetAdapter1(0); device = new SharpDX.Direct3D11.Device(adapter); output = adapter.GetOutput(0); output1 = output.QueryInterface <Output1>(); //设置纹理信息,供后续使用(截图大小和质量) textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = output.Description.DesktopBounds.Right, Height = output.Description.DesktopBounds.Bottom, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); }
private static void InitDevice() { // Create DXGI Factory1 factory = new Factory1(); adapter = factory.GetAdapter1(0); // Create device from Adapter //device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_11_1); device = new SharpDX.Direct3D11.Device(adapter); }
public static Bitmap GetCurrentScreen(int adapterNumber = 0, int output = 0) { Factory1 factory = new Factory1(); Adapter adapter = factory.GetAdapter1(adapterNumber); Device device = new Device(adapter); throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsAdapter" /> class. /// </summary> /// <param name="adapterOrdinal">The adapter ordinal.</param> private GraphicsAdapter(int adapterOrdinal) { this.adapterOrdinal = adapterOrdinal; adapter = ToDispose(defaultFactory.GetAdapter1(adapterOrdinal)); Description = adapter.Description1; var outputs = adapter.Outputs; outputs1 = new GraphicsOutput[outputs.Length]; for (var i = 0; i < outputs.Length; i++) { outputs1[i] = ToDispose(new GraphicsOutput(this, outputs[i])); } }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsAdapter" /> class. /// </summary> /// <param name="defaultFactory">The default factory.</param> /// <param name="adapterOrdinal">The adapter ordinal.</param> internal GraphicsAdapter(Factory1 defaultFactory, int adapterOrdinal) { this.adapterOrdinal = adapterOrdinal; adapter = defaultFactory.GetAdapter1(adapterOrdinal).DisposeBy(this); description = adapter.Description1; //var nativeOutputs = adapter.Outputs; var count = adapter.GetOutputCount(); outputs = new GraphicsOutput[count]; for (var i = 0; i < outputs.Length; i++) { outputs[i] = new GraphicsOutput(this, i).DisposeBy(this); } }
public DirectScreenshot(GPGPU gpu, int screenWidth, int screenHeight) { OutputFileName = "ScreenCapture.bmp"; const int numAdapter = 0; const int numOutput = 0; _gpu = gpu; rgbValues = gpu.Allocate <GPUColorBGRA>(screenWidth * screenHeight); // Create DXGI Factory1 factory = new Factory1(); adapter = factory.GetAdapter1(numAdapter); // Create device from Adapter device = new Device(adapter); // Get DXGI.Output output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture width = screenWidth; height = screenHeight; // Create Staging texture CPU-accessible textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); // Duplicate the output duplicatedOutput = output1.DuplicateOutput(device); var screenResource = BeginCapture(out var pp); screenResource.Dispose(); duplicatedOutput.ReleaseFrame(); }
/// <summary> /// Init some variables one times to spend execution time. /// </summary> public DirectX() { try { factory = new Factory1(); adapter = factory.GetAdapter1(numAdapter); device = new Device(adapter); output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // get screen wize textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Right - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Left, Height = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Bottom - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Top, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); try { duplicatedOutput = output1.DuplicateOutput(device); } catch (SharpDXException e) { if (e.ResultCode.Code == SharpDX.DXGI.ResultCode.Unsupported.Result.Code) { throw new System.ApplicationException("Your system does not support DirectX 11.2 (normally on windows 7). Please use 'Use GDI Capture' option to prevent this error!"); } else { throw e; } } } catch (Exception ex) { throw ex; } }
/*Multi-Thread Variable*/ /// <summary> /// Create LocalCapture to capture screen (by DXGI.) /// </summary> /// <param name="bitmapBuffer">Communication pipe with other threads. It stores some processing Mat and some unused Mat</param> /// <param name="numOutput"># of output device (i.e. monitor).</param> /// <param name="numAdapter"># of output adapter (i.e. iGPU). </param> public LocalCapture(BitmapBuffer bitmapBuffer, int numOutput = 0, int numAdapter = 0) { // Create DXGI Factory1 factory = new Factory1(); adapter = factory.GetAdapter1(numAdapter); // Create device from Adapter device = new Device(adapter); // Get DXGI.Output output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture width = ((Rectangle)output.Description.DesktopBounds).Width; height = ((Rectangle)output.Description.DesktopBounds).Height; // Create Staging texture CPU-accessible textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); // Duplicate the output duplicatedOutput = output1.DuplicateOutput(device); //Create enough UnusedMat for (int i = 0; i < PreCreateMatCount; ++i) { bitmapBuffer.PushUnusedMat(CreateSuitableMat()); } //Save the buffer this.bitmapBuffer = bitmapBuffer; }
private void Init() { // # of graphics card adapter const int numAdapter = 0; // # of output device (i.e. monitor) const int numOutput = 0; // Create DXGI Factory1 var factory = new Factory1(); Adapter1 adapter = factory.GetAdapter1(numAdapter); // Create device from Adapter device = new Device(adapter); // Get DXGI.Output Output output = adapter.GetOutput(numOutput); var output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture width = output.Description.DesktopBounds.Width; height = output.Description.DesktopBounds.Height; // Create Staging screenTexture CPU-accessible textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; outputDescription = output.Description; // Demo the output duplicatedOutput = output1.DuplicateOutput(device); screenTexture = new Texture2D(device, textureDesc); }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsAdapter" /> class. /// </summary> /// <param name="defaultFactory">The default factory.</param> /// <param name="adapterOrdinal">The adapter ordinal.</param> internal GraphicsAdapter(Factory1 defaultFactory, int adapterOrdinal) { this.adapterOrdinal = adapterOrdinal; adapter = defaultFactory.GetAdapter1(adapterOrdinal).DisposeBy(this); description = adapter.Description1; description.Description = description.Description.TrimEnd('\0'); // for some reason sharpDX returns an adaptater name of fixed size filled with trailing '\0' //var nativeOutputs = adapter.Outputs; var count = adapter.GetOutputCount(); outputs = new GraphicsOutput[count]; for (var i = 0; i < outputs.Length; i++) { outputs[i] = new GraphicsOutput(this, i).DisposeBy(this); } AdapterUid = adapter.Description1.Luid.ToString(); }
private Tuple <int, int>[] GetCapturedOutputs() { var ret = new List <Tuple <int, int> >(6);//most cases for (var adapterIndex = _factory.GetAdapterCount1() - 1; adapterIndex >= 0; adapterIndex--) { using (var adapter = _factory.GetAdapter1(adapterIndex)) for (var outputIndex = adapter.GetOutputCount() - 1; outputIndex >= 0; outputIndex--) { using (var output = adapter.GetOutput(outputIndex)) if (output.Description.DesktopBounds.ToGDIRect().IntersectsWith(_sourceRect.Value)) { ret.Add(new Tuple <int, int>(adapterIndex, outputIndex)); } } } return(ret.ToArray()); }
public CompressScreen(bool _dxMode) { this.screenBounds = Screen.PrimaryScreen.Bounds; prev = new Bitmap(screenBounds.Width, screenBounds.Height, PixelFormat.Format32bppArgb); cur = new Bitmap(screenBounds.Width, screenBounds.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(prev)) { g.Clear(Color.Black); } compressionBuffer = new byte[screenBounds.Width * screenBounds.Height * 4]; int backBufSize = LZ4.LZ4Codec.MaximumOutputLength(compressionBuffer.Length) + 4; compressedScreen = new CompressedScreen(backBufSize); //directX Constructor if (_dxMode == true) { factory = new Factory1(); adapter = factory.GetAdapter1(0); device = new SharpDX.Direct3D11.Device(adapter); output = adapter.GetOutput(0); output1 = output.QueryInterface <Output1>(); textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = screenBounds.Width, Height = screenBounds.Height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); duplicatedOutput = output1.DuplicateOutput(device); } }
public DXSnapperInput(Factory1 factory, int adapterIndex, int outputIndex, Rectangle captureRectangle) { _adapter = factory.GetAdapter1(adapterIndex); _device = new SharpDX.Direct3D11.Device(_adapter); _output = _adapter.GetOutput(outputIndex); var outputBounds = _output.Description.DesktopBounds.ToGDIRect(); var intersection = Rectangle.Intersect(outputBounds, captureRectangle); if (intersection.IsEmpty) { Dispose(); throw new ArgumentOutOfRangeException(nameof(captureRectangle), $"Output {outputIndex} for adapter {adapterIndex} {FormatRectangle(outputBounds)} doesn't intersect with capture rectangle {FormatRectangle(captureRectangle)}"); } _textureDescription = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = sourcePixelFormat, Height = outputBounds.Height, Width = outputBounds.Width, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging, }; _screenTexture = new Texture2D(_device, _textureDescription); _output1 = _output.QueryInterface <Output1>(); _duplicatedOutput = _output1.DuplicateOutput(_device); _destXOffset = intersection.Left - captureRectangle.Left; _destYOffset = intersection.Top - captureRectangle.Top; _sourceXOffset = intersection.Left - outputBounds.Left; _sourceYOffset = intersection.Top - outputBounds.Top; _width = intersection.Width; _height = intersection.Height; }
public GxContext(RenderControl window) { mWindow = window; mFactory = new Factory1(); if (mFactory.Adapters1.Length == 0) { throw new InvalidOperationException( "Sorry, but DirectX returned that there is no graphics card installed on your system. Please check if all your drivers are up to date!"); } Adapter = mFactory.GetAdapter1(0); if (Adapter.Outputs.Length == 0) { throw new InvalidOperationException( "Sorry, but DirectX returned that there is no output (monitor) assigned to the graphics card: \"" + Adapter.Description.Description + "\". Please check if your drivers are OK and if your graphics card and monitor show up in the device manager."); } mOutput = Adapter.Outputs[0]; }
private static void QueryAdapters() { var adapt = new Dictionary <string, string>(); var displ = new Dictionary <string, List <string> >(); using (var factory = new Factory1()) { var acount = factory.GetAdapterCount1(); for (var i = 0; i < acount; i++) { using (var adapter = factory.GetAdapter1(i)) { var adesc = adapter.Description1; if (adesc.Flags.HasFlag(AdapterFlags.Software)) { continue; } var disp = new List <string>(); displ.Add(adesc.DeviceId.ToString(), disp); adapt.Add(adesc.DeviceId.ToString(), adesc.Description); var ocount = adapter.GetOutputCount(); for (var j = 0; j < ocount; j++) { using (var output = adapter.GetOutput(i)) { var odesc = output.Description; var width = odesc.DesktopBounds.Right - odesc.DesktopBounds.Left; var height = odesc.DesktopBounds.Bottom - odesc.DesktopBounds.Top; disp.Add($"{odesc.DeviceName} ({width} x {height})"); } } } } } adapters = adapt; displays = displ; }
/// <summary> /// デバイスの初期化処理 /// </summary> /// <param name="control">適用するコントロールへの参照</param> public void Load(bool needDX11 = false, DeviceCreationFlags dx11flag = DeviceCreationFlags.None, SlimDX.Direct3D10.DeviceCreationFlags dx10flag_for2DDraw = SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport) { ApplyDebugFlags(ref dx11flag, ref dx10flag_for2DDraw); Factory = new Factory1(); CurrentAdapter = Factory.GetAdapter1(0); //スワップチェーンの初期化 try { Device = new Device(CurrentAdapter, dx11flag, new[] { FeatureLevel.Level_11_0 }); } catch (Direct3D11Exception) { if (needDX11) { throw new NotSupportedException("DX11がサポートされていません。DX10.1で初期化するにはLoadの第一引数needDraw=falseとして下さい。"); } try { Device = new Device(CurrentAdapter, dx11flag, new[] { FeatureLevel.Level_10_0 }); } catch (Direct3D11Exception) { throw new NotSupportedException("DX11,DX10.1での初期化を試みましたが、両方ともサポートされていません。"); } } DeviceFeatureLevel = Device.FeatureLevel; Context = Device.ImmediateContext; SampleDescription sampleDesc = new SampleDescription(1, 0); #if VSG_DEBUG #else Device10 = new Device1(CurrentAdapter, DriverType.Hardware, dx10flag_for2DDraw, SlimDX.Direct3D10_1.FeatureLevel.Level_9_3); #endif MMEEffectManager.IniatializeMMEEffectManager(this); }
public DXScreenCapture() { // Create DXGI Factory1 if (device == null) { factory = new Factory1(); adapter = factory.GetAdapter1(numAdapter); // Create device from Adapter device = new Device(adapter); } if (output1 == null) { // Get DXGI.Output var output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // Duplicate the output duplicatedOutput = output1.DuplicateOutput(device); } // Create Staging texture CPU-accessible textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); }
internal static Adapter1 GetAdapter(int deviceId) { using (var factory = new Factory1()) { var count = factory.GetAdapterCount1(); Adapter1 adapter = null; for (var i = 0; i < count; i++) { try { adapter = factory.GetAdapter1(i); if (adapter.Description1.DeviceId == deviceId) { return(adapter); } adapter.Dispose(); } catch { adapter?.Dispose(); } } } throw new ArgumentException($"Invalid adapter {deviceId}"); }
private void Init() { var factory = new Factory1(); // change index to adjust which GPU to use // factory.Adapters1 will return an array of adapters Adapter = factory.GetAdapter1(0); Device = new Device(Adapter); // change index to adjust which monitor to use // adapter.Outputs lists possible outputs // adapter.GetOutputCount() number of outputs var output = Adapter.GetOutput(0); var output1 = output.QueryInterface <Output1>(); var bounds = output.Description.DesktopBounds; DisplayBounds = Rectangle.FromLTRB(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); _duplicateOutput = output1.DuplicateOutput(Device); GetOutputAsBitmap(100).Dispose(); }