Axiom.RenderSystems.DirectX9.D3DRenderWindow.BuildPresentParameters C# (CSharp) Method

BuildPresentParameters() public method

public BuildPresentParameters ( PresentParameters presentParams ) : void
presentParams PresentParameters
return void
	    public void BuildPresentParameters( PresentParameters presentParams )
	    {
	        // Set up the presentation parameters		
		    var pD3D = D3DRenderSystem.Direct3D9;
		    var devType = SlimDX.Direct3D9.DeviceType.Hardware;

		    if (device != null)		
			    devType = device.DeviceType;		
	
            
#warning Do we need to zero anything here or does everything get inited?
		    //ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );

		    presentParams.Windowed					= !isFullScreen;
		    presentParams.SwapEffect				= SwapEffect.Discard;
		    // triple buffer if VSync is on
		    presentParams.BackBufferCount			= vSync ? 2 : 1;
		    presentParams.EnableAutoDepthStencil	= (depthBufferPoolId != PoolId.NoDepth);
		    presentParams.DeviceWindowHandle = hWnd.Handle;
		    presentParams.BackBufferWidth			= width;
		    presentParams.BackBufferHeight			= height;
		    presentParams.FullScreenRefreshRateInHertz = isFullScreen ? _displayFrequency : 0;
		
		    if (presentParams.BackBufferWidth == 0)		
			    presentParams.BackBufferWidth = 1;					

		    if (presentParams.BackBufferHeight == 0)	
			    presentParams.BackBufferHeight = 1;					


		    if (vSync)
		    {
			    // D3D9 only seems to support 2-4 presentation intervals in fullscreen
			    if (isFullScreen)
			    {
				    switch(vSyncInterval)
				    {
				    case 1:
				    default:
					    presentParams.PresentationInterval = PresentInterval.One;
					    break;
				    case 2:
					    presentParams.PresentationInterval = PresentInterval.Two;
					    break;
				    case 3:
					    presentParams.PresentationInterval = PresentInterval.Three;
					    break;
				    case 4:
					    presentParams.PresentationInterval = PresentInterval.Four;
					    break;
				    };
				    // check that the interval was supported, revert to 1 to be safe otherwise
			        var caps = pD3D.GetDeviceCaps( device.AdapterNumber, devType );
				    if ((caps.PresentationIntervals & presentParams.PresentationInterval) != 0)
					    presentParams.PresentationInterval = PresentInterval.One;

			    }
			    else
			    {
				    presentParams.PresentationInterval = PresentInterval.One;
			    }

		    }
		    else
		    {
			    // NB not using vsync in windowed mode in D3D9 can cause jerking at low 
			    // frame rates no matter what buffering modes are used (odd - perhaps a
			    // timer issue in D3D9 since GL doesn't suffer from this) 
			    // low is < 200fps in this context
			    if (!isFullScreen)
			    {
				    LogManager.Instance.Write("D3D9 : WARNING - " +
					    "disabling VSync in windowed mode can cause timing issues at lower " +
					    "frame rates, turn VSync on if you observe this problem.");
			    }
			    presentParams.PresentationInterval = PresentInterval.Immediate;
		    }

		    presentParams.BackBufferFormat		= Format.R5G6B5;
		    if( colorDepth > 16 )
			    presentParams.BackBufferFormat = Format.X8R8G8B8;

		    if (colorDepth > 16 )
		    {
                // Try to create a 32-bit depth, 8-bit stencil

                if (!pD3D.CheckDeviceFormat(device.AdapterNumber,
                    devType, presentParams.BackBufferFormat, Usage.DepthStencil,
                    ResourceType.Surface, Format.D24S8))
			    {
				    // Bugger, no 8-bit hardware stencil, just try 32-bit zbuffer
                    if (!pD3D.CheckDeviceFormat(device.AdapterNumber, 
                        devType, presentParams.BackBufferFormat, Usage.DepthStencil,
                        ResourceType.Surface, Format.D32))
				    {
					    // Jeez, what a naff card. Fall back on 16-bit depth buffering
					    presentParams.AutoDepthStencilFormat = Format.D16;
				    }
				    else
					    presentParams.AutoDepthStencilFormat = Format.D32;
			    }
			    else
			    {
				    // Woohoo!
                    if (pD3D.CheckDepthStencilMatch(device.AdapterNumber, devType,
                        presentParams.BackBufferFormat, presentParams.BackBufferFormat, Format.D24S8))
				    {
					    presentParams.AutoDepthStencilFormat = Format.D24S8; 
				    } 
				    else 
					    presentParams.AutoDepthStencilFormat = Format.D24X8; 
			    }
		    }
		    else
			    // 16-bit depth, software stencil
			    presentParams.AutoDepthStencilFormat	= Format.D16;


		    var rsys = (D3DRenderSystem)Root.Instance.RenderSystem;
		
		    rsys.DetermineFSAASettings(device.D3DDevice,
			    fsaa, fsaaHint, presentParams.BackBufferFormat, isFullScreen, 
			    out fsaaType, out fsaaQuality);

            presentParams.Multisample = fsaaType;
            presentParams.MultisampleQuality = (fsaaQuality == 0) ? 0 : fsaaQuality;

		    // Check sRGB
		    if (hwGamma)
		    {
			    /* hmm, this never succeeds even when device does support??
			    if(FAILED(pD3D->CheckDeviceFormat(mDriver->getAdapterNumber(),
				    devType, presentParams->BackBufferFormat, D3DUSAGE_QUERY_SRGBWRITE, 
				    D3DRTYPE_SURFACE, presentParams->BackBufferFormat )))
			    {
				    // disable - not supported
				    mHwGamma = false;
			    }
			    */

		    }
	    }