Skip to content

Commit

Permalink
Update support for MipMap without width or height
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Aug 14, 2024
1 parent 7bfdc4d commit 4cab4a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 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 7090
#define BUILD_NUMBER 7091
18 changes: 17 additions & 1 deletion ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3992,6 +3992,12 @@ LPDIRECT3DTEXTURE9 m_IDirectDrawSurfaceX::GetD3d9Texture()
return nullptr;
}

// Check if surface is render target
if (IsRenderTarget())
{
LOG_LIMIT(100, __FUNCTION__ << " Error: Render Target textures not implemented!");
}

return Get3DTexture();
}

Expand Down Expand Up @@ -4270,8 +4276,9 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
}
}
// Create render target
else if (IsRenderTarget() || (UseVideoMemory && IsSurface3D()))
else if (IsRenderTarget())
{
// ToDo: if render surface is a texture then create as a texture (MipMaps can be supported on render target textures)
surface.Type = D3DTYPE_RENDERTARGET;
surface.Pool = D3DPOOL_DEFAULT;
BOOL IsLockable = (surface.MultiSampleType || (surfaceDesc2.ddsCaps.dwCaps2 & DDSCAPS2_NOTUSERLOCKABLE)) ? FALSE : TRUE;
Expand Down Expand Up @@ -5605,6 +5612,15 @@ inline void m_IDirectDrawSurfaceX::InitSurfaceDesc(DWORD DirectXVersion)
if ((!(surfaceDesc2.dwFlags & DDSD_MIPMAPCOUNT) || ((surfaceDesc2.dwFlags & DDSD_MIPMAPCOUNT) && surfaceDesc2.dwMipMapCount != 1)) &&
(surfaceDesc2.ddsCaps.dwCaps & (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX | DDSCAPS_TEXTURE)) == (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX | DDSCAPS_TEXTURE))
{
// Compute width and height
if ((!(surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) || (!surfaceDesc2.dwWidth && !surfaceDesc2.dwHeight)) &&
(surfaceDesc2.dwFlags & DDSD_MIPMAPCOUNT) && surfaceDesc2.dwMipMapCount > 0)
{
surfaceDesc2.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
surfaceDesc2.dwWidth = pow(2, surfaceDesc2.dwMipMapCount - 1);
surfaceDesc2.dwHeight = surfaceDesc2.dwWidth;
}
// Compute mipcount
DWORD MipMapLevelCount = ((surfaceDesc2.dwFlags & DDSD_MIPMAPCOUNT) && surfaceDesc2.dwMipMapCount) ? surfaceDesc2.dwMipMapCount :
GetMaxMipMapLevel(surfaceDesc2.dwWidth, surfaceDesc2.dwHeight);
MaxMipMapLevel = MipMapLevelCount;
Expand Down
17 changes: 10 additions & 7 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,14 @@ HRESULT m_IDirectDrawX::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRE
}

// Check MipMap count
if ((lpDDSurfaceDesc2->dwFlags & DDSD_MIPMAPCOUNT) && (lpDDSurfaceDesc2->dwMipMapCount != 1) &&
(lpDDSurfaceDesc2->ddsCaps.dwCaps & (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX | DDSCAPS_TEXTURE)) == (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX | DDSCAPS_TEXTURE) &&
GetMaxMipMapLevel(lpDDSurfaceDesc2->dwWidth, lpDDSurfaceDesc2->dwHeight) < lpDDSurfaceDesc2->dwMipMapCount)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: MipMap count too large. Count: " << lpDDSurfaceDesc2->dwMipMapCount <<
if ((lpDDSurfaceDesc2->ddsCaps.dwCaps & (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX | DDSCAPS_TEXTURE)) == (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX | DDSCAPS_TEXTURE) &&
(((lpDDSurfaceDesc2->dwFlags & DDSD_MIPMAPCOUNT) && (lpDDSurfaceDesc2->dwMipMapCount != 1) &&
((lpDDSurfaceDesc2->dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == (DDSD_WIDTH | DDSD_HEIGHT) && lpDDSurfaceDesc2->dwWidth && lpDDSurfaceDesc2->dwHeight) &&
GetMaxMipMapLevel(lpDDSurfaceDesc2->dwWidth, lpDDSurfaceDesc2->dwHeight) < lpDDSurfaceDesc2->dwMipMapCount) ||
((!(lpDDSurfaceDesc2->dwFlags & DDSD_WIDTH) || !(lpDDSurfaceDesc2->dwFlags & DDSD_HEIGHT) || !lpDDSurfaceDesc2->dwWidth || !lpDDSurfaceDesc2->dwHeight) &&
(!(lpDDSurfaceDesc2->dwFlags & DDSD_MIPMAPCOUNT) || ((lpDDSurfaceDesc2->dwFlags & DDSD_MIPMAPCOUNT) && (lpDDSurfaceDesc2->dwMipMapCount == 0))))))
{
LOG_LIMIT(100, __FUNCTION__ << " Error: invalid MipMap count. Count: " << lpDDSurfaceDesc2->dwMipMapCount <<
" " << lpDDSurfaceDesc2->dwWidth << "x" << lpDDSurfaceDesc2->dwHeight << " Max: " << GetMaxMipMapLevel(lpDDSurfaceDesc2->dwWidth, lpDDSurfaceDesc2->dwHeight));
return DDERR_INVALIDPARAMS;
}
Expand Down Expand Up @@ -700,12 +703,12 @@ HRESULT m_IDirectDrawX::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRE
{
Desc2.dwRefreshRate = 0;
}
if (((Desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (Desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE)) || (Desc2.ddpfPixelFormat.dwFlags & (DDPF_ZBUFFER | DDPF_STENCILBUFFER)))
// Removing texture flags from primary and stencil buffer surfaces
if ((Desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) || (Desc2.ddpfPixelFormat.dwFlags & (DDPF_ZBUFFER | DDPF_STENCILBUFFER)))
{
Desc2.dwFlags &= ~DDSD_MIPMAPCOUNT;
Desc2.ddsCaps.dwCaps &= ~(DDSCAPS_TEXTURE | DDSCAPS_MIPMAP);
Desc2.ddsCaps.dwCaps2 &= ~(DDSCAPS2_HINTDYNAMIC | DDSCAPS2_HINTSTATIC | DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE);
LOG_LIMIT(100, __FUNCTION__ << " Warning: removing texture flag from primary or stencil buffer surface!");
}

// Check for depth stencil surface
Expand Down

0 comments on commit 4cab4a9

Please sign in to comment.