Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions Client/core/Graphics/CGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2786,27 +2786,42 @@ void CGraphics::DrawProgressMessage(bool bPreserveBackbuffer)
//
/////////////////////////////////////////////////////////////
bool CGraphics::ResizeTextureData(const void* pData, uint uiDataPitch, uint uiWidth, uint uiHeight, uint d3dFormat, uint uiNewWidth, uint uiNewHeight,
CBuffer& outBuffer)
CBuffer& outBuffer, uint d3dNewFormat)
{
bool bResult = false;
IDirect3DSurface9* pCurrentSurface = NULL;
IDirect3DSurface9* pNewSurface = NULL;

// Output format defaults to the source format.
const D3DFORMAT destFormat = d3dNewFormat ? (D3DFORMAT)d3dNewFormat : (D3DFORMAT)d3dFormat;
const bool bConvertFormat = destFormat != (D3DFORMAT)d3dFormat;

do
{
// Create surfaces
if (FAILED(g_pGraphics->GetDevice()->CreateOffscreenPlainSurface(uiWidth, uiHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pCurrentSurface, NULL)))
break;
if (FAILED(g_pGraphics->GetDevice()->CreateOffscreenPlainSurface(uiNewWidth, uiNewHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pNewSurface, NULL)))
break;

// Data in
if (!CopyDataToSurface(pCurrentSurface, (const BYTE*)pData, uiDataPitch))
// Destination surface (resized and/or reformatted)
if (FAILED(g_pGraphics->GetDevice()->CreateOffscreenPlainSurface(uiNewWidth, uiNewHeight, destFormat, D3DPOOL_SCRATCH, &pNewSurface, NULL)))
break;

// Resize
if (FAILED(D3DXLoadSurfaceFromSurface(pNewSurface, NULL, NULL, pCurrentSurface, NULL, NULL, D3DX_FILTER_TRIANGLE, 0)))
break;
if (bConvertFormat)
{
// Format conversion (e.g. a DXT-compressed source to A8R8G8B8). Load straight from
// memory: D3DXLoadSurfaceFromMemory decodes the source format (decompressing DXT) and
// resizes into the destination surface in one step. This is more reliable than copying
// compressed blocks into an intermediate surface by hand.
RECT srcRect = {0, 0, (LONG)uiWidth, (LONG)uiHeight};
if (FAILED(D3DXLoadSurfaceFromMemory(pNewSurface, NULL, NULL, pData, (D3DFORMAT)d3dFormat, uiDataPitch, NULL, &srcRect, D3DX_FILTER_TRIANGLE, 0)))
break;
}
else
{
// Same-format resize: copy the source pixels into a matching surface and resize
if (FAILED(g_pGraphics->GetDevice()->CreateOffscreenPlainSurface(uiWidth, uiHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pCurrentSurface, NULL)))
break;
if (!CopyDataToSurface(pCurrentSurface, (const BYTE*)pData, uiDataPitch))
break;
if (FAILED(D3DXLoadSurfaceFromSurface(pNewSurface, NULL, NULL, pCurrentSurface, NULL, NULL, D3DX_FILTER_TRIANGLE, 0)))
break;
}

// Data out
if (!CopyDataFromSurface(pNewSurface, outBuffer))
Expand Down
2 changes: 1 addition & 1 deletion Client/core/Graphics/CGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>

// Texture data manipulation
bool ResizeTextureData(const void* pData, uint uiDataPitch, uint uiWidth, uint uiHeight, uint d3dFormat, uint uiNewWidth, uint uiNewHeight,
CBuffer& outBuffer);
CBuffer& outBuffer, uint d3dNewFormat = 0);
bool CopyDataToSurface(IDirect3DSurface9* pSurface, const uchar* pPixelsData, uint uiDataPitch);
bool CopyDataFromSurface(IDirect3DSurface9* pSurface, CBuffer& outBuffer);

Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CRenderWareSA.ClothesReplacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,5 @@ static void __declspec(naked) HOOK_CStreaming_RequestModel_Mid()
void CRenderWareSA::StaticSetClothesReplacingHooks()
{
EZHookInstall(CStreaming_RequestModel_Mid);
StaticSetClothesTexturesHooks();
}
Loading