@@ -532,7 +532,7 @@ template <typename T>
532532HRESULT m_IDirect3D9Ex::CreateDeviceT (DEVICEDETAILS& DeviceDetails, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, bool IsEx, D3DDISPLAYMODEEX* pFullscreenDisplayMode, T ppReturnedDeviceInterface)
533533{
534534 // Hook WndProc before creating device
535- HWND hWnd = (hFocusWindow && IsWindow (hFocusWindow) ? hFocusWindow :
535+ const HWND hWnd = (hFocusWindow && IsWindow (hFocusWindow) ? hFocusWindow :
536536 (pPresentationParameters && IsWindow (pPresentationParameters->hDeviceWindow ) ? pPresentationParameters->hDeviceWindow : nullptr ));
537537 WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc (hWnd);
538538
@@ -576,6 +576,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
576576
577577 // Check fullscreen
578578 bool ForceFullscreen = false ;
579+ bool MultiSampleFlag = false ;
579580
580581 // Setup presentation parameters
581582 D3DPRESENT_PARAMETERS d3dpp = {};
@@ -589,87 +590,88 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
589590 CopyMemory (p_d3dpp, pPresentationParameters, sizeof (D3DPRESENT_PARAMETERS));
590591
591592 UpdatePresentParameter (p_d3dpp, hFocusWindow, DeviceDetails, IsEx, ForceFullscreen, true );
592- }
593593
594- bool MultiSampleFlag = false ;
594+ // Check for AntiAliasing (doesn't work with FlipEx)
595+ if (Config.AntiAliasing )
596+ {
597+ if (IsEx && Config.FlipEx )
598+ {
599+ LOG_LIMIT (3 , __FUNCTION__ << " Warning: AntiAliasing is not supported on FlipEx presentation mode!" );
600+ }
601+ else
602+ {
603+ DWORD QualityLevels = 0 ;
595604
596- // Check for AntiAliasing (doesn't work with FlipEx)
597- if (Config.AntiAliasing && pPresentationParameters && !(IsEx && Config.FlipEx ))
598- {
599- DWORD QualityLevels = 0 ;
605+ // Check AntiAliasing quality
606+ for (int x = min (D3DMULTISAMPLE_16_SAMPLES, Config.AntiAliasing ); x > 0 ; x--)
607+ {
608+ D3DMULTISAMPLE_TYPE Samples = (D3DMULTISAMPLE_TYPE)x;
609+ D3DFORMAT BufferFormat = (d3dpp.BackBufferFormat ) ? d3dpp.BackBufferFormat : D3DFMT_X8R8G8B8;
610+ D3DFORMAT StencilFormat = (d3dpp.AutoDepthStencilFormat ) ? d3dpp.AutoDepthStencilFormat : D3DFMT_X8R8G8B8;
600611
601- // Check AntiAliasing quality
602- for (int x = min (D3DMULTISAMPLE_16_SAMPLES, Config.AntiAliasing ); x > 0 ; x--)
603- {
604- D3DMULTISAMPLE_TYPE Samples = (D3DMULTISAMPLE_TYPE)x;
605- D3DFORMAT BufferFormat = (d3dpp.BackBufferFormat ) ? d3dpp.BackBufferFormat : D3DFMT_X8R8G8B8;
606- D3DFORMAT StencilFormat = (d3dpp.AutoDepthStencilFormat ) ? d3dpp.AutoDepthStencilFormat : D3DFMT_X8R8G8B8;
612+ if (SUCCEEDED (ProxyInterface->CheckDeviceMultiSampleType (Adapter, DeviceType, BufferFormat, d3dpp.Windowed , Samples, &QualityLevels)) &&
613+ SUCCEEDED (ProxyInterface->CheckDeviceMultiSampleType (Adapter, DeviceType, StencilFormat, d3dpp.Windowed , Samples, &QualityLevels)))
614+ {
615+ // Update Present Parameter for Multisample
616+ UpdatePresentParameterForMultisample (p_d3dpp, Samples, (QualityLevels > 0 ) ? QualityLevels - 1 : 0 );
607617
608- if (SUCCEEDED (ProxyInterface->CheckDeviceMultiSampleType (Adapter, DeviceType, BufferFormat, d3dpp.Windowed , Samples, &QualityLevels)) &&
609- SUCCEEDED (ProxyInterface->CheckDeviceMultiSampleType (Adapter, DeviceType, StencilFormat, d3dpp.Windowed , Samples, &QualityLevels)))
610- {
611- // Update Present Parameter for Multisample
612- UpdatePresentParameterForMultisample (p_d3dpp, Samples, (QualityLevels > 0 ) ? QualityLevels - 1 : 0 );
618+ // Create Device
619+ hr = CreateDeviceT (Adapter, DeviceType, hFocusWindow, BehaviorFlags, p_d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
613620
614- // Create Device
615- hr = CreateDeviceT (Adapter, DeviceType, hFocusWindow, BehaviorFlags, p_d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
621+ // Check if device was created successfully
622+ if (SUCCEEDED (hr) && ppReturnedDeviceInterface)
623+ {
624+ MultiSampleFlag = true ;
616625
617- // Check if device was created successfully
618- if (SUCCEEDED (hr) && ppReturnedDeviceInterface)
619- {
620- MultiSampleFlag = true ;
626+ (*ppReturnedDeviceInterface)->SetRenderState (D3DRS_MULTISAMPLEANTIALIAS, TRUE );
621627
622- (*ppReturnedDeviceInterface)-> SetRenderState (D3DRS_MULTISAMPLEANTIALIAS, TRUE );
628+ LOG_LIMIT ( 3 , " Setting MultiSample " << d3dpp. MultiSampleType << " Quality " << d3dpp. MultiSampleQuality );
623629
624- LOG_LIMIT (3 , " Setting MultiSample " << d3dpp.MultiSampleType << " Quality " << d3dpp.MultiSampleQuality );
630+ break ;
631+ }
632+ }
633+ }
634+ if (FAILED (hr))
635+ {
636+ // Reset presentation parameters
637+ CopyMemory (p_d3dpp, pPresentationParameters, sizeof (D3DPRESENT_PARAMETERS));
625638
626- break ;
639+ UpdatePresentParameter (p_d3dpp, hFocusWindow, DeviceDetails, IsEx, ForceFullscreen, false );
640+
641+ LOG_LIMIT (100 , __FUNCTION__ << " Failed to enable AntiAliasing!" );
627642 }
628643 }
629644 }
630- if (FAILED (hr))
631- {
632- LOG_LIMIT (100 , __FUNCTION__ << " Failed to enable AntiAliasing!" );
633- }
634- }
635- else if (Config.AntiAliasing && IsEx && Config.FlipEx )
636- {
637- LOG_LIMIT (3 , __FUNCTION__ << " Warning: AntiAliasing is not supported on FlipEx presentation mode!" );
638645 }
639646
640647 // Create Device
641648 if (FAILED (hr))
642649 {
643- // Update presentation parameters
644- if (pPresentationParameters)
645- {
646- CopyMemory (p_d3dpp, pPresentationParameters, sizeof (D3DPRESENT_PARAMETERS));
647- UpdatePresentParameter (p_d3dpp, hFocusWindow, DeviceDetails, IsEx, ForceFullscreen, false );
648- }
649-
650- // Create Device
651650 hr = CreateDeviceT (Adapter, DeviceType, hFocusWindow, BehaviorFlags, p_d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
652651 }
653652
654- if (SUCCEEDED (hr) && pPresentationParameters )
653+ if (SUCCEEDED (hr))
655654 {
656- GetFinalPresentParameter (p_d3dpp, DeviceDetails);
655+ if (pPresentationParameters)
656+ {
657+ GetFinalPresentParameter (p_d3dpp, DeviceDetails);
657658
658- d3dpp.Windowed = DeviceDetails.AppRequestedWindowMode ;
659+ d3dpp.Windowed = DeviceDetails.AppRequestedWindowMode ;
659660
660- if (MultiSampleFlag)
661- {
662- DeviceDetails.DeviceMultiSampleFlag = true ;
663- DeviceDetails.DeviceMultiSampleType = d3dpp.MultiSampleType ;
664- DeviceDetails.DeviceMultiSampleQuality = d3dpp.MultiSampleQuality ;
665- }
661+ if (MultiSampleFlag)
662+ {
663+ DeviceDetails.DeviceMultiSampleFlag = true ;
664+ DeviceDetails.DeviceMultiSampleType = d3dpp.MultiSampleType ;
665+ DeviceDetails.DeviceMultiSampleQuality = d3dpp.MultiSampleQuality ;
666+ }
666667
667- CopyMemory (pPresentationParameters, p_d3dpp, sizeof (D3DPRESENT_PARAMETERS));
668+ CopyMemory (pPresentationParameters, p_d3dpp, sizeof (D3DPRESENT_PARAMETERS));
668669
669- // Adjust window style after device creation
670- if (IsWindow (DeviceDetails.DeviceWindow ))
671- {
672- AdjustWindowStyle (DeviceDetails.DeviceWindow );
670+ // Adjust window style after device creation
671+ if (IsWindow (DeviceDetails.DeviceWindow ))
672+ {
673+ AdjustWindowStyle (DeviceDetails.DeviceWindow );
674+ }
673675 }
674676 }
675677
0 commit comments