/// <summary> /// Initializes all adapters with the specified factory. /// </summary> internal static void InitializeInternal() { staticCollector.Dispose(); #if DIRECTX11_1 using (var factory = new Factory1()) NativeFactory = factory.QueryInterface <Factory2>(); #elif STRIDE_PLATFORM_UWP // Maybe this will become default code for everybody if we switch to DX 11.1/11.2 SharpDX dll? NativeFactory = new Factory2(); #else NativeFactory = new Factory1(); #endif staticCollector.Add(NativeFactory); int countAdapters = NativeFactory.GetAdapterCount1(); var adapterList = new List <GraphicsAdapter>(); for (int i = 0; i < countAdapters; i++) { var adapter = new GraphicsAdapter(NativeFactory, i); staticCollector.Add(adapter); adapterList.Add(adapter); } defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null; adapters = adapterList.ToArray(); }
private static SwapChain3 CreateSwapChain( IntPtr windowHandle, D3D12.CommandQueue commandQueue, PixelFormat backBufferFormat, int backBufferCount, int width, int height) { var swapChainDescription = new SwapChainDescription1 { Width = width, Height = height, Format = backBufferFormat.ToDxgiFormat(), Stereo = false, SampleDescription = new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, Scaling = Scaling.Stretch, BufferCount = backBufferCount, SwapEffect = SwapEffect.FlipSequential, Flags = SwapChainFlags.None }; #if DEBUG const bool debug = true; #else const bool debug = false; #endif using (var dxgiFactory = new Factory2(debug)) using (var tempSwapChain = new SwapChain1(dxgiFactory, commandQueue, windowHandle, ref swapChainDescription)) { return(tempSwapChain.QueryInterface <SwapChain3>()); } }
void CreateSwapChain() { SwapChainDescription1 swapChainDescription = new SwapChainDescription1() { Usage = Usage.RenderTargetOutput, BufferCount = 2, SwapEffect = SwapEffect.FlipSequential, Stereo = false, SampleDescription = new SampleDescription(1, 0), Scaling = Scaling.Stretch, Format = Format.R8G8B8A8_UNorm, Height = 1080, Width = 1920, }; // 建立SwapChain using (SharpDX.DXGI.Device3 dxgiDevice3 = D3D11Device.QueryInterface <SharpDX.DXGI.Device3>()) { using (Factory2 dxgiFactory2 = dxgiDevice3.Adapter.GetParent <Factory2>()) { swapChain1 = new SwapChain1(dxgiFactory2, D3D11Device, ref swapChainDescription); swapChain1.QueryInterface <SwapChain>(); } } // 把Xaml的SwapChainPanel與DirectX的SwapChain連結起來 using (ISwapChainPanelNative swapChainPanelNative = ComObject.As <ISwapChainPanelNative>(this)) { swapChainPanelNative.SwapChain = swapChain1; SetViewport(); } }
public void GetNumberOfAvailableCyborgs_single_own_troop( int numberOfCyborgsInFactory, int numberOfCyborgsInOwnTroop, int expectedAvailableCyborgs) { var factory1 = new Factory2(Factory1Id) { NumberOfCyborgs = numberOfCyborgsInFactory }; var state = new State { Factories = new List <Factory2> { factory1 }, Troops = new List <Troop2> { new Troop2(Troop1Id) { Destination = Factory1Id, NumberOfCyborgs = numberOfCyborgsInOwnTroop, Owner = Owner2.Own } } }; Assert.Equal( expectedAvailableCyborgs, _robot.GetNumberOfAvailableCyborgs(factory1, state)); }
/// <summary> /// Initializes all adapters with the specified factory. /// </summary> internal static void InitializeInternal() { staticCollector.Dispose(); #if DIRECTX11_1 using (var factory = new Factory1()) NativeFactory = factory.QueryInterface <Factory2>(); #else NativeFactory = new Factory1(); #endif staticCollector.Add(NativeFactory); int countAdapters = NativeFactory.GetAdapterCount1(); var adapterList = new List <GraphicsAdapter>(); for (int i = 0; i < countAdapters; i++) { var adapter = new GraphicsAdapter(NativeFactory, i); staticCollector.Add(adapter); adapterList.Add(adapter); } defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null; adapters = adapterList.ToArray(); }
public void Initialize(Device2 device, IntPtr hwnd, CompositionType compositionType, Size2 size) { if (Device != null) { Dispose(); } Device = device; Adapter = Device.GetParent <Adapter>(); Factory = Adapter.GetParent <Factory2>(); var swapChainDescription = new SwapChainDescription1 { SampleDescription = new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, BufferCount = 2, SwapEffect = GetBestSwapEffectForPlatform(), Scaling = Scaling.Stretch, Format = Format.B8G8R8A8_UNorm, AlphaMode = compositionType.HasFlag(CompositionType.Composited) ? AlphaMode.Premultiplied : AlphaMode.Ignore, Width = size.Width, Height = size.Height }; SwapChain = compositionType.HasFlag(CompositionType.Composited) ? new SwapChain1(Factory, Device, ref swapChainDescription) : new SwapChain1(Factory, Device, hwnd, ref swapChainDescription); }
public void GetNumberOfAvailableCyborgs_single_enemy_troop( int numberOfCyborgsInFactory, int factoryProduction, int numberOfCyborgsInEnemyTroop, int enemyTroopRemainingTravelTime, int expectedAvailableCyborgs) { var factory1 = new Factory2(Factory1Id) { NumberOfCyborgs = numberOfCyborgsInFactory, Production = factoryProduction }; var state = new State { Factories = new List <Factory2> { factory1 }, Troops = new List <Troop2> { new Troop2(Troop1Id) { Destination = Factory1Id, NumberOfCyborgs = numberOfCyborgsInEnemyTroop, Owner = Owner2.Opponent, RemainingTravelTime = enemyTroopRemainingTravelTime } } }; Assert.Equal( expectedAvailableCyborgs, _robot.GetNumberOfAvailableCyborgs(factory1, state)); }
public void FindTargets_orders_factories_by_distance() { var expectedCloseFactory = new Factory2(Factory2Id) { Owner = Owner2.Neutral, Production = 1, Distances = new Dictionary <int, int> { { Factory1Id, 1 } } }; const int factory3Id = 2; var expectedFarFactory = new Factory2(factory3Id) { Owner = Owner2.Neutral, Production = 1, Distances = new Dictionary <int, int> { { Factory1Id, 2 } } }; _state.Factories.Add(expectedFarFactory); _state.Factories.Add(expectedCloseFactory); var targets = _robot.FindTargets(_originFactory, _state); var closeFactory = targets[0]; Assert.Equal(expectedCloseFactory, closeFactory); var farFactory = targets[1]; Assert.Equal(expectedFarFactory, farFactory); }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = display; _window = window; _vsync = vsync; FeatureLevel[] features = { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0 }; SharpDX.Direct3D11.Device dev11 = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.None, features); _dev = dev11.QueryInterfaceOrNull <SharpDX.Direct3D11.Device1>(); SampleDescription sampleDesc = new SampleDescription(); do { if (_dev.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, (int)samples) > 0) { sampleDesc.Count = (int)samples; sampleDesc.Quality = 0; break; } else { samples >>= 1; } } while (samples > 0); SwapChainDescription1 desc = new SwapChainDescription1(); desc.Width = 0; desc.Height = 0; desc.Format = sRGB ? Format.R8G8B8A8_UNorm_SRgb : Format.R8G8B8A8_UNorm; desc.Scaling = Scaling.None; desc.SampleDescription = sampleDesc; desc.Usage = Usage.RenderTargetOutput; desc.BufferCount = 2; desc.SwapEffect = SwapEffect.FlipSequential; desc.Flags = SwapChainFlags.None; SharpDX.DXGI.Device2 dev = _dev.QueryInterface <SharpDX.DXGI.Device2>(); Adapter adapter = dev.Adapter; Factory2 factory = adapter.GetParent <Factory2>(); if (display == IntPtr.Zero) { GCHandle handle = (GCHandle)window; SharpDX.ComObject coreWindow = new SharpDX.ComObject(handle.Target as object); _swapChain = new SwapChain1(factory, _dev, coreWindow, ref desc); } else { _swapChain = new SwapChain1(factory, _dev, window, ref desc); } _device = new RenderDeviceD3D11(_dev.ImmediateContext.NativePointer, sRGB); }
public void setFactory2(Factory2 factory2) { if (this.mFactory2 == null) { this.mFactory2 = factory2; } }
private void Application_SlideShowBegin(SlideShowWindow Wn) { if (!PresentationToNDIAddIn.Properties.Settings.Default.NDIDynamic) { return; } _window = Wn; _wasFullscreenBefore = IsFullscreen; _xOrig = Wn.Presentation.SlideMaster.Width; _yOrig = Wn.Presentation.SlideMaster.Height; _device = Direct3D11Helper.CreateDevice(!PresentationToNDIAddIn.Properties.Settings.Default.UseHw); _d3dDevice = Direct3D11Helper.CreateSharpDXDevice(_device); _factory = new Factory2(); _item = GetItem(); CreateCaptureItemDependendStuff(); _ndiSender = new Thread(SendNdi) { Priority = ThreadPriority.Normal, Name = "DynamicNdiSenderThread", IsBackground = true }; _ndiSender.Start(); }
public BackBuffer(Factory2 factory, Device1 device1, RenderForm renderForm) { swapChainDescription1 = new SwapChainDescription1() { Width = renderForm.ClientSize.Width, Height = renderForm.ClientSize.Height, Format = Format.R8G8B8A8_UNorm, Stereo = false, SampleDescription = new SampleDescription(4, 0), Usage = Usage.RenderTargetOutput, BufferCount = 1, SwapEffect = SwapEffect.Discard, Flags = SwapChainFlags.AllowModeSwitch, }; SwapChain = new SwapChain1(factory, device1, renderForm.Handle, ref swapChainDescription1, new SwapChainFullScreenDescription() { RefreshRate = new Rational(60, 1), Scaling = DisplayModeScaling.Centered, Windowed = true }, null); BackBufferTexture = Resource.FromSwapChain <Texture2D>(SwapChain, 0); }
static void Main(string[] args) { AbstractFactory factory1 = new Factory1(); factory1.Run(); AbstractFactory factory2 = new Factory2(); factory2.Run(); }
public ScreenGrabberWindowsCapture(MonitorInfo screen) : base(screen) { Application.Current.Dispatcher.Invoke(() => { var device = WindowsCaptureHelper.CreateDirect3DDeviceFromSharpDXDevice(new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport)); _d3dDevice = WindowsCaptureHelper.CreateSharpDXDevice(device); var item = WindowsCaptureHelper.CreateItemForMonitor(Screen.HMon); var factory = new Factory2(); var description = new SwapChainDescription1 { Width = item.Size.Width, Height = item.Size.Height, Format = Format.B8G8R8A8_UNorm, Stereo = false, SampleDescription = new SampleDescription { Count = 1, Quality = 0 }, Usage = Usage.RenderTargetOutput, BufferCount = 2, Scaling = Scaling.Stretch, SwapEffect = SwapEffect.FlipSequential, AlphaMode = AlphaMode.Premultiplied, Flags = SwapChainFlags.None }; _swapChain = new SwapChain1(factory, _d3dDevice, ref description); _framePool = Direct3D11CaptureFramePool.Create(device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size); _session = _framePool.CreateCaptureSession(item); _session.IsCursorCaptureEnabled = false; _swapChain.ResizeBuffers(2, item.Size.Width, item.Size.Height, Format.B8G8R8A8_UNorm, SwapChainFlags.None); _screenTexture = new Texture2D(_d3dDevice, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = item.Size.Width, Height = item.Size.Height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }); _framePool.FrameArrived += OnFrameArrived; _session.StartCapture(); }); }
private static void CovarianceDelegates() { Factory1 <DerivedExample> derivedTypeFactoryM1E1 = MakeDerivedInstance; // covariance enables this assignment Factory1 <BaseExample> baseTypeFactoryM1E1 = derivedTypeFactoryM1E1; Factory1 <BaseExample> baseTypeFactoryM1E2 = MakeDerivedInstance; BaseExampleFactory baseExampleFactory = MakeDerivedInstance; Factory2 <DerivedExample> derivedTypeFactoryM2E1 = MakeDerivedInstance; // error //Factory2<BaseExample> baseTypeFactoryM2E1 = derivedTypeFactoryM2E1; }
public FindTargetsTests() { _robot = new Robot(null); _originFactory = new Factory2(Factory1Id) { Owner = Owner2.Own }; _state = new State { Factories = new List <Factory2> { _originFactory } }; }
public void FindTargets_single_factory_no_link_returns_no_target(Owner2 owner) { var factory = new Factory2(Factory2Id) { Owner = owner, Production = 1, Distances = new Dictionary <int, int>() }; _state.Factories.Add(factory); var targets = _robot.FindTargets(_originFactory, _state); Assert.Empty(targets); }
private static void ClassHierarchyTest() { var vegetables = new Factory1(); var fruits = new Factory2(); var clientA = new Client <Factory1>(); var clientB = new Client <Factory2>(); Console.WriteLine(clientA.ImportProduct()); Console.WriteLine(clientA.ExportProduct()); Console.WriteLine(new string('-', 30)); Console.WriteLine(clientB.ImportProduct()); Console.WriteLine(clientB.ExportProduct()); }
private void btnAbstractFactory_Click(object sender, EventArgs e) { txtResult.Text = "ABSTRACT FACTORY Pattern" + Environment.NewLine; IFactory factory = new Factory1(); txtResult.Text += "Factory 1:" + Environment.NewLine; txtResult.Text += factory.getCar().getMerke() + Environment.NewLine; txtResult.Text += factory.getBike().getSize().ToString() + Environment.NewLine; txtResult.Text += Environment.NewLine; txtResult.Text += "Factory 2:" + Environment.NewLine; factory = new Factory2(); txtResult.Text += factory.getCar().getMerke() + Environment.NewLine; txtResult.Text += factory.getBike().getSize().ToString() + Environment.NewLine; }
public void UpdateState_updates_factory() { const int entityCount = 1; const int factory1Id = 0; const int factory2Id = 1; const int distance = 1; const Owner2 factoryOwner = Owner2.Own; const int numberOfCyborgs = 10; const int production = 1; const int turnsUntilProducing = 0; var previousFactory = new Factory2(factory1Id) { Distances = new Dictionary <int, int>() { { factory2Id, distance } } }; var previousState = new State { Factories = new List <Factory2> { previousFactory } }; _consoleMock .SetupSequence(c => c.ReadLine()) .Returns($"{entityCount}") .Returns($"{factory1Id} " + $"{FactoryEntityType} " + $"{(int) factoryOwner} " + $"{numberOfCyborgs} " + $"{production} " + $"{turnsUntilProducing}"); var state = _robot.UpdateState(previousState); var factory1 = state.Factories[factory1Id]; Assert.Equal(factory1Id, factory1.Id); Assert.Equal(factoryOwner, factory1.Owner); Assert.Equal(numberOfCyborgs, factory1.NumberOfCyborgs); Assert.Equal(previousFactory.Distances, factory1.Distances); Assert.Equal(production, factory1.Production); Assert.Equal(turnsUntilProducing, factory1.TurnsUntilProducing); }
public void FindTargets_no_production_factory_returns_no_target() { var factory = new Factory2(Factory2Id) { Owner = Owner2.Neutral, Production = 0, Distances = new Dictionary <int, int> { { Factory1Id, 1 } } }; _state.Factories.Add(factory); var targets = _robot.FindTargets(_originFactory, _state); Assert.Empty(targets); }
public void FindTargets_single_own_factory_with_link_returns_no_target() { var ownFactory = new Factory2(Factory2Id) { Owner = Owner2.Own, Production = 1, Distances = new Dictionary <int, int> { { Factory1Id, 1 } } }; _state.Factories.Add(ownFactory); var targets = _robot.FindTargets(_originFactory, _state); Assert.Empty(targets); }
public ScreenCapture(GraphicsCaptureItem i) { item = i; device = Direct3D11Helper.CreateDevice(); d3dDevice = Direct3D11Helper.CreateSharpDXDevice(device); SizeInt32 correctedSize = item.Size; correctedSize.Width = correctedSize.Width / 8 * 8; correctedSize.Height = correctedSize.Height / 8 * 8; var dxgiFactory = new Factory2(); var description = new SwapChainDescription1() { Width = correctedSize.Width, Height = correctedSize.Height, Format = Format.B8G8R8A8_UNorm, Stereo = false, SampleDescription = new SampleDescription() { Count = 1, Quality = 0 }, Usage = Usage.RenderTargetOutput, BufferCount = 2, Scaling = Scaling.Stretch, SwapEffect = SwapEffect.FlipSequential, AlphaMode = AlphaMode.Premultiplied, Flags = SwapChainFlags.None }; swapChain = new SwapChain1(dxgiFactory, d3dDevice, ref description); framePool = Direct3D11CaptureFramePool.Create( device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, correctedSize); session = framePool.CreateCaptureSession(i); lastSize = correctedSize; framePool.FrameArrived += OnFrameArrived; }
public void GetNumberOfAvailableCyborgs_no_troops(int numberOfCyborgsInFactory, int expectedAvailableCyborgs) { var factory1 = new Factory2(Factory1Id) { NumberOfCyborgs = numberOfCyborgsInFactory }; var state = new State { Factories = new List <Factory2> { factory1 }, Troops = new List <Troop2>() }; Assert.Equal( expectedAvailableCyborgs, _robot.GetNumberOfAvailableCyborgs(factory1, state)); }
public void ScalarWithTwoArgument() { Factory2 factory2 = null; Assert.DoesNotThrow(() => factory2 = new Factory2()); IFunction function = null; var args = new DataObject[] {DataObject.BigInt(2), DataObject.Number(new SqlNumber(54))}; Assert.DoesNotThrow(() => function = factory2.ResolveFunction("add2", args)); Assert.IsNotNull(function); ExecuteResult result = null; Assert.DoesNotThrow(() => result = function.Execute(args)); Assert.IsNotNull(result); Assert.IsInstanceOf<SqlNumber>(result.ReturnValue.Value); var value = ((SqlNumber) result.ReturnValue.Value).ToInt64(); Assert.AreEqual(56, value); }
public void FindTargets_single_factory_link_returns_target(Owner2 owner) { var factory = new Factory2(Factory2Id) { Owner = owner, Production = 1, Distances = new Dictionary <int, int> { { Factory1Id, 1 } } }; _state.Factories.Add(factory); var targets = _robot.FindTargets(_originFactory, _state); var target = Assert.Single(targets); Assert.Equal(factory, target); }
public void ScalarWithTwoArgument() { Factory2 factory2 = null; Assert.DoesNotThrow(() => factory2 = new Factory2()); IFunction function = null; var args = new DataObject[] { DataObject.BigInt(2), DataObject.Number(new SqlNumber(54)) }; Assert.DoesNotThrow(() => function = factory2.ResolveFunction("add2", args)); Assert.IsNotNull(function); InvokeResult result = null; Assert.DoesNotThrow(() => result = function.Execute(args)); Assert.IsNotNull(result); Assert.IsInstanceOf <SqlNumber>(result.ReturnValue.Value); var value = ((SqlNumber)result.ReturnValue.Value).ToInt64(); Assert.AreEqual(56, value); }
public Registration Register(string name, Factory2 factory) { return null; }
protected override SwapChain1 CreateSwapChain(Factory2 dxgiFactory, SwapChainDescription1 swapChainDesc) { return(new SwapChain1(dxgiFactory, DxgiDevice, _window.Handle, ref swapChainDesc)); }
public void CreateDirectXSwapChain(Adapter adapter) { var desc = adapter.Description; Debug.WriteLine(desc.Description); Debug.WriteLine($"vender = {desc.VendorId:X4}"); Debug.WriteLine($"Shared Memory: {desc.SharedSystemMemory} bytes"); Debug.WriteLine($"Video Memory: {desc.DedicatedVideoMemory} bytes"); Debug.WriteLine($"device: {desc.DeviceId}"); FeatureLevel[] featureLevels = new FeatureLevel[] { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, }; D3D11Device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport, featureLevels); SwapChainDescription1 swapChainDescription = new SwapChainDescription1() { // Double buffer. BufferCount = 2, // BGRA 32bit pixel format. Format = Format.B8G8R8A8_UNorm, // Unlike in CoreWindow swap chains, the dimensions must be set. Height = (int)(ActualHeight), Width = (int)(ActualWidth), // Default multisampling. SampleDescription = new SampleDescription(1, 0), // In case the control is resized, stretch the swap chain accordingly. Scaling = Scaling.Stretch, // No support for stereo display. Stereo = false, // Sequential displaying for double buffering. SwapEffect = SwapEffect.FlipSequential, // This swapchain is going to be used as the back buffer. Usage = Usage.BackBuffer | Usage.RenderTargetOutput, }; // 建立SwapChain using (SharpDX.DXGI.Device3 dxgiDevice3 = D3D11Device.QueryInterface <SharpDX.DXGI.Device3>()) { using (Factory2 dxgiFactory2 = dxgiDevice3.Adapter.GetParent <Factory2>()) { using (SwapChain1 swapChain1 = new SwapChain1(dxgiFactory2, D3D11Device, ref swapChainDescription)) { swapChain = swapChain1.QueryInterface <SwapChain>(); } } } // 把Xaml的SwapChainPanel與DirectX的SwapChain連結起來 using (ISwapChainPanelNative swapChainPanelNative = ComObject.As <ISwapChainPanelNative>(this)) { swapChainPanelNative.SwapChain = swapChain; } backBuffer = SharpDX.Direct3D11.Resource.FromSwapChain <Texture2D>(swapChain, 0); var renderTarget = new RenderTargetView(D3D11Device, backBuffer); context = D3D11Device.ImmediateContext; // Clear Screen to Teel Blue. context.ClearRenderTargetView(renderTarget, new Color(0xFF887536)); swapChain.Present(1, PresentFlags.None); }
public Factory5(Factory2 <T> factory) => Factory = factory;
public IPair <S1, S2> Repeat(IPair <E1, E2> e, IPair <S1, S2> s) { return(new Pair <S1, S2>(Factory1.Repeat(e.Item1, s.Item1), Factory2.Repeat(e.Item2, s.Item2))); }