示例#1
0
		public D3D11_2D1(Device11 drawdevice, Device10 textdevice)
			: base(false) // nothing!
		{
			if (drawdevice == null || textdevice == null)
			{
				using (var dg = new DisposeGroup())
				{
					if (drawdevice == null && textdevice == null)
					{
						Adapter a = null;
						foreach (var item in DeviceUtil.GetAdapters(dg))
						{
							if (!item.IsInterfaceSupported<Device10>())
								continue;
							if (Device11.GetSupportedFeatureLevel(item) < Direct3D.FeatureLevel.Level_10_1)
								continue;
							a = item;
							break;
						}
						device = new Device11(a, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.Debug);
						device10 = new Device10(a, Direct3D10.DeviceCreationFlags.BgraSupport | Direct3D10.DeviceCreationFlags.Singlethreaded | Direct3D10.DeviceCreationFlags.Debug);
					}
					else
					{
						if (drawdevice == null)
						{
							using (var xgidtext = textdevice.QueryInterface<DeviceXGI>())
								device = new Device11(xgidtext.Adapter, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.Debug);
							textdevice.AddReference();
							device10 = textdevice;
						}
						else
						{
							using (var xgiddraw = drawdevice.QueryInterface<DeviceXGI>())
								device10 = new Device10(xgiddraw.Adapter, Direct3D10.DeviceCreationFlags.BgraSupport | Direct3D10.DeviceCreationFlags.Singlethreaded | Direct3D10.DeviceCreationFlags.Debug);
							drawdevice.AddReference();
							device = drawdevice;
						}
					}
				}
			}
			else
			{
				using (var xgidev10 = device10.QueryInterface<DeviceXGI>())
				using (var xgidev11 = device.QueryInterface<DeviceXGI>())
				{
					if (xgidev10.Adapter.NativePointer != xgidev11.Adapter.NativePointer)
						throw new ArgumentException("drawdevice.Adapter.NativePointer != textdevice.Adapter.NativePointer");
				}
				textdevice.AddReference();
				drawdevice.AddReference();
				device = drawdevice;
				device10 = textdevice;
			}

			factory2D = new SharpDX.Direct2D1.Factory();
			factoryDW = new FactoryDW();
		}