Beispiel #1
0
		protected void CreateD3D9Device()
		{
			// Update focus window.
			var primaryRenderWindow = PrimaryWindow;

			// Case we have to share the same focus window.
			this._focusWindow = SharedFocusWindow != IntPtr.Zero ? SharedFocusWindow : primaryRenderWindow.WindowHandle;

			var pD3D9 = D3D9RenderSystem.Direct3D9;

			if ( IsMultihead )
			{
				this.BehaviorFlags |= D3D9.CreateFlags.AdapterGroupDevice;
			}
			else
			{
				this.BehaviorFlags &= ~D3D9.CreateFlags.AdapterGroupDevice;
			}

			// Try to create the device with hardware vertex processing.
			this.BehaviorFlags |= D3D9.CreateFlags.HardwareVertexProcessing;

			var keepTrying = true;
			var loopCount = 0;

			LogManager.Instance.Write( "Creating D3D9 Device..." );
			while ( keepTrying )
			{
				try
				{
					this.pDevice = new D3D9.Device( pD3D9, AdapterNumber, DeviceType, this._focusWindow, this.BehaviorFlags,
					                                this.PresentationParams );
					keepTrying = false;
				}
				catch ( DX.SharpDXException ex )
				{
					LogManager.Instance.Write( "FAIL!" );
					switch ( loopCount )
					{
						case 0:
							// Try a second time, may fail the first time due to back buffer count,
							// which will be corrected down to 1 by the runtime
							LogManager.Instance.Write( "Trying to create the device a second time.." );
							break;

						case 1:
							// Case hardware vertex processing failed.
							// Try to create the device with mixed vertex processing.
							this.BehaviorFlags &= ~D3D9.CreateFlags.HardwareVertexProcessing;
							this.BehaviorFlags |= D3D9.CreateFlags.MixedVertexProcessing;
							LogManager.Instance.Write( "Trying to create the device with mixed vertex processing.." );
							break;

						case 2:
							// try to create the device with software vertex processing.
							this.BehaviorFlags &= ~D3D9.CreateFlags.MixedVertexProcessing;
							this.BehaviorFlags |= D3D9.CreateFlags.SoftwareVertexProcessing;
							LogManager.Instance.Write( "Trying to create the device with software vertex processing.." );
							break;

						case 3:
							// try reference device
							DeviceType = D3D9.DeviceType.Reference;
							LogManager.Instance.Write( "Trying to create a reference device.." );
							break;

						default:
							throw new AxiomException( "Cannot create device!", ex );
					}
					;

					loopCount++;
				}
			}
			;

			// Get current device caps.
			this.d3d9DeviceCaps = this.pDevice.Capabilities;

			// Get current creation parameters caps.
			this.creationParams = this.pDevice.CreationParameters;

			this.D3D9DeviceCapsValid = true;

			// Initialize device states.
			SetupDeviceStates();

			// Lock access to rendering device.
			D3D9RenderSystem.ResourceManager.LockDeviceAccess();

			var pCurActiveDevice = this.pDeviceManager.ActiveDevice;

			this.pDeviceManager.ActiveDevice = this;

			// Inform all resources that new device created.
			D3D9RenderSystem.ResourceManager.NotifyOnDeviceCreate( this.pDevice );

			this.pDeviceManager.ActiveDevice = pCurActiveDevice;

			// UnLock access to rendering device.
			D3D9RenderSystem.ResourceManager.UnlockDeviceAccess();
		}
 private Result GetCreationParameters(IntPtr devicePointer, out CreationParameters parameters)
 {
     try
     {
         this.Log.LogMethodSignatureTypesAndValues(devicePointer, "out");
         this.GetOrCreateDevice(devicePointer);
         parameters = this.Device.CreationParameters;
         return Result.Ok;
     }
     catch (SharpDXException ex)
     {
         Log.Warn(ex);
         parameters = default(CreationParameters);
         return ex.ResultCode;
     }
     catch (Exception ex)
     {
         this.Log.Fatal(ex);
         parameters = default(CreationParameters);
         return Result.UnexpectedFailure;
     }
 }