Skip to content

Commit

Permalink
Enable MipMap support
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed May 10, 2024
1 parent 3054a05 commit 39384fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7011
#define BUILD_NUMBER 7012
12 changes: 0 additions & 12 deletions ddraw/IDirect3DDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4193,18 +4193,6 @@ inline void m_IDirect3DDeviceX::SetDrawStates(DWORD dwVertexTypeDesc, DWORD& dwF
}
}
}
// For now just disable mipmap filtering
if (Config.Dd7to9)
{
for (UINT x = 0; x < MaxTextureBlendStages; x++)
{
if (ssMipFilter[x] != D3DTEXF_NONE)
{
ssMipFilter[x] = D3DTEXF_NONE;
(*d3d9Device)->SetSamplerState(x, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
}
}
}
if (dwFlags & D3DDP_DXW_COLORKEYENABLE)
{
if (!colorkeyPixelShader || !*colorkeyPixelShader)
Expand Down
18 changes: 10 additions & 8 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3690,7 +3690,7 @@ LPDIRECT3DTEXTURE9 m_IDirectDrawSurfaceX::Get3DDrawTexture()
// Create texture
if (surface.Texture)
{
if (FAILED((*d3d9Device)->CreateTexture(surface.Tex.Width, surface.Tex.Height, MaxMipMapLevel, 0, D3DFMT_A8R8G8B8, surface.Tex.TexturePool, &surface.DrawTexture, nullptr)))
if (FAILED((*d3d9Device)->CreateTexture(surface.Tex.Width, surface.Tex.Height, MaxMipMapLevel, surface.Tex.Usage, D3DFMT_A8R8G8B8, surface.Tex.Pool, &surface.DrawTexture, nullptr)))
{
LOG_LIMIT(100, __FUNCTION__ << " Error: failed to create surface texture. Size: " << surface.Tex.Width << "x" << surface.Tex.Height << " Format: " << surfaceFormat << " dwCaps: " << Logging::hex(surfaceDesc2.ddsCaps.dwCaps));
return nullptr;
Expand Down Expand Up @@ -3726,9 +3726,9 @@ LPDIRECT3DTEXTURE9 m_IDirectDrawSurfaceX::Get3DTexture()
}

// Check texture pool
if (surface.Tex.TexturePool == D3DPOOL_SYSTEMMEM || surface.Tex.TexturePool == D3DPOOL_SCRATCH)
if (surface.Tex.Pool == D3DPOOL_SYSTEMMEM || surface.Tex.Pool == D3DPOOL_SCRATCH)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: texture pool does not support Driect3D: " << surfaceFormat << " Pool: " << surface.Tex.TexturePool <<
LOG_LIMIT(100, __FUNCTION__ << " Error: texture pool does not support Driect3D: " << surfaceFormat << " Pool: " << surface.Tex.Pool <<
" Caps: " << Logging::hex(surfaceDesc2.ddsCaps.dwCaps) << " Attached: " << attached3DTexture);
return nullptr;
}
Expand Down Expand Up @@ -3851,7 +3851,7 @@ HRESULT m_IDirectDrawSurfaceX::CheckInterface(char *FunctionName, bool CheckD3DD
}

// Check if texture pool is wrong
if (attached3DTexture && surface.Tex.TexturePool != D3DPOOL_MANAGED)
if (attached3DTexture && surface.Tex.Pool != D3DPOOL_MANAGED)
{
ReleaseD9Surface(true, false);
}
Expand Down Expand Up @@ -3908,7 +3908,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
const D3DFORMAT TextureFormat = (surfaceFormat == D3DFMT_P8) ? D3DFMT_L8 : Format;

// Get texture memory pool
surface.Tex.TexturePool = (IsPrimaryOrBackBuffer() && surface.IsUsingWindowedMode && !Using3D) ? D3DPOOL_SYSTEMMEM :
surface.Tex.Pool = (IsPrimaryOrBackBuffer() && surface.IsUsingWindowedMode && !Using3D) ? D3DPOOL_SYSTEMMEM :
(IsPrimaryOrBackBuffer() || (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE) ||
(surfaceDesc2.ddsCaps.dwCaps2 & (DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE))) ? D3DPOOL_MANAGED :
(surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
Expand All @@ -3921,7 +3921,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
ShouldEmulate = (ShouldEmulate == SC_NOT_CREATED) ? SC_DONT_FORCE : ShouldEmulate;

Logging::LogDebug() << __FUNCTION__ " (" << this << ") D3d9 Surface. Size: " << Width << "x" << Height << " Format: " << surfaceFormat <<
" Pool: " << surface.Tex.TexturePool << " dwCaps: " << Logging::hex(surfaceDesc2.ddsCaps.dwCaps);
" Pool: " << surface.Tex.Pool << " dwCaps: " << Logging::hex(surfaceDesc2.ddsCaps.dwCaps);

HRESULT hr = DD_OK;

Expand All @@ -3943,11 +3943,13 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
DWORD MipMapLevel = (SurfaceRequiresEmulation || MipMaps.empty()) ? 1 : MaxMipMapLevel;
HRESULT hr_t;
do {
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, 0, TextureFormat, surface.Tex.TexturePool, &surface.Texture, nullptr);
surface.Tex.Usage = (MipMapLevel != 1 && (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) &&
(surfaceDesc2.ddsCaps.dwCaps2 & DDSCAPS2_HINTDYNAMIC)) ? D3DUSAGE_AUTOGENMIPMAP : 0;
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, surface.Tex.Usage, TextureFormat, surface.Tex.Pool, &surface.Texture, nullptr);
// Try failover format
if (FAILED(hr_t))
{
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, 0, GetFailoverFormat(TextureFormat), surface.Tex.TexturePool, &surface.Texture, nullptr);
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, surface.Tex.Usage, GetFailoverFormat(TextureFormat), surface.Tex.Pool, &surface.Texture, nullptr);
}
} while (FAILED(hr_t) && ((!MipMapLevel && ++MipMapLevel) || --MipMapLevel > 0));
if (FAILED(hr_t))
Expand Down
3 changes: 2 additions & 1 deletion ddraw/IDirectDrawSurfaceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
{
DWORD Width = 0;
DWORD Height = 0;
D3DPOOL TexturePool = D3DPOOL_DEFAULT;
D3DPOOL Pool = D3DPOOL_DEFAULT;
DWORD Usage = 0;
};

// Extra Direct3D9 devices used in the primary surface
Expand Down

0 comments on commit 39384fb

Please sign in to comment.