@@ -4405,9 +4405,10 @@ HRESULT m_IDirectDrawSurfaceX::CreateD9Surface()
44054405 UpdateSurfaceDesc ();
44064406
44074407 // Get texture format
4408+ const bool IsMipMapEnabled = (surfaceDesc2.dwFlags & DDSD_MIPMAPCOUNT) && surfaceDesc2.dwMipMapCount != 1 && IsSurfaceTexture ();
44084409 surface.Format = GetDisplayFormat (surfaceDesc2.ddpfPixelFormat );
44094410 surface.BitCount = GetBitCount (surface.Format );
4410- SurfaceRequiresEmulation = (CanSurfaceUseEmulation () && (Config.DdrawEmulateSurface || ShouldEmulate == SC_FORCE_EMULATED ||
4411+ SurfaceRequiresEmulation = (CanSurfaceUseEmulation () && ((!IsMipMapEnabled && ( Config.DdrawEmulateSurface || ShouldEmulate == SC_FORCE_EMULATED)) ||
44114412 surface.Format == D3DFMT_A8B8G8R8 || surface.Format == D3DFMT_X8B8G8R8 || surface.Format == D3DFMT_B8G8R8 || surface.Format == D3DFMT_R8G8B8));
44124413 const bool CreateSurfaceEmulated = (CanSurfaceUseEmulation () && (SurfaceRequiresEmulation ||
44134414 (IsPrimaryOrBackBuffer () && (Config.DdrawWriteToGDI || Config.DdrawReadFromGDI || Config.DdrawRemoveScanlines ))));
@@ -4528,12 +4529,11 @@ HRESULT m_IDirectDrawSurfaceX::CreateD9Surface()
45284529 else if (IsTexture)
45294530 {
45304531 surface.Type = D3DTYPE_TEXTURE;
4531- DWORD MipMapCount = (surfaceDesc2.dwFlags & DDSD_MIPMAPCOUNT) ? surfaceDesc2.dwMipMapCount : 1 ;
4532- DWORD MipMapLevel = (CreateSurfaceEmulated || !MipMapCount) ? 1 : MipMapCount;
4532+ DWORD MipMapLevel = IsMipMapEnabled && !CreateSurfaceEmulated ? surfaceDesc2.dwMipMapCount : 1 ;
45334533 HRESULT hr_t ;
45344534 do {
4535- surface.Usage = (Config.DdrawForceMipMapAutoGen && MipMapLevel > 1 ) ? D3DUSAGE_AUTOGENMIPMAP : 0 ;
4536- DWORD Level = (( surface.Usage & D3DUSAGE_AUTOGENMIPMAP) && MipMapLevel == MipMapCount) ? 0 : MipMapLevel ;
4535+ surface.Usage = (Config.DdrawForceMipMapAutoGen && MipMapLevel != 1 ) ? D3DUSAGE_AUTOGENMIPMAP : 0 ;
4536+ DWORD Level = (surface.Usage & D3DUSAGE_AUTOGENMIPMAP) == 0 ? MipMapLevel : 0 ;
45374537 // Create texture
45384538 hr_t = (*d3d9Device)->CreateTexture (surface.Width , surface.Height , Level, surface.Usage , Format, surface.Pool , &surface.Texture , nullptr );
45394539 if (FAILED (hr_t ))
@@ -4547,7 +4547,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD9Surface()
45474547 hr = DDERR_GENERIC;
45484548 break ;
45494549 }
4550- MaxMipMapLevel = (MipMapLevel > 1 && ! IsMipMapAutogen ()) ? MipMapLevel - 1 : 0 ;
4550+ MaxMipMapLevel = (!IsMipMapEnabled || IsMipMapAutogen () || CreateSurfaceEmulated ? 1 : MipMapLevel > 0 ? MipMapLevel : surface. Texture -> GetLevelCount ()) - 1 ;
45514551 while (MipMaps.size () < MaxMipMapLevel)
45524552 {
45534553 MIPMAP MipMap;
0 commit comments